Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(375)

Side by Side Diff: cc/layers/effect_tree_layer_list_iterator_unittest.cc

Issue 2751783002: cc: Replace LayerIterator with iterator that walks layer list and effect tree (Closed)
Patch Set: Clean up #includes Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/layers/layer_iterator.h" 5 #include "cc/layers/effect_tree_layer_list_iterator.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "cc/layers/layer.h" 10 #include "cc/layers/layer.h"
11 #include "cc/test/fake_layer_tree_host.h" 11 #include "cc/test/fake_layer_tree_host.h"
12 #include "cc/test/test_task_graph_runner.h" 12 #include "cc/test/test_task_graph_runner.h"
13 #include "cc/trees/layer_tree_host_common.h" 13 #include "cc/trees/layer_tree_host_common.h"
14 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "ui/gfx/transform.h" 16 #include "ui/gfx/transform.h"
17 17
18 using ::testing::Mock;
19 using ::testing::_;
20 using ::testing::AtLeast;
21 using ::testing::AnyNumber;
22
23 namespace cc { 18 namespace cc {
24 namespace { 19 namespace {
25 20
26 class TestLayerImpl : public LayerImpl { 21 class TestLayerImpl : public LayerImpl {
27 public: 22 public:
28 static std::unique_ptr<TestLayerImpl> Create(LayerTreeImpl* tree, int id) { 23 static std::unique_ptr<TestLayerImpl> Create(LayerTreeImpl* tree, int id) {
29 return base::WrapUnique(new TestLayerImpl(tree, id)); 24 return base::WrapUnique(new TestLayerImpl(tree, id));
30 } 25 }
31 ~TestLayerImpl() override {} 26 ~TestLayerImpl() override {}
32 27
33 int count_representing_target_surface_; 28 int count_;
34 int count_representing_contributing_surface_;
35 int count_representing_itself_;
36 29
37 private: 30 private:
38 explicit TestLayerImpl(LayerTreeImpl* tree, int id) 31 explicit TestLayerImpl(LayerTreeImpl* tree, int id)
39 : LayerImpl(tree, id), 32 : LayerImpl(tree, id), count_(-1) {
40 count_representing_target_surface_(-1),
41 count_representing_contributing_surface_(-1),
42 count_representing_itself_(-1) {
43 SetBounds(gfx::Size(100, 100)); 33 SetBounds(gfx::Size(100, 100));
44 SetPosition(gfx::PointF()); 34 SetPosition(gfx::PointF());
45 SetDrawsContent(true); 35 SetDrawsContent(true);
46 } 36 }
47 }; 37 };
48 38
49 #define EXPECT_COUNT(layer, target, contrib, itself) \ 39 #define EXPECT_COUNT(layer, target, contrib, itself) \
50 EXPECT_EQ(target, layer->count_representing_target_surface_); \ 40 if (layer->GetRenderSurface()) { \
51 EXPECT_EQ(contrib, layer->count_representing_contributing_surface_); \ 41 EXPECT_EQ(target, target_surface_count_[layer->effect_tree_index()]); \
52 EXPECT_EQ(itself, layer->count_representing_itself_); 42 EXPECT_EQ(contrib, \
43 contributing_surface_count_[layer->effect_tree_index()]); \
44 } \
45 EXPECT_EQ(itself, layer->count_);
53 46
54 void ResetCounts(LayerImplList* render_surface_layer_list) { 47 class EffectTreeLayerListIteratorTest : public testing::Test {
55 for (unsigned surface_index = 0;
56 surface_index < render_surface_layer_list->size();
57 ++surface_index) {
58 TestLayerImpl* render_surface_layer = static_cast<TestLayerImpl*>(
59 render_surface_layer_list->at(surface_index));
60 RenderSurfaceImpl* render_surface =
61 render_surface_layer->GetRenderSurface();
62
63 render_surface_layer->count_representing_target_surface_ = -1;
64 render_surface_layer->count_representing_contributing_surface_ = -1;
65 render_surface_layer->count_representing_itself_ = -1;
66
67 for (unsigned layer_index = 0;
68 layer_index < render_surface->layer_list().size();
69 ++layer_index) {
70 TestLayerImpl* layer = static_cast<TestLayerImpl*>(
71 render_surface->layer_list()[layer_index]);
72
73 layer->count_representing_target_surface_ = -1;
74 layer->count_representing_contributing_surface_ = -1;
75 layer->count_representing_itself_ = -1;
76 }
77 }
78 }
79
80 void IterateFrontToBack(LayerImplList* render_surface_layer_list) {
81 ResetCounts(render_surface_layer_list);
82 int count = 0;
83 for (LayerIterator it = LayerIterator::Begin(render_surface_layer_list);
84 it != LayerIterator::End(render_surface_layer_list); ++it, ++count) {
85 TestLayerImpl* layer = static_cast<TestLayerImpl*>(*it);
86 if (it.represents_target_render_surface())
87 layer->count_representing_target_surface_ = count;
88 if (it.represents_contributing_render_surface())
89 layer->count_representing_contributing_surface_ = count;
90 if (it.represents_itself())
91 layer->count_representing_itself_ = count;
92 }
93 }
94
95 class LayerIteratorTest : public testing::Test {
96 public: 48 public:
97 LayerIteratorTest() 49 EffectTreeLayerListIteratorTest()
98 : host_impl_(&task_runner_provider_, &task_graph_runner_), id_(1) {} 50 : host_impl_(&task_runner_provider_, &task_graph_runner_), id_(1) {}
99 51
100 std::unique_ptr<TestLayerImpl> CreateLayer() { 52 std::unique_ptr<TestLayerImpl> CreateLayer() {
101 return TestLayerImpl::Create(host_impl_.active_tree(), id_++); 53 return TestLayerImpl::Create(host_impl_.active_tree(), id_++);
102 } 54 }
103 55
56 void IterateFrontToBack() {
57 ResetCounts();
58 int count = 0;
59 for (EffectTreeLayerListIterator it(host_impl_.active_tree());
60 it.state() != EffectTreeLayerListIterator::State::END; ++it, ++count) {
61 switch (it.state()) {
62 case EffectTreeLayerListIterator::State::LAYER:
63 static_cast<TestLayerImpl*>(it.current_layer())->count_ = count;
64 break;
65 case EffectTreeLayerListIterator::State::TARGET_SURFACE:
66 target_surface_count_[it.target_render_surface()->EffectTreeIndex()] =
67 count;
68 break;
69 case EffectTreeLayerListIterator::State::CONTRIBUTING_SURFACE:
70 contributing_surface_count_[it.current_render_surface()
71 ->EffectTreeIndex()] = count;
72 break;
73 default:
74 NOTREACHED();
75 }
76 }
77 }
78
79 void ResetCounts() {
80 for (LayerImpl* layer : *host_impl_.active_tree()) {
81 static_cast<TestLayerImpl*>(layer)->count_ = -1;
82 }
83
84 target_surface_count_ = std::vector<int>(
85 host_impl_.active_tree()->property_trees()->effect_tree.size(), -1);
86 contributing_surface_count_ = std::vector<int>(
87 host_impl_.active_tree()->property_trees()->effect_tree.size(), -1);
88 }
89
104 protected: 90 protected:
105 FakeImplTaskRunnerProvider task_runner_provider_; 91 FakeImplTaskRunnerProvider task_runner_provider_;
106 TestTaskGraphRunner task_graph_runner_; 92 TestTaskGraphRunner task_graph_runner_;
107 FakeLayerTreeHostImpl host_impl_; 93 FakeLayerTreeHostImpl host_impl_;
108 94
109 int id_; 95 int id_;
96
97 // Tracks when each render surface is visited as a target surface or
98 // contributing surface. Indexed by effect node id.
99 std::vector<int> target_surface_count_;
100 std::vector<int> contributing_surface_count_;
110 }; 101 };
111 102
112 TEST_F(LayerIteratorTest, EmptyTree) { 103 TEST_F(EffectTreeLayerListIteratorTest, EmptyTree) {
113 LayerImplList render_surface_layer_list; 104 IterateFrontToBack();
114
115 IterateFrontToBack(&render_surface_layer_list);
116 } 105 }
117 106
118 TEST_F(LayerIteratorTest, SimpleTree) { 107 TEST_F(EffectTreeLayerListIteratorTest, SimpleTree) {
119 std::unique_ptr<TestLayerImpl> root_layer = CreateLayer(); 108 std::unique_ptr<TestLayerImpl> root_layer = CreateLayer();
120 std::unique_ptr<TestLayerImpl> first = CreateLayer(); 109 std::unique_ptr<TestLayerImpl> first = CreateLayer();
121 std::unique_ptr<TestLayerImpl> second = CreateLayer(); 110 std::unique_ptr<TestLayerImpl> second = CreateLayer();
122 std::unique_ptr<TestLayerImpl> third = CreateLayer(); 111 std::unique_ptr<TestLayerImpl> third = CreateLayer();
123 std::unique_ptr<TestLayerImpl> fourth = CreateLayer(); 112 std::unique_ptr<TestLayerImpl> fourth = CreateLayer();
124 113
125 TestLayerImpl* root_ptr = root_layer.get(); 114 TestLayerImpl* root_ptr = root_layer.get();
126 TestLayerImpl* first_ptr = first.get(); 115 TestLayerImpl* first_ptr = first.get();
127 TestLayerImpl* second_ptr = second.get(); 116 TestLayerImpl* second_ptr = second.get();
128 TestLayerImpl* third_ptr = third.get(); 117 TestLayerImpl* third_ptr = third.get();
129 TestLayerImpl* fourth_ptr = fourth.get(); 118 TestLayerImpl* fourth_ptr = fourth.get();
130 119
131 root_layer->test_properties()->AddChild(std::move(first)); 120 root_layer->test_properties()->AddChild(std::move(first));
132 root_layer->test_properties()->AddChild(std::move(second)); 121 root_layer->test_properties()->AddChild(std::move(second));
133 root_layer->test_properties()->AddChild(std::move(third)); 122 root_layer->test_properties()->AddChild(std::move(third));
134 root_layer->test_properties()->AddChild(std::move(fourth)); 123 root_layer->test_properties()->AddChild(std::move(fourth));
135 124
136 host_impl_.active_tree()->SetRootLayerForTesting(std::move(root_layer)); 125 host_impl_.active_tree()->SetRootLayerForTesting(std::move(root_layer));
137 126
138 LayerImplList render_surface_layer_list; 127 LayerImplList render_surface_layer_list;
139 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( 128 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
140 root_ptr, root_ptr->bounds(), &render_surface_layer_list); 129 root_ptr, root_ptr->bounds(), &render_surface_layer_list);
141 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); 130 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
142 131
143 IterateFrontToBack(&render_surface_layer_list); 132 IterateFrontToBack();
144 EXPECT_COUNT(root_ptr, 5, -1, 4); 133 EXPECT_COUNT(root_ptr, 5, -1, 4);
145 EXPECT_COUNT(first_ptr, -1, -1, 3); 134 EXPECT_COUNT(first_ptr, -1, -1, 3);
146 EXPECT_COUNT(second_ptr, -1, -1, 2); 135 EXPECT_COUNT(second_ptr, -1, -1, 2);
147 EXPECT_COUNT(third_ptr, -1, -1, 1); 136 EXPECT_COUNT(third_ptr, -1, -1, 1);
148 EXPECT_COUNT(fourth_ptr, -1, -1, 0); 137 EXPECT_COUNT(fourth_ptr, -1, -1, 0);
149 } 138 }
150 139
151 TEST_F(LayerIteratorTest, ComplexTree) { 140 TEST_F(EffectTreeLayerListIteratorTest, ComplexTree) {
152 std::unique_ptr<TestLayerImpl> root_layer = CreateLayer(); 141 std::unique_ptr<TestLayerImpl> root_layer = CreateLayer();
153 std::unique_ptr<TestLayerImpl> root1 = CreateLayer(); 142 std::unique_ptr<TestLayerImpl> root1 = CreateLayer();
154 std::unique_ptr<TestLayerImpl> root2 = CreateLayer(); 143 std::unique_ptr<TestLayerImpl> root2 = CreateLayer();
155 std::unique_ptr<TestLayerImpl> root3 = CreateLayer(); 144 std::unique_ptr<TestLayerImpl> root3 = CreateLayer();
156 std::unique_ptr<TestLayerImpl> root21 = CreateLayer(); 145 std::unique_ptr<TestLayerImpl> root21 = CreateLayer();
157 std::unique_ptr<TestLayerImpl> root22 = CreateLayer(); 146 std::unique_ptr<TestLayerImpl> root22 = CreateLayer();
158 std::unique_ptr<TestLayerImpl> root23 = CreateLayer(); 147 std::unique_ptr<TestLayerImpl> root23 = CreateLayer();
159 std::unique_ptr<TestLayerImpl> root221 = CreateLayer(); 148 std::unique_ptr<TestLayerImpl> root221 = CreateLayer();
160 std::unique_ptr<TestLayerImpl> root231 = CreateLayer(); 149 std::unique_ptr<TestLayerImpl> root231 = CreateLayer();
161 150
(...skipping 16 matching lines...) Expand all
178 root_layer->test_properties()->AddChild(std::move(root2)); 167 root_layer->test_properties()->AddChild(std::move(root2));
179 root_layer->test_properties()->AddChild(std::move(root3)); 168 root_layer->test_properties()->AddChild(std::move(root3));
180 169
181 host_impl_.active_tree()->SetRootLayerForTesting(std::move(root_layer)); 170 host_impl_.active_tree()->SetRootLayerForTesting(std::move(root_layer));
182 171
183 LayerImplList render_surface_layer_list; 172 LayerImplList render_surface_layer_list;
184 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( 173 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
185 root_ptr, root_ptr->bounds(), &render_surface_layer_list); 174 root_ptr, root_ptr->bounds(), &render_surface_layer_list);
186 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); 175 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
187 176
188 IterateFrontToBack(&render_surface_layer_list); 177 IterateFrontToBack();
189 EXPECT_COUNT(root_ptr, 9, -1, 8); 178 EXPECT_COUNT(root_ptr, 9, -1, 8);
190 EXPECT_COUNT(root1_ptr, -1, -1, 7); 179 EXPECT_COUNT(root1_ptr, -1, -1, 7);
191 EXPECT_COUNT(root2_ptr, -1, -1, 6); 180 EXPECT_COUNT(root2_ptr, -1, -1, 6);
192 EXPECT_COUNT(root21_ptr, -1, -1, 5); 181 EXPECT_COUNT(root21_ptr, -1, -1, 5);
193 EXPECT_COUNT(root22_ptr, -1, -1, 4); 182 EXPECT_COUNT(root22_ptr, -1, -1, 4);
194 EXPECT_COUNT(root221_ptr, -1, -1, 3); 183 EXPECT_COUNT(root221_ptr, -1, -1, 3);
195 EXPECT_COUNT(root23_ptr, -1, -1, 2); 184 EXPECT_COUNT(root23_ptr, -1, -1, 2);
196 EXPECT_COUNT(root231_ptr, -1, -1, 1); 185 EXPECT_COUNT(root231_ptr, -1, -1, 1);
197 EXPECT_COUNT(root3_ptr, -1, -1, 0); 186 EXPECT_COUNT(root3_ptr, -1, -1, 0);
198 } 187 }
199 188
200 TEST_F(LayerIteratorTest, ComplexTreeMultiSurface) { 189 TEST_F(EffectTreeLayerListIteratorTest, ComplexTreeMultiSurface) {
201 std::unique_ptr<TestLayerImpl> root_layer = CreateLayer(); 190 std::unique_ptr<TestLayerImpl> root_layer = CreateLayer();
202 std::unique_ptr<TestLayerImpl> root1 = CreateLayer(); 191 std::unique_ptr<TestLayerImpl> root1 = CreateLayer();
203 std::unique_ptr<TestLayerImpl> root2 = CreateLayer(); 192 std::unique_ptr<TestLayerImpl> root2 = CreateLayer();
204 std::unique_ptr<TestLayerImpl> root3 = CreateLayer(); 193 std::unique_ptr<TestLayerImpl> root3 = CreateLayer();
205 std::unique_ptr<TestLayerImpl> root21 = CreateLayer(); 194 std::unique_ptr<TestLayerImpl> root21 = CreateLayer();
206 std::unique_ptr<TestLayerImpl> root22 = CreateLayer(); 195 std::unique_ptr<TestLayerImpl> root22 = CreateLayer();
207 std::unique_ptr<TestLayerImpl> root23 = CreateLayer(); 196 std::unique_ptr<TestLayerImpl> root23 = CreateLayer();
208 std::unique_ptr<TestLayerImpl> root221 = CreateLayer(); 197 std::unique_ptr<TestLayerImpl> root221 = CreateLayer();
209 std::unique_ptr<TestLayerImpl> root231 = CreateLayer(); 198 std::unique_ptr<TestLayerImpl> root231 = CreateLayer();
210 199
(...skipping 20 matching lines...) Expand all
231 root_layer->test_properties()->AddChild(std::move(root2)); 220 root_layer->test_properties()->AddChild(std::move(root2));
232 root_layer->test_properties()->AddChild(std::move(root3)); 221 root_layer->test_properties()->AddChild(std::move(root3));
233 222
234 host_impl_.active_tree()->SetRootLayerForTesting(std::move(root_layer)); 223 host_impl_.active_tree()->SetRootLayerForTesting(std::move(root_layer));
235 224
236 LayerImplList render_surface_layer_list; 225 LayerImplList render_surface_layer_list;
237 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( 226 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
238 root_ptr, root_ptr->bounds(), &render_surface_layer_list); 227 root_ptr, root_ptr->bounds(), &render_surface_layer_list);
239 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); 228 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
240 229
241 IterateFrontToBack(&render_surface_layer_list); 230 IterateFrontToBack();
242 EXPECT_COUNT(root_ptr, 14, -1, 13); 231 EXPECT_COUNT(root_ptr, 14, -1, 13);
243 EXPECT_COUNT(root1_ptr, -1, -1, 12); 232 EXPECT_COUNT(root1_ptr, -1, -1, 12);
244 EXPECT_COUNT(root2_ptr, 10, 11, -1); 233 EXPECT_COUNT(root2_ptr, 10, 11, -1);
245 EXPECT_COUNT(root21_ptr, -1, -1, 9); 234 EXPECT_COUNT(root21_ptr, -1, -1, 9);
246 EXPECT_COUNT(root22_ptr, 7, 8, 6); 235 EXPECT_COUNT(root22_ptr, 7, 8, 6);
247 EXPECT_COUNT(root221_ptr, -1, -1, 5); 236 EXPECT_COUNT(root221_ptr, -1, -1, 5);
248 EXPECT_COUNT(root23_ptr, 3, 4, 2); 237 EXPECT_COUNT(root23_ptr, 3, 4, 2);
249 EXPECT_COUNT(root231_ptr, -1, -1, 1); 238 EXPECT_COUNT(root231_ptr, -1, -1, 1);
250 EXPECT_COUNT(root3_ptr, -1, -1, 0); 239 EXPECT_COUNT(root3_ptr, -1, -1, 0);
251 } 240 }
252 241
253 } // namespace 242 } // namespace
254 } // namespace cc 243 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698