14#include "gtest/gtest.h"
40 std::make_shared<ShaderMaskLayer>(
nullptr,
DlRect(), DlBlendMode::kSrc);
42 layer->Preroll(preroll_context());
43 EXPECT_EQ(layer->paint_bounds(),
DlRect());
44 EXPECT_EQ(layer->child_paint_bounds(),
DlRect());
45 EXPECT_FALSE(layer->needs_painting(paint_context()));
47 EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()),
48 "needs_painting\\(context\\)");
54 auto mock_layer = std::make_shared<MockLayer>(child_path);
56 std::make_shared<ShaderMaskLayer>(
nullptr,
DlRect(), DlBlendMode::kSrc);
57 layer->Add(mock_layer);
59 EXPECT_EQ(layer->paint_bounds(),
DlRect());
60 EXPECT_EQ(layer->child_paint_bounds(),
DlRect());
61 EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()),
62 "needs_painting\\(context\\)");
72 auto mock_layer = std::make_shared<MockLayer>(child_path, child_paint);
73 auto layer = std::make_shared<ShaderMaskLayer>(
nullptr, layer_bounds,
75 layer->Add(mock_layer);
77 preroll_context()->state_stack.set_preroll_delegate(initial_transform);
78 layer->Preroll(preroll_context());
79 EXPECT_EQ(mock_layer->paint_bounds(), child_bounds);
80 EXPECT_EQ(layer->paint_bounds(), child_bounds);
81 EXPECT_EQ(layer->child_paint_bounds(), child_bounds);
82 EXPECT_TRUE(mock_layer->needs_painting(paint_context()));
83 EXPECT_TRUE(layer->needs_painting(paint_context()));
84 EXPECT_EQ(mock_layer->parent_matrix(), initial_transform);
90 layer->Paint(display_list_paint_context());
91 DisplayListBuilder expected_builder;
93 expected_builder.Save();
95 expected_builder.SaveLayer(child_bounds);
98 expected_builder.DrawPath(child_path, child_paint);
100 expected_builder.Translate(layer_bounds.GetLeft(),
101 layer_bounds.GetTop());
105 expected_builder.Restore();
107 expected_builder.Restore();
119 auto mock_layer = std::make_shared<MockLayer>(child_path, child_paint);
120 auto layer = std::make_shared<ShaderMaskLayer>(dl_filter, layer_bounds,
122 layer->Add(mock_layer);
124 preroll_context()->state_stack.set_preroll_delegate(initial_transform);
125 layer->Preroll(preroll_context());
126 EXPECT_EQ(layer->paint_bounds(), child_bounds);
127 EXPECT_EQ(layer->child_paint_bounds(), child_bounds);
128 EXPECT_TRUE(layer->needs_painting(paint_context()));
129 EXPECT_EQ(mock_layer->parent_matrix(), initial_transform);
135 layer->Paint(display_list_paint_context());
136 DisplayListBuilder expected_builder;
138 expected_builder.Save();
140 expected_builder.SaveLayer(child_bounds);
143 expected_builder.DrawPath(child_path, child_paint);
145 expected_builder.Translate(layer_bounds.GetLeft(),
146 layer_bounds.GetTop());
150 expected_builder.Restore();
152 expected_builder.Restore();
166 auto mock_layer1 = std::make_shared<MockLayer>(child_path1, child_paint1);
167 auto mock_layer2 = std::make_shared<MockLayer>(child_path2, child_paint2);
168 auto layer = std::make_shared<ShaderMaskLayer>(dl_filter, layer_bounds,
170 layer->Add(mock_layer1);
171 layer->Add(mock_layer2);
173 const DlRect children_bounds =
174 child_path1.GetBounds().
Union(child_path2.GetBounds());
175 preroll_context()->state_stack.set_preroll_delegate(initial_transform);
176 layer->Preroll(preroll_context());
177 EXPECT_EQ(mock_layer1->paint_bounds(), child_path1.GetBounds());
178 EXPECT_EQ(mock_layer2->paint_bounds(), child_path2.GetBounds());
179 EXPECT_EQ(layer->paint_bounds(), children_bounds);
180 EXPECT_EQ(layer->child_paint_bounds(), children_bounds);
181 EXPECT_TRUE(mock_layer1->needs_painting(paint_context()));
182 EXPECT_TRUE(mock_layer2->needs_painting(paint_context()));
183 EXPECT_TRUE(layer->needs_painting(paint_context()));
184 EXPECT_EQ(mock_layer1->parent_matrix(), initial_transform);
185 EXPECT_EQ(mock_layer2->parent_matrix(), initial_transform);
191 layer->Paint(display_list_paint_context());
192 DisplayListBuilder expected_builder;
194 expected_builder.Save();
196 expected_builder.SaveLayer(children_bounds);
199 expected_builder.DrawPath(child_path1, child_paint1);
202 expected_builder.DrawPath(child_path2, child_paint2);
204 expected_builder.Translate(layer_bounds.GetLeft(),
205 layer_bounds.GetTop());
209 expected_builder.Restore();
211 expected_builder.Restore();
226 auto mock_layer1 = std::make_shared<MockLayer>(child_path1, child_paint1);
227 auto mock_layer2 = std::make_shared<MockLayer>(child_path2, child_paint2);
228 auto layer1 = std::make_shared<ShaderMaskLayer>(dl_filter1, layer_bounds,
230 auto layer2 = std::make_shared<ShaderMaskLayer>(dl_filter2, layer_bounds,
232 layer2->Add(mock_layer2);
233 layer1->Add(mock_layer1);
236 const DlRect children_bounds =
237 child_path1.GetBounds().
Union(child_path2.GetBounds());
238 preroll_context()->state_stack.set_preroll_delegate(initial_transform);
239 layer1->Preroll(preroll_context());
240 EXPECT_EQ(mock_layer1->paint_bounds(), child_path1.GetBounds());
241 EXPECT_EQ(mock_layer2->paint_bounds(), child_path2.GetBounds());
242 EXPECT_EQ(layer1->paint_bounds(), children_bounds);
243 EXPECT_EQ(layer1->child_paint_bounds(), children_bounds);
244 EXPECT_EQ(layer2->paint_bounds(), mock_layer2->paint_bounds());
245 EXPECT_EQ(layer2->child_paint_bounds(), mock_layer2->paint_bounds());
246 EXPECT_TRUE(mock_layer1->needs_painting(paint_context()));
247 EXPECT_TRUE(mock_layer2->needs_painting(paint_context()));
248 EXPECT_TRUE(layer1->needs_painting(paint_context()));
249 EXPECT_TRUE(layer2->needs_painting(paint_context()));
250 EXPECT_EQ(mock_layer1->parent_matrix(), initial_transform);
251 EXPECT_EQ(mock_layer2->parent_matrix(), initial_transform);
253 DlPaint filter_paint1, filter_paint2;
259 layer1->Paint(display_list_paint_context());
260 DisplayListBuilder expected_builder;
262 expected_builder.Save();
264 expected_builder.SaveLayer(children_bounds);
267 expected_builder.DrawPath(child_path1, child_paint1);
270 expected_builder.Save();
272 expected_builder.SaveLayer(child_path2.GetBounds());
275 expected_builder.DrawPath(child_path2, child_paint2);
277 expected_builder.Translate(layer_bounds.GetLeft(),
278 layer_bounds.GetTop());
279 expected_builder.DrawRect(
282 expected_builder.Restore();
284 expected_builder.Restore();
286 expected_builder.Translate(layer_bounds.GetLeft(),
287 layer_bounds.GetTop());
291 expected_builder.Restore();
293 expected_builder.Restore();
301 auto layer = std::make_shared<ShaderMaskLayer>(dl_filter, layer_bounds,
305 preroll_context()->surface_needs_readback =
false;
306 layer->Preroll(preroll_context());
307 EXPECT_FALSE(preroll_context()->surface_needs_readback);
310 auto mock_layer = std::make_shared<MockLayer>(
DlPath(),
DlPaint());
311 mock_layer->set_fake_reads_surface(
true);
312 layer->Add(mock_layer);
313 preroll_context()->surface_needs_readback =
false;
314 layer->Preroll(preroll_context());
315 EXPECT_FALSE(preroll_context()->surface_needs_readback);
324 auto mock_layer = std::make_shared<MockLayer>(child_path);
325 auto layer = std::make_shared<ShaderMaskLayer>(dl_filter, layer_bounds,
327 layer->Add(mock_layer);
329 DlMatrix cache_ctm = initial_transform;
330 DisplayListBuilder cache_canvas;
333 use_mock_raster_cache();
334 preroll_context()->state_stack.set_preroll_delegate(initial_transform);
335 const auto* cacheable_shader_masker_item = layer->raster_cache_item();
337 EXPECT_EQ(raster_cache()->GetLayerCachedEntriesCount(), (
size_t)0);
338 EXPECT_EQ(cacheable_shader_masker_item->cache_state(),
340 EXPECT_FALSE(cacheable_shader_masker_item->GetId().has_value());
343 layer->Preroll(preroll_context());
346 EXPECT_EQ(raster_cache()->GetLayerCachedEntriesCount(), (
size_t)0);
347 EXPECT_EQ(cacheable_shader_masker_item->cache_state(),
349 EXPECT_FALSE(cacheable_shader_masker_item->GetId().has_value());
352 layer->Preroll(preroll_context());
354 EXPECT_EQ(raster_cache()->GetLayerCachedEntriesCount(), (
size_t)0);
355 EXPECT_EQ(cacheable_shader_masker_item->cache_state(),
357 EXPECT_FALSE(cacheable_shader_masker_item->GetId().has_value());
360 layer->Preroll(preroll_context());
362 EXPECT_EQ(raster_cache()->GetLayerCachedEntriesCount(), (
size_t)1);
363 EXPECT_EQ(cacheable_shader_masker_item->cache_state(),
366 EXPECT_TRUE(raster_cache()->Draw(
367 cacheable_shader_masker_item->GetId().value(), cache_canvas, &paint));
375 auto shader_mask_layer =
376 std::make_shared<ShaderMaskLayer>(
nullptr, mask_rect, DlBlendMode::kSrc);
377 shader_mask_layer->Add(mock_layer);
380 PrerollContext* context = preroll_context();
381 shader_mask_layer->Preroll(context);
384 int opacity_alpha = 0x7F;
386 auto opacity_layer = std::make_shared<OpacityLayer>(opacity_alpha, offset);
387 opacity_layer->Add(shader_mask_layer);
388 opacity_layer->Preroll(context);
389 EXPECT_TRUE(opacity_layer->children_can_accept_opacity());
391 DisplayListBuilder expected_builder;
393 expected_builder.Save();
395 expected_builder.Translate(offset.x, offset.y);
398 expected_builder.SaveLayer(child_path.GetBounds(), &sl_paint);
401 expected_builder.DrawPath(child_path,
DlPaint());
403 expected_builder.Translate(mask_rect.GetLeft(), mask_rect.GetTop());
405 DlPaint().setBlendMode(DlBlendMode::kSrc));
407 expected_builder.Restore();
410 expected_builder.Restore();
413 opacity_layer->Paint(display_list_paint_context());
418 use_mock_raster_cache();
426 auto mock_layer = std::make_shared<MockLayer>(child_path, child_paint);
427 auto layer = std::make_shared<ShaderMaskLayer>(dl_filter, layer_bounds,
429 layer->Add(mock_layer);
431 preroll_context()->state_stack.set_preroll_delegate(initial_transform);
432 layer->Preroll(preroll_context());
438 layer->Paint(display_list_paint_context());
441 expected_builder.
Save();
447 expected_builder.
SaveLayer(child_bounds);
450 expected_builder.
DrawPath(child_path, child_paint);
void SaveLayer(const std::optional< DlRect > &bounds, const DlPaint *paint=nullptr, const DlImageFilter *backdrop=nullptr, std::optional< int64_t > backdrop_id=std::nullopt) override
void Translate(DlScalar tx, DlScalar ty) override
sk_sp< DisplayList > Build()
void DrawPath(const DlPath &path, const DlPaint &paint) override
void DrawRect(const DlRect &rect, const DlPaint &paint) override
static std::shared_ptr< DlColorSource > MakeLinear(const DlPoint start_point, const DlPoint end_point, uint32_t stop_count, const DlColor *colors, const float *stops, DlTileMode tile_mode, const DlMatrix *matrix=nullptr)
DlPaint & setBlendMode(DlBlendMode mode)
DlPaint & setColorSource(std::nullptr_t source)
static DlPath MakeRect(const DlRect &rect)
static constexpr int kSaveLayerRenderFlags
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 DlPath &path, DlPaint paint=DlPaint())
TEST_F(DisplayListTest, Defaults)
LayerTestBase<::testing::Test > LayerTest
static std::shared_ptr< DlColorSource > MakeFilter(DlColor color)
LayerTest ShaderMaskLayerTest
bool DisplayListsEQ_Verbose(const DisplayList *a, const DisplayList *b)
impeller::Matrix DlMatrix
static constexpr DlColor kMagenta()
static constexpr DlColor kBlue()
static constexpr DlColor kYellow()
static constexpr DlColor kGreen()
static constexpr DlColor kCyan()
DlColor withAlpha(uint8_t alpha) const
A 4x4 matrix using column-major storage.
static constexpr Matrix MakeTranslation(const Vector3 &t)
constexpr Quad Transform(const Quad &quad) const
static constexpr TRect MakeWH(Type width, Type height)
constexpr auto GetTop() const
constexpr TSize< Type > GetSize() const
Returns the size of the rectangle which may be negative in either width or height and may have been c...
constexpr TRect Union(const TRect &o) const
constexpr auto GetLeft() const
static constexpr TRect MakeSize(const TSize< U > &size)
static constexpr TRect MakeLTRB(Type left, Type top, Type right, Type bottom)