From baaf31aaa795a015710cbc3b9bcbe16d6053d743 Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Sun, 29 May 2022 22:40:50 +0200 Subject: [PATCH] Switch from ndk_glue to raw-window-handle --- glutin/Cargo.toml | 2 +- glutin/src/api/android/mod.rs | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/glutin/Cargo.toml b/glutin/Cargo.toml index f462fd3fad4..74d20950aa0 100644 --- a/glutin/Cargo.toml +++ b/glutin/Cargo.toml @@ -27,8 +27,8 @@ winit = { version = "0.26", default-features = false } [target.'cfg(target_os = "android")'.dependencies] glutin_egl_sys = { version = "0.1.5", path = "../glutin_egl_sys" } libloading = "0.7" -ndk-glue = "0.5" parking_lot = "0.11" +raw-window-handle = "0.4" [target.'cfg(target_os = "emscripten")'.dependencies] glutin_emscripten_sys = { version = "0.1.1", path = "../glutin_emscripten_sys" } diff --git a/glutin/src/api/android/mod.rs b/glutin/src/api/android/mod.rs index c3a2bef2991..9815410bad7 100644 --- a/glutin/src/api/android/mod.rs +++ b/glutin/src/api/android/mod.rs @@ -6,6 +6,7 @@ use crate::{Api, ContextError, GlAttributes, PixelFormat, PixelFormatRequirement use glutin_egl_sys as ffi; use parking_lot::Mutex; +use raw_window_handle::{AndroidNdkHandle, HasRawWindowHandle, RawWindowHandle}; use winit; use winit::dpi; use winit::event_loop::EventLoopWindowTarget; @@ -32,14 +33,20 @@ impl Context { ) -> Result<(winit::window::Window, Self), CreationError> { let win = wb.build(el)?; let gl_attr = gl_attr.clone().map_sharing(|c| &c.0.egl_context); - let nwin = ndk_glue::native_window(); - let nwin = nwin.as_ref().ok_or_else(|| OsError("Android's native window is null".to_string()))?; + let nwin = + if let RawWindowHandle::AndroidNdk(AndroidNdkHandle { a_native_window, .. }) = + win.raw_window_handle() + { + a_native_window + } else { + return Err(OsError("raw_window_handle() is not for Android".to_string())); + }; let native_display = NativeDisplay::Android; let egl_context = EglContext::new(pf_reqs, &gl_attr, native_display, EglSurfaceType::Window, |c, _| { Ok(c[0]) }) - .and_then(|p| p.finish(nwin.ptr().as_ptr() as *const _))?; + .and_then(|p| p.finish(nwin))?; let ctx = Arc::new(AndroidContext { egl_context, stopped: Some(Mutex::new(false)) }); let context = Context(ctx.clone());