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 d79aee3f78)
This commit is contained in:
Jon Evans 2020-12-18 13:52:57 -05:00
parent a7efb179eb
commit 93173fca93
1 changed files with 5 additions and 14 deletions

View File

@ -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
}