Bug 1337313 - Part 2: Add AnimationValue::SerializeSpecifiedValue. draft
authorBoris Chiou <boris.chiou@gmail.com>
Thu, 09 Feb 2017 11:33:17 +0800
changeset 481603 2179b30ec43d4edbd15869db56c488f31ccffd33
parent 481602 26414bc77682955ea09b9c57be6be38cff4c07e5
child 481604 da0f8eae94caeac347bd55ec8b5ecee77b528035
push id44867
push userbmo:boris.chiou@gmail.com
push dateFri, 10 Feb 2017 04:28:38 +0000
bugs1337313
milestone54.0a1
Bug 1337313 - Part 2: Add AnimationValue::SerializeSpecifiedValue. Move the implementation of uncomputing to string into AnimationValue, and add one more FFI for RawServoAnimationValue. MozReview-Commit-ID: JFnXnGO3mlp
dom/animation/KeyframeEffectReadOnly.cpp
layout/style/ServoBindingList.h
layout/style/StyleAnimationValue.h
--- a/dom/animation/KeyframeEffectReadOnly.cpp
+++ b/dom/animation/KeyframeEffectReadOnly.cpp
@@ -1009,22 +1009,18 @@ KeyframeEffectReadOnly::GetTargetStyleCo
 #ifdef DEBUG
 void
 DumpAnimationProperties(nsTArray<AnimationProperty>& aAnimationProperties)
 {
   for (auto& p : aAnimationProperties) {
     printf("%s\n", nsCSSProps::GetStringValue(p.mProperty).get());
     for (auto& s : p.mSegments) {
       nsString fromValue, toValue;
-      Unused << StyleAnimationValue::UncomputeValue(p.mProperty,
-                                                    s.mFromValue.mGecko,
-                                                    fromValue);
-      Unused << StyleAnimationValue::UncomputeValue(p.mProperty,
-                                                    s.mToValue.mGecko,
-                                                    toValue);
+      s.mFromValue.SerializeSpecifiedValue(p.mProperty, fromValue);
+      s.mToValue.SerializeSpecifiedValue(p.mProperty, toValue);
       printf("  %f..%f: %s..%s\n", s.mFromKey, s.mToKey,
              NS_ConvertUTF16toUTF8(fromValue).get(),
              NS_ConvertUTF16toUTF8(toValue).get());
     }
   }
 }
 #endif
 
@@ -1083,19 +1079,17 @@ CreatePropertyValue(nsCSSPropertyID aPro
                     const AnimationValue& aValue,
                     dom::CompositeOperation aComposite,
                     AnimationPropertyValueDetails& aResult)
 {
   aResult.mOffset = aOffset;
 
   if (!aValue.IsNull()) {
     nsString stringValue;
-    DebugOnly<bool> uncomputeResult =
-      StyleAnimationValue::UncomputeValue(aProperty, aValue.mGecko, stringValue);
-    MOZ_ASSERT(uncomputeResult, "failed to uncompute value");
+    aValue.SerializeSpecifiedValue(aProperty, stringValue);
     aResult.mValue.Construct(stringValue);
   }
 
   if (aTimingFunction) {
     aResult.mEasing.Construct();
     aTimingFunction->AppendToString(aResult.mEasing.Value());
   } else {
     aResult.mEasing.Construct(NS_LITERAL_STRING("linear"));
--- a/layout/style/ServoBindingList.h
+++ b/layout/style/ServoBindingList.h
@@ -122,16 +122,20 @@ SERVO_BINDING_FUNC(Servo_AnimationValues
 SERVO_BINDING_FUNC(Servo_AnimationValues_Interpolate,
                    RawServoAnimationValueStrong,
                    RawServoAnimationValueBorrowed from,
                    RawServoAnimationValueBorrowed to,
                    double progress)
 SERVO_BINDING_FUNC(Servo_AnimationValues_Uncompute,
                    RawServoDeclarationBlockStrong,
                    RawServoAnimationValueBorrowedListBorrowed value)
+SERVO_BINDING_FUNC(Servo_AnimationValue_Serialize, void,
+                   RawServoAnimationValueBorrowed value,
+                   nsCSSPropertyID property,
+                   nsAString* buffer)
 SERVO_BINDING_FUNC(Servo_AnimationValues_GetOpacity, float,
                    RawServoAnimationValueBorrowed value)
 SERVO_BINDING_FUNC(Servo_AnimationValues_GetTransform, void,
                    RawServoAnimationValueBorrowed value,
                    RefPtr<nsCSSValueSharedList>* list)
 
 // Style attribute
 SERVO_BINDING_FUNC(Servo_ParseStyleAttribute, RawServoDeclarationBlockStrong,
--- a/layout/style/StyleAnimationValue.h
+++ b/layout/style/StyleAnimationValue.h
@@ -584,38 +584,55 @@ private:
   }
 };
 
 struct AnimationValue
 {
   StyleAnimationValue mGecko;
   RefPtr<RawServoAnimationValue> mServo;
 
-  bool operator==(const AnimationValue& aOther) const {
+  bool operator==(const AnimationValue& aOther) const
+  {
     // FIXME: Bug 1337229: add a deep == impl for RawServoAnimationValue.
     return mGecko == aOther.mGecko && mServo == aOther.mServo;
   }
 
   bool IsNull() const { return mGecko.IsNull() && !mServo; }
 
-  float GetOpacity() const {
+  float GetOpacity() const
+  {
     return mServo ? Servo_AnimationValues_GetOpacity(mServo)
                   : mGecko.GetFloatValue();
   }
 
   // Returns the scale for mGecko or mServo, which are calculated with
   // reference to aFrame.
-  gfxSize GetScaleValue(const nsIFrame* aFrame) const {
+  gfxSize GetScaleValue(const nsIFrame* aFrame) const
+  {
     if (mServo) {
       RefPtr<nsCSSValueSharedList> list;
       Servo_AnimationValues_GetTransform(mServo, &list);
       return nsStyleTransformMatrix::GetScaleValue(list, aFrame);
     }
     return mGecko.GetScaleValue(aFrame);
   }
+
+  // Uncompute this AnimationValue and then serialize it.
+  void SerializeSpecifiedValue(nsCSSPropertyID aProperty,
+                               nsAString& aString) const
+  {
+    if (mServo) {
+      Servo_AnimationValue_Serialize(mServo, aProperty, &aString);
+      return;
+    }
+
+    DebugOnly<bool> uncomputeResult =
+      StyleAnimationValue::UncomputeValue(aProperty, mGecko, aString);
+    MOZ_ASSERT(uncomputeResult, "failed to uncompute StyleAnimationValue");
+  }
 };
 
 struct PropertyStyleAnimationValuePair
 {
   nsCSSPropertyID mProperty;
   AnimationValue mValue;
 };
 } // namespace mozilla