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"
|
|
|
|
#include "gfxPlatform.h"
|
|
|
|
#include "mozilla/TimeStamp.h"
|
|
|
|
#include "mozilla/VsyncDispatcher.h"
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
|
|
|
void
|
2014-12-19 12:52:42 -08:00
|
|
|
VsyncSource::AddCompositorVsyncDispatcher(CompositorVsyncDispatcher* aCompositorVsyncDispatcher)
|
2014-12-18 08:30:06 -08:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
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
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2014-12-19 12:52:42 -08:00
|
|
|
GetGlobalDisplay().RemoveCompositorVsyncDispatcher(aCompositorVsyncDispatcher);
|
2014-12-18 08:30:06 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
VsyncSource::Display&
|
2014-12-19 12:52:42 -08:00
|
|
|
VsyncSource::FindDisplay(CompositorVsyncDispatcher* aCompositorVsyncDispatcher)
|
2014-12-18 08:30:06 -08:00
|
|
|
{
|
|
|
|
return GetGlobalDisplay();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VsyncSource::Display::NotifyVsync(TimeStamp aVsyncTimestamp)
|
|
|
|
{
|
|
|
|
// Called on the hardware vsync thread
|
2014-12-19 12:52:42 -08:00
|
|
|
for (size_t i = 0; i < mCompositorVsyncDispatchers.Length(); i++) {
|
|
|
|
mCompositorVsyncDispatchers[i]->NotifyVsync(aVsyncTimestamp);
|
2014-12-18 08:30:06 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VsyncSource::Display::Display()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
}
|
|
|
|
|
|
|
|
VsyncSource::Display::~Display()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2014-12-19 12:52:42 -08:00
|
|
|
mCompositorVsyncDispatchers.Clear();
|
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());
|
2014-12-19 12:52:42 -08:00
|
|
|
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());
|
2014-12-19 12:52:42 -08:00
|
|
|
mCompositorVsyncDispatchers.RemoveElement(aCompositorVsyncDispatcher);
|
2014-12-18 08:30:06 -08:00
|
|
|
}
|