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:
@@ -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 ==
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user