2015-01-13 15:37:00 -08: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-29 13:19:00 -08:00
|
|
|
, mIsShutdown(false)
|
2015-01-13 15:37:00 -08:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
}
|
|
|
|
|
|
|
|
VsyncChild::~VsyncChild()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
VsyncChild::SendObserve()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-01-29 13:19:00 -08:00
|
|
|
if (!mObservingVsync && !mIsShutdown) {
|
2015-01-13 15:37:00 -08:00
|
|
|
mObservingVsync = true;
|
2015-01-29 13:19:00 -08:00
|
|
|
PVsyncChild::SendObserve();
|
2015-01-13 15:37:00 -08:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
VsyncChild::SendUnobserve()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-01-29 13:19:00 -08:00
|
|
|
if (mObservingVsync && !mIsShutdown) {
|
2015-01-13 15:37:00 -08:00
|
|
|
mObservingVsync = false;
|
2015-01-29 13:19:00 -08:00
|
|
|
PVsyncChild::SendUnobserve();
|
2015-01-13 15:37:00 -08:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VsyncChild::ActorDestroy(ActorDestroyReason aActorDestroyReason)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-01-29 13:19:00 -08:00
|
|
|
MOZ_ASSERT(!mIsShutdown);
|
|
|
|
mIsShutdown = true;
|
2015-01-13 15:37:00 -08:00
|
|
|
mObserver = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
VsyncChild::RecvNotify(const TimeStamp& aVsyncTimestamp)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-01-29 13:19:00 -08:00
|
|
|
MOZ_ASSERT(!mIsShutdown);
|
2015-01-13 15:37:00 -08:00
|
|
|
if (mObservingVsync && mObserver) {
|
|
|
|
mObserver->NotifyVsync(aVsyncTimestamp);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VsyncChild::SetVsyncObserver(VsyncObserver* aVsyncObserver)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
mObserver = aVsyncObserver;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace layout
|
|
|
|
} // namespace mozilla
|