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/VsyncDispatcher.h" 9 #include "nsThreadUtils.h" 10 11 namespace mozilla { 12 namespace layout { 13 VsyncChild()14VsyncChild::VsyncChild() 15 : mObservingVsync(false) 16 , mIsShutdown(false) 17 , mVsyncRate(TimeDuration::Forever()) 18 { 19 MOZ_ASSERT(NS_IsMainThread()); 20 } 21 ~VsyncChild()22VsyncChild::~VsyncChild() 23 { 24 MOZ_ASSERT(NS_IsMainThread()); 25 } 26 27 bool SendObserve()28VsyncChild::SendObserve() 29 { 30 MOZ_ASSERT(NS_IsMainThread()); 31 if (!mObservingVsync && !mIsShutdown) { 32 mObservingVsync = true; 33 PVsyncChild::SendObserve(); 34 } 35 return true; 36 } 37 38 bool SendUnobserve()39VsyncChild::SendUnobserve() 40 { 41 MOZ_ASSERT(NS_IsMainThread()); 42 if (mObservingVsync && !mIsShutdown) { 43 mObservingVsync = false; 44 PVsyncChild::SendUnobserve(); 45 } 46 return true; 47 } 48 49 void ActorDestroy(ActorDestroyReason aActorDestroyReason)50VsyncChild::ActorDestroy(ActorDestroyReason aActorDestroyReason) 51 { 52 MOZ_ASSERT(NS_IsMainThread()); 53 MOZ_ASSERT(!mIsShutdown); 54 mIsShutdown = true; 55 mObserver = nullptr; 56 } 57 58 bool RecvNotify(const TimeStamp & aVsyncTimestamp)59VsyncChild::RecvNotify(const TimeStamp& aVsyncTimestamp) 60 { 61 MOZ_ASSERT(NS_IsMainThread()); 62 MOZ_ASSERT(!mIsShutdown); 63 if (mObservingVsync && mObserver) { 64 mObserver->NotifyVsync(aVsyncTimestamp); 65 } 66 return true; 67 } 68 69 void SetVsyncObserver(VsyncObserver * aVsyncObserver)70VsyncChild::SetVsyncObserver(VsyncObserver* aVsyncObserver) 71 { 72 MOZ_ASSERT(NS_IsMainThread()); 73 mObserver = aVsyncObserver; 74 } 75 76 TimeDuration GetVsyncRate()77VsyncChild::GetVsyncRate() 78 { 79 if (mVsyncRate == TimeDuration::Forever()) { 80 PVsyncChild::SendRequestVsyncRate(); 81 } 82 83 return mVsyncRate; 84 } 85 86 bool RecvVsyncRate(const float & aVsyncRate)87VsyncChild::RecvVsyncRate(const float& aVsyncRate) 88 { 89 mVsyncRate = TimeDuration::FromMilliseconds(aVsyncRate); 90 return true; 91 } 92 93 } // namespace layout 94 } // namespace mozilla 95