From 48fe9b26442662517b1590cb98ab81d79b059953 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Mon, 21 Sep 2015 09:15:53 +0200 Subject: Extract WindowAttributes from the BuilderAttribs --- src/api/wayland/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/api/wayland/mod.rs') diff --git a/src/api/wayland/mod.rs b/src/api/wayland/mod.rs index b46e2d1..7bc5798 100644 --- a/src/api/wayland/mod.rs +++ b/src/api/wayland/mod.rs @@ -251,7 +251,7 @@ impl Window { if !is_egl_available() { return Err(CreationError::NotSupported) } - let (w, h) = builder.dimensions.unwrap_or((800, 600)); + let (w, h) = builder.window.dimensions.unwrap_or((800, 600)); let surface = EGLSurface::new( wayland_context.compositor.create_surface(), @@ -259,12 +259,12 @@ impl Window { h as i32 ); - let mut shell_window = if let Some(PlatformMonitorID::Wayland(ref monitor)) = builder.monitor { + let mut shell_window = if let Some(PlatformMonitorID::Wayland(ref monitor)) = builder.window.monitor { let shell_surface = wayland_context.shell.get_shell_surface(surface); shell_surface.set_fullscreen(ShellFullscreenMethod::Default, Some(&monitor.output)); ShellWindow::Plain(shell_surface) } else { - if builder.decorations { + if builder.window.decorations { ShellWindow::Decorated(match DecoratedSurface::new( surface, w as i32, -- cgit v1.2.3 From 3054e2ee0236672ae88bd124e60ba49aae701695 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Mon, 21 Sep 2015 10:11:32 +0200 Subject: Switch EGL to use only pf_reqs and opengl --- src/api/android/mod.rs | 5 +++-- src/api/egl/mod.rs | 39 ++++++++++++++++++------------------ src/api/wayland/mod.rs | 2 +- src/api/win32/init.rs | 2 +- src/api/x11/window.rs | 5 +++-- src/lib.rs | 48 ++++++++++++++++++++++++++------------------- src/platform/windows/mod.rs | 5 +++-- 7 files changed, 58 insertions(+), 48 deletions(-) (limited to 'src/api/wayland/mod.rs') diff --git a/src/api/android/mod.rs b/src/api/android/mod.rs index 0f770c2..ecea9b3 100644 --- a/src/api/android/mod.rs +++ b/src/api/android/mod.rs @@ -112,7 +112,8 @@ impl Window { return Err(OsError(format!("Android's native window is null"))); } - let context = try!(EglContext::new(egl::ffi::egl::Egl, &builder, egl::NativeDisplay::Android) + let context = try!(EglContext::new(egl::ffi::egl::Egl, &builder.pf_reqs, &builder.opengl, + egl::NativeDisplay::Android) .and_then(|p| p.finish(native_window as *const _))); let (tx, rx) = channel(); @@ -256,7 +257,7 @@ impl HeadlessContext { /// See the docs in the crate root file. pub fn new(builder: BuilderAttribs) -> Result { let context = try!(EglContext::new(egl::ffi::egl::Egl, &builder, egl::NativeDisplay::Android)); - let context = try!(context.finish_pbuffer()); + let context = try!(context.finish_pbuffer(builder.window.dimensions.unwrap_or((800, 600)))); // TODO: Ok(HeadlessContext(context)) } } diff --git a/src/api/egl/mod.rs b/src/api/egl/mod.rs index 32ab71e..56b709d 100644 --- a/src/api/egl/mod.rs +++ b/src/api/egl/mod.rs @@ -2,12 +2,13 @@ target_os = "dragonfly", target_os = "freebsd"))] #![allow(unused_variables)] -use BuilderAttribs; use ContextError; use CreationError; +use GlAttributes; use GlContext; use GlRequest; use PixelFormat; +use PixelFormatRequirements; use Robustness; use Api; @@ -158,11 +159,11 @@ impl Context { /// This function initializes some things and chooses the pixel format. /// /// To finish the process, you must call `.finish(window)` on the `ContextPrototype`. - pub fn new<'a>(egl: ffi::egl::Egl, builder: &'a BuilderAttribs<'a>, - native_display: NativeDisplay) + pub fn new<'a>(egl: ffi::egl::Egl, pf_reqs: &PixelFormatRequirements, + opengl: &'a GlAttributes<&'a Context>, native_display: NativeDisplay) -> Result, CreationError> { - if builder.opengl.sharing.is_some() { + if opengl.sharing.is_some() { unimplemented!() } @@ -197,7 +198,7 @@ impl Context { // binding the right API and choosing the version let (version, api) = unsafe { - match builder.opengl.version { + match opengl.version { GlRequest::Latest => { if egl_version >= (1, 4) { if egl.BindAPI(ffi::egl::OPENGL_API) != 0 { @@ -246,10 +247,10 @@ impl Context { }; let configs = unsafe { try!(enumerate_configs(&egl, display, &egl_version, api, version)) }; - let (config_id, pixel_format) = try!(builder.choose_pixel_format(configs.into_iter())); + let (config_id, pixel_format) = try!(pf_reqs.choose_pixel_format(configs.into_iter())); Ok(ContextPrototype { - builder: builder, + opengl: opengl, egl: egl, display: display, egl_version: egl_version, @@ -330,7 +331,7 @@ impl Drop for Context { } pub struct ContextPrototype<'a> { - builder: &'a BuilderAttribs<'a>, + opengl: &'a GlAttributes<&'a Context>, egl: ffi::egl::Egl, display: ffi::egl::types::EGLDisplay, egl_version: (ffi::egl::types::EGLint, ffi::egl::types::EGLint), @@ -366,9 +367,7 @@ impl<'a> ContextPrototype<'a> { self.finish_impl(surface) } - pub fn finish_pbuffer(self) -> Result { - let dimensions = self.builder.window.dimensions.unwrap_or((800, 600)); - + pub fn finish_pbuffer(self, dimensions: (u32, u32)) -> Result { let attrs = &[ ffi::egl::WIDTH as libc::c_int, dimensions.0 as libc::c_int, ffi::egl::HEIGHT as libc::c_int, dimensions.1 as libc::c_int, @@ -394,18 +393,18 @@ impl<'a> ContextPrototype<'a> { if let Some(version) = self.version { try!(create_context(&self.egl, self.display, &self.egl_version, &self.extensions, self.api, version, self.config_id, - self.builder.opengl.debug, self.builder.opengl.robustness)) + self.opengl.debug, self.opengl.robustness)) } else if self.api == Api::OpenGlEs { if let Ok(ctxt) = create_context(&self.egl, self.display, &self.egl_version, &self.extensions, self.api, (2, 0), self.config_id, - self.builder.opengl.debug, self.builder.opengl.robustness) + self.opengl.debug, self.opengl.robustness) { ctxt } else if let Ok(ctxt) = create_context(&self.egl, self.display, &self.egl_version, &self.extensions, self.api, (1, 0), - self.config_id, self.builder.opengl.debug, - self.builder.opengl.robustness) + self.config_id, self.opengl.debug, + self.opengl.robustness) { ctxt } else { @@ -415,19 +414,19 @@ impl<'a> ContextPrototype<'a> { } else { if let Ok(ctxt) = create_context(&self.egl, self.display, &self.egl_version, &self.extensions, self.api, (3, 2), self.config_id, - self.builder.opengl.debug, self.builder.opengl.robustness) + self.opengl.debug, self.opengl.robustness) { ctxt } else if let Ok(ctxt) = create_context(&self.egl, self.display, &self.egl_version, &self.extensions, self.api, (3, 1), - self.config_id, self.builder.opengl.debug, - self.builder.opengl.robustness) + self.config_id, self.opengl.debug, + self.opengl.robustness) { ctxt } else if let Ok(ctxt) = create_context(&self.egl, self.display, &self.egl_version, &self.extensions, self.api, (1, 0), - self.config_id, self.builder.opengl.debug, - self.builder.opengl.robustness) + self.config_id, self.opengl.debug, + self.opengl.robustness) { ctxt } else { diff --git a/src/api/wayland/mod.rs b/src/api/wayland/mod.rs index 7bc5798..56b9218 100644 --- a/src/api/wayland/mod.rs +++ b/src/api/wayland/mod.rs @@ -291,7 +291,7 @@ impl Window { }); try!(EglContext::new( egl, - &builder, + &builder.pf_reqs, &builder.opengl.clone().map_sharing(|_| unimplemented!()), // TODO: egl::NativeDisplay::Wayland(Some(wayland_context.display.ptr() as *const _))) .and_then(|p| p.finish((**shell_window.get_shell()).ptr() as *const _)) ) diff --git a/src/api/win32/init.rs b/src/api/win32/init.rs index 8c2d86c..ad6d2ea 100644 --- a/src/api/win32/init.rs +++ b/src/api/win32/init.rs @@ -162,7 +162,7 @@ unsafe fn init(title: Vec, builder: BuilderAttribs<'static>, let context = match builder.opengl.version { GlRequest::Specific(Api::OpenGlEs, (_major, _minor)) => { if let Some(egl) = egl { - if let Ok(c) = EglContext::new(egl, &builder, + if let Ok(c) = EglContext::new(egl, &builder.pf_reqs, &builder.opengl.clone().map_sharing(|_| unimplemented!()), egl::NativeDisplay::Other(Some(ptr::null()))) .and_then(|p| p.finish(real_window.0)) { diff --git a/src/api/x11/window.rs b/src/api/x11/window.rs index d39e701..0a9189a 100644 --- a/src/api/x11/window.rs +++ b/src/api/x11/window.rs @@ -349,6 +349,7 @@ impl Window { Egl(::api::egl::ContextPrototype<'a>), } let builder_clone = builder.clone(); + let builder_clone_opengl = builder_clone.opengl.clone().map_sharing(|_| unimplemented!()); let context = match builder.opengl.version { GlRequest::Latest | GlRequest::Specific(Api::OpenGl, _) | GlRequest::GlThenGles { .. } => { // GLX should be preferred over EGL, otherwise crashes may occur @@ -356,14 +357,14 @@ impl Window { if let Some(ref glx) = display.glx { Prototype::Glx(try!(GlxContext::new(glx.clone(), &display.xlib, &builder_clone, display.display))) } else if let Some(ref egl) = display.egl { - Prototype::Egl(try!(EglContext::new(egl.clone(), &builder_clone, egl::NativeDisplay::X11(Some(display.display as *const _))))) + Prototype::Egl(try!(EglContext::new(egl.clone(), &builder_clone.pf_reqs, &builder_clone_opengl, egl::NativeDisplay::X11(Some(display.display as *const _))))) } else { return Err(CreationError::NotSupported); } }, GlRequest::Specific(Api::OpenGlEs, _) => { if let Some(ref egl) = display.egl { - Prototype::Egl(try!(EglContext::new(egl.clone(), &builder_clone, egl::NativeDisplay::X11(Some(display.display as *const _))))) + Prototype::Egl(try!(EglContext::new(egl.clone(), &builder_clone.pf_reqs, &builder_clone_opengl, egl::NativeDisplay::X11(Some(display.display as *const _))))) } else { return Err(CreationError::NotSupported); } diff --git a/src/lib.rs b/src/lib.rs index a5155f9..8c93036 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -411,32 +411,53 @@ impl<'a> BuilderAttribs<'a> { (new_attribs, sharing) } + fn choose_pixel_format(&self, iter: I) -> Result<(T, PixelFormat), CreationError> + where I: IntoIterator, T: Clone + { + self.pf_reqs.choose_pixel_format(iter) + } +} + +/// VERY UNSTABLE! Describes how the backend should choose a pixel format. +#[derive(Clone, Debug)] +#[allow(missing_docs)] +pub struct PixelFormatRequirements { + pub multisampling: Option, + pub depth_bits: Option, + pub stencil_bits: Option, + pub color_bits: Option, + pub alpha_bits: Option, + pub stereoscopy: bool, + pub srgb: Option, +} + +impl PixelFormatRequirements { fn choose_pixel_format(&self, iter: I) -> Result<(T, PixelFormat), CreationError> where I: IntoIterator, T: Clone { // filtering formats that don't match the requirements let iter = iter.into_iter().filter(|&(_, ref format)| { - if format.color_bits < self.pf_reqs.color_bits.unwrap_or(0) { + if format.color_bits < self.color_bits.unwrap_or(0) { return false; } - if format.alpha_bits < self.pf_reqs.alpha_bits.unwrap_or(0) { + if format.alpha_bits < self.alpha_bits.unwrap_or(0) { return false; } - if format.depth_bits < self.pf_reqs.depth_bits.unwrap_or(0) { + if format.depth_bits < self.depth_bits.unwrap_or(0) { return false; } - if format.stencil_bits < self.pf_reqs.stencil_bits.unwrap_or(0) { + if format.stencil_bits < self.stencil_bits.unwrap_or(0) { return false; } - if !format.stereoscopy && self.pf_reqs.stereoscopy { + if !format.stereoscopy && self.stereoscopy { return false; } - if let Some(req_ms) = self.pf_reqs.multisampling { + if let Some(req_ms) = self.multisampling { match format.multisampling { Some(val) if val >= req_ms => (), _ => return false @@ -447,7 +468,7 @@ impl<'a> BuilderAttribs<'a> { } } - if let Some(srgb) = self.pf_reqs.srgb { + if let Some(srgb) = self.srgb { if srgb != format.srgb { return false; } @@ -511,19 +532,6 @@ impl<'a> BuilderAttribs<'a> { } } -/// VERY UNSTABLE! Describes how the backend should choose a pixel format. -#[derive(Clone, Debug)] -#[allow(missing_docs)] -pub struct PixelFormatRequirements { - pub multisampling: Option, - pub depth_bits: Option, - pub stencil_bits: Option, - pub color_bits: Option, - pub alpha_bits: Option, - pub stereoscopy: bool, - pub srgb: Option, -} - impl Default for PixelFormatRequirements { fn default() -> PixelFormatRequirements { PixelFormatRequirements { diff --git a/src/platform/windows/mod.rs b/src/platform/windows/mod.rs index 521939c..918b779 100644 --- a/src/platform/windows/mod.rs +++ b/src/platform/windows/mod.rs @@ -91,8 +91,9 @@ impl HeadlessContext { // 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(), &builder.pf_reqs, &builder.opengl.clone().map_sharing(|_| unimplemented!()), // TODO: + egl::NativeDisplay::Other(None)) + .and_then(|prototype| prototype.finish_pbuffer(builder.window.dimensions.unwrap_or((800, 600)))) // TODO: .map(|ctxt| HeadlessContext::EglPbuffer(ctxt)); if let Ok(context) = context { -- cgit v1.2.3 From 5182023fd6f14469290b80f0f5e9b0dead73048e Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Mon, 21 Sep 2015 11:52:21 +0200 Subject: Switch X11 and wayland to the new design --- src/api/wayland/mod.rs | 16 +++++++++------ src/api/x11/window.rs | 41 +++++++++++++++++++++----------------- src/platform/linux/api_dispatch.rs | 24 ++++++++++++++++++++-- 3 files changed, 55 insertions(+), 26 deletions(-) (limited to 'src/api/wayland/mod.rs') diff --git a/src/api/wayland/mod.rs b/src/api/wayland/mod.rs index 56b9218..10d2acb 100644 --- a/src/api/wayland/mod.rs +++ b/src/api/wayland/mod.rs @@ -13,14 +13,16 @@ use api::dlopen; use api::egl; use api::egl::Context as EglContext; -use BuilderAttribs; use ContextError; use CreationError; use Event; use PixelFormat; use CursorState; use MouseCursor; +use GlAttributes; use GlContext; +use PixelFormatRequirements; +use WindowAttributes; use std::collections::VecDeque; use std::ops::{Deref, DerefMut}; @@ -241,7 +243,9 @@ impl<'a> Iterator for WaitEventsIterator<'a> { } impl Window { - pub fn new(builder: BuilderAttribs) -> Result { + pub fn new(window: &WindowAttributes, pf_reqs: &PixelFormatRequirements, + opengl: &GlAttributes<&Window>) -> Result + { use self::wayland::internals::FFI; let wayland_context = match *WAYLAND_CONTEXT { @@ -251,7 +255,7 @@ impl Window { if !is_egl_available() { return Err(CreationError::NotSupported) } - let (w, h) = builder.window.dimensions.unwrap_or((800, 600)); + let (w, h) = window.dimensions.unwrap_or((800, 600)); let surface = EGLSurface::new( wayland_context.compositor.create_surface(), @@ -259,12 +263,12 @@ impl Window { h as i32 ); - let mut shell_window = if let Some(PlatformMonitorID::Wayland(ref monitor)) = builder.window.monitor { + let mut shell_window = if let Some(PlatformMonitorID::Wayland(ref monitor)) = window.monitor { let shell_surface = wayland_context.shell.get_shell_surface(surface); shell_surface.set_fullscreen(ShellFullscreenMethod::Default, Some(&monitor.output)); ShellWindow::Plain(shell_surface) } else { - if builder.window.decorations { + if window.decorations { ShellWindow::Decorated(match DecoratedSurface::new( surface, w as i32, @@ -291,7 +295,7 @@ impl Window { }); try!(EglContext::new( egl, - &builder.pf_reqs, &builder.opengl.clone().map_sharing(|_| unimplemented!()), // TODO: + pf_reqs, &opengl.clone().map_sharing(|_| unimplemented!()), // TODO: egl::NativeDisplay::Wayland(Some(wayland_context.display.ptr() as *const _))) .and_then(|p| p.finish((**shell_window.get_shell()).ptr() as *const _)) ) diff --git a/src/api/x11/window.rs b/src/api/x11/window.rs index 8447c7f..3032bfd 100644 --- a/src/api/x11/window.rs +++ b/src/api/x11/window.rs @@ -1,4 +1,4 @@ -use {Event, BuilderAttribs, MouseCursor}; +use {Event, MouseCursor}; use CreationError; use CreationError::OsError; use libc; @@ -12,9 +12,12 @@ use std::sync::{Arc, Mutex}; use Api; use ContextError; use CursorState; +use GlAttributes; use GlContext; use GlRequest; use PixelFormat; +use PixelFormatRequirements; +use WindowAttributes; use api::glx::Context as GlxContext; use api::egl; @@ -295,10 +298,13 @@ pub struct Window { } impl Window { - pub fn new(display: &Arc, builder: BuilderAttribs) -> Result { - let dimensions = builder.window.dimensions.unwrap_or((800, 600)); + pub fn new(display: &Arc, window_attrs: &WindowAttributes, + pf_reqs: &PixelFormatRequirements, opengl: &GlAttributes<&Window>) + -> Result + { + let dimensions = window_attrs.dimensions.unwrap_or((800, 600)); - let screen_id = match builder.window.monitor { + let screen_id = match window_attrs.monitor { Some(PlatformMonitorID::X(MonitorID(_, monitor))) => monitor as i32, _ => unsafe { (display.xlib.XDefaultScreen)(display.display) }, }; @@ -316,7 +322,7 @@ impl Window { // FIXME: `XF86VidModeModeInfo` is missing its `hskew` field. Therefore we point to // `vsyncstart` instead of `vdisplay` as a temporary hack. - let mode_to_switch_to = if builder.window.monitor.is_some() { + let mode_to_switch_to = if window_attrs.monitor.is_some() { let matching_mode = (0 .. mode_num).map(|i| { let m: ffi::XF86VidModeModeInfo = ptr::read(*modes.offset(i as isize) as *const _); m }).find(|m| m.hdisplay == dimensions.0 as u16 && m.vsyncstart == dimensions.1 as u16); @@ -348,24 +354,23 @@ impl Window { Glx(::api::glx::ContextPrototype<'a>), Egl(::api::egl::ContextPrototype<'a>), } - let builder_clone = builder.clone(); - let builder_clone_opengl_glx = builder_clone.opengl.clone().map_sharing(|_| unimplemented!()); // FIXME: - let builder_clone_opengl_egl = builder_clone.opengl.clone().map_sharing(|_| unimplemented!()); // FIXME: - let context = match builder.opengl.version { + let builder_clone_opengl_glx = opengl.clone().map_sharing(|_| unimplemented!()); // FIXME: + let builder_clone_opengl_egl = opengl.clone().map_sharing(|_| unimplemented!()); // FIXME: + let context = match opengl.version { GlRequest::Latest | GlRequest::Specific(Api::OpenGl, _) | GlRequest::GlThenGles { .. } => { // GLX should be preferred over EGL, otherwise crashes may occur // on X11 – issue #314 if let Some(ref glx) = display.glx { - Prototype::Glx(try!(GlxContext::new(glx.clone(), &display.xlib, &builder_clone.pf_reqs, &builder_clone_opengl_glx, display.display))) + Prototype::Glx(try!(GlxContext::new(glx.clone(), &display.xlib, pf_reqs, &builder_clone_opengl_glx, display.display))) } else if let Some(ref egl) = display.egl { - Prototype::Egl(try!(EglContext::new(egl.clone(), &builder_clone.pf_reqs, &builder_clone_opengl_egl, egl::NativeDisplay::X11(Some(display.display as *const _))))) + Prototype::Egl(try!(EglContext::new(egl.clone(), pf_reqs, &builder_clone_opengl_egl, egl::NativeDisplay::X11(Some(display.display as *const _))))) } else { return Err(CreationError::NotSupported); } }, GlRequest::Specific(Api::OpenGlEs, _) => { if let Some(ref egl) = display.egl { - Prototype::Egl(try!(EglContext::new(egl.clone(), &builder_clone.pf_reqs, &builder_clone_opengl_egl, egl::NativeDisplay::X11(Some(display.display as *const _))))) + Prototype::Egl(try!(EglContext::new(egl.clone(), pf_reqs, &builder_clone_opengl_egl, egl::NativeDisplay::X11(Some(display.display as *const _))))) } else { return Err(CreationError::NotSupported); } @@ -417,7 +422,7 @@ impl Window { ffi::KeyReleaseMask | ffi::ButtonPressMask | ffi::ButtonReleaseMask | ffi::KeymapStateMask; swa.border_pixel = 0; - if builder.window.transparent { + if window_attrs.transparent { swa.background_pixel = 0; } swa.override_redirect = 0; @@ -426,7 +431,7 @@ impl Window { let mut window_attributes = ffi::CWBorderPixel | ffi::CWColormap | ffi::CWEventMask; - if builder.window.transparent { + if window_attrs.transparent { window_attributes |= ffi::CWBackPixel; } @@ -450,7 +455,7 @@ impl Window { }; // set visibility - if builder.window.visible { + if window_attrs.visible { unsafe { (display.xlib.XMapRaised)(display.display, window); (display.xlib.XFlush)(display.display); @@ -463,7 +468,7 @@ impl Window { (display.xlib.XInternAtom)(display.display, delete_window, 0) ); (display.xlib.XSetWMProtocols)(display.display, window, &mut wm_delete_window, 1); - with_c_str(&*builder.window.title, |title| {; + with_c_str(&*window_attrs.title, |title| {; (display.xlib.XStoreName)(display.display, window, title); }); (display.xlib.XFlush)(display.display); @@ -511,7 +516,7 @@ impl Window { // Set ICCCM WM_CLASS property based on initial window title unsafe { - with_c_str(&*builder.window.title, |c_name| { + with_c_str(&*window_attrs.title, |c_name| { let hint = (display.xlib.XAllocClassHint)(); (*hint).res_name = c_name as *mut libc::c_char; (*hint).res_class = c_name as *mut libc::c_char; @@ -520,7 +525,7 @@ impl Window { }); } - let is_fullscreen = builder.window.monitor.is_some(); + let is_fullscreen = window_attrs.monitor.is_some(); // finish creating the OpenGL context let context = match context { diff --git a/src/platform/linux/api_dispatch.rs b/src/platform/linux/api_dispatch.rs index f25bda9..0fae6a0 100644 --- a/src/platform/linux/api_dispatch.rs +++ b/src/platform/linux/api_dispatch.rs @@ -162,9 +162,29 @@ impl<'a> Iterator for WaitEventsIterator<'a> { impl Window { pub fn new(builder: BuilderAttribs) -> Result { + let window = builder.window; + let pf_reqs = builder.pf_reqs; + let opengl = builder.opengl; + 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.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.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()))) } } -- cgit v1.2.3