diff --git a/src/components/main/compositing/mod.rs b/src/components/main/compositing/mod.rs index d22258170c1..3ed53a47e40 100644 --- a/src/components/main/compositing/mod.rs +++ b/src/components/main/compositing/mod.rs @@ -197,7 +197,8 @@ impl CompositorTask { profiler_chan); } Headless => { - run_headless::run_compositor(&constellation_chan, port); + run_headless::NullCompositor::create(port, + constellation_chan.clone()); } } diff --git a/src/components/main/compositing/run_headless.rs b/src/components/main/compositing/run_headless.rs index 0d663aeb580..4ec179c7e05 100644 --- a/src/components/main/compositing/run_headless.rs +++ b/src/components/main/compositing/run_headless.rs @@ -8,34 +8,55 @@ use geom::size::Size2D; use servo_msg::constellation_msg::{ConstellationChan, ResizedWindowMsg}; use std::comm::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. /// It's intended for headless testing. -pub fn run_compositor(constellation_chan: &ConstellationChan, port: Port) { - // Tell the constellation about the initial fake size. - constellation_chan.send(ResizedWindowMsg(Size2D(640u, 480u))); +pub struct NullCompositor { + /// The port on which we receive messages. + port: Port, +} - loop { - match port.recv() { - Exit => break, +impl NullCompositor { - GetGraphicsMetadata(chan) => { - chan.send(None); + fn new(port: Port) -> NullCompositor { + + NullCompositor { + port: port + } + } + + pub fn create(port: Port, constellation_chan: ConstellationChan) { + let compositor = NullCompositor::new(port); + + // Tell the constellation about the initial fake size. + constellation_chan.send(ResizedWindowMsg(Size2D(640u, 480u))); + compositor.handle_message(); + } + + fn handle_message(&self) { + loop { + match self.port.recv() { + Exit => break, + + GetGraphicsMetadata(chan) => { + chan.send(None); + } + + SetIds(_, response_chan, _) => { + response_chan.send(()); + } + + // Explicitly list ignored messages so that when we add a new one, + // we'll notice and think about whether it needs a response, like + // SetIds. + + NewLayer(*) | SetLayerPageSize(*) | SetLayerClipRect(*) | DeleteLayer(*) | + Paint(*) | InvalidateRect(*) | ChangeReadyState(*) | ChangeRenderState(*)| + ScrollFragmentPoint(*) | SetUnRenderedColor(*) + => () } - - SetIds(_, response_chan, _) => { - response_chan.send(()); - } - - // Explicitly list ignored messages so that when we add a new one, - // we'll notice and think about whether it needs a response, like - // SetIds. - - NewLayer(*) | SetLayerPageSize(*) | SetLayerClipRect(*) | DeleteLayer(*) | - Paint(*) | InvalidateRect(*) | ChangeReadyState(*) | ChangeRenderState(*)| - ScrollFragmentPoint(*) | SetUnRenderedColor(*) - => () } } }