1
- using Avalonia . Platform ;
1
+ using System ;
2
+ using Avalonia . Platform ;
2
3
using Avalonia . Rendering ;
3
4
using SkiaSharp ;
4
5
5
6
namespace Avalonia . Skia . Helpers
6
7
{
7
- public class DrawingContextHelper
8
+ public static class DrawingContextHelper
8
9
{
9
10
/// <summary>
10
11
/// 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
27
28
28
29
return new DrawingContextImpl ( createInfo ) ;
29
30
}
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
+ }
30
97
}
31
98
}
0 commit comments