2014-10-22 02:40:54 +04: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 "VsyncDispatcher.h"
|
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
2014-10-27 15:57:36 +03:00
|
|
|
#include "mozilla/layers/CompositorParent.h"
|
2014-10-24 05:50:31 +04:00
|
|
|
#include "gfxPrefs.h"
|
2014-12-18 19:30:06 +03:00
|
|
|
#include "gfxPlatform.h"
|
|
|
|
#include "VsyncSource.h"
|
2014-10-24 05:50:31 +04:00
|
|
|
|
2014-11-19 00:28:42 +03:00
|
|
|
#ifdef MOZ_ENABLE_PROFILER_SPS
|
|
|
|
#include "GeckoProfiler.h"
|
|
|
|
#include "ProfilerMarkers.h"
|
|
|
|
#endif
|
|
|
|
|
2014-10-24 05:50:31 +04:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
#include "GeckoTouchDispatcher.h"
|
|
|
|
#endif
|
2014-10-22 02:40:54 +04:00
|
|
|
|
|
|
|
using namespace mozilla::layers;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
VsyncDispatcher::VsyncDispatcher()
|
2014-10-24 05:50:31 +04:00
|
|
|
: mCompositorObserverLock("CompositorObserverLock")
|
2014-10-22 02:40:54 +04:00
|
|
|
{
|
2014-12-18 19:30:06 +03:00
|
|
|
MOZ_ASSERT(XRE_IsParentProcess());
|
|
|
|
gfxPlatform::GetPlatform()->GetHardwareVsync()->AddVsyncDispatcher(this);
|
2014-10-22 02:40:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
VsyncDispatcher::~VsyncDispatcher()
|
|
|
|
{
|
2014-12-18 19:30:06 +03:00
|
|
|
// We auto remove this vsync dispatcher from the vsync source in the nsBaseWidget
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2014-10-24 05:50:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-10-29 23:37:06 +03:00
|
|
|
VsyncDispatcher::NotifyVsync(TimeStamp aVsyncTimestamp)
|
2014-10-24 05:50:31 +04:00
|
|
|
{
|
2014-12-18 19:30:06 +03:00
|
|
|
// In hardware vsync thread
|
2014-11-19 00:28:42 +03:00
|
|
|
#ifdef MOZ_ENABLE_PROFILER_SPS
|
|
|
|
if (profiler_is_active()) {
|
|
|
|
CompositorParent::PostInsertVsyncProfilerMarker(aVsyncTimestamp);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-12-18 19:30:06 +03:00
|
|
|
MutexAutoLock lock(mCompositorObserverLock);
|
|
|
|
if (gfxPrefs::VsyncAlignedCompositor() && mCompositorVsyncObserver) {
|
|
|
|
mCompositorVsyncObserver->NotifyVsync(aVsyncTimestamp);
|
2014-10-24 05:50:31 +04:00
|
|
|
}
|
2014-10-22 02:40:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-12-18 19:30:06 +03:00
|
|
|
VsyncDispatcher::SetCompositorVsyncObserver(VsyncObserver* aVsyncObserver)
|
2014-10-22 02:40:54 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(CompositorParent::IsInCompositorThread());
|
2014-10-24 05:50:31 +04:00
|
|
|
MutexAutoLock lock(mCompositorObserverLock);
|
2014-12-18 19:30:06 +03:00
|
|
|
mCompositorVsyncObserver = aVsyncObserver;
|
2014-10-22 02:40:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-12-18 19:30:06 +03:00
|
|
|
VsyncDispatcher::Shutdown()
|
2014-10-22 02:40:54 +04:00
|
|
|
{
|
2014-12-18 19:30:06 +03:00
|
|
|
// Need to explicitly remove VsyncDispatcher when the nsBaseWidget shuts down.
|
|
|
|
// Otherwise, we would get dead vsync notifications between when the nsBaseWidget
|
|
|
|
// shuts down and the CompositorParent shuts down.
|
|
|
|
MOZ_ASSERT(XRE_IsParentProcess());
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
gfxPlatform::GetPlatform()->GetHardwareVsync()->RemoveVsyncDispatcher(this);
|
2014-10-22 02:40:54 +04:00
|
|
|
}
|
|
|
|
} // namespace mozilla
|