Introduce InitialPipelineState

This commit is contained in:
Anthony Ramine 2015-09-15 23:14:56 +02:00
parent 5cf8d597e6
commit 7d140113e7
2 changed files with 79 additions and 56 deletions

View file

@ -9,7 +9,7 @@
//! navigation context, each `Pipeline` encompassing a `ScriptTask`, //! navigation context, each `Pipeline` encompassing a `ScriptTask`,
//! `LayoutTask`, and `PaintTask`. //! `LayoutTask`, and `PaintTask`.
use pipeline::{Pipeline, CompositionPipeline}; use pipeline::{Pipeline, CompositionPipeline, InitialPipelineState};
use canvas::canvas_paint_task::CanvasPaintTask; use canvas::canvas_paint_task::CanvasPaintTask;
use canvas::webgl_paint_task::WebGLPaintTask; use canvas::webgl_paint_task::WebGLPaintTask;
@ -296,21 +296,23 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
let spawning_paint_only = script_channel.is_some(); let spawning_paint_only = script_channel.is_some();
let (pipeline, mut pipeline_content) = let (pipeline, mut pipeline_content) =
Pipeline::create::<LTF, STF>(pipeline_id, Pipeline::create::<LTF, STF>(InitialPipelineState {
parent_info, id: pipeline_id,
self.chan.clone(), parent_info: parent_info,
self.compositor_proxy.clone_compositor_proxy(), constellation_chan: self.chan.clone(),
self.devtools_chan.clone(), compositor_proxy: self.compositor_proxy.clone_compositor_proxy(),
self.image_cache_task.clone(), devtools_chan: self.devtools_chan.clone(),
self.font_cache_task.clone(), image_cache_task: self.image_cache_task.clone(),
self.resource_task.clone(), font_cache_task: self.font_cache_task.clone(),
self.storage_task.clone(), resource_task: self.resource_task.clone(),
self.time_profiler_chan.clone(), storage_task: self.storage_task.clone(),
self.mem_profiler_chan.clone(), time_profiler_chan: self.time_profiler_chan.clone(),
initial_window_rect, mem_profiler_chan: self.mem_profiler_chan.clone(),
script_channel, window_rect: initial_window_rect,
load_data, script_chan: script_channel,
self.window_size.device_pixel_ratio); load_data: load_data,
device_pixel_ratio: self.window_size.device_pixel_ratio,
});
// TODO(pcwalton): In multiprocess mode, send that `PipelineContent` instance over to // TODO(pcwalton): In multiprocess mode, send that `PipelineContent` instance over to
// the content process and call this over there. // the content process and call this over there.

View file

