From 3dd6e55e45a08eed7432fa0a7c5a318a1aef28e1 Mon Sep 17 00:00:00 2001 From: Brandon DeRosier Date: Thu, 8 Jun 2023 15:00:56 -0700 Subject: [PATCH] [Impeller] Reorder blend filter checks to avoid unnecessary destination snapshot (flutter/engine#42678) Side quest of https://github.com/flutter/flutter/issues/127232. Tiny reordering to avoid unnecessary input resolution. :) Happened to notice we were hitting this case while going through some frame captures of reported fidelity issues. Before: ![Screenshot 2023-06-08 at 1 45 48 PM](https://github.com/flutter/engine/assets/919017/aae28b7d-985d-4f16-9801-c689f8dc6f18) After: ![Screenshot 2023-06-08 at 1 48 49 PM](https://github.com/flutter/engine/assets/919017/b667a4cd-bcf7-4e3a-98f7-0ed182b7a227) --- .../contents/filters/blend_filter_contents.cc | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/engine/src/flutter/impeller/entity/contents/filters/blend_filter_contents.cc b/engine/src/flutter/impeller/entity/contents/filters/blend_filter_contents.cc index 4fb81ce6fa..041477710c 100644 --- a/engine/src/flutter/impeller/entity/contents/filters/blend_filter_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/filters/blend_filter_contents.cc @@ -362,21 +362,10 @@ std::optional BlendFilterContents::CreateForegroundPorterDuffBlend( BlendMode blend_mode, std::optional alpha, bool absorb_opacity) const { - auto dst_snapshot = - input->GetSnapshot("ForegroundPorterDuffBlend", renderer, entity); - if (!dst_snapshot.has_value()) { - return std::nullopt; - } - if (blend_mode == BlendMode::kClear) { return std::nullopt; } - if (blend_mode == BlendMode::kDestination) { - return Entity::FromSnapshot(dst_snapshot, entity.GetBlendMode(), - entity.GetStencilDepth()); - } - if (blend_mode == BlendMode::kSource) { auto contents = std::make_shared(); contents->SetGeometry(Geometry::MakeRect(coverage)); @@ -389,6 +378,17 @@ std::optional BlendFilterContents::CreateForegroundPorterDuffBlend( return foreground_entity; } + auto dst_snapshot = + input->GetSnapshot("ForegroundPorterDuffBlend", renderer, entity); + if (!dst_snapshot.has_value()) { + return std::nullopt; + } + + if (blend_mode == BlendMode::kDestination) { + return Entity::FromSnapshot(dst_snapshot, entity.GetBlendMode(), + entity.GetStencilDepth()); + } + RenderProc render_proc = [foreground_color, coverage, dst_snapshot, blend_mode, absorb_opacity, alpha]( const ContentContext& renderer,