2014-12-18 08:30:06 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* 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 "VsyncSource.h"
|
2015-01-13 05:04:00 -08:00
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#include "nsXULAppAPI.h"
|
2014-12-18 08:30:06 -08:00
|
|
|
#include "mozilla/VsyncDispatcher.h"
|
2015-01-07 18:17:36 -08:00
|
|
|
#include "MainThreadUtils.h"
|
2014-12-18 08:30:06 -08:00
|
|
|
|
2015-01-13 05:04:00 -08:00
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
2014-12-18 08:30:06 -08:00
|
|
|
|
|
|
|
void
|
2014-12-19 12:52:42 -08:00
|
|
|
VsyncSource::AddCompositorVsyncDispatcher(CompositorVsyncDispatcher* aCompositorVsyncDispatcher)
|
2014-12-18 08:30:06 -08:00
|
|
|
{
|
2015-01-13 05:04:00 -08:00
|
|
|
MOZ_ASSERT(XRE_IsParentProcess());
|
2014-12-18 08:30:06 -08:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-01-13 05:04:00 -08:00
|
|
|
// Just use the global display until we have enough information to get the
|
|
|
|
// corresponding display for compositor.
|
2014-12-19 12:52:42 -08:00
|
|
|
GetGlobalDisplay().AddCompositorVsyncDispatcher(aCompositorVsyncDispatcher);
|
2014-12-18 08:30:06 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-12-19 12:52:42 -08:00
|
|
|
VsyncSource::RemoveCompositorVsyncDispatcher(CompositorVsyncDispatcher* aCompositorVsyncDispatcher)
|
2014-12-18 08:30:06 -08:00
|
|
|
{
|
2015-01-13 05:04:00 -08:00
|
|
|
MOZ_ASSERT(XRE_IsParentProcess());
|
2014-12-18 08:30:06 -08:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-01-13 05:04:00 -08:00
|
|
|
// See also AddCompositorVsyncDispatcher().
|
2014-12-19 12:52:42 -08:00
|
|
|
GetGlobalDisplay().RemoveCompositorVsyncDispatcher(aCompositorVsyncDispatcher);
|
2014-12-18 08:30:06 -08:00
|
|
|
}
|
|
|
|
|
2015-01-13 05:04:00 -08:00
|
|
|
nsRefPtr<RefreshTimerVsyncDispatcher>
|
|
|
|
VsyncSource::GetRefreshTimerVsyncDispatcher()
|
2014-12-18 08:30:06 -08:00
|
|
|
{
|
2015-01-13 05:04:00 -08:00
|
|
|
MOZ_ASSERT(XRE_IsParentProcess());
|
|
|
|
// See also AddCompositorVsyncDispatcher().
|
|
|
|
return GetGlobalDisplay().GetRefreshTimerVsyncDispatcher();
|
2014-12-18 08:30:06 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
VsyncSource::Display::Display()
|
2015-01-13 05:04:00 -08:00
|
|
|
: mDispatcherLock("display dispatcher lock")
|
2014-12-18 08:30:06 -08:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-01-13 05:04:00 -08:00
|
|
|
mRefreshTimerVsyncDispatcher = new RefreshTimerVsyncDispatcher();
|
2014-12-18 08:30:06 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
VsyncSource::Display::~Display()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-01-13 05:04:00 -08:00
|
|
|
MutexAutoLock lock(mDispatcherLock);
|
|
|
|
mRefreshTimerVsyncDispatcher = nullptr;
|
2014-12-19 12:52:42 -08:00
|
|
|
mCompositorVsyncDispatchers.Clear();
|
2014-12-18 08:30:06 -08:00
|
|
|
}
|
|
|
|
|
2015-01-13 05:04:00 -08:00
|
|
|
void
|
|
|
|
VsyncSource::Display::NotifyVsync(TimeStamp aVsyncTimestamp)
|
|
|
|
{
|
|
|
|
// Called on the vsync thread
|
|
|
|
MutexAutoLock lock(mDispatcherLock);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < mCompositorVsyncDispatchers.Length(); i++) {
|
|
|
|
mCompositorVsyncDispatchers[i]->NotifyVsync(aVsyncTimestamp);
|
|
|
|
}
|
|
|
|
|
|
|
|
mRefreshTimerVsyncDispatcher->NotifyVsync(aVsyncTimestamp);
|
|
|
|
}
|
|
|
|
|
2014-12-18 08:30:06 -08:00
|
|
|
void
|
2014-12-19 12:52:42 -08:00
|
|
|
VsyncSource::Display::AddCompositorVsyncDispatcher(CompositorVsyncDispatcher* aCompositorVsyncDispatcher)
|
2014-12-18 08:30:06 -08:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-01-13 05:04:00 -08:00
|
|
|
MOZ_ASSERT(aCompositorVsyncDispatcher);
|
|
|
|
MutexAutoLock lock(mDispatcherLock);
|
|
|
|
if (!mCompositorVsyncDispatchers.Contains(aCompositorVsyncDispatcher)) {
|
|
|
|
mCompositorVsyncDispatchers.AppendElement(aCompositorVsyncDispatcher);
|
|
|
|
}
|
2014-12-18 08:30:06 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-12-19 12:52:42 -08:00
|
|
|
VsyncSource::Display::RemoveCompositorVsyncDispatcher(CompositorVsyncDispatcher* aCompositorVsyncDispatcher)
|
2014-12-18 08:30:06 -08:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-01-13 05:04:00 -08:00
|
|
|
MOZ_ASSERT(aCompositorVsyncDispatcher);
|
|
|
|
MutexAutoLock lock(mDispatcherLock);
|
2014-12-19 12:52:42 -08:00
|
|
|
mCompositorVsyncDispatchers.RemoveElement(aCompositorVsyncDispatcher);
|
2014-12-18 08:30:06 -08:00
|
|
|
}
|
2015-01-13 05:04:00 -08:00
|
|
|
|
|
|
|
nsRefPtr<RefreshTimerVsyncDispatcher>
|
|
|
|
VsyncSource::Display::GetRefreshTimerVsyncDispatcher()
|
|
|
|
{
|
|
|
|
return mRefreshTimerVsyncDispatcher;
|
|
|
|
}
|
|
|
|
|
|
|
|
} //namespace gfx
|
|
|
|
} //namespace mozilla
|