[Impeller] Made the clear optimization handle backdrop filters. (flutter/engine#44192)

fixes https://github.com/flutter/flutter/issues/131576

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This commit is contained in:
gaaclarke 2023-08-01 09:24:03 -07:00 committed by GitHub
parent 1b4f573c46
commit dbf0e3eead
2 changed files with 27 additions and 9 deletions

View File

@ -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;

View File

@ -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 =