diff --git a/android-activity/CHANGELOG.md b/android-activity/CHANGELOG.md index aebf0b5..f26262b 100644 --- a/android-activity/CHANGELOG.md +++ b/android-activity/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - *Breaking*: updates to `ndk 0.7` and `ndk-sys 0.4` - *Breaking*: `AndroidApp::config()` now returns a clonable `ConfigurationRef` instead of a deep `Configuration` copy +### Removed +- The `NativeWindowRef` wrapper struct was removed since `NativeWindow` now implements `Clone` and `Drop` in `ndk 0.7` ## [0.1.1] - 2022-07-04 ### Changed diff --git a/android-activity/src/game_activity/mod.rs b/android-activity/src/game_activity/mod.rs index ce30444..de9440d 100644 --- a/android-activity/src/game_activity/mod.rs +++ b/android-activity/src/game_activity/mod.rs @@ -24,7 +24,7 @@ use ndk::configuration::Configuration; use ndk::looper::FdEvent; use ndk::native_window::NativeWindow; -use crate::{util, AndroidApp, ConfigurationRef, MainEvent, NativeWindowRef, PollEvent, Rect}; +use crate::{util, AndroidApp, ConfigurationRef, MainEvent, PollEvent, Rect}; mod ffi; @@ -154,13 +154,8 @@ pub struct AndroidAppInner { } impl AndroidAppInner { - pub fn native_window<'a>(&self) -> Option { - let guard = self.native_window.read().unwrap(); - if let Some(ref window) = *guard { - Some(NativeWindowRef::new(window)) - } else { - None - } + pub fn native_window<'a>(&self) -> Option { + self.native_window.read().unwrap().clone() } pub fn poll_events(&self, timeout: Option, mut callback: F) diff --git a/android-activity/src/lib.rs b/android-activity/src/lib.rs index 99ffdb5..b98e8f1 100644 --- a/android-activity/src/lib.rs +++ b/android-activity/src/lib.rs @@ -1,5 +1,4 @@ use std::hash::Hash; -use std::ops::Deref; use std::sync::RwLock; use std::time::Duration; use std::{os::unix::prelude::RawFd, sync::Arc}; @@ -55,39 +54,6 @@ pub struct Rect { pub bottom: i32, } -// XXX: NativeWindow is a ref-counted object but the NativeWindow rust API -// doesn't currently implement Clone() in terms of acquiring a reference -// and Drop() in terms of releasing a reference. NativeWindowRef lets -// us expose a pointer to a NativeWindow more safely by ensuring it won't -// become invalid, even it it gets 'terminated'. - -/// A reference to a `NativeWindow`, used for rendering -pub struct NativeWindowRef { - inner: NativeWindow, -} -impl NativeWindowRef { - pub fn new(native_window: &NativeWindow) -> Self { - unsafe { - ndk_sys::ANativeWindow_acquire(native_window.ptr().as_ptr()); - } - Self { - inner: native_window.clone(), - } - } -} -impl Drop for NativeWindowRef { - fn drop(&mut self) { - unsafe { ndk_sys::ANativeWindow_release(self.inner.ptr().as_ptr()) } - } -} -impl Deref for NativeWindowRef { - type Target = NativeWindow; - - fn deref(&self) -> &Self::Target { - &self.inner - } -} - pub type StateSaver<'a> = activity_impl::StateSaver<'a>; pub type StateLoader<'a> = activity_impl::StateLoader<'a>; @@ -240,7 +206,7 @@ impl AndroidApp { /// This will only return `Some(window)` between /// [`AndroidAppMainEvent::InitWindow`] and [`AndroidAppMainEvent::TerminateWindow`] /// events. - pub fn native_window<'a>(&self) -> Option { + pub fn native_window<'a>(&self) -> Option { self.inner.read().unwrap().native_window() } diff --git a/android-activity/src/native_activity/mod.rs b/android-activity/src/native_activity/mod.rs index 5faca83..e32845b 100644 --- a/android-activity/src/native_activity/mod.rs +++ b/android-activity/src/native_activity/mod.rs @@ -22,7 +22,7 @@ use ndk::input_queue::InputQueue; use ndk::looper::FdEvent; use ndk::native_window::NativeWindow; -use crate::{util, AndroidApp, ConfigurationRef, MainEvent, NativeWindowRef, PollEvent, Rect}; +use crate::{util, AndroidApp, ConfigurationRef, MainEvent, PollEvent, Rect}; mod ffi; @@ -163,13 +163,8 @@ impl AndroidAppInner { } } - pub fn native_window<'a>(&self) -> Option { - let guard = self.native_window.read().unwrap(); - if let Some(ref window) = *guard { - Some(NativeWindowRef::new(window)) - } else { - None - } + pub fn native_window<'a>(&self) -> Option { + self.native_window.read().unwrap().clone() } pub fn poll_events(&self, timeout: Option, mut callback: F)