diff --git a/binding/Binding/Binding.projitems b/binding/Binding/Binding.projitems index b6db9854..f7b5cd97 100644 --- a/binding/Binding/Binding.projitems +++ b/binding/Binding/Binding.projitems @@ -18,6 +18,7 @@ + diff --git a/binding/Binding/Definitions.cs b/binding/Binding/Definitions.cs index fe7d12b4..42597cf1 100644 --- a/binding/Binding/Definitions.cs +++ b/binding/Binding/Definitions.cs @@ -41,6 +41,9 @@ using System; using System.Runtime.InteropServices; using System.Globalization; + +using GRBackendObject = System.IntPtr; +using GRBackendContext = System.IntPtr; namespace SkiaSharp { @@ -265,6 +268,14 @@ namespace SkiaSharp BgrVertical } + [Flags] + public enum SKSurfacePropsFlags { + DisallowAntiAlias = 1 << 0, + DisallowDither = 1 << 1, + UseDeviceIndependentFonts = 1 << 2, + GammaCorrect = 1 << 3, + } + public enum SKEncoding { Utf8, Utf16, Utf32 } @@ -457,6 +468,7 @@ namespace SkiaSharp [StructLayout(LayoutKind.Sequential)] public struct SKSurfaceProps { public SKPixelGeometry PixelGeometry; + public SKSurfacePropsFlags Flags; } public enum SKZeroInitialized { @@ -1141,6 +1153,9 @@ namespace SkiaSharp Bottom = bottom; } + public float Height => Bottom - Top; + public float Width => Right - Left; + public static SKRectI Create (int width, int height) { return new SKRectI (0, 0, width, height); @@ -1163,6 +1178,9 @@ namespace SkiaSharp Bottom = bottom; } + public float Height => Bottom - Top; + public float Width => Right - Left; + public static SKRect Create (float width, float height) { return new SKRect (0, 0, width, height); @@ -1614,5 +1632,45 @@ typeMask = Mask.Scale | Mask.RectStaysRect } } } + + public enum GRSurfaceOrigin { + TopLeft, + BottomLeft, + } + + public enum GRPixelConfig { + Unknown, + Alpha8, + Index8, + Rgb565, + Rgba4444, + Rgba8888, + Bgra8888, + Srgba8888, + Sbgra8888, + Etc1, + Latc, + R11Eac, + Astc12x12, + RgbaFloat, + AlphaHalf, + RgbaHalf, + } + + [StructLayout(LayoutKind.Sequential)] + public struct GRBackendRenderTargetDesc { + public int Width; + public int Height; + public GRPixelConfig Config; + public GRSurfaceOrigin Origin; + public int SampleCount; + public int StencilBits; + public GRBackendObject RenderTargetHandle; + } + + public enum GRBackend { + OpenGL, + Vulkan, + } } diff --git a/binding/Binding/GRContext.cs b/binding/Binding/GRContext.cs new file mode 100644 index 00000000..8b923256 --- /dev/null +++ b/binding/Binding/GRContext.cs @@ -0,0 +1,42 @@ +// +// Bindings for GRContext +// +// Author: +// Matthew Leibowitz +// +// Copyright 2016 Xamarin Inc +// + +using System; + +namespace SkiaSharp +{ + public class GRContext : SKObject + { + [Preserve] + internal GRContext (IntPtr h, bool owns) + : base (h, owns) + { + } + + public static GRContext Create (GRBackend backend) + { + return Create (backend, IntPtr.Zero); + } + + public static GRContext Create (GRBackend backend, IntPtr backendContext) + { + return GetObject (SkiaApi.gr_context_create_with_defaults (backend, backendContext)); + } + + protected override void Dispose (bool disposing) + { + if (Handle != IntPtr.Zero && OwnsHandle) { + SkiaApi.gr_context_unref (Handle); + } + + base.Dispose (disposing); + } + } +} + diff --git a/binding/Binding/SKCanvas.cs b/binding/Binding/SKCanvas.cs index b93e1ddc..c5ef17c2 100644 --- a/binding/Binding/SKCanvas.cs +++ b/binding/Binding/SKCanvas.cs @@ -349,6 +349,10 @@ namespace SkiaSharp SkiaApi.sk_canvas_draw_text_on_path (Handle, bytes, bytes.Length, path.Handle, hOffset, vOffset, paint.Handle); } + public void Flush () + { + SkiaApi.sk_canvas_flush (Handle); + } public void ResetMatrix () { diff --git a/binding/Binding/SKSurface.cs b/binding/Binding/SKSurface.cs index 1949ef19..f4cd5533 100644 --- a/binding/Binding/SKSurface.cs +++ b/binding/Binding/SKSurface.cs @@ -44,6 +44,16 @@ namespace SkiaSharp return GetObject (SkiaApi.sk_surface_new_raster_direct (ref info, pixels, (IntPtr)rowBytes, ref props)); } + public static SKSurface Create (GRContext context, GRBackendRenderTargetDesc desc, SKSurfaceProps props) + { + return GetObject (SkiaApi.sk_surface_new_backend_render_target (context.Handle, ref desc, ref props)); + } + + public static SKSurface Create (GRContext context, GRBackendRenderTargetDesc desc) + { + return GetObject (SkiaApi.sk_surface_new_backend_render_target (context.Handle, ref desc, IntPtr.Zero)); + } + protected override void Dispose (bool disposing) { if (Handle != IntPtr.Zero && OwnsHandle) { diff --git a/binding/Binding/SkiaApi.cs b/binding/Binding/SkiaApi.cs index 06104cfb..7730cb52 100755 --- a/binding/Binding/SkiaApi.cs +++ b/binding/Binding/SkiaApi.cs @@ -9,6 +9,9 @@ using System; using System.Runtime.InteropServices; +using GRBackendObject = System.IntPtr; +using GRBackendContext = System.IntPtr; + using sk_surface_t = System.IntPtr; using sk_canvas_t = System.IntPtr; using sk_image_t = System.IntPtr; @@ -42,6 +45,7 @@ using sk_path_iterator_t = System.IntPtr; using sk_path_effect_t = System.IntPtr; using sk_pixelref_factory_t = System.IntPtr; using sk_colortable_t = System.IntPtr; +using gr_context_t = System.IntPtr; namespace SkiaSharp { @@ -77,6 +81,10 @@ namespace SkiaSharp public extern static sk_canvas_t sk_surface_get_canvas(sk_surface_t t); [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] public extern static sk_image_t sk_surface_new_image_snapshot(sk_surface_t t); + [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] + public extern static sk_surface_t sk_surface_new_backend_render_target (gr_context_t context, ref GRBackendRenderTargetDesc desc, ref SKSurfaceProps props); + [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] + public extern static sk_surface_t sk_surface_new_backend_render_target (gr_context_t context, ref GRBackendRenderTargetDesc desc, IntPtr propsZero); [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] public extern static int sk_canvas_save(sk_canvas_t t); @@ -173,6 +181,10 @@ namespace SkiaSharp public extern static bool sk_canvas_get_clip_device_bounds(sk_canvas_t t, ref SKRectI cbounds); [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] public extern static bool sk_canvas_get_clip_bounds(sk_canvas_t t, ref SKRect cbounds); + [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] + public extern static void sk_canvas_flush (sk_canvas_t canvas); + + // Paint [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] public extern static sk_paint_t sk_paint_new(); @@ -910,6 +922,13 @@ namespace SkiaSharp public extern static void sk_colortable_read_colors (sk_colortable_t ctable, [Out] SKColor[] colors); [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] public extern static void sk_colortable_read_colors (sk_colortable_t ctable, out IntPtr colors); + + // GRContext + + [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] + public extern static gr_context_t gr_context_create_with_defaults (GRBackend backend, GRBackendContext backendContext); + [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] + public extern static void gr_context_unref (gr_context_t context); } } diff --git a/native-builds/src/SkiaKeeper.c b/native-builds/src/SkiaKeeper.c index 4b348cdb..e47c88f9 100644 --- a/native-builds/src/SkiaKeeper.c +++ b/native-builds/src/SkiaKeeper.c @@ -29,6 +29,7 @@ #include "sk_string.h" #include "sk_surface.h" #include "sk_typeface.h" +#include "gr_context.h" // Xamarin #include "sk_managedstream.h" @@ -80,6 +81,7 @@ void** KeepSkiaCSymbols () (void*)sk_matrix_map_radius, (void*)sk_matrix_try_invert, (void*)sk_colortable_new, + (void*)gr_context_unref, // Xamarin (void*)sk_managedstream_new, diff --git a/skia b/skia index 3343ae58..e83f322d 160000 --- a/skia +++ b/skia @@ -1 +1 @@ -Subproject commit 3343ae587f9da023dfd43ed1ab12dcddf0bd097b +Subproject commit e83f322d4ccfd5cbf5bdfbd973aa951b7171504e