Skip to content

Commit

Permalink
Use StructGenerator on Android
Browse files Browse the repository at this point in the history
Rather than StaticStructGenerator. This avoids a compilation error due
to calling SwapBuffersWithDamageKHR.is_loaded(), which isn't defined
when using the static generator.
  • Loading branch information
jamienicol committed Apr 29, 2022
1 parent d5c1724 commit 9952703
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 29 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Unreleased

- On Android, switched from StaticStructGenerator to StructGenerator, fixing some compilation errors.

# Version 0.28.0 (2021-12-02)

- On Windows, fixed a panic for headless contexts because of active drag-and-drop (OleInitialize failed! Result was: `RPC_E_CHANGED_MODE`)
Expand Down
1 change: 1 addition & 0 deletions glutin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions glutin/src/api/dlloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd",
target_os = "android",
))]

use libloading::Library;
Expand Down
30 changes: 2 additions & 28 deletions glutin/src/api/egl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
))]
#![allow(unused_variables)]

#[cfg(not(target_os = "android"))]
mod egl {
use super::ffi;
use crate::api::dlloader::{SymTrait, SymWrapper};
Expand Down Expand Up @@ -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<Self, ()> {
Ok(Egl(ffi::egl::Egl))
}
}
}

mod make_current_guard;

pub use self::egl::Egl;
Expand Down Expand Up @@ -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> {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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() =>
Expand All @@ -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")
Expand All @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion glutin_egl_sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 9952703

Please sign in to comment.