Skip to content

Commit

Permalink
Update the managed API to match the C API
Browse files Browse the repository at this point in the history
  • Loading branch information
mattleibow committed Jan 29, 2021
1 parent 3aa8f96 commit c311ede
Show file tree
Hide file tree
Showing 11 changed files with 372 additions and 470 deletions.
46 changes: 23 additions & 23 deletions VERSIONS.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# dependencies
mdoc release 5.7.4.10
harfbuzz release 2.6.1
skia release m80
skia release m88
xunit release 2.4.1
xunit.runner.console release 2.4.1
Xamarin.Forms release 4.5.0.725
Expand Down Expand Up @@ -30,39 +30,39 @@ Xamarin.Forms reference 4.4.0.991757
# this is related to the API versions, not the library versions
# - milestone: the skia milestone determined by Google/Chromium
# - increment: the C API version increment caused by new APIs
libSkiaSharp milestone 80
libSkiaSharp increment 3
libSkiaSharp milestone 88
libSkiaSharp increment 0

# native sonames
libSkiaSharp soname 80.3.0
libSkiaSharp soname 88.0.0
HarfBuzz soname 0.20601.0

# SkiaSharp.dll
SkiaSharp assembly 2.80.0.0
SkiaSharp file 2.80.3.0
SkiaSharp assembly 2.88.0.0
SkiaSharp file 2.88.0.0

# HarfBuzzSharp.dll
HarfBuzzSharp assembly 1.0.0.0
HarfBuzzSharp file 2.6.1.7

# nuget versions
SkiaSharp nuget 2.80.3
SkiaSharp.NativeAssets.Linux nuget 2.80.3
SkiaSharp.NativeAssets.Linux.NoDependencies nuget 2.80.3
SkiaSharp.NativeAssets.NanoServer nuget 2.80.3
SkiaSharp.NativeAssets.WebAssembly nuget 2.80.3
SkiaSharp.Views nuget 2.80.3
SkiaSharp.Views.Desktop.Common nuget 2.80.3
SkiaSharp.Views.Gtk2 nuget 2.80.3
SkiaSharp.Views.Gtk3 nuget 2.80.3
SkiaSharp.Views.WindowsForms nuget 2.80.3
SkiaSharp.Views.WPF nuget 2.80.3
SkiaSharp.Views.Forms nuget 2.80.3
SkiaSharp.Views.Forms.WPF nuget 2.80.3
SkiaSharp.Views.Forms.GTK nuget 2.80.3
SkiaSharp.Views.Uno nuget 2.80.3
SkiaSharp.HarfBuzz nuget 2.80.3
SkiaSharp.Vulkan.SharpVk nuget 2.80.3
SkiaSharp nuget 2.88.0
SkiaSharp.NativeAssets.Linux nuget 2.88.0
SkiaSharp.NativeAssets.Linux.NoDependencies nuget 2.88.0
SkiaSharp.NativeAssets.NanoServer nuget 2.88.0
SkiaSharp.NativeAssets.WebAssembly nuget 2.88.0
SkiaSharp.Views nuget 2.88.0
SkiaSharp.Views.Desktop.Common nuget 2.88.0
SkiaSharp.Views.Gtk2 nuget 2.88.0
SkiaSharp.Views.Gtk3 nuget 2.88.0
SkiaSharp.Views.WindowsForms nuget 2.88.0
SkiaSharp.Views.WPF nuget 2.88.0
SkiaSharp.Views.Forms nuget 2.88.0
SkiaSharp.Views.Forms.WPF nuget 2.88.0
SkiaSharp.Views.Forms.GTK nuget 2.88.0
SkiaSharp.Views.Uno nuget 2.88.0
SkiaSharp.HarfBuzz nuget 2.88.0
SkiaSharp.Vulkan.SharpVk nuget 2.88.0
HarfBuzzSharp nuget 2.6.1.7
HarfBuzzSharp.NativeAssets.Linux nuget 2.6.1.7
HarfBuzzSharp.NativeAssets.WebAssembly nuget 2.6.1.7
Expand Down
34 changes: 17 additions & 17 deletions binding/Binding/GRContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static GRContext Create (GRBackend backend, IntPtr backendContext) =>
backend switch
{
GRBackend.Metal => throw new NotSupportedException (),
GRBackend.OpenGL => GetObject (SkiaApi.gr_context_make_gl (backendContext)),
GRBackend.OpenGL => GetObject (SkiaApi.gr_direct_context_make_gl (backendContext)),
GRBackend.Vulkan => throw new NotSupportedException (),
GRBackend.Dawn => throw new NotSupportedException (),
_ => throw new ArgumentOutOfRangeException (nameof (backend)),
Expand All @@ -57,7 +57,7 @@ public static GRContext CreateGl () =>
CreateGl (null);

public static GRContext CreateGl (GRGlInterface backendContext) =>
GetObject (SkiaApi.gr_context_make_gl (backendContext == null ? IntPtr.Zero : backendContext.Handle));
GetObject (SkiaApi.gr_direct_context_make_gl (backendContext == null ? IntPtr.Zero : backendContext.Handle));

// CreateVulkan

Expand All @@ -66,19 +66,19 @@ public static GRContext CreateVulkan (GRVkBackendContext backendContext)
if (backendContext == null)
throw new ArgumentNullException (nameof (backendContext));

return GetObject (SkiaApi.gr_context_make_vulkan (backendContext.ToNative ()));
return GetObject (SkiaApi.gr_direct_context_make_vulkan (backendContext.ToNative ()));
}

