aboutsummaryrefslogtreecommitdiffstats
path: root/components/layout/inline.rs
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2014-11-11 22:07:39 -0800
committerPatrick Walton <pcwalton@mimiga.net>2014-11-14 17:31:15 -0800
commita4a9a46a87221aaa40e145602a9211e5542753a0 (patch)
tree104a88e5e9b5eb28a093127480d72ea05b52e4cc /components/layout/inline.rs
parent0ab70dd539798022ebadd07fb799096809f14d3f (diff)
downloadservo-a4a9a46a87221aaa40e145602a9211e5542753a0.tar.gz
servo-a4a9a46a87221aaa40e145602a9211e5542753a0.zip
gfx: Rewrite display list construction to make stacking-contexts more
first-class. This implements the scheme described here: https://groups.google.com/forum/#!topic/mozilla.dev.servo/sZVPSfPVfkg This commit changes Servo to generate one display list per stacking context instead of one display list per layer. This is purely a refactoring; there are no functional changes. Performance is essentially the same as before. However, there should be numerous future benefits that this is intended to allow for: * It makes the code simpler to understand because the "new layer needed" vs. "no new layer needed" code paths are more consolidated. * It makes it easy to support CSS properties that did not fit into our previous flat display list model (without unconditionally layerizing them): o `opacity` should be easy to support because the stacking context provides the higher-level grouping of display items to which opacity is to be applied. o `transform` can be easily supported because the stacking context provides a place to stash the transformation matrix. This has the side benefit of nicely separating the transformation matrix from the clipping regions. * The `flatten` logic is now O(1) instead of O(n) and now only needs to be invoked for pseudo-stacking contexts (right now: just floats), instead of for every stacking context. * Layers are now a proper tree instead of a flat list as far as layout is concerned, bringing us closer to a production-quality compositing/layers framework. * This commit opens the door to incremental display list construction at the level of stacking contexts. Future performance improvements could come from optimizing allocation of display list items, and, of course, incremental display list construction.
Diffstat (limited to 'components/layout/inline.rs')
-rw-r--r--components/layout/inline.rs47
1 files changed, 25 insertions, 22 deletions
diff --git a/components/layout/inline.rs b/components/layout/inline.rs
index c6ca65fd799..d1a6b22b992 100644
--- a/components/layout/inline.rs
+++ b/components/layout/inline.rs
@@ -6,7 +6,7 @@
use css::node_style::StyledNode;
use context::LayoutContext;
-use display_list_builder::FragmentDisplayListBuilding;
+use display_list_builder::{ContentLevel, DisplayListResult, FragmentDisplayListBuilding};
use floats::{FloatLeft, Floats, PlacementInfo};
use flow::{BaseFlow, FlowClass, Flow, InlineFlowClass, MutableFlowUtils};
use flow;
@@ -20,7 +20,7 @@ use text;
use collections::{RingBuf};
use geom::{Rect, Size2D};
-use gfx::display_list::ContentLevel;
+use gfx::display_list::DisplayList;
use gfx::font::FontMetrics;
use gfx::font_context::FontContext;
use gfx::text::glyph::CharIndex;
@@ -1136,34 +1136,34 @@ impl Flow for InlineFlow {
fn compute_absolute_position(&mut self) {
for fragment in self.fragments.fragments.iter_mut() {
- let absolute_position = match fragment.specific {
+ let stacking_relative_position = match fragment.specific {
InlineBlockFragment(ref mut info) => {
let block_flow = info.flow_ref.as_block();
// FIXME(#2795): Get the real container size
let container_size = Size2D::zero();
- block_flow.base.abs_position =
- self.base.abs_position +
+ block_flow.base.stacking_relative_position =
+ self.base.stacking_relative_position +
fragment.border_box.start.to_physical(self.base.writing_mode,
container_size);
- block_flow.base.abs_position
+ block_flow.base.stacking_relative_position
}
InlineAbsoluteHypotheticalFragment(ref mut info) => {
let block_flow = info.flow_ref.as_block();
// FIXME(#2795): Get the real container size
let container_size = Size2D::zero();
- block_flow.base.abs_position =
- self.base.abs_position +
+ block_flow.base.stacking_relative_position =
+ self.base.stacking_relative_position +
fragment.border_box.start.to_physical(self.base.writing_mode,
container_size);
- block_flow.base.abs_position
+ block_flow.base.stacking_relative_position
}
_ => continue,
};
let clip_rect = fragment.clip_rect_for_children(self.base.clip_rect,
- absolute_position);
+ stacking_relative_position);
match fragment.specific {
InlineBlockFragment(ref mut info) => {
@@ -1183,11 +1183,11 @@ impl Flow for InlineFlow {
fn build_display_list(&mut self, layout_context: &LayoutContext) {
let size = self.base.position.size.to_physical(self.base.writing_mode);
- if !Rect(self.base.abs_position, size).intersects(&layout_context.shared.dirty) {
- debug!("inline block (abs pos {}, size {}) didn't intersect \
- dirty rect two",
- self.base.abs_position,
- size);
+ if !Rect(self.base.stacking_relative_position, size).intersects(&layout_context.shared
+ .dirty) {
+ debug!("inline block (stacking relative pos {}, size {}) didn't intersect dirty rect",
+ self.base.stacking_relative_position,
+ size);
return
}
@@ -1195,9 +1195,10 @@ impl Flow for InlineFlow {
// not recurse on a line if nothing in it can intersect the dirty region.
debug!("Flow: building display list for {:u} inline fragments", self.fragments.len());
+ let mut display_list = box DisplayList::new();
for fragment in self.fragments.fragments.iter_mut() {
- let fragment_origin = self.base.child_fragment_absolute_position(fragment);
- fragment.build_display_list(&mut self.base.display_list,
+ let fragment_origin = self.base.stacking_relative_position_of_child_fragment(fragment);
+ fragment.build_display_list(&mut *display_list,
layout_context,
fragment_origin,
ContentLevel,
@@ -1205,14 +1206,15 @@ impl Flow for InlineFlow {
match fragment.specific {
InlineBlockFragment(ref mut block_flow) => {
let block_flow = block_flow.flow_ref.deref_mut();
- self.base
- .display_list
- .append_from(&mut flow::mut_base(block_flow).display_list)
+ flow::mut_base(block_flow).display_list_building_result
+ .add_to(&mut *display_list)
}
_ => {}
}
}
+ self.base.display_list_building_result = DisplayListResult(display_list);
+
if opts::get().validate_display_list_geometry {
self.base.validate_display_list_geometry();
}
@@ -1223,8 +1225,9 @@ impl Flow for InlineFlow {
fn iterate_through_fragment_bounds(&self, iterator: &mut FragmentBoundsIterator) {
for fragment in self.fragments.fragments.iter() {
if iterator.should_process(fragment) {
- let fragment_origin = self.base.child_fragment_absolute_position(fragment);
- iterator.process(fragment, fragment.abs_bounds_from_origin(&fragment_origin));
+ let fragment_origin =
+ self.base.stacking_relative_position_of_child_fragment(fragment);
+ iterator.process(fragment, fragment.stacking_relative_bounds(&fragment_origin));
}
}
}