|
3 | 3 | // found in the LICENSE file. |
4 | 4 |
|
5 | 5 | #include "display_list/display_list_blend_mode.h" |
| 6 | +#include "display_list/display_list_color.h" |
6 | 7 | #include "display_list/display_list_color_filter.h" |
7 | 8 | #include "display_list/display_list_image_filter.h" |
| 9 | +#include "display_list/display_list_paint.h" |
8 | 10 | #include "display_list/display_list_tile_mode.h" |
9 | 11 | #include "gtest/gtest.h" |
10 | 12 | #include "third_party/imgui/imgui.h" |
@@ -285,5 +287,64 @@ TEST_P(DisplayListTest, CanDrawWithImageBlurFilter) { |
285 | 287 | ASSERT_TRUE(OpenPlaygroundHere(callback)); |
286 | 288 | } |
287 | 289 |
|
| 290 | +TEST_P(DisplayListTest, CanDrawBackdropFilter) { |
| 291 | + auto texture = CreateTextureForFixture("embarcadero.jpg"); |
| 292 | + |
| 293 | + bool first_frame = true; |
| 294 | + auto callback = [&]() { |
| 295 | + if (first_frame) { |
| 296 | + first_frame = false; |
| 297 | + ImGui::SetNextWindowSize({400, 100}); |
| 298 | + ImGui::SetNextWindowPos({300, 650}); |
| 299 | + } |
| 300 | + |
| 301 | + static float sigma[] = {10, 10}; |
| 302 | + static bool use_bounds = true; |
| 303 | + static bool draw_circle = true; |
| 304 | + |
| 305 | + ImGui::Begin("Controls"); |
| 306 | + ImGui::SliderFloat2("Sigma", sigma, 0, 100); |
| 307 | + ImGui::Checkbox("Use SaveLayer bounds", &use_bounds); |
| 308 | + ImGui::Checkbox("Draw child element", &draw_circle); |
| 309 | + ImGui::End(); |
| 310 | + |
| 311 | + flutter::DisplayListBuilder builder; |
| 312 | + |
| 313 | + Vector2 scale = GetContentScale(); |
| 314 | + builder.scale(scale.x, scale.y); |
| 315 | + |
| 316 | + auto filter = flutter::DlBlurImageFilter(sigma[0], sigma[1], |
| 317 | + flutter::DlTileMode::kClamp); |
| 318 | + |
| 319 | + std::optional<SkRect> bounds; |
| 320 | + if (use_bounds) { |
| 321 | + auto [p1, p2] = IMPELLER_PLAYGROUND_LINE( |
| 322 | + Point(250, 150), Point(800, 600), 20, Color::White(), Color::White()); |
| 323 | + bounds = SkRect::MakeLTRB(p1.x, p1.y, p2.x, p2.y); |
| 324 | + } |
| 325 | + |
| 326 | + builder.drawImage(DlImageImpeller::Make(texture), SkPoint::Make(200, 200), |
| 327 | + SkSamplingOptions{}, true); |
| 328 | + builder.saveLayer(bounds.has_value() ? &bounds.value() : nullptr, nullptr, |
| 329 | + &filter); |
| 330 | + |
| 331 | + if (draw_circle) { |
| 332 | + auto circle_center = |
| 333 | + IMPELLER_PLAYGROUND_POINT(Point(500, 400), 20, Color::Red()); |
| 334 | + |
| 335 | + builder.setStyle(flutter::DlDrawStyle::kStroke); |
| 336 | + builder.setStrokeCap(flutter::DlStrokeCap::kButt); |
| 337 | + builder.setStrokeJoin(flutter::DlStrokeJoin::kBevel); |
| 338 | + builder.setStrokeWidth(10); |
| 339 | + builder.setColor(flutter::DlColor::kRed().withAlpha(100)); |
| 340 | + builder.drawCircle({circle_center.x, circle_center.y}, 100); |
| 341 | + } |
| 342 | + |
| 343 | + return builder.Build(); |
| 344 | + }; |
| 345 | + |
| 346 | + ASSERT_TRUE(OpenPlaygroundHere(callback)); |
| 347 | +} |
| 348 | + |
288 | 349 | } // namespace testing |
289 | 350 | } // namespace impeller |
0 commit comments