mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
auto merge of #3925 : mbrubeck/servo/glut-loop, r=pcwalton
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
This commit is contained in:
commit
25e9830938
2 changed files with 41 additions and 10 deletions
|
@ -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();
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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<Rc<Window>>)
|
||||
-> (Box<CompositorProxy+Send>, Box<CompositorReceiver>) {
|
||||
let (sender, receiver) = channel();
|
||||
(box GlutCompositorProxy {
|
||||
sender: sender,
|
||||
} as Box<CompositorProxy+Send>,
|
||||
box receiver as Box<CompositorReceiver>)
|
||||
}
|
||||
|
||||
/// Sets the ready state.
|
||||
|
@ -288,6 +299,24 @@ impl Window {
|
|||
}
|
||||
}
|
||||
|
||||
struct GlutCompositorProxy {
|
||||
sender: Sender<compositor_task::Msg>,
|
||||
}
|
||||
|
||||
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<CompositorProxy+Send> {
|
||||
box GlutCompositorProxy {
|
||||
sender: self.sender.clone(),
|
||||
} as Box<CompositorProxy+Send>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
local_data_key!(TLS_KEY: Rc<Window>)
|
||||
|
||||
fn install_local_window(window: Rc<Window>) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue