[Impeller] fallback to position data if texture coordinates are undefined. (#46264)
Fixes https://github.com/flutter/flutter/issues/135441
This check was lost in some refactor, I added a test for it.
diff --git a/impeller/aiks/aiks_unittests.cc b/impeller/aiks/aiks_unittests.cc
index ded5012..caa3372 100644
--- a/impeller/aiks/aiks_unittests.cc
+++ b/impeller/aiks/aiks_unittests.cc
@@ -3559,5 +3559,27 @@
"released.";
}
+// Regression test for https://github.com/flutter/flutter/issues/135441 .
+TEST_P(AiksTest, VerticesGeometryUVPositionData) {
+ Canvas canvas;
+ Paint paint;
+ auto texture = CreateTextureForFixture("table_mountain_nx.png");
+
+ paint.color_source = ColorSource::MakeImage(texture, Entity::TileMode::kClamp,
+ Entity::TileMode::kClamp, {}, {});
+
+ auto vertices = {Point(0, 0), Point(texture->GetSize().width, 0),
+ Point(0, texture->GetSize().height)};
+ std::vector<uint16_t> indices = {0u, 1u, 2u};
+ std::vector<Point> texture_coordinates = {};
+ std::vector<Color> vertex_colors = {};
+ auto geometry = std::make_shared<VerticesGeometry>(
+ vertices, indices, texture_coordinates, vertex_colors,
+ Rect::MakeLTRB(0, 0, 1, 1), VerticesGeometry::VertexMode::kTriangleStrip);
+
+ canvas.DrawVertices(geometry, BlendMode::kSourceOver, paint);
+ ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
+}
+
} // namespace testing
} // namespace impeller
diff --git a/impeller/entity/geometry/vertices_geometry.cc b/impeller/entity/geometry/vertices_geometry.cc
index 8c1a0c0..23a1c32 100644
--- a/impeller/entity/geometry/vertices_geometry.cc
+++ b/impeller/entity/geometry/vertices_geometry.cc
@@ -229,11 +229,13 @@
auto vertex_count = vertices_.size();
auto size = texture_coverage.size;
auto origin = texture_coverage.origin;
+ auto has_texture_coordinates = HasTextureCoordinates();
std::vector<VS::PerVertexData> vertex_data(vertex_count);
{
for (auto i = 0u; i < vertex_count; i++) {
auto vertex = vertices_[i];
- auto texture_coord = texture_coordinates_[i];
+ auto texture_coord =
+ has_texture_coordinates ? texture_coordinates_[i] : vertices_[i];
auto uv =
effect_transform * Point((texture_coord.x - origin.x) / size.width,
(texture_coord.y - origin.y) / size.height);