Fix android build

This commit is contained in:
Glenn Watson 2015-08-28 08:58:17 +10:00
parent 66317f5924
commit 7d43ca32bb
2 changed files with 112 additions and 98 deletions

View file

@ -257,7 +257,7 @@ impl HeadlessContext {
pub fn new(builder: BuilderAttribs) -> Result<HeadlessContext, CreationError> { pub fn new(builder: BuilderAttribs) -> Result<HeadlessContext, CreationError> {
let context = try!(EglContext::new(egl::ffi::egl::Egl, &builder, egl::NativeDisplay::Android)); let context = try!(EglContext::new(egl::ffi::egl::Egl, &builder, egl::NativeDisplay::Android));
let context = try!(context.finish_pbuffer()); let context = try!(context.finish_pbuffer());
Ok(context) Ok(HeadlessContext(context))
} }
} }

View file

@ -41,20 +41,15 @@ pub struct Context {
pixel_format: PixelFormat, pixel_format: PixelFormat,
} }
impl Context { #[cfg(target_os = "android")]
/// Start building an EGL context. fn get_native_display(egl: &ffi::egl::Egl,
/// native_display: NativeDisplay) -> *const libc::c_void {
/// This function initializes some things and chooses the pixel format. unsafe { egl.GetDisplay(ffi::egl::DEFAULT_DISPLAY as *mut _) }
/// }
/// To finish the process, you must call `.finish(window)` on the `ContextPrototype`.
pub fn new<'a>(egl: ffi::egl::Egl, builder: &'a BuilderAttribs<'a>,
native_display: NativeDisplay)
-> Result<ContextPrototype<'a>, CreationError>
{
if builder.sharing.is_some() {
unimplemented!()
}
#[cfg(not(target_os = "android"))]
fn get_native_display(egl: &ffi::egl::Egl,
native_display: NativeDisplay) -> *const libc::c_void {
// the first step is to query the list of extensions without any display, if supported // the first step is to query the list of extensions without any display, if supported
let dp_extensions = unsafe { let dp_extensions = unsafe {
let p = egl.QueryString(ffi::egl::NO_DISPLAY, ffi::egl::EXTENSIONS as i32); let p = egl.QueryString(ffi::egl::NO_DISPLAY, ffi::egl::EXTENSIONS as i32);
@ -72,8 +67,7 @@ impl Context {
let has_dp_extension = |e: &str| dp_extensions.iter().find(|s| s == &e).is_some(); let has_dp_extension = |e: &str| dp_extensions.iter().find(|s| s == &e).is_some();
// calling `eglGetDisplay` or equivalent match native_display {
let display = match native_display {
// Note: Some EGL implementations are missing the `eglGetPlatformDisplay(EXT)` symbol // Note: Some EGL implementations are missing the `eglGetPlatformDisplay(EXT)` symbol
// despite reporting `EGL_EXT_platform_base`. I'm pretty sure this is a bug. // despite reporting `EGL_EXT_platform_base`. I'm pretty sure this is a bug.
// Therefore we detect whether the symbol is loaded in addition to checking for // Therefore we detect whether the symbol is loaded in addition to checking for
@ -128,6 +122,8 @@ impl Context {
ptr::null()) } ptr::null()) }
}, },
// 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") && NativeDisplay::Android if has_dp_extension("EGL_KHR_platform_android") &&
egl.GetPlatformDisplay.is_loaded() => egl.GetPlatformDisplay.is_loaded() =>
{ {
@ -152,7 +148,25 @@ impl Context {
NativeDisplay::Android | NativeDisplay::Other(None) => { NativeDisplay::Android | NativeDisplay::Other(None) => {
unsafe { egl.GetDisplay(ffi::egl::DEFAULT_DISPLAY as *mut _) } unsafe { egl.GetDisplay(ffi::egl::DEFAULT_DISPLAY as *mut _) }
}, },
}; }
}
impl Context {
/// Start building an EGL context.
///
/// This function initializes some things and chooses the pixel format.
///
/// To finish the process, you must call `.finish(window)` on the `ContextPrototype`.
pub fn new<'a>(egl: ffi::egl::Egl, builder: &'a BuilderAttribs<'a>,
native_display: NativeDisplay)
-> Result<ContextPrototype<'a>, CreationError>
{
if builder.sharing.is_some() {
unimplemented!()
}
// calling `eglGetDisplay` or equivalent
let display = get_native_display(&egl, native_display);
if display.is_null() { if display.is_null() {
return Err(CreationError::OsError("Could not create EGL display object".to_string())); return Err(CreationError::OsError("Could not create EGL display object".to_string()));