Ejemplo n.º 1
0
        /// <inheritdoc />
        public IDrawingContextImpl CreateDrawingContext(IVisualBrushRenderer visualBrushRenderer)
        {
            var framebuffer          = _platformSurface.Lock();
            var framebufferImageInfo = new SKImageInfo(framebuffer.Size.Width, framebuffer.Size.Height,
                                                       framebuffer.Format.ToSkColorType(),
                                                       framebuffer.Format == PixelFormat.Rgb565 ? SKAlphaType.Opaque : SKAlphaType.Premul);

            CreateSurface(framebufferImageInfo, framebuffer);

            var canvas = _framebufferSurface.Canvas;

            canvas.RestoreToCount(-1);
            canvas.Save();
            canvas.ResetMatrix();

            var createInfo = new DrawingContextImpl.CreateInfo
            {
                Canvas = canvas,
                Dpi    = framebuffer.Dpi,
                VisualBrushRenderer     = visualBrushRenderer,
                DisableTextLcdRendering = true
            };

            return(new DrawingContextImpl(createInfo, _preFramebufferCopyHandler, canvas, framebuffer));
        }
Ejemplo n.º 2
0
        public IDrawingContextImpl CreateDrawingContext(IVisualBrushRenderer visualBrushRenderer)
        {
            var session = _surface.BeginDraw();
            var disp    = session.Display;
            var gl      = disp.GlInterface;

            gl.GetIntegerv(GL_FRAMEBUFFER_BINDING, out var fb);

            var size    = session.Size;
            var scaling = session.Scaling;

            if (size.Width <= 0 || size.Height <= 0 || scaling < 0)
            {
                throw new InvalidOperationException(
                          $"Can't create drawing context for surface with {size} size and {scaling} scaling");
            }

            gl.Viewport(0, 0, size.Width, size.Height);
            gl.ClearStencil(0);
            gl.ClearColor(0, 0, 0, 0);
            gl.Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
            lock (_grContext)
            {
                _grContext.ResetContext();

                GRBackendRenderTarget renderTarget =
                    new GRBackendRenderTarget(size.Width, size.Height, disp.SampleCount, disp.StencilSize,
                                              new GRGlFramebufferInfo((uint)fb, GRPixelConfig.Rgba8888.ToGlSizedFormat()));
                var surface = SKSurface.Create(_grContext, renderTarget,
                                               GRSurfaceOrigin.BottomLeft,
                                               GRPixelConfig.Rgba8888.ToColorType());

                var nfo = new DrawingContextImpl.CreateInfo
                {
                    GrContext               = _grContext,
                    Canvas                  = surface.Canvas,
                    Dpi                     = SkiaPlatform.DefaultDpi * scaling,
                    VisualBrushRenderer     = visualBrushRenderer,
                    DisableTextLcdRendering = true
                };

                return(new DrawingContextImpl(nfo, Disposable.Create(() =>
                {
                    surface.Canvas.Flush();
                    surface.Dispose();
                    renderTarget.Dispose();
                    _grContext.Flush();
                    session.Dispose();
                })));
            }
        }
Ejemplo n.º 3
0
        public IDrawingContextImpl CreateDrawingContext(IVisualBrushRenderer visualBrushRenderer)
        {
            ICustomSkiaRenderSession session = _renderTarget.BeginRendering();

            var nfo = new DrawingContextImpl.CreateInfo
            {
                GrContext               = session.GrContext,
                Canvas                  = session.Canvas,
                Dpi                     = SkiaPlatform.DefaultDpi * session.ScaleFactor,
                VisualBrushRenderer     = visualBrushRenderer,
                DisableTextLcdRendering = true
            };

            return(new DrawingContextImpl(nfo, session));
        }
Ejemplo n.º 4
0
        /// <inheritdoc />
        public IDrawingContextImpl CreateDrawingContext(IVisualBrushRenderer visualBrushRenderer)
        {
            _canvas.RestoreToCount(-1);
            _canvas.ResetMatrix();

            var createInfo = new DrawingContextImpl.CreateInfo
            {
                Canvas = _canvas,
                Dpi    = _dpi,
                VisualBrushRenderer     = visualBrushRenderer,
                DisableTextLcdRendering = _disableLcdRendering
            };

            return(new DrawingContextImpl(createInfo));
        }
Ejemplo n.º 5
0
        public IDrawingContextImpl CreateDrawingContext(IVisualBrushRenderer visualBrushRenderer)
        {
            var session = _renderTarget.BeginRenderingSession();

            var nfo = new DrawingContextImpl.CreateInfo
            {
                GrContext               = session.GrContext,
                Surface                 = session.SkSurface,
                Dpi                     = SkiaPlatform.DefaultDpi * session.ScaleFactor,
                VisualBrushRenderer     = visualBrushRenderer,
                DisableTextLcdRendering = true
            };

            return(new DrawingContextImpl(nfo, session));
        }
        /// <inheritdoc />
        public IDrawingContextImpl CreateDrawingContext(IVisualBrushRenderer visualBrushRenderer)
        {
            _canvas.RestoreToCount(-1);
            _canvas.ResetMatrix();

            var createInfo = new DrawingContextImpl.CreateInfo
            {
                Canvas = _canvas,
                Dpi    = Dpi,
                VisualBrushRenderer     = visualBrushRenderer,
                DisableTextLcdRendering = _disableLcdRendering,
                GrContext = _grContext
            };

            return(new DrawingContextImpl(createInfo, Disposable.Create(() => Version++)));
        }
Ejemplo n.º 7
0
        public IDrawingContextImpl CreateDrawingContext(IVisualBrushRenderer visualBrushRenderer)
        {
            var session = _surface.BeginDraw();
            var disp    = session.Display;
            var gl      = disp.GlInterface;

            gl.GetIntegerv(GL_FRAMEBUFFER_BINDING, out var fb);

            var size    = session.PixelSize;
            var scaling = session.Scaling;

            GRBackendRenderTargetDesc desc = new GRBackendRenderTargetDesc
            {
                Width              = size.Width,
                Height             = size.Height,
                SampleCount        = disp.SampleCount,
                StencilBits        = disp.StencilSize,
                Config             = GRPixelConfig.Rgba8888,
                Origin             = GRSurfaceOrigin.BottomLeft,
                RenderTargetHandle = new IntPtr(fb)
            };

            gl.Viewport(0, 0, desc.Width, desc.Height);
            gl.ClearStencil(0);
            gl.ClearColor(0, 0, 0, 0);
            gl.Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

            var surface = SKSurface.Create(_grContext, desc);

            var nfo = new DrawingContextImpl.CreateInfo
            {
                GrContext               = _grContext,
                Canvas                  = surface.Canvas,
                Dpi                     = SkiaPlatform.DefaultDpi * scaling,
                VisualBrushRenderer     = visualBrushRenderer,
                DisableTextLcdRendering = true
            };

            return(new DrawingContextImpl(nfo, Disposable.Create(() =>
            {
                surface.Canvas.Flush();
                surface.Dispose();
                session.Dispose();
            })));
        }