mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Use the passed-in reflow root rather than the one stored in the SharedLayoutContext.
This commit is contained in:
parent
f6e3146de2
commit
9f91984415
4 changed files with 47 additions and 35 deletions
|
@ -11,6 +11,7 @@
|
||||||
use context::{LayoutContext, SharedLayoutContext};
|
use context::{LayoutContext, SharedLayoutContext};
|
||||||
use flow::{self, Flow, MutableFlowUtils, PostorderFlowTraversal, PreorderFlowTraversal};
|
use flow::{self, Flow, MutableFlowUtils, PostorderFlowTraversal, PreorderFlowTraversal};
|
||||||
use flow_ref::{self, FlowRef};
|
use flow_ref::{self, FlowRef};
|
||||||
|
use gfx::display_list::OpaqueNode;
|
||||||
use profile_traits::time::{self, ProfilerMetadata, profile};
|
use profile_traits::time::{self, ProfilerMetadata, profile};
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::sync::atomic::{AtomicIsize, Ordering};
|
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);
|
pub type UnsafeFlowList = (Box<Vec<UnsafeLayoutNode>>, usize);
|
||||||
|
|
||||||
|
@ -90,7 +91,7 @@ pub type ChunkedDomTraversalFunction =
|
||||||
&mut WorkerProxy<SharedLayoutContext, UnsafeLayoutNodeList>);
|
&mut WorkerProxy<SharedLayoutContext, UnsafeLayoutNodeList>);
|
||||||
|
|
||||||
pub type DomTraversalFunction =
|
pub type DomTraversalFunction =
|
||||||
extern "Rust" fn(UnsafeLayoutNode,
|
extern "Rust" fn(OpaqueNode, UnsafeLayoutNode,
|
||||||
&mut WorkerProxy<SharedLayoutContext, UnsafeLayoutNodeList>);
|
&mut WorkerProxy<SharedLayoutContext, UnsafeLayoutNodeList>);
|
||||||
|
|
||||||
pub type ChunkedFlowTraversalFunction =
|
pub type ChunkedFlowTraversalFunction =
|
||||||
|
@ -138,14 +139,14 @@ pub trait ParallelPreorderDomTraversal : PreorderDomTraversal {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// If there were no more children, start walking back up.
|
// 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) {
|
for chunk in discovered_child_nodes.chunks(CHUNK_SIZE) {
|
||||||
proxy.push(WorkUnit {
|
proxy.push(WorkUnit {
|
||||||
fun: top_down_func,
|
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.
|
/// A parallel bottom-up DOM traversal.
|
||||||
trait ParallelPostorderDomTraversal : PostorderDomTraversal {
|
trait ParallelPostorderDomTraversal : PostorderDomTraversal {
|
||||||
|
fn root(&self) -> OpaqueNode;
|
||||||
|
|
||||||
/// Process current node and potentially traverse its ancestors.
|
/// Process current node and potentially traverse its ancestors.
|
||||||
///
|
///
|
||||||
/// If we are the last child that finished processing, recursively process
|
/// 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
|
/// The only communication between siblings is that they both
|
||||||
/// fetch-and-subtract the parent's children count.
|
/// fetch-and-subtract the parent's children count.
|
||||||
fn run_parallel(&self,
|
fn run_parallel(&self, unsafe_node: UnsafeLayoutNode) {
|
||||||
unsafe_node: UnsafeLayoutNode,
|
|
||||||
proxy: &mut WorkerProxy<SharedLayoutContext, UnsafeLayoutNodeList>) {
|
|
||||||
// Get a real layout node.
|
// Get a real layout node.
|
||||||
let mut node: LayoutNode = unsafe {
|
let mut node: LayoutNode = unsafe {
|
||||||
layout_node_from_unsafe_layout_node(&unsafe_node)
|
layout_node_from_unsafe_layout_node(&unsafe_node)
|
||||||
|
@ -175,8 +176,7 @@ trait ParallelPostorderDomTraversal : PostorderDomTraversal {
|
||||||
// Perform the appropriate operation.
|
// Perform the appropriate operation.
|
||||||
self.process(node);
|
self.process(node);
|
||||||
|
|
||||||
let shared_layout_context = proxy.user_data();
|
let parent = match node.layout_parent_node(self.root()) {
|
||||||
let parent = match node.layout_parent_node(shared_layout_context) {
|
|
||||||
None => break,
|
None => break,
|
||||||
Some(parent) => parent,
|
Some(parent) => parent,
|
||||||
};
|
};
|
||||||
|
@ -361,7 +361,11 @@ impl<'a> ParallelPreorderFlowTraversal for ComputeAbsolutePositions<'a> {
|
||||||
|
|
||||||
impl<'a> ParallelPostorderFlowTraversal for BuildDisplayList<'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> {
|
impl <'a> ParallelPreorderDomTraversal for RecalcStyleForNode<'a> {
|
||||||
fn run_parallel(&self,
|
fn run_parallel(&self,
|
||||||
|
@ -377,18 +381,21 @@ fn recalc_style(unsafe_nodes: UnsafeLayoutNodeList,
|
||||||
let layout_context = LayoutContext::new(shared_layout_context);
|
let layout_context = LayoutContext::new(shared_layout_context);
|
||||||
let recalc_style_for_node_traversal = RecalcStyleForNode {
|
let recalc_style_for_node_traversal = RecalcStyleForNode {
|
||||||
layout_context: &layout_context,
|
layout_context: &layout_context,
|
||||||
|
root: unsafe_nodes.1,
|
||||||
};
|
};
|
||||||
recalc_style_for_node_traversal.run_parallel(unsafe_nodes, proxy)
|
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>) {
|
proxy: &mut WorkerProxy<SharedLayoutContext, UnsafeLayoutNodeList>) {
|
||||||
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 construct_flows_traversal = ConstructFlows {
|
||||||
layout_context: &layout_context,
|
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,
|
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| {
|
run_queue_with_custom_work_data_type(queue, |queue| {
|
||||||
queue.push(WorkUnit {
|
queue.push(WorkUnit {
|
||||||
fun: recalc_style,
|
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);
|
}, shared_layout_context);
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,8 +34,14 @@ pub fn traverse_dom_preorder(root: LayoutNode,
|
||||||
}
|
}
|
||||||
|
|
||||||
let layout_context = LayoutContext::new(shared_layout_context);
|
let layout_context = LayoutContext::new(shared_layout_context);
|
||||||
let recalc_style = RecalcStyleForNode { layout_context: &layout_context };
|
let recalc_style = RecalcStyleForNode {
|
||||||
let construct_flows = ConstructFlows { layout_context: &layout_context };
|
layout_context: &layout_context,
|
||||||
|
root: root.opaque(),
|
||||||
|
};
|
||||||
|
let construct_flows = ConstructFlows {
|
||||||
|
layout_context: &layout_context,
|
||||||
|
root: root.opaque(),
|
||||||
|
};
|
||||||
|
|
||||||
doit(root, recalc_style, construct_flows);
|
doit(root, recalc_style, construct_flows);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ use context::LayoutContext;
|
||||||
use css::matching::{ApplicableDeclarations, ElementMatchMethods, MatchMethods, StyleSharingResult};
|
use css::matching::{ApplicableDeclarations, ElementMatchMethods, MatchMethods, StyleSharingResult};
|
||||||
use flow::{MutableFlowUtils, PostorderFlowTraversal, PreorderFlowTraversal};
|
use flow::{MutableFlowUtils, PostorderFlowTraversal, PreorderFlowTraversal};
|
||||||
use flow::{self, Flow};
|
use flow::{self, Flow};
|
||||||
|
use gfx::display_list::OpaqueNode;
|
||||||
use incremental::{self, BUBBLE_ISIZES, REFLOW, REFLOW_OUT_OF_FLOW, RestyleDamage};
|
use incremental::{self, BUBBLE_ISIZES, REFLOW, REFLOW_OUT_OF_FLOW, RestyleDamage};
|
||||||
use script::layout_interface::ReflowGoal;
|
use script::layout_interface::ReflowGoal;
|
||||||
use selectors::bloom::BloomFilter;
|
use selectors::bloom::BloomFilter;
|
||||||
|
@ -50,7 +51,9 @@ thread_local!(
|
||||||
///
|
///
|
||||||
/// If one does not exist, a new one will be made for you. If it is out of date,
|
/// If one does not exist, a new one will be made for you. If it is out of date,
|
||||||
/// it will be cleared and reused.
|
/// it will be cleared and reused.
|
||||||
fn take_task_local_bloom_filter(parent_node: Option<LayoutNode>, layout_context: &LayoutContext)
|
fn take_task_local_bloom_filter(parent_node: Option<LayoutNode>,
|
||||||
|
root: OpaqueNode,
|
||||||
|
layout_context: &LayoutContext)
|
||||||
-> Box<BloomFilter> {
|
-> Box<BloomFilter> {
|
||||||
STYLE_BLOOM.with(|style_bloom| {
|
STYLE_BLOOM.with(|style_bloom| {
|
||||||
match (parent_node, style_bloom.borrow_mut().take()) {
|
match (parent_node, style_bloom.borrow_mut().take()) {
|
||||||
|
@ -62,7 +65,7 @@ fn take_task_local_bloom_filter(parent_node: Option<LayoutNode>, layout_context:
|
||||||
// No bloom filter for this thread yet.
|
// No bloom filter for this thread yet.
|
||||||
(Some(parent), None) => {
|
(Some(parent), None) => {
|
||||||
let mut bloom_filter = box BloomFilter::new();
|
let mut bloom_filter = box BloomFilter::new();
|
||||||
insert_ancestors_into_bloom_filter(&mut bloom_filter, parent, layout_context);
|
insert_ancestors_into_bloom_filter(&mut bloom_filter, parent, root);
|
||||||
bloom_filter
|
bloom_filter
|
||||||
}
|
}
|
||||||
// Found cached bloom filter.
|
// Found cached bloom filter.
|
||||||
|
@ -75,7 +78,7 @@ fn take_task_local_bloom_filter(parent_node: Option<LayoutNode>, layout_context:
|
||||||
// Oh no. the cached parent is stale. I guess we need a new one. Reuse the existing
|
// Oh no. the cached parent is stale. I guess we need a new one. Reuse the existing
|
||||||
// allocation to avoid malloc churn.
|
// allocation to avoid malloc churn.
|
||||||
bloom_filter.clear();
|
bloom_filter.clear();
|
||||||
insert_ancestors_into_bloom_filter(&mut bloom_filter, parent, layout_context);
|
insert_ancestors_into_bloom_filter(&mut bloom_filter, parent, root);
|
||||||
}
|
}
|
||||||
bloom_filter
|
bloom_filter
|
||||||
},
|
},
|
||||||
|
@ -96,14 +99,14 @@ fn put_task_local_bloom_filter(bf: Box<BloomFilter>,
|
||||||
/// "Ancestors" in this context is inclusive of ourselves.
|
/// "Ancestors" in this context is inclusive of ourselves.
|
||||||
fn insert_ancestors_into_bloom_filter(bf: &mut Box<BloomFilter>,
|
fn insert_ancestors_into_bloom_filter(bf: &mut Box<BloomFilter>,
|
||||||
mut n: LayoutNode,
|
mut n: LayoutNode,
|
||||||
layout_context: &LayoutContext) {
|
root: OpaqueNode) {
|
||||||
debug!("[{}] Inserting ancestors.", tid());
|
debug!("[{}] Inserting ancestors.", tid());
|
||||||
let mut ancestors = 0;
|
let mut ancestors = 0;
|
||||||
loop {
|
loop {
|
||||||
ancestors += 1;
|
ancestors += 1;
|
||||||
|
|
||||||
n.insert_into_bloom_filter(&mut **bf);
|
n.insert_into_bloom_filter(&mut **bf);
|
||||||
n = match n.layout_parent_node(layout_context.shared) {
|
n = match n.layout_parent_node(root) {
|
||||||
None => break,
|
None => break,
|
||||||
Some(p) => p,
|
Some(p) => p,
|
||||||
};
|
};
|
||||||
|
@ -135,6 +138,7 @@ pub trait PostorderNodeMutTraversal {
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub struct RecalcStyleForNode<'a> {
|
pub struct RecalcStyleForNode<'a> {
|
||||||
pub layout_context: &'a LayoutContext<'a>,
|
pub layout_context: &'a LayoutContext<'a>,
|
||||||
|
pub root: OpaqueNode,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> PreorderDomTraversal for RecalcStyleForNode<'a> {
|
impl<'a> PreorderDomTraversal for RecalcStyleForNode<'a> {
|
||||||
|
@ -148,10 +152,10 @@ impl<'a> PreorderDomTraversal for RecalcStyleForNode<'a> {
|
||||||
node.initialize_layout_data();
|
node.initialize_layout_data();
|
||||||
|
|
||||||
// Get the parent node.
|
// Get the parent node.
|
||||||
let parent_opt = node.layout_parent_node(self.layout_context.shared);
|
let parent_opt = node.layout_parent_node(self.root);
|
||||||
|
|
||||||
// Get the style bloom filter.
|
// Get the style bloom filter.
|
||||||
let mut bf = take_task_local_bloom_filter(parent_opt, self.layout_context);
|
let mut bf = take_task_local_bloom_filter(parent_opt, self.root, self.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() {
|
||||||
|
@ -239,6 +243,7 @@ impl<'a> PreorderDomTraversal for RecalcStyleForNode<'a> {
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub struct ConstructFlows<'a> {
|
pub struct ConstructFlows<'a> {
|
||||||
pub layout_context: &'a LayoutContext<'a>,
|
pub layout_context: &'a LayoutContext<'a>,
|
||||||
|
pub root: OpaqueNode,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> PostorderDomTraversal for ConstructFlows<'a> {
|
impl<'a> PostorderDomTraversal for ConstructFlows<'a> {
|
||||||
|
@ -283,7 +288,7 @@ impl<'a> PostorderDomTraversal for ConstructFlows<'a> {
|
||||||
assert_eq!(old_node, unsafe_layout_node);
|
assert_eq!(old_node, unsafe_layout_node);
|
||||||
assert_eq!(old_generation, self.layout_context.shared.generation);
|
assert_eq!(old_generation, self.layout_context.shared.generation);
|
||||||
|
|
||||||
match node.layout_parent_node(self.layout_context.shared) {
|
match node.layout_parent_node(self.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.
|
||||||
|
|
|
@ -30,7 +30,6 @@
|
||||||
|
|
||||||
#![allow(unsafe_code)]
|
#![allow(unsafe_code)]
|
||||||
|
|
||||||
use context::SharedLayoutContext;
|
|
||||||
use data::{LayoutDataFlags, LayoutDataWrapper, PrivateLayoutData};
|
use data::{LayoutDataFlags, LayoutDataWrapper, PrivateLayoutData};
|
||||||
use gfx::display_list::OpaqueNode;
|
use gfx::display_list::OpaqueNode;
|
||||||
use gfx::text::glyph::CharIndex;
|
use gfx::text::glyph::CharIndex;
|
||||||
|
@ -183,18 +182,13 @@ impl<'ln> LayoutNode<'ln> {
|
||||||
|
|
||||||
/// While doing a reflow, the node at the root has no parent, as far as we're
|
/// While doing a reflow, the node at the root has no parent, as far as we're
|
||||||
/// concerned. This method returns `None` at the reflow root.
|
/// concerned. This method returns `None` at the reflow root.
|
||||||
pub fn layout_parent_node(self, shared: &SharedLayoutContext) -> Option<LayoutNode<'ln>> {
|
pub fn layout_parent_node(self, reflow_root: OpaqueNode) -> Option<LayoutNode<'ln>> {
|
||||||
match shared.reflow_root {
|
|
||||||
None => panic!("layout_parent_node(): This layout has no access to the DOM!"),
|
|
||||||
Some(reflow_root) => {
|
|
||||||
if self.opaque() == reflow_root {
|
if self.opaque() == reflow_root {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
self.parent_node()
|
self.parent_node()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn debug_id(self) -> usize {
|
pub fn debug_id(self) -> usize {
|
||||||
self.opaque().to_untrusted_node_address().0 as usize
|
self.opaque().to_untrusted_node_address().0 as usize
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue