Skip to content

Commit

Permalink
Switch from ndk_glue to raw-window-handle
Browse files Browse the repository at this point in the history
  • Loading branch information
MarijnS95 committed May 29, 2022
1 parent 232c69e commit baaf31a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion glutin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
13 changes: 10 additions & 3 deletions glutin/src/api/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
Expand Down

0 comments on commit baaf31a

Please sign in to comment.