diff options
author | Pierre Krieger <pierre.krieger1708@gmail.com> | 2015-09-21 14:42:05 +0200 |
---|---|---|
committer | Pierre Krieger <pierre.krieger1708@gmail.com> | 2015-09-23 13:11:47 +0200 |
commit | aa9cb99929ee1893699184ded888b2586455f016 (patch) | |
tree | b16503dbfe2248beeed0f7d82b150e64e6453043 /src/api | |
parent | 3820d307a3f23828790e8a46a9c46849592104d6 (diff) | |
download | glutin-aa9cb99929ee1893699184ded888b2586455f016.tar.gz glutin-aa9cb99929ee1893699184ded888b2586455f016.zip |
Add #[inline] attributes
Diffstat (limited to 'src/api')
-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/mod.rs | 23 | ||||
-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 |
17 files changed, 270 insertions, 3 deletions
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 539545c..9e9a001 100644 --- a/src/api/cocoa/mod.rs +++ b/src/api/cocoa/mod.rs @@ -568,10 +568,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); } } @@ -606,6 +608,7 @@ impl Window { } } + #[inline] pub fn get_inner_size(&self) -> Option<(u32, u32)> { unsafe { let view_frame = NSView::frame(*self.view); @@ -613,6 +616,7 @@ impl Window { } } + #[inline] pub fn get_outer_size(&self) -> Option<(u32, u32)> { unsafe { let window_frame = NSWindow::frame(*self.window); @@ -620,22 +624,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 @@ -652,14 +660,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; } @@ -723,24 +734,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); @@ -765,15 +780,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/mod.rs b/src/api/win32/mod.rs index 235fa2f..0bc36a7 100644 --- a/src/api/win32/mod.rs +++ b/src/api/win32/mod.rs @@ -71,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); @@ -84,6 +85,7 @@ pub struct WindowProxy { } impl WindowProxy { + #[inline] pub fn wakeup_event_loop(&self) { unsafe { user32::PostMessageA(self.hwnd, *WAKEUP_MSG_ID, 0, 0); @@ -119,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); @@ -158,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() }; @@ -172,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() }; @@ -196,11 +202,13 @@ impl Window { } } + #[inline] pub fn create_window_proxy(&self) -> WindowProxy { WindowProxy { hwnd: self.window.0 } } /// See the docs in the crate root file. + #[inline] pub fn poll_events(&self) -> PollEventsIterator { PollEventsIterator { window: self, @@ -208,12 +216,14 @@ 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 { // What should this return on win32? // It could be GetDC(NULL), but that requires a ReleaseDC() @@ -221,13 +231,16 @@ impl Window { 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!() } @@ -297,6 +310,7 @@ impl Window { res } + #[inline] pub fn hidpi_factor(&self) -> f32 { 1.0 } @@ -322,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(), @@ -329,6 +344,7 @@ impl GlContext for Window { } } + #[inline] fn is_current(&self) -> bool { match self.context { Context::Wgl(ref c) => c.is_current(), @@ -336,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), @@ -343,6 +360,7 @@ impl GlContext for Window { } } + #[inline] fn swap_buffers(&self) -> Result<(), ContextError> { match self.context { Context::Wgl(ref c) => c.swap_buffers(), @@ -350,6 +368,7 @@ impl GlContext for Window { } } + #[inline] fn get_api(&self) -> Api { match self.context { Context::Wgl(ref c) => c.get_api(), @@ -357,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(), @@ -372,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() } @@ -384,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), |