From bd427b7cecc809ba801927c83fecb092872f326f Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Mon, 12 Aug 2024 16:31:55 +0200 Subject: [PATCH] [metal]: Use kCAGravityResize for smoother resizing --- wgpu-hal/src/metal/surface.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/wgpu-hal/src/metal/surface.rs b/wgpu-hal/src/metal/surface.rs index 74770d9e48..a717983c64 100644 --- a/wgpu-hal/src/metal/surface.rs +++ b/wgpu-hal/src/metal/surface.rs @@ -24,7 +24,7 @@ use parking_lot::{Mutex, RwLock}; #[link(name = "QuartzCore", kind = "framework")] extern "C" { #[allow(non_upper_case_globals)] - static kCAGravityTopLeft: *mut Object; + static kCAGravityResize: *mut Object; } extern "C" fn layer_should_inherit_contents_scale_from_window( @@ -239,7 +239,15 @@ impl super::Surface { let frame: CGRect = msg_send![root_layer, bounds]; let () = msg_send![new_layer, setFrame: frame]; - let _: () = msg_send![new_layer, setContentsGravity: unsafe { kCAGravityTopLeft }]; + // The desired content gravity is `kCAGravityResize`, because it + // masks / alleviates issues with resizing when + // `present_with_transaction` is disabled, and behaves better when + // moving the window between monitors. + // + // Unfortunately, it also makes it harder to see changes to + // `width` and `height` in `configure`. When debugging resize + // issues, swap this for `kCAGravityTopLeft` instead. + let _: () = msg_send![new_layer, setContentsGravity: unsafe { kCAGravityResize }]; // Set initial scale factor of the layer. This is kept in sync by // `configure` (on UIKit), and the delegate below (on AppKit).