Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 639d21a

Browse files
authored
[Impeller] make sure to render TiledTextureContents if the geometry doesn't fit in the texture's bounds. (#51393)
fixes flutter/flutter#144836 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
1 parent 89fb886 commit 639d21a

4 files changed

Lines changed: 43 additions & 2 deletions

File tree

impeller/aiks/aiks_blur_unittests.cc

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,5 +1146,40 @@ TEST_P(AiksTest, GaussianBlurMipMapSolidColor) {
11461146
#endif
11471147
}
11481148

1149+
TEST_P(AiksTest, MaskBlurDoesntStretchContents) {
1150+
Scalar sigma = 70;
1151+
auto callback = [&](AiksContext& renderer) -> std::optional<Picture> {
1152+
if (AiksTest::ImGuiBegin("Controls", nullptr,
1153+
ImGuiWindowFlags_AlwaysAutoResize)) {
1154+
ImGui::SliderFloat("Sigma", &sigma, 0, 500);
1155+
ImGui::End();
1156+
}
1157+
Canvas canvas;
1158+
canvas.Scale(GetContentScale());
1159+
canvas.DrawPaint({.color = Color(0.1, 0.1, 0.1, 1.0)});
1160+
1161+
std::shared_ptr<Texture> boston = CreateTextureForFixture("boston.jpg");
1162+
ColorSource image_source = ColorSource::MakeImage(
1163+
boston, Entity::TileMode::kRepeat, Entity::TileMode::kRepeat, {}, {});
1164+
1165+
canvas.Transform(Matrix::MakeTranslation({100, 100, 0}) *
1166+
Matrix::MakeScale({0.5, 0.5, 1.0}));
1167+
Paint paint = {
1168+
.color_source = image_source,
1169+
.mask_blur_descriptor =
1170+
Paint::MaskBlurDescriptor{
1171+
.style = FilterContents::BlurStyle::kNormal,
1172+
.sigma = Sigma(sigma),
1173+
},
1174+
};
1175+
canvas.DrawRect(
1176+
Rect::MakeXYWH(0, 0, boston->GetSize().width, boston->GetSize().height),
1177+
paint);
1178+
1179+
return canvas.EndRecordingAsPicture();
1180+
};
1181+
ASSERT_TRUE(OpenPlaygroundHere(callback));
1182+
}
1183+
11491184
} // namespace testing
11501185
} // namespace impeller

impeller/aiks/paint.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ std::shared_ptr<FilterContents> Paint::MaskBlurDescriptor::CreateMaskBlur(
183183
}
184184
color_source_contents->SetGeometry(
185185
Geometry::MakeRect(*expanded_local_bounds));
186-
187186
std::shared_ptr<Contents> color_contents = color_source_contents;
188187

189188
/// 4. Apply the user set color filter on the GPU, if applicable.

impeller/entity/contents/tiled_texture_contents.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,12 @@ std::optional<Snapshot> TiledTextureContents::RenderToSnapshot(
228228
bool msaa_enabled,
229229
int32_t mip_count,
230230
const std::string& label) const {
231+
std::optional<Rect> geometry_coverage = GetGeometry()->GetCoverage({});
231232
if (GetInverseEffectTransform().IsIdentity() &&
232-
GetGeometry()->IsAxisAlignedRect()) {
233+
GetGeometry()->IsAxisAlignedRect() &&
234+
(!geometry_coverage.has_value() ||
235+
Rect::MakeSize(texture_->GetSize())
236+
.Contains(geometry_coverage.value()))) {
233237
auto coverage = GetCoverage(entity);
234238
if (!coverage.has_value()) {
235239
return std::nullopt;

testing/impeller_golden_tests_output.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,9 @@ impeller_Play_AiksTest_ImageFilteredUnboundedSaveLayerWithUnboundedContents_Vulk
528528
impeller_Play_AiksTest_LinearToSrgbFilterSubpassCollapseOptimization_Metal.png
529529
impeller_Play_AiksTest_LinearToSrgbFilterSubpassCollapseOptimization_OpenGLES.png
530530
impeller_Play_AiksTest_LinearToSrgbFilterSubpassCollapseOptimization_Vulkan.png
531+
impeller_Play_AiksTest_MaskBlurDoesntStretchContents_Metal.png
532+
impeller_Play_AiksTest_MaskBlurDoesntStretchContents_OpenGLES.png
533+
impeller_Play_AiksTest_MaskBlurDoesntStretchContents_Vulkan.png
531534
impeller_Play_AiksTest_MaskBlurTexture_Metal.png
532535
impeller_Play_AiksTest_MaskBlurTexture_OpenGLES.png
533536
impeller_Play_AiksTest_MaskBlurTexture_Vulkan.png

0 commit comments

Comments
 (0)