From b5f3d4cf7bd6c7749331bd549027456adcedf7ff Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Tue, 26 Aug 2025 05:29:02 -0700 Subject: [PATCH] Reduce GDI usage by caching layer swatches --- pcbnew/grid_layer_box_helpers.cpp | 11 ++++++----- pcbnew/grid_layer_box_helpers.h | 2 ++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/pcbnew/grid_layer_box_helpers.cpp b/pcbnew/grid_layer_box_helpers.cpp index 519287c98b..8492cfd21e 100644 --- a/pcbnew/grid_layer_box_helpers.cpp +++ b/pcbnew/grid_layer_box_helpers.cpp @@ -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 ); } diff --git a/pcbnew/grid_layer_box_helpers.h b/pcbnew/grid_layer_box_helpers.h index 7c7198b54b..6321ef0520 100644 --- a/pcbnew/grid_layer_box_helpers.h +++ b/pcbnew/grid_layer_box_helpers.h @@ -28,6 +28,7 @@ #include #include "pcb_layer_box_selector.h" #include +#include class wxGrid; class PCB_LAYER_BOX_SELECTOR; @@ -46,6 +47,7 @@ public: private: PCB_BASE_FRAME* m_frame; + wxBitmap m_bitmap; };