[Impeller] fallback to position data if texture coordinates are undefined. (flutter/engine#46264)

Fixes https://github.com/flutter/flutter/issues/135441

This check was lost in some refactor, I added a test for it.
This commit is contained in:
Jonah Williams
2023-09-25 13:23:03 -07:00
committed by GitHub
parent a02355a95c
commit 7e31f94005
2 changed files with 25 additions and 1 deletions

View File

@@ -3559,5 +3559,27 @@ TEST_P(AiksTest, ReleasesTextureOnTeardown) {
"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

View File

@@ -229,11 +229,13 @@ GeometryResult VerticesGeometry::GetPositionUVBuffer(
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);