[Impeller] Corrected the 'texture_coords' computation in 'Geometry::GetPositionUVBuffer' (flutter/engine#42619)
fix https://github.com/flutter/flutter/issues/128328 We need to transform the 'position' first and then divide 'texture_coverage', otherwise the result will be incorrect. without patch  with patch 
This commit is contained in:
@@ -147,7 +147,9 @@ bool GenerateMipmap(const std::shared_ptr<Context>& context,
|
||||
return buffer->SubmitCommands();
|
||||
}
|
||||
|
||||
void CanRenderTiledTexture(AiksTest* aiks_test, Entity::TileMode tile_mode) {
|
||||
void CanRenderTiledTexture(AiksTest* aiks_test,
|
||||
Entity::TileMode tile_mode,
|
||||
Matrix local_matrix = {}) {
|
||||
auto context = aiks_test->GetContext();
|
||||
ASSERT_TRUE(context);
|
||||
auto texture = aiks_test->CreateTextureForFixture("table_mountain_nx.png",
|
||||
@@ -158,7 +160,7 @@ void CanRenderTiledTexture(AiksTest* aiks_test, Entity::TileMode tile_mode) {
|
||||
canvas.Translate({100.0f, 100.0f, 0});
|
||||
Paint paint;
|
||||
paint.color_source =
|
||||
ColorSource::MakeImage(texture, tile_mode, tile_mode, {}, {});
|
||||
ColorSource::MakeImage(texture, tile_mode, tile_mode, {}, local_matrix);
|
||||
paint.color = Color(1, 1, 1, 1);
|
||||
canvas.DrawRect({0, 0, 600, 600}, paint);
|
||||
|
||||
@@ -199,6 +201,11 @@ TEST_P(AiksTest, CanRenderTiledTextureDecal) {
|
||||
CanRenderTiledTexture(this, Entity::TileMode::kDecal);
|
||||
}
|
||||
|
||||
TEST_P(AiksTest, CanRenderTiledTextureClampWithTranslate) {
|
||||
CanRenderTiledTexture(this, Entity::TileMode::kClamp,
|
||||
Matrix::MakeTranslation({172.f, 172.f, 0.f}));
|
||||
}
|
||||
|
||||
TEST_P(AiksTest, CanRenderImageRect) {
|
||||
Canvas canvas;
|
||||
Paint paint;
|
||||
|
||||
@@ -84,9 +84,9 @@ GeometryResult FillPathGeometry::GetPositionUVBuffer(
|
||||
for (auto i = 0u; i < points.size(); i++) {
|
||||
VS::PerVertexData data;
|
||||
data.position = points[i];
|
||||
auto coverage_coords =
|
||||
(points[i] - texture_coverage.origin) / texture_coverage.size;
|
||||
data.texture_coords = effect_transform * coverage_coords;
|
||||
data.texture_coords = effect_transform *
|
||||
(points[i] - texture_coverage.origin) /
|
||||
texture_coverage.size;
|
||||
vertex_builder.AppendVertex(data);
|
||||
}
|
||||
for (auto i = 0u; i < indices.size(); i++) {
|
||||
@@ -114,9 +114,9 @@ GeometryResult FillPathGeometry::GetPositionUVBuffer(
|
||||
VS::PerVertexData data;
|
||||
Point vtx = {vertices[i], vertices[i + 1]};
|
||||
data.position = vtx;
|
||||
auto coverage_coords =
|
||||
(vtx - texture_coverage.origin) / texture_coverage.size;
|
||||
data.texture_coords = effect_transform * coverage_coords;
|
||||
data.texture_coords = effect_transform *
|
||||
(vtx - texture_coverage.origin) /
|
||||
texture_coverage.size;
|
||||
vertex_builder.AppendVertex(data);
|
||||
}
|
||||
FML_DCHECK(vertex_builder.GetVertexCount() == vertices_count / 2);
|
||||
|
||||
@@ -56,9 +56,9 @@ ComputeUVGeometryCPU(
|
||||
&texture_origin](SolidFillVertexShader::PerVertexData old_vtx) {
|
||||
TextureFillVertexShader::PerVertexData data;
|
||||
data.position = old_vtx.position;
|
||||
auto coverage_coords =
|
||||
(old_vtx.position - texture_origin) / texture_coverage;
|
||||
data.texture_coords = effect_transform * coverage_coords;
|
||||
data.texture_coords = effect_transform *
|
||||
(old_vtx.position - texture_origin) /
|
||||
texture_coverage;
|
||||
vertex_builder.AppendVertex(data);
|
||||
});
|
||||
return vertex_builder;
|
||||
@@ -76,8 +76,8 @@ GeometryResult ComputeUVGeometryForRect(Rect source_rect,
|
||||
auto points = source_rect.GetPoints();
|
||||
for (auto i = 0u, j = 0u; i < 8; i += 2, j++) {
|
||||
data[i] = points[j];
|
||||
data[i + 1] = effect_transform * ((points[j] - texture_coverage.origin) /
|
||||
texture_coverage.size);
|
||||
data[i + 1] = effect_transform * (points[j] - texture_coverage.origin) /
|
||||
texture_coverage.size;
|
||||
}
|
||||
|
||||
return GeometryResult{
|
||||
|
||||
Reference in New Issue
Block a user