Flutter Engine
 
Loading...
Searching...
No Matches
diff_context_unittests.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
7namespace flutter {
8namespace testing {
9
10TEST_F(DiffContextTest, ClipAlignment) {
12 t1.root()->Add(CreateDisplayListLayer(
13 CreateDisplayList(DlRect::MakeLTRB(30, 30, 50, 50))));
14 auto damage = DiffLayerTree(t1, MockLayerTree(), DlIRect(), 0, 0);
15 EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(30, 30, 50, 50));
16 EXPECT_EQ(damage.buffer_damage, DlIRect::MakeLTRB(30, 30, 50, 50));
17
18 damage = DiffLayerTree(t1, MockLayerTree(), DlIRect(), 1, 1);
19 EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(30, 30, 50, 50));
20 EXPECT_EQ(damage.buffer_damage, DlIRect::MakeLTRB(30, 30, 50, 50));
21
22 damage = DiffLayerTree(t1, MockLayerTree(), DlIRect(), 8, 1);
23 EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(24, 30, 56, 50));
24 EXPECT_EQ(damage.buffer_damage, DlIRect::MakeLTRB(24, 30, 56, 50));
25
26 damage = DiffLayerTree(t1, MockLayerTree(), DlIRect(), 1, 8);
27 EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(30, 24, 50, 56));
28 EXPECT_EQ(damage.buffer_damage, DlIRect::MakeLTRB(30, 24, 50, 56));
29
30 damage = DiffLayerTree(t1, MockLayerTree(), DlIRect(), 16, 16);
31 EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(16, 16, 64, 64));
32 EXPECT_EQ(damage.buffer_damage, DlIRect::MakeLTRB(16, 16, 64, 64));
33}
34
35TEST_F(DiffContextTest, DisjointDamage) {
36 DlISize frame_size = DlISize(90, 90);
37 auto in_bounds_dl = CreateDisplayList(DlRect::MakeLTRB(30, 30, 50, 50));
38 auto out_bounds_dl = CreateDisplayList(DlRect::MakeLTRB(100, 100, 120, 120));
39
40 // We need both DisplayLists to be non-empty.
41 ASSERT_FALSE(in_bounds_dl->GetBounds().IsEmpty());
42 ASSERT_FALSE(out_bounds_dl->GetBounds().IsEmpty());
43
44 // We need the in_bounds DisplayList to be inside the frame size.
45 // We need the out_bounds DisplayList to be completely outside the frame.
46 ASSERT_TRUE(DlRect::MakeSize(frame_size).Contains(in_bounds_dl->GetBounds()));
47 ASSERT_FALSE(DlRect::MakeSize(frame_size)
48 .IntersectsWithRect(out_bounds_dl->GetBounds()));
49
50 MockLayerTree t1(frame_size);
51 t1.root()->Add(CreateDisplayListLayer(in_bounds_dl));
52
53 MockLayerTree t2(frame_size);
54 // Include previous
55 t2.root()->Add(CreateDisplayListLayer(in_bounds_dl));
56 // Add a new layer that is out of frame bounds
57 t2.root()->Add(CreateDisplayListLayer(out_bounds_dl));
58
59 // Cannot use DiffLayerTree because it implicitly adds a clip layer
60 // around the tree, but we want the out of bounds dl to not be pruned
61 // to test the intersection code inside layer::Diff/ComputeDamage
62 // damage = DiffLayerTree(t2, t1, DlIRect(), 0, 0);
63
64 DiffContext dc(frame_size, t2.paint_region_map(), t1.paint_region_map(), true,
65 false);
66 t2.root()->Diff(&dc, t1.root());
67 auto damage = dc.ComputeDamage(DlIRect(), 0, 0);
68 EXPECT_EQ(damage.frame_damage, DlIRect());
69 EXPECT_EQ(damage.buffer_damage, DlIRect());
70}
71
72} // namespace testing
73} // namespace flutter
virtual void Add(std::shared_ptr< Layer > layer)
void Diff(DiffContext *context, const Layer *old_layer) override
Damage ComputeDamage(const DlIRect &additional_damage, int horizontal_clip_alignment=0, int vertical_clip_alignment=0) const
TEST_F(DisplayListTest, Defaults)
impeller::ISize32 DlISize
impeller::IRect32 DlIRect
static constexpr TRect MakeSize(const TSize< U > &size)
Definition rect.h:150
static constexpr TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
Definition rect.h:129