Bug 1305325 - Part 13: Factor the base value's scale in GetMinAndMaxScaleForAnimationProperty. r?birtles draft
authorHiroyuki Ikezoe <hiikezoe@mozilla-japan.org>
Sun, 04 Dec 2016 08:07:40 +0900
changeset 447348 a07714983b759d9c00e660bf145108c453f7bb09
parent 447347 ee8855c3a1772bc06dfaa893f56aff763b0663de
child 447349 cccd11f36543ca937c4c645169fb8c5983b3bdbc
push id38039
push userhiikezoe@mozilla-japan.org
push dateSat, 03 Dec 2016 23:26:35 +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,