Window.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using Ryujinx.Graphics.GAL;
  2. using Ryujinx.Graphics.Gpu.Image;
  3. using System;
  4. using System.Collections.Concurrent;
  5. namespace Ryujinx.Graphics.Gpu
  6. {
  7. using Texture = Image.Texture;
  8. public class Window
  9. {
  10. private readonly 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 readonly 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. 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. }