2017-10-28 02:10:06 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2016-07-19 21:56:06 +03:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#include "VsyncBridgeChild.h"
|
|
|
|
#include "VsyncIOThreadHolder.h"
|
2016-10-04 11:31:27 +03:00
|
|
|
#include "mozilla/dom/ContentChild.h"
|
2016-07-19 21:56:06 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
|
|
|
|
VsyncBridgeChild::VsyncBridgeChild(RefPtr<VsyncIOThreadHolder> aThread,
|
|
|
|
const uint64_t& aProcessToken)
|
2019-03-12 22:08:01 +03:00
|
|
|
: mThread(aThread), mProcessToken(aProcessToken) {}
|
2016-07-19 21:56:06 +03:00
|
|
|
|
|
|
|
VsyncBridgeChild::~VsyncBridgeChild() {}
|
|
|
|
|
2019-02-26 01:07:19 +03:00
|
|
|
/* static */
|
|
|
|
RefPtr<VsyncBridgeChild> VsyncBridgeChild::Create(
|
2016-07-19 21:56:06 +03:00
|
|
|
RefPtr<VsyncIOThreadHolder> aThread, const uint64_t& aProcessToken,
|
|
|
|
Endpoint<PVsyncBridgeChild>&& aEndpoint) {
|
|
|
|
RefPtr<VsyncBridgeChild> child = new VsyncBridgeChild(aThread, aProcessToken);
|
|
|
|
|
|
|
|
RefPtr<nsIRunnable> task = NewRunnableMethod<Endpoint<PVsyncBridgeChild>&&>(
|
2017-06-12 22:34:10 +03:00
|
|
|
"gfx::VsyncBridgeChild::Open", child, &VsyncBridgeChild::Open,
|
2018-05-30 22:15:35 +03:00
|
|
|
std::move(aEndpoint));
|
2016-07-19 21:56:06 +03:00
|
|
|
aThread->GetThread()->Dispatch(task.forget(), nsIThread::DISPATCH_NORMAL);
|
|
|
|
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VsyncBridgeChild::Open(Endpoint<PVsyncBridgeChild>&& aEndpoint) {
|
2016-09-02 23:13:50 +03:00
|
|
|
if (!aEndpoint.Bind(this)) {
|
2016-07-19 21:56:06 +03:00
|
|
|
// The GPU Process Manager might be gone if we receive ActorDestroy very
|
|
|
|
// late in shutdown.
|
|
|
|
if (GPUProcessManager* gpm = GPUProcessManager::Get())
|
|
|
|
gpm->NotifyRemoteActorDestroyed(mProcessToken);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Last reference is freed in DeallocPVsyncBridgeChild.
|
|
|
|
AddRef();
|
|
|
|
}
|
|
|
|
|
2016-07-19 21:56:07 +03:00
|
|
|
class NotifyVsyncTask : public Runnable {
|
|
|
|
public:
|
2018-12-08 02:27:28 +03:00
|
|
|
NotifyVsyncTask(RefPtr<VsyncBridgeChild> aVsyncBridge,
|
|
|
|
const VsyncEvent& aVsync, const layers::LayersId& aLayersId)
|
2017-06-12 22:34:10 +03:00
|
|
|
: Runnable("gfx::NotifyVsyncTask"),
|
|
|
|
mVsyncBridge(aVsyncBridge),
|
2018-12-08 02:27:28 +03:00
|
|
|
mVsync(aVsync),
|
2017-06-12 22:34:10 +03:00
|
|
|
mLayersId(aLayersId) {}
|
2016-07-19 21:56:07 +03:00
|
|
|
|
|
|
|
NS_IMETHOD Run() override {
|
2018-12-08 02:27:28 +03:00
|
|
|
mVsyncBridge->NotifyVsyncImpl(mVsync, mLayersId);
|
2016-07-19 21:56:07 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
RefPtr<VsyncBridgeChild> mVsyncBridge;
|
2018-12-08 02:27:28 +03:00
|
|
|
VsyncEvent mVsync;
|
2018-03-25 02:06:01 +03:00
|
|
|
layers::LayersId mLayersId;
|
2016-07-19 21:56:07 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
bool VsyncBridgeChild::IsOnVsyncIOThread() const {
|
2019-03-12 22:08:01 +03:00
|
|
|
return mThread->IsOnCurrentThread();
|
2016-07-19 21:56:07 +03:00
|
|
|
}
|
|
|
|
|
2018-12-08 02:27:28 +03:00
|
|
|
void VsyncBridgeChild::NotifyVsync(const VsyncEvent& aVsync,
|
2018-03-25 02:06:01 +03:00
|
|
|
const layers::LayersId& aLayersId) {
|
2016-07-19 21:56:07 +03:00
|
|
|
// This should be on the Vsync thread (not the Vsync I/O thread).
|
|
|
|
MOZ_ASSERT(!IsOnVsyncIOThread());
|
|
|
|
|
2018-12-08 02:27:28 +03:00
|
|
|
RefPtr<NotifyVsyncTask> task = new NotifyVsyncTask(this, aVsync, aLayersId);
|
2019-03-12 22:08:01 +03:00
|
|
|
mThread->Dispatch(task.forget());
|
2016-07-19 21:56:07 +03:00
|
|
|
}
|
|
|
|
|
2018-12-08 02:27:28 +03:00
|
|
|
void VsyncBridgeChild::NotifyVsyncImpl(const VsyncEvent& aVsync,
|
2018-03-25 02:06:01 +03:00
|
|
|
const layers::LayersId& aLayersId) {
|
2016-07-19 21:56:07 +03:00
|
|
|
// This should be on the Vsync I/O thread.
|
|
|
|
MOZ_ASSERT(IsOnVsyncIOThread());
|
|
|
|
|
|
|
|
if (!mProcessToken) {
|
|
|
|
return;
|
|
|
|
}
|
2018-12-08 02:27:28 +03:00
|
|
|
SendNotifyVsync(aVsync, aLayersId);
|
2016-07-19 21:56:07 +03:00
|
|
|
}
|
|
|
|
|
2016-07-19 21:56:06 +03:00
|
|
|
void VsyncBridgeChild::Close() {
|
2016-07-19 21:56:07 +03:00
|
|
|
if (!IsOnVsyncIOThread()) {
|
2019-03-12 22:08:01 +03:00
|
|
|
mThread->Dispatch(NewRunnableMethod("gfx::VsyncBridgeChild::Close", this,
|
|
|
|
&VsyncBridgeChild::Close));
|
2016-07-19 21:56:06 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We clear mProcessToken when the channel is closed.
|
|
|
|
if (!mProcessToken) {
|
|
|
|
return;
|
|
|
|
}
|
2016-11-03 02:45:38 +03:00
|
|
|
|
|
|
|
// Clear the process token so we don't notify the GPUProcessManager. It
|
|
|
|
// already knows we're closed since it manually called Close, and in fact the
|
|
|
|
// GPM could have already been destroyed during shutdown.
|
2016-07-19 21:56:06 +03:00
|
|
|
mProcessToken = 0;
|
2016-11-03 02:45:38 +03:00
|
|
|
|
|
|
|
// Close the underlying IPC channel.
|
|
|
|
PVsyncBridgeChild::Close();
|
2016-07-19 21:56:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void VsyncBridgeChild::ActorDestroy(ActorDestroyReason aWhy) {
|
|
|
|
if (mProcessToken) {
|
|
|
|
GPUProcessManager::Get()->NotifyRemoteActorDestroyed(mProcessToken);
|
|
|
|
mProcessToken = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VsyncBridgeChild::DeallocPVsyncBridgeChild() { Release(); }
|
|
|
|
|
|
|
|
void VsyncBridgeChild::ProcessingError(Result aCode, const char* aReason) {
|
2016-09-19 08:13:53 +03:00
|
|
|
MOZ_RELEASE_ASSERT(aCode == MsgDropped,
|
|
|
|
"Processing error in VsyncBridgeChild");
|
2016-07-19 21:56:06 +03:00
|
|
|
}
|
|
|
|
|
2018-04-23 21:13:36 +03:00
|
|
|
void VsyncBridgeChild::HandleFatalError(const char* aMsg) const {
|
|
|
|
dom::ContentChild::FatalErrorIfNotUsingGPUProcess(aMsg, OtherPid());
|
2016-10-04 11:31:27 +03:00
|
|
|
}
|
|
|
|
|
2016-07-19 21:56:06 +03:00
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|