Bug 1772463 - Move mVsyncSkipCounter into mState. r=bas

VsyncDispatcher::NotifyVsync can be called from two different threads
at the same time, if it just swapped out its vsync source and the old
vsync source is still notifying it. So we need to protect mVsyncSkipCounter
behind a lock.

Differential Revision: https://phabricator.services.mozilla.com/D148958
This commit is contained in:
Markus Stange
2022-07-19 18:51:46 +00:00
parent ffc15fb0a9
commit 3312a835ba
2 changed files with 14 additions and 7 deletions

View File

@@ -126,17 +126,20 @@ TimeDuration VsyncDispatcher::GetVsyncRate() {
}
void VsyncDispatcher::NotifyVsync(const VsyncEvent& aVsync) {
if (++mVsyncSkipCounter < StaticPrefs::gfx_display_frame_rate_divisor()) {
return;
}
mVsyncSkipCounter = 0;
nsTArray<RefPtr<VsyncObserver>> observers;
bool shouldDispatchToMainThread = false;
{
auto state = mState.Lock();
// Respect the pref gfx.display.frame-rate-divisor.
if (++state->mVsyncSkipCounter <
StaticPrefs::gfx_display_frame_rate_divisor()) {
return;
}
state->mVsyncSkipCounter = 0;
// Copy out the observers so that we don't keep the mutex
// locked while notifying vsync.
auto state = mState.Lock();
observers = state->mObservers.Clone();
shouldDispatchToMainThread = !state->mMainThreadObservers.IsEmpty() &&
(state->mLastVsyncIdSentToMainThread ==

View File

@@ -141,11 +141,15 @@ class VsyncDispatcher final {
// Always non-null.
RefPtr<gfx::VsyncSource> mCurrentVsyncSource;
// The number of skipped vsyncs since the last non-skipped vsync.
// Reset to zero every n vsyncs, where n is given by the pref
// gfx.display.frame-rate-divisor.
int32_t mVsyncSkipCounter = 0;
bool mIsObservingVsync = false;
};
DataMutex<State> mState;
int32_t mVsyncSkipCounter = 0;
};
} // namespace mozilla