Skip to content

Commit

Permalink
[Impeller] Set the correct stencil depth for backdrop filter elements (
Browse files Browse the repository at this point in the history
  • Loading branch information
bdero authored Jul 18, 2022
1 parent f89fc25 commit 95cdf36
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
21 changes: 17 additions & 4 deletions impeller/display_list/display_list_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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;
Expand All @@ -319,10 +325,17 @@ TEST_P(DisplayListTest, CanDrawBackdropFilter) {
std::optional<SkRect> 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,
Expand Down
1 change: 1 addition & 0 deletions impeller/entity/entity_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 95cdf36

Please sign in to comment.