From 05e2f3f60c2b6d8c88e9ad190c0480c9a00303fa Mon Sep 17 00:00:00 2001 From: Brandon DeRosier Date: Wed, 20 Sep 2023 19:02:34 -0700 Subject: [PATCH 1/2] [Impeller] Incorporate backdrop filters in subpass coverage. --- impeller/entity/entity_pass.cc | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/impeller/entity/entity_pass.cc b/impeller/entity/entity_pass.cc index 7390c14df9d61..d22372b10c4e4 100644 --- a/impeller/entity/entity_pass.cc +++ b/impeller/entity/entity_pass.cc @@ -124,10 +124,40 @@ std::optional EntityPass::GetElementsCoverage( std::optional unfiltered_coverage = GetSubpassCoverage(subpass, std::nullopt); + + // If the current pass elements have any coverage so far and there's a + // backdrop filter, then incorporate the backdrop filter in the + // pre-filtered coverage of the subpass. + if (result.has_value() && subpass.backdrop_filter_proc_) { + std::shared_ptr backdrop_filter = + subpass.backdrop_filter_proc_(FilterInput::Make(result.value()), + subpass.xformation_, + Entity::RenderingMode::kSubpass); + if (backdrop_filter) { + auto backdrop_coverage = backdrop_filter->GetCoverage({}); + backdrop_coverage->origin += result->origin; + if (backdrop_coverage.has_value()) { + if (unfiltered_coverage.has_value()) { + unfiltered_coverage = coverage->Union(*backdrop_coverage); + } else { + unfiltered_coverage = backdrop_coverage; + } + } + } + } + if (!unfiltered_coverage.has_value()) { continue; } + // Additionally, subpass textures may be passed through filters, which may + // modify the coverage. + // + // Note that we currently only assume that ImageFilters (such as blurs and + // matrix transforms) may modify coverage, although it's technically + // possible ColorFilters to affect coverage as well. For example: A + // ColorMatrixFilter could output a completely transparent result, and + // we could potentially detect this case as zero coverage in the future. std::shared_ptr image_filter = subpass.delegate_->WithImageFilter(*unfiltered_coverage, subpass.xformation_); From 9315ed17404f8d8ce9c8826b3e966eba5735c5a9 Mon Sep 17 00:00:00 2001 From: Brandon DeRosier Date: Fri, 22 Sep 2023 13:23:48 -0700 Subject: [PATCH 2/2] Address comment --- impeller/entity/entity_pass.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/impeller/entity/entity_pass.cc b/impeller/entity/entity_pass.cc index d22372b10c4e4..1d8b0a4f3735e 100644 --- a/impeller/entity/entity_pass.cc +++ b/impeller/entity/entity_pass.cc @@ -143,6 +143,9 @@ std::optional EntityPass::GetElementsCoverage( unfiltered_coverage = backdrop_coverage; } } + } else { + VALIDATION_LOG << "The EntityPass backdrop filter proc didn't return " + "a valid filter."; } }