aboutsummaryrefslogtreecommitdiffstats
path: root/components/layout/parallel.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/layout/parallel.rs')
-rw-r--r--components/layout/parallel.rs45
1 files changed, 23 insertions, 22 deletions
diff --git a/components/layout/parallel.rs b/components/layout/parallel.rs
index 03aaa512d3e..a51f585eb3c 100644
--- a/components/layout/parallel.rs
+++ b/components/layout/parallel.rs
@@ -13,13 +13,13 @@ use flow::{self, Flow, MutableFlowUtils, PostorderFlowTraversal, PreorderFlowTra
use flow_ref::FlowRef;
use profile_traits::time::{self, TimerMetadata, profile};
use rayon;
+use servo_config::opts;
use std::mem;
use std::sync::atomic::{AtomicIsize, Ordering};
use style::dom::UnsafeNode;
use style::parallel::CHUNK_SIZE;
use traversal::{AssignISizes, BubbleISizes};
use traversal::AssignBSizes;
-use util::opts;
pub use style::parallel::traverse_dom;
@@ -50,9 +50,9 @@ pub fn borrowed_flow_to_unsafe_flow(flow: &Flow) -> UnsafeFlow {
}
pub type ChunkedFlowTraversalFunction<'scope> =
- extern "Rust" fn(Box<[UnsafeFlow]>, &'scope SharedLayoutContext, &rayon::Scope<'scope>);
+ extern "Rust" fn(Box<[UnsafeFlow]>, &rayon::Scope<'scope>, &'scope SharedLayoutContext);
-pub type FlowTraversalFunction = extern "Rust" fn(UnsafeFlow, &SharedLayoutContext);
+pub type FlowTraversalFunction = extern "Rust" fn(UnsafeFlow, &LayoutContext);
/// Information that we need stored in each flow.
pub struct FlowParallelInfo {
@@ -132,20 +132,22 @@ trait ParallelPostorderFlowTraversal : PostorderFlowTraversal {
trait ParallelPreorderFlowTraversal : PreorderFlowTraversal {
fn run_parallel<'scope>(&self,
unsafe_flows: &[UnsafeFlow],
- layout_context: &'scope SharedLayoutContext,
- scope: &rayon::Scope<'scope>);
+ scope: &rayon::Scope<'scope>,
+ shared: &'scope SharedLayoutContext);
fn should_record_thread_ids(&self) -> bool;
#[inline(always)]
fn run_parallel_helper<'scope>(&self,
unsafe_flows: &[UnsafeFlow],
- layout_context: &'scope SharedLayoutContext,
scope: &rayon::Scope<'scope>,
+ shared: &'scope SharedLayoutContext,
top_down_func: ChunkedFlowTraversalFunction<'scope>,
bottom_up_func: FlowTraversalFunction)
{
let mut discovered_child_flows = vec![];
+ let context = LayoutContext::new(&shared);
+
for unsafe_flow in unsafe_flows {
let mut had_children = false;
unsafe {
@@ -175,7 +177,7 @@ trait ParallelPreorderFlowTraversal : PreorderFlowTraversal {
// If there were no more children, start assigning block-sizes.
if !had_children {
- bottom_up_func(*unsafe_flow, layout_context)
+ bottom_up_func(*unsafe_flow, &context)
}
}
@@ -183,7 +185,7 @@ trait ParallelPreorderFlowTraversal : PreorderFlowTraversal {
let nodes = chunk.iter().cloned().collect::<Vec<_>>().into_boxed_slice();
scope.spawn(move |scope| {
- top_down_func(nodes, layout_context, scope);
+ top_down_func(nodes, scope, shared);
});
}
}
@@ -192,12 +194,12 @@ trait ParallelPreorderFlowTraversal : PreorderFlowTraversal {
impl<'a> ParallelPreorderFlowTraversal for AssignISizes<'a> {
fn run_parallel<'scope>(&self,
unsafe_flows: &[UnsafeFlow],
- layout_context: &'scope SharedLayoutContext,
- scope: &rayon::Scope<'scope>)
+ scope: &rayon::Scope<'scope>,
+ shared: &'scope SharedLayoutContext)
{
self.run_parallel_helper(unsafe_flows,
- layout_context,
scope,
+ shared,
assign_inline_sizes,
assign_block_sizes_and_store_overflow)
}
@@ -210,20 +212,19 @@ impl<'a> ParallelPreorderFlowTraversal for AssignISizes<'a> {
impl<'a> ParallelPostorderFlowTraversal for AssignBSizes<'a> {}
fn assign_inline_sizes<'scope>(unsafe_flows: Box<[UnsafeFlow]>,
- shared_layout_context: &'scope SharedLayoutContext,
- scope: &rayon::Scope<'scope>) {
+ scope: &rayon::Scope<'scope>,
+ shared: &'scope SharedLayoutContext) {
let assign_inline_sizes_traversal = AssignISizes {
- shared_context: &shared_layout_context.style_context,
+ shared_context: &shared.style_context,
};
- assign_inline_sizes_traversal.run_parallel(&unsafe_flows, shared_layout_context, scope)
+ assign_inline_sizes_traversal.run_parallel(&unsafe_flows, scope, shared)
}
fn assign_block_sizes_and_store_overflow(
unsafe_flow: UnsafeFlow,
- shared_layout_context: &SharedLayoutContext) {
- let layout_context = LayoutContext::new(shared_layout_context);
+ context: &LayoutContext) {
let assign_block_sizes_traversal = AssignBSizes {
- layout_context: &layout_context,
+ layout_context: context,
};
assign_block_sizes_traversal.run_parallel(unsafe_flow)
}
@@ -232,11 +233,11 @@ pub fn traverse_flow_tree_preorder(
root: &mut Flow,
profiler_metadata: Option<TimerMetadata>,
time_profiler_chan: time::ProfilerChan,
- shared_layout_context: &SharedLayoutContext,
+ shared: &SharedLayoutContext,
queue: &rayon::ThreadPool) {
if opts::get().bubble_inline_sizes_separately {
- let layout_context = LayoutContext::new(shared_layout_context);
- let bubble_inline_sizes = BubbleISizes { layout_context: &layout_context };
+ let context = LayoutContext::new(shared);
+ let bubble_inline_sizes = BubbleISizes { layout_context: &context };
root.traverse_postorder(&bubble_inline_sizes);
}
@@ -246,7 +247,7 @@ pub fn traverse_flow_tree_preorder(
rayon::scope(move |scope| {
profile(time::ProfilerCategory::LayoutParallelWarmup,
profiler_metadata, time_profiler_chan, move || {
- assign_inline_sizes(nodes, &shared_layout_context, scope);
+ assign_inline_sizes(nodes, scope, &shared);
});
});
});