android: Hold NativeWindow lock until after notifying the user with Event::Suspended (#2307)
This applies https://github.com/rust-windowing/android-ndk-rs/issues/117 on the `winit` side: Android destroys its window/surface as soon as the user returns from [`onNativeWindowDestroyed`], and we "fixed" this on the `ndk-glue` side by sending the `WindowDestroyed` event before locking the window and removing it: this lock has to wait for any user of `ndk-glue` - ie. `winit` - to give up its readlock on the window, which is what we utilize here to give users of `winit` "time" to destroy any resource created on top of a `RawWindowHandle`. since we can't pass the user a `RawWindowHandle` through the `HasRawWindowHandle` trait we have to document this case explicitly and keep the lock alive on the `winit` side instead. [`onNativeWindowDestroyed`]: https://developer.android.com/ndk/reference/struct/a-native-activity-callbacks#onnativewindowdestroyed
This commit is contained in:
parent
50dd7881b1
commit
472d7b9376
4 changed files with 53 additions and 20 deletions
|
|
@ -1039,8 +1039,17 @@ unsafe impl raw_window_handle::HasRawWindowHandle for Window {
|
|||
///
|
||||
/// ## Platform-specific
|
||||
///
|
||||
/// - **Android:** Only available after receiving the Resumed event and before Suspended. *If you*
|
||||
/// *try to get the handle outside of that period, this function will panic*!
|
||||
/// ### Android
|
||||
///
|
||||
/// Only available after receiving [`Event::Resumed`] and before [`Event::Suspended`]. *If you
|
||||
/// try to get the handle outside of that period, this function will panic*!
|
||||
///
|
||||
/// Make sure to release or destroy any resources created from this `RawWindowHandle` (ie. Vulkan
|
||||
/// or OpenGL surfaces) before returning from [`Event::Suspended`], at which point Android will
|
||||
/// release the underlying window/surface: any subsequent interaction is undefined behavior.
|
||||
///
|
||||
/// [`Event::Resumed`]: crate::event::Event::Resumed
|
||||
/// [`Event::Suspended`]: crate::event::Event::Suspended
|
||||
fn raw_window_handle(&self) -> raw_window_handle::RawWindowHandle {
|
||||
self.window.raw_window_handle()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue