mirror of
https://github.com/servo/servo.git
synced 2025-08-24 06:45:33 +01:00
Make Restyle tracking more granular.
The primary idea of this patch is to ditch the rigid enum of Previous/Current styles, and replace it with a series of indicators for the various types of work that needs to be performed (expanding snapshots, rematching, recascading, and damage processing). This loses us a little bit of sanity checking (since the up-to-date-ness of our style is no longer baked into the type system), but gives us a lot more flexibility that we'll need going forward (especially when we separate matching from cascading). We also eliminate get_styling_mode in favor of a method on the traversal. This patch does a few other things as ridealongs: * Temporarily eliminates the handling for transfering ownership of styles to the frame. We'll need this again at some point, but for now it's causing too much complexity for a half-implemented feature. * Ditches TRestyleDamage, which is no longer necessary post-crate-merge, and is a constant source of compilation failures from either needing to be imported or being unnecessarily imported (which varies between gecko and servo). * Expands Snapshots for the traversal root, which was missing before. * Fixes up the skip_root stuff to avoid visiting the skipped root. * Unifies parallel traversal and avoids spawning for a single work item. * Adds an explicit pre_traverse step do any pre-processing and determine whether we need to traverse at all. MozReview-Commit-ID: IKhLAkAigXE
This commit is contained in:
parent
4cb3404c09
commit
80460cc549
27 changed files with 502 additions and 474 deletions
|
@ -2,7 +2,6 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use dom::TRestyleDamage;
|
||||
use gecko_bindings::bindings;
|
||||
use gecko_bindings::structs;
|
||||
use gecko_bindings::structs::{nsChangeHint, nsStyleContext};
|
||||
|
@ -22,17 +21,17 @@ impl GeckoRestyleDamage {
|
|||
pub fn as_change_hint(&self) -> nsChangeHint {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl TRestyleDamage for GeckoRestyleDamage {
|
||||
type PreExistingComputedValues = nsStyleContext;
|
||||
|
||||
fn empty() -> Self {
|
||||
pub fn empty() -> Self {
|
||||
GeckoRestyleDamage(nsChangeHint(0))
|
||||
}
|
||||
|
||||
fn compute(source: &nsStyleContext,
|
||||
new_style: &Arc<ComputedValues>) -> Self {
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.0 == nsChangeHint(0)
|
||||
}
|
||||
|
||||
pub fn compute(source: &nsStyleContext,
|
||||
new_style: &Arc<ComputedValues>) -> Self {
|
||||
let context = source as *const nsStyleContext as *mut nsStyleContext;
|
||||
let hint = unsafe {
|
||||
bindings::Gecko_CalcStyleDifference(context,
|
||||
|
@ -41,7 +40,7 @@ impl TRestyleDamage for GeckoRestyleDamage {
|
|||
GeckoRestyleDamage(hint)
|
||||
}
|
||||
|
||||
fn rebuild_and_reflow() -> Self {
|
||||
pub fn rebuild_and_reflow() -> Self {
|
||||
GeckoRestyleDamage(structs::nsChangeHint_nsChangeHint_ReconstructFrame)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,10 @@ use string_cache::Atom;
|
|||
#[derive(Debug)]
|
||||
pub struct GeckoElementSnapshot(bindings::ServoElementSnapshotOwned);
|
||||
|
||||
// FIXME(bholley): Add support for *OwnedConst type, and then we get Sync
|
||||
// automatically.
|
||||
unsafe impl Sync for GeckoElementSnapshot {}
|
||||
|
||||
impl Drop for GeckoElementSnapshot {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
use atomic_refcell::AtomicRefCell;
|
||||
use context::{LocalStyleContext, SharedStyleContext, StyleContext};
|
||||
use data::ElementData;
|
||||
use dom::{NodeInfo, OpaqueNode, StylingMode, TElement, TNode};
|
||||
use dom::{NodeInfo, OpaqueNode, TNode};
|
||||
use gecko::context::StandaloneStyleContext;
|
||||
use gecko::wrapper::{GeckoElement, GeckoNode};
|
||||
use std::mem;
|
||||
|
@ -13,26 +13,25 @@ use traversal::{DomTraversalContext, PerLevelTraversalData, recalc_style_at};
|
|||
|
||||
pub struct RecalcStyleOnly<'lc> {
|
||||
context: StandaloneStyleContext<'lc>,
|
||||
root: OpaqueNode,
|
||||
}
|
||||
|
||||
impl<'lc, 'ln> DomTraversalContext<GeckoNode<'ln>> for RecalcStyleOnly<'lc> {
|
||||
type SharedContext = SharedStyleContext;
|
||||
#[allow(unsafe_code)]
|
||||
fn new<'a>(shared: &'a Self::SharedContext, root: OpaqueNode) -> Self {
|
||||
fn new<'a>(shared: &'a Self::SharedContext, _root: OpaqueNode) -> Self {
|
||||
// See the comment in RecalcStyleAndConstructFlows::new for an explanation of why this is
|
||||
// necessary.
|
||||
let shared_lc: &'lc Self::SharedContext = unsafe { mem::transmute(shared) };
|
||||
RecalcStyleOnly {
|
||||
context: StandaloneStyleContext::new(shared_lc),
|
||||
root: root,
|
||||
}
|
||||
}
|
||||
|
||||
fn process_preorder(&self, node: GeckoNode<'ln>, data: &mut PerLevelTraversalData) {
|
||||
if node.is_element() && (!self.context.shared_context().skip_root || node.opaque() != self.root) {
|
||||
fn process_preorder(&self, node: GeckoNode<'ln>, traversal_data: &mut PerLevelTraversalData) {
|
||||
if node.is_element() {
|
||||
let el = node.as_element().unwrap();
|
||||
recalc_style_at::<_, _, Self>(&self.context, data, el);
|
||||
let mut data = unsafe { el.ensure_data() }.borrow_mut();
|
||||
recalc_style_at::<_, _, Self>(&self.context, traversal_data, el, &mut data);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,14 +40,7 @@ impl<'lc, 'ln> DomTraversalContext<GeckoNode<'ln>> for RecalcStyleOnly<'lc> {
|
|||
}
|
||||
|
||||
/// We don't use the post-order traversal for anything.
|
||||
fn needs_postorder_traversal(&self) -> bool { false }
|
||||
|
||||
fn should_traverse_child(child: GeckoNode<'ln>) -> bool {
|
||||
match child.as_element() {
|
||||
Some(el) => el.styling_mode() != StylingMode::Stop,
|
||||
None => false, // Gecko restyle doesn't need to traverse text nodes.
|
||||
}
|
||||
}
|
||||
fn needs_postorder_traversal() -> bool { false }
|
||||
|
||||
unsafe fn ensure_element_data<'a>(element: &'a GeckoElement<'ln>) -> &'a AtomicRefCell<ElementData> {
|
||||
element.ensure_data()
|
||||
|
|
|
@ -260,10 +260,10 @@ impl<'le> GeckoElement<'le> {
|
|||
}
|
||||
|
||||
pub fn get_pseudo_style(&self, pseudo: &PseudoElement) -> Option<Arc<ComputedValues>> {
|
||||
// NB: Gecko sometimes resolves pseudos after an element has already been
|
||||
// marked for restyle. We should consider fixing this, but for now just allow
|
||||
// it with current_or_previous_styles.
|
||||
self.borrow_data().and_then(|data| data.current_or_previous_styles().pseudos
|
||||
// FIXME(bholley): Gecko sometimes resolves pseudos after an element has
|
||||
// already been marked for restyle. We should consider fixing this, and
|
||||
// then assert has_current_styles here.
|
||||
self.borrow_data().and_then(|data| data.styles().pseudos
|
||||
.get(pseudo).map(|c| c.values.clone()))
|
||||
}
|
||||
|
||||
|
@ -273,8 +273,7 @@ impl<'le> GeckoElement<'le> {
|
|||
Some(x) => x,
|
||||
None => {
|
||||
debug!("Creating ElementData for {:?}", self);
|
||||
let existing = self.get_styles_from_frame();
|
||||
let ptr = Box::into_raw(Box::new(AtomicRefCell::new(ElementData::new(existing))));
|
||||
let ptr = Box::into_raw(Box::new(AtomicRefCell::new(ElementData::new(None))));
|
||||
self.0.mServoData.set(ptr);
|
||||
unsafe { &* ptr }
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue