Skip to content

Commit 7ab8ce9

Browse files
author
Jonah Williams
authored
[Impeller] fix image shader matrix to 3x3. (flutter#166612)
Fixes flutter#165205 Our users expect image shader matrices to be converted to 3x3
1 parent 22bcb9d commit 7ab8ce9

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

engine/src/flutter/impeller/display_list/aiks_dl_basic_unittests.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,7 @@ TEST_P(AiksTest, ImageColorSourceEffectTransform) {
938938

939939
// Scale
940940
{
941+
builder.Save();
941942
builder.Translate(100, 0);
942943
builder.Scale(100, 100);
943944
DlPaint paint;
@@ -948,6 +949,23 @@ TEST_P(AiksTest, ImageColorSourceEffectTransform) {
948949
DlImageSampling::kNearestNeighbor, &matrix));
949950

950951
builder.DrawRect(DlRect::MakeLTRB(0, 0, 1, 1), paint);
952+
builder.Restore();
953+
}
954+
955+
// Perspective
956+
{
957+
builder.Save();
958+
builder.Translate(150, 150);
959+
DlPaint paint;
960+
961+
DlMatrix matrix =
962+
DlMatrix::MakePerspective(Radians{0.5}, ISize{200, 200}, 0.05, 1);
963+
paint.setColorSource(DlColorSource::MakeImage(
964+
texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
965+
DlImageSampling::kNearestNeighbor, &matrix));
966+
967+
builder.DrawRect(DlRect::MakeLTRB(0, 0, 200, 200), paint);
968+
builder.Restore();
951969
}
952970

953971
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));

engine/src/flutter/impeller/display_list/paint.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ std::shared_ptr<ColorSourceContents> Paint::CreateContents() const {
197197
image_color_source->vertical_tile_mode());
198198
auto sampler_descriptor =
199199
skia_conversions::ToSamplerDescriptor(image_color_source->sampling());
200-
auto effect_transform = image_color_source->matrix();
200+
// See https://github.com/flutter/flutter/issues/165205
201+
flutter::DlMatrix effect_transform = image_color_source->matrix().To3x3();
201202

202203
auto contents = std::make_shared<TiledTextureContents>();
203204
contents->SetOpacityFactor(color.alpha);

engine/src/flutter/impeller/geometry/matrix.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,19 @@ struct Matrix {
247247
// clang-format on
248248
}
249249

250+
// Converts the second row/col to identity to make this an equivalent
251+
// to a Skia 3x3 Matrix.
252+
constexpr Matrix To3x3() const {
253+
// clang-format off
254+
return Matrix(
255+
m[0], m[1], 0, m[3],
256+
m[4], m[5], 0, m[7],
257+
0, 0, 1, 0,
258+
m[12], m[13], 0, m[15]
259+
);
260+
// clang-format on
261+
}
262+
250263
constexpr Matrix Translate(const Vector3& t) const {
251264
// clang-format off
252265
return Matrix(m[0], m[1], m[2], m[3],

engine/src/flutter/impeller/geometry/matrix_unittests.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,5 +313,14 @@ TEST(MatrixTest, MakeScaleTranslate) {
313313
Matrix::MakeTranslation({0, 0, 0}) * Matrix::MakeScale({0, 0, 0})));
314314
}
315315

316+
TEST(MatrixTest, To3x3) {
317+
Matrix x(1.0, 0.0, 4.0, 0.0, //
318+
0.0, 1.0, 4.0, 0.0, //
319+
6.0, 5.0, 111.0, 7.0, //
320+
0.0, 0.0, 9.0, 1.0);
321+
322+
EXPECT_TRUE(MatrixNear(x.To3x3(), Matrix()));
323+
}
324+
316325
} // namespace testing
317326
} // namespace impeller

0 commit comments

Comments
 (0)