示例#1
0
 public static PixelRect FromRectWithDpi(Rect rect, Vector dpi) => new PixelRect(
     PixelPoint.FromPointWithDpi(rect.Position, dpi),
     PixelSize.FromSizeWithDpi(rect.Size, dpi));
示例#2
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();
                }
            }
        }
示例#3
0
 public static PixelRect FromRect(Rect rect, Vector scale) => new PixelRect(
     PixelPoint.FromPoint(rect.Position, scale),
     PixelSize.FromSize(rect.Size, scale));