Example #1
0
        public static SKSurface Create(GRRecordingContext context, CoreAnimation.CAMetalLayer layer, GRSurfaceOrigin origin, int sampleCount, SKColorType colorType, SKColorSpace colorspace, SKSurfaceProperties props, out CoreAnimation.ICAMetalDrawable drawable)
        {
            void *drawablePtr;
            var   surface = GetObject(SkiaApi.sk_surface_new_metal_layer(context.Handle, (void *)layer.Handle, origin, sampleCount, colorType.ToNative(), colorspace?.Handle ?? IntPtr.Zero, props?.Handle ?? IntPtr.Zero, &drawablePtr));

            drawable = ObjCRuntime.Runtime.GetINativeObject <CoreAnimation.ICAMetalDrawable> ((IntPtr)drawablePtr, true);
            return(surface);
        }
Example #2
0
 public static SKShader CreateLinearGradient(SKPoint start, SKPoint end, SKColorF[] colors, SKColorSpace colorspace, SKShaderTileMode mode) =>
 CreateLinearGradient(start, end, colors, colorspace, null, mode);
Example #3
0
 public static SKShader CreateRadialGradient(SKPoint center, float radius, SKColorF[] colors, SKColorSpace colorspace, SKShaderTileMode mode) =>
 CreateRadialGradient(center, radius, colors, colorspace, null, mode);
Example #4
0
 public static SKSurface Create(GRContext context, GRBackendRenderTarget renderTarget, GRSurfaceOrigin origin, SKColorType colorType, SKColorSpace colorspace) =>
 Create(context, renderTarget, origin, colorType, colorspace, null);
Example #5
0
 public static SKSurface CreateAsRenderTarget(GRContext context, GRBackendTexture texture, GRSurfaceOrigin origin, int sampleCount, SKColorType colorType, SKColorSpace colorspace) =>
 CreateAsRenderTarget(context, texture, origin, sampleCount, colorType, colorspace, null);
Example #6
0
 public static SKShader CreateSweepGradient(SKPoint center, SKColorF[] colors, SKColorSpace colorspace, SKShaderTileMode tileMode, float startAngle, float endAngle) =>
 CreateSweepGradient(center, colors, colorspace, null, tileMode, startAngle, endAngle);
Example #7
0
 public static SKShader CreateTwoPointConicalGradient(SKPoint start, float startRadius, SKPoint end, float endRadius, SKColorF[] colors, SKColorSpace colorspace, SKShaderTileMode mode) =>
 CreateTwoPointConicalGradient(start, startRadius, end, endRadius, colors, colorspace, null, mode);
Example #8
0
 static SKColorSpace()
 {
     srgb       = new SKColorSpaceStatic(SkiaApi.sk_colorspace_new_srgb());
     srgbLinear = new SKColorSpaceStatic(SkiaApi.sk_colorspace_new_srgb_linear());
 }
Example #9
0
 public static SKImage FromTexture(GRContext context, GRBackendTexture texture, GRSurfaceOrigin origin, SKColorType colorType, SKAlphaType alpha, SKColorSpace colorspace)
 {
     return(FromTexture(context, texture, origin, colorType, alpha, colorspace, null, null));
 }
Example #10
0
        public static SKImage FromTexture(GRContext context, GRBackendTexture texture, GRSurfaceOrigin origin, SKColorType colorType, SKAlphaType alpha, SKColorSpace colorspace, SKImageTextureReleaseDelegate releaseProc, object releaseContext)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (texture == null)
            {
                throw new ArgumentNullException(nameof(texture));
            }

            var cs = colorspace == null ? IntPtr.Zero : colorspace.Handle;

            if (releaseProc == null)
            {
                return(GetObject <SKImage> (SkiaApi.sk_image_new_from_texture(context.Handle, texture.Handle, origin, colorType, alpha, cs, IntPtr.Zero, IntPtr.Zero)));
            }
            else
            {
                var ctx = new NativeDelegateContext(releaseContext, releaseProc);
                return(GetObject <SKImage> (SkiaApi.sk_image_new_from_texture(context.Handle, texture.Handle, origin, colorType, alpha, cs, textureReleaseDelegate, ctx.NativeContext)));
            }
        }
