Bug 1358966 - Compute distance for each sub properties of shorthand. r=birtles
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Fri, 09 Jun 2017 06:19:37 +0900
changeset 363100 854d41e31f4bcfbe093b89580b51d72a24c7c095
parent 363099 4e730eaffad1568c62771acf447bbb305e731406
child 363101 a9f39ff3b27bd0ca1b9a3e80a2d7e0e195a249ef
push id31994
push usercbook@mozilla.com
push dateFri, 09 Jun 2017 10:56:24 +0000
treeherdermozilla-central@7c9d96bbc400 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbirtles
bugs1358966
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1358966 - Compute distance for each sub properties of shorthand. r=birtles We use Euclidean distance for shorhand. MozReview-Commit-ID: 6gUbIUl9SZ
dom/smil/nsSMILCSSValueType.cpp
--- a/dom/smil/nsSMILCSSValueType.cpp
+++ b/dom/smil/nsSMILCSSValueType.cpp
@@ -415,25 +415,41 @@ nsSMILCSSValueType::Add(nsSMILValue& aDe
          : NS_ERROR_FAILURE;
 }
 
 static nsresult
 ComputeDistanceForServo(const ValueWrapper* aFromWrapper,
                         const ValueWrapper& aToWrapper,
                         double& aDistance)
 {
-  const RefPtr<RawServoAnimationValue>* fromValue =
-    aFromWrapper ? &aFromWrapper->mServoValues[0] : nullptr;
-  const RefPtr<RawServoAnimationValue>* toValue = &aToWrapper.mServoValues[0];
-  RefPtr<RawServoAnimationValue> zeroValueStorage;
-  if (!FinalizeServoAnimationValues(fromValue, toValue, zeroValueStorage)) {
-    return NS_ERROR_FAILURE;
+  size_t len = aToWrapper.mServoValues.Length();
+  MOZ_ASSERT(!aFromWrapper || aFromWrapper->mServoValues.Length() == len,
+             "From and to values length should be the same if "
+             "The start value exists");
+
+  double squareDistance = 0;
+
+  for (size_t i = 0; i < len; i++) {
+    const RefPtr<RawServoAnimationValue>* fromValue =
+      aFromWrapper ? &aFromWrapper->mServoValues[0] : nullptr;
+    const RefPtr<RawServoAnimationValue>* toValue = &aToWrapper.mServoValues[0];
+    RefPtr<RawServoAnimationValue> zeroValueStorage;
+    if (!FinalizeServoAnimationValues(fromValue, toValue, zeroValueStorage)) {
+      return NS_ERROR_FAILURE;
+    }
+
+    double distance = Servo_AnimationValues_ComputeDistance(*fromValue, *toValue);
+    if (len == 1) {
+      aDistance = distance;
+      return NS_OK;
+    }
+    squareDistance += distance * distance;
   }
 
-  aDistance = Servo_AnimationValues_ComputeDistance(*fromValue, *toValue);
+  aDistance = sqrt(squareDistance);
 
   return NS_OK;
 }
 
 nsresult
 nsSMILCSSValueType::ComputeDistance(const nsSMILValue& aFrom,
                                     const nsSMILValue& aTo,
                                     double& aDistance) const