5#define FML_USED_ON_EMBEDDER
7#include "flutter/flow/layers/display_list_layer.h"
9#include "flutter/display_list/dl_builder.h"
10#include "flutter/flow/layers/layer_tree.h"
11#include "flutter/flow/testing/diff_context_test.h"
12#include "flutter/fml/macros.h"
25 auto layer = std::make_shared<DisplayListLayer>(
28 EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()),
"display_list_");
36 auto display_list =
builder.Build();
37 auto layer = std::make_shared<DisplayListLayer>(layer_offset, display_list,
41 EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()),
42 "needs_painting\\(context\\)");
50 auto display_list =
builder.Build();
51 auto layer = std::make_shared<DisplayListLayer>(layer_offset, display_list,
54 layer->Preroll(preroll_context());
56 EXPECT_FALSE(layer->needs_painting(paint_context()));
58 EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()),
59 "needs_painting\\(context\\)");
64 auto layer = std::make_shared<DisplayListLayer>(
68 EXPECT_DEATH_IF_SUPPORTED(layer->Preroll(preroll_context()),
"");
77 auto display_list =
builder.Build();
78 auto layer = std::make_shared<DisplayListLayer>(layer_offset, display_list,
81 layer->Preroll(preroll_context());
82 EXPECT_EQ(layer->paint_bounds(),
84 EXPECT_EQ(layer->display_list(), display_list.get());
85 EXPECT_TRUE(layer->needs_painting(paint_context()));
87 layer->Paint(display_list_paint_context());
90 expected_builder.
Save();
105 auto display_list =
builder.Build();
106 auto layer = std::make_shared<DisplayListLayer>(layer_offset, display_list,
109 SkRect original_cull_rect = preroll_context()->state_stack.device_cull_rect();
110 use_mock_raster_cache();
111 layer->Preroll(preroll_context());
112 ASSERT_EQ(preroll_context()->state_stack.device_cull_rect(),
121 auto display_list =
builder.Build();
122 auto display_list_layer = std::make_shared<DisplayListLayer>(
123 layer_offset, display_list,
false,
false);
124 EXPECT_TRUE(display_list->can_apply_group_opacity());
126 auto context = preroll_context();
127 display_list_layer->Preroll(preroll_context());
128 EXPECT_EQ(context->renderable_state_flags,
131 int opacity_alpha = 0x7F;
132 SkScalar opacity = opacity_alpha / 255.0;
135 std::make_shared<OpacityLayer>(opacity_alpha, opacity_offset);
136 opacity_layer->Add(display_list_layer);
137 opacity_layer->Preroll(context);
138 EXPECT_TRUE(opacity_layer->children_can_accept_opacity());
142 auto child_display_list = child_builder.
Build();
146 expected_builder.
Save();
148 expected_builder.
Translate(opacity_offset.
fX, opacity_offset.
fY);
150 expected_builder.
Save();
152 expected_builder.
Translate(layer_offset.
fX, layer_offset.
fY);
161 opacity_layer->Paint(display_list_paint_context());
173 auto display_list =
builder.Build();
174 auto display_list_layer = std::make_shared<DisplayListLayer>(
175 layer_offset, display_list,
false,
false);
176 EXPECT_FALSE(display_list->can_apply_group_opacity());
178 auto context = preroll_context();
179 display_list_layer->Preroll(preroll_context());
180 EXPECT_EQ(context->renderable_state_flags, 0);
182 int opacity_alpha = 0x7F;
185 std::make_shared<OpacityLayer>(opacity_alpha, opacity_offset);
186 opacity_layer->Add(display_list_layer);
187 opacity_layer->Preroll(context);
188 EXPECT_FALSE(opacity_layer->children_can_accept_opacity());
193 auto child_display_list = child_builder.
Build();
195 auto display_list_bounds = picture1_bounds;
196 display_list_bounds.
join(picture2_bounds);
197 auto save_layer_bounds =
198 display_list_bounds.makeOffset(layer_offset.
fX, layer_offset.
fY);
201 expected_builder.
Save();
203 expected_builder.
Translate(opacity_offset.
fX, opacity_offset.
fY);
204 expected_builder.
SaveLayer(&save_layer_bounds,
205 &
DlPaint().setAlpha(opacity_alpha));
208 expected_builder.
Save();
210 expected_builder.
Translate(layer_offset.
fX, layer_offset.
fY);
221 opacity_layer->Paint(display_list_paint_context());
233 auto display_list =
builder.Build();
234 auto display_list_layer = std::make_shared<DisplayListLayer>(
235 layer_offset, display_list,
true,
false);
236 EXPECT_FALSE(display_list->can_apply_group_opacity());
238 use_skia_raster_cache();
240 auto context = preroll_context();
241 display_list_layer->Preroll(preroll_context());
242 EXPECT_EQ(context->renderable_state_flags, 0);
245 display_list_layer->Preroll(preroll_context());
246 display_list_layer->Preroll(preroll_context());
247 display_list_layer->Preroll(preroll_context());
249 &paint_context(),
false);
251 int opacity_alpha = 0x7F;
254 std::make_shared<OpacityLayer>(opacity_alpha, opacity_offset);
255 opacity_layer->Add(display_list_layer);
256 opacity_layer->Preroll(context);
257 EXPECT_TRUE(opacity_layer->children_can_accept_opacity());
259 auto display_list_bounds = picture1_bounds;
260 display_list_bounds.
join(picture2_bounds);
261 auto save_layer_bounds =
262 display_list_bounds.makeOffset(layer_offset.
fX, layer_offset.
fY);
263 save_layer_bounds.roundOut(&save_layer_bounds);
264 auto opacity_integral_matrix =
266 SkMatrix layer_offset_matrix = opacity_integral_matrix;
268 auto layer_offset_integral_matrix =
276 expected.
Transform(opacity_integral_matrix);
282 expected.
Transform(layer_offset_integral_matrix);
283 context->raster_cache->Draw(display_list_layer->caching_key_id(),
285 &
DlPaint().setAlpha(opacity_alpha));
293 opacity_layer->Paint(display_list_paint_context());
303 auto display_list =
builder.Build();
304 auto display_list_layer = std::make_shared<DisplayListLayer>(
307 use_skia_raster_cache();
309 auto context = preroll_context();
311 auto mutator = context->state_stack.save();
313 display_list_layer->Preroll(preroll_context());
314 EXPECT_EQ(context->renderable_state_flags, 0);
317 display_list_layer->Preroll(preroll_context());
318 display_list_layer->Preroll(preroll_context());
319 display_list_layer->Preroll(preroll_context());
321 &paint_context(),
false);
325 expected_root_canvas.
Scale(2.0, 2.0);
326 ASSERT_TRUE(context->raster_cache->Draw(display_list_layer->caching_key_id(),
327 expected_root_canvas,
nullptr,
329 auto root_canvas_dl = expected_root_canvas.
Build();
330 const auto root_canvas_rects =
331 root_canvas_dl->rtree()->searchAndConsolidateRects(
kGiantRect,
true);
332 std::list<SkRect> root_canvas_rects_expected = {
335 EXPECT_EQ(root_canvas_rects_expected, root_canvas_rects);
338 expected_overlay_canvas.
Scale(2.0, 2.0);
339 ASSERT_TRUE(context->raster_cache->Draw(display_list_layer->caching_key_id(),
340 expected_overlay_canvas,
nullptr,
342 auto overlay_canvas_dl = expected_overlay_canvas.
Build();
343 const auto overlay_canvas_rects =
344 overlay_canvas_dl->rtree()->searchAndConsolidateRects(
kGiantRect,
true);
347 std::list<SkRect> overlay_canvas_rects_expected = {
352 EXPECT_EQ(overlay_canvas_rects_expected, overlay_canvas_rects);
361 tree1.
root()->
Add(CreateDisplayListLayer(display_list));
367 tree2.
root()->
Add(CreateDisplayListLayer(display_list));
369 damage = DiffLayerTree(tree2, tree1);
373 damage = DiffLayerTree(tree3, tree2);
382 CreateDisplayListLayer(display_list,
SkPoint::Make(0.5, 0.5)));
395 CreateDisplayListLayer(display_list,
SkPoint::Make(0.5, 0.5)));
407 tree1.
root()->
Add(CreateDisplayListLayer(display_list1));
416 tree2.
root()->
Add(CreateDisplayListLayer(display_list2));
418 damage = DiffLayerTree(tree2, tree1);
426 CreateDisplayListLayer(display_list3,
SkPoint::Make(10, 10)));
428 damage = DiffLayerTree(tree3, tree2);
436 CreateDisplayListLayer(display_list4,
SkPoint::Make(10, 10)));
438 damage = DiffLayerTree(tree4, tree3);
447 auto display_list =
builder.Build();
448 auto layer = std::make_shared<DisplayListLayer>(layer_offset, display_list,
451 layer->Preroll(preroll_context());
453 enable_leaf_layer_tracing();
454 layer->Paint(paint_context());
455 disable_leaf_layer_tracing();
457 auto& snapshot_store = layer_snapshot_store();
458 EXPECT_EQ(1u, snapshot_store.Size());
466 auto display_list =
builder.Build();
467 auto layer = std::make_shared<DisplayListLayer>(layer_offset, display_list,
470 layer->Preroll(preroll_context());
471 layer->Paint(paint_context());
473 auto& snapshot_store = layer_snapshot_store();
474 EXPECT_EQ(0u, snapshot_store.Size());
484 auto display_list =
builder.Build();
485 auto layer = std::make_shared<DisplayListLayer>(layer_offset, display_list,
488 auto raster_cache_item = layer->raster_cache_item();
489 use_mock_raster_cache();
494 ASSERT_TRUE(preroll_context()->state_stack.is_empty());
495 preroll_context()->state_stack.set_preroll_delegate(missed_cull_rect);
496 for (
int i = 0;
i < 10;
i++) {
497 preroll_context()->raster_cached_entries->clear();
498 layer->Preroll(preroll_context());
500 ASSERT_TRUE(raster_cache_item->GetId().has_value());
501 ASSERT_EQ(preroll_context()->raster_cache->GetAccessCount(
502 raster_cache_item->GetId().value(),
SkMatrix::I()),
504 ASSERT_EQ(preroll_context()->raster_cached_entries->size(),
size_t(1));
505 ASSERT_EQ(preroll_context()->raster_cache->EstimatePictureCacheByteSize(),
507 ASSERT_FALSE(raster_cache_item->TryToPrepareRasterCache(paint_context()));
508 ASSERT_FALSE(raster_cache_item->Draw(paint_context(),
nullptr));
515 ASSERT_TRUE(preroll_context()->state_stack.is_empty());
516 preroll_context()->state_stack.set_preroll_delegate(hit_cull_rect);
517 preroll_context()->raster_cached_entries->clear();
518 layer->Preroll(preroll_context());
520 ASSERT_TRUE(raster_cache_item->GetId().has_value());
521 ASSERT_EQ(preroll_context()->raster_cache->GetAccessCount(
522 raster_cache_item->GetId().value(),
SkMatrix::I()),
524 ASSERT_EQ(preroll_context()->raster_cached_entries->size(),
size_t(1));
525 ASSERT_EQ(preroll_context()->raster_cache->EstimatePictureCacheByteSize(),
527 ASSERT_FALSE(raster_cache_item->TryToPrepareRasterCache(paint_context()));
528 ASSERT_FALSE(raster_cache_item->Draw(paint_context(),
nullptr));
534 ASSERT_TRUE(preroll_context()->state_stack.is_empty());
535 preroll_context()->state_stack.set_preroll_delegate(missed_cull_rect);
536 for (
int i = 0;
i < 10;
i++) {
537 preroll_context()->raster_cached_entries->clear();
538 layer->Preroll(preroll_context());
540 ASSERT_TRUE(raster_cache_item->GetId().has_value());
541 ASSERT_EQ(preroll_context()->raster_cache->GetAccessCount(
542 raster_cache_item->GetId().value(),
SkMatrix::I()),
544 ASSERT_EQ(preroll_context()->raster_cached_entries->size(),
size_t(1));
545 ASSERT_EQ(preroll_context()->raster_cache->EstimatePictureCacheByteSize(),
547 ASSERT_FALSE(raster_cache_item->TryToPrepareRasterCache(paint_context()));
548 ASSERT_FALSE(raster_cache_item->Draw(paint_context(),
nullptr));
555 ASSERT_TRUE(preroll_context()->state_stack.is_empty());
556 preroll_context()->state_stack.set_preroll_delegate(hit_cull_rect);
557 preroll_context()->raster_cached_entries->clear();
558 layer->Preroll(preroll_context());
560 ASSERT_TRUE(raster_cache_item->GetId().has_value());
561 ASSERT_EQ(preroll_context()->raster_cache->GetAccessCount(
562 raster_cache_item->GetId().value(),
SkMatrix::I()),
564 ASSERT_EQ(preroll_context()->raster_cached_entries->size(),
size_t(1));
565 ASSERT_EQ(preroll_context()->raster_cache->EstimatePictureCacheByteSize(),
567 ASSERT_TRUE(raster_cache_item->TryToPrepareRasterCache(paint_context()));
568 ASSERT_GT(preroll_context()->raster_cache->EstimatePictureCacheByteSize(),
570 ASSERT_TRUE(raster_cache_item->Draw(paint_context(),
nullptr));
574 use_mock_raster_cache();
578 int layer_count = per_frame + 1;
579 SkPoint opacity_offset = {10, 10};
580 auto opacity_layer = std::make_shared<OpacityLayer>(0.5f, opacity_offset);
581 std::vector<std::shared_ptr<DisplayListLayer>> layers;
582 for (
int i = 0;
i < layer_count;
i++) {
586 auto display_list =
builder.Build();
587 ASSERT_FALSE(display_list->can_apply_group_opacity());
591 std::make_shared<DisplayListLayer>(
offset, display_list,
true,
false));
592 opacity_layer->Add(layers.back());
594 for (
size_t j = 0; j < context->raster_cache->access_threshold(); j++) {
595 context->raster_cache->BeginFrame();
596 for (
int i = 0;
i < layer_count;
i++) {
598 layers[
i]->Preroll(context);
602 opacity_layer->Preroll(context);
603 ASSERT_FALSE(opacity_layer->children_can_accept_opacity());
607 context->raster_cache->BeginFrame();
608 for (
int i = 0;
i < per_frame;
i++) {
610 layers[
i]->Preroll(context);
613 <<
"layer " << (
i + 1);
615 for (
int i = per_frame;
i < layer_count;
i++) {
617 layers[
i]->Preroll(context);
620 opacity_layer->Preroll(context);
621 ASSERT_FALSE(opacity_layer->children_can_accept_opacity());
625 context->raster_cache->BeginFrame();
626 for (
int i = 0;
i < layer_count;
i++) {
628 layers[
i]->Preroll(context);
631 <<
"layer " << (
i + 1);
633 opacity_layer->Preroll(context);
634 ASSERT_TRUE(opacity_layer->children_can_accept_opacity());
static SkMatrix Scale(SkScalar sx, SkScalar sy)
SkMatrix & postTranslate(SkScalar dx, SkScalar dy)
static SkMatrix Translate(SkScalar dx, SkScalar dy)
static const SkMatrix & I()
virtual void Add(std::shared_ptr< Layer > layer)
void DrawRect(const SkRect &rect, const DlPaint &paint) override
void Transform(const SkMatrix *matrix) override
void TransformReset() override
void Translate(SkScalar tx, SkScalar ty) override
void Scale(SkScalar sx, SkScalar sy) override
void SaveLayer(const SkRect *bounds, const DlPaint *paint=nullptr, const DlImageFilter *backdrop=nullptr) override
sk_sp< DisplayList > Build()
void DrawDisplayList(const sk_sp< DisplayList > display_list, SkScalar opacity=SK_Scalar1) override
static constexpr int kCallerCanApplyOpacity
static void TryToRasterCache(const std::vector< RasterCacheItem * > &raster_cached_entries, const PaintContext *paint_context, bool ignore_raster_cache=false)
TEST_F(DisplayListTest, Defaults)
LayerTestBase<::testing::Test > LayerTest
LayerTest DisplayListLayerTest
bool DisplayListsEQ_Verbose(const DisplayList *a, const DisplayList *b)
static constexpr SkRect kGiantRect
static constexpr SkIRect MakeLTRB(int32_t l, int32_t t, int32_t r, int32_t b)
static constexpr SkIRect MakeEmpty()
static constexpr SkPoint Make(float x, float y)
static constexpr SkRect MakeEmpty()
constexpr SkRect makeOffset(float dx, float dy) const
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
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 kRed()
static constexpr DlColor kGreen()
std::vector< RasterCacheItem * > * raster_cached_entries
int renderable_state_flags
static SkMatrix GetIntegralTransCTM(const SkMatrix &ctm)
Snap the translation components of the matrix to integers.
static constexpr int kDefaultPictureAndDisplayListCacheLimitPerFrame
#define EXPECT_TRUE(handle)