Skip to content

Commit

Permalink
split script_task::ExitMsg into WindowExitMsg and PipelineExitMsg
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Kuehn committed Sep 24, 2013
1 parent 99f125b commit 103cd62
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 34 deletions.
37 changes: 23 additions & 14 deletions src/components/main/constellation.rs
Expand Up @@ -760,6 +760,28 @@ impl Constellation {
}
}

// Close all pipelines at and beneath a given frame
fn close_pipelines(&mut self, frame_tree: @mut FrameTree) {
// TODO(tkuehn): should only exit once per unique script task,
// and then that script task will handle sub-exits
for @FrameTree { pipeline, _ } in frame_tree.iter() {
pipeline.exit();
self.pipelines.remove(&pipeline.id);
}
}

fn handle_evicted_frames(&mut self, evicted: ~[@mut FrameTree]) {
for &frame_tree in evicted.iter() {
if !self.navigation_context.contains(frame_tree.pipeline.id) {
self.close_pipelines(frame_tree);
} else {
self.handle_evicted_frames(frame_tree.children.iter()
.map(|child| child.frame_tree)
.collect());
}
}
}

// Grants a frame tree permission to paint; optionally updates navigation to reflect a new page
fn grant_paint_permission(&mut self, frame_tree: @mut FrameTree, navigation_type: NavigationType) {
// Give permission to paint to the new frame and all child frames
Expand All @@ -770,20 +792,7 @@ impl Constellation {
match navigation_type {
constellation_msg::Load => {
let evicted = self.navigation_context.load(frame_tree);
let mut exited = HashSet::new();
// exit any pipelines that don't exist outside the evicted frame trees
for frame_tree in evicted.iter() {
for @FrameTree { pipeline, _ } in frame_tree.iter() {
if !self.navigation_context.contains(pipeline.id) &&
!exited.contains(&pipeline.id) {
debug!("Constellation: shutting down pipeline %?", pipeline.id);
pipeline.exit();
self.pipelines.remove(&pipeline.id);

exited.insert(pipeline.id);
}
}
}
self.handle_evicted_frames(evicted);
}
_ => {}
}
Expand Down
4 changes: 4 additions & 0 deletions src/components/main/layout/layout_task.rs
Expand Up @@ -26,6 +26,7 @@ use gfx::font_context::FontContext;
use gfx::geometry::Au;
use gfx::opts::Opts;
use gfx::render_task::{RenderMsg, RenderChan, RenderLayer};
use gfx::render_task;
use newcss::select::SelectCtx;
use newcss::stylesheet::Stylesheet;
use newcss::types::OriginAuthor;
Expand Down Expand Up @@ -162,6 +163,9 @@ impl LayoutTask {
}
ExitMsg => {
debug!("layout: ExitMsg received");
let (response_port, response_chan) = stream();
self.render_chan.send(render_task::ExitMsg(response_chan));
response_port.recv();
return false
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/main/macros.rs
Expand Up @@ -5,7 +5,7 @@
macro_rules! special_stream(
($Chan:ident) => (
{
let (port, chan) = comm::stream::();
let (port, chan) = stream::();
(port, $Chan::new(chan))
}
);
Expand Down
11 changes: 3 additions & 8 deletions src/components/main/pipeline.rs
Expand Up @@ -6,7 +6,6 @@ use extra::url::Url;
use compositing::CompositorChan;
use gfx::render_task::{RenderChan, RenderTask};
use gfx::render_task::{PaintPermissionGranted, PaintPermissionRevoked};
use gfx::render_task;
use gfx::opts::Opts;
use layout::layout_task::LayoutTask;
use script::layout_interface::LayoutChan;
Expand All @@ -21,7 +20,6 @@ use servo_util::time::ProfilerChan;
use geom::size::Size2D;
use extra::future::Future;
use std::cell::Cell;
use std::comm;
use std::task;

/// A uniquely-identifiable pipeline of script task, layout task, and render task.
Expand Down Expand Up @@ -216,12 +214,9 @@ impl Pipeline {
}

pub fn exit(&self) {
// Script task handles shutting down layout, as well
self.script_chan.send(script_task::ExitMsg(self.id));

let (response_port, response_chan) = comm::stream();
self.render_chan.send(render_task::ExitMsg(response_chan));
response_port.recv();
// Script task handles shutting down layout,
// and layout handles shutting down the renderer.
self.script_chan.try_send(script_task::ExitPipelineMsg(self.id));
}
}

4 changes: 2 additions & 2 deletions src/components/script/dom/window.rs
Expand Up @@ -10,7 +10,7 @@ use dom::node::{AbstractNode, ScriptView};
use dom::navigator::Navigator;

use layout_interface::ReflowForDisplay;
use script_task::{ExitMsg, FireTimerMsg, Page, ScriptChan};
use script_task::{ExitWindowMsg, FireTimerMsg, Page, ScriptChan};
use servo_msg::compositor_msg::ScriptListener;
use servo_net::image_cache_task::ImageCacheTask;

Expand Down Expand Up @@ -212,7 +212,7 @@ impl Window {
match timer_port.recv() {
TimerMessage_Close => break,
TimerMessage_Fire(td) => script_chan.send(FireTimerMsg(id, td)),
TimerMessage_TriggerExit => script_chan.send(ExitMsg(id)),
TimerMessage_TriggerExit => script_chan.send(ExitWindowMsg(id)),
}
}
}
Expand Down
29 changes: 20 additions & 9 deletions src/components/script/script_task.rs
Expand Up @@ -70,8 +70,10 @@ pub enum ScriptMsg {
ReflowCompleteMsg(PipelineId, uint),
/// Notifies script that window has been resized but to not take immediate action.
ResizeInactiveMsg(PipelineId, Size2D<uint>),
/// Exits the constellation.
ExitMsg(PipelineId),
/// Notifies the script that a pipeline should be closed.
ExitPipelineMsg(PipelineId),
/// Notifies the script that a window associated with a particular pipeline should be closed.
ExitWindowMsg(PipelineId),
}

pub struct NewLayoutInfo {
Expand Down Expand Up @@ -516,9 +518,8 @@ impl ScriptTask {
NavigateMsg(direction) => self.handle_navigate_msg(direction),
ReflowCompleteMsg(id, reflow_id) => self.handle_reflow_complete_msg(id, reflow_id),
ResizeInactiveMsg(id, new_size) => self.handle_resize_inactive_msg(id, new_size),
ExitMsg(id) => {
if self.handle_exit_msg(id) { return false }
},
ExitPipelineMsg(id) => if self.handle_exit_pipeline_msg(id) { return false },
ExitWindowMsg(id) => if self.handle_exit_window_msg(id) { return false },
ResizeMsg(*) => fail!("should have handled ResizeMsg already"),
}
}
Expand Down Expand Up @@ -623,9 +624,17 @@ impl ScriptTask {
}
}

fn handle_exit_window_msg(&mut self, _id: PipelineId) -> bool {
// TODO(tkuehn): currently there is only one window,
// so this can afford to be naive and just shut down the
// compositor. In the future it'll need to be smarter.
self.compositor.close();
true
}

/// Handles a request to exit the script task and shut down layout.
/// Returns true if the script task should shut down and false otherwise.
fn handle_exit_msg(&mut self, id: PipelineId) -> bool {
fn handle_exit_pipeline_msg(&mut self, id: PipelineId) -> bool {
// If root is being exited, shut down all pages
if self.page_tree.page.id == id {
for page in self.page_tree.iter() {
Expand All @@ -641,10 +650,12 @@ impl ScriptTask {
page.join_layout();
page.layout_chan.send(layout_interface::ExitMsg);
}
return false
false
}
None => fail!("ScriptTask: Received exit message from
pipeline whose id is not in page tree"),
// TODO(tkuehn): pipeline closing is currently duplicated across
// script and constellation, which can cause this to happen. Constellation
// needs to be smarter about exiting pipelines.
None => false,
}

}
Expand Down

5 comments on commit 103cd62

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from metajack
at tikue@103cd62

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging tikue/servo/master = 103cd62 into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tikue/servo/master = 103cd62 merged ok, testing candidate = 401176b

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 401176b

Please sign in to comment.