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,45 +406,36 @@ 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) = id: pipeline_id,
Pipeline::create::<LTF, STF>(InitialPipelineState { parent_info: parent_info,
id: pipeline_id, constellation_chan: self.script_sender.clone(),
parent_info: parent_info, layout_to_constellation_chan: self.layout_sender.clone(),
constellation_chan: self.script_sender.clone(), panic_chan: self.panic_sender.clone(),
layout_to_constellation_chan: self.layout_sender.clone(), scheduler_chan: self.scheduler_chan.clone(),
panic_chan: self.panic_sender.clone(), compositor_proxy: self.compositor_proxy.clone_compositor_proxy(),
scheduler_chan: self.scheduler_chan.clone(), devtools_chan: self.devtools_chan.clone(),
compositor_proxy: self.compositor_proxy.clone_compositor_proxy(), bluetooth_thread: self.bluetooth_thread.clone(),
devtools_chan: self.devtools_chan.clone(), image_cache_thread: self.image_cache_thread.clone(),
bluetooth_thread: self.bluetooth_thread.clone(), font_cache_thread: self.font_cache_thread.clone(),
image_cache_thread: self.image_cache_thread.clone(), resource_threads: self.resource_threads.clone(),
font_cache_thread: self.font_cache_thread.clone(), time_profiler_chan: self.time_profiler_chan.clone(),
resource_threads: self.resource_threads.clone(), mem_profiler_chan: self.mem_profiler_chan.clone(),
time_profiler_chan: self.time_profiler_chan.clone(), window_size: initial_window_size,
mem_profiler_chan: self.mem_profiler_chan.clone(), script_chan: script_channel,
window_size: initial_window_size, load_data: load_data,
script_chan: script_channel, device_pixel_ratio: self.window_size.device_pixel_ratio,
load_data: load_data, pipeline_namespace_id: self.next_pipeline_namespace_id(),
device_pixel_ratio: self.window_size.device_pixel_ratio, webrender_api_sender: self.webrender_api_sender.clone(),
pipeline_namespace_id: self.next_pipeline_namespace_id(), });
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,10 +120,8 @@ 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. -> (Pipeline, UnprivilegedPipelineContent, PrivilegedPipelineContent)
pub fn create<LTF, STF>(state: InitialPipelineState)
-> (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,