Esempio n. 1
0
        private void DrawGpuTextureWithDesc(Action <SKSurface, GRGlBackendTextureDesc> draw)
        {
            using (var ctx = CreateGlContext())
            {
                ctx.MakeCurrent();

                // create the texture
                var textureInfo = ctx.CreateTexture(new SKSizeI(100, 100));
                // this is a new field that was added to the struct
                textureInfo.Format = 0;
                var textureDesc = new GRGlBackendTextureDesc
                {
                    Width         = 100,
                    Height        = 100,
                    Config        = GRPixelConfig.Rgba8888,
                    Flags         = GRBackendTextureDescFlags.RenderTarget,
                    Origin        = GRSurfaceOrigin.BottomLeft,
                    SampleCount   = 0,
                    TextureHandle = textureInfo,
                };

                // create the surface
                using (var grContext = GRContext.Create(GRBackend.OpenGL))
                    using (var surface = SKSurface.CreateAsRenderTarget(grContext, textureDesc))
                    {
                        Assert.NotNull(surface);

                        draw(surface, textureDesc);
                    }

                // clean up
                ctx.DestroyTexture(textureInfo.Id);
            }
        }
Esempio n. 2
0
        private void DrawGpuTextureWithOldDesc(Action <SKSurface, GRBackendTextureDesc> draw)
        {
            using (var ctx = CreateGlContext())
            {
                ctx.MakeCurrent();

                // create the texture
                var textureInfo = ctx.CreateTexture(new SKSizeI(100, 100));

                var oldInfo = new GRTextureInfoOld
                {
                    Id     = textureInfo.Id,
                    Target = textureInfo.Target
                };
                var textureHandle = GCHandle.Alloc(oldInfo, GCHandleType.Pinned);
                var textureDesc   = new GRBackendTextureDesc
                {
                    Width         = 100,
                    Height        = 100,
                    Config        = GRPixelConfig.Rgba8888,
                    Flags         = GRBackendTextureDescFlags.RenderTarget,
                    Origin        = GRSurfaceOrigin.BottomLeft,
                    SampleCount   = 0,
                    TextureHandle = textureHandle.AddrOfPinnedObject(),
                };

                // create the surface
                using (var grContext = GRContext.Create(GRBackend.OpenGL))
                    using (var surface = SKSurface.CreateAsRenderTarget(grContext, textureDesc))
                    {
                        Assert.NotNull(surface);

                        draw(surface, textureDesc);
                    }

                // clean up
                textureHandle.Free();
                ctx.DestroyTexture(textureInfo.Id);
            }
        }
Esempio n. 3
0
        internal static RasterCacheResult Rasterize(GRContext context, SKMatrix ctm, SKColorSpace dst_color_space, bool checkerboard, SKRect logical_rect, Action <SKCanvas> draw_function)
        {
            SKRectI cache_rect = RasterCache.GetDeviceBounds(logical_rect, ctm);

            SKImageInfo image_info = new SKImageInfo(cache_rect.Width, cache_rect.Height);

            SKSurface surface = context != null?SKSurface.CreateAsRenderTarget(context, new GRGlBackendTextureDesc()
            {
                Width = cache_rect.Width, Height = cache_rect.Height
            }) : SKSurface.Create(image_info);                                                                                                                                                                    //{ image_info.

            if (surface == null)
            {
                return(new RasterCacheResult());
            }

            SKCanvas canvas      = surface.Canvas;
            SKCanvas xformCanvas = canvas;

            //if (dst_color_space != null)
            //{
            //    xformCanvas = SkCreateColorSpaceXformCanvas(canvas, GlobalMembers.sk_ref_sp(dst_color_space));
            //    if (xformCanvas != null)
            //    {
            //        canvas = xformCanvas;
            //    }
            //}

            canvas.Clear(GlobalMembers.SK_ColorTRANSPARENT);
            canvas.Translate(-cache_rect.Left, -cache_rect.Top);
            canvas.Concat(ref ctm);
            draw_function(canvas);

            //if (checkerboard)
            //{
            //    DrawCheckerboard(canvas, logical_rect);
            //}

            return(new RasterCacheResult(surface.Snapshot(), logical_rect));
        }
Esempio n. 4
0
        private void DrawGpuTexture(Action <SKSurface, GRBackendTexture> draw)
        {
            using (var ctx = CreateGlContext())
            {
                ctx.MakeCurrent();

                // create the texture
                var textureInfo = ctx.CreateTexture(new SKSizeI(100, 100));
                var texture     = new GRBackendTexture(100, 100, false, textureInfo);

                // create the surface
                using (var grContext = GRContext.Create(GRBackend.OpenGL))
                    using (var surface = SKSurface.CreateAsRenderTarget(grContext, texture, SKColorType.Rgba8888))
                    {
                        Assert.NotNull(surface);

                        draw(surface, texture);
                    }

                // clean up
                ctx.DestroyTexture(textureInfo.Id);
            }
        }
        private void PrepareSkia()
        {
            // CONTEXT

            // create the SkiaSharp context
            var glInterface = GRGlInterface.CreateNativeGlInterface();

            context = GRContext.Create(GRBackend.OpenGL, glInterface);

            // TEXTURE

            // the texture size
            var textureSize = new SKSizeI(256, 256);

            // create the OpenGL texture
            textureId = GL.GenTexture();
            GL.BindTexture(TextureTarget.Texture2D, textureId);
            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, textureSize.Width, textureSize.Height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero);
            GL.BindTexture(TextureTarget.Texture2D, 0);

            // create the SkiaSharp texture description
            var textureInfo = new GRGlTextureInfo
            {
                Id     = (uint)textureId,
                Target = (uint)TextureTarget.Texture2D
            };
            var textureHandle = GCHandle.Alloc(textureInfo, GCHandleType.Pinned);

            textureDesc = new GRBackendTextureDesc
            {
                Width         = textureSize.Width,
                Height        = textureSize.Height,
                Config        = GRPixelConfig.Rgba8888,
                Flags         = GRBackendTextureDescFlags.RenderTarget,
                Origin        = GRSurfaceOrigin.TopLeft,
                SampleCount   = 0,
                TextureHandle = textureHandle.AddrOfPinnedObject(),
            };

            // create the SkiaSharp texture surface
            textureSurface = SKSurface.CreateAsRenderTarget(context, textureDesc);

            // free the pinned GC handle when we are done
            textureHandle.Free();

            // initialize the texture content
            UpdateTexture(false);

            // RENDER TARGET

            // create the SkiaSharp render target description
            renderDesc = new GRBackendRenderTargetDesc
            {
                RenderTargetHandle = (IntPtr)0,
                Width       = Width,
                Height      = Height,
                Config      = GRPixelConfig.Rgba8888,
                Origin      = GRSurfaceOrigin.TopLeft,
                SampleCount = 0,
                StencilBits = 0,
            };

            // create the SkiaSharp render target surface
            renderSurface = SKSurface.Create(context, renderDesc);
        }