Bug 1324554 - Part 1: Filter out zero-length segments earlier. r=hiro
authorBoris Chiou <boris.chiou@gmail.com>
Tue, 31 Jan 2017 23:30:19 +0800
changeset 469870 1ff224f1e876bb2062aa476916d2dbd60a1ed70a
parent 469869 4057a8f658fc04c77d06fd4b1999285c0c8c18f1
child 469871 d2c410e1c919825c4c80e771b7afdc86321b4efe
push id43881
push userbmo:gps@mozilla.com
push dateThu, 02 Feb 2017 23:49:03 +0000
reviewershiro
bugs1324554
milestone54.0a1
Bug 1324554 - Part 1: Filter out zero-length segments earlier. r=hiro We need to filter zero-length segments (i.e. entries with the same offsets) before handle missing final keyframes. MozReview-Commit-ID: DGJPrNRXlmd
dom/animation/KeyframeUtils.cpp
--- a/dom/animation/KeyframeUtils.cpp
+++ b/dom/animation/KeyframeUtils.cpp
@@ -1325,61 +1325,69 @@ BuildSegmentsFromValueEntries(nsTArray<K
         lastProperty = aEntries[i].mProperty;
       } else {
         // Skip this entry if we did not handle the missing entry.
         ++i;
         continue;
       }
     }
 
+    // Skip this entry if the next entry has the same offset except for initial
+    // and final ones. We will handle missing keyframe in the next loop
+    // if the property is changed on the next entry.
+    if (aEntries[i].mProperty == aEntries[i + 1].mProperty &&
+        aEntries[i].mOffset == aEntries[i + 1].mOffset &&
+        aEntries[i].mOffset != 1.0f && aEntries[i].mOffset != 0.0f) {
+      ++i;
+      continue;
+    }
+
     // No keyframe for this property at offset 1.
     if (aEntries[i].mProperty != aEntries[i + 1].mProperty &&
         aEntries[i].mOffset != 1.0f) {
       HandleMissingFinalKeyframe(aResult, aEntries[i], animationProperty);
       // Move on to new property.
       animationProperty = nullptr;
       ++i;
       continue;
     }
 
-    // Starting from i, determine the next [i, j] interval from which to
-    // generate a segment.
-    size_t j;
+    // Starting from i + 1, determine the next [i, j] interval from which to
+    // generate a segment. Basically, j is i + 1, but there are some special
+    // cases for offset 0 and 1, so we need to handle them specifically.
+    // Note: From this moment, we make sure [i + 1] is valid and
+    //       there must be an initial entry (i.e. mOffset = 0.0) and
+    //       a final entry (i.e. mOffset = 1.0). Besides, all the entries
+    //       with the same offsets except for initial/final ones are filtered
+    //       out already.
+    size_t j = i + 1;
     if (aEntries[i].mOffset == 0.0f && aEntries[i + 1].mOffset == 0.0f) {
       // We need to generate an initial zero-length segment.
       MOZ_ASSERT(aEntries[i].mProperty == aEntries[i + 1].mProperty);
-      j = i + 1;
       while (j + 1 < n &&
              aEntries[j + 1].mOffset == 0.0f &&
              aEntries[j + 1].mProperty == aEntries[j].mProperty) {
         ++j;
       }
     } else if (aEntries[i].mOffset == 1.0f) {
       if (aEntries[i + 1].mOffset == 1.0f &&
           aEntries[i + 1].mProperty == aEntries[i].mProperty) {
         // We need to generate a final zero-length segment.
-        j = i + 1;
         while (j + 1 < n &&
                aEntries[j + 1].mOffset == 1.0f &&
                aEntries[j + 1].mProperty == aEntries[j].mProperty) {
           ++j;
         }
       } else {
         // New property.
         MOZ_ASSERT(aEntries[i].mProperty != aEntries[i + 1].mProperty);
         animationProperty = nullptr;
         ++i;
         continue;
       }
-    } else {
-      while (aEntries[i].mOffset == aEntries[i + 1].mOffset &&
-             aEntries[i].mProperty == aEntries[i + 1].mProperty) {
-        ++i;
-      }
-      j = i + 1;
     }
 
     // If we've moved on to a new property, create a new AnimationProperty
     // to insert segments into.
     if (aEntries[i].mProperty != lastProperty) {
       MOZ_ASSERT(aEntries[i].mOffset == 0.0f);
       MOZ_ASSERT(!animationProperty);
       animationProperty = aResult.AppendElement();