Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/native/ios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,31 @@
draw_in_rect(this, s, o, nil);
}

// `MTKViewDelegate` requires this alongside `drawInMTKView:`;
// missing it crashes `_resizeDrawable` with
// `NSInvalidArgumentException`. Sync `native_display` here so
// the next frame's `setScissorRect` (and anything else reading
// `screen_size`) matches the new drawable — `draw_in_rect`'s
// `UIScreen.bounds` poll is the fallback but lags drawableSize
// during rotation animations.
extern "C" fn drawable_size_will_change(_: &Object, _: Sel, _: ObjcId, size: NSSize) {
let width = size.width as i32;
let height = size.height as i32;
let changed = {
let mut display = native_display().lock().unwrap();
let changed =
display.screen_width != width || display.screen_height != height;
if changed {
display.screen_width = width;
display.screen_height = height;
}
changed
};
if changed {
send_message(Message::Resize { width, height });
}
}

unsafe {
decl.add_method(
sel!(glkView: drawInRect:),
Expand All @@ -381,6 +406,11 @@
sel!(drawInMTKView:),
draw_in_rect2 as extern "C" fn(&Object, Sel, ObjcId),
);

decl.add_method(
sel!(mtkView: drawableSizeWillChange:),
drawable_size_will_change as extern "C" fn(&Object, Sel, ObjcId, NSSize),
);
}

decl.add_ivar::<*mut c_void>("display_ptr");
Expand Down Expand Up @@ -499,7 +529,7 @@
_: ObjcId,
) -> BOOL {
unsafe {
let (f, conf) = RUN_ARGS.take().unwrap();

Check warning on line 532 in src/native/ios.rs

View workflow job for this annotation

GitHub Actions / Build (macos-latest, x86_64-apple-ios)

creating a mutable reference to mutable static

Check warning on line 532 in src/native/ios.rs

View workflow job for this annotation

GitHub Actions / Build (macos-latest, aarch64-apple-ios)

creating a mutable reference to mutable static

let main_screen: ObjcId = msg_send![class!(UIScreen), mainScreen];
let screen_rect: NSRect = msg_send![main_screen, bounds];
Expand Down
Loading