Bug 1822393 - Consume GeckoView directly in Android Components for CI builds. r=owlis...
[gecko.git] / gfx / ipc / VsyncBridgeParent.cpp
blobc98b641ba2b4c95b567541dc2a44232e29d61fda
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"
11 using mozilla::layers::CompositorBridgeParent;
12 using mozilla::layers::CompositorThreadHolder;
14 namespace mozilla {
15 namespace gfx {
17 RefPtr<VsyncBridgeParent> VsyncBridgeParent::Start(
18 Endpoint<PVsyncBridgeParent>&& aEndpoint) {
19 RefPtr<VsyncBridgeParent> parent = new VsyncBridgeParent();
21 RefPtr<Runnable> task = NewRunnableMethod<Endpoint<PVsyncBridgeParent>&&>(
22 "gfx::VsyncBridgeParent::Open", parent, &VsyncBridgeParent::Open,
23 std::move(aEndpoint));
24 layers::CompositorThread()->Dispatch(task.forget());
26 return parent;
29 VsyncBridgeParent::VsyncBridgeParent() : mOpen(false) {
30 MOZ_COUNT_CTOR(VsyncBridgeParent);
31 mCompositorThreadRef = CompositorThreadHolder::GetSingleton();
34 VsyncBridgeParent::~VsyncBridgeParent() { MOZ_COUNT_DTOR(VsyncBridgeParent); }
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");
41 mOpen = true;
44 mozilla::ipc::IPCResult VsyncBridgeParent::RecvNotifyVsync(
45 const VsyncEvent& aVsync, const LayersId& aLayersId) {
46 CompositorBridgeParent::NotifyVsync(aVsync, aLayersId);
47 return IPC_OK();
50 void VsyncBridgeParent::Shutdown() {
51 if (!CompositorThreadHolder::IsInCompositorThread()) {
52 layers::CompositorThread()->Dispatch(
53 NewRunnableMethod("gfx::VsyncBridgeParent::ShutdownImpl", this,
54 &VsyncBridgeParent::ShutdownImpl));
55 return;
58 ShutdownImpl();
61 void VsyncBridgeParent::ShutdownImpl() {
62 if (mOpen) {
63 Close();
64 mOpen = false;
68 void VsyncBridgeParent::ActorDestroy(ActorDestroyReason aWhy) {
69 mOpen = false;
70 mCompositorThreadRef = nullptr;
73 } // namespace gfx
74 } // namespace mozilla