diff options
| author | gdk <gab.dark.100@gmail.com> | 2019-11-23 23:24:03 -0300 |
|---|---|---|
| committer | Thog <thog@protonmail.com> | 2020-01-09 02:13:00 +0100 |
| commit | 16d88c21fc98cd7302811e142a39d590370e182e (patch) | |
| tree | e2c1a457666a11427ca3a26d701720bfe508e0e3 /Ryujinx.Graphics.Gpu/Window.cs | |
| parent | b2b2e046696e9c187cd9d7d4e3e92dc521082fe5 (diff) | |
Improved and simplified window texture presentation
Diffstat (limited to 'Ryujinx.Graphics.Gpu/Window.cs')
| -rw-r--r-- | Ryujinx.Graphics.Gpu/Window.cs | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/Ryujinx.Graphics.Gpu/Window.cs b/Ryujinx.Graphics.Gpu/Window.cs new file mode 100644 index 00000000..a3dc3b26 --- /dev/null +++ b/Ryujinx.Graphics.Gpu/Window.cs @@ -0,0 +1,94 @@ +using Ryujinx.Graphics.GAL; +using Ryujinx.Graphics.GAL.Texture; +using Ryujinx.Graphics.Gpu.Image; +using System; +using System.Collections.Concurrent; + +namespace Ryujinx.Graphics.Gpu +{ + public class Window + { + private GpuContext _context; + + private struct PresentationTexture + { + public TextureInfo Info { get; } + public ImageCrop Crop { get; } + public Action<object> Callback { get; } + public object UserObj { get; } + + public PresentationTexture( + TextureInfo info, + ImageCrop crop, + Action<object> callback, + object userObj) + { + Info = info; + Crop = crop; + Callback = callback; + UserObj = userObj; + } + } + + private ConcurrentQueue<PresentationTexture> _frameQueue; + + public Window(GpuContext context) + { + _context = context; + + _frameQueue = new ConcurrentQueue<PresentationTexture>(); + } + + public void EnqueueFrameThreadSafe( + ulong address, + int width, + int height, + int stride, + bool isLinear, + int gobBlocksInY, + Format format, + int bytesPerPixel, + ImageCrop crop, + Action<object> callback, + object userObj) + { + FormatInfo formatInfo = new FormatInfo(format, 1, 1, bytesPerPixel); + + TextureInfo info = new TextureInfo( + address, + width, + height, + 1, + 1, + 1, + 1, + stride, + isLinear, + gobBlocksInY, + 1, + 1, + Target.Texture2D, + formatInfo); + + _frameQueue.Enqueue(new PresentationTexture(info, crop, callback, userObj)); + } + + public void Present(Action swapBuffersCallback) + { + _context.AdvanceSequence(); + + if (_frameQueue.TryDequeue(out PresentationTexture pt)) + { + Image.Texture texture = _context.Methods.TextureManager.FindOrCreateTexture(pt.Info); + + texture.SynchronizeMemory(); + + _context.Renderer.Window.Present(texture.HostTexture, pt.Crop); + + swapBuffersCallback(); + + pt.Callback(pt.UserObj); + } + } + } +}
\ No newline at end of file |
