Auto merge of #22852 - paulrouget:opengl, r=Manishearth

libsimpleservo: OpenGL support for Linux (glx)

Tested with Xorg + nouveau driver.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/22852)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2019-02-18 05:04:08 -05:00 committed by GitHub
commit 884aac7233
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 62 additions and 4 deletions

View file

@ -75,7 +75,7 @@ pub mod egl {
}
}
#[cfg(any(target_os = "windows", target_os = "linux"))]
#[cfg(target_os = "windows")]
pub mod gl {
pub fn init() -> Result<crate::gl_glue::ServoGl, &'static str> {
unimplemented!();
@ -110,3 +110,45 @@ pub mod gl {
Ok(gl)
}
}
#[cfg(any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "openbsd"
))]
pub mod gl {
use libloading::{Library, Symbol};
use servo::gl::GlFns;
use std::ffi::CString;
use std::os::raw::c_void;
pub fn init() -> Result<crate::gl_glue::ServoGl, &'static str> {
info!("Loading OpenGL");
pub mod glx {
include!(concat!(env!("OUT_DIR"), "/glx_bindings.rs"));
}
let lib = match Library::new("libGL.so.1").or_else(|_| Library::new("libGL.so")) {
Ok(lib) => lib,
Err(_) => return Err("Can't find libGL.so, OpenGL isn't configured/installed"),
};
let glx = glx::Glx::load_with(|sym| unsafe {
let symbol: Symbol<*const c_void> = lib.get(sym.as_bytes()).unwrap();
*symbol.into_raw()
});
let gl = unsafe {
GlFns::load_with(|addr| {
let addr = CString::new(addr.as_bytes()).unwrap();
glx.GetProcAddress(addr.as_ptr() as *const _) as *const _
})
};
info!("OpenGL is loaded");
Ok(gl)
}
}