Example #11
0
 public SKImageInfo(int width, int height, SKColorType colorType, SKAlphaType alphaType, SKColorSpace colorspace)
 {
     this.width      = width;
     this.height     = height;
     this.colorType  = colorType;
     this.alphaType  = alphaType;
     this.colorSpace = colorspace;
 }
Example #12
0
        public bool CopyTo(SKBitmap destination, SKColorType colorType)
        {
            if (destination == null)
            {
                throw new ArgumentNullException(nameof(destination));
            }

            if (!CanCopyTo(colorType))
            {
                return(false);
            }

            var srcPM = PeekPixels();

            if (srcPM == null)
            {
                return(false);
            }

            var dstInfo = srcPM.Info.WithColorType(colorType);

            switch (colorType)
            {
            case SKColorType.Rgb565:
                // CopyTo() is not strict on alpha type. Here we set the src to opaque to allow
                // the call to ReadPixels() to succeed and preserve this lenient behavior.
                if (srcPM.AlphaType != SKAlphaType.Opaque)
                {
                    srcPM = srcPM.WithAlphaType(SKAlphaType.Opaque);
                }
                dstInfo.AlphaType = SKAlphaType.Opaque;
                break;

            case SKColorType.RgbaF16:
                // The caller does not have an opportunity to pass a dst color space.
                // Assume that they want linear sRGB.
                dstInfo.ColorSpace = SKColorSpace.CreateSrgbLinear();
                if (srcPM.ColorSpace == null)
                {
                    // We can't do a sane conversion to F16 without a dst color space.
                    // Guess sRGB in this case.
                    srcPM = srcPM.WithColorSpace(SKColorSpace.CreateSrgb());
                }
                break;
            }

            var tmpDst = new SKBitmap();

            if (!tmpDst.TryAllocPixels(dstInfo))
            {
                return(false);
            }

            var dstPM = tmpDst.PeekPixels();

            if (dstPM == null)
            {
                return(false);
            }

            // We can't do a sane conversion from F16 without a src color space. Guess sRGB in this case.
            if (srcPM.ColorType == SKColorType.RgbaF16 && dstPM.ColorSpace == null)
            {
                dstPM = dstPM.WithColorSpace(SKColorSpace.CreateSrgb());
            }

            // ReadPixels does not yet support color spaces with parametric transfer functions. This
            // works around that restriction when the color spaces are equal.
            if (colorType != SKColorType.RgbaF16 && srcPM.ColorType != SKColorType.RgbaF16 && dstPM.ColorSpace == srcPM.ColorSpace)
            {
                dstPM = dstPM.WithColorSpace(null);
                srcPM = srcPM.WithColorSpace(null);
            }

            if (!srcPM.ReadPixels(dstPM))
            {
                return(false);
            }

            destination.Swap(tmpDst);

            return(true);
        }
Example #13
0
 public static SKSurface Create(GRRecordingContext context, MetalKit.MTKView view, GRSurfaceOrigin origin, int sampleCount, SKColorType colorType, SKColorSpace colorspace, SKSurfaceProperties props) =>
 GetObject(SkiaApi.sk_surface_new_metal_view(context.Handle, (void *)view.Handle, origin, sampleCount, colorType.ToNative(), colorspace?.Handle ?? IntPtr.Zero, props?.Handle ?? IntPtr.Zero));
Example #14
0
 public static SKSurface Create(GRRecordingContext context, MetalKit.MTKView view, GRSurfaceOrigin origin, int sampleCount, SKColorType colorType, SKColorSpace colorspace) =>
 Create(context, view, origin, sampleCount, colorType, colorspace, null);
