Bug 1095242. Part 5: Unobserve vsync in RefreshTimerVsyncDispatcher. r=kats

This commit is contained in:
Mason Chang 2015-01-20 08:31:26 -08:00
Родитель ebe0a9bec5
Коммит 94e7103a97
2 изменённых файлов: 45 добавлений и 8 удалений

Просмотреть файл

@ -123,26 +123,61 @@ RefreshTimerVsyncDispatcher::NotifyVsync(TimeStamp aVsyncTimestamp)
void
RefreshTimerVsyncDispatcher::SetParentRefreshTimer(VsyncObserver* aVsyncObserver)
{
MOZ_ASSERT(NS_IsMainThread());
{ // lock scope because UpdateVsyncStatus runs on main thread and will deadlock
MutexAutoLock lock(mRefreshTimersLock);
mParentRefreshTimer = aVsyncObserver;
}
UpdateVsyncStatus();
}
void
RefreshTimerVsyncDispatcher::AddChildRefreshTimer(VsyncObserver* aVsyncObserver)
{
{ // scope lock - called on pbackground thread
MutexAutoLock lock(mRefreshTimersLock);
MOZ_ASSERT(aVsyncObserver);
if (!mChildRefreshTimers.Contains(aVsyncObserver)) {
mChildRefreshTimers.AppendElement(aVsyncObserver);
}
}
UpdateVsyncStatus();
}
void
RefreshTimerVsyncDispatcher::RemoveChildRefreshTimer(VsyncObserver* aVsyncObserver)
{
{ // scope lock - called on pbackground thread
MutexAutoLock lock(mRefreshTimersLock);
MOZ_ASSERT(aVsyncObserver);
mChildRefreshTimers.RemoveElement(aVsyncObserver);
}
UpdateVsyncStatus();
}
void
RefreshTimerVsyncDispatcher::UpdateVsyncStatus()
{
if (!NS_IsMainThread()) {
nsCOMPtr<nsIRunnable> vsyncControl = NS_NewRunnableMethod(this,
&RefreshTimerVsyncDispatcher::UpdateVsyncStatus);
NS_DispatchToMainThread(vsyncControl);
return;
}
gfx::VsyncSource::Display& display = gfxPlatform::GetPlatform()->GetHardwareVsync()->GetGlobalDisplay();
display.NotifyRefreshTimerVsyncStatus(NeedsVsync());
}
bool
RefreshTimerVsyncDispatcher::NeedsVsync()
{
MOZ_ASSERT(NS_IsMainThread());
MutexAutoLock lock(mRefreshTimersLock);
return (mParentRefreshTimer != nullptr) || !mChildRefreshTimers.IsEmpty();
}
} // namespace mozilla

Просмотреть файл

@ -79,6 +79,8 @@ public:
private:
virtual ~RefreshTimerVsyncDispatcher();
void UpdateVsyncStatus();
bool NeedsVsync();
Mutex mRefreshTimersLock;
nsRefPtr<VsyncObserver> mParentRefreshTimer;