/src/mozilla-central/layout/ipc/VsyncChild.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | |
7 | | #include "VsyncChild.h" |
8 | | |
9 | | #include "mozilla/SchedulerGroup.h" |
10 | | #include "mozilla/VsyncDispatcher.h" |
11 | | #include "nsThreadUtils.h" |
12 | | |
13 | | namespace mozilla { |
14 | | namespace layout { |
15 | | |
16 | | VsyncChild::VsyncChild() |
17 | | : mObservingVsync(false) |
18 | | , mIsShutdown(false) |
19 | | , mVsyncRate(TimeDuration::Forever()) |
20 | 0 | { |
21 | 0 | MOZ_ASSERT(NS_IsMainThread()); |
22 | 0 | } |
23 | | |
24 | | VsyncChild::~VsyncChild() |
25 | 0 | { |
26 | 0 | MOZ_ASSERT(NS_IsMainThread()); |
27 | 0 | } |
28 | | |
29 | | bool |
30 | | VsyncChild::SendObserve() |
31 | 0 | { |
32 | 0 | MOZ_ASSERT(NS_IsMainThread()); |
33 | 0 | if (!mObservingVsync && !mIsShutdown) { |
34 | 0 | mObservingVsync = true; |
35 | 0 | PVsyncChild::SendObserve(); |
36 | 0 | } |
37 | 0 | return true; |
38 | 0 | } |
39 | | |
40 | | bool |
41 | | VsyncChild::SendUnobserve() |
42 | 0 | { |
43 | 0 | MOZ_ASSERT(NS_IsMainThread()); |
44 | 0 | if (mObservingVsync && !mIsShutdown) { |
45 | 0 | mObservingVsync = false; |
46 | 0 | PVsyncChild::SendUnobserve(); |
47 | 0 | } |
48 | 0 | return true; |
49 | 0 | } |
50 | | |
51 | | void |
52 | | VsyncChild::ActorDestroy(ActorDestroyReason aActorDestroyReason) |
53 | 0 | { |
54 | 0 | MOZ_ASSERT(NS_IsMainThread()); |
55 | 0 | MOZ_ASSERT(!mIsShutdown); |
56 | 0 | mIsShutdown = true; |
57 | 0 | mObserver = nullptr; |
58 | 0 |
|
59 | 0 | if (recordreplay::IsRecordingOrReplaying()) { |
60 | 0 | recordreplay::child::SetVsyncObserver(nullptr); |
61 | 0 | } |
62 | 0 | } |
63 | | |
64 | | mozilla::ipc::IPCResult |
65 | | VsyncChild::RecvNotify(const TimeStamp& aVsyncTimestamp) |
66 | 0 | { |
67 | 0 | MOZ_ASSERT(NS_IsMainThread()); |
68 | 0 | MOZ_ASSERT(!mIsShutdown); |
69 | 0 |
|
70 | 0 | // Ignore Vsync messages sent to a recording/replaying process. Vsyncs are |
71 | 0 | // triggered at the top of the main thread's event loop instead. |
72 | 0 | if (recordreplay::IsRecordingOrReplaying()) { |
73 | 0 | return IPC_OK(); |
74 | 0 | } |
75 | 0 |
|
76 | 0 | SchedulerGroup::MarkVsyncRan(); |
77 | 0 | if (mObservingVsync && mObserver) { |
78 | 0 | mObserver->NotifyVsync(aVsyncTimestamp); |
79 | 0 | } |
80 | 0 | return IPC_OK(); |
81 | 0 | } |
82 | | |
83 | | void |
84 | | VsyncChild::SetVsyncObserver(VsyncObserver* aVsyncObserver) |
85 | 0 | { |
86 | 0 | MOZ_ASSERT(NS_IsMainThread()); |
87 | 0 | mObserver = aVsyncObserver; |
88 | 0 |
|
89 | 0 | if (recordreplay::IsRecordingOrReplaying()) { |
90 | 0 | recordreplay::child::SetVsyncObserver(mObserver); |
91 | 0 | } |
92 | 0 | } |
93 | | |
94 | | TimeDuration |
95 | | VsyncChild::GetVsyncRate() |
96 | 0 | { |
97 | 0 | if (mVsyncRate == TimeDuration::Forever()) { |
98 | 0 | PVsyncChild::SendRequestVsyncRate(); |
99 | 0 | } |
100 | 0 |
|
101 | 0 | return mVsyncRate; |
102 | 0 | } |
103 | | |
104 | | TimeDuration |
105 | | VsyncChild::VsyncRate() |
106 | 0 | { |
107 | 0 | return mVsyncRate; |
108 | 0 | } |
109 | | |
110 | | mozilla::ipc::IPCResult |
111 | | VsyncChild::RecvVsyncRate(const float& aVsyncRate) |
112 | 0 | { |
113 | 0 | mVsyncRate = TimeDuration::FromMilliseconds(aVsyncRate); |
114 | 0 | return IPC_OK(); |
115 | 0 | } |
116 | | |
117 | | } // namespace layout |
118 | | } // namespace mozilla |