1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Core - Reduced memory allocations

This commit is contained in:
Diogo Trindade 2023-02-04 19:27:49 +00:00
parent a1086df41a
commit 9f20f52b22
2 changed files with 9 additions and 10 deletions

View File

@ -1,4 +1,5 @@
using System.ComponentModel; using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using Artemis.Core.Properties; using Artemis.Core.Properties;
@ -26,7 +27,7 @@ public abstract class CorePropertyChanged : INotifyPropertyChanged
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
protected bool RequiresUpdate<T>(ref T storage, T value) protected bool RequiresUpdate<T>(ref T storage, T value)
{ {
return !Equals(storage, value); return !EqualityComparer<T>.Default.Equals(storage, value);
} }
/// <summary> /// <summary>

View File

@ -28,6 +28,8 @@ public abstract class PerLedLayerBrush<T> : PropertiesLayerBrush<T> where T : La
/// <returns>The color the LED will receive</returns> /// <returns>The color the LED will receive</returns>
public abstract SKColor GetColor(ArtemisLed led, SKPoint renderPoint); public abstract SKColor GetColor(ArtemisLed led, SKPoint renderPoint);
private readonly SKPoint[] _points = new SKPoint[2];
internal override void InternalRender(SKCanvas canvas, SKRect bounds, SKPaint paint) internal override void InternalRender(SKCanvas canvas, SKRect bounds, SKPaint paint)
{ {
// We don't want rotation on this canvas because that'll displace the LEDs, translations are applied to the points of each LED instead // We don't want rotation on this canvas because that'll displace the LEDs, translations are applied to the points of each LED instead
@ -37,25 +39,21 @@ public abstract class PerLedLayerBrush<T> : PropertiesLayerBrush<T> where T : La
using SKPath pointsPath = new(); using SKPath pointsPath = new();
foreach (ArtemisLed artemisLed in Layer.Leds) foreach (ArtemisLed artemisLed in Layer.Leds)
{ {
pointsPath.AddPoly(new[] _points[0] = new SKPoint(0, 0);
{ _points[1] = new SKPoint(artemisLed.AbsoluteRectangle.Left - Layer.Bounds.Left, artemisLed.AbsoluteRectangle.Top - Layer.Bounds.Top);
new SKPoint(0, 0), pointsPath.AddPoly(_points);
new SKPoint(artemisLed.AbsoluteRectangle.Left - Layer.Bounds.Left, artemisLed.AbsoluteRectangle.Top - Layer.Bounds.Top)
});
} }
// Apply the translation to the points of each LED instead // Apply the translation to the points of each LED instead
if (Layer.General.TransformMode.CurrentValue == LayerTransformMode.Normal && SupportsTransformation) if (Layer.General.TransformMode.CurrentValue == LayerTransformMode.Normal && SupportsTransformation)
pointsPath.Transform(Layer.GetTransformMatrix(true, true, true, true).Invert()); pointsPath.Transform(Layer.GetTransformMatrix(true, true, true, true).Invert());
SKPoint[] points = pointsPath.Points;
TryOrBreak(() => TryOrBreak(() =>
{ {
for (int index = 0; index < Layer.Leds.Count; index++) for (int index = 0; index < Layer.Leds.Count; index++)
{ {
ArtemisLed artemisLed = Layer.Leds[index]; ArtemisLed artemisLed = Layer.Leds[index];
SKPoint renderPoint = points[index * 2 + 1]; SKPoint renderPoint = pointsPath.GetPoint(index * 2 + 1);
if (!float.IsFinite(renderPoint.X) || !float.IsFinite(renderPoint.Y)) if (!float.IsFinite(renderPoint.X) || !float.IsFinite(renderPoint.Y))
continue; continue;