Window.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using Ryujinx.Graphics.GAL;
  2. using Ryujinx.Graphics.GAL.Texture;
  3. using Ryujinx.Graphics.Gpu.Image;
  4. using System;
  5. using System.Collections.Concurrent;
  6. namespace Ryujinx.Graphics.Gpu
  7. {
  8. public class Window
  9. {
  10. private GpuContext _context;
  11. private struct PresentationTexture
  12. {
  13. public TextureInfo Info { get; }
  14. public ImageCrop Crop { get; }
  15. public Action<object> Callback { get; }
  16. public object UserObj { get; }
  17. public PresentationTexture(
  18. TextureInfo info,
  19. ImageCrop crop,
  20. Action<object> callback,
  21. object userObj)
  22. {
  23. Info = info;
  24. Crop = crop;
  25. Callback = callback;
  26. UserObj = userObj;
  27. }
  28. }
  29. private ConcurrentQueue<PresentationTexture> _frameQueue;
  30. public Window(GpuContext context)
  31. {
  32. _context = context;
  33. _frameQueue = new ConcurrentQueue<PresentationTexture>();
  34. }
  35. public void EnqueueFrameThreadSafe(
  36. ulong address,
  37. int width,
  38. int height,
  39. int stride,
  40. bool isLinear,
  41. int gobBlocksInY,
  42. Format format,
  43. int bytesPerPixel,
  44. ImageCrop crop,
  45. Action<object> callback,
  46. object userObj)
  47. {
  48. FormatInfo formatInfo = new FormatInfo(format, 1, 1, bytesPerPixel);
  49. TextureInfo info = new TextureInfo(
  50. address,
  51. width,
  52. height,
  53. 1,
  54. 1,
  55. 1,
  56. 1,
  57. stride,
  58. isLinear,
  59. gobBlocksInY,
  60. 1,
  61. 1,
  62. Target.Texture2D,
  63. formatInfo);
  64. _frameQueue.Enqueue(new PresentationTexture(info, crop, callback, userObj));
  65. }
  66. public void Present(Action swapBuffersCallback)
  67. {
  68. _context.AdvanceSequence();
  69. if (_frameQueue.TryDequeue(out PresentationTexture pt))
  70. {
  71. Image.Texture texture = _context.Methods.TextureManager.FindOrCreateTexture(pt.Info);
  72. texture.SynchronizeMemory();
  73. _context.Renderer.Window.Present(texture.HostTexture, pt.Crop);
  74. swapBuffersCallback();
  75. pt.Callback(pt.UserObj);
  76. }
  77. }
  78. }
  79. }