diff --git a/gfx/2d/Matrix.h b/gfx/2d/Matrix.h index e425de6f30df..85de653a5448 100644 --- a/gfx/2d/Matrix.h +++ b/gfx/2d/Matrix.h @@ -635,6 +635,15 @@ class Matrix4x4Typed { 4 * aIndex); } + // External code should avoid calling this, and instead use + // ViewAs() from UnitTransforms.h, which requires providing + // a justification. + template + [[nodiscard]] NewMatrix4x4Typed Cast() const { + return NewMatrix4x4Typed(_11, _12, _13, _14, _21, _22, _23, _24, _31, _32, + _33, _34, _41, _42, _43, _44); + } + /** * Returns true if the matrix is isomorphic to a 2D affine transformation. */ @@ -1121,8 +1130,7 @@ class Matrix4x4Typed { template [[nodiscard]] Matrix4x4Typed PreScale( const ScaleFactor& aScale) const { - auto clone = Matrix4x4Typed::FromUnknownMatrix( - ToUnknownMatrix()); + auto clone = Cast>(); clone.PreScale(aScale.scale, aScale.scale, 1); return clone; } @@ -1130,8 +1138,7 @@ class Matrix4x4Typed { template [[nodiscard]] Matrix4x4Typed PreScale( const BaseScaleFactors2D& aScale) const { - auto clone = Matrix4x4Typed::FromUnknownMatrix( - ToUnknownMatrix()); + auto clone = Cast>(); clone.PreScale(aScale.xScale, aScale.yScale, 1); return clone; } @@ -1159,8 +1166,7 @@ class Matrix4x4Typed { template [[nodiscard]] Matrix4x4Typed PostScale( const ScaleFactor& aScale) const { - auto clone = Matrix4x4Typed::FromUnknownMatrix( - ToUnknownMatrix()); + auto clone = Cast>(); clone.PostScale(aScale.scale, aScale.scale, 1); return clone; } @@ -1168,8 +1174,7 @@ class Matrix4x4Typed { template [[nodiscard]] Matrix4x4Typed PostScale( const BaseScaleFactors2D& aScale) const { - auto clone = Matrix4x4Typed::FromUnknownMatrix( - ToUnknownMatrix()); + auto clone = Cast>(); clone.PostScale(aScale.xScale, aScale.yScale, 1); return clone; } @@ -1356,7 +1361,7 @@ class Matrix4x4Typed { Matrix4x4Typed Inverse() const { typedef Matrix4x4Typed InvertedMatrix; - InvertedMatrix clone = InvertedMatrix::FromUnknownMatrix(ToUnknownMatrix()); + InvertedMatrix clone = Cast(); DebugOnly inverted = clone.Invert(); MOZ_ASSERT(inverted, "Attempted to get the inverse of a non-invertible matrix"); @@ -1365,7 +1370,7 @@ class Matrix4x4Typed { Maybe> MaybeInverse() const { typedef Matrix4x4Typed InvertedMatrix; - InvertedMatrix clone = InvertedMatrix::FromUnknownMatrix(ToUnknownMatrix()); + InvertedMatrix clone = Cast(); if (clone.Invert()) { return Some(clone); } @@ -1975,6 +1980,12 @@ class Matrix4x4TypedFlagged Analyze(); } + template + [[nodiscard]] NewMatrix4x4TypedFlagged Cast() const { + return NewMatrix4x4TypedFlagged(_11, _12, _13, _14, _21, _22, _23, _24, _31, + _32, _33, _34, _41, _42, _43, _44, mType); + } + template PointTyped TransformPoint( const PointTyped& aPoint) const { @@ -2126,7 +2137,7 @@ class Matrix4x4TypedFlagged Matrix4x4TypedFlagged Inverse() const { typedef Matrix4x4TypedFlagged InvertedMatrix; - InvertedMatrix clone = InvertedMatrix::FromUnknownMatrix(ToUnknownMatrix()); + InvertedMatrix clone = Cast(); if (mType == MatrixType::Identity) { return clone; } @@ -2201,8 +2212,7 @@ class Matrix4x4TypedFlagged } if (aMatrix.mType == MatrixType::Identity) { - return Matrix4x4TypedFlagged:: - FromUnknownMatrix(this->ToUnknownMatrix()); + return Cast>(); } if (mType == MatrixType::Simple && aMatrix.mType == MatrixType::Simple) { diff --git a/layout/base/UnitTransforms.h b/layout/base/UnitTransforms.h index 374fe63b47bd..7bbd0f088f73 100644 --- a/layout/base/UnitTransforms.h +++ b/layout/base/UnitTransforms.h @@ -174,7 +174,7 @@ template & aMatrix, PixelCastJustification) { - return TargetMatrix::FromUnknownMatrix(aMatrix.ToUnknownMatrix()); + return aMatrix.template Cast(); } template @@ -183,7 +183,7 @@ Maybe ViewAs( SourceMatrixTargetUnits>>& aMatrix, PixelCastJustification) { if (aMatrix.isSome()) { - return Some(TargetMatrix::FromUnknownMatrix(aMatrix->ToUnknownMatrix())); + return Some(aMatrix->template Cast()); } return Nothing(); }