Skip to content

Commit

Permalink
On Android, Use HasRawWindowHandle directly from the ndk crate
Browse files Browse the repository at this point in the history
The `ndk` crate now implements [`HasRawWindowHandle` directly on
`NativeWindow`], relieving the burden to reimplement it on `winit`.

[`HasRawWindowHandle` directly on `NativeWindow`]: rust-mobile/ndk#274
  • Loading branch information
MarijnS95 committed Jun 9, 2022
1 parent 2c01e9e commit 77cd6fd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,7 @@ console_log = "0.2"
members = [
"run-wasm",
]

[patch.crates-io]
ndk = { git = "https://github.com/rust-windowing/android-ndk-rs", rev = "7e33384" }
ndk-glue = { git = "https://github.com/rust-windowing/android-ndk-rs", rev = "7e33384" }
8 changes: 3 additions & 5 deletions src/platform_impl/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use ndk::{
};
use ndk_glue::{Event, Rect};
use once_cell::sync::Lazy;
use raw_window_handle::{AndroidNdkHandle, RawWindowHandle};
use raw_window_handle::RawWindowHandle;

use crate::{
dpi::{PhysicalPosition, PhysicalSize, Position, Size},
Expand Down Expand Up @@ -786,13 +786,11 @@ impl Window {
}

pub fn raw_window_handle(&self) -> RawWindowHandle {
let mut handle = AndroidNdkHandle::empty();
if let Some(native_window) = ndk_glue::native_window().as_ref() {
handle.a_native_window = unsafe { native_window.ptr().as_mut() as *mut _ as *mut _ }
native_window.raw_window_handle()
} else {
panic!("Cannot get the native window, it's null and will always be null before Event::Resumed and after Event::Suspended. Make sure you only call this function between those events.");
};
RawWindowHandle::AndroidNdk(handle)
}
}

pub fn config(&self) -> Configuration {
Expand Down

0 comments on commit 77cd6fd

Please sign in to comment.