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
--- 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