зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1095242. Part 5: Unobserve vsync in RefreshTimerVsyncDispatcher. r=kats
This commit is contained in:
Родитель
ebe0a9bec5
Коммит
94e7103a97
|
@ -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;
|
||||
|
|
Загрузка…
Ссылка в новой задаче