diff --git a/Cargo.lock b/Cargo.lock index ce67b74..b28ce0b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,9 +8,9 @@ dependencies = [ "gleam 0.0.1 (git+https://github.com/servo/gleam)", "glx 0.0.1 (git+https://github.com/servo/rust-glx)", "layers 0.1.0 (git+https://github.com/servo/rust-layers)", - "libc 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "xlib 0.1.0 (git+https://github.com/servo/rust-xlib)", + "x11 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -24,7 +24,7 @@ dependencies = [ "egl 0.1.0 (git+https://github.com/servo/rust-egl)", "freetype 0.1.0 (git+https://github.com/servo/rust-freetype)", "geom 0.1.0 (git+https://github.com/servo/rust-geom)", - "libc 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "skia 0.0.20130412 (git+https://github.com/servo/skia)", "xlib 0.1.0 (git+https://github.com/servo/rust-xlib)", ] @@ -40,7 +40,7 @@ version = "0.0.1" source = "git+https://github.com/servo/rust-cgl#851ca1b90081d221c3c38d33548d3e22a19db79f" dependencies = [ "gleam 0.0.1 (git+https://github.com/servo/gleam)", - "libc 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -48,7 +48,7 @@ name = "core_foundation" version = "0.1.0" source = "git+https://github.com/servo/rust-core-foundation#c8236c28599b07894fa7d6887db2fa91bc7fda24" dependencies = [ - "libc 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -57,7 +57,7 @@ version = "0.1.0" source = "git+https://github.com/servo/rust-core-graphics#2d8d665c5bdd116b4a1addbe5c415735fb78e1a9" dependencies = [ "core_foundation 0.1.0 (git+https://github.com/servo/rust-core-foundation)", - "libc 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -67,7 +67,7 @@ source = "git+https://github.com/servo/rust-core-text#2b4b546718310a9d3fe4273a1d dependencies = [ "core_foundation 0.1.0 (git+https://github.com/servo/rust-core-foundation)", "core_graphics 0.1.0 (git+https://github.com/servo/rust-core-graphics)", - "libc 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -75,7 +75,7 @@ name = "egl" version = "0.1.0" source = "git+https://github.com/servo/rust-egl#c0159346b3adfdcf13f2cd86f5ee41750a72c078" dependencies = [ - "libc 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -88,7 +88,7 @@ name = "freetype" version = "0.1.0" source = "git+https://github.com/servo/rust-freetype#f256a9ac84893f0a183b8966de2a3a03d7552b8b" dependencies = [ - "libc 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -112,7 +112,7 @@ name = "gl_common" version = "0.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -133,7 +133,7 @@ dependencies = [ "gl_common 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "gl_generator 0.0.25 (registry+https://github.com/rust-lang/crates.io-index)", "khronos_api 0.0.5 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -144,7 +144,7 @@ dependencies = [ "gl_common 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "gl_generator 0.0.25 (registry+https://github.com/rust-lang/crates.io-index)", "khronos_api 0.0.5 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -156,7 +156,7 @@ dependencies = [ "core_foundation 0.1.0 (git+https://github.com/servo/rust-core-foundation)", "geom 0.1.0 (git+https://github.com/servo/rust-geom)", "gleam 0.0.1 (git+https://github.com/servo/gleam)", - "libc 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -177,7 +177,7 @@ dependencies = [ "gleam 0.0.1 (git+https://github.com/servo/gleam)", "glx 0.0.1 (git+https://github.com/servo/rust-glx)", "io_surface 0.1.0 (git+https://github.com/servo/rust-io-surface)", - "libc 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "skia 0.0.20130412 (git+https://github.com/servo/skia)", @@ -186,7 +186,7 @@ dependencies = [ [[package]] name = "libc" -version = "0.1.6" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -194,7 +194,7 @@ name = "log" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -206,12 +206,17 @@ dependencies = [ "rustc-serialize 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "pkg-config" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "rand" version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -228,13 +233,22 @@ dependencies = [ "freetype-sys 2.4.11 (git+https://github.com/servo/libfreetype2)", ] +[[package]] +name = "x11" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", + "pkg-config 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "xlib" version = "0.1.0" source = "git+https://github.com/servo/rust-xlib#1a0f3d48fbebf96e2d1bf83ac71309b27f49e0c7" dependencies = [ "bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index b23afe3..85f2756 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ log = "*" git = "https://github.com/servo/rust-glx" [dependencies.x11] -version = "1.0.0" +version = "1.1.0" features = ["xlib"] [dependencies.cgl] diff --git a/src/gl_context.rs b/src/gl_context.rs index 29f6f69..2f6a2e9 100644 --- a/src/gl_context.rs +++ b/src/gl_context.rs @@ -29,6 +29,11 @@ pub struct GLContext { } impl GLContext { + #[inline(always)] + pub fn get_proc_address(addr: &str) -> *const () { + NativeGLContext::get_proc_address(addr) + } + pub fn create_headless() -> Result { let native_context = try!(NativeGLContext::create_headless()); diff --git a/src/platform/mod.rs b/src/platform/mod.rs index 2379e4b..220b46f 100644 --- a/src/platform/mod.rs +++ b/src/platform/mod.rs @@ -2,9 +2,12 @@ use layers::platform::surface::NativeGraphicsMetadata; pub trait NativeGLContextMethods { + fn get_proc_address(&str) -> *const (); + fn create_headless() -> Result; fn is_current(&self) -> bool; fn make_current(&self) -> Result<(), &'static str>; + #[cfg(feature="texture_surface")] fn get_metadata(&self) -> NativeGraphicsMetadata; diff --git a/src/platform/not_implemented/native_gl_context.rs b/src/platform/not_implemented/native_gl_context.rs index 62f4445..70ebec1 100644 --- a/src/platform/not_implemented/native_gl_context.rs +++ b/src/platform/not_implemented/native_gl_context.rs @@ -6,6 +6,10 @@ pub struct NativeGLContext; use layers::platform::surface::NativeGraphicsMetadata; impl NativeGLContextMethods for NativeGLContext { + fn get_proc_address(addr: &str) -> *const () { + 0 as *const () + } + fn create_headless() -> Result { Err("Not implemented (yet)") } diff --git a/src/platform/with_cgl/native_gl_context.rs b/src/platform/with_cgl/native_gl_context.rs index eebabc2..1e51679 100644 --- a/src/platform/with_cgl/native_gl_context.rs +++ b/src/platform/with_cgl/native_gl_context.rs @@ -1,6 +1,11 @@ use cgl::*; use std::mem; +use core_foundation::bundle::{CFBundleGetBundleWithIdentifier, CFBundleGetFunctionPointerForName}; +use core_foundation::base::TCFType; +use core_foundation::string::CFString; +use std::str::FromStr; + use platform::NativeGLContextMethods; #[cfg(feature="texture_surface")] @@ -56,6 +61,18 @@ impl Drop for NativeGLContext { } impl NativeGLContextMethods for NativeGLContext { + fn get_proc_address(addr: &str) -> *const () { + let symbol_name: CFString = FromStr::from_str(addr).unwrap(); + let framework_name: CFString = FromStr::from_str("com.apple.opengl").unwrap(); + let framework = unsafe { + CFBundleGetBundleWithIdentifier(framework_name.as_concrete_TypeRef()) + }; + let symbol = unsafe { + CFBundleGetFunctionPointerForName(framework, symbol_name.as_concrete_TypeRef()) + }; + symbol as *const () + } + fn create_headless() -> Result { let mut attributes = [ 0 diff --git a/src/platform/with_egl/native_gl_context.rs b/src/platform/with_egl/native_gl_context.rs index 590b89a..ac8adc0 100644 --- a/src/platform/with_egl/native_gl_context.rs +++ b/src/platform/with_egl/native_gl_context.rs @@ -1,3 +1,4 @@ +use std::ffi::CString; use geom::Size2D; use NativeGLContextMethods; use platform::with_egl::utils::{create_pixel_buffer_backed_offscreen_context}; @@ -52,6 +53,14 @@ impl NativeGLContext { impl NativeGLContextMethods for NativeGLContext { + fn get_proc_address(addr: &str) -> *const () { + let addr = CString::new(s.as_bytes()).unwrap(); + let addr = addr.as_ptr(); + unsafe { + egl::GetProcAddress(addr as *const _) as *const () + } + } + fn create_headless() -> Result { // We create a context with a dummy size, we can't rely on a // default framebuffer diff --git a/src/platform/with_glx/native_gl_context.rs b/src/platform/with_glx/native_gl_context.rs index bfc7e1d..4fb8610 100644 --- a/src/platform/with_glx/native_gl_context.rs +++ b/src/platform/with_glx/native_gl_context.rs @@ -1,3 +1,5 @@ +use std::ffi::CString; + use glx; use x11::xlib::*; use libc::*; @@ -65,6 +67,14 @@ impl Drop for NativeGLContext { } impl NativeGLContextMethods for NativeGLContext { + fn get_proc_address(addr: &str) -> *const () { + let addr = CString::new(addr.as_bytes()).unwrap(); + let addr = addr.as_ptr(); + unsafe { + glx::GetProcAddress(addr as *const _) as *const () + } + } + fn create_headless() -> Result { // We create a context with a dummy size since in other platforms // a default framebuffer is not bound diff --git a/src/tests.rs b/src/tests.rs index 6ddeaef..5cda3c1 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -5,22 +5,6 @@ use GLContext; use GLContextAttributes; use ColorAttachmentType; -use std::ffi::CString; - -#[cfg(target_os = "linux")] -use glx; -#[cfg(target_os = "android")] -use egl; - -#[cfg(target_os = "macos")] -use core_foundation::bundle::{CFBundleGetBundleWithIdentifier, CFBundleGetFunctionPointerForName}; -#[cfg(target_os = "macos")] -use core_foundation::base::TCFType; -#[cfg(target_os = "macos")] -use core_foundation::string::CFString; - -use std::str::FromStr; - #[cfg(feature="texture_surface")] use layers::texturegl::Texture; @@ -38,37 +22,6 @@ extern {} // This is probably a time bomb static mut GL_LOADED : bool = false; -// Shamelessly stolen from glutin -#[cfg(target_os = "linux")] -fn get_proc_address(addr: &str) -> *const () { - let addr = CString::new(addr.as_bytes()).unwrap(); - let addr = addr.as_ptr(); - unsafe { - glx::GetProcAddress(addr as *const _) as *const () - } -} - -#[cfg(target_os = "android")] -fn get_proc_address(addr: &str) -> *const () { - let addr = CString::new(s.as_bytes()).unwrap(); - let addr = addr.as_ptr(); - unsafe { - egl::GetProcAddress(addr as *const _) as *const () - } -} - -#[cfg(target_os = "macos")] -fn get_proc_address(addr: &str) -> *const () { - let symbol_name: CFString = FromStr::from_str(addr).unwrap(); - let framework_name: CFString = FromStr::from_str("com.apple.opengl").unwrap(); - let framework = unsafe { - CFBundleGetBundleWithIdentifier(framework_name.as_concrete_TypeRef()) - }; - let symbol = unsafe { - CFBundleGetFunctionPointerForName(framework, symbol_name.as_concrete_TypeRef()) - }; - symbol as *const () -} fn load_gl() { unsafe { @@ -76,7 +29,7 @@ fn load_gl() { return; } - gl::load_with(|s| get_proc_address(s) as *const _); + gl::load_with(|s| GLContext::get_proc_address(s) as *const _); GL_LOADED = true; } }