First part of refactoring constellation to support iframe navigation.

The history is now recorded per frame, but needs to be exposed in a followup PR.

Also fixes a race condition that occurs loading iframes under heavy CPU load.

This ensures that iframes never do a reflow / layout until they have a valid
window size set from their parent frame.
This commit is contained in:
Glenn Watson 2015-03-13 15:08:02 +10:00
parent 0888a3a16d
commit 939a89568e
11 changed files with 587 additions and 921 deletions

View file

@ -291,18 +291,6 @@ impl<Window: WindowMethods> IOCompositor<Window> {
self.get_title_for_main_frame();
}
(Msg::ChangeLayerPipelineAndRemoveChildren(old_pipeline, new_pipeline, response_channel),
ShutdownState::NotShuttingDown) => {
self.handle_change_layer_pipeline_and_remove_children(old_pipeline, new_pipeline);
response_channel.send(()).unwrap();
}
(Msg::CreateRootLayerForPipeline(parent_pipeline, pipeline, rect, response_channel),
ShutdownState::NotShuttingDown) => {
self.handle_create_root_layer_for_pipeline(parent_pipeline, pipeline, rect);
response_channel.send(()).unwrap();
}
(Msg::CreateOrUpdateBaseLayer(layer_properties), ShutdownState::NotShuttingDown) => {
self.create_or_update_base_layer(layer_properties);
}
@ -554,62 +542,11 @@ impl<Window: WindowMethods> IOCompositor<Window> {
let root_layer = self.create_root_layer_for_pipeline_and_rect(&frame_tree.pipeline,
frame_rect);
for kid in frame_tree.children.iter() {
root_layer.add_child(self.create_frame_tree_root_layers(&kid.frame_tree, kid.rect));
root_layer.add_child(self.create_frame_tree_root_layers(kid, kid.rect));
}
return root_layer;
}
fn handle_change_layer_pipeline_and_remove_children(&mut self,
old_pipeline: CompositionPipeline,
new_pipeline: CompositionPipeline) {
let root_layer = match self.find_pipeline_root_layer(old_pipeline.id) {
Some(root_layer) => root_layer,
None => {
debug!("Ignoring ChangeLayerPipelineAndRemoveChildren message \
for pipeline ({:?}) shutting down.",
old_pipeline.id);
return;
}
};
root_layer.clear_all_tiles(self);
root_layer.children().clear();
debug_assert!(root_layer.extra_data.borrow().pipeline_id == old_pipeline.id);
root_layer.extra_data.borrow_mut().pipeline_id = new_pipeline.id;
let new_pipeline_id = new_pipeline.id;
self.get_or_create_pipeline_details(new_pipeline_id).pipeline = Some(new_pipeline);
}
fn handle_create_root_layer_for_pipeline(&mut self,
parent_pipeline: CompositionPipeline,
new_pipeline: CompositionPipeline,
frame_rect: Option<TypedRect<PagePx, f32>>) {
let root_layer = self.create_root_layer_for_pipeline_and_rect(&new_pipeline, frame_rect);
match frame_rect {
Some(ref frame_rect) => {
*root_layer.masks_to_bounds.borrow_mut() = true;
let frame_rect = frame_rect.to_untyped();
*root_layer.bounds.borrow_mut() = Rect::from_untyped(&frame_rect);
}
None => {}
}
let pipeline_id = parent_pipeline.id;
let parent_layer = match self.find_pipeline_root_layer(pipeline_id) {
Some(root_layer) => root_layer,
None => {
debug!("Ignoring FrameTreeUpdate message for pipeline ({:?}) \
shutting down.",
pipeline_id);
return;
}
};
parent_layer.add_child(root_layer);
}
fn find_pipeline_root_layer(&self, pipeline_id: PipelineId) -> Option<Rc<Layer<CompositorData>>> {
if !self.pipeline_details.contains_key(&pipeline_id) {
panic!("Tried to create or update layer for unknown pipeline")

View file

@ -13,18 +13,16 @@ use windowing::{WindowEvent, WindowMethods};
use azure::azure_hl::{SourceSurfaceMethods, Color};
use geom::point::Point2D;
use geom::rect::{Rect, TypedRect};
use geom::rect::Rect;
use geom::size::Size2D;
use layers::platform::surface::{NativeCompositingGraphicsContext, NativeGraphicsMetadata};
use layers::layers::LayerBufferSet;
use pipeline::CompositionPipeline;
use msg::compositor_msg::{Epoch, LayerId, LayerMetadata, ReadyState};
use msg::compositor_msg::{PaintListener, PaintState, ScriptListener, ScrollPolicy};
use msg::constellation_msg::{ConstellationChan, PipelineId};
use msg::constellation_msg::{Key, KeyState, KeyModifiers};
use url::Url;
use util::cursor::Cursor;
use util::geometry::PagePx;
use util::memory::MemoryProfilerChan;
use util::time::TimeProfilerChan;
use std::sync::mpsc::{channel, Sender, Receiver};
@ -207,10 +205,6 @@ pub enum Msg {
PaintMsgDiscarded,
/// Replaces the current frame tree, typically called during main frame navigation.
SetFrameTree(SendableFrameTree, Sender<()>, ConstellationChan),
/// Requests the compositor to create a root layer for a new frame.
CreateRootLayerForPipeline(CompositionPipeline, CompositionPipeline, Option<TypedRect<PagePx, f32>>, Sender<()>),
/// Requests the compositor to change a root layer's pipeline and remove all child layers.
ChangeLayerPipelineAndRemoveChildren(CompositionPipeline, CompositionPipeline, Sender<()>),
/// The load of a page has completed.
LoadComplete,
/// Indicates that the scrolling timeout with the given starting timestamp has happened and a
@ -241,8 +235,6 @@ impl Debug for Msg {
Msg::ChangePageUrl(..) => write!(f, "ChangePageUrl"),
Msg::PaintMsgDiscarded(..) => write!(f, "PaintMsgDiscarded"),
Msg::SetFrameTree(..) => write!(f, "SetFrameTree"),
Msg::CreateRootLayerForPipeline(..) => write!(f, "CreateRootLayerForPipeline"),
Msg::ChangeLayerPipelineAndRemoveChildren(..) => write!(f, "ChangeLayerPipelineAndRemoveChildren"),
Msg::LoadComplete => write!(f, "LoadComplete"),
Msg::ScrollTimeout(..) => write!(f, "ScrollTimeout"),
Msg::KeyEvent(..) => write!(f, "KeyEvent"),

File diff suppressed because it is too large Load diff

View file

@ -90,14 +90,6 @@ impl CompositorEventListener for NullCompositor {
response_chan.send(()).unwrap();
}
Msg::ChangeLayerPipelineAndRemoveChildren(_, _, response_channel) => {
response_channel.send(()).unwrap();
}
Msg::CreateRootLayerForPipeline(_, _, _, response_channel) => {
response_channel.send(()).unwrap();
}
// Explicitly list ignored messages so that when we add a new one,
// we'll notice and think about whether it needs a response, like
// SetFrameTree.

View file

@ -8,23 +8,24 @@ use script_traits::{ScriptControlChan, ScriptTaskFactory};
use script_traits::{NewLayoutInfo, ConstellationControlMsg};
use devtools_traits::DevtoolsControlChan;
use geom::rect::{TypedRect};
use gfx::paint_task::Msg as PaintMsg;
use gfx::paint_task::{PaintChan, PaintTask};
use gfx::font_cache_task::FontCacheTask;
use msg::constellation_msg::{ConstellationChan, Failure, PipelineId, SubpageId};
use msg::constellation_msg::{ConstellationChan, Failure, FrameId, PipelineId, SubpageId};
use msg::constellation_msg::{LoadData, WindowSizeData, PipelineExitType};
use net::image_cache_task::ImageCacheTask;
use net::resource_task::ResourceTask;
use net::storage_task::StorageTask;
use url::Url;
use util::geometry::{PagePx};
use util::time::TimeProfilerChan;
use std::rc::Rc;
use std::sync::mpsc::{Receiver, channel};
/// A uniquely-identifiable pipeline of script task, layout task, and paint task.
pub struct Pipeline {
pub id: PipelineId,
pub parent: Option<(PipelineId, SubpageId)>,
pub parent_info: Option<(PipelineId, SubpageId)>,
pub script_chan: ScriptControlChan,
pub layout_chan: LayoutControlChan,
pub paint_chan: PaintChan,
@ -34,6 +35,8 @@ pub struct Pipeline {
pub url: Url,
/// The title of the most recently-loaded page.
pub title: Option<String>,
pub rect: Option<TypedRect<PagePx, f32>>,
pub children: Vec<FrameId>,
}
/// The subset of the pipeline that is needed for layer composition.
@ -49,7 +52,7 @@ impl Pipeline {
/// Returns the channels wrapped in a struct.
/// If script_pipeline is not None, then subpage_id must also be not None.
pub fn create<LTF,STF>(id: PipelineId,
parent: Option<(PipelineId, SubpageId)>,
parent_info: Option<(PipelineId, SubpageId)>,
constellation_chan: ConstellationChan,
compositor_proxy: Box<CompositorProxy+'static+Send>,
devtools_chan: Option<DevtoolsControlChan>,
@ -58,8 +61,8 @@ impl Pipeline {
resource_task: ResourceTask,
storage_task: StorageTask,
time_profiler_chan: TimeProfilerChan,
window_size: WindowSizeData,
script_pipeline: Option<Rc<Pipeline>>,
window_size: Option<WindowSizeData>,
script_chan: Option<ScriptControlChan>,
load_data: LoadData)
-> Pipeline
where LTF: LayoutTaskFactory, STF:ScriptTaskFactory {
@ -71,10 +74,10 @@ impl Pipeline {
let failure = Failure {
pipeline_id: id,
parent: parent,
parent_info: parent_info,
};
let script_chan = match script_pipeline {
let script_chan = match script_chan {
None => {
let (script_chan, script_port) = channel();
ScriptTaskFactory::create(None::<&mut STF>,
@ -93,18 +96,19 @@ impl Pipeline {
load_data.clone());
ScriptControlChan(script_chan)
}
Some(spipe) => {
Some(script_chan) => {
let (containing_pipeline_id, subpage_id) = parent_info.expect("script_pipeline != None but subpage_id == None");
let new_layout_info = NewLayoutInfo {
old_pipeline_id: spipe.id.clone(),
containing_pipeline_id: containing_pipeline_id,
new_pipeline_id: id,
subpage_id: parent.expect("script_pipeline != None but subpage_id == None").1,
subpage_id: subpage_id,
layout_chan: ScriptTaskFactory::clone_layout_channel(None::<&mut STF>, &layout_pair),
load_data: load_data.clone(),
};
let ScriptControlChan(ref chan) = spipe.script_chan;
let ScriptControlChan(ref chan) = script_chan;
chan.send(ConstellationControlMsg::AttachLayout(new_layout_info)).unwrap();
spipe.script_chan.clone()
script_chan.clone()
}
};
@ -132,7 +136,7 @@ impl Pipeline {
layout_shutdown_chan);
Pipeline::new(id,
parent,
parent_info,
script_chan,
LayoutControlChan(pipeline_chan),
paint_chan,
@ -142,7 +146,7 @@ impl Pipeline {
}
pub fn new(id: PipelineId,
parent: Option<(PipelineId, SubpageId)>,
parent_info: Option<(PipelineId, SubpageId)>,
script_chan: ScriptControlChan,
layout_chan: LayoutControlChan,
paint_chan: PaintChan,
@ -152,7 +156,7 @@ impl Pipeline {
-> Pipeline {
Pipeline {
id: id,
parent: parent,
parent_info: parent_info,
script_chan: script_chan,
layout_chan: layout_chan,
paint_chan: paint_chan,
@ -160,14 +164,11 @@ impl Pipeline {
paint_shutdown_port: paint_shutdown_port,
url: url,
title: None,
children: vec!(),
rect: None,
}
}
pub fn activate(&self) {
let ScriptControlChan(ref chan) = self.script_chan;
chan.send(ConstellationControlMsg::Activate(self.id)).unwrap();
}
pub fn grant_paint_permission(&self) {
let _ = self.paint_chan.send(PaintMsg::PaintPermissionGranted);
}
@ -221,7 +222,7 @@ impl Pipeline {
}
}
pub fn subpage_id(&self) -> Option<SubpageId> {
self.parent.map(|parent| parent.1)
pub fn add_child(&mut self, frame_id: FrameId) {
self.children.push(frame_id);
}
}