Bug 1867190 - Initialise the PHC allocate delay later r=glandium
[gecko.git] / dom / ipc / VsyncMainChild.cpp
bloba1ea332e75870035881bac9ed0b6e4d5b6b98f07
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/. */
7 #include "VsyncMainChild.h"
9 #include "mozilla/SchedulerGroup.h"
10 #include "mozilla/VsyncDispatcher.h"
11 #include "nsThreadUtils.h"
13 namespace mozilla::dom {
15 VsyncMainChild::VsyncMainChild()
16 : mIsShutdown(false), mVsyncRate(TimeDuration::Forever()) {
17 MOZ_ASSERT(NS_IsMainThread());
20 VsyncMainChild::~VsyncMainChild() { MOZ_ASSERT(NS_IsMainThread()); }
22 void VsyncMainChild::AddChildRefreshTimer(VsyncObserver* aVsyncObserver) {
23 MOZ_ASSERT(NS_IsMainThread());
24 MOZ_ASSERT(!mObservers.Contains(aVsyncObserver));
26 if (mIsShutdown) {
27 return;
30 if (mObservers.IsEmpty()) {
31 Unused << PVsyncChild::SendObserve();
33 mObservers.AppendElement(std::move(aVsyncObserver));
36 void VsyncMainChild::RemoveChildRefreshTimer(VsyncObserver* aVsyncObserver) {
37 MOZ_ASSERT(NS_IsMainThread());
38 if (mIsShutdown) {
39 return;
42 if (mObservers.RemoveElement(aVsyncObserver) && mObservers.IsEmpty()) {
43 Unused << PVsyncChild::SendUnobserve();
47 void VsyncMainChild::ActorDestroy(ActorDestroyReason aActorDestroyReason) {
48 MOZ_ASSERT(NS_IsMainThread());
49 MOZ_ASSERT(!mIsShutdown);
50 mIsShutdown = true;
52 if (!mObservers.IsEmpty()) {
53 Unused << PVsyncChild::SendUnobserve();
55 mObservers.Clear();
58 mozilla::ipc::IPCResult VsyncMainChild::RecvNotify(const VsyncEvent& aVsync,
59 const float& aVsyncRate) {
60 MOZ_ASSERT(NS_IsMainThread());
61 MOZ_ASSERT(!mIsShutdown);
63 mVsyncRate = TimeDuration::FromMilliseconds(aVsyncRate);
65 for (RefPtr<VsyncObserver> observer : mObservers.ForwardRange()) {
66 observer->NotifyVsync(aVsync);
68 return IPC_OK();
71 TimeDuration VsyncMainChild::GetVsyncRate() { return mVsyncRate; }
73 } // namespace mozilla::dom