-
-
Save mstange/0ad8deaeceb547b64eff9c289040c523 to your computer and use it in GitHub Desktop.
Pseudocode for ticking the refresh driver as quickly as possible when a key event comes in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool mPendingTick = false; | |
bool mAlreadyTickedThisVsyncInterval = false; | |
void ScheduleTick() { | |
if (mPendingTick) { | |
return; | |
} | |
mPendingTick = true; | |
EnsureListeningToVsync([](){ OnVSync(); }); | |
if (!mAlreadyTickedThisVsyncInterval) { | |
ScheduleImmediatelyWithVsyncPriority([](){ Tick(); }); | |
} | |
} | |
void OnVSync() { | |
// This notification indicates the start of a new “vsync interval”. | |
mAlreadyTickedThisVsyncInterval = false; | |
if (mPendingTick) { | |
Tick(); | |
} | |
} | |
void Tick() { | |
MOZ_RELEASE_ASSERT(mPendingTick); | |
MOZ_RELEASE_ASSERT(!mAlreadyTickedThisVsyncInterval); | |
mAlreadyTickedThisVsyncInterval = true; | |
mPendingTick = false; | |
DoTheWork(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment