Reimplement NativeDisplayMode on iOS for #1310 (#1330)

* Reimplement NativeDisplayMode on iOS for #1310

* Type annotations from code review.

Co-Authored-By: Aleksi Juvani <3168386+aleksijuvani@users.noreply.github.com>

Co-authored-by: Aleksi Juvani <3168386+aleksijuvani@users.noreply.github.com>
This commit is contained in:
simlay 2019-12-22 00:39:22 -08:00 committed by Freya Gentz
parent 82889e2367
commit c10c820311
2 changed files with 28 additions and 13 deletions

View file

@ -18,31 +18,44 @@ pub struct VideoMode {
pub(crate) size: (u32, u32), pub(crate) size: (u32, u32),
pub(crate) bit_depth: u16, pub(crate) bit_depth: u16,
pub(crate) refresh_rate: u16, pub(crate) refresh_rate: u16,
pub(crate) screen_mode: id, pub(crate) screen_mode: NativeDisplayMode,
pub(crate) monitor: MonitorHandle, pub(crate) monitor: MonitorHandle,
} }
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct NativeDisplayMode(pub id);
unsafe impl Send for NativeDisplayMode {}
impl Drop for NativeDisplayMode {
fn drop(&mut self) {
unsafe {
let () = msg_send![self.0, release];
}
}
}
impl Clone for NativeDisplayMode {
fn clone(&self) -> Self {
unsafe {
let _: id = msg_send![self.0, retain];
}
NativeDisplayMode(self.0)
}
}
impl Clone for VideoMode { impl Clone for VideoMode {
fn clone(&self) -> VideoMode { fn clone(&self) -> VideoMode {
VideoMode { VideoMode {
size: self.size, size: self.size,
bit_depth: self.bit_depth, bit_depth: self.bit_depth,
refresh_rate: self.refresh_rate, refresh_rate: self.refresh_rate,
screen_mode: unsafe { msg_send![self.screen_mode, retain] }, screen_mode: self.screen_mode.clone(),
monitor: self.monitor.clone(), monitor: self.monitor.clone(),
} }
} }
} }
impl Drop for VideoMode {
fn drop(&mut self) {
unsafe {
assert_main_thread!("`VideoMode` can only be dropped on the main thread on iOS");
let () = msg_send![self.screen_mode, release];
}
}
}
impl VideoMode { impl VideoMode {
unsafe fn retained_new(uiscreen: id, screen_mode: id) -> VideoMode { unsafe fn retained_new(uiscreen: id, screen_mode: id) -> VideoMode {
assert_main_thread!("`VideoMode` can only be created on the main thread on iOS"); assert_main_thread!("`VideoMode` can only be created on the main thread on iOS");
@ -64,11 +77,13 @@ impl VideoMode {
60 60
}; };
let size: CGSize = msg_send![screen_mode, size]; let size: CGSize = msg_send![screen_mode, size];
let screen_mode: id = msg_send![screen_mode, retain];
let screen_mode = NativeDisplayMode(screen_mode);
VideoMode { VideoMode {
size: (size.width as u32, size.height as u32), size: (size.width as u32, size.height as u32),
bit_depth: 32, bit_depth: 32,
refresh_rate: refresh_rate as u16, refresh_rate: refresh_rate as u16,
screen_mode: msg_send![screen_mode, retain], screen_mode,
monitor: MonitorHandle::retained_new(uiscreen), monitor: MonitorHandle::retained_new(uiscreen),
} }
} }

View file

@ -497,7 +497,7 @@ pub unsafe fn create_window(
match window_attributes.fullscreen { match window_attributes.fullscreen {
Some(Fullscreen::Exclusive(ref video_mode)) => { Some(Fullscreen::Exclusive(ref video_mode)) => {
let uiscreen = video_mode.monitor().ui_screen() as id; let uiscreen = video_mode.monitor().ui_screen() as id;
let () = msg_send![uiscreen, setCurrentMode: video_mode.video_mode.screen_mode]; let () = msg_send![uiscreen, setCurrentMode: video_mode.video_mode.screen_mode.0];
msg_send![window, setScreen:video_mode.monitor().ui_screen()] msg_send![window, setScreen:video_mode.monitor().ui_screen()]
} }
Some(Fullscreen::Borderless(ref monitor)) => { Some(Fullscreen::Borderless(ref monitor)) => {