diff options
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | Cargo.toml | 8 | ||||
-rw-r--r-- | src/api/android/mod.rs | 39 | ||||
-rw-r--r-- | src/api/caca/mod.rs | 34 | ||||
-rw-r--r-- | src/api/cocoa/headless.rs | 6 | ||||
-rw-r--r-- | src/api/cocoa/mod.rs | 18 | ||||
-rw-r--r-- | src/api/cocoa/monitor.rs | 2 | ||||
-rw-r--r-- | src/api/egl/mod.rs | 5 | ||||
-rw-r--r-- | src/api/emscripten/mod.rs | 29 | ||||
-rw-r--r-- | src/api/glx/mod.rs | 5 | ||||
-rw-r--r-- | src/api/ios/mod.rs | 34 | ||||
-rw-r--r-- | src/api/osmesa/mod.rs | 10 | ||||
-rw-r--r-- | src/api/wayland/mod.rs | 31 | ||||
-rw-r--r-- | src/api/wgl/mod.rs | 8 | ||||
-rw-r--r-- | src/api/win32/callback.rs | 6 | ||||
-rw-r--r-- | src/api/win32/mod.rs | 42 | ||||
-rw-r--r-- | src/api/win32/monitor.rs | 5 | ||||
-rw-r--r-- | src/api/x11/monitor.rs | 2 | ||||
-rw-r--r-- | src/api/x11/window.rs | 18 | ||||
-rw-r--r-- | src/api/x11/xdisplay.rs | 4 | ||||
-rw-r--r-- | src/headless.rs | 15 | ||||
-rw-r--r-- | src/lib.rs | 4 | ||||
-rw-r--r-- | src/platform/emscripten/mod.rs | 7 | ||||
-rw-r--r-- | src/platform/linux/api_dispatch.rs | 33 | ||||
-rw-r--r-- | src/platform/windows/mod.rs | 9 | ||||
-rw-r--r-- | src/window.rs | 46 |
26 files changed, 411 insertions, 11 deletions
@@ -1,2 +1,4 @@ Cargo.lock target/ +*~ +#*# @@ -56,7 +56,7 @@ core-graphics = "0" winapi = "0.2" shell32-sys = "0.1" gdi32-sys = "0.1" -user32-sys = "~0.1.1" +user32-sys = "~0.1.2" kernel32-sys = "0.1" dwmapi-sys = "0.1" @@ -64,7 +64,7 @@ dwmapi-sys = "0.1" winapi = "0.2" shell32-sys = "0.1" gdi32-sys = "0.1" -user32-sys = "~0.1.1" +user32-sys = "~0.1.2" kernel32-sys = "0.1" dwmapi-sys = "0.1" @@ -72,7 +72,7 @@ dwmapi-sys = "0.1" winapi = "0.2" shell32-sys = "0.1" gdi32-sys = "0.1" -user32-sys = "~0.1.1" +user32-sys = "~0.1.2" kernel32-sys = "0.1" dwmapi-sys = "0.1" @@ -80,7 +80,7 @@ dwmapi-sys = "0.1" winapi = "0.2" shell32-sys = "0.1" gdi32-sys = "0.1" -user32-sys = "~0.1.1" +user32-sys = "~0.1.2" kernel32-sys = "0.1" dwmapi-sys = "0.1" diff --git a/src/api/android/mod.rs b/src/api/android/mod.rs index 12d0bea..eb49037 100644 --- a/src/api/android/mod.rs +++ b/src/api/android/mod.rs @@ -36,25 +36,30 @@ pub struct MonitorID; mod ffi; +#[inline] pub fn get_available_monitors() -> VecDeque<MonitorID> { let mut rb = VecDeque::new(); rb.push_back(MonitorID); rb } +#[inline] pub fn get_primary_monitor() -> MonitorID { MonitorID } impl MonitorID { + #[inline] pub fn get_name(&self) -> Option<String> { Some("Primary".to_string()) } + #[inline] pub fn get_native_identifier(&self) -> NativeMonitorId { NativeMonitorId::Unavailable } + #[inline] pub fn get_dimensions(&self) -> (u32, u32) { unimplemented!() } @@ -95,6 +100,7 @@ pub struct WaitEventsIterator<'a> { impl<'a> Iterator for WaitEventsIterator<'a> { type Item = Event; + #[inline] fn next(&mut self) -> Option<Event> { loop { // calling poll_events() @@ -134,26 +140,33 @@ impl Window { }) } + #[inline] pub fn is_closed(&self) -> bool { false } + #[inline] pub fn set_title(&self, _: &str) { } + #[inline] pub fn show(&self) { } + #[inline] pub fn hide(&self) { } + #[inline] pub fn get_position(&self) -> Option<(i32, i32)> { None } + #[inline] pub fn set_position(&self, _x: i32, _y: i32) { } + #[inline] pub fn get_inner_size(&self) -> Option<(u32, u32)> { let native_window = unsafe { android_glue::get_native_window() }; @@ -167,55 +180,68 @@ impl Window { } } + #[inline] pub fn get_outer_size(&self) -> Option<(u32, u32)> { self.get_inner_size() } + #[inline] pub fn set_inner_size(&self, _x: u32, _y: u32) { } + #[inline] pub fn create_window_proxy(&self) -> WindowProxy { WindowProxy } + #[inline] pub fn poll_events(&self) -> PollEventsIterator { PollEventsIterator { window: self } } + #[inline] pub fn wait_events(&self) -> WaitEventsIterator { WaitEventsIterator { window: self } } + #[inline] pub fn platform_display(&self) -> *mut libc::c_void { unimplemented!(); } + #[inline] pub fn platform_window(&self) -> *mut libc::c_void { unimplemented!() } + #[inline] pub fn get_pixel_format(&self) -> PixelFormat { unimplemented!(); } + #[inline] pub fn set_window_resize_callback(&mut self, _: Option<fn(u32, u32)>) { } + #[inline] pub fn set_cursor(&self, _: MouseCursor) { } + #[inline] pub fn set_cursor_state(&self, state: CursorState) -> Result<(), String> { Ok(()) } + #[inline] pub fn hidpi_factor(&self) -> f32 { 1.0 } + #[inline] pub fn set_cursor_position(&self, x: i32, y: i32) -> Result<(), ()> { unimplemented!(); } @@ -225,26 +251,32 @@ unsafe impl Send for Window {} unsafe impl Sync for Window {} impl GlContext for Window { + #[inline] unsafe fn make_current(&self) -> Result<(), ContextError> { self.context.make_current() } + #[inline] fn is_current(&self) -> bool { self.context.is_current() } + #[inline] fn get_proc_address(&self, addr: &str) -> *const libc::c_void { self.context.get_proc_address(addr) } + #[inline] fn swap_buffers(&self) -> Result<(), ContextError> { self.context.swap_buffers() } + #[inline] fn get_api(&self) -> Api { self.context.get_api() } + #[inline] fn get_pixel_format(&self) -> PixelFormat { self.context.get_pixel_format() } @@ -255,6 +287,7 @@ impl GlContext for Window { pub struct WindowProxy; impl WindowProxy { + #[inline] pub fn wakeup_event_loop(&self) { unimplemented!() } @@ -279,26 +312,32 @@ unsafe impl Send for HeadlessContext {} unsafe impl Sync for HeadlessContext {} impl GlContext for HeadlessContext { + #[inline] unsafe fn make_current(&self) -> Result<(), ContextError> { self.0.make_current() } + #[inline] fn is_current(&self) -> bool { self.0.is_current() } + #[inline] fn get_proc_address(&self, addr: &str) -> *const libc::c_void { self.0.get_proc_address(addr) } + #[inline] fn swap_buffers(&self) -> Result<(), ContextError> { self.0.swap_buffers() } + #[inline] fn get_api(&self) -> Api { self.0.get_api() } + #[inline] fn get_pixel_format(&self) -> PixelFormat { self.0.get_pixel_format() } diff --git a/src/api/caca/mod.rs b/src/api/caca/mod.rs index c1a19c7..1c32b4c 100644 --- a/src/api/caca/mod.rs +++ b/src/api/caca/mod.rs @@ -33,6 +33,7 @@ pub struct Window { pub struct WindowProxy; impl WindowProxy { + #[inline] pub fn wakeup_event_loop(&self) { unimplemented!() } @@ -40,22 +41,27 @@ impl WindowProxy { pub struct MonitorID; +#[inline] pub fn get_available_monitors() -> VecDeque<MonitorID> { VecDeque::new() } +#[inline] pub fn get_primary_monitor() -> MonitorID { MonitorID } impl MonitorID { + #[inline] pub fn get_name(&self) -> Option<String> { unimplemented!(); } + #[inline] pub fn get_native_identifier(&self) -> ::native_monitor::NativeMonitorId { ::native_monitor::NativeMonitorId::Unavailable } + #[inline] pub fn get_dimensions(&self) -> (u32, u32) { unimplemented!(); } @@ -68,6 +74,7 @@ pub struct PollEventsIterator<'a> { impl<'a> Iterator for PollEventsIterator<'a> { type Item = Event; + #[inline] fn next(&mut self) -> Option<Event> { None } @@ -80,6 +87,7 @@ pub struct WaitEventsIterator<'a> { impl<'a> Iterator for WaitEventsIterator<'a> { type Item = Event; + #[inline] fn next(&mut self) -> Option<Event> { loop {} } @@ -138,94 +146,117 @@ impl Window { }) } + #[inline] pub fn set_title(&self, title: &str) { } + #[inline] pub fn show(&self) { } + #[inline] pub fn hide(&self) { } + #[inline] pub fn get_position(&self) -> Option<(i32, i32)> { unimplemented!() } + #[inline] pub fn set_position(&self, x: i32, y: i32) { } + #[inline] pub fn get_inner_size(&self) -> Option<(u32, u32)> { Some(self.opengl.get_dimensions()) } + #[inline] pub fn get_outer_size(&self) -> Option<(u32, u32)> { self.get_inner_size() } + #[inline] pub fn set_inner_size(&self, _x: u32, _y: u32) { unimplemented!() } + #[inline] pub fn create_window_proxy(&self) -> WindowProxy { unimplemented!() } + #[inline] pub fn poll_events(&self) -> PollEventsIterator { PollEventsIterator { window: self } } + #[inline] pub fn wait_events(&self) -> WaitEventsIterator { WaitEventsIterator { window: self } } + #[inline] pub fn platform_display(&self) -> *mut libc::c_void { unimplemented!() } + #[inline] pub fn platform_window(&self) -> *mut libc::c_void { unimplemented!() } + #[inline] pub fn get_pixel_format(&self) -> PixelFormat { unimplemented!(); } + #[inline] pub fn set_window_resize_callback(&mut self, _: Option<fn(u32, u32)>) { } + #[inline] pub fn set_cursor(&self, cursor: MouseCursor) { } + #[inline] pub fn set_cursor_state(&self, state: CursorState) -> Result<(), String> { Ok(()) } + #[inline] pub fn hidpi_factor(&self) -> f32 { 1.0 } + #[inline] pub fn set_cursor_position(&self, x: i32, y: i32) -> Result<(), ()> { Ok(()) } } impl GlContext for Window { + #[inline] unsafe fn make_current(&self) -> Result<(), ContextError> { self.opengl.make_current() } + #[inline] fn is_current(&self) -> bool { self.opengl.is_current() } + #[inline] fn get_proc_address(&self, addr: &str) -> *const libc::c_void { self.opengl.get_proc_address(addr) } + #[inline] fn swap_buffers(&self) -> Result<(), ContextError> { unsafe { let canvas = (self.libcaca.caca_get_canvas)(self.display); @@ -244,16 +275,19 @@ impl GlContext for Window { Ok(()) } + #[inline] fn get_api(&self) -> Api { self.opengl.get_api() } + #[inline] fn get_pixel_format(&self) -> PixelFormat { self.opengl.get_pixel_format() } } impl Drop for Window { + #[inline] fn drop(&mut self) { unsafe { (self.libcaca.caca_free_dither)(self.dither); diff --git a/src/api/cocoa/headless.rs b/src/api/cocoa/headless.rs index f9bbffd..eb1a06f 100644 --- a/src/api/cocoa/headless.rs +++ b/src/api/cocoa/headless.rs @@ -85,10 +85,12 @@ impl GlContext for HeadlessContext { Ok(()) } + #[inline] fn is_current(&self) -> bool { unimplemented!() } + #[inline] fn get_proc_address(&self, _addr: &str) -> *const libc::c_void { let symbol_name: CFString = _addr.parse().unwrap(); let framework_name: CFString = "com.apple.opengl".parse().unwrap(); @@ -101,14 +103,17 @@ impl GlContext for HeadlessContext { symbol as *const libc::c_void } + #[inline] fn swap_buffers(&self) -> Result<(), ContextError> { Ok(()) } + #[inline] fn get_api(&self) -> ::Api { ::Api::OpenGl } + #[inline] fn get_pixel_format(&self) -> PixelFormat { unimplemented!(); } @@ -118,6 +123,7 @@ unsafe impl Send for HeadlessContext {} unsafe impl Sync for HeadlessContext {} impl Drop for HeadlessContext { + #[inline] fn drop(&mut self) { unsafe { gl::DeleteTextures(1, &texture); diff --git a/src/api/cocoa/mod.rs b/src/api/cocoa/mod.rs index f602f1f..78d0f52 100644 --- a/src/api/cocoa/mod.rs +++ b/src/api/cocoa/mod.rs @@ -584,10 +584,12 @@ impl Window { } } + #[inline] pub fn show(&self) { unsafe { NSWindow::makeKeyAndOrderFront_(*self.window, nil); } } + #[inline] pub fn hide(&self) { unsafe { NSWindow::orderOut_(*self.window, nil); } } @@ -622,6 +624,7 @@ impl Window { } } + #[inline] pub fn get_inner_size(&self) -> Option<(u32, u32)> { unsafe { let view_frame = NSView::frame(*self.view); @@ -629,6 +632,7 @@ impl Window { } } + #[inline] pub fn get_outer_size(&self) -> Option<(u32, u32)> { unsafe { let window_frame = NSWindow::frame(*self.window); @@ -636,22 +640,26 @@ impl Window { } } + #[inline] pub fn set_inner_size(&self, width: u32, height: u32) { unsafe { NSWindow::setContentSize_(*self.window, NSSize::new(width as f64, height as f64)); } } + #[inline] pub fn create_window_proxy(&self) -> WindowProxy { WindowProxy } + #[inline] pub fn poll_events(&self) -> PollEventsIterator { PollEventsIterator { window: self } } + #[inline] pub fn wait_events(&self) -> WaitEventsIterator { WaitEventsIterator { window: self @@ -668,14 +676,17 @@ impl Window { return None; } + #[inline] pub fn platform_display(&self) -> *mut libc::c_void { unimplemented!() } + #[inline] pub fn platform_window(&self) -> *mut libc::c_void { unimplemented!() } + #[inline] pub fn set_window_resize_callback(&mut self, callback: Option<fn(u32, u32)>) { self.delegate.state.resize_handler = callback; } @@ -739,24 +750,28 @@ impl Window { } } + #[inline] pub fn hidpi_factor(&self) -> f32 { unsafe { NSWindow::backingScaleFactor(*self.window) as f32 } } + #[inline] pub fn set_cursor_position(&self, x: i32, y: i32) -> Result<(), ()> { unimplemented!(); } } impl GlContext for Window { + #[inline] unsafe fn make_current(&self) -> Result<(), ContextError> { let _: () = msg_send![*self.context, update]; self.context.makeCurrentContext(); Ok(()) } + #[inline] fn is_current(&self) -> bool { unsafe { let current = NSOpenGLContext::currentContext(nil); @@ -781,15 +796,18 @@ impl GlContext for Window { symbol as *const _ } + #[inline] fn swap_buffers(&self) -> Result<(), ContextError> { unsafe { self.context.flushBuffer(); } Ok(()) } + #[inline] fn get_api(&self) -> ::Api { ::Api::OpenGl } + #[inline] fn get_pixel_format(&self) -> PixelFormat { self.pixel_format.clone() } diff --git a/src/api/cocoa/monitor.rs b/src/api/cocoa/monitor.rs index 138bbcd..600f7e9 100644 --- a/src/api/cocoa/monitor.rs +++ b/src/api/cocoa/monitor.rs @@ -21,6 +21,7 @@ pub fn get_available_monitors() -> VecDeque<MonitorID> { monitors } +#[inline] pub fn get_primary_monitor() -> MonitorID { let id = unsafe { MonitorID(display::CGMainDisplayID()) @@ -37,6 +38,7 @@ impl MonitorID { Some(format!("Monitor #{}", screen_num)) } + #[inline] pub fn get_native_identifier(&self) -> NativeMonitorId { let MonitorID(display_id) = *self; NativeMonitorId::Numeric(display_id) diff --git a/src/api/egl/mod.rs b/src/api/egl/mod.rs index 56b709d..0c0ec1f 100644 --- a/src/api/egl/mod.rs +++ b/src/api/egl/mod.rs @@ -44,6 +44,7 @@ pub struct Context { } #[cfg(target_os = "android")] +#[inline] fn get_native_display(egl: &ffi::egl::Egl, native_display: NativeDisplay) -> *const libc::c_void { unsafe { egl.GetDisplay(ffi::egl::DEFAULT_DISPLAY as *mut _) } @@ -278,6 +279,7 @@ impl GlContext for Context { } } + #[inline] fn is_current(&self) -> bool { unsafe { self.egl.GetCurrentContext() == self.context } } @@ -290,6 +292,7 @@ impl GlContext for Context { } } + #[inline] fn swap_buffers(&self) -> Result<(), ContextError> { let ret = unsafe { self.egl.SwapBuffers(self.display, self.surface) @@ -306,10 +309,12 @@ impl GlContext for Context { } } + #[inline] fn get_api(&self) -> Api { self.api } + #[inline] fn get_pixel_format(&self) -> PixelFormat { self.pixel_format.clone() } diff --git a/src/api/emscripten/mod.rs b/src/api/emscripten/mod.rs index e6f51e3..0913623 100644 --- a/src/api/emscripten/mod.rs +++ b/src/api/emscripten/mod.rs @@ -23,6 +23,7 @@ pub struct PollEventsIterator<'a> { impl<'a> Iterator for PollEventsIterator<'a> { type Item = Event; + #[inline] fn next(&mut self) -> Option<Event> { None } @@ -35,6 +36,7 @@ pub struct WaitEventsIterator<'a> { impl<'a> Iterator for WaitEventsIterator<'a> { type Item = Event; + #[inline] fn next(&mut self) -> Option<Event> { None } @@ -44,6 +46,7 @@ impl<'a> Iterator for WaitEventsIterator<'a> { pub struct WindowProxy; impl WindowProxy { + #[inline] pub fn wakeup_event_loop(&self) { unimplemented!() } @@ -51,21 +54,25 @@ impl WindowProxy { pub struct MonitorID; +#[inline] pub fn get_available_monitors() -> VecDeque<MonitorID> { let mut list = VecDeque::new(); list.push_back(MonitorID); list } +#[inline] pub fn get_primary_monitor() -> MonitorID { MonitorID } impl MonitorID { + #[inline] pub fn get_name(&self) -> Option<String> { - Some("Canvas".to_string()) + Some("Canvas".to_owned()) } + #[inline] pub fn get_dimensions(&self) -> (u32, u32) { unimplemented!() } @@ -109,13 +116,16 @@ impl Window { }) } + #[inline] pub fn set_title(&self, _title: &str) { } + #[inline] pub fn get_position(&self) -> Option<(i32, i32)> { Some((0, 0)) } + #[inline] pub fn set_position(&self, _: i32, _: i32) { } @@ -135,10 +145,12 @@ impl Window { } } + #[inline] pub fn get_outer_size(&self) -> Option<(u32, u32)> { self.get_inner_size() } + #[inline] pub fn set_inner_size(&self, width: u32, height: u32) { unsafe { use std::ptr; @@ -147,52 +159,64 @@ impl Window { } } + #[inline] pub fn poll_events(&self) -> PollEventsIterator { PollEventsIterator { window: self, } } + #[inline] pub fn wait_events(&self) -> WaitEventsIterator { WaitEventsIterator { window: self, } } + #[inline] pub fn create_window_proxy(&self) -> WindowProxy { WindowProxy } + #[inline] pub fn show(&self) {} + #[inline] pub fn hide(&self) {} + #[inline] pub fn platform_display(&self) -> *mut libc::c_void { unimplemented!() } + #[inline] pub fn platform_window(&self) -> *mut libc::c_void { unimplemented!() } + #[inline] pub fn set_window_resize_callback(&mut self, _: Option<fn(u32, u32)>) { } + #[inline] pub fn set_cursor(&self, _cursor: MouseCursor) { unimplemented!() } + #[inline] pub fn hidpi_factor(&self) -> f32 { 1.0 } } impl GlContext for Window { + #[inline] unsafe fn make_current(&self) -> Result<(), ContextError> { // TOOD: check if == EMSCRIPTEN_RESULT ffi::emscripten_webgl_make_context_current(self.context); Ok(()) } + #[inline] fn is_current(&self) -> bool { true // FIXME: } @@ -206,15 +230,18 @@ impl GlContext for Window { } } + #[inline] fn swap_buffers(&self) -> Result<(), ContextError> { unsafe { ffi::emscripten_sleep(1); } // FIXME: Ok(()) } + #[inline] fn get_api(&self) -> Api { Api::WebGl } + #[inline] fn get_pixel_format(&self) -> PixelFormat { unimplemented!(); } diff --git a/src/api/glx/mod.rs b/src/api/glx/mod.rs index 7f54760..43bb1d7 100644 --- a/src/api/glx/mod.rs +++ b/src/api/glx/mod.rs @@ -77,6 +77,7 @@ impl GlContext for Context { Ok(()) } + #[inline] fn is_current(&self) -> bool { unsafe { self.glx.GetCurrentContext() == self.context } } @@ -89,16 +90,19 @@ impl GlContext for Context { } } + #[inline] fn swap_buffers(&self) -> Result<(), ContextError> { // TODO: glutin needs some internal changes for proper error recovery unsafe { self.glx.SwapBuffers(self.display as *mut _, self.window); } Ok(()) } + #[inline] fn get_api(&self) -> ::Api { ::Api::OpenGl } + #[inline] fn get_pixel_format(&self) -> PixelFormat { self.pixel_format.clone() } @@ -129,6 +133,7 @@ pub struct ContextPrototype<'a> { } impl<'a> ContextPrototype<'a> { + #[inline] pub fn get_visual_infos(&self) -> &ffi::XVisualInfo { &self.visual_infos } diff --git a/src/api/ios/mod.rs b/src/api/ios/mod.rs index ef34955..0d7de57 100644 --- a/src/api/ios/mod.rs +++ b/src/api/ios/mod.rs @@ -135,6 +135,7 @@ struct DelegateState { impl DelegateState { + #[inline] fn new(window: id, controller:id, view: id, size: (u32,u32), scale: f32) -> DelegateState { DelegateState { events_queue: VecDeque::new(), @@ -147,26 +148,30 @@ impl DelegateState { } } - +#[inline] pub fn get_available_monitors() -> VecDeque<MonitorID> { let mut rb = VecDeque::new(); rb.push_back(MonitorID); rb } +#[inline] pub fn get_primary_monitor() -> MonitorID { MonitorID } impl MonitorID { + #[inline] pub fn get_name(&self) -> Option<String> { Some("Primary".to_string()) } + #[inline] pub fn get_native_identifier(&self) -> NativeMonitorId { NativeMonitorId::Unavailable } + #[inline] pub fn get_dimensions(&self) -> (u32, u32) { unimplemented!() } @@ -262,81 +267,101 @@ impl Window { } } + #[inline] fn start_app() { unsafe { UIApplicationMain(0, ptr::null(), nil, NSString::alloc(nil).init_str("AppDelegate")); } } + #[inline] pub fn set_title(&self, _: &str) { } + #[inline] pub fn show(&self) { } + #[inline] pub fn hide(&self) { } + #[inline] pub fn get_position(&self) -> Option<(i32, i32)> { None } + #[inline] pub fn set_position(&self, _x: i32, _y: i32) { } + #[inline] pub fn get_inner_size(&self) -> Option<(u32, u32)> { unsafe { Some((&*self.delegate_state).size) } } + #[inline] pub fn get_outer_size(&self) -> Option<(u32, u32)> { self.get_inner_size() } + #[inline] pub fn set_inner_size(&self, _x: u32, _y: u32) { } + #[inline] pub fn poll_events(&self) -> PollEventsIterator { PollEventsIterator { window: self } } + #[inline] pub fn wait_events(&self) -> WaitEventsIterator { WaitEventsIterator { window: self } } + #[inline] pub fn platform_display(&self) -> *mut libc::c_void { unimplemented!(); } + #[inline] pub fn platform_window(&self) -> *mut libc::c_void { unimplemented!() } + #[inline] pub fn get_pixel_format(&self) -> PixelFormat { unimplemented!(); } + #[inline] pub fn set_window_resize_callback(&mut self, _: Option<fn(u32, u32)>) { } + #[inline] pub fn set_cursor(&self, _: MouseCursor) { } + #[inline] pub fn set_cursor_state(&self, _: CursorState) -> Result<(), String> { Ok(()) } + #[inline] pub fn hidpi_factor(&self) -> f32 { unsafe { (&*self.delegate_state) }.scale } + #[inline] pub fn set_cursor_position(&self, _x: i32, _y: i32) -> Result<(), ()> { unimplemented!(); } + #[inline] pub fn create_window_proxy(&self) -> WindowProxy { WindowProxy } @@ -344,6 +369,7 @@ impl Window { } impl GlContext for Window { + #[inline] unsafe fn make_current(&self) -> Result<(), ContextError> { let res: BOOL = msg_send![Class::get("EAGLContext").unwrap(), setCurrentContext: self.eagl_context]; if res == YES { @@ -353,6 +379,7 @@ impl GlContext for Window { } } + #[inline] fn is_current(&self) -> bool { false } @@ -366,6 +393,7 @@ impl GlContext for Window { } } + #[inline] fn swap_buffers(&self) -> Result<(), ContextError> { unsafe { let res: BOOL = msg_send![self.eagl_context, presentRenderbuffer: gles::RENDERBUFFER]; @@ -377,16 +405,19 @@ impl GlContext for Window { } } + #[inline] fn get_api(&self) -> Api { unimplemented!() } + #[inline] fn get_pixel_format(&self) -> PixelFormat { unimplemented!() } } impl WindowProxy { + #[inline] pub fn wakeup_event_loop(&self) { unimplemented!() } @@ -396,6 +427,7 @@ impl WindowProxy { impl<'a> Iterator for WaitEventsIterator<'a> { type Item = Event; + #[inline] fn next(&mut self) -> Option<Event> { loop { if let Some(ev) = self.window.poll_events().next() { diff --git a/src/api/osmesa/mod.rs b/src/api/osmesa/mod.rs index ca34e93..c41c997 100644 --- a/src/api/osmesa/mod.rs +++ b/src/api/osmesa/mod.rs @@ -27,6 +27,7 @@ pub enum OsMesaCreationError { } impl From<CreationError> for OsMesaCreationError { + #[inline] fn from(e: CreationError) -> OsMesaCreationError { OsMesaCreationError::CreationError(e) } @@ -67,21 +68,25 @@ impl OsMesaContext { }) } + #[inline] pub fn get_framebuffer(&self) -> &[u32] { &self.buffer } + #[inline] pub fn get_dimensions(&self) -> (u32, u32) { (self.width, self.height) } #[allow(dead_code)] // TODO: can we remove this without causing havoc? + #[inline] pub fn set_window_resize_callback(&mut self, _: Option<fn(u32, u32)>) { } } impl GlContext for OsMesaContext { + #[inline] unsafe fn make_current(&self) -> Result<(), ContextError> { let ret = osmesa_sys::OSMesaMakeCurrent(self.context, self.buffer.as_ptr() as *mut libc::c_void, 0x1401, self.width @@ -96,6 +101,7 @@ impl GlContext for OsMesaContext { Ok(()) } + #[inline] fn is_current(&self) -> bool { unsafe { osmesa_sys::OSMesaGetCurrentContext() == self.context } } @@ -107,20 +113,24 @@ impl GlContext for OsMesaContext { } } + #[inline] fn swap_buffers(&self) -> Result<(), ContextError> { Ok(()) } + #[inline] fn get_api(&self) -> Api { Api::OpenGl } + #[inline] fn get_pixel_format(&self) -> PixelFormat { unimplemented!(); } } impl Drop for OsMesaContext { + #[inline] fn drop(&mut self) { unsafe { osmesa_sys::OSMesaDestroyContext(self.context) } } diff --git a/src/api/wayland/mod.rs b/src/api/wayland/mod.rs index 10d2acb..a57ffec 100644 --- a/src/api/wayland/mod.rs +++ b/src/api/wayland/mod.rs @@ -46,6 +46,7 @@ lazy_static! { }; } +#[inline] pub fn is_available() -> bool { WAYLAND_CONTEXT.is_some() } @@ -56,6 +57,7 @@ enum ShellWindow { } impl ShellWindow { + #[inline] fn get_shell(&mut self) -> ShellGuard { match self { &mut ShellWindow::Plain(ref mut s) => { @@ -98,6 +100,8 @@ enum ShellGuard<'a> { impl<'a> Deref for ShellGuard<'a> { type Target = ShellSurface<EGLSurface>; + + #[inline] fn deref(&self) -> &ShellSurface<EGLSurface> { match self { &ShellGuard::Plain(ref s) => s, @@ -107,6 +111,7 @@ impl<'a> Deref for ShellGuard<'a> { } impl<'a> DerefMut for ShellGuard<'a> { + #[inline] fn deref_mut(&mut self) -> &mut ShellSurface<EGLSurface> { match self { &mut ShellGuard::Plain(ref mut s) => s, @@ -152,6 +157,7 @@ impl Window { pub struct WindowProxy; impl WindowProxy { + #[inline] pub fn wakeup_event_loop(&self) { if let Some(ref ctxt) = *WAYLAND_CONTEXT { ctxt.display.sync(); @@ -164,9 +170,11 @@ pub struct MonitorID { output: Arc<Output> } +#[inline] pub fn get_available_monitors() -> VecDeque<MonitorID> { WAYLAND_CONTEXT.as_ref().unwrap().outputs.iter().map(|o| MonitorID::new(o.clone())).collect() } +#[inline] pub fn get_primary_monitor() -> MonitorID { match WAYLAND_CONTEXT.as_ref().unwrap().outputs.iter().next() { Some(o) => MonitorID::new(o.clone()), @@ -185,6 +193,7 @@ impl MonitorID { Some(format!("{} - {}", self.output.manufacturer(), self.output.model())) } + #[inline] pub fn get_native_identifier(&self) -> ::native_monitor::NativeMonitorId { ::native_monitor::NativeMonitorId::Unavailable } @@ -336,19 +345,23 @@ impl Window { guard.get_shell().set_title(&ctitle); } + #[inline] pub fn show(&self) { // TODO } + #[inline] pub fn hide(&self) { // TODO } + #[inline] pub fn get_position(&self) -> Option<(i32, i32)> { // not available with wayland None } + #[inline] pub fn set_position(&self, _x: i32, _y: i32) { // not available with wayland } @@ -362,84 +375,102 @@ impl Window { Some((w as u32, h as u32)) } + #[inline] pub fn get_outer_size(&self) -> Option<(u32, u32)> { // maybe available if we draw the border ourselves ? // but for now, no. None } + #[inline] pub fn set_inner_size(&self, x: u32, y: u32) { self.shell_window.lock().unwrap().resize(x as i32, y as i32, 0, 0) } + #[inline] pub fn create_window_proxy(&self) -> WindowProxy { WindowProxy } + #[inline] pub fn poll_events(&self) -> PollEventsIterator { PollEventsIterator { window: self } } + #[inline] pub fn wait_events(&self) -> WaitEventsIterator { WaitEventsIterator { window: self } } + #[inline] pub fn set_window_resize_callback(&mut self, callback: Option<fn(u32, u32)>) { self.resize_callback = callback; } + #[inline] pub fn set_cursor(&self, cursor: MouseCursor) { // TODO } + #[inline] pub fn set_cursor_state(&self, state: CursorState) -> Result<(), String> { // TODO Ok(()) } + #[inline] pub fn hidpi_factor(&self) -> f32 { 1.0 } + #[inline] pub fn set_cursor_position(&self, x: i32, y: i32) -> Result<(), ()> { // TODO Ok(()) } + #[inline] pub fn platform_display(&self) -> *mut libc::c_void { unimplemented!() } + #[inline] pub fn platform_window(&self) -> *mut libc::c_void { unimplemented!() } } impl GlContext for Window { + #[inline] unsafe fn make_current(&self) -> Result<(), ContextError> { self.context.make_current() } + #[inline] fn is_current(&self) -> bool { self.context.is_current() } + #[inline] fn get_proc_address(&self, addr: &str) -> *const libc::c_void { self.context.get_proc_address(addr) } + #[inline] fn swap_buffers(&self) -> Result<(), ContextError> { self.context.swap_buffers() } + #[inline] fn get_api(&self) -> ::Api { self.context.get_api() } + #[inline] fn get_pixel_format(&self) -> PixelFormat { self.context.get_pixel_format().clone() } diff --git a/src/api/wgl/mod.rs b/src/api/wgl/mod.rs index c8a1910..e118931 100644 --- a/src/api/wgl/mod.rs +++ b/src/api/wgl/mod.rs @@ -49,6 +49,7 @@ pub struct Context { struct WindowWrapper(winapi::HWND, winapi::HDC); impl Drop for WindowWrapper { + #[inline] fn drop(&mut self) { unsafe { user32::DestroyWindow(self.0); @@ -60,6 +61,7 @@ impl Drop for WindowWrapper { struct ContextWrapper(winapi::HGLRC); impl Drop for ContextWrapper { + #[inline] fn drop(&mut self) { unsafe { gl::wgl::DeleteContext(self.0 as *const _); @@ -150,12 +152,14 @@ impl Context { } /// Returns the raw HGLRC. + #[inline] pub fn get_hglrc(&self) -> winapi::HGLRC { self.context.0 } } impl GlContext for Context { + #[inline] unsafe fn make_current(&self) -> Result<(), ContextError> { if gl::wgl::MakeCurrent(self.hdc as *const _, self.context.0 as *const _) != 0 { Ok(()) @@ -164,6 +168,7 @@ impl GlContext for Context { } } + #[inline] fn is_current(&self) -> bool { unsafe { gl::wgl::GetCurrentContext() == self.context.0 as *const libc::c_void } } @@ -179,6 +184,7 @@ impl GlContext for Context { } } + #[inline] fn swap_buffers(&self) -> Result<(), ContextError> { // TODO: decide how to handle the error /*if unsafe { gdi32::SwapBuffers(self.hdc) } != 0 { @@ -190,11 +196,13 @@ impl GlContext for Context { Ok(()) } + #[inline] fn get_api(&self) -> Api { // FIXME: can be opengl es Api::OpenGl } + #[inline] fn get_pixel_format(&self) -> PixelFormat { self.pixel_format.clone() } diff --git a/src/api/win32/callback.rs b/src/api/win32/callback.rs index da8e1a6..45de907 100644 --- a/src/api/win32/callback.rs +++ b/src/api/win32/callback.rs @@ -281,6 +281,12 @@ pub unsafe extern "system" fn callback(window: winapi::HWND, msg: winapi::UINT, 0 }, + x if x == *super::WAKEUP_MSG_ID => { + use events::Event::Awakened; + send_event(window, Awakened); + 0 + }, + _ => { user32::DefWindowProcW(window, msg, wparam, lparam) } diff --git a/src/api/win32/mod.rs b/src/api/win32/mod.rs index f580950..0bc36a7 100644 --- a/src/api/win32/mod.rs +++ b/src/api/win32/mod.rs @@ -38,6 +38,10 @@ mod event; mod init; mod monitor; +lazy_static! { + static ref WAKEUP_MSG_ID: u32 = unsafe { user32::RegisterWindowMessageA("Glutin::EventID".as_ptr() as *const i8) }; +} + /// The Win32 implementation of the main `Window` object. pub struct Window { /// Main handle for the window. @@ -67,6 +71,7 @@ enum Context { pub struct WindowWrapper(pub winapi::HWND, pub winapi::HDC); impl Drop for WindowWrapper { + #[inline] fn drop(&mut self) { unsafe { user32::DestroyWindow(self.0); @@ -75,11 +80,16 @@ impl Drop for WindowWrapper { } #[derive(Clone)] -pub struct WindowProxy; +pub struct WindowProxy { + hwnd: winapi::HWND, +} impl WindowProxy { + #[inline] pub fn wakeup_event_loop(&self) { - unimplemented!() + unsafe { + user32::PostMessageA(self.hwnd, *WAKEUP_MSG_ID, 0, 0); + } } } @@ -111,12 +121,14 @@ impl Window { } } + #[inline] pub fn show(&self) { unsafe { user32::ShowWindow(self.window.0, winapi::SW_SHOW); } } + #[inline] pub fn hide(&self) { unsafe { user32::ShowWindow(self.window.0, winapi::SW_HIDE); @@ -150,6 +162,7 @@ impl Window { } /// See the docs in the crate root file. + #[inline] pub fn get_inner_size(&self) -> Option<(u32, u32)> { let mut rect: winapi::RECT = unsafe { mem::uninitialized() }; @@ -164,6 +177,7 @@ impl Window { } /// See the docs in the crate root file. + #[inline] pub fn get_outer_size(&self) -> Option<(u32, u32)> { let mut rect: winapi::RECT = unsafe { mem::uninitialized() }; @@ -188,11 +202,13 @@ impl Window { } } + #[inline] pub fn create_window_proxy(&self) -> WindowProxy { - WindowProxy + WindowProxy { hwnd: self.window.0 } } /// See the docs in the crate root file. + #[inline] pub fn poll_events(&self) -> PollEventsIterator { PollEventsIterator { window: self, @@ -200,23 +216,31 @@ impl Window { } /// See the docs in the crate root file. + #[inline] pub fn wait_events(&self) -> WaitEventsIterator { WaitEventsIterator { window: self, } } + #[inline] pub fn platform_display(&self) -> *mut libc::c_void { - unimplemented!() + // What should this return on win32? + // It could be GetDC(NULL), but that requires a ReleaseDC() + // to avoid leaking the DC. + ptr::null_mut() } + #[inline] pub fn platform_window(&self) -> *mut libc::c_void { self.window.0 as *mut libc::c_void } + #[inline] pub fn set_window_resize_callback(&mut self, _: Option<fn(u32, u32)>) { } + #[inline] pub fn set_cursor(&self, _cursor: MouseCursor) { unimplemented!() } @@ -286,6 +310,7 @@ impl Window { res } + #[inline] pub fn hidpi_factor(&self) -> f32 { 1.0 } @@ -311,6 +336,7 @@ impl Window { } impl GlContext for Window { + #[inline] unsafe fn make_current(&self) -> Result<(), ContextError> { match self.context { Context::Wgl(ref c) => c.make_current(), @@ -318,6 +344,7 @@ impl GlContext for Window { } } + #[inline] fn is_current(&self) -> bool { match self.context { Context::Wgl(ref c) => c.is_current(), @@ -325,6 +352,7 @@ impl GlContext for Window { } } + #[inline] fn get_proc_address(&self, addr: &str) -> *const libc::c_void { match self.context { Context::Wgl(ref c) => c.get_proc_address(addr), @@ -332,6 +360,7 @@ impl GlContext for Window { } } + #[inline] fn swap_buffers(&self) -> Result<(), ContextError> { match self.context { Context::Wgl(ref c) => c.swap_buffers(), @@ -339,6 +368,7 @@ impl GlContext for Window { } } + #[inline] fn get_api(&self) -> Api { match self.context { Context::Wgl(ref c) => c.get_api(), @@ -346,6 +376,7 @@ impl GlContext for Window { } } + #[inline] fn get_pixel_format(&self) -> PixelFormat { match self.context { Context::Wgl(ref c) => c.get_pixel_format(), @@ -361,6 +392,7 @@ pub struct PollEventsIterator<'a> { impl<'a> Iterator for PollEventsIterator<'a> { type Item = Event; + #[inline] fn next(&mut self) -> Option<Event> { self.window.events_receiver.try_recv().ok() } @@ -373,12 +405,14 @@ pub struct WaitEventsIterator<'a> { impl<'a> Iterator for WaitEventsIterator<'a> { type Item = Event; + #[inline] fn next(&mut self) -> Option<Event> { self.window.events_receiver.recv().ok() } } impl Drop for Window { + #[inline] fn drop(&mut self) { unsafe { // we don't call MakeCurrent(0, 0) because we are not sure that the context diff --git a/src/api/win32/monitor.rs b/src/api/win32/monitor.rs index d87c928..2f2e2c1 100644 --- a/src/api/win32/monitor.rs +++ b/src/api/win32/monitor.rs @@ -151,16 +151,19 @@ pub fn get_primary_monitor() -> MonitorID { impl MonitorID { /// See the docs if the crate root file. + #[inline] pub fn get_name(&self) -> Option<String> { Some(self.readable_name.clone()) } /// See the docs of the crate root file. + #[inline] pub fn get_native_identifier(&self) -> NativeMonitorId { NativeMonitorId::Name(self.monitor_name.clone()) } /// See the docs if the crate root file. + #[inline] pub fn get_dimensions(&self) -> (u32, u32) { // TODO: retreive the dimensions every time this is called self.dimensions @@ -168,6 +171,7 @@ impl MonitorID { /// This is a Win32-only function for `MonitorID` that returns the system name of the adapter /// device. + #[inline] pub fn get_adapter_name(&self) -> &[winapi::WCHAR] { &self.adapter_name } @@ -175,6 +179,7 @@ impl MonitorID { /// This is a Win32-only function for `MonitorID` that returns the position of the /// monitor on the desktop. /// A window that is positionned at these coordinates will overlap the monitor. + #[inline] pub fn get_position(&self) -> (u32, u32) { self.position } diff --git a/src/api/x11/monitor.rs b/src/api/x11/monitor.rs index 90b12c2..0a20b63 100644 --- a/src/api/x11/monitor.rs +++ b/src/api/x11/monitor.rs @@ -15,6 +15,7 @@ pub fn get_available_monitors(x: &Arc<XConnection>) -> VecDeque<MonitorID> { monitors } +#[inline] pub fn get_primary_monitor(x: &Arc<XConnection>) -> MonitorID { let primary_monitor = unsafe { (x.xlib.XDefaultScreen)(x.display) }; MonitorID(x.clone(), primary_monitor as u32) @@ -26,6 +27,7 @@ impl MonitorID { Some(format!("Monitor #{}", screen_num)) } + #[inline] pub fn get_native_identifier(&self) -> NativeMonitorId { NativeMonitorId::Numeric(self.1) } diff --git a/src/api/x11/window.rs b/src/api/x11/window.rs index 3032bfd..2da226f 100644 --- a/src/api/x11/window.rs +++ b/src/api/x11/window.rs @@ -613,6 +613,7 @@ impl Window { } } + #[inline] pub fn get_position(&self) -> Option<(i32, i32)> { self.get_geometry().map(|(x, y, _, _, _)| (x, y)) } @@ -621,45 +622,53 @@ impl Window { unsafe { (self.x.display.xlib.XMoveWindow)(self.x.display.display, self.x.window, x as libc::c_int, y as libc::c_int); } } + #[inline] pub fn get_inner_size(&self) -> Option<(u32, u32)> { self.get_geometry().map(|(_, _, w, h, _)| (w, h)) } + #[inline] pub fn get_outer_size(&self) -> Option<(u32, u32)> { self.get_geometry().map(|(_, _, w, h, b)| (w + b, h + b)) // TODO: is this really outside? } + #[inline] pub fn set_inner_size(&self, x: u32, y: u32) { unsafe { (self.x.display.xlib.XResizeWindow)(self.x.display.display, self.x.window, x as libc::c_uint, y as libc::c_uint); } } + #[inline] pub fn create_window_proxy(&self) -> WindowProxy { WindowProxy { data: self.x.window_proxy_data.clone() } } + #[inline] pub fn poll_events(&self) -> PollEventsIterator { PollEventsIterator { window: self } } + #[inline] pub fn wait_events(&self) -> WaitEventsIterator { WaitEventsIterator { window: self } } + #[inline] pub fn platform_display(&self) -> *mut libc::c_void { self.x.display.display as *mut libc::c_void } + #[inline] pub fn platform_window(&self) -> *mut libc::c_void { self.x.window as *mut libc::c_void } - + #[inline] pub fn set_window_resize_callback(&mut self, _: Option<fn(u32, u32)>) { } @@ -754,6 +763,7 @@ impl Window { } } + #[inline] pub fn hidpi_factor(&self) -> f32 { 1.0 } @@ -768,6 +778,7 @@ impl Window { } impl GlContext for Window { + #[inline] unsafe fn make_current(&self) -> Result<(), ContextError> { match self.x.context { Context::Glx(ref ctxt) => ctxt.make_current(), @@ -776,6 +787,7 @@ impl GlContext for Window { } } + #[inline] fn is_current(&self) -> bool { match self.x.context { Context::Glx(ref ctxt) => ctxt.is_current(), @@ -784,6 +796,7 @@ impl GlContext for Window { } } + #[inline] fn get_proc_address(&self, addr: &str) -> *const libc::c_void { match self.x.context { Context::Glx(ref ctxt) => ctxt.get_proc_address(addr), @@ -792,6 +805,7 @@ impl GlContext for Window { } } + #[inline] fn swap_buffers(&self) -> Result<(), ContextError> { match self.x.context { Context::Glx(ref ctxt) => ctxt.swap_buffers(), @@ -800,6 +814,7 @@ impl GlContext for Window { } } + #[inline] fn get_api(&self) -> Api { match self.x.context { Context::Glx(ref ctxt) => ctxt.get_api(), @@ -808,6 +823,7 @@ impl GlContext for Window { } } + #[inline] fn get_pixel_format(&self) -> PixelFormat { match self.x.context { Context::Glx(ref ctxt) => ctxt.get_pixel_format(), diff --git a/src/api/x11/xdisplay.rs b/src/api/x11/xdisplay.rs index 2aa5d95..2b77d9c 100644 --- a/src/api/x11/xdisplay.rs +++ b/src/api/x11/xdisplay.rs @@ -98,6 +98,7 @@ impl XConnection { } impl Drop for XConnection { + #[inline] fn drop(&mut self) { unsafe { (self.xlib.XCloseDisplay)(self.display) }; } @@ -113,12 +114,14 @@ pub enum XNotSupported { } impl From<ffi::OpenError> for XNotSupported { + #[inline] fn from(err: ffi::OpenError) -> XNotSupported { XNotSupported::LibraryOpenError(err) } } impl Error for XNotSupported { + #[inline] fn description(&self) -> &str { match *self { XNotSupported::LibraryOpenError(_) => "Failed to load one of xlib's shared libraries", @@ -126,6 +129,7 @@ impl Error for XNotSupported { } } + #[inline] fn cause(&self) -> Option<&Error> { match *self { XNotSupported::LibraryOpenError(ref err) => Some(err), diff --git a/src/headless.rs b/src/headless.rs index f3ddbf0..a0c8c2d 100644 --- a/src/headless.rs +++ b/src/headless.rs @@ -28,6 +28,7 @@ pub struct HeadlessRendererBuilder<'a> { impl<'a> HeadlessRendererBuilder<'a> { /// Initializes a new `HeadlessRendererBuilder` with default values. + #[inline] pub fn new(width: u32, height: u32) -> HeadlessRendererBuilder<'a> { HeadlessRendererBuilder { dimensions: (width, height), @@ -37,6 +38,7 @@ impl<'a> HeadlessRendererBuilder<'a> { } /// Sets how the backend should choose the OpenGL API and version. + #[inline] pub fn with_gl(mut self, request: GlRequest) -> HeadlessRendererBuilder<'a> { self.opengl.version = request; self @@ -46,12 +48,14 @@ impl<'a> HeadlessRendererBuilder<'a> { /// /// The default value for this flag is `cfg!(ndebug)`, which means that it's enabled /// when you run `cargo build` and disabled when you run `cargo build --release`. + #[inline] pub fn with_gl_debug_flag(mut self, flag: bool) -> HeadlessRendererBuilder<'a> { self.opengl.debug = flag; self } /// Sets the robustness of the OpenGL context. See the docs of `Robustness`. + #[inline] pub fn with_gl_robustness(mut self, robustness: Robustness) -> HeadlessRendererBuilder<'a> { self.opengl.robustness = robustness; self @@ -61,6 +65,7 @@ impl<'a> HeadlessRendererBuilder<'a> { /// /// Error should be very rare and only occur in case of permission denied, incompatible system, /// out of memory, etc. + #[inline] pub fn build(self) -> Result<HeadlessContext, CreationError> { platform::HeadlessContext::new(self.dimensions, &self.pf_reqs, &self.opengl) .map(|w| HeadlessContext { context: w }) @@ -70,6 +75,7 @@ impl<'a> HeadlessRendererBuilder<'a> { /// /// The context is build in a *strict* way. That means that if the backend couldn't give /// you what you requested, an `Err` will be returned. + #[inline] pub fn build_strict(self) -> Result<HeadlessContext, CreationError> { self.build() } @@ -105,41 +111,50 @@ impl HeadlessContext { /// Returns the API that is currently provided by this window. /// /// See `Window::get_api` for more infos. + #[inline] pub fn get_api(&self) -> Api { self.context.get_api() } + #[inline] pub fn set_window_resize_callback(&mut self, _: Option<fn(u32, u32)>) { } } impl gl_common::GlFunctionsSource for HeadlessContext { + #[inline] fn get_proc_addr(&self, addr: &str) -> *const libc::c_void { self.get_proc_address(addr) } } impl GlContext for HeadlessContext { + #[inline] unsafe fn make_current(&self) -> Result<(), ContextError> { self.context.make_current() } + #[inline] fn is_current(&self) -> bool { self.context.is_current() } + #[inline] fn get_proc_address(&self, addr: &str) -> *const libc::c_void { self.context.get_proc_address(addr) } + #[inline] fn swap_buffers(&self) -> Result<(), ContextError> { self.context.swap_buffers() } + #[inline] fn get_api(&self) -> Api { self.context.get_api() } + #[inline] fn get_pixel_format(&self) -> PixelFormat { self.context.get_pixel_format() } @@ -478,6 +478,7 @@ impl PixelFormatRequirements { } impl Default for PixelFormatRequirements { + #[inline] fn default() -> PixelFormatRequirements { PixelFormatRequirements { multisampling: None, @@ -532,6 +533,7 @@ pub struct WindowAttributes { } impl Default for WindowAttributes { + #[inline] fn default() -> WindowAttributes { WindowAttributes { dimensions: None, @@ -585,6 +587,7 @@ pub struct GlAttributes<S> { impl<S> GlAttributes<S> { /// Turns the `sharing` parameter into another type by calling a closure. + #[inline] pub fn map_sharing<F, T>(self, f: F) -> GlAttributes<T> where F: FnOnce(S) -> T { GlAttributes { sharing: self.sharing.map(f), @@ -598,6 +601,7 @@ impl<S> GlAttributes<S> { } impl<S> Default for GlAttributes<S> { + #[inline] fn default() -> GlAttributes<S> { GlAttributes { sharing: None, diff --git a/src/platform/emscripten/mod.rs b/src/platform/emscripten/mod.rs index d3aa6d6..16f3250 100644 --- a/src/platform/emscripten/mod.rs +++ b/src/platform/emscripten/mod.rs @@ -10,32 +10,39 @@ pub struct HeadlessContext(Window); impl HeadlessContext { /// See the docs in the crate root file. + #[inline] pub fn new(builder: BuilderAttribs) -> Result<HeadlessContext, CreationError> { Window::new(builder).map(|w| HeadlessContext(w)) } } impl GlContext for HeadlessContext { + #[inline] unsafe fn make_current(&self) -> Result<(), ContextError> { self.0.make_current() } + #[inline] fn is_current(&self) -> bool { self.0.is_current() } + #[inline] fn get_proc_address(&self, addr: &str) -> *const libc::c_void { self.0.get_proc_address(addr) } + #[inline] fn swap_buffers(&self) -> Result<(), ContextError> { self.0.swap_buffers() } + #[inline] fn get_api(&self) -> Api { self.0.get_api() } + #[inline] fn get_pixel_format(&self) -> PixelFormat { self.0.get_pixel_format() } diff --git a/src/platform/linux/api_dispatch.rs b/src/platform/linux/api_dispatch.rs index 46c58bb..5ab4ae2 100644 --- a/src/platform/linux/api_dispatch.rs +++ b/src/platform/linux/api_dispatch.rs @@ -59,6 +59,7 @@ pub enum WindowProxy { } impl WindowProxy { + #[inline] pub fn wakeup_event_loop(&self) { match self { &WindowProxy::X(ref wp) => wp.wakeup_event_loop(), @@ -77,6 +78,7 @@ pub enum MonitorID { None, } +#[inline] pub fn get_available_monitors() -> VecDeque<MonitorID> { match *BACKEND { Backend::Wayland => wayland::get_available_monitors() @@ -91,6 +93,7 @@ pub fn get_available_monitors() -> VecDeque<MonitorID> { } } +#[inline] pub fn get_primary_monitor() -> MonitorID { match *BACKEND { Backend::Wayland => MonitorID::Wayland(wayland::get_primary_monitor()), @@ -100,6 +103,7 @@ pub fn get_primary_monitor() -> MonitorID { } impl MonitorID { + #[inline] pub fn get_name(&self) -> Option<String> { match self { &MonitorID::X(ref m) => m.get_name(), @@ -108,6 +112,7 @@ impl MonitorID { } } + #[inline] pub fn get_native_identifier(&self) -> ::native_monitor::NativeMonitorId { match self { &MonitorID::X(ref m) => m.get_native_identifier(), @@ -116,6 +121,7 @@ impl MonitorID { } } + #[inline] pub fn get_dimensions(&self) -> (u32, u32) { match self { &MonitorID::X(ref m) => m.get_dimensions(), @@ -136,6 +142,7 @@ pub enum PollEventsIterator<'a> { impl<'a> Iterator for PollEventsIterator<'a> { type Item = Event; + #[inline] fn next(&mut self) -> Option<Event> { match self { &mut PollEventsIterator::X(ref mut it) => it.next(), @@ -154,6 +161,7 @@ pub enum WaitEventsIterator<'a> { impl<'a> Iterator for WaitEventsIterator<'a> { type Item = Event; + #[inline] fn next(&mut self) -> Option<Event> { match self { &mut WaitEventsIterator::X(ref mut it) => it.next(), @@ -163,6 +171,7 @@ impl<'a> Iterator for WaitEventsIterator<'a> { } impl Window { + #[inline] pub fn new(window: &WindowAttributes, pf_reqs: &PixelFormatRequirements, opengl: &GlAttributes<&Window>) -> Result<Window, CreationError> { @@ -189,6 +198,7 @@ impl Window { } } + #[inline] pub fn set_title(&self, title: &str) { match self { &Window::X(ref w) => w.set_title(title), @@ -196,6 +206,7 @@ impl Window { } } + #[inline] pub fn show(&self) { match self { &Window::X(ref w) => w.show(), @@ -203,6 +214,7 @@ impl Window { } } + #[inline] pub fn hide(&self) { match self { &Window::X(ref w) => w.hide(), @@ -210,6 +222,7 @@ impl Window { } } + #[inline] pub fn get_position(&self) -> Option<(i32, i32)> { match self { &Window::X(ref w) => w.get_position(), @@ -217,6 +230,7 @@ impl Window { } } + #[inline] pub fn set_position(&self, x: i32, y: i32) { match self { &Window::X(ref w) => w.set_position(x, y), @@ -224,6 +238,7 @@ impl Window { } } + #[inline] pub fn get_inner_size(&self) -> Option<(u32, u32)> { match self { &Window::X(ref w) => w.get_inner_size(), @@ -231,6 +246,7 @@ impl Window { } } + #[inline] pub fn get_outer_size(&self) -> Option<(u32, u32)> { match self { &Window::X(ref w) => w.get_outer_size(), @@ -238,6 +254,7 @@ impl Window { } } + #[inline] pub fn set_inner_size(&self, x: u32, y: u32) { match self { &Window::X(ref w) => w.set_inner_size(x, y), @@ -245,6 +262,7 @@ impl Window { } } + #[inline] pub fn create_window_proxy(&self) -> WindowProxy { match self { &Window::X(ref w) => WindowProxy::X(w.create_window_proxy()), @@ -252,6 +270,7 @@ impl Window { } } + #[inline] pub fn poll_events(&self) -> PollEventsIterator { match self { &Window::X(ref w) => PollEventsIterator::X(w.poll_events()), @@ -259,6 +278,7 @@ impl Window { } } + #[inline] pub fn wait_events(&self) -> WaitEventsIterator { match self { &Window::X(ref w) => WaitEventsIterator::X(w.wait_events()), @@ -266,6 +286,7 @@ impl Window { } } + #[inline] pub fn set_window_resize_callback(&mut self, callback: Option<fn(u32, u32)>) { match self { &mut Window::X(ref mut w) => w.set_window_resize_callback(callback), @@ -273,6 +294,7 @@ impl Window { } } + #[inline] pub fn set_cursor(&self, cursor: MouseCursor) { match self { &Window::X(ref w) => w.set_cursor(cursor), @@ -280,6 +302,7 @@ impl Window { } } + #[inline] pub fn set_cursor_state(&self, state: CursorState) -> Result<(), String> { match self { &Window::X(ref w) => w.set_cursor_state(state), @@ -287,6 +310,7 @@ impl Window { } } + #[inline] pub fn hidpi_factor(&self) -> f32 { match self { &Window::X(ref w) => w.hidpi_factor(), @@ -294,6 +318,7 @@ impl Window { } } + #[inline] pub fn set_cursor_position(&self, x: i32, y: i32) -> Result<(), ()> { match self { &Window::X(ref w) => w.set_cursor_position(x, y), @@ -301,6 +326,7 @@ impl Window { } } + #[inline] pub fn platform_display(&self) -> *mut libc::c_void { match self { &Window::X(ref w) => w.platform_display(), @@ -308,6 +334,7 @@ impl Window { } } + #[inline] pub fn platform_window(&self) -> *mut libc::c_void { match self { &Window::X(ref w) => w.platform_window(), @@ -317,6 +344,7 @@ impl Window { } impl GlContext for Window { + #[inline] unsafe fn make_current(&self) -> Result<(), ContextError> { match self { &Window::X(ref w) => w.make_current(), @@ -324,6 +352,7 @@ impl GlContext for Window { } } + #[inline] fn is_current(&self) -> bool { match self { &Window::X(ref w) => w.is_current(), @@ -331,6 +360,7 @@ impl GlContext for Window { } } + #[inline] fn get_proc_address(&self, addr: &str) -> *const libc::c_void { match self { &Window::X(ref w) => w.get_proc_address(addr), @@ -338,6 +368,7 @@ impl GlContext for Window { } } + #[inline] fn swap_buffers(&self) -> Result<(), ContextError> { match self { &Window::X(ref w) => w.swap_buffers(), @@ -345,6 +376,7 @@ impl GlContext for Window { } } + #[inline] fn get_api(&self) -> ::Api { match self { &Window::X(ref w) => w.get_api(), @@ -352,6 +384,7 @@ impl GlContext for Window { } } + #[inline] fn get_pixel_format(&self) -> PixelFormat { match self { &Window::X(ref w) => w.get_pixel_format(), diff --git a/src/platform/windows/mod.rs b/src/platform/windows/mod.rs index af9261f..1d55e71 100644 --- a/src/platform/windows/mod.rs +++ b/src/platform/windows/mod.rs @@ -59,6 +59,7 @@ pub struct Window(win32::Window); impl Window { /// See the docs in the crate root file. + #[inline] pub fn new(window: &WindowAttributes, pf_reqs: &PixelFormatRequirements, opengl: &GlAttributes<&Window>) -> Result<Window, CreationError> { @@ -70,12 +71,14 @@ impl Window { impl Deref for Window { type Target = win32::Window; + #[inline] fn deref(&self) -> &win32::Window { &self.0 } } impl DerefMut for Window { + #[inline] fn deref_mut(&mut self) -> &mut win32::Window { &mut self.0 } @@ -114,6 +117,7 @@ impl HeadlessContext { } impl GlContext for HeadlessContext { + #[inline] unsafe fn make_current(&self) -> Result<(), ContextError> { match self { &HeadlessContext::HiddenWindow(ref ctxt) => ctxt.make_current(), @@ -121,6 +125,7 @@ impl GlContext for HeadlessContext { } } + #[inline] fn is_current(&self) -> bool { match self { &HeadlessContext::HiddenWindow(ref ctxt) => ctxt.is_current(), @@ -128,6 +133,7 @@ impl GlContext for HeadlessContext { } } + #[inline] fn get_proc_address(&self, addr: &str) -> *const libc::c_void { match self { &HeadlessContext::HiddenWindow(ref ctxt) => ctxt.get_proc_address(addr), @@ -135,6 +141,7 @@ impl GlContext for HeadlessContext { } } + #[inline] fn swap_buffers(&self) -> Result<(), ContextError> { match self { &HeadlessContext::HiddenWindow(ref ctxt) => ctxt.swap_buffers(), @@ -142,6 +149,7 @@ impl GlContext for HeadlessContext { } } + #[inline] fn get_api(&self) -> Api { match self { &HeadlessContext::HiddenWindow(ref ctxt) => ctxt.get_api(), @@ -149,6 +157,7 @@ impl GlContext for HeadlessContext { } } + #[inline] fn get_pixel_format(&self) -> PixelFormat { match self { &HeadlessContext::HiddenWindow(ref ctxt) => ctxt.get_pixel_format(), diff --git a/src/window.rs b/src/window.rs index e69f525..9d9aeff 100644 --- a/src/window.rs +++ b/src/window.rs @@ -36,6 +36,7 @@ pub struct WindowBuilder<'a> { impl<'a> WindowBuilder<'a> { /// Initializes a new `WindowBuilder` with default values. + #[inline] pub fn new() -> WindowBuilder<'a> { WindowBuilder { pf_reqs: Default::default(), @@ -47,12 +48,14 @@ impl<'a> WindowBuilder<'a> { /// Requests the window to be of specific dimensions. /// /// Width and height are in pixels. + #[inline] pub fn with_dimensions(mut self, width: u32, height: u32) -> WindowBuilder<'a> { self.window.dimensions = Some((width, height)); self } /// Requests a specific title for the window. + #[inline] pub fn with_title(mut self, title: String) -> WindowBuilder<'a> { self.window.title = title; self @@ -61,6 +64,7 @@ impl<'a> WindowBuilder<'a> { /// Requests fullscreen mode. /// /// If you don't specify dimensions for the window, it will match the monitor's. + #[inline] pub fn with_fullscreen(mut self, monitor: MonitorID) -> WindowBuilder<'a> { let MonitorID(monitor) = monitor; self.window.monitor = Some(monitor); @@ -70,18 +74,21 @@ impl<'a> WindowBuilder<'a> { /// The created window will share all its OpenGL objects with the window in the parameter. /// /// There are some exceptions, like FBOs or VAOs. See the OpenGL documentation. + #[inline] pub fn with_shared_lists(mut self, other: &'a Window) -> WindowBuilder<'a> { self.opengl.sharing = Some(&other.window); self } /// Sets how the backend should choose the OpenGL API and version. + #[inline] pub fn with_gl(mut self, request: GlRequest) -> WindowBuilder<'a> { self.opengl.version = request; self } /// Sets the desired OpenGL context profile. + #[inline] pub fn with_gl_profile(mut self, profile: GlProfile) -> WindowBuilder<'a> { self.opengl.profile = Some(profile); self @@ -91,24 +98,28 @@ impl<'a> WindowBuilder<'a> { /// /// The default value for this flag is `cfg!(debug_assertions)`, which means that it's enabled /// when you run `cargo build` and disabled when you run `cargo build --release`. + #[inline] pub fn with_gl_debug_flag(mut self, flag: bool) -> WindowBuilder<'a> { self.opengl.debug = flag; self } /// Sets the robustness of the OpenGL context. See the docs of `Robustness`. + #[inline] pub fn with_gl_robustness(mut self, robustness: Robustness) -> WindowBuilder<'a> { self.opengl.robustness = robustness; self } /// Requests that the window has vsync enabled. + #[inline] pub fn with_vsync(mut self) -> WindowBuilder<'a> { self.opengl.vsync = true; self } /// Sets whether the window will be initially hidden or visible. + #[inline] pub fn with_visibility(mut self, visible: bool) -> WindowBuilder<'a> { self.window.visible = visible; self @@ -119,6 +130,7 @@ impl<'a> WindowBuilder<'a> { /// # Panic /// /// Will panic if `samples` is not a power of two. + #[inline] pub fn with_multisampling(mut self, samples: u16) -> WindowBuilder<'a> { assert!(samples.is_power_of_two()); self.pf_reqs.multisampling = Some(samples); @@ -126,18 +138,21 @@ impl<'a> WindowBuilder<'a> { } /// Sets the number of bits in the depth buffer. + #[inline] pub fn with_depth_buffer(mut self, bits: u8) -> WindowBuilder<'a> { self.pf_reqs.depth_bits = Some(bits); self } /// Sets the number of bits in the stencil buffer. + #[inline] pub fn with_stencil_buffer(mut self, bits: u8) -> WindowBuilder<'a> { self.pf_reqs.stencil_bits = Some(bits); self } /// Sets the number of bits in the color buffer. + #[inline] pub fn with_pixel_format(mut self, color_bits: u8, alpha_bits: u8) -> WindowBuilder<'a> { self.pf_reqs.color_bits = Some(color_bits); self.pf_reqs.alpha_bits = Some(alpha_bits); @@ -145,30 +160,35 @@ impl<'a> WindowBuilder<'a> { } /// Request the backend to be stereoscopic. + #[inline] pub fn with_stereoscopy(mut self) -> WindowBuilder<'a> { self.pf_reqs.stereoscopy = true; self } /// Sets whether sRGB should be enabled on the window. `None` means "I don't care". + #[inline] pub fn with_srgb(mut self, srgb_enabled: Option<bool>) -> WindowBuilder<'a> { self.pf_reqs.srgb = srgb_enabled; self } /// Sets whether the background of the window should be transparent. + #[inline] pub fn with_transparency(mut self, transparent: bool) -> WindowBuilder<'a> { self.window.transparent = transparent; self } /// Sets whether the window should have a border, a title bar, etc. + #[inline] pub fn with_decorations(mut self, decorations: bool) -> WindowBuilder<'a> { self.window.decorations = decorations; self } /// Enables multitouch + #[inline] pub fn with_multitouch(mut self) -> WindowBuilder<'a> { self.window.multitouch = true; self @@ -198,6 +218,7 @@ impl<'a> WindowBuilder<'a> { /// /// The context is build in a *strict* way. That means that if the backend couldn't give /// you what you requested, an `Err` will be returned. + #[inline] pub fn build_strict(self) -> Result<Window, CreationError> { self.build() } @@ -231,6 +252,7 @@ pub struct Window { } impl Default for Window { + #[inline] fn default() -> Window { Window::new().unwrap() } @@ -438,11 +460,13 @@ impl Window { /// - On Windows and OS/X, this always returns `OpenGl`. /// - On Android, this always returns `OpenGlEs`. /// - On Linux, it must be checked at runtime. + #[inline] pub fn get_api(&self) -> Api { self.window.get_api() } /// Returns the pixel format of this window. + #[inline] pub fn get_pixel_format(&self) -> PixelFormat { self.window.get_pixel_format() } @@ -459,6 +483,7 @@ impl Window { /// Sets a resize callback that is called by Mac (and potentially other /// operating systems) during resize operations. This can be used to repaint /// during window resizing. + #[inline] pub fn set_window_resize_callback(&mut self, callback: Option<fn(u32, u32)>) { self.window.set_window_resize_callback(callback); } @@ -472,11 +497,13 @@ impl Window { /// Returns the ratio between the backing framebuffer resolution and the /// window size in screen pixels. This is typically one for a normal display /// and two for a retina display. + #[inline] pub fn hidpi_factor(&self) -> f32 { self.window.hidpi_factor() } /// Changes the position of the cursor in window coordinates. + #[inline] pub fn set_cursor_position(&self, x: i32, y: i32) -> Result<(), ()> { self.window.set_cursor_position(x, y) } @@ -484,38 +511,46 @@ impl Window { /// Sets how glutin handles the cursor. See the documentation of `CursorState` for details. /// /// Has no effect on Android. + #[inline] pub fn set_cursor_state(&self, state: CursorState) -> Result<(), String> { self.window.set_cursor_state(state) } } impl gl_common::GlFunctionsSource for Window { + #[inline] fn get_proc_addr(&self, addr: &str) -> *const libc::c_void { self.get_proc_address(addr) } } impl GlContext for Window { + #[inline] unsafe fn make_current(&self) -> Result<(), ContextError> { self.make_current() } + #[inline] fn is_current(&self) -> bool { self.is_current() } + #[inline] fn get_proc_address(&self, addr: &str) -> *const libc::c_void { self.get_proc_address(addr) } + #[inline] fn swap_buffers(&self) -> Result<(), ContextError> { self.swap_buffers() } + #[inline] fn get_api(&self) -> Api { self.get_api() } + #[inline] fn get_pixel_format(&self) -> PixelFormat { self.get_pixel_format() } @@ -544,10 +579,12 @@ pub struct PollEventsIterator<'a>(platform::PollEventsIterator<'a>); impl<'a> Iterator for PollEventsIterator<'a> { type Item = Event; + #[inline] fn next(&mut self) -> Option<Event> { self.0.next() } + #[inline] fn size_hint(&self) -> (usize, Option<usize>) { self.0.size_hint() } @@ -559,10 +596,12 @@ pub struct WaitEventsIterator<'a>(platform::WaitEventsIterator<'a>); impl<'a> Iterator for WaitEventsIterator<'a> { type Item = Event; + #[inline] fn next(&mut self) -> Option<Event> { self.0.next() } + #[inline] fn size_hint(&self) -> (usize, Option<usize>) { self.0.size_hint() } @@ -578,22 +617,26 @@ pub struct AvailableMonitorsIter { impl Iterator for AvailableMonitorsIter { type Item = MonitorID; + #[inline] fn next(&mut self) -> Option<MonitorID> { self.data.next().map(|id| MonitorID(id)) } + #[inline] fn size_hint(&self) -> (usize, Option<usize>) { self.data.size_hint() } } /// Returns the list of all available monitors. +#[inline] pub fn get_available_monitors() -> AvailableMonitorsIter { let data = platform::get_available_monitors(); AvailableMonitorsIter{ data: data.into_iter() } } /// Returns the primary monitor of the system. +#[inline] pub fn get_primary_monitor() -> MonitorID { MonitorID(platform::get_primary_monitor()) } @@ -603,18 +646,21 @@ pub struct MonitorID(platform::MonitorID); impl MonitorID { /// Returns a human-readable name of the monitor. + #[inline] pub fn get_name(&self) -> Option<String> { let &MonitorID(ref id) = self; id.get_name() } /// Returns the native platform identifier for this monitor. + #[inline] pub fn get_native_identifier(&self) -> NativeMonitorId { let &MonitorID(ref id) = self; id.get_native_identifier() } /// Returns the number of pixels currently displayed on the monitor. + #[inline] pub fn get_dimensions(&self) -> (u32, u32) { let &MonitorID(ref id) = self; id.get_dimensions() |