Introduce 'NullCompositor'.

This commit is contained in:
Tetsuharu OHZEKI 2013-12-17 20:06:05 +09:00
parent 513ff0259a
commit 56ba7fc343
2 changed files with 44 additions and 22 deletions

View file

@ -197,7 +197,8 @@ impl CompositorTask {
profiler_chan); profiler_chan);
} }
Headless => { Headless => {
run_headless::run_compositor(&constellation_chan, port); run_headless::NullCompositor::create(port,
constellation_chan.clone());
} }
} }

View file

@ -8,16 +8,36 @@ use geom::size::Size2D;
use servo_msg::constellation_msg::{ConstellationChan, ResizedWindowMsg}; use servo_msg::constellation_msg::{ConstellationChan, ResizedWindowMsg};
use std::comm::Port; use std::comm::Port;
/// Starts the compositor, which listens for messages on the specified port. /// Starts the compositor, which listens for messages on the specified port.
/// ///
/// This is the null compositor which doesn't draw anything to the screen. /// This is the null compositor which doesn't draw anything to the screen.
/// It's intended for headless testing. /// It's intended for headless testing.
pub fn run_compositor(constellation_chan: &ConstellationChan, port: Port<Msg>) { pub struct NullCompositor {
/// The port on which we receive messages.
port: Port<Msg>,
}
impl NullCompositor {
fn new(port: Port<Msg>) -> NullCompositor {
NullCompositor {
port: port
}
}
pub fn create(port: Port<Msg>, constellation_chan: ConstellationChan) {
let compositor = NullCompositor::new(port);
// Tell the constellation about the initial fake size. // Tell the constellation about the initial fake size.
constellation_chan.send(ResizedWindowMsg(Size2D(640u, 480u))); constellation_chan.send(ResizedWindowMsg(Size2D(640u, 480u)));
compositor.handle_message();
}
fn handle_message(&self) {
loop { loop {
match port.recv() { match self.port.recv() {
Exit => break, Exit => break,
GetGraphicsMetadata(chan) => { GetGraphicsMetadata(chan) => {
@ -38,4 +58,5 @@ pub fn run_compositor(constellation_chan: &ConstellationChan, port: Port<Msg>) {
=> () => ()
} }
} }
}
} }