public SKPaintGLSurfaceEventArgs(SKSurface surface, GRBackendRenderTarget renderTarget, GRSurfaceOrigin origin, SKColorType colorType) { Surface = surface; BackendRenderTarget = renderTarget; ColorType = colorType; Origin = origin; }
public BlazorSkiaSurface(GRContext context, SKHtmlCanvasInterop.GLInfo glInfo, SKColorType colorType, PixelSize size, double scaling, GRSurfaceOrigin origin) { Context = context; GlInfo = glInfo; ColorType = colorType; Size = size; Scaling = scaling; Origin = origin; }
public SKPaintGLSurfaceEventArgs(SKSurface surface, GRBackendRenderTarget renderTarget, GRSurfaceOrigin origin, SKImageInfo info, SKImageInfo rawInfo) { Surface = surface; BackendRenderTarget = renderTarget; ColorType = info.ColorType; Origin = origin; Info = info; RawInfo = rawInfo; }
public SKPaintGLSurfaceEventArgs(SKSurface surface, GRBackendRenderTarget renderTarget, GRSurfaceOrigin origin, SKColorType colorType) { Surface = surface; BackendRenderTarget = renderTarget; ColorType = colorType; Origin = origin; Info = new SKImageInfo(renderTarget.Width, renderTarget.Height, ColorType); RawInfo = Info; }
public SKPaintGLSurfaceEventArgs(SKSurface surface, GRBackendRenderTarget renderTarget, GRSurfaceOrigin origin, SKColorType colorType, GRGlFramebufferInfo glInfo) { Surface = surface; BackendRenderTarget = renderTarget; ColorType = colorType; Origin = origin; rtDesc = CreateDesc(glInfo); Info = new SKImageInfo(renderTarget.Width, renderTarget.Height, colorType); RawInfo = Info; }
public SKPaintGLSurfaceEventArgs(SKSurface surface, GRBackendRenderTarget renderTarget, GRSurfaceOrigin origin, SKColorType colorType, GRGlFramebufferInfo glInfo) { Surface = surface; BackendRenderTarget = renderTarget; ColorType = colorType; Origin = origin; #pragma warning disable CS0612 // Type or member is obsolete rtDesc = CreateDesc(glInfo); #pragma warning restore CS0612 // Type or member is obsolete }
public static SKSurface Create(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 <SKSurface> (SkiaApi.sk_surface_new_backend_texture(context.Handle, texture.Handle, origin, sampleCount, colorType, colorspace?.Handle ?? IntPtr.Zero, props?.Handle ?? IntPtr.Zero))); }
void IMTKViewDelegate.Draw(MTKView view) { if (designMode) { return; } if (backendContext.Device == null || backendContext.Queue == null || CurrentDrawable?.Texture == null) { return; } CanvasSize = DrawableSize.ToSKSize(); if (CanvasSize.Width <= 0 || CanvasSize.Height <= 0) { return; } // create the contexts if not done already context ??= GRContext.CreateMetal(backendContext); const SKColorType colorType = SKColorType.Bgra8888; const GRSurfaceOrigin surfaceOrigin = GRSurfaceOrigin.TopLeft; // create the render target var metalInfo = new GRMtlTextureInfo(CurrentDrawable.Texture); using var renderTarget = new GRBackendRenderTarget((int)CanvasSize.Width, (int)CanvasSize.Height, (int)SampleCount, metalInfo); // create the surface using var surface = SKSurface.Create(context, renderTarget, surfaceOrigin, colorType); using var canvas = surface.Canvas; // start drawing var e = new SKPaintMetalSurfaceEventArgs(surface, renderTarget, surfaceOrigin, colorType); OnPaintSurface(e); // flush the SkiaSharp contents canvas.Flush(); surface.Flush(); context.Flush(); // present using var commandBuffer = backendContext.Queue.CommandBuffer(); commandBuffer.PresentDrawable(CurrentDrawable); commandBuffer.Commit(); }
public static SKSurface CreateAsRenderTarget(GRContext context, GRBackendTexture texture, GRSurfaceOrigin origin, SKColorType colorType) => CreateAsRenderTarget(context, texture, origin, 0, colorType, null, null);
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))); } }
public static SKImage FromAdoptedTexture(GRContext context, GRBackendTexture texture, GRSurfaceOrigin origin, SKColorType colorType, SKAlphaType alpha) { return(FromAdoptedTexture(context, texture, origin, colorType, alpha, null)); }
public static SKImage FromTexture(GRContext context, GRBackendTexture texture, GRSurfaceOrigin origin, SKColorType colorType, SKAlphaType alpha, SKColorSpace colorspace, SKImageTextureReleaseDelegate releaseProc) { return(FromTexture(context, texture, origin, colorType, alpha, colorspace, releaseProc, null)); }
public static SKSurface Create(GRContext 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);
public static SKSurface Create(GRContext context, bool budgeted, SKImageInfo info, int sampleCount, GRSurfaceOrigin origin) => Create(context, budgeted, info, sampleCount, GRSurfaceOrigin.BottomLeft, null, false);
public static SKSurface CreateAsRenderTarget(GRContext context, GRBackendTexture texture, GRSurfaceOrigin origin, int sampleCount, SKColorType colorType, SKColorSpace colorspace) => CreateAsRenderTarget(context, texture, origin, sampleCount, colorType, colorspace, null);
public static SKSurface Create(GRContext 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); }
public SKPaintGLSurfaceEventArgs(SKSurface surface, GRBackendRenderTarget renderTarget, GRSurfaceOrigin origin, SKImageInfo info) : this(surface, renderTarget, origin, info, info) { }
public FboSkiaSurface(GRContext grContext, IGlContext glContext, PixelSize pixelSize, GRSurfaceOrigin surfaceOrigin) { _grContext = grContext; _glContext = glContext; _pixelSize = pixelSize; var InternalFormat = glContext.Version.Type == GlProfileType.OpenGLES ? GL_RGBA : GL_RGBA8; var gl = glContext.GlInterface; // Save old bindings gl.GetIntegerv(GL_FRAMEBUFFER_BINDING, out var oldFbo); gl.GetIntegerv(GL_RENDERBUFFER_BINDING, out var oldRenderbuffer); gl.GetIntegerv(GL_TEXTURE_BINDING_2D, out var oldTexture); var arr = new int[2]; // Generate FBO gl.GenFramebuffers(1, arr); _fbo = arr[0]; gl.BindFramebuffer(GL_FRAMEBUFFER, _fbo); // Create a texture to render into gl.GenTextures(1, arr); _texture = arr[0]; gl.BindTexture(GL_TEXTURE_2D, _texture); gl.TexImage2D(GL_TEXTURE_2D, 0, InternalFormat, pixelSize.Width, pixelSize.Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, IntPtr.Zero); gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); gl.FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _texture, 0); var success = false; foreach (var useStencil8 in TrueFalse) { gl.GenRenderbuffers(1, arr); _depthStencil = arr[0]; gl.BindRenderbuffer(GL_RENDERBUFFER, _depthStencil); if (useStencil8) { gl.RenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, pixelSize.Width, pixelSize.Height); gl.FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, _depthStencil); } else { gl.RenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, pixelSize.Width, pixelSize.Height); gl.FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, _depthStencil); gl.FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, _depthStencil); } var status = gl.CheckFramebufferStatus(GL_FRAMEBUFFER); if (status == GL_FRAMEBUFFER_COMPLETE) { success = true; break; } else { gl.BindRenderbuffer(GL_RENDERBUFFER, oldRenderbuffer); gl.DeleteRenderbuffers(1, arr); } } gl.BindRenderbuffer(GL_RENDERBUFFER, oldRenderbuffer); gl.BindTexture(GL_TEXTURE_2D, oldTexture); gl.BindFramebuffer(GL_FRAMEBUFFER, oldFbo); if (!success) { arr[0] = _fbo; gl.DeleteFramebuffers(1, arr); arr[0] = _texture; gl.DeleteTextures(1, arr); throw new OpenGlException("Unable to create FBO with stencil"); } var target = new GRBackendRenderTarget(pixelSize.Width, pixelSize.Height, 0, 8, new GRGlFramebufferInfo((uint)_fbo, SKColorType.Rgba8888.ToGlSizedFormat())); Surface = SKSurface.Create(_grContext, target, surfaceOrigin, SKColorType.Rgba8888); CanBlit = gl.BlitFramebuffer != null; }
public static SKSurface CreateAsRenderTarget(GRContext context, GRBackendTexture texture, GRSurfaceOrigin origin, int sampleCount, SKColorType colorType, SKSurfaceProperties props) => CreateAsRenderTarget(context, texture, origin, sampleCount, colorType, null, props);
protected override void PaintSurface(SKSurface skSurface, GRBackendRenderTarget grBackendRenderTarget, GRSurfaceOrigin grSurfaceOrigin, SKColorType skColorType) { // Paint all elements from the canvas on the surface new SkiaPainter(skSurface).Paint(view.Content); }
public static SKSurface Create(GRContext context, bool budgeted, SKImageInfo info, int sampleCount, GRSurfaceOrigin origin, SKSurfaceProperties props, bool shouldCreateWithMips) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var cinfo = SKImageInfoNative.FromManaged(ref info); return(GetObject <SKSurface> (SkiaApi.sk_surface_new_render_target(context.Handle, budgeted, ref cinfo, sampleCount, origin, props?.Handle ?? IntPtr.Zero, shouldCreateWithMips))); }
public static SKSurface Create(GRContext context, GRBackendRenderTarget renderTarget, GRSurfaceOrigin origin, SKColorType colorType, SKColorSpace colorspace) => Create(context, renderTarget, origin, colorType, colorspace, null);
public static SKSurface Create(GRContext context, GRBackendRenderTarget renderTarget, GRSurfaceOrigin origin, SKColorType colorType, SKSurfaceProperties props) => Create(context, renderTarget, origin, colorType, null, props);
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 <SKSurface> (SkiaApi.sk_surface_new_backend_render_target(context.Handle, renderTarget.Handle, origin, colorType, colorspace?.Handle ?? IntPtr.Zero, props?.Handle ?? IntPtr.Zero))); }
public static SKImage FromTexture(GRContext context, GRBackendTexture texture, GRSurfaceOrigin origin, SKColorType colorType) { return(FromTexture(context, texture, origin, colorType, SKAlphaType.Premul, null, null, null)); }
public static SKSurface Create(GRContext context, GRBackendTexture texture, GRSurfaceOrigin origin, int sampleCount, SKColorType colorType) => Create(context, texture, origin, sampleCount, colorType, null, null);
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; var del = releaseProc != null && releaseContext != null ? new SKImageTextureReleaseDelegate((_) => releaseProc(releaseContext)) : releaseProc; var proxy = DelegateProxies.Create(del, DelegateProxies.SKImageTextureReleaseDelegateProxy, out _, out var ctx); return(GetObject <SKImage> (SkiaApi.sk_image_new_from_texture(context.Handle, texture.Handle, origin, colorType, alpha, cs, proxy, (void *)ctx))); }
public static SKSurface Create(GRContext context, GRBackendTexture texture, GRSurfaceOrigin origin, SKColorType colorType, SKSurfaceProperties props) => Create(context, texture, origin, 0, colorType, null, props);
public static SKImage FromAdoptedTexture(GRContext 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 <SKImage> (SkiaApi.sk_image_new_from_adopted_texture(context.Handle, texture.Handle, origin, colorType, alpha, cs))); }
public static SKSurface CreateAsRenderTarget(GRContext context, GRBackendTexture texture, GRSurfaceOrigin origin, int sampleCount, SKColorType colorType, 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 <SKSurface> (SkiaApi.sk_surface_new_backend_texture_as_render_target(context.Handle, texture.Handle, origin, sampleCount, colorType, cs, IntPtr.Zero))); }