Skip to content

Commit

Permalink
Rework the way scroll roots are collected
Browse files Browse the repository at this point in the history
Collect scroll roots during the collect_stacking_context phase instead
of during display list construction. This will be useful in order to
collect containing block scroll roots as well as to give scroll roots
sequential ids in the future. This change also pulls stacking context
children out of the StackingContext struct itself, which should reduce
very slightly the memory used by the finished display list. This also
simplifies the DisplayListBuilder because it no longer has to maintain
a stack of ScrollRootIds and StackingContextIds and can instead just
rely on the program stack.
  • Loading branch information
mrobinson committed Jan 10, 2017
1 parent 124301c commit 29876d2
Show file tree
Hide file tree
Showing 17 changed files with 224 additions and 272 deletions.
39 changes: 1 addition & 38 deletions components/gfx/display_list/mod.rs
Expand Up @@ -303,9 +303,6 @@ pub struct StackingContext {
/// The scroll policy of this layer.
pub scroll_policy: ScrollPolicy,

/// Children of this StackingContext.
pub children: Vec<StackingContext>,

/// The id of the parent scrolling area that contains this StackingContext.
pub parent_scroll_id: ScrollRootId,
}
Expand Down Expand Up @@ -338,7 +335,6 @@ impl StackingContext {
perspective: perspective,
establishes_3d_context: establishes_3d_context,
scroll_policy: scroll_policy,
children: Vec::new(),
parent_scroll_id: parent_scroll_id,
}
}
Expand All @@ -359,32 +355,7 @@ impl StackingContext {
ScrollRootId::root())
}

pub fn add_child(&mut self, mut child: StackingContext) {
child.update_overflow_for_all_children();
self.children.push(child);
}

pub fn child_at_mut(&mut self, index: usize) -> &mut StackingContext {
&mut self.children[index]
}

pub fn children(&self) -> &[StackingContext] {
&self.children
}

fn update_overflow_for_all_children(&mut self) {
for child in self.children.iter() {
if self.context_type == StackingContextType::Real &&
child.context_type == StackingContextType::Real {
// This child might be transformed, so we need to take into account
// its transformed overflow rect too, but at the correct position.
let overflow = child.overflow_rect_in_parent_space();
self.overflow = self.overflow.union(&overflow);
}
}
}

