From dab093953cbf44a9d4b0d0cc7f862b50b858f14d Mon Sep 17 00:00:00 2001 From: Razvan Cojocaru Date: Wed, 1 Jun 2022 23:19:11 +0000 Subject: [PATCH] Bug 1770289 - Change the return type of nsLayoutUtils::ComputeSuitableScaleForAnimation() to MatrixScales. r=botond Differential Revision: https://phabricator.services.mozilla.com/D147835 --- gfx/2d/ScaleFactors2D.h | 12 ++++++ gfx/layers/wr/StackingContextHelper.cpp | 3 +- layout/base/nsLayoutUtils.cpp | 55 +++++++++++++------------ layout/base/nsLayoutUtils.h | 7 ++-- 4 files changed, 45 insertions(+), 32 deletions(-) diff --git a/gfx/2d/ScaleFactors2D.h b/gfx/2d/ScaleFactors2D.h index 784485e7d9ef..8bd8299263f3 100644 --- a/gfx/2d/ScaleFactors2D.h +++ b/gfx/2d/ScaleFactors2D.h @@ -168,6 +168,18 @@ struct BaseScaleFactors2D { const BaseScaleFactors2D& scale) { return BaseScaleFactors2D(scale.xScale, scale.yScale); } + + friend BaseScaleFactors2D Min(const BaseScaleFactors2D& aA, + const BaseScaleFactors2D& aB) { + return BaseScaleFactors2D(std::min(aA.xScale, aB.xScale), + std::min(aA.yScale, aB.yScale)); + } + + friend BaseScaleFactors2D Max(const BaseScaleFactors2D& aA, + const BaseScaleFactors2D& aB) { + return BaseScaleFactors2D(std::max(aA.xScale, aB.xScale), + std::max(aA.yScale, aB.yScale)); + } }; template diff --git a/gfx/layers/wr/StackingContextHelper.cpp b/gfx/layers/wr/StackingContextHelper.cpp index e08e15a79cbb..081476fa3b69 100644 --- a/gfx/layers/wr/StackingContextHelper.cpp +++ b/gfx/layers/wr/StackingContextHelper.cpp @@ -67,9 +67,8 @@ MatrixScales ChooseScale(nsIFrame* aContainerFrame, // to account nsSize scaledVisibleSize = nsSize(aVisibleRect.Width() * aXScale, aVisibleRect.Height() * aYScale); - Size size = nsLayoutUtils::ComputeSuitableScaleForAnimation( + scale = nsLayoutUtils::ComputeSuitableScaleForAnimation( aContainerFrame, scaledVisibleSize, displaySize); - scale = MatrixScales(size.width, size.height); // multiply by the scale inherited from ancestors--we use a uniform // scale factor to prevent blurring when the layer is rotated. float incomingScale = std::max(aXScale, aYScale); diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index 529120c8ab4a..04c50eb002f0 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -361,17 +361,17 @@ static float GetSuitableScale(float aMaxScale, float aMinScale, // The first value in this pair is the min scale, and the second one is the max // scale. -using MinAndMaxScale = std::pair; +using MinAndMaxScale = std::pair; static inline void UpdateMinMaxScale(const nsIFrame* aFrame, const AnimationValue& aValue, MinAndMaxScale& aMinAndMaxScale) { MatrixScales size = aValue.GetScaleValue(aFrame); - Size& minScale = aMinAndMaxScale.first; - Size& maxScale = aMinAndMaxScale.second; + MatrixScales& minScale = aMinAndMaxScale.first; + MatrixScales& maxScale = aMinAndMaxScale.second; - minScale = Min(minScale, {size.xScale, size.yScale}); - maxScale = Max(maxScale, {size.xScale, size.yScale}); + minScale = Min(minScale, size); + maxScale = Max(maxScale, size); } // The final transform matrix is calculated by merging the final results of each @@ -394,10 +394,10 @@ static Array GetMinAndMaxScaleForAnimationProperty( // The first element in the array is for eCSSProperty_transform, and the // second one is for eCSSProperty_scale. const MinAndMaxScale defaultValue = - std::make_pair(Size(std::numeric_limits::max(), - std::numeric_limits::max()), - Size(std::numeric_limits::min(), - std::numeric_limits::min())); + std::make_pair(MatrixScales(std::numeric_limits::max(), + std::numeric_limits::max()), + MatrixScales(std::numeric_limits::min(), + std::numeric_limits::min())); Array minAndMaxScales(defaultValue, defaultValue); for (dom::Animation* anim : aAnimations) { @@ -445,7 +445,7 @@ static Array GetMinAndMaxScaleForAnimationProperty( return minAndMaxScales; } -Size nsLayoutUtils::ComputeSuitableScaleForAnimation( +MatrixScales nsLayoutUtils::ComputeSuitableScaleForAnimation( const nsIFrame* aFrame, const nsSize& aVisibleSize, const nsSize& aDisplaySize) { const nsTArray> compositorAnimations = @@ -454,7 +454,7 @@ Size nsLayoutUtils::ComputeSuitableScaleForAnimation( nsCSSPropertyIDSet{eCSSProperty_transform, eCSSProperty_scale}); if (compositorAnimations.IsEmpty()) { - return Size(1.0, 1.0); + return MatrixScales(); } const Array minAndMaxScales = @@ -464,22 +464,22 @@ Size nsLayoutUtils::ComputeSuitableScaleForAnimation( // (or max()) as the scale value. However, in this case, we may render an // extreme small (or large) element, so this may not be a problem. If so, // please fix this. - Size maxScale(std::numeric_limits::min(), - std::numeric_limits::min()); - Size minScale(std::numeric_limits::max(), - std::numeric_limits::max()); + MatrixScales maxScale(std::numeric_limits::min(), + std::numeric_limits::min()); + MatrixScales minScale(std::numeric_limits::max(), + std::numeric_limits::max()); - auto isUnset = [](const Size& aMax, const Size& aMin) { - return aMax.width == std::numeric_limits::min() && - aMax.height == std::numeric_limits::min() && - aMin.width == std::numeric_limits::max() && - aMin.height == std::numeric_limits::max(); + auto isUnset = [](const MatrixScales& aMax, const MatrixScales& aMin) { + return aMax.xScale == std::numeric_limits::min() && + aMax.yScale == std::numeric_limits::min() && + aMin.xScale == std::numeric_limits::max() && + aMin.yScale == std::numeric_limits::max(); }; // Iterate the slots to get the final scale value. for (const auto& pair : minAndMaxScales) { - const Size& currMinScale = pair.first; - const Size& currMaxScale = pair.second; + const MatrixScales& currMinScale = pair.first; + const MatrixScales& currMaxScale = pair.second; if (isUnset(currMaxScale, currMinScale)) { // We don't have this animation property, so skip. @@ -502,13 +502,14 @@ Size nsLayoutUtils::ComputeSuitableScaleForAnimation( if (isUnset(maxScale, minScale)) { // We didn't encounter any transform-like property. - return Size(1.0, 1.0); + return MatrixScales(); } - return Size(GetSuitableScale(maxScale.width, minScale.width, - aVisibleSize.width, aDisplaySize.width), - GetSuitableScale(maxScale.height, minScale.height, - aVisibleSize.height, aDisplaySize.height)); + return MatrixScales( + GetSuitableScale(maxScale.xScale, minScale.xScale, aVisibleSize.width, + aDisplaySize.width), + GetSuitableScale(maxScale.yScale, minScale.yScale, aVisibleSize.height, + aDisplaySize.height)); } bool nsLayoutUtils::AreAsyncAnimationsEnabled() { diff --git a/layout/base/nsLayoutUtils.h b/layout/base/nsLayoutUtils.h index 0b0bc5ec18d2..39c1d5018ee6 100644 --- a/layout/base/nsLayoutUtils.h +++ b/layout/base/nsLayoutUtils.h @@ -164,6 +164,7 @@ class nsLayoutUtils { typedef mozilla::gfx::Size Size; typedef mozilla::gfx::Matrix4x4 Matrix4x4; typedef mozilla::gfx::Matrix4x4Flagged Matrix4x4Flagged; + typedef mozilla::gfx::MatrixScales MatrixScales; typedef mozilla::gfx::MatrixScalesDouble MatrixScalesDouble; typedef mozilla::gfx::RectCornerRadii RectCornerRadii; typedef mozilla::gfx::StrokeOptions StrokeOptions; @@ -2420,9 +2421,9 @@ class nsLayoutUtils { * @param aVisibleSize is the size of the area we want to paint * @param aDisplaySize is the size of the display area of the pres context */ - static Size ComputeSuitableScaleForAnimation(const nsIFrame* aFrame, - const nsSize& aVisibleSize, - const nsSize& aDisplaySize); + static MatrixScales ComputeSuitableScaleForAnimation( + const nsIFrame* aFrame, const nsSize& aVisibleSize, + const nsSize& aDisplaySize); /** * Checks whether we want to use the GPU to scale images when