From c78d3bbc2eb8f4c07b0f16893889ce309bca4a92 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Thu, 24 Aug 2017 16:51:39 +0200 Subject: [PATCH] Added some TODOs for future features --- binding/Binding/SKBitmap.cs | 5 ++ binding/Binding/SKCanvas.cs | 116 +++++++++++++++++++++++++++++-- binding/Binding/SKCodec.cs | 4 ++ binding/Binding/SKColorFilter.cs | 2 + 4 files changed, 122 insertions(+), 5 deletions(-) diff --git a/binding/Binding/SKBitmap.cs b/binding/Binding/SKBitmap.cs index d72c651e..1a4f157e 100644 --- a/binding/Binding/SKBitmap.cs +++ b/binding/Binding/SKBitmap.cs @@ -21,6 +21,11 @@ namespace SkiaSharp [UnmanagedFunctionPointer (CallingConvention.Cdecl)] internal delegate void SKBitmapReleaseDelegateInternal (IntPtr address, IntPtr context); + // TODO: keep in mind SKBitmap may be going away (according to Google) + // TODO: `ComputeIsOpaque` may be useful + // TODO: `GenerationID` may be useful + // TODO: `GetAddr` and `GetPixel` are confusing + public class SKBitmap : SKObject { private const string UnsupportedColorTypeMessage = "Setting the ColorTable is only supported for bitmaps with ColorTypes of Index8."; diff --git a/binding/Binding/SKCanvas.cs b/binding/Binding/SKCanvas.cs index a112fa67..d7678f42 100644 --- a/binding/Binding/SKCanvas.cs +++ b/binding/Binding/SKCanvas.cs @@ -10,7 +10,17 @@ using System; namespace SkiaSharp { - // No dispose, the Canvas is only valid while the Surface is valid. + // TODO: carefully consider the `PeekPixels`, `ReadPixels` + // TODO: `ClipRRect` may be useful + // TODO: `DrawRRect` may be useful + // TODO: `DrawDRRect` may be useful + // TODO: add the `DrawArc` variants + // TODO: add `DrawTextBlob` variants if/when we bind `SKTextBlob` + // TODO: add `DrawPatch` variants + // TODO: add `DrawAtlas` variants + // TODO: add `DrawDrawable` variants if/when we bind `SKDrawable` + // TODO: add `IsClipEmpty` and `IsClipRect` + public class SKCanvas : SKObject { [Preserve] @@ -76,6 +86,11 @@ namespace SkiaSharp SkiaApi.sk_canvas_draw_color (Handle, color, mode); } + public void DrawLine (SKPoint p0, SKPoint p1, SKPaint paint) + { + DrawLine (p0.X, p0.Y, p1.X, p1.Y, paint); + } + public void DrawLine (float x0, float y0, float x1, float y1, SKPaint paint) { if (paint == null) @@ -267,6 +282,11 @@ namespace SkiaSharp SkiaApi.sk_canvas_draw_region (Handle, region.Handle, paint.Handle); } + public void DrawRect (float x, float y, float w, float h, SKPaint paint) + { + DrawRect (SKRect.Create (x, y, w, h), paint); + } + public void DrawRect (SKRect rect, SKPaint paint) { if (paint == null) @@ -274,11 +294,21 @@ namespace SkiaSharp SkiaApi.sk_canvas_draw_rect (Handle, ref rect, paint.Handle); } + public void DrawRoundRect (float x, float y, float w, float h, float rx, float ry, SKPaint paint) + { + DrawRoundRect (SKRect.Create (x, y, w, h), rx, ry, paint); + } + public void DrawRoundRect (SKRect rect, float rx, float ry, SKPaint paint) { - if (paint == null) - throw new ArgumentNullException (nameof (paint)); - SkiaApi.sk_canvas_draw_round_rect (Handle, ref rect, rx, ry, paint.Handle); + if (paint == null) + throw new ArgumentNullException (nameof (paint)); + SkiaApi.sk_canvas_draw_round_rect (Handle, ref rect, rx, ry, paint.Handle); + } + + public void DrawRoundRect (SKRect rect, SKSize r, SKPaint paint) + { + DrawRoundRect (rect, r.Width, r.Height, paint); } public void DrawOval (float cx, float cy, float rx, float ry, SKPaint paint) @@ -286,6 +316,11 @@ namespace SkiaSharp DrawOval (new SKRect (cx - rx, cy - ry, cx + rx, cy + ry), paint); } + public void DrawOval (SKPoint c, SKSize r, SKPaint paint) + { + DrawOval (c.X, c.Y, r.Width, r.Height, paint); + } + public void DrawOval (SKRect rect, SKPaint paint) { if (paint == null) @@ -299,6 +334,11 @@ namespace SkiaSharp throw new ArgumentNullException (nameof (paint)); SkiaApi.sk_canvas_draw_circle (Handle, cx, cy, radius, paint.Handle); } + + public void DrawCircle (SKPoint c, float radius, SKPaint paint) + { + DrawCircle (c.X, c.Y, radius, paint); + } public void DrawPath (SKPath path, SKPaint paint) { @@ -318,6 +358,11 @@ namespace SkiaSharp SkiaApi.sk_canvas_draw_points (Handle, mode, (IntPtr)points.Length, points, paint.Handle); } + public void DrawPoint (SKPoint p, SKPaint paint) + { + DrawPoint (p.X, p.Y, paint); + } + public void DrawPoint (float x, float y, SKPaint paint) { if (paint == null) @@ -325,13 +370,23 @@ namespace SkiaSharp SkiaApi.sk_canvas_draw_point (Handle, x, y, paint.Handle); } + public void DrawPoint (SKPoint p, SKColor color) + { + DrawPoint (p.X, p.Y, color); + } + public void DrawPoint (float x, float y, SKColor color) { using (var paint = new SKPaint { Color = color }) { DrawPoint (x, y, paint); } } - + + public void DrawImage (SKImage image, SKPoint p, SKPaint paint = null) + { + DrawImage (image, p.X, p.Y, paint); + } + public void DrawImage (SKImage image, float x, float y, SKPaint paint = null) { if (image == null) @@ -353,6 +408,17 @@ namespace SkiaSharp SkiaApi.sk_canvas_draw_image_rect (Handle, image.Handle, ref source, ref dest, paint == null ? IntPtr.Zero : paint.Handle); } + public void DrawPicture (SKPicture picture, float x, float y, SKPaint paint = null) + { + var matrix = SKMatrix.MakeTranslation (x, y); + DrawPicture (picture, ref matrix, paint); + } + + public void DrawPicture (SKPicture picture, SKPoint p, SKPaint paint = null) + { + DrawPicture (picture, p.X, p.Y, paint); + } + public void DrawPicture (SKPicture picture, ref SKMatrix matrix, SKPaint paint = null) { if (picture == null) @@ -367,6 +433,11 @@ namespace SkiaSharp SkiaApi.sk_canvas_draw_picture (Handle, picture.Handle, IntPtr.Zero, paint == null ? IntPtr.Zero : paint.Handle); } + 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) @@ -388,6 +459,11 @@ namespace SkiaSharp SkiaApi.sk_canvas_draw_bitmap_rect (Handle, bitmap.Handle, ref source, ref dest, paint == null ? IntPtr.Zero : paint.Handle); } + public void DrawSurface (SKSurface surface, SKPoint p, SKPaint paint = null) + { + DrawSurface (surface, p.X, p.Y, paint); + } + public void DrawSurface (SKSurface surface, float x, float y, SKPaint paint = null) { if (surface == null) @@ -396,6 +472,11 @@ namespace SkiaSharp surface.Draw (this, x, y, paint); } + public void DrawText (string text, SKPoint p, SKPaint paint) + { + DrawText (text, p.X, p.Y, paint); + } + public void DrawText (string text, float x, float y, SKPaint paint) { if (text == null) @@ -407,6 +488,11 @@ namespace SkiaSharp DrawText (bytes, x, y, paint); } + public void DrawText (byte[] text, SKPoint p, SKPaint paint) + { + DrawText (text, p.X, p.Y, paint); + } + public void DrawText (byte[] text, float x, float y, SKPaint paint) { if (text == null) @@ -454,6 +540,11 @@ namespace SkiaSharp DrawTextOnPath (buffer, length, path, hOffset, vOffset, paint); } + public void DrawTextOnPath (IntPtr buffer, int length, SKPath path, SKPoint offset, SKPaint paint) + { + DrawTextOnPath (buffer, length, path, offset.X, offset.Y, paint); + } + public void DrawTextOnPath (IntPtr buffer, int length, SKPath path, float hOffset, float vOffset, SKPaint paint) { if (buffer == IntPtr.Zero) @@ -466,6 +557,11 @@ namespace SkiaSharp SkiaApi.sk_canvas_draw_text_on_path (Handle, buffer, length, path.Handle, hOffset, vOffset, paint.Handle); } + public void DrawText (IntPtr buffer, int length, SKPoint p, SKPaint paint) + { + DrawText (buffer, length, p.X, p.Y, paint); + } + public void DrawText (IntPtr buffer, int length, float x, float y, SKPaint paint) { if (buffer == IntPtr.Zero) @@ -500,6 +596,11 @@ namespace SkiaSharp DrawTextOnPath (text, path, hOffset, vOffset, paint); } + public void DrawTextOnPath (string text, SKPath path, SKPoint offset, SKPaint paint) + { + DrawTextOnPath (text, path, offset.X, offset.Y, paint); + } + public void DrawTextOnPath (string text, SKPath path, float hOffset, float vOffset, SKPaint paint) { if (text == null) @@ -519,6 +620,11 @@ namespace SkiaSharp DrawTextOnPath (text, path, hOffset, vOffset, paint); } + public void DrawTextOnPath (byte[] text, SKPath path, SKPoint offset, SKPaint paint) + { + DrawTextOnPath (text, path, offset.X, offset.Y, paint); + } + public void DrawTextOnPath (byte[] text, SKPath path, float hOffset, float vOffset, SKPaint paint) { if (text == null) diff --git a/binding/Binding/SKCodec.cs b/binding/Binding/SKCodec.cs index 6e8c71f8..77008f38 100644 --- a/binding/Binding/SKCodec.cs +++ b/binding/Binding/SKCodec.cs @@ -12,6 +12,10 @@ using System.Runtime.InteropServices; namespace SkiaSharp { + // TODO: `Create(...)` should have overloads that accept a SKPngChunkReader + // TODO: missing the `QueryYuv8` and `GetYuv8Planes` members + // TODO: might be useful to wrap `GetFrameInfo` (single result) + public class SKCodec : SKObject { [Preserve] diff --git a/binding/Binding/SKColorFilter.cs b/binding/Binding/SKColorFilter.cs index de0fdd57..7be1499b 100644 --- a/binding/Binding/SKColorFilter.cs +++ b/binding/Binding/SKColorFilter.cs @@ -10,6 +10,8 @@ using System; namespace SkiaSharp { + // TODO: `FilterColor` may be useful + public class SKColorFilter : SKObject { public const int ColorMatrixSize = 20;