Bug 1335942 - Part 1: Introduce mozilla::AnimationValue.
Currently, we have StyleAnimationValue for Gecko and
RawServoAnimationValue for Servo, and use this struct to wrap them to
avoid the duplicated code.
MozReview-Commit-ID: ATDBSCOX2C5
--- a/dom/animation/KeyframeUtils.cpp
+++ b/dom/animation/KeyframeUtils.cpp
@@ -266,18 +266,17 @@ struct AdditionalProperty
* whose value is a StyleAnimationValue.
*
* KeyframeValueEntry is used in GetAnimationPropertiesFromKeyframes
* to gather data for each individual segment.
*/
struct KeyframeValueEntry
{
nsCSSPropertyID mProperty;
- StyleAnimationValue mValue;
- RefPtr<RawServoAnimationValue> mServoValue;
+ AnimationValue mValue;
float mOffset;
Maybe<ComputedTimingFunction> mTimingFunction;
dom::CompositeOperation mComposite;
struct PropertyOffsetComparator
{
static bool Equals(const KeyframeValueEntry& aLhs,
@@ -699,17 +698,16 @@ KeyframeUtils::GetAnimationPropertiesFro
const Keyframe& frame = aKeyframes[i];
for (auto& value : aComputedValues[i]) {
MOZ_ASSERT(frame.mComputedOffset != Keyframe::kComputedOffsetNotSet,
"Invalid computed offset");
KeyframeValueEntry* entry = entries.AppendElement();
entry->mOffset = frame.mComputedOffset;
entry->mProperty = value.mProperty;
entry->mValue = value.mValue;
- entry->mServoValue = value.mServoValue;
entry->mTimingFunction = frame.mTimingFunction;
entry->mComposite =
frame.mComposite ? frame.mComposite.value() : aEffectComposite;
}
}
nsTArray<AnimationProperty> result;
BuildSegmentsFromValueEntries(entries, result);
@@ -1163,28 +1161,28 @@ static void
AppendInitialSegment(AnimationProperty* aAnimationProperty,
const KeyframeValueEntry& aFirstEntry)
{
AnimationPropertySegment* segment =
aAnimationProperty->mSegments.AppendElement();
segment->mFromKey = 0.0f;
segment->mFromComposite = dom::CompositeOperation::Add;
segment->mToKey = aFirstEntry.mOffset;
- segment->mToValue = aFirstEntry.mValue;
+ segment->mToValue = aFirstEntry.mValue.mGecko;
segment->mToComposite = aFirstEntry.mComposite;
}
static void
AppendFinalSegment(AnimationProperty* aAnimationProperty,
const KeyframeValueEntry& aLastEntry)
{
AnimationPropertySegment* segment =
aAnimationProperty->mSegments.AppendElement();
segment->mFromKey = aLastEntry.mOffset;
- segment->mFromValue = aLastEntry.mValue;
+ segment->mFromValue = aLastEntry.mValue.mGecko;
segment->mFromComposite = aLastEntry.mComposite;
segment->mToKey = 1.0f;
segment->mToComposite = dom::CompositeOperation::Add;
segment->mTimingFunction = aLastEntry.mTimingFunction;
}
// Returns a newly created AnimationProperty if one was created to fill-in the
// missing keyframe, nullptr otherwise (if we decided not to fill the keyframe
@@ -1397,20 +1395,20 @@ BuildSegmentsFromValueEntries(nsTArray<K
MOZ_ASSERT(animationProperty, "animationProperty should be valid pointer.");
// Now generate the segment.
AnimationPropertySegment* segment =
animationProperty->mSegments.AppendElement();
segment->mFromKey = aEntries[i].mOffset;
segment->mToKey = aEntries[j].mOffset;
- segment->mFromValue = aEntries[i].mValue;
- segment->mToValue = aEntries[j].mValue;
- segment->mServoFromValue = aEntries[i].mServoValue;
- segment->mServoToValue = aEntries[j].mServoValue;
+ segment->mFromValue = aEntries[i].mValue.mGecko;
+ segment->mToValue = aEntries[j].mValue.mGecko;
+ segment->mServoFromValue = aEntries[i].mValue.mServo;
+ segment->mServoToValue = aEntries[j].mValue.mServo;
segment->mTimingFunction = aEntries[i].mTimingFunction;
segment->mFromComposite = aEntries[i].mComposite;
segment->mToComposite = aEntries[j].mComposite;
i = j;
}
}
@@ -1781,32 +1779,32 @@ GetCumulativeDistances(const nsTArray<Co
for (size_t propIdx = 0; propIdx < pacedPropertyCount; ++propIdx) {
nsCSSPropertyID prop = prevPacedValues[propIdx].mProperty;
MOZ_ASSERT(pacedValues[propIdx].mProperty == prop,
"Property mismatch");
double componentDistance = 0.0;
if (StyleAnimationValue::ComputeDistance(
prop,
- prevPacedValues[propIdx].mValue,
- pacedValues[propIdx].mValue,
+ prevPacedValues[propIdx].mValue.mGecko,
+ pacedValues[propIdx].mValue.mGecko,
aStyleContext,
componentDistance)) {
dist += componentDistance * componentDistance;
}
}
dist = sqrt(dist);
} else {
// If the property is longhand, we just use the 1st value.
// If ComputeDistance() fails, |dist| will remain zero so there will be
// no distance between the previous paced value and this value.
Unused <<
StyleAnimationValue::ComputeDistance(aPacedProperty,
- prevPacedValues[0].mValue,
- pacedValues[0].mValue,
+ prevPacedValues[0].mValue.mGecko,
+ pacedValues[0].mValue.mGecko,
aStyleContext,
dist);
}
cumulativeDistances[i] = cumulativeDistances[preIdx] + dist;
}
prevPacedValues.SwapElements(pacedValues);
preIdx = i;
}
--- a/layout/style/StyleAnimationValue.cpp
+++ b/layout/style/StyleAnimationValue.cpp
@@ -3453,27 +3453,27 @@ ComputeValuesFromStyleContext(
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aProperty, aEnabledState) {
if (nsCSSProps::kAnimTypeTable[*p] == eStyleAnimType_None) {
// Skip non-animatable component longhands.
continue;
}
PropertyStyleAnimationValuePair* pair = aValues.AppendElement();
pair->mProperty = *p;
if (!StyleAnimationValue::ExtractComputedValue(*p, aStyleContext,
- pair->mValue)) {
+ pair->mValue.mGecko)) {
return false;
}
}
return true;
}
PropertyStyleAnimationValuePair* pair = aValues.AppendElement();
pair->mProperty = aProperty;
return StyleAnimationValue::ExtractComputedValue(aProperty, aStyleContext,
- pair->mValue);
+ pair->mValue.mGecko);
}
static bool
ComputeValuesFromStyleRule(nsCSSPropertyID aProperty,
CSSEnabledState aEnabledState,
nsStyleContext* aStyleContext,
css::StyleRule* aStyleRule,
nsTArray<PropertyStyleAnimationValuePair>& aValues,
@@ -3578,17 +3578,17 @@ StyleAnimationValue::ComputeValue(nsCSSP
values, aIsContextSensitive);
if (!ok) {
return false;
}
MOZ_ASSERT(values.Length() == 1);
MOZ_ASSERT(values[0].mProperty == aProperty);
- aComputedValue = values[0].mValue;
+ aComputedValue = values[0].mValue.mGecko;
return true;
}
template <class T>
bool
ComputeValuesFromSpecifiedValue(
nsCSSPropertyID aProperty,
CSSEnabledState aEnabledState,
--- a/layout/style/StyleAnimationValue.h
+++ b/layout/style/StyleAnimationValue.h
@@ -577,17 +577,22 @@ private:
static bool IsCSSValuePairListUnit(Unit aUnit) {
return aUnit == eUnit_CSSValuePairList;
}
static bool IsStringUnit(Unit aUnit) {
return aUnit == eUnit_UnparsedString;
}
};
+struct AnimationValue
+{
+ StyleAnimationValue mGecko;
+ RefPtr<RawServoAnimationValue> mServo;
+};
+
struct PropertyStyleAnimationValuePair
{
nsCSSPropertyID mProperty;
- StyleAnimationValue mValue;
- RefPtr<RawServoAnimationValue> mServoValue;
+ AnimationValue mValue;
};
} // namespace mozilla
#endif