VulkanSurfaceRenderingSession.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using Avalonia;
  3. using Ryujinx.Ava.Ui.Vulkan.Surfaces;
  4. using Silk.NET.Vulkan;
  5. namespace Ryujinx.Ava.Ui.Vulkan
  6. {
  7. internal class VulkanSurfaceRenderingSession : IDisposable
  8. {
  9. private readonly VulkanDevice _device;
  10. private readonly VulkanSurfaceRenderTarget _renderTarget;
  11. private VulkanCommandBufferPool.VulkanCommandBuffer _commandBuffer;
  12. public VulkanSurfaceRenderingSession(VulkanDisplay display, VulkanDevice device,
  13. VulkanSurfaceRenderTarget renderTarget, float scaling)
  14. {
  15. Display = display;
  16. _device = device;
  17. _renderTarget = renderTarget;
  18. Scaling = scaling;
  19. Begin();
  20. }
  21. public VulkanDisplay Display { get; }
  22. public PixelSize Size => _renderTarget.Size;
  23. public Vk Api => _device.Api;
  24. public float Scaling { get; }
  25. private void Begin()
  26. {
  27. if (!Display.EnsureSwapchainAvailable())
  28. {
  29. _renderTarget.Invalidate();
  30. }
  31. }
  32. public void Dispose()
  33. {
  34. _commandBuffer = Display.StartPresentation(_renderTarget);
  35. Display.BlitImageToCurrentImage(_renderTarget, _commandBuffer.InternalHandle);
  36. Display.EndPresentation(_commandBuffer);
  37. }
  38. }
  39. }