2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2015-01-14 02:37:00 +03:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "VsyncChild.h"
|
|
|
|
|
2017-05-02 15:10:00 +03:00
|
|
|
#include "mozilla/SchedulerGroup.h"
|
2015-01-14 02:37:00 +03:00
|
|
|
#include "mozilla/VsyncDispatcher.h"
|
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
|
2020-01-18 16:48:34 +03:00
|
|
|
namespace mozilla::layout {
|
2015-01-14 02:37:00 +03:00
|
|
|
|
|
|
|
VsyncChild::VsyncChild()
|
|
|
|
: mObservingVsync(false),
|
2015-01-30 00:19:00 +03:00
|
|
|
mIsShutdown(false),
|
2015-11-06 19:20:58 +03:00
|
|
|
mVsyncRate(TimeDuration::Forever()) {
|
2015-01-14 02:37:00 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
}
|
|
|
|
|
|
|
|
VsyncChild::~VsyncChild() { MOZ_ASSERT(NS_IsMainThread()); }
|
|
|
|
|
|
|
|
bool VsyncChild::SendObserve() {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-01-30 00:19:00 +03:00
|
|
|
if (!mObservingVsync && !mIsShutdown) {
|
2015-01-14 02:37:00 +03:00
|
|
|
mObservingVsync = true;
|
2015-01-30 00:19:00 +03:00
|
|
|
PVsyncChild::SendObserve();
|
2015-01-14 02:37:00 +03:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VsyncChild::SendUnobserve() {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-01-30 00:19:00 +03:00
|
|
|
if (mObservingVsync && !mIsShutdown) {
|
2015-01-14 02:37:00 +03:00
|
|
|
mObservingVsync = false;
|
2015-01-30 00:19:00 +03:00
|
|
|
PVsyncChild::SendUnobserve();
|
2015-01-14 02:37:00 +03:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VsyncChild::ActorDestroy(ActorDestroyReason aActorDestroyReason) {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-01-30 00:19:00 +03:00
|
|
|
MOZ_ASSERT(!mIsShutdown);
|
|
|
|
mIsShutdown = true;
|
2015-01-14 02:37:00 +03:00
|
|
|
mObserver = nullptr;
|
|
|
|
}
|
|
|
|
|
2018-12-08 02:27:28 +03:00
|
|
|
mozilla::ipc::IPCResult VsyncChild::RecvNotify(const VsyncEvent& aVsync) {
|
2015-01-14 02:37:00 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-01-30 00:19:00 +03:00
|
|
|
MOZ_ASSERT(!mIsShutdown);
|
2017-05-02 15:10:00 +03:00
|
|
|
|
|
|
|
SchedulerGroup::MarkVsyncRan();
|
2015-01-14 02:37:00 +03:00
|
|
|
if (mObservingVsync && mObserver) {
|
2018-12-08 02:27:28 +03:00
|
|
|
mObserver->NotifyVsync(aVsync);
|
2015-01-14 02:37:00 +03:00
|
|
|
}
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2015-01-14 02:37:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void VsyncChild::SetVsyncObserver(VsyncObserver* aVsyncObserver) {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
mObserver = aVsyncObserver;
|
|
|
|
}
|
|
|
|
|
2015-11-06 19:20:58 +03:00
|
|
|
TimeDuration VsyncChild::GetVsyncRate() {
|
|
|
|
if (mVsyncRate == TimeDuration::Forever()) {
|
|
|
|
PVsyncChild::SendRequestVsyncRate();
|
|
|
|
}
|
|
|
|
|
|
|
|
return mVsyncRate;
|
|
|
|
}
|
|
|
|
|
2016-11-10 12:01:51 +03:00
|
|
|
TimeDuration VsyncChild::VsyncRate() { return mVsyncRate; }
|
|
|
|
|
2015-11-06 19:20:58 +03:00
|
|
|
mozilla::ipc::IPCResult VsyncChild::RecvVsyncRate(const float& aVsyncRate) {
|
|
|
|
mVsyncRate = TimeDuration::FromMilliseconds(aVsyncRate);
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2015-11-06 19:20:58 +03:00
|
|
|
}
|
|
|
|
|
2020-01-18 16:48:34 +03:00
|
|
|
} // namespace mozilla::layout
|