diff --git a/common/draw_panel_gal.cpp b/common/draw_panel_gal.cpp index 361c32cfd6..f6eae5935c 100644 --- a/common/draw_panel_gal.cpp +++ b/common/draw_panel_gal.cpp @@ -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 ); diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index 95b2fd75d6..67b9b14dde 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -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 ); diff --git a/include/class_draw_panel_gal.h b/include/class_draw_panel_gal.h index 4d4081b278..9bdcf8ba12 100644 --- a/include/class_draw_panel_gal.h +++ b/include/class_draw_panel_gal.h @@ -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 diff --git a/include/gal/graphics_abstraction_layer.h b/include/gal/graphics_abstraction_layer.h index 0470486a57..67a497b641 100644 --- a/include/gal/graphics_abstraction_layer.h +++ b/include/gal/graphics_abstraction_layer.h @@ -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() {}; diff --git a/include/gal/opengl/opengl_gal.h b/include/gal/opengl/opengl_gal.h index 38f5d3df01..c14fa8d026 100644 --- a/include/gal/opengl/opengl_gal.h +++ b/include/gal/opengl/opengl_gal.h @@ -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;