Example #15
0
 public static SKShader CreateSweepGradient(SKPoint center, SKColorF[] colors, SKColorSpace colorspace) =>
 CreateSweepGradient(center, colors, colorspace, null, SKShaderTileMode.Clamp, 0, 360);
Example #16
0
 public SKImageInfo(int width, int height, SKColorType colorType, SKAlphaType alphaType, SKColorSpace colorspace)
 {
     Width      = width;
     Height     = height;
     ColorType  = colorType;
     AlphaType  = alphaType;
     ColorSpace = colorspace;
 }
Example #17
0
 public static SKShader CreateSweepGradient(SKPoint center, SKColorF[] colors, SKColorSpace colorspace, float[] colorPos, SKMatrix localMatrix) =>
 CreateSweepGradient(center, colors, colorspace, colorPos, SKShaderTileMode.Clamp, 0, 360, localMatrix);
Example #18
0
 public static SKImage FromTexture(GRRecordingContext context, GRBackendTexture texture, GRSurfaceOrigin origin, SKColorType colorType, SKAlphaType alpha, SKColorSpace colorspace, SKImageTextureReleaseDelegate releaseProc) =>
 FromTexture(context, texture, origin, colorType, alpha, colorspace, releaseProc, null);
Example #19
0
        public static SKShader CreateSweepGradient(SKPoint center, SKColorF[] colors, SKColorSpace colorspace, float[] colorPos, SKShaderTileMode tileMode, float startAngle, float endAngle)
        {
            if (colors == null)
            {
                throw new ArgumentNullException(nameof(colors));
            }
            if (colorPos != null && colors.Length != colorPos.Length)
            {
                throw new ArgumentException("The number of colors must match the number of color positions.");

                fixed(SKColorF *c = colors)
                fixed(float *cp = colorPos)
                {
                    return(GetObject(SkiaApi.sk_shader_new_sweep_gradient_color4f(&center, c, colorspace?.Handle ?? IntPtr.Zero, cp, colors.Length, tileMode, startAngle, endAngle, null)));
                }
        }
Example #20
0
        public static SKImage FromTexture(GRRecordingContext context, GRBackendTexture texture, GRSurfaceOrigin origin, SKColorType colorType, SKAlphaType alpha, SKColorSpace colorspace, SKImageTextureReleaseDelegate releaseProc, object releaseContext)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (texture == null)
            {
                throw new ArgumentNullException(nameof(texture));
            }

            var cs  = colorspace == null ? IntPtr.Zero : colorspace.Handle;
            var del = releaseProc != null && releaseContext != null
                                ? new SKImageTextureReleaseDelegate((_) => releaseProc(releaseContext))
                                : releaseProc;
            var proxy = DelegateProxies.Create(del, DelegateProxies.SKImageTextureReleaseDelegateProxy, out _, out var ctx);

            return(GetObject(SkiaApi.sk_image_new_from_texture(context.Handle, texture.Handle, origin, colorType.ToNative(), alpha, cs, proxy, (void *)ctx)));
        }
Example #21
0
 public static SKShader CreateTwoPointConicalGradient(SKPoint start, float startRadius, SKPoint end, float endRadius, SKColorF[] colors, SKColorSpace colorspace, float[] colorPos, SKShaderTileMode mode)
 {
     if (colors == null)
         throw new ArgumentNullException(nameof(colors)); }
Example #22
0
 public static SKImage FromAdoptedTexture(GRContext context, GRBackendTexture texture, GRSurfaceOrigin origin, SKColorType colorType, SKAlphaType alpha, SKColorSpace colorspace) =>
 FromAdoptedTexture((GRRecordingContext)context, texture, origin, colorType, alpha, colorspace);
