diff --git a/Cargo.lock b/Cargo.lock index 58f8b71d72b..e365e6cf801 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3936,6 +3936,7 @@ source = "git+https://github.com/pcwalton/signpost.git#7ed712507f343c38646b9d1fe name = "simpleservo" version = "0.0.1" dependencies = [ + "core-foundation 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "gl_generator 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", "libservo 0.0.1", diff --git a/ports/libsimpleservo/api/Cargo.toml b/ports/libsimpleservo/api/Cargo.toml index a8c61f2c8f1..031dc1fca19 100644 --- a/ports/libsimpleservo/api/Cargo.toml +++ b/ports/libsimpleservo/api/Cargo.toml @@ -14,6 +14,9 @@ serde_json = "1.0" [target.'cfg(not(target_os = "macos"))'.dependencies] libc = "0.2" +[target.'cfg(target_os = "macos")'.dependencies] +core-foundation = "0.6" + [target.'cfg(target_os = "windows")'.dependencies] winapi = "0.3.2" diff --git a/ports/libsimpleservo/api/src/gl_glue.rs b/ports/libsimpleservo/api/src/gl_glue.rs index 3eb1f087afd..bc8c3ddb1b7 100644 --- a/ports/libsimpleservo/api/src/gl_glue.rs +++ b/ports/libsimpleservo/api/src/gl_glue.rs @@ -2,9 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -use std::rc::Rc; - -pub type ServoGl = Rc; +pub type ServoGl = std::rc::Rc; #[cfg(any(target_os = "android", target_os = "windows"))] #[allow(non_camel_case_types)] @@ -56,7 +54,7 @@ pub mod egl { } #[cfg(target_os = "windows")] - pub fn init() -> Result, &'static str> { + pub fn init() -> Result { info!("Loading EGL..."); let dll = b"libEGL.dll\0" as &[u8]; @@ -77,10 +75,38 @@ pub mod egl { } } -#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))] +#[cfg(any(target_os = "windows", target_os = "linux"))] pub mod gl { pub fn init() -> Result { - // FIXME: Add an OpenGL version - unimplemented!() + unimplemented!(); + } +} + +#[cfg(target_os = "macos")] +pub mod gl { + use core_foundation::base::TCFType; + use core_foundation::bundle::{ + CFBundleGetBundleWithIdentifier, CFBundleGetFunctionPointerForName, + }; + use core_foundation::string::CFString; + use servo::gl::GlFns; + use std::os::raw::c_void; + use std::str; + + pub fn init() -> Result { + info!("Loading OpenGL..."); + let gl = unsafe { + GlFns::load_with(|addr| { + let symbol_name: CFString = str::FromStr::from_str(addr).unwrap(); + let framework_name: CFString = str::FromStr::from_str("com.apple.opengl").unwrap(); + let framework = + CFBundleGetBundleWithIdentifier(framework_name.as_concrete_TypeRef()); + let symbol = + CFBundleGetFunctionPointerForName(framework, symbol_name.as_concrete_TypeRef()); + symbol as *const c_void + }) + }; + info!("OpenGL loaded"); + Ok(gl) } }