Skip to content

Commit c311ede

Browse files
committed
Update the managed API to match the C API
1 parent 3aa8f96 commit c311ede

File tree

11 files changed

+372
-470
lines changed

11 files changed

+372
-470
lines changed

VERSIONS.txt

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# dependencies
22
mdoc release 5.7.4.10
33
harfbuzz release 2.6.1
4-
skia release m80
4+
skia release m88
55
xunit release 2.4.1
66
xunit.runner.console release 2.4.1
77
Xamarin.Forms release 4.5.0.725
@@ -30,39 +30,39 @@ Xamarin.Forms reference 4.4.0.991757
3030
# this is related to the API versions, not the library versions
3131
# - milestone: the skia milestone determined by Google/Chromium
3232
# - increment: the C API version increment caused by new APIs
33-
libSkiaSharp milestone 80
34-
libSkiaSharp increment 3
33+
libSkiaSharp milestone 88
34+
libSkiaSharp increment 0
3535

3636
# native sonames
37-
libSkiaSharp soname 80.3.0
37+
libSkiaSharp soname 88.0.0
3838
HarfBuzz soname 0.20601.0
3939

4040
# SkiaSharp.dll
41-
SkiaSharp assembly 2.80.0.0
42-
SkiaSharp file 2.80.3.0
41+
SkiaSharp assembly 2.88.0.0
42+
SkiaSharp file 2.88.0.0
4343

4444
# HarfBuzzSharp.dll
4545
HarfBuzzSharp assembly 1.0.0.0
4646
HarfBuzzSharp file 2.6.1.7
4747

4848
# nuget versions
49-
SkiaSharp nuget 2.80.3
50-
SkiaSharp.NativeAssets.Linux nuget 2.80.3
51-
SkiaSharp.NativeAssets.Linux.NoDependencies nuget 2.80.3
52-
SkiaSharp.NativeAssets.NanoServer nuget 2.80.3
53-
SkiaSharp.NativeAssets.WebAssembly nuget 2.80.3
54-
SkiaSharp.Views nuget 2.80.3
55-
SkiaSharp.Views.Desktop.Common nuget 2.80.3
56-
SkiaSharp.Views.Gtk2 nuget 2.80.3
57-
SkiaSharp.Views.Gtk3 nuget 2.80.3
58-
SkiaSharp.Views.WindowsForms nuget 2.80.3
59-
SkiaSharp.Views.WPF nuget 2.80.3
60-
SkiaSharp.Views.Forms nuget 2.80.3
61-
SkiaSharp.Views.Forms.WPF nuget 2.80.3
62-
SkiaSharp.Views.Forms.GTK nuget 2.80.3
63-
SkiaSharp.Views.Uno nuget 2.80.3
64-
SkiaSharp.HarfBuzz nuget 2.80.3
65-
SkiaSharp.Vulkan.SharpVk nuget 2.80.3
49+
SkiaSharp nuget 2.88.0
50+
SkiaSharp.NativeAssets.Linux nuget 2.88.0
51+
SkiaSharp.NativeAssets.Linux.NoDependencies nuget 2.88.0
52+
SkiaSharp.NativeAssets.NanoServer nuget 2.88.0
53+
SkiaSharp.NativeAssets.WebAssembly nuget 2.88.0
54+
SkiaSharp.Views nuget 2.88.0
55+
SkiaSharp.Views.Desktop.Common nuget 2.88.0
56+
SkiaSharp.Views.Gtk2 nuget 2.88.0
57+
SkiaSharp.Views.Gtk3 nuget 2.88.0
58+
SkiaSharp.Views.WindowsForms nuget 2.88.0
59+
SkiaSharp.Views.WPF nuget 2.88.0
60+
SkiaSharp.Views.Forms nuget 2.88.0
61+
SkiaSharp.Views.Forms.WPF nuget 2.88.0
62+
SkiaSharp.Views.Forms.GTK nuget 2.88.0
63+
SkiaSharp.Views.Uno nuget 2.88.0
64+
SkiaSharp.HarfBuzz nuget 2.88.0
65+
SkiaSharp.Vulkan.SharpVk nuget 2.88.0
6666
HarfBuzzSharp nuget 2.6.1.7
6767
HarfBuzzSharp.NativeAssets.Linux nuget 2.6.1.7
6868
HarfBuzzSharp.NativeAssets.WebAssembly nuget 2.6.1.7

