Device visualizer - Fixed memory leak

Device visualizer - Improved performance on very large devices
Dynamic data model - Reworked API
This commit is contained in:
Robert committed 2021-04-19 17:43:46 +02:00
1 parent 8cba36f5d4
commit 6904a137e1
7 files changed
+274 -199

No files matched your search

@@ -314,6 +314,7 @@ namespace Artemis.UI.Shared
ImageBrush bitmapBrush = new(bitmap);
bitmapBrush.Freeze();
_backingStore.OpacityMask = bitmapBrush;
_backingStore.Children.Clear();
InvalidateMeasure();
}
@@ -331,14 +332,19 @@ namespace Artemis.UI.Shared
private void Render()
{
DrawingContext drawingContext = _backingStore.Append();
// DrawingContext drawingContext = _backingStore.Open();
if (HighlightedLeds != null && HighlightedLeds.Any())
{
// Faster on large devices, maybe a bit slower on smaller ones but that's ok
ILookup<ArtemisLed, ArtemisLed> toHighlight = HighlightedLeds.ToLookup(l => l);
foreach (DeviceVisualizerLed deviceVisualizerLed in _deviceVisualizerLeds)
deviceVisualizerLed.RenderColor(_backingStore, drawingContext, !HighlightedLeds.Contains(deviceVisualizerLed.Led));
deviceVisualizerLed.RenderColor(_backingStore, drawingContext, !toHighlight.Contains(deviceVisualizerLed.Led));
}
else
{
foreach (DeviceVisualizerLed deviceVisualizerLed in _deviceVisualizerLeds)
deviceVisualizerLed.RenderColor(_backingStore, drawingContext, false);
}
drawingContext.Close();
}
@@ -14,10 +14,10 @@ namespace Artemis.UI.Shared
{
private const byte Dimmed = 100;
private const byte NonDimmed = 255;
private GeometryDrawing? _geometryDrawing;
private Color _renderColor;
private GeometryDrawing? _geometryDrawing;
private SolidColorBrush? _renderColorBrush;
private DrawingGroup? _lastBackingStore;
public DeviceVisualizerLed(ArtemisLed led)
{
@@ -43,12 +43,12 @@ namespace Artemis.UI.Shared
public void RenderColor(DrawingGroup backingStore, DrawingContext drawingContext, bool isDimmed)
{
if (DisplayGeometry == null)
if (DisplayGeometry == null || backingStore == null)
return;
_renderColorBrush ??= new SolidColorBrush();
_geometryDrawing ??= new GeometryDrawing(_renderColorBrush, null, new RectangleGeometry(LedRect));
byte r = Led.RgbLed.Color.GetR();
byte g = Led.RgbLed.Color.GetG();
byte b = Led.RgbLed.Color.GetB();
@@ -59,9 +59,12 @@ namespace Artemis.UI.Shared
_renderColor.B = b;
_renderColorBrush.Color = _renderColor;
if (!backingStore.Children.Contains(_geometryDrawing))
if (_lastBackingStore != backingStore)
{
backingStore.Children.Add(_geometryDrawing);
_lastBackingStore = backingStore;
}
}
public void RenderImage(DrawingContext drawingContext)