From b2cc3bd27552a71025704236913b874834062d50 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Fri, 12 Mar 2021 08:09:33 +0200 Subject: [PATCH 1/3] Add some of the new APIs --- binding/Binding/GRContext.cs | 26 ++-- binding/Binding/GRRecordingContext.cs | 20 +++ binding/Binding/SKCanvas.cs | 22 ++-- binding/Binding/SKColorSpaceStructs.cs | 2 +- binding/Binding/SKImage.cs | 90 ++++++++----- binding/Binding/SKImageFilter.cs | 10 +- binding/Binding/SKPixmap.cs | 19 ++- binding/Binding/SKSurface.cs | 132 +++++++++++++++---- binding/Binding/SkiaApi.generated.cs | 176 ++++++++++++++++++------- externals/skia | 2 +- tests/Tests/GRContextTest.cs | 34 +++++ 11 files changed, 398 insertions(+), 135 deletions(-) create mode 100644 binding/Binding/GRRecordingContext.cs diff --git a/binding/Binding/GRContext.cs b/binding/Binding/GRContext.cs index 311d1d8f61a..b95ecaa96a3 100644 --- a/binding/Binding/GRContext.cs +++ b/binding/Binding/GRContext.cs @@ -3,7 +3,7 @@ namespace SkiaSharp { - public unsafe class GRContext : SKObject, ISKReferenceCounted, ISKSkipObjectRegistration + public unsafe class GRContext : GRRecordingContext { internal GRContext (IntPtr h, bool owns) : base (h, owns) @@ -126,7 +126,7 @@ public static GRContext CreateMetal (GRMtlBackendContext backendContext, GRConte // - public GRBackend Backend => SkiaApi.gr_direct_context_get_backend (Handle).FromNative (); + public new GRBackend Backend => base.Backend; public void AbandonContext (bool releaseResources = false) { @@ -173,11 +173,21 @@ public void ResetContext (GRBackendState state = GRBackendState.All) => public void ResetContext (uint state) => SkiaApi.gr_direct_context_reset_context (Handle, state); - public void Flush () => - SkiaApi.gr_direct_context_flush (Handle); + public void Flush () => Flush (true); - public int GetMaxSurfaceSampleCount (SKColorType colorType) => - SkiaApi.gr_direct_context_get_max_surface_sample_count_for_color_type (Handle, colorType.ToNative ()); + public void Flush (bool submit, bool synchronous = false) + { + if (submit) + SkiaApi.gr_direct_context_flush_and_submit (Handle, synchronous); + else + SkiaApi.gr_direct_context_flush (Handle); + } + + public void Submit (bool synchronous = false) => + SkiaApi.gr_direct_context_submit (Handle, synchronous); + + public new int GetMaxSurfaceSampleCount (SKColorType colorType) => + GetMaxSurfaceSampleCount (colorType); [EditorBrowsable (EditorBrowsableState.Never)] [Obsolete] @@ -198,7 +208,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) => - handle == IntPtr.Zero ? null : new GRContext (handle, true); + internal static new GRContext GetObject (IntPtr handle, bool owns = true) => + GetOrAddObject (handle, owns, (h, o) => new GRContext (h, o)); } } diff --git a/binding/Binding/GRRecordingContext.cs b/binding/Binding/GRRecordingContext.cs new file mode 100644 index 00000000000..04c2a0ea832 --- /dev/null +++ b/binding/Binding/GRRecordingContext.cs @@ -0,0 +1,20 @@ +using System; + +namespace SkiaSharp +{ + public unsafe class GRRecordingContext : SKObject, ISKReferenceCounted + { + internal GRRecordingContext (IntPtr h, bool owns) + : base (h, owns) + { + } + + public GRBackend Backend => SkiaApi.gr_recording_context_get_backend (Handle).FromNative (); + + 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) => + GetOrAddObject (handle, owns, (h, o) => new GRRecordingContext (h, o)); + } +} diff --git a/binding/Binding/SKCanvas.cs b/binding/Binding/SKCanvas.cs index 29e1062f6d8..5287a71de73 100644 --- a/binding/Binding/SKCanvas.cs +++ b/binding/Binding/SKCanvas.cs @@ -70,10 +70,11 @@ public int SaveLayer () => // DrawColor - public void DrawColor (SKColor color, SKBlendMode mode = SKBlendMode.Src) - { + public void DrawColor (SKColor color, SKBlendMode mode = SKBlendMode.Src) => SkiaApi.sk_canvas_draw_color (Handle, (uint)color, mode); - } + + public void DrawColor (SKColorF color, SKBlendMode mode = SKBlendMode.Src) => + SkiaApi.sk_canvas_draw_color4f (Handle, color, mode); // DrawLine @@ -91,15 +92,14 @@ public void DrawLine (float x0, float y0, float x1, float y1, SKPaint paint) // Clear - public void Clear () - { - DrawColor (SKColors.Empty, SKBlendMode.Src); - } + public void Clear () => + Clear (SKColors.Empty); - public void Clear (SKColor color) - { - DrawColor (color, SKBlendMode.Src); - } + public void Clear (SKColor color) => + SkiaApi.sk_canvas_clear (Handle, (uint)color); + + public void Clear (SKColorF color) => + SkiaApi.sk_canvas_clear_color4f (Handle, color); // Restore* diff --git a/binding/Binding/SKColorSpaceStructs.cs b/binding/Binding/SKColorSpaceStructs.cs index 298a37c1e7f..973ca9847e2 100644 --- a/binding/Binding/SKColorSpaceStructs.cs +++ b/binding/Binding/SKColorSpaceStructs.cs @@ -453,7 +453,7 @@ public SKColorSpaceIccProfile () : this (SkiaApi.sk_colorspace_icc_profile_new (), true) { if (Handle == IntPtr.Zero) - throw new InvalidOperationException ("Unable to create a new SK3dView instance."); + throw new InvalidOperationException ("Unable to create a new SKColorSpaceIccProfile instance."); } protected override void DisposeNative () => diff --git a/binding/Binding/SKImage.cs b/binding/Binding/SKImage.cs index b217566a258..e0f94e59c4c 100644 --- a/binding/Binding/SKImage.cs +++ b/binding/Binding/SKImage.cs @@ -319,32 +319,40 @@ public static SKImage FromTexture (GRContext context, GRGlBackendTextureDesc des return FromTexture (context, texture, desc.Origin, desc.Config.ToColorType (), alpha, null, releaseProc, releaseContext); } - public static SKImage FromTexture (GRContext context, GRBackendTexture texture, SKColorType colorType) - { - return FromTexture (context, texture, GRSurfaceOrigin.BottomLeft, colorType, SKAlphaType.Premul, null, null, null); - } + public static SKImage FromTexture (GRContext context, GRBackendTexture texture, SKColorType colorType) => + FromTexture ((GRRecordingContext)context, texture, colorType); - public static SKImage FromTexture (GRContext context, GRBackendTexture texture, GRSurfaceOrigin origin, SKColorType colorType) - { - return FromTexture (context, texture, origin, colorType, SKAlphaType.Premul, null, null, null); - } + public static SKImage FromTexture (GRContext context, GRBackendTexture texture, GRSurfaceOrigin origin, SKColorType colorType) => + FromTexture ((GRRecordingContext)context, texture, origin, colorType); - public static SKImage FromTexture (GRContext context, GRBackendTexture texture, GRSurfaceOrigin origin, SKColorType colorType, SKAlphaType alpha) - { - return FromTexture (context, texture, origin, colorType, alpha, null, null, null); - } + public static SKImage FromTexture (GRContext context, GRBackendTexture texture, GRSurfaceOrigin origin, SKColorType colorType, SKAlphaType alpha) => + FromTexture ((GRRecordingContext)context, texture, origin, colorType, alpha); - public static SKImage FromTexture (GRContext context, GRBackendTexture texture, GRSurfaceOrigin origin, SKColorType colorType, SKAlphaType alpha, SKColorSpace colorspace) - { - return FromTexture (context, texture, origin, colorType, alpha, colorspace, null, null); - } + public static SKImage FromTexture (GRContext context, GRBackendTexture texture, GRSurfaceOrigin origin, SKColorType colorType, SKAlphaType alpha, SKColorSpace colorspace) => + FromTexture ((GRRecordingContext)context, texture, origin, colorType, alpha, colorspace); - public static SKImage FromTexture (GRContext context, GRBackendTexture texture, GRSurfaceOrigin origin, SKColorType colorType, SKAlphaType alpha, SKColorSpace colorspace, SKImageTextureReleaseDelegate releaseProc) - { - return FromTexture (context, texture, origin, colorType, alpha, colorspace, releaseProc, null); - } + public static SKImage FromTexture (GRContext context, GRBackendTexture texture, GRSurfaceOrigin origin, SKColorType colorType, SKAlphaType alpha, SKColorSpace colorspace, SKImageTextureReleaseDelegate releaseProc) => + FromTexture ((GRRecordingContext)context, texture, origin, colorType, alpha, colorspace, releaseProc); + + public static SKImage FromTexture (GRContext context, GRBackendTexture texture, GRSurfaceOrigin origin, SKColorType colorType, SKAlphaType alpha, SKColorSpace colorspace, SKImageTextureReleaseDelegate releaseProc, object releaseContext) => + FromTexture ((GRRecordingContext)context, texture, origin, colorType, alpha, colorspace, releaseProc, releaseContext); + + public static SKImage FromTexture (GRRecordingContext context, GRBackendTexture texture, SKColorType colorType) => + FromTexture (context, texture, GRSurfaceOrigin.BottomLeft, colorType, SKAlphaType.Premul, null, null, null); + + public static SKImage FromTexture (GRRecordingContext context, GRBackendTexture texture, GRSurfaceOrigin origin, SKColorType colorType) => + FromTexture (context, texture, origin, colorType, SKAlphaType.Premul, null, null, null); + + public static SKImage FromTexture (GRRecordingContext context, GRBackendTexture texture, GRSurfaceOrigin origin, SKColorType colorType, SKAlphaType alpha) => + FromTexture (context, texture, origin, colorType, alpha, null, null, null); - public static SKImage FromTexture (GRContext context, GRBackendTexture texture, GRSurfaceOrigin origin, SKColorType colorType, SKAlphaType alpha, SKColorSpace colorspace, SKImageTextureReleaseDelegate releaseProc, object releaseContext) + public static SKImage FromTexture (GRRecordingContext context, GRBackendTexture texture, GRSurfaceOrigin origin, SKColorType colorType, SKAlphaType alpha, SKColorSpace colorspace) => + FromTexture (context, texture, origin, colorType, alpha, colorspace, null, null); + + public static SKImage FromTexture (GRRecordingContext context, GRBackendTexture texture, GRSurfaceOrigin origin, SKColorType colorType, SKAlphaType alpha, SKColorSpace colorspace, SKImageTextureReleaseDelegate releaseProc) => + FromTexture (context, texture, origin, colorType, alpha, colorspace, releaseProc, null); + + public static SKImage FromTexture (GRRecordingContext context, GRBackendTexture texture, GRSurfaceOrigin origin, SKColorType colorType, SKAlphaType alpha, SKColorSpace colorspace, SKImageTextureReleaseDelegate releaseProc, object releaseContext) { if (context == null) throw new ArgumentNullException (nameof (context)); @@ -389,22 +397,28 @@ public static SKImage FromAdoptedTexture (GRContext context, GRGlBackendTextureD return FromAdoptedTexture (context, texture, desc.Origin, desc.Config.ToColorType (), alpha, null); } - public static SKImage FromAdoptedTexture (GRContext context, GRBackendTexture texture, SKColorType colorType) - { - return FromAdoptedTexture (context, texture, GRSurfaceOrigin.BottomLeft, colorType, SKAlphaType.Premul, null); - } + public static SKImage FromAdoptedTexture (GRContext context, GRBackendTexture texture, SKColorType colorType) => + FromAdoptedTexture ((GRRecordingContext)context, texture, colorType); - public static SKImage FromAdoptedTexture (GRContext context, GRBackendTexture texture, GRSurfaceOrigin origin, SKColorType colorType) - { - return FromAdoptedTexture (context, texture, origin, colorType, SKAlphaType.Premul, null); - } + public static SKImage FromAdoptedTexture (GRContext context, GRBackendTexture texture, GRSurfaceOrigin origin, SKColorType colorType) => + FromAdoptedTexture ((GRRecordingContext)context, texture, origin, colorType); - public static SKImage FromAdoptedTexture (GRContext context, GRBackendTexture texture, GRSurfaceOrigin origin, SKColorType colorType, SKAlphaType alpha) - { - return FromAdoptedTexture (context, texture, origin, colorType, alpha, null); - } + public static SKImage FromAdoptedTexture (GRContext context, GRBackendTexture texture, GRSurfaceOrigin origin, SKColorType colorType, SKAlphaType alpha) => + FromAdoptedTexture ((GRRecordingContext)context, texture, origin, colorType, alpha); + + public static SKImage FromAdoptedTexture (GRContext context, GRBackendTexture texture, GRSurfaceOrigin origin, SKColorType colorType, SKAlphaType alpha, SKColorSpace colorspace) => + FromAdoptedTexture ((GRRecordingContext)context, texture, origin, colorType, alpha, colorspace); + + public static SKImage FromAdoptedTexture (GRRecordingContext context, GRBackendTexture texture, SKColorType colorType) => + FromAdoptedTexture (context, texture, GRSurfaceOrigin.BottomLeft, colorType, SKAlphaType.Premul, null); + + public static SKImage FromAdoptedTexture (GRRecordingContext context, GRBackendTexture texture, GRSurfaceOrigin origin, SKColorType colorType) => + FromAdoptedTexture (context, texture, origin, colorType, SKAlphaType.Premul, null); - public static SKImage FromAdoptedTexture (GRContext context, GRBackendTexture texture, GRSurfaceOrigin origin, SKColorType colorType, SKAlphaType alpha, SKColorSpace colorspace) + public static SKImage FromAdoptedTexture (GRRecordingContext context, GRBackendTexture texture, GRSurfaceOrigin origin, SKColorType colorType, SKAlphaType alpha) => + FromAdoptedTexture (context, texture, origin, colorType, alpha, null); + + public static SKImage FromAdoptedTexture (GRRecordingContext context, GRBackendTexture texture, GRSurfaceOrigin origin, SKColorType colorType, SKAlphaType alpha, SKColorSpace colorspace) { if (context == null) throw new ArgumentNullException (nameof (context)); @@ -555,6 +569,9 @@ public SKPixmap PeekPixels () SkiaApi.sk_image_is_lazy_generated (Handle); public bool IsValid (GRContext context) => + IsValid ((GRRecordingContext)context); + + public bool IsValid (GRRecordingContext context) => SkiaApi.sk_image_is_valid (Handle, context?.Handle ?? IntPtr.Zero); // ReadPixels @@ -661,7 +678,10 @@ public SKImage ApplyImageFilter (SKImageFilter filter, SKRectI subset, SKRectI c } } - public SKImage ApplyImageFilter (GRContext context, SKImageFilter filter, SKRectI subset, SKRectI clipBounds, out SKRectI outSubset, out SKPointI outOffset) + public SKImage ApplyImageFilter (GRContext context, SKImageFilter filter, SKRectI subset, SKRectI clipBounds, out SKRectI outSubset, out SKPointI outOffset) => + ApplyImageFilter ((GRRecordingContext)context, filter, subset, clipBounds, out outSubset, out outOffset); + + public SKImage ApplyImageFilter (GRRecordingContext context, SKImageFilter filter, SKRectI subset, SKRectI clipBounds, out SKRectI outSubset, out SKPointI outOffset) { if (filter == null) throw new ArgumentNullException (nameof (filter)); diff --git a/binding/Binding/SKImageFilter.cs b/binding/Binding/SKImageFilter.cs index 4bb9e274462..00e01e7b221 100644 --- a/binding/Binding/SKImageFilter.cs +++ b/binding/Binding/SKImageFilter.cs @@ -249,14 +249,20 @@ public static SKImageFilter CreateMerge(SKImageFilter[] filters, SKImageFilter.C // CreateDilate - public static SKImageFilter CreateDilate(int radiusX, int radiusY, SKImageFilter input = null, SKImageFilter.CropRect cropRect = null) + public static SKImageFilter CreateDilate(int radiusX, int radiusY, SKImageFilter input = null, SKImageFilter.CropRect cropRect = null) => + CreateDilate ((float)radiusX, (float)radiusY, input, cropRect); + + public static SKImageFilter CreateDilate(float radiusX, float radiusY, SKImageFilter input = null, SKImageFilter.CropRect cropRect = null) { return GetObject(SkiaApi.sk_imagefilter_new_dilate(radiusX, radiusY, input == null ? IntPtr.Zero : input.Handle, cropRect == null ? IntPtr.Zero : cropRect.Handle)); } // CreateErode - public static SKImageFilter CreateErode(int radiusX, int radiusY, SKImageFilter input = null, SKImageFilter.CropRect cropRect = null) + public static SKImageFilter CreateErode(int radiusX, int radiusY, SKImageFilter input = null, SKImageFilter.CropRect cropRect = null) => + CreateErode ((float)radiusX, (float)radiusY, input, cropRect); + + public static SKImageFilter CreateErode(float radiusX, float radiusY, SKImageFilter input = null, SKImageFilter.CropRect cropRect = null) { return GetObject(SkiaApi.sk_imagefilter_new_erode(radiusX, radiusY, input == null ? IntPtr.Zero : input.Handle, cropRect == null ? IntPtr.Zero : cropRect.Handle)); } diff --git a/binding/Binding/SKPixmap.cs b/binding/Binding/SKPixmap.cs index 27d6fc7c2c1..a512dda4b53 100644 --- a/binding/Binding/SKPixmap.cs +++ b/binding/Binding/SKPixmap.cs @@ -393,21 +393,20 @@ public bool ExtractSubset (SKPixmap result, SKRectI subset) // Erase - public bool Erase (SKColor color) - { - return Erase (color, Rect); - } + public bool Erase (SKColor color) => + Erase (color, Rect); - public bool Erase (SKColor color, SKRectI subset) - { - return SkiaApi.sk_pixmap_erase_color (Handle, (uint)color, &subset); - } + public bool Erase (SKColor color, SKRectI subset) => + SkiaApi.sk_pixmap_erase_color (Handle, (uint)color, &subset); public bool Erase (SKColorF color) => - Erase (color, Rect); + Erase (color, null, Rect); public bool Erase (SKColorF color, SKRectI subset) => - SkiaApi.sk_pixmap_erase_color4f (Handle, &color, &subset); + Erase (color, null, subset); + + public bool Erase (SKColorF color, SKColorSpace colorspace, SKRectI subset) => + SkiaApi.sk_pixmap_erase_color4f (Handle, &color, colorspace?.Handle ?? IntPtr.Zero, &subset); // With* diff --git a/binding/Binding/SKSurface.cs b/binding/Binding/SKSurface.cs index c65e7ac677d..277cc3763fc 100644 --- a/binding/Binding/SKSurface.cs +++ b/binding/Binding/SKSurface.cs @@ -123,21 +123,39 @@ public static SKSurface Create (GRContext context, GRBackendRenderTargetDesc des } public static SKSurface Create (GRContext context, GRBackendRenderTarget renderTarget, SKColorType colorType) => - Create (context, renderTarget, GRSurfaceOrigin.BottomLeft, colorType, null, null); + Create ((GRRecordingContext)context, renderTarget, colorType); public static SKSurface Create (GRContext context, GRBackendRenderTarget renderTarget, GRSurfaceOrigin origin, SKColorType colorType) => - Create (context, renderTarget, origin, colorType, null, null); + Create ((GRRecordingContext)context, renderTarget, origin, colorType); public static SKSurface Create (GRContext context, GRBackendRenderTarget renderTarget, GRSurfaceOrigin origin, SKColorType colorType, SKColorSpace colorspace) => - Create (context, renderTarget, origin, colorType, colorspace, null); + Create ((GRRecordingContext)context, renderTarget, origin, colorType, colorspace); public static SKSurface Create (GRContext context, GRBackendRenderTarget renderTarget, SKColorType colorType, SKSurfaceProperties props) => - Create (context, renderTarget, GRSurfaceOrigin.BottomLeft, colorType, null, props); + Create ((GRRecordingContext)context, renderTarget, colorType, props); public static SKSurface Create (GRContext context, GRBackendRenderTarget renderTarget, GRSurfaceOrigin origin, SKColorType colorType, SKSurfaceProperties props) => + Create ((GRRecordingContext)context, renderTarget, origin, colorType, props); + + public static SKSurface Create (GRContext context, GRBackendRenderTarget renderTarget, GRSurfaceOrigin origin, SKColorType colorType, SKColorSpace colorspace, SKSurfaceProperties props) => + Create ((GRRecordingContext)context, renderTarget, origin, colorType, colorspace, props); + + public static SKSurface Create (GRRecordingContext context, GRBackendRenderTarget renderTarget, SKColorType colorType) => + Create (context, renderTarget, GRSurfaceOrigin.BottomLeft, colorType, null, null); + + public static SKSurface Create (GRRecordingContext context, GRBackendRenderTarget renderTarget, GRSurfaceOrigin origin, SKColorType colorType) => + Create (context, renderTarget, origin, colorType, null, null); + + public static SKSurface Create (GRRecordingContext context, GRBackendRenderTarget renderTarget, GRSurfaceOrigin origin, SKColorType colorType, SKColorSpace colorspace) => + Create (context, renderTarget, origin, colorType, colorspace, null); + + public static SKSurface Create (GRRecordingContext context, GRBackendRenderTarget renderTarget, SKColorType colorType, SKSurfaceProperties props) => + Create (context, renderTarget, GRSurfaceOrigin.BottomLeft, colorType, null, props); + + public static SKSurface Create (GRRecordingContext context, GRBackendRenderTarget renderTarget, GRSurfaceOrigin origin, SKColorType colorType, SKSurfaceProperties props) => Create (context, renderTarget, origin, colorType, null, props); - public static SKSurface Create (GRContext context, GRBackendRenderTarget renderTarget, GRSurfaceOrigin origin, SKColorType colorType, SKColorSpace colorspace, SKSurfaceProperties props) + public static SKSurface Create (GRRecordingContext context, GRBackendRenderTarget renderTarget, GRSurfaceOrigin origin, SKColorType colorType, SKColorSpace colorspace, SKSurfaceProperties props) { if (context == null) throw new ArgumentNullException (nameof (context)); @@ -170,27 +188,51 @@ public static SKSurface Create (GRContext context, GRBackendTextureDesc desc, SK Create (context, new GRBackendTexture (desc), desc.Origin, desc.SampleCount, desc.Config.ToColorType (), null, new SKSurfaceProperties (props)); public static SKSurface Create (GRContext context, GRBackendTexture texture, SKColorType colorType) => - Create (context, texture, GRSurfaceOrigin.BottomLeft, 0, colorType, null, null); + Create ((GRRecordingContext)context, texture, colorType); public static SKSurface Create (GRContext context, GRBackendTexture texture, GRSurfaceOrigin origin, SKColorType colorType) => - Create (context, texture, origin, 0, colorType, null, null); + Create ((GRRecordingContext)context, texture, origin, colorType); public static SKSurface Create (GRContext context, GRBackendTexture texture, GRSurfaceOrigin origin, int sampleCount, SKColorType colorType) => - Create (context, texture, origin, sampleCount, colorType, null, null); + Create ((GRRecordingContext)context, texture, origin, sampleCount, colorType); public static SKSurface Create (GRContext context, GRBackendTexture texture, GRSurfaceOrigin origin, int sampleCount, SKColorType colorType, SKColorSpace colorspace) => - Create (context, texture, origin, sampleCount, colorType, colorspace, null); + Create ((GRRecordingContext)context, texture, origin, sampleCount, colorType, colorspace); public static SKSurface Create (GRContext context, GRBackendTexture texture, SKColorType colorType, SKSurfaceProperties props) => - Create (context, texture, GRSurfaceOrigin.BottomLeft, 0, colorType, null, props); + Create ((GRRecordingContext)context, texture, colorType, props); public static SKSurface Create (GRContext context, GRBackendTexture texture, GRSurfaceOrigin origin, SKColorType colorType, SKSurfaceProperties props) => - Create (context, texture, origin, 0, colorType, null, props); + Create ((GRRecordingContext)context, texture, origin, colorType, props); public static SKSurface Create (GRContext context, GRBackendTexture texture, GRSurfaceOrigin origin, int sampleCount, SKColorType colorType, SKSurfaceProperties props) => + Create ((GRRecordingContext)context, texture, origin, sampleCount, colorType, props); + + public static SKSurface Create (GRContext context, GRBackendTexture texture, GRSurfaceOrigin origin, int sampleCount, SKColorType colorType, SKColorSpace colorspace, SKSurfaceProperties props) => + Create ((GRRecordingContext)context, texture, origin, sampleCount, colorType, colorspace, props); + + public static SKSurface Create (GRRecordingContext context, GRBackendTexture texture, SKColorType colorType) => + Create (context, texture, GRSurfaceOrigin.BottomLeft, 0, colorType, null, null); + + public static SKSurface Create (GRRecordingContext context, GRBackendTexture texture, GRSurfaceOrigin origin, SKColorType colorType) => + Create (context, texture, origin, 0, colorType, null, null); + + public static SKSurface Create (GRRecordingContext context, GRBackendTexture texture, GRSurfaceOrigin origin, int sampleCount, SKColorType colorType) => + Create (context, texture, origin, sampleCount, colorType, null, null); + + public static SKSurface Create (GRRecordingContext context, GRBackendTexture texture, GRSurfaceOrigin origin, int sampleCount, SKColorType colorType, SKColorSpace colorspace) => + Create (context, texture, origin, sampleCount, colorType, colorspace, null); + + public static SKSurface Create (GRRecordingContext context, GRBackendTexture texture, SKColorType colorType, SKSurfaceProperties props) => + Create (context, texture, GRSurfaceOrigin.BottomLeft, 0, colorType, null, props); + + public static SKSurface Create (GRRecordingContext context, GRBackendTexture texture, GRSurfaceOrigin origin, SKColorType colorType, SKSurfaceProperties props) => + Create (context, texture, origin, 0, colorType, null, props); + + public static SKSurface Create (GRRecordingContext context, GRBackendTexture texture, GRSurfaceOrigin origin, int sampleCount, SKColorType colorType, SKSurfaceProperties props) => Create (context, texture, origin, sampleCount, colorType, null, props); - public static SKSurface Create (GRContext context, GRBackendTexture texture, GRSurfaceOrigin origin, int sampleCount, SKColorType colorType, SKColorSpace colorspace, SKSurfaceProperties props) + public static SKSurface Create (GRRecordingContext context, GRBackendTexture texture, GRSurfaceOrigin origin, int sampleCount, SKColorType colorType, SKColorSpace colorspace, SKSurfaceProperties props) { if (context == null) throw new ArgumentNullException (nameof (context)); @@ -268,23 +310,41 @@ public static SKSurface CreateAsRenderTarget (GRContext context, GRBackendTextur [Obsolete ("Use Create(GRContext, bool, SKImageInfo, int, SKSurfaceProperties) instead.")] public static SKSurface Create (GRContext context, bool budgeted, SKImageInfo info, int sampleCount, SKSurfaceProps props) => Create (context, budgeted, info, sampleCount, GRSurfaceOrigin.BottomLeft, new SKSurfaceProperties (props), false); - + public static SKSurface Create (GRContext context, bool budgeted, SKImageInfo info) => - Create (context, budgeted, info, 0, GRSurfaceOrigin.BottomLeft, null, false); + Create ((GRRecordingContext)context, budgeted, info); public static SKSurface Create (GRContext context, bool budgeted, SKImageInfo info, int sampleCount) => - Create (context, budgeted, info, sampleCount, GRSurfaceOrigin.BottomLeft, null, false); + Create ((GRRecordingContext)context, budgeted, info, sampleCount); public static SKSurface Create (GRContext context, bool budgeted, SKImageInfo info, int sampleCount, GRSurfaceOrigin origin) => - Create (context, budgeted, info, sampleCount, origin, null, false); + Create ((GRRecordingContext)context, budgeted, info, sampleCount, origin); public static SKSurface Create (GRContext context, bool budgeted, SKImageInfo info, SKSurfaceProperties props) => - Create (context, budgeted, info, 0, GRSurfaceOrigin.BottomLeft, props, false); + Create ((GRRecordingContext)context, budgeted, info, props); public static SKSurface Create (GRContext context, bool budgeted, SKImageInfo info, int sampleCount, SKSurfaceProperties props) => + Create ((GRRecordingContext)context, budgeted, info, sampleCount, props); + + public static SKSurface Create (GRContext context, bool budgeted, SKImageInfo info, int sampleCount, GRSurfaceOrigin origin, SKSurfaceProperties props, bool shouldCreateWithMips) => + Create ((GRRecordingContext)context, budgeted, info, sampleCount, origin, props, false); + + public static SKSurface Create (GRRecordingContext context, bool budgeted, SKImageInfo info) => + Create (context, budgeted, info, 0, GRSurfaceOrigin.BottomLeft, null, false); + + public static SKSurface Create (GRRecordingContext context, bool budgeted, SKImageInfo info, int sampleCount) => + Create (context, budgeted, info, sampleCount, GRSurfaceOrigin.BottomLeft, null, false); + + public static SKSurface Create (GRRecordingContext context, bool budgeted, SKImageInfo info, int sampleCount, GRSurfaceOrigin origin) => + Create (context, budgeted, info, sampleCount, origin, null, false); + + public static SKSurface Create (GRRecordingContext context, bool budgeted, SKImageInfo info, SKSurfaceProperties props) => + Create (context, budgeted, info, 0, GRSurfaceOrigin.BottomLeft, props, false); + + public static SKSurface Create (GRRecordingContext context, bool budgeted, SKImageInfo info, int sampleCount, SKSurfaceProperties props) => Create (context, budgeted, info, sampleCount, GRSurfaceOrigin.BottomLeft, props, false); - public static SKSurface Create (GRContext context, bool budgeted, SKImageInfo info, int sampleCount, GRSurfaceOrigin origin, SKSurfaceProperties props, bool shouldCreateWithMips) + public static SKSurface Create (GRRecordingContext context, bool budgeted, SKImageInfo info, int sampleCount, GRSurfaceOrigin origin, SKSurfaceProperties props, bool shouldCreateWithMips) { if (context == null) throw new ArgumentNullException (nameof (context)); @@ -296,12 +356,21 @@ public static SKSurface Create (GRContext context, bool budgeted, SKImageInfo in #if __MACOS__ || __IOS__ public static SKSurface Create (GRContext context, CoreAnimation.CAMetalLayer layer, GRSurfaceOrigin origin, int sampleCount, SKColorType colorType, out CoreAnimation.ICAMetalDrawable drawable) => - Create (context, layer, origin, sampleCount, colorType, null, null, out drawable); + Create ((GRRecordingContext)context, layer, origin, sampleCount, colorType, out drawable); public static SKSurface Create (GRContext context, CoreAnimation.CAMetalLayer layer, GRSurfaceOrigin origin, int sampleCount, SKColorType colorType, SKColorSpace colorspace, out CoreAnimation.ICAMetalDrawable drawable) => + Create ((GRRecordingContext)context, layer, origin, sampleCount, colorType, colorspace, out drawable); + + public static SKSurface Create (GRContext context, CoreAnimation.CAMetalLayer layer, GRSurfaceOrigin origin, int sampleCount, SKColorType colorType, SKColorSpace colorspace, SKSurfaceProperties props, out CoreAnimation.ICAMetalDrawable drawable) => + Create ((GRRecordingContext)context, layer, origin, sampleCount, colorType, colorspace, props, out drawable); + + public static SKSurface Create (GRRecordingContext context, CoreAnimation.CAMetalLayer layer, GRSurfaceOrigin origin, int sampleCount, SKColorType colorType, out CoreAnimation.ICAMetalDrawable drawable) => + Create (context, layer, origin, sampleCount, colorType, null, null, out drawable); + + public static SKSurface Create (GRRecordingContext context, CoreAnimation.CAMetalLayer layer, GRSurfaceOrigin origin, int sampleCount, SKColorType colorType, SKColorSpace colorspace, out CoreAnimation.ICAMetalDrawable drawable) => Create (context, layer, origin, sampleCount, colorType, colorspace, null, out drawable); - public static SKSurface Create (GRContext context, CoreAnimation.CAMetalLayer layer, GRSurfaceOrigin origin, int sampleCount, SKColorType colorType, SKColorSpace colorspace, SKSurfaceProperties props, out CoreAnimation.ICAMetalDrawable drawable) + public static SKSurface Create (GRRecordingContext context, CoreAnimation.CAMetalLayer layer, GRSurfaceOrigin origin, int sampleCount, SKColorType colorType, SKColorSpace colorspace, SKSurfaceProperties props, out CoreAnimation.ICAMetalDrawable drawable) { void* drawablePtr; var surface = GetObject (SkiaApi.sk_surface_new_metal_layer (context.Handle, (void*)layer.Handle, origin, sampleCount, colorType.ToNative (), colorspace?.Handle ?? IntPtr.Zero, props?.Handle ?? IntPtr.Zero, &drawablePtr)); @@ -309,6 +378,15 @@ public static SKSurface Create (GRContext context, CoreAnimation.CAMetalLayer la return surface; } + public static SKSurface Create (GRRecordingContext context, MetalKit.MTKView view, GRSurfaceOrigin origin, int sampleCount, SKColorType colorType) => + Create (context, view, origin, sampleCount, colorType, null, null); + + public static SKSurface Create (GRRecordingContext context, MetalKit.MTKView view, GRSurfaceOrigin origin, int sampleCount, SKColorType colorType, SKColorSpace colorspace) => + Create (context, view, origin, sampleCount, colorType, colorspace, null); + + public static SKSurface Create (GRRecordingContext context, MetalKit.MTKView view, GRSurfaceOrigin origin, int sampleCount, SKColorType colorType, SKColorSpace colorspace, SKSurfaceProperties props) => + GetObject (SkiaApi.sk_surface_new_metal_view (context.Handle, (void*)view.Handle, origin, sampleCount, colorType.ToNative (), colorspace?.Handle ?? IntPtr.Zero, props?.Handle ?? IntPtr.Zero)); + #endif // NULL surface @@ -336,6 +414,9 @@ public SKSurfaceProps SurfaceProps { public SKSurfaceProperties SurfaceProperties => OwnedBy (SKSurfaceProperties.GetObject (SkiaApi.sk_surface_get_props (Handle), false), this); + public GRRecordingContext Context => + GRRecordingContext.GetObject (SkiaApi.sk_surface_get_recording_context (Handle)); + public SKImage Snapshot () => SKImage.GetObject (SkiaApi.sk_surface_new_image_snapshot (Handle)); @@ -381,8 +462,15 @@ public bool ReadPixels (SKImageInfo dstInfo, IntPtr dstPixels, int dstRowBytes, return result; } - public void Flush () => - SkiaApi.sk_surface_flush (Handle); + public void Flush () => Flush (true); + + public void Flush (bool submit, bool synchronous = false) + { + if (submit) + SkiaApi.sk_surface_flush_and_submit (Handle, synchronous); + else + SkiaApi.sk_surface_flush (Handle); + } internal static SKSurface GetObject (IntPtr handle) => handle == IntPtr.Zero ? null : new SKSurface (handle, true); diff --git a/binding/Binding/SkiaApi.generated.cs b/binding/Binding/SkiaApi.generated.cs index 8f24fc7b036..1d13290f458 100644 --- a/binding/Binding/SkiaApi.generated.cs +++ b/binding/Binding/SkiaApi.generated.cs @@ -440,46 +440,32 @@ internal static void gr_direct_context_flush (gr_direct_context_t context) => (gr_direct_context_flush_delegate ??= GetSymbol ("gr_direct_context_flush")).Invoke (context); #endif - // void gr_direct_context_free_gpu_resources(gr_direct_context_t* context) - #if !USE_DELEGATES - [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] - internal static extern void gr_direct_context_free_gpu_resources (gr_direct_context_t context); - #else - private partial class Delegates { - [UnmanagedFunctionPointer (CallingConvention.Cdecl)] - internal delegate void gr_direct_context_free_gpu_resources (gr_direct_context_t context); - } - private static Delegates.gr_direct_context_free_gpu_resources gr_direct_context_free_gpu_resources_delegate; - internal static void gr_direct_context_free_gpu_resources (gr_direct_context_t context) => - (gr_direct_context_free_gpu_resources_delegate ??= GetSymbol ("gr_direct_context_free_gpu_resources")).Invoke (context); - #endif - - // gr_backend_t gr_direct_context_get_backend(gr_direct_context_t* context) + // void gr_direct_context_flush_and_submit(gr_direct_context_t* context, bool syncCpu) #if !USE_DELEGATES [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] - internal static extern GRBackendNative gr_direct_context_get_backend (gr_direct_context_t context); + internal static extern void gr_direct_context_flush_and_submit (gr_direct_context_t context, [MarshalAs (UnmanagedType.I1)] bool syncCpu); #else private partial class Delegates { [UnmanagedFunctionPointer (CallingConvention.Cdecl)] - internal delegate GRBackendNative gr_direct_context_get_backend (gr_direct_context_t context); + internal delegate void gr_direct_context_flush_and_submit (gr_direct_context_t context, [MarshalAs (UnmanagedType.I1)] bool syncCpu); } - private static Delegates.gr_direct_context_get_backend gr_direct_context_get_backend_delegate; - internal static GRBackendNative gr_direct_context_get_backend (gr_direct_context_t context) => - (gr_direct_context_get_backend_delegate ??= GetSymbol ("gr_direct_context_get_backend")).Invoke (context); + private static Delegates.gr_direct_context_flush_and_submit gr_direct_context_flush_and_submit_delegate; + internal static void gr_direct_context_flush_and_submit (gr_direct_context_t context, [MarshalAs (UnmanagedType.I1)] bool syncCpu) => + (gr_direct_context_flush_and_submit_delegate ??= GetSymbol ("gr_direct_context_flush_and_submit")).Invoke (context, syncCpu); #endif - // int gr_direct_context_get_max_surface_sample_count_for_color_type(gr_direct_context_t* context, sk_colortype_t colorType) + // void gr_direct_context_free_gpu_resources(gr_direct_context_t* context) #if !USE_DELEGATES [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] - internal static extern Int32 gr_direct_context_get_max_surface_sample_count_for_color_type (gr_direct_context_t context, SKColorTypeNative colorType); + internal static extern void gr_direct_context_free_gpu_resources (gr_direct_context_t context); #else private partial class Delegates { [UnmanagedFunctionPointer (CallingConvention.Cdecl)] - internal delegate Int32 gr_direct_context_get_max_surface_sample_count_for_color_type (gr_direct_context_t context, SKColorTypeNative colorType); + internal delegate void gr_direct_context_free_gpu_resources (gr_direct_context_t context); } - private static Delegates.gr_direct_context_get_max_surface_sample_count_for_color_type gr_direct_context_get_max_surface_sample_count_for_color_type_delegate; - internal static Int32 gr_direct_context_get_max_surface_sample_count_for_color_type (gr_direct_context_t context, SKColorTypeNative colorType) => - (gr_direct_context_get_max_surface_sample_count_for_color_type_delegate ??= GetSymbol ("gr_direct_context_get_max_surface_sample_count_for_color_type")).Invoke (context, colorType); + private static Delegates.gr_direct_context_free_gpu_resources gr_direct_context_free_gpu_resources_delegate; + internal static void gr_direct_context_free_gpu_resources (gr_direct_context_t context) => + (gr_direct_context_free_gpu_resources_delegate ??= GetSymbol ("gr_direct_context_free_gpu_resources")).Invoke (context); #endif // size_t gr_direct_context_get_resource_cache_limit(gr_direct_context_t* context) @@ -678,18 +664,20 @@ internal static void gr_direct_context_set_resource_cache_limit (gr_direct_conte (gr_direct_context_set_resource_cache_limit_delegate ??= GetSymbol ("gr_direct_context_set_resource_cache_limit")).Invoke (context, maxResourceBytes); #endif - // void gr_direct_context_unref(gr_direct_context_t* context) + // bool gr_direct_context_submit(gr_direct_context_t* context, bool syncCpu) #if !USE_DELEGATES [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] - internal static extern void gr_direct_context_unref (gr_direct_context_t context); + [return: MarshalAs (UnmanagedType.I1)] + internal static extern bool gr_direct_context_submit (gr_direct_context_t context, [MarshalAs (UnmanagedType.I1)] bool syncCpu); #else private partial class Delegates { [UnmanagedFunctionPointer (CallingConvention.Cdecl)] - internal delegate void gr_direct_context_unref (gr_direct_context_t context); + [return: MarshalAs (UnmanagedType.I1)] + internal delegate bool gr_direct_context_submit (gr_direct_context_t context, [MarshalAs (UnmanagedType.I1)] bool syncCpu); } - private static Delegates.gr_direct_context_unref gr_direct_context_unref_delegate; - internal static void gr_direct_context_unref (gr_direct_context_t context) => - (gr_direct_context_unref_delegate ??= GetSymbol ("gr_direct_context_unref")).Invoke (context); + private static Delegates.gr_direct_context_submit gr_direct_context_submit_delegate; + internal static bool gr_direct_context_submit (gr_direct_context_t context, [MarshalAs (UnmanagedType.I1)] bool syncCpu) => + (gr_direct_context_submit_delegate ??= GetSymbol ("gr_direct_context_submit")).Invoke (context, syncCpu); #endif // const gr_glinterface_t* gr_glinterface_assemble_gl_interface(void* ctx, gr_gl_get_proc get) @@ -808,6 +796,48 @@ internal static bool gr_glinterface_validate (gr_glinterface_t glInterface) => (gr_glinterface_validate_delegate ??= GetSymbol ("gr_glinterface_validate")).Invoke (glInterface); #endif + // gr_backend_t gr_recording_context_get_backend(gr_recording_context_t* context) + #if !USE_DELEGATES + [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] + internal static extern GRBackendNative gr_recording_context_get_backend (gr_recording_context_t context); + #else + private partial class Delegates { + [UnmanagedFunctionPointer (CallingConvention.Cdecl)] + internal delegate GRBackendNative gr_recording_context_get_backend (gr_recording_context_t context); + } + private static Delegates.gr_recording_context_get_backend gr_recording_context_get_backend_delegate; + internal static GRBackendNative gr_recording_context_get_backend (gr_recording_context_t context) => + (gr_recording_context_get_backend_delegate ??= GetSymbol ("gr_recording_context_get_backend")).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 + [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] + internal static extern Int32 gr_recording_context_get_max_surface_sample_count_for_color_type (gr_recording_context_t context, SKColorTypeNative colorType); + #else + private partial class Delegates { + [UnmanagedFunctionPointer (CallingConvention.Cdecl)] + internal delegate Int32 gr_recording_context_get_max_surface_sample_count_for_color_type (gr_recording_context_t context, SKColorTypeNative colorType); + } + private static Delegates.gr_recording_context_get_max_surface_sample_count_for_color_type gr_recording_context_get_max_surface_sample_count_for_color_type_delegate; + internal static Int32 gr_recording_context_get_max_surface_sample_count_for_color_type (gr_recording_context_t context, SKColorTypeNative colorType) => + (gr_recording_context_get_max_surface_sample_count_for_color_type_delegate ??= GetSymbol ("gr_recording_context_get_max_surface_sample_count_for_color_type")).Invoke (context, colorType); + #endif + + // void gr_recording_context_unref(gr_recording_context_t* context) + #if !USE_DELEGATES + [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] + internal static extern void gr_recording_context_unref (gr_recording_context_t context); + #else + private partial class Delegates { + [UnmanagedFunctionPointer (CallingConvention.Cdecl)] + internal delegate void gr_recording_context_unref (gr_recording_context_t context); + } + private static Delegates.gr_recording_context_unref gr_recording_context_unref_delegate; + internal static void gr_recording_context_unref (gr_recording_context_t context) => + (gr_recording_context_unref_delegate ??= GetSymbol ("gr_recording_context_unref")).Invoke (context); + #endif + // void gr_vk_extensions_delete(gr_vk_extensions_t* extensions) #if !USE_DELEGATES [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] @@ -1344,6 +1374,20 @@ internal static void sk_canvas_clear (sk_canvas_t param0, UInt32 param1) => (sk_canvas_clear_delegate ??= GetSymbol ("sk_canvas_clear")).Invoke (param0, param1); #endif + // void sk_canvas_clear_color4f(sk_canvas_t*, sk_color4f_t) + #if !USE_DELEGATES + [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] + internal static extern void sk_canvas_clear_color4f (sk_canvas_t param0, SKColorF param1); + #else + private partial class Delegates { + [UnmanagedFunctionPointer (CallingConvention.Cdecl)] + internal delegate void sk_canvas_clear_color4f (sk_canvas_t param0, SKColorF param1); + } + private static Delegates.sk_canvas_clear_color4f sk_canvas_clear_color4f_delegate; + internal static void sk_canvas_clear_color4f (sk_canvas_t param0, SKColorF param1) => + (sk_canvas_clear_color4f_delegate ??= GetSymbol ("sk_canvas_clear_color4f")).Invoke (param0, param1); + #endif + // void sk_canvas_clip_path_with_operation(sk_canvas_t* t, const sk_path_t* crect, sk_clipop_t op, bool doAA) #if !USE_DELEGATES [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] @@ -1512,6 +1556,20 @@ internal static void sk_canvas_draw_color (sk_canvas_t ccanvas, UInt32 color, SK (sk_canvas_draw_color_delegate ??= GetSymbol ("sk_canvas_draw_color")).Invoke (ccanvas, color, mode); #endif + // void sk_canvas_draw_color4f(sk_canvas_t* ccanvas, sk_color4f_t color, sk_blendmode_t mode) + #if !USE_DELEGATES + [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] + internal static extern void sk_canvas_draw_color4f (sk_canvas_t ccanvas, SKColorF color, SKBlendMode mode); + #else + private partial class Delegates { + [UnmanagedFunctionPointer (CallingConvention.Cdecl)] + internal delegate void sk_canvas_draw_color4f (sk_canvas_t ccanvas, SKColorF color, SKBlendMode mode); + } + private static Delegates.sk_canvas_draw_color4f sk_canvas_draw_color4f_delegate; + internal static void sk_canvas_draw_color4f (sk_canvas_t ccanvas, SKColorF color, SKBlendMode mode) => + (sk_canvas_draw_color4f_delegate ??= GetSymbol ("sk_canvas_draw_color4f")).Invoke (ccanvas, color, mode); + #endif + // void sk_canvas_draw_drawable(sk_canvas_t*, sk_drawable_t*, const sk_matrix_t*) #if !USE_DELEGATES [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] @@ -5384,17 +5442,17 @@ internal static sk_imagefilter_t sk_imagefilter_new_compose (sk_imagefilter_t ou (sk_imagefilter_new_compose_delegate ??= GetSymbol ("sk_imagefilter_new_compose")).Invoke (outer, inner); #endif - // sk_imagefilter_t* sk_imagefilter_new_dilate(int radiusX, int radiusY, sk_imagefilter_t* input, const sk_imagefilter_croprect_t* cropRect) + // sk_imagefilter_t* sk_imagefilter_new_dilate(float radiusX, float radiusY, sk_imagefilter_t* input, const sk_imagefilter_croprect_t* cropRect) #if !USE_DELEGATES [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] - internal static extern sk_imagefilter_t sk_imagefilter_new_dilate (Int32 radiusX, Int32 radiusY, sk_imagefilter_t input, sk_imagefilter_croprect_t cropRect); + internal static extern sk_imagefilter_t sk_imagefilter_new_dilate (Single radiusX, Single radiusY, sk_imagefilter_t input, sk_imagefilter_croprect_t cropRect); #else private partial class Delegates { [UnmanagedFunctionPointer (CallingConvention.Cdecl)] - internal delegate sk_imagefilter_t sk_imagefilter_new_dilate (Int32 radiusX, Int32 radiusY, sk_imagefilter_t input, sk_imagefilter_croprect_t cropRect); + internal delegate sk_imagefilter_t sk_imagefilter_new_dilate (Single radiusX, Single radiusY, sk_imagefilter_t input, sk_imagefilter_croprect_t cropRect); } private static Delegates.sk_imagefilter_new_dilate sk_imagefilter_new_dilate_delegate; - internal static sk_imagefilter_t sk_imagefilter_new_dilate (Int32 radiusX, Int32 radiusY, sk_imagefilter_t input, sk_imagefilter_croprect_t cropRect) => + internal static sk_imagefilter_t sk_imagefilter_new_dilate (Single radiusX, Single radiusY, sk_imagefilter_t input, sk_imagefilter_croprect_t cropRect) => (sk_imagefilter_new_dilate_delegate ??= GetSymbol ("sk_imagefilter_new_dilate")).Invoke (radiusX, radiusY, input, cropRect); #endif @@ -5468,17 +5526,17 @@ internal static sk_imagefilter_t sk_imagefilter_new_drop_shadow_only (Single dx, (sk_imagefilter_new_drop_shadow_only_delegate ??= GetSymbol ("sk_imagefilter_new_drop_shadow_only")).Invoke (dx, dy, sigmaX, sigmaY, color, input, cropRect); #endif - // sk_imagefilter_t* sk_imagefilter_new_erode(int radiusX, int radiusY, sk_imagefilter_t* input, const sk_imagefilter_croprect_t* cropRect) + // sk_imagefilter_t* sk_imagefilter_new_erode(float radiusX, float radiusY, sk_imagefilter_t* input, const sk_imagefilter_croprect_t* cropRect) #if !USE_DELEGATES [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] - internal static extern sk_imagefilter_t sk_imagefilter_new_erode (Int32 radiusX, Int32 radiusY, sk_imagefilter_t input, sk_imagefilter_croprect_t cropRect); + internal static extern sk_imagefilter_t sk_imagefilter_new_erode (Single radiusX, Single radiusY, sk_imagefilter_t input, sk_imagefilter_croprect_t cropRect); #else private partial class Delegates { [UnmanagedFunctionPointer (CallingConvention.Cdecl)] - internal delegate sk_imagefilter_t sk_imagefilter_new_erode (Int32 radiusX, Int32 radiusY, sk_imagefilter_t input, sk_imagefilter_croprect_t cropRect); + internal delegate sk_imagefilter_t sk_imagefilter_new_erode (Single radiusX, Single radiusY, sk_imagefilter_t input, sk_imagefilter_croprect_t cropRect); } private static Delegates.sk_imagefilter_new_erode sk_imagefilter_new_erode_delegate; - internal static sk_imagefilter_t sk_imagefilter_new_erode (Int32 radiusX, Int32 radiusY, sk_imagefilter_t input, sk_imagefilter_croprect_t cropRect) => + internal static sk_imagefilter_t sk_imagefilter_new_erode (Single radiusX, Single radiusY, sk_imagefilter_t input, sk_imagefilter_croprect_t cropRect) => (sk_imagefilter_new_erode_delegate ??= GetSymbol ("sk_imagefilter_new_erode")).Invoke (radiusX, radiusY, input, cropRect); #endif @@ -9058,20 +9116,20 @@ internal static bool sk_pixmap_erase_color (sk_pixmap_t cpixmap, UInt32 color, S (sk_pixmap_erase_color_delegate ??= GetSymbol ("sk_pixmap_erase_color")).Invoke (cpixmap, color, subset); #endif - // bool sk_pixmap_erase_color4f(const sk_pixmap_t* cpixmap, const sk_color4f_t* color, const sk_irect_t* subset) + // bool sk_pixmap_erase_color4f(const sk_pixmap_t* cpixmap, const sk_color4f_t* color, sk_colorspace_t* colorspace, const sk_irect_t* subset) #if !USE_DELEGATES [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs (UnmanagedType.I1)] - internal static extern bool sk_pixmap_erase_color4f (sk_pixmap_t cpixmap, SKColorF* color, SKRectI* subset); + internal static extern bool sk_pixmap_erase_color4f (sk_pixmap_t cpixmap, SKColorF* color, sk_colorspace_t colorspace, SKRectI* subset); #else private partial class Delegates { [UnmanagedFunctionPointer (CallingConvention.Cdecl)] [return: MarshalAs (UnmanagedType.I1)] - internal delegate bool sk_pixmap_erase_color4f (sk_pixmap_t cpixmap, SKColorF* color, SKRectI* subset); + internal delegate bool sk_pixmap_erase_color4f (sk_pixmap_t cpixmap, SKColorF* color, sk_colorspace_t colorspace, SKRectI* subset); } private static Delegates.sk_pixmap_erase_color4f sk_pixmap_erase_color4f_delegate; - internal static bool sk_pixmap_erase_color4f (sk_pixmap_t cpixmap, SKColorF* color, SKRectI* subset) => - (sk_pixmap_erase_color4f_delegate ??= GetSymbol ("sk_pixmap_erase_color4f")).Invoke (cpixmap, color, subset); + internal static bool sk_pixmap_erase_color4f (sk_pixmap_t cpixmap, SKColorF* color, sk_colorspace_t colorspace, SKRectI* subset) => + (sk_pixmap_erase_color4f_delegate ??= GetSymbol ("sk_pixmap_erase_color4f")).Invoke (cpixmap, color, colorspace, subset); #endif // bool sk_pixmap_extract_subset(const sk_pixmap_t* cpixmap, sk_pixmap_t* result, const sk_irect_t* subset) @@ -11618,6 +11676,20 @@ 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 + [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] + internal static extern void sk_surface_flush_and_submit (sk_surface_t surface, [MarshalAs (UnmanagedType.I1)] bool syncCpu); + #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 [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] @@ -11646,6 +11718,20 @@ internal static sk_surfaceprops_t sk_surface_get_props (sk_surface_t surface) => (sk_surface_get_props_delegate ??= GetSymbol ("sk_surface_get_props")).Invoke (surface); #endif + // gr_recording_context_t* sk_surface_get_recording_context(sk_surface_t* surface) + #if !USE_DELEGATES + [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] + internal static extern gr_recording_context_t sk_surface_get_recording_context (sk_surface_t surface); + #else + private partial class Delegates { + [UnmanagedFunctionPointer (CallingConvention.Cdecl)] + internal delegate gr_recording_context_t sk_surface_get_recording_context (sk_surface_t surface); + } + private static Delegates.sk_surface_get_recording_context sk_surface_get_recording_context_delegate; + internal static gr_recording_context_t sk_surface_get_recording_context (sk_surface_t surface) => + (sk_surface_get_recording_context_delegate ??= GetSymbol ("sk_surface_get_recording_context")).Invoke (surface); + #endif + // sk_surface_t* sk_surface_new_backend_render_target(gr_recording_context_t* context, const gr_backendrendertarget_t* target, gr_surfaceorigin_t origin, sk_colortype_t colorType, sk_colorspace_t* colorspace, const sk_surfaceprops_t* props) #if !USE_DELEGATES [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] diff --git a/externals/skia b/externals/skia index cecf0b0ccf4..9f6c7b6ef7d 160000 --- a/externals/skia +++ b/externals/skia @@ -1 +1 @@ -Subproject commit cecf0b0ccf451b67e67695ec2c5031eb3ea52028 +Subproject commit 9f6c7b6ef7d1f722aae2b54be76009ea202049ec diff --git a/tests/Tests/GRContextTest.cs b/tests/Tests/GRContextTest.cs index 64504299cd4..9a9473535db 100644 --- a/tests/Tests/GRContextTest.cs +++ b/tests/Tests/GRContextTest.cs @@ -99,5 +99,39 @@ public void GpuSurfaceIsCreated() } } } + + [Trait(CategoryKey, GpuCategory)] + [SkippableFact] + public void GpuSurfaceReferencesSameContext() + { + using var ctx = CreateGlContext(); + ctx.MakeCurrent(); + + using var grContext = GRContext.CreateGl(); + using var surface = SKSurface.Create(grContext, true, new SKImageInfo(100, 100)); + Assert.NotNull(surface); + + Assert.Equal(grContext, surface.Context); + } + + [Trait(CategoryKey, GpuCategory)] + [SkippableFact] + public void GpuSurfaceCanMakeAnotherSurface() + { + using var ctx = CreateGlContext(); + ctx.MakeCurrent(); + + using var grContext = GRContext.CreateGl(); + + using var surface1 = SKSurface.Create(grContext, true, new SKImageInfo(100, 100)); + Assert.NotNull(surface1); + + using var surface2 = SKSurface.Create(surface1.Context, true, new SKImageInfo(100, 100)); + Assert.NotNull(surface2); + + Assert.NotEqual(surface1, surface2); + Assert.Equal(grContext, surface1.Context); + Assert.Equal(grContext, surface2.Context); + } } } From fbbdab1d4197448166695aaf53eac9e980a5bd5e Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Tue, 12 Oct 2021 18:16:57 +0200 Subject: [PATCH 2/3] this is an un-reffed thing --- binding/Binding/GRRecordingContext.cs | 4 ++-- binding/Binding/SKSurface.cs | 2 +- .../Properties/launchSettings.json | 8 ++++++++ 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 tests/SkiaSharp.NetCore.Tests/Properties/launchSettings.json diff --git a/binding/Binding/GRRecordingContext.cs b/binding/Binding/GRRecordingContext.cs index 04c2a0ea832..efcc74c62c8 100644 --- a/binding/Binding/GRRecordingContext.cs +++ b/binding/Binding/GRRecordingContext.cs @@ -14,7 +14,7 @@ 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) => - GetOrAddObject (handle, owns, (h, o) => new GRRecordingContext (h, o)); + internal static GRRecordingContext GetObject (IntPtr handle, bool owns = true, bool unrefExisting = true) => + GetOrAddObject (handle, owns, unrefExisting, (h, o) => new GRRecordingContext (h, o)); } } diff --git a/binding/Binding/SKSurface.cs b/binding/Binding/SKSurface.cs index 277cc3763fc..b98654b1f51 100644 --- a/binding/Binding/SKSurface.cs +++ b/binding/Binding/SKSurface.cs @@ -415,7 +415,7 @@ public SKSurfaceProps SurfaceProps { OwnedBy (SKSurfaceProperties.GetObject (SkiaApi.sk_surface_get_props (Handle), false), this); public GRRecordingContext Context => - GRRecordingContext.GetObject (SkiaApi.sk_surface_get_recording_context (Handle)); + GRRecordingContext.GetObject (SkiaApi.sk_surface_get_recording_context (Handle), false, unrefExisting: false); public SKImage Snapshot () => SKImage.GetObject (SkiaApi.sk_surface_new_image_snapshot (Handle)); diff --git a/tests/SkiaSharp.NetCore.Tests/Properties/launchSettings.json b/tests/SkiaSharp.NetCore.Tests/Properties/launchSettings.json new file mode 100644 index 00000000000..4fc3cd6aaea --- /dev/null +++ b/tests/SkiaSharp.NetCore.Tests/Properties/launchSettings.json @@ -0,0 +1,8 @@ +{ + "profiles": { + "SkiaSharp.NetCore.Tests": { + "commandName": "Project", + "nativeDebugging": true + } + } +} \ No newline at end of file From 8eaecb3c358ae51b44443a9a59ac934fa1311fdc Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Thu, 14 Oct 2021 07:13:02 +0200 Subject: [PATCH 3/3] native --- externals/skia | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/externals/skia b/externals/skia index 301ce28916f..916a1e9721d 160000 --- a/externals/skia +++ b/externals/skia @@ -1 +1 @@ -Subproject commit 301ce28916f91c88d7c12c24e417be07262eb621 +Subproject commit 916a1e9721de74a05c75391f52393972ed7f736c