binding/Binding/GRContext.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static GRContext Create (GRBackend backend, IntPtr backendContext) =>
4545
backend switch
4646
{
4747
GRBackend.Metal => throw new NotSupportedException (),
48-
GRBackend.OpenGL => GetObject (SkiaApi.gr_context_make_gl (backendContext)),
48+
GRBackend.OpenGL => GetObject (SkiaApi.gr_direct_context_make_gl (backendContext)),
4949
GRBackend.Vulkan => throw new NotSupportedException (),
5050
GRBackend.Dawn => throw new NotSupportedException (),
5151
_ => throw new ArgumentOutOfRangeException (nameof (backend)),
@@ -57,7 +57,7 @@ public static GRContext CreateGl () =>
5757
CreateGl (null);
5858

5959
public static GRContext CreateGl (GRGlInterface backendContext) =>
60-
GetObject (SkiaApi.gr_context_make_gl (backendContext == null ? IntPtr.Zero : backendContext.Handle));
60+
GetObject (SkiaApi.gr_direct_context_make_gl (backendContext == null ? IntPtr.Zero : backendContext.Handle));
6161

6262
// CreateVulkan
6363

@@ -66,19 +66,19 @@ public static GRContext CreateVulkan (GRVkBackendContext backendContext)
6666
if (backendContext == null)
6767
throw new ArgumentNullException (nameof (backendContext));
6868

69-
return GetObject (SkiaApi.gr_context_make_vulkan (backendContext.ToNative ()));
69+
return GetObject (SkiaApi.gr_direct_context_make_vulkan (backendContext.ToNative ()));
7070
}
7171

7272
//
7373

74-
public GRBackend Backend => SkiaApi.gr_context_get_backend (Handle).FromNative ();
74+
public GRBackend Backend => SkiaApi.gr_direct_context_get_backend (Handle).FromNative ();
7575

7676
public void AbandonContext (bool releaseResources = false)
7777
{
7878
if (releaseResources)
79-
SkiaApi.gr_context_release_resources_and_abandon_context (Handle);
79+
SkiaApi.gr_direct_context_release_resources_and_abandon_context (Handle);
8080
else
81-
SkiaApi.gr_context_abandon_context (Handle);
81+
SkiaApi.gr_direct_context_abandon_context (Handle);
8282
}
8383

8484
[EditorBrowsable (EditorBrowsableState.Never)]
@@ -95,16 +95,16 @@ public void SetResourceCacheLimits (int maxResources, long maxResourceBytes) =>
9595
SetResourceCacheLimit (maxResourceBytes);
9696

9797
public long GetResourceCacheLimit () =>
98-
(long)SkiaApi.gr_context_get_resource_cache_limit (Handle);
98+
(long)SkiaApi.gr_direct_context_get_resource_cache_limit (Handle);
9999

100100
public void SetResourceCacheLimit (long maxResourceBytes) =>
101-
SkiaApi.gr_context_set_resource_cache_limit (Handle, (IntPtr)maxResourceBytes);
101+
SkiaApi.gr_direct_context_set_resource_cache_limit (Handle, (IntPtr)maxResourceBytes);
102102

103103
public void GetResourceCacheUsage (out int maxResources, out long maxResourceBytes)
104104
{
105105
IntPtr maxResBytes;
106106
fixed (int* maxRes = &maxResources) {
107-
SkiaApi.gr_context_get_resource_cache_usage (Handle, maxRes, &maxResBytes);
107+
SkiaApi.gr_direct_context_get_resource_cache_usage (Handle, maxRes, &maxResBytes);
108108
}
109109
maxResourceBytes = (long)maxResBytes;
110110
}
@@ -116,32 +116,32 @@ public void ResetContext (GRBackendState state = GRBackendState.All) =>
116116
ResetContext ((uint)state);
117117

118118
public void ResetContext (uint state) =>
119-
SkiaApi.gr_context_reset_context (Handle, state);
119+
SkiaApi.gr_direct_context_reset_context (Handle, state);
120120

121121
public void Flush () =>
122-
SkiaApi.gr_context_flush (Handle);
122+
SkiaApi.gr_direct_context_flush (Handle);
123123

124124
public int GetMaxSurfaceSampleCount (SKColorType colorType) =>
125-
SkiaApi.gr_context_get_max_surface_sample_count_for_color_type (Handle, colorType.ToNative ());
125+
SkiaApi.gr_direct_context_get_max_surface_sample_count_for_color_type (Handle, colorType.ToNative ());
126126

