Skip to content

Commit

Permalink
Use StructGenerator on Android (#1398)
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.

Co-authored-by: Marijn Suijten <marijns95@gmail.com>
  • Loading branch information
jamienicol and MarijnS95 authored May 26, 2022
1 parent 988b070 commit 1332f57
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 27 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- Fix crash when creating OpenGLES context without explicit version
- Add `buffer_age` method on `WindowedContext`
- On Android, switched from `StaticStructGenerator` to `StructGenerator`, fixing some compilation errors.

# Version 0.28.0 (2021-12-02)

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
26 changes: 0 additions & 26 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 Down
2 changes: 1 addition & 1 deletion glutin_egl_sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,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 1332f57

Please sign in to comment.