style: Pass old ComputedValues into Gecko_CalcStyleDifference. draft
authorCameron McCormack <cam@mcc.id.au>
Mon, 17 Jul 2017 13:08:07 +0800
changeset 609639 a9860d977e97ee29c12c3e45e167e944050c0b65
parent 609638 3c259dc7f1c5a674b53fe40157efe548d995b24e
child 609640 15843e4800548d4a6a59499abbbe5e755bbad4f1
push id68611
push userbmo:cam@mcc.id.au
push dateMon, 17 Jul 2017 05:09:54 +0000
milestone56.0a1
style: Pass old ComputedValues into Gecko_CalcStyleDifference. MozReview-Commit-ID: 7LVI1H3PtTa
servo/components/style/gecko/restyle_damage.rs
servo/components/style/matching.rs
servo/components/style/servo/restyle_damage.rs
--- a/servo/components/style/gecko/restyle_damage.rs
+++ b/servo/components/style/gecko/restyle_damage.rs
@@ -6,16 +6,17 @@
 
 use gecko_bindings::bindings;
 use gecko_bindings::structs;
 use gecko_bindings::structs::{nsChangeHint, nsStyleContext};
 use matching::{StyleChange, StyleDifference};
 use properties::ComputedValues;
 use std::mem::transmute;
 use std::ops::{BitAnd, BitOr, BitOrAssign, Not};
+use std::ptr;
 use stylearc::Arc;
 
 /// The representation of Gecko's restyle damage is just a wrapper over
 /// `nsChangeHint`.
 #[derive(Clone, Copy, Debug, PartialEq)]
 pub struct GeckoRestyleDamage(nsChangeHint);
 
 impl GeckoRestyleDamage {
@@ -43,27 +44,31 @@ impl GeckoRestyleDamage {
     /// given an old style (in the form of a `nsStyleContext`, and a new style
     /// (in the form of `ComputedValues`).
     ///
     /// Note that we could in theory just get two `ComputedValues` here and diff
     /// them, but Gecko has an interesting optimization when they mark accessed
     /// structs, so they effectively only diff structs that have ever been
     /// accessed from layout.
     pub fn compute_style_difference(
-        source: &nsStyleContext,
+        source: Option<&nsStyleContext>,
+        old_style: &ComputedValues,
         new_style: &Arc<ComputedValues>
     ) -> StyleDifference {
         // TODO(emilio): Const-ify this?
-        let context = source as *const nsStyleContext as *mut nsStyleContext;
+        let context = source
+            .map(|s| s as *const nsStyleContext as *mut nsStyleContext)
+            .unwrap_or(ptr::null_mut());
         let mut any_style_changed: bool = false;
         let hint = unsafe {
             // transmute rather than use HasSimpleFFI, since we can't
             // implement both HasArcFFI and HasSimpleFFI for ComputedValues
             // at the same time.
             bindings::Gecko_CalcStyleDifference(context,
+                                                transmute(old_style),
                                                 transmute(&**new_style),
                                                 &mut any_style_changed)
         };
         let change = if any_style_changed { StyleChange::Changed } else { StyleChange::Unchanged };
         StyleDifference::new(GeckoRestyleDamage(hint), change)
     }
 
     /// Returns true if this restyle damage contains all the damage of |other|.
--- a/servo/components/style/matching.rs
+++ b/servo/components/style/matching.rs
@@ -763,17 +763,17 @@ pub trait MatchMethods : TElement {
     fn compute_style_difference(
         &self,
         old_values: &ComputedValues,
         new_values: &Arc<ComputedValues>,
         pseudo: Option<&PseudoElement>
     ) -> StyleDifference {
         debug_assert!(pseudo.map_or(true, |p| p.is_eager()));
         if let Some(source) = self.existing_style_for_restyle_damage(old_values, pseudo) {
-            return RestyleDamage::compute_style_difference(source, new_values)
+            return RestyleDamage::compute_style_difference(Some(source), old_values, new_values);
         }
 
         let new_display = new_values.get_box().clone_display();
         let old_display = old_values.get_box().clone_display();
 
         let new_style_is_display_none = new_display == display::T::none;
         let old_style_is_display_none = old_display == display::T::none;
 
--- a/servo/components/style/servo/restyle_damage.rs
+++ b/servo/components/style/servo/restyle_damage.rs
@@ -55,17 +55,18 @@ bitflags! {
 
 impl HeapSizeOf for ServoRestyleDamage {
     fn heap_size_of_children(&self) -> usize { 0 }
 }
 
 impl ServoRestyleDamage {
     /// Compute the `StyleDifference` (including the appropriate restyle damage)
     /// for a given style change between `old` and `new`.
-    pub fn compute_style_difference(old: &ServoComputedValues,
+    pub fn compute_style_difference(_source: &ServoComputedValues,
+                                    old: &ServoComputedValues,
                                     new: &ServoComputedValues)
                                     -> StyleDifference {
         let damage = compute_damage(old, new);
         let change = if damage.is_empty() { StyleChange::Unchanged } else { StyleChange::Changed };
         StyleDifference::new(damage, change)
     }
 
     /// Returns a bitmask that represents a flow that needs to be rebuilt and