Auto merge of #8598 - g-k:split-scriptmsg, r=KiChjang

Split paint task messages from ScriptMsg

Refs: https://github.com/servo/servo/issues/8592

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8598)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-11-26 03:02:47 +05:30
commit 5e7306bf19
4 changed files with 50 additions and 15 deletions

View file

@ -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};
@ -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>,
@ -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,
@ -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(),
@ -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())
}
};
@ -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)) => {
@ -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)) => {
@ -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
}
@ -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.