aboutsummaryrefslogtreecommitdiffstats
path: root/src/api/caca/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/api/caca/mod.rs')
-rw-r--r--src/api/caca/mod.rs83
1 files changed, 48 insertions, 35 deletions
diff --git a/src/api/caca/mod.rs b/src/api/caca/mod.rs
index d8199dd..1e3840c 100644
--- a/src/api/caca/mod.rs
+++ b/src/api/caca/mod.rs
@@ -1,11 +1,13 @@
-#![cfg(all(any(target_os = "linux", target_os = "freebsd"), feature="headless"))]
+#![cfg(any(target_os = "linux", target_os = "freebsd"))]
use libc;
-use api::osmesa::OsMesaContext;
+use api::osmesa::{OsMesaContext, OsMesaCreationError};
+use Api;
use BuilderAttribs;
use CreationError;
use Event;
+use GlContext;
use PixelFormat;
use CursorState;
use MouseCursor;
@@ -81,7 +83,12 @@ impl<'a> Iterator for WaitEventsIterator<'a> {
impl Window {
pub fn new(builder: BuilderAttribs) -> Result<Window, CreationError> {
- let opengl = try!(OsMesaContext::new(builder));
+ let opengl = match OsMesaContext::new(builder) {
+ Err(OsMesaCreationError::NotSupported) => return Err(CreationError::NotSupported),
+ Err(OsMesaCreationError::CreationError(e)) => return Err(e),
+ Ok(c) => c
+ };
+
let opengl_dimensions = opengl.get_dimensions();
let libcaca = match ffi::LibCaca::open(&Path::new("libcaca.so.0")) {
@@ -169,34 +176,6 @@ impl Window {
}
}
- pub unsafe fn make_current(&self) {
- self.opengl.make_current()
- }
-
- pub fn is_current(&self) -> bool {
- self.opengl.is_current()
- }
-
- pub fn get_proc_address(&self, addr: &str) -> *const () {
- self.opengl.get_proc_address(addr) as *const _
- }
-
- pub fn swap_buffers(&self) {
- unsafe {
- let canvas = (self.libcaca.caca_get_canvas)(self.display);
- let width = (self.libcaca.caca_get_canvas_width)(canvas);
- let height = (self.libcaca.caca_get_canvas_height)(canvas);
-
- let buffer = self.opengl.get_framebuffer().chunks(self.opengl.get_dimensions().0 as usize)
- .flat_map(|i| i.iter().cloned()).rev().collect::<Vec<u32>>();
-
- (self.libcaca.caca_dither_bitmap)(canvas, 0, 0, width as libc::c_int,
- height as libc::c_int, self.dither,
- buffer.as_ptr() as *const _);
- (self.libcaca.caca_refresh_display)(self.display);
- };
- }
-
pub fn platform_display(&self) -> *mut libc::c_void {
unimplemented!()
}
@@ -205,10 +184,6 @@ impl Window {
unimplemented!()
}
- pub fn get_api(&self) -> ::Api {
- self.opengl.get_api()
- }
-
pub fn get_pixel_format(&self) -> PixelFormat {
unimplemented!();
}
@@ -232,6 +207,44 @@ impl Window {
}
}
+impl GlContext for Window {
+ unsafe fn make_current(&self) {
+ self.opengl.make_current()
+ }
+
+ fn is_current(&self) -> bool {
+ self.opengl.is_current()
+ }
+
+ fn get_proc_address(&self, addr: &str) -> *const libc::c_void {
+ self.opengl.get_proc_address(addr)
+ }
+
+ fn swap_buffers(&self) {
+ unsafe {
+ let canvas = (self.libcaca.caca_get_canvas)(self.display);
+ let width = (self.libcaca.caca_get_canvas_width)(canvas);
+ let height = (self.libcaca.caca_get_canvas_height)(canvas);
+
+ let buffer = self.opengl.get_framebuffer().chunks(self.opengl.get_dimensions().0 as usize)
+ .flat_map(|i| i.iter().cloned()).rev().collect::<Vec<u32>>();
+
+ (self.libcaca.caca_dither_bitmap)(canvas, 0, 0, width as libc::c_int,
+ height as libc::c_int, self.dither,
+ buffer.as_ptr() as *const _);
+ (self.libcaca.caca_refresh_display)(self.display);
+ };
+ }
+
+ fn get_api(&self) -> Api {
+ self.opengl.get_api()
+ }
+
+ fn get_pixel_format(&self) -> PixelFormat {
+ self.opengl.get_pixel_format()
+ }
+}
+
impl Drop for Window {
fn drop(&mut self) {
unsafe {