Core - Reworked rendering pipeline to work with different contexts

Core - Added GPU-based Vulkan rendering context
This commit is contained in:
Robert committed 2021-03-21 22:40:23 +01:00
1 parent 34b9d69ed8
commit a02431bb82
17 files changed
+489 -56

No files matched your search

+5 -5
View File
@@ -193,12 +193,12 @@ namespace Artemis.Core
{
canvas.Save();
Renderer.Open(Path, Parent as Folder);
if (Renderer.Canvas == null || Renderer.Path == null || Renderer.Paint == null)
if (Renderer.Surface == null || Renderer.Path == null || Renderer.Paint == null)
throw new ArtemisCoreException("Failed to open folder render context");
SKRect rendererBounds = Renderer.Path.Bounds;
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => e.Enabled))
baseLayerEffect.PreProcess(Renderer.Canvas, rendererBounds, Renderer.Paint);
baseLayerEffect.PreProcess(Renderer.Surface.Canvas, rendererBounds, Renderer.Paint);
// If required, apply the opacity override of the module to the root folder
if (IsRootFolder && Profile.Module.OpacityOverride < 1)
@@ -213,12 +213,12 @@ namespace Artemis.Core
// Iterate the children in reverse because the first layer must be rendered last to end up on top
for (int index = Children.Count - 1; index > -1; index--)
Children[index].Render(Renderer.Canvas);
Children[index].Render(Renderer.Surface.Canvas);
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => e.Enabled))
baseLayerEffect.PostProcess(Renderer.Canvas, rendererBounds, Renderer.Paint);
baseLayerEffect.PostProcess(Renderer.Surface.Canvas, rendererBounds, Renderer.Paint);
canvas.DrawBitmap(Renderer.Bitmap, Renderer.TargetLocation, Renderer.Paint);
canvas.DrawSurface(Renderer.Surface, Renderer.TargetLocation, Renderer.Paint);
}
finally
{
+9 -10
View File
@@ -330,8 +330,7 @@ namespace Artemis.Core
{
canvas.Save();
Renderer.Open(Path, Parent as Folder);
if (Renderer.Canvas == null || Renderer.Path == null || Renderer.Paint == null)
if (Renderer.Surface == null || Renderer.Path == null || Renderer.Paint == null)
throw new ArtemisCoreException("Failed to open layer render context");
// Apply blend mode and color
@@ -357,11 +356,11 @@ namespace Artemis.Core
if (LayerBrush.SupportsTransformation)
{
SKMatrix rotationMatrix = GetTransformMatrix(true, false, false, true);
Renderer.Canvas.SetMatrix(Renderer.Canvas.TotalMatrix.PreConcat(rotationMatrix));
Renderer.Surface.Canvas.SetMatrix(Renderer.Surface.Canvas.TotalMatrix.PreConcat(rotationMatrix));
}
// If a brush is a bad boy and tries to color outside the lines, ensure that its clipped off
Renderer.Canvas.ClipPath(renderPath);
Renderer.Surface.Canvas.ClipPath(renderPath);
DelegateRendering(renderPath.Bounds);
}
else if (General.TransformMode.CurrentValue == LayerTransformMode.Clip)
@@ -370,11 +369,11 @@ namespace Artemis.Core
renderPath.Transform(renderPathMatrix);
// If a brush is a bad boy and tries to color outside the lines, ensure that its clipped off
Renderer.Canvas.ClipPath(renderPath);
Renderer.Surface.Canvas.ClipPath(renderPath);
DelegateRendering(Renderer.Path.Bounds);
}
canvas.DrawBitmap(Renderer.Bitmap, Renderer.TargetLocation, Renderer.Paint);
canvas.DrawSurface(Renderer.Surface, Renderer.TargetLocation, Renderer.Paint);
}
finally
{
@@ -395,16 +394,16 @@ namespace Artemis.Core
{
if (LayerBrush == null)
throw new ArtemisCoreException("The layer is not yet ready for rendering");
if (Renderer.Canvas == null || Renderer.Paint == null)
if (Renderer.Surface == null || Renderer.Paint == null)
throw new ArtemisCoreException("Failed to open layer render context");
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => e.Enabled))
baseLayerEffect.PreProcess(Renderer.Canvas, bounds, Renderer.Paint);
baseLayerEffect.PreProcess(Renderer.Surface.Canvas, bounds, Renderer.Paint);
LayerBrush.InternalRender(Renderer.Canvas, bounds, Renderer.Paint);
LayerBrush.InternalRender(Renderer.Surface.Canvas, bounds, Renderer.Paint);
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => e.Enabled))
baseLayerEffect.PostProcess(Renderer.Canvas, bounds, Renderer.Paint);
baseLayerEffect.PostProcess(Renderer.Surface.Canvas, bounds, Renderer.Paint);
}
internal void CalculateRenderProperties()
+14 -13
View File
@@ -9,8 +9,7 @@ namespace Artemis.Core
private bool _disposed;
private SKRect _lastBounds;
private SKRect _lastParentBounds;
public SKBitmap? Bitmap { get; private set; }
public SKCanvas? Canvas { get; private set; }
public SKSurface? Surface { get; private set; }
public SKPaint? Paint { get; private set; }
public SKPath? Path { get; private set; }
public SKPoint TargetLocation { get; private set; }
@@ -31,22 +30,26 @@ namespace Artemis.Core
if (path.Bounds != _lastBounds || (parent != null && parent.Bounds != _lastParentBounds))
Invalidate();
if (!_valid || Canvas == null)
if (!_valid || Surface == null)
{
SKRect pathBounds = path.Bounds;
int width = (int) pathBounds.Width;
int height = (int) pathBounds.Height;
Bitmap = new SKBitmap(width, height);
SKImageInfo imageInfo = new SKImageInfo(width, height);
if (Constants.SkiaGraphicsContext == null)
Surface = SKSurface.Create(imageInfo);
else
Surface = SKSurface.Create(Constants.SkiaGraphicsContext, true, imageInfo);
Path = new SKPath(path);
Canvas = new SKCanvas(Bitmap);
Path.Transform(SKMatrix.CreateTranslation(pathBounds.Left * -1, pathBounds.Top * -1));
TargetLocation = new SKPoint(pathBounds.Location.X, pathBounds.Location.Y);
if (parent != null)
TargetLocation -= parent.Bounds.Location;
Canvas.ClipPath(Path);
Surface.Canvas.ClipPath(Path);
_lastParentBounds = parent?.Bounds ?? new SKRect();
_lastBounds = path.Bounds;
@@ -55,8 +58,8 @@ namespace Artemis.Core
Paint = new SKPaint();
Canvas.Clear();
Canvas.Save();
Surface.Canvas.Clear();
Surface.Canvas.Save();
IsOpen = true;
}
@@ -66,7 +69,7 @@ namespace Artemis.Core
if (_disposed)
throw new ObjectDisposedException("Renderer");
Canvas?.Restore();
Surface?.Canvas.Restore();
Paint?.Dispose();
Paint = null;
@@ -86,15 +89,13 @@ namespace Artemis.Core
if (IsOpen)
Close();
Canvas?.Dispose();
Surface?.Dispose();
Paint?.Dispose();
Path?.Dispose();
Bitmap?.Dispose();
Canvas = null;
Surface = null;
Paint = null;
Path = null;
Bitmap = null;
_disposed = true;
}