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
int size = KiROUND( 14 * aDC.GetContentScaleFactor() );
#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( value ) ) );
aDC.DrawBitmap( bitmap, rect.GetLeft() + 4,
rect.GetTop() + ( rect.GetHeight() - bitmap.GetHeight() ) / 2, true );
aDC.DrawBitmap( m_bitmap, rect.GetLeft() + 4,
rect.GetTop() + ( rect.GetHeight() - m_bitmap.GetHeight() ) / 2, true );
// draw the text
PCB_LAYER_ID layer = ToLAYER_ID( value );
@ -92,7 +93,7 @@ void GRID_CELL_LAYER_RENDERER::Draw( wxGrid& aGrid, wxGridCellAttr& aAttr, wxDC&
else
layerName = BOARD::GetStandardLayerName( layer );
rect.SetLeft( rect.GetLeft() + bitmap.GetWidth() + 8 );
rect.SetLeft( rect.GetLeft() + m_bitmap.GetWidth() + 8 );
SetTextColoursAndFont( aGrid, aAttr, aDC, isSelected );
aGrid.DrawTextRectangle( aDC, layerName, rect, wxALIGN_LEFT, wxALIGN_CENTRE );
}

View File

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