Skip to content

Commit d22e627

Browse files
committed
Merge pull request AvaloniaUI#7605 from AvaloniaUI/feature/skia-layering-extensions
Add Skia Helper Methods to allow applying Skia Filter Effects (Blur, DropShadow, Lighting) to DC content
1 parent 50e2085 commit d22e627

File tree

1 file changed

+69
-2
lines changed

1 file changed

+69
-2
lines changed

src/Skia/Avalonia.Skia/Helpers/DrawingContextHelper.cs

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
using Avalonia.Platform;
1+
using System;
2+
using Avalonia.Platform;
23
using Avalonia.Rendering;
34
using SkiaSharp;
45

56
namespace Avalonia.Skia.Helpers
67
{
7-
public class DrawingContextHelper
8+
public static class DrawingContextHelper
89
{
910
/// <summary>
1011
/// Wrap Skia canvas in drawing context so we can use Avalonia api to render to external skia canvas
@@ -27,5 +28,71 @@ public static IDrawingContextImpl WrapSkiaCanvas(SKCanvas canvas, Vector dpi, IV
2728

2829
return new DrawingContextImpl(createInfo);
2930
}
31+
32+
/// <summary>
33+
/// Unsupported - Wraps a GPU Backed SkiaSurface in an Avalonia DrawingContext.
34+
/// </summary>
35+
[Obsolete]
36+
public static ISkiaDrawingContextImpl WrapSkiaSurface(this SKSurface surface, GRContext grContext, Vector dpi, params IDisposable[] disposables)
37+
{
38+
var createInfo = new DrawingContextImpl.CreateInfo
39+
{
40+
GrContext = grContext,
41+
Surface = surface,
42+
Dpi = dpi,
43+
DisableTextLcdRendering = false,
44+
};
45+
46+
return new DrawingContextImpl(createInfo, disposables);
47+
}
48+
49+
/// <summary>
50+
/// Unsupported - Wraps a non-GPU Backed SkiaSurface in an Avalonia DrawingContext.
51+
/// </summary>
52+
[Obsolete]
53+
public static ISkiaDrawingContextImpl WrapSkiaSurface(this SKSurface surface, Vector dpi, params IDisposable[] disposables)
54+
{
55+
var createInfo = new DrawingContextImpl.CreateInfo
56+
{
57+
Surface = surface,
58+
Dpi = dpi,
59+
DisableTextLcdRendering = false,
60+
};
61+
62+
return new DrawingContextImpl(createInfo, disposables);
63+
}
64+
65+
[Obsolete]
66+
public static ISkiaDrawingContextImpl CreateDrawingContext(Size size, Vector dpi, GRContext grContext = null)
67+
{
68+
if (grContext is null)
69+
{
70+
var surface = SKSurface.Create(
71+
new SKImageInfo(
72+
(int)Math.Ceiling(size.Width),
73+
(int)Math.Ceiling(size.Height),
74+
SKImageInfo.PlatformColorType,
75+
SKAlphaType.Premul));
76+
77+
return WrapSkiaSurface(surface, dpi, surface);
78+
}
79+
else
80+
{
81+
var surface = SKSurface.Create(grContext, false,
82+
new SKImageInfo(
83+
(int)Math.Ceiling(size.Width),
84+
(int)Math.Ceiling(size.Height),
85+
SKImageInfo.PlatformColorType,
86+
SKAlphaType.Premul));
87+
88+
return WrapSkiaSurface(surface, grContext, dpi, surface);
89+
}
90+
}
91+
92+
[Obsolete]
93+
public static void DrawTo(this ISkiaDrawingContextImpl source, ISkiaDrawingContextImpl destination, SKPaint paint = null)
94+
{
95+
destination.SkCanvas.DrawSurface(source.SkSurface, new SKPoint(0, 0), paint);
96+
}
3097
}
3198
}

0 commit comments

Comments
 (0)