From 4a70752a87d60aedd0f471e5c6b5c11e11f94d70 Mon Sep 17 00:00:00 2001 From: Glenn Watson Date: Wed, 17 Dec 2014 13:58:09 +1000 Subject: [PATCH] glutin - Add support for waking up blocked event loop, and smooth resize on mac. --- components/servo/Cargo.lock | 10 +++---- ports/cef/Cargo.lock | 2 +- ports/glutin/window.rs | 52 ++++++++++++++++++++++++++----------- 3 files changed, 43 insertions(+), 21 deletions(-) diff --git a/components/servo/Cargo.lock b/components/servo/Cargo.lock index 27781ede26b..068350ccd01 100644 --- a/components/servo/Cargo.lock +++ b/components/servo/Cargo.lock @@ -59,7 +59,7 @@ dependencies = [ [[package]] name = "cocoa" version = "0.1.1" -source = "git+https://github.com/servo/rust-cocoa#19d6f6977dcedbf29000b65d83df66cf589c20c3" +source = "git+https://github.com/servo/rust-cocoa#8f47f126fe534d4dad86aa1f5b2da46a0581a232" [[package]] name = "compile_msg" @@ -329,14 +329,14 @@ dependencies = [ [[package]] name = "glutin" version = "0.0.2" -source = "git+https://github.com/servo/glutin?ref=servo#b86cbe5c61a943683309384fc9d7e7e97d58e290" +source = "git+https://github.com/servo/glutin?ref=servo#936519a44f77f6b646c504eff38fe7d57a17b1f4" dependencies = [ "android_glue 0.0.1 (git+https://github.com/servo/android-rs-glue?ref=servo)", "cocoa 0.1.1 (git+https://github.com/servo/rust-cocoa)", "core_graphics 0.1.0 (git+https://github.com/servo/rust-core-graphics)", "gl_common 0.0.1 (git+https://github.com/bjz/gl-rs.git)", "gl_generator 0.0.1 (git+https://github.com/bjz/gl-rs.git)", - "winapi 0.0.1 (git+https://github.com/retep998/winapi-rs)", + "winapi 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -720,8 +720,8 @@ source = "git+https://github.com/rust-lang/uuid#f5d94d0043a615756edefaf9c6041f11 [[package]] name = "winapi" -version = "0.0.1" -source = "git+https://github.com/retep998/winapi-rs#80b6574a8bad8fc0a1f19c788b27a459bab26c83" +version = "0.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "xlib" diff --git a/ports/cef/Cargo.lock b/ports/cef/Cargo.lock index e569fba7e8d..094429f5fc6 100644 --- a/ports/cef/Cargo.lock +++ b/ports/cef/Cargo.lock @@ -60,7 +60,7 @@ dependencies = [ [[package]] name = "cocoa" version = "0.1.1" -source = "git+https://github.com/servo/rust-cocoa#19d6f6977dcedbf29000b65d83df66cf589c20c3" +source = "git+https://github.com/servo/rust-cocoa#8f47f126fe534d4dad86aa1f5b2da46a0581a232" [[package]] name = "compositing" diff --git a/ports/glutin/window.rs b/ports/glutin/window.rs index 8b9e5f70f68..270cc1adcf2 100644 --- a/ports/glutin/window.rs +++ b/ports/glutin/window.rs @@ -47,6 +47,19 @@ enum WindowHandle { Headless(HeadlessContext), } +static mut g_nested_event_loop_listener: Option<*mut NestedEventLoopListener + 'static> = None; + +fn nested_window_resize(width: uint, height: uint) { + unsafe { + match g_nested_event_loop_listener { + None => {} + Some(listener) => { + (*listener).handle_event_from_nested_event_loop(Resize(TypedSize2D(width, height))); + } + } + } +} + bitflags!( #[deriving(Show)] flags KeyModifiers: u8 { @@ -107,7 +120,7 @@ impl Window { let glutin = match render_api { OpenGL => { - let glutin_window = glutin::WindowBuilder::new() + let mut glutin_window = glutin::WindowBuilder::new() .with_title("Servo [glutin]".to_string()) .with_dimensions(window_size.width, window_size.height) .with_gl_version(gl_version()) @@ -116,6 +129,7 @@ impl Window { .unwrap(); unsafe { glutin_window.make_current() }; + glutin_window.set_window_resize_callback(Some(nested_window_resize)); WindowHandle::Windowed(glutin_window) } Mesa => { @@ -186,11 +200,23 @@ impl WindowMethods for Window { } } - fn create_compositor_channel(_: &Option>) + fn create_compositor_channel(window: &Option>) -> (Box, Box) { let (sender, receiver) = channel(); + + let window_proxy = match window { + &Some(ref window) => { + match window.glutin { + WindowHandle::Windowed(ref window) => Some(window.create_window_proxy()), + WindowHandle::Headless(_) => None, + } + } + &None => None, + }; + (box GlutinCompositorProxy { sender: sender, + window_proxy: window_proxy, } as Box, box receiver as Box) } @@ -476,20 +502,12 @@ impl Window { pub unsafe fn set_nested_event_loop_listener( &self, - _listener: *mut NestedEventLoopListener + 'static) { - // TODO: Support this with glutin - //self.glfw_window.set_refresh_polling(false); - //glfw::ffi::glfwSetWindowRefreshCallback(self.glfw_window.ptr, Some(on_refresh)); - //glfw::ffi::glfwSetFramebufferSizeCallback(self.glfw_window.ptr, Some(on_framebuffer_size)); - //g_nested_event_loop_listener = Some(listener) + listener: *mut NestedEventLoopListener + 'static) { + g_nested_event_loop_listener = Some(listener) } pub unsafe fn remove_nested_event_loop_listener(&self) { - // TODO: Support this with glutin - //glfw::ffi::glfwSetWindowRefreshCallback(self.glfw_window.ptr, None); - //glfw::ffi::glfwSetFramebufferSizeCallback(self.glfw_window.ptr, None); - //self.glfw_window.set_refresh_polling(true); - //g_nested_event_loop_listener = None + g_nested_event_loop_listener = None } pub fn wait_events(&self) -> WindowEvent { @@ -525,18 +543,22 @@ impl Window { struct GlutinCompositorProxy { sender: Sender, + window_proxy: Option, } impl CompositorProxy for GlutinCompositorProxy { fn send(&mut self, msg: compositor_task::Msg) { // Send a message and kick the OS event loop awake. self.sender.send(msg); - // TODO: Support this with glutin - //glfw::Glfw::post_empty_event() + match self.window_proxy { + Some(ref window_proxy) => window_proxy.wakeup_event_loop(), + None => {} + } } fn clone_compositor_proxy(&self) -> Box { box GlutinCompositorProxy { sender: self.sender.clone(), + window_proxy: self.window_proxy.clone(), } as Box } }