EDA_DRAW_PANEL_GAL: redraw stuff in a single place, with "coalescing"

Redraws can be requested way too often than it is required. This commit adds redraw timeout:
- if the view became dirty and there has been no redraw for longer than certain time, it is redrawed immediately
- otherwise, we wait for the next frame

This in general improves smoothness of rendering.
parent 660d4cc6
...@@ -91,6 +91,11 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin ...@@ -91,6 +91,11 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin
Connect( wxEVT_KEY_UP, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this ); Connect( wxEVT_KEY_UP, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this );
Connect( wxEVT_KEY_DOWN, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this ); Connect( wxEVT_KEY_DOWN, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this );
Connect( wxEVT_ENTER_WINDOW, wxEventHandler (EDA_DRAW_PANEL_GAL::onEnter ), NULL, this ); Connect( wxEVT_ENTER_WINDOW, wxEventHandler (EDA_DRAW_PANEL_GAL::onEnter ), NULL, this );
m_refreshTimer.SetOwner( this );
Connect( wxEVT_TIMER, wxTimerEventHandler( EDA_DRAW_PANEL_GAL::onRefreshTimer ), NULL, this );
this->SetFocus(); this->SetFocus();
} }
...@@ -113,6 +118,9 @@ EDA_DRAW_PANEL_GAL::~EDA_DRAW_PANEL_GAL() ...@@ -113,6 +118,9 @@ EDA_DRAW_PANEL_GAL::~EDA_DRAW_PANEL_GAL()
void EDA_DRAW_PANEL_GAL::onPaint( wxPaintEvent& WXUNUSED( aEvent ) ) void EDA_DRAW_PANEL_GAL::onPaint( wxPaintEvent& WXUNUSED( aEvent ) )
{ {
m_pendingRefresh = false;
m_lastRefresh = wxGetLocalTimeMillis();
#ifdef __WXDEBUG__ #ifdef __WXDEBUG__
prof_counter time; prof_counter time;
prof_start( &time, false ); prof_start( &time, false );
...@@ -147,13 +155,33 @@ void EDA_DRAW_PANEL_GAL::onSize( wxSizeEvent& aEvent ) ...@@ -147,13 +155,33 @@ void EDA_DRAW_PANEL_GAL::onSize( wxSizeEvent& aEvent )
} }
void EDA_DRAW_PANEL_GAL::Refresh( bool eraseBackground, const wxRect* rect ) void EDA_DRAW_PANEL_GAL::onRefreshTimer( wxTimerEvent& aEvent )
{ {
wxPaintEvent redrawEvent; wxPaintEvent redrawEvent;
wxPostEvent( this, redrawEvent ); wxPostEvent( this, redrawEvent );
} }
void EDA_DRAW_PANEL_GAL::Refresh( bool eraseBackground, const wxRect* rect )
{
if(m_pendingRefresh)
return;
wxLongLong t = wxGetLocalTimeMillis();
wxLongLong delta = t - m_lastRefresh;
if(t >= MinRefreshPeriod)
{
wxPaintEvent redrawEvent;
wxPostEvent( this, redrawEvent );
m_pendingRefresh = true;
} else {
m_refreshTimer.Start ( (MinRefreshPeriod - t).ToLong(), true );
m_pendingRefresh = true;
}
}
void EDA_DRAW_PANEL_GAL::SwitchBackend( GalType aGalType ) void EDA_DRAW_PANEL_GAL::SwitchBackend( GalType aGalType )
{ {
// Do not do anything if the currently used GAL is correct // Do not do anything if the currently used GAL is correct
...@@ -208,7 +236,8 @@ void EDA_DRAW_PANEL_GAL::onEvent( wxEvent& aEvent ) ...@@ -208,7 +236,8 @@ void EDA_DRAW_PANEL_GAL::onEvent( wxEvent& aEvent )
m_eventDispatcher->DispatchWxEvent( aEvent ); m_eventDispatcher->DispatchWxEvent( aEvent );
} }
Refresh(); if(m_view->IsDirty())
Refresh();
} }
......
...@@ -196,8 +196,7 @@ void WX_VIEW_CONTROLS::onTimer( wxTimerEvent& aEvent ) ...@@ -196,8 +196,7 @@ void WX_VIEW_CONTROLS::onTimer( wxTimerEvent& aEvent )
dir = m_view->ToWorld( dir, false ); dir = m_view->ToWorld( dir, false );
m_view->SetCenter( m_view->GetCenter() + dir * m_autoPanSpeed ); m_view->SetCenter( m_view->GetCenter() + dir * m_autoPanSpeed );
m_view->MakeDirty();
m_parentPanel->Refresh();
} }
break; break;
......
...@@ -116,8 +116,15 @@ protected: ...@@ -116,8 +116,15 @@ protected:
void onSize( wxSizeEvent& aEvent ); void onSize( wxSizeEvent& aEvent );
void onEvent( wxEvent& aEvent ); void onEvent( wxEvent& aEvent );
void onEnter( wxEvent& aEvent ); void onEnter( wxEvent& aEvent );
void onRefreshTimer ( wxTimerEvent& aEvent );
void skipEvent( wxEvent& aEvent ); void skipEvent( wxEvent& aEvent );
static const int MinRefreshPeriod = 17; ///< 60 FPS.
wxLongLong m_lastRefresh; ///< Last time the panel was refreshed
bool m_pendingRefresh;
wxTimer m_refreshTimer;
KiGfx::GAL* m_gal; ///< Interface for drawing objects on a 2D-surface KiGfx::GAL* m_gal; ///< Interface for drawing objects on a 2D-surface
KiGfx::VIEW* m_view; ///< Stores view settings (scale, center, etc.) KiGfx::VIEW* m_view; ///< Stores view settings (scale, center, etc.)
///< and items to be drawn ///< and items to be drawn
......
...@@ -443,6 +443,11 @@ public: ...@@ -443,6 +443,11 @@ public:
return ( m_layers.at( aLayer ).target == TARGET_CACHED ); return ( m_layers.at( aLayer ).target == TARGET_CACHED );
} }
void MakeDirty()
{
for(int i = 0; i < TARGETS_NUMBER; i++)
m_dirtyTargets[i] = true;
}
static const int VIEW_MAX_LAYERS = 128; ///* maximum number of layers that may be shown static const int VIEW_MAX_LAYERS = 128; ///* maximum number of layers that may be shown
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment