OLD | NEW |
| (Empty) |
1 // Copyright 2012 The Chromium 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 | |
5 #include "cc/layers/layer_iterator.h" | |
6 | |
7 #include <vector> | |
8 | |
9 #include "base/memory/ptr_util.h" | |
10 #include "cc/layers/layer.h" | |
11 #include "cc/test/fake_layer_tree_host.h" | |
12 #include "cc/test/test_task_graph_runner.h" | |
13 #include "cc/trees/layer_tree_host_common.h" | |
14 #include "testing/gmock/include/gmock/gmock.h" | |
15 #include "testing/gtest/include/gtest/gtest.h" | |
16 #include "ui/gfx/transform.h" | |
17 | |
18 using ::testing::Mock; | |
19 using ::testing::_; | |
20 using ::testing::AtLeast; | |
21 using ::testing::AnyNumber; | |
22 | |
23 namespace cc { | |
24 namespace { | |
25 | |
26 class TestLayerImpl : public LayerImpl { | |
27 public: | |
28 static std::unique_ptr<TestLayerImpl> Create(LayerTreeImpl* tree, int id) { | |
29 return base::WrapUnique(new TestLayerImpl(tree, id)); | |
30 } | |
31 ~TestLayerImpl() override {} | |
32 | |
33 int count_representing_target_surface_; | |
34 int count_representing_contributing_surface_; | |
35 int count_representing_itself_; | |
36 | |
37 private: | |
38 explicit TestLayerImpl(LayerTreeImpl* tree, int id) | |
39 : LayerImpl(tree, id), | |
40 count_representing_target_surface_(-1), | |
41 count_representing_contributing_surface_(-1), | |
42 count_representing_itself_(-1) { | |
43 SetBounds(gfx::Size(100, 100)); | |
44 SetPosition(gfx::PointF()); | |
45 SetDrawsContent(true); | |
46 } | |
47 }; | |
48 | |
49 #define EXPECT_COUNT(layer, target, contrib, itself) \ | |
50 EXPECT_EQ(target, layer->count_representing_target_surface_); \ | |
51 EXPECT_EQ(contrib, layer->count_representing_contributing_surface_); \ | |
52 EXPECT_EQ(itself, layer->count_representing_itself_); | |
53 | |
54 void ResetCounts(LayerImplList* render_surface_layer_list) { | |
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: | |
97 LayerIteratorTest() | |
98 : host_impl_(&task_runner_provider_, &task_graph_runner_), id_(1) {} | |
99 | |
100 std::unique_ptr<TestLayerImpl> CreateLayer() { | |
101 return TestLayerImpl::Create(host_impl_.active_tree(), id_++); | |
102 } | |
103 | |
104 protected: | |
105 FakeImplTaskRunnerProvider task_runner_provider_; | |
106 TestTaskGraphRunner task_graph_runner_; | |
107 FakeLayerTreeHostImpl host_impl_; | |
108 | |
109 int id_; | |
110 }; | |
111 | |
112 TEST_F(LayerIteratorTest, EmptyTree) { | |
113 LayerImplList render_surface_layer_list; | |
114 | |
115 IterateFrontToBack(&render_surface_layer_list); | |
116 } | |
117 | |
118 TEST_F(LayerIteratorTest, SimpleTree) { | |
119 std::unique_ptr<TestLayerImpl> root_layer = CreateLayer(); | |
120 std::unique_ptr<TestLayerImpl> first = CreateLayer(); | |
121 std::unique_ptr<TestLayerImpl> second = CreateLayer(); | |
122 std::unique_ptr<TestLayerImpl> third = CreateLayer(); | |
123 std::unique_ptr<TestLayerImpl> fourth = CreateLayer(); | |
124 | |
125 TestLayerImpl* root_ptr = root_layer.get(); | |
126 TestLayerImpl* first_ptr = first.get(); | |
127 TestLayerImpl* second_ptr = second.get(); | |
128 TestLayerImpl* third_ptr = third.get(); | |
129 TestLayerImpl* fourth_ptr = fourth.get(); | |
130 | |
131 root_layer->test_properties()->AddChild(std::move(first)); | |
132 root_layer->test_properties()->AddChild(std::move(second)); | |
133 root_layer->test_properties()->AddChild(std::move(third)); | |
134 root_layer->test_properties()->AddChild(std::move(fourth)); | |
135 | |
136 host_impl_.active_tree()->SetRootLayerForTesting(std::move(root_layer)); | |
137 | |
138 LayerImplList render_surface_layer_list; | |
139 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( | |
140 root_ptr, root_ptr->bounds(), &render_surface_layer_list); | |
141 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); | |
142 | |
143 IterateFrontToBack(&render_surface_layer_list); | |
144 EXPECT_COUNT(root_ptr, 5, -1, 4); | |
145 EXPECT_COUNT(first_ptr, -1, -1, 3); | |
146 EXPECT_COUNT(second_ptr, -1, -1, 2); | |
147 EXPECT_COUNT(third_ptr, -1, -1, 1); | |
148 EXPECT_COUNT(fourth_ptr, -1, -1, 0); | |
149 } | |
150 | |
151 TEST_F(LayerIteratorTest, ComplexTree) { | |
152 std::unique_ptr<TestLayerImpl> root_layer = CreateLayer(); | |
153 std::unique_ptr<TestLayerImpl> root1 = CreateLayer(); | |
154 std::unique_ptr<TestLayerImpl> root2 = CreateLayer(); | |
155 std::unique_ptr<TestLayerImpl> root3 = CreateLayer(); | |
156 std::unique_ptr<TestLayerImpl> root21 = CreateLayer(); | |
157 std::unique_ptr<TestLayerImpl> root22 = CreateLayer(); | |
158 std::unique_ptr<TestLayerImpl> root23 = CreateLayer(); | |
159 std::unique_ptr<TestLayerImpl> root221 = CreateLayer(); | |
160 std::unique_ptr<TestLayerImpl> root231 = CreateLayer(); | |
161 | |
162 TestLayerImpl* root_ptr = root_layer.get(); | |
163 TestLayerImpl* root1_ptr = root1.get(); | |
164 TestLayerImpl* root2_ptr = root2.get(); | |
165 TestLayerImpl* root3_ptr = root3.get(); | |
166 TestLayerImpl* root21_ptr = root21.get(); | |
167 TestLayerImpl* root22_ptr = root22.get(); | |
168 TestLayerImpl* root23_ptr = root23.get(); | |
169 TestLayerImpl* root221_ptr = root221.get(); | |
170 TestLayerImpl* root231_ptr = root231.get(); | |
171 | |
172 root22->test_properties()->AddChild(std::move(root221)); | |
173 root23->test_properties()->AddChild(std::move(root231)); | |
174 root2->test_properties()->AddChild(std::move(root21)); | |
175 root2->test_properties()->AddChild(std::move(root22)); | |
176 root2->test_properties()->AddChild(std::move(root23)); | |
177 root_layer->test_properties()->AddChild(std::move(root1)); | |
178 root_layer->test_properties()->AddChild(std::move(root2)); | |
179 root_layer->test_properties()->AddChild(std::move(root3)); | |
180 | |
181 host_impl_.active_tree()->SetRootLayerForTesting(std::move(root_layer)); | |
182 | |
183 LayerImplList render_surface_layer_list; | |
184 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( | |
185 root_ptr, root_ptr->bounds(), &render_surface_layer_list); | |
186 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); | |
187 | |
188 IterateFrontToBack(&render_surface_layer_list); | |
189 EXPECT_COUNT(root_ptr, 9, -1, 8); | |
190 EXPECT_COUNT(root1_ptr, -1, -1, 7); | |
191 EXPECT_COUNT(root2_ptr, -1, -1, 6); | |
192 EXPECT_COUNT(root21_ptr, -1, -1, 5); | |
193 EXPECT_COUNT(root22_ptr, -1, -1, 4); | |
194 EXPECT_COUNT(root221_ptr, -1, -1, 3); | |
195 EXPECT_COUNT(root23_ptr, -1, -1, 2); | |
196 EXPECT_COUNT(root231_ptr, -1, -1, 1); | |
197 EXPECT_COUNT(root3_ptr, -1, -1, 0); | |
198 } | |
199 | |
200 TEST_F(LayerIteratorTest, ComplexTreeMultiSurface) { | |
201 std::unique_ptr<TestLayerImpl> root_layer = CreateLayer(); | |
202 std::unique_ptr<TestLayerImpl> root1 = CreateLayer(); | |
203 std::unique_ptr<TestLayerImpl> root2 = CreateLayer(); | |
204 std::unique_ptr<TestLayerImpl> root3 = CreateLayer(); | |
205 std::unique_ptr<TestLayerImpl> root21 = CreateLayer(); | |
206 std::unique_ptr<TestLayerImpl> root22 = CreateLayer(); | |
207 std::unique_ptr<TestLayerImpl> root23 = CreateLayer(); | |
208 std::unique_ptr<TestLayerImpl> root221 = CreateLayer(); | |
209 std::unique_ptr<TestLayerImpl> root231 = CreateLayer(); | |
210 | |
211 TestLayerImpl* root_ptr = root_layer.get(); | |
212 TestLayerImpl* root1_ptr = root1.get(); | |
213 TestLayerImpl* root2_ptr = root2.get(); | |
214 TestLayerImpl* root3_ptr = root3.get(); | |
215 TestLayerImpl* root21_ptr = root21.get(); | |
216 TestLayerImpl* root22_ptr = root22.get(); | |
217 TestLayerImpl* root23_ptr = root23.get(); | |
218 TestLayerImpl* root221_ptr = root221.get(); | |
219 TestLayerImpl* root231_ptr = root231.get(); | |
220 | |
221 root22->test_properties()->force_render_surface = true; | |
222 root23->test_properties()->force_render_surface = true; | |
223 root2->test_properties()->force_render_surface = true; | |
224 root22->test_properties()->AddChild(std::move(root221)); | |
225 root23->test_properties()->AddChild(std::move(root231)); | |
226 root2->SetDrawsContent(false); | |
227 root2->test_properties()->AddChild(std::move(root21)); | |
228 root2->test_properties()->AddChild(std::move(root22)); | |
229 root2->test_properties()->AddChild(std::move(root23)); | |
230 root_layer->test_properties()->AddChild(std::move(root1)); | |
231 root_layer->test_properties()->AddChild(std::move(root2)); | |
232 root_layer->test_properties()->AddChild(std::move(root3)); | |
233 | |
234 host_impl_.active_tree()->SetRootLayerForTesting(std::move(root_layer)); | |
235 | |
236 LayerImplList render_surface_layer_list; | |
237 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( | |
238 root_ptr, root_ptr->bounds(), &render_surface_layer_list); | |
239 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); | |
240 | |
241 IterateFrontToBack(&render_surface_layer_list); | |
242 EXPECT_COUNT(root_ptr, 14, -1, 13); | |
243 EXPECT_COUNT(root1_ptr, -1, -1, 12); | |
244 EXPECT_COUNT(root2_ptr, 10, 11, -1); | |
245 EXPECT_COUNT(root21_ptr, -1, -1, 9); | |
246 EXPECT_COUNT(root22_ptr, 7, 8, 6); | |
247 EXPECT_COUNT(root221_ptr, -1, -1, 5); | |
248 EXPECT_COUNT(root23_ptr, 3, 4, 2); | |
249 EXPECT_COUNT(root231_ptr, -1, -1, 1); | |
250 EXPECT_COUNT(root3_ptr, -1, -1, 0); | |
251 } | |
252 | |
253 } // namespace | |
254 } // namespace cc | |
OLD | NEW |