OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 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/layer_iterator.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "cc/layers/layer.h" | 9 #include "cc/layers/layer.h" |
10 #include "cc/trees/layer_tree_host_common.h" | 10 #include "cc/trees/layer_tree_host_common.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 | 43 |
44 bool draws_content_; | 44 bool draws_content_; |
45 }; | 45 }; |
46 | 46 |
47 #define EXPECT_COUNT(layer, target, contrib, itself) \ | 47 #define EXPECT_COUNT(layer, target, contrib, itself) \ |
48 EXPECT_EQ(target, layer->count_representing_target_surface_); \ | 48 EXPECT_EQ(target, layer->count_representing_target_surface_); \ |
49 EXPECT_EQ(contrib, layer->count_representing_contributing_surface_); \ | 49 EXPECT_EQ(contrib, layer->count_representing_contributing_surface_); \ |
50 EXPECT_EQ(itself, layer->count_representing_itself_); | 50 EXPECT_EQ(itself, layer->count_representing_itself_); |
51 | 51 |
52 typedef LayerIterator<Layer, | 52 typedef LayerIterator<Layer, |
53 std::vector<scoped_refptr<Layer> >, | 53 LayerList, |
54 RenderSurface, | 54 RenderSurface, |
55 LayerIteratorActions::FrontToBack> FrontToBack; | 55 LayerIteratorActions::FrontToBack> FrontToBack; |
56 typedef LayerIterator<Layer, | 56 typedef LayerIterator<Layer, |
57 std::vector<scoped_refptr<Layer> >, | 57 LayerList, |
58 RenderSurface, | 58 RenderSurface, |
59 LayerIteratorActions::BackToFront> BackToFront; | 59 LayerIteratorActions::BackToFront> BackToFront; |
60 | 60 |
61 void ResetCounts(std::vector<scoped_refptr<Layer> >* render_surface_layerList) { | 61 void ResetCounts(LayerList* render_surface_layerList) { |
62 for (unsigned surface_index = 0; | 62 for (unsigned surface_index = 0; |
63 surface_index < render_surface_layerList->size(); | 63 surface_index < render_surface_layerList->size(); |
64 ++surface_index) { | 64 ++surface_index) { |
65 TestLayer* render_surface_layer = static_cast<TestLayer*>( | 65 TestLayer* render_surface_layer = static_cast<TestLayer*>( |
66 (*render_surface_layerList)[surface_index].get()); | 66 (*render_surface_layerList)[surface_index].get()); |
67 RenderSurface* render_surface = render_surface_layer->render_surface(); | 67 RenderSurface* render_surface = render_surface_layer->render_surface(); |
68 | 68 |
69 render_surface_layer->count_representing_target_surface_ = -1; | 69 render_surface_layer->count_representing_target_surface_ = -1; |
70 render_surface_layer->count_representing_contributing_surface_ = -1; | 70 render_surface_layer->count_representing_contributing_surface_ = -1; |
71 render_surface_layer->count_representing_itself_ = -1; | 71 render_surface_layer->count_representing_itself_ = -1; |
72 | 72 |
73 for (unsigned layer_index = 0; | 73 for (unsigned layer_index = 0; |
74 layer_index < render_surface->layer_list().size(); | 74 layer_index < render_surface->layer_list().size(); |
75 ++layer_index) { | 75 ++layer_index) { |
76 TestLayer* layer = static_cast<TestLayer*>( | 76 TestLayer* layer = static_cast<TestLayer*>( |
77 render_surface->layer_list()[layer_index].get()); | 77 render_surface->layer_list()[layer_index].get()); |
78 | 78 |
79 layer->count_representing_target_surface_ = -1; | 79 layer->count_representing_target_surface_ = -1; |
80 layer->count_representing_contributing_surface_ = -1; | 80 layer->count_representing_contributing_surface_ = -1; |
81 layer->count_representing_itself_ = -1; | 81 layer->count_representing_itself_ = -1; |
82 } | 82 } |
83 } | 83 } |
84 } | 84 } |
85 | 85 |
86 void IterateFrontToBack( | 86 void IterateFrontToBack( |
87 std::vector<scoped_refptr<Layer> >* render_surface_layerList) { | 87 LayerList* render_surface_layerList) { |
88 ResetCounts(render_surface_layerList); | 88 ResetCounts(render_surface_layerList); |
89 int count = 0; | 89 int count = 0; |
90 for (FrontToBack it = FrontToBack::Begin(render_surface_layerList); | 90 for (FrontToBack it = FrontToBack::Begin(render_surface_layerList); |
91 it != FrontToBack::End(render_surface_layerList); | 91 it != FrontToBack::End(render_surface_layerList); |
92 ++it, ++count) { | 92 ++it, ++count) { |
93 TestLayer* layer = static_cast<TestLayer*>(*it); | 93 TestLayer* layer = static_cast<TestLayer*>(*it); |
94 if (it.represents_target_render_surface()) | 94 if (it.represents_target_render_surface()) |
95 layer->count_representing_target_surface_ = count; | 95 layer->count_representing_target_surface_ = count; |
96 if (it.represents_contributing_render_surface()) | 96 if (it.represents_contributing_render_surface()) |
97 layer->count_representing_contributing_surface_ = count; | 97 layer->count_representing_contributing_surface_ = count; |
98 if (it.represents_itself()) | 98 if (it.represents_itself()) |
99 layer->count_representing_itself_ = count; | 99 layer->count_representing_itself_ = count; |
100 } | 100 } |
101 } | 101 } |
102 | 102 |
103 void IterateBackToFront( | 103 void IterateBackToFront( |
104 std::vector<scoped_refptr<Layer> >* render_surface_layerList) { | 104 LayerList* render_surface_layerList) { |
105 ResetCounts(render_surface_layerList); | 105 ResetCounts(render_surface_layerList); |
106 int count = 0; | 106 int count = 0; |
107 for (BackToFront it = BackToFront::Begin(render_surface_layerList); | 107 for (BackToFront it = BackToFront::Begin(render_surface_layerList); |
108 it != BackToFront::End(render_surface_layerList); | 108 it != BackToFront::End(render_surface_layerList); |
109 ++it, ++count) { | 109 ++it, ++count) { |
110 TestLayer* layer = static_cast<TestLayer*>(*it); | 110 TestLayer* layer = static_cast<TestLayer*>(*it); |
111 if (it.represents_target_render_surface()) | 111 if (it.represents_target_render_surface()) |
112 layer->count_representing_target_surface_ = count; | 112 layer->count_representing_target_surface_ = count; |
113 if (it.represents_contributing_render_surface()) | 113 if (it.represents_contributing_render_surface()) |
114 layer->count_representing_contributing_surface_ = count; | 114 layer->count_representing_contributing_surface_ = count; |
115 if (it.represents_itself()) | 115 if (it.represents_itself()) |
116 layer->count_representing_itself_ = count; | 116 layer->count_representing_itself_ = count; |
117 } | 117 } |
118 } | 118 } |
119 | 119 |
120 TEST(LayerIteratorTest, EmptyTree) { | 120 TEST(LayerIteratorTest, EmptyTree) { |
121 std::vector<scoped_refptr<Layer> > render_surface_layerList; | 121 LayerList render_surface_layerList; |
122 | 122 |
123 IterateBackToFront(&render_surface_layerList); | 123 IterateBackToFront(&render_surface_layerList); |
124 IterateFrontToBack(&render_surface_layerList); | 124 IterateFrontToBack(&render_surface_layerList); |
125 } | 125 } |
126 | 126 |
127 TEST(LayerIteratorTest, SimpleTree) { | 127 TEST(LayerIteratorTest, SimpleTree) { |
128 scoped_refptr<TestLayer> root_layer = TestLayer::Create(); | 128 scoped_refptr<TestLayer> root_layer = TestLayer::Create(); |
129 scoped_refptr<TestLayer> first = TestLayer::Create(); | 129 scoped_refptr<TestLayer> first = TestLayer::Create(); |
130 scoped_refptr<TestLayer> second = TestLayer::Create(); | 130 scoped_refptr<TestLayer> second = TestLayer::Create(); |
131 scoped_refptr<TestLayer> third = TestLayer::Create(); | 131 scoped_refptr<TestLayer> third = TestLayer::Create(); |
132 scoped_refptr<TestLayer> fourth = TestLayer::Create(); | 132 scoped_refptr<TestLayer> fourth = TestLayer::Create(); |
133 | 133 |
134 root_layer->CreateRenderSurface(); | 134 root_layer->CreateRenderSurface(); |
135 | 135 |
136 root_layer->AddChild(first); | 136 root_layer->AddChild(first); |
137 root_layer->AddChild(second); | 137 root_layer->AddChild(second); |
138 root_layer->AddChild(third); | 138 root_layer->AddChild(third); |
139 root_layer->AddChild(fourth); | 139 root_layer->AddChild(fourth); |
140 | 140 |
141 std::vector<scoped_refptr<Layer> > render_surface_layerList; | 141 LayerList render_surface_layerList; |
142 LayerTreeHostCommon::CalculateDrawProperties(root_layer.get(), | 142 LayerTreeHostCommon::CalculateDrawProperties(root_layer.get(), |
143 root_layer->bounds(), | 143 root_layer->bounds(), |
144 1, | 144 1, |
145 1, | 145 1, |
146 256, | 146 256, |
147 false, | 147 false, |
148 &render_surface_layerList); | 148 &render_surface_layerList); |
149 | 149 |
150 IterateBackToFront(&render_surface_layerList); | 150 IterateBackToFront(&render_surface_layerList); |
151 EXPECT_COUNT(root_layer, 0, -1, 1); | 151 EXPECT_COUNT(root_layer, 0, -1, 1); |
(...skipping 25 matching lines...) Expand all Loading... |
177 | 177 |
178 root_layer->AddChild(root1); | 178 root_layer->AddChild(root1); |
179 root_layer->AddChild(root2); | 179 root_layer->AddChild(root2); |
180 root_layer->AddChild(root3); | 180 root_layer->AddChild(root3); |
181 root2->AddChild(root21); | 181 root2->AddChild(root21); |
182 root2->AddChild(root22); | 182 root2->AddChild(root22); |
183 root2->AddChild(root23); | 183 root2->AddChild(root23); |
184 root22->AddChild(root221); | 184 root22->AddChild(root221); |
185 root23->AddChild(root231); | 185 root23->AddChild(root231); |
186 | 186 |
187 std::vector<scoped_refptr<Layer> > render_surface_layerList; | 187 LayerList render_surface_layerList; |
188 LayerTreeHostCommon::CalculateDrawProperties(root_layer.get(), | 188 LayerTreeHostCommon::CalculateDrawProperties(root_layer.get(), |
189 root_layer->bounds(), | 189 root_layer->bounds(), |
190 1, | 190 1, |
191 1, | 191 1, |
192 256, | 192 256, |
193 false, | 193 false, |
194 &render_surface_layerList); | 194 &render_surface_layerList); |
195 | 195 |
196 IterateBackToFront(&render_surface_layerList); | 196 IterateBackToFront(&render_surface_layerList); |
197 EXPECT_COUNT(root_layer, 0, -1, 1); | 197 EXPECT_COUNT(root_layer, 0, -1, 1); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 root2->SetOpacity(0.5f); | 238 root2->SetOpacity(0.5f); |
239 root2->SetForceRenderSurface(true); // Force the layer to own a new surface. | 239 root2->SetForceRenderSurface(true); // Force the layer to own a new surface. |
240 root2->AddChild(root21); | 240 root2->AddChild(root21); |
241 root2->AddChild(root22); | 241 root2->AddChild(root22); |
242 root2->AddChild(root23); | 242 root2->AddChild(root23); |
243 root22->SetOpacity(0.5f); | 243 root22->SetOpacity(0.5f); |
244 root22->AddChild(root221); | 244 root22->AddChild(root221); |
245 root23->SetOpacity(0.5f); | 245 root23->SetOpacity(0.5f); |
246 root23->AddChild(root231); | 246 root23->AddChild(root231); |
247 | 247 |
248 std::vector<scoped_refptr<Layer> > render_surface_layerList; | 248 LayerList render_surface_layerList; |
249 LayerTreeHostCommon::CalculateDrawProperties(root_layer.get(), | 249 LayerTreeHostCommon::CalculateDrawProperties(root_layer.get(), |
250 root_layer->bounds(), | 250 root_layer->bounds(), |
251 1, | 251 1, |
252 1, | 252 1, |
253 256, | 253 256, |
254 false, | 254 false, |
255 &render_surface_layerList); | 255 &render_surface_layerList); |
256 | 256 |
257 IterateBackToFront(&render_surface_layerList); | 257 IterateBackToFront(&render_surface_layerList); |
258 EXPECT_COUNT(root_layer, 0, -1, 1); | 258 EXPECT_COUNT(root_layer, 0, -1, 1); |
(...skipping 13 matching lines...) Expand all Loading... |
272 EXPECT_COUNT(root21, -1, -1, 9); | 272 EXPECT_COUNT(root21, -1, -1, 9); |
273 EXPECT_COUNT(root22, 7, 8, 6); | 273 EXPECT_COUNT(root22, 7, 8, 6); |
274 EXPECT_COUNT(root221, -1, -1, 5); | 274 EXPECT_COUNT(root221, -1, -1, 5); |
275 EXPECT_COUNT(root23, 3, 4, 2); | 275 EXPECT_COUNT(root23, 3, 4, 2); |
276 EXPECT_COUNT(root231, -1, -1, 1); | 276 EXPECT_COUNT(root231, -1, -1, 1); |
277 EXPECT_COUNT(root3, -1, -1, 0); | 277 EXPECT_COUNT(root3, -1, -1, 0); |
278 } | 278 } |
279 | 279 |
280 } // namespace | 280 } // namespace |
281 } // namespace cc | 281 } // namespace cc |
OLD | NEW |