servo: Changed parallel css matching to use shared state instead of copying

Source-Repo: https://github.com/servo/servo
Source-Revision: ce615bf12a2998c10b3ae445ecfb7f854235edc2
This commit is contained in:
Margaret Meyerhofer 2012-06-20 12:44:03 -07:00
Родитель 8393ca8782
Коммит ec2c64a6ac
2 изменённых файлов: 27 добавлений и 15 удалений

Просмотреть файл

@ -3,6 +3,8 @@
rendered. rendered.
"]; "];
import arc::arc;
import display_list_builder::build_display_list; import display_list_builder::build_display_list;
import dom::base::{Node}; import dom::base::{Node};
import dom::style::stylesheet; import dom::style::stylesheet;
@ -36,7 +38,7 @@ fn layout(to_renderer: chan<renderer::Msg>) -> chan<Msg> {
node.dump(); node.dump();
node.initialize_style_for_subtree(); node.initialize_style_for_subtree();
node.recompute_style_for_subtree(styles); node.recompute_style_for_subtree(arc(styles));
let this_box = node.construct_boxes(); let this_box = node.construct_boxes();
this_box.dump(); this_box.dump();

Просмотреть файл

@ -1,5 +1,7 @@
#[doc="High-level interface to CSS selector matching."] #[doc="High-level interface to CSS selector matching."]
import arc::{arc, get, clone};
import dom::style::{display_type, di_block, di_inline, di_none, stylesheet}; import dom::style::{display_type, di_block, di_inline, di_none, stylesheet};
import dom::base::{Element, HTMLDivElement, HTMLHeadElement, HTMLImageElement, Node, NodeKind}; import dom::base::{Element, HTMLDivElement, HTMLHeadElement, HTMLImageElement, Node, NodeKind};
import dom::base::{Text}; import dom::base::{Text};
@ -15,8 +17,7 @@ type computed_style = {mut display : display_type, mut back_color : Color};
fn default_style_for_node_kind(kind: NodeKind) -> computed_style { fn default_style_for_node_kind(kind: NodeKind) -> computed_style {
alt kind { alt kind {
Text(*) { Text(*) {
{mut display: di_inline, {mut display: di_inline, mut back_color: white()}
mut back_color: white()}
} }
Element(element) { Element(element) {
let r = rand::rng(); let r = rand::rng();
@ -54,7 +55,9 @@ impl style_methods for Node {
fn initialize_style_for_subtree() { fn initialize_style_for_subtree() {
self.initialize_style(); self.initialize_style();
for ntree.each_child(self) { |kid| kid.initialize_style_for_subtree(); } for ntree.each_child(self) { |kid|
kid.initialize_style_for_subtree();
}
} }
#[doc=" #[doc="
@ -76,21 +79,28 @@ impl style_methods for Node {
This is, importantly, the function that updates the layout data for the node (the reader- This is, importantly, the function that updates the layout data for the node (the reader-
auxiliary box in the RCU model) with the computed style. auxiliary box in the RCU model) with the computed style.
"] "]
fn recompute_style_for_subtree(styles : stylesheet) { fn recompute_style_for_subtree(styles : arc<stylesheet>) {
listen { |ack_chan| listen { |ack_chan|
let mut i = 0u;
// TODO: Don't copy this for every element, look into shared, immutable state
let new_styles = copy styles;
task::spawn { || // Compute the styles of each of our children in parallel
self.match_css_style(new_styles); for ntree.each_child(self) { |kid|
ack_chan.send(()); i = i + 1u;
} let new_styles = clone(&styles);
for ntree.each_child(self) { |kid| kid.recompute_style_for_subtree(styles); } task::spawn { ||
kid.recompute_style_for_subtree(new_styles);
ack_chan.send(());
}
}
// Make sure we finish updating the tree before returning self.match_css_style(*get(&styles));
ack_chan.recv();
// Make sure we have finished updating the tree before returning
while i > 0 {
ack_chan.recv();
i = i - 1u;
}
} }
} }
} }