From 5ed3c76c5d43600cd833be571a2f36f3984b6ba5 Mon Sep 17 00:00:00 2001 From: Brandon DeRosier Date: Mon, 18 Jul 2022 11:19:43 -0700 Subject: [PATCH] [Impeller] Set the correct stencil depth for backdrop filter elements (flutter/engine#34709) --- .../display_list/display_list_unittests.cc | 21 +++++++++++++++---- .../flutter/impeller/entity/entity_pass.cc | 1 + 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/engine/src/flutter/impeller/display_list/display_list_unittests.cc b/engine/src/flutter/impeller/display_list/display_list_unittests.cc index 6d775baecc..e962caa852 100644 --- a/engine/src/flutter/impeller/display_list/display_list_unittests.cc +++ b/engine/src/flutter/impeller/display_list/display_list_unittests.cc @@ -10,6 +10,7 @@ #include "display_list/display_list_tile_mode.h" #include "gtest/gtest.h" #include "third_party/imgui/imgui.h" +#include "third_party/skia/include/core/SkClipOp.h" #include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkPathBuilder.h" @@ -294,18 +295,23 @@ TEST_P(DisplayListTest, CanDrawBackdropFilter) { auto callback = [&]() { if (first_frame) { first_frame = false; - ImGui::SetNextWindowSize({400, 100}); - ImGui::SetNextWindowPos({300, 650}); + ImGui::SetNextWindowPos({10, 10}); } static float sigma[] = {10, 10}; static bool use_bounds = true; static bool draw_circle = true; + static bool add_clip = true; - ImGui::Begin("Controls"); + ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize); ImGui::SliderFloat2("Sigma", sigma, 0, 100); + ImGui::NewLine(); + ImGui::TextWrapped( + "If everything is working correctly, none of the options below should " + "impact the filter's appearance."); ImGui::Checkbox("Use SaveLayer bounds", &use_bounds); ImGui::Checkbox("Draw child element", &draw_circle); + ImGui::Checkbox("Add pre-clip", &add_clip); ImGui::End(); flutter::DisplayListBuilder builder; @@ -319,10 +325,17 @@ TEST_P(DisplayListTest, CanDrawBackdropFilter) { std::optional bounds; if (use_bounds) { auto [p1, p2] = IMPELLER_PLAYGROUND_LINE( - Point(250, 150), Point(800, 600), 20, Color::White(), Color::White()); + Point(350, 150), Point(800, 600), 20, Color::White(), Color::White()); bounds = SkRect::MakeLTRB(p1.x, p1.y, p2.x, p2.y); } + // Insert a clip to test that the backdrop filter handles stencil depths > 0 + // correctly. + if (add_clip) { + builder.clipRect(SkRect::MakeLTRB(0, 0, 99999, 99999), + SkClipOp::kIntersect, true); + } + builder.drawImage(DlImageImpeller::Make(texture), SkPoint::Make(200, 200), flutter::DlImageSampling::kNearestNeighbor, true); builder.saveLayer(bounds.has_value() ? &bounds.value() : nullptr, nullptr, diff --git a/engine/src/flutter/impeller/entity/entity_pass.cc b/engine/src/flutter/impeller/entity/entity_pass.cc index 04231efc5b..b35b782916 100644 --- a/engine/src/flutter/impeller/entity/entity_pass.cc +++ b/engine/src/flutter/impeller/entity/entity_pass.cc @@ -379,6 +379,7 @@ bool EntityPass::OnRender(ContentContext& renderer, backdrop_entity.SetContents(std::move(backdrop_contents)); backdrop_entity.SetTransformation( Matrix::MakeTranslation(Vector3(parent_position - position))); + backdrop_entity.SetStencilDepth(stencil_depth_floor); render_element(backdrop_entity); }