GDIPlus renderer - use brush cache for text drawing

This commit is contained in:
adelikat 2019-10-24 16:35:07 -05:00
parent 2e8d7346c3
commit 28dcae6c8b
1 changed files with 10 additions and 4 deletions

View File

@ -11,16 +11,14 @@ namespace BizHawk.Client.EmuHawk.CustomControls
private int _width;
private int _height;
// TODO: see if caching has any benefit
private readonly Dictionary<Color, Pen> _penCache = new Dictionary<Color, Pen>();
private Pen _currentPen;
private readonly Dictionary<Color, Brush> _brushCache = new Dictionary<Color, Brush>();
private Brush _currentBrush;
private Brush _currentStringBrush = new SolidBrush(Color.Black);
private Font _currentFont = new Font("Arial", 8, FontStyle.Bold);
// TODO: cache this?
private Brush _currentStringBrush = new SolidBrush(Color.Black);
public GdiPlusRenderer()
{
@ -104,7 +102,15 @@ namespace BizHawk.Client.EmuHawk.CustomControls
}
_currentFont = font;
_currentStringBrush = new SolidBrush(color);
var result = _brushCache.TryGetValue(color, out Brush brush);
if (!result)
{
brush = new SolidBrush(color);
_brushCache.Add(color, brush);
}
_currentStringBrush = brush;
}
public void SetBrush(Color color)