fn overflow_rect_in_parent_space(&self) -> Rect<Au> {
pub fn overflow_rect_in_parent_space(&self) -> Rect<Au> {
// Transform this stacking context to get it into the same space as
// the parent stacking context.
//
Expand All @@ -402,14 +373,6 @@ impl StackingContext {
f32_rect_to_au_rect(overflow)
}

pub fn print_with_tree(&self, print_tree: &mut PrintTree) {
print_tree.new_level(format!("{:?}", self));
for kid in self.children() {
kid.print_with_tree(print_tree);
}
print_tree.end_level();
}

pub fn to_display_list_items(self) -> (DisplayItem, DisplayItem) {
let mut base_item = BaseDisplayItem::empty();
base_item.stacking_context_id = self.id;
Expand Down
9 changes: 3 additions & 6 deletions components/layout/block.rs
Expand Up @@ -42,8 +42,7 @@ use flow::IS_ABSOLUTELY_POSITIONED;
use flow_list::FlowList;
use fragment::{CoordinateSystem, Fragment, FragmentBorderBoxIterator, Overflow};
use fragment::{IS_INLINE_FLEX_ITEM, IS_BLOCK_FLEX_ITEM};
use gfx::display_list::{ClippingRegion, StackingContext};
use gfx_traits::ScrollRootId;
use gfx::display_list::ClippingRegion;
use gfx_traits::print_tree::PrintTree;
use layout_debug;
use model::{AdjoiningMargins, CollapsibleMargins, IntrinsicISizes, MarginCollapseInfo, MaybeAuto};
Expand Down Expand Up @@ -2195,10 +2194,8 @@ impl Flow for BlockFlow {
}
}

fn collect_stacking_contexts(&mut self,
parent: &mut StackingContext,
parent_scroll_root_id: ScrollRootId) {
self.collect_stacking_contexts_for_block(parent, parent_scroll_root_id);
fn collect_stacking_contexts(&mut self, state: &mut DisplayListBuildState) {
self.collect_stacking_contexts_for_block(state);
}

fn build_display_list(&mut self, state: &mut DisplayListBuildState) {
Expand Down
314 changes: 184 additions & 130 deletions components/layout/display_list_builder.rs

Large diffs are not rendered by default.

8 changes: 2 additions & 6 deletions components/layout/flex.rs
Expand Up @@ -16,8 +16,6 @@ use flow;
use flow::{Flow, FlowClass, ImmutableFlowUtils, OpaqueFlow};
use flow::{INLINE_POSITION_IS_STATIC, IS_ABSOLUTELY_POSITIONED};
use fragment::{Fragment, FragmentBorderBoxIterator, Overflow};
use gfx::display_list::StackingContext;
use gfx_traits::ScrollRootId;
use layout_debug;
use model::{IntrinsicISizes, MaybeAuto, SizeConstraint};
use model::{specified, specified_or_none};
Expand Down Expand Up @@ -967,10 +965,8 @@ impl Flow for FlexFlow {
self.build_display_list_for_flex(state);
}

fn collect_stacking_contexts(&mut self,
parent: &mut StackingContext,
parent_scroll_root_id: ScrollRootId) {
self.block_flow.collect_stacking_contexts(parent, parent_scroll_root_id);
fn collect_stacking_contexts(&mut self, state: &mut DisplayListBuildState) {
self.block_flow.collect_stacking_contexts(state);
}

fn repair_style(&mut self, new_style: &Arc<ServoComputedValues>) {
Expand Down
12 changes: 4 additions & 8 deletions components/layout/flow.rs
Expand Up @@ -35,7 +35,7 @@ use floats::{Floats, SpeculatedFloatPlacement};
use flow_list::{FlowList, MutFlowListIterator};
use flow_ref::{FlowRef, WeakFlowRef};
use fragment::{Fragment, FragmentBorderBoxIterator, Overflow};
use gfx::display_list::{ClippingRegion, StackingContext};
use gfx::display_list::ClippingRegion;
use gfx_traits::{ScrollRootId, StackingContextId};
use gfx_traits::print_tree::PrintTree;
use inline::InlineFlow;
Expand Down Expand Up @@ -221,9 +221,7 @@ pub trait Flow: fmt::Debug + Sync + Send + 'static {
None
}

fn collect_stacking_contexts(&mut self,
_parent: &mut StackingContext,
parent_scroll_root_id: ScrollRootId);
fn collect_stacking_contexts(&mut self, state: &mut DisplayListBuildState);

/// If this is a float, places it. The default implementation does nothing.
fn place_float_if_applicable<'a>(&mut self) {}
Expand Down Expand Up @@ -1115,11 +1113,9 @@ impl BaseFlow {
return self as *const BaseFlow as usize;
}

pub fn collect_stacking_contexts_for_children(&mut self,
parent: &mut StackingContext,
parent_scroll_root_id: ScrollRootId) {
pub fn collect_stacking_contexts_for_children(&mut self, state: &mut DisplayListBuildState) {
for kid in self.children.iter_mut() {
kid.collect_stacking_contexts(parent, parent_scroll_root_id);
kid.collect_stacking_contexts(state);
}
}

Expand Down
9 changes: 3 additions & 6 deletions components/layout/inline.rs
Expand Up @@ -16,10 +16,9 @@ use flow::OpaqueFlow;
use flow_ref::FlowRef;
use fragment::{CoordinateSystem, Fragment, FragmentBorderBoxIterator, Overflow};
use fragment::SpecificFragmentInfo;
use gfx::display_list::{OpaqueNode, StackingContext};
use gfx::display_list::OpaqueNode;
use gfx::font::FontMetrics;
use gfx::font_context::FontContext;
use gfx_traits::ScrollRootId;
use gfx_traits::print_tree::PrintTree;
use layout_debug;
use model::IntrinsicISizesContribution;
Expand Down Expand Up @@ -1622,10 +1621,8 @@ impl Flow for InlineFlow {

fn update_late_computed_block_position_if_necessary(&mut self, _: Au) {}

fn collect_stacking_contexts(&mut self,
parent: &mut StackingContext,
parent_scroll_root_id: ScrollRootId) {
self.collect_stacking_contexts_for_inline(parent, parent_scroll_root_id);
fn collect_stacking_contexts(&mut self, state: &mut DisplayListBuildState) {
self.collect_stacking_contexts_for_inline(state);
}

fn build_display_list(&mut self, state: &mut DisplayListBuildState) {
Expand Down
8 changes: 2 additions & 6 deletions components/layout/list_item.rs
Expand Up @@ -17,8 +17,6 @@ use flow::{Flow, FlowClass, OpaqueFlow};
use fragment::{CoordinateSystem, Fragment, FragmentBorderBoxIterator, GeneratedContentInfo};
use fragment::Overflow;
use generated_content;
use gfx::display_list::StackingContext;
use gfx_traits::ScrollRootId;
use inline::InlineFlow;
use std::sync::Arc;
use style::computed_values::{list_style_type, position};
Expand Down Expand Up @@ -144,10 +142,8 @@ impl Flow for ListItemFlow {
self.build_display_list_for_list_item(state);
}

fn collect_stacking_contexts(&mut self,
parent: &mut StackingContext,
parent_scroll_root_id: ScrollRootId) {
self.block_flow.collect_stacking_contexts(parent, parent_scroll_root_id);
fn collect_stacking_contexts(&mut self, state: &mut DisplayListBuildState) {
self.block_flow.collect_stacking_contexts(state);
}

fn repair_style(&mut self, new_style: &Arc<ServoComputedValues>) {
Expand Down
14 changes: 4 additions & 10 deletions components/layout/multicol.rs
Expand Up @@ -15,8 +15,6 @@ use euclid::Size2D;
use floats::FloatKind;
use flow::{Flow, FlowClass, OpaqueFlow, mut_base, FragmentationContext};
use fragment::{Fragment, FragmentBorderBoxIterator, Overflow};
use gfx::display_list::StackingContext;
use gfx_traits::ScrollRootId;
use gfx_traits::print_tree::PrintTree;
use std::cmp::{min, max};
use std::fmt;
Expand Down Expand Up @@ -188,10 +186,8 @@ impl Flow for MulticolFlow {
self.block_flow.build_display_list(state);
}

fn collect_stacking_contexts(&mut self,
parent: &mut StackingContext,
parent_scroll_root_id: ScrollRootId) {
self.block_flow.collect_stacking_contexts(parent, parent_scroll_root_id);
fn collect_stacking_contexts(&mut self, state: &mut DisplayListBuildState) {
self.block_flow.collect_stacking_contexts(state);
}

fn repair_style(&mut self, new_style: &Arc<ServoComputedValues>) {
Expand Down Expand Up @@ -272,10 +268,8 @@ impl Flow for MulticolColumnFlow {
self.block_flow.build_display_list(state);
}

fn collect_stacking_contexts(&mut self,
parent: &mut StackingContext,
parent_scroll_root_id: ScrollRootId) {
self.block_flow.collect_stacking_contexts(parent, parent_scroll_root_id);
fn collect_stacking_contexts(&mut self, state: &mut DisplayListBuildState) {
self.block_flow.collect_stacking_contexts(state);
}

fn repair_style(&mut self, new_style: &Arc<ServoComputedValues>) {
Expand Down
6 changes: 2 additions & 4 deletions components/layout/sequential.rs
Expand Up @@ -14,7 +14,6 @@ use flow::{PostorderFlowTraversal, PreorderFlowTraversal};
use flow::IS_ABSOLUTELY_POSITIONED;
use fragment::FragmentBorderBoxIterator;
use generated_content::ResolveGeneratedContent;
use gfx_traits::ScrollRootId;
use servo_config::opts;
use style::servo::restyle_damage::{REFLOW, STORE_OVERFLOW};
use traversal::{AssignBSizes, AssignISizes, BubbleISizes, BuildDisplayList};
Expand Down Expand Up @@ -76,9 +75,8 @@ pub fn traverse_flow_tree_preorder(root: &mut Flow,
pub fn build_display_list_for_subtree<'a>(flow_root: &mut Flow,
shared_layout_context: &'a SharedLayoutContext)
-> DisplayListBuildState<'a> {
let mut state = DisplayListBuildState::new(shared_layout_context,
flow::base(flow_root).stacking_context_id);
flow_root.collect_stacking_contexts(&mut state.root_stacking_context, ScrollRootId::root());
let mut state = DisplayListBuildState::new(shared_layout_context);
flow_root.collect_stacking_contexts(&mut state);

let mut build_display_list = BuildDisplayList { state: state };
build_display_list.traverse(flow_root);
Expand Down
8 changes: 2 additions & 6 deletions components/layout/table.rs
Expand Up @@ -16,8 +16,6 @@ use flow;
use flow::{BaseFlow, EarlyAbsolutePositionInfo, Flow, FlowClass, ImmutableFlowUtils, OpaqueFlow};
use flow_list::MutFlowListIterator;
use fragment::{Fragment, FragmentBorderBoxIterator, Overflow};
use gfx::display_list::StackingContext;
use gfx_traits::ScrollRootId;
use gfx_traits::print_tree::PrintTree;
use layout_debug;
use model::{IntrinsicISizes, IntrinsicISizesContribution, MaybeAuto};
Expand Down Expand Up @@ -501,10 +499,8 @@ impl Flow for TableFlow {
self.block_flow.build_display_list_for_block(state, border_painting_mode);
}

fn collect_stacking_contexts(&mut self,
parent: &mut StackingContext,
parent_scroll_root_id: ScrollRootId) {
self.block_flow.collect_stacking_contexts(parent, parent_scroll_root_id);
fn collect_stacking_contexts(&mut self, state: &mut DisplayListBuildState) {
self.block_flow.collect_stacking_contexts(state);
}

fn repair_style(&mut self, new_style: &Arc<ServoComputedValues>) {
Expand Down
8 changes: 2 additions & 6 deletions components/layout/table_caption.rs
Expand Up @@ -13,8 +13,6 @@ use display_list_builder::DisplayListBuildState;
use euclid::Point2D;
use flow::{Flow, FlowClass, OpaqueFlow};
use fragment::{Fragment, FragmentBorderBoxIterator, Overflow};
use gfx::display_list::StackingContext;
use gfx_traits::ScrollRootId;
use gfx_traits::print_tree::PrintTree;
use std::fmt;
use std::sync::Arc;
Expand Down Expand Up @@ -83,10 +81,8 @@ impl Flow for TableCaptionFlow {
self.block_flow.build_display_list(state);
}

fn collect_stacking_contexts(&mut self,
parent: &mut StackingContext,
parent_scroll_root_id: ScrollRootId) {
self.block_flow.collect_stacking_contexts(parent, parent_scroll_root_id);
fn collect_stacking_contexts(&mut self, state: &mut DisplayListBuildState) {
self.block_flow.collect_stacking_contexts(state);
}

fn repair_style(&mut self, new_style: &Arc<ServoComputedValues>) {
Expand Down
8 changes: 2 additions & 6 deletions components/layout/table_cell.rs
Expand Up @@ -14,8 +14,6 @@ use display_list_builder::{BlockFlowDisplayListBuilding, BorderPaintingMode, Dis
use euclid::{Point2D, Rect, SideOffsets2D, Size2D};
use flow::{self, Flow, FlowClass, IS_ABSOLUTELY_POSITIONED, OpaqueFlow};
use fragment::{Fragment, FragmentBorderBoxIterator, Overflow};
use gfx::display_list::StackingContext;
use gfx_traits::ScrollRootId;
use gfx_traits::print_tree::PrintTree;
use layout_debug;
use model::MaybeAuto;
Expand Down Expand Up @@ -262,10 +260,8 @@ impl Flow for TableCellFlow {
self.block_flow.build_display_list_for_block(state, border_painting_mode)
}

fn collect_stacking_contexts(&mut self,
parent: &mut StackingContext,
parent_scroll_root_id: ScrollRootId) {
self.block_flow.collect_stacking_contexts(parent, parent_scroll_root_id);
fn collect_stacking_contexts(&mut self, state: &mut DisplayListBuildState) {
self.block_flow.collect_stacking_contexts(state);
}

fn repair_style(&mut self, new_style: &Arc<ServoComputedValues>) {
Expand Down
6 changes: 1 addition & 5 deletions components/layout/table_colgroup.rs
Expand Up @@ -12,8 +12,6 @@ use display_list_builder::DisplayListBuildState;
use euclid::Point2D;
use flow::{BaseFlow, Flow, FlowClass, ForceNonfloatedFlag, OpaqueFlow};
use fragment::{Fragment, FragmentBorderBoxIterator, Overflow, SpecificFragmentInfo};
use gfx::display_list::StackingContext;
use gfx_traits::ScrollRootId;
use layout_debug;
use std::cmp::max;
use std::fmt;
Expand Down Expand Up @@ -96,9 +94,7 @@ impl Flow for TableColGroupFlow {
// Table columns are invisible.
fn build_display_list(&mut self, _: &mut DisplayListBuildState) { }

fn collect_stacking_contexts(&mut self,
_parent: &mut StackingContext,
_parent_scroll_root_id: ScrollRootId) {}
fn collect_stacking_contexts(&mut self, _: &mut DisplayListBuildState) {}

fn repair_style(&mut self, _: &Arc<ServoComputedValues>) {}

Expand Down
8 changes: 2 additions & 6 deletions components/layout/table_row.rs
Expand Up @@ -15,8 +15,6 @@ use euclid::Point2D;
use flow::{self, EarlyAbsolutePositionInfo, Flow, FlowClass, ImmutableFlowUtils, OpaqueFlow};
use flow_list::MutFlowListIterator;
use fragment::{Fragment, FragmentBorderBoxIterator, Overflow};
use gfx::display_list::StackingContext;
use gfx_traits::ScrollRootId;
use gfx_traits::print_tree::PrintTree;
use layout_debug;
use model::MaybeAuto;
Expand Down Expand Up @@ -481,10 +479,8 @@ impl Flow for TableRowFlow {
self.block_flow.build_display_list_for_block(state, border_painting_mode);
}

fn collect_stacking_contexts(&mut self,
parent: &mut StackingContext,
parent_scroll_root_id: ScrollRootId) {
self.block_flow.collect_stacking_contexts(parent, parent_scroll_root_id);
fn collect_stacking_contexts(&mut self, state: &mut DisplayListBuildState) {
self.block_flow.collect_stacking_contexts(state);
}

fn repair_style(&mut self, new_style: &Arc<ServoComputedValues>) {
Expand Down
8 changes: 2 additions & 6 deletions components/layout/table_rowgroup.rs
Expand Up @@ -13,8 +13,6 @@ use display_list_builder::DisplayListBuildState;
use euclid::Point2D;
use flow::{Flow, FlowClass, OpaqueFlow};
use fragment::{Fragment, FragmentBorderBoxIterator, Overflow};
use gfx::display_list::StackingContext;
use gfx_traits::ScrollRootId;
use gfx_traits::print_tree::PrintTree;
use layout_debug;
use serde::{Serialize, Serializer};
Expand Down Expand Up @@ -184,10 +182,8 @@ impl Flow for TableRowGroupFlow {
self.block_flow.build_display_list(state);
}

fn collect_stacking_contexts(&mut self,
parent: &mut StackingContext,
parent_scroll_root_id: ScrollRootId) {
self.block_flow.collect_stacking_contexts(parent, parent_scroll_root_id);
fn collect_stacking_contexts(&mut self, state: &mut DisplayListBuildState) {
self.block_flow.collect_stacking_contexts(state);
}

fn repair_style(&mut self, new_style: &Arc<ServoComputedValues>) {
Expand Down
8 changes: 2 additions & 6 deletions components/layout/table_wrapper.rs
Expand Up @@ -22,8 +22,6 @@ use euclid::Point2D;
use floats::FloatKind;
use flow::{Flow, FlowClass, ImmutableFlowUtils, INLINE_POSITION_IS_STATIC, OpaqueFlow};
use fragment::{Fragment, FragmentBorderBoxIterator, Overflow};
use gfx::display_list::StackingContext;
use gfx_traits::ScrollRootId;
use gfx_traits::print_tree::PrintTree;
use model::MaybeAuto;
use std::cmp::{max, min};
Expand Down Expand Up @@ -462,10 +460,8 @@ impl Flow for TableWrapperFlow {
self.block_flow.build_display_list(state);
}

fn collect_stacking_contexts(&mut self,
parent: &mut StackingContext,
parent_scroll_root_id: ScrollRootId) {
self.block_flow.collect_stacking_contexts(parent, parent_scroll_root_id);
fn collect_stacking_contexts(&mut self, state: &mut DisplayListBuildState) {
self.block_flow.collect_stacking_contexts(state);
}

fn repair_style(&mut self, new_style: &Arc<ServoComputedValues>) {
Expand Down

0 comments on commit 29876d2

Please sign in to comment.