aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Ava/UI/Helpers
diff options
context:
space:
mode:
authorAc_K <Acoustik666@gmail.com>2023-01-16 01:14:01 +0100
committerGitHub <noreply@github.com>2023-01-16 01:14:01 +0100
commit784cf9d5947d60d146e518a7913220155362396b (patch)
treed03aa9efe879f48c64ee96a8d7432e3026c35819 /Ryujinx.Ava/UI/Helpers
parent64263c5218271f2e217aa593b4e47a59fe097835 (diff)
Ava UI: `Renderer` refactoring (#4297)
* Ava UI: `Renderer` refactoring * Fix Vulkan CreateSurface
Diffstat (limited to 'Ryujinx.Ava/UI/Helpers')
-rw-r--r--Ryujinx.Ava/UI/Helpers/AvaloniaGlxContext.cs16
-rw-r--r--Ryujinx.Ava/UI/Helpers/AvaloniaWglContext.cs16
-rw-r--r--Ryujinx.Ava/UI/Helpers/EmbeddedWindow.cs235
-rw-r--r--Ryujinx.Ava/UI/Helpers/IGlContextExtension.cs25
-rw-r--r--Ryujinx.Ava/UI/Helpers/OpenGLEmbeddedWindow.cs82
-rw-r--r--Ryujinx.Ava/UI/Helpers/OpenToolkitBindingsContext.cs20
-rw-r--r--Ryujinx.Ava/UI/Helpers/SPBOpenGLContext.cs47
-rw-r--r--Ryujinx.Ava/UI/Helpers/VulkanEmbeddedWindow.cs52
8 files changed, 0 insertions, 493 deletions
diff --git a/Ryujinx.Ava/UI/Helpers/AvaloniaGlxContext.cs b/Ryujinx.Ava/UI/Helpers/AvaloniaGlxContext.cs
deleted file mode 100644
index 6b696ba7..00000000
--- a/Ryujinx.Ava/UI/Helpers/AvaloniaGlxContext.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-using SPB.Graphics;
-using System;
-using System.Runtime.Versioning;
-
-namespace Ryujinx.Ava.UI.Helpers
-{
- [SupportedOSPlatform("linux")]
- internal class AvaloniaGlxContext : SPB.Platform.GLX.GLXOpenGLContext
- {
- public AvaloniaGlxContext(IntPtr handle)
- : base(FramebufferFormat.Default, 0, 0, 0, false, null)
- {
- ContextHandle = handle;
- }
- }
-}
diff --git a/Ryujinx.Ava/UI/Helpers/AvaloniaWglContext.cs b/Ryujinx.Ava/UI/Helpers/AvaloniaWglContext.cs
deleted file mode 100644
index b63a973a..00000000
--- a/Ryujinx.Ava/UI/Helpers/AvaloniaWglContext.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-using SPB.Graphics;
-using System;
-using System.Runtime.Versioning;
-
-namespace Ryujinx.Ava.UI.Helpers
-{
- [SupportedOSPlatform("windows")]
- internal class AvaloniaWglContext : SPB.Platform.WGL.WGLOpenGLContext
- {
- public AvaloniaWglContext(IntPtr handle)
- : base(FramebufferFormat.Default, 0, 0, 0, false, null)
- {
- ContextHandle = handle;
- }
- }
-}
diff --git a/Ryujinx.Ava/UI/Helpers/EmbeddedWindow.cs b/Ryujinx.Ava/UI/Helpers/EmbeddedWindow.cs
deleted file mode 100644
index 67ab80aa..00000000
--- a/Ryujinx.Ava/UI/Helpers/EmbeddedWindow.cs
+++ /dev/null
@@ -1,235 +0,0 @@
-using Avalonia;
-using Avalonia.Controls;
-using Avalonia.Input;
-using Avalonia.Platform;
-using SPB.Graphics;
-using SPB.Platform;
-using SPB.Platform.GLX;
-using System;
-using System.Runtime.InteropServices;
-using System.Runtime.Versioning;
-using System.Threading.Tasks;
-using static Ryujinx.Ava.UI.Helpers.Win32NativeInterop;
-
-namespace Ryujinx.Ava.UI.Helpers
-{
- public class EmbeddedWindow : NativeControlHost
- {
- private WindowProc _wndProcDelegate;
- private string _className;
-
- protected GLXWindow X11Window { get; set; }
- protected IntPtr WindowHandle { get; set; }
- protected IntPtr X11Display { get; set; }
- protected IntPtr NsView { get; set; }
- protected IntPtr MetalLayer { get; set; }
-
- private UpdateBoundsCallbackDelegate _updateBoundsCallback;
-
- public event EventHandler<IntPtr> WindowCreated;
- public event EventHandler<Size> SizeChanged;
-
- protected virtual void OnWindowDestroyed() { }
- protected virtual void OnWindowDestroying()
- {
- WindowHandle = IntPtr.Zero;
- X11Display = IntPtr.Zero;
- NsView = IntPtr.Zero;
- MetalLayer = IntPtr.Zero;
- }
-
- public EmbeddedWindow()
- {
- var stateObserverable = this.GetObservable(BoundsProperty);
-
- stateObserverable.Subscribe(StateChanged);
-
- Initialized += NativeEmbeddedWindow_Initialized;
- }
-
- public virtual void OnWindowCreated() { }
-
- private void NativeEmbeddedWindow_Initialized(object sender, EventArgs e)
- {
- OnWindowCreated();
-
- Task.Run(() =>
- {
- WindowCreated?.Invoke(this, WindowHandle);
- });
- }
-
- private void StateChanged(Rect rect)
- {
- SizeChanged?.Invoke(this, rect.Size);
- _updateBoundsCallback?.Invoke(rect);
- }
-
- protected override IPlatformHandle CreateNativeControlCore(IPlatformHandle parent)
- {
- if (OperatingSystem.IsLinux())
- {
- return CreateLinux(parent);
- }
- else if (OperatingSystem.IsWindows())
- {
- return CreateWin32(parent);
- }
- else if (OperatingSystem.IsMacOS())
- {
- return CreateMacOs(parent);
- }
-
- return base.CreateNativeControlCore(parent);
- }
-
- protected override void DestroyNativeControlCore(IPlatformHandle control)
- {
- OnWindowDestroying();
-
- if (OperatingSystem.IsLinux())
- {
- DestroyLinux();
- }
- else if (OperatingSystem.IsWindows())
- {
- DestroyWin32(control);
- }
- else if (OperatingSystem.IsMacOS())
- {
- DestroyMacOS();
- }
- else
- {
- base.DestroyNativeControlCore(control);
- }
-
- OnWindowDestroyed();
- }
-
- [SupportedOSPlatform("linux")]
- protected virtual IPlatformHandle CreateLinux(IPlatformHandle parent)
- {
- X11Window = PlatformHelper.CreateOpenGLWindow(FramebufferFormat.Default, 0, 0, 100, 100) as GLXWindow;
- WindowHandle = X11Window.WindowHandle.RawHandle;
- X11Display = X11Window.DisplayHandle.RawHandle;
-
- return new PlatformHandle(WindowHandle, "X11");
- }
-
- [SupportedOSPlatform("windows")]
- IPlatformHandle CreateWin32(IPlatformHandle parent)
- {
- _className = "NativeWindow-" + Guid.NewGuid();
- _wndProcDelegate = WndProc;
- var wndClassEx = new WNDCLASSEX
- {
- cbSize = Marshal.SizeOf<WNDCLASSEX>(),
- hInstance = GetModuleHandle(null),
- lpfnWndProc = Marshal.GetFunctionPointerForDelegate(_wndProcDelegate),
- style = ClassStyles.CS_OWNDC,
- lpszClassName = Marshal.StringToHGlobalUni(_className),
- hCursor = CreateArrowCursor()
- };
-
- var atom = RegisterClassEx(ref wndClassEx);
-
- var handle = CreateWindowEx(
- 0,
- _className,
- "NativeWindow",
- WindowStyles.WS_CHILD,
- 0,
- 0,
- 640,
- 480,
- parent.Handle,
- IntPtr.Zero,
- IntPtr.Zero,
- IntPtr.Zero);
-
- WindowHandle = handle;
-
- Marshal.FreeHGlobal(wndClassEx.lpszClassName);
-
- return new PlatformHandle(WindowHandle, "HWND");
- }
-
- [SupportedOSPlatform("windows")]
- IntPtr WndProc(IntPtr hWnd, WindowsMessages msg, IntPtr wParam, IntPtr lParam)
- {
- var point = new Point((long)lParam & 0xFFFF, ((long)lParam >> 16) & 0xFFFF);
- var root = VisualRoot as Window;
- bool isLeft = false;
- switch (msg)
- {
- case WindowsMessages.LBUTTONDOWN:
- case WindowsMessages.RBUTTONDOWN:
- isLeft = msg == WindowsMessages.LBUTTONDOWN;
- this.RaiseEvent(new PointerPressedEventArgs(
- this,
- new Pointer(0, PointerType.Mouse, true),
- root,
- this.TranslatePoint(point, root).Value,
- (ulong)Environment.TickCount64,
- new PointerPointProperties(isLeft ? RawInputModifiers.LeftMouseButton : RawInputModifiers.RightMouseButton, isLeft ? PointerUpdateKind.LeftButtonPressed : PointerUpdateKind.RightButtonPressed),
- KeyModifiers.None));
- break;
- case WindowsMessages.LBUTTONUP:
- case WindowsMessages.RBUTTONUP:
- isLeft = msg == WindowsMessages.LBUTTONUP;
- this.RaiseEvent(new PointerReleasedEventArgs(
- this,
- new Pointer(0, PointerType.Mouse, true),
- root,
- this.TranslatePoint(point, root).Value,
- (ulong)Environment.TickCount64,
- new PointerPointProperties(isLeft ? RawInputModifiers.LeftMouseButton : RawInputModifiers.RightMouseButton, isLeft ? PointerUpdateKind.LeftButtonReleased : PointerUpdateKind.RightButtonReleased),
- KeyModifiers.None,
- isLeft ? MouseButton.Left : MouseButton.Right));
- break;
- case WindowsMessages.MOUSEMOVE:
- this.RaiseEvent(new PointerEventArgs(
- PointerMovedEvent,
- this,
- new Pointer(0, PointerType.Mouse, true),
- root,
- this.TranslatePoint(point, root).Value,
- (ulong)Environment.TickCount64,
- new PointerPointProperties(RawInputModifiers.None, PointerUpdateKind.Other),
- KeyModifiers.None));
- break;
- }
-
- return DefWindowProc(hWnd, msg, wParam, lParam);
- }
-
- [SupportedOSPlatform("macos")]
- IPlatformHandle CreateMacOs(IPlatformHandle parent)
- {
- MetalLayer = MetalHelper.GetMetalLayer(out IntPtr nsView, out _updateBoundsCallback);
-
- NsView = nsView;
-
- return new PlatformHandle(nsView, "NSView");
- }
-
- void DestroyLinux()
- {
- X11Window?.Dispose();
- }
-
- [SupportedOSPlatform("windows")]
- void DestroyWin32(IPlatformHandle handle)
- {
- DestroyWindow(handle.Handle);
- UnregisterClass(_className, GetModuleHandle(null));
- }
-
- [SupportedOSPlatform("macos")]
- void DestroyMacOS()
- {
- MetalHelper.DestroyMetalLayer(NsView, MetalLayer);
- }
- }
-} \ No newline at end of file
diff --git a/Ryujinx.Ava/UI/Helpers/IGlContextExtension.cs b/Ryujinx.Ava/UI/Helpers/IGlContextExtension.cs
deleted file mode 100644
index e69774c3..00000000
--- a/Ryujinx.Ava/UI/Helpers/IGlContextExtension.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-using Avalonia.OpenGL;
-using SPB.Graphics.OpenGL;
-using System;
-
-namespace Ryujinx.Ava.UI.Helpers
-{
- internal static class IGlContextExtension
- {
- public static OpenGLContextBase AsOpenGLContextBase(this IGlContext context)
- {
- var handle = (IntPtr)context.GetType().GetProperty("Handle").GetValue(context);
-
- if (OperatingSystem.IsWindows())
- {
- return new AvaloniaWglContext(handle);
- }
- else if (OperatingSystem.IsLinux())
- {
- return new AvaloniaGlxContext(handle);
- }
-
- return null;
- }
- }
-} \ No newline at end of file
diff --git a/Ryujinx.Ava/UI/Helpers/OpenGLEmbeddedWindow.cs b/Ryujinx.Ava/UI/Helpers/OpenGLEmbeddedWindow.cs
deleted file mode 100644
index db77f66b..00000000
--- a/Ryujinx.Ava/UI/Helpers/OpenGLEmbeddedWindow.cs
+++ /dev/null
@@ -1,82 +0,0 @@
-using OpenTK.Graphics.OpenGL;
-using Ryujinx.Common.Configuration;
-using SPB.Graphics;
-using SPB.Graphics.OpenGL;
-using SPB.Platform;
-using SPB.Platform.WGL;
-using SPB.Windowing;
-using System;
-
-namespace Ryujinx.Ava.UI.Helpers
-{
- public class OpenGLEmbeddedWindow : EmbeddedWindow
- {
- private readonly int _major;
- private readonly int _minor;
- private readonly GraphicsDebugLevel _graphicsDebugLevel;
- private SwappableNativeWindowBase _window;
- public OpenGLContextBase Context { get; set; }
-
- public OpenGLEmbeddedWindow(int major, int minor, GraphicsDebugLevel graphicsDebugLevel)
- {
- _major = major;
- _minor = minor;
- _graphicsDebugLevel = graphicsDebugLevel;
- }
-
- protected override void OnWindowDestroying()
- {
- Context.Dispose();
- base.OnWindowDestroying();
- }
-
- public override void OnWindowCreated()
- {
- base.OnWindowCreated();
-
- if (OperatingSystem.IsWindows())
- {
- _window = new WGLWindow(new NativeHandle(WindowHandle));
- }
- else if (OperatingSystem.IsLinux())
- {
- _window = X11Window;
- }
- else
- {
- throw new PlatformNotSupportedException();
- }
-
- var flags = OpenGLContextFlags.Compat;
- if (_graphicsDebugLevel != GraphicsDebugLevel.None)
- {
- flags |= OpenGLContextFlags.Debug;
- }
-
- Context = PlatformHelper.CreateOpenGLContext(FramebufferFormat.Default, _major, _minor, flags);
-
- Context.Initialize(_window);
- Context.MakeCurrent(_window);
-
- var bindingsContext = new OpenToolkitBindingsContext(Context.GetProcAddress);
-
- GL.LoadBindings(bindingsContext);
- Context.MakeCurrent(null);
- }
-
- public void MakeCurrent()
- {
- Context?.MakeCurrent(_window);
- }
-
- public void MakeCurrent(NativeWindowBase window)
- {
- Context?.MakeCurrent(window);
- }
-
- public void SwapBuffers()
- {
- _window.SwapBuffers();
- }
- }
-} \ No newline at end of file
diff --git a/Ryujinx.Ava/UI/Helpers/OpenToolkitBindingsContext.cs b/Ryujinx.Ava/UI/Helpers/OpenToolkitBindingsContext.cs
deleted file mode 100644
index efb703ba..00000000
--- a/Ryujinx.Ava/UI/Helpers/OpenToolkitBindingsContext.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-using OpenTK;
-using System;
-
-namespace Ryujinx.Ava.UI.Helpers
-{
- internal class OpenToolkitBindingsContext : IBindingsContext
- {
- private readonly Func<string, IntPtr> _getProcAddress;
-
- public OpenToolkitBindingsContext(Func<string, IntPtr> getProcAddress)
- {
- _getProcAddress = getProcAddress;
- }
-
- public IntPtr GetProcAddress(string procName)
- {
- return _getProcAddress(procName);
- }
- }
-} \ No newline at end of file
diff --git a/Ryujinx.Ava/UI/Helpers/SPBOpenGLContext.cs b/Ryujinx.Ava/UI/Helpers/SPBOpenGLContext.cs
deleted file mode 100644
index 21f206c8..00000000
--- a/Ryujinx.Ava/UI/Helpers/SPBOpenGLContext.cs
+++ /dev/null
@@ -1,47 +0,0 @@
-using OpenTK.Graphics.OpenGL;
-using Ryujinx.Graphics.OpenGL;
-using SPB.Graphics;
-using SPB.Graphics.OpenGL;
-using SPB.Platform;
-using SPB.Windowing;
-
-namespace Ryujinx.Ava.UI.Helpers
-{
- class SPBOpenGLContext : IOpenGLContext
- {
- private OpenGLContextBase _context;
- private NativeWindowBase _window;
-
- private SPBOpenGLContext(OpenGLContextBase context, NativeWindowBase window)
- {
- _context = context;
- _window = window;
- }
-
- public void Dispose()
- {
- _context.Dispose();
- _window.Dispose();
- }
-
- public void MakeCurrent()
- {
- _context.MakeCurrent(_window);
- }
-
- public static SPBOpenGLContext CreateBackgroundContext(OpenGLContextBase sharedContext)
- {
- OpenGLContextBase context = PlatformHelper.CreateOpenGLContext(FramebufferFormat.Default, 3, 3, OpenGLContextFlags.Compat, true, sharedContext);
- NativeWindowBase window = PlatformHelper.CreateOpenGLWindow(FramebufferFormat.Default, 0, 0, 100, 100);
-
- context.Initialize(window);
- context.MakeCurrent(window);
-
- GL.LoadBindings(new OpenToolkitBindingsContext(context.GetProcAddress));
-
- context.MakeCurrent(null);
-
- return new SPBOpenGLContext(context, window);
- }
- }
-}
diff --git a/Ryujinx.Ava/UI/Helpers/VulkanEmbeddedWindow.cs b/Ryujinx.Ava/UI/Helpers/VulkanEmbeddedWindow.cs
deleted file mode 100644
index 6581610b..00000000
--- a/Ryujinx.Ava/UI/Helpers/VulkanEmbeddedWindow.cs
+++ /dev/null
@@ -1,52 +0,0 @@
-using Avalonia.Platform;
-using Silk.NET.Vulkan;
-using SPB.Graphics.Vulkan;
-using SPB.Platform.GLX;
-using SPB.Platform.Metal;
-using SPB.Platform.Win32;
-using SPB.Platform.X11;
-using SPB.Windowing;
-using System;
-using System.Runtime.Versioning;
-
-namespace Ryujinx.Ava.UI.Helpers
-{
- public class VulkanEmbeddedWindow : EmbeddedWindow
- {
- private NativeWindowBase _window;
-
- [SupportedOSPlatform("linux")]
- protected override IPlatformHandle CreateLinux(IPlatformHandle parent)
- {
- X11Window = new GLXWindow(new NativeHandle(X11.DefaultDisplay), new NativeHandle(parent.Handle));
- WindowHandle = X11Window.WindowHandle.RawHandle;
- X11Display = X11Window.DisplayHandle.RawHandle;
-
- X11Window.Hide();
-
- return new PlatformHandle(WindowHandle, "X11");
- }
-
- public SurfaceKHR CreateSurface(Instance instance)
- {
- if (OperatingSystem.IsWindows())
- {
- _window = new SimpleWin32Window(new NativeHandle(WindowHandle));
- }
- else if (OperatingSystem.IsLinux())
- {
- _window = new SimpleX11Window(new NativeHandle(X11Display), new NativeHandle(WindowHandle));
- }
- else if (OperatingSystem.IsMacOS())
- {
- _window = new SimpleMetalWindow(new NativeHandle(NsView), new NativeHandle(MetalLayer));
- }
- else
- {
- throw new PlatformNotSupportedException();
- }
-
- return new SurfaceKHR((ulong?)VulkanHelper.CreateWindowSurface(instance.Handle, _window));
- }
- }
-} \ No newline at end of file