aboutsummaryrefslogtreecommitdiffstats
path: root/src/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/api')
-rw-r--r--src/api/android/mod.rs40
-rw-r--r--src/api/win32/init.rs30
-rw-r--r--src/api/win32/mod.rs5
-rw-r--r--src/api/x11/xdisplay.rs5
4 files changed, 56 insertions, 24 deletions
diff --git a/src/api/android/mod.rs b/src/api/android/mod.rs
index 83ef12b..7c09a7b 100644
--- a/src/api/android/mod.rs
+++ b/src/api/android/mod.rs
@@ -249,3 +249,43 @@ impl WindowProxy {
unimplemented!()
}
}
+
+pub struct HeadlessContext(EglContext);
+
+impl HeadlessContext {
+ /// See the docs in the crate root file.
+ pub fn new(builder: BuilderAttribs) -> Result<HeadlessContext, CreationError> {
+ let context = try!(EglContext::new(egl::ffi::egl::Egl, &builder, None));
+ let context = try!(context.finish_pbuffer());
+ Ok(context)
+ }
+}
+
+unsafe impl Send for HeadlessContext {}
+unsafe impl Sync for HeadlessContext {}
+
+impl GlContext for HeadlessContext {
+ unsafe fn make_current(&self) -> Result<(), ContextError> {
+ self.0.make_current()
+ }
+
+ fn is_current(&self) -> bool {
+ self.0.is_current()
+ }
+
+ fn get_proc_address(&self, addr: &str) -> *const libc::c_void {
+ self.0.get_proc_address(addr)
+ }
+
+ fn swap_buffers(&self) -> Result<(), ContextError> {
+ self.0.swap_buffers()
+ }
+
+ fn get_api(&self) -> Api {
+ self.0.get_api()
+ }
+
+ fn get_pixel_format(&self) -> PixelFormat {
+ self.0.get_pixel_format()
+ }
+}
diff --git a/src/api/win32/init.rs b/src/api/win32/init.rs
index fdb88c9..e6f0648 100644
--- a/src/api/win32/init.rs
+++ b/src/api/win32/init.rs
@@ -32,6 +32,7 @@ use api::wgl;
use api::wgl::Context as WglContext;
use api::egl;
use api::egl::Context as EglContext;
+use api::egl::ffi::egl::Egl;
pub enum RawContext {
Egl(egl::ffi::egl::types::EGLContext),
@@ -41,9 +42,12 @@ pub enum RawContext {
unsafe impl Send for RawContext {}
unsafe impl Sync for RawContext {}
-pub fn new_window(builder: BuilderAttribs<'static>, builder_sharelists: Option<RawContext>)
+pub fn new_window(builder: BuilderAttribs<'static>, builder_sharelists: Option<RawContext>,
+ egl: Option<&Egl>)
-> Result<Window, CreationError>
{
+ let egl = egl.map(|e| e.clone());
+
// initializing variables to be sent to the task
let title = OsStr::new(&builder.title).encode_wide().chain(Some(0).into_iter())
@@ -56,7 +60,7 @@ pub fn new_window(builder: BuilderAttribs<'static>, builder_sharelists: Option<R
thread::spawn(move || {
unsafe {
// creating and sending the `Window`
- match init(title, builder, builder_sharelists) {
+ match init(title, builder, builder_sharelists, egl) {
Ok(w) => tx.send(Ok(w)).ok(),
Err(e) => {
tx.send(Err(e)).ok();
@@ -83,7 +87,8 @@ pub fn new_window(builder: BuilderAttribs<'static>, builder_sharelists: Option<R
}
unsafe fn init(title: Vec<u16>, builder: BuilderAttribs<'static>,
- builder_sharelists: Option<RawContext>) -> Result<Window, CreationError>
+ builder_sharelists: Option<RawContext>, egl: Option<Egl>)
+ -> Result<Window, CreationError>
{
// registering the window class
let class_name = register_window_class();
@@ -159,24 +164,7 @@ unsafe fn init(title: Vec<u16>, builder: BuilderAttribs<'static>,
// creating the OpenGL context
let context = match builder.gl_version {
GlRequest::Specific(Api::OpenGlEs, (major, minor)) => {
- // trying to load EGL from the ATI drivers
-
- // TODO: use LoadLibraryA instead
- let dll_name = if cfg!(target_pointer_width = "64") {
- "atio6axx.dll"
- } else {
- "atioglxx.dll"
- };
- let dll_name = OsStr::new(dll_name).encode_wide().chain(Some(0).into_iter())
- .collect::<Vec<_>>();
- let dll = unsafe { kernel32::LoadLibraryW(dll_name.as_ptr()) };
-
- if !dll.is_null() {
- let egl = ::api::egl::ffi::egl::Egl::load_with(|name| {
- let name = CString::new(name).unwrap();
- unsafe { kernel32::GetProcAddress(dll, name.as_ptr()) as *const libc::c_void }
- });
-
+ if let Some(egl) = egl {
if let Ok(c) = EglContext::new(egl, &builder, Some(ptr::null()))
.and_then(|p| p.finish(real_window.0))
{
diff --git a/src/api/win32/mod.rs b/src/api/win32/mod.rs
index d21f16d..9b03f64 100644
--- a/src/api/win32/mod.rs
+++ b/src/api/win32/mod.rs
@@ -29,6 +29,7 @@ use kernel32;
use api::wgl;
use api::wgl::Context as WglContext;
use api::egl::Context as EglContext;
+use api::egl::ffi::egl::Egl;
use self::init::RawContext;
@@ -84,7 +85,7 @@ impl WindowProxy {
impl Window {
/// See the docs in the crate root file.
- pub fn new(builder: BuilderAttribs) -> Result<Window, CreationError> {
+ pub fn new(builder: BuilderAttribs, egl: Option<&Egl>) -> Result<Window, CreationError> {
let (builder, sharing) = builder.extract_non_static();
let sharing = sharing.map(|w| match w.context {
@@ -92,7 +93,7 @@ impl Window {
Context::Egl(_) => unimplemented!(), // FIXME:
});
- init::new_window(builder, sharing)
+ init::new_window(builder, sharing, egl)
}
/// See the docs in the crate root file.
diff --git a/src/api/x11/xdisplay.rs b/src/api/x11/xdisplay.rs
index 2576b74..c960c00 100644
--- a/src/api/x11/xdisplay.rs
+++ b/src/api/x11/xdisplay.rs
@@ -63,7 +63,10 @@ impl XConnection {
// TODO: use something safer than raw "dlopen"
let egl = {
- let libegl = unsafe { dlopen::dlopen(b"libEGL.so\0".as_ptr() as *const _, dlopen::RTLD_NOW) };
+ let mut libegl = unsafe { dlopen::dlopen(b"libEGL.so.1\0".as_ptr() as *const _, dlopen::RTLD_NOW) };
+ if libegl.is_null() {
+ libegl = unsafe { dlopen::dlopen(b"libEGL.so\0".as_ptr() as *const _, dlopen::RTLD_NOW) };
+ }
if libegl.is_null() {
None