mirror of
https://github.com/rust-mobile/android-activity.git
synced 2026-07-12 01:28:54 +00:00
Remove NativeWindowRef type
Since ndk 0.7 the `NativeWindow` type implements Clone and Drop which makes this wrapper type redundant now.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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<NativeWindowRef> {
|
||||
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<NativeWindow> {
|
||||
self.native_window.read().unwrap().clone()
|
||||
}
|
||||
|
||||
pub fn poll_events<F>(&self, timeout: Option<Duration>, mut callback: F)
|
||||
|
||||
@@ -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<NativeWindowRef> {
|
||||
pub fn native_window<'a>(&self) -> Option<NativeWindow> {
|
||||
self.inner.read().unwrap().native_window()
|
||||
}
|
||||
|
||||
|
||||
@@ -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<NativeWindowRef> {
|
||||
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<NativeWindow> {
|
||||
self.native_window.read().unwrap().clone()
|
||||
}
|
||||
|
||||
pub fn poll_events<F>(&self, timeout: Option<Duration>, mut callback: F)
|
||||
|
||||
Reference in New Issue
Block a user