diff --git a/binding/Binding/GRContext.cs b/binding/Binding/GRContext.cs index 56b44f258..8f6384822 100644 --- a/binding/Binding/GRContext.cs +++ b/binding/Binding/GRContext.cs @@ -3,7 +3,7 @@ using System.ComponentModel; 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 @@ namespace SkiaSharp // - public GRBackend Backend => SkiaApi.gr_direct_context_get_backend (Handle).FromNative (); + public new GRBackend Backend => base.Backend; public bool IsAbandoned => SkiaApi.gr_direct_context_is_abandoned (Handle); @@ -175,11 +175,21 @@ namespace SkiaSharp 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) => + base.GetMaxSurfaceSampleCount (colorType); [EditorBrowsable (EditorBrowsableState.Never)] [Obsolete] @@ -200,7 +210,7 @@ namespace SkiaSharp 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 000000000..efcc74c62 --- /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, bool unrefExisting = true) => + GetOrAddObject (handle, owns, unrefExisting, (h, o) => new GRRecordingContext (h, o)); + } +} diff --git a/binding/Binding/SKCanvas.cs b/binding/Binding/SKCanvas.cs index 2310f6a98..d435c6ad4 100644 --- a/binding/Binding/SKCanvas.cs +++ b/binding/Binding/SKCanvas.cs @@ -72,10 +72,11 @@ namespace SkiaSharp // 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 @@ -93,15 +94,14 @@ namespace SkiaSharp // 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 298a37c1e..973ca9847 100644 --- a/binding/Binding/SKColorSpaceStructs.cs +++ b/binding/Binding/SKColorSpaceStructs.cs @@ -453,7 +453,7 @@ namespace SkiaSharp : 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 b217566a2..e0f94e59c 100644 --- a/binding/Binding/SKImage.cs +++ b/binding/Binding/SKImage.cs @@ -319,32 +319,40 @@ namespace SkiaSharp 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) + 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 (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 @@ namespace SkiaSharp 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) + 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 (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 @@ namespace SkiaSharp 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 @@ namespace SkiaSharp } } - 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 4bb9e2744..00e01e7b2 100644 --- a/binding/Binding/SKImageFilter.cs +++ b/binding/Binding/SKImageFilter.cs @@ -249,14 +249,20 @@ namespace SkiaSharp // 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 27d6fc7c2..a512dda4b 100644 --- a/binding/Binding/SKPixmap.cs +++ b/binding/Binding/SKPixmap.cs @@ -393,21 +393,20 @@ namespace SkiaSharp // Erase - public bool Erase (SKColor color) - { - return Erase (color, Rect); - } - - public bool Erase (SKColor color, SKRectI subset) - { - return SkiaApi.sk_pixmap_erase_color (Handle, (uint)color, &subset); - } - - public bool Erase (SKColorF color) => + public bool Erase (SKColor color) => Erase (color, Rect); + public bool Erase (SKColor color, SKRectI subset) => + SkiaApi.sk_pixmap_erase_color (Handle, (uint)color, &subset); + + public bool Erase (SKColorF color) => + 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 c65e7ac67..b98654b1f 100644 --- a/binding/Binding/SKSurface.cs +++ b/binding/Binding/SKSurface.cs @@ -123,21 +123,39 @@ namespace SkiaSharp } 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 @@ namespace SkiaSharp 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 @@ namespace SkiaSharp [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 @@ namespace SkiaSharp #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 @@ namespace SkiaSharp 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 @@ namespace SkiaSharp 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), false, unrefExisting: false); + public SKImage Snapshot () => SKImage.GetObject (SkiaApi.sk_surface_new_image_snapshot (Handle)); @@ -381,8 +462,15 @@ namespace SkiaSharp 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 72996a490..c785b5cd2 100644 --- a/binding/Binding/SkiaApi.generated.cs +++ b/binding/Binding/SkiaApi.generated.cs @@ -440,6 +440,20 @@ namespace SkiaSharp (gr_direct_context_flush_delegate ??= GetSymbol ("gr_direct_context_flush")).Invoke (context); #endif + // 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 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 void gr_direct_context_flush_and_submit (gr_direct_context_t context, [MarshalAs (UnmanagedType.I1)] bool syncCpu); + } + 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 + // void gr_direct_context_free_gpu_resources(gr_direct_context_t* context) #if !USE_DELEGATES [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] @@ -454,34 +468,6 @@ namespace SkiaSharp (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) - #if !USE_DELEGATES - [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] - internal static extern GRBackendNative gr_direct_context_get_backend (gr_direct_context_t context); - #else - private partial class Delegates { - [UnmanagedFunctionPointer (CallingConvention.Cdecl)] - internal delegate GRBackendNative gr_direct_context_get_backend (gr_direct_context_t context); - } - 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); - #endif - - // int gr_direct_context_get_max_surface_sample_count_for_color_type(gr_direct_context_t* context, sk_colortype_t colorType) - #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); - #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); - } - 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); - #endif - // size_t gr_direct_context_get_resource_cache_limit(gr_direct_context_t* context) #if !USE_DELEGATES [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] @@ -694,18 +680,20 @@ namespace SkiaSharp (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) @@ -824,6 +812,48 @@ namespace SkiaSharp (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)] @@ -1360,6 +1390,20 @@ namespace SkiaSharp (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)] @@ -1528,6 +1572,20 @@ namespace SkiaSharp (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)] @@ -5400,17 +5458,17 @@ namespace SkiaSharp (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 @@ -5484,17 +5542,17 @@ namespace SkiaSharp (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 @@ -9074,20 +9132,20 @@ namespace SkiaSharp (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) @@ -11634,6 +11692,20 @@ namespace SkiaSharp (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)] @@ -11662,6 +11734,20 @@ namespace SkiaSharp (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 be5de14f9..916a1e972 160000 --- a/externals/skia +++ b/externals/skia @@ -1 +1 @@ -Subproject commit be5de14f94d5c3d36df37e085d65165c62aebe22 +Subproject commit 916a1e9721de74a05c75391f52393972ed7f736c diff --git a/tests/SkiaSharp.NetCore.Tests/Properties/launchSettings.json b/tests/SkiaSharp.NetCore.Tests/Properties/launchSettings.json new file mode 100644 index 000000000..4fc3cd6aa --- /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 diff --git a/tests/Tests/GRContextTest.cs b/tests/Tests/GRContextTest.cs index dfc5d11ca..02cfb1b24 100644 --- a/tests/Tests/GRContextTest.cs +++ b/tests/Tests/GRContextTest.cs @@ -116,5 +116,39 @@ namespace SkiaSharp.Tests } } } + + [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); + } } }