[Impeller] Fix handling of perspective matrices in Matrix::Translate (flutter/engine#55536)

Fixes https://github.com/flutter/flutter/issues/155450
This commit is contained in:
Jason Simmons 2024-10-03 08:28:47 -07:00 committed by GitHub
parent 56f6d72cd1
commit 8478ab1dfb
2 changed files with 13 additions and 1 deletions

View File

@ -245,7 +245,7 @@ struct Matrix {
m[0] * t.x + m[4] * t.y + m[8] * t.z + m[12],
m[1] * t.x + m[5] * t.y + m[9] * t.z + m[13],
m[2] * t.x + m[6] * t.y + m[10] * t.z + m[14],
m[15]);
m[3] * t.x + m[7] * t.y + m[11] * t.z + m[15]);
// clang-format on
}

View File

@ -187,5 +187,17 @@ TEST(MatrixTest, GetMaxBasisXYWithLargeAndSmallScalingFactorNonScaleTranslate) {
EXPECT_TRUE(std::isinf(m.GetMaxBasisLengthXY()));
}
TEST(MatrixTest, TranslateWithPerspective) {
Matrix m = Matrix::MakeRow(1.0, 0.0, 0.0, 10.0, //
0.0, 1.0, 0.0, 20.0, //
0.0, 0.0, 1.0, 0.0, //
0.0, 2.0, 0.0, 30.0);
Matrix result = m.Translate({100, 200});
EXPECT_TRUE(MatrixNear(result, Matrix::MakeRow(1.0, 0.0, 0.0, 110.0, //
0.0, 1.0, 0.0, 220.0, //
0.0, 0.0, 1.0, 0.0, //
0.0, 2.0, 0.0, 430.0)));
}
} // namespace testing
} // namespace impeller