示例#1
0
        internal void RenderFrame()
        {
            if (!jsInfo.IsValid)
            {
                return;
            }

            // create the SkiaSharp context
            if (context == null)
            {
                glInterface = GRGlInterface.Create();
                context     = GRContext.CreateGl(glInterface);

                // bump the default resource cache limit
                context.SetResourceCacheLimit(ResourceCacheBytes);
            }

            // get the new surface size
            var newSize = new SKSizeI((int)(ActualWidth * ContentsScale), (int)(ActualHeight * ContentsScale));

            // manage the drawing surface
            if (renderTarget == null || lastSize != newSize || !renderTarget.IsValid)
            {
                // create or update the dimensions
                lastSize = newSize;

                glInfo = new GRGlFramebufferInfo(jsInfo.FboId, colorType.ToGlSizedFormat());

                // destroy the old surface
                surface?.Dispose();
                surface = null;
                canvas  = null;

                // re-create the render target
                renderTarget?.Dispose();
                renderTarget = new GRBackendRenderTarget(newSize.Width, newSize.Height, jsInfo.Samples, jsInfo.Stencil, glInfo);
            }

            // create the surface
            if (surface == null)
            {
                surface = SKSurface.Create(context, renderTarget, surfaceOrigin, colorType);
                canvas  = surface.Canvas;
            }

            using (new SKAutoCanvasRestore(canvas, true))
            {
                // start drawing
#pragma warning disable CS0612 // Type or member is obsolete
                OnPaintSurface(new SKPaintGLSurfaceEventArgs(surface, renderTarget, surfaceOrigin, colorType, glInfo));
#pragma warning restore CS0612 // Type or member is obsolete
            }

            // update the control
            canvas.Flush();
            context.Flush();
        }
示例#2
0
        public GlSkiaGpu(IWindowingPlatformGlFeature gl, long?maxResourceBytes)
        {
            var context = gl.MainContext;

            using (context.MakeCurrent())
            {
                using (var iface = context.Version.Type == GlProfileType.OpenGL ?
                                   GRGlInterface.CreateOpenGl(proc => context.GlInterface.GetProcAddress(proc)) :
                                   GRGlInterface.CreateGles(proc => context.GlInterface.GetProcAddress(proc)))
                {
                    _grContext = GRContext.CreateGl(iface);
                    if (maxResourceBytes.HasValue)
                    {
                        _grContext.SetResourceCacheLimit(maxResourceBytes.Value);
                    }
                }
            }
        }
示例#3
0
        public GlSkiaGpu(IPlatformOpenGlInterface openGl, long?maxResourceBytes)
        {
            var context = openGl.PrimaryContext;

            _glContext = context;
            using (context.MakeCurrent())
            {
                using (var iface = context.Version.Type == GlProfileType.OpenGL ?
                                   GRGlInterface.CreateOpenGl(proc => context.GlInterface.GetProcAddress(proc)) :
                                   GRGlInterface.CreateGles(proc => context.GlInterface.GetProcAddress(proc)))
                {
                    _grContext = GRContext.CreateGl(iface, new GRContextOptions {
                        AvoidStencilBuffers = true
                    });
                    if (maxResourceBytes.HasValue)
                    {
                        _grContext.SetResourceCacheLimit(maxResourceBytes.Value);
                    }
                }
            }
        }
示例#4
0
        private void Initialize()
        {
            GRVkGetProcedureAddressDelegate getProc = GetVulkanProcAddress;

            _grVkBackend = new GRVkBackendContext()
            {
                VkInstance          = _surface.Device.Handle,
                VkPhysicalDevice    = _vulkanPlatformInterface.PhysicalDevice.Handle,
                VkDevice            = _surface.Device.Handle,
                VkQueue             = _surface.Device.Queue.Handle,
                GraphicsQueueIndex  = _vulkanPlatformInterface.PhysicalDevice.QueueFamilyIndex,
                GetProcedureAddress = getProc
            };

            GrContext = GRContext.CreateVulkan(_grVkBackend);

            var gpu = AvaloniaLocator.Current.GetService <VulkanSkiaGpu>();

            if (gpu.MaxResourceBytes.HasValue)
            {
                GrContext.SetResourceCacheLimit(gpu.MaxResourceBytes.Value);
            }
        }