diff options
Diffstat (limited to 'components/layout/parallel.rs')
-rw-r--r-- | components/layout/parallel.rs | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/components/layout/parallel.rs b/components/layout/parallel.rs index 358a5e64f5e..1ea9bffeb51 100644 --- a/components/layout/parallel.rs +++ b/components/layout/parallel.rs @@ -11,6 +11,7 @@ use context::{LayoutContext, SharedLayoutContext}; use flow::{self, Flow, MutableFlowUtils, PostorderFlowTraversal, PreorderFlowTraversal}; use flow_ref::{self, FlowRef}; +use gfx::display_list::OpaqueNode; use profile_traits::time::{self, ProfilerMetadata, profile}; use std::mem; use std::sync::atomic::{AtomicIsize, Ordering}; @@ -81,7 +82,7 @@ impl DomParallelInfo { } } -pub type UnsafeLayoutNodeList = (Box<Vec<UnsafeLayoutNode>>, usize); +pub type UnsafeLayoutNodeList = (Box<Vec<UnsafeLayoutNode>>, OpaqueNode); pub type UnsafeFlowList = (Box<Vec<UnsafeLayoutNode>>, usize); @@ -90,7 +91,7 @@ pub type ChunkedDomTraversalFunction = &mut WorkerProxy<SharedLayoutContext, UnsafeLayoutNodeList>); pub type DomTraversalFunction = - extern "Rust" fn(UnsafeLayoutNode, + extern "Rust" fn(OpaqueNode, UnsafeLayoutNode, &mut WorkerProxy<SharedLayoutContext, UnsafeLayoutNodeList>); pub type ChunkedFlowTraversalFunction = @@ -138,14 +139,14 @@ pub trait ParallelPreorderDomTraversal : PreorderDomTraversal { } } else { // If there were no more children, start walking back up. - bottom_up_func(unsafe_node, proxy) + 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(), 0), + data: (box chunk.iter().cloned().collect(), unsafe_nodes.1), }); } } @@ -153,6 +154,8 @@ pub trait ParallelPreorderDomTraversal : PreorderDomTraversal { /// A parallel bottom-up DOM traversal. trait ParallelPostorderDomTraversal : PostorderDomTraversal { + fn root(&self) -> OpaqueNode; + /// Process current node and potentially traverse its ancestors. /// /// If we are the last child that finished processing, recursively process @@ -164,9 +167,7 @@ trait ParallelPostorderDomTraversal : PostorderDomTraversal { /// /// The only communication between siblings is that they both /// fetch-and-subtract the parent's children count. - fn run_parallel(&self, - unsafe_node: UnsafeLayoutNode, - proxy: &mut WorkerProxy<SharedLayoutContext, UnsafeLayoutNodeList>) { + fn run_parallel(&self, unsafe_node: UnsafeLayoutNode) { // Get a real layout node. let mut node: LayoutNode = unsafe { layout_node_from_unsafe_layout_node(&unsafe_node) @@ -175,8 +176,7 @@ trait ParallelPostorderDomTraversal : PostorderDomTraversal { // Perform the appropriate operation. self.process(node); - let shared_layout_context = proxy.user_data(); - let parent = match node.layout_parent_node(shared_layout_context) { + let parent = match node.layout_parent_node(self.root()) { None => break, Some(parent) => parent, }; @@ -361,7 +361,11 @@ impl<'a> ParallelPreorderFlowTraversal for ComputeAbsolutePositions<'a> { impl<'a> ParallelPostorderFlowTraversal for BuildDisplayList<'a> {} -impl<'a> ParallelPostorderDomTraversal for ConstructFlows<'a> {} +impl<'a> ParallelPostorderDomTraversal for ConstructFlows<'a> { + fn root(&self) -> OpaqueNode { + self.root + } +} impl <'a> ParallelPreorderDomTraversal for RecalcStyleForNode<'a> { fn run_parallel(&self, @@ -377,18 +381,21 @@ fn recalc_style(unsafe_nodes: UnsafeLayoutNodeList, let layout_context = LayoutContext::new(shared_layout_context); let recalc_style_for_node_traversal = RecalcStyleForNode { layout_context: &layout_context, + root: unsafe_nodes.1, }; recalc_style_for_node_traversal.run_parallel(unsafe_nodes, proxy) } -fn construct_flows(unsafe_node: UnsafeLayoutNode, +fn construct_flows(root: OpaqueNode, + unsafe_node: UnsafeLayoutNode, proxy: &mut WorkerProxy<SharedLayoutContext, UnsafeLayoutNodeList>) { let shared_layout_context = proxy.user_data(); let layout_context = LayoutContext::new(shared_layout_context); let construct_flows_traversal = ConstructFlows { layout_context: &layout_context, + root: root, }; - construct_flows_traversal.run_parallel(unsafe_node, proxy) + construct_flows_traversal.run_parallel(unsafe_node) } fn assign_inline_sizes(unsafe_flows: UnsafeFlowList, @@ -451,7 +458,7 @@ pub fn traverse_dom_preorder(root: LayoutNode, run_queue_with_custom_work_data_type(queue, |queue| { queue.push(WorkUnit { fun: recalc_style, - data: (box vec![layout_node_to_unsafe_layout_node(&root)], 0), + data: (box vec![layout_node_to_unsafe_layout_node(&root)], root.opaque()), }); }, shared_layout_context); } |