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 25, 2024
1 parent 1b153ae commit bd427b7
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 @@ -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(
Expand Down Expand Up @@ -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).
Expand Down

0 comments on commit bd427b7

Please sign in to comment.