Invert control flow, fix resizing, and improve checkerboarding

significantly by giving tiles some time to paint before we render
unrendered content.
This commit is contained in:
Patrick Walton 2014-10-19 09:23:18 -07:00
parent e483a189a3
commit 10f7b49cf7
27 changed files with 1195 additions and 678 deletions

View file

@ -30,10 +30,11 @@ extern crate native;
extern crate rustrt;
extern crate url;
use compositing::CompositorEventListener;
use compositing::windowing::{WindowEvent, WindowMethods};
#[cfg(not(test))]
use compositing::{CompositorChan, CompositorTask, Constellation};
#[cfg(not(test))]
use compositing::windowing::WindowMethods;
use compositing::{CompositorProxy, CompositorTask, Constellation};
#[cfg(not(test))]
use servo_msg::constellation_msg::{ConstellationChan, InitLoadUrlMsg};
#[cfg(not(test))]
@ -63,77 +64,105 @@ use std::rc::Rc;
#[cfg(not(test))]
use std::task::TaskBuilder;
#[cfg(not(test))]
pub fn run<Window: WindowMethods>(window: Option<Rc<Window>>) {
::servo_util::opts::set_experimental_enabled(opts::get().enable_experimental);
let opts = opts::get();
RegisterBindings::RegisterProxyHandlers();
pub struct Browser<Window> {
pool: green::SchedPool,
compositor: Box<CompositorEventListener + 'static>,
}
let mut pool_config = green::PoolConfig::new();
pool_config.event_loop_factory = rustuv::event_loop;
let mut pool = green::SchedPool::new(pool_config);
impl<Window> Browser<Window> where Window: WindowMethods + 'static {
#[cfg(not(test))]
pub fn new(window: Option<Rc<Window>>) -> Browser<Window> {
::servo_util::opts::set_experimental_enabled(opts::get().enable_experimental);
let opts = opts::get();
RegisterBindings::RegisterProxyHandlers();
let (compositor_port, compositor_chan) = CompositorChan::new();
let time_profiler_chan = TimeProfiler::create(opts.time_profiler_period);
let memory_profiler_chan = MemoryProfiler::create(opts.memory_profiler_period);
let devtools_chan = opts.devtools_port.map(|port| {
devtools::start_server(port)
});
let mut pool_config = green::PoolConfig::new();
pool_config.event_loop_factory = rustuv::event_loop;
let mut pool = green::SchedPool::new(pool_config);
let shared_task_pool = TaskPool::new(8);
let time_profiler_chan_clone = time_profiler_chan.clone();
let shared_task_pool = TaskPool::new(8);
let (compositor_proxy, compositor_receiver) =
WindowMethods::create_compositor_channel(&window);
let time_profiler_chan = TimeProfiler::create(opts.time_profiler_period);
let memory_profiler_chan = MemoryProfiler::create(opts.memory_profiler_period);
let devtools_chan = opts.devtools_port.map(|port| {
devtools::start_server(port)
});
let (result_chan, result_port) = channel();
TaskBuilder::new()
.green(&mut pool)
.spawn(proc() {
// Create a Servo instance.
let resource_task = new_resource_task(opts.user_agent.clone());
// If we are emitting an output file, then we need to block on
// image load or we risk emitting an output file missing the
// image.
let image_cache_task = if opts.output_file.is_some() {
let opts_clone = opts.clone();
let time_profiler_chan_clone = time_profiler_chan.clone();
let (result_chan, result_port) = channel();
let compositor_proxy_for_constellation = compositor_proxy.clone_compositor_proxy();
TaskBuilder::new()
.green(&mut pool)
.spawn(proc() {
let opts = &opts_clone;
// Create a Servo instance.
let resource_task = new_resource_task(opts.user_agent.clone());
// If we are emitting an output file, then we need to block on
// image load or we risk emitting an output file missing the
// image.
let image_cache_task = if opts.output_file.is_some() {
ImageCacheTask::new_sync(resource_task.clone(), shared_task_pool)
} else {
ImageCacheTask::new(resource_task.clone(), shared_task_pool)
};
let font_cache_task = FontCacheTask::new(resource_task.clone());
let constellation_chan = Constellation::<layout::layout_task::LayoutTask,
script::script_task::ScriptTask>::start(
compositor_chan,
resource_task,
image_cache_task,
font_cache_task,
time_profiler_chan_clone,
devtools_chan);
let font_cache_task = FontCacheTask::new(resource_task.clone());
let constellation_chan = Constellation::<layout::layout_task::LayoutTask,
script::script_task::ScriptTask>::start(
compositor_proxy_for_constellation,
resource_task,
image_cache_task,
font_cache_task,
time_profiler_chan_clone,
devtools_chan);
// Send the URL command to the constellation.
let cwd = os::getcwd();
for url in opts.urls.iter() {
let url = match url::Url::parse(url.as_slice()) {
Ok(url) => url,
Err(url::RelativeUrlWithoutBase)
=> url::Url::from_file_path(&cwd.join(url.as_slice())).unwrap(),
Err(_) => fail!("URL parsing failed"),
};
// Send the URL command to the constellation.
let cwd = os::getcwd();
for url in opts.urls.iter() {
let url = match url::Url::parse(url.as_slice()) {
Ok(url) => url,
Err(url::RelativeUrlWithoutBase)
=> url::Url::from_file_path(&cwd.join(url.as_slice())).unwrap(),
Err(_) => fail!("URL parsing failed"),
};
let ConstellationChan(ref chan) = constellation_chan;
chan.send(InitLoadUrlMsg(url));
let ConstellationChan(ref chan) = constellation_chan;
chan.send(InitLoadUrlMsg(url));
}
// Send the constallation Chan as the result
result_chan.send(constellation_chan);
});
let constellation_chan = result_port.recv();
debug!("preparing to enter main loop");
let compositor = CompositorTask::create(window,
compositor_proxy,
compositor_receiver,
constellation_chan,
time_profiler_chan,
memory_profiler_chan);
Browser {
pool: pool,
compositor: compositor,
}
}
// Send the constallation Chan as the result
result_chan.send(constellation_chan);
});
pub fn handle_event(&mut self, event: WindowEvent) -> bool {
self.compositor.handle_event(event)
}
let constellation_chan = result_port.recv();
pub fn repaint_synchronously(&mut self) {
self.compositor.repaint_synchronously()
}
debug!("preparing to enter main loop");
CompositorTask::create(window,
compositor_port,
constellation_chan,
time_profiler_chan,
memory_profiler_chan);
pool.shutdown();
pub fn shutdown(mut self) {
self.compositor.shutdown();
self.pool.shutdown();
}
}

View file

@ -9,10 +9,13 @@
extern crate servo;
extern crate native;
extern crate time;
extern crate "util" as servo_util;
#[cfg(not(test),not(target_os="android"))]
extern crate glfw_app;
#[cfg(not(test),not(target_os="android"))]
extern crate compositing;
#[cfg(not(test),not(target_os="android"))]
use servo_util::opts;
@ -21,11 +24,18 @@ use servo_util::opts;
use servo_util::rtinstrument;
#[cfg(not(test),not(target_os="android"))]
use servo::run;
use servo::Browser;
#[cfg(not(test),not(target_os="android"))]
use compositing::windowing::{IdleWindowEvent, ResizeWindowEvent, WindowEvent};
#[cfg(not(test),not(target_os="android"))]
use std::os;
#[cfg(not(test),not(target_os="android"))]
struct BrowserWrapper {
browser: Browser<glfw_app::window::Window>,
}
#[cfg(not(test), not(target_os="android"))]
#[start]
#[allow(dead_code)]
@ -37,7 +47,46 @@ fn start(argc: int, argv: *const *const u8) -> int {
} else {
Some(glfw_app::create_window())
};
run(window);
let mut browser = BrowserWrapper {
browser: Browser::new(window.clone()),
};
match window {
None => {}
Some(ref window) => {
unsafe {
window.set_nested_event_loop_listener(&mut browser);
}
}
}
loop {
let should_continue = match window {
None => browser.browser.handle_event(IdleWindowEvent),
Some(ref window) => {
let event = window.wait_events();
browser.browser.handle_event(event)
}
};
if !should_continue {
break
}
}
match window {
None => {}
Some(ref window) => {
unsafe {
window.remove_nested_event_loop_listener();
}
}
}
let BrowserWrapper {
browser
} = browser;
browser.shutdown();
rtinstrument::teardown();
}
@ -46,3 +95,21 @@ fn start(argc: int, argv: *const *const u8) -> int {
#[cfg(not(test), target_os="android")]
fn main() {}
#[cfg(not(test),not(target_os="android"))]
impl glfw_app::NestedEventLoopListener for BrowserWrapper {
fn handle_event_from_nested_event_loop(&mut self, event: WindowEvent) -> bool {
let is_resize = match event {
ResizeWindowEvent(..) => true,
_ => false,
};
if !self.browser.handle_event(event) {
return false
}
if is_resize {
self.browser.repaint_synchronously()
}
true
}
}