Пример #1
0
        private void CreateVulkan(int width, int height, GRVkImageInfo vkInfo)
        {
            Handle = SkiaApi.gr_backendtexture_new_vulkan(width, height, &vkInfo);

            if (Handle == IntPtr.Zero)
            {
                throw new InvalidOperationException("Unable to create a new GRBackendTexture instance.");
            }
        }
Пример #2
0
        private void CreateVulkan(int width, int height, int sampleCount, GRVkImageInfo vkImageInfo)
        {
            Handle = SkiaApi.gr_backendrendertarget_new_vulkan(width, height, sampleCount, &vkImageInfo);

            if (Handle == IntPtr.Zero)
            {
                throw new InvalidOperationException("Unable to create a new GRBackendRenderTarget instance.");
            }
        }
Пример #3
0
 public GRBackendTexture(int width, int height, GRVkImageInfo vkInfo)
     : this(IntPtr.Zero, true)
 {
     CreateVulkan(width, height, vkInfo);
 }
Пример #4
0
 public GRBackendRenderTarget(int width, int height, int sampleCount, GRVkImageInfo vkImageInfo)
     : this(IntPtr.Zero, true)
 {
     CreateVulkan(width, height, sampleCount, vkImageInfo);
 }
Пример #5
0
            public unsafe void Render(IDrawingContextImpl context)
            {
                if (_isDestroyed || _control.Image == null || _control.RenderSize.Width == 0 || _control.RenderSize.Height == 0 ||
                    context is not ISkiaDrawingContextImpl skiaDrawingContextImpl)
                {
                    return;
                }

                var image = _control.GetImage();

                if (!image.State.IsValid)
                {
                    _control._currentImage = null;

                    return;
                }

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

                image.Get();

                var imageInfo = new GRVkImageInfo()
                {
                    CurrentQueueFamily = _control._platformInterface.PhysicalDevice.QueueFamilyIndex,
                    Format             = (uint)Format.R8G8B8A8Unorm,
                    Image           = image.Image.Handle,
                    ImageLayout     = (uint)ImageLayout.TransferSrcOptimal,
                    ImageTiling     = (uint)ImageTiling.Optimal,
                    ImageUsageFlags = (uint)(ImageUsageFlags.ImageUsageColorAttachmentBit
                                             | ImageUsageFlags.ImageUsageTransferSrcBit
                                             | ImageUsageFlags.ImageUsageTransferDstBit),
                    LevelCount  = 1,
                    SampleCount = 1,
                    Protected   = false,
                    Alloc       = new GRVkAlloc()
                    {
                        Memory = image.Memory.Handle,
                        Flags  = 0,
                        Offset = image.MemoryOffset,
                        Size   = image.MemorySize
                    }
                };

                using var backendTexture = new GRBackendRenderTarget(
                          (int)image.Extent.Width,
                          (int)image.Extent.Height,
                          1,
                          imageInfo);

                var vulkan = AvaloniaLocator.Current.GetService <VulkanPlatformInterface>();

                using var surface = SKSurface.Create(
                          skiaDrawingContextImpl.GrContext,
                          backendTexture,
                          GRSurfaceOrigin.TopLeft,
                          SKColorType.Rgba8888);

                if (surface == null)
                {
                    return;
                }

                var rect = new Rect(new Point(), new Size(image.Extent.Width, image.Extent.Height));

                using var snapshot = surface.Snapshot();
                skiaDrawingContextImpl.SkCanvas.DrawImage(snapshot, rect.ToSKRect(), _control.Bounds.ToSKRect(),
                                                          new SKPaint());
            }
Пример #6
0
        public ISkiaGpuRenderSession BeginRenderingSession()
        {
            var  session = _surface.BeginDraw(_vulkanPlatformSurface.Scaling);
            bool success = false;

            try
            {
                var disp = session.Display;
                var api  = session.Api;

                var size    = session.Size;
                var scaling = session.Scaling;
                if (size.Width <= 0 || size.Height <= 0 || scaling < 0)
                {
                    size    = new Avalonia.PixelSize(1, 1);
                    scaling = 1;
                }

                lock (GrContext)
                {
                    GrContext.ResetContext();

                    var image = _surface.GetImage();

                    var imageInfo = new GRVkImageInfo()
                    {
                        CurrentQueueFamily = disp.QueueFamilyIndex,
                        Format             = (uint)image.Format,
                        Image           = image.Handle,
                        ImageLayout     = (uint)image.CurrentLayout,
                        ImageTiling     = (uint)image.Tiling,
                        ImageUsageFlags = _surface.UsageFlags,
                        LevelCount      = _surface.MipLevels,
                        SampleCount     = 1,
                        Protected       = false,
                        Alloc           = new GRVkAlloc()
                        {
                            Memory = image.MemoryHandle,
                            Flags  = 0,
                            Offset = 0,
                            Size   = _surface.MemorySize
                        }
                    };

                    var renderTarget =
                        new GRBackendRenderTarget((int)size.Width, (int)size.Height, 1,
                                                  imageInfo);
                    var surface = SKSurface.Create(GrContext, renderTarget,
                                                   GRSurfaceOrigin.TopLeft,
                                                   _surface.IsRgba ? SKColorType.Rgba8888 : SKColorType.Bgra8888, SKColorSpace.CreateSrgb());

                    if (surface == null)
                    {
                        throw new InvalidOperationException(
                                  "Surface can't be created with the provided render target");
                    }

                    success = true;

                    return(new VulkanGpuSession(GrContext, renderTarget, surface, session));
                }
            }
            finally
            {
                if (!success)
                {
                    session.Dispose();
                }
            }
        }