Skip to content

Commit

Permalink
servo: Merge #1208 - Use Any for the layout data (from pcwalton:any…
Browse files Browse the repository at this point in the history
…-layout-data); r=metajack

Breaks the dependency between `gfx` and `script`, which is nice.

This exposed some performance issues with Rust's `Any` type, which I've filed:

rust-lang/rust#10382

Source-Repo: https://github.com/servo/servo
Source-Revision: 4eb84496211bb48d2804a0ddcd16849536546103

UltraBlame original commit: 307ff07f5dc6474afb4176fcf3c599315d4408f2
  • Loading branch information
marco-c committed Sep 30, 2019
1 parent a848376 commit 76a5ae5
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 143 deletions.
4 changes: 2 additions & 2 deletions servo/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,14 @@ DONE_gfx = $(B)src/components/gfx/libgfx.dummy

DEPS_gfx = $(CRATE_gfx) $(SRC_gfx) $(DONE_SUBMODULES) $(DONE_util) $(DONE_style) $(DONE_net) $(DONE_msg)

RFLAGS_script = $(strip $(CFG_RUSTC_FLAGS)) $(addprefix -L $(B)src/,$(DEPS_SUBMODULES)) -L $(B)src/components/util -L $(B)src/components/style -L $(B)src/components/net -L $(B)src/components/gfx -L $(B)src/components/msg
RFLAGS_script = $(strip $(CFG_RUSTC_FLAGS)) $(addprefix -L $(B)src/,$(DEPS_SUBMODULES)) -L $(B)src/components/util -L $(B)src/components/style -L $(B)src/components/net -L $(B)src/components/msg
WEBIDL_script = $(call rwildcard,$(S)src/components/script/,*.webidl)
AUTOGEN_SRC_script = $(patsubst %.webidl, %Binding.rs, $(WEBIDL_script))
SRC_script = $(call rwildcard,$(S)src/components/script/,*.rs) $(AUTOGEN_SRC_script)
CRATE_script = $(S)src/components/script/script.rc
DONE_script = $(B)src/components/script/libscript.dummy

DEPS_script = $(CRATE_script) $(SRC_script) $(DONE_SUBMODULES) $(DONE_util) $(DONE_style) $(DONE_net) $(DONE_gfx) $(DONE_msg)
DEPS_script = $(CRATE_script) $(SRC_script) $(DONE_SUBMODULES) $(DONE_util) $(DONE_style) $(DONE_net) $(DONE_msg)

RFLAGS_style = $(strip $(CFG_RUSTC_FLAGS)) $(addprefix -L $(B)src/,$(DEPS_SUBMODULES)) -L $(B)src/components/util
MAKO_ZIP = $(S)src/components/style/Mako-0.8.1.zip
Expand Down
31 changes: 14 additions & 17 deletions servo/src/components/main/css/matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use extra::arc::RWArc;
use css::node_style::StyledNode;
use css::node_util::NodeUtil;
use layout::incremental;
use layout::util::LayoutDataAccess;

