Skip to content

Commit

Permalink
Fix contentScaleFactor on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
jinleili committed Jul 13, 2024
1 parent d4607a9 commit 3d79d61
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app-surface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "app-surface"
authors = ["jinleili"]
description = "Integrate wgpu into your existing iOS and Android apps."
edition = "2021"
version = "0.4.2"
version = "0.4.4"
rust-version = "1.76"
repository = "https://github.com/jinleili/wgpu-in-app"
keywords = ["android", "SurfaceView", "ios", "macos", "wgpu"]
Expand Down
17 changes: 15 additions & 2 deletions app-surface/src/ios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,19 @@ impl AppSurface {
}

fn get_scale_factor(obj: *mut Object) -> f32 {
let s: CGFloat = unsafe { msg_send![obj, contentScaleFactor] };
s as f32
let mut scale_factor: CGFloat = 1.0;
#[cfg(target_os = "macos")]
unsafe {
let window: *mut Object = msg_send![obj, window];
if !window.is_null() {
scale_factor = msg_send![window, backingScaleFactor];
}
};

#[cfg(target_os = "ios")]
{
scale_factor = unsafe { msg_send![obj, contentScaleFactor] };
}

scale_factor as f32
}

0 comments on commit 3d79d61

Please sign in to comment.