compositing: Use an OptionalIpcSender for communication between the

layout and paint tasks.
This commit is contained in:
Patrick Walton 2015-07-27 14:06:03 -07:00
parent 3be5bbbaa3
commit 1ff7a51f0a
4 changed files with 26 additions and 9 deletions

View file

@ -29,7 +29,9 @@ use std::mem;
use std::sync::mpsc::{Receiver, Sender, channel};
use std::thread;
use url::Url;
use util;
use util::geometry::{PagePx, ViewportPx};
use util::ipc::OptionalIpcSender;
use util::opts;
/// A uniquely-identifiable pipeline of script task, layout task, and paint task.
@ -83,7 +85,7 @@ impl Pipeline {
device_pixel_ratio: ScaleFactor<ViewportPx, DevicePixel, f32>)
-> (Pipeline, PipelineContent)
where LTF: LayoutTaskFactory, STF:ScriptTaskFactory {
let (layout_to_paint_chan, layout_to_paint_port) = channel();
let (layout_to_paint_chan, layout_to_paint_port) = util::ipc::optional_ipc_channel();
let (chrome_to_paint_chan, chrome_to_paint_port) = channel();
let (paint_shutdown_chan, paint_shutdown_port) = channel();
let (layout_shutdown_chan, layout_shutdown_port) = channel();
@ -206,12 +208,12 @@ impl Pipeline {
}
pub fn grant_paint_permission(&self) {
drop(self.chrome_to_paint_chan.send(ChromeToPaintMsg::PaintPermissionGranted));
let _ = self.chrome_to_paint_chan.send(ChromeToPaintMsg::PaintPermissionGranted);
}
pub fn revoke_paint_permission(&self) {
debug!("pipeline revoking paint channel paint permission");
drop(self.chrome_to_paint_chan.send(ChromeToPaintMsg::PaintPermissionRevoked));
let _ = self.chrome_to_paint_chan.send(ChromeToPaintMsg::PaintPermissionRevoked);
}
pub fn exit(&self, exit_type: PipelineExitType) {
@ -300,7 +302,7 @@ pub struct PipelineContent {
load_data: LoadData,
failure: Failure,
script_port: Option<Receiver<ConstellationControlMsg>>,
layout_to_paint_chan: Sender<LayoutToPaintMsg>,
layout_to_paint_chan: OptionalIpcSender<LayoutToPaintMsg>,
chrome_to_paint_chan: Sender<ChromeToPaintMsg>,
layout_to_paint_port: Option<Receiver<LayoutToPaintMsg>>,
chrome_to_paint_port: Option<Receiver<ChromeToPaintMsg>>,

View file

@ -78,6 +78,7 @@ use style::stylesheets::{Origin, Stylesheet, CSSRuleIteratorExt};
use url::Url;
use util::cursor::Cursor;
use util::geometry::{Au, MAX_RECT, ZERO_POINT};
use util::ipc::OptionalIpcSender;
use util::logical_geometry::{LogicalPoint, WritingMode};
use util::mem::HeapSizeOf;
use util::opts;
@ -187,7 +188,7 @@ pub struct LayoutTask {
pub script_chan: ScriptControlChan,
/// The channel on which messages can be sent to the painting task.
pub paint_chan: Sender<LayoutToPaintMsg>,
pub paint_chan: OptionalIpcSender<LayoutToPaintMsg>,
/// The channel on which messages can be sent to the time profiler.
pub time_profiler_chan: time::ProfilerChan,
@ -227,7 +228,7 @@ impl LayoutTaskFactory for LayoutTask {
constellation_chan: ConstellationChan,
failure_msg: Failure,
script_chan: ScriptControlChan,
paint_chan: Sender<LayoutToPaintMsg>,
paint_chan: OptionalIpcSender<LayoutToPaintMsg>,
image_cache_task: ImageCacheTask,
font_cache_task: FontCacheTask,
time_profiler_chan: time::ProfilerChan,
@ -317,7 +318,7 @@ impl LayoutTask {
pipeline_port: IpcReceiver<LayoutControlMsg>,
constellation_chan: ConstellationChan,
script_chan: ScriptControlChan,
paint_chan: Sender<LayoutToPaintMsg>,
paint_chan: OptionalIpcSender<LayoutToPaintMsg>,
image_cache_task: ImageCacheTask,
font_cache_task: FontCacheTask,
time_profiler_chan: time::ProfilerChan,
@ -647,7 +648,7 @@ impl LayoutTask {
info.failure,
ScriptControlChan(info.script_chan.clone()),
*info.paint_chan
.downcast::<Sender<LayoutToPaintMsg>>()
.downcast::<OptionalIpcSender<LayoutToPaintMsg>>()
.unwrap(),
self.image_cache_task.clone(),
self.font_cache_task.clone(),

View file

@ -31,6 +31,7 @@ use net_traits::image_cache_task::ImageCacheTask;
use script_traits::{LayoutControlMsg, ScriptControlChan, OpaqueScriptLayoutChannel};
use std::sync::mpsc::Sender;
use url::Url;
use util::ipc::OptionalIpcSender;
/// A channel wrapper for constellation messages
#[derive(Clone, Deserialize, Serialize)]
@ -49,7 +50,7 @@ pub trait LayoutTaskFactory {
constellation_chan: ConstellationChan,
failure_msg: Failure,
script_chan: ScriptControlChan,
layout_to_paint_chan: Sender<LayoutToPaintMsg>,
layout_to_paint_chan: OptionalIpcSender<LayoutToPaintMsg>,
image_cache_task: ImageCacheTask,
font_cache_task: FontCacheTask,
time_profiler_chan: time::ProfilerChan,

View file

@ -34,6 +34,19 @@ impl<T> OptionalIpcSender<T> where T: Deserialize + Serialize + Send + Any {
}
}
impl<T> Clone for OptionalIpcSender<T> where T: Deserialize + Serialize + Send + Any {
fn clone(&self) -> OptionalIpcSender<T> {
match *self {
OptionalIpcSender::OutOfProcess(ref ipc_sender) => {
OptionalIpcSender::OutOfProcess((*ipc_sender).clone())
}
OptionalIpcSender::InProcess(ref sender) => {
OptionalIpcSender::InProcess((*sender).clone())
}
}
}
}
impl<T> Deserialize for OptionalIpcSender<T> where T: Deserialize + Serialize + Send + Any {
fn deserialize<D>(deserializer: &mut D)
-> Result<OptionalIpcSender<T>,D::Error> where D: Deserializer {