diff options
Diffstat (limited to 'src/api')
-rw-r--r-- | src/api/android/mod.rs | 22 | ||||
-rw-r--r-- | src/api/caca/mod.rs | 14 | ||||
-rw-r--r-- | src/api/cocoa/headless.rs | 8 | ||||
-rw-r--r-- | src/api/cocoa/mod.rs | 17 | ||||
-rw-r--r-- | src/api/osmesa/mod.rs | 12 | ||||
-rw-r--r-- | src/api/win32/init.rs | 1 | ||||
-rw-r--r-- | src/api/win32/mod.rs | 1 |
7 files changed, 49 insertions, 26 deletions
diff --git a/src/api/android/mod.rs b/src/api/android/mod.rs index ecea9b3..be5a79f 100644 --- a/src/api/android/mod.rs +++ b/src/api/android/mod.rs @@ -14,12 +14,14 @@ use events::MouseButton; use std::collections::VecDeque; use Api; -use BuilderAttribs; use ContextError; use CursorState; +use GlAttributes; use GlContext; use GlRequest; use PixelFormat; +use PixelFormatRequirements; +use WindowAttributes; use native_monitor::NativeMonitorId; use api::egl; @@ -104,15 +106,19 @@ impl<'a> Iterator for WaitEventsIterator<'a> { } impl Window { - pub fn new(builder: BuilderAttribs) -> Result<Window, CreationError> { + pub fn new(win_attribs: &WindowAttributes, pf_reqs: &PixelFormatRequirements, + opengl: &GlAttributes<&Window>) -> Result<Window, CreationError> + { use std::{mem, ptr}; + let opengl = opengl.clone().map_sharing(|w| &w.context); + let native_window = unsafe { android_glue::get_native_window() }; if native_window.is_null() { return Err(OsError(format!("Android's native window is null"))); } - let context = try!(EglContext::new(egl::ffi::egl::Egl, &builder.pf_reqs, &builder.opengl, + let context = try!(EglContext::new(egl::ffi::egl::Egl, pf_reqs, &opengl, egl::NativeDisplay::Android) .and_then(|p| p.finish(native_window as *const _))); @@ -255,9 +261,13 @@ 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, egl::NativeDisplay::Android)); - let context = try!(context.finish_pbuffer(builder.window.dimensions.unwrap_or((800, 600)))); // TODO: + pub fn new(dimensions: (u32, u32), pf_reqs: &PixelFormatRequirements, + opengl: &GlAttributes<&HeadlessContext>) -> Result<HeadlessContext, CreationError> + { + let opengl = opengl.clone().map_sharing(|c| &c.0); + let context = try!(EglContext::new(egl::ffi::egl::Egl, pf_reqs, &opengl, + egl::NativeDisplay::Android)); + let context = try!(context.finish_pbuffer(dimensions)); // TODO: Ok(HeadlessContext(context)) } } diff --git a/src/api/caca/mod.rs b/src/api/caca/mod.rs index 3b4018e..c1a19c7 100644 --- a/src/api/caca/mod.rs +++ b/src/api/caca/mod.rs @@ -5,14 +5,16 @@ use libc; use api::osmesa::{OsMesaContext, OsMesaCreationError}; use Api; -use BuilderAttribs; use ContextError; use CreationError; use Event; +use GlAttributes; use GlContext; use PixelFormat; +use PixelFormatRequirements; use CursorState; use MouseCursor; +use WindowAttributes; use std::collections::VecDeque; use std::path::Path; @@ -84,8 +86,14 @@ impl<'a> Iterator for WaitEventsIterator<'a> { } impl Window { - pub fn new(builder: BuilderAttribs) -> Result<Window, CreationError> { - let opengl = match OsMesaContext::new(builder) { + pub fn new(window: &WindowAttributes, pf_reqs: &PixelFormatRequirements, + opengl: &GlAttributes<&Window>) -> Result<Window, CreationError> + { + let opengl = opengl.clone().map_sharing(|w| &w.opengl); + + let opengl = match OsMesaContext::new(window.dimensions.unwrap_or((800, 600)), pf_reqs, + &opengl) + { Err(OsMesaCreationError::NotSupported) => return Err(CreationError::NotSupported), Err(OsMesaCreationError::CreationError(e)) => return Err(e), Ok(c) => c diff --git a/src/api/cocoa/headless.rs b/src/api/cocoa/headless.rs index ad1a464..f9bbffd 100644 --- a/src/api/cocoa/headless.rs +++ b/src/api/cocoa/headless.rs @@ -1,8 +1,9 @@ use ContextError; use CreationError; use CreationError::OsError; -use BuilderAttribs; +use GlAttributes; use GlContext; +use PixelFormatRequirements; use libc; use std::ptr; @@ -27,8 +28,9 @@ pub struct HeadlessContext { } impl HeadlessContext { - pub fn new(builder: BuilderAttribs) -> Result<HeadlessContext, CreationError> { - let (width, height) = builder.window.dimensions.unwrap_or((1024, 768)); + pub fn new((width, height): (u32, u32), pf_reqs: &PixelFormatRequirements, + opengl: &GlAttributes<&HeadlessContext>) -> Result<HeadlessContext, CreationError> + { let context = unsafe { let attributes = [ NSOpenGLPFAAccelerated as u32, diff --git a/src/api/cocoa/mod.rs b/src/api/cocoa/mod.rs index 35b7046..539545c 100644 --- a/src/api/cocoa/mod.rs +++ b/src/api/cocoa/mod.rs @@ -7,7 +7,6 @@ use CreationError::OsError; use libc; use Api; -use BuilderAttribs; use ContextError; use GlAttributes; use GlContext; @@ -269,12 +268,14 @@ impl<'a> Iterator for WaitEventsIterator<'a> { impl Window { #[cfg(feature = "window")] - pub fn new(builder: BuilderAttribs) -> Result<Window, CreationError> { - if builder.opengl.sharing.is_some() { + pub fn new(win_attribs: &WindowAttributes, pf_reqs: &PixelFormatRequirements, + opengl: &GlAttributes<&Window>) -> Result<Window, CreationError> + { + if opengl.sharing.is_some() { unimplemented!() } - match builder.opengl.robustness { + match opengl.robustness { Robustness::RobustNoResetNotification | Robustness::RobustLoseContextOnReset => { return Err(CreationError::RobustnessNotSupported); }, @@ -286,7 +287,7 @@ impl Window { None => { return Err(OsError(format!("Couldn't create NSApplication"))); }, }; - let window = match Window::create_window(&builder.window) + let window = match Window::create_window(win_attribs) { Some(window) => window, None => { return Err(OsError(format!("Couldn't create NSWindow"))); }, @@ -298,13 +299,13 @@ impl Window { // TODO: perhaps we should return error from create_context so we can // determine the cause of failure and possibly recover? - let (context, pf) = match Window::create_context(*view, &builder.pf_reqs, &builder.opengl) { + let (context, pf) = match Window::create_context(*view, pf_reqs, opengl) { Ok((context, pf)) => (context, pf), Err(e) => { return Err(OsError(format!("Couldn't create OpenGL context: {}", e))); }, }; unsafe { - if builder.window.transparent { + if win_attribs.transparent { let clear_col = { let cls = Class::get("NSColor").unwrap(); @@ -320,7 +321,7 @@ impl Window { } app.activateIgnoringOtherApps_(YES); - if builder.window.visible { + if win_attribs.visible { window.makeKeyAndOrderFront_(nil); } else { window.makeKeyWindow(); diff --git a/src/api/osmesa/mod.rs b/src/api/osmesa/mod.rs index 2debc7e..ca34e93 100644 --- a/src/api/osmesa/mod.rs +++ b/src/api/osmesa/mod.rs @@ -3,11 +3,12 @@ extern crate osmesa_sys; use Api; -use BuilderAttribs; use ContextError; use CreationError; +use GlAttributes; use GlContext; use PixelFormat; +use PixelFormatRequirements; use Robustness; use libc; use std::{mem, ptr}; @@ -32,20 +33,23 @@ impl From<CreationError> for OsMesaCreationError { } impl OsMesaContext { - pub fn new(builder: BuilderAttribs) -> Result<OsMesaContext, OsMesaCreationError> { + pub fn new(dimensions: (u32, u32), pf_reqs: &PixelFormatRequirements, + opengl: &GlAttributes<&OsMesaContext>) -> Result<OsMesaContext, OsMesaCreationError> + { if let Err(_) = osmesa_sys::OsMesa::try_loading() { return Err(OsMesaCreationError::NotSupported); } - let dimensions = builder.window.dimensions.unwrap(); + if opengl.sharing.is_some() { unimplemented!() } // TODO: proper error - match builder.opengl.robustness { + match opengl.robustness { Robustness::RobustNoResetNotification | Robustness::RobustLoseContextOnReset => { return Err(CreationError::RobustnessNotSupported.into()); }, _ => () } + // TODO: use `pf_reqs` for the format // TODO: check OpenGL version and return `OpenGlVersionNotSupported` if necessary Ok(OsMesaContext { diff --git a/src/api/win32/init.rs b/src/api/win32/init.rs index 5628a98..7c7eb83 100644 --- a/src/api/win32/init.rs +++ b/src/api/win32/init.rs @@ -11,7 +11,6 @@ use super::WindowWrapper; use super::Context; use Api; -use BuilderAttribs; use CreationError; use CreationError::OsError; use CursorState; diff --git a/src/api/win32/mod.rs b/src/api/win32/mod.rs index eb31873..f580950 100644 --- a/src/api/win32/mod.rs +++ b/src/api/win32/mod.rs @@ -19,7 +19,6 @@ use GlContext; use Api; use PixelFormat; use PixelFormatRequirements; -use BuilderAttribs; use WindowAttributes; pub use self::monitor::{MonitorID, get_available_monitors, get_primary_monitor}; |