Reduce GDI usage by caching layer swatches

This commit is contained in:
Seth Hillbrand 2025-08-26 05:29:02 -07:00
parent 412fc1e6d9
commit b5f3d4cf7b
2 changed files with 8 additions and 5 deletions

View File

@ -74,14 +74,15 @@ void GRID_CELL_LAYER_RENDERER::Draw( wxGrid& aGrid, wxGridCellAttr& aAttr, wxDC&
#else #else
int size = KiROUND( 14 * aDC.GetContentScaleFactor() ); int size = KiROUND( 14 * aDC.GetContentScaleFactor() );
#endif #endif
wxBitmap bitmap( size, size ); if( !m_bitmap.IsOk() || m_bitmap.GetWidth() != size || m_bitmap.GetHeight() != size )
m_bitmap = wxBitmap( size, size );
LAYER_PRESENTATION::DrawColorSwatch( bitmap, LAYER_PRESENTATION::DrawColorSwatch( m_bitmap,
cs->GetColor( ToLAYER_ID( LAYER_PCB_BACKGROUND ) ), cs->GetColor( ToLAYER_ID( LAYER_PCB_BACKGROUND ) ),
cs->GetColor( ToLAYER_ID( value ) ) ); cs->GetColor( ToLAYER_ID( value ) ) );
aDC.DrawBitmap( bitmap, rect.GetLeft() + 4, aDC.DrawBitmap( m_bitmap, rect.GetLeft() + 4,
rect.GetTop() + ( rect.GetHeight() - bitmap.GetHeight() ) / 2, true ); rect.GetTop() + ( rect.GetHeight() - m_bitmap.GetHeight() ) / 2, true );
// draw the text // draw the text
PCB_LAYER_ID layer = ToLAYER_ID( value ); PCB_LAYER_ID layer = ToLAYER_ID( value );
@ -92,7 +93,7 @@ void GRID_CELL_LAYER_RENDERER::Draw( wxGrid& aGrid, wxGridCellAttr& aAttr, wxDC&
else else
layerName = BOARD::GetStandardLayerName( layer ); layerName = BOARD::GetStandardLayerName( layer );
rect.SetLeft( rect.GetLeft() + bitmap.GetWidth() + 8 ); rect.SetLeft( rect.GetLeft() + m_bitmap.GetWidth() + 8 );
SetTextColoursAndFont( aGrid, aAttr, aDC, isSelected ); SetTextColoursAndFont( aGrid, aAttr, aDC, isSelected );
aGrid.DrawTextRectangle( aDC, layerName, rect, wxALIGN_LEFT, wxALIGN_CENTRE ); aGrid.DrawTextRectangle( aDC, layerName, rect, wxALIGN_LEFT, wxALIGN_CENTRE );
} }

View File

@ -28,6 +28,7 @@
#include <wx/generic/grideditors.h> #include <wx/generic/grideditors.h>
#include "pcb_layer_box_selector.h" #include "pcb_layer_box_selector.h"
#include <lset.h> #include <lset.h>
#include <wx/bitmap.h>
class wxGrid; class wxGrid;
class PCB_LAYER_BOX_SELECTOR; class PCB_LAYER_BOX_SELECTOR;
@ -46,6 +47,7 @@ public:
private: private:
PCB_BASE_FRAME* m_frame; PCB_BASE_FRAME* m_frame;
wxBitmap m_bitmap;
}; };