diff --git a/engine/src/flutter/impeller/aiks/aiks_unittests.cc b/engine/src/flutter/impeller/aiks/aiks_unittests.cc index 0dc42ed6a8d..d6ed92840a8 100644 --- a/engine/src/flutter/impeller/aiks/aiks_unittests.cc +++ b/engine/src/flutter/impeller/aiks/aiks_unittests.cc @@ -2179,6 +2179,23 @@ TEST_P(AiksTest, CollapsedDrawPaintInSubpass) { ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture())); } +TEST_P(AiksTest, CollapsedDrawPaintInSubpassBackdropFilter) { + // Bug: https://github.com/flutter/flutter/issues/131576 + Canvas canvas; + canvas.DrawPaint( + {.color = Color::Yellow(), .blend_mode = BlendMode::kSource}); + canvas.SaveLayer({}, {}, + [](const FilterInput::Ref& input, + const Matrix& effect_transform, bool is_subpass) { + return FilterContents::MakeGaussianBlur(input, Sigma(20.0), + Sigma(20.0)); + }); + canvas.DrawPaint( + {.color = Color::CornflowerBlue(), .blend_mode = BlendMode::kSourceOver}); + + ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture())); +} + TEST_P(AiksTest, ForegroundBlendSubpassCollapseOptimization) { Canvas canvas; diff --git a/engine/src/flutter/impeller/entity/entity_pass.cc b/engine/src/flutter/impeller/entity/entity_pass.cc index ec070920678..b07374a8930 100644 --- a/engine/src/flutter/impeller/entity/entity_pass.cc +++ b/engine/src/flutter/impeller/entity/entity_pass.cc @@ -748,18 +748,19 @@ bool EntityPass::OnRender( render_element(backdrop_entity); } - bool is_collapsing_clear_colors = true; + bool is_collapsing_clear_colors = !collapsed_parent_pass && + // Backdrop filters act as a entity before + // everything and disrupt the optimization. + !backdrop_filter_proc_; for (const auto& element : elements_) { // Skip elements that are incorporated into the clear color. - if (!collapsed_parent_pass) { - if (is_collapsing_clear_colors) { - auto [entity_color, _] = - ElementAsBackgroundColor(element, root_pass_size); - if (entity_color.has_value()) { - continue; - } - is_collapsing_clear_colors = false; + if (is_collapsing_clear_colors) { + auto [entity_color, _] = + ElementAsBackgroundColor(element, root_pass_size); + if (entity_color.has_value()) { + continue; } + is_collapsing_clear_colors = false; } EntityResult result =