mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Pass parameters directly to 'run_compositor()'.
This commit is contained in:
parent
43b3d7bcfe
commit
8487c02a39
3 changed files with 41 additions and 47 deletions
|
@ -153,31 +153,18 @@ pub enum CompositorMode {
|
||||||
|
|
||||||
pub struct CompositorTask {
|
pub struct CompositorTask {
|
||||||
mode: CompositorMode,
|
mode: CompositorMode,
|
||||||
opts: Opts,
|
|
||||||
port: Port<Msg>,
|
|
||||||
constellation_chan: ConstellationChan,
|
|
||||||
profiler_chan: ProfilerChan,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CompositorTask {
|
impl CompositorTask {
|
||||||
fn new(opts: Opts,
|
fn new(is_headless: bool) -> CompositorTask {
|
||||||
port: Port<Msg>,
|
let mode: CompositorMode = if is_headless {
|
||||||
constellation_chan: ConstellationChan,
|
|
||||||
profiler_chan: ProfilerChan)
|
|
||||||
-> CompositorTask {
|
|
||||||
|
|
||||||
let mode: CompositorMode = if opts.headless {
|
|
||||||
Headless
|
Headless
|
||||||
} else {
|
} else {
|
||||||
Windowed(ApplicationMethods::new())
|
Windowed(ApplicationMethods::new())
|
||||||
};
|
};
|
||||||
|
|
||||||
CompositorTask {
|
CompositorTask {
|
||||||
mode: mode,
|
mode: mode
|
||||||
opts: opts,
|
|
||||||
port: port,
|
|
||||||
constellation_chan: constellation_chan,
|
|
||||||
profiler_chan: profiler_chan
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,25 +186,26 @@ impl CompositorTask {
|
||||||
profiler_chan: ProfilerChan,
|
profiler_chan: ProfilerChan,
|
||||||
exit_chan: Chan<()>,
|
exit_chan: Chan<()>,
|
||||||
exit_response_from_constellation: Port<()>) {
|
exit_response_from_constellation: Port<()>) {
|
||||||
let compositor = CompositorTask::new(opts,
|
|
||||||
port,
|
|
||||||
constellation_chan,
|
|
||||||
profiler_chan);
|
|
||||||
compositor.run(exit_chan, exit_response_from_constellation);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn run(&self,
|
let compositor = CompositorTask::new(opts.headless);
|
||||||
exit_chan: Chan<()>,
|
|
||||||
exit_response_from_constellation: Port<()>) {
|
match compositor.mode {
|
||||||
match self.mode {
|
Windowed(ref app) => {
|
||||||
Windowed(ref app) => run::run_compositor(self, app),
|
run::run_compositor(app,
|
||||||
Headless => run_headless::run_compositor(self),
|
opts,
|
||||||
|
port,
|
||||||
|
&constellation_chan,
|
||||||
|
profiler_chan);
|
||||||
|
}
|
||||||
|
Headless => {
|
||||||
|
run_headless::run_compositor(&constellation_chan, port);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Constellation has to be shut down before the compositor goes out of
|
// Constellation has to be shut down before the compositor goes out of
|
||||||
// scope, as the compositor manages setup/teardown of global subsystems
|
// scope, as the compositor manages setup/teardown of global subsystems
|
||||||
debug!("shutting down the constellation");
|
debug!("shutting down the constellation");
|
||||||
self.constellation_chan.send(ExitMsg(exit_chan));
|
constellation_chan.send(ExitMsg(exit_chan));
|
||||||
exit_response_from_constellation.recv();
|
exit_response_from_constellation.recv();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ use geom::matrix::identity;
|
||||||
use geom::point::Point2D;
|
use geom::point::Point2D;
|
||||||
use geom::rect::Rect;
|
use geom::rect::Rect;
|
||||||
use geom::size::Size2D;
|
use geom::size::Size2D;
|
||||||
|
use gfx::opts::Opts;
|
||||||
use layers::layers::{ContainerLayer, ContainerLayerKind};
|
use layers::layers::{ContainerLayer, ContainerLayerKind};
|
||||||
use layers::rendergl;
|
use layers::rendergl;
|
||||||
use layers::scene::Scene;
|
use layers::scene::Scene;
|
||||||
|
@ -28,7 +29,7 @@ use png;
|
||||||
use servo_msg::compositor_msg::IdleRenderState;
|
use servo_msg::compositor_msg::IdleRenderState;
|
||||||
use servo_msg::constellation_msg::{ConstellationChan, NavigateMsg, ResizedWindowMsg, LoadUrlMsg};
|
use servo_msg::constellation_msg::{ConstellationChan, NavigateMsg, ResizedWindowMsg, LoadUrlMsg};
|
||||||
use servo_msg::constellation_msg;
|
use servo_msg::constellation_msg;
|
||||||
use servo_util::time::profile;
|
use servo_util::time::{profile, ProfilerChan};
|
||||||
use servo_util::{time, url};
|
use servo_util::{time, url};
|
||||||
use std::comm::Port;
|
use std::comm::Port;
|
||||||
use std::num::Orderable;
|
use std::num::Orderable;
|
||||||
|
@ -37,7 +38,11 @@ use std::rt::io::timer::Timer;
|
||||||
use std::vec;
|
use std::vec;
|
||||||
|
|
||||||
/// Starts the compositor, which listens for messages on the specified port.
|
/// Starts the compositor, which listens for messages on the specified port.
|
||||||
pub fn run_compositor(compositor: &CompositorTask, app: &Application) {
|
pub fn run_compositor(app: &Application,
|
||||||
|
opts: Opts,
|
||||||
|
port: Port<Msg>,
|
||||||
|
constellation_chan: &ConstellationChan,
|
||||||
|
profiler_chan: ProfilerChan) {
|
||||||
let window: @mut Window = WindowMethods::new(app);
|
let window: @mut Window = WindowMethods::new(app);
|
||||||
|
|
||||||
// Create an initial layer tree.
|
// Create an initial layer tree.
|
||||||
|
@ -63,7 +68,7 @@ pub fn run_compositor(compositor: &CompositorTask, app: &Application) {
|
||||||
|
|
||||||
// The root CompositorLayer
|
// The root CompositorLayer
|
||||||
let mut compositor_layer: Option<CompositorLayer> = None;
|
let mut compositor_layer: Option<CompositorLayer> = None;
|
||||||
let mut constellation_chan: ConstellationChan = compositor.constellation_chan.clone();
|
let mut constellation_chan: ConstellationChan = constellation_chan.clone();
|
||||||
|
|
||||||
// Get BufferRequests from each layer.
|
// Get BufferRequests from each layer.
|
||||||
let ask_for_tiles = || {
|
let ask_for_tiles = || {
|
||||||
|
@ -112,9 +117,9 @@ pub fn run_compositor(compositor: &CompositorTask, app: &Application) {
|
||||||
}
|
}
|
||||||
|
|
||||||
let layer = CompositorLayer::from_frame_tree(frame_tree,
|
let layer = CompositorLayer::from_frame_tree(frame_tree,
|
||||||
compositor.opts.tile_size,
|
opts.tile_size,
|
||||||
Some(10000000u),
|
Some(10000000u),
|
||||||
compositor.opts.cpu_painting);
|
opts.cpu_painting);
|
||||||
root_layer.add_child_start(ContainerLayerKind(layer.root_layer));
|
root_layer.add_child_start(ContainerLayerKind(layer.root_layer));
|
||||||
|
|
||||||
// If there's already a root layer, destroy it cleanly.
|
// If there's already a root layer, destroy it cleanly.
|
||||||
|
@ -147,9 +152,9 @@ pub fn run_compositor(compositor: &CompositorTask, app: &Application) {
|
||||||
let page_size = Size2D(new_size.width as f32, new_size.height as f32);
|
let page_size = Size2D(new_size.width as f32, new_size.height as f32);
|
||||||
let new_layer = CompositorLayer::new(p,
|
let new_layer = CompositorLayer::new(p,
|
||||||
Some(page_size),
|
Some(page_size),
|
||||||
compositor.opts.tile_size,
|
opts.tile_size,
|
||||||
Some(10000000u),
|
Some(10000000u),
|
||||||
compositor.opts.cpu_painting);
|
opts.cpu_painting);
|
||||||
|
|
||||||
let current_child = root_layer.first_child;
|
let current_child = root_layer.first_child;
|
||||||
// This assumes there is at most one child, which should be the case.
|
// This assumes there is at most one child, which should be the case.
|
||||||
|
@ -331,7 +336,7 @@ pub fn run_compositor(compositor: &CompositorTask, app: &Application) {
|
||||||
}
|
}
|
||||||
|
|
||||||
FinishedWindowEvent => {
|
FinishedWindowEvent => {
|
||||||
if compositor.opts.exit_after_load {
|
if opts.exit_after_load {
|
||||||
done = true;
|
done = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -343,9 +348,9 @@ pub fn run_compositor(compositor: &CompositorTask, app: &Application) {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
let profiler_chan = compositor.profiler_chan.clone();
|
let profiler_chan = profiler_chan.clone();
|
||||||
let write_png = compositor.opts.output_file.is_some();
|
let write_png = opts.output_file.is_some();
|
||||||
let exit = compositor.opts.exit_after_load;
|
let exit = opts.exit_after_load;
|
||||||
let composite = || {
|
let composite = || {
|
||||||
do profile(time::CompositingCategory, profiler_chan.clone()) {
|
do profile(time::CompositingCategory, profiler_chan.clone()) {
|
||||||
debug!("compositor: compositing");
|
debug!("compositor: compositing");
|
||||||
|
@ -368,7 +373,7 @@ pub fn run_compositor(compositor: &CompositorTask, app: &Application) {
|
||||||
// window.present()) as OpenGL ES 2 does not have glReadBuffer().
|
// window.present()) as OpenGL ES 2 does not have glReadBuffer().
|
||||||
if write_png {
|
if write_png {
|
||||||
let (width, height) = (window_size.width as uint, window_size.height as uint);
|
let (width, height) = (window_size.width as uint, window_size.height as uint);
|
||||||
let path = from_str::<Path>(*compositor.opts.output_file.get_ref()).unwrap();
|
let path = from_str::<Path>(*opts.output_file.get_ref()).unwrap();
|
||||||
let mut pixels = gl2::read_pixels(0, 0,
|
let mut pixels = gl2::read_pixels(0, 0,
|
||||||
width as gl2::GLsizei,
|
width as gl2::GLsizei,
|
||||||
height as gl2::GLsizei,
|
height as gl2::GLsizei,
|
||||||
|
@ -407,7 +412,7 @@ pub fn run_compositor(compositor: &CompositorTask, app: &Application) {
|
||||||
let mut tm = Timer::new().unwrap();
|
let mut tm = Timer::new().unwrap();
|
||||||
while !done {
|
while !done {
|
||||||
// Check for new messages coming from the rendering task.
|
// Check for new messages coming from the rendering task.
|
||||||
check_for_messages(&compositor.port);
|
check_for_messages(&port);
|
||||||
|
|
||||||
// Check for messages coming from the windowing system.
|
// Check for messages coming from the windowing system.
|
||||||
check_for_window_messages(window.recv());
|
check_for_window_messages(window.recv());
|
||||||
|
@ -436,5 +441,5 @@ pub fn run_compositor(compositor: &CompositorTask, app: &Application) {
|
||||||
|
|
||||||
// Drain compositor port, sometimes messages contain channels that are blocking
|
// Drain compositor port, sometimes messages contain channels that are blocking
|
||||||
// another task from finishing (i.e. SetIds)
|
// another task from finishing (i.e. SetIds)
|
||||||
while compositor.port.peek() { compositor.port.recv(); }
|
while port.peek() { port.recv(); }
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,18 +5,19 @@
|
||||||
use compositing::*;
|
use compositing::*;
|
||||||
|
|
||||||
use geom::size::Size2D;
|
use geom::size::Size2D;
|
||||||
use servo_msg::constellation_msg::ResizedWindowMsg;
|
use servo_msg::constellation_msg::{ConstellationChan, ResizedWindowMsg};
|
||||||
|
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(compositor: &CompositorTask) {
|
pub fn run_compositor(constellation_chan: &ConstellationChan, port: Port<Msg>) {
|
||||||
// Tell the constellation about the initial fake size.
|
// Tell the constellation about the initial fake size.
|
||||||
compositor.constellation_chan.send(ResizedWindowMsg(Size2D(640u, 480u)));
|
constellation_chan.send(ResizedWindowMsg(Size2D(640u, 480u)));
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match compositor.port.recv() {
|
match port.recv() {
|
||||||
Exit => break,
|
Exit => break,
|
||||||
|
|
||||||
GetGraphicsMetadata(chan) => {
|
GetGraphicsMetadata(chan) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue