Improve canvas responsiveness by better swap interval management.
This commit is contained in:
parent
d98e08d90b
commit
dcb131c20d
|
@ -150,6 +150,8 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin
|
|||
m_drawing = false;
|
||||
m_drawingEnabled = false;
|
||||
|
||||
m_minRefreshPeriod = 13; // 77 FPS (minus render time) by default
|
||||
|
||||
// Set up timer that prevents too frequent redraw commands
|
||||
m_refreshTimer.SetOwner( this );
|
||||
Connect( m_refreshTimer.GetId(), wxEVT_TIMER,
|
||||
|
@ -379,16 +381,16 @@ void EDA_DRAW_PANEL_GAL::Refresh( bool aEraseBackground, const wxRect* aRect )
|
|||
// 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 )
|
||||
if( delta >= m_minRefreshPeriod )
|
||||
{
|
||||
if( !m_pendingRefresh )
|
||||
ForceRefresh();
|
||||
|
||||
m_refreshTimer.Start( MinRefreshPeriod, true );
|
||||
m_refreshTimer.Start( m_minRefreshPeriod, true );
|
||||
}
|
||||
else if( !m_refreshTimer.IsRunning() )
|
||||
{
|
||||
m_refreshTimer.Start( ( MinRefreshPeriod - delta ).ToLong(), true );
|
||||
m_refreshTimer.Start( ( m_minRefreshPeriod - delta ).ToLong(), true );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -530,6 +532,12 @@ bool EDA_DRAW_PANEL_GAL::SwitchBackend( GAL_TYPE aGalType )
|
|||
|
||||
m_gal->SetGridVisibility( grid_visibility );
|
||||
|
||||
if( m_gal->GetSwapInterval() != 0 )
|
||||
{
|
||||
// In theory this could be 0 but then more CPU cycles will be wasted in SwapBuffers
|
||||
m_minRefreshPeriod = 5;
|
||||
}
|
||||
|
||||
// Make sure the cursor is set on the new canvas
|
||||
SetCurrentCursor( KICURSOR::ARROW );
|
||||
|
||||
|
|
|
@ -2565,7 +2565,7 @@ void OPENGL_GAL::init()
|
|||
throw std::runtime_error( "Requested texture size is not supported" );
|
||||
}
|
||||
|
||||
GL_UTILS::SetSwapInterval( -1 );
|
||||
m_swapInterval = GL_UTILS::SetSwapInterval( -1 );
|
||||
|
||||
m_cachedManager = new VERTEX_MANAGER( true );
|
||||
m_nonCachedManager = new VERTEX_MANAGER( false );
|
||||
|
|
|
@ -255,11 +255,10 @@ protected:
|
|||
void onRefreshTimer( wxTimerEvent& aEvent );
|
||||
void onShowTimer( wxTimerEvent& aEvent );
|
||||
|
||||
static const int MinRefreshPeriod = 17; ///< 60 FPS.
|
||||
|
||||
wxWindow* m_parent; ///< Pointer to the parent window
|
||||
EDA_DRAW_FRAME* m_edaFrame; ///< Parent EDA_DRAW_FRAME (if available)
|
||||
|
||||
int m_minRefreshPeriod; ///< A minimum delay before another draw can start
|
||||
wxLongLong m_lastRefresh; ///< Last timestamp when the panel was refreshed
|
||||
bool m_pendingRefresh; ///< Is there a redraw event requested?
|
||||
wxTimer m_refreshTimer; ///< Timer to prevent too-frequent refreshing
|
||||
|
|
|
@ -249,6 +249,9 @@ public:
|
|||
return m_screenSize;
|
||||
}
|
||||
|
||||
/// Return the swap interval. -1 for adaptive, 0 for disabled/unknown
|
||||
virtual int GetSwapInterval() const { return 0; };
|
||||
|
||||
/// Force all remaining objects to be drawn.
|
||||
virtual void Flush() {};
|
||||
|
||||
|
|
|
@ -186,6 +186,9 @@ public:
|
|||
/// @brief Shows/hides the GAL canvas
|
||||
bool Show( bool aShow ) override;
|
||||
|
||||
/// @copydoc GAL::GetSwapInterval()
|
||||
int GetSwapInterval() const override { return m_swapInterval; };
|
||||
|
||||
/// @copydoc GAL::Flush()
|
||||
void Flush() override;
|
||||
|
||||
|
@ -327,6 +330,7 @@ private:
|
|||
|
||||
static wxGLContext* m_glMainContext; ///< Parent OpenGL context
|
||||
wxGLContext* m_glPrivContext; ///< Canvas-specific OpenGL context
|
||||
int m_swapInterval; ///< Used to store swap interval information
|
||||
static int m_instanceCounter; ///< GL GAL instance counter
|
||||
wxEvtHandler* m_mouseListener;
|
||||
wxEvtHandler* m_paintListener;
|
||||
|
|
Loading…
Reference in New Issue