Skip to content

Commit

Permalink
Support building with 1.57.0 compiler
Browse files Browse the repository at this point in the history
This is to support the same compiler versions as Winit
  • Loading branch information
rib committed Aug 31, 2022
1 parent d5ff06f commit 66e3293
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
15 changes: 9 additions & 6 deletions android-activity/src/game_activity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,10 @@ impl AndroidAppInner {
} else {
-1
};
trace!("Calling ALooper_pollAll, timeout = {timeout_milliseconds}");
trace!(
"Calling ALooper_pollAll, timeout = {}",
timeout_milliseconds
);
let id = ALooper_pollAll(
timeout_milliseconds,
&mut fd,
Expand Down Expand Up @@ -262,9 +265,9 @@ impl AndroidAppInner {
_ => unreachable!(),
};

trace!("Read ID_MAIN command {cmd_i} = {cmd:?}");
trace!("Read ID_MAIN command {} = {:?}", cmd_i, cmd);

trace!("Calling android_app_pre_exec_cmd({cmd_i})");
trace!("Calling android_app_pre_exec_cmd({})", cmd_i);
ffi::android_app_pre_exec_cmd(native_app.as_ptr(), cmd_i);
match cmd {
MainEvent::ConfigChanged { .. } => {
Expand All @@ -291,19 +294,19 @@ impl AndroidAppInner {
trace!("Invoking callback for ID_MAIN command = {:?}", cmd);
callback(PollEvent::Main(cmd));

trace!("Calling android_app_post_exec_cmd({cmd_i})");
trace!("Calling android_app_post_exec_cmd({})", cmd_i);
ffi::android_app_post_exec_cmd(native_app.as_ptr(), cmd_i);
} else {
panic!("ALooper_pollAll returned ID_MAIN event with NULL android_poll_source!");
}
}
_ => {
error!("Ignoring spurious ALooper event source: id = {id}, fd = {fd}, events = {events:?}, data = {source:?}");
error!("Ignoring spurious ALooper event source: id = {}, fd = {}, events = {:?}, data = {:?}", id, fd, events, source);
}
}
}
_ => {
error!("Spurious ALooper_pollAll return value {id} (ignored)");
error!("Spurious ALooper_pollAll return value {} (ignored)", id);
}
}
}
Expand Down
16 changes: 9 additions & 7 deletions android-activity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ pub enum MainEvent<'a> {
InputAvailable,

/// Command from main thread: a new [`NativeWindow`] is ready for use. Upon
/// receiving this command, [`native_window()`] will return the new window
/// receiving this command, [`AndroidApp::native_window()`] will return the new window
#[non_exhaustive]
InitWindow {},

/// Command from main thread: the existing [`NativeWindow`] needs to be
/// terminated. Upon receiving this command, [`native_window()`] still
/// terminated. Upon receiving this command, [`AndroidApp::native_window()`] still
/// returns the existing window; after returning from the [`AndroidApp::poll_events()`]
/// callback then [`native_window()`] will return `None`.
/// callback then [`AndroidApp::native_window()`] will return `None`.
#[non_exhaustive]
TerminateWindow {},

Expand Down Expand Up @@ -106,7 +106,7 @@ pub enum MainEvent<'a> {
LostFocus,

/// Command from main thread: the current device configuration has changed.
/// You can get a copy of the latest [Configuration] by calling
/// You can get a copy of the latest [`ndk::configuration::Configuration`] by calling
/// [`AndroidApp::config()`]
#[non_exhaustive]
ConfigChanged {},
Expand Down Expand Up @@ -185,7 +185,7 @@ impl AndroidApp {
/// Queries the current [`NativeWindow`] for the application.
///
/// This will only return `Some(window)` between
/// [`AndroidAppMainEvent::InitWindow`] and [`AndroidAppMainEvent::TerminateWindow`]
/// [`MainEvent::InitWindow`] and [`MainEvent::TerminateWindow`]
/// events.
pub fn native_window<'a>(&self) -> Option<NativeWindow> {
self.inner.read().unwrap().native_window()
Expand All @@ -202,6 +202,8 @@ impl AndroidApp {
/// set to `None` once the callback returns, and this is also synchronized with the Java
/// main thread. The [`MainEvent::SaveState`] event is also synchronized with the
/// Java main thread.
///
/// [`ALooper_pollAll`]: ndk::looper::ThreadLooper::poll_all
pub fn poll_events<F>(&self, timeout: Option<Duration>, callback: F)
where
F: FnMut(PollEvent),
Expand All @@ -210,12 +212,12 @@ impl AndroidApp {
}

/// Creates a means to wake up the main loop while it is blocked waiting for
/// events within [`poll_events()`].
/// events within [`AndroidApp::poll_events()`].
pub fn create_waker(&self) -> activity_impl::AndroidAppWaker {
self.inner.read().unwrap().create_waker()
}

/// Returns a (cheaply clonable) reference to this application's [`Configuration`]
/// Returns a (cheaply clonable) reference to this application's [`ndk::configuration::Configuration`]
pub fn config(&self) -> ConfigurationRef {
self.inner.read().unwrap().config()
}
Expand Down
17 changes: 10 additions & 7 deletions android-activity/src/native_activity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,17 @@ impl AndroidAppInner {
} else {
-1
};
info!("Calling ALooper_pollAll, timeout = {timeout_milliseconds}");
trace!(
"Calling ALooper_pollAll, timeout = {}",
timeout_milliseconds
);
let id = ALooper_pollAll(
timeout_milliseconds,
&mut fd,
&mut events,
&mut source as *mut *mut core::ffi::c_void,
);
info!("pollAll id = {id}");
trace!("pollAll id = {}", id);
match id {
ffi::ALOOPER_POLL_WAKE => {
trace!("ALooper_pollAll returned POLL_WAKE");
Expand Down Expand Up @@ -257,11 +260,11 @@ impl AndroidAppInner {
_ => unreachable!(),
};

trace!("Calling android_app_pre_exec_cmd({cmd_i})");
trace!("Calling android_app_pre_exec_cmd({})", cmd_i);
ffi::android_app_pre_exec_cmd(native_app.as_ptr(), cmd_i);

if let Some(cmd) = cmd {
trace!("Read ID_MAIN command {cmd_i} = {cmd:?}");
trace!("Read ID_MAIN command {} = {:?}", cmd_i, cmd);
match cmd {
MainEvent::ConfigChanged { .. } => {
self.config.replace(Configuration::clone_from_ptr(
Expand Down Expand Up @@ -290,7 +293,7 @@ impl AndroidAppInner {
callback(PollEvent::Main(cmd));
}

trace!("Calling android_app_post_exec_cmd({cmd_i})");
trace!("Calling android_app_post_exec_cmd({})", cmd_i);
ffi::android_app_post_exec_cmd(native_app.as_ptr(), cmd_i);
} else {
panic!("ALooper_pollAll returned ID_MAIN event with NULL android_poll_source!");
Expand All @@ -307,12 +310,12 @@ impl AndroidAppInner {
callback(PollEvent::Main(MainEvent::InputAvailable))
}
_ => {
error!("Ignoring spurious ALooper event source: id = {id}, fd = {fd}, events = {events:?}, data = {source:?}");
error!("Ignoring spurious ALooper event source: id = {}, fd = {}, events = {:?}, data = {:?}", id, fd, events, source);
}
}
}
_ => {
error!("Spurious ALooper_pollAll return value {id} (ignored)");
error!("Spurious ALooper_pollAll return value {} (ignored)", id);
}
}
}
Expand Down

0 comments on commit 66e3293

Please sign in to comment.