From 8828f4b23abc07c36c001fbfc9f602df308074d2 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Wed, 17 May 2023 10:02:18 -0700 Subject: [PATCH] Fix bounds when painting style is stroke width for image shaders (#42052) Fixes https://github.com/flutter/flutter/issues/126739 When we're sampling from the texture, we need to sample from its origin regardless of how much offset the stroke width gives to the path. --- impeller/aiks/aiks_unittests.cc | 11 +++++++++++ impeller/entity/contents/tiled_texture_contents.cc | 5 ++--- impeller/entity/geometry.cc | 3 +-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/impeller/aiks/aiks_unittests.cc b/impeller/aiks/aiks_unittests.cc index b01bcf3bb665f..b856d86b22a15 100644 --- a/impeller/aiks/aiks_unittests.cc +++ b/impeller/aiks/aiks_unittests.cc @@ -165,6 +165,17 @@ void CanRenderTiledTexture(AiksTest* aiks_test, Entity::TileMode tile_mode) { }; paint.color = Color(1, 1, 1, 1); canvas.DrawRect({0, 0, 600, 600}, paint); + + // Should not change the image. + constexpr auto stroke_width = 64; + paint.style = Paint::Style::kStroke; + paint.stroke_width = stroke_width; + if (tile_mode == Entity::TileMode::kDecal) { + canvas.DrawRect({stroke_width, stroke_width, 600, 600}, paint); + } else { + canvas.DrawRect({0, 0, 600, 600}, paint); + } + ASSERT_TRUE(aiks_test->OpenPlaygroundHere(canvas.EndRecordingAsPicture())); } } // namespace diff --git a/impeller/entity/contents/tiled_texture_contents.cc b/impeller/entity/contents/tiled_texture_contents.cc index a53af0d0b82de..fbcf2291a5ebd 100644 --- a/impeller/entity/contents/tiled_texture_contents.cc +++ b/impeller/entity/contents/tiled_texture_contents.cc @@ -109,10 +109,9 @@ bool TiledTextureContents::Render(const ContentContext& renderer, auto& host_buffer = pass.GetTransientsBuffer(); - auto bounds_origin = GetGeometry()->GetCoverage(Matrix())->origin; auto geometry_result = GetGeometry()->GetPositionUVBuffer( - Rect(bounds_origin, Size(texture_size)), GetInverseMatrix(), renderer, - entity, pass); + Rect({0, 0}, Size(texture_size)), GetInverseMatrix(), renderer, entity, + pass); bool uses_emulated_tile_mode = UsesEmulatedTileMode(renderer.GetDeviceCapabilities()); diff --git a/impeller/entity/geometry.cc b/impeller/entity/geometry.cc index 612d9cb3a1af2..36ad666d5a28b 100644 --- a/impeller/entity/geometry.cc +++ b/impeller/entity/geometry.cc @@ -581,8 +581,7 @@ GeometryResult StrokePathGeometry::GetPositionUVBuffer( &effect_transform](SolidFillVertexShader::PerVertexData old_vtx) { TextureFillVertexShader::PerVertexData data; data.position = old_vtx.position; - auto coverage_coords = (old_vtx.position - texture_coverage.origin) / - texture_coverage.size; + auto coverage_coords = old_vtx.position / texture_coverage.size; data.texture_coords = effect_transform * coverage_coords; vertex_builder.AppendVertex(data); });