From 04883d0fb69e72ace243f44d0a45cc380645f3d7 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Sat, 21 Jul 2018 22:35:05 +0200 Subject: [PATCH] Added bindings for SkOverdrawCanvas - also set flags to reduce file sizes --- binding/Binding/SKOverdrawCanvas.cs | 22 ++++++++++++++++++++++ binding/Binding/SkiaApi.cs | 7 +++++++ externals/skia | 2 +- tests/Tests/SKCanvasTest.cs | 19 +++++++++++++++++++ 4 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 binding/Binding/SKOverdrawCanvas.cs diff --git a/binding/Binding/SKOverdrawCanvas.cs b/binding/Binding/SKOverdrawCanvas.cs new file mode 100644 index 00000000..7e5b61a7 --- /dev/null +++ b/binding/Binding/SKOverdrawCanvas.cs @@ -0,0 +1,22 @@ +using System; + +namespace SkiaSharp +{ + public class SKOverdrawCanvas : SKNWayCanvas + { + [Preserve] + internal SKOverdrawCanvas (IntPtr handle, bool owns) + : base (handle, owns) + { + } + + public SKOverdrawCanvas (SKCanvas canvas) + : this (IntPtr.Zero, true) + { + if (canvas == null) + throw new ArgumentNullException (nameof (canvas)); + + Handle = SkiaApi.sk_overdraw_canvas_new (canvas.Handle); + } + } +} diff --git a/binding/Binding/SkiaApi.cs b/binding/Binding/SkiaApi.cs index 0067de63..90b4c962 100755 --- a/binding/Binding/SkiaApi.cs +++ b/binding/Binding/SkiaApi.cs @@ -7,6 +7,7 @@ using GRBackendObject = System.IntPtr; using sk_surface_t = System.IntPtr; using sk_canvas_t = System.IntPtr; using sk_nodraw_canvas_t = System.IntPtr; +using sk_overdraw_canvas_t = System.IntPtr; using sk_nway_canvas_t = System.IntPtr; using sk_image_t = System.IntPtr; using sk_paint_t = System.IntPtr; @@ -317,6 +318,12 @@ namespace SkiaSharp [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] public extern static void sk_nway_canvas_remove_all(sk_nway_canvas_t t); + // overdraw canvas + [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] + public extern static sk_overdraw_canvas_t sk_overdraw_canvas_new(sk_canvas_t canvas); + [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] + public extern static void sk_overdraw_canvas_destroy(sk_overdraw_canvas_t canvas); + // paint [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] public extern static sk_paint_t sk_paint_new(); diff --git a/externals/skia b/externals/skia index 65cfd58f..d42756a5 160000 --- a/externals/skia +++ b/externals/skia @@ -1 +1 @@ -Subproject commit 65cfd58f44c312e418a73551850f467a27ab4acf +Subproject commit d42756a5d583b02ee472e8c747a905c31e2c5f2b diff --git a/tests/Tests/SKCanvasTest.cs b/tests/Tests/SKCanvasTest.cs index fadfd01a..2125a75a 100644 --- a/tests/Tests/SKCanvasTest.cs +++ b/tests/Tests/SKCanvasTest.cs @@ -91,6 +91,25 @@ namespace SkiaSharp.Tests } } + [SkippableFact] + public void OverdrawCanvasDrawsProperly() + { + using (var bitmap = new SKBitmap(new SKImageInfo(100, 100))) + using (var canvas = new SKCanvas(bitmap)) + using (var overdraw = new SKOverdrawCanvas(canvas)) + { + bitmap.Erase(SKColors.Transparent); + + overdraw.DrawRect(SKRect.Create(10, 10, 30, 30), new SKPaint()); + overdraw.DrawRect(SKRect.Create(20, 20, 30, 30), new SKPaint()); + + Assert.Equal(0, bitmap.GetPixel(5, 5).Alpha); + Assert.Equal(1, bitmap.GetPixel(15, 15).Alpha); + Assert.Equal(2, bitmap.GetPixel(25, 25).Alpha); + Assert.Equal(1, bitmap.GetPixel(45, 45).Alpha); + } + } + [SkippableFact] public void SvgCanvasSavesFile() {