From 93173fca9379e4be32096278e78b5a6b234d5d66 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Fri, 18 Dec 2020 13:52:57 -0500 Subject: [PATCH] Fix refresh logic on MacOS to prevent excessive redraws This new logic does not need to be MacOS-specific; it should account for timer inconsistencies on any platform. Thanks to Mark for the suggestions. Fixes https://gitlab.com/kicad/code/kicad/-/issues/6222 Fixes https://gitlab.com/kicad/code/kicad/-/issues/6332 (cherry picked from commit d79aee3f78e6819a7c5bc73547984959f8a5efff) --- common/draw_panel_gal.cpp | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/common/draw_panel_gal.cpp b/common/draw_panel_gal.cpp index b082095a3e..e0fe05c408 100644 --- a/common/draw_panel_gal.cpp +++ b/common/draw_panel_gal.cpp @@ -287,30 +287,21 @@ void EDA_DRAW_PANEL_GAL::onSize( wxSizeEvent& aEvent ) void EDA_DRAW_PANEL_GAL::Refresh( bool aEraseBackground, const wxRect* aRect ) { - if( m_pendingRefresh ) - return; - - m_pendingRefresh = true; - -#ifdef __WXMAC__ - // Timers on OS X may have a high latency (seen up to 500ms and more) which - // makes repaints jerky. No negative impact seen without throttling, so just - // do an unconditional refresh for OS X. - ForceRefresh(); -#else wxLongLong t = wxGetLocalTimeMillis(); wxLongLong delta = t - m_lastRefresh; + // If it has been too long since the last frame (possible depending on platform timer latency), + // just do a refresh. Otherwise, start the refresh timer if it hasn't already been started. + // This ensures that we will render often enough but not too often. if( delta >= MinRefreshPeriod ) { ForceRefresh(); + m_refreshTimer.Start( MinRefreshPeriod, true ); } - else + else if( !m_refreshTimer.IsRunning() ) { - // One shot timer m_refreshTimer.Start( ( MinRefreshPeriod - delta ).ToLong(), true ); } -#endif }