Skip to content

Commit

Permalink
[metal]: Use kCAGravityResize for smoother resizing
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Aug 12, 2024
1 parent 45059ac commit 37dba73
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions wgpu-hal/src/metal/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,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(
Expand Down Expand Up @@ -241,7 +241,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).
Expand Down

0 comments on commit 37dba73

Please sign in to comment.