From 388251b1e24a19518dceee73c64f2aca93285ad6 Mon Sep 17 00:00:00 2001 From: hogliux Date: Mon, 21 Nov 2016 09:26:52 +0000 Subject: [PATCH] Made message queue throttling more precise by using Time::getMillisecondCounter --- .../native/juce_mac_NSViewComponentPeer.mm | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm b/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm index 8281315aac..c362b4546a 100644 --- a/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm +++ b/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm @@ -83,7 +83,7 @@ public: textWasInserted (false), isStretchingTop (false), isStretchingLeft (false), isStretchingBottom (false), isStretchingRight (false), - notificationCenter (nil) + notificationCenter (nil), lastRepaintTime (Time::getMillisecondCounter()) { appFocusChangeCallback = appFocusChanged; isEventBlockedByModalComps = checkEventBlockedByModalComps; @@ -908,8 +908,12 @@ public: // already a timer running -> stop if (isTimerRunning()) return; - int64 msSinceLastRepaint = Time::getCurrentTime().toMilliseconds() - lastRepaintTime.toMilliseconds(); - static int minimumRepaintInterval = 1000 / 30; // 30fps + const uint32 now = Time::getMillisecondCounter(); + uint32 msSinceLastRepaint = + (lastRepaintTime >= now ? now - lastRepaintTime + : (std::numeric_limits::max() - lastRepaintTime) + now); + + static uint32 minimumRepaintInterval = 1000 / 30; // 30fps // When windows are being resized, artificially throttling high-frequency repaints helps // to stop the event queue getting clogged, and keeps everything working smoothly. @@ -917,7 +921,7 @@ public: if (shouldThrottle && msSinceLastRepaint < minimumRepaintInterval) { - startTimer (static_cast (static_cast (minimumRepaintInterval) - msSinceLastRepaint)); + startTimer (static_cast (minimumRepaintInterval - msSinceLastRepaint)); return; } @@ -935,7 +939,7 @@ public: for (const Rectangle* i = deferredRepaints.begin(), *e = deferredRepaints.end(); i != e; ++i) [view setNeedsDisplayInRect: makeNSRect (*i)]; - lastRepaintTime = Time::getCurrentTime(); + lastRepaintTime = Time::getMillisecondCounter(); deferredRepaints.clear(); }; @@ -1364,7 +1368,7 @@ public: NSNotificationCenter* notificationCenter; RectangleList deferredRepaints; - Time lastRepaintTime; + uint32 lastRepaintTime; static ModifierKeys currentModifiers; static ComponentPeer* currentlyFocusedPeer;