//

public GRBackend Backend => SkiaApi.gr_context_get_backend (Handle).FromNative ();
public GRBackend Backend => SkiaApi.gr_direct_context_get_backend (Handle).FromNative ();

public void AbandonContext (bool releaseResources = false)
{
if (releaseResources)
SkiaApi.gr_context_release_resources_and_abandon_context (Handle);
SkiaApi.gr_direct_context_release_resources_and_abandon_context (Handle);
else
SkiaApi.gr_context_abandon_context (Handle);
SkiaApi.gr_direct_context_abandon_context (Handle);
}

[EditorBrowsable (EditorBrowsableState.Never)]
Expand All @@ -95,16 +95,16 @@ public void SetResourceCacheLimits (int maxResources, long maxResourceBytes) =>
SetResourceCacheLimit (maxResourceBytes);

public long GetResourceCacheLimit () =>
(long)SkiaApi.gr_context_get_resource_cache_limit (Handle);
(long)SkiaApi.gr_direct_context_get_resource_cache_limit (Handle);

public void SetResourceCacheLimit (long maxResourceBytes) =>
SkiaApi.gr_context_set_resource_cache_limit (Handle, (IntPtr)maxResourceBytes);
SkiaApi.gr_direct_context_set_resource_cache_limit (Handle, (IntPtr)maxResourceBytes);

public void GetResourceCacheUsage (out int maxResources, out long maxResourceBytes)
{
IntPtr maxResBytes;
fixed (int* maxRes = &maxResources) {
SkiaApi.gr_context_get_resource_cache_usage (Handle, maxRes, &maxResBytes);
SkiaApi.gr_direct_context_get_resource_cache_usage (Handle, maxRes, &maxResBytes);
}
maxResourceBytes = (long)maxResBytes;
}
Expand All @@ -116,32 +116,32 @@ public void ResetContext (GRBackendState state = GRBackendState.All) =>
ResetContext ((uint)state);

public void ResetContext (uint state) =>
SkiaApi.gr_context_reset_context (Handle, state);
SkiaApi.gr_direct_context_reset_context (Handle, state);

public void Flush () =>
SkiaApi.gr_context_flush (Handle);
SkiaApi.gr_direct_context_flush (Handle);

public int GetMaxSurfaceSampleCount (SKColorType colorType) =>
SkiaApi.gr_context_get_max_surface_sample_count_for_color_type (Handle, colorType.ToNative ());
SkiaApi.gr_direct_context_get_max_surface_sample_count_for_color_type (Handle, colorType.ToNative ());

