2015-01-14 02:37:00 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* 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"
|
|
|
|
|
|
|
|
#include "mozilla/VsyncDispatcher.h"
|
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layout {
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
VsyncChild::RecvNotify(const TimeStamp& aVsyncTimestamp)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-01-30 00:19:00 +03:00
|
|
|
MOZ_ASSERT(!mIsShutdown);
|
2015-01-14 02:37:00 +03:00
|
|
|
if (mObservingVsync && mObserver) {
|
|
|
|
mObserver->NotifyVsync(aVsyncTimestamp);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
VsyncChild::RecvVsyncRate(const float& aVsyncRate)
|
|
|
|
{
|
|
|
|
mVsyncRate = TimeDuration::FromMilliseconds(aVsyncRate);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-14 02:37:00 +03:00
|
|
|
} // namespace layout
|
|
|
|
} // namespace mozilla
|