use script::dom::node::{AbstractNode, LayoutView};
use style::Stylist;
Expand All @@ -37,10 +38,7 @@ impl MatchMethods for AbstractNode<LayoutView> {
};
stylist.get_applicable_declarations(self, style_attribute, None)
};
let cell = Cell::new(applicable_declarations);
do self.write_layout_data |data| {
data.applicable_declarations = cell.take();
}
self.layout_data().applicable_declarations.set(applicable_declarations)
}
fn match_subtree(&self, stylist: RWArc<Stylist>) {
let num_tasks = default_sched_threads() * 2;
Expand Down Expand Up @@ -84,22 +82,21 @@ impl MatchMethods for AbstractNode<LayoutView> {
Some(parent) => Some(parent.style()),
None => None
};
let computed_values = do self.read_layout_data |data| {
cascade(data.applicable_declarations, parent_style)
};
let cell = Cell::new(computed_values);
do self.write_layout_data |data| {
let style = cell.take();


match data.style {
None => (),
Some(ref previous_style) => self.set_restyle_damage(
incremental::compute_damage(previous_style, &style))

let layout_data = self.layout_data();
let computed_values = cascade(*layout_data.applicable_declarations.borrow().ptr,
parent_style);
let style = layout_data.style.mutate();
match *style.ptr {
None => (),
Some(ref previous_style) => {
self.set_restyle_damage(incremental::compute_damage(previous_style,
&computed_values))
}
data.style = Some(style);
}
*style.ptr = Some(computed_values)
}

fn cascade_subtree(&self, parent: Option<AbstractNode<LayoutView>>) {
self.cascade_node(parent);

Expand Down
31 changes: 15 additions & 16 deletions servo/src/components/main/css/node_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@


use layout::incremental::RestyleDamage;
use layout::util::LayoutDataAccess;

use std::cast;
use std::cell::Cell;
use style::ComputedValues;
use script::dom::node::{AbstractNode, LayoutView};
use servo_util::tree::TreeNodeRef;


pub trait NodeUtil<'self> {
fn get_css_select_results(self) -> &'self ComputedValues;
fn set_css_select_results(self, decl: ComputedValues);
Expand All @@ -29,23 +28,21 @@ impl<'self> NodeUtil<'self> for AbstractNode<LayoutView> {


fn get_css_select_results(self) -> &'self ComputedValues {
do self.read_layout_data |layout_data| {
match layout_data.style {
None => fail!(~"style() called on node without a style!"),
Some(ref style) => unsafe { cast::transmute_region(style) }
}
let layout_data = self.layout_data();
match *layout_data.style.borrow().ptr {
None => fail!(~"style() called on node without a style!"),
Some(ref style) => unsafe { cast::transmute_region(style) }
}
}


fn have_css_select_results(self) -> bool {
self.read_layout_data(|data| data.style.is_some())
self.layout_data().style.borrow().ptr.is_some()
}


fn set_css_select_results(self, decl: ComputedValues) {
let cell = Cell::new(decl);
self.write_layout_data(|data| data.style = Some(cell.take()));
*self.layout_data().style.mutate().ptr = Some(decl)
}


Expand All @@ -59,15 +56,17 @@ impl<'self> NodeUtil<'self> for AbstractNode<LayoutView> {
RestyleDamage::none()
};

do self.read_layout_data |layout_data| {
layout_data.restyle_damage
.map(|x| RestyleDamage::from_int(x))
.unwrap_or(default)
}
self.layout_data()
.restyle_damage
.borrow()
.ptr
.map(|x| RestyleDamage::from_int(x))
.unwrap_or(default)
}


fn set_restyle_damage(self, damage: RestyleDamage) {
self.write_layout_data(|data| data.restyle_damage = Some(damage.to_int()));
*self.layout_data().restyle_damage.mutate().ptr = Some(damage.to_int())
}
}

15 changes: 12 additions & 3 deletions servo/src/components/main/layout/aux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@



use layout::util::{DisplayBoxes, LayoutData, LayoutDataAccess};

use script::dom::node::{AbstractNode, LayoutView};
use servo_util::tree::TreeNodeRef;
use std::cast;


pub trait LayoutAuxMethods {
Expand All @@ -15,10 +18,16 @@ pub trait LayoutAuxMethods {

impl LayoutAuxMethods for AbstractNode<LayoutView> {



fn initialize_layout_data(self) {
do self.write_layout_data |data| {
data.boxes.display_list = None;
data.boxes.range = None;
unsafe {
let node = cast::transmute_mut(self.node());
if node.layout_data.is_none() {
node.layout_data = Some(~LayoutData::new() as ~Any)
} else {
self.layout_data().boxes.set(DisplayBoxes::init());
}
}
}

Expand Down
107 changes: 54 additions & 53 deletions servo/src/components/main/layout/layout_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ use layout::flow::{FlowContext, ImmutableFlowUtils, MutableFlowUtils, PreorderFl
use layout::flow::{PostorderFlowTraversal};
use layout::flow;
use layout::incremental::{RestyleDamage, BubbleWidths};
use layout::util::LayoutDataAccess;

use std::cast::transmute;
use std::cell::Cell;
use std::comm::{Port};
use std::comm::Port;
use std::task;
use extra::arc::{Arc, RWArc};
use geom::point::Point2D;
Expand Down Expand Up @@ -419,22 +420,23 @@ impl LayoutTask {
transmute(display_list.get().list[i].base().extra)
};
do node.write_layout_data |layout_data| {
layout_data.boxes.display_list = Some(display_list.clone());
if layout_data.boxes.range.is_none() {
debug!("Creating initial range for node");
layout_data.boxes.range = Some(Range::new(i,1));
} else {
debug!("Appending item to range");
unsafe {
let old_node: AbstractNode<()> = transmute(node);
assert!(old_node == display_list.get().list[i-1].base().extra,
"Non-contiguous arrangement of display items");
}
layout_data.boxes.range.unwrap().extend_by(1);
// FIXME(pcwalton): Why are we cloning the display list here?!
let layout_data = node.layout_data();
let boxes = layout_data.boxes.mutate();
boxes.ptr.display_list = Some(display_list.clone());
if boxes.ptr.range.is_none() {
debug!("Creating initial range for node");
boxes.ptr.range = Some(Range::new(i,1));
} else {
debug!("Appending item to range");
unsafe {
let old_node: AbstractNode<()> = transmute(node);
assert!(old_node == display_list.get().list[i-1].base().extra,
"Non-contiguous arrangement of display items");
}
boxes.ptr.range.unwrap().extend_by(1);
}
}
Expand Down Expand Up @@ -469,34 +471,35 @@ impl LayoutTask {
};
fn box_for_node(node: AbstractNode<LayoutView>) -> Option<Rect<Au>> {
do node.read_layout_data |layout_data| {
match (layout_data.boxes.display_list.clone(), layout_data.boxes.range) {
(Some(display_list), Some(range)) => {
let mut rect: Option<Rect<Au>> = None;
for i in range.eachi() {
rect = match rect {
Some(acc) => {
Some(acc.union(&display_list.get().list[i].bounds()))
}
None => Some(display_list.get().list[i].bounds())
// FIXME(pcwalton): Why are we cloning the display list here?!
let boxes = node.layout_data().boxes.borrow();
let boxes = boxes.ptr;
match (boxes.display_list.clone(), boxes.range) {
(Some(display_list), Some(range)) => {
let mut rect: Option<Rect<Au>> = None;
for i in range.eachi() {
rect = match rect {
Some(acc) => {
Some(acc.union(&display_list.get().list[i].bounds()))
}
None => Some(display_list.get().list[i].bounds())
}
rect
}
_ => {
let mut acc: Option<Rect<Au>> = None;
for child in node.children() {
let rect = box_for_node(child);
match rect {
None => continue,
Some(rect) => acc = match acc {
Some(acc) => Some(acc.union(&rect)),
None => Some(rect)
}
rect
}
_ => {
let mut acc: Option<Rect<Au>> = None;
for child in node.children() {
let rect = box_for_node(child);
match rect {
None => continue,
Some(rect) => acc = match acc {
Some(acc) => Some(acc.union(&rect)),
None => Some(rect)
}
}
acc
}
acc
}
}
}
Expand All @@ -511,25 +514,23 @@ impl LayoutTask {
transmute(node)
};
fn boxes_for_node(node: AbstractNode<LayoutView>,
boxes: ~[Rect<Au>]) -> ~[Rect<Au>] {
let boxes = Cell::new(boxes);
do node.read_layout_data |layout_data| {
let mut boxes = boxes.take();
match (layout_data.boxes.display_list.clone(), layout_data.boxes.range) {
(Some(display_list), Some(range)) => {
for i in range.eachi() {
boxes.push(display_list.get().list[i].bounds());
}
fn boxes_for_node(node: AbstractNode<LayoutView>, mut box_accumulator: ~[Rect<Au>])
-> ~[Rect<Au>] {
let boxes = node.layout_data().boxes.borrow();
let boxes = boxes.ptr;
match (boxes.display_list.clone(), boxes.range) {
(Some(display_list), Some(range)) => {
for i in range.eachi() {
box_accumulator.push(display_list.get().list[i].bounds());
}
_ => {
for child in node.children() {
boxes = boxes_for_node(child, boxes);
}
}
_ => {
for child in node.children() {
box_accumulator = boxes_for_node(child, box_accumulator);
}
}
boxes
}
box_accumulator
}
let mut boxes = ~[];
Expand Down
Loading

0 comments on commit 76a5ae5

Please sign in to comment.