Remove BuilderAttribs

This commit is contained in:
Pierre Krieger 2015-09-21 13:15:43 +02:00
parent a8d3342468
commit 62bafe2130
13 changed files with 138 additions and 134 deletions

View file

@ -6,14 +6,16 @@ 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;
@ -161,28 +163,26 @@ impl<'a> Iterator for WaitEventsIterator<'a> {
}
impl Window {
pub fn new(builder: BuilderAttribs) -> Result<Window, CreationError> {
let window = builder.window;
let pf_reqs = builder.pf_reqs;
let opengl = builder.opengl;
pub fn new(window: &WindowAttributes, pf_reqs: &PixelFormatRequirements,
opengl: &GlAttributes<&Window>) -> Result<Window, CreationError>
{
match *BACKEND {
Backend::Wayland => {
let opengl = opengl.map_sharing(|w| match w {
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)
wayland::Window::new(window, pf_reqs, &opengl).map(Window::Wayland)
},
Backend::X(ref connec) => {
let opengl = opengl.map_sharing(|w| match w {
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)
x11::Window::new(connec, window, pf_reqs, &opengl).map(Window::X)
},
Backend::Error(ref error) => Err(CreationError::NoBackendAvailable(Box::new(error.clone())))

View file

@ -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),

View file

@ -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,10 @@ 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.window, &builder.pf_reqs, &builder.opengl.clone().map_sharing(|w| &w.0),
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))
}
}
@ -86,15 +90,15 @@ pub enum HeadlessContext {
}
impl HeadlessContext {
pub fn new(mut builder: BuilderAttribs) -> Result<HeadlessContext, CreationError> {
builder.window.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.pf_reqs, &builder.opengl.clone().map_sharing(|_| unimplemented!()), // TODO:
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(builder.window.dimensions.unwrap_or((800, 600)))) // TODO:
.and_then(|prototype| prototype.finish_pbuffer(dimensions))
.map(|ctxt| HeadlessContext::EglPbuffer(ctxt));
if let Ok(context) = context {
@ -102,7 +106,8 @@ impl HeadlessContext {
}
}
let window = try!(win32::Window::new(&builder.window, &builder.pf_reqs, &builder.opengl.clone().map_sharing(|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))
}