diff --git a/README.md b/README.md index e20162e2ec..164d1c2182 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/binding/SkiaSharp/GRContext.cs b/binding/SkiaSharp/GRContext.cs index 55071e4187..85ef32eeba 100644 --- a/binding/SkiaSharp/GRContext.cs +++ b/binding/SkiaSharp/GRContext.cs @@ -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)); } } diff --git a/binding/SkiaSharp/GRRecordingContext.cs b/binding/SkiaSharp/GRRecordingContext.cs index 636533197d..3a40694362 100644 --- a/binding/SkiaSharp/GRRecordingContext.cs +++ b/binding/SkiaSharp/GRRecordingContext.cs @@ -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)); + } } } diff --git a/binding/SkiaSharp/SKCanvas.cs b/binding/SkiaSharp/SKCanvas.cs index d1d7300964..81966b9a45 100644 --- a/binding/SkiaSharp/SKCanvas.cs +++ b/binding/SkiaSharp/SKCanvas.cs @@ -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 diff --git a/binding/SkiaSharp/SKSurface.cs b/binding/SkiaSharp/SKSurface.cs index c76938bbf4..4f2fa3c349 100644 --- a/binding/SkiaSharp/SKSurface.cs +++ b/binding/SkiaSharp/SKSurface.cs @@ -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) @@ -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)); } } diff --git a/binding/SkiaSharp/SkiaApi.generated.cs b/binding/SkiaSharp/SkiaApi.generated.cs index a8062dc7f8..067d64a2ad 100644 --- a/binding/SkiaSharp/SkiaApi.generated.cs +++ b/binding/SkiaSharp/SkiaApi.generated.cs @@ -1144,6 +1144,25 @@ internal static GRBackendNative gr_recording_context_get_backend (gr_recording_c (gr_recording_context_get_backend_delegate ??= GetSymbol ("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 ("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 @@ -2750,25 +2769,6 @@ internal static void sk_canvas_draw_vertices (sk_canvas_t ccanvas, sk_vertices_t (sk_canvas_draw_vertices_delegate ??= GetSymbol ("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 ("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 @@ -3164,6 +3164,44 @@ internal static void sk_canvas_translate (sk_canvas_t ccanvas, Single dx, Single (sk_canvas_translate_delegate ??= GetSymbol ("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 ("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 ("sk_get_surface")).Invoke (canvas); + #endif + // void sk_nodraw_canvas_destroy(sk_nodraw_canvas_t* t) #if !USE_DELEGATES #if USE_LIBRARY_IMPORT @@ -14927,44 +14965,6 @@ internal static void sk_surface_draw (sk_surface_t surface, sk_canvas_t canvas, (sk_surface_draw_delegate ??= GetSymbol ("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 ("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 ("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 diff --git a/externals/skia b/externals/skia index c16e913577..5ab716e1f4 160000 --- a/externals/skia +++ b/externals/skia @@ -1 +1 @@ -Subproject commit c16e913577083761d847146db7a04b8d3b3bf755 +Subproject commit 5ab716e1f47fd2f5f258380c6feabc5997728dc7 diff --git a/scripts/VERSIONS.txt b/scripts/VERSIONS.txt index 1de07950fc..1674ae8199 100644 --- a/scripts/VERSIONS.txt +++ b/scripts/VERSIONS.txt @@ -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 @@ -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 # ..0 -libSkiaSharp soname 116.0.0 +libSkiaSharp soname 117.0.0 # 0.<60000 + major*100 + minor*10 + micro>.0 HarfBuzz soname 0.60830.0 diff --git a/tests/Tests/SkiaSharp/SKCanvasTest.cs b/tests/Tests/SkiaSharp/SKCanvasTest.cs index 7ffea35fa8..e40a11f35f 100644 --- a/tests/Tests/SkiaSharp/SKCanvasTest.cs +++ b/tests/Tests/SkiaSharp/SKCanvasTest.cs @@ -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() diff --git a/tests/Tests/SkiaSharp/SKSurfaceTest.cs b/tests/Tests/SkiaSharp/SKSurfaceTest.cs index a4863460ab..a312bf57a0 100644 --- a/tests/Tests/SkiaSharp/SKSurfaceTest.cs +++ b/tests/Tests/SkiaSharp/SKSurfaceTest.cs @@ -48,6 +48,29 @@ private void DrawGpuTexture(Action 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() {