From e211c3f00a847f50b286349918e5c51967862e93 Mon Sep 17 00:00:00 2001 From: riperiperi Date: Tue, 6 Dec 2022 22:00:25 +0000 Subject: 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 * Address Feedback Co-authored-by: Mary-nyan --- Ryujinx.Ava/Ui/Controls/EmbeddedWindow.cs | 33 +++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'Ryujinx.Ava/Ui/Controls/EmbeddedWindow.cs') 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 WindowCreated; public event EventHandler 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 -- cgit v1.2.3