Auto merge of #7645 - nox:omtc-types, r=Ms2ger

Introduce structs for compositing and script task constructors' arguments

Extracted from @pcwalton's #4271.

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7645)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-09-16 10:41:10 -06:00
commit 2879da54f9
8 changed files with 255 additions and 242 deletions

View file

@ -3,7 +3,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use compositor_layer::{CompositorData, CompositorLayer, WantsScrollEventsFlag};
use compositor_task::{CompositorEventListener, CompositorProxy, CompositorReceiver, Msg};
use compositor_task::{CompositorEventListener, CompositorProxy};
use compositor_task::{CompositorReceiver, InitialCompositorState, Msg};
use constellation::SendableFrameTree;
use pipeline::CompositionPipeline;
use scrolling::ScrollingTimerProxy;
@ -248,23 +249,19 @@ pub fn reporter_name() -> String {
}
impl<Window: WindowMethods> IOCompositor<Window> {
fn new(window: Rc<Window>,
sender: Box<CompositorProxy + Send>,
receiver: Box<CompositorReceiver>,
constellation_chan: ConstellationChan,
time_profiler_chan: time::ProfilerChan,
mem_profiler_chan: mem::ProfilerChan)
fn new(window: Rc<Window>, state: InitialCompositorState)
-> IOCompositor<Window> {
// Register this thread as a memory reporter, via its own channel.
let (reporter_sender, reporter_receiver) = ipc::channel().unwrap();
let compositor_proxy_for_memory_reporter = sender.clone_compositor_proxy();
let compositor_proxy_for_memory_reporter = state.sender.clone_compositor_proxy();
ROUTER.add_route(reporter_receiver.to_opaque(), box move |reporter_request| {
let reporter_request: ReporterRequest = reporter_request.to().unwrap();
compositor_proxy_for_memory_reporter.send(Msg::CollectMemoryReports(
reporter_request.reports_channel));
});
let reporter = Reporter(reporter_sender);
mem_profiler_chan.send(mem::ProfilerMsg::RegisterReporter(reporter_name(), reporter));
state.mem_profiler_chan.send(
mem::ProfilerMsg::RegisterReporter(reporter_name(), reporter));
let window_size = window.framebuffer_size();
let hidpi_factor = window.hidpi_factor();
@ -276,7 +273,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
IOCompositor {
window: window,
native_display: native_display,
port: receiver,
port: state.receiver,
context: None,
root_pipeline: None,
pipeline_details: HashMap::new(),
@ -286,8 +283,8 @@ impl<Window: WindowMethods> IOCompositor<Window> {
}),
window_size: window_size,
hidpi_factor: hidpi_factor,
channel_to_self: sender.clone_compositor_proxy(),
scrolling_timer: ScrollingTimerProxy::new(sender),
channel_to_self: state.sender.clone_compositor_proxy(),
scrolling_timer: ScrollingTimerProxy::new(state.sender),
composition_request: CompositionRequest::NoCompositingNecessary,
pending_scroll_events: Vec::new(),
composite_target: composite_target,
@ -300,9 +297,9 @@ impl<Window: WindowMethods> IOCompositor<Window> {
zoom_time: 0f64,
got_load_complete_message: false,
frame_tree_id: FrameTreeId(0),
constellation_chan: constellation_chan,
time_profiler_chan: time_profiler_chan,
mem_profiler_chan: mem_profiler_chan,
constellation_chan: state.constellation_chan,
time_profiler_chan: state.time_profiler_chan,
mem_profiler_chan: state.mem_profiler_chan,
fragment_point: None,
last_composite_time: 0,
has_seen_quit_event: false,
@ -311,19 +308,9 @@ impl<Window: WindowMethods> IOCompositor<Window> {
}
}
pub fn create(window: Rc<Window>,
sender: Box<CompositorProxy + Send>,
receiver: Box<CompositorReceiver>,
constellation_chan: ConstellationChan,
time_profiler_chan: time::ProfilerChan,
mem_profiler_chan: mem::ProfilerChan)
pub fn create(window: Rc<Window>, state: InitialCompositorState)
-> IOCompositor<Window> {
let mut compositor = IOCompositor::new(window,
sender,
receiver,
constellation_chan,
time_profiler_chan,
mem_profiler_chan);
let mut compositor = IOCompositor::new(window, state);
// Set the size of the root layer.
compositor.update_zoom_transform();

View file

@ -260,28 +260,16 @@ pub struct CompositorTask;
impl CompositorTask {
pub fn create<Window>(window: Option<Rc<Window>>,
sender: Box<CompositorProxy + Send>,
receiver: Box<CompositorReceiver>,
constellation_chan: ConstellationChan,
time_profiler_chan: time::ProfilerChan,
mem_profiler_chan: mem::ProfilerChan)
state: InitialCompositorState)
-> Box<CompositorEventListener + 'static>
where Window: WindowMethods + 'static {
match window {
Some(window) => {
box compositor::IOCompositor::create(window,
sender,
receiver,
constellation_chan,
time_profiler_chan,
mem_profiler_chan)
box compositor::IOCompositor::create(window, state)
as Box<CompositorEventListener>
}
None => {
box headless::NullCompositor::create(receiver,
constellation_chan,
time_profiler_chan,
mem_profiler_chan)
box headless::NullCompositor::create(state)
as Box<CompositorEventListener>
}
}
@ -296,3 +284,17 @@ pub trait CompositorEventListener {
/// Requests that the compositor send the title for the main frame as soon as possible.
fn title_for_main_frame(&self);
}
/// Data used to construct a compositor.
pub struct InitialCompositorState {
/// A channel to the compositor.
pub sender: Box<CompositorProxy + Send>,
/// A port on which messages inbound to the compositor can be received.
pub receiver: Box<CompositorReceiver>,
/// A channel to the constellation.
pub constellation_chan: ConstellationChan,
/// A channel to the time profiler thread.
pub time_profiler_chan: time::ProfilerChan,
/// A channel to the memory profiler thread.
pub mem_profiler_chan: mem::ProfilerChan,
}

View file

@ -9,7 +9,7 @@
//! navigation context, each `Pipeline` encompassing a `ScriptTask`,
//! `LayoutTask`, and `PaintTask`.
use pipeline::{Pipeline, CompositionPipeline};
use pipeline::{Pipeline, CompositionPipeline, InitialPipelineState};
use canvas::canvas_paint_task::CanvasPaintTask;
use canvas::webgl_paint_task::WebGLPaintTask;
@ -139,6 +139,28 @@ pub struct Constellation<LTF, STF> {
webgl_paint_tasks: Vec<Sender<CanvasMsg>>,
}
/// State needed to construct a constellation.
pub struct InitialConstellationState {
/// A channel through which messages can be sent to the compositor.
pub compositor_proxy: Box<CompositorProxy + 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: mem::ProfilerChan,
/// Whether the constellation supports the clipboard.
pub supports_clipboard: bool,
}
/// Stores the navigation context for a single frame in the frame tree.
pub struct Frame {
prev: Vec<PipelineId>,
@ -219,28 +241,19 @@ enum ExitPipelineMode {
}
impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
pub fn start(compositor_proxy: Box<CompositorProxy + Send>,
resource_task: ResourceTask,
image_cache_task: ImageCacheTask,
font_cache_task: FontCacheTask,
time_profiler_chan: time::ProfilerChan,
mem_profiler_chan: mem::ProfilerChan,
devtools_chan: Option<Sender<DevtoolsControlMsg>>,
storage_task: StorageTask,
supports_clipboard: bool)
-> ConstellationChan {
pub fn start(state: InitialConstellationState) -> ConstellationChan {
let (constellation_port, constellation_chan) = ConstellationChan::new();
let constellation_chan_clone = constellation_chan.clone();
spawn_named("Constellation".to_owned(), move || {
let mut constellation: Constellation<LTF, STF> = Constellation {
chan: constellation_chan_clone,
request_port: constellation_port,
compositor_proxy: compositor_proxy,
devtools_chan: devtools_chan,
resource_task: resource_task,
image_cache_task: image_cache_task,
font_cache_task: font_cache_task,
storage_task: storage_task,
compositor_proxy: state.compositor_proxy,
devtools_chan: state.devtools_chan,
resource_task: state.resource_task,
image_cache_task: state.image_cache_task,
font_cache_task: state.font_cache_task,
storage_task: state.storage_task,
pipelines: HashMap::new(),
frames: HashMap::new(),
pipeline_to_frame_map: HashMap::new(),
@ -250,8 +263,8 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
root_frame_id: None,
next_frame_id: FrameId(0),
focus_pipeline_id: None,
time_profiler_chan: time_profiler_chan,
mem_profiler_chan: mem_profiler_chan,
time_profiler_chan: state.time_profiler_chan,
mem_profiler_chan: state.mem_profiler_chan,
window_size: WindowSizeData {
visible_viewport: opts::get().initial_window_size.as_f32() *
ScaleFactor::new(1.0),
@ -260,7 +273,7 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
device_pixel_ratio: ScaleFactor::new(1.0),
},
phantom: PhantomData,
clipboard_ctx: if supports_clipboard {
clipboard_ctx: if state.supports_clipboard {
ClipboardContext::new().ok()
} else {
None
@ -296,21 +309,23 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
let spawning_paint_only = script_channel.is_some();
let (pipeline, mut pipeline_content) =
Pipeline::create::<LTF, STF>(pipeline_id,
parent_info,
self.chan.clone(),
self.compositor_proxy.clone_compositor_proxy(),
self.devtools_chan.clone(),
self.image_cache_task.clone(),
self.font_cache_task.clone(),
self.resource_task.clone(),
self.storage_task.clone(),
self.time_profiler_chan.clone(),
self.mem_profiler_chan.clone(),
initial_window_rect,
script_channel,
load_data,
self.window_size.device_pixel_ratio);
Pipeline::create::<LTF, STF>(InitialPipelineState {
id: pipeline_id,
parent_info: parent_info,
constellation_chan: self.chan.clone(),
compositor_proxy: self.compositor_proxy.clone_compositor_proxy(),
devtools_chan: self.devtools_chan.clone(),
image_cache_task: self.image_cache_task.clone(),
font_cache_task: self.font_cache_task.clone(),
resource_task: self.resource_task.clone(),
storage_task: self.storage_task.clone(),
time_profiler_chan: self.time_profiler_chan.clone(),
mem_profiler_chan: self.mem_profiler_chan.clone(),
window_rect: initial_window_rect,
script_chan: script_channel,
load_data: load_data,
device_pixel_ratio: self.window_size.device_pixel_ratio,
});
// TODO(pcwalton): In multiprocess mode, send that `PipelineContent` instance over to
// the content process and call this over there.

View file

@ -2,7 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use compositor_task::{CompositorEventListener, CompositorReceiver, Msg};
use compositor_task::{CompositorEventListener, CompositorReceiver};
use compositor_task::{InitialCompositorState, Msg};
use windowing::WindowEvent;
use euclid::scale_factor::ScaleFactor;
@ -29,28 +30,17 @@ pub struct NullCompositor {
}
impl NullCompositor {
fn new(port: Box<CompositorReceiver>,
constellation_chan: ConstellationChan,
time_profiler_chan: time::ProfilerChan,
mem_profiler_chan: mem::ProfilerChan)
-> NullCompositor {
fn new(state: InitialCompositorState) -> NullCompositor {
NullCompositor {
port: port,
constellation_chan: constellation_chan,
time_profiler_chan: time_profiler_chan,
mem_profiler_chan: mem_profiler_chan,
port: state.receiver,
constellation_chan: state.constellation_chan,
time_profiler_chan: state.time_profiler_chan,
mem_profiler_chan: state.mem_profiler_chan,
}
}
pub fn create(port: Box<CompositorReceiver>,
constellation_chan: ConstellationChan,
time_profiler_chan: time::ProfilerChan,
mem_profiler_chan: mem::ProfilerChan)
-> NullCompositor {
let compositor = NullCompositor::new(port,
constellation_chan,
time_profiler_chan,
mem_profiler_chan);
pub fn create(state: InitialCompositorState) -> NullCompositor {
let compositor = NullCompositor::new(state);
// Tell the constellation about the initial fake size.
{

View file

@ -4,8 +4,8 @@
use CompositorProxy;
use layout_traits::{LayoutTaskFactory, LayoutControlChan};
use script_traits::{LayoutControlMsg, ScriptTaskFactory};
use script_traits::{NewLayoutInfo, ConstellationControlMsg};
use script_traits::{ConstellationControlMsg, InitialScriptState};
use script_traits::{LayoutControlMsg, NewLayoutInfo, ScriptTaskFactory};
use compositor_task;
use devtools_traits::{DevtoolsControlMsg, ScriptToDevtoolsControlMsg};
@ -63,25 +63,46 @@ pub struct CompositionPipeline {
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 {
/// Starts a paint task, layout task, and possibly a script task.
/// 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>(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>)
pub fn create<LTF, STF>(state: InitialPipelineState)
-> (Pipeline, PipelineContent)
where LTF: LayoutTaskFactory, STF: ScriptTaskFactory {
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 failure = Failure {
pipeline_id: id,
parent_info: parent_info,
pipeline_id: state.id,
parent_info: state.parent_info,
};
let window_size = window_rect.map(|rect| {
let window_size = state.window_rect.map(|rect| {
WindowSizeData {
visible_viewport: rect.size,
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.
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 devtools_chan = (*devtools_chan).clone();
ROUTER.add_route(script_to_devtools_port.to_opaque(), box move |message| {
@ -115,15 +136,15 @@ impl Pipeline {
script_to_devtools_chan
});
let (script_chan, script_port) = match script_chan {
let (script_chan, script_port) = match state.script_chan {
Some(script_chan) => {
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 {
containing_pipeline_id: containing_pipeline_id,
new_pipeline_id: id,
new_pipeline_id: state.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>,
failure: failure,
pipeline_port: mem::replace(&mut pipeline_port, None).unwrap(),
@ -140,31 +161,31 @@ impl Pipeline {
}
};
let pipeline = Pipeline::new(id,
parent_info,
let pipeline = Pipeline::new(state.id,
state.parent_info,
script_chan.clone(),
LayoutControlChan(pipeline_chan),
chrome_to_paint_chan.clone(),
layout_shutdown_port,
paint_shutdown_port,
load_data.url.clone(),
window_rect);
state.load_data.url.clone(),
state.window_rect);
let pipeline_content = PipelineContent {
id: id,
parent_info: parent_info,
constellation_chan: constellation_chan,
compositor_proxy: compositor_proxy,
id: state.id,
parent_info: state.parent_info,
constellation_chan: state.constellation_chan,
compositor_proxy: state.compositor_proxy,
devtools_chan: script_to_devtools_chan,
image_cache_task: image_cache_task,
font_cache_task: font_cache_task,
resource_task: resource_task,
storage_task: storage_task,
time_profiler_chan: time_profiler_chan,
mem_profiler_chan: mem_profiler_chan,
image_cache_task: state.image_cache_task,
font_cache_task: state.font_cache_task,
resource_task: state.resource_task,
storage_task: state.storage_task,
time_profiler_chan: state.time_profiler_chan,
mem_profiler_chan: state.mem_profiler_chan,
window_size: window_size,
script_chan: script_chan,
load_data: load_data,
load_data: state.load_data,
failure: failure,
script_port: script_port,
layout_to_paint_chan: layout_to_paint_chan,
@ -319,23 +340,22 @@ impl PipelineContent {
script_to_compositor_port)
});
ScriptTaskFactory::create(None::<&mut STF>,
self.id,
self.parent_info,
script_to_compositor_chan,
&layout_pair,
self.script_chan.clone(),
mem::replace(&mut self.script_port, None).unwrap(),
self.constellation_chan.clone(),
self.failure.clone(),
self.resource_task,
self.storage_task.clone(),
self.image_cache_task.clone(),
self.time_profiler_chan.clone(),
self.mem_profiler_chan.clone(),
self.devtools_chan,
self.window_size,
self.load_data.clone());
ScriptTaskFactory::create(None::<&mut STF>, InitialScriptState {
id: self.id,
parent_info: self.parent_info,
compositor: script_to_compositor_chan,
control_chan: self.script_chan.clone(),
control_port: mem::replace(&mut self.script_port, None).unwrap(),
constellation_chan: self.constellation_chan.clone(),
failure_info: self.failure.clone(),
resource_task: self.resource_task,
storage_task: self.storage_task.clone(),
image_cache_task: self.image_cache_task.clone(),
time_profiler_chan: self.time_profiler_chan.clone(),
mem_profiler_chan: self.mem_profiler_chan.clone(),
devtools_chan: self.devtools_chan,
window_size: self.window_size,
}, &layout_pair, self.load_data.clone());
LayoutTaskFactory::create(None::<&mut LTF>,
self.id,