From 664c63c6a8bf682f42f045f75536c30b250a72af Mon Sep 17 00:00:00 2001 From: Evan Husted Date: Fri, 27 Dec 2024 20:47:02 -0600 Subject: [PATCH] metal: Bump SharpMetal to preview 21 --- Directory.Packages.props | 2 +- .../CAMetalLayerExtensions.cs | 18 ++++-------- .../NSHelper.cs | 28 +++++++++++++++++++ ...Graphics.Metal.SharpMetalExtensions.csproj | 1 + src/Ryujinx.Graphics.Metal/Window.cs | 8 +++--- 5 files changed, 39 insertions(+), 18 deletions(-) create mode 100644 src/Ryujinx.Graphics.Metal.SharpMetalExtensions/NSHelper.cs diff --git a/Directory.Packages.props b/Directory.Packages.props index 07fc8cc28..59abe363c 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -44,7 +44,7 @@ - + diff --git a/src/Ryujinx.Graphics.Metal.SharpMetalExtensions/CAMetalLayerExtensions.cs b/src/Ryujinx.Graphics.Metal.SharpMetalExtensions/CAMetalLayerExtensions.cs index 0d29a502b..f8fe7d2e7 100644 --- a/src/Ryujinx.Graphics.Metal.SharpMetalExtensions/CAMetalLayerExtensions.cs +++ b/src/Ryujinx.Graphics.Metal.SharpMetalExtensions/CAMetalLayerExtensions.cs @@ -1,4 +1,5 @@ using SharpMetal; +using SharpMetal.Foundation; using SharpMetal.ObjectiveCCore; using SharpMetal.QuartzCore; using System.Runtime.Versioning; @@ -9,22 +10,13 @@ namespace Ryujinx.Graphics.Metal.SharpMetalExtensions [SupportedOSPlatform("macOS")] public static class CAMetalLayerExtensions { - private static readonly Selector sel_displaySyncEnabled = "displaySyncEnabled"; - private static readonly Selector sel_setDisplaySyncEnabled = "setDisplaySyncEnabled:"; - private static readonly Selector sel_developerHUDProperties = "developerHUDProperties"; private static readonly Selector sel_setDeveloperHUDProperties = "setDeveloperHUDProperties:"; - - public static bool IsDisplaySyncEnabled(this CAMetalLayer metalLayer) - => ObjectiveCRuntime.bool_objc_msgSend(metalLayer.NativePtr, sel_displaySyncEnabled); - public static void SetDisplaySyncEnabled(this CAMetalLayer metalLayer, bool enabled) - => ObjectiveCRuntime.objc_msgSend(metalLayer.NativePtr, sel_setDisplaySyncEnabled, enabled); + public static NSDictionary GetDeveloperHudProperties(this CAMetalLayer metalLayer) + => new(ObjectiveCRuntime.IntPtr_objc_msgSend(metalLayer.NativePtr, sel_developerHUDProperties)); - public static nint GetDeveloperHudProperties(this CAMetalLayer metalLayer) - => ObjectiveCRuntime.IntPtr_objc_msgSend(metalLayer.NativePtr, sel_developerHUDProperties); - - public static void SetDeveloperHudProperties(this CAMetalLayer metalLayer, nint dictionaryPointer) - => ObjectiveCRuntime.objc_msgSend(metalLayer.NativePtr, sel_setDeveloperHUDProperties, dictionaryPointer); + public static void SetDeveloperHudProperties(this CAMetalLayer metalLayer, NSDictionary dictionary) + => ObjectiveCRuntime.objc_msgSend(metalLayer.NativePtr, sel_setDeveloperHUDProperties, dictionary); } } diff --git a/src/Ryujinx.Graphics.Metal.SharpMetalExtensions/NSHelper.cs b/src/Ryujinx.Graphics.Metal.SharpMetalExtensions/NSHelper.cs new file mode 100644 index 000000000..52c192a90 --- /dev/null +++ b/src/Ryujinx.Graphics.Metal.SharpMetalExtensions/NSHelper.cs @@ -0,0 +1,28 @@ +using SharpMetal.Foundation; +using SharpMetal.ObjectiveCCore; +using System.Runtime.Versioning; + +namespace Ryujinx.Graphics.Metal.SharpMetalExtensions +{ + [SupportedOSPlatform("macOS")] + public static class NSHelper + { + public static unsafe string ToDotNetString(this NSString source) + { + char[] sourceBuffer = new char[source.Length]; + fixed (char* pSourceBuffer = sourceBuffer) + { + ObjectiveC.bool_objc_msgSend(source, + "getCString:maxLength:encoding:", + pSourceBuffer, + source.MaximumLengthOfBytes(NSStringEncoding.UTF16) + 1, + (ulong)NSStringEncoding.UTF16); + } + + return new string(sourceBuffer); + } + + public static NSString ToNSString(this string source) + => new(ObjectiveC.IntPtr_objc_msgSend(new ObjectiveCClass("NSString"), "stringWithUTF8String:", source)); + } +} diff --git a/src/Ryujinx.Graphics.Metal.SharpMetalExtensions/Ryujinx.Graphics.Metal.SharpMetalExtensions.csproj b/src/Ryujinx.Graphics.Metal.SharpMetalExtensions/Ryujinx.Graphics.Metal.SharpMetalExtensions.csproj index 9836063a3..1e75b4d26 100644 --- a/src/Ryujinx.Graphics.Metal.SharpMetalExtensions/Ryujinx.Graphics.Metal.SharpMetalExtensions.csproj +++ b/src/Ryujinx.Graphics.Metal.SharpMetalExtensions/Ryujinx.Graphics.Metal.SharpMetalExtensions.csproj @@ -2,6 +2,7 @@ enable enable + true diff --git a/src/Ryujinx.Graphics.Metal/Window.cs b/src/Ryujinx.Graphics.Metal/Window.cs index 203a29ebc..61137f97d 100644 --- a/src/Ryujinx.Graphics.Metal/Window.cs +++ b/src/Ryujinx.Graphics.Metal/Window.cs @@ -18,7 +18,7 @@ class Window : IWindow, IDisposable public bool ScreenCaptureRequested { get; set; } private readonly MetalRenderer _renderer; - private readonly CAMetalLayer _metalLayer; + private CAMetalLayer _metalLayer; private int _width; private int _height; @@ -146,11 +146,11 @@ public void ChangeVSyncMode(VSyncMode vSyncMode) { switch (vSyncMode) { - case VSyncMode.Unbounded: - _metalLayer.SetDisplaySyncEnabled(false); + case VSyncMode.Unbounded: + _metalLayer.DisplaySyncEnabled = false; break; case VSyncMode.Switch: - _metalLayer.SetDisplaySyncEnabled(true); + _metalLayer.DisplaySyncEnabled = true; break; } }