Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 tw=99: */
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/layers/CompositorThread.h"
8 :
9 : namespace mozilla {
10 : namespace gfx {
11 :
12 : RefPtr<VsyncBridgeParent>
13 0 : VsyncBridgeParent::Start(Endpoint<PVsyncBridgeParent>&& aEndpoint)
14 : {
15 0 : RefPtr<VsyncBridgeParent> parent = new VsyncBridgeParent();
16 :
17 0 : RefPtr<Runnable> task = NewRunnableMethod<Endpoint<PVsyncBridgeParent>&&>(
18 : "gfx::VsyncBridgeParent::Open",
19 : parent,
20 : &VsyncBridgeParent::Open,
21 0 : Move(aEndpoint));
22 0 : CompositorThreadHolder::Loop()->PostTask(task.forget());
23 :
24 0 : return parent;
25 : }
26 :
27 0 : VsyncBridgeParent::VsyncBridgeParent()
28 0 : : mOpen(false)
29 : {
30 0 : MOZ_COUNT_CTOR(VsyncBridgeParent);
31 0 : mCompositorThreadRef = CompositorThreadHolder::GetSingleton();
32 0 : }
33 :
34 0 : VsyncBridgeParent::~VsyncBridgeParent()
35 : {
36 0 : MOZ_COUNT_DTOR(VsyncBridgeParent);
37 0 : }
38 :
39 : void
40 0 : VsyncBridgeParent::Open(Endpoint<PVsyncBridgeParent>&& aEndpoint)
41 : {
42 0 : if (!aEndpoint.Bind(this)) {
43 : // We can't recover from this.
44 0 : MOZ_CRASH("Failed to bind VsyncBridgeParent to endpoint");
45 : }
46 0 : AddRef();
47 0 : mOpen = true;
48 0 : }
49 :
50 : mozilla::ipc::IPCResult
51 0 : VsyncBridgeParent::RecvNotifyVsync(const TimeStamp& aTimeStamp, const uint64_t& aLayersId)
52 : {
53 0 : CompositorBridgeParent::NotifyVsync(aTimeStamp, aLayersId);
54 0 : return IPC_OK();
55 : }
56 :
57 : void
58 0 : VsyncBridgeParent::Shutdown()
59 : {
60 0 : MessageLoop* ccloop = CompositorThreadHolder::Loop();
61 0 : if (MessageLoop::current() != ccloop) {
62 0 : ccloop->PostTask(NewRunnableMethod("gfx::VsyncBridgeParent::ShutdownImpl",
63 : this,
64 0 : &VsyncBridgeParent::ShutdownImpl));
65 0 : return;
66 : }
67 :
68 0 : ShutdownImpl();
69 : }
70 :
71 : void
72 0 : VsyncBridgeParent::ShutdownImpl()
73 : {
74 0 : if (mOpen) {
75 0 : Close();
76 0 : mOpen = false;
77 : }
78 0 : }
79 :
80 : void
81 0 : VsyncBridgeParent::ActorDestroy(ActorDestroyReason aWhy)
82 : {
83 0 : mOpen = false;
84 0 : mCompositorThreadRef = nullptr;
85 0 : }
86 :
87 : void
88 0 : VsyncBridgeParent::DeallocPVsyncBridgeParent()
89 : {
90 0 : Release();
91 0 : }
92 :
93 : } // namespace gfx
94 : } // namespace mozilla
|