mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
Refactor parallel dom traversal to be agnostic to the processing steps themselves.
This commit is contained in:
parent
5ad9207a99
commit
947134949a
4 changed files with 262 additions and 327 deletions
|
@ -69,6 +69,7 @@ use style::dom::{TDocument, TElement, TNode};
|
||||||
use style::media_queries::{Device, MediaType};
|
use style::media_queries::{Device, MediaType};
|
||||||
use style::selector_matching::{Stylist, USER_OR_USER_AGENT_STYLESHEETS};
|
use style::selector_matching::{Stylist, USER_OR_USER_AGENT_STYLESHEETS};
|
||||||
use style::stylesheets::{CSSRuleIteratorExt, Stylesheet};
|
use style::stylesheets::{CSSRuleIteratorExt, Stylesheet};
|
||||||
|
use traversal::RecalcStyleAndConstructFlows;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
use util::geometry::MAX_RECT;
|
use util::geometry::MAX_RECT;
|
||||||
use util::ipc::OptionalIpcSender;
|
use util::ipc::OptionalIpcSender;
|
||||||
|
@ -1024,10 +1025,12 @@ impl LayoutTask {
|
||||||
// Perform CSS selector matching and flow construction.
|
// Perform CSS selector matching and flow construction.
|
||||||
match self.parallel_traversal {
|
match self.parallel_traversal {
|
||||||
None => {
|
None => {
|
||||||
sequential::traverse_dom_preorder(node, &shared_layout_context);
|
sequential::traverse_dom_preorder::<ServoLayoutNode, RecalcStyleAndConstructFlows>(
|
||||||
|
node, &shared_layout_context);
|
||||||
}
|
}
|
||||||
Some(ref mut traversal) => {
|
Some(ref mut traversal) => {
|
||||||
parallel::traverse_dom_preorder(node, &shared_layout_context, traversal);
|
parallel::traverse_dom_preorder::<ServoLayoutNode, RecalcStyleAndConstructFlows>(
|
||||||
|
node, &shared_layout_context, traversal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -19,8 +19,7 @@ use style::dom::UnsafeNode;
|
||||||
use traversal::PostorderNodeMutTraversal;
|
use traversal::PostorderNodeMutTraversal;
|
||||||
use traversal::{AssignBSizesAndStoreOverflow, AssignISizes, BubbleISizes};
|
use traversal::{AssignBSizesAndStoreOverflow, AssignISizes, BubbleISizes};
|
||||||
use traversal::{BuildDisplayList, ComputeAbsolutePositions};
|
use traversal::{BuildDisplayList, ComputeAbsolutePositions};
|
||||||
use traversal::{ConstructFlows, RecalcStyleForNode};
|
use traversal::{DomTraversal, DomTraversalContext};
|
||||||
use traversal::{PostorderDomTraversal, PreorderDomTraversal};
|
|
||||||
use util::opts;
|
use util::opts;
|
||||||
use util::workqueue::{WorkQueue, WorkUnit, WorkerProxy};
|
use util::workqueue::{WorkQueue, WorkUnit, WorkerProxy};
|
||||||
use wrapper::LayoutNode;
|
use wrapper::LayoutNode;
|
||||||
|
@ -73,105 +72,6 @@ pub type ChunkedFlowTraversalFunction =
|
||||||
|
|
||||||
pub type FlowTraversalFunction = extern "Rust" fn(UnsafeFlow, &SharedLayoutContext);
|
pub type FlowTraversalFunction = extern "Rust" fn(UnsafeFlow, &SharedLayoutContext);
|
||||||
|
|
||||||
/// A parallel top-down DOM traversal.
|
|
||||||
pub trait ParallelPreorderDomTraversal<'ln, ConcreteLayoutNode>
|
|
||||||
: PreorderDomTraversal<'ln, ConcreteLayoutNode>
|
|
||||||
where ConcreteLayoutNode: LayoutNode<'ln> {
|
|
||||||
fn run_parallel(&self,
|
|
||||||
nodes: UnsafeNodeList,
|
|
||||||
proxy: &mut WorkerProxy<SharedLayoutContext, UnsafeNodeList>);
|
|
||||||
|
|
||||||
#[inline(always)]
|
|
||||||
fn run_parallel_helper(
|
|
||||||
&self,
|
|
||||||
unsafe_nodes: UnsafeNodeList,
|
|
||||||
proxy: &mut WorkerProxy<SharedLayoutContext, UnsafeNodeList>,
|
|
||||||
top_down_func: ChunkedDomTraversalFunction,
|
|
||||||
bottom_up_func: DomTraversalFunction) {
|
|
||||||
let mut discovered_child_nodes = Vec::new();
|
|
||||||
for unsafe_node in *unsafe_nodes.0 {
|
|
||||||
// Get a real layout node.
|
|
||||||
let node = unsafe { ConcreteLayoutNode::from_unsafe(&unsafe_node) };
|
|
||||||
|
|
||||||
// Perform the appropriate traversal.
|
|
||||||
self.process(node);
|
|
||||||
|
|
||||||
let child_count = node.children_count();
|
|
||||||
|
|
||||||
// Reset the count of children.
|
|
||||||
{
|
|
||||||
let data = node.mutate_data().unwrap();
|
|
||||||
data.parallel.children_count.store(child_count as isize,
|
|
||||||
Ordering::Relaxed);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Possibly enqueue the children.
|
|
||||||
if child_count != 0 {
|
|
||||||
for kid in node.children() {
|
|
||||||
discovered_child_nodes.push(kid.to_unsafe())
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// If there were no more children, start walking back up.
|
|
||||||
bottom_up_func(unsafe_nodes.1, unsafe_node, proxy)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for chunk in discovered_child_nodes.chunks(CHUNK_SIZE) {
|
|
||||||
proxy.push(WorkUnit {
|
|
||||||
fun: top_down_func,
|
|
||||||
data: (box chunk.iter().cloned().collect(), unsafe_nodes.1),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A parallel bottom-up DOM traversal.
|
|
||||||
trait ParallelPostorderDomTraversal<'ln, ConcreteLayoutNode>
|
|
||||||
: PostorderDomTraversal<'ln, ConcreteLayoutNode>
|
|
||||||
where ConcreteLayoutNode: LayoutNode<'ln> {
|
|
||||||
fn root(&self) -> OpaqueNode;
|
|
||||||
|
|
||||||
/// Process current node and potentially traverse its ancestors.
|
|
||||||
///
|
|
||||||
/// If we are the last child that finished processing, recursively process
|
|
||||||
/// our parent. Else, stop. Also, stop at the root.
|
|
||||||
///
|
|
||||||
/// Thus, if we start with all the leaves of a tree, we end up traversing
|
|
||||||
/// the whole tree bottom-up because each parent will be processed exactly
|
|
||||||
/// once (by the last child that finishes processing).
|
|
||||||
///
|
|
||||||
/// The only communication between siblings is that they both
|
|
||||||
/// fetch-and-subtract the parent's children count.
|
|
||||||
fn run_parallel(&self, unsafe_node: UnsafeNode) {
|
|
||||||
// Get a real layout node.
|
|
||||||
let mut node = unsafe { ConcreteLayoutNode::from_unsafe(&unsafe_node) };
|
|
||||||
loop {
|
|
||||||
// Perform the appropriate operation.
|
|
||||||
self.process(node);
|
|
||||||
|
|
||||||
let parent = match node.layout_parent_node(self.root()) {
|
|
||||||
None => break,
|
|
||||||
Some(parent) => parent,
|
|
||||||
};
|
|
||||||
|
|
||||||
let parent_data = unsafe {
|
|
||||||
&*parent.borrow_data_unchecked().unwrap()
|
|
||||||
};
|
|
||||||
|
|
||||||
if parent_data
|
|
||||||
.parallel
|
|
||||||
.children_count
|
|
||||||
.fetch_sub(1, Ordering::Relaxed) != 1 {
|
|
||||||
// Get out of here and find another node to work on.
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
// We were the last child of our parent. Construct flows for our parent.
|
|
||||||
node = parent;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Information that we need stored in each flow.
|
/// Information that we need stored in each flow.
|
||||||
pub struct FlowParallelInfo {
|
pub struct FlowParallelInfo {
|
||||||
/// The number of children that still need work done.
|
/// The number of children that still need work done.
|
||||||
|
@ -332,59 +232,102 @@ impl<'a> ParallelPreorderFlowTraversal for ComputeAbsolutePositions<'a> {
|
||||||
|
|
||||||
impl<'a> ParallelPostorderFlowTraversal for BuildDisplayList<'a> {}
|
impl<'a> ParallelPostorderFlowTraversal for BuildDisplayList<'a> {}
|
||||||
|
|
||||||
impl<'a, 'ln, ConcreteLayoutNode> ParallelPostorderDomTraversal<'ln, ConcreteLayoutNode>
|
/// A parallel top-down DOM traversal.
|
||||||
for ConstructFlows<'a>
|
#[inline(always)]
|
||||||
where ConcreteLayoutNode: LayoutNode<'ln> {
|
fn top_down_dom<'ln, N, T>(unsafe_nodes: UnsafeNodeList,
|
||||||
fn root(&self) -> OpaqueNode {
|
|
||||||
self.root
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, 'ln, ConcreteLayoutNode> ParallelPreorderDomTraversal<'ln, ConcreteLayoutNode>
|
|
||||||
for RecalcStyleForNode<'a>
|
|
||||||
where ConcreteLayoutNode: LayoutNode<'ln> {
|
|
||||||
fn run_parallel(&self,
|
|
||||||
unsafe_nodes: UnsafeNodeList,
|
|
||||||
proxy: &mut WorkerProxy<SharedLayoutContext, UnsafeNodeList>) {
|
|
||||||
// Not exactly sure why we need UFCS here, but we seem to.
|
|
||||||
<RecalcStyleForNode<'a> as ParallelPreorderDomTraversal<'ln, ConcreteLayoutNode>>
|
|
||||||
::run_parallel_helper(self, unsafe_nodes, proxy,
|
|
||||||
recalc_style::<'ln, ConcreteLayoutNode>,
|
|
||||||
construct_flows::<'ln, ConcreteLayoutNode>)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn recalc_style<'ln, ConcreteLayoutNode>(unsafe_nodes: UnsafeNodeList,
|
|
||||||
proxy: &mut WorkerProxy<SharedLayoutContext, UnsafeNodeList>)
|
proxy: &mut WorkerProxy<SharedLayoutContext, UnsafeNodeList>)
|
||||||
where ConcreteLayoutNode: LayoutNode<'ln> {
|
where N: LayoutNode<'ln>, T: DomTraversal<'ln, N> {
|
||||||
let shared_layout_context = proxy.user_data();
|
let shared_layout_context = proxy.user_data();
|
||||||
let layout_context = LayoutContext::new(shared_layout_context);
|
let layout_context = LayoutContext::new(shared_layout_context);
|
||||||
let recalc_style_for_node_traversal = RecalcStyleForNode {
|
let traversal_context = DomTraversalContext {
|
||||||
layout_context: &layout_context,
|
layout_context: &layout_context,
|
||||||
root: unsafe_nodes.1,
|
root: unsafe_nodes.1,
|
||||||
};
|
};
|
||||||
|
|
||||||
// The UFCS is necessary here to select the proper set of generic routines which
|
let mut discovered_child_nodes = Vec::new();
|
||||||
// will eventually cast the UnsafeNode to a concrete LayoutNode implementation.
|
for unsafe_node in *unsafe_nodes.0 {
|
||||||
<RecalcStyleForNode as ParallelPreorderDomTraversal<'ln, ConcreteLayoutNode>>
|
// Get a real layout node.
|
||||||
::run_parallel(&recalc_style_for_node_traversal, unsafe_nodes, proxy)
|
let node = unsafe { N::from_unsafe(&unsafe_node) };
|
||||||
|
|
||||||
|
// Perform the appropriate traversal.
|
||||||
|
T::process_preorder(&traversal_context, node);
|
||||||
|
|
||||||
|
let child_count = node.children_count();
|
||||||
|
|
||||||
|
// Reset the count of children.
|
||||||
|
{
|
||||||
|
let data = node.mutate_data().unwrap();
|
||||||
|
data.parallel.children_count.store(child_count as isize,
|
||||||
|
Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn construct_flows<'ln, ConcreteLayoutNode: LayoutNode<'ln>>(
|
// Possibly enqueue the children.
|
||||||
root: OpaqueNode,
|
if child_count != 0 {
|
||||||
|
for kid in node.children() {
|
||||||
|
discovered_child_nodes.push(kid.to_unsafe())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// If there were no more children, start walking back up.
|
||||||
|
bottom_up_dom::<N, T>(unsafe_nodes.1, unsafe_node, proxy)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for chunk in discovered_child_nodes.chunks(CHUNK_SIZE) {
|
||||||
|
proxy.push(WorkUnit {
|
||||||
|
fun: top_down_dom::<N, T>,
|
||||||
|
data: (box chunk.iter().cloned().collect(), unsafe_nodes.1),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Process current node and potentially traverse its ancestors.
|
||||||
|
///
|
||||||
|
/// If we are the last child that finished processing, recursively process
|
||||||
|
/// our parent. Else, stop. Also, stop at the root.
|
||||||
|
///
|
||||||
|
/// Thus, if we start with all the leaves of a tree, we end up traversing
|
||||||
|
/// the whole tree bottom-up because each parent will be processed exactly
|
||||||
|
/// once (by the last child that finishes processing).
|
||||||
|
///
|
||||||
|
/// The only communication between siblings is that they both
|
||||||
|
/// fetch-and-subtract the parent's children count.
|
||||||
|
fn bottom_up_dom<'ln, N, T>(root: OpaqueNode,
|
||||||
unsafe_node: UnsafeNode,
|
unsafe_node: UnsafeNode,
|
||||||
proxy: &mut WorkerProxy<SharedLayoutContext, UnsafeNodeList>) {
|
proxy: &mut WorkerProxy<SharedLayoutContext, UnsafeNodeList>)
|
||||||
|
where N: LayoutNode<'ln>, T: DomTraversal<'ln, N> {
|
||||||
let shared_layout_context = proxy.user_data();
|
let shared_layout_context = proxy.user_data();
|
||||||
let layout_context = LayoutContext::new(shared_layout_context);
|
let layout_context = LayoutContext::new(shared_layout_context);
|
||||||
let construct_flows_traversal = ConstructFlows {
|
let traversal_context = DomTraversalContext {
|
||||||
layout_context: &layout_context,
|
layout_context: &layout_context,
|
||||||
root: root,
|
root: root,
|
||||||
};
|
};
|
||||||
|
|
||||||
// The UFCS is necessary here to select the proper set of generic routines which
|
// Get a real layout node.
|
||||||
// will eventually cast the UnsafeNode to a concrete LayoutNode implementation.
|
let mut node = unsafe { N::from_unsafe(&unsafe_node) };
|
||||||
<ConstructFlows as ParallelPostorderDomTraversal<'ln, ConcreteLayoutNode>>
|
loop {
|
||||||
::run_parallel(&construct_flows_traversal, unsafe_node)
|
// Perform the appropriate operation.
|
||||||
|
T::process_postorder(&traversal_context, node);
|
||||||
|
|
||||||
|
let parent = match node.layout_parent_node(traversal_context.root) {
|
||||||
|
None => break,
|
||||||
|
Some(parent) => parent,
|
||||||
|
};
|
||||||
|
|
||||||
|
let parent_data = unsafe {
|
||||||
|
&*parent.borrow_data_unchecked().unwrap()
|
||||||
|
};
|
||||||
|
|
||||||
|
if parent_data
|
||||||
|
.parallel
|
||||||
|
.children_count
|
||||||
|
.fetch_sub(1, Ordering::Relaxed) != 1 {
|
||||||
|
// Get out of here and find another node to work on.
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
// We were the last child of our parent. Construct flows for our parent.
|
||||||
|
node = parent;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn assign_inline_sizes(unsafe_flows: UnsafeFlowList,
|
fn assign_inline_sizes(unsafe_flows: UnsafeFlowList,
|
||||||
|
@ -441,12 +384,14 @@ fn run_queue_with_custom_work_data_type<To, F>(
|
||||||
queue.run(shared_layout_context);
|
queue.run(shared_layout_context);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn traverse_dom_preorder<'ln, ConcreteLayoutNode: LayoutNode<'ln>>(root: ConcreteLayoutNode,
|
pub fn traverse_dom_preorder<'ln, N, T>(
|
||||||
|
root: N,
|
||||||
shared_layout_context: &SharedLayoutContext,
|
shared_layout_context: &SharedLayoutContext,
|
||||||
queue: &mut WorkQueue<SharedLayoutContext, WorkQueueData>) {
|
queue: &mut WorkQueue<SharedLayoutContext, WorkQueueData>)
|
||||||
|
where N: LayoutNode<'ln>, T: DomTraversal<'ln, N> {
|
||||||
run_queue_with_custom_work_data_type(queue, |queue| {
|
run_queue_with_custom_work_data_type(queue, |queue| {
|
||||||
queue.push(WorkUnit {
|
queue.push(WorkUnit {
|
||||||
fun: recalc_style::<'ln, ConcreteLayoutNode>,
|
fun: top_down_dom::<N, T>,
|
||||||
data: (box vec![root.to_unsafe()], root.opaque()),
|
data: (box vec![root.to_unsafe()], root.opaque()),
|
||||||
});
|
});
|
||||||
}, shared_layout_context);
|
}, shared_layout_context);
|
||||||
|
|
|
@ -14,39 +14,33 @@ use fragment::FragmentBorderBoxIterator;
|
||||||
use generated_content::ResolveGeneratedContent;
|
use generated_content::ResolveGeneratedContent;
|
||||||
use traversal::PostorderNodeMutTraversal;
|
use traversal::PostorderNodeMutTraversal;
|
||||||
use traversal::{AssignBSizesAndStoreOverflow, AssignISizes};
|
use traversal::{AssignBSizesAndStoreOverflow, AssignISizes};
|
||||||
use traversal::{BubbleISizes, ConstructFlows, RecalcStyleForNode};
|
use traversal::{BubbleISizes, BuildDisplayList, ComputeAbsolutePositions};
|
||||||
use traversal::{BuildDisplayList, ComputeAbsolutePositions};
|
use traversal::{DomTraversal, DomTraversalContext};
|
||||||
use traversal::{PostorderDomTraversal, PreorderDomTraversal};
|
|
||||||
use util::opts;
|
use util::opts;
|
||||||
use wrapper::LayoutNode;
|
use wrapper::LayoutNode;
|
||||||
|
|
||||||
pub fn traverse_dom_preorder<'le, N>(root: N,
|
pub fn traverse_dom_preorder<'ln, N, T>(root: N,
|
||||||
shared_layout_context: &SharedLayoutContext)
|
shared_layout_context: &SharedLayoutContext)
|
||||||
where N: LayoutNode<'le> {
|
where N: LayoutNode<'ln>,
|
||||||
fn doit<'le, N>(node: N,
|
T: DomTraversal<'ln, N> {
|
||||||
recalc_style: RecalcStyleForNode,
|
fn doit<'a, 'ln, N, T>(context: &'a DomTraversalContext<'a>, node: N)
|
||||||
construct_flows: ConstructFlows)
|
where N: LayoutNode<'ln>, T: DomTraversal<'ln, N> {
|
||||||
where N: LayoutNode<'le> {
|
T::process_preorder(context, node);
|
||||||
recalc_style.process(node);
|
|
||||||
|
|
||||||
for kid in node.children() {
|
for kid in node.children() {
|
||||||
doit(kid, recalc_style, construct_flows);
|
doit::<N, T>(context, kid);
|
||||||
}
|
}
|
||||||
|
|
||||||
construct_flows.process(node);
|
T::process_postorder(context, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
let layout_context = LayoutContext::new(shared_layout_context);
|
let layout_context = LayoutContext::new(shared_layout_context);
|
||||||
let recalc_style = RecalcStyleForNode {
|
let traversal_context = DomTraversalContext {
|
||||||
layout_context: &layout_context,
|
|
||||||
root: root.opaque(),
|
|
||||||
};
|
|
||||||
let construct_flows = ConstructFlows {
|
|
||||||
layout_context: &layout_context,
|
layout_context: &layout_context,
|
||||||
root: root.opaque(),
|
root: root.opaque(),
|
||||||
};
|
};
|
||||||
|
|
||||||
doit::<'le, N>(root, recalc_style, construct_flows);
|
doit::<N, T>(&traversal_context, root);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn resolve_generated_content(root: &mut FlowRef, shared_layout_context: &SharedLayoutContext) {
|
pub fn resolve_generated_content(root: &mut FlowRef, shared_layout_context: &SharedLayoutContext) {
|
||||||
|
|
|
@ -118,17 +118,30 @@ fn insert_ancestors_into_bloom_filter<'ln, N>(bf: &mut Box<BloomFilter>,
|
||||||
debug!("[{}] Inserted {} ancestors.", tid(), ancestors);
|
debug!("[{}] Inserted {} ancestors.", tid(), ancestors);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
/// A top-down traversal.
|
pub struct DomTraversalContext<'a> {
|
||||||
pub trait PreorderDomTraversal<'ln, ConcreteLayoutNode: LayoutNode<'ln>> {
|
pub layout_context: &'a LayoutContext<'a>,
|
||||||
/// The operation to perform. Return true to continue or false to stop.
|
pub root: OpaqueNode,
|
||||||
fn process(&self, node: ConcreteLayoutNode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A bottom-up traversal, with a optional in-order pass.
|
pub trait DomTraversal<'ln, N: LayoutNode<'ln>> {
|
||||||
pub trait PostorderDomTraversal<'ln, ConcreteLayoutNode: LayoutNode<'ln>> {
|
fn process_preorder<'a>(context: &'a DomTraversalContext<'a>, node: N);
|
||||||
/// The operation to perform. Return true to continue or false to stop.
|
fn process_postorder<'a>(context: &'a DomTraversalContext<'a>, node: N);
|
||||||
fn process(&self, node: ConcreteLayoutNode);
|
}
|
||||||
|
|
||||||
|
/// FIXME(bholley): I added this now to demonstrate the usefulness of the new design.
|
||||||
|
/// This is currently unused, but will be used shortly.
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub struct RecalcStyleOnly;
|
||||||
|
impl<'ln, N: LayoutNode<'ln>> DomTraversal<'ln, N> for RecalcStyleOnly {
|
||||||
|
fn process_preorder<'a>(context: &'a DomTraversalContext<'a>, node: N) { recalc_style_at(context, node); }
|
||||||
|
fn process_postorder<'a>(_: &'a DomTraversalContext<'a>, _: N) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct RecalcStyleAndConstructFlows;
|
||||||
|
impl<'ln, N: LayoutNode<'ln>> DomTraversal<'ln, N> for RecalcStyleAndConstructFlows {
|
||||||
|
fn process_preorder<'a>(context: &'a DomTraversalContext<'a>, node: N) { recalc_style_at(context, node); }
|
||||||
|
fn process_postorder<'a>(context: &'a DomTraversalContext<'a>, node: N) { construct_flows_at(context, node); }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A bottom-up, parallelizable traversal.
|
/// A bottom-up, parallelizable traversal.
|
||||||
|
@ -139,18 +152,9 @@ pub trait PostorderNodeMutTraversal<'ln, ConcreteThreadSafeLayoutNode: ThreadSaf
|
||||||
|
|
||||||
/// The recalc-style-for-node traversal, which styles each node and must run before
|
/// The recalc-style-for-node traversal, which styles each node and must run before
|
||||||
/// layout computation. This computes the styles applied to each node.
|
/// layout computation. This computes the styles applied to each node.
|
||||||
#[derive(Copy, Clone)]
|
|
||||||
pub struct RecalcStyleForNode<'a> {
|
|
||||||
pub layout_context: &'a LayoutContext<'a>,
|
|
||||||
pub root: OpaqueNode,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, 'ln, ConcreteLayoutNode> PreorderDomTraversal<'ln, ConcreteLayoutNode>
|
|
||||||
for RecalcStyleForNode<'a>
|
|
||||||
where ConcreteLayoutNode: LayoutNode<'ln> {
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
fn process(&self, node: ConcreteLayoutNode) {
|
fn recalc_style_at<'a, 'ln, N: LayoutNode<'ln>> (context: &'a DomTraversalContext<'a>, node: N) {
|
||||||
// Initialize layout data.
|
// Initialize layout data.
|
||||||
//
|
//
|
||||||
// FIXME(pcwalton): Stop allocating here. Ideally this should just be done by the HTML
|
// FIXME(pcwalton): Stop allocating here. Ideally this should just be done by the HTML
|
||||||
|
@ -158,10 +162,10 @@ impl<'a, 'ln, ConcreteLayoutNode> PreorderDomTraversal<'ln, ConcreteLayoutNode>
|
||||||
node.initialize_data();
|
node.initialize_data();
|
||||||
|
|
||||||
// Get the parent node.
|
// Get the parent node.
|
||||||
let parent_opt = node.layout_parent_node(self.root);
|
let parent_opt = node.layout_parent_node(context.root);
|
||||||
|
|
||||||
// Get the style bloom filter.
|
// Get the style bloom filter.
|
||||||
let mut bf = take_task_local_bloom_filter(parent_opt, self.root, self.layout_context);
|
let mut bf = take_task_local_bloom_filter(parent_opt, context.root, context.layout_context);
|
||||||
|
|
||||||
let nonincremental_layout = opts::get().nonincremental_layout;
|
let nonincremental_layout = opts::get().nonincremental_layout;
|
||||||
if nonincremental_layout || node.is_dirty() {
|
if nonincremental_layout || node.is_dirty() {
|
||||||
|
@ -174,7 +178,7 @@ impl<'a, 'ln, ConcreteLayoutNode> PreorderDomTraversal<'ln, ConcreteLayoutNode>
|
||||||
|
|
||||||
// Check to see whether we can share a style with someone.
|
// Check to see whether we can share a style with someone.
|
||||||
let style_sharing_candidate_cache =
|
let style_sharing_candidate_cache =
|
||||||
&mut self.layout_context.style_sharing_candidate_cache();
|
&mut context.layout_context.style_sharing_candidate_cache();
|
||||||
|
|
||||||
let sharing_result = match node.as_element() {
|
let sharing_result = match node.as_element() {
|
||||||
Some(element) => {
|
Some(element) => {
|
||||||
|
@ -194,7 +198,7 @@ impl<'a, 'ln, ConcreteLayoutNode> PreorderDomTraversal<'ln, ConcreteLayoutNode>
|
||||||
let shareable_element = match node.as_element() {
|
let shareable_element = match node.as_element() {
|
||||||
Some(element) => {
|
Some(element) => {
|
||||||
// Perform the CSS selector matching.
|
// Perform the CSS selector matching.
|
||||||
let stylist = unsafe { &*self.layout_context.shared_context().stylist.0 };
|
let stylist = unsafe { &*context.layout_context.shared_context().stylist.0 };
|
||||||
if element.match_element(stylist,
|
if element.match_element(stylist,
|
||||||
Some(&*bf),
|
Some(&*bf),
|
||||||
&mut applicable_declarations) {
|
&mut applicable_declarations) {
|
||||||
|
@ -214,11 +218,11 @@ impl<'a, 'ln, ConcreteLayoutNode> PreorderDomTraversal<'ln, ConcreteLayoutNode>
|
||||||
|
|
||||||
// Perform the CSS cascade.
|
// Perform the CSS cascade.
|
||||||
unsafe {
|
unsafe {
|
||||||
node.cascade_node(self.layout_context.shared,
|
node.cascade_node(context.layout_context.shared,
|
||||||
parent_opt,
|
parent_opt,
|
||||||
&applicable_declarations,
|
&applicable_declarations,
|
||||||
&mut self.layout_context.applicable_declarations_cache(),
|
&mut context.layout_context.applicable_declarations_cache(),
|
||||||
&self.layout_context.shared_context().new_animations_sender);
|
&context.layout_context.shared_context().new_animations_sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add ourselves to the LRU cache.
|
// Add ourselves to the LRU cache.
|
||||||
|
@ -241,23 +245,13 @@ impl<'a, 'ln, ConcreteLayoutNode> PreorderDomTraversal<'ln, ConcreteLayoutNode>
|
||||||
node.insert_into_bloom_filter(&mut *bf);
|
node.insert_into_bloom_filter(&mut *bf);
|
||||||
|
|
||||||
// NB: flow construction updates the bloom filter on the way up.
|
// NB: flow construction updates the bloom filter on the way up.
|
||||||
put_task_local_bloom_filter(bf, &unsafe_layout_node, self.layout_context);
|
put_task_local_bloom_filter(bf, &unsafe_layout_node, context.layout_context);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The flow construction traversal, which builds flows for styled nodes.
|
/// The flow construction traversal, which builds flows for styled nodes.
|
||||||
#[derive(Copy, Clone)]
|
|
||||||
pub struct ConstructFlows<'a> {
|
|
||||||
pub layout_context: &'a LayoutContext<'a>,
|
|
||||||
pub root: OpaqueNode,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, 'ln, ConcreteLayoutNode> PostorderDomTraversal<'ln, ConcreteLayoutNode>
|
|
||||||
for ConstructFlows<'a>
|
|
||||||
where ConcreteLayoutNode: LayoutNode<'ln> {
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
fn process(&self, node: ConcreteLayoutNode) {
|
fn construct_flows_at<'a, 'ln, N: LayoutNode<'ln>>(context: &'a DomTraversalContext<'a>, node: N) {
|
||||||
// Construct flows for this node.
|
// Construct flows for this node.
|
||||||
{
|
{
|
||||||
let tnode = node.to_threadsafe();
|
let tnode = node.to_threadsafe();
|
||||||
|
@ -265,7 +259,7 @@ impl<'a, 'ln, ConcreteLayoutNode> PostorderDomTraversal<'ln, ConcreteLayoutNode>
|
||||||
// Always reconstruct if incremental layout is turned off.
|
// Always reconstruct if incremental layout is turned off.
|
||||||
let nonincremental_layout = opts::get().nonincremental_layout;
|
let nonincremental_layout = opts::get().nonincremental_layout;
|
||||||
if nonincremental_layout || node.has_dirty_descendants() {
|
if nonincremental_layout || node.has_dirty_descendants() {
|
||||||
let mut flow_constructor = FlowConstructor::new(self.layout_context);
|
let mut flow_constructor = FlowConstructor::new(context.layout_context);
|
||||||
if nonincremental_layout || !flow_constructor.repair_if_possible(&tnode) {
|
if nonincremental_layout || !flow_constructor.repair_if_possible(&tnode) {
|
||||||
flow_constructor.process(&tnode);
|
flow_constructor.process(&tnode);
|
||||||
debug!("Constructed flow for {:x}: {:x}",
|
debug!("Constructed flow for {:x}: {:x}",
|
||||||
|
@ -294,9 +288,9 @@ impl<'a, 'ln, ConcreteLayoutNode> PostorderDomTraversal<'ln, ConcreteLayoutNode>
|
||||||
});
|
});
|
||||||
|
|
||||||
assert_eq!(old_node, unsafe_layout_node);
|
assert_eq!(old_node, unsafe_layout_node);
|
||||||
assert_eq!(old_generation, self.layout_context.shared_context().generation);
|
assert_eq!(old_generation, context.layout_context.shared_context().generation);
|
||||||
|
|
||||||
match node.layout_parent_node(self.root) {
|
match node.layout_parent_node(context.root) {
|
||||||
None => {
|
None => {
|
||||||
debug!("[{}] - {:X}, and deleting BF.", tid(), unsafe_layout_node.0);
|
debug!("[{}] - {:X}, and deleting BF.", tid(), unsafe_layout_node.0);
|
||||||
// If this is the reflow root, eat the task-local bloom filter.
|
// If this is the reflow root, eat the task-local bloom filter.
|
||||||
|
@ -305,11 +299,10 @@ impl<'a, 'ln, ConcreteLayoutNode> PostorderDomTraversal<'ln, ConcreteLayoutNode>
|
||||||
// Otherwise, put it back, but remove this node.
|
// Otherwise, put it back, but remove this node.
|
||||||
node.remove_from_bloom_filter(&mut *bf);
|
node.remove_from_bloom_filter(&mut *bf);
|
||||||
let unsafe_parent = parent.to_unsafe();
|
let unsafe_parent = parent.to_unsafe();
|
||||||
put_task_local_bloom_filter(bf, &unsafe_parent, self.layout_context);
|
put_task_local_bloom_filter(bf, &unsafe_parent, context.layout_context);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// The bubble-inline-sizes traversal, the first part of layout computation. This computes
|
/// The bubble-inline-sizes traversal, the first part of layout computation. This computes
|
||||||
/// preferred and intrinsic inline-sizes and bubbles them up the tree.
|
/// preferred and intrinsic inline-sizes and bubbles them up the tree.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue