From b85adf8b3545524f1c8515cb3f93bd8737a987ee Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Thu, 6 Nov 2014 17:11:40 -0800 Subject: [PATCH] Build fixes for Android windowing code This begins porting the Android event loop to work with the inverted flow control from #3761. Unfortunately, GLUT does not give us enough control over the event loop to really make this work, so this will build but it may not run properly. Our current plan is to get rid of GLUT and switch to Glutin in the near future. r? @pcwalton --- ports/android/glut_app/lib.rs | 6 +++-- ports/android/glut_app/window.rs | 45 ++++++++++++++++++++++++++------ 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/ports/android/glut_app/lib.rs b/ports/android/glut_app/lib.rs index 07eefc7132e..ab032d888e4 100644 --- a/ports/android/glut_app/lib.rs +++ b/ports/android/glut_app/lib.rs @@ -56,8 +56,10 @@ pub extern "C" fn android_start(argc: int, argv: *const *const u8) -> int { } if opts::from_cmdline_args(args.as_slice()) { - let window = Some(create_window()); - servo::run(window); + let window = create_window(); + let mut browser = servo::Browser::new(Some(window.clone())); + while browser.handle_event(window.wait_events()) {} + browser.shutdown(); } }) } diff --git a/ports/android/glut_app/window.rs b/ports/android/glut_app/window.rs index de5c7063eac..d2db495d8f7 100644 --- a/ports/android/glut_app/window.rs +++ b/ports/android/glut_app/window.rs @@ -4,6 +4,7 @@ //! A windowing implementation using GLUT. +use compositing::compositor_task::{mod, CompositorProxy, CompositorReceiver}; use compositing::windowing::{WindowEvent, WindowMethods}; use compositing::windowing::{IdleWindowEvent, ResizeWindowEvent, LoadUrlWindowEvent, MouseWindowEventClass}; use compositing::windowing::{ScrollWindowEvent, ZoomWindowEvent, NavigationWindowEvent, FinishedWindowEvent}; @@ -129,6 +130,17 @@ impl Window { wrapped_window } + + pub fn wait_events(&self) -> WindowEvent { + if !self.event_queue.borrow_mut().is_empty() { + return self.event_queue.borrow_mut().remove(0).unwrap(); + } + + // XXX: Need a function that blocks waiting for events, like glfwWaitEvents. + glut::check_loop(); + + self.event_queue.borrow_mut().remove(0).unwrap_or(IdleWindowEvent) + } } impl Drop for Window { @@ -153,14 +165,13 @@ impl WindowMethods for Window { glut::swap_buffers(); } - fn recv(&self) -> WindowEvent { - if !self.event_queue.borrow_mut().is_empty() { - return self.event_queue.borrow_mut().remove(0).unwrap(); - } - - glut::check_loop(); - - self.event_queue.borrow_mut().remove(0).unwrap_or(IdleWindowEvent) + fn create_compositor_channel(_: &Option>) + -> (Box, Box) { + let (sender, receiver) = channel(); + (box GlutCompositorProxy { + sender: sender, + } as Box, + box receiver as Box) } /// Sets the ready state. @@ -288,6 +299,24 @@ impl Window { } } +struct GlutCompositorProxy { + sender: Sender, +} + +impl CompositorProxy for GlutCompositorProxy { + fn send(&mut self, msg: compositor_task::Msg) { + // Send a message and kick the OS event loop awake. + self.sender.send(msg); + // XXX: Need a way to unblock wait_events, like glfwPostEmptyEvent + } + fn clone_compositor_proxy(&self) -> Box { + box GlutCompositorProxy { + sender: self.sender.clone(), + } as Box + } +} + + local_data_key!(TLS_KEY: Rc) fn install_local_window(window: Rc) {