Skip to content

Commit 8de547b

Browse files
authored
Update skia to milestone 117 (#3047)
* Update the interop API after the update * Update the C# API after the update * More API changes * Tests * Update externals * Update readme
1 parent 9bea7b2 commit 8de547b

File tree

10 files changed

+172
-74
lines changed

10 files changed

+172
-74
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,6 @@ However, these are easy to install as they are found on the various websites. If
6767

6868
Here are some links to show the differences in our code as compared to Google's code.
6969

70-
What version are we on? [**m116**](https://github.com/google/skia/tree/chrome/m116)
71-
Are we up-to-date with Google? [Compare](https://github.com/mono/skia/compare/skiasharp...google:chrome/m116)
72-
What have we added? [Compare](https://github.com/google/skia/compare/chrome/m116...mono:skiasharp)
70+
What version are we on? [**m116**](https://github.com/google/skia/tree/chrome/m117)
71+
Are we up-to-date with Google? [Compare](https://github.com/mono/skia/compare/skiasharp...google:chrome/m117)
72+
What have we added? [Compare](https://github.com/google/skia/compare/chrome/m117...mono:skiasharp)

binding/SkiaSharp/GRContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public void PurgeUnlockedResources (bool scratchResourcesOnly) =>
153153
public void PurgeUnlockedResources (long bytesToPurge, bool preferScratchResources) =>
154154
SkiaApi.gr_direct_context_purge_unlocked_resources_bytes (Handle, (IntPtr)bytesToPurge, preferScratchResources);
155155

156-
internal static GRContext GetObject (IntPtr handle, bool owns = true) =>
157-
GetOrAddObject (handle, owns, (h, o) => new GRContext (h, o));
156+
internal static GRContext GetObject (IntPtr handle, bool owns = true, bool unrefExisting = true) =>
157+
GetOrAddObject (handle, owns, unrefExisting, (h, o) => new GRContext (h, o));
158158
}
159159
}

binding/SkiaSharp/GRRecordingContext.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,14 @@ internal GRRecordingContext (IntPtr h, bool owns)
2222
public int GetMaxSurfaceSampleCount (SKColorType colorType) =>
2323
SkiaApi.gr_recording_context_get_max_surface_sample_count_for_color_type (Handle, colorType.ToNative ());
2424

25-
internal static GRRecordingContext GetObject (IntPtr handle, bool owns = true, bool unrefExisting = true) =>
26-
GetOrAddObject (handle, owns, unrefExisting, (h, o) => new GRRecordingContext (h, o));
25+
internal static GRRecordingContext GetObject (IntPtr handle, bool owns = true, bool unrefExisting = true)
26+
{
27+
var directContext = SkiaApi.gr_recording_context_get_direct_context (handle);
28+
if (directContext != IntPtr.Zero) {
29+
return GRContext.GetObject (directContext, owns: false, unrefExisting: false);
30+
}
31+
32+
return GetOrAddObject (handle, owns, unrefExisting, (h, o) => new GRRecordingContext (h, o));
33+
}
2734
}
2835
}

binding/SkiaSharp/SKCanvas.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,11 +711,25 @@ public void DrawTextOnPath (string text, SKPath path, SKPoint offset, bool warpG
711711
}
712712
}
713713

714+
// Surface
715+
716+
#nullable enable
717+
public SKSurface? Surface =>
718+
SKSurface.GetObject (SkiaApi.sk_get_surface (Handle), owns: false, unrefExisting: false);
719+
#nullable disable
720+
721+
// Context
722+
723+
#nullable enable
724+
public GRRecordingContext? Context =>
725+
GRRecordingContext.GetObject (SkiaApi.sk_get_recording_context (Handle), owns: false, unrefExisting: false);
726+
#nullable disable
727+
714728
// Flush
715729

716730
public void Flush ()
717731
{
718-
SkiaApi.sk_canvas_flush (Handle);
732+
(Context as GRContext)?.Flush ();
719733
}
720734

721735
// Draw*Annotation

binding/SkiaSharp/SKSurface.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace SkiaSharp
77
{
8-
public unsafe class SKSurface : SKObject, ISKReferenceCounted, ISKSkipObjectRegistration
8+
public unsafe class SKSurface : SKObject, ISKReferenceCounted
99
{
1010
internal SKSurface (IntPtr h, bool owns)
1111
: base (h, owns)
@@ -320,13 +320,16 @@ public bool ReadPixels (SKImageInfo dstInfo, IntPtr dstPixels, int dstRowBytes,
320320

321321
public void Flush (bool submit, bool synchronous = false)
322322
{
323+
if (Context is not GRContext grContext)
324+
return;
325+
323326
if (submit)
324-
SkiaApi.sk_surface_flush_and_submit (Handle, synchronous);
327+
grContext.Flush (submit, synchronous);
325328
else
326-
SkiaApi.sk_surface_flush (Handle);
329+
grContext.Flush ();
327330
}
328331

329-
internal static SKSurface GetObject (IntPtr handle) =>
330-
handle == IntPtr.Zero ? null : new SKSurface (handle, true);
332+
internal static SKSurface GetObject (IntPtr handle, bool owns = true, bool unrefExisting = true) =>
333+
GetOrAddObject (handle, owns, unrefExisting, (h, o) => new SKSurface (h, o));
331334
}
332335
}

binding/SkiaSharp/SkiaApi.generated.cs

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,25 @@ internal static GRBackendNative gr_recording_context_get_backend (gr_recording_c
11441144
(gr_recording_context_get_backend_delegate ??= GetSymbol<Delegates.gr_recording_context_get_backend> ("gr_recording_context_get_backend")).Invoke (context);
11451145
#endif
11461146

1147+
// gr_direct_context_t* gr_recording_context_get_direct_context(gr_recording_context_t* context)
1148+
#if !USE_DELEGATES
1149+
#if USE_LIBRARY_IMPORT
1150+
[LibraryImport (SKIA)]
1151+
internal static partial gr_direct_context_t gr_recording_context_get_direct_context (gr_recording_context_t context);
1152+
#else // !USE_LIBRARY_IMPORT
1153+
[DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)]
1154+
internal static extern gr_direct_context_t gr_recording_context_get_direct_context (gr_recording_context_t context);
1155+
#endif
1156+
#else
1157+
private partial class Delegates {
1158+
[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
1159+
internal delegate gr_direct_context_t gr_recording_context_get_direct_context (gr_recording_context_t context);
1160+
}
1161+
private static Delegates.gr_recording_context_get_direct_context gr_recording_context_get_direct_context_delegate;
1162+
internal static gr_direct_context_t gr_recording_context_get_direct_context (gr_recording_context_t context) =>
1163+
(gr_recording_context_get_direct_context_delegate ??= GetSymbol<Delegates.gr_recording_context_get_direct_context> ("gr_recording_context_get_direct_context")).Invoke (context);
1164+
#endif
1165+
11471166
// int gr_recording_context_get_max_surface_sample_count_for_color_type(gr_recording_context_t* context, sk_colortype_t colorType)
11481167
#if !USE_DELEGATES
11491168
#if USE_LIBRARY_IMPORT
@@ -2750,25 +2769,6 @@ internal static void sk_canvas_draw_vertices (sk_canvas_t ccanvas, sk_vertices_t
27502769
(sk_canvas_draw_vertices_delegate ??= GetSymbol<Delegates.sk_canvas_draw_vertices> ("sk_canvas_draw_vertices")).Invoke (ccanvas, vertices, mode, paint);
27512770
#endif
27522771

2753-
// void sk_canvas_flush(sk_canvas_t* ccanvas)
2754-
#if !USE_DELEGATES
2755-
#if USE_LIBRARY_IMPORT
2756-
[LibraryImport (SKIA)]
2757-
internal static partial void sk_canvas_flush (sk_canvas_t ccanvas);
2758-
#else // !USE_LIBRARY_IMPORT
2759-
[DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)]
2760-
internal static extern void sk_canvas_flush (sk_canvas_t ccanvas);
2761-
#endif
2762-
#else
2763-
private partial class Delegates {
2764-
[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
2765-
internal delegate void sk_canvas_flush (sk_canvas_t ccanvas);
2766-
}
2767-
private static Delegates.sk_canvas_flush sk_canvas_flush_delegate;
2768-
internal static void sk_canvas_flush (sk_canvas_t ccanvas) =>
2769-
(sk_canvas_flush_delegate ??= GetSymbol<Delegates.sk_canvas_flush> ("sk_canvas_flush")).Invoke (ccanvas);
2770-
#endif
2771-
27722772
// bool sk_canvas_get_device_clip_bounds(sk_canvas_t* ccanvas, sk_irect_t* cbounds)
27732773
#if !USE_DELEGATES
27742774
#if USE_LIBRARY_IMPORT
@@ -3164,6 +3164,44 @@ internal static void sk_canvas_translate (sk_canvas_t ccanvas, Single dx, Single
31643164
(sk_canvas_translate_delegate ??= GetSymbol<Delegates.sk_canvas_translate> ("sk_canvas_translate")).Invoke (ccanvas, dx, dy);
31653165
#endif
31663166

3167+
// gr_recording_context_t* sk_get_recording_context(sk_canvas_t* canvas)
3168+
#if !USE_DELEGATES
3169+
#if USE_LIBRARY_IMPORT
3170+
[LibraryImport (SKIA)]
3171+
internal static partial gr_recording_context_t sk_get_recording_context (sk_canvas_t canvas);
3172+
#else // !USE_LIBRARY_IMPORT
3173+
[DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)]
3174+
internal static extern gr_recording_context_t sk_get_recording_context (sk_canvas_t canvas);
3175+
#endif
3176+
#else
3177+
private partial class Delegates {
3178+
[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
3179+
internal delegate gr_recording_context_t sk_get_recording_context (sk_canvas_t canvas);
3180+
}
3181+
private static Delegates.sk_get_recording_context sk_get_recording_context_delegate;
3182+
internal static gr_recording_context_t sk_get_recording_context (sk_canvas_t canvas) =>
3183+
(sk_get_recording_context_delegate ??= GetSymbol<Delegates.sk_get_recording_context> ("sk_get_recording_context")).Invoke (canvas);
3184+
#endif
3185+
3186+
// sk_surface_t* sk_get_surface(sk_canvas_t* canvas)
3187+
#if !USE_DELEGATES
3188+
#if USE_LIBRARY_IMPORT
3189+
[LibraryImport (SKIA)]
3190+
internal static partial sk_surface_t sk_get_surface (sk_canvas_t canvas);
3191+
#else // !USE_LIBRARY_IMPORT
3192+
[DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)]
3193+
internal static extern sk_surface_t sk_get_surface (sk_canvas_t canvas);
3194+
#endif
3195+
#else
3196+
private partial class Delegates {
3197+
[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
3198+
internal delegate sk_surface_t sk_get_surface (sk_canvas_t canvas);
3199+
}
3200+
private static Delegates.sk_get_surface sk_get_surface_delegate;
3201+
internal static sk_surface_t sk_get_surface (sk_canvas_t canvas) =>
3202+
(sk_get_surface_delegate ??= GetSymbol<Delegates.sk_get_surface> ("sk_get_surface")).Invoke (canvas);
3203+
#endif
3204+
31673205
// void sk_nodraw_canvas_destroy(sk_nodraw_canvas_t* t)
31683206
#if !USE_DELEGATES
31693207
#if USE_LIBRARY_IMPORT
@@ -14927,44 +14965,6 @@ internal static void sk_surface_draw (sk_surface_t surface, sk_canvas_t canvas,
1492714965
(sk_surface_draw_delegate ??= GetSymbol<Delegates.sk_surface_draw> ("sk_surface_draw")).Invoke (surface, canvas, x, y, paint);
1492814966
#endif
1492914967

14930-
// void sk_surface_flush(sk_surface_t* surface)
14931-
#if !USE_DELEGATES
14932-
#if USE_LIBRARY_IMPORT
14933-
[LibraryImport (SKIA)]
14934-
internal static partial void sk_surface_flush (sk_surface_t surface);
14935-
#else // !USE_LIBRARY_IMPORT
14936-
[DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)]
14937-
internal static extern void sk_surface_flush (sk_surface_t surface);
14938-
#endif
14939-
#else
14940-
private partial class Delegates {
14941-
[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
14942-
internal delegate void sk_surface_flush (sk_surface_t surface);
14943-
}
14944-
private static Delegates.sk_surface_flush sk_surface_flush_delegate;
14945-
internal static void sk_surface_flush (sk_surface_t surface) =>
14946-
(sk_surface_flush_delegate ??= GetSymbol<Delegates.sk_surface_flush> ("sk_surface_flush")).Invoke (surface);
14947-
#endif
14948-
14949-
// void sk_surface_flush_and_submit(sk_surface_t* surface, bool syncCpu)
14950-
#if !USE_DELEGATES
14951-
#if USE_LIBRARY_IMPORT
14952-
[LibraryImport (SKIA)]
14953-
internal static partial void sk_surface_flush_and_submit (sk_surface_t surface, [MarshalAs (UnmanagedType.I1)] bool syncCpu);
14954-
#else // !USE_LIBRARY_IMPORT
14955-
[DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)]
14956-
internal static extern void sk_surface_flush_and_submit (sk_surface_t surface, [MarshalAs (UnmanagedType.I1)] bool syncCpu);
14957-
#endif
14958-
#else
14959-
private partial class Delegates {
14960-
[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
14961-
internal delegate void sk_surface_flush_and_submit (sk_surface_t surface, [MarshalAs (UnmanagedType.I1)] bool syncCpu);
14962-
}
14963-
private static Delegates.sk_surface_flush_and_submit sk_surface_flush_and_submit_delegate;
14964-
internal static void sk_surface_flush_and_submit (sk_surface_t surface, [MarshalAs (UnmanagedType.I1)] bool syncCpu) =>
14965-
(sk_surface_flush_and_submit_delegate ??= GetSymbol<Delegates.sk_surface_flush_and_submit> ("sk_surface_flush_and_submit")).Invoke (surface, syncCpu);
14966-
#endif
14967-
1496814968
// sk_canvas_t* sk_surface_get_canvas(sk_surface_t*)
1496914969
#if !USE_DELEGATES
1497014970
#if USE_LIBRARY_IMPORT

externals/skia

Submodule skia updated 2316 files

scripts/VERSIONS.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# dependencies
22
mdoc release 5.8.9
33
harfbuzz release 8.3.0
4-
skia release m116
4+
skia release m117
55
xunit release 2.4.2
66
xunit.runner.console release 2.4.2
77
OpenTK release 3.1.0
@@ -23,12 +23,12 @@ ANGLE release chromium/6275
2323
# this is related to the API versions, not the library versions
2424
# - milestone: the skia milestone determined by Google/Chromium
2525
# - increment: the C API version increment caused by new APIs (externals\skia\include\c\sk_types.h)
26-
libSkiaSharp milestone 116
26+
libSkiaSharp milestone 117
2727
libSkiaSharp increment 0
2828

2929
# native sonames
3030
# <milestone>.<increment>.0
31-
libSkiaSharp soname 116.0.0
31+
libSkiaSharp soname 117.0.0
3232
# 0.<60000 + major*100 + minor*10 + micro>.0
3333
HarfBuzz soname 0.60830.0
3434

tests/Tests/SkiaSharp/SKCanvasTest.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,57 @@ namespace SkiaSharp.Tests
77
{
88
public class SKCanvasTest : SKTest
99
{
10+
[Trait(Traits.Category.Key, Traits.Category.Values.Gpu)]
11+
[SkippableFact]
12+
public void GpuCanvasReferencesSameSurface()
13+
{
14+
using var ctx = CreateGlContext();
15+
ctx.MakeCurrent();
16+
17+
using var grContext = GRContext.CreateGl();
18+
using var surface = SKSurface.Create(grContext, true, new SKImageInfo(100, 100));
19+
var canvas = surface.Canvas;
20+
21+
var canvasSurface = canvas.Surface;
22+
Assert.NotNull(canvasSurface);
23+
Assert.Same(surface, canvasSurface);
24+
}
25+
26+
[SkippableFact]
27+
public void RasterCanvasReferencesSameSurface()
28+
{
29+
using var surface = SKSurface.Create(new SKImageInfo(100, 100));
30+
var canvas = surface.Canvas;
31+
32+
var canvasSurface = canvas.Surface;
33+
Assert.NotNull(canvasSurface);
34+
Assert.Same(surface, canvasSurface);
35+
}
36+
37+
[Trait(Traits.Category.Key, Traits.Category.Values.Gpu)]
38+
[SkippableFact]
39+
public void GpuCanvasReferencesSameContext()
40+
{
41+
using var ctx = CreateGlContext();
42+
ctx.MakeCurrent();
43+
44+
using var grContext = GRContext.CreateGl();
45+
using var surface = SKSurface.Create(grContext, true, new SKImageInfo(100, 100));
46+
var canvas = surface.Canvas;
47+
48+
Assert.Equal(grContext, canvas.Context);
49+
}
50+
51+
[Trait(Traits.Category.Key, Traits.Category.Values.Gpu)]
52+
[SkippableFact]
53+
public void RasterCanvasHasNoContext()
54+
{
55+
using var surface = SKSurface.Create(new SKImageInfo(100, 100));
56+
var canvas = surface.Canvas;
57+
58+
Assert.Null(canvas.Context);
59+
}
60+
1061
[Trait(Traits.Category.Key, Traits.Category.Values.Gpu)]
1162
[SkippableFact]
1263
public void CanvasCanRestoreOnGpu()

tests/Tests/SkiaSharp/SKSurfaceTest.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,29 @@ private void DrawGpuTexture(Action<SKSurface, GRBackendTexture> draw)
4848
}
4949
}
5050

51+
[Trait(Traits.Category.Key, Traits.Category.Values.Gpu)]
52+
[SkippableFact]
53+
public void GpuSurfaceHasCanvas()
54+
{
55+
using var ctx = CreateGlContext();
56+
ctx.MakeCurrent();
57+
58+
using var grContext = GRContext.CreateGl();
59+
using var surface = SKSurface.Create(grContext, true, new SKImageInfo(100, 100));
60+
61+
var canvas = surface.Canvas;
62+
Assert.NotNull(canvas);
63+
}
64+
65+
[SkippableFact]
66+
public void RasterSurfaceHasCanvas()
67+
{
68+
using var surface = SKSurface.Create(new SKImageInfo(100, 100));
69+
70+
var canvas = surface.Canvas;
71+
Assert.NotNull(canvas);
72+
}
73+
5174
[SkippableFact]
5275
public void SimpleSurfaceIsUnknownPixelGeometry()
5376
{

0 commit comments

Comments
 (0)