Bug 1382017 - stylo: Remove usage of ServoComputedValues from most Gecko code; r?xidorn draft
authorManish Goregaokar <manishearth@gmail.com>
Thu, 20 Jul 2017 17:27:05 -0700 (2017-07-21)
changeset 612920 345899482d5c4e167c175804e9c38ef76891c629
parent 612899 de74e3ac81a4f11f1ea32e2b8001a3a96fb6bdcd
child 612921 a4c5332ebab1ef39013d3dc85ca830589ec33de3
child 613088 403cfe74655cd4d7e66f31498dbc81616393289b
child 613092 3e79f781338e088e6ce45310ea90dea6d5aac1d0
push id69647
push userbmo:manishearth@gmail.com
push dateFri, 21 Jul 2017 07:33:15 +0000 (2017-07-21)
reviewersxidorn
bugs1382017
milestone56.0a1
Bug 1382017 - stylo: Remove usage of ServoComputedValues from most Gecko code; r?xidorn MozReview-Commit-ID: 2NB4DgxMrL3
dom/animation/KeyframeUtils.h
layout/base/ServoRestyleManager.cpp
layout/style/ServoBindingTypes.h
layout/style/ServoBindings.cpp
layout/style/ServoBindings.toml
layout/style/nsStyleContext.cpp
layout/style/nsStyleContext.h
layout/style/nsStyleContextInlines.h
servo/components/style/gecko/generated/bindings.rs
servo/components/style/gecko/generated/structs_debug.rs
servo/components/style/gecko/generated/structs_release.rs
servo/components/style/gecko/restyle_damage.rs
servo/components/style/properties/gecko.mako.rs
--- a/dom/animation/KeyframeUtils.h
+++ b/dom/animation/KeyframeUtils.h
@@ -11,17 +11,16 @@
 #include "nsCSSPropertyID.h"
 #include "nsTArrayForwardDeclare.h" // For nsTArray
 #include "js/RootingAPI.h" // For JS::Handle
 
 struct JSContext;
 class JSObject;
 class nsIDocument;
 class nsStyleContext;
-class ServoComputedValues;
 struct RawServoDeclarationBlock;
 
 namespace mozilla {
 struct AnimationProperty;
 enum class CSSPseudoElementType : uint8_t;
 class ErrorResult;
 struct Keyframe;
 struct PropertyStyleAnimationValuePair;
@@ -77,17 +76,17 @@ public:
   /**
    * Converts an array of Keyframe objects into an array of AnimationProperty
    * objects. This involves creating an array of computed values for each
    * longhand property and determining the offset and timing function to use
    * for each value.
    *
    * @param aKeyframes The input keyframes.
    * @param aElement The context element.
-   * @param aStyleType The |ServoComputedValues| or |nsStyleContext| to use
+   * @param aStyleType The |ServoStyleContext| or |GeckoStyleContext| to use
    *   when computing values.
    * @param aEffectComposite The composite operation specified on the effect.
    *   For any keyframes in |aKeyframes| that do not specify a composite
    *   operation, this value will be used.
    * @return The set of animation properties. If an error occurs, the returned
    *   array will be empty.
    */
   template<typename StyleType>
--- a/layout/base/ServoRestyleManager.cpp
+++ b/layout/base/ServoRestyleManager.cpp
@@ -510,17 +510,17 @@ ServoRestyleManager::ProcessPostTraversa
   // XXXbholley: We should teach the frame constructor how to clear the dirty
   // descendants bit to avoid the traversal here.
   if (changeHint & nsChangeHint_ReconstructFrame) {
     ClearRestyleStateFromSubtree(aElement);
     return true;
   }
 
   // TODO(emilio): We could avoid some refcount traffic here, specially in the
-  // ServoComputedValues case, which uses atomic refcounting.
+  // ServoStyleContext case, which uses atomic refcounting.
   //
   // Hold the old style context alive, because it could become a dangling
   // pointer during the replacement. In practice it's not a huge deal, but
   // better not playing with dangling pointers if not needed.
   RefPtr<ServoStyleContext> oldStyleContext =
     styleFrame ? styleFrame->StyleContext()->AsServo() : nullptr;
 
   UndisplayedNode* displayContentsNode = nullptr;
--- a/layout/style/ServoBindingTypes.h
+++ b/layout/style/ServoBindingTypes.h
@@ -103,17 +103,16 @@ typedef mozilla::dom::StyleChildrenItera
     already_AddRefed<type_> Consume();       \
   };
 #include "mozilla/ServoArcTypeList.h"
 #undef SERVO_ARC_TYPE
 
 typedef mozilla::ServoStyleContext const* ServoStyleContextBorrowed;
 typedef mozilla::ServoStyleContext const* ServoStyleContextBorrowedOrNull;
 typedef ServoComputedValues const* ServoComputedValuesBorrowed;
