Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

incremental restyle: Hoist most styling functionality from TNode to TElement #13956

Merged
merged 2 commits into from Oct 30, 2016
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Prev

Rename NodeData and associated data structures to Element*.

MozReview-Commit-ID: 96VsmsoZtjZ
  • Loading branch information
bholley committed Oct 29, 2016
commit be89f736751d63307c01750f98d5c07a1e940add
@@ -15,7 +15,7 @@ use script_layout_interface::wrapper_traits::{LayoutElement, LayoutNode, ThreadS
use std::mem;
use style::atomic_refcell::AtomicRefCell;
use style::context::{LocalStyleContext, SharedStyleContext, StyleContext};
use style::data::NodeData;
use style::data::ElementData;
use style::dom::{StylingMode, TElement, TNode};
use style::traversal::{DomTraversalContext, put_thread_local_bloom_filter};
use style::traversal::{recalc_style_at, remove_from_bloom_filter};
@@ -131,7 +131,7 @@ impl<'lc, N> DomTraversalContext<N> for RecalcStyleAndConstructFlows<'lc>
}
}

fn ensure_element_data(element: &N::ConcreteElement) -> &AtomicRefCell<NodeData> {
fn ensure_element_data(element: &N::ConcreteElement) -> &AtomicRefCell<ElementData> {
element.as_node().initialize_data();
element.get_style_data().unwrap()
}
@@ -42,7 +42,7 @@ pub type NonOpaqueStyleAndLayoutData = AtomicRefCell<PersistentLayoutData>;

pub trait LayoutNodeLayoutData {
/// Similar to borrow_data*, but returns the full PersistentLayoutData rather
/// than only the style::data::NodeData.
/// than only the style::data::ElementData.
fn borrow_layout_data(&self) -> Option<AtomicRef<PersistentLayoutData>>;
fn mutate_layout_data(&self) -> Option<AtomicRefMut<PersistentLayoutData>>;
fn flow_debug_id(self) -> usize;
@@ -60,7 +60,7 @@ use style::atomic_refcell::{AtomicRef, AtomicRefCell, AtomicRefMut};
use style::attr::AttrValue;
use style::computed_values::display;
use style::context::SharedStyleContext;
use style::data::NodeData;
use style::data::ElementData;
use style::dom::{LayoutIterator, NodeInfo, OpaqueNode, PresentationalHintsSynthetizer, TDocument, TElement, TNode};
use style::dom::{TRestyleDamage, UnsafeNode};
use style::element_state::*;
@@ -506,24 +506,24 @@ impl<'le> TElement for ServoLayoutElement<'le> {
old_value - 1
}

fn begin_styling(&self) -> AtomicRefMut<NodeData> {
fn begin_styling(&self) -> AtomicRefMut<ElementData> {
let mut data = self.mutate_data().unwrap();
data.gather_previous_styles(|| None);
data
}

fn borrow_data(&self) -> Option<AtomicRef<NodeData>> {
fn borrow_data(&self) -> Option<AtomicRef<ElementData>> {
self.get_style_data().map(|d| d.borrow())
}

}

impl<'le> LayoutElement for ServoLayoutElement<'le> {
fn get_style_data(&self) -> Option<&AtomicRefCell<NodeData>> {
fn get_style_data(&self) -> Option<&AtomicRefCell<ElementData>> {
unsafe {
self.get_style_and_layout_data().map(|d| {
let ppld: &AtomicRefCell<PartialPersistentLayoutData> = &**d.ptr;
let psd: &AtomicRefCell<NodeData> = transmute(ppld);
let psd: &AtomicRefCell<ElementData> = transmute(ppld);
psd
})
}
@@ -551,15 +551,13 @@ impl<'le> ServoLayoutElement<'le> {
}
}

fn mutate_data(&self) -> Option<AtomicRefMut<NodeData>> {
fn mutate_data(&self) -> Option<AtomicRefMut<ElementData>> {
self.get_style_data().map(|d| d.borrow_mut())
}

fn get_partial_layout_data(&self) -> Option<&AtomicRefCell<PartialPersistentLayoutData>> {
unsafe {
self.get_style_and_layout_data().map(|d| {
&**d.ptr
})
self.get_style_and_layout_data().map(|d| &**d.ptr)
}
}
}
@@ -1090,7 +1088,7 @@ impl<'le> ThreadSafeLayoutElement for ServoThreadSafeLayoutElement<'le> {
self.element.get_attr(namespace, name)
}

fn get_style_data(&self) -> Option<&AtomicRefCell<NodeData>> {
fn get_style_data(&self) -> Option<&AtomicRefCell<ElementData>> {
self.element.get_style_data()
}
}
@@ -53,14 +53,14 @@ use libc::c_void;
use restyle_damage::RestyleDamage;
use std::sync::atomic::AtomicIsize;
use style::atomic_refcell::AtomicRefCell;
use style::data::NodeData;
use style::data::ElementData;

pub struct PartialPersistentLayoutData {
/// Data that the style system associates with a node. When the
/// style system is being used standalone, this is all that hangs
/// off the node. This must be first to permit the various
/// transmutations between NodeData and PersistentLayoutData.
pub style_data: NodeData,
/// transmutations between ElementData and PersistentLayoutData.
pub style_data: ElementData,

/// Description of how to account for recent style changes.
pub restyle_damage: RestyleDamage,
@@ -72,7 +72,7 @@ pub struct PartialPersistentLayoutData {
impl PartialPersistentLayoutData {
pub fn new() -> Self {
PartialPersistentLayoutData {
style_data: NodeData::new(),
style_data: ElementData::new(),
restyle_damage: RestyleDamage::empty(),
parallel: DomParallelInfo::new(),
}
@@ -18,7 +18,7 @@ use string_cache::{Atom, Namespace};
use style::atomic_refcell::AtomicRefCell;
use style::computed_values::display;
use style::context::SharedStyleContext;
use style::data::NodeData;
use style::data::ElementData;
use style::dom::{LayoutIterator, NodeInfo, PresentationalHintsSynthetizer, TElement, TNode};
use style::dom::OpaqueNode;
use style::properties::ServoComputedValues;
@@ -274,7 +274,7 @@ pub trait DangerousThreadSafeLayoutNode: ThreadSafeLayoutNode {
}

pub trait LayoutElement: Clone + Copy + Sized + Debug + GetLayoutData + TElement {
fn get_style_data(&self) -> Option<&AtomicRefCell<NodeData>>;
fn get_style_data(&self) -> Option<&AtomicRefCell<ElementData>>;
}

pub trait ThreadSafeLayoutElement: Clone + Copy + Sized + Debug +
@@ -296,7 +296,7 @@ pub trait ThreadSafeLayoutElement: Clone + Copy + Sized + Debug +
#[inline]
fn get_attr(&self, namespace: &Namespace, name: &Atom) -> Option<&str>;

fn get_style_data(&self) -> Option<&AtomicRefCell<NodeData>>;
fn get_style_data(&self) -> Option<&AtomicRefCell<ElementData>>;

#[inline]
fn get_pseudo_element_type(&self) -> PseudoElementType<Option<display::T>>;
@@ -67,7 +67,7 @@
},
"raw_lines": [
"use atomic_refcell::AtomicRefCell;",
"use data::NodeData;",
"use data::ElementData;",
"pub use nsstring::nsStringRepr as nsString;"
],
"blacklist_types": ["nsString"],
@@ -226,7 +226,7 @@
}, {
"generic": False,
"gecko": "ServoNodeData",
"servo": "AtomicRefCell<NodeData>",
"servo": "AtomicRefCell<ElementData>",
}
],
},
@@ -35,25 +35,25 @@ impl DerefMut for PseudoStyles {
/// The styles associated with a node, including the styles for any
/// pseudo-elements.
#[derive(Clone, Debug)]
pub struct NodeStyles {
pub struct ElementStyles {
/// The results of CSS styling for this node.
pub primary: Arc<ComputedValues>,

/// The results of CSS styling for each pseudo-element (if any).
pub pseudos: PseudoStyles,
}

impl NodeStyles {
impl ElementStyles {
pub fn new(primary: Arc<ComputedValues>) -> Self {
NodeStyles {
ElementStyles {
primary: primary,
pseudos: PseudoStyles::empty(),
}
}
}

#[derive(Debug)]
enum NodeDataStyles {
enum ElementDataStyles {
/// The field has not been initialized.
Uninitialized,

@@ -64,19 +64,19 @@ enum NodeDataStyles {
/// immutable, but for now we need to mutate it a bit before styling to
/// handle animations.
///
/// Note that since NodeStyles contains an Arc, the null pointer
/// Note that since ElementStyles contains an Arc, the null pointer
/// optimization prevents the Option<> here from consuming an extra word.
Previous(Option<NodeStyles>),
Previous(Option<ElementStyles>),

/// The field holds the current, up-to-date style.
///
/// This is the output of the styling algorithm.
Current(NodeStyles),
Current(ElementStyles),
}

impl NodeDataStyles {
impl ElementDataStyles {
fn is_previous(&self) -> bool {
use self::NodeDataStyles::*;
use self::ElementDataStyles::*;
match *self {
Previous(_) => true,
_ => false,
@@ -113,34 +113,34 @@ impl RestyleData {
/// In both cases, it is wrapped inside an AtomicRefCell to ensure thread
/// safety.
#[derive(Debug)]
pub struct NodeData {
styles: NodeDataStyles,
pub struct ElementData {
styles: ElementDataStyles,
pub restyle_data: Option<RestyleData>,
}

impl NodeData {
impl ElementData {
pub fn new() -> Self {
NodeData {
styles: NodeDataStyles::Uninitialized,
ElementData {
styles: ElementDataStyles::Uninitialized,
restyle_data: None,
}
}

pub fn has_current_styles(&self) -> bool {
match self.styles {
NodeDataStyles::Current(_) => true,
ElementDataStyles::Current(_) => true,
_ => false,
}
}

pub fn get_current_styles(&self) -> Option<&NodeStyles> {
pub fn get_current_styles(&self) -> Option<&ElementStyles> {
match self.styles {
NodeDataStyles::Current(ref s) => Some(s),
ElementDataStyles::Current(ref s) => Some(s),
_ => None,
}
}

pub fn current_styles(&self) -> &NodeStyles {
pub fn current_styles(&self) -> &ElementStyles {
self.get_current_styles().expect("Calling current_styles before or during styling")
}

@@ -149,29 +149,29 @@ impl NodeData {
#[cfg(not(feature = "gecko"))]
pub fn current_pseudos_mut(&mut self) -> &mut PseudoStyles {
match self.styles {
NodeDataStyles::Current(ref mut s) => &mut s.pseudos,
ElementDataStyles::Current(ref mut s) => &mut s.pseudos,
_ => panic!("Calling current_pseudos_mut before or during styling"),
}
}

pub fn previous_styles(&self) -> Option<&NodeStyles> {
pub fn previous_styles(&self) -> Option<&ElementStyles> {
match self.styles {
NodeDataStyles::Previous(ref s) => s.as_ref(),
ElementDataStyles::Previous(ref s) => s.as_ref(),
_ => panic!("Calling previous_styles without having gathered it"),
}
}

pub fn previous_styles_mut(&mut self) -> Option<&mut NodeStyles> {
pub fn previous_styles_mut(&mut self) -> Option<&mut ElementStyles> {
match self.styles {
NodeDataStyles::Previous(ref mut s) => s.as_mut(),
ElementDataStyles::Previous(ref mut s) => s.as_mut(),
_ => panic!("Calling previous_styles without having gathered it"),
}
}

pub fn gather_previous_styles<F>(&mut self, f: F)
where F: FnOnce() -> Option<NodeStyles>
where F: FnOnce() -> Option<ElementStyles>
{
use self::NodeDataStyles::*;
use self::ElementDataStyles::*;
self.styles = match mem::replace(&mut self.styles, Uninitialized) {
Uninitialized => Previous(f()),
Current(x) => Previous(Some(x)),
@@ -186,13 +186,13 @@ impl NodeData {
}

pub fn style_text_node(&mut self, style: Arc<ComputedValues>) {
self.styles = NodeDataStyles::Current(NodeStyles::new(style));
self.styles = ElementDataStyles::Current(ElementStyles::new(style));
self.restyle_data = None;
}

pub fn finish_styling(&mut self, styles: NodeStyles) {
pub fn finish_styling(&mut self, styles: ElementStyles) {
debug_assert!(self.styles.is_previous());
self.styles = NodeDataStyles::Current(styles);
self.styles = ElementDataStyles::Current(styles);
self.restyle_data = None;
}
}
@@ -7,7 +7,7 @@
#![allow(unsafe_code)]

use atomic_refcell::{AtomicRef, AtomicRefMut};
use data::{NodeStyles, NodeData};
use data::{ElementStyles, ElementData};
use element_state::ElementState;
use parking_lot::RwLock;
use properties::{ComputedValues, PropertyDeclarationBlock};
@@ -219,10 +219,10 @@ pub trait TElement : PartialEq + Debug + Sized + Copy + Clone + ElementExt + Pre

/// Returns the styles from the layout frame that owns them, if any.
///
/// FIXME(bholley): Once we start dropping NodeData from nodes when
/// FIXME(bholley): Once we start dropping ElementData from nodes when
/// creating frames, we'll want to teach this method to actually get
/// style data from the frame.
fn get_styles_from_frame(&self) -> Option<NodeStyles> { None }
fn get_styles_from_frame(&self) -> Option<ElementStyles> { None }

/// Returns the styling mode for this node. This is only valid to call before
/// and during restyling, before finish_styling is invoked.
@@ -262,10 +262,10 @@ pub trait TElement : PartialEq + Debug + Sized + Copy + Clone + ElementExt + Pre
/// Sets up the appropriate data structures to style a node, returing a
/// mutable handle to the node data upon which further style calculations
/// can be performed.
fn begin_styling(&self) -> AtomicRefMut<NodeData>;
fn begin_styling(&self) -> AtomicRefMut<ElementData>;

/// Immutable borrows the NodeData.
fn borrow_data(&self) -> Option<AtomicRef<NodeData>>;
/// Immutable borrows the ElementData.
fn borrow_data(&self) -> Option<AtomicRef<ElementData>>;

/// Properly marks nodes as dirty in response to restyle hints.
fn note_restyle_hint<C: DomTraversalContext<Self::ConcreteNode>>(&self, hint: RestyleHint) {
@@ -4,7 +4,7 @@

use atomic_refcell::AtomicRefCell;
use context::{LocalStyleContext, SharedStyleContext, StyleContext};
use data::NodeData;
use data::ElementData;
use dom::{NodeInfo, OpaqueNode, StylingMode, TElement, TNode};
use gecko::context::StandaloneStyleContext;
use gecko::wrapper::{GeckoElement, GeckoNode};
@@ -55,7 +55,7 @@ impl<'lc, 'ln> DomTraversalContext<GeckoNode<'ln>> for RecalcStyleOnly<'lc> {
}
}

fn ensure_element_data<'a>(element: &'a GeckoElement<'ln>) -> &'a AtomicRefCell<NodeData> {
fn ensure_element_data<'a>(element: &'a GeckoElement<'ln>) -> &'a AtomicRefCell<ElementData> {
element.ensure_data()
}

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.