127127
[EditorBrowsable (EditorBrowsableState.Never)]
128128
[Obsolete]
129129
public int GetRecommendedSampleCount (GRPixelConfig config, float dpi) => 0;
130130

131131
public void DumpMemoryStatistics (SKTraceMemoryDump dump) =>
132-
SkiaApi.gr_context_dump_memory_statistics (Handle, dump?.Handle ?? throw new ArgumentNullException (nameof (dump)));
132+
SkiaApi.gr_direct_context_dump_memory_statistics (Handle, dump?.Handle ?? throw new ArgumentNullException (nameof (dump)));
133133

134134
public void PurgeResources () =>
135-
SkiaApi.gr_context_free_gpu_resources (Handle);
135+
SkiaApi.gr_direct_context_free_gpu_resources (Handle);
136136

137137
public void PurgeUnusedResources (long milliseconds) =>
138-
SkiaApi.gr_context_perform_deferred_cleanup (Handle, milliseconds);
138+
SkiaApi.gr_direct_context_perform_deferred_cleanup (Handle, milliseconds);
139139

140140
public void PurgeUnlockedResources (bool scratchResourcesOnly) =>
141-
SkiaApi.gr_context_purge_unlocked_resources (Handle, scratchResourcesOnly);
141+
SkiaApi.gr_direct_context_purge_unlocked_resources (Handle, scratchResourcesOnly);
142142

143143
public void PurgeUnlockedResources (long bytesToPurge, bool preferScratchResources) =>
144-
SkiaApi.gr_context_purge_unlocked_resources_bytes (Handle, (IntPtr)bytesToPurge, preferScratchResources);
144+
SkiaApi.gr_direct_context_purge_unlocked_resources_bytes (Handle, (IntPtr)bytesToPurge, preferScratchResources);
145145

146146
internal static GRContext GetObject (IntPtr handle) =>
147147
handle == IntPtr.Zero ? null : new GRContext (handle, true);

binding/Binding/SKBitmap.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,9 +459,10 @@ public bool IsImmutable {
459459
get { return SkiaApi.sk_bitmap_is_immutable (Handle); }
460460
}
461461

462+
[Obsolete]
462463
public bool IsVolatile {
463-
get { return SkiaApi.sk_bitmap_is_volatile (Handle); }
464-
set { SkiaApi.sk_bitmap_set_volatile (Handle, value); }
464+
get => false;
465+
set { }
465466
}
466467

467468
[EditorBrowsable (EditorBrowsableState.Never)]

binding/Binding/SKCanvas.cs

Lines changed: 13 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -490,30 +490,25 @@ public void DrawDrawable (SKDrawable drawable, SKPoint p)
490490

491491
// DrawBitmap
492492

493-
public void DrawBitmap (SKBitmap bitmap, SKPoint p, SKPaint paint = null)
494-
{
493+
public void DrawBitmap (SKBitmap bitmap, SKPoint p, SKPaint paint = null) =>
495494
DrawBitmap (bitmap, p.X, p.Y, paint);
496-
}
497495

498496
public void DrawBitmap (SKBitmap bitmap, float x, float y, SKPaint paint = null)
499497
{
500-
if (bitmap == null)
501-
throw new ArgumentNullException (nameof (bitmap));
502-
SkiaApi.sk_canvas_draw_bitmap (Handle, bitmap.Handle, x, y, paint == null ? IntPtr.Zero : paint.Handle);
498+
using var image = SKImage.FromBitmap (bitmap);
499+
DrawImage (image, x, y, paint);
503500
}
504501

505502
public void DrawBitmap (SKBitmap bitmap, SKRect dest, SKPaint paint = null)
506503
{
507-
if (bitmap == null)
508-
throw new ArgumentNullException (nameof (bitmap));
509-
SkiaApi.sk_canvas_draw_bitmap_rect (Handle, bitmap.Handle, null, &dest, paint == null ? IntPtr.Zero : paint.Handle);
504+
using var image = SKImage.FromBitmap (bitmap);
505+
DrawImage (image, dest, paint);
510506
}
511507

512508
public void DrawBitmap (SKBitmap bitmap, SKRect source, SKRect dest, SKPaint paint = null)
513509
{
514-
if (bitmap == null)
515-
throw new ArgumentNullException (nameof (bitmap));
516-
SkiaApi.sk_canvas_draw_bitmap_rect (Handle, bitmap.Handle, &source, &dest, paint == null ? IntPtr.Zero : paint.Handle);
510+
using var image = SKImage.FromBitmap (bitmap);
511+
DrawImage (image, source, dest, paint);
517512
}
518513

