mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Implemented most of the rendering pipeline in SkiaSharp
This commit is contained in:
1 parent
0e3afef6ca
commit
07b2ad87c4
35 files changed
+234
-274
No files matched your search
@@ -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()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user