Put the compositor on the main thread in the newrt way

This commit is contained in:
Brian Anderson 2013-08-14 16:32:57 -07:00 committed by Keegan McAllister
parent fb3db6a72d
commit c377ec7516
2 changed files with 47 additions and 59 deletions

View file

@ -191,24 +191,7 @@ impl CompositorTask {
}
/// Starts the compositor, which listens for messages on the specified port.
pub fn create(opts: Opts,
port: Port<Msg>,
profiler_chan: ProfilerChan,
shutdown_chan: Chan<()>) {
let port = Cell::new(port);
let shutdown_chan = Cell::new(shutdown_chan);
let opts = Cell::new(opts);
do on_osmain {
let compositor_task = CompositorTask::new(opts.take(),
port.take(),
profiler_chan.clone(),
shutdown_chan.take());
debug!("preparing to enter main loop");
compositor_task.run_main_loop();
};
}
fn run_main_loop(&self) {
pub fn run(&self) {
let app: Application = ApplicationMethods::new();
let window: @mut Window = WindowMethods::new(&app);
@ -508,17 +491,3 @@ impl CompositorTask {
self.shutdown_chan.send(())
}
}
/// A function for spawning into the platform's main thread.
fn on_osmain(f: ~fn()) {
// FIXME: rust#6399
let mut main_task = task::task();
/*
main_task.sched_mode(task::PlatformThread);
*/
fail!("stubbed out!");
do main_task.spawn {
f();
}
}

View file

@ -47,6 +47,7 @@ use servo_util::time::{Profiler, ProfilerChan, PrintMsg};
pub use gfx::opts::Opts;
pub use gfx::text;
pub use servo_util::url::make_url;
use std::cell::Cell;
use std::comm;
use std::os;
use std::rt::rtio::RtioTimer;
@ -95,15 +96,19 @@ pub mod platform;
#[path = "util/mod.rs"]
pub mod util;
fn main() {
run(&opts::from_cmdline_args(os::args()))
#[start]
fn start(argc: int, argv: **u8, crate_map: *u8) -> int {
do std::rt::start_on_main_thread(argc, argv, crate_map) {
let opts = opts::from_cmdline_args(os::args());
run(opts)
}
}
fn run(opts: &Opts) {
fn run(opts: Opts) {
let (shutdown_port, shutdown_chan) = comm::stream();
// Create the profiler channel.
let (profiler_port, profiler_chan) = comm::stream();
let (compositor_port, compositor_chan) = comm::stream();
let profiler_chan = ProfilerChan::new(profiler_chan);
Profiler::create(profiler_port);
do opts.profiler_period.map |&period| {
@ -117,34 +122,48 @@ fn run(opts: &Opts) {
}
}
};
// Create the compositor.
let (compositor_port, compositor_chan) = comm::stream();
let compositor_chan = CompositorChan::new(compositor_chan);
CompositorTask::create(opts.clone(), compositor_port, profiler_chan.clone(), shutdown_chan);
let profiler_chan_clone = profiler_chan.clone();
// Create a Servo instance.
let opts_clone = opts.clone();
let resource_task = ResourceTask();
let image_cache_task = ImageCacheTask(resource_task.clone());
let constellation_chan = Constellation::start(compositor_chan.clone(),
opts,
resource_task,
image_cache_task,
profiler_chan.clone());
do spawn {
let profiler_chan = profiler_chan_clone.clone();
let compositor_chan = compositor_chan.clone();
// Send the URL command to the constellation.
for filename in opts.urls.iter() {
constellation_chan.send(InitLoadUrlMsg(make_url(filename.clone(), None)))
let opts = &opts_clone.clone();
// Create a Servo instance.
let resource_task = ResourceTask();
let image_cache_task = ImageCacheTask(resource_task.clone());
let constellation_chan = Constellation::start(compositor_chan.clone(),
opts,
resource_task,
image_cache_task,
profiler_chan.clone());
// Send the URL command to the constellation.
for filename in opts.urls.iter() {
constellation_chan.send(InitLoadUrlMsg(make_url(filename.clone(), None)))
}
// Wait for the compositor to shut down.
shutdown_port.recv();
// Shut the constellation down.
debug!("master: Shut down");
let (exit_response_from_constellation, exit_chan) = comm::stream();
constellation_chan.send(ExitMsg(exit_chan));
exit_response_from_constellation.recv();
}
// Wait for the compositor to shut down.
shutdown_port.recv();
// Shut the constellation down.
debug!("master: Shut down");
let (exit_response_from_constellation, exit_chan) = comm::stream();
constellation_chan.send(ExitMsg(exit_chan));
exit_response_from_constellation.recv();
let compositor_task = CompositorTask::new(opts,
compositor_port,
profiler_chan,
shutdown_chan);
debug!("preparing to enter main loop");
compositor_task.run();
}