Bug 1335942 - Part 5: Add AnimationValue::GetScaleValue(). r=hiro
authorBoris Chiou <boris.chiou@gmail.com>
Mon, 06 Feb 2017 16:32:21 +0800
changeset 341410 72d2c783f673c71ab1011e185a10f672a9b8220d
parent 341409 aa75aa7d8517d8f36ee750f9d2eba214b8758a48
child 341411 60a5029865aaf52c413a2553088db8395452d5fd
push id86727
push userkwierso@gmail.com
push dateThu, 09 Feb 2017 00:21:26 +0000
treeherdermozilla-inbound@55a4f5189115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershiro
bugs1335942
milestone54.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1335942 - Part 5: Add AnimationValue::GetScaleValue(). r=hiro Move the common part of GetScaleValue into nsStyleTransformMatrix, and add a new method, GetScaleValue, on AnimationValue, which can get the scale value from StyleAnimationValue or RawServoAnimationValue. MozReview-Commit-ID: 4spi1LkZrWP
layout/base/nsLayoutUtils.cpp
layout/painting/ActiveLayerTracker.cpp
layout/style/StyleAnimationValue.cpp
layout/style/StyleAnimationValue.h
layout/style/nsStyleTransformMatrix.cpp
layout/style/nsStyleTransformMatrix.h
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -546,17 +546,17 @@ GetSuitableScale(float aMaxScale, float 
     // (avoiding visually clunky delayerization).
     return aMaxScale;
   }
   return std::max(std::min(aMaxScale, displayVisibleRatio), aMinScale);
 }
 
 static inline void
 UpdateMinMaxScale(const nsIFrame* aFrame,
-                  const StyleAnimationValue& aValue,
+                  const AnimationValue& 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);
@@ -586,29 +586,29 @@ GetMinAndMaxScaleForAnimationProperty(co
       }
 
       // 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)) {
         StyleAnimationValue baseStyle =
           EffectCompositor::GetBaseStyle(prop.mProperty, aFrame);
         MOZ_ASSERT(!baseStyle.IsNull(), "The base value should be set");
-        UpdateMinMaxScale(aFrame, baseStyle, aMinScale, aMaxScale);
+        // FIXME: Bug 1311257: We need to get the baseStyle for
+        //        RawServoAnimationValue.
+        UpdateMinMaxScale(aFrame, { baseStyle, nullptr }, 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) {
-          UpdateMinMaxScale(aFrame, segment.mFromValue.mGecko, aMinScale,
-                            aMaxScale);
+          UpdateMinMaxScale(aFrame, segment.mFromValue, aMinScale, aMaxScale);
         }
         if (segment.mToComposite == dom::CompositeOperation::Replace) {
-          UpdateMinMaxScale(aFrame, segment.mToValue.mGecko, aMinScale,
-                            aMaxScale);
+          UpdateMinMaxScale(aFrame, segment.mToValue, aMinScale, aMaxScale);
         }
       }
     }
   }
 }
 
 gfxSize
 nsLayoutUtils::ComputeSuitableScaleForAnimation(const nsIFrame* aFrame,
--- a/layout/painting/ActiveLayerTracker.cpp
+++ b/layout/painting/ActiveLayerTracker.cpp
@@ -483,21 +483,21 @@ ContainsAnimatedScale(EffectSet& aEffect
       continue;
     }
 
     for (const AnimationProperty& prop : effect->Properties()) {
       if (prop.mProperty != eCSSProperty_transform) {
         continue;
       }
       for (AnimationPropertySegment segment : prop.mSegments) {
-        gfxSize from = segment.mFromValue.mGecko.GetScaleValue(aFrame);
+        gfxSize from = segment.mFromValue.GetScaleValue(aFrame);
         if (from != gfxSize(1.0f, 1.0f)) {
           return true;
         }
-        gfxSize to = segment.mToValue.mGecko.GetScaleValue(aFrame);
+        gfxSize to = segment.mToValue.GetScaleValue(aFrame);
         if (to != gfxSize(1.0f, 1.0f)) {
           return true;
         }
       }
     }
   }
 
   return false;
--- a/layout/style/StyleAnimationValue.cpp
+++ b/layout/style/StyleAnimationValue.cpp
@@ -4810,39 +4810,20 @@ StyleAnimationValue::ExtractComputedValu
       NS_NOTREACHED("shouldn't use on non-animatable properties");
   }
   return false;
 }
 
 gfxSize
 StyleAnimationValue::GetScaleValue(const nsIFrame* aForFrame) const
 {
-  MOZ_ASSERT(aForFrame);
   MOZ_ASSERT(GetUnit() == StyleAnimationValue::eUnit_Transform);
 
   nsCSSValueSharedList* list = GetCSSValueSharedListValue();
-  MOZ_ASSERT(list->mHead);
-
-  RuleNodeCacheConditions dontCare;
-  bool dontCareBool;
-  nsStyleTransformMatrix::TransformReferenceBox refBox(aForFrame);
-  Matrix4x4 transform = nsStyleTransformMatrix::ReadTransforms(
-                          list->mHead,
-                          aForFrame->StyleContext(),
-                          aForFrame->PresContext(), dontCare, refBox,
-                          aForFrame->PresContext()->AppUnitsPerDevPixel(),
-                          &dontCareBool);
-
-  Matrix transform2d;
-  bool canDraw2D = transform.CanDraw2D(&transform2d);
-  if (!canDraw2D) {
-    return gfxSize();
-  }
-
-  return ThebesMatrix(transform2d).ScaleFactors(true);
+  return nsStyleTransformMatrix::GetScaleValue(list, aForFrame);
 }
 
 StyleAnimationValue::StyleAnimationValue(int32_t aInt, Unit aUnit,
                                          IntegerConstructorType)
 {
   NS_ASSERTION(IsIntUnit(aUnit), "unit must be of integer type");
   mUnit = aUnit;
   mValue.mInt = aInt;
--- a/layout/style/StyleAnimationValue.h
+++ b/layout/style/StyleAnimationValue.h
@@ -594,16 +594,23 @@ struct AnimationValue
   }
 
   bool IsNull() const { return mGecko.IsNull() && !mServo; }
 
   float GetOpacity() const {
     return mServo ? Servo_AnimationValues_GetOpacity(mServo)
                   : mGecko.GetFloatValue();
   }
+
+  // Returns the scale for mGecko or mServo, which are calculated with
+  // reference to aFrame.
+  gfxSize GetScaleValue(const nsIFrame* aFrame) const {
+    // TODO: GetScaleValue for mServo.
+    return mGecko.GetScaleValue(aFrame);
+  }
 };
 
 struct PropertyStyleAnimationValuePair
 {
   nsCSSPropertyID mProperty;
   AnimationValue mValue;
 };
 } // namespace mozilla
--- a/layout/style/nsStyleTransformMatrix.cpp
+++ b/layout/style/nsStyleTransformMatrix.cpp
@@ -1254,9 +1254,34 @@ CSSValueArrayTo3DMatrix(nsCSSValue::Arra
   gfx::Float array[16];
   for (size_t i = 0; i < 16; ++i) {
     array[i] = aArray->Item(i+1).GetFloatValue();
   }
   Matrix4x4 m(array);
   return m;
 }
 
+gfxSize
+GetScaleValue(const nsCSSValueSharedList* aList,
+              const nsIFrame* aForFrame)
+{
+  MOZ_ASSERT(aList && aList->mHead);
+  MOZ_ASSERT(aForFrame);
+
+  RuleNodeCacheConditions dontCare;
+  bool dontCareBool;
+  TransformReferenceBox refBox(aForFrame);
+  Matrix4x4 transform = ReadTransforms(
+                          aList->mHead,
+                          aForFrame->StyleContext(),
+                          aForFrame->PresContext(), dontCare, refBox,
+                          aForFrame->PresContext()->AppUnitsPerDevPixel(),
+                          &dontCareBool);
+  Matrix transform2d;
+  bool canDraw2D = transform.CanDraw2D(&transform2d);
+  if (!canDraw2D) {
+    return gfxSize();
+  }
+
+  return ThebesMatrix(transform2d).ScaleFactors(true);
+}
+
 } // namespace nsStyleTransformMatrix
--- a/layout/style/nsStyleTransformMatrix.h
+++ b/layout/style/nsStyleTransformMatrix.h
@@ -225,11 +225,14 @@ namespace nsStyleTransformMatrix {
                          mozilla::gfx::Point3D& aScale,
                          ShearArray& aShear,
                          gfxQuaternion& aRotate,
                          mozilla::gfx::Point3D& aTranslate,
                          mozilla::gfx::Point4D& aPerspective);
 
   mozilla::gfx::Matrix CSSValueArrayTo2DMatrix(nsCSSValue::Array* aArray);
   mozilla::gfx::Matrix4x4 CSSValueArrayTo3DMatrix(nsCSSValue::Array* aArray);
+
+  gfxSize GetScaleValue(const nsCSSValueSharedList* aList,
+                        const nsIFrame* aForFrame);
 } // namespace nsStyleTransformMatrix
 
 #endif