Bug 1338927 - Part 5: Templatize UpdateProperties(). r?birtles draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Thu, 23 Feb 2017 09:52:44 +0900
changeset 488332 bb854cdc3b3b62321cf7a9f5e52a2486fac46aac
parent 488331 3003971d98cacfad5604838f98a46fb926441a81
child 488333 960a90a93dbc913f70c6b93bf4e09f3f239e0e97
push id46496
push userhikezoe@mozilla.com
push dateThu, 23 Feb 2017 00:53:38 +0000
reviewersbirtles
bugs1338927
milestone54.0a1
Bug 1338927 - Part 5: Templatize UpdateProperties(). r?birtles We had to implement UpdateProperties(nsStyleContext*) explicitly since there are some calls of UpdateProperties() with RefPtr<nsStyleContext>. Without this compiler tries to use template function instead. MozReview-Commit-ID: 72NgwmJ4kcx
dom/animation/KeyframeEffectReadOnly.cpp
dom/animation/KeyframeEffectReadOnly.h
--- a/dom/animation/KeyframeEffectReadOnly.cpp
+++ b/dom/animation/KeyframeEffectReadOnly.cpp
@@ -268,32 +268,47 @@ SpecifiedKeyframeArraysAreEqual(const ns
 
   return true;
 }
 #endif
 
 void
 KeyframeEffectReadOnly::UpdateProperties(nsStyleContext* aStyleContext)
 {
-  MOZ_ASSERT(aStyleContext);
+  DoUpdateProperties(Move(aStyleContext));
+}
+
+void
+KeyframeEffectReadOnly::UpdateProperties(
+  const ServoComputedStyleValues& aServoValues)
+{
+  DoUpdateProperties(aServoValues);
+}
+
+template<typename StyleType>
+void
+KeyframeEffectReadOnly::DoUpdateProperties(StyleType&& aStyle)
+{
+  MOZ_ASSERT_IF(IsPointer<StyleType>::value, aStyle);
 
   // Skip updating properties when we are composing style.
   // FIXME: Bug 1324966. Drop this check once we have a function to get
   // nsStyleContext without resolving animating style.
   MOZ_DIAGNOSTIC_ASSERT(!mIsComposingStyle,
                         "Should not be called while processing ComposeStyle()");
   if (mIsComposingStyle) {
     return;
   }
 
-  nsTArray<AnimationProperty> properties = BuildProperties(Move(aStyleContext));
+  nsTArray<AnimationProperty> properties =
+    BuildProperties(Forward<StyleType>(aStyle));
 
   // We need to update base styles even if any properties are not changed at all
   // since base styles might have been changed due to parent style changes, etc.
-  EnsureBaseStyles(aStyleContext, properties);
+  EnsureBaseStyles(aStyle, properties);
 
   if (mProperties == properties) {
     return;
   }
 
   // Preserve the state of the mIsRunningOnCompositor flag.
   nsCSSPropertyIDSet runningOnCompositorProperties;
 
@@ -305,20 +320,17 @@ KeyframeEffectReadOnly::UpdateProperties
 
   mProperties = Move(properties);
 
   for (AnimationProperty& property : mProperties) {
     property.mIsRunningOnCompositor =
       runningOnCompositorProperties.HasProperty(property.mProperty);
   }
 
-  // FIXME (bug 1303235): Do this for Servo too
-  if (aStyleContext->PresContext()->StyleSet()->IsGecko()) {
-    CalculateCumulativeChangeHint(aStyleContext);
-  }
+  CalculateCumulativeChangeHint(aStyle);
 
   MarkCascadeNeedsUpdate();
 
   RequestRestyle(EffectCompositor::RestyleType::Layer);
 }
 
 /* static */ StyleAnimationValue
 KeyframeEffectReadOnly::CompositeValue(
@@ -1569,16 +1581,20 @@ CreateStyleContextForAnimationValue(nsCS
 
   return styleContext.forget();
 }
 
 void
 KeyframeEffectReadOnly::CalculateCumulativeChangeHint(
   nsStyleContext *aStyleContext)
 {
+  if (aStyleContext->PresContext()->StyleSet()->IsServo()) {
+    // FIXME (bug 1303235): Do this for Servo too
+    return;
+  }
   mCumulativeChangeHint = nsChangeHint(0);
 
   for (const AnimationProperty& property : mProperties) {
     for (const AnimationPropertySegment& segment : property.mSegments) {
       // In case composite operation is not 'replace', 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.
--- a/dom/animation/KeyframeEffectReadOnly.h
+++ b/dom/animation/KeyframeEffectReadOnly.h
@@ -225,16 +225,18 @@ public:
   const InfallibleTArray<AnimationProperty>& Properties() const
   {
     return mProperties;
   }
 
   // Update |mProperties| by recalculating from |mKeyframes| using
   // |aStyleContext| to resolve specified values.
   void UpdateProperties(nsStyleContext* aStyleContext);
+  // Servo version of the above function.
+  void UpdateProperties(const ServoComputedStyleValues& aServoValues);
 
   // Updates |aStyleRule| with the animation values produced by this
   // AnimationEffect for the current time except any properties contained
   // in |aPropertiesToSkip|.
   void ComposeStyle(AnimationRule& aStyleRule,
                     const nsCSSPropertyIDSet& aPropertiesToSkip);
 
   // Composite |aValueToComposite| on |aUnderlyingValue| with
@@ -279,16 +281,20 @@ public:
   // will be used to generate a localized message for devtools.
   void SetPerformanceWarning(
     nsCSSPropertyID aProperty,
     const AnimationPerformanceWarning& aWarning);
 
   // 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 ServoComputedStyleValues& aServoValues)
+  {
+  }
 
   // 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.
@@ -380,16 +386,21 @@ protected:
   // Returns underlying style animation value for |aProperty|.
   StyleAnimationValue GetUnderlyingStyle(
     nsCSSPropertyID aProperty,
     const RefPtr<AnimValuesStyleRule>& aAnimationRule);
 
   // Ensure the base styles is available for any properties in |aProperties|.
   void EnsureBaseStyles(nsStyleContext* aStyleContext,
                         const nsTArray<AnimationProperty>& aProperties);
+  void EnsureBaseStyles(const ServoComputedStyleValues& aServoValues,
+                        const nsTArray<AnimationProperty>& aProperties)
+  {
+    // FIXME: Bug 1311257: Support missing keyframes.
+  }
 
   // Returns the base style resolved by |aStyleContext| for |aProperty|.
   StyleAnimationValue ResolveBaseStyle(nsCSSPropertyID aProperty,
                                        nsStyleContext* aStyleContext);
 
   Maybe<OwningAnimationTarget> mTarget;
 
   KeyframeEffectParams mEffectOptions;
@@ -417,16 +428,19 @@ protected:
   // The non-animated values for properties in this effect that contain at
   // least one animation value that is composited with the underlying value
   // (i.e. it uses the additive or accumulate composite mode).
   nsDataHashtable<nsUint32HashKey, StyleAnimationValue> mBaseStyleValues;
 
 private:
   nsChangeHint mCumulativeChangeHint;
 
+  template<typename StyleType>
+  void DoUpdateProperties(StyleType&& aStyle);
+
   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;