aboutsummaryrefslogtreecommitdiffstats
path: root/src/platform
diff options
context:
space:
mode:
Diffstat (limited to 'src/platform')
-rw-r--r--src/platform/ios/mod.rs11
-rw-r--r--src/platform/linux/api_dispatch.rs53
-rw-r--r--src/platform/linux/mod.rs11
-rw-r--r--src/platform/windows/mod.rs26
4 files changed, 75 insertions, 26 deletions
diff --git a/src/platform/ios/mod.rs b/src/platform/ios/mod.rs
index 7cbdd84..95fa7e1 100644
--- a/src/platform/ios/mod.rs
+++ b/src/platform/ios/mod.rs
@@ -1,9 +1,11 @@
#![cfg(target_os = "ios")]
use libc::c_void;
-use BuilderAttribs;
+use GlAttributes;
use CreationError;
use PixelFormat;
+use PixelFormatRequirements;
+use ContextError;
pub use api::ios::*;
@@ -11,16 +13,17 @@ pub struct HeadlessContext(i32);
impl HeadlessContext {
/// See the docs in the crate root file.
- pub fn new(_builder: BuilderAttribs) -> Result<HeadlessContext, CreationError> {
+ pub fn new(_: (u32, u32), _: &PixelFormatRequirements, _: &GlAttributes<&HeadlessContext>)
+ -> Result<HeadlessContext, CreationError> {
unimplemented!()
}
/// See the docs in the crate root file.
- pub unsafe fn make_current(&self) {
+ pub unsafe fn make_current(&self) -> Result<(), ContextError> {
unimplemented!()
}
- pub fn swap_buffers(&self) {
+ pub fn swap_buffers(&self) -> Result<(), ContextError> {
unimplemented!()
}
diff --git a/src/platform/linux/api_dispatch.rs b/src/platform/linux/api_dispatch.rs
index e580ab1..46c58bb 100644
--- a/src/platform/linux/api_dispatch.rs
+++ b/src/platform/linux/api_dispatch.rs
@@ -6,23 +6,27 @@ pub use api::x11::{WaitEventsIterator, PollEventsIterator};*/
use std::collections::VecDeque;
use std::sync::Arc;
-use BuilderAttribs;
use ContextError;
use CreationError;
use CursorState;
use Event;
+use GlAttributes;
use GlContext;
use MouseCursor;
use PixelFormat;
+use PixelFormatRequirements;
+use WindowAttributes;
use libc;
use api::wayland;
use api::x11;
use api::x11::XConnection;
+use api::x11::XNotSupported;
enum Backend {
X(Arc<XConnection>),
- Wayland
+ Wayland,
+ Error(XNotSupported),
}
lazy_static!(
@@ -31,7 +35,10 @@ lazy_static!(
if false && wayland::is_available() {
Backend::Wayland
} else {
- Backend::X(Arc::new(XConnection::new().unwrap()))
+ match XConnection::new() {
+ Ok(x) => Backend::X(Arc::new(x)),
+ Err(e) => Backend::Error(e),
+ }
}
};
);
@@ -65,7 +72,9 @@ pub enum MonitorID {
#[doc(hidden)]
X(x11::MonitorID),
#[doc(hidden)]
- Wayland(wayland::MonitorID)
+ Wayland(wayland::MonitorID),
+ #[doc(hidden)]
+ None,
}
pub fn get_available_monitors() -> VecDeque<MonitorID> {
@@ -78,6 +87,7 @@ pub fn get_available_monitors() -> VecDeque<MonitorID> {
.into_iter()
.map(MonitorID::X)
.collect(),
+ Backend::Error(_) => { let mut d = VecDeque::new(); d.push_back(MonitorID::None); d},
}
}
@@ -85,6 +95,7 @@ pub fn get_primary_monitor() -> MonitorID {
match *BACKEND {
Backend::Wayland => MonitorID::Wayland(wayland::get_primary_monitor()),
Backend::X(ref connec) => MonitorID::X(x11::get_primary_monitor(connec)),
+ Backend::Error(_) => MonitorID::None,
}
}
@@ -92,21 +103,24 @@ impl MonitorID {
pub fn get_name(&self) -> Option<String> {
match self {
&MonitorID::X(ref m) => m.get_name(),
- &MonitorID::Wayland(ref m) => m.get_name()
+ &MonitorID::Wayland(ref m) => m.get_name(),
+ &MonitorID::None => None,
}
}
pub fn get_native_identifier(&self) -> ::native_monitor::NativeMonitorId {
match self {
&MonitorID::X(ref m) => m.get_native_identifier(),
- &MonitorID::Wayland(ref m) => m.get_native_identifier()
+ &MonitorID::Wayland(ref m) => m.get_native_identifier(),
+ &MonitorID::None => unimplemented!() // FIXME:
}
}
pub fn get_dimensions(&self) -> (u32, u32) {
match self {
&MonitorID::X(ref m) => m.get_dimensions(),
- &MonitorID::Wayland(ref m) => m.get_dimensions()
+ &MonitorID::Wayland(ref m) => m.get_dimensions(),
+ &MonitorID::None => (800, 600), // FIXME:
}
}
}
@@ -149,10 +163,29 @@ impl<'a> Iterator for WaitEventsIterator<'a> {
}
impl Window {
- pub fn new(builder: BuilderAttribs) -> Result<Window, CreationError> {
+ pub fn new(window: &WindowAttributes, pf_reqs: &PixelFormatRequirements,
+ opengl: &GlAttributes<&Window>) -> Result<Window, CreationError>
+ {
match *BACKEND {
- Backend::Wayland => wayland::Window::new(builder).map(Window::Wayland),
- Backend::X(ref connec) => x11::Window::new(connec, builder).map(Window::X),
+ Backend::Wayland => {
+ let opengl = opengl.clone().map_sharing(|w| match w {
+ &Window::Wayland(ref w) => w,
+ _ => panic!() // TODO: return an error
+ });
+
+ wayland::Window::new(window, pf_reqs, &opengl).map(Window::Wayland)
+ },
+
+ Backend::X(ref connec) => {
+ let opengl = opengl.clone().map_sharing(|w| match w {
+ &Window::X(ref w) => w,
+ _ => panic!() // TODO: return an error
+ });
+
+ x11::Window::new(connec, window, pf_reqs, &opengl).map(Window::X)
+ },
+
+ Backend::Error(ref error) => Err(CreationError::NoBackendAvailable(Box::new(error.clone())))
}
}
diff --git a/src/platform/linux/mod.rs b/src/platform/linux/mod.rs
index 3525ce5..f5d663b 100644
--- a/src/platform/linux/mod.rs
+++ b/src/platform/linux/mod.rs
@@ -1,11 +1,12 @@
#![cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd"))]
use Api;
-use BuilderAttribs;
use ContextError;
use CreationError;
+use GlAttributes;
use GlContext;
use PixelFormat;
+use PixelFormatRequirements;
use libc;
use api::osmesa::{self, OsMesaContext};
@@ -25,8 +26,12 @@ pub type MonitorID = (); // TODO: hack to make things work
pub struct HeadlessContext(OsMesaContext);
impl HeadlessContext {
- pub fn new(builder: BuilderAttribs) -> Result<HeadlessContext, CreationError> {
- match OsMesaContext::new(builder) {
+ pub fn new(dimensions: (u32, u32), pf_reqs: &PixelFormatRequirements,
+ opengl: &GlAttributes<&HeadlessContext>) -> Result<HeadlessContext, CreationError>
+ {
+ let opengl = opengl.clone().map_sharing(|c| &c.0);
+
+ match OsMesaContext::new(dimensions, pf_reqs, &opengl) {
Ok(c) => return Ok(HeadlessContext(c)),
Err(osmesa::OsMesaCreationError::NotSupported) => (),
Err(osmesa::OsMesaCreationError::CreationError(e)) => return Err(e),
diff --git a/src/platform/windows/mod.rs b/src/platform/windows/mod.rs
index 7087a23..af9261f 100644
--- a/src/platform/windows/mod.rs
+++ b/src/platform/windows/mod.rs
@@ -7,11 +7,13 @@ pub use api::win32::{WindowProxy, PollEventsIterator, WaitEventsIterator};
use libc;
use Api;
-use BuilderAttribs;
use ContextError;
use CreationError;
use PixelFormat;
+use PixelFormatRequirements;
+use GlAttributes;
use GlContext;
+use WindowAttributes;
use api::egl::ffi::egl::Egl;
use api::egl;
@@ -57,8 +59,11 @@ pub struct Window(win32::Window);
impl Window {
/// See the docs in the crate root file.
- pub fn new(builder: BuilderAttribs) -> Result<Window, CreationError> {
- win32::Window::new(builder, EGL.as_ref().map(|w| &w.0)).map(|w| Window(w))
+ pub fn new(window: &WindowAttributes, pf_reqs: &PixelFormatRequirements,
+ opengl: &GlAttributes<&Window>) -> Result<Window, CreationError>
+ {
+ win32::Window::new(window, pf_reqs, &opengl.clone().map_sharing(|w| &w.0),
+ EGL.as_ref().map(|w| &w.0)).map(|w| Window(w))
}
}
@@ -85,14 +90,15 @@ pub enum HeadlessContext {
}
impl HeadlessContext {
- pub fn new(mut builder: BuilderAttribs) -> Result<HeadlessContext, CreationError> {
- builder.visible = false;
-
+ pub fn new(dimensions: (u32, u32), pf_reqs: &PixelFormatRequirements,
+ opengl: &GlAttributes<&HeadlessContext>) -> Result<HeadlessContext, CreationError>
+ {
// if EGL is available, we try using EGL first
// if EGL returns an error, we try the hidden window method
if let &Some(ref egl) = &*EGL {
- let context = EglContext::new(egl.0.clone(), &builder, egl::NativeDisplay::Other(None))
- .and_then(|prototype| prototype.finish_pbuffer())
+ let context = EglContext::new(egl.0.clone(), pf_reqs, &opengl.clone().map_sharing(|_| unimplemented!()), // TODO:
+ egl::NativeDisplay::Other(None))
+ .and_then(|prototype| prototype.finish_pbuffer(dimensions))
.map(|ctxt| HeadlessContext::EglPbuffer(ctxt));
if let Ok(context) = context {
@@ -100,7 +106,9 @@ impl HeadlessContext {
}
}
- let window = try!(win32::Window::new(builder, EGL.as_ref().map(|w| &w.0)));
+ let window = try!(win32::Window::new(&WindowAttributes { visible: false, .. Default::default() },
+ pf_reqs, &opengl.clone().map_sharing(|_| unimplemented!()), //TODO:
+ EGL.as_ref().map(|w| &w.0)));
Ok(HeadlessContext::HiddenWindow(window))
}
}