From a52e2ee60ab8af69ccad5da7a5eb2b3aec56309e Mon Sep 17 00:00:00 2001 From: Jamie Nicol Date: Fri, 22 Apr 2022 10:15:25 +0100 Subject: [PATCH] Use StructGenerator on Android Rather than StaticStructGenerator. This avoids a compilation error due to calling SwapBuffersWithDamageKHR.is_loaded(), which isn't defined when using the static generator. --- glutin/Cargo.toml | 1 + glutin/src/api/dlloader.rs | 1 + glutin/src/api/egl/mod.rs | 30 ++---------------------------- glutin_egl_sys/build.rs | 2 +- 4 files changed, 5 insertions(+), 29 deletions(-) diff --git a/glutin/Cargo.toml b/glutin/Cargo.toml index ddd23eec905..5daaf418395 100644 --- a/glutin/Cargo.toml +++ b/glutin/Cargo.toml @@ -27,6 +27,7 @@ winit = { version = "0.26", default-features = false } [target.'cfg(target_os = "android")'.dependencies] android_glue = "0.2" glutin_egl_sys = { version = "0.1.5", path = "../glutin_egl_sys" } +libloading = "0.7" parking_lot = "0.11" [target.'cfg(target_os = "emscripten")'.dependencies] diff --git a/glutin/src/api/dlloader.rs b/glutin/src/api/dlloader.rs index 9cfba937d57..fa35b03412e 100644 --- a/glutin/src/api/dlloader.rs +++ b/glutin/src/api/dlloader.rs @@ -5,6 +5,7 @@ target_os = "freebsd", target_os = "netbsd", target_os = "openbsd", + target_os = "android", ))] use libloading::Library; diff --git a/glutin/src/api/egl/mod.rs b/glutin/src/api/egl/mod.rs index d567678e83b..709c31f2989 100644 --- a/glutin/src/api/egl/mod.rs +++ b/glutin/src/api/egl/mod.rs @@ -9,7 +9,6 @@ ))] #![allow(unused_variables)] -#[cfg(not(target_os = "android"))] mod egl { use super::ffi; use crate::api::dlloader::{SymTrait, SymWrapper}; @@ -90,20 +89,6 @@ mod egl { } } -#[cfg(target_os = "android")] -mod egl { - use super::ffi; - - #[derive(Clone)] - pub struct Egl(pub ffi::egl::Egl); - - impl Egl { - pub fn new() -> Result { - Ok(Egl(ffi::egl::Egl)) - } - } -} - mod make_current_guard; pub use self::egl::Egl; @@ -180,13 +165,6 @@ pub struct Context { config_id: ffi::egl::types::EGLConfig, } -#[cfg(target_os = "android")] -#[inline] -fn get_native_display(native_display: &NativeDisplay) -> *const raw::c_void { - let egl = EGL.as_ref().unwrap(); - unsafe { egl.GetDisplay(ffi::egl::DEFAULT_DISPLAY as *mut _) } -} - fn get_egl_version( display: ffi::egl::types::EGLDisplay, ) -> Result<(ffi::egl::types::EGLint, ffi::egl::types::EGLint), CreationError> { @@ -256,7 +234,6 @@ unsafe fn bind_and_get_api<'a>( } } -#[cfg(not(target_os = "android"))] fn get_native_display(native_display: &NativeDisplay) -> *const raw::c_void { let egl = EGL.as_ref().unwrap(); // the first step is to query the list of extensions without any display, if @@ -352,9 +329,6 @@ fn get_native_display(native_display: &NativeDisplay) -> *const raw::c_void { } } - // TODO: This will never be reached right now, as the android egl - // bindings use the static generator, so can't rely on - // GetPlatformDisplay(EXT). NativeDisplay::Android if has_dp_extension("EGL_KHR_platform_android") && egl.GetPlatformDisplay.is_loaded() => @@ -364,7 +338,7 @@ fn get_native_display(native_display: &NativeDisplay) -> *const raw::c_void { ffi::egl::DEFAULT_DISPLAY as *mut _, std::ptr::null(), ) - } + }, NativeDisplay::Device(display) if has_dp_extension("EGL_EXT_platform_device") @@ -375,7 +349,7 @@ fn get_native_display(native_display: &NativeDisplay) -> *const raw::c_void { display as *mut _, std::ptr::null(), ) - } + }, NativeDisplay::X11(Some(display)) | NativeDisplay::Gbm(Some(display)) diff --git a/glutin_egl_sys/build.rs b/glutin_egl_sys/build.rs index 2920f3b04fc..1b2cef3edb3 100644 --- a/glutin_egl_sys/build.rs +++ b/glutin_egl_sys/build.rs @@ -41,7 +41,7 @@ fn main() { ], ); - if target.contains("android") || target.contains("ios") { + if target.contains("ios") { reg.write_bindings(gl_generator::StaticStructGenerator, &mut file) } else { reg.write_bindings(gl_generator::StructGenerator, &mut file)