Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Add OpenGL support to libsimpleservo ... #22805

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

I am just having a lot of issues with my dependencies and the bulkyn…

…ess of building. Can i place my patch in treeherder, and yup i have done the changes paul and jdm you might review it !
  • Loading branch information
Hyperion101010 committed Feb 6, 2019
commit 800da52920e9fd85a2112c21cced093074ec3a80
@@ -2,6 +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 servo::gl::GlType::Gl;
use std::rc::Rc;

pub type ServoGl = Rc<dyn servo::gl::Gl>;
@@ -56,6 +57,9 @@ pub mod egl {
}

#[cfg(target_os = "windows")]
use winapi::shared::windef::HGLRC;
use winapi::um::libloaderapi::*;

pub fn init() -> Result<Rc<Gl>, &'static str> {
info!("Loading EGL...");

@@ -77,10 +81,111 @@ pub mod egl {
}
}

#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
//#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
//pub mod gl {
// pub fn init() -> Result<crate::gl_glue::ServoGl, &'static str> {
// FIXME: Add an OpenGL version
//unimplemented!()
// }
//}

#[cfg(target_os = "macos")]
pub mod gl {
pub fn init() -> Result<crate::gl_glue::ServoGl, &'static str> {
// FIXME: Add an OpenGL version
unimplemented!()
use core_foundation::base::TCFType;
use core_foundation::bundle::{
CFBundleGetBundleWithIdentifier, CFBundleGetFunctionPointerForName,
};
use core_foundation::string::CFString;
use servo::gl::GlType::Gl;
use std::os::raw::c_void;
use std::rc::Rc;
use std::str;

#[cfg(target_os = "macos")]
pub fn init() -> Result<Rc<Gl>, &'static str> {
info!("Loading OpenGL...");
let opengl_pointer;
opengl_pointer = unsafe {
gl::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
})
};
if opengl_pointer.is_null() {
Err("OpenGL isn't configured/installed")
}
info!("OpenGL loaded");
Ok(opengl_pointer)
}
}

#[cfg(target_os = "windows")]
pub mod gl {
use servo::gl::GlType::Gl;
use std::ffi::CString;
use std::rc::Rc;
use winapi::um::libloaderapi::{GetProcAddress, LoadLibraryA};

pub fn init() -> Result<Rc<Gl>, &'static str> {
info!("Loading OpenGL...");

let opengl_pointer;
let dll = b"OpenGL32.dll\0" as &[u8];
let dll = unsafe { LoadLibraryA(dll.as_ptr() as *const _) };
if dll.is_null {
Err("Can't find Opengl32.dll, OpenGL isn't configured/installed")
} else {
unsafe {
opengl_pointer = gl::GlFns::load_with(|addr| {
let addr = CString::new(addr.as_bytes()).unwrap();
let addr = addr.as_ptr();
GetProcAddress(dll, addr) as *const _
});
}
}
info!("OpenGL loaded");
Ok(opengl_pointer)
}
}

#[cfg(any(
target_os = "dragonfly",
target_os = "linux",
target_os = "freebsd",
target_os = "openbsd"
))]

pub mod gl {
use api::dlopen;
use servo::gl::GlType::Gl;
use std::ffi::CString;
use std::rc::Rc;

pub fn init() -> Result<Rc<Gl>, &'static str> {
info!("Loading OpenGL");
//Glx bindings
pub mod glx {
include!(concat!(env!("OUT_DIR"), "/glx_bindings.rs"));
}

let mut libglx =
unsafe { dlopen::dlopen(b"libGL.so\0".as_ptr() as *const _, dlopen::RTLD_NOW) };
if libglx.is_null() {
Err("Can't find libGL.so, OpenGL isn't configured/installed")
}
//initializing glx instance
let glx_instance = Glx::load_with(|sym| {
let sym = CString::new(sym).unwrap();
unsafe { dlopen::dlsym(libglx, sym.as_ptr()) }
});
//finding the opengl address loaded in memory and returning the pointer to memory address
let opengl_instance = gl::GlFns::load_with(|addr| glx_instance.GetProcAddress(addr));
info!("OpenGL is loaded");
Ok(opengl_instance)
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.