Bug 1920673. Avoid calling IsSingular on a matrix before inverting it, just try to invert it and see if it succeeds. r=gfx-reviewers,nical

This repeated work does show up in profiles.

Differential Revision: https://phabricator.services.mozilla.com/D223289
This commit is contained in:
Timothy Nikkel
2024-10-02 11:43:25 +00:00
parent 961fede4de
commit 3951dc1258
3 changed files with 16 additions and 7 deletions

View File

@@ -2227,6 +2227,15 @@ class Matrix4x4TypedFlagged
return clone;
}
Maybe<Matrix4x4TypedFlagged<TargetUnits, SourceUnits>> MaybeInverse() const {
typedef Matrix4x4TypedFlagged<TargetUnits, SourceUnits> InvertedMatrix;
InvertedMatrix clone = Cast<InvertedMatrix>();
if (clone.Invert()) {
return Some(clone);
}
return Nothing();
}
template <typename NewTargetUnits>
bool operator==(
const Matrix4x4TypedFlagged<TargetUnits, NewTargetUnits>& aMatrix) const {

View File

@@ -2059,11 +2059,10 @@ static bool TransformGfxPointFromAncestor(RelativeTo aFrame,
auto matrix = nsLayoutUtils::GetTransformToAncestor(
RelativeTo{text ? text : aFrame.mFrame, aFrame.mViewportType},
aAncestor);
if (matrix.IsSingular()) {
aMatrixCache = matrix.MaybeInverse();
if (aMatrixCache.isNothing()) {
return false;
}
matrix.Invert();
aMatrixCache.emplace(matrix);
}
const Matrix4x4Flagged& ctm = *aMatrixCache;
@@ -2211,10 +2210,10 @@ nsLayoutUtils::TransformResult nsLayoutUtils::TransformRect(
}
Matrix4x4Flagged downToDest = GetTransformToAncestor(
RelativeTo{aToFrame}, RelativeTo{nearestCommonAncestor});
if (downToDest.IsSingular()) {
// invert downToDest in place
if (!downToDest.Invert()) {
return NONINVERTIBLE_TRANSFORM;
}
downToDest.Invert();
aRect = TransformFrameRectToAncestor(aFromFrame, aRect,
RelativeTo{nearestCommonAncestor});

View File

@@ -7239,7 +7239,8 @@ bool nsDisplayTransform::UntransformRect(const nsRect& aTransformedBounds,
const Matrix4x4& aMatrix,
float aAppUnitsPerPixel,
nsRect* aOutRect) {
if (aMatrix.IsSingular()) {
Maybe<Matrix4x4> inverse = aMatrix.MaybeInverse();
if (inverse.isNothing()) {
return false;
}
@@ -7255,7 +7256,7 @@ bool nsDisplayTransform::UntransformRect(const nsRect& aTransformedBounds,
NSAppUnitsToFloatPixels(aChildBounds.width, aAppUnitsPerPixel),
NSAppUnitsToFloatPixels(aChildBounds.height, aAppUnitsPerPixel));
result = aMatrix.Inverse().ProjectRectBounds(result, childGfxBounds);
result = inverse->ProjectRectBounds(result, childGfxBounds);
*aOutRect = nsLayoutUtils::RoundGfxRectToAppRect(ThebesRect(result),
aAppUnitsPerPixel);
return true;