Bug 1324554 - Part 1: Filter out zero-length segments earlier.
We need to filter zero-length segments (i.e. entries with the same
offsets) before handle missing final keyframes.
MozReview-Commit-ID: DGJPrNRXlmd
--- 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();