stylo: Allow computing change hints during the traversal.

This commit is contained in:
Emilio Cobos Álvarez 2016-07-28 19:36:37 -07:00
parent 67ac81f440
commit 1470d5b174
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
7 changed files with 55 additions and 21 deletions

View file

@ -44,7 +44,7 @@ bitflags! {
}
impl TRestyleDamage for RestyleDamage {
fn compute(old: Option<&Arc<ServoComputedValues>>, new: &ServoComputedValues) ->
fn compute(old: Option<&Arc<ServoComputedValues>>, new: &Arc<ServoComputedValues>) ->
RestyleDamage { compute_damage(old, new) }
/// Returns a bitmask that represents a flow that needs to be rebuilt and reflowed.
@ -143,7 +143,8 @@ macro_rules! add_if_not_equal(
})
);
fn compute_damage(old: Option<&Arc<ServoComputedValues>>, new: &ServoComputedValues) -> RestyleDamage {
fn compute_damage(old: Option<&Arc<ServoComputedValues>>, new: &Arc<ServoComputedValues>) -> RestyleDamage {
let new = &**new;
let old: &ServoComputedValues = match old {
None => return RestyleDamage::rebuild_and_reflow(),
Some(cv) => &**cv,

View file

@ -46,7 +46,7 @@ impl OpaqueNode {
}
pub trait TRestyleDamage : BitOr<Output=Self> + Copy {
fn compute(old: Option<&Arc<ComputedValues>>, new: &ComputedValues) -> Self;
fn compute(old: Option<&Arc<ComputedValues>>, new: &Arc<ComputedValues>) -> Self;
fn rebuild_and_reflow() -> Self;
}

View file

@ -13,7 +13,6 @@ pub struct ArcHelpers<GeckoType, ServoType> {
phantom2: PhantomData<ServoType>,
}
impl<GeckoType, ServoType> ArcHelpers<GeckoType, ServoType> {
pub fn with<F, Output>(raw: *mut GeckoType, cb: F) -> Output
where F: FnOnce(&Arc<ServoType>) -> Output {
@ -47,6 +46,10 @@ impl<GeckoType, ServoType> ArcHelpers<GeckoType, ServoType> {
unsafe { transmute(owned) }
}
pub unsafe fn borrow(borrowed: &Arc<ServoType>) -> *const &mut GeckoType {
transmute(borrowed)
}
pub unsafe fn addref(ptr: *mut GeckoType) {
Self::with(ptr, |arc| forget(arc.clone()));
}

View file

@ -443,7 +443,7 @@ trait PrivateMatchMethods: TNode
}
// Calculate style difference.
let damage = Self::ConcreteRestyleDamage::compute(style.map(|s| &*s), &*this_style);
let damage = Self::ConcreteRestyleDamage::compute(style.map(|s| &*s), &this_style);
// Cache the resolved style if it was cacheable.
if cacheable {
@ -587,7 +587,7 @@ pub trait ElementMatchMethods : TElement {
let node = self.as_node();
let style = &mut node.mutate_data().unwrap().style;
let damage = <<Self as TElement>::ConcreteNode as TNode>
::ConcreteRestyleDamage::compute((*style).as_ref(), &*shared_style);
::ConcreteRestyleDamage::compute((*style).as_ref(), &shared_style);
*style = Some(shared_style);
return StyleSharingResult::StyleWasShared(i, damage)
}
@ -676,7 +676,7 @@ pub trait MatchMethods : TNode {
let mut data = &mut *data_ref;
let cloned_parent_style = ComputedValues::style_for_child_text_node(parent_style.unwrap());
damage = Self::ConcreteRestyleDamage::compute(data.style.as_ref(),
&*cloned_parent_style);
&cloned_parent_style);
data.style = Some(cloned_parent_style);
} else {
damage = {

View file

@ -12,7 +12,6 @@ use selector_impl::SelectorImplExt;
use selectors::Element;
use selectors::bloom::BloomFilter;
use std::cell::RefCell;
use std::sync::Arc;
use tid::tid;
use util::opts;
use values::HasViewportPercentage;

View file

@ -294,10 +294,11 @@ extern "C" {
pub fn Gecko_GetNodeFlags(node: *mut RawGeckoNode) -> u32;
pub fn Gecko_SetNodeFlags(node: *mut RawGeckoNode, flags: u32);
pub fn Gecko_UnsetNodeFlags(node: *mut RawGeckoNode, flags: u32);
pub fn Gecko_CalcAndStoreStyleDifference(element: *mut RawGeckoElement,
newstyle:
*mut ServoComputedValues)
pub fn Gecko_CalcStyleDifference(oldstyle: *mut ServoComputedValues,
newstyle: *mut ServoComputedValues)
-> nsChangeHint;
pub fn Gecko_StoreStyleDifference(node: *mut RawGeckoNode,
change: nsChangeHint);
pub fn Gecko_EnsureTArrayCapacity(array: *mut ::std::os::raw::c_void,
capacity: usize, elem_size: usize);
pub fn Gecko_EnsureImageLayersLength(layers: *mut nsStyleImageLayers,

View file

@ -8,7 +8,9 @@ use gecko_bindings::bindings;
use gecko_bindings::bindings::Gecko_ChildrenCount;
use gecko_bindings::bindings::Gecko_ClassOrClassList;
use gecko_bindings::bindings::Gecko_GetNodeData;
use gecko_bindings::bindings::ServoComputedValues;
use gecko_bindings::bindings::ServoNodeData;
use gecko_bindings::bindings::{Gecko_CalcStyleDifference, Gecko_StoreStyleDifference};
use gecko_bindings::bindings::{Gecko_ElementState, Gecko_GetDocumentElement};
use gecko_bindings::bindings::{Gecko_GetFirstChild, Gecko_GetFirstChildElement};
use gecko_bindings::bindings::{Gecko_GetLastChild, Gecko_GetLastChildElement};
@ -21,8 +23,8 @@ use gecko_bindings::bindings::{Gecko_IsLink, Gecko_IsRootElement, Gecko_IsTextNo
use gecko_bindings::bindings::{Gecko_IsUnvisitedLink, Gecko_IsVisitedLink};
use gecko_bindings::bindings::{Gecko_LocalName, Gecko_Namespace, Gecko_NodeIsElement, Gecko_SetNodeData};
use gecko_bindings::bindings::{RawGeckoDocument, RawGeckoElement, RawGeckoNode};
use gecko_bindings::structs::nsIAtom;
use gecko_bindings::structs::{NODE_HAS_DIRTY_DESCENDANTS_FOR_SERVO, NODE_IS_DIRTY_FOR_SERVO};
use gecko_bindings::structs::{nsIAtom, nsChangeHint};
use glue::GeckoDeclarationBlock;
use libc::uintptr_t;
use selectors::Element;
@ -40,6 +42,7 @@ use style::dom::{OpaqueNode, PresentationalHintsSynthetizer};
use style::dom::{TDocument, TElement, TNode, TRestyleDamage, UnsafeNode};
use style::element_state::ElementState;
use style::error_reporting::StdoutErrorReporter;
use style::gecko_glue::ArcHelpers;
use style::gecko_selector_impl::{GeckoSelectorImpl, NonTSPseudoClass};
use style::parser::ParserContextExtraData;
use style::properties::{ComputedValues, parse_style_attribute};
@ -91,14 +94,36 @@ impl<'ln> GeckoNode<'ln> {
}
#[derive(Clone, Copy)]
pub struct DummyRestyleDamage;
impl TRestyleDamage for DummyRestyleDamage {
fn compute(_: Option<&Arc<ComputedValues>>, _: &ComputedValues) -> Self { DummyRestyleDamage }
fn rebuild_and_reflow() -> Self { DummyRestyleDamage }
pub struct GeckoRestyleDamage(nsChangeHint);
impl TRestyleDamage for GeckoRestyleDamage {
fn compute(previous_style: Option<&Arc<ComputedValues>>,
current_style: &Arc<ComputedValues>) -> Self {
type Helpers = ArcHelpers<ServoComputedValues, ComputedValues>;
let previous_style = match previous_style {
Some(previous) => previous,
None => return Self::rebuild_and_reflow(),
};
let previous = unsafe { Helpers::borrow(previous_style) };
let current = unsafe { Helpers::borrow(current_style) };
let hint = unsafe { Gecko_CalcStyleDifference(*previous, *current) };
GeckoRestyleDamage(hint)
}
impl BitOr for DummyRestyleDamage {
fn rebuild_and_reflow() -> Self {
GeckoRestyleDamage(nsChangeHint::nsChangeHint_ReconstructFrame)
}
}
impl BitOr for GeckoRestyleDamage {
type Output = Self;
fn bitor(self, _: Self) -> Self { DummyRestyleDamage }
fn bitor(self, other: Self) -> Self {
use std::mem;
GeckoRestyleDamage(unsafe { mem::transmute(self.0 as u32 | other.0 as u32) })
}
}
@ -106,7 +131,7 @@ impl BitOr for DummyRestyleDamage {
impl<'ln> TNode for GeckoNode<'ln> {
type ConcreteDocument = GeckoDocument<'ln>;
type ConcreteElement = GeckoElement<'ln>;
type ConcreteRestyleDamage = DummyRestyleDamage;
type ConcreteRestyleDamage = GeckoRestyleDamage;
fn to_unsafe(&self) -> UnsafeNode {
(self.node as usize, 0)
@ -243,9 +268,14 @@ impl<'ln> TNode for GeckoNode<'ln> {
}
}
fn restyle_damage(self) -> Self::ConcreteRestyleDamage { DummyRestyleDamage }
fn restyle_damage(self) -> Self::ConcreteRestyleDamage {
// Not called from style, only for layout.
unimplemented!();
}
fn set_restyle_damage(self, _: Self::ConcreteRestyleDamage) {}
fn set_restyle_damage(self, damage: Self::ConcreteRestyleDamage) {
unsafe { Gecko_StoreStyleDifference(self.node, damage.0) }
}
fn parent_node(&self) -> Option<GeckoNode<'ln>> {
unsafe {