Support building with 1.57.0 compiler

This is to support the same compiler versions as Winit
This commit is contained in:
Robert Bragg
2022-08-31 23:02:38 +01:00
parent d5ff06ffb2
commit 66e3293f4d
3 changed files with 28 additions and 20 deletions
+9 -6
View File
@@ -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,
@@ -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 { .. } => {
@@ -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);
}
}
}
+9 -7
View File
@@ -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 {},
@@ -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 {},
@@ -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()
@@ -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),
@@ -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()
}
+10 -7
View File
@@ -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");
@@ -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(
@@ -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!");
@@ -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);
}
}
}