Bug 1303235 - Part 2: Templatize CalculateCumulativeChangeHint.
MozReview-Commit-ID: JHSn7FoRPpW
--- a/dom/animation/KeyframeEffectReadOnly.cpp
+++ b/dom/animation/KeyframeEffectReadOnly.cpp
@@ -1681,76 +1681,99 @@ KeyframeEffectReadOnly::SetPerformanceWa
void
KeyframeEffectReadOnly::RecordFrameSizeTelemetry(uint32_t aPixelArea) {
if (!mRecordedFrameSize) {
Telemetry::Accumulate(Telemetry::ASYNC_ANIMATION_FRAME_SIZE, aPixelArea);
mRecordedFrameSize = true;
}
}
-static already_AddRefed<GeckoStyleContext>
-CreateStyleContextForAnimationValue(nsCSSPropertyID aProperty,
- const StyleAnimationValue& aValue,
- GeckoStyleContext* aBaseStyleContext)
+already_AddRefed<nsStyleContext>
+KeyframeEffectReadOnly::CreateStyleContextForAnimationValue(
+ nsCSSPropertyID aProperty,
+ const AnimationValue& aValue,
+ GeckoStyleContext* aBaseStyleContext)
{
MOZ_ASSERT(aBaseStyleContext,
"CreateStyleContextForAnimationValue needs to be called "
- "with a valid nsStyleContext");
+ "with a valid GeckoStyleContext");
RefPtr<AnimValuesStyleRule> styleRule = new AnimValuesStyleRule();
- styleRule->AddValue(aProperty, aValue);
+ styleRule->AddValue(aProperty, aValue.mGecko);
nsCOMArray<nsIStyleRule> rules;
rules.AppendObject(styleRule);
- MOZ_ASSERT(aBaseStyleContext->PresContext()->StyleSet()->IsGecko(),
- "ServoStyleSet should not use StyleAnimationValue for animations");
nsStyleSet* styleSet =
aBaseStyleContext->PresContext()->StyleSet()->AsGecko();
RefPtr<GeckoStyleContext> styleContext =
styleSet->ResolveStyleByAddingRules(aBaseStyleContext, rules);
// We need to call StyleData to generate cached data for the style context.
// Otherwise CalcStyleDifference returns no meaningful result.
styleContext->StyleData(nsCSSProps::kSIDTable[aProperty]);
return styleContext.forget();
}
-void
-KeyframeEffectReadOnly::CalculateCumulativeChangeHint(
- nsStyleContext* aStyleContext)
+already_AddRefed<nsStyleContext>
+KeyframeEffectReadOnly::CreateStyleContextForAnimationValue(
+ nsCSSPropertyID aProperty,
+ const AnimationValue& aValue,
+ const ServoStyleContext* aBaseStyleContext)
{
- if (mDocument->IsStyledByServo()) {
- // FIXME (bug 1303235): Do this for Servo too
- return;
- }
+ MOZ_ASSERT(aBaseStyleContext,
+ "CreateStyleContextForAnimationValue needs to be called "
+ "with a valid ServoStyleContext");
+
+ ServoStyleSet* styleSet =
+ aBaseStyleContext->PresContext()->StyleSet()->AsServo();
+ Element* elementForResolve =
+ EffectCompositor::GetElementToRestyle(mTarget->mElement,
+ mTarget->mPseudoType);
+ MOZ_ASSERT(elementForResolve, "The target element shouldn't be null");
+ return styleSet->ResolveServoStyleByAddingAnimation(elementForResolve,
+ aBaseStyleContext,
+ aValue.mServo);
+}
+
+template<typename StyleType>
+void
+KeyframeEffectReadOnly::CalculateCumulativeChangeHint(StyleType* aStyleContext)
+{
mCumulativeChangeHint = nsChangeHint(0);
- auto* geckoContext = aStyleContext ? aStyleContext->AsGecko() : nullptr;
for (const AnimationProperty& property : mProperties) {
for (const AnimationPropertySegment& segment : property.mSegments) {
// In case composite operation is not 'replace' or value is null,
// we can't throttle animations which will not cause any layout changes
// on invisible elements because we can't calculate the change hint for
// such properties until we compose it.
if (!segment.HasReplaceableValues()) {
mCumulativeChangeHint = ~nsChangeHint_Hints_CanIgnoreIfNotVisible;
return;
}
- RefPtr<GeckoStyleContext> fromContext =
+ RefPtr<nsStyleContext> fromContext =
CreateStyleContextForAnimationValue(property.mProperty,
- segment.mFromValue.mGecko,
- geckoContext);
+ segment.mFromValue,
+ aStyleContext);
+ if (!fromContext) {
+ mCumulativeChangeHint = ~nsChangeHint_Hints_CanIgnoreIfNotVisible;
+ return;
+ }
- RefPtr<GeckoStyleContext> toContext =
+ RefPtr<nsStyleContext> toContext =
CreateStyleContextForAnimationValue(property.mProperty,
- segment.mToValue.mGecko,
- geckoContext);
+ segment.mToValue,
+ aStyleContext);
+ if (!toContext) {
+ mCumulativeChangeHint = ~nsChangeHint_Hints_CanIgnoreIfNotVisible;
+ return;
+ }
uint32_t equalStructs = 0;
uint32_t samePointerStructs = 0;
nsChangeHint changeHint =
fromContext->CalcStyleDifference(toContext,
&equalStructs,
&samePointerStructs);
--- a/dom/animation/KeyframeEffectReadOnly.h
+++ b/dom/animation/KeyframeEffectReadOnly.h
@@ -254,20 +254,18 @@ public:
nsCSSPropertyID aProperty,
const AnimationPerformanceWarning& aWarning);
// Record telemetry about the size of the content being animated.
void RecordFrameSizeTelemetry(uint32_t aPixelArea);
// Cumulative change hint on each segment for each property.
// This is used for deciding the animation is paint-only.
- void CalculateCumulativeChangeHint(nsStyleContext* aStyleContext);
- void CalculateCumulativeChangeHint(const ServoStyleContext* aComputedValues)
- {
- }
+ template<typename StyleType>
+ void CalculateCumulativeChangeHint(StyleType* aStyleContext);
// Returns true if all of animation properties' change hints
// can ignore painting if the animation is not visible.
// See nsChangeHint_Hints_CanIgnoreIfNotVisible in nsChangeHint.h
// in detail which change hint can be ignored.
bool CanIgnoreIfNotVisible() const;
// Returns true if the effect is current state and has scale animation.
@@ -448,16 +446,26 @@ private:
const AnimationPropertySegment& aSegment,
const ComputedTiming& aComputedTiming);
void ComposeStyleRule(RawServoAnimationValueMap& aAnimationValues,
const AnimationProperty& aProperty,
const AnimationPropertySegment& aSegment,
const ComputedTiming& aComputedTiming);
+ already_AddRefed<nsStyleContext> CreateStyleContextForAnimationValue(
+ nsCSSPropertyID aProperty,
+ const AnimationValue& aValue,
+ GeckoStyleContext* aBaseStyleContext);
+
+ already_AddRefed<nsStyleContext> CreateStyleContextForAnimationValue(
+ nsCSSPropertyID aProperty,
+ const AnimationValue& aValue,
+ const ServoStyleContext* aBaseStyleContext);
+
nsIFrame* GetAnimationFrame() const;
bool CanThrottle() const;
bool CanThrottleTransformChanges(nsIFrame& aFrame) const;
// Returns true if the computedTiming has changed since the last
// composition.
bool HasComputedTimingChanged() const;