servo: Merge #8212 - Remove SharedLayoutContext::reflow_root (from Ms2ger:reflow-root); r=pcwalton

Source-Repo: https://github.com/servo/servo
Source-Revision: b6bcccb204f710665482fa8098084a30126a3bac
This commit is contained in:
Ms2ger 2015-10-30 04:53:54 +05:01
Родитель 1b01c21c9d
Коммит fad7f9bff1
6 изменённых файлов: 47 добавлений и 45 удалений

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

@ -102,9 +102,6 @@ pub struct SharedLayoutContext {
/// FIXME(#2604): Make this no longer an unsafe pointer once we have fast `RWArc`s.
pub stylist: *const Stylist,
/// The root node at which we're starting the layout.
pub reflow_root: Option<OpaqueNode>,
/// The URL.
pub url: Url,

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

@ -441,7 +441,6 @@ impl LayoutTask {
fn build_shared_layout_context(&self,
rw_data: &LayoutTaskData,
screen_size_changed: bool,
reflow_root: Option<&LayoutNode>,
url: &Url,
goal: ReflowGoal)
-> SharedLayoutContext {
@ -456,7 +455,6 @@ impl LayoutTask {
canvas_layers_sender: self.canvas_layers_sender.clone(),
stylist: &*rw_data.stylist,
url: (*url).clone(),
reflow_root: reflow_root.map(|node| node.opaque()),
visible_rects: rw_data.visible_rects.clone(),
generation: rw_data.generation,
new_animations_sender: rw_data.new_animations_sender.clone(),
@ -557,7 +555,6 @@ impl LayoutTask {
let mut layout_context = self.build_shared_layout_context(&*rw_data,
false,
None,
&self.url,
reflow_info.goal);
@ -1210,7 +1207,6 @@ impl LayoutTask {
// Create a layout context for use throughout the following passes.
let mut shared_layout_context = self.build_shared_layout_context(&*rw_data,
screen_size_changed,
Some(&node),
&self.url,
data.reflow_info.goal);
@ -1319,7 +1315,6 @@ impl LayoutTask {
let mut layout_context = self.build_shared_layout_context(&*rw_data,
false,
None,
&self.url,
reflow_info.goal);
@ -1342,7 +1337,6 @@ impl LayoutTask {
let mut layout_context = self.build_shared_layout_context(&*rw_data,
false,
None,
&self.url,
reflow_info.goal);
@ -1376,7 +1370,6 @@ impl LayoutTask {
let mut layout_context = self.build_shared_layout_context(&*rw_data,
false,
None,
&self.url,
reflow_info.goal);

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

@ -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);
}

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

@ -33,9 +33,15 @@ pub fn traverse_dom_preorder(root: LayoutNode,
construct_flows.process(node);
}
let layout_context = LayoutContext::new(shared_layout_context);
let recalc_style = RecalcStyleForNode { layout_context: &layout_context };
let construct_flows = ConstructFlows { layout_context: &layout_context };
let layout_context = LayoutContext::new(shared_layout_context);
let recalc_style = RecalcStyleForNode {
layout_context: &layout_context,
root: root.opaque(),
};
let construct_flows = ConstructFlows {
layout_context: &layout_context,
root: root.opaque(),
};
doit(root, recalc_style, construct_flows);
}

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

@ -9,6 +9,7 @@ use context::LayoutContext;
use css::matching::{ApplicableDeclarations, ElementMatchMethods, MatchMethods, StyleSharingResult};
use flow::{MutableFlowUtils, PostorderFlowTraversal, PreorderFlowTraversal};
use flow::{self, Flow};
use gfx::display_list::OpaqueNode;
use incremental::{self, BUBBLE_ISIZES, REFLOW, REFLOW_OUT_OF_FLOW, RestyleDamage};
use script::layout_interface::ReflowGoal;
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,
/// 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> {
STYLE_BLOOM.with(|style_bloom| {
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.
(Some(parent), None) => {
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
}
// 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
// allocation to avoid malloc churn.
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
},
@ -96,14 +99,14 @@ fn put_task_local_bloom_filter(bf: Box<BloomFilter>,
/// "Ancestors" in this context is inclusive of ourselves.
fn insert_ancestors_into_bloom_filter(bf: &mut Box<BloomFilter>,
mut n: LayoutNode,
layout_context: &LayoutContext) {
root: OpaqueNode) {
debug!("[{}] Inserting ancestors.", tid());
let mut ancestors = 0;
loop {
ancestors += 1;
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,
Some(p) => p,
};
@ -135,6 +138,7 @@ pub trait PostorderNodeMutTraversal {
#[derive(Copy, Clone)]
pub struct RecalcStyleForNode<'a> {
pub layout_context: &'a LayoutContext<'a>,
pub root: OpaqueNode,
}
impl<'a> PreorderDomTraversal for RecalcStyleForNode<'a> {
@ -148,10 +152,10 @@ impl<'a> PreorderDomTraversal for RecalcStyleForNode<'a> {
node.initialize_layout_data();
// 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.
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;
if nonincremental_layout || node.is_dirty() {
@ -239,6 +243,7 @@ impl<'a> PreorderDomTraversal for RecalcStyleForNode<'a> {
#[derive(Copy, Clone)]
pub struct ConstructFlows<'a> {
pub layout_context: &'a LayoutContext<'a>,
pub root: OpaqueNode,
}
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_generation, self.layout_context.shared.generation);
match node.layout_parent_node(self.layout_context.shared) {
match node.layout_parent_node(self.root) {
None => {
debug!("[{}] - {:X}, and deleting BF.", tid(), unsafe_layout_node.0);
// If this is the reflow root, eat the task-local bloom filter.

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

@ -30,7 +30,6 @@
#![allow(unsafe_code)]
use context::SharedLayoutContext;
use data::{LayoutDataFlags, LayoutDataWrapper, PrivateLayoutData};
use gfx::display_list::OpaqueNode;
use gfx::text::glyph::CharIndex;
@ -191,16 +190,11 @@ impl<'ln> LayoutNode<'ln> {
/// 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.
pub fn layout_parent_node(self, shared: &SharedLayoutContext) -> 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 {
None
} else {
self.parent_node()
}
}
pub fn layout_parent_node(self, reflow_root: OpaqueNode) -> Option<LayoutNode<'ln>> {
if self.opaque() == reflow_root {
None
} else {
self.parent_node()
}
}