[EditorBrowsable (EditorBrowsableState.Never)]
[Obsolete]
public int GetRecommendedSampleCount (GRPixelConfig config, float dpi) => 0;

public void DumpMemoryStatistics (SKTraceMemoryDump dump) =>
SkiaApi.gr_context_dump_memory_statistics (Handle, dump?.Handle ?? throw new ArgumentNullException (nameof (dump)));
SkiaApi.gr_direct_context_dump_memory_statistics (Handle, dump?.Handle ?? throw new ArgumentNullException (nameof (dump)));

public void PurgeResources () =>
SkiaApi.gr_context_free_gpu_resources (Handle);
SkiaApi.gr_direct_context_free_gpu_resources (Handle);

public void PurgeUnusedResources (long milliseconds) =>
SkiaApi.gr_context_perform_deferred_cleanup (Handle, milliseconds);
SkiaApi.gr_direct_context_perform_deferred_cleanup (Handle, milliseconds);

public void PurgeUnlockedResources (bool scratchResourcesOnly) =>
SkiaApi.gr_context_purge_unlocked_resources (Handle, scratchResourcesOnly);
SkiaApi.gr_direct_context_purge_unlocked_resources (Handle, scratchResourcesOnly);

public void PurgeUnlockedResources (long bytesToPurge, bool preferScratchResources) =>
SkiaApi.gr_context_purge_unlocked_resources_bytes (Handle, (IntPtr)bytesToPurge, 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);
Expand Down
5 changes: 3 additions & 2 deletions binding/Binding/SKBitmap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -459,9 +459,10 @@ public bool IsImmutable {
get { return SkiaApi.sk_bitmap_is_immutable (Handle); }
}

[Obsolete]
public bool IsVolatile {
get { return SkiaApi.sk_bitmap_is_volatile (Handle); }
set { SkiaApi.sk_bitmap_set_volatile (Handle, value); }
get => false;
set { }
}

[EditorBrowsable (EditorBrowsableState.Never)]
Expand Down
63 changes: 13 additions & 50 deletions binding/Binding/SKCanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -490,30 +490,25 @@ public void DrawDrawable (SKDrawable drawable, SKPoint p)

// DrawBitmap

public void DrawBitmap (SKBitmap bitmap, SKPoint p, SKPaint paint = null)
{
public void DrawBitmap (SKBitmap bitmap, SKPoint p, SKPaint paint = null) =>
DrawBitmap (bitmap, p.X, p.Y, paint);
}

public void DrawBitmap (SKBitmap bitmap, float x, float y, SKPaint paint = null)
{
if (bitmap == null)
throw new ArgumentNullException (nameof (bitmap));
SkiaApi.sk_canvas_draw_bitmap (Handle, bitmap.Handle, x, y, paint == null ? IntPtr.Zero : paint.Handle);
using var image = SKImage.FromBitmap (bitmap);
DrawImage (image, x, y, paint);
}

public void DrawBitmap (SKBitmap bitmap, SKRect dest, SKPaint paint = null)
{
if (bitmap == null)
throw new ArgumentNullException (nameof (bitmap));
SkiaApi.sk_canvas_draw_bitmap_rect (Handle, bitmap.Handle, null, &dest, paint == null ? IntPtr.Zero : paint.Handle);
using var image = SKImage.FromBitmap (bitmap);
DrawImage (image, dest, paint);
}

public void DrawBitmap (SKBitmap bitmap, SKRect source, SKRect dest, SKPaint paint = null)
{
if (bitmap == null)
throw new ArgumentNullException (nameof (bitmap));
SkiaApi.sk_canvas_draw_bitmap_rect (Handle, bitmap.Handle, &source, &dest, paint == null ? IntPtr.Zero : paint.Handle);
using var image = SKImage.FromBitmap (bitmap);
DrawImage (image, source, dest, paint);
}

// DrawSurface
Expand Down Expand Up @@ -839,13 +834,8 @@ public SKData DrawLinkDestinationAnnotation (SKRect rect, string value)

public void DrawBitmapNinePatch (SKBitmap bitmap, SKRectI center, SKRect dst, SKPaint paint = null)
{
if (bitmap == null)
throw new ArgumentNullException (nameof (bitmap));
// the "center" rect must fit inside the bitmap "rect"
if (!SKRect.Create (bitmap.Info.Size).Contains (center))
throw new ArgumentException ("Center rectangle must be contained inside the bitmap bounds.", nameof (center));

SkiaApi.sk_canvas_draw_bitmap_nine (Handle, bitmap.Handle, &center, &dst, paint == null ? IntPtr.Zero : paint.Handle);
using var image = SKImage.FromBitmap (bitmap);
DrawImageNinePatch (image, center, dst, paint);
}

public void DrawImageNinePatch (SKImage image, SKRectI center, SKRect dst, SKPaint paint = null)
Expand All @@ -863,11 +853,8 @@ public void DrawImageNinePatch (SKImage image, SKRectI center, SKRect dst, SKPai

public void DrawBitmapLattice (SKBitmap bitmap, int[] xDivs, int[] yDivs, SKRect dst, SKPaint paint = null)
{
var lattice = new SKLattice {
XDivs = xDivs,
YDivs = yDivs
};
DrawBitmapLattice (bitmap, lattice, dst, paint);
using var image = SKImage.FromBitmap (bitmap);
DrawImageLattice (image, xDivs, yDivs, dst, paint);
}

public void DrawImageLattice (SKImage image, int[] xDivs, int[] yDivs, SKRect dst, SKPaint paint = null)
Expand All @@ -881,32 +868,8 @@ public void DrawImageLattice (SKImage image, int[] xDivs, int[] yDivs, SKRect ds

public void DrawBitmapLattice (SKBitmap bitmap, SKLattice lattice, SKRect dst, SKPaint paint = null)
{
if (bitmap == null)
throw new ArgumentNullException (nameof (bitmap));
if (lattice.XDivs == null)
throw new ArgumentNullException (nameof (lattice.XDivs));
if (lattice.YDivs == null)
throw new ArgumentNullException (nameof (lattice.YDivs));

fixed (int* x = lattice.XDivs)
fixed (int* y = lattice.YDivs)
fixed (SKLatticeRectType* r = lattice.RectTypes)
fixed (SKColor* c = lattice.Colors) {
var nativeLattice = new SKLatticeInternal {
fBounds = null,
fRectTypes = r,
fXCount = lattice.XDivs.Length,
fXDivs = x,
fYCount = lattice.YDivs.Length,
fYDivs = y,
fColors = (uint*)c,
};
if (lattice.Bounds != null) {
var bounds = lattice.Bounds.Value;
nativeLattice.fBounds = &bounds;
}
SkiaApi.sk_canvas_draw_bitmap_lattice (Handle, bitmap.Handle, &nativeLattice, &dst, paint == null ? IntPtr.Zero : paint.Handle);
}
using var image = SKImage.FromBitmap (bitmap);
DrawImageLattice (image, lattice, dst, paint);
}

public void DrawImageLattice (SKImage image, SKLattice lattice, SKRect dst, SKPaint paint = null)
Expand Down
7 changes: 5 additions & 2 deletions binding/Binding/SKColorSpaceStructs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,13 @@ public static SKColorSpaceXyz AdobeRgb {
}
}

public static SKColorSpaceXyz Dcip3 {
[Obsolete ("Use DisplayP3 instead.")]
public static SKColorSpaceXyz Dcip3 => DisplayP3;

public static SKColorSpaceXyz DisplayP3 {
get {
SKColorSpaceXyz xyz;
SkiaApi.sk_colorspace_xyz_named_dcip3 (&xyz);
SkiaApi.sk_colorspace_xyz_named_display_p3 (&xyz);
return xyz;
}
}
Expand Down
18 changes: 14 additions & 4 deletions binding/Binding/SKImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,15 @@ public static SKImage FromEncodedData (SKData data, SKRectI subset)
if (data == null)
throw new ArgumentNullException (nameof (data));

var handle = SkiaApi.sk_image_new_from_encoded (data.Handle, &subset);
return GetObject (handle);
return FromEncodedData (data)?.Subset (subset);
}

public static SKImage FromEncodedData (SKData data)
{
if (data == null)
throw new ArgumentNullException (nameof (data));

var handle = SkiaApi.sk_image_new_from_encoded (data.Handle, null);
var handle = SkiaApi.sk_image_new_from_encoded (data.Handle);
return GetObject (handle);
}

Expand Down Expand Up @@ -655,7 +654,18 @@ public SKImage ApplyImageFilter (SKImageFilter filter, SKRectI subset, SKRectI c

fixed (SKRectI* os = &outSubset)
fixed (SKPointI* oo = &outOffset) {
return GetObject (SkiaApi.sk_image_make_with_filter (Handle, filter.Handle, &subset, &clipBounds, os, oo));
return GetObject (SkiaApi.sk_image_make_with_filter_legacy (Handle, filter.Handle, &subset, &clipBounds, os, oo));
}
}

public SKImage ApplyImageFilter (GRContext context, SKImageFilter filter, SKRectI subset, SKRectI clipBounds, out SKRectI outSubset, out SKPointI outOffset)
{
if (filter == null)
throw new ArgumentNullException (nameof (filter));

fixed (SKRectI* os = &outSubset)
fixed (SKPointI* oo = &outOffset) {
return GetObject (SkiaApi.sk_image_make_with_filter (Handle, context?.Handle ?? IntPtr.Zero, filter.Handle, &subset, &clipBounds, os, oo));
}
}

Expand Down
16 changes: 12 additions & 4 deletions binding/Binding/SKPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@

namespace SkiaSharp
{
public enum SKPathConvexity
{
Unknown = 0,
Convex = 1,
Concave = 2,
}

public unsafe class SKPath : SKObject, ISKSkipObjectRegistration
{
internal SKPath (IntPtr handle, bool owns)
Expand Down Expand Up @@ -38,13 +45,14 @@ public SKPathFillType FillType {
}

public SKPathConvexity Convexity {
get => SkiaApi.sk_path_get_convexity (Handle);
set => SkiaApi.sk_path_set_convexity (Handle, value);
get => IsConvex ? SKPathConvexity.Convex : SKPathConvexity.Concave;
[Obsolete]
set { }
}

public bool IsConvex => Convexity == SKPathConvexity.Convex;
public bool IsConvex => SkiaApi.sk_path_is_convex(Handle);

public bool IsConcave => Convexity == SKPathConvexity.Concave;
public bool IsConcave => !IsConvex;

public bool IsEmpty => VerbCount == 0;

Expand Down
4 changes: 2 additions & 2 deletions binding/Binding/SKShader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ public static SKShader CreateCompose (SKShader shaderA, SKShader shaderB, SKBlen
if (shaderB == null)
throw new ArgumentNullException (nameof (shaderB));

return GetObject (SkiaApi.sk_shader_new_blend (mode, shaderA.Handle, shaderB.Handle, null));
return GetObject (SkiaApi.sk_shader_new_blend (mode, shaderA.Handle, shaderB.Handle));
}

// CreateLerp
Expand All @@ -429,7 +429,7 @@ public static SKShader CreateLerp (float weight, SKShader dst, SKShader src)
if (src == null)
throw new ArgumentNullException (nameof (src));

return GetObject (SkiaApi.sk_shader_new_lerp (weight, dst.Handle, src.Handle, null));
return GetObject (SkiaApi.sk_shader_new_lerp (weight, dst.Handle, src.Handle));
}

// CreateColorFilter
Expand Down
Loading

0 comments on commit c311ede

Please sign in to comment.