Metal: opt-in long-edge drawable cap via SHARPEMU_METAL_CAP_DRAWABLE (#711)

Default presentation resolution is unchanged; set SHARPEMU_METAL_CAP_DRAWABLE=1 to cap the drawable long edge at 1920.
This commit is contained in:
kuba
2026-07-31 11:09:09 +02:00
committed by GitHub
parent 79aa764d03
commit b75e4e01a0
@@ -646,6 +646,30 @@ internal static partial class MetalVideoPresenter
var pixelSize = hostWindow.PixelSize;
var width = (double)pixelSize.Width;
var height = (double)pixelSize.Height;
// Retina hosts often present at 3840x2160 into a 1920x1080 window.
// Cap is opt-in: defaulting it on silently drops present resolution for
// every Metal title. SHARPEMU_METAL_CAP_DRAWABLE=1 enables the long-edge
// cap; SHARPEMU_METAL_FULL_DRAWABLE=1 remains a no-op when the cap is off.
if (string.Equals(
Environment.GetEnvironmentVariable("SHARPEMU_METAL_CAP_DRAWABLE"),
"1",
StringComparison.Ordinal) &&
!string.Equals(
Environment.GetEnvironmentVariable("SHARPEMU_METAL_FULL_DRAWABLE"),
"1",
StringComparison.Ordinal))
{
const double maxLongEdge = 1920.0;
var longEdge = Math.Max(width, height);
if (longEdge > maxLongEdge)
{
var scale = maxLongEdge / longEdge;
width = Math.Round(width * scale);
height = Math.Round(height * scale);
}
}
if (width == _drawableWidth && height == _drawableHeight)
{
return;