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

Side by Side Diff: cc/layer_iterator_unittest.cc

Issue 12774006: cc: Chromify Layer and LayerImpl classes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: MoreAndroidCompilings Created 7 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 | Annotate | Revision Log
« no previous file with comments | « cc/layer_iterator.h ('k') | cc/layer_sorter.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/layer_iterator.h" 5 #include "cc/layer_iterator.h"
6 6
7 #include "cc/layer.h" 7 #include "cc/layer.h"
8 #include "cc/layer_tree_host_common.h" 8 #include "cc/layer_tree_host_common.h"
9 #include "testing/gmock/include/gmock/gmock.h" 9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "ui/gfx/transform.h" 11 #include "ui/gfx/transform.h"
12 12
13 using ::testing::Mock; 13 using ::testing::Mock;
14 using ::testing::_; 14 using ::testing::_;
15 using ::testing::AtLeast; 15 using ::testing::AtLeast;
16 using ::testing::AnyNumber; 16 using ::testing::AnyNumber;
17 17
18 namespace cc { 18 namespace cc {
19 namespace { 19 namespace {
20 20
21 class TestLayer : public Layer { 21 class TestLayer : public Layer {
22 public: 22 public:
23 static scoped_refptr<TestLayer> create() { return make_scoped_refptr(new Tes tLayer()); } 23 static scoped_refptr<TestLayer> Create() { return make_scoped_refptr(new Tes tLayer()); }
24 24
25 int m_countRepresentingTargetSurface; 25 int m_countRepresentingTargetSurface;
26 int m_countRepresentingContributingSurface; 26 int m_countRepresentingContributingSurface;
27 int m_countRepresentingItself; 27 int m_countRepresentingItself;
28 28
29 virtual bool drawsContent() const OVERRIDE { return m_drawsContent; } 29 virtual bool DrawsContent() const OVERRIDE { return m_drawsContent; }
30 void setDrawsContent(bool drawsContent) { m_drawsContent = drawsContent; } 30 void setDrawsContent(bool drawsContent) { m_drawsContent = drawsContent; }
31 31
32 private: 32 private:
33 TestLayer() 33 TestLayer()
34 : Layer() 34 : Layer()
35 , m_drawsContent(true) 35 , m_drawsContent(true)
36 { 36 {
37 setBounds(gfx::Size(100, 100)); 37 SetBounds(gfx::Size(100, 100));
38 setPosition(gfx::Point()); 38 SetPosition(gfx::Point());
39 setAnchorPoint(gfx::Point()); 39 SetAnchorPoint(gfx::Point());
40 } 40 }
41 virtual ~TestLayer() 41 virtual ~TestLayer()
42 { 42 {
43 } 43 }
44 44
45 bool m_drawsContent; 45 bool m_drawsContent;
46 }; 46 };
47 47
48 #define EXPECT_COUNT(layer, target, contrib, itself) \ 48 #define EXPECT_COUNT(layer, target, contrib, itself) \
49 EXPECT_EQ(target, layer->m_countRepresentingTargetSurface); \ 49 EXPECT_EQ(target, layer->m_countRepresentingTargetSurface); \
50 EXPECT_EQ(contrib, layer->m_countRepresentingContributingSurface); \ 50 EXPECT_EQ(contrib, layer->m_countRepresentingContributingSurface); \
51 EXPECT_EQ(itself, layer->m_countRepresentingItself); 51 EXPECT_EQ(itself, layer->m_countRepresentingItself);
52 52
53 typedef LayerIterator<Layer, std::vector<scoped_refptr<Layer> >, RenderSurface, LayerIteratorActions::FrontToBack> FrontToBack; 53 typedef LayerIterator<Layer, std::vector<scoped_refptr<Layer> >, RenderSurface, LayerIteratorActions::FrontToBack> FrontToBack;
54 typedef LayerIterator<Layer, std::vector<scoped_refptr<Layer> >, RenderSurface, LayerIteratorActions::BackToFront> BackToFront; 54 typedef LayerIterator<Layer, std::vector<scoped_refptr<Layer> >, RenderSurface, LayerIteratorActions::BackToFront> BackToFront;
55 55
56 void resetCounts(std::vector<scoped_refptr<Layer> >& renderSurfaceLayerList) 56 void resetCounts(std::vector<scoped_refptr<Layer> >& renderSurfaceLayerList)
57 { 57 {
58 for (unsigned surfaceIndex = 0; surfaceIndex < renderSurfaceLayerList.size() ; ++surfaceIndex) { 58 for (unsigned surfaceIndex = 0; surfaceIndex < renderSurfaceLayerList.size() ; ++surfaceIndex) {
59 TestLayer* renderSurfaceLayer = static_cast<TestLayer*>(renderSurfaceLay erList[surfaceIndex].get()); 59 TestLayer* renderSurfaceLayer = static_cast<TestLayer*>(renderSurfaceLay erList[surfaceIndex].get());
60 RenderSurface* renderSurface = renderSurfaceLayer->renderSurface(); 60 RenderSurface* renderSurface = renderSurfaceLayer->render_surface();
61 61
62 renderSurfaceLayer->m_countRepresentingTargetSurface = -1; 62 renderSurfaceLayer->m_countRepresentingTargetSurface = -1;
63 renderSurfaceLayer->m_countRepresentingContributingSurface = -1; 63 renderSurfaceLayer->m_countRepresentingContributingSurface = -1;
64 renderSurfaceLayer->m_countRepresentingItself = -1; 64 renderSurfaceLayer->m_countRepresentingItself = -1;
65 65
66 for (unsigned layerIndex = 0; layerIndex < renderSurface->layer_list().s ize(); ++layerIndex) { 66 for (unsigned layerIndex = 0; layerIndex < renderSurface->layer_list().s ize(); ++layerIndex) {
67 TestLayer* layer = static_cast<TestLayer*>(renderSurface->layer_list ()[layerIndex].get()); 67 TestLayer* layer = static_cast<TestLayer*>(renderSurface->layer_list ()[layerIndex].get());
68 68
69 layer->m_countRepresentingTargetSurface = -1; 69 layer->m_countRepresentingTargetSurface = -1;
70 layer->m_countRepresentingContributingSurface = -1; 70 layer->m_countRepresentingContributingSurface = -1;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 TEST(LayerIteratorTest, emptyTree) 106 TEST(LayerIteratorTest, emptyTree)
107 { 107 {
108 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; 108 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
109 109
110 iterateBackToFront(&renderSurfaceLayerList); 110 iterateBackToFront(&renderSurfaceLayerList);
111 iterateFrontToBack(&renderSurfaceLayerList); 111 iterateFrontToBack(&renderSurfaceLayerList);
112 } 112 }
113 113
114 TEST(LayerIteratorTest, simpleTree) 114 TEST(LayerIteratorTest, simpleTree)
115 { 115 {
116 scoped_refptr<TestLayer> rootLayer = TestLayer::create(); 116 scoped_refptr<TestLayer> rootLayer = TestLayer::Create();
117 scoped_refptr<TestLayer> first = TestLayer::create(); 117 scoped_refptr<TestLayer> first = TestLayer::Create();
118 scoped_refptr<TestLayer> second = TestLayer::create(); 118 scoped_refptr<TestLayer> second = TestLayer::Create();
119 scoped_refptr<TestLayer> third = TestLayer::create(); 119 scoped_refptr<TestLayer> third = TestLayer::Create();
120 scoped_refptr<TestLayer> fourth = TestLayer::create(); 120 scoped_refptr<TestLayer> fourth = TestLayer::Create();
121 121
122 rootLayer->createRenderSurface(); 122 rootLayer->CreateRenderSurface();
123 123
124 rootLayer->addChild(first); 124 rootLayer->AddChild(first);
125 rootLayer->addChild(second); 125 rootLayer->AddChild(second);
126 rootLayer->addChild(third); 126 rootLayer->AddChild(third);
127 rootLayer->addChild(fourth); 127 rootLayer->AddChild(fourth);
128 128
129 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; 129 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
130 LayerTreeHostCommon::calculateDrawProperties(rootLayer.get(), rootLayer->bou nds(), 1, 1, 256, false, renderSurfaceLayerList); 130 LayerTreeHostCommon::calculateDrawProperties(rootLayer.get(), rootLayer->bou nds(), 1, 1, 256, false, renderSurfaceLayerList);
131 131
132 iterateBackToFront(&renderSurfaceLayerList); 132 iterateBackToFront(&renderSurfaceLayerList);
133 EXPECT_COUNT(rootLayer, 0, -1, 1); 133 EXPECT_COUNT(rootLayer, 0, -1, 1);
134 EXPECT_COUNT(first, -1, -1, 2); 134 EXPECT_COUNT(first, -1, -1, 2);
135 EXPECT_COUNT(second, -1, -1, 3); 135 EXPECT_COUNT(second, -1, -1, 3);
136 EXPECT_COUNT(third, -1, -1, 4); 136 EXPECT_COUNT(third, -1, -1, 4);
137 EXPECT_COUNT(fourth, -1, -1, 5); 137 EXPECT_COUNT(fourth, -1, -1, 5);
138 138
139 iterateFrontToBack(&renderSurfaceLayerList); 139 iterateFrontToBack(&renderSurfaceLayerList);
140 EXPECT_COUNT(rootLayer, 5, -1, 4); 140 EXPECT_COUNT(rootLayer, 5, -1, 4);
141 EXPECT_COUNT(first, -1, -1, 3); 141 EXPECT_COUNT(first, -1, -1, 3);
142 EXPECT_COUNT(second, -1, -1, 2); 142 EXPECT_COUNT(second, -1, -1, 2);
143 EXPECT_COUNT(third, -1, -1, 1); 143 EXPECT_COUNT(third, -1, -1, 1);
144 EXPECT_COUNT(fourth, -1, -1, 0); 144 EXPECT_COUNT(fourth, -1, -1, 0);
145 145
146 } 146 }
147 147
148 TEST(LayerIteratorTest, complexTree) 148 TEST(LayerIteratorTest, complexTree)
149 { 149 {
150 scoped_refptr<TestLayer> rootLayer = TestLayer::create(); 150 scoped_refptr<TestLayer> rootLayer = TestLayer::Create();
151 scoped_refptr<TestLayer> root1 = TestLayer::create(); 151 scoped_refptr<TestLayer> root1 = TestLayer::Create();
152 scoped_refptr<TestLayer> root2 = TestLayer::create(); 152 scoped_refptr<TestLayer> root2 = TestLayer::Create();
153 scoped_refptr<TestLayer> root3 = TestLayer::create(); 153 scoped_refptr<TestLayer> root3 = TestLayer::Create();
154 scoped_refptr<TestLayer> root21 = TestLayer::create(); 154 scoped_refptr<TestLayer> root21 = TestLayer::Create();
155 scoped_refptr<TestLayer> root22 = TestLayer::create(); 155 scoped_refptr<TestLayer> root22 = TestLayer::Create();
156 scoped_refptr<TestLayer> root23 = TestLayer::create(); 156 scoped_refptr<TestLayer> root23 = TestLayer::Create();
157 scoped_refptr<TestLayer> root221 = TestLayer::create(); 157 scoped_refptr<TestLayer> root221 = TestLayer::Create();
158 scoped_refptr<TestLayer> root231 = TestLayer::create(); 158 scoped_refptr<TestLayer> root231 = TestLayer::Create();
159 159
160 rootLayer->createRenderSurface(); 160 rootLayer->CreateRenderSurface();
161 161
162 rootLayer->addChild(root1); 162 rootLayer->AddChild(root1);
163 rootLayer->addChild(root2); 163 rootLayer->AddChild(root2);
164 rootLayer->addChild(root3); 164 rootLayer->AddChild(root3);
165 root2->addChild(root21); 165 root2->AddChild(root21);
166 root2->addChild(root22); 166 root2->AddChild(root22);
167 root2->addChild(root23); 167 root2->AddChild(root23);
168 root22->addChild(root221); 168 root22->AddChild(root221);
169 root23->addChild(root231); 169 root23->AddChild(root231);
170 170
171 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; 171 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
172 LayerTreeHostCommon::calculateDrawProperties(rootLayer.get(), rootLayer->bou nds(), 1, 1, 256, false, renderSurfaceLayerList); 172 LayerTreeHostCommon::calculateDrawProperties(rootLayer.get(), rootLayer->bou nds(), 1, 1, 256, false, renderSurfaceLayerList);
173 173
174 iterateBackToFront(&renderSurfaceLayerList); 174 iterateBackToFront(&renderSurfaceLayerList);
175 EXPECT_COUNT(rootLayer, 0, -1, 1); 175 EXPECT_COUNT(rootLayer, 0, -1, 1);
176 EXPECT_COUNT(root1, -1, -1, 2); 176 EXPECT_COUNT(root1, -1, -1, 2);
177 EXPECT_COUNT(root2, -1, -1, 3); 177 EXPECT_COUNT(root2, -1, -1, 3);
178 EXPECT_COUNT(root21, -1, -1, 4); 178 EXPECT_COUNT(root21, -1, -1, 4);
179 EXPECT_COUNT(root22, -1, -1, 5); 179 EXPECT_COUNT(root22, -1, -1, 5);
(...skipping 10 matching lines...) Expand all
190 EXPECT_COUNT(root22, -1, -1, 4); 190 EXPECT_COUNT(root22, -1, -1, 4);
191 EXPECT_COUNT(root221, -1, -1, 3); 191 EXPECT_COUNT(root221, -1, -1, 3);
192 EXPECT_COUNT(root23, -1, -1, 2); 192 EXPECT_COUNT(root23, -1, -1, 2);
193 EXPECT_COUNT(root231, -1, -1, 1); 193 EXPECT_COUNT(root231, -1, -1, 1);
194 EXPECT_COUNT(root3, -1, -1, 0); 194 EXPECT_COUNT(root3, -1, -1, 0);
195 195
196 } 196 }
197 197
198 TEST(LayerIteratorTest, complexTreeMultiSurface) 198 TEST(LayerIteratorTest, complexTreeMultiSurface)
199 { 199 {
200 scoped_refptr<TestLayer> rootLayer = TestLayer::create(); 200 scoped_refptr<TestLayer> rootLayer = TestLayer::Create();
201 scoped_refptr<TestLayer> root1 = TestLayer::create(); 201 scoped_refptr<TestLayer> root1 = TestLayer::Create();
202 scoped_refptr<TestLayer> root2 = TestLayer::create(); 202 scoped_refptr<TestLayer> root2 = TestLayer::Create();
203 scoped_refptr<TestLayer> root3 = TestLayer::create(); 203 scoped_refptr<TestLayer> root3 = TestLayer::Create();
204 scoped_refptr<TestLayer> root21 = TestLayer::create(); 204 scoped_refptr<TestLayer> root21 = TestLayer::Create();
205 scoped_refptr<TestLayer> root22 = TestLayer::create(); 205 scoped_refptr<TestLayer> root22 = TestLayer::Create();
206 scoped_refptr<TestLayer> root23 = TestLayer::create(); 206 scoped_refptr<TestLayer> root23 = TestLayer::Create();
207 scoped_refptr<TestLayer> root221 = TestLayer::create(); 207 scoped_refptr<TestLayer> root221 = TestLayer::Create();
208 scoped_refptr<TestLayer> root231 = TestLayer::create(); 208 scoped_refptr<TestLayer> root231 = TestLayer::Create();
209 209
210 rootLayer->createRenderSurface(); 210 rootLayer->CreateRenderSurface();
211 rootLayer->renderSurface()->SetContentRect(gfx::Rect(gfx::Point(), rootLayer ->bounds())); 211 rootLayer->render_surface()->SetContentRect(gfx::Rect(gfx::Point(), rootLaye r->bounds()));
212 212
213 rootLayer->addChild(root1); 213 rootLayer->AddChild(root1);
214 rootLayer->addChild(root2); 214 rootLayer->AddChild(root2);
215 rootLayer->addChild(root3); 215 rootLayer->AddChild(root3);
216 root2->setDrawsContent(false); 216 root2->setDrawsContent(false);
217 root2->setOpacity(0.5); 217 root2->SetOpacity(0.5);
218 root2->setForceRenderSurface(true); // Force the layer to own a new surface. 218 root2->SetForceRenderSurface(true); // Force the layer to own a new surface.
219 root2->addChild(root21); 219 root2->AddChild(root21);
220 root2->addChild(root22); 220 root2->AddChild(root22);
221 root2->addChild(root23); 221 root2->AddChild(root23);
222 root22->setOpacity(0.5); 222 root22->SetOpacity(0.5);
223 root22->addChild(root221); 223 root22->AddChild(root221);
224 root23->setOpacity(0.5); 224 root23->SetOpacity(0.5);
225 root23->addChild(root231); 225 root23->AddChild(root231);
226 226
227 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; 227 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
228 LayerTreeHostCommon::calculateDrawProperties(rootLayer.get(), rootLayer->bou nds(), 1, 1, 256, false, renderSurfaceLayerList); 228 LayerTreeHostCommon::calculateDrawProperties(rootLayer.get(), rootLayer->bou nds(), 1, 1, 256, false, renderSurfaceLayerList);
229 229
230 iterateBackToFront(&renderSurfaceLayerList); 230 iterateBackToFront(&renderSurfaceLayerList);
231 EXPECT_COUNT(rootLayer, 0, -1, 1); 231 EXPECT_COUNT(rootLayer, 0, -1, 1);
232 EXPECT_COUNT(root1, -1, -1, 2); 232 EXPECT_COUNT(root1, -1, -1, 2);
233 EXPECT_COUNT(root2, 4, 3, -1); 233 EXPECT_COUNT(root2, 4, 3, -1);
234 EXPECT_COUNT(root21, -1, -1, 5); 234 EXPECT_COUNT(root21, -1, -1, 5);
235 EXPECT_COUNT(root22, 7, 6, 8); 235 EXPECT_COUNT(root22, 7, 6, 8);
236 EXPECT_COUNT(root221, -1, -1, 9); 236 EXPECT_COUNT(root221, -1, -1, 9);
237 EXPECT_COUNT(root23, 11, 10, 12); 237 EXPECT_COUNT(root23, 11, 10, 12);
238 EXPECT_COUNT(root231, -1, -1, 13); 238 EXPECT_COUNT(root231, -1, -1, 13);
239 EXPECT_COUNT(root3, -1, -1, 14); 239 EXPECT_COUNT(root3, -1, -1, 14);
240 240
241 iterateFrontToBack(&renderSurfaceLayerList); 241 iterateFrontToBack(&renderSurfaceLayerList);
242 EXPECT_COUNT(rootLayer, 14, -1, 13); 242 EXPECT_COUNT(rootLayer, 14, -1, 13);
243 EXPECT_COUNT(root1, -1, -1, 12); 243 EXPECT_COUNT(root1, -1, -1, 12);
244 EXPECT_COUNT(root2, 10, 11, -1); 244 EXPECT_COUNT(root2, 10, 11, -1);
245 EXPECT_COUNT(root21, -1, -1, 9); 245 EXPECT_COUNT(root21, -1, -1, 9);
246 EXPECT_COUNT(root22, 7, 8, 6); 246 EXPECT_COUNT(root22, 7, 8, 6);
247 EXPECT_COUNT(root221, -1, -1, 5); 247 EXPECT_COUNT(root221, -1, -1, 5);
248 EXPECT_COUNT(root23, 3, 4, 2); 248 EXPECT_COUNT(root23, 3, 4, 2);
249 EXPECT_COUNT(root231, -1, -1, 1); 249 EXPECT_COUNT(root231, -1, -1, 1);
250 EXPECT_COUNT(root3, -1, -1, 0); 250 EXPECT_COUNT(root3, -1, -1, 0);
251 } 251 }
252 252
253 } // namespace 253 } // namespace
254 } // namespace cc 254 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layer_iterator.h ('k') | cc/layer_sorter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698