Bug 1305325 - Part 13: Factor the base value's scale in GetMinAndMaxScaleForAnimationProperty. r=birtles
authorHiroyuki Ikezoe <hiikezoe@mozilla-japan.org>
Sun, 04 Dec 2016 08:07:40 +0900
changeset 325235 78cd157b2c91127e26e2f19dd376f39a6bd58c89
parent 325234 a037e71a1150b10d2f7dae927b57ccf2929c6443
child 325236 fdaaa1b24b8c88e0b56eb052bb8dbdf858381537
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewersbirtles
bugs1305325
milestone53.0a1
Bug 1305325 - Part 13: Factor the base value's scale in GetMinAndMaxScaleForAnimationProperty. r=birtles MozReview-Commit-ID: IlDNyJwrbKW
layout/base/nsLayoutUtils.cpp
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -510,16 +510,29 @@ GetSuitableScale(float aMaxScale, float 
     // fraction of a second before we delayerize the composited texture it has
     // a better chance of being pixel aligned and composited without resampling
     // (avoiding visually clunky delayerization).
     return aMaxScale;
   }
   return std::max(std::min(aMaxScale, displayVisibleRatio), aMinScale);
 }
 
+static inline void
+UpdateMinMaxScale(const nsIFrame* aFrame,
+                  const StyleAnimationValue& aValue,
+                  gfxSize& aMinScale,
+                  gfxSize& aMaxScale)
+{
+  gfxSize size = aValue.GetScaleValue(aFrame);
+  aMaxScale.width = std::max<float>(aMaxScale.width, size.width);
+  aMaxScale.height = std::max<float>(aMaxScale.height, size.height);
+  aMinScale.width = std::min<float>(aMinScale.width, size.width);
+  aMinScale.height = std::min<float>(aMinScale.height, size.height);
+}
+
 static void
 GetMinAndMaxScaleForAnimationProperty(const nsIFrame* aFrame,
                                       nsTArray<RefPtr<dom::Animation>>&
                                         aAnimations,
                                       gfxSize& aMaxScale,
                                       gfxSize& aMinScale)
 {
   for (dom::Animation* anim : aAnimations) {
@@ -532,32 +545,35 @@ GetMinAndMaxScaleForAnimationProperty(co
     dom::KeyframeEffectReadOnly* effect =
       anim->GetEffect() ? anim->GetEffect()->AsKeyframeEffect() : nullptr;
     MOZ_ASSERT(effect, "A playing animation should have a keyframe effect");
     for (size_t propIdx = effect->Properties().Length(); propIdx-- != 0; ) {
       const AnimationProperty& prop = effect->Properties()[propIdx];
       if (prop.mProperty != eCSSProperty_transform) {
         continue;
       }
+
+      // We need to factor in the scale of the base style if the base style
+      // will be used on the compositor.
+      if (effect->NeedsBaseStyle(prop.mProperty)) {
+        EffectSet* effects = EffectSet::GetEffectSet(aFrame);
+        StyleAnimationValue baseStyle =
+          effects->GetBaseStyle(prop.mProperty);
+        MOZ_ASSERT(!baseStyle.IsNull(), "The base value should be set");
+        UpdateMinMaxScale(aFrame, baseStyle, aMinScale, aMaxScale);
+      }
+
       for (const AnimationPropertySegment& segment : prop.mSegments) {
         // In case of add or accumulate composite, StyleAnimationValue does
         // not have a valid value.
         if (segment.mFromComposite == dom::CompositeOperation::Replace) {
-          gfxSize from = segment.mFromValue.GetScaleValue(aFrame);
-          aMaxScale.width = std::max<float>(aMaxScale.width, from.width);
-          aMaxScale.height = std::max<float>(aMaxScale.height, from.height);
-          aMinScale.width = std::min<float>(aMinScale.width, from.width);
-          aMinScale.height = std::min<float>(aMinScale.height, from.height);
+          UpdateMinMaxScale(aFrame, segment.mFromValue, aMinScale, aMaxScale);
         }
         if (segment.mToComposite == dom::CompositeOperation::Replace) {
-          gfxSize to = segment.mToValue.GetScaleValue(aFrame);
-          aMaxScale.width = std::max<float>(aMaxScale.width, to.width);
-          aMaxScale.height = std::max<float>(aMaxScale.height, to.height);
-          aMinScale.width = std::min<float>(aMinScale.width, to.width);
-          aMinScale.height = std::min<float>(aMinScale.height, to.height);
+          UpdateMinMaxScale(aFrame, segment.mToValue, aMinScale, aMaxScale);
         }
       }
     }
   }
 }
 
 gfxSize
 nsLayoutUtils::ComputeSuitableScaleForAnimation(const nsIFrame* aFrame,