5#include "flutter/flow/layers/transform_layer.h"
7#include "flutter/flow/testing/diff_context_test.h"
8#include "flutter/flow/testing/layer_test.h"
9#include "flutter/flow/testing/mock_layer.h"
10#include "flutter/fml/macros.h"
19 auto layer = std::make_shared<TransformLayer>(
SkMatrix());
21 layer->Preroll(preroll_context());
24 EXPECT_FALSE(layer->needs_painting(paint_context()));
26 EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()),
27 "needs_painting\\(context\\)");
32 child_path.
addRect(5.0f, 6.0f, 20.5f, 21.5f);
33 auto mock_layer = std::make_shared<MockLayer>(child_path,
DlPaint());
34 auto layer = std::make_shared<TransformLayer>(
SkMatrix());
35 layer->Add(mock_layer);
37 EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()),
38 "needs_painting\\(context\\)");
44 child_path.
addRect(5.0f, 6.0f, 20.5f, 21.5f);
46 auto mock_layer = std::make_shared<MockLayer>(child_path,
DlPaint());
47 auto layer = std::make_shared<TransformLayer>(
SkMatrix());
48 layer->Add(mock_layer);
50 preroll_context()->state_stack.set_preroll_delegate(cull_rect);
51 layer->Preroll(preroll_context());
52 EXPECT_EQ(mock_layer->paint_bounds(), child_path.
getBounds());
53 EXPECT_EQ(layer->paint_bounds(), mock_layer->paint_bounds());
54 EXPECT_EQ(layer->child_paint_bounds(), mock_layer->paint_bounds());
55 EXPECT_TRUE(mock_layer->needs_painting(paint_context()));
56 EXPECT_TRUE(layer->needs_painting(paint_context()));
57 EXPECT_EQ(mock_layer->parent_matrix(),
SkMatrix());
58 EXPECT_EQ(mock_layer->parent_cull_rect(), cull_rect);
59 EXPECT_EQ(mock_layer->parent_mutators().stack_count(), 0u);
62 layer->Paint(display_list_paint_context());
65 expected_builder.
Save();
79 child_path.
addRect(5.0f, 6.0f, 20.5f, 21.5f);
82 SkRect device_cull_rect = initial_transform.
mapRect(local_cull_rect);
87 auto mock_layer = std::make_shared<MockLayer>(child_path,
DlPaint());
88 auto layer = std::make_shared<TransformLayer>(layer_transform);
89 layer->Add(mock_layer);
91 preroll_context()->state_stack.set_preroll_delegate(device_cull_rect,
93 layer->Preroll(preroll_context());
94 EXPECT_EQ(mock_layer->paint_bounds(), child_path.
getBounds());
95 EXPECT_EQ(layer->paint_bounds(),
96 layer_transform.
mapRect(mock_layer->paint_bounds()));
97 EXPECT_EQ(layer->child_paint_bounds(), mock_layer->paint_bounds());
98 EXPECT_TRUE(mock_layer->needs_painting(paint_context()));
99 EXPECT_TRUE(layer->needs_painting(paint_context()));
100 EXPECT_EQ(mock_layer->parent_matrix(),
102 EXPECT_EQ(mock_layer->parent_cull_rect(),
103 inverse_layer_transform.
mapRect(local_cull_rect));
104 EXPECT_EQ(mock_layer->parent_mutators(),
105 std::vector({Mutator(layer_transform)}));
107 layer->Paint(display_list_paint_context());
110 expected_builder.
Save();
112 expected_builder.
Transform(layer_transform);
124 child_path.
addRect(5.0f, 6.0f, 20.5f, 21.5f);
127 SkRect device_cull_rect = initial_transform.
mapRect(local_cull_rect);
132 auto mock_layer = std::make_shared<MockLayer>(child_path,
DlPaint());
133 auto layer = std::make_shared<TransformLayer>(
SkM44::Translate(2.5f, 3.5f));
134 layer->Add(mock_layer);
136 preroll_context()->state_stack.set_preroll_delegate(device_cull_rect,
138 layer->Preroll(preroll_context());
139 EXPECT_EQ(mock_layer->paint_bounds(), child_path.
getBounds());
140 EXPECT_EQ(layer->paint_bounds(),
141 layer_transform.
mapRect(mock_layer->paint_bounds()));
142 EXPECT_EQ(layer->child_paint_bounds(), mock_layer->paint_bounds());
143 EXPECT_TRUE(mock_layer->needs_painting(paint_context()));
144 EXPECT_TRUE(layer->needs_painting(paint_context()));
145 EXPECT_EQ(mock_layer->parent_matrix(),
147 EXPECT_EQ(mock_layer->parent_cull_rect(),
148 inverse_layer_transform.
mapRect(local_cull_rect));
149 EXPECT_EQ(mock_layer->parent_mutators(),
150 std::vector({Mutator(layer_transform)}));
152 layer->Paint(display_list_paint_context());
155 expected_builder.
Save();
157 expected_builder.
Transform(layer_transform);
169 child_path.
addRect(5.0f, 6.0f, 20.5f, 21.5f);
172 SkRect device_cull_rect = initial_transform.
mapRect(local_cull_rect);
179 SkM44 inverse_layer_transform44;
182 SkMatrix inverse_layer_transform = inverse_layer_transform44.
asM33();
184 auto mock_layer = std::make_shared<MockLayer>(child_path,
DlPaint());
185 auto layer = std::make_shared<TransformLayer>(layer_transform44);
186 layer->Add(mock_layer);
188 preroll_context()->state_stack.set_preroll_delegate(device_cull_rect,
190 layer->Preroll(preroll_context());
191 EXPECT_EQ(mock_layer->paint_bounds(), child_path.
getBounds());
192 EXPECT_EQ(layer->paint_bounds(),
193 layer_transform.
mapRect(mock_layer->paint_bounds()));
194 EXPECT_EQ(layer->child_paint_bounds(), mock_layer->paint_bounds());
195 EXPECT_TRUE(mock_layer->needs_painting(paint_context()));
196 EXPECT_TRUE(layer->needs_painting(paint_context()));
197 EXPECT_EQ(mock_layer->parent_matrix(),
204 SkRect parent_cull_rect = mock_layer->parent_cull_rect();
205 SkRect expect_parent_cull_rect =
206 inverse_layer_transform.
mapRect(local_cull_rect);
207 EXPECT_FLOAT_EQ(parent_cull_rect.
fLeft, expect_parent_cull_rect.
fLeft);
208 EXPECT_FLOAT_EQ(parent_cull_rect.
fTop, expect_parent_cull_rect.
fTop);
209 EXPECT_FLOAT_EQ(parent_cull_rect.
fRight, expect_parent_cull_rect.
fRight);
210 EXPECT_FLOAT_EQ(parent_cull_rect.
fBottom, expect_parent_cull_rect.
fBottom);
212 EXPECT_EQ(mock_layer->parent_mutators(),
213 std::vector({Mutator(layer_transform)}));
215 layer->Paint(display_list_paint_context());
218 expected_builder.
Save();
220 expected_builder.
Transform(layer_transform44);
232 child_path.
addRect(5.0f, 6.0f, 20.5f, 21.5f);
235 SkRect device_cull_rect = initial_transform.
mapRect(local_cull_rect);
238 SkMatrix inverse_layer1_transform, inverse_layer2_transform;
242 auto mock_layer = std::make_shared<MockLayer>(child_path,
DlPaint());
243 auto layer1 = std::make_shared<TransformLayer>(layer1_transform);
244 auto layer2 = std::make_shared<TransformLayer>(layer2_transform);
246 layer2->Add(mock_layer);
248 preroll_context()->state_stack.set_preroll_delegate(device_cull_rect,
250 layer1->Preroll(preroll_context());
251 EXPECT_EQ(mock_layer->paint_bounds(), child_path.
getBounds());
252 EXPECT_EQ(layer2->paint_bounds(),
253 layer2_transform.
mapRect(mock_layer->paint_bounds()));
254 EXPECT_EQ(layer2->child_paint_bounds(), mock_layer->paint_bounds());
255 EXPECT_EQ(layer1->paint_bounds(),
256 layer1_transform.
mapRect(layer2->paint_bounds()));
257 EXPECT_EQ(layer1->child_paint_bounds(), layer2->paint_bounds());
258 EXPECT_TRUE(mock_layer->needs_painting(paint_context()));
259 EXPECT_TRUE(layer2->needs_painting(paint_context()));
260 EXPECT_TRUE(layer1->needs_painting(paint_context()));
262 mock_layer->parent_matrix(),
265 EXPECT_EQ(mock_layer->parent_cull_rect(),
266 inverse_layer2_transform.
mapRect(
267 inverse_layer1_transform.
mapRect(local_cull_rect)));
269 mock_layer->parent_mutators(),
270 std::vector({Mutator(layer1_transform), Mutator(layer2_transform)}));
272 layer1->Paint(display_list_paint_context());
275 expected_builder.
Save();
277 expected_builder.
Transform(layer1_transform);
279 expected_builder.
Save();
281 expected_builder.
Transform(layer2_transform);
296 child_path.
addRect(5.0f, 6.0f, 20.5f, 21.5f);
299 SkRect device_cull_rect = initial_transform.
mapRect(local_cull_rect);
302 SkMatrix inverse_layer1_transform, inverse_layer2_transform;
308 auto mock_layer1 = std::make_shared<MockLayer>(child_path, child_paint1);
309 auto mock_layer2 = std::make_shared<MockLayer>(child_path, child_paint2);
310 auto layer1 = std::make_shared<TransformLayer>(layer1_transform);
311 auto layer2 = std::make_shared<TransformLayer>(layer2_transform);
312 layer1->Add(mock_layer1);
314 layer2->Add(mock_layer2);
316 preroll_context()->state_stack.set_preroll_delegate(device_cull_rect,
318 layer1->Preroll(preroll_context());
319 SkRect layer1_child_bounds = layer2->paint_bounds();
320 layer1_child_bounds.
join(mock_layer1->paint_bounds());
321 SkRect expected_layer1_bounds = layer1_child_bounds;
322 layer1_transform.
mapRect(&expected_layer1_bounds);
324 EXPECT_EQ(mock_layer2->paint_bounds(), child_path.
getBounds());
325 EXPECT_EQ(layer2->paint_bounds(),
326 layer2_transform.
mapRect(mock_layer2->paint_bounds()));
327 EXPECT_EQ(layer2->child_paint_bounds(), mock_layer2->paint_bounds());
328 EXPECT_EQ(mock_layer1->paint_bounds(), child_path.
getBounds());
329 EXPECT_EQ(layer1->paint_bounds(), expected_layer1_bounds);
330 EXPECT_EQ(layer1->child_paint_bounds(), layer1_child_bounds);
331 EXPECT_TRUE(mock_layer2->needs_painting(paint_context()));
332 EXPECT_TRUE(layer2->needs_painting(paint_context()));
333 EXPECT_TRUE(mock_layer1->needs_painting(paint_context()));
334 EXPECT_TRUE(layer1->needs_painting(paint_context()));
335 EXPECT_EQ(mock_layer1->parent_matrix(),
338 mock_layer2->parent_matrix(),
341 EXPECT_EQ(mock_layer1->parent_cull_rect(),
342 inverse_layer1_transform.
mapRect(local_cull_rect));
343 EXPECT_EQ(mock_layer2->parent_cull_rect(),
344 inverse_layer2_transform.
mapRect(
345 inverse_layer1_transform.
mapRect(local_cull_rect)));
346 EXPECT_EQ(mock_layer1->parent_mutators(),
347 std::vector({Mutator(layer1_transform)}));
349 mock_layer2->parent_mutators(),
350 std::vector({Mutator(layer1_transform), Mutator(layer2_transform)}));
352 layer1->Paint(display_list_paint_context());
355 expected_builder.
Save();
357 expected_builder.
Transform(layer1_transform);
359 expected_builder.
DrawPath(child_path, child_paint1);
362 expected_builder.
Save();
364 expected_builder.
Transform(layer2_transform);
366 expected_builder.
DrawPath(child_path, child_paint2);
380 auto transform1 = std::make_shared<TransformLayer>(
SkMatrix::Scale(2, 2));
381 transform1->Add(mock1);
384 PrerollContext* context = preroll_context();
385 transform1->Preroll(context);
386 EXPECT_EQ(context->renderable_state_flags,
391 transform1->Add(mock2);
395 transform1->Preroll(context);
396 EXPECT_EQ(context->renderable_state_flags,
401 transform1->Add(mock3);
405 transform1->Preroll(context);
406 EXPECT_EQ(context->renderable_state_flags, 0);
408 auto transform2 = std::make_shared<TransformLayer>(
SkMatrix::Scale(2, 2));
409 transform2->Add(mock1);
410 transform2->Add(mock2);
413 transform2->Preroll(context);
414 EXPECT_EQ(context->renderable_state_flags,
419 transform2->Add(mock4);
423 transform2->Preroll(context);
424 EXPECT_EQ(context->renderable_state_flags, 0);
433 auto transform_layer = std::make_shared<TransformLayer>(
transform);
434 transform_layer->Add(mock1);
435 transform_layer->Add(mock2);
439 PrerollContext* context = preroll_context();
440 transform_layer->Preroll(context);
441 EXPECT_EQ(context->renderable_state_flags,
444 int opacity_alpha = 0x7F;
446 auto opacity_layer = std::make_shared<OpacityLayer>(opacity_alpha,
offset);
447 opacity_layer->Add(transform_layer);
448 opacity_layer->Preroll(context);
449 EXPECT_TRUE(opacity_layer->children_can_accept_opacity());
451 DisplayListBuilder expected_builder;
453 expected_builder.
Save();
457 expected_builder.Save();
460 expected_builder.DrawPath(
path1,
DlPaint().setAlpha(opacity_alpha));
463 expected_builder.DrawPath(
path2,
DlPaint().setAlpha(opacity_alpha));
465 expected_builder.Restore();
468 expected_builder.Restore();
471 opacity_layer->Paint(display_list_paint_context());
479 auto m1 = std::make_shared<MockLayer>(
path1);
494 transform2->AssignOldLayer(transform1.get());
499 damage = DiffLayerTree(t2, t1);
505 transform3->AssignOldLayer(transform2.get());
510 damage = DiffLayerTree(t3, t2);
516 auto m1 = CreateContainerLayer(std::make_shared<MockLayer>(
path1));
517 auto m2 = CreateContainerLayer(std::make_shared<MockLayer>(
path1));
518 auto m3 = CreateContainerLayer(std::make_shared<MockLayer>(
path1));
520 auto transform1 = std::make_shared<TransformLayer>(
SkMatrix::Scale(2.0, 2.0));
524 transform1_1->Add(m1);
525 transform1->Add(transform1_1);
529 transform1_2->Add(m2);
530 transform1->Add(transform1_2);
534 transform1_3->Add(m3);
535 transform1->Add(transform1_3);
543 auto transform2 = std::make_shared<TransformLayer>(
SkMatrix::Scale(2.0, 2.0));
547 transform2_1->Add(m1);
548 transform2_1->AssignOldLayer(transform1_1.get());
549 transform2->Add(transform2_1);
554 transform2_2->Add(m2);
555 transform2_2->AssignOldLayer(transform1_2.get());
556 transform2->Add(transform2_2);
560 transform2_3->Add(m3);
561 transform2_3->AssignOldLayer(transform1_3.get());
562 transform2->Add(transform2_3);
567 damage = DiffLayerTree(l2, l1);
575 transform2->AssignOldLayer(transform1.get());
576 damage = DiffLayerTree(l2, l1);
static SkM44 Rotate(SkV3 axis, SkScalar radians)
SkM44 & preConcat(const SkM44 &m)
static SkM44 Translate(SkScalar x, SkScalar y, SkScalar z=0)
bool invert(SkM44 *inverse) const
SkM44 & preTranslate(SkScalar x, SkScalar y, SkScalar z=0)
static SkMatrix Scale(SkScalar sx, SkScalar sy)
static SkMatrix Translate(SkScalar dx, SkScalar dy)
static SkMatrix Concat(const SkMatrix &a, const SkMatrix &b)
bool invert(SkMatrix *inverse) const
bool mapRect(SkRect *dst, const SkRect &src, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
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 DrawPath(const SkPath &path, const DlPaint &paint) override
sk_sp< DisplayList > Build()
static constexpr int kCallerCanApplyOpacity
static std::shared_ptr< MockLayer > MakeOpacityCompatible(const SkPath &path)
static std::shared_ptr< MockLayer > Make(const SkPath &path, DlPaint paint=DlPaint())
TEST_F(DisplayListTest, Defaults)
LayerTestBase<::testing::Test > LayerTest
LayerTest TransformLayerTest
bool DisplayListsEQ_Verbose(const DisplayList *a, const DisplayList *b)
skgpu::graphite::Transform Transform
static SkColor4f transform(SkColor4f c, SkColorSpace *src, SkColorSpace *dst)
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()
SkScalar fBottom
larger y-axis bounds
SkScalar fLeft
smaller x-axis bounds
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
SkScalar fRight
larger x-axis bounds
void join(const SkRect &r)
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
SkScalar fTop
smaller y-axis bounds
static constexpr DlColor kBlue()
static constexpr DlColor kGreen()
#define EXPECT_TRUE(handle)