Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions ndk-glue/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Unreleased

- Document when to lock and unlock the window/input queue when certain events are received.

# 0.4.0 (2021-08-02)

- Looper is now created before returning from `ANativeActivity_onCreate`, solving
Expand Down
14 changes: 12 additions & 2 deletions ndk-glue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,16 @@ pub enum Event {
WindowCreated,
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add some docs about acquiring and holding the lock here too? And on InputQueueCreated?

WindowResized,
WindowRedrawNeeded,
/// If the window is in use by ie. a graphics API, make sure the lock from
/// [`native_window()`] is held on to until after freeing those resources.
///
/// After receiving this [`Event`] `ndk_glue` will block until that read-lock
/// is released before returning to Android and allowing it to free up the window.
WindowDestroyed,
InputQueueCreated,
/// After receiving this [`Event`] `ndk_glue` will block until the read-lock from
/// [`input_queue()`] is released before returning to Android and allowing it to
/// free up the input queue.
InputQueueDestroyed,
ContentRectChanged,
}
Expand Down Expand Up @@ -281,10 +289,12 @@ unsafe extern "C" fn on_window_redraw_needed(

unsafe extern "C" fn on_window_destroyed(
activity: *mut ANativeActivity,
_window: *mut ANativeWindow,
window: *mut ANativeWindow,
) {
wake(activity, Event::WindowDestroyed);
*NATIVE_WINDOW.write().unwrap() = None;
let mut native_window_guard = NATIVE_WINDOW.write().unwrap();
assert_eq!(native_window_guard.as_ref().unwrap().ptr().as_ptr(), window);
*native_window_guard = None;
}

unsafe extern "C" fn on_input_queue_created(
Expand Down