Bug 1335942 - Part 5: Add AnimationValue::GetScaleValue(). draft
authorBoris Chiou <boris.chiou@gmail.com>
Mon, 06 Feb 2017 16:32:21 +0800
changeset 480418 661f88b412561262558c1131dc6816d98bec74e8
parent 480417 2c3a6a7b035d577e158fe66f60a7ee4a8922d93d
child 480419 56c87da700fb074a664885c6f5e9423e0b3a8977
push id44527
push userbmo:boris.chiou@gmail.com
push dateWed, 08 Feb 2017 05:25:55 +0000
bugs1335942
milestone54.0a1
Bug 1335942 - Part 5: Add AnimationValue::GetScaleValue(). 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,28 +586,30 @@ 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,
+          UpdateMinMaxScale(aFrame, segment.mFromValue, aMinScale,
                             aMaxScale);
         }
         if (segment.mToComposite == dom::CompositeOperation::Replace) {
-          UpdateMinMaxScale(aFrame, segment.mToValue.mGecko, aMinScale,
+          UpdateMinMaxScale(aFrame, segment.mToValue, aMinScale,
                             aMaxScale);
         }
       }
     }
   }
 }
 
 gfxSize
--- 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