mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 19:36:28 +00:00
Implemented most of the rendering pipeline in SkiaSharp
This commit is contained in:
1 parent
b8a678c97f
commit
96a057df23
35 files changed
+234
-274
No files matched your search
@@ -113,8 +113,8 @@
|
||||
<Reference Include="SkiaSharp, Version=1.68.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\SkiaSharp.1.68.1\lib\net45\SkiaSharp.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Stylet, Version=1.2.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Stylet.1.2.0\lib\net45\Stylet.dll</HintPath>
|
||||
<Reference Include="Stylet, Version=1.3.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Stylet.1.3.0\lib\net45\Stylet.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
@@ -132,15 +132,15 @@
|
||||
<HintPath>..\packages\System.Memory.4.5.3\lib\netstandard2.0\System.Memory.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Numerics.Vectors, Version=4.1.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Numerics.Vectors.4.6.0-preview5.19224.8\lib\net46\System.Numerics.Vectors.dll</HintPath>
|
||||
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Reflection.Metadata, Version=1.4.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Reflection.Metadata.1.7.0-preview8.19405.3\lib\netstandard2.0\System.Reflection.Metadata.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Runtime" />
|
||||
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.6.0-preview8.19405.3\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
|
||||
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.6.0\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath>
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using Artemis.Core.RGB.NET;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace Artemis.Core.Events
|
||||
{
|
||||
public class FrameRenderedEventArgs : EventArgs
|
||||
{
|
||||
public FrameRenderedEventArgs(Bitmap bitmap, RGBSurface rgbSurface)
|
||||
public FrameRenderedEventArgs(GraphicsDecorator graphicsDecorator, RGBSurface rgbSurface)
|
||||
{
|
||||
Bitmap = bitmap;
|
||||
GraphicsDecorator = graphicsDecorator;
|
||||
RgbSurface = rgbSurface;
|
||||
}
|
||||
|
||||
public Bitmap Bitmap { get; }
|
||||
|
||||
public GraphicsDecorator GraphicsDecorator { get; }
|
||||
public RGBSurface RgbSurface { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.Core.RGB.NET;
|
||||
using RGB.NET.Core;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.Core.Events
|
||||
{
|
||||
public class FrameRenderingEventArgs : EventArgs
|
||||
{
|
||||
public FrameRenderingEventArgs(List<Module> modules, GraphicsDecorator graphicsDecorator, double deltaTime, RGBSurface rgbSurface)
|
||||
public FrameRenderingEventArgs(List<Module> modules, SKCanvas canvas, double deltaTime, RGBSurface rgbSurface)
|
||||
{
|
||||
Modules = modules;
|
||||
GraphicsDecorator = graphicsDecorator;
|
||||
Canvas = canvas;
|
||||
DeltaTime = deltaTime;
|
||||
RgbSurface = rgbSurface;
|
||||
}
|
||||
|
||||
public List<Module> Modules { get; }
|
||||
public GraphicsDecorator GraphicsDecorator { get; }
|
||||
public SKCanvas Canvas { get; }
|
||||
public double DeltaTime { get; }
|
||||
public RGBSurface RgbSurface { get; }
|
||||
}
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
using System.Drawing;
|
||||
using RGB.NET.Core;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.Core.Extensions
|
||||
{
|
||||
public static class RgbRectangleExtensions
|
||||
{
|
||||
public static Rectangle ToDrawingRectangle(this global::RGB.NET.Core.Rectangle rectangle, double scale)
|
||||
public static SKRect ToSKRect(this Rectangle rectangle, double scale)
|
||||
{
|
||||
return new Rectangle(
|
||||
(int) (rectangle.Location.X * scale),
|
||||
(int) (rectangle.Location.Y * scale),
|
||||
(int) (rectangle.Size.Width * scale),
|
||||
(int) (rectangle.Size.Height * scale)
|
||||
return SKRect.Create(
|
||||
(rectangle.Location.X * scale).RoundToInt(),
|
||||
(rectangle.Location.Y * scale).RoundToInt(),
|
||||
(rectangle.Size.Width * scale).RoundToInt(),
|
||||
(rectangle.Size.Height * scale).RoundToInt()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using Artemis.Core.Models.Surface;
|
||||
using SkiaSharp;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.Core.Models.Profile.Abstract
|
||||
@@ -45,7 +45,7 @@ namespace Artemis.Core.Models.Profile.Abstract
|
||||
/// <summary>
|
||||
/// Renders the element
|
||||
/// </summary>
|
||||
public abstract void Render(double deltaTime, ArtemisSurface surface, Graphics graphics);
|
||||
public abstract void Render(double deltaTime, ArtemisSurface surface, SKCanvas canvas);
|
||||
|
||||
/// <summary>
|
||||
/// Applies the profile element's properties to the underlying storage entity
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using Artemis.Core.Models.Profile.Abstract;
|
||||
using Artemis.Core.Models.Surface;
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.Core.Models.Profile
|
||||
{
|
||||
@@ -56,11 +56,11 @@ namespace Artemis.Core.Models.Profile
|
||||
profileElement.Update(deltaTime);
|
||||
}
|
||||
|
||||
public override void Render(double deltaTime, ArtemisSurface surface, Graphics graphics)
|
||||
public override void Render(double deltaTime, ArtemisSurface surface, SKCanvas canvas)
|
||||
{
|
||||
// Folders don't render but their children do
|
||||
foreach (var profileElement in Children)
|
||||
profileElement.Render(deltaTime, surface, graphics);
|
||||
profileElement.Render(deltaTime, surface, canvas);
|
||||
}
|
||||
|
||||
public Folder AddFolder(string name)
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Linq;
|
||||
using Artemis.Core.Extensions;
|
||||
using Artemis.Core.Models.Profile.Abstract;
|
||||
@@ -10,6 +8,7 @@ using Artemis.Core.Models.Surface;
|
||||
using Artemis.Core.Plugins.LayerElement;
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
using Newtonsoft.Json;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.Core.Models.Profile
|
||||
{
|
||||
@@ -50,8 +49,8 @@ namespace Artemis.Core.Models.Profile
|
||||
public ReadOnlyCollection<ArtemisLed> Leds => _leds.AsReadOnly();
|
||||
public ReadOnlyCollection<LayerElement> LayerElements => _layerElements.AsReadOnly();
|
||||
|
||||
public Rectangle RenderRectangle { get; set; }
|
||||
public GraphicsPath RenderPath { get; set; }
|
||||
public SKRect RenderRectangle { get; set; }
|
||||
public SKPath RenderPath { get; set; }
|
||||
|
||||
public override void Update(double deltaTime)
|
||||
{
|
||||
@@ -59,20 +58,21 @@ namespace Artemis.Core.Models.Profile
|
||||
layerElement.Update(deltaTime);
|
||||
}
|
||||
|
||||
public override void Render(double deltaTime, ArtemisSurface surface, Graphics graphics)
|
||||
public override void Render(double deltaTime, ArtemisSurface surface, SKCanvas canvas)
|
||||
{
|
||||
graphics.SetClip(RenderPath);
|
||||
canvas.Save();
|
||||
canvas.ClipPath(RenderPath);
|
||||
|
||||
foreach (var layerElement in LayerElements)
|
||||
layerElement.RenderPreProcess(surface, graphics);
|
||||
layerElement.RenderPreProcess(surface, canvas);
|
||||
|
||||
foreach (var layerElement in LayerElements)
|
||||
layerElement.Render(surface, graphics);
|
||||
layerElement.Render(surface, canvas);
|
||||
|
||||
foreach (var layerElement in LayerElements)
|
||||
layerElement.RenderPostProcess(surface, graphics);
|
||||
layerElement.RenderPostProcess(surface, canvas);
|
||||
|
||||
graphics.ResetClip();
|
||||
canvas.Restore();
|
||||
}
|
||||
|
||||
internal override void ApplyToEntity()
|
||||
@@ -167,15 +167,17 @@ namespace Artemis.Core.Models.Profile
|
||||
}
|
||||
|
||||
// Determine to top-left and bottom-right
|
||||
var minX = Leds.Min(l => l.AbsoluteRenderRectangle.X);
|
||||
var minY = Leds.Min(l => l.AbsoluteRenderRectangle.Y);
|
||||
var maxX = Leds.Max(l => l.AbsoluteRenderRectangle.X + l.AbsoluteRenderRectangle.Width);
|
||||
var maxY = Leds.Max(l => l.AbsoluteRenderRectangle.Y + l.AbsoluteRenderRectangle.Height);
|
||||
var minX = Leds.Min(l => l.AbsoluteRenderRectangle.Left);
|
||||
var minY = Leds.Min(l => l.AbsoluteRenderRectangle.Top);
|
||||
var maxX = Leds.Max(l => l.AbsoluteRenderRectangle.Bottom);
|
||||
var maxY = Leds.Max(l => l.AbsoluteRenderRectangle.Right);
|
||||
|
||||
RenderRectangle = new Rectangle(minX, minY, maxX - minX, maxY - minY);
|
||||
RenderRectangle = SKRect.Create(minX, minY, maxX - minX, maxY - minY);
|
||||
|
||||
var path = new SKPath {FillType = SKPathFillType.Winding};
|
||||
foreach (var artemisLed in Leds)
|
||||
path.AddRect(artemisLed.AbsoluteRenderRectangle);
|
||||
|
||||
var path = new GraphicsPath();
|
||||
path.AddRectangles(Leds.Select(l => l.AbsoluteRenderRectangle).ToArray());
|
||||
RenderPath = path;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using Artemis.Core.Exceptions;
|
||||
using Artemis.Core.Models.Profile.Abstract;
|
||||
using Artemis.Core.Models.Surface;
|
||||
using Artemis.Core.Plugins.Models;
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.Core.Models.Profile
|
||||
{
|
||||
@@ -56,7 +56,7 @@ namespace Artemis.Core.Models.Profile
|
||||
}
|
||||
}
|
||||
|
||||
public override void Render(double deltaTime, ArtemisSurface surface, Graphics graphics)
|
||||
public override void Render(double deltaTime, ArtemisSurface surface, SKCanvas canvas)
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
@@ -64,7 +64,7 @@ namespace Artemis.Core.Models.Profile
|
||||
throw new ArtemisCoreException($"Cannot render inactive profile: {this}");
|
||||
|
||||
foreach (var profileElement in Children)
|
||||
profileElement.Render(deltaTime, surface, graphics);
|
||||
profileElement.Render(deltaTime, surface, canvas);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Linq;
|
||||
using Artemis.Core.Extensions;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
@@ -8,7 +7,6 @@ using Artemis.Storage.Entities.Surface;
|
||||
using RGB.NET.Core;
|
||||
using SkiaSharp;
|
||||
using Stylet;
|
||||
using Rectangle = System.Drawing.Rectangle;
|
||||
|
||||
namespace Artemis.Core.Models.Surface
|
||||
{
|
||||
@@ -99,14 +97,8 @@ namespace Artemis.Core.Models.Surface
|
||||
RenderRectangle = SKRect.Create(
|
||||
(RgbDevice.Location.X * Surface.Scale).RoundToInt(),
|
||||
(RgbDevice.Location.Y * Surface.Scale).RoundToInt(),
|
||||
(RgbDevice.Location.X * Surface.Scale).RoundToInt(),
|
||||
(RgbDevice.Location.X * Surface.Scale).RoundToInt()
|
||||
);
|
||||
RenderRectangle = new Rectangle(
|
||||
(int) Math.Round(RgbDevice.Location.X * Surface.Scale, MidpointRounding.AwayFromZero),
|
||||
(int) Math.Round(RgbDevice.Location.Y * Surface.Scale, MidpointRounding.AwayFromZero),
|
||||
(int) Math.Round(RgbDevice.DeviceRectangle.Size.Width * Surface.Scale, MidpointRounding.AwayFromZero),
|
||||
(int) Math.Round(RgbDevice.DeviceRectangle.Size.Height * Surface.Scale, MidpointRounding.AwayFromZero)
|
||||
(RgbDevice.DeviceRectangle.Size.Width * Surface.Scale).RoundToInt(),
|
||||
(RgbDevice.DeviceRectangle.Size.Height * Surface.Scale).RoundToInt()
|
||||
);
|
||||
|
||||
if (!Leds.Any())
|
||||
@@ -115,9 +107,10 @@ namespace Artemis.Core.Models.Surface
|
||||
foreach (var led in Leds)
|
||||
led.CalculateRenderRectangle();
|
||||
|
||||
var path = new GraphicsPath();
|
||||
path.AddRectangles(Leds.Select(l => l.AbsoluteRenderRectangle).ToArray());
|
||||
path.FillMode = FillMode.Winding;
|
||||
var path = new SKPath {FillType = SKPathFillType.Winding};
|
||||
foreach (var artemisLed in Leds)
|
||||
path.AddRect(artemisLed.AbsoluteRenderRectangle);
|
||||
|
||||
RenderPath = path;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using Artemis.Core.Extensions;
|
||||
using RGB.NET.Core;
|
||||
using SkiaSharp;
|
||||
using Stylet;
|
||||
using Rectangle = System.Drawing.Rectangle;
|
||||
|
||||
namespace Artemis.Core.Models.Surface
|
||||
{
|
||||
@@ -17,22 +17,22 @@ namespace Artemis.Core.Models.Surface
|
||||
public Led RgbLed { get; }
|
||||
public ArtemisDevice Device { get; }
|
||||
|
||||
public Rectangle RenderRectangle { get; private set; }
|
||||
public Rectangle AbsoluteRenderRectangle { get; private set; }
|
||||
public SKRect RenderRectangle { get; private set; }
|
||||
public SKRect AbsoluteRenderRectangle { get; private set; }
|
||||
|
||||
public void CalculateRenderRectangle()
|
||||
{
|
||||
RenderRectangle = new Rectangle(
|
||||
(int) Math.Round(RgbLed.LedRectangle.Location.X * Device.Surface.Scale, MidpointRounding.AwayFromZero),
|
||||
(int) Math.Round(RgbLed.LedRectangle.Location.Y * Device.Surface.Scale, MidpointRounding.AwayFromZero),
|
||||
(int) Math.Round(RgbLed.LedRectangle.Size.Width * Device.Surface.Scale, MidpointRounding.AwayFromZero),
|
||||
(int) Math.Round(RgbLed.LedRectangle.Size.Height * Device.Surface.Scale, MidpointRounding.AwayFromZero)
|
||||
RenderRectangle = SKRect.Create(
|
||||
(RgbLed.LedRectangle.Location.X * Device.Surface.Scale).RoundToInt(),
|
||||
(RgbLed.LedRectangle.Location.Y * Device.Surface.Scale).RoundToInt(),
|
||||
(RgbLed.LedRectangle.Size.Width * Device.Surface.Scale).RoundToInt(),
|
||||
(RgbLed.LedRectangle.Size.Height * Device.Surface.Scale).RoundToInt()
|
||||
);
|
||||
AbsoluteRenderRectangle = new Rectangle(
|
||||
(int) Math.Round(RgbLed.AbsoluteLedRectangle.Location.X * Device.Surface.Scale, MidpointRounding.AwayFromZero),
|
||||
(int) Math.Round(RgbLed.AbsoluteLedRectangle.Location.Y * Device.Surface.Scale, MidpointRounding.AwayFromZero),
|
||||
(int) Math.Round(RgbLed.AbsoluteLedRectangle.Size.Width * Device.Surface.Scale, MidpointRounding.AwayFromZero),
|
||||
(int) Math.Round(RgbLed.AbsoluteLedRectangle.Size.Height * Device.Surface.Scale, MidpointRounding.AwayFromZero)
|
||||
AbsoluteRenderRectangle = SKRect.Create(
|
||||
(RgbLed.AbsoluteLedRectangle.Location.X * Device.Surface.Scale).RoundToInt(),
|
||||
(RgbLed.AbsoluteLedRectangle.Location.Y * Device.Surface.Scale).RoundToInt(),
|
||||
(RgbLed.AbsoluteLedRectangle.Size.Width * Device.Surface.Scale).RoundToInt(),
|
||||
(RgbLed.AbsoluteLedRectangle.Size.Height * Device.Surface.Scale).RoundToInt()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using Artemis.Core.Models.Surface;
|
||||
using Artemis.Core.Plugins.Models;
|
||||
using SkiaSharp;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using Artemis.Core.Exceptions;
|
||||
using Artemis.Core.Models.Profile;
|
||||
using Artemis.Core.Models.Surface;
|
||||
using Artemis.Core.Plugins.Models;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.Core.Plugins.Abstract
|
||||
{
|
||||
@@ -26,12 +26,12 @@ namespace Artemis.Core.Plugins.Abstract
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Render(double deltaTime, ArtemisSurface surface, Graphics graphics)
|
||||
public override void Render(double deltaTime, ArtemisSurface surface, SKCanvas canvas)
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
// Render the profile
|
||||
ActiveProfile?.Render(deltaTime, surface, graphics);
|
||||
ActiveProfile?.Render(deltaTime, surface, canvas);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.Drawing;
|
||||
using Artemis.Core.Models.Profile;
|
||||
using Artemis.Core.Models.Profile;
|
||||
using Artemis.Core.Models.Surface;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.Core.Plugins.LayerElement
|
||||
{
|
||||
@@ -32,16 +32,16 @@ namespace Artemis.Core.Plugins.LayerElement
|
||||
/// <summary>
|
||||
/// Called before rendering, in the order configured on the layer
|
||||
/// </summary>
|
||||
public abstract void RenderPreProcess(ArtemisSurface surface, Graphics graphics);
|
||||
public abstract void RenderPreProcess(ArtemisSurface surface, SKCanvas canvas);
|
||||
|
||||
/// <summary>
|
||||
/// Called during rendering, in the order configured on the layer
|
||||
/// </summary>
|
||||
public abstract void Render(ArtemisSurface surface, Graphics graphics);
|
||||
public abstract void Render(ArtemisSurface surface, SKCanvas canvas);
|
||||
|
||||
/// <summary>
|
||||
/// Called after rendering, in the order configured on the layer
|
||||
/// </summary>
|
||||
public abstract void RenderPostProcess(ArtemisSurface surface, Graphics graphics);
|
||||
public abstract void RenderPostProcess(ArtemisSurface surface, SKCanvas canvas);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Artemis.Core.Extensions;
|
||||
using RGB.NET.Core;
|
||||
using SkiaSharp;
|
||||
|
||||
@@ -19,12 +20,10 @@ namespace Artemis.Core.RGB.NET
|
||||
|
||||
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(RoundToInt(width), RoundToInt(height)));
|
||||
Canvas = new SKCanvas(Bitmap);
|
||||
Bitmap = new SKBitmap(new SKImageInfo(width.RoundToInt(), height.RoundToInt()));
|
||||
}
|
||||
|
||||
|
||||
public SKBitmap Bitmap { get; private set; }
|
||||
public SKCanvas Canvas { get; private set; }
|
||||
|
||||
public Color ManipulateColor(Rectangle rectangle, BrushRenderTarget renderTarget, Color color)
|
||||
{
|
||||
@@ -46,9 +45,7 @@ namespace Artemis.Core.RGB.NET
|
||||
public void Dispose()
|
||||
{
|
||||
Bitmap?.Dispose();
|
||||
Canvas?.Dispose();
|
||||
Bitmap = null;
|
||||
Canvas = null;
|
||||
}
|
||||
|
||||
private int RoundToInt(double number)
|
||||
|
||||
@@ -8,6 +8,7 @@ using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Core.Services.Storage.Interfaces;
|
||||
using RGB.NET.Core;
|
||||
using Serilog;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.Core.Services
|
||||
{
|
||||
@@ -78,19 +79,24 @@ namespace Artemis.Core.Services
|
||||
}
|
||||
|
||||
// If there is no ready graphics decorator, skip the frame
|
||||
if (_rgbService.GraphicsDecorator?.Canvas == null)
|
||||
return;
|
||||
|
||||
// Render all active modules
|
||||
_rgbService.GraphicsDecorator.Canvas.Clear();
|
||||
lock (_modules)
|
||||
lock (_rgbService.GraphicsDecorator)
|
||||
{
|
||||
foreach (var module in _modules)
|
||||
module.Render(args.DeltaTime, _surfaceService.ActiveSurface, _rgbService.GraphicsDecorator.Canvas);
|
||||
if (_rgbService.GraphicsDecorator?.Bitmap == null)
|
||||
return;
|
||||
|
||||
// Render all active modules
|
||||
using (var canvas = new SKCanvas(_rgbService.GraphicsDecorator.Bitmap))
|
||||
{
|
||||
canvas.Clear(new SKColor(0, 0, 0));
|
||||
lock (_modules)
|
||||
{
|
||||
foreach (var module in _modules)
|
||||
module.Render(args.DeltaTime, _surfaceService.ActiveSurface, canvas);
|
||||
}
|
||||
|
||||
OnFrameRendering(new FrameRenderingEventArgs(_modules, canvas, args.DeltaTime, _rgbService.Surface));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
OnFrameRendering(new FrameRenderingEventArgs(_modules, _rgbService.GraphicsDecorator, args.DeltaTime, _rgbService.Surface));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using System.Drawing;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core.Events;
|
||||
using Artemis.Core.Models.Surface;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.Core.Services
|
||||
{
|
||||
@@ -25,10 +25,7 @@ namespace Artemis.Core.Services
|
||||
// Draw a white overlay over the device
|
||||
void DrawOverlay(object sender, FrameRenderingEventArgs args)
|
||||
{
|
||||
using (var g = Graphics.FromImage(args.Bitmap))
|
||||
{
|
||||
g.FillPath(new SolidBrush(Color.White), device.RenderPath);
|
||||
}
|
||||
args.Canvas.DrawPath(device.RenderPath, new SKPaint {Color = new SKColor(255, 255, 255)});
|
||||
}
|
||||
|
||||
_coreService.FrameRendering += DrawOverlay;
|
||||
|
||||
@@ -30,6 +30,7 @@ namespace Artemis.Core.Services
|
||||
_targetFrameRateSetting = settingsService.GetSetting("Core.TargetFrameRate", 25);
|
||||
|
||||
Surface = RGBSurface.Instance;
|
||||
GraphicsDecorator = new GraphicsDecorator(new ListLedGroup(), 1);
|
||||
|
||||
// Let's throw these for now
|
||||
Surface.Exception += SurfaceOnException;
|
||||
@@ -100,21 +101,22 @@ namespace Artemis.Core.Services
|
||||
|
||||
public void UpdateGraphicsDecorator()
|
||||
{
|
||||
// TODO: Create new one first, then clean up the old one for a smoother transition
|
||||
|
||||
// Clean up the old background if present
|
||||
if (_background != null)
|
||||
lock (GraphicsDecorator)
|
||||
{
|
||||
_background.Brush?.RemoveAllDecorators();
|
||||
_background.Detach();
|
||||
// Clean up the old background if present
|
||||
if (_background != null)
|
||||
{
|
||||
_background.Brush?.RemoveAllDecorators();
|
||||
_background.Detach();
|
||||
}
|
||||
|
||||
// Apply the application wide brush and decorator
|
||||
_background = new ListLedGroup(Surface.Leds) {Brush = new SolidColorBrush(new Color(255, 255, 255, 255))};
|
||||
GraphicsDecorator = new GraphicsDecorator(_background, _renderScaleSetting.Value);
|
||||
_background.Brush.RemoveAllDecorators();
|
||||
|
||||
_background.Brush.AddDecorator(GraphicsDecorator);
|
||||
}
|
||||
|
||||
// Apply the application wide brush and decorator
|
||||
_background = new ListLedGroup(Surface.Leds) {Brush = new SolidColorBrush(new Color(255, 255, 255, 255))};
|
||||
GraphicsDecorator = new GraphicsDecorator(_background, _renderScaleSetting.Value);
|
||||
_background.Brush.RemoveAllDecorators();
|
||||
|
||||
_background.Brush.AddDecorator(GraphicsDecorator);
|
||||
}
|
||||
|
||||
private void OnDeviceLoaded(DeviceEventArgs e)
|
||||
|
||||
@@ -97,7 +97,7 @@
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.1.5.0" newVersion="4.1.5.0" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.1.4.0" newVersion="4.1.4.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
|
||||
@@ -15,13 +15,13 @@
|
||||
<package id="Serilog.Enrichers.Demystify" version="1.0.0-dev-00019" targetFramework="net472" />
|
||||
<package id="Serilog.Sinks.File" version="4.0.0" targetFramework="net472" />
|
||||
<package id="SkiaSharp" version="1.68.1" targetFramework="net472" />
|
||||
<package id="Stylet" version="1.2.0" targetFramework="net472" />
|
||||
<package id="Stylet" version="1.3.0" targetFramework="net472" />
|
||||
<package id="System.Buffers" version="4.5.0" targetFramework="net472" />
|
||||
<package id="System.Collections.Immutable" version="1.6.0-preview8.19405.3" targetFramework="net472" />
|
||||
<package id="System.Diagnostics.DiagnosticSource" version="4.5.1" targetFramework="net472" />
|
||||
<package id="System.Memory" version="4.5.3" targetFramework="net472" />
|
||||
<package id="System.Numerics.Vectors" version="4.6.0-preview5.19224.8" targetFramework="net472" />
|
||||
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net472" />
|
||||
<package id="System.Reflection.Metadata" version="1.7.0-preview8.19405.3" targetFramework="net472" />
|
||||
<package id="System.Runtime.CompilerServices.Unsafe" version="4.6.0-preview8.19405.3" targetFramework="net472" />
|
||||
<package id="System.Runtime.CompilerServices.Unsafe" version="4.6.0" targetFramework="net472" />
|
||||
<package id="System.ValueTuple" version="4.5.0" targetFramework="net472" />
|
||||
</packages>
|
||||
Reference in new issue
Block a user