示例#1
0
        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();
        }
示例#2
0
 protected virtual void OnPaintSurface(SKPaintMetalSurfaceEventArgs e)
 {
     PaintSurface?.Invoke(this, e);
 }