aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Ava/Ui/Controls
diff options
context:
space:
mode:
authorriperiperi <rhy3756547@hotmail.com>2022-12-06 22:00:25 +0000
committerGitHub <noreply@github.com>2022-12-06 19:00:25 -0300
commite211c3f00a847f50b286349918e5c51967862e93 (patch)
tree5c703923741ee42362c86fef3981bdf745f881a4 /Ryujinx.Ava/Ui/Controls
parentd3709a753f88e6b02d6a1760835227a7fdcc5a19 (diff)
UI: Add Metal surface creation for MoltenVK (#3980)
* Initial implementation of metal surface across UIs * Fix SDL2 on windows * Update Ryujinx/Ryujinx.csproj Co-authored-by: Mary-nyan <thog@protonmail.com> * Address Feedback Co-authored-by: Mary-nyan <thog@protonmail.com>
Diffstat (limited to 'Ryujinx.Ava/Ui/Controls')
-rw-r--r--Ryujinx.Ava/Ui/Controls/EmbeddedWindow.cs33
-rw-r--r--Ryujinx.Ava/Ui/Controls/VulkanEmbeddedWindow.cs5
2 files changed, 36 insertions, 2 deletions
diff --git a/Ryujinx.Ava/Ui/Controls/EmbeddedWindow.cs b/Ryujinx.Ava/Ui/Controls/EmbeddedWindow.cs
index 7acbefca..6ef15982 100644
--- a/Ryujinx.Ava/Ui/Controls/EmbeddedWindow.cs
+++ b/Ryujinx.Ava/Ui/Controls/EmbeddedWindow.cs
@@ -2,11 +2,10 @@ using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Platform;
+using Ryujinx.Ava.Ui.Helper;
using SPB.Graphics;
using SPB.Platform;
using SPB.Platform.GLX;
-using SPB.Platform.X11;
-using SPB.Windowing;
using System;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
@@ -23,6 +22,10 @@ namespace Ryujinx.Ava.Ui.Controls
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;
@@ -58,6 +61,7 @@ namespace Ryujinx.Ava.Ui.Controls
private void StateChanged(Rect rect)
{
SizeChanged?.Invoke(this, rect.Size);
+ _updateBoundsCallback?.Invoke(rect);
}
protected override IPlatformHandle CreateNativeControlCore(IPlatformHandle parent)
@@ -70,6 +74,11 @@ namespace Ryujinx.Ava.Ui.Controls
{
return CreateWin32(parent);
}
+ else if (OperatingSystem.IsMacOS())
+ {
+ return CreateMacOs(parent);
+ }
+
return base.CreateNativeControlCore(parent);
}
@@ -85,6 +94,10 @@ namespace Ryujinx.Ava.Ui.Controls
{
DestroyWin32(control);
}
+ else if (OperatingSystem.IsMacOS())
+ {
+ DestroyMacOS();
+ }
else
{
base.DestroyNativeControlCore(control);
@@ -187,6 +200,16 @@ namespace Ryujinx.Ava.Ui.Controls
return DefWindowProc(hWnd, msg, (IntPtr)wParam, (IntPtr)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();
@@ -198,5 +221,11 @@ namespace Ryujinx.Ava.Ui.Controls
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/Controls/VulkanEmbeddedWindow.cs b/Ryujinx.Ava/Ui/Controls/VulkanEmbeddedWindow.cs
index 236a0a16..b9c5f75f 100644
--- a/Ryujinx.Ava/Ui/Controls/VulkanEmbeddedWindow.cs
+++ b/Ryujinx.Ava/Ui/Controls/VulkanEmbeddedWindow.cs
@@ -3,6 +3,7 @@ using Ryujinx.Ava.Ui.Controls;
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;
@@ -37,6 +38,10 @@ namespace Ryujinx.Ava.Ui
{
_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();