Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : #include "VsyncChild.h"
7 :
8 : #include "mozilla/SchedulerGroup.h"
9 : #include "mozilla/VsyncDispatcher.h"
10 : #include "nsThreadUtils.h"
11 :
12 : namespace mozilla {
13 : namespace layout {
14 :
15 1 : VsyncChild::VsyncChild()
16 : : mObservingVsync(false)
17 : , mIsShutdown(false)
18 1 : , mVsyncRate(TimeDuration::Forever())
19 : {
20 1 : MOZ_ASSERT(NS_IsMainThread());
21 1 : }
22 :
23 0 : VsyncChild::~VsyncChild()
24 : {
25 0 : MOZ_ASSERT(NS_IsMainThread());
26 0 : }
27 :
28 : bool
29 2 : VsyncChild::SendObserve()
30 : {
31 2 : MOZ_ASSERT(NS_IsMainThread());
32 2 : if (!mObservingVsync && !mIsShutdown) {
33 2 : mObservingVsync = true;
34 2 : PVsyncChild::SendObserve();
35 : }
36 2 : return true;
37 : }
38 :
39 : bool
40 2 : VsyncChild::SendUnobserve()
41 : {
42 2 : MOZ_ASSERT(NS_IsMainThread());
43 2 : if (mObservingVsync && !mIsShutdown) {
44 2 : mObservingVsync = false;
45 2 : PVsyncChild::SendUnobserve();
46 : }
47 2 : return true;
48 : }
49 :
50 : void
51 0 : VsyncChild::ActorDestroy(ActorDestroyReason aActorDestroyReason)
52 : {
53 0 : MOZ_ASSERT(NS_IsMainThread());
54 0 : MOZ_ASSERT(!mIsShutdown);
55 0 : mIsShutdown = true;
56 0 : mObserver = nullptr;
57 0 : }
58 :
59 : mozilla::ipc::IPCResult
60 4 : VsyncChild::RecvNotify(const TimeStamp& aVsyncTimestamp)
61 : {
62 4 : MOZ_ASSERT(NS_IsMainThread());
63 4 : MOZ_ASSERT(!mIsShutdown);
64 :
65 4 : SchedulerGroup::MarkVsyncRan();
66 4 : if (mObservingVsync && mObserver) {
67 4 : mObserver->NotifyVsync(aVsyncTimestamp);
68 : }
69 4 : return IPC_OK();
70 : }
71 :
72 : void
73 1 : VsyncChild::SetVsyncObserver(VsyncObserver* aVsyncObserver)
74 : {
75 1 : MOZ_ASSERT(NS_IsMainThread());
76 1 : mObserver = aVsyncObserver;
77 1 : }
78 :
79 : TimeDuration
80 2 : VsyncChild::GetVsyncRate()
81 : {
82 2 : if (mVsyncRate == TimeDuration::Forever()) {
83 1 : PVsyncChild::SendRequestVsyncRate();
84 : }
85 :
86 2 : return mVsyncRate;
87 : }
88 :
89 : TimeDuration
90 1 : VsyncChild::VsyncRate()
91 : {
92 1 : return mVsyncRate;
93 : }
94 :
95 : mozilla::ipc::IPCResult
96 1 : VsyncChild::RecvVsyncRate(const float& aVsyncRate)
97 : {
98 1 : mVsyncRate = TimeDuration::FromMilliseconds(aVsyncRate);
99 1 : return IPC_OK();
100 : }
101 :
102 : } // namespace layout
103 : } // namespace mozilla
|