Introduce Pipeline::spawn().

This commit is contained in:
Ms2ger 2016-05-26 10:10:22 +02:00
parent 82832f134b
commit 739e091e8b
2 changed files with 59 additions and 42 deletions

View file

@ -406,9 +406,7 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
initial_window_size: Option<TypedSize2D<PagePx, f32>>, initial_window_size: Option<TypedSize2D<PagePx, f32>>,
script_channel: Option<IpcSender<ConstellationControlMsg>>, script_channel: Option<IpcSender<ConstellationControlMsg>>,
load_data: LoadData) { load_data: LoadData) {
let spawning_content = script_channel.is_none(); let result = Pipeline::spawn::<Message, LTF, STF>(InitialPipelineState {
let (pipeline, unprivileged_pipeline_content, privileged_pipeline_content) =
Pipeline::create::<LTF, STF>(InitialPipelineState {
id: pipeline_id, id: pipeline_id,
parent_info: parent_info, parent_info: parent_info,
constellation_chan: self.script_sender.clone(), constellation_chan: self.script_sender.clone(),
@ -431,20 +429,13 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
webrender_api_sender: self.webrender_api_sender.clone(), webrender_api_sender: self.webrender_api_sender.clone(),
}); });
privileged_pipeline_content.start(); let (pipeline, child_process) = match result {
Ok(result) => result,
Err(e) => return self.handle_send_error(pipeline_id, e),
};
if spawning_content { if let Some(child_process) = child_process {
// Spawn the child process. self.child_processes.push(child_process);
//
// Yes, that's all there is to it!
if opts::multiprocess() {
match unprivileged_pipeline_content.spawn_multiprocess() {
Ok(child_process) => self.child_processes.push(child_process),
Err(e) => self.handle_send_error(pipeline_id, e),
}
} else {
unprivileged_pipeline_content.start_all::<Message, LTF, STF>(false);
}
} }
assert!(!self.pipelines.contains_key(&pipeline_id)); assert!(!self.pipelines.contains_key(&pipeline_id));

View file

@ -120,9 +120,7 @@ pub struct InitialPipelineState {
} }
impl Pipeline { impl Pipeline {
/// Starts a paint thread, layout thread, and possibly a script thread. fn create<LTF, STF>(state: InitialPipelineState)
/// Returns the channels wrapped in a struct.
pub fn create<LTF, STF>(state: InitialPipelineState)
-> (Pipeline, UnprivilegedPipelineContent, PrivilegedPipelineContent) -> (Pipeline, UnprivilegedPipelineContent, PrivilegedPipelineContent)
where LTF: LayoutThreadFactory, where LTF: LayoutThreadFactory,
STF: ScriptThreadFactory STF: ScriptThreadFactory
@ -256,6 +254,34 @@ impl Pipeline {
(pipeline, unprivileged_pipeline_content, privileged_pipeline_content) (pipeline, unprivileged_pipeline_content, privileged_pipeline_content)
} }
/// Starts a paint thread, layout thread, and possibly a script thread, in
/// a new process if requested.
pub fn spawn<Message, LTF, STF>(state: InitialPipelineState)
-> Result<(Pipeline, Option<ChildProcess>), IOError>
where LTF: LayoutThreadFactory<Message=Message>,
STF: ScriptThreadFactory<Message=Message>
{
let spawning_content = state.script_chan.is_none();
let (pipeline, unprivileged_pipeline_content, privileged_pipeline_content) =
Pipeline::create::<LTF, STF>(state);
privileged_pipeline_content.start();
let mut child_process = None;
if spawning_content {
// Spawn the child process.
//
// Yes, that's all there is to it!
if opts::multiprocess() {
child_process = Some(try!(unprivileged_pipeline_content.spawn_multiprocess()));
} else {
unprivileged_pipeline_content.start_all::<Message, LTF, STF>(false);
}
}
Ok((pipeline, child_process))
}
fn new(id: PipelineId, fn new(id: PipelineId,
parent_info: Option<(PipelineId, SubpageId, FrameType)>, parent_info: Option<(PipelineId, SubpageId, FrameType)>,
script_chan: IpcSender<ConstellationControlMsg>, script_chan: IpcSender<ConstellationControlMsg>,
@ -520,7 +546,7 @@ impl UnprivilegedPipelineContent {
} }
} }
pub struct PrivilegedPipelineContent { struct PrivilegedPipelineContent {
id: PipelineId, id: PipelineId,
compositor_proxy: Box<CompositorProxy + Send + 'static>, compositor_proxy: Box<CompositorProxy + Send + 'static>,
font_cache_thread: FontCacheThread, font_cache_thread: FontCacheThread,