Merge branch 'ava/retina-scaling' into 'master'

Avalonia: fix HiDPI/Retina scaling for embedded window on macOS.

See merge request [ryubing/ryujinx!210](https://git.ryujinx.app/ryubing/ryujinx/-/merge_requests/210)
This commit is contained in:
V380-Ori 2025-12-08 14:18:30 -06:00
commit 452ed9899a
2 changed files with 15 additions and 2 deletions

View file

@ -42,6 +42,9 @@ namespace Ryujinx.Common.Helper
[return: MarshalAs(UnmanagedType.Bool)]
private static partial bool bool_objc_msgSend(nint receiver, Selector selector, nint param);
[LibraryImport(ObjCRuntime, EntryPoint = "objc_msgSend")]
private static partial double double_objc_msgSend(nint receiver, Selector selector);
public readonly struct Object
{
public readonly nint ObjPtr;
@ -105,6 +108,11 @@ namespace Ryujinx.Common.Helper
{
return bool_objc_msgSend(ObjPtr, selector, obj.ObjPtr);
}
public double GetDoubleFromMessage(string selectorName)
{
return double_objc_msgSend(ObjPtr, selectorName);
}
}
public readonly struct Selector

View file

@ -186,12 +186,17 @@ namespace Ryujinx.Ava.UI.Renderer
// Make its renderer our metal layer.
child.SendMessage("setWantsLayer:", 1);
child.SendMessage("setLayer:", metalLayer);
metalLayer.SendMessage("setContentsScale:", Program.DesktopScaleFactor);
double initialScaleFactor = child.GetDoubleFromMessage("backingScaleFactor");
metalLayer.SendMessage("setContentsScale:", initialScaleFactor);
// Ensure the scale factor is up to date.
_updateBoundsCallback = rect =>
{
metalLayer.SendMessage("setContentsScale:", Program.DesktopScaleFactor);
double currentScaleFactor = child.GetDoubleFromMessage("backingScaleFactor");
metalLayer.SendMessage("setContentsScale:", currentScaleFactor);
};
nint nsView = child.ObjPtr;