Skip to content
Permalink
Browse files

libsimpleservo: OpenGL support for Linux (glx)

  • Loading branch information...
paulrouget committed Feb 8, 2019
1 parent 71ba247 commit 38ed1fcf0f6a5f14b4a355606e7191d10151f815
Showing with 62 additions and 4 deletions.
  1. +1 −0 Cargo.lock
  2. +3 −0 ports/libsimpleservo/api/Cargo.toml
  3. +15 −3 ports/libsimpleservo/api/build.rs
  4. +43 −1 ports/libsimpleservo/api/src/gl_glue.rs

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -20,6 +20,9 @@ core-foundation = "0.6"
[target.'cfg(target_os = "windows")'.dependencies]
winapi = "0.3.2"

[target.'cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd"))'.dependencies]
libloading = "0.5"

[build-dependencies]
gl_generator = "0.10"

@@ -5,15 +5,16 @@
use gl_generator::{Api, Fallbacks, Profile, Registry};
use std::env;
use std::fs::File;
use std::path::Path;
use std::path::PathBuf;

fn main() {
let target = env::var("TARGET").unwrap();
let dest = PathBuf::from(&env::var("OUT_DIR").unwrap());

// Generate GL bindings
// For now, we only support EGL, and only on Windows and Android.
if target.contains("android") || target.contains("windows") {
let dest = env::var("OUT_DIR").unwrap();
let mut file = File::create(&Path::new(&dest).join("egl_bindings.rs")).unwrap();
let mut file = File::create(&dest.join("egl_bindings.rs")).unwrap();
if target.contains("android") {
Registry::new(Api::Egl, (1, 5), Profile::Core, Fallbacks::All, [])
.write_bindings(gl_generator::StaticStructGenerator, &mut file)
@@ -25,4 +26,15 @@ fn main() {
.unwrap();
};
}

if target.contains("linux") ||
target.contains("dragonfly") ||
target.contains("freebsd") ||
target.contains("openbsd")
{
let mut file = File::create(&dest.join("glx_bindings.rs")).unwrap();
Registry::new(Api::Glx, (1, 4), Profile::Core, Fallbacks::All, [])
.write_bindings(gl_generator::StructGenerator, &mut file)
.unwrap();
}
}
@@ -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)
}
}

0 comments on commit 38ed1fc

Please sign in to comment.
You can’t perform that action at this time.