Skip to content

Commit

Permalink
Split paint task messages from ScriptMsg
Browse files Browse the repository at this point in the history
Refs: #8592
  • Loading branch information
g-k committed Nov 25, 2015
1 parent 6ab205a commit 7668fd0
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 15 deletions.
44 changes: 34 additions & 10 deletions components/compositing/constellation.rs
Expand Up @@ -27,6 +27,7 @@ use layout_traits::{LayoutControlChan, LayoutTaskFactory};
use msg::compositor_msg::Epoch;
use msg::constellation_msg::AnimationState;
use msg::constellation_msg::CompositorMsg as FromCompositorMsg;
use msg::constellation_msg::PaintMsg as FromPaintMsg;
use msg::constellation_msg::ScriptMsg as FromScriptMsg;
use msg::constellation_msg::WebDriverCommandMsg;
use msg::constellation_msg::{FrameId, PipelineId};
Expand Down Expand Up @@ -86,12 +87,18 @@ pub struct Constellation<LTF, STF> {
/// A channel through which compositor messages can be sent to this object.
pub compositor_sender: Sender<FromCompositorMsg>,

/// A channel through which paint task messages can be sent to this object.
pub painter_sender: ConstellationChan<FromPaintMsg>,

/// Receives messages from scripts.
pub script_receiver: Receiver<FromScriptMsg>,

/// Receives messages from the compositor
pub compositor_receiver: Receiver<FromCompositorMsg>,

/// Receives messages from paint task.
pub painter_receiver: Receiver<FromPaintMsg>,

/// A channel (the implementation of which is port-specific) through which messages can be sent
/// to the compositor.
pub compositor_proxy: Box<CompositorProxy>,
Expand Down Expand Up @@ -275,16 +282,19 @@ enum ChildProcess {
impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
pub fn start(state: InitialConstellationState) -> Sender<FromCompositorMsg> {
let (ipc_script_receiver, ipc_script_sender) = ConstellationChan::<FromScriptMsg>::new();
//let (script_receiver, script_sender) = channel();
let script_receiver = ROUTER.route_ipc_receiver_to_new_mpsc_receiver(ipc_script_receiver);
let (compositor_sender, compositor_receiver) = channel();
let (ipc_painter_receiver, ipc_painter_sender) = ConstellationChan::<FromPaintMsg>::new();
let painter_receiver = ROUTER.route_ipc_receiver_to_new_mpsc_receiver(ipc_painter_receiver);
let compositor_sender_clone = compositor_sender.clone();
spawn_named("Constellation".to_owned(), move || {
let mut constellation: Constellation<LTF, STF> = Constellation {
script_sender: ipc_script_sender,
compositor_sender: compositor_sender_clone,
painter_sender: ipc_painter_sender,
script_receiver: script_receiver,
compositor_receiver: compositor_receiver,
painter_receiver: painter_receiver,
compositor_proxy: state.compositor_proxy,
devtools_chan: state.devtools_chan,
resource_task: state.resource_task,
Expand Down Expand Up @@ -357,6 +367,7 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
id: pipeline_id,
parent_info: parent_info,
constellation_chan: self.script_sender.clone(),
painter_chan: self.painter_sender.clone(),
scheduler_chan: self.scheduler_chan.clone(),
compositor_proxy: self.compositor_proxy.clone_compositor_proxy(),
devtools_chan: self.devtools_chan.clone(),
Expand Down Expand Up @@ -458,17 +469,21 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
fn handle_request(&mut self) -> bool {
enum Request {
Script(FromScriptMsg),
Compositor(FromCompositorMsg)
Compositor(FromCompositorMsg),
Paint(FromPaintMsg)
}

let request = {
let receiver_from_script = &self.script_receiver;
let receiver_from_compositor = &self.compositor_receiver;
let receiver_from_paint = &self.painter_receiver;
select! {
msg = receiver_from_script.recv() =>
Request::Script(msg.unwrap()),
msg = receiver_from_compositor.recv() =>
Request::Compositor(msg.unwrap())
Request::Compositor(msg.unwrap()),
msg = receiver_from_paint.recv() =>
Request::Paint(msg.unwrap())
}
};

Expand Down Expand Up @@ -548,6 +563,7 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {


Request::Script(FromScriptMsg::Failure(Failure { pipeline_id, parent_info })) => {
debug!("handling script failure message from pipeline {:?}, {:?}", pipeline_id, parent_info);
self.handle_failure_msg(pipeline_id, parent_info);
}
Request::Script(FromScriptMsg::ScriptLoadedURLInIFrame(load_info)) => {
Expand Down Expand Up @@ -585,11 +601,6 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
debug!("constellation got navigation message from script");
self.handle_navigate_msg(pipeline_info, direction);
}
// Notification that painting has finished and is requesting permission to paint.
Request::Script(FromScriptMsg::PainterReady(pipeline_id)) => {
debug!("constellation got painter ready message");
self.handle_painter_ready_msg(pipeline_id);
}
Request::Script(FromScriptMsg::MozBrowserEvent(pipeline_id,
subpage_id,
event)) => {
Expand Down Expand Up @@ -647,6 +658,21 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
debug!("constellation got NodeStatus message");
self.compositor_proxy.send(ToCompositorMsg::Status(message));
}


// Messages from paint task


// Notification that painting has finished and is requesting permission to paint.
Request::Paint(FromPaintMsg::Ready(pipeline_id)) => {
debug!("constellation got painter ready message");
self.handle_painter_ready_msg(pipeline_id);
}
Request::Paint(FromPaintMsg::Failure(Failure { pipeline_id, parent_info })) => {
debug!("handling paint failure message from pipeline {:?}, {:?}", pipeline_id, parent_info);
self.handle_failure_msg(pipeline_id, parent_info);
}

}
true
}
Expand All @@ -669,8 +695,6 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
fn handle_failure_msg(&mut self,
pipeline_id: PipelineId,
parent_info: Option<(PipelineId, SubpageId)>) {
debug!("handling failure message from pipeline {:?}, {:?}", pipeline_id, parent_info);

if opts::get().hard_fail {
// It's quite difficult to make Servo exit cleanly if some tasks have failed.
// Hard fail exists for test runners so we crash and that's good enough.
Expand Down
7 changes: 6 additions & 1 deletion components/compositing/pipeline.rs
Expand Up @@ -15,6 +15,7 @@ use ipc_channel::router::ROUTER;
use layers::geometry::DevicePixel;
use layout_traits::{LayoutControlChan, LayoutTaskFactory};
use msg::compositor_msg::ScriptToCompositorMsg;
use msg::constellation_msg::PaintMsg;
use msg::constellation_msg::ScriptMsg as ConstellationMsg;
use msg::constellation_msg::{ConstellationChan, Failure, FrameId, PipelineId, SubpageId};
use msg::constellation_msg::{LoadData, MozBrowserEvent, WindowSizeData};
Expand Down Expand Up @@ -81,6 +82,8 @@ pub struct InitialPipelineState {
pub parent_info: Option<(PipelineId, SubpageId)>,
/// A channel to the associated constellation.
pub constellation_chan: ConstellationChan<ConstellationMsg>,
/// A channel to the associated paint task.
pub painter_chan: ConstellationChan<PaintMsg>,
/// A channel to schedule timer events.
pub scheduler_chan: IpcSender<TimerEventRequest>,
/// A channel to the compositor.
Expand Down Expand Up @@ -226,6 +229,7 @@ impl Pipeline {
let privileged_pipeline_content = PrivilegedPipelineContent {
id: state.id,
constellation_chan: state.constellation_chan,
painter_chan: state.painter_chan,
compositor_proxy: state.compositor_proxy,
font_cache_task: state.font_cache_task,
time_profiler_chan: state.time_profiler_chan,
Expand Down Expand Up @@ -429,6 +433,7 @@ impl UnprivilegedPipelineContent {
pub struct PrivilegedPipelineContent {
id: PipelineId,
constellation_chan: ConstellationChan<ConstellationMsg>,
painter_chan: ConstellationChan<PaintMsg>,
compositor_proxy: Box<CompositorProxy + Send + 'static>,
script_to_compositor_port: Option<IpcReceiver<ScriptToCompositorMsg>>,
font_cache_task: FontCacheTask,
Expand Down Expand Up @@ -464,7 +469,7 @@ impl PrivilegedPipelineContent {
mem::replace(&mut self.layout_to_paint_port, None).unwrap(),
mem::replace(&mut self.chrome_to_paint_port, None).unwrap(),
self.compositor_proxy.clone_compositor_proxy(),
self.constellation_chan.clone(),
self.painter_chan.clone(),
self.font_cache_task.clone(),
self.failure.clone(),
self.time_profiler_chan.clone(),
Expand Down
6 changes: 3 additions & 3 deletions components/gfx/paint_task.rs
Expand Up @@ -21,7 +21,7 @@ use layers::layers::{BufferRequest, LayerBuffer, LayerBufferSet};
use layers::platform::surface::{NativeDisplay, NativeSurface};
use msg::compositor_msg::{Epoch, FrameTreeId, LayerId, LayerKind, LayerProperties};
use msg::compositor_msg::{PaintListener, ScrollPolicy};
use msg::constellation_msg::ScriptMsg as ConstellationMsg;
use msg::constellation_msg::PaintMsg as ConstellationMsg;
use msg::constellation_msg::{ConstellationChan, Failure, PipelineId};
use paint_context::PaintContext;
use profile_traits::mem::{self, ReportsChan};
Expand Down Expand Up @@ -330,7 +330,7 @@ impl<C> PaintTask<C> where C: PaintListener + Send + 'static {
if !self.paint_permission {
debug!("PaintTask: paint ready msg");
let ConstellationChan(ref mut c) = self.constellation_chan;
c.send(ConstellationMsg::PainterReady(self.id)).unwrap();
c.send(ConstellationMsg::Ready(self.id)).unwrap();
continue;
}

Expand All @@ -345,7 +345,7 @@ impl<C> PaintTask<C> where C: PaintListener + Send + 'static {
if !self.paint_permission {
debug!("PaintTask: paint ready msg");
let ConstellationChan(ref mut c) = self.constellation_chan;
c.send(ConstellationMsg::PainterReady(self.id)).unwrap();
c.send(ConstellationMsg::Ready(self.id)).unwrap();
continue;
}

Expand Down
8 changes: 7 additions & 1 deletion components/msg/constellation_msg.rs
Expand Up @@ -294,7 +294,6 @@ pub enum ScriptMsg {
NewFavicon(Url),
/// Status message to be displayed in the chrome, eg. a link URL on mouseover.
NodeStatus(Option<String>),
PainterReady(PipelineId),
/// Notification that this iframe should be removed.
RemoveIFrame(PipelineId),
ScriptLoadedURLInIFrame(IframeLoadInfo),
Expand All @@ -306,6 +305,13 @@ pub enum ScriptMsg {
ViewportConstrained(PipelineId, ViewportConstraints),
}

/// Messages from the paint task to the constellation.
#[derive(Deserialize, Serialize)]
pub enum PaintMsg {
Ready(PipelineId),
Failure(Failure),
}

#[derive(Clone, Eq, PartialEq, Deserialize, Serialize, Debug)]
pub enum AnimationState {
AnimationsPresent,
Expand Down

0 comments on commit 7668fd0

Please sign in to comment.