示例#1
0
        public void Draw(DrawingContextImpl context, SKRect sourceRect, SKRect destRect, SKPaint paint)
        {
            // For now silently ignore
            if (context.GrContext == null)
            {
                return;
            }

            using (Lock())
            {
                if (_textureId == 0)
                {
                    return;
                }
                using (var backendTexture = new GRBackendTexture(PixelSize.Width, PixelSize.Height, false,
                                                                 new GRGlTextureInfo(
                                                                     GlConsts.GL_TEXTURE_2D, (uint)_textureId,
                                                                     (uint)_internalFormat)))
                    using (var surface = SKSurface.Create(context.GrContext, backendTexture, GRSurfaceOrigin.TopLeft,
                                                          SKColorType.Rgba8888))
                    {
                        // Again, silently ignore, if something went wrong it's not our fault
                        if (surface == null)
                        {
                            return;
                        }

                        using (var snapshot = surface.Snapshot())
                            context.Canvas.DrawImage(snapshot, sourceRect, destRect, paint);
                    }
            }
        }
            public void Render(IDrawingContextImpl context)
            {
                var eglSurface = _eglInterop.CreateEglSurface();

                var textureHandle = _eglInterop.BindTexture(eglSurface);

                var grContext = (context as ISkiaDrawingContextImpl).GrContext;

                var desc = new GRBackendTextureDesc
                {
                    TextureHandle = new IntPtr(textureHandle),
                    Config        = GRPixelConfig.Rgba8888,
                    Height        = 600,
                    Width         = 800,
                    Origin        = GRSurfaceOrigin.TopLeft
                };

                using (var texture = new GRBackendTexture(600, 800, false, new GRGlTextureInfo(GlConsts.GL_TEXTURE_2D, textureHandle, GlConsts.GL_RGBA8)))
                {
                    using (var surface = SKSurface.Create(grContext, texture, SKColorType.Rgba8888))
                    {
                        var canvas = (context as ISkiaDrawingContextImpl)?.SkCanvas;

                        canvas.DrawSurface(surface, new SKPoint(10, 10));
                    }
                }
            }
示例#3
0
        SKImage ToImage(Texture2D texture)
        {
            // Taken form VL.Video.MediaFoundation
            const int GL_TEXTURE_BINDING_2D = 0x8069;

            var eglContext = renderContext.EglContext;
            var eglImage   = eglContext.CreateImageFromD3D11Texture(texture.NativePointer);

            uint textureId = 0;

            NativeGles.glGenTextures(1, ref textureId);

            // We need to restore the currently bound texture (https://github.com/devvvvs/vvvv/issues/5925)
            NativeGles.glGetIntegerv(GL_TEXTURE_BINDING_2D, out var currentTextureId);
            NativeGles.glBindTexture(NativeGles.GL_TEXTURE_2D, textureId);
            NativeGles.glEGLImageTargetTexture2DOES(NativeGles.GL_TEXTURE_2D, eglImage);
            NativeGles.glBindTexture(NativeGles.GL_TEXTURE_2D, (uint)currentTextureId);

            var description = texture.Description;
            var colorType   = GetColorType(description.Format);
            var glInfo      = new GRGlTextureInfo(
                id: textureId,
                target: NativeGles.GL_TEXTURE_2D,
                format: colorType.ToGlSizedFormat());

            var backendTexture = new GRBackendTexture(
                width: description.Width,
                height: description.Height,
                mipmapped: false,
                glInfo: glInfo);

            var image = SKImage.FromTexture(
                renderContext.SkiaContext,
                backendTexture,
                GRSurfaceOrigin.BottomLeft,
                colorType,
                SKAlphaType.Premul,
                colorspace: SKColorSpace.CreateSrgb(),
                releaseProc: _ =>
            {
                renderContext.MakeCurrent();

                backendTexture.Dispose();
                NativeGles.glDeleteTextures(1, ref textureId);
                eglImage.Dispose();
                texture.Dispose();
            });

            return(image);
        }
示例#4
0
        public void CanConvertFromPointerToDescToTextureWithNewInfo()
        {
            // the custom struct to contain the info
            var oldInfo = new GRGlTextureInfo
            {
                Id     = 123,
                Target = 456,
                Format = 789
            };

            // pin it for the native code
            var textureHandle = GCHandle.Alloc(oldInfo, GCHandleType.Pinned);

            // use the very old desc
            var textureDesc = new GRBackendTextureDesc
            {
                Width         = 100,
                Height        = 100,
                Config        = GRPixelConfig.Rgba8888,
                Flags         = GRBackendTextureDescFlags.RenderTarget,
                Origin        = GRSurfaceOrigin.BottomLeft,
                SampleCount   = 246,
                TextureHandle = textureHandle.AddrOfPinnedObject(),
            };

            // create the new texture
            var texture = new GRBackendTexture(textureDesc);

            // free up all resourcess
            textureHandle.Free();

            // make sure we kept the information
            Assert.Equal(100, texture.Width);
            Assert.Equal(100, texture.Height);
            var newInfo = texture.GetGlTextureInfo();

            Assert.Equal(oldInfo.Id, newInfo.Id);
            Assert.Equal(oldInfo.Target, newInfo.Target);
            Assert.Equal(GRPixelConfig.Rgba8888.ToGlSizedFormat(), newInfo.Format);
        }
示例#5
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);
            }
        }