UI - Large amount of memory improvements in the VMs

Core - Minor memory improvements
This commit is contained in:
SpoinkyNL committed 2020-06-19 21:48:26 +02:00
1 parent 63cb6d211e
commit 24afb6b0f5
26 files changed
+243 -191

No files matched your search

@@ -1,4 +1,5 @@
using RGB.NET.Core;
using System.Text;
using RGB.NET.Core;
namespace Artemis.Core.Extensions
{
@@ -6,11 +7,17 @@ namespace Artemis.Core.Extensions
{
public static string GetDeviceIdentifier(this IRGBDevice rgbDevice)
{
return rgbDevice.DeviceInfo.DeviceName +
"-" + rgbDevice.DeviceInfo.Manufacturer +
"-" + rgbDevice.DeviceInfo.Model +
"-" + rgbDevice.DeviceInfo.DeviceType +
"-" + rgbDevice.DeviceInfo.Lighting;
var builder = new StringBuilder();
builder.Append(rgbDevice.DeviceInfo.DeviceName);
builder.Append('-');
builder.Append(rgbDevice.DeviceInfo.Manufacturer);
builder.Append('-');
builder.Append(rgbDevice.DeviceInfo.Model);
builder.Append('-');
builder.Append(rgbDevice.DeviceInfo.DeviceType);
builder.Append('-');
builder.Append(rgbDevice.DeviceInfo.Lighting);
return builder.ToString();
}
}
}
+3 -3
View File
@@ -80,7 +80,7 @@ namespace Artemis.Core.Models.Profile
{
if (!Enabled || Path == null || !Children.Any(c => c.Enabled))
return;
if (_folderBitmap == null)
_folderBitmap = new SKBitmap(new SKImageInfo((int) Path.Bounds.Width, (int) Path.Bounds.Height));
else if (_folderBitmap.Info.Width != (int) Path.Bounds.Width || _folderBitmap.Info.Height != (int) Path.Bounds.Height)
@@ -89,11 +89,11 @@ namespace Artemis.Core.Models.Profile
_folderBitmap = new SKBitmap(new SKImageInfo((int) Path.Bounds.Width, (int) Path.Bounds.Height));
}
using var folderPath = new SKPath(Path);
using var folderCanvas = new SKCanvas(_folderBitmap);
using var folderPaint = new SKPaint();
folderCanvas.Clear();
var folderPath = new SKPath(Path);
folderPath.Transform(SKMatrix.MakeTranslation(folderPath.Bounds.Left * -1, folderPath.Bounds.Top * -1));
foreach (var baseLayerEffect in LayerEffects.Where(e => e.Enabled))
@@ -112,7 +112,7 @@ namespace Artemis.Core.Models.Profile
canvas.Save();
var clipPath = new SKPath(folderPath);
using var clipPath = new SKPath(folderPath);
clipPath.Transform(SKMatrix.MakeTranslation(targetLocation.X, targetLocation.Y));
canvas.ClipPath(clipPath);
+10 -7
View File
@@ -246,6 +246,7 @@ namespace Artemis.Core.Models.Profile
_layerBitmap = new SKBitmap(new SKImageInfo((int)Path.Bounds.Width, (int)Path.Bounds.Height));
}
using var layerPath = new SKPath(Path);
using var layerCanvas = new SKCanvas(_layerBitmap);
using var layerPaint = new SKPaint
{
@@ -254,8 +255,7 @@ namespace Artemis.Core.Models.Profile
Color = new SKColor(0, 0, 0, (byte) (Transform.Opacity.CurrentValue * 2.55f))
};
layerCanvas.Clear();
var layerPath = new SKPath(Path);
layerPath.Transform(SKMatrix.MakeTranslation(layerPath.Bounds.Left * -1, layerPath.Bounds.Top * -1));
foreach (var baseLayerEffect in LayerEffects.Where(e => e.Enabled))
@@ -278,11 +278,13 @@ namespace Artemis.Core.Models.Profile
targetLocation = Path.Bounds.Location - parentFolder.Path.Bounds.Location;
canvas.DrawBitmap(_layerBitmap, targetLocation, layerPaint);
}
private void SimpleRender(SKCanvas canvas, SKImageInfo canvasInfo, SKPaint paint, SKPath layerPath)
{
LayerBrush.InternalRender(canvas, canvasInfo, new SKPath(LayerShape.Path), paint);
using var renderPath = new SKPath(LayerShape.Path);
LayerBrush.InternalRender(canvas, canvasInfo, renderPath, paint);
}
private void StretchRender(SKCanvas canvas, SKImageInfo canvasInfo, SKPaint paint, SKPath layerPath)
@@ -302,8 +304,9 @@ namespace Artemis.Core.Models.Profile
canvas.RotateDegrees(rotationProperty, anchorPosition.X, anchorPosition.Y);
canvas.Scale(sizeProperty.Width / 100f, sizeProperty.Height / 100f, anchorPosition.X, anchorPosition.Y);
canvas.Translate(x, y);
LayerBrush.InternalRender(canvas, canvasInfo, new SKPath(LayerShape.Path), paint);
using var renderPath = new SKPath(LayerShape.Path);
LayerBrush.InternalRender(canvas, canvasInfo, renderPath, paint);
}
private void ClipRender(SKCanvas canvas, SKImageInfo canvasInfo, SKPaint paint, SKPath layerPath)
@@ -319,7 +322,7 @@ namespace Artemis.Core.Models.Profile
var x = anchorPosition.X - layerPath.Bounds.MidX - anchorProperty.X * layerPath.Bounds.Width;
var y = anchorPosition.Y - layerPath.Bounds.MidY - anchorProperty.Y * layerPath.Bounds.Height;
var clipPath = new SKPath(LayerShape.Path);
using var clipPath = new SKPath(LayerShape.Path);
clipPath.Transform(SKMatrix.MakeTranslation(x, y));
clipPath.Transform(SKMatrix.MakeScale(sizeProperty.Width / 100f, sizeProperty.Height / 100f, anchorPosition.X, anchorPosition.Y));
clipPath.Transform(SKMatrix.MakeRotationDegrees(rotationProperty, anchorPosition.X, anchorPosition.Y));
@@ -336,7 +339,7 @@ namespace Artemis.Core.Models.Profile
Math.Max(clipPath.Bounds.Right - x, Bounds.Right - x),
Math.Max(clipPath.Bounds.Bottom - y, Bounds.Bottom - y)
);
var renderPath = new SKPath();
using var renderPath = new SKPath();
renderPath.AddRect(boundsRect);
LayerBrush.InternalRender(canvas, canvasInfo, renderPath, paint);
@@ -4,8 +4,6 @@ namespace Artemis.Core.Models.Profile.LayerShapes
{
public abstract class LayerShape
{
private SKPath _path;
protected LayerShape(Layer layer)
{
Layer = layer;
@@ -17,13 +15,9 @@ namespace Artemis.Core.Models.Profile.LayerShapes
public Layer Layer { get; set; }
/// <summary>
/// Gets a copy of the path outlining the shape
/// Gets a the path outlining the shape
/// </summary>
public SKPath Path
{
get => _path != null ? new SKPath(_path) : null;
protected set => _path = value;
}
public SKPath Path { get; protected set; }
public abstract void CalculateRenderProperties();
}
@@ -11,12 +11,12 @@ namespace Artemis.Core.Models.Profile
private SKPath _path;
/// <summary>
/// Gets a copy of the path containing all the LEDs this entity is applied to, any rendering outside the entity Path is
/// Gets the path containing all the LEDs this entity is applied to, any rendering outside the entity Path is
/// clipped.
/// </summary>
public SKPath Path
{
get => _path != null ? new SKPath(_path) : null;
get => _path;
protected set
{
_path = value;
+1 -1
View File
@@ -98,7 +98,7 @@ namespace Artemis.Core.RGB.NET
var bitmapWidth = Bitmap.Width;
var bitmapHeight = Bitmap.Height;
var pixmap = Bitmap.PeekPixels();
using var pixmap = Bitmap.PeekPixels();
foreach (var renderTarget in renderTargets)
{
// SKRect has all the good stuff we need
@@ -1,56 +0,0 @@
using System;
using System.Linq;
using Artemis.Core.Extensions;
using RGB.NET.Core;
using SkiaSharp;
namespace Artemis.Core.RGB.NET
{
public class GraphicsDecorator : AbstractDecorator, IBrushDecorator, IDisposable
{
private readonly double _scale;
public GraphicsDecorator(ILedGroup ledGroup, double scale)
{
_scale = scale;
var leds = ledGroup.GetLeds().ToList();
if (!leds.Any())
return;
var width = Math.Min(leds.Max(l => l.AbsoluteLedRectangle.Location.X + l.AbsoluteLedRectangle.Size.Width) * scale, 4096);
var height = Math.Min(leds.Max(l => l.AbsoluteLedRectangle.Location.Y + l.AbsoluteLedRectangle.Size.Height) * scale, 4096);
Bitmap = new SKBitmap(new SKImageInfo(width.RoundToInt(), height.RoundToInt()));
}
public SKBitmap Bitmap { get; private set; }
public Color ManipulateColor(Rectangle rectangle, BrushRenderTarget renderTarget, Color color)
{
if (Bitmap == null)
return new Color(0, 0, 0);
var x = renderTarget.Led.AbsoluteLedRectangle.Center.X * _scale;
var y = renderTarget.Led.AbsoluteLedRectangle.Center.Y * _scale;
var pixel = Bitmap.GetPixel(RoundToInt(x), RoundToInt(y));
return new Color(pixel.Alpha, pixel.Red, pixel.Green, pixel.Blue);
}
public override void OnDetached(IDecoratable decoratable)
{
Dispose();
}
public void Dispose()
{
Bitmap?.Dispose();
Bitmap = null;
}
private int RoundToInt(double number)
{
return (int) Math.Round(number, MidpointRounding.AwayFromZero);
}
}
}