From 73041bd7d498a21c06a51ab37302a0b84533cb64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benoi=CC=82t=20Rouleau?= Date: Mon, 5 Oct 2026 12:05:42 -0400 Subject: [PATCH] macos: honour Conf::high_dpi on the Metal path `create_metal_view` ignored `high_dpi`. `MTKView` sizes its drawable for the window's backing scale, and `update_dimensions` derived `dpi_scale` from that same scale, so `high_dpi: false` still rendered at 2x on a Retina display, with a `dpi_scale` of 2. Without high DPI, the view no longer resizes its drawable itself, and `update_dimensions` keeps `dpi_scale` at 1 and sizes the drawable in points, which the window scales up, as the OpenGL path does with `setWantsBestResolutionOpenGLSurface: NO`. It compares against the drawable's current size rather than relying on `dim_changed`, since the first call, right after the view joins the window, usually finds the size `Conf` asked for already recorded. Verified on a Retina display: a 300x200 window with `high_dpi: false` now reports a 300x200 screen at a `dpi_scale` of 1 instead of 600x400 at 2, and renders and reads back at that size. `high_dpi: true` is unchanged. Co-Authored-By: Claude Opus 5.5 Co-authored-by: multica-agent --- src/native/macos.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/native/macos.rs b/src/native/macos.rs index b8d01fdef..074354552 100644 --- a/src/native/macos.rs +++ b/src/native/macos.rs @@ -219,6 +219,8 @@ impl MacosDisplay { if dpi_scale > 0.0 { d.dpi_scale = dpi_scale as f32; } + } else if self.gfx_api == AppleGfxApi::Metal { + d.dpi_scale = 1.0; } else { let bounds: NSRect = msg_send![self.view, bounds]; let backing_size: NSSize = msg_send![self.view, convertSizeToBacking: NSSize {width: bounds.size.width, height: bounds.size.height}]; @@ -230,6 +232,20 @@ impl MacosDisplay { let screen_width = (bounds.size.width as f32 * d.dpi_scale) as i32; let screen_height = (bounds.size.height as f32 * d.dpi_scale) as i32; + if !d.high_dpi && self.gfx_api == AppleGfxApi::Metal { + // Without high DPI, the view leaves its drawable's size to us. + let drawable_size: CGSize = msg_send![self.view, drawableSize]; + if drawable_size.width != screen_width as f64 + || drawable_size.height != screen_height as f64 + { + let size = CGSize { + width: screen_width as f64, + height: screen_height as f64, + }; + msg_send_![self.view, setDrawableSize: size]; + } + } + let dim_changed = screen_width != d.screen_width || screen_height != d.screen_height; d.screen_width = screen_width; @@ -992,7 +1008,7 @@ fn get_window_payload(this: &Object) -> &mut MacosDisplay { } } -unsafe fn create_metal_view(_: &mut MacosDisplay, sample_count: i32, _: bool) -> ObjcId { +unsafe fn create_metal_view(_: &mut MacosDisplay, sample_count: i32, high_dpi: bool) -> ObjcId { let mtl_device_obj = MTLCreateSystemDefaultDevice(); let view_class = define_metal_view_class(); let view: ObjcId = msg_send![view_class, alloc]; @@ -1006,6 +1022,9 @@ unsafe fn create_metal_view(_: &mut MacosDisplay, sample_count: i32, _: bool) -> ]; let () = msg_send![view, setSampleCount: sample_count]; let () = msg_send![view, setPaused: true]; + // Without high DPI, `update_dimensions` sizes the drawable in points + // rather than for the screen's backing scale. + let () = msg_send![view, setAutoResizeDrawable: high_dpi]; view }