From 57981b533d9ce217345bfcee0c24d0619563e2bc Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Fri, 10 Jun 2022 11:37:06 +0200 Subject: [PATCH] On Android, use `HasRawWindowHandle` directly from the `ndk` crate (#2318) The `ndk` crate now implements [`HasRawWindowHandle` directly on `NativeWindow`], relieving the burden to reimplement it on `winit`. [`HasRawWindowHandle` directly on `NativeWindow`]: https://github.com/rust-windowing/android-ndk-rs/pull/274 --- Cargo.toml | 6 +++--- src/platform_impl/android/mod.rs | 8 +++----- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 764da52e..d98a6bc1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,9 +38,9 @@ image = { version = "0.24.0", default-features = false, features = ["png"] } simple_logger = "2.1.0" [target.'cfg(target_os = "android")'.dependencies] -ndk = "0.6" -ndk-sys = "0.3" -ndk-glue = "0.6" +# Coordinate the next winit release with android-ndk-rs: https://github.com/rust-windowing/winit/issues/1995 +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" } [target.'cfg(any(target_os = "ios", target_os = "macos"))'.dependencies] objc = "0.2.7" diff --git a/src/platform_impl/android/mod.rs b/src/platform_impl/android/mod.rs index b67f47eb..255f9211 100644 --- a/src/platform_impl/android/mod.rs +++ b/src/platform_impl/android/mod.rs @@ -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::{HasRawWindowHandle, RawWindowHandle}; use crate::{ dpi::{PhysicalPosition, PhysicalSize, Position, Size}, @@ -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 {