519514
// DrawSurface
@@ -839,13 +834,8 @@ public SKData DrawLinkDestinationAnnotation (SKRect rect, string value)
839834

840835
public void DrawBitmapNinePatch (SKBitmap bitmap, SKRectI center, SKRect dst, SKPaint paint = null)
841836
{
842-
if (bitmap == null)
843-
throw new ArgumentNullException (nameof (bitmap));
844-
// the "center" rect must fit inside the bitmap "rect"
845-
if (!SKRect.Create (bitmap.Info.Size).Contains (center))
846-
throw new ArgumentException ("Center rectangle must be contained inside the bitmap bounds.", nameof (center));
847-
848-
SkiaApi.sk_canvas_draw_bitmap_nine (Handle, bitmap.Handle, &center, &dst, paint == null ? IntPtr.Zero : paint.Handle);
837+
using var image = SKImage.FromBitmap (bitmap);
838+
DrawImageNinePatch (image, center, dst, paint);
849839
}
850840

851841
public void DrawImageNinePatch (SKImage image, SKRectI center, SKRect dst, SKPaint paint = null)
@@ -863,11 +853,8 @@ public void DrawImageNinePatch (SKImage image, SKRectI center, SKRect dst, SKPai
863853

864854
public void DrawBitmapLattice (SKBitmap bitmap, int[] xDivs, int[] yDivs, SKRect dst, SKPaint paint = null)
865855
{
866-
var lattice = new SKLattice {
867-
XDivs = xDivs,
868-
YDivs = yDivs
869-
};
870-
DrawBitmapLattice (bitmap, lattice, dst, paint);
856+
using var image = SKImage.FromBitmap (bitmap);
857+
DrawImageLattice (image, xDivs, yDivs, dst, paint);
871858
}
872859

873860
public void DrawImageLattice (SKImage image, int[] xDivs, int[] yDivs, SKRect dst, SKPaint paint = null)
@@ -881,32 +868,8 @@ public void DrawImageLattice (SKImage image, int[] xDivs, int[] yDivs, SKRect ds
881868

882869
public void DrawBitmapLattice (SKBitmap bitmap, SKLattice lattice, SKRect dst, SKPaint paint = null)
883870
{
884-
if (bitmap == null)
885-
throw new ArgumentNullException (nameof (bitmap));
886-
if (lattice.XDivs == null)
887-
throw new ArgumentNullException (nameof (lattice.XDivs));
888-
if (lattice.YDivs == null)
889-
throw new ArgumentNullException (nameof (lattice.YDivs));
890-
891-
fixed (int* x = lattice.XDivs)
892-
fixed (int* y = lattice.YDivs)
893-
fixed (SKLatticeRectType* r = lattice.RectTypes)
894-
fixed (SKColor* c = lattice.Colors) {
895-
var nativeLattice = new SKLatticeInternal {
896-
fBounds = null,
897-
fRectTypes = r,
898-
fXCount = lattice.XDivs.Length,
899-
fXDivs = x,
900-
fYCount = lattice.YDivs.Length,
901-
fYDivs = y,
902-
fColors = (uint*)c,
903-
};
904-
if (lattice.Bounds != null) {
905-
var bounds = lattice.Bounds.Value;
906-
nativeLattice.fBounds = &bounds;
907-
}
908-
SkiaApi.sk_canvas_draw_bitmap_lattice (Handle, bitmap.Handle, &nativeLattice, &dst, paint == null ? IntPtr.Zero : paint.Handle);
909-
}
871+
using var image = SKImage.FromBitmap (bitmap);
872+
DrawImageLattice (image, lattice, dst, paint);
910873
}
911874

912875
public void DrawImageLattice (SKImage image, SKLattice lattice, SKRect dst, SKPaint paint = null)

binding/Binding/SKColorSpaceStructs.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,13 @@ public static SKColorSpaceXyz AdobeRgb {
288288
}
289289
}
290290

291-
public static SKColorSpaceXyz Dcip3 {
291+
[Obsolete ("Use DisplayP3 instead.")]
292+
public static SKColorSpaceXyz Dcip3 => DisplayP3;
293+
294+
public static SKColorSpaceXyz DisplayP3 {
292295
get {
293296
SKColorSpaceXyz xyz;
294-
SkiaApi.sk_colorspace_xyz_named_dcip3 (&xyz);
297+
SkiaApi.sk_colorspace_xyz_named_display_p3 (&xyz);
295298
return xyz;
296299
}
297300
}

binding/Binding/SKImage.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,16 +172,15 @@ public static SKImage FromEncodedData (SKData data, SKRectI subset)
172172
if (data == null)
173173
throw new ArgumentNullException (nameof (data));
174174

175-
var handle = SkiaApi.sk_image_new_from_encoded (data.Handle, &subset);
176-
return GetObject (handle);
175+
return FromEncodedData (data)?.Subset (subset);
177176
}
178177

179178
public static SKImage FromEncodedData (SKData data)
180179
{
181180
if (data == null)
182181
throw new ArgumentNullException (nameof (data));
183182

184-
var handle = SkiaApi.sk_image_new_from_encoded (data.Handle, null);
183+
var handle = SkiaApi.sk_image_new_from_encoded (data.Handle);
185184
return GetObject (handle);
186185
}
187186

@@ -655,7 +654,18 @@ public SKImage ApplyImageFilter (SKImageFilter filter, SKRectI subset, SKRectI c
655654

656655
fixed (SKRectI* os = &outSubset)
657656
fixed (SKPointI* oo = &outOffset) {
658-
return GetObject (SkiaApi.sk_image_make_with_filter (Handle, filter.Handle, &subset, &clipBounds, os, oo));
657+
return GetObject (SkiaApi.sk_image_make_with_filter_legacy (Handle, filter.Handle, &subset, &clipBounds, os, oo));
658+
}
659+
}
660+
661+
public SKImage ApplyImageFilter (GRContext context, SKImageFilter filter, SKRectI subset, SKRectI clipBounds, out SKRectI outSubset, out SKPointI outOffset)
662+
{
663+
if (filter == null)
664+
throw new ArgumentNullException (nameof (filter));
665+
666+
fixed (SKRectI* os = &outSubset)
667+
fixed (SKPointI* oo = &outOffset) {
668+
return GetObject (SkiaApi.sk_image_make_with_filter (Handle, context?.Handle ?? IntPtr.Zero, filter.Handle, &subset, &clipBounds, os, oo));
659669
}
660670
}
661671

binding/Binding/SKPath.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33

44
namespace SkiaSharp
55
{
6+
public enum SKPathConvexity
7+
{
8+
Unknown = 0,
9+
Convex = 1,
10+
Concave = 2,
11+
}
12+
613
public unsafe class SKPath : SKObject, ISKSkipObjectRegistration
714
{
815
internal SKPath (IntPtr handle, bool owns)
@@ -38,13 +45,14 @@ public SKPathFillType FillType {
3845
}
3946

4047
public SKPathConvexity Convexity {
41-
get => SkiaApi.sk_path_get_convexity (Handle);
42-
set => SkiaApi.sk_path_set_convexity (Handle, value);
48+
get => IsConvex ? SKPathConvexity.Convex : SKPathConvexity.Concave;
49+
[Obsolete]
50+
set { }
4351
}
4452

45-
public bool IsConvex => Convexity == SKPathConvexity.Convex;
53+
public bool IsConvex => SkiaApi.sk_path_is_convex(Handle);
4654

47-
public bool IsConcave => Convexity == SKPathConvexity.Concave;
55+
public bool IsConcave => !IsConvex;
4856

4957
public bool IsEmpty => VerbCount == 0;
5058

binding/Binding/SKShader.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ public static SKShader CreateCompose (SKShader shaderA, SKShader shaderB, SKBlen
417417
if (shaderB == null)
418418
throw new ArgumentNullException (nameof (shaderB));
419419

420-
return GetObject (SkiaApi.sk_shader_new_blend (mode, shaderA.Handle, shaderB.Handle, null));
420+
return GetObject (SkiaApi.sk_shader_new_blend (mode, shaderA.Handle, shaderB.Handle));
421421
}
422422

423423
// CreateLerp
@@ -429,7 +429,7 @@ public static SKShader CreateLerp (float weight, SKShader dst, SKShader src)
429429
if (src == null)
430430
throw new ArgumentNullException (nameof (src));
431431

432-
return GetObject (SkiaApi.sk_shader_new_lerp (weight, dst.Handle, src.Handle, null));
432+
return GetObject (SkiaApi.sk_shader_new_lerp (weight, dst.Handle, src.Handle));
433433
}
434434

435435
// CreateColorFilter

0 commit comments

Comments
 (0)