Skip to content

Commit

Permalink
Update skia to milestone 117 (#3047)
Browse files Browse the repository at this point in the history
* Update the interop API after the update

* Update the C# API after the update

* More API changes

* Tests

* Update externals

* Update readme
  • Loading branch information
mattleibow authored Oct 28, 2024
1 parent 9bea7b2 commit 8de547b
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 74 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ However, these are easy to install as they are found on the various websites. If

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

What version are we on? [**m116**](https://github.com/google/skia/tree/chrome/m116)
Are we up-to-date with Google? [Compare](https://github.com/mono/skia/compare/skiasharp...google:chrome/m116)
What have we added? [Compare](https://github.com/google/skia/compare/chrome/m116...mono:skiasharp)
What version are we on? [**m116**](https://github.com/google/skia/tree/chrome/m117)
Are we up-to-date with Google? [Compare](https://github.com/mono/skia/compare/skiasharp...google:chrome/m117)
What have we added? [Compare](https://github.com/google/skia/compare/chrome/m117...mono:skiasharp)
4 changes: 2 additions & 2 deletions binding/SkiaSharp/GRContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public void PurgeUnlockedResources (bool scratchResourcesOnly) =>
public void PurgeUnlockedResources (long bytesToPurge, bool preferScratchResources) =>
SkiaApi.gr_direct_context_purge_unlocked_resources_bytes (Handle, (IntPtr)bytesToPurge, preferScratchResources);

internal static GRContext GetObject (IntPtr handle, bool owns = true) =>
GetOrAddObject (handle, owns, (h, o) => new GRContext (h, o));
internal static GRContext GetObject (IntPtr handle, bool owns = true, bool unrefExisting = true) =>
GetOrAddObject (handle, owns, unrefExisting, (h, o) => new GRContext (h, o));
}
}
11 changes: 9 additions & 2 deletions binding/SkiaSharp/GRRecordingContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ internal GRRecordingContext (IntPtr h, bool owns)
public int GetMaxSurfaceSampleCount (SKColorType colorType) =>
SkiaApi.gr_recording_context_get_max_surface_sample_count_for_color_type (Handle, colorType.ToNative ());

internal static GRRecordingContext GetObject (IntPtr handle, bool owns = true, bool unrefExisting = true) =>
GetOrAddObject (handle, owns, unrefExisting, (h, o) => new GRRecordingContext (h, o));
internal static GRRecordingContext GetObject (IntPtr handle, bool owns = true, bool unrefExisting = true)
{
var directContext = SkiaApi.gr_recording_context_get_direct_context (handle);
if (directContext != IntPtr.Zero) {
return GRContext.GetObject (directContext, owns: false, unrefExisting: false);
}

return GetOrAddObject (handle, owns, unrefExisting, (h, o) => new GRRecordingContext (h, o));
}
}
}
16 changes: 15 additions & 1 deletion binding/SkiaSharp/SKCanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -711,11 +711,25 @@ public void DrawTextOnPath (string text, SKPath path, SKPoint offset, bool warpG
}
}

// Surface

#nullable enable
public SKSurface? Surface =>
SKSurface.GetObject (SkiaApi.sk_get_surface (Handle), owns: false, unrefExisting: false);
#nullable disable

// Context

#nullable enable
public GRRecordingContext? Context =>
GRRecordingContext.GetObject (SkiaApi.sk_get_recording_context (Handle), owns: false, unrefExisting: false);
#nullable disable

// Flush

public void Flush ()
{
SkiaApi.sk_canvas_flush (Handle);
(Context as GRContext)?.Flush ();
}

// Draw*Annotation
Expand Down
13 changes: 8 additions & 5 deletions binding/SkiaSharp/SKSurface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace SkiaSharp
{
public unsafe class SKSurface : SKObject, ISKReferenceCounted, ISKSkipObjectRegistration
public unsafe class SKSurface : SKObject, ISKReferenceCounted
{
internal SKSurface (IntPtr h, bool owns)
: base (h, owns)
Expand Down Expand Up @@ -320,13 +320,16 @@ public bool ReadPixels (SKImageInfo dstInfo, IntPtr dstPixels, int dstRowBytes,

public void Flush (bool submit, bool synchronous = false)
{
if (Context is not GRContext grContext)
return;

if (submit)
SkiaApi.sk_surface_flush_and_submit (Handle, synchronous);
grContext.Flush (submit, synchronous);
else
SkiaApi.sk_surface_flush (Handle);
grContext.Flush ();
}

internal static SKSurface GetObject (IntPtr handle) =>
handle == IntPtr.Zero ? null : new SKSurface (handle, true);
internal static SKSurface GetObject (IntPtr handle, bool owns = true, bool unrefExisting = true) =>
GetOrAddObject (handle, owns, unrefExisting, (h, o) => new SKSurface (h, o));
}
}
114 changes: 57 additions & 57 deletions binding/SkiaSharp/SkiaApi.generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,25 @@ internal static GRBackendNative gr_recording_context_get_backend (gr_recording_c
(gr_recording_context_get_backend_delegate ??= GetSymbol<Delegates.gr_recording_context_get_backend> ("gr_recording_context_get_backend")).Invoke (context);
#endif

// gr_direct_context_t* gr_recording_context_get_direct_context(gr_recording_context_t* context)
#if !USE_DELEGATES
#if USE_LIBRARY_IMPORT
[LibraryImport (SKIA)]
internal static partial gr_direct_context_t gr_recording_context_get_direct_context (gr_recording_context_t context);
#else // !USE_LIBRARY_IMPORT
[DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)]
internal static extern gr_direct_context_t gr_recording_context_get_direct_context (gr_recording_context_t context);
#endif
#else
private partial class Delegates {
[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
internal delegate gr_direct_context_t gr_recording_context_get_direct_context (gr_recording_context_t context);
}
private static Delegates.gr_recording_context_get_direct_context gr_recording_context_get_direct_context_delegate;
internal static gr_direct_context_t gr_recording_context_get_direct_context (gr_recording_context_t context) =>
(gr_recording_context_get_direct_context_delegate ??= GetSymbol<Delegates.gr_recording_context_get_direct_context> ("gr_recording_context_get_direct_context")).Invoke (context);
#endif

// int gr_recording_context_get_max_surface_sample_count_for_color_type(gr_recording_context_t* context, sk_colortype_t colorType)
#if !USE_DELEGATES
#if USE_LIBRARY_IMPORT
Expand Down Expand Up @@ -2750,25 +2769,6 @@ internal static void sk_canvas_draw_vertices (sk_canvas_t ccanvas, sk_vertices_t
(sk_canvas_draw_vertices_delegate ??= GetSymbol<Delegates.sk_canvas_draw_vertices> ("sk_canvas_draw_vertices")).Invoke (ccanvas, vertices, mode, paint);
#endif

// void sk_canvas_flush(sk_canvas_t* ccanvas)
#if !USE_DELEGATES
#if USE_LIBRARY_IMPORT
[LibraryImport (SKIA)]
internal static partial void sk_canvas_flush (sk_canvas_t ccanvas);
#else // !USE_LIBRARY_IMPORT
[DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)]
internal static extern void sk_canvas_flush (sk_canvas_t ccanvas);
#endif
#else
private partial class Delegates {
[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
internal delegate void sk_canvas_flush (sk_canvas_t ccanvas);
}
private static Delegates.sk_canvas_flush sk_canvas_flush_delegate;
internal static void sk_canvas_flush (sk_canvas_t ccanvas) =>
(sk_canvas_flush_delegate ??= GetSymbol<Delegates.sk_canvas_flush> ("sk_canvas_flush")).Invoke (ccanvas);
#endif

// bool sk_canvas_get_device_clip_bounds(sk_canvas_t* ccanvas, sk_irect_t* cbounds)
#if !USE_DELEGATES
#if USE_LIBRARY_IMPORT
Expand Down Expand Up @@ -3164,6 +3164,44 @@ internal static void sk_canvas_translate (sk_canvas_t ccanvas, Single dx, Single
(sk_canvas_translate_delegate ??= GetSymbol<Delegates.sk_canvas_translate> ("sk_canvas_translate")).Invoke (ccanvas, dx, dy);
#endif

// gr_recording_context_t* sk_get_recording_context(sk_canvas_t* canvas)
#if !USE_DELEGATES
#if USE_LIBRARY_IMPORT
[LibraryImport (SKIA)]
internal static partial gr_recording_context_t sk_get_recording_context (sk_canvas_t canvas);
#else // !USE_LIBRARY_IMPORT
[DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)]
internal static extern gr_recording_context_t sk_get_recording_context (sk_canvas_t canvas);
#endif
#else
private partial class Delegates {
[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
internal delegate gr_recording_context_t sk_get_recording_context (sk_canvas_t canvas);
}
private static Delegates.sk_get_recording_context sk_get_recording_context_delegate;
internal static gr_recording_context_t sk_get_recording_context (sk_canvas_t canvas) =>
(sk_get_recording_context_delegate ??= GetSymbol<Delegates.sk_get_recording_context> ("sk_get_recording_context")).Invoke (canvas);
#endif

// sk_surface_t* sk_get_surface(sk_canvas_t* canvas)
#if !USE_DELEGATES
#if USE_LIBRARY_IMPORT
[LibraryImport (SKIA)]
internal static partial sk_surface_t sk_get_surface (sk_canvas_t canvas);
#else // !USE_LIBRARY_IMPORT
[DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)]
internal static extern sk_surface_t sk_get_surface (sk_canvas_t canvas);
#endif
#else
private partial class Delegates {
[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
internal delegate sk_surface_t sk_get_surface (sk_canvas_t canvas);
}
private static Delegates.sk_get_surface sk_get_surface_delegate;
internal static sk_surface_t sk_get_surface (sk_canvas_t canvas) =>
(sk_get_surface_delegate ??= GetSymbol<Delegates.sk_get_surface> ("sk_get_surface")).Invoke (canvas);
#endif

// void sk_nodraw_canvas_destroy(sk_nodraw_canvas_t* t)
#if !USE_DELEGATES
#if USE_LIBRARY_IMPORT
Expand Down Expand Up @@ -14927,44 +14965,6 @@ internal static void sk_surface_draw (sk_surface_t surface, sk_canvas_t canvas,
(sk_surface_draw_delegate ??= GetSymbol<Delegates.sk_surface_draw> ("sk_surface_draw")).Invoke (surface, canvas, x, y, paint);
#endif

// void sk_surface_flush(sk_surface_t* surface)
#if !USE_DELEGATES
#if USE_LIBRARY_IMPORT
[LibraryImport (SKIA)]
internal static partial void sk_surface_flush (sk_surface_t surface);
#else // !USE_LIBRARY_IMPORT
[DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)]
internal static extern void sk_surface_flush (sk_surface_t surface);
#endif
#else
private partial class Delegates {
[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
internal delegate void sk_surface_flush (sk_surface_t surface);
}
private static Delegates.sk_surface_flush sk_surface_flush_delegate;
internal static void sk_surface_flush (sk_surface_t surface) =>
(sk_surface_flush_delegate ??= GetSymbol<Delegates.sk_surface_flush> ("sk_surface_flush")).Invoke (surface);
#endif

// void sk_surface_flush_and_submit(sk_surface_t* surface, bool syncCpu)
#if !USE_DELEGATES
#if USE_LIBRARY_IMPORT
[LibraryImport (SKIA)]
internal static partial void sk_surface_flush_and_submit (sk_surface_t surface, [MarshalAs (UnmanagedType.I1)] bool syncCpu);
#else // !USE_LIBRARY_IMPORT
[DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)]
internal static extern void sk_surface_flush_and_submit (sk_surface_t surface, [MarshalAs (UnmanagedType.I1)] bool syncCpu);
#endif
#else
private partial class Delegates {
[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
internal delegate void sk_surface_flush_and_submit (sk_surface_t surface, [MarshalAs (UnmanagedType.I1)] bool syncCpu);
}
private static Delegates.sk_surface_flush_and_submit sk_surface_flush_and_submit_delegate;
internal static void sk_surface_flush_and_submit (sk_surface_t surface, [MarshalAs (UnmanagedType.I1)] bool syncCpu) =>
(sk_surface_flush_and_submit_delegate ??= GetSymbol<Delegates.sk_surface_flush_and_submit> ("sk_surface_flush_and_submit")).Invoke (surface, syncCpu);
#endif

// sk_canvas_t* sk_surface_get_canvas(sk_surface_t*)
#if !USE_DELEGATES
#if USE_LIBRARY_IMPORT
Expand Down
2 changes: 1 addition & 1 deletion externals/skia
Submodule skia updated 2316 files
6 changes: 3 additions & 3 deletions scripts/VERSIONS.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# dependencies
mdoc release 5.8.9
harfbuzz release 8.3.0
skia release m116
skia release m117
xunit release 2.4.2
xunit.runner.console release 2.4.2
OpenTK release 3.1.0
Expand All @@ -23,12 +23,12 @@ ANGLE release chromium/6275
# this is related to the API versions, not the library versions
# - milestone: the skia milestone determined by Google/Chromium
# - increment: the C API version increment caused by new APIs (externals\skia\include\c\sk_types.h)
libSkiaSharp milestone 116
libSkiaSharp milestone 117
libSkiaSharp increment 0

# native sonames
# <milestone>.<increment>.0
libSkiaSharp soname 116.0.0
libSkiaSharp soname 117.0.0
# 0.<60000 + major*100 + minor*10 + micro>.0
HarfBuzz soname 0.60830.0

Expand Down
51 changes: 51 additions & 0 deletions tests/Tests/SkiaSharp/SKCanvasTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,57 @@ namespace SkiaSharp.Tests
{
public class SKCanvasTest : SKTest
{
[Trait(Traits.Category.Key, Traits.Category.Values.Gpu)]
[SkippableFact]
public void GpuCanvasReferencesSameSurface()
{
using var ctx = CreateGlContext();
ctx.MakeCurrent();

using var grContext = GRContext.CreateGl();
using var surface = SKSurface.Create(grContext, true, new SKImageInfo(100, 100));
var canvas = surface.Canvas;

var canvasSurface = canvas.Surface;
Assert.NotNull(canvasSurface);
Assert.Same(surface, canvasSurface);
}

[SkippableFact]
public void RasterCanvasReferencesSameSurface()
{
using var surface = SKSurface.Create(new SKImageInfo(100, 100));
var canvas = surface.Canvas;

var canvasSurface = canvas.Surface;
Assert.NotNull(canvasSurface);
Assert.Same(surface, canvasSurface);
}

[Trait(Traits.Category.Key, Traits.Category.Values.Gpu)]
[SkippableFact]
public void GpuCanvasReferencesSameContext()
{
using var ctx = CreateGlContext();
ctx.MakeCurrent();

using var grContext = GRContext.CreateGl();
using var surface = SKSurface.Create(grContext, true, new SKImageInfo(100, 100));
var canvas = surface.Canvas;

Assert.Equal(grContext, canvas.Context);
}

[Trait(Traits.Category.Key, Traits.Category.Values.Gpu)]
[SkippableFact]
public void RasterCanvasHasNoContext()
{
using var surface = SKSurface.Create(new SKImageInfo(100, 100));
var canvas = surface.Canvas;

Assert.Null(canvas.Context);
}

[Trait(Traits.Category.Key, Traits.Category.Values.Gpu)]
[SkippableFact]
public void CanvasCanRestoreOnGpu()
Expand Down
23 changes: 23 additions & 0 deletions tests/Tests/SkiaSharp/SKSurfaceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,29 @@ private void DrawGpuTexture(Action<SKSurface, GRBackendTexture> draw)
}
}

[Trait(Traits.Category.Key, Traits.Category.Values.Gpu)]
[SkippableFact]
public void GpuSurfaceHasCanvas()
{
using var ctx = CreateGlContext();
ctx.MakeCurrent();

using var grContext = GRContext.CreateGl();
using var surface = SKSurface.Create(grContext, true, new SKImageInfo(100, 100));

var canvas = surface.Canvas;
Assert.NotNull(canvas);
}

[SkippableFact]
public void RasterSurfaceHasCanvas()
{
using var surface = SKSurface.Create(new SKImageInfo(100, 100));

var canvas = surface.Canvas;
Assert.NotNull(canvas);
}

[SkippableFact]
public void SimpleSurfaceIsUnknownPixelGeometry()
{
Expand Down

0 comments on commit 8de547b

Please sign in to comment.