5#include "flutter/flow/layers/clip_path_layer.h"
7#include "flutter/flow/layers/layer_tree.h"
8#include "flutter/flow/layers/opacity_layer.h"
9#include "flutter/flow/layers/platform_view_layer.h"
10#include "flutter/flow/raster_cache_item.h"
11#include "flutter/flow/testing/layer_test.h"
12#include "flutter/flow/testing/mock_embedder.h"
13#include "flutter/flow/testing/mock_layer.h"
14#include "gtest/gtest.h"
28 EXPECT_DEATH_IF_SUPPORTED(
30 "clip_behavior != Clip::kNone");
36 layer->Preroll(preroll_context());
39 EXPECT_EQ(preroll_context()->state_stack.device_cull_rect(),
kGiantRect);
40 EXPECT_TRUE(preroll_context()->state_stack.is_empty());
43 EXPECT_EQ(layer->child_paint_bounds(),
kEmptyRect);
44 EXPECT_FALSE(layer->needs_painting(paint_context()));
46 EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()),
47 "needs_painting\\(context\\)");
53 auto layer = std::make_shared<ClipPathLayer>(layer_path,
Clip::kHardEdge);
55 EXPECT_EQ(layer->child_paint_bounds(),
kEmptyRect);
56 EXPECT_FALSE(layer->needs_painting(paint_context()));
58 EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()),
59 "needs_painting\\(context\\)");
69 auto mock_layer = std::make_shared<MockLayer>(child_path);
70 auto layer = std::make_shared<ClipPathLayer>(layer_path,
Clip::kHardEdge);
71 layer->Add(mock_layer);
74 preroll_context()->state_stack.set_preroll_delegate(distant_bounds,
76 layer->Preroll(preroll_context());
79 EXPECT_EQ(preroll_context()->state_stack.device_cull_rect(), distant_bounds);
80 EXPECT_TRUE(preroll_context()->state_stack.is_empty());
82 EXPECT_EQ(mock_layer->paint_bounds(), child_bounds);
83 EXPECT_EQ(layer->paint_bounds(), child_bounds);
84 EXPECT_EQ(layer->child_paint_bounds(), child_bounds);
85 EXPECT_TRUE(mock_layer->needs_painting(paint_context()));
86 EXPECT_TRUE(layer->needs_painting(paint_context()));
87 EXPECT_EQ(mock_layer->parent_cull_rect(),
kEmptyRect);
88 EXPECT_EQ(mock_layer->parent_matrix(), initial_matrix);
89 EXPECT_EQ(mock_layer->parent_mutators(), std::vector({Mutator(layer_path)}));
91 auto mutator = paint_context().state_stack.save();
92 mutator.clipRect(distant_bounds,
false);
93 EXPECT_FALSE(mock_layer->needs_painting(paint_context()));
94 EXPECT_FALSE(layer->needs_painting(paint_context()));
95 EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()),
96 "needs_painting\\(context\\)");
103 const SkRect device_cull_bounds = initial_matrix.
mapRect(local_cull_bounds);
109 auto mock_layer = std::make_shared<MockLayer>(child_path, child_paint);
110 auto layer = std::make_shared<ClipPathLayer>(clip_path,
Clip::kHardEdge);
111 layer->Add(mock_layer);
113 SkRect clip_cull_rect = local_cull_bounds;
114 ASSERT_TRUE(clip_cull_rect.
intersect(clip_bounds));
115 SkRect clip_layer_bounds = child_bounds;
116 ASSERT_TRUE(clip_layer_bounds.
intersect(clip_bounds));
119 preroll_context()->state_stack.set_preroll_delegate(device_cull_bounds,
121 paint_context().canvas->ClipRect(device_cull_bounds);
122 paint_context().canvas->Transform(initial_matrix);
124 layer->Preroll(preroll_context());
126 EXPECT_EQ(preroll_context()->state_stack.device_cull_rect(),
128 EXPECT_EQ(preroll_context()->state_stack.local_cull_rect(),
130 EXPECT_TRUE(preroll_context()->state_stack.is_empty());
132 EXPECT_EQ(mock_layer->paint_bounds(), child_bounds);
133 EXPECT_EQ(layer->paint_bounds(), clip_layer_bounds);
134 EXPECT_EQ(layer->child_paint_bounds(), child_bounds);
135 EXPECT_EQ(mock_layer->parent_cull_rect(), clip_cull_rect);
136 EXPECT_EQ(mock_layer->parent_matrix(), initial_matrix);
137 EXPECT_EQ(mock_layer->parent_mutators(), std::vector({Mutator(clip_path)}));
139 EXPECT_FALSE(layer->needs_painting(paint_context()));
140 EXPECT_FALSE(mock_layer->needs_painting(paint_context()));
154 auto mock_layer = std::make_shared<MockLayer>(child_path, child_paint);
155 auto layer = std::make_shared<ClipPathLayer>(layer_path,
Clip::kHardEdge);
156 layer->Add(mock_layer);
158 preroll_context()->state_stack.set_preroll_delegate(initial_matrix);
159 layer->Preroll(preroll_context());
162 EXPECT_EQ(preroll_context()->state_stack.device_cull_rect(),
kGiantRect);
163 EXPECT_TRUE(preroll_context()->state_stack.is_empty());
165 EXPECT_EQ(mock_layer->paint_bounds(), child_bounds);
166 EXPECT_EQ(layer->paint_bounds(), mock_layer->paint_bounds());
167 EXPECT_EQ(layer->child_paint_bounds(), child_bounds);
168 EXPECT_TRUE(mock_layer->needs_painting(paint_context()));
169 EXPECT_TRUE(layer->needs_painting(paint_context()));
170 EXPECT_EQ(mock_layer->parent_cull_rect(), layer_bounds);
171 EXPECT_EQ(mock_layer->parent_matrix(), initial_matrix);
172 EXPECT_EQ(mock_layer->parent_mutators(), std::vector({Mutator(layer_path)}));
174 layer->Paint(display_list_paint_context());
177 expected_builder.
Save();
179 expected_builder.
ClipPath(layer_path);
181 expected_builder.
DrawPath(child_path, child_paint);
192 const SkRect device_cull_bounds = initial_matrix.
mapRect(local_cull_bounds);
200 auto mock_layer = std::make_shared<MockLayer>(child_path, child_paint);
201 auto layer = std::make_shared<ClipPathLayer>(clip_path,
Clip::kHardEdge);
202 layer->Add(mock_layer);
204 SkRect clip_cull_rect = local_cull_bounds;
205 ASSERT_TRUE(clip_cull_rect.
intersect(clip_bounds));
206 SkRect clip_layer_bounds = child_bounds;
207 ASSERT_TRUE(clip_layer_bounds.
intersect(clip_bounds));
210 preroll_context()->state_stack.set_preroll_delegate(device_cull_bounds,
212 layer->Preroll(preroll_context());
215 EXPECT_EQ(preroll_context()->state_stack.device_cull_rect(),
217 EXPECT_EQ(preroll_context()->state_stack.local_cull_rect(),
219 EXPECT_TRUE(preroll_context()->state_stack.is_empty());
221 EXPECT_EQ(mock_layer->paint_bounds(), child_bounds);
222 EXPECT_EQ(layer->paint_bounds(), clip_layer_bounds);
223 EXPECT_EQ(layer->child_paint_bounds(), child_bounds);
224 EXPECT_TRUE(mock_layer->needs_painting(paint_context()));
225 EXPECT_TRUE(layer->needs_painting(paint_context()));
226 EXPECT_EQ(mock_layer->parent_cull_rect(), clip_cull_rect);
227 EXPECT_EQ(mock_layer->parent_matrix(), initial_matrix);
228 EXPECT_EQ(mock_layer->parent_mutators(), std::vector({Mutator(clip_path)}));
230 layer->Paint(display_list_paint_context());
233 expected_builder.
Save();
235 expected_builder.
ClipPath(clip_path);
237 expected_builder.
DrawPath(child_path, child_paint);
247 const std::shared_ptr<Layer>& child,
251 auto layer = std::make_shared<ClipPathLayer>(layer_path, clip_behavior);
252 if (child !=
nullptr) {
256 layer->Preroll(context);
269 std::shared_ptr<MockLayer> nochild;
270 auto reader = std::make_shared<MockLayer>(
path,
paint);
271 reader->set_fake_reads_surface(
true);
272 auto nonreader = std::make_shared<MockLayer>(
path,
paint);
277 EXPECT_FALSE(
ReadbackResult(context, save_layer, nochild,
false));
287 EXPECT_FALSE(
ReadbackResult(context, save_layer, nonreader,
false));
308 auto layer_clip =
SkPath()
311 auto clip_path_layer =
313 clip_path_layer->Add(mock1);
316 PrerollContext* context = preroll_context();
317 clip_path_layer->Preroll(context);
318 EXPECT_EQ(context->renderable_state_flags,
323 clip_path_layer->Add(mock2);
327 clip_path_layer->Preroll(context);
328 EXPECT_EQ(context->renderable_state_flags,
333 clip_path_layer->Add(mock3);
337 clip_path_layer->Preroll(context);
338 EXPECT_EQ(context->renderable_state_flags, 0);
342 auto clip_path_savelayer = std::make_shared<ClipPathLayer>(
344 clip_path_savelayer->Add(mock1);
345 clip_path_savelayer->Add(mock2);
348 clip_path_savelayer->Preroll(context);
352 clip_path_savelayer->Add(mock3);
353 clip_path_savelayer->Preroll(context);
363 auto clip_path_bad_child =
365 clip_path_bad_child->Add(mock1);
366 clip_path_bad_child->Add(mock2);
369 clip_path_bad_child->Preroll(context);
370 EXPECT_EQ(context->renderable_state_flags,
373 clip_path_bad_child->Add(mock4);
377 clip_path_bad_child->Preroll(context);
378 EXPECT_EQ(context->renderable_state_flags, 0);
383 auto clip_path_savelayer_bad_child = std::make_shared<ClipPathLayer>(
385 clip_path_savelayer_bad_child->Add(mock1);
386 clip_path_savelayer_bad_child->Add(mock2);
389 clip_path_savelayer_bad_child->Preroll(context);
393 clip_path_savelayer_bad_child->Add(mock4);
394 clip_path_savelayer_bad_child->Preroll(context);
404 auto layer_clip =
SkPath()
407 auto clip_path_layer =
409 clip_path_layer->Add(mock1);
410 clip_path_layer->Add(mock2);
415 clip_path_layer->Preroll(context);
419 int opacity_alpha = 0x7F;
421 auto opacity_layer = std::make_shared<OpacityLayer>(opacity_alpha,
offset);
422 opacity_layer->Add(clip_path_layer);
423 opacity_layer->Preroll(context);
424 EXPECT_TRUE(opacity_layer->children_can_accept_opacity());
428 expected_builder.
Save();
432 expected_builder.
Save();
446 opacity_layer->Paint(display_list_paint_context());
457 auto layer_clip =
SkPath()
460 auto clip_path_layer = std::make_shared<ClipPathLayer>(
462 clip_path_layer->Add(mock1);
463 clip_path_layer->Add(mock2);
468 clip_path_layer->Preroll(context);
471 int opacity_alpha = 0x7F;
473 auto opacity_layer = std::make_shared<OpacityLayer>(opacity_alpha,
offset);
474 opacity_layer->Add(clip_path_layer);
475 opacity_layer->Preroll(context);
476 EXPECT_TRUE(opacity_layer->children_can_accept_opacity());
480 expected_builder.
Save();
484 expected_builder.
Save();
486 expected_builder.
SaveLayer(&children_bounds,
487 &
DlPaint().setAlpha(opacity_alpha));
500 opacity_layer->Paint(display_list_paint_context());
507 auto layer_clip =
SkPath()
510 auto layer = std::make_shared<ClipPathLayer>(layer_clip,
515 SkMatrix cache_ctm = initial_transform;
519 use_mock_raster_cache();
520 preroll_context()->state_stack.set_preroll_delegate(initial_transform);
522 const auto* clip_cache_item = layer->raster_cache_item();
524 EXPECT_EQ(raster_cache()->GetLayerCachedEntriesCount(), (
size_t)0);
526 layer->Preroll(preroll_context());
529 EXPECT_EQ(raster_cache()->GetLayerCachedEntriesCount(), (
size_t)0);
532 layer->Preroll(preroll_context());
534 EXPECT_EQ(raster_cache()->GetLayerCachedEntriesCount(), (
size_t)0);
537 layer->Preroll(preroll_context());
539 EXPECT_EQ(raster_cache()->GetLayerCachedEntriesCount(), (
size_t)1);
540 EXPECT_EQ(clip_cache_item->cache_state(),
541 RasterCacheItem::CacheState::kCurrent);
544 cache_canvas, &
paint));
550 const int64_t view_id = 42;
552 std::make_shared<PlatformViewLayer>(view_offset, view_size, view_id);
555 auto clip = std::make_shared<ClipPathLayer>(layer_clip,
561 embedder.AddCanvas(&fake_overlay_builder);
562 preroll_context()->view_embedder = &embedder;
563 paint_context().view_embedder = &embedder;
565 clip->Preroll(preroll_context());
566 EXPECT_EQ(embedder.prerolled_views(), std::vector<int64_t>({view_id}));
568 clip->Paint(paint_context());
569 EXPECT_EQ(embedder.painted_views(), std::vector<int64_t>({view_id}));
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
static SkMatrix Translate(SkScalar dx, SkScalar dy)
bool mapRect(SkRect *dst, const SkRect &src, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
const SkRect & getBounds() const
SkPath & addOval(const SkRect &oval, SkPathDirection dir=SkPathDirection::kCW)
SkPath & addRect(const SkRect &rect, SkPathDirection dir, unsigned start)
void Transform(const SkMatrix *matrix) 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()
void ClipPath(const SkPath &path, ClipOp clip_op=ClipOp::kIntersect, bool is_aa=false) override
static constexpr int kCallerCanApplyOpacity
static void TryToRasterCache(const std::vector< RasterCacheItem * > &raster_cached_entries, const PaintContext *paint_context, bool ignore_raster_cache=false)
static constexpr int kSaveLayerRenderFlags
static std::shared_ptr< MockLayer > MakeOpacityCompatible(const SkPath &path)
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
bool DisplayListsEQ_Verbose(const DisplayList *a, const DisplayList *b)
static constexpr SkRect kEmptyRect
static bool ReadbackResult(PrerollContext *context, Clip clip_behavior, const std::shared_ptr< Layer > &child, bool before)
LayerTest ClipPathLayerTest
@ kAntiAliasWithSaveLayer
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 SkRect kGiantRect
static constexpr SkPoint Make(float x, float y)
bool intersect(const SkRect &r)
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
SkRect makeInset(float dx, float dy) const
void join(const SkRect &r)
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
static constexpr SkSize Make(SkScalar w, SkScalar h)
static constexpr DlColor kYellow()
bool surface_needs_readback
int renderable_state_flags
#define EXPECT_TRUE(handle)