mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
libsimpleservo: OpenGL support for Linux (glx)
This commit is contained in:
parent
71ba247942
commit
38ed1fcf0f
4 changed files with 62 additions and 4 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue