Added many more SKImage members
This commit is contained in:
Родитель
a637922aa5
Коммит
b181924095
|
@ -2652,4 +2652,9 @@ namespace SkiaSharp
|
|||
Argb32,
|
||||
Lcd16,
|
||||
}
|
||||
|
||||
public enum SKImageCachingHint {
|
||||
Allow,
|
||||
Disallow,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
// Copyright 2016 Xamarin Inc
|
||||
//
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SkiaSharp
|
||||
{
|
||||
|
@ -21,9 +22,33 @@ namespace SkiaSharp
|
|||
Webp,
|
||||
Ktx,
|
||||
}
|
||||
|
||||
|
||||
// public delegates
|
||||
public delegate void SKImageRasterReleaseDelegate (IntPtr pixels, object context);
|
||||
public delegate void SKImageTextureReleaseDelegate (object context);
|
||||
|
||||
// internal proxy delegates
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
internal delegate void SKImageRasterReleaseDelegateInternal (IntPtr pixels, IntPtr context);
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
internal delegate void SKImageTextureReleaseDelegateInternal (IntPtr context);
|
||||
|
||||
public class SKImage : SKObject
|
||||
{
|
||||
// so the GC doesn't collect the delegate
|
||||
private static readonly SKImageRasterReleaseDelegateInternal rasterReleaseDelegateInternal;
|
||||
private static readonly SKImageTextureReleaseDelegateInternal textureReleaseDelegateInternal;
|
||||
private static readonly IntPtr rasterReleaseDelegate;
|
||||
private static readonly IntPtr textureReleaseDelegate;
|
||||
static SKImage()
|
||||
{
|
||||
rasterReleaseDelegateInternal = new SKImageRasterReleaseDelegateInternal (RasterReleaseInternal);
|
||||
textureReleaseDelegateInternal = new SKImageTextureReleaseDelegateInternal (TextureReleaseInternal);
|
||||
|
||||
rasterReleaseDelegate = Marshal.GetFunctionPointerForDelegate (rasterReleaseDelegateInternal);
|
||||
textureReleaseDelegate = Marshal.GetFunctionPointerForDelegate (textureReleaseDelegateInternal);
|
||||
}
|
||||
|
||||
protected override void Dispose (bool disposing)
|
||||
{
|
||||
if (Handle != IntPtr.Zero && OwnsHandle) {
|
||||
|
@ -39,15 +64,65 @@ namespace SkiaSharp
|
|||
{
|
||||
}
|
||||
|
||||
[Obsolete ("Use FromCopyPixels instead.")]
|
||||
public static SKImage FromPixels (SKImageInfo info, IntPtr pixels, int rowBytes)
|
||||
{
|
||||
return FromCopyPixels (info, pixels, rowBytes);
|
||||
}
|
||||
|
||||
public static SKImage FromCopyPixels (SKImageInfo info, IntPtr pixels, int rowBytes)
|
||||
{
|
||||
return FromCopyPixels (info, pixels, rowBytes, null);
|
||||
}
|
||||
|
||||
public static SKImage FromCopyPixels (SKImageInfo info, IntPtr pixels, int rowBytes, SKColorTable ctable)
|
||||
{
|
||||
if (pixels == IntPtr.Zero)
|
||||
throw new ArgumentNullException (nameof (pixels));
|
||||
var handle = SkiaApi.sk_image_new_raster_copy (ref info, pixels, (IntPtr) rowBytes);
|
||||
|
||||
var ct = (ctable == null ? IntPtr.Zero : ctable.Handle);
|
||||
var handle = SkiaApi.sk_image_new_raster_copy_with_colortable (ref info, pixels, (IntPtr) rowBytes, ct);
|
||||
return GetObject<SKImage> (handle);
|
||||
}
|
||||
|
||||
public static SKImage FromData (SKData data, SKRectI subset)
|
||||
public static SKImage FromCopyPixels (SKPixmap pixmap)
|
||||
{
|
||||
if (pixmap == null)
|
||||
throw new ArgumentNullException (nameof (pixmap));
|
||||
return GetObject<SKImage> (SkiaApi.sk_image_new_raster_copy_with_pixmap (pixmap.Handle));
|
||||
}
|
||||
|
||||
public static SKImage FromPixelData (SKImageInfo info, SKData data, int rowBytes)
|
||||
{
|
||||
if (data == null)
|
||||
throw new ArgumentNullException (nameof (data));
|
||||
return GetObject<SKImage> (SkiaApi.sk_image_new_raster_data (ref info, data.Handle, (IntPtr) rowBytes));
|
||||
}
|
||||
|
||||
public static SKImage FromPixels (SKPixmap pixmap)
|
||||
{
|
||||
return FromPixels (pixmap, null, null);
|
||||
}
|
||||
|
||||
public static SKImage FromPixels (SKPixmap pixmap, SKImageRasterReleaseDelegate releaseProc)
|
||||
{
|
||||
return FromPixels (pixmap, releaseProc, null);
|
||||
}
|
||||
|
||||
public static SKImage FromPixels (SKPixmap pixmap, SKImageRasterReleaseDelegate releaseProc, object releaseContext)
|
||||
{
|
||||
if (pixmap == null)
|
||||
throw new ArgumentNullException (nameof (pixmap));
|
||||
|
||||
if (releaseProc == null) {
|
||||
return GetObject<SKImage> (SkiaApi.sk_image_new_raster (pixmap.Handle, IntPtr.Zero, IntPtr.Zero));
|
||||
} else {
|
||||
var ctx = new NativeDelegateContext (releaseContext, releaseProc);
|
||||
return GetObject<SKImage> (SkiaApi.sk_image_new_raster (pixmap.Handle, rasterReleaseDelegate, ctx.NativeContext));
|
||||
}
|
||||
}
|
||||
|
||||
public static SKImage FromEncodedData (SKData data, SKRectI subset)
|
||||
{
|
||||
if (data == null)
|
||||
throw new ArgumentNullException (nameof (data));
|
||||
|
@ -55,7 +130,7 @@ namespace SkiaSharp
|
|||
return GetObject<SKImage> (handle);
|
||||
}
|
||||
|
||||
public static SKImage FromData (SKData data)
|
||||
public static SKImage FromEncodedData (SKData data)
|
||||
{
|
||||
if (data == null)
|
||||
throw new ArgumentNullException (nameof (data));
|
||||
|
@ -63,6 +138,18 @@ namespace SkiaSharp
|
|||
return GetObject<SKImage> (handle);
|
||||
}
|
||||
|
||||
[Obsolete ("Use FromEncodedData instead.")]
|
||||
public static SKImage FromData (SKData data, SKRectI subset)
|
||||
{
|
||||
return FromEncodedData (data, subset);
|
||||
}
|
||||
|
||||
[Obsolete ("Use FromEncodedData instead.")]
|
||||
public static SKImage FromData (SKData data)
|
||||
{
|
||||
return FromEncodedData (data);
|
||||
}
|
||||
|
||||
public static SKImage FromBitmap (SKBitmap bitmap)
|
||||
{
|
||||
if (bitmap == null)
|
||||
|
@ -71,6 +158,75 @@ namespace SkiaSharp
|
|||
return GetObject<SKImage> (handle);
|
||||
}
|
||||
|
||||
public static SKImage FromTexture (GRContext context, GRBackendTextureDesc desc)
|
||||
{
|
||||
return FromTexture (context, desc, SKAlphaType.Premul);
|
||||
}
|
||||
|
||||
public static SKImage FromTexture (GRContext context, GRBackendTextureDesc desc, SKAlphaType alpha)
|
||||
{
|
||||
return FromTexture (context, desc, alpha, null);
|
||||
}
|
||||
|
||||
public static SKImage FromTexture (GRContext context, GRBackendTextureDesc desc, SKAlphaType alpha, SKImageTextureReleaseDelegate releaseProc)
|
||||
{
|
||||
return FromTexture (context, desc, alpha, releaseProc, null);
|
||||
}
|
||||
|
||||
public static SKImage FromTexture (GRContext context, GRBackendTextureDesc desc, SKAlphaType alpha, SKImageTextureReleaseDelegate releaseProc, object releaseContext)
|
||||
{
|
||||
if (context == null)
|
||||
throw new ArgumentNullException (nameof (context));
|
||||
|
||||
if (releaseProc == null) {
|
||||
return GetObject<SKImage> (SkiaApi.sk_image_new_from_texture (context.Handle, ref desc, alpha, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero));
|
||||
} else {
|
||||
var ctx = new NativeDelegateContext (releaseContext, releaseProc);
|
||||
return GetObject<SKImage> (SkiaApi.sk_image_new_from_texture (context.Handle, ref desc, alpha, IntPtr.Zero, textureReleaseDelegate, ctx.NativeContext));
|
||||
}
|
||||
}
|
||||
|
||||
public static SKImage FromAdoptedTexture (GRContext context, GRBackendTextureDesc desc)
|
||||
{
|
||||
return FromAdoptedTexture (context, desc, SKAlphaType.Premul);
|
||||
}
|
||||
|
||||
public static SKImage FromAdoptedTexture (GRContext context, GRBackendTextureDesc desc, SKAlphaType alpha)
|
||||
{
|
||||
if (context == null)
|
||||
throw new ArgumentNullException (nameof (context));
|
||||
|
||||
return GetObject<SKImage> (SkiaApi.sk_image_new_from_adopted_texture (context.Handle, ref desc, alpha, IntPtr.Zero));
|
||||
}
|
||||
|
||||
public static SKImage FromPicture (SKPicture picture, SKSizeI dimensions)
|
||||
{
|
||||
return FromPicture (picture, dimensions, null);
|
||||
}
|
||||
|
||||
public static SKImage FromPicture (SKPicture picture, SKSizeI dimensions, SKMatrix matrix)
|
||||
{
|
||||
return FromPicture (picture, dimensions, matrix, null);
|
||||
}
|
||||
|
||||
public static SKImage FromPicture (SKPicture picture, SKSizeI dimensions, SKPaint paint)
|
||||
{
|
||||
if (picture == null)
|
||||
throw new ArgumentNullException (nameof (picture));
|
||||
|
||||
var p = (paint == null ? IntPtr.Zero : paint.Handle);
|
||||
return GetObject<SKImage> (SkiaApi.sk_image_new_from_picture (picture.Handle, ref dimensions, IntPtr.Zero, p));
|
||||
}
|
||||
|
||||
public static SKImage FromPicture (SKPicture picture, SKSizeI dimensions, SKMatrix matrix, SKPaint paint)
|
||||
{
|
||||
if (picture == null)
|
||||
throw new ArgumentNullException (nameof (picture));
|
||||
|
||||
var p = (paint == null ? IntPtr.Zero : paint.Handle);
|
||||
return GetObject<SKImage> (SkiaApi.sk_image_new_from_picture (picture.Handle, ref dimensions, ref matrix, p));
|
||||
}
|
||||
|
||||
public SKData Encode ()
|
||||
{
|
||||
return GetObject<SKData> (SkiaApi.sk_image_encode (Handle));
|
||||
|
@ -84,6 +240,126 @@ namespace SkiaSharp
|
|||
public int Width => SkiaApi.sk_image_get_width (Handle);
|
||||
public int Height => SkiaApi.sk_image_get_height (Handle);
|
||||
public uint UniqueId => SkiaApi.sk_image_get_unique_id (Handle);
|
||||
public SKAlphaType AlphaType => SkiaApi.sk_image_get_alpha_type (Handle);
|
||||
public bool IsAlphaOnly => SkiaApi.sk_image_is_alpha_only (Handle);
|
||||
|
||||
public SKShader ToShader (SKShaderTileMode tileX, SKShaderTileMode tileY)
|
||||
{
|
||||
return GetObject<SKShader> (SkiaApi.sk_image_make_shader (Handle, tileX, tileY, IntPtr.Zero));
|
||||
}
|
||||
|
||||
public SKShader ToShader (SKShaderTileMode tileX, SKShaderTileMode tileY, SKMatrix localMatrix)
|
||||
{
|
||||
return GetObject<SKShader> (SkiaApi.sk_image_make_shader (Handle, tileX, tileY, ref localMatrix));
|
||||
}
|
||||
|
||||
public bool PeekPixels (SKPixmap pixmap)
|
||||
{
|
||||
if (pixmap == null)
|
||||
throw new ArgumentNullException (nameof (pixmap));
|
||||
return SkiaApi.sk_bitmap_peek_pixels (Handle, pixmap.Handle);
|
||||
}
|
||||
|
||||
public SKPixmap PeekPixels ()
|
||||
{
|
||||
var pixmap = new SKPixmap ();
|
||||
if (!PeekPixels (pixmap)) {
|
||||
pixmap.Dispose ();
|
||||
pixmap = null;
|
||||
}
|
||||
return pixmap;
|
||||
}
|
||||
|
||||
public bool IsTextureBacked => SkiaApi.sk_image_is_texture_backed (Handle);
|
||||
|
||||
public bool ReadPixels (SKImageInfo dstInfo, IntPtr dstPixels, int dstRowBytes, int srcX, int srcY)
|
||||
{
|
||||
return ReadPixels (dstInfo, dstPixels, dstRowBytes, srcX, srcY, SKImageCachingHint.Allow);
|
||||
}
|
||||
|
||||
public bool ReadPixels (SKImageInfo dstInfo, IntPtr dstPixels, int dstRowBytes, int srcX, int srcY, SKImageCachingHint cachingHint)
|
||||
{
|
||||
return SkiaApi.sk_image_read_pixels (Handle, ref dstInfo, dstPixels, (IntPtr)dstRowBytes, srcX, srcY, cachingHint);
|
||||
}
|
||||
|
||||
public bool ReadPixels (SKPixmap pixmap, int srcX, int srcY)
|
||||
{
|
||||
return ReadPixels (pixmap, srcX, srcY, SKImageCachingHint.Allow);
|
||||
}
|
||||
|
||||
public bool ReadPixels (SKPixmap pixmap, int srcX, int srcY, SKImageCachingHint cachingHint)
|
||||
{
|
||||
if (pixmap == null)
|
||||
throw new ArgumentNullException (nameof (pixmap));
|
||||
return SkiaApi.sk_image_read_pixels_into_pixmap (Handle, pixmap.Handle, srcX, srcY, cachingHint);
|
||||
}
|
||||
|
||||
public SKPixmap ScalePixels (SKFilterQuality quality, SKImageCachingHint cachingHint)
|
||||
{
|
||||
var pixmap = new SKPixmap ();
|
||||
if (!ScalePixels (pixmap, quality, cachingHint)) {
|
||||
pixmap.Dispose ();
|
||||
pixmap = null;
|
||||
}
|
||||
return pixmap;
|
||||
}
|
||||
|
||||
public bool ScalePixels (SKPixmap dst, SKFilterQuality quality)
|
||||
{
|
||||
return ScalePixels (dst, quality, SKImageCachingHint.Allow);
|
||||
}
|
||||
|
||||
public bool ScalePixels (SKPixmap dst, SKFilterQuality quality, SKImageCachingHint cachingHint)
|
||||
{
|
||||
if (dst == null)
|
||||
throw new ArgumentNullException (nameof (dst));
|
||||
return SkiaApi.sk_image_scale_pixels (Handle, dst.Handle, quality, cachingHint);
|
||||
}
|
||||
|
||||
public SKImage Subset (SKRectI subset)
|
||||
{
|
||||
return GetObject<SKImage> (SkiaApi.sk_image_make_subset (Handle, ref subset));
|
||||
}
|
||||
|
||||
public SKImage ToTextureImage (GRContext context)
|
||||
{
|
||||
if (context == null)
|
||||
throw new ArgumentNullException (nameof (context));
|
||||
return GetObject<SKImage> (SkiaApi.sk_image_make_texture_image (Handle, context.Handle));
|
||||
}
|
||||
|
||||
public SKImage ToRasterImage ()
|
||||
{
|
||||
return GetObject<SKImage> (SkiaApi.sk_image_make_non_texture_image (Handle));
|
||||
}
|
||||
|
||||
public SKImage ApplyImageFilter (SKImageFilter filter, SKRectI subset, SKRectI clipBounds, out SKRectI outSubset, out SKPoint outOffset)
|
||||
{
|
||||
if (filter == null)
|
||||
throw new ArgumentNullException (nameof (filter));
|
||||
return GetObject<SKImage> (SkiaApi.sk_image_make_with_filter (Handle, filter.Handle, ref subset, ref clipBounds, out outSubset, out outOffset));
|
||||
}
|
||||
|
||||
// internal proxies
|
||||
|
||||
#if __IOS__
|
||||
[ObjCRuntime.MonoPInvokeCallback (typeof (SKImageRasterReleaseDelegateInternal))]
|
||||
#endif
|
||||
private static void RasterReleaseInternal (IntPtr pixels, IntPtr context)
|
||||
{
|
||||
using (var ctx = NativeDelegateContext.Unwrap (context)) {
|
||||
ctx.GetDelegate<SKImageRasterReleaseDelegate> () (pixels, ctx.ManagedContext);
|
||||
}
|
||||
}
|
||||
|
||||
#if __IOS__
|
||||
[ObjCRuntime.MonoPInvokeCallback (typeof (SKImageTextureReleaseDelegateInternal))]
|
||||
#endif
|
||||
private static void TextureReleaseInternal (IntPtr context)
|
||||
{
|
||||
using (var ctx = NativeDelegateContext.Unwrap (context)) {
|
||||
ctx.GetDelegate<SKImageTextureReleaseDelegate> () (ctx.ManagedContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
// Copyright 2015 Xamarin Inc
|
||||
//
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using GRBackendObject = System.IntPtr;
|
||||
|
@ -427,28 +428,80 @@ namespace SkiaSharp
|
|||
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static sk_paint_t sk_paint_clone(sk_paint_t cpaint);
|
||||
|
||||
// Image
|
||||
|
||||
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static void sk_image_ref(sk_image_t image);
|
||||
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static void sk_image_unref(sk_image_t image);
|
||||
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static sk_image_t sk_image_new_raster_copy(ref SKImageInfo info, IntPtr pixels, IntPtr rowBytes);
|
||||
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static sk_image_t sk_image_new_raster_copy_with_pixmap(sk_pixmap_t pixmap);
|
||||
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static sk_image_t sk_image_new_raster_copy_with_colortable(ref SKImageInfo info, IntPtr pixels, IntPtr rowBytes, sk_colortable_t ctable);
|
||||
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static sk_image_t sk_image_new_raster_data(ref SKImageInfo info, sk_data_t pixels, IntPtr rowBytes);
|
||||
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static sk_image_t sk_image_new_raster(sk_pixmap_t pixmap, IntPtr releaseProc, IntPtr context);
|
||||
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static sk_image_t sk_image_new_from_bitmap(sk_bitmap_t cbitmap);
|
||||
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static sk_image_t sk_image_new_from_encoded(sk_data_t encoded, ref SKRectI subset);
|
||||
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static sk_image_t sk_image_new_from_encoded(sk_data_t encoded, IntPtr subsetPtr);
|
||||
public extern static sk_image_t sk_image_new_from_encoded(sk_data_t encoded, IntPtr subsetZero);
|
||||
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static sk_data_t sk_image_encode(sk_image_t t);
|
||||
public extern static sk_image_t sk_image_new_from_texture(gr_context_t context, ref GRBackendTextureDesc desc, SKAlphaType alpha, sk_colorspace_t colorSpace, IntPtr releaseProc, IntPtr releaseContext);
|
||||
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static sk_data_t sk_image_encode_specific(sk_image_t t, SKImageEncodeFormat format, int quality);
|
||||
public extern static sk_image_t sk_image_new_from_adopted_texture(gr_context_t context, ref GRBackendTextureDesc desc, SKAlphaType alpha, sk_colorspace_t colorSpace);
|
||||
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static sk_image_t sk_image_new_from_bitmap(sk_bitmap_t b);
|
||||
public extern static sk_image_t sk_image_new_from_picture(sk_picture_t picture, ref SKSizeI dimensions, ref SKMatrix matrix, sk_paint_t paint);
|
||||
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static void sk_image_unref(sk_image_t t);
|
||||
public extern static sk_image_t sk_image_new_from_picture(sk_picture_t picture, ref SKSizeI dimensions, IntPtr matrixZero, sk_paint_t paint);
|
||||
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int sk_image_get_width(sk_image_t t);
|
||||
public extern static int sk_image_get_width(sk_image_t image);
|
||||
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int sk_image_get_height(sk_image_t t);
|
||||
public extern static int sk_image_get_height(sk_image_t image);
|
||||
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static uint sk_image_get_unique_id(sk_image_t t);
|
||||
public extern static uint sk_image_get_unique_id(sk_image_t image);
|
||||
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static SKAlphaType sk_image_get_alpha_type(sk_image_t image);
|
||||
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||
[return: MarshalAs(UnmanagedType.I1)]
|
||||
public extern static bool sk_image_is_alpha_only(sk_image_t image);
|
||||
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static sk_shader_t sk_image_make_shader(sk_image_t image, SKShaderTileMode tileX, SKShaderTileMode tileY, ref SKMatrix localMatrix);
|
||||
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static sk_shader_t sk_image_make_shader(sk_image_t image, SKShaderTileMode tileX, SKShaderTileMode tileY, IntPtr localMatrixZero);
|
||||
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||
[return: MarshalAs(UnmanagedType.I1)]
|
||||
public extern static bool sk_image_peek_pixels(sk_image_t image, sk_pixmap_t pixmap);
|
||||
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||
[return: MarshalAs(UnmanagedType.I1)]
|
||||
public extern static bool sk_image_is_texture_backed(sk_image_t image);
|
||||
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||
[return: MarshalAs(UnmanagedType.I1)]
|
||||
public extern static bool sk_image_read_pixels(sk_image_t image, ref SKImageInfo dstInfo, IntPtr dstPixels, IntPtr dstRowBytes, int srcX, int srcY, SKImageCachingHint cachingHint);
|
||||
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||
[return: MarshalAs(UnmanagedType.I1)]
|
||||
public extern static bool sk_image_read_pixels_into_pixmap(sk_image_t image, sk_pixmap_t dst, int srcX, int srcY, SKImageCachingHint cachingHint);
|
||||
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||
[return: MarshalAs(UnmanagedType.I1)]
|
||||
public extern static bool sk_image_scale_pixels(sk_image_t image, sk_pixmap_t dst, SKFilterQuality quality, SKImageCachingHint cachingHint);
|
||||
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static sk_data_t sk_image_encode(sk_image_t image);
|
||||
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static sk_data_t sk_image_encode_specific(sk_image_t image, SKImageEncodeFormat encoder, int quality);
|
||||
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static sk_image_t sk_image_make_subset(sk_image_t image, ref SKRectI subset);
|
||||
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static sk_image_t sk_image_make_texture_image(sk_image_t image, gr_context_t context);
|
||||
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static sk_image_t sk_image_make_non_texture_image(sk_image_t image);
|
||||
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static sk_image_t sk_image_make_with_filter(sk_image_t image, sk_imagefilter_t filter, ref SKRectI subset, ref SKRectI clipbounds, out SKRectI outSubset, out SKPoint outOffset);
|
||||
|
||||
// Path
|
||||
|
||||
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||
[return: MarshalAs(UnmanagedType.I1)]
|
||||
|
@ -1452,6 +1505,79 @@ namespace SkiaSharp
|
|||
public extern static void sk_region_get_bounds(sk_region_t r, out SKRectI rect);
|
||||
}
|
||||
|
||||
// This is the actual context passed to native code.
|
||||
// Instead of marshalling the user's data as an IntPtr and requiring
|
||||
// him to wrap/unwarp, we do it via a proxy class. This also prevents
|
||||
// us from having to marshal the user's callback too.
|
||||
internal class NativeDelegateContext : IDisposable
|
||||
{
|
||||
// instead of pinning the struct, we pin a GUID which is paired to the struct
|
||||
private static readonly IDictionary<Guid, NativeDelegateContext> contexts = new Dictionary<Guid, NativeDelegateContext>();
|
||||
|
||||
// the "managed version" of the callback
|
||||
private readonly Delegate managedDelegate;
|
||||
|
||||
public NativeDelegateContext(object context, Delegate get)
|
||||
{
|
||||
managedDelegate = get;
|
||||
ManagedContext = context;
|
||||
NativeContext = Wrap();
|
||||
}
|
||||
|
||||
public object ManagedContext { get; }
|
||||
|
||||
public IntPtr NativeContext { get; }
|
||||
|
||||
public T GetDelegate<T>()
|
||||
{
|
||||
return (T)(object)managedDelegate;
|
||||
}
|
||||
|
||||
// wrap this context into a "native" pointer
|
||||
public IntPtr Wrap()
|
||||
{
|
||||
var guid = Guid.NewGuid();
|
||||
lock (contexts)
|
||||
{
|
||||
contexts.Add(guid, this);
|
||||
}
|
||||
var gc = GCHandle.Alloc(guid, GCHandleType.Pinned);
|
||||
return GCHandle.ToIntPtr(gc);
|
||||
}
|
||||
|
||||
// unwrap the "native" pointer into a managed context
|
||||
public static NativeDelegateContext Unwrap(IntPtr ptr)
|
||||
{
|
||||
var gchandle = GCHandle.FromIntPtr(ptr);
|
||||
var guid = (Guid)gchandle.Target;
|
||||
lock (contexts)
|
||||
{
|
||||
NativeDelegateContext value;
|
||||
contexts.TryGetValue(guid, out value);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
public void Free()
|
||||
{
|
||||
Free(NativeContext);
|
||||
}
|
||||
|
||||
// unwrap and free the context
|
||||
public static void Free(IntPtr ptr)
|
||||
{
|
||||
var gchandle = GCHandle.FromIntPtr(ptr);
|
||||
var guid = (Guid)gchandle.Target;
|
||||
lock (contexts)
|
||||
{
|
||||
contexts.Remove(guid);
|
||||
}
|
||||
gchandle.Free();
|
||||
}
|
||||
|
||||
void IDisposable.Dispose() => Free();
|
||||
}
|
||||
|
||||
internal static class PlatformConfiguration
|
||||
{
|
||||
public static bool IsUnix { get; }
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 1daf9781faba0f10188d03b0510a16fa2ac4bf6d
|
||||
Subproject commit 705b36175b691b598bc06b12b7e2485946f3c88f
|
Загрузка…
Ссылка в новой задаче