@ -63,25 +63,46 @@ pub struct CompositionPipeline {
pub chrome_to_paint_chan: Sender<ChromeToPaintMsg>, pub chrome_to_paint_chan: Sender<ChromeToPaintMsg>,
} }
/// Initial setup data needed to construct a pipeline.
pub struct InitialPipelineState {
/// The ID of the pipeline to create.
pub id: PipelineId,
/// The subpage ID of this pipeline to create in its pipeline parent.
/// If `None`, this is the root.
pub parent_info: Option<(PipelineId, SubpageId)>,
/// A channel to the associated constellation.
pub constellation_chan: ConstellationChan,
/// A channel to the compositor.
pub compositor_proxy: Box<CompositorProxy + 'static + Send>,
/// A channel to the developer tools, if applicable.
pub devtools_chan: Option<Sender<DevtoolsControlMsg>>,
/// A channel to the image cache task.
pub image_cache_task: ImageCacheTask,
/// A channel to the font cache task.
pub font_cache_task: FontCacheTask,
/// A channel to the resource task.
pub resource_task: ResourceTask,
/// A channel to the storage task.
pub storage_task: StorageTask,
/// A channel to the time profiler thread.
pub time_profiler_chan: time::ProfilerChan,
/// A channel to the memory profiler thread.
pub mem_profiler_chan: profile_mem::ProfilerChan,
/// Information about the initial window size.
pub window_rect: Option<TypedRect<PagePx, f32>>,
/// Information about the device pixel ratio.
pub device_pixel_ratio: ScaleFactor<ViewportPx, DevicePixel, f32>,
/// A channel to the script thread, if applicable. If this is `Some`,
/// then `parent_info` must also be `Some`.
pub script_chan: Option<Sender<ConstellationControlMsg>>,
/// Information about the page to load.
pub load_data: LoadData,
}
impl Pipeline { impl Pipeline {
/// Starts a paint task, layout task, and possibly a script task. /// Starts a paint task, layout task, and possibly a script task.
/// Returns the channels wrapped in a struct. /// Returns the channels wrapped in a struct.
/// If script_pipeline is not None, then subpage_id must also be not None. pub fn create<LTF, STF>(state: InitialPipelineState)
pub fn create<LTF, STF>(id: PipelineId,
parent_info: Option<(PipelineId, SubpageId)>,
constellation_chan: ConstellationChan,
compositor_proxy: Box<CompositorProxy + 'static + Send>,
devtools_chan: Option<Sender<DevtoolsControlMsg>>,
image_cache_task: ImageCacheTask,
font_cache_task: FontCacheTask,
resource_task: ResourceTask,
storage_task: StorageTask,
time_profiler_chan: time::ProfilerChan,
mem_profiler_chan: profile_mem::ProfilerChan,
window_rect: Option<TypedRect<PagePx, f32>>,
script_chan: Option<Sender<ConstellationControlMsg>>,
load_data: LoadData,
device_pixel_ratio: ScaleFactor<ViewportPx, DevicePixel, f32>)
-> (Pipeline, PipelineContent) -> (Pipeline, PipelineContent)
where LTF: LayoutTaskFactory, STF: ScriptTaskFactory { where LTF: LayoutTaskFactory, STF: ScriptTaskFactory {
let (layout_to_paint_chan, layout_to_paint_port) = util::ipc::optional_ipc_channel(); let (layout_to_paint_chan, layout_to_paint_port) = util::ipc::optional_ipc_channel();
@ -92,20 +113,20 @@ impl Pipeline {
let mut pipeline_port = Some(pipeline_port); let mut pipeline_port = Some(pipeline_port);
let failure = Failure { let failure = Failure {
pipeline_id: id, pipeline_id: state.id,
parent_info: parent_info, parent_info: state.parent_info,
}; };
let window_size = window_rect.map(|rect| { let window_size = state.window_rect.map(|rect| {
WindowSizeData { WindowSizeData {
visible_viewport: rect.size, visible_viewport: rect.size,
initial_viewport: rect.size * ScaleFactor::new(1.0), initial_viewport: rect.size * ScaleFactor::new(1.0),
device_pixel_ratio: device_pixel_ratio, device_pixel_ratio: state.device_pixel_ratio,
} }
}); });
// Route messages coming from content to devtools as appropriate. // Route messages coming from content to devtools as appropriate.
let script_to_devtools_chan = devtools_chan.as_ref().map(|devtools_chan| { let script_to_devtools_chan = state.devtools_chan.as_ref().map(|devtools_chan| {
let (script_to_devtools_chan, script_to_devtools_port) = ipc::channel().unwrap(); let (script_to_devtools_chan, script_to_devtools_port) = ipc::channel().unwrap();
let devtools_chan = (*devtools_chan).clone(); let devtools_chan = (*devtools_chan).clone();
ROUTER.add_route(script_to_devtools_port.to_opaque(), box move |message| { ROUTER.add_route(script_to_devtools_port.to_opaque(), box move |message| {
@ -115,15 +136,15 @@ impl Pipeline {
script_to_devtools_chan script_to_devtools_chan
}); });
let (script_chan, script_port) = match script_chan { let (script_chan, script_port) = match state.script_chan {
Some(script_chan) => { Some(script_chan) => {
let (containing_pipeline_id, subpage_id) = let (containing_pipeline_id, subpage_id) =
parent_info.expect("script_pipeline != None but subpage_id == None"); state.parent_info.expect("script_pipeline != None but subpage_id == None");
let new_layout_info = NewLayoutInfo { let new_layout_info = NewLayoutInfo {
containing_pipeline_id: containing_pipeline_id, containing_pipeline_id: containing_pipeline_id,
new_pipeline_id: id, new_pipeline_id: state.id,
subpage_id: subpage_id, subpage_id: subpage_id,
load_data: load_data.clone(), load_data: state.load_data.clone(),
paint_chan: box layout_to_paint_chan.clone() as Box<Any + Send>, paint_chan: box layout_to_paint_chan.clone() as Box<Any + Send>,
failure: failure, failure: failure,
pipeline_port: mem::replace(&mut pipeline_port, None).unwrap(), pipeline_port: mem::replace(&mut pipeline_port, None).unwrap(),
@ -140,31 +161,31 @@ impl Pipeline {
} }
}; };
let pipeline = Pipeline::new(id, let pipeline = Pipeline::new(state.id,
parent_info, state.parent_info,
script_chan.clone(), script_chan.clone(),
LayoutControlChan(pipeline_chan), LayoutControlChan(pipeline_chan),
chrome_to_paint_chan.clone(), chrome_to_paint_chan.clone(),
layout_shutdown_port, layout_shutdown_port,
paint_shutdown_port, paint_shutdown_port,
load_data.url.clone(), state.load_data.url.clone(),
window_rect); state.window_rect);
let pipeline_content = PipelineContent { let pipeline_content = PipelineContent {
id: id, id: state.id,
parent_info: parent_info, parent_info: state.parent_info,
constellation_chan: constellation_chan, constellation_chan: state.constellation_chan,
compositor_proxy: compositor_proxy, compositor_proxy: state.compositor_proxy,
devtools_chan: script_to_devtools_chan, devtools_chan: script_to_devtools_chan,
image_cache_task: image_cache_task, image_cache_task: state.image_cache_task,
font_cache_task: font_cache_task, font_cache_task: state.font_cache_task,
resource_task: resource_task, resource_task: state.resource_task,
storage_task: storage_task, storage_task: state.storage_task,
time_profiler_chan: time_profiler_chan, time_profiler_chan: state.time_profiler_chan,
mem_profiler_chan: mem_profiler_chan, mem_profiler_chan: state.mem_profiler_chan,
window_size: window_size, window_size: window_size,
script_chan: script_chan, script_chan: script_chan,
load_data: load_data, load_data: state.load_data,
failure: failure, failure: failure,
script_port: script_port, script_port: script_port,
layout_to_paint_chan: layout_to_paint_chan, layout_to_paint_chan: layout_to_paint_chan,