5#include "flutter/display_list/dl_tile_mode.h"
6#include "flutter/flow/layers/image_filter_layer.h"
8#include "flutter/flow/layers/layer_tree.h"
9#include "flutter/flow/layers/transform_layer.h"
10#include "flutter/flow/testing/diff_context_test.h"
11#include "flutter/flow/testing/layer_test.h"
12#include "flutter/flow/testing/mock_layer.h"
13#include "flutter/fml/macros.h"
14#include "gtest/gtest.h"
28 auto layer = std::make_shared<ImageFilterLayer>(
nullptr);
30 layer->Preroll(preroll_context());
32 EXPECT_FALSE(layer->needs_painting(paint_context()));
34 EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()),
35 "needs_painting\\(context\\)");
41 auto mock_layer = std::make_shared<MockLayer>(child_path);
42 auto layer = std::make_shared<ImageFilterLayer>(
nullptr);
43 layer->Add(mock_layer);
46 EXPECT_EQ(layer->child_paint_bounds(),
kEmptyRect);
47 EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()),
48 "needs_painting\\(context\\)");
57 auto mock_layer = std::make_shared<MockLayer>(child_path, child_paint);
58 auto layer = std::make_shared<ImageFilterLayer>(
nullptr);
59 layer->Add(mock_layer);
61 preroll_context()->state_stack.set_preroll_delegate(initial_transform);
62 layer->Preroll(preroll_context());
63 EXPECT_EQ(layer->paint_bounds(), child_bounds);
64 EXPECT_EQ(layer->child_paint_bounds(), child_bounds);
65 EXPECT_TRUE(layer->needs_painting(paint_context()));
66 EXPECT_EQ(mock_layer->parent_matrix(), initial_transform);
68 layer->Paint(display_list_paint_context());
69 DisplayListBuilder expected_builder;
71 expected_builder.Save();
73 expected_builder.DrawPath(child_path, child_paint);
75 expected_builder.Restore();
85 auto dl_image_filter = std::make_shared<DlMatrixImageFilter>(
87 auto mock_layer = std::make_shared<MockLayer>(child_path, child_paint);
88 auto layer = std::make_shared<ImageFilterLayer>(dl_image_filter);
89 layer->Add(mock_layer);
91 const SkRect child_rounded_bounds =
94 preroll_context()->state_stack.set_preroll_delegate(initial_transform);
95 layer->Preroll(preroll_context());
96 EXPECT_EQ(layer->paint_bounds(), child_rounded_bounds);
97 EXPECT_EQ(layer->child_paint_bounds(), child_bounds);
98 EXPECT_TRUE(layer->needs_painting(paint_context()));
99 EXPECT_EQ(mock_layer->parent_matrix(), initial_transform);
101 DisplayListBuilder expected_builder;
105 expected_builder.SaveLayer(&child_bounds, &dl_paint);
112 expected_builder.Restore();
113 auto expected_display_list = expected_builder.Build();
115 layer->Paint(display_list_paint_context());
126 auto dl_image_filter = std::make_shared<DlMatrixImageFilter>(
128 auto mock_layer = std::make_shared<MockLayer>(child_path, child_paint);
130 std::make_shared<ImageFilterLayer>(dl_image_filter, layer_offset);
131 layer->Add(mock_layer);
133 SkMatrix child_matrix = initial_transform;
135 const SkRect child_rounded_bounds =
138 preroll_context()->state_stack.set_preroll_delegate(initial_cull_rect,
140 layer->Preroll(preroll_context());
141 EXPECT_EQ(layer->paint_bounds(), child_rounded_bounds);
142 EXPECT_EQ(layer->child_paint_bounds(), child_bounds);
143 EXPECT_TRUE(layer->needs_painting(paint_context()));
144 EXPECT_EQ(mock_layer->parent_matrix(), child_matrix);
145 EXPECT_EQ(preroll_context()->state_stack.device_cull_rect(),
150 expected_builder.
Save();
152 expected_builder.
Translate(layer_offset.
fX, layer_offset.
fY);
155 expected_builder.
SaveLayer(&child_bounds, &dl_paint);
165 auto expected_display_list = expected_builder.
Build();
167 layer->Paint(display_list_paint_context());
178 auto dl_image_filter = std::make_shared<DlMatrixImageFilter>(
180 auto mock_layer = std::make_shared<MockLayer>(child_path, child_paint);
181 auto layer = std::make_shared<ImageFilterLayer>(dl_image_filter);
182 layer->Add(mock_layer);
186 preroll_context()->state_stack.set_preroll_delegate(initial_transform);
187 layer->Preroll(preroll_context());
188 EXPECT_EQ(layer->paint_bounds(), filter_bounds);
189 EXPECT_EQ(layer->child_paint_bounds(), child_bounds);
190 EXPECT_TRUE(layer->needs_painting(paint_context()));
191 EXPECT_EQ(mock_layer->parent_matrix(), initial_transform);
197 expected_builder.
SaveLayer(&child_bounds, &dl_paint);
205 auto expected_display_list = expected_builder.
Build();
207 layer->Paint(display_list_paint_context());
215 const SkPath child_path2 =
219 auto dl_image_filter = std::make_shared<DlMatrixImageFilter>(
221 auto mock_layer1 = std::make_shared<MockLayer>(child_path1, child_paint1);
222 auto mock_layer2 = std::make_shared<MockLayer>(child_path2, child_paint2);
223 auto layer = std::make_shared<ImageFilterLayer>(dl_image_filter);
224 layer->Add(mock_layer1);
225 layer->Add(mock_layer2);
231 preroll_context()->state_stack.set_preroll_delegate(initial_transform);
232 layer->Preroll(preroll_context());
233 EXPECT_EQ(mock_layer1->paint_bounds(), child_path1.
getBounds());
234 EXPECT_EQ(mock_layer2->paint_bounds(), child_path2.
getBounds());
235 EXPECT_EQ(layer->paint_bounds(), children_rounded_bounds);
236 EXPECT_EQ(layer->child_paint_bounds(), children_bounds);
237 EXPECT_TRUE(mock_layer1->needs_painting(paint_context()));
238 EXPECT_TRUE(mock_layer2->needs_painting(paint_context()));
239 EXPECT_TRUE(layer->needs_painting(paint_context()));
240 EXPECT_EQ(mock_layer1->parent_matrix(), initial_transform);
241 EXPECT_EQ(mock_layer2->parent_matrix(), initial_transform);
247 expected_builder.
SaveLayer(&children_bounds, &dl_paint);
258 auto expected_display_list = expected_builder.
Build();
260 layer->Paint(display_list_paint_context());
268 const SkPath child_path2 =
272 auto dl_image_filter1 = std::make_shared<DlMatrixImageFilter>(
274 auto dl_image_filter2 = std::make_shared<DlMatrixImageFilter>(
276 auto mock_layer1 = std::make_shared<MockLayer>(child_path1, child_paint1);
277 auto mock_layer2 = std::make_shared<MockLayer>(child_path2, child_paint2);
278 auto layer1 = std::make_shared<ImageFilterLayer>(dl_image_filter1);
279 auto layer2 = std::make_shared<ImageFilterLayer>(dl_image_filter2);
280 layer2->Add(mock_layer2);
281 layer1->Add(mock_layer1);
286 const SkRect children_rounded_bounds =
288 const SkRect mock_layer2_rounded_bounds =
291 preroll_context()->state_stack.set_preroll_delegate(initial_transform);
292 layer1->Preroll(preroll_context());
293 EXPECT_EQ(mock_layer1->paint_bounds(), child_path1.
getBounds());
294 EXPECT_EQ(mock_layer2->paint_bounds(), child_path2.
getBounds());
295 EXPECT_EQ(layer1->paint_bounds(), children_rounded_bounds);
296 EXPECT_EQ(layer1->child_paint_bounds(), children_bounds);
297 EXPECT_EQ(layer2->paint_bounds(), mock_layer2_rounded_bounds);
298 EXPECT_EQ(layer2->child_paint_bounds(), child_path2.
getBounds());
299 EXPECT_TRUE(mock_layer1->needs_painting(paint_context()));
300 EXPECT_TRUE(mock_layer2->needs_painting(paint_context()));
301 EXPECT_TRUE(layer1->needs_painting(paint_context()));
302 EXPECT_TRUE(layer2->needs_painting(paint_context()));
303 EXPECT_EQ(mock_layer1->parent_matrix(), initial_transform);
304 EXPECT_EQ(mock_layer2->parent_matrix(), initial_transform);
306 DisplayListBuilder expected_builder;
310 expected_builder.SaveLayer(&children_bounds, &dl_paint);
318 expected_builder.SaveLayer(&child_path2.
getBounds(), &child_paint);
322 expected_builder.Restore();
326 expected_builder.Restore();
327 auto expected_display_list = expected_builder.Build();
329 layer1->Paint(display_list_paint_context());
334 auto dl_image_filter = std::make_shared<DlMatrixImageFilter>(
338 auto layer = std::make_shared<ImageFilterLayer>(dl_image_filter);
339 preroll_context()->surface_needs_readback =
false;
340 layer->Preroll(preroll_context());
341 EXPECT_FALSE(preroll_context()->surface_needs_readback);
344 auto mock_layer = std::make_shared<MockLayer>(
SkPath(),
DlPaint());
345 mock_layer->set_fake_reads_surface(
true);
346 layer->Add(mock_layer);
347 preroll_context()->surface_needs_readback =
false;
348 layer->Preroll(preroll_context());
349 EXPECT_FALSE(preroll_context()->surface_needs_readback);
353 auto dl_image_filter = std::make_shared<DlMatrixImageFilter>(
358 auto mock_layer = std::make_shared<MockLayer>(child_path);
359 auto layer = std::make_shared<ImageFilterLayer>(dl_image_filter);
360 layer->Add(mock_layer);
362 SkMatrix cache_ctm = initial_transform;
363 DisplayListBuilder cache_canvas;
364 cache_canvas.Transform(cache_ctm);
365 DisplayListBuilder other_canvas;
366 other_canvas.Transform(other_transform);
369 use_mock_raster_cache();
370 const auto* cacheable_image_filter_item = layer->raster_cache_item();
372 EXPECT_EQ(raster_cache()->GetLayerCachedEntriesCount(), (
size_t)0);
374 EXPECT_EQ(cacheable_image_filter_item->cache_state(),
376 EXPECT_FALSE(cacheable_image_filter_item->Draw(paint_context(), &
paint));
378 preroll_context()->state_stack.set_preroll_delegate(initial_transform);
379 layer->Preroll(preroll_context());
382 EXPECT_EQ(raster_cache()->GetLayerCachedEntriesCount(), (
size_t)1);
385 EXPECT_EQ(cacheable_image_filter_item->cache_state(),
386 RasterCacheItem::CacheState::kChildren);
387 EXPECT_TRUE(raster_cache()->
Draw(cacheable_image_filter_item->GetId().value(),
388 cache_canvas, &
paint));
389 EXPECT_FALSE(raster_cache()->
Draw(
390 cacheable_image_filter_item->GetId().value(), other_canvas, &
paint));
394 auto dl_image_filter = std::make_shared<DlMatrixImageFilter>(
401 auto mock_layer1 = std::make_shared<MockLayer>(child_path1);
402 auto mock_layer2 = std::make_shared<MockLayer>(child_path2);
404 auto layer = std::make_shared<ImageFilterLayer>(dl_image_filter,
offset);
405 layer->Add(mock_layer1);
406 layer->Add(mock_layer2);
408 SkMatrix cache_ctm = initial_transform;
409 DisplayListBuilder cache_canvas;
410 cache_canvas.Transform(cache_ctm);
411 DisplayListBuilder other_canvas;
412 other_canvas.Transform(other_transform);
414 use_mock_raster_cache();
416 const auto* cacheable_image_filter_item = layer->raster_cache_item();
417 EXPECT_EQ(raster_cache()->GetLayerCachedEntriesCount(), (
size_t)0);
420 EXPECT_EQ(cacheable_image_filter_item->cache_state(),
422 EXPECT_FALSE(cacheable_image_filter_item->Draw(paint_context(), &
paint));
424 preroll_context()->state_stack.set_preroll_delegate(initial_transform);
425 layer->Preroll(preroll_context());
428 EXPECT_EQ(raster_cache()->GetLayerCachedEntriesCount(), (
size_t)1);
432 EXPECT_EQ(cacheable_image_filter_item->cache_state(),
433 RasterCacheItem::CacheState::kChildren);
434 EXPECT_TRUE(raster_cache()->
Draw(cacheable_image_filter_item->GetId().value(),
435 cache_canvas, &
paint));
436 EXPECT_FALSE(raster_cache()->
Draw(
437 cacheable_image_filter_item->GetId().value(), other_canvas, &
paint));
439 layer->Preroll(preroll_context());
447 SkMatrix cache_matrix = initial_transform;
449 auto transformed_filter = dl_image_filter->makeWithLocalMatrix(cache_matrix);
451 layer->Paint(display_list_paint_context());
452 DisplayListBuilder expected_builder;
454 expected_builder.Save();
461 raster_cache()->Draw(cacheable_image_filter_item->GetId().value(),
462 expected_builder, &dl_paint);
464 expected_builder.Restore();
466 expected_builder.Restore();
471 auto dl_image_filter = std::make_shared<DlMatrixImageFilter>(
478 auto mock_layer = std::make_shared<MockLayer>(child_path);
480 auto layer = std::make_shared<ImageFilterLayer>(dl_image_filter,
offset);
481 layer->Add(mock_layer);
483 SkMatrix cache_ctm = initial_transform;
495 use_mock_raster_cache();
496 preroll_context()->state_stack.set_preroll_delegate(initial_transform);
497 const auto* cacheable_image_filter_item = layer->raster_cache_item();
499 layer->Preroll(preroll_context());
501 layer->Paint(display_list_paint_context());
505 expected_builder.
Save();
510 expected_builder.
Transform(snapped_matrix);
512 expected_builder.
SaveLayer(&child_rect, &save_paint);
527 layer->Preroll(preroll_context());
528 layer->Paint(display_list_paint_context());
530 layer->Preroll(preroll_context());
531 layer->Paint(display_list_paint_context());
536 EXPECT_EQ(raster_cache()->GetLayerCachedEntriesCount(), (
size_t)2);
539 EXPECT_EQ(cacheable_image_filter_item->cache_state(),
540 RasterCacheItem::CacheState::kCurrent);
541 EXPECT_EQ(cacheable_image_filter_item->GetId(),
543 EXPECT_TRUE(raster_cache()->
Draw(cacheable_image_filter_item->GetId().value(),
544 cache_canvas, &
paint));
545 EXPECT_FALSE(raster_cache()->
Draw(
546 cacheable_image_filter_item->GetId().value(), other_canvas, &
paint));
548 layer->Preroll(preroll_context());
550 reset_display_list();
551 layer->Paint(display_list_paint_context());
555 expected_builder.
Save();
558 raster_cache()->
Draw(cacheable_image_filter_item->GetId().value(),
559 expected_builder,
nullptr));
573 auto dl_image_filter = std::make_shared<DlMatrixImageFilter>(
578 auto image_filter_layer = std::make_shared<ImageFilterLayer>(dl_image_filter);
579 image_filter_layer->Add(mock_layer);
583 image_filter_layer->Preroll(preroll_context());
590 int opacity_alpha = 0x7F;
592 auto opacity_layer = std::make_shared<OpacityLayer>(opacity_alpha,
offset);
593 opacity_layer->Add(image_filter_layer);
595 opacity_layer->Preroll(context);
596 EXPECT_TRUE(opacity_layer->children_can_accept_opacity());
600 expected_builder.
Save();
608 &image_filter_paint);
610 expected_builder.
DrawPath(child_path,
619 opacity_layer->Paint(display_list_paint_context());
626 auto dl_blur_filter =
637 auto filter_layer = std::make_shared<ImageFilterLayer>(dl_blur_filter);
639 filter_layer->Add(std::make_shared<MockLayer>(
path));
647 scale->Add(filter_layer);
659 damage = DiffLayerTree(l3, l2);
668 damage = DiffLayerTree(l4, l3);
673 auto dl_blur_filter =
687 auto filter_layer_1_1 = std::make_shared<ImageFilterLayer>(dl_blur_filter);
688 auto filter_layer_1_2 = std::make_shared<ImageFilterLayer>(dl_blur_filter);
689 filter_layer_1_1->Add(filter_layer_1_2);
691 filter_layer_1_2->Add(
693 l1.
root()->
Add(filter_layer_1_1);
697 auto filter_layer2_1 = std::make_shared<ImageFilterLayer>(dl_blur_filter);
698 filter_layer2_1->AssignOldLayer(filter_layer_1_1.get());
699 auto filter_layer2_2 = std::make_shared<ImageFilterLayer>(dl_blur_filter);
700 filter_layer2_2->AssignOldLayer(filter_layer_1_2.get());
701 filter_layer2_1->Add(filter_layer2_2);
702 filter_layer2_2->Add(
704 l2.
root()->
Add(filter_layer2_1);
707 auto damage = DiffLayerTree(l2, l1);
717 auto mock_layer = std::make_shared<MockLayer>(child_path, child_paint);
719 auto layer = std::make_shared<ImageFilterLayer>(
nullptr,
offset);
720 layer->Add(mock_layer);
722 layer->Preroll(preroll_context());
#define SkScalarRoundToScalar(x)
static SkMatrix Scale(SkScalar sx, SkScalar sy)
static SkMatrix Translate(SkScalar dx, SkScalar dy)
static SkMatrix MakeAll(SkScalar scaleX, SkScalar skewX, SkScalar transX, SkScalar skewY, SkScalar scaleY, SkScalar transY, SkScalar pers0, SkScalar pers1, SkScalar pers2)
static const SkMatrix & I()
SkMatrix & preTranslate(SkScalar dx, SkScalar dy)
SkMatrix & preConcat(const SkMatrix &other)
const SkRect & getBounds() const
SkPath & addRect(const SkRect &rect, SkPathDirection dir, unsigned start)
virtual void Add(std::shared_ptr< Layer > layer)
void Transform(const SkMatrix *matrix) override
void TransformReset() override
void Translate(SkScalar tx, SkScalar ty) override
void DrawPath(const SkPath &path, const DlPaint &paint) override
void SaveLayer(const SkRect *bounds, const DlPaint *paint=nullptr, const DlImageFilter *backdrop=nullptr) override
sk_sp< DisplayList > Build()
DlPaint & setColor(DlColor color)
DlPaint & setImageFilter(const std::shared_ptr< const DlImageFilter > &filter)
void set_preroll_delegate(const SkRect &cull_rect, const SkMatrix &matrix)
static constexpr int kCallerCanApplyColorFilter
static constexpr int kCallerCanApplyOpacity
static void TryToRasterCache(const std::vector< RasterCacheItem * > &raster_cached_entries, const PaintContext *paint_context, bool ignore_raster_cache=false)
static std::shared_ptr< MockLayer > Make(const SkPath &path, DlPaint paint=DlPaint())
static void Draw(SkCanvas *canvas, const SkRect &rect)
TEST_F(DisplayListTest, Defaults)
LayerTestBase<::testing::Test > LayerTest
LayerTest ImageFilterLayerTest
bool DisplayListsEQ_Verbose(const DisplayList *a, const DisplayList *b)
static constexpr SkRect kEmptyRect
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
static constexpr SkIRect MakeLTRB(int32_t l, int32_t t, int32_t r, int32_t b)
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
static constexpr SkPoint Make(float x, float y)
static SkRect Make(const SkISize &size)
constexpr SkRect makeOffset(float dx, float dy) const
void roundOut(SkIRect *dst) const
void join(const SkRect &r)
static constexpr SkRect MakeWH(float w, float h)
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
static constexpr DlColor kYellow()
static constexpr DlColor kRed()
static constexpr DlColor kCyan()
LayerStateStack & state_stack
int renderable_state_flags
#define EXPECT_TRUE(handle)