-typedef ServoComputedValues const* ServoComputedValuesBorrowedOrNull;
 
 struct MOZ_MUST_USE_TYPE ServoStyleContextStrong
 {
   mozilla::ServoStyleContext* mPtr;
   already_AddRefed<mozilla::ServoStyleContext> Consume();
 };
 
 #define DECL_OWNED_REF_TYPE_FOR(type_)    \
--- a/layout/style/ServoBindings.cpp
+++ b/layout/style/ServoBindings.cpp
@@ -411,22 +411,16 @@ Gecko_CalcStyleDifference(const ServoSty
   uint32_t equalStructs;
   uint32_t samePointerStructs;  // unused
   nsChangeHint result = const_cast<ServoStyleContext*>(aOldStyle)->
     CalcStyleDifference(
       const_cast<ServoStyleContext*>(aNewStyle),
       &equalStructs,
       &samePointerStructs,
       relevantStructs);
-
-  uint32_t equalStructs, samePointerStructs;
-  nsChangeHint result =
-    aOldStyleContext->CalcStyleDifference(aComputedValues,
-                                          &equalStructs,
-                                          &samePointerStructs);
   *aAnyStyleChanged = equalStructs != NS_STYLE_INHERIT_MASK;
   return result;
 }
 
 nsChangeHint
 Gecko_HintsHandledForDescendants(nsChangeHint aHint)
 {
   return aHint & ~NS_HintsNotHandledForDescendantsIn(aHint);
--- a/layout/style/ServoBindings.toml
+++ b/layout/style/ServoBindings.toml
@@ -244,17 +244,16 @@ whitelist-types = [
     "nsTArrayHeader",
     "Position",
     "PropertyValuePair",
     "Runnable",
     "ServoAttrSnapshot",
     "ServoBundledURI",
     "ServoComputedValues",
     "ServoComputedValuesBorrowed",
-    "ServoComputedValuesBorrowedOrNull",
     "ServoElementSnapshot",
     "ServoStyleContextStrong",
     "ServoStyleContextBorrowed",
     "ServoStyleContextBorrowedOrNull",
     "SheetParsingMode",
     "StaticRefPtr",
     "StyleAnimation",
     "StyleBasicShape",
@@ -343,17 +342,16 @@ raw-lines = [
     "pub use nsstring::{nsACString, nsAString, nsString, nsStringRepr};",
     "use gecko_bindings::structs::nsStyleTransformMatrix;",
     "use gecko_bindings::structs::nsTArray;",
     "type nsACString_internal = nsACString;",
     "type nsAString_internal = nsAString;",
     "pub type ServoStyleContextBorrowed<'a> = &'a ::properties::ComputedValues;",
     "pub type ServoStyleContextBorrowedOrNull<'a> = Option<&'a ::properties::ComputedValues>;",
     "pub type ServoComputedValuesBorrowed<'a> = &'a ServoComputedValues;",
-    "pub type ServoComputedValuesBorrowedOrNull<'a> = Option<&'a ServoComputedValues>;",
 ]
 whitelist-functions = ["Servo_.*", "Gecko_.*"]
 structs-types = [
     "mozilla::css::GridTemplateAreasValue",
     "mozilla::css::ErrorReporter",
     "mozilla::css::ImageValue",
     "mozilla::css::URLValue",
     "mozilla::css::URLValueData",
--- a/layout/style/nsStyleContext.cpp
+++ b/layout/style/nsStyleContext.cpp
@@ -229,17 +229,17 @@ nsStyleContext::CalcStyleDifference(nsSt
       if (thisVariables->mVariables == otherVariables->mVariables) {
         *aEqualStructs |= NS_STYLE_INHERIT_BIT(Variables);
       }
     } else {
       *aEqualStructs |= NS_STYLE_INHERIT_BIT(Variables);
     }
   } else {
     if (Servo_ComputedValues_EqualCustomProperties(
-          ComputedValues(),
+          AsServo()->ComputedValues(),
           aNewContext->ComputedValues())) {
       *aEqualStructs |= NS_STYLE_INHERIT_BIT(Variables);
     }
   }
 
   DebugOnly<int> styleStructCount = 1;  // count Variables already
 
   // Servo's optimization to stop the cascade when there are no style changes
--- a/layout/style/nsStyleContext.h
+++ b/layout/style/nsStyleContext.h
@@ -338,18 +338,16 @@ protected:
                  nsIAtom* aPseudoTag,
                  mozilla::CSSPseudoElementType aPseudoType);
 
   // Helper post-contruct hook.
   void FinishConstruction();
 
   void SetStyleBits();
 
-  inline const void* StyleStructFromServoComputedValues(nsStyleStructID aSID);
-
   // Helper functions for GetStyle* and PeekStyle*
   #define STYLE_STRUCT_INHERITED(name_, checkdata_cb_)                  \
     template<bool aComputeData>                                         \
     const nsStyle##name_ * DoGetStyle##name_();
   #define STYLE_STRUCT_RESET(name_, checkdata_cb_)                      \
     template<bool aComputeData>                                         \
     const nsStyle##name_ * DoGetStyle##name_();
 
--- a/layout/style/nsStyleContextInlines.h
+++ b/layout/style/nsStyleContextInlines.h
@@ -211,25 +211,9 @@ nsStyleContext::IsLinkContext() const
 
 void
 nsStyleContext::StartBackgroundImageLoads()
 {
   // Just get our background struct; that should do the trick
   StyleBackground();
 }
 
-const void*
-nsStyleContext::StyleStructFromServoComputedValues(nsStyleStructID aSID)
-{
-  switch (aSID) {
-#define STYLE_STRUCT(name_, checkdata_cb_)        \
-    case eStyleStruct_##name_:                    \
-      return ComputedValues()->GetStyle##name_();
-#include "nsStyleStructList.h"
-#undef STYLE_STRUCT
-    default:
-      MOZ_ASSERT_UNREACHABLE("unexpected nsStyleStructID value");
-      return nullptr;
-  }
-}
-
-
 #endif // nsStyleContextInlines_h
--- a/servo/components/style/gecko/generated/bindings.rs
+++ b/servo/components/style/gecko/generated/bindings.rs
@@ -3,17 +3,16 @@
 pub use nsstring::{nsACString, nsAString, nsString, nsStringRepr};
 use gecko_bindings::structs::nsStyleTransformMatrix;
 use gecko_bindings::structs::nsTArray;
 type nsACString_internal = nsACString;
 type nsAString_internal = nsAString;
 pub type ServoStyleContextBorrowed<'a> = &'a ::properties::ComputedValues;
 pub type ServoStyleContextBorrowedOrNull<'a> = Option<&'a ::properties::ComputedValues>;
 pub type ServoComputedValuesBorrowed<'a> = &'a ServoComputedValues;
-pub type ServoComputedValuesBorrowedOrNull<'a> = Option<&'a ServoComputedValues>;
 use gecko_bindings::structs::mozilla::css::GridTemplateAreasValue;
 use gecko_bindings::structs::mozilla::css::ErrorReporter;
 use gecko_bindings::structs::mozilla::css::ImageValue;
 use gecko_bindings::structs::mozilla::css::URLValue;
 use gecko_bindings::structs::mozilla::css::URLValueData;
 use gecko_bindings::structs::mozilla::MallocSizeOf;
 use gecko_bindings::structs::mozilla::Side;
 use gecko_bindings::structs::nsIContent;
--- a/servo/components/style/gecko/generated/structs_debug.rs
+++ b/servo/components/style/gecko/generated/structs_debug.rs
@@ -38451,18 +38451,16 @@ pub mod root {
         root::mozilla::dom::StyleChildrenIterator;
     pub type RawServoDeclarationBlockBorrowed =
         *const root::RawServoDeclarationBlock;
     pub type ServoStyleContextBorrowed =
         *const root::mozilla::ServoStyleContext;
     pub type ServoStyleContextBorrowedOrNull =
         *const root::mozilla::ServoStyleContext;
     pub type ServoComputedValuesBorrowed = *const root::ServoComputedValues;
-    pub type ServoComputedValuesBorrowedOrNull =
-        *const root::ServoComputedValues;
     pub type RawServoAnimationValueMapBorrowedMut =
         *mut root::RawServoAnimationValueMap;
     pub type RawGeckoNodeBorrowed = *const root::RawGeckoNode;
     pub type RawGeckoNodeBorrowedOrNull = *const root::RawGeckoNode;
     pub type RawGeckoElementBorrowed = *const root::RawGeckoElement;
     pub type RawGeckoElementBorrowedOrNull = *const root::RawGeckoElement;
     pub type RawGeckoDocumentBorrowed = *const root::RawGeckoDocument;
     pub type RawGeckoDocumentBorrowedOrNull = *const root::RawGeckoDocument;
--- a/servo/components/style/gecko/generated/structs_release.rs
+++ b/servo/components/style/gecko/generated/structs_release.rs
@@ -37760,18 +37760,16 @@ pub mod root {
         root::mozilla::dom::StyleChildrenIterator;
     pub type RawServoDeclarationBlockBorrowed =
         *const root::RawServoDeclarationBlock;
     pub type ServoStyleContextBorrowed =
         *const root::mozilla::ServoStyleContext;
     pub type ServoStyleContextBorrowedOrNull =
         *const root::mozilla::ServoStyleContext;
     pub type ServoComputedValuesBorrowed = *const root::ServoComputedValues;
-    pub type ServoComputedValuesBorrowedOrNull =
-        *const root::ServoComputedValues;
     pub type RawServoAnimationValueMapBorrowedMut =
         *mut root::RawServoAnimationValueMap;
     pub type RawGeckoNodeBorrowed = *const root::RawGeckoNode;
     pub type RawGeckoNodeBorrowedOrNull = *const root::RawGeckoNode;
     pub type RawGeckoElementBorrowed = *const root::RawGeckoElement;
     pub type RawGeckoElementBorrowedOrNull = *const root::RawGeckoElement;
     pub type RawGeckoDocumentBorrowed = *const root::RawGeckoDocument;
     pub type RawGeckoDocumentBorrowedOrNull = *const root::RawGeckoDocument;
--- a/servo/components/style/gecko/restyle_damage.rs
+++ b/servo/components/style/gecko/restyle_damage.rs
@@ -48,18 +48,18 @@ impl GeckoRestyleDamage {
     /// accessed from layout.
     pub fn compute_style_difference(
         source: &nsStyleContext,
         old_style: &ComputedValues,
         new_style: &Arc<ComputedValues>,
     ) -> StyleDifference {
         let mut any_style_changed: bool = false;
         let hint = unsafe {
-            bindings::Gecko_CalcStyleDifference(old_style.as_style_context(),
-                                                new_style.as_style_context(),
+            bindings::Gecko_CalcStyleDifference(old_style,
+                                                new_style,
                                                 source.mBits,
                                                 &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/properties/gecko.mako.rs
+++ b/servo/components/style/properties/gecko.mako.rs
@@ -34,17 +34,16 @@ use gecko_bindings::bindings::Gecko_SetC
 use gecko_bindings::bindings::Gecko_SetCursorImageValue;
 use gecko_bindings::bindings::Gecko_StyleTransition_SetUnsupportedProperty;
 use gecko_bindings::bindings::Gecko_NewCSSShadowArray;
 use gecko_bindings::bindings::Gecko_nsStyleFont_SetLang;
 use gecko_bindings::bindings::Gecko_nsStyleFont_CopyLangFrom;
 use gecko_bindings::bindings::Gecko_SetListStyleImageNone;
 use gecko_bindings::bindings::Gecko_SetListStyleImageImageValue;
 use gecko_bindings::bindings::Gecko_SetNullImageValue;
-use gecko_bindings::bindings::ServoComputedValuesBorrowedOrNull;
 use gecko_bindings::bindings::{Gecko_ResetFilters, Gecko_CopyFiltersFrom};
 use gecko_bindings::bindings::RawGeckoPresContextBorrowed;
 use gecko_bindings::structs;
 use gecko_bindings::structs::nsCSSPropertyID;
 use gecko_bindings::structs::nsStyleVariables;
 use gecko_bindings::sugar::ns_style_coord::{CoordDataValue, CoordData, CoordDataMut};
 use gecko::values::convert_nscolor_to_rgba;
 use gecko::values::convert_rgba_to_nscolor;
@@ -132,20 +131,16 @@ impl ComputedValues {
         let atom = (self.0)._base.mPseudoTag.raw::<structs::nsIAtom>();
         if atom.is_null() {
             return None;
         }
 
         let atom = Atom::from(atom);
         PseudoElement::from_atom(&atom)
     }
-
-    pub fn as_style_context(&self) -> &::gecko_bindings::structs::mozilla::ServoStyleContext {
-        &self.0
-    }
 }
 
 impl Drop for ComputedValues {
     fn drop(&mut self) {
         unsafe {
             bindings::Gecko_ServoStyleContext_Destroy(&mut self.0);
         }
     }
@@ -4969,33 +4964,22 @@ clip-path
     ${impl_simple_copy("_moz_box_ordinal_group", "mBoxOrdinal")}
 
     #[allow(non_snake_case)]
     pub fn clone__moz_box_ordinal_group(&self) -> i32{
         self.gecko.mBoxOrdinal as i32
     }
 </%self:impl_trait>
 
-<%def name="define_ffi_struct_accessor(style_struct)">
-#[no_mangle]
-#[allow(non_snake_case, unused_variables)]
-pub unsafe extern "C" fn Servo_GetStyle${style_struct.gecko_name}(computed_values:
-        ServoComputedValuesBorrowedOrNull) -> *const ${style_struct.gecko_ffi_name} {
-    computed_values.unwrap().get_${style_struct.name_lower}().get_gecko()
-        as *const ${style_struct.gecko_ffi_name}
-}
-</%def>
-
 % for style_struct in data.style_structs:
 ${declare_style_struct(style_struct)}
 ${impl_style_struct(style_struct)}
 % if not style_struct.name in data.manual_style_structs:
 <%self:raw_impl_trait style_struct="${style_struct}"></%self:raw_impl_trait>
 % endif
-${define_ffi_struct_accessor(style_struct)}
 % endfor
 
 // This is only accessed from the Gecko main thread.
 static mut EMPTY_VARIABLES_STRUCT: Option<nsStyleVariables> = None;
 
 #[no_mangle]
 #[allow(non_snake_case)]
 pub unsafe extern "C" fn Servo_GetEmptyVariables()