diff options
author | Bobby Holley <bobbyholley@gmail.com> | 2015-12-31 11:05:17 -0800 |
---|---|---|
committer | Bobby Holley <bobbyholley@gmail.com> | 2016-01-06 17:58:53 -0800 |
commit | ebc5eb1b98e07c9d130bec81400f917b33927447 (patch) | |
tree | 0c47467d3742aa0fac02a89af5bb84f275115fbf | |
parent | 238a8786de66344d2dd6855dca25a4d4be6fa949 (diff) | |
download | servo-ebc5eb1b98e07c9d130bec81400f917b33927447.tar.gz servo-ebc5eb1b98e07c9d130bec81400f917b33927447.zip |
Make parallel DOM traversal and style calculation operate on TNode instead of LayoutNode.
-rw-r--r-- | components/layout/parallel.rs | 9 | ||||
-rw-r--r-- | components/layout/traversal.rs | 13 | ||||
-rw-r--r-- | components/layout/wrapper.rs | 12 | ||||
-rw-r--r-- | components/style/dom.rs | 8 |
4 files changed, 30 insertions, 12 deletions
diff --git a/components/layout/parallel.rs b/components/layout/parallel.rs index fa52a7efdb2..a451747b410 100644 --- a/components/layout/parallel.rs +++ b/components/layout/parallel.rs @@ -15,14 +15,13 @@ use gfx::display_list::OpaqueNode; use profile_traits::time::{self, TimerMetadata, profile}; use std::mem; use std::sync::atomic::{AtomicIsize, Ordering}; -use style::dom::UnsafeNode; +use style::dom::{TNode, UnsafeNode}; use traversal::PostorderNodeMutTraversal; use traversal::{AssignBSizesAndStoreOverflow, AssignISizes, BubbleISizes}; use traversal::{BuildDisplayList, ComputeAbsolutePositions}; use traversal::{DomTraversal, DomTraversalContext}; use util::opts; use util::workqueue::{WorkQueue, WorkUnit, WorkerProxy}; -use wrapper::LayoutNode; const CHUNK_SIZE: usize = 64; @@ -236,7 +235,7 @@ impl<'a> ParallelPostorderFlowTraversal for BuildDisplayList<'a> {} #[inline(always)] fn top_down_dom<'ln, N, T>(unsafe_nodes: UnsafeNodeList, proxy: &mut WorkerProxy<SharedLayoutContext, UnsafeNodeList>) - where N: LayoutNode<'ln>, T: DomTraversal<'ln, N> { + where N: TNode<'ln>, T: DomTraversal<'ln, N> { let shared_layout_context = proxy.user_data(); let layout_context = LayoutContext::new(shared_layout_context); let traversal_context = DomTraversalContext { @@ -294,7 +293,7 @@ fn top_down_dom<'ln, N, T>(unsafe_nodes: UnsafeNodeList, fn bottom_up_dom<'ln, N, T>(root: OpaqueNode, unsafe_node: UnsafeNode, proxy: &mut WorkerProxy<SharedLayoutContext, UnsafeNodeList>) - where N: LayoutNode<'ln>, T: DomTraversal<'ln, N> { + where N: TNode<'ln>, T: DomTraversal<'ln, N> { let shared_layout_context = proxy.user_data(); let layout_context = LayoutContext::new(shared_layout_context); let traversal_context = DomTraversalContext { @@ -388,7 +387,7 @@ pub fn traverse_dom_preorder<'ln, N, T>( root: N, shared_layout_context: &SharedLayoutContext, queue: &mut WorkQueue<SharedLayoutContext, WorkQueueData>) - where N: LayoutNode<'ln>, T: DomTraversal<'ln, N> { + where N: TNode<'ln>, T: DomTraversal<'ln, N> { run_queue_with_custom_work_data_type(queue, |queue| { queue.push(WorkUnit { fun: top_down_dom::<N, T>, diff --git a/components/layout/traversal.rs b/components/layout/traversal.rs index b740e7dbcf3..a37d7301530 100644 --- a/components/layout/traversal.rs +++ b/components/layout/traversal.rs @@ -15,7 +15,7 @@ use selectors::bloom::BloomFilter; use std::cell::RefCell; use std::mem; use style::context::StyleContext; -use style::dom::{TRestyleDamage, UnsafeNode}; +use style::dom::{TNode, TRestyleDamage, UnsafeNode}; use style::matching::{ApplicableDeclarations, ElementMatchMethods, MatchMethods, StyleSharingResult}; use util::opts; use util::tid::tid; @@ -56,7 +56,7 @@ fn take_task_local_bloom_filter<'ln, N>(parent_node: Option<N>, root: OpaqueNode, layout_context: &LayoutContext) -> Box<BloomFilter> - where N: LayoutNode<'ln> { + where N: TNode<'ln> { STYLE_BLOOM.with(|style_bloom| { match (parent_node, style_bloom.borrow_mut().take()) { // Root node. Needs new bloom filter. @@ -102,7 +102,7 @@ fn put_task_local_bloom_filter(bf: Box<BloomFilter>, fn insert_ancestors_into_bloom_filter<'ln, N>(bf: &mut Box<BloomFilter>, mut n: N, root: OpaqueNode) - where N: LayoutNode<'ln> { + where N: TNode<'ln> { debug!("[{}] Inserting ancestors.", tid()); let mut ancestors = 0; loop { @@ -123,7 +123,7 @@ pub struct DomTraversalContext<'a> { pub root: OpaqueNode, } -pub trait DomTraversal<'ln, N: LayoutNode<'ln>> { +pub trait DomTraversal<'ln, N: TNode<'ln>> { fn process_preorder<'a>(context: &'a DomTraversalContext<'a>, node: N); fn process_postorder<'a>(context: &'a DomTraversalContext<'a>, node: N); } @@ -132,7 +132,7 @@ pub trait DomTraversal<'ln, N: LayoutNode<'ln>> { /// 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 { +impl<'ln, N: TNode<'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) {} } @@ -153,7 +153,7 @@ pub trait PostorderNodeMutTraversal<'ln, ConcreteThreadSafeLayoutNode: ThreadSaf /// layout computation. This computes the styles applied to each node. #[inline] #[allow(unsafe_code)] -fn recalc_style_at<'a, 'ln, N: LayoutNode<'ln>> (context: &'a DomTraversalContext<'a>, node: N) { +fn recalc_style_at<'a, 'ln, N: TNode<'ln>> (context: &'a DomTraversalContext<'a>, node: N) { // Initialize layout data. // // FIXME(pcwalton): Stop allocating here. Ideally this should just be done by the HTML @@ -171,7 +171,6 @@ fn recalc_style_at<'a, 'ln, N: LayoutNode<'ln>> (context: &'a DomTraversalContex // Remove existing CSS styles from nodes whose content has changed (e.g. text changed), // to force non-incremental reflow. if node.has_changed() { - let node = node.to_threadsafe(); node.unstyle(); } diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs index 4a3ca347848..aa947937d0b 100644 --- a/components/layout/wrapper.rs +++ b/components/layout/wrapper.rs @@ -275,6 +275,14 @@ impl<'ln> TNode<'ln> for ServoLayoutNode<'ln> { self.node.next_sibling_ref().map(|node| self.new_with_this_lifetime(&node)) } } + + fn style(&self) -> Ref<Arc<ComputedValues>> { + Ref::map(self.borrow_data().unwrap(), |data| data.style.as_ref().unwrap()) + } + + fn unstyle(self) { + self.mutate_data().unwrap().style = None; + } } impl<'ln> LayoutNode<'ln> for ServoLayoutNode<'ln> { @@ -696,6 +704,8 @@ pub trait ThreadSafeLayoutNode<'ln> : Clone + Copy + Sized { /// Returns the style results for the given node. If CSS selector matching /// has not yet been performed, fails. + /// + /// Unlike the version on TNode, this handles pseudo-elements. #[inline] fn style(&self) -> Ref<Arc<ComputedValues>> { Ref::map(self.borrow_layout_data().unwrap(), |data| { @@ -709,6 +719,8 @@ pub trait ThreadSafeLayoutNode<'ln> : Clone + Copy + Sized { } /// Removes the style from this node. + /// + /// Unlike the version on TNode, this handles pseudo-elements. fn unstyle(self) { let mut data = self.mutate_layout_data().unwrap(); let style = diff --git a/components/style/dom.rs b/components/style/dom.rs index 40933b03a7e..f85484e0c70 100644 --- a/components/style/dom.rs +++ b/components/style/dom.rs @@ -156,6 +156,14 @@ pub trait TNode<'ln> : Sized + Copy + Clone { fn prev_sibling(&self) -> Option<Self>; fn next_sibling(&self) -> Option<Self>; + + + /// Returns the style results for the given node. If CSS selector matching + /// has not yet been performed, fails. + fn style(&self) -> Ref<Arc<ComputedValues>>; + + /// Removes the style from this node. + fn unstyle(self); } pub trait TDocument<'ld> : Sized + Copy + Clone { |