Example #23
0
        public static SKSurface Create(GRContext context, GRBackendRenderTarget renderTarget, GRSurfaceOrigin origin, SKColorType colorType, SKColorSpace colorspace, SKSurfaceProperties props)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (renderTarget == null)
            {
                throw new ArgumentNullException(nameof(renderTarget));
            }

            return(GetObject(SkiaApi.sk_surface_new_backend_render_target(context.Handle, renderTarget.Handle, origin, colorType, colorspace?.Handle ?? IntPtr.Zero, props?.Handle ?? IntPtr.Zero)));
        }
Example #24
0
        public static SKImage FromAdoptedTexture(GRRecordingContext context, GRBackendTexture texture, GRSurfaceOrigin origin, SKColorType colorType, SKAlphaType alpha, SKColorSpace colorspace)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (texture == null)
            {
                throw new ArgumentNullException(nameof(texture));
            }

            var cs = colorspace == null ? IntPtr.Zero : colorspace.Handle;

            return(GetObject(SkiaApi.sk_image_new_from_adopted_texture(context.Handle, texture.Handle, origin, colorType.ToNative(), alpha, cs)));
        }
Example #25
0
        public static SKSurface CreateAsRenderTarget(GRContext context, GRBackendTexture texture, GRSurfaceOrigin origin, int sampleCount, SKColorType colorType, SKColorSpace colorspace, SKSurfaceProperties props)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (texture == null)
            {
                throw new ArgumentNullException(nameof(texture));
            }

            return(GetObject(SkiaApi.sk_surface_new_backend_texture_as_render_target(context.Handle, texture.Handle, origin, sampleCount, colorType, colorspace?.Handle ?? IntPtr.Zero, props?.Handle ?? IntPtr.Zero)));
        }
Example #26
0
 public SKImage ToTextureImage(GRContext context, SKColorSpace colorspace) =>
 ToTextureImage(context, false);
Example #27
0
        public static SKShader CreateLinearGradient(SKPoint start, SKPoint end, SKColorF[] colors, SKColorSpace colorspace, float[] colorPos, SKShaderTileMode mode)
        {
            if (colors == null)
            {
                throw new ArgumentNullException(nameof(colors));
            }
            if (colorPos != null && colors.Length != colorPos.Length)
            {
                throw new ArgumentException("The number of colors must match the number of color positions.");
            }

            var points = stackalloc SKPoint[] { start, end };

            fixed(SKColorF *c = colors)
            fixed(float *cp = colorPos)
            {
                return(GetObject(SkiaApi.sk_shader_new_linear_gradient_color4f(points, c, colorspace?.Handle ?? IntPtr.Zero, cp, colors.Length, mode, null)));
            }
        }
Example #28
0
 public SKPixmap WithColorSpace(SKColorSpace newColorSpace)
 {
     return(new SKPixmap(Info.WithColorSpace(newColorSpace), GetPixels(), RowBytes));
 }
Example #29
0
        public static SKShader CreateRadialGradient(SKPoint center, float radius, SKColorF[] colors, SKColorSpace colorspace, float[] colorPos, SKShaderTileMode mode, SKMatrix localMatrix)
        {
            if (colors == null)
            {
                throw new ArgumentNullException(nameof(colors));
            }
            if (colorPos != null && colors.Length != colorPos.Length)
            {
                throw new ArgumentException("The number of colors must match the number of color positions.");

                fixed(SKColorF *c = colors)
                fixed(float *cp = colorPos)
                {
                    return(GetObject(SkiaApi.sk_shader_new_radial_gradient_color4f(&center, radius, c, colorspace?.Handle ?? IntPtr.Zero, cp, colors.Length, mode, &localMatrix)));
                }
        }
Example #30
0
 public static SKSurface Create(GRRecordingContext context, CoreAnimation.CAMetalLayer layer, GRSurfaceOrigin origin, int sampleCount, SKColorType colorType, SKColorSpace colorspace, out CoreAnimation.ICAMetalDrawable drawable) =>
 Create(context, layer, origin, sampleCount, colorType, colorspace, null, out drawable);