Improved recaching (all items when a board is loaded), still needs some fixing (mem leak).

This commit is contained in:
Maciej Suminski 2013-04-30 17:55:24 +02:00
parent 191cb40e79
commit e9e4ed4230
5 changed files with 61 additions and 22 deletions

View File

@ -941,17 +941,19 @@ void EDA_DRAW_FRAME::AdjustScrollBars( const wxPoint& aCenterPositionIU )
void EDA_DRAW_FRAME::UseGalCanvas( bool aEnable )
{
#ifdef KICAD_GAL
KiGfx::VIEW* view = m_galCanvas->GetView();
KiGfx::GAL* gal = m_galCanvas->GetGAL();
if( aEnable && m_galCanvasActive )
{
// When we switch between GAL based canvases, all we need is a refresh
view->RecacheAllItems( true );
m_galCanvas->Refresh();
}
if( !( aEnable ^ m_galCanvasActive ) )
return;
KiGfx::VIEW* view = m_galCanvas->GetView();
KiGfx::GAL* gal = m_galCanvas->GetGAL();
double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor();
// Display the same view after canvas switching
@ -979,6 +981,9 @@ void EDA_DRAW_FRAME::UseGalCanvas( bool aEnable )
m_auimgr.GetPane( wxT( "DrawFrameGal" ) ).Show( aEnable );
m_auimgr.Update();
if( aEnable )
view->RecacheAllItems( true );
m_galCanvasActive = aEnable;
#endif /* KICAD_GAL */
}

View File

@ -403,7 +403,10 @@ void OPENGL_GAL::BeginDrawing()
SetFillColor( fillColor );
SetStrokeColor( strokeColor );
isDeleteSavedPixels = true;
vboNeedsUpdate = false;
// If any of VBO items is dirty - recache everything
if( vboNeedsUpdate )
rebuildVbo();
}
@ -455,13 +458,6 @@ void OPENGL_GAL::blitMainTexture( bool aIsClearFrameBuffer )
void OPENGL_GAL::EndDrawing()
{
// If any of VBO items is dirty - recache everything
if( vboNeedsUpdate )
{
rebuildVbo();
vboNeedsUpdate = false;
}
// Draw the remaining contents, blit the main texture to the screen, swap the buffers
glFlush();
blitMainTexture( true );
@ -521,6 +517,8 @@ void OPENGL_GAL::rebuildVbo()
delete verticesBuffer;
delete indicesBuffer;
vboNeedsUpdate = false;
#ifdef __WXDEBUG__
prof_end( &totalTime );
@ -1484,9 +1482,6 @@ void OPENGL_GAL::EndGroup()
{
vboSize += curVboItem->GetSize();
// TODO this has to be removed in final version
rebuildVbo();
isGroupStarted = false;
}

View File

@ -209,8 +209,8 @@ void VIEW::SetGAL( GAL* aGal )
m_painter->SetGAL( m_gal );
// items need to be recached after changing GAL
if( m_useGroups )
recacheAllItems();
//if( m_useGroups )
//RecacheAllItems();
// force the new GAL to display the current viewport.
SetCenter( m_center );
@ -387,7 +387,7 @@ struct VIEW::drawItem
aItem->setGroup( currentLayer, group );
view->m_painter->Draw( static_cast<EDA_ITEM*>( aItem ), currentLayer );
gal->EndGroup();
gal->DrawGroup( group );
//gal->DrawGroup( group );
}
}
else if( aItem->ViewIsVisible() )
@ -453,10 +453,33 @@ struct VIEW::unlinkItem
struct VIEW::recacheItem
{
recacheItem( VIEW* aView, GAL* aGal, int aLayer, bool aImmediately ) :
view( aView ), gal( aGal ), layer( aLayer ), immediately( aImmediately )
{
}
void operator()( VIEW_ITEM* aItem )
{
aItem->deleteGroups();
//aItem->deleteGroups();
/*int prevGroup = aItem->getGroup( layer );
if( prevGroup != -1 )
{
gal->DeleteGroup( prevGroup );
}*/
if( immediately )
{
int group = gal->BeginGroup();
aItem->setGroup( layer, group );
view->m_painter->Draw( static_cast<EDA_ITEM*>( aItem ), layer );
gal->EndGroup();
}
}
VIEW* view;
GAL* gal;
int layer;
bool immediately;
};
@ -571,16 +594,24 @@ void VIEW::clearGroupCache()
}
void VIEW::recacheAllItems()
void VIEW::RecacheAllItems( bool aImmediately )
{
BOX2I r;
r.SetMaximum();
wxLogDebug( wxT( "RecacheAllItems::immediately: %u" ), aImmediately );
if( aImmediately )
m_gal->BeginDrawing();
for( LayerMapIter i = m_layers.begin(); i != m_layers.end(); ++i )
{
VIEW_LAYER* l = & ( ( *i ).second );
recacheItem visitor;
recacheItem visitor( this, m_gal, l->id, aImmediately );
l->items->Query( r, visitor );
};
if( aImmediately )
m_gal->EndDrawing();
}

View File

@ -294,6 +294,14 @@ public:
*/
void PartialRedraw();
/**
* Function RecacheAllItems()
* Rebuilds GAL display lists.
* @param aForceNow decides if every item should be instantly recached. Otherwise items are
* going to be recached when they become visible.
*/
void RecacheAllItems( bool aForceNow = false );
/**
* Function IsDynamic()
* Tells if the VIEW is dynamic (ie. can be changed, for example displaying PCBs in a window)
@ -350,9 +358,6 @@ private:
///* Clears cached GAL display lists
void clearGroupCache();
///* Rebuilds GAL display lists
void recacheAllItems();
/// Determines rendering order of layers. Used in display order sorting function.
static bool compareRenderingOrder( VIEW_LAYER* i, VIEW_LAYER* j )
{

View File

@ -243,7 +243,10 @@ void PCB_BASE_FRAME::SetBoard( BOARD* aBoard )
view->SetTopLayer( m_Pcb->GetLayer() );
if( m_galCanvasActive )
{
view->RecacheAllItems( true );
m_galCanvas->Refresh();
}
}
#endif
}