VsyncBridgeParent.cpp (2267B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 #include "VsyncBridgeParent.h" 7 #include "mozilla/ipc/Endpoint.h" 8 #include "mozilla/layers/CompositorBridgeParent.h" 9 #include "mozilla/layers/CompositorThread.h" 10 11 using mozilla::layers::CompositorBridgeParent; 12 using mozilla::layers::CompositorThreadHolder; 13 14 namespace mozilla { 15 namespace gfx { 16 17 RefPtr<VsyncBridgeParent> VsyncBridgeParent::Start( 18 Endpoint<PVsyncBridgeParent>&& aEndpoint) { 19 RefPtr<VsyncBridgeParent> parent = new VsyncBridgeParent(); 20 21 RefPtr<Runnable> task = NewRunnableMethod<Endpoint<PVsyncBridgeParent>&&>( 22 "gfx::VsyncBridgeParent::Open", parent, &VsyncBridgeParent::Open, 23 std::move(aEndpoint)); 24 layers::CompositorThread()->Dispatch(task.forget()); 25 26 return parent; 27 } 28 29 VsyncBridgeParent::VsyncBridgeParent() : mOpen(false) { 30 MOZ_COUNT_CTOR(VsyncBridgeParent); 31 mCompositorThreadRef = CompositorThreadHolder::GetSingleton(); 32 } 33 34 VsyncBridgeParent::~VsyncBridgeParent() { MOZ_COUNT_DTOR(VsyncBridgeParent); } 35 36 void VsyncBridgeParent::Open(Endpoint<PVsyncBridgeParent>&& aEndpoint) { 37 if (!aEndpoint.Bind(this)) { 38 // We can't recover from this. 39 MOZ_CRASH("Failed to bind VsyncBridgeParent to endpoint"); 40 } 41 mOpen = true; 42 } 43 44 mozilla::ipc::IPCResult VsyncBridgeParent::RecvNotifyVsync( 45 const VsyncEvent& aVsync, const LayersId& aLayersId) { 46 CompositorBridgeParent::NotifyVsync(aVsync, aLayersId); 47 return IPC_OK(); 48 } 49 50 void VsyncBridgeParent::Shutdown() { 51 if (!CompositorThreadHolder::IsInCompositorThread()) { 52 layers::CompositorThread()->Dispatch( 53 NewRunnableMethod("gfx::VsyncBridgeParent::ShutdownImpl", this, 54 &VsyncBridgeParent::ShutdownImpl)); 55 return; 56 } 57 58 ShutdownImpl(); 59 } 60 61 void VsyncBridgeParent::ShutdownImpl() { 62 if (mOpen) { 63 Close(); 64 mOpen = false; 65 } 66 } 67 68 void VsyncBridgeParent::ActorDestroy(ActorDestroyReason aWhy) { 69 mOpen = false; 70 mCompositorThreadRef = nullptr; 71 } 72 73 } // namespace gfx 74 } // namespace mozilla