1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-21 01:24:21 +00:00

Windows: Throttle VBlankThread when the display is off

When the display goes to sleep IDXGIOutput::WaitForVBlank returns S_OK
immediately causing the VBlankThread to consume a core entirely with the
VBlank related messaging.

To limit this problem, we use the same technique as Chromium presently
does, and we sleep for 1 ms, if the time between the last two VBlank
events was less than a ms. This limits the VBlankThread messaging rate
of about 50.000/s on an Intel 13600 to 1000/s.
This commit is contained in:
attila 2024-07-22 17:18:30 +02:00
parent 4c5c336e65
commit fb670d209b

View file

@ -121,6 +121,12 @@ private:
{
if (output->WaitForVBlank() == S_OK)
{
if (const auto now = Time::getMillisecondCounterHiRes();
now - std::exchange (lastVBlankEvent, now) < 1.0)
{
Thread::sleep (1);
}
std::unique_lock lock { mutex };
condvar.wait (lock, [this] { return threadState != ThreadState::sleep; });
@ -164,6 +170,7 @@ private:
exit,
};
double lastVBlankEvent = 0.0;
ThreadState threadState = ThreadState::paint;
std::condition_variable condvar;
std::mutex mutex;