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

Side by Side Diff: cc/tree_synchronizer_unittest.cc

Issue 11519018: [cc] Make LayerImpls point at LayerTreeImpl instead of LTHI (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years 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
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 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/tree_synchronizer.h" 5 #include "cc/tree_synchronizer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "cc/layer.h" 9 #include "cc/layer.h"
10 #include "cc/layer_animation_controller.h" 10 #include "cc/layer_animation_controller.h"
11 #include "cc/layer_impl.h" 11 #include "cc/layer_impl.h"
12 #include "cc/proxy.h" 12 #include "cc/proxy.h"
13 #include "cc/single_thread_proxy.h" 13 #include "cc/single_thread_proxy.h"
14 #include "cc/test/animation_test_common.h" 14 #include "cc/test/animation_test_common.h"
15 #include "cc/test/fake_proxy.h" 15 #include "cc/test/fake_proxy.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 17
18 namespace cc { 18 namespace cc {
19 namespace { 19 namespace {
20 20
21 class MockLayerImpl : public LayerImpl { 21 class MockLayerImpl : public LayerImpl {
22 public: 22 public:
23 static scoped_ptr<MockLayerImpl> create(LayerTreeHostImpl* hostImpl, int lay erId) 23 static scoped_ptr<MockLayerImpl> create(LayerTreeImpl* treeImpl, int layerId )
24 { 24 {
25 return make_scoped_ptr(new MockLayerImpl(hostImpl, layerId)); 25 return make_scoped_ptr(new MockLayerImpl(treeImpl, layerId));
26 } 26 }
27 virtual ~MockLayerImpl() 27 virtual ~MockLayerImpl()
28 { 28 {
29 if (m_layerImplDestructionList) 29 if (m_layerImplDestructionList)
30 m_layerImplDestructionList->push_back(id()); 30 m_layerImplDestructionList->push_back(id());
31 } 31 }
32 32
33 void setLayerImplDestructionList(std::vector<int>* list) { m_layerImplDestru ctionList = list; } 33 void setLayerImplDestructionList(std::vector<int>* list) { m_layerImplDestru ctionList = list; }
34 34
35 private: 35 private:
36 MockLayerImpl(LayerTreeHostImpl* hostImpl, int layerId) 36 MockLayerImpl(LayerTreeImpl* treeImpl, int layerId)
37 : LayerImpl(hostImpl, layerId) 37 : LayerImpl(treeImpl, layerId)
38 , m_layerImplDestructionList(0) 38 , m_layerImplDestructionList(0)
39 { 39 {
40 } 40 }
41 41
42 std::vector<int>* m_layerImplDestructionList; 42 std::vector<int>* m_layerImplDestructionList;
43 }; 43 };
44 44
45 class MockLayer : public Layer { 45 class MockLayer : public Layer {
46 public: 46 public:
47 static scoped_refptr<MockLayer> create(std::vector<int>* layerImplDestructio nList) 47 static scoped_refptr<MockLayer> create(std::vector<int>* layerImplDestructio nList)
48 { 48 {
49 return make_scoped_refptr(new MockLayer(layerImplDestructionList)); 49 return make_scoped_refptr(new MockLayer(layerImplDestructionList));
50 } 50 }
51 51
52 virtual scoped_ptr<LayerImpl> createLayerImpl(LayerTreeHostImpl* hostImpl) O VERRIDE 52 virtual scoped_ptr<LayerImpl> createLayerImpl(LayerTreeImpl* treeImpl) OVERR IDE
53 { 53 {
54 return MockLayerImpl::create(hostImpl, m_layerId).PassAs<LayerImpl>(); 54 return MockLayerImpl::create(treeImpl, m_layerId).PassAs<LayerImpl>();
55 } 55 }
56 56
57 virtual void pushPropertiesTo(LayerImpl* layerImpl) OVERRIDE 57 virtual void pushPropertiesTo(LayerImpl* layerImpl) OVERRIDE
58 { 58 {
59 Layer::pushPropertiesTo(layerImpl); 59 Layer::pushPropertiesTo(layerImpl);
60 60
61 MockLayerImpl* mockLayerImpl = static_cast<MockLayerImpl*>(layerImpl); 61 MockLayerImpl* mockLayerImpl = static_cast<MockLayerImpl*>(layerImpl);
62 mockLayerImpl->setLayerImplDestructionList(m_layerImplDestructionList); 62 mockLayerImpl->setLayerImplDestructionList(m_layerImplDestructionList);
63 } 63 }
64 64
(...skipping 26 matching lines...) Expand all
91 91
92 virtual void pushAnimationUpdatesTo(LayerAnimationController* controllerImpl ) 92 virtual void pushAnimationUpdatesTo(LayerAnimationController* controllerImpl )
93 { 93 {
94 LayerAnimationController::pushAnimationUpdatesTo(controllerImpl); 94 LayerAnimationController::pushAnimationUpdatesTo(controllerImpl);
95 m_synchronizedAnimations = true; 95 m_synchronizedAnimations = true;
96 } 96 }
97 97
98 bool m_synchronizedAnimations; 98 bool m_synchronizedAnimations;
99 }; 99 };
100 100
101 void expectTreesAreIdentical(Layer* layer, LayerImpl* layerImpl, LayerTreeHostIm pl* hostImpl) 101 void expectTreesAreIdentical(Layer* layer, LayerImpl* layerImpl, LayerTreeImpl* treeImpl)
102 { 102 {
103 ASSERT_TRUE(layer); 103 ASSERT_TRUE(layer);
104 ASSERT_TRUE(layerImpl); 104 ASSERT_TRUE(layerImpl);
105 105
106 EXPECT_EQ(layer->id(), layerImpl->id()); 106 EXPECT_EQ(layer->id(), layerImpl->id());
107 EXPECT_EQ(layerImpl->layerTreeHostImpl(), hostImpl); 107 EXPECT_EQ(layerImpl->layerTreeImpl(), treeImpl);
108 108
109 EXPECT_EQ(layer->nonFastScrollableRegion(), layerImpl->nonFastScrollableRegi on()); 109 EXPECT_EQ(layer->nonFastScrollableRegion(), layerImpl->nonFastScrollableRegi on());
110 110
111 ASSERT_EQ(!!layer->maskLayer(), !!layerImpl->maskLayer()); 111 ASSERT_EQ(!!layer->maskLayer(), !!layerImpl->maskLayer());
112 if (layer->maskLayer()) 112 if (layer->maskLayer())
113 expectTreesAreIdentical(layer->maskLayer(), layerImpl->maskLayer(), host Impl); 113 expectTreesAreIdentical(layer->maskLayer(), layerImpl->maskLayer(), tree Impl);
114 114
115 ASSERT_EQ(!!layer->replicaLayer(), !!layerImpl->replicaLayer()); 115 ASSERT_EQ(!!layer->replicaLayer(), !!layerImpl->replicaLayer());
116 if (layer->replicaLayer()) 116 if (layer->replicaLayer())
117 expectTreesAreIdentical(layer->replicaLayer(), layerImpl->replicaLayer() , hostImpl); 117 expectTreesAreIdentical(layer->replicaLayer(), layerImpl->replicaLayer() , treeImpl);
118 118
119 const std::vector<scoped_refptr<Layer> >& layerChildren = layer->children(); 119 const std::vector<scoped_refptr<Layer> >& layerChildren = layer->children();
120 const ScopedPtrVector<LayerImpl>& layerImplChildren = layerImpl->children(); 120 const ScopedPtrVector<LayerImpl>& layerImplChildren = layerImpl->children();
121 121
122 ASSERT_EQ(layerChildren.size(), layerImplChildren.size()); 122 ASSERT_EQ(layerChildren.size(), layerImplChildren.size());
123 123
124 for (size_t i = 0; i < layerChildren.size(); ++i) 124 for (size_t i = 0; i < layerChildren.size(); ++i)
125 expectTreesAreIdentical(layerChildren[i].get(), layerImplChildren[i], ho stImpl); 125 expectTreesAreIdentical(layerChildren[i].get(), layerImplChildren[i], tr eeImpl);
126 } 126 }
127 127
128 // Attempts to synchronizes a null tree. This should not crash, and should 128 // Attempts to synchronizes a null tree. This should not crash, and should
129 // return a null tree. 129 // return a null tree.
130 TEST(TreeSynchronizerTest, syncNullTree) 130 TEST(TreeSynchronizerTest, syncNullTree)
131 { 131 {
132 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (0, scoped_ptr<LayerImpl>(), 0); 132 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (0, scoped_ptr<LayerImpl>(), 0);
133 133
134 EXPECT_TRUE(!layerImplTreeRoot.get()); 134 EXPECT_TRUE(!layerImplTreeRoot.get());
135 } 135 }
136 136
137 // Constructs a very simple tree and synchronizes it without trying to reuse any preexisting layers. 137 // Constructs a very simple tree and synchronizes it without trying to reuse any preexisting layers.
138 TEST(TreeSynchronizerTest, syncSimpleTreeFromEmpty) 138 TEST(TreeSynchronizerTest, syncSimpleTreeFromEmpty)
139 { 139 {
140 LayerTreeSettings settings; 140 LayerTreeSettings settings;
141 FakeProxy proxy(scoped_ptr<Thread>(NULL)); 141 FakeProxy proxy(scoped_ptr<Thread>(NULL));
142 DebugScopedSetImplThread impl(&proxy); 142 DebugScopedSetImplThread impl(&proxy);
143 scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0, &proxy); 143 scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0, &proxy);
144 144
145 scoped_refptr<Layer> layerTreeRoot = Layer::create(); 145 scoped_refptr<Layer> layerTreeRoot = Layer::create();
146 layerTreeRoot->addChild(Layer::create()); 146 layerTreeRoot->addChild(Layer::create());
147 layerTreeRoot->addChild(Layer::create()); 147 layerTreeRoot->addChild(Layer::create());
148 148
149 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl.get()); 149 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl->activeTree());
150 150
151 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm pl.get()); 151 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm pl->activeTree());
152 } 152 }
153 153
154 // Constructs a very simple tree and synchronizes it attempting to reuse some la yers 154 // Constructs a very simple tree and synchronizes it attempting to reuse some la yers
155 TEST(TreeSynchronizerTest, syncSimpleTreeReusingLayers) 155 TEST(TreeSynchronizerTest, syncSimpleTreeReusingLayers)
156 { 156 {
157 std::vector<int> layerImplDestructionList; 157 std::vector<int> layerImplDestructionList;
158 158
159 LayerTreeSettings settings; 159 LayerTreeSettings settings;
160 FakeProxy proxy(scoped_ptr<Thread>(NULL)); 160 FakeProxy proxy(scoped_ptr<Thread>(NULL));
161 DebugScopedSetImplThread impl(&proxy); 161 DebugScopedSetImplThread impl(&proxy);
162 scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0, &proxy); 162 scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0, &proxy);
163 163
164 scoped_refptr<Layer> layerTreeRoot = MockLayer::create(&layerImplDestruction List); 164 scoped_refptr<Layer> layerTreeRoot = MockLayer::create(&layerImplDestruction List);
165 layerTreeRoot->addChild(MockLayer::create(&layerImplDestructionList)); 165 layerTreeRoot->addChild(MockLayer::create(&layerImplDestructionList));
166 layerTreeRoot->addChild(MockLayer::create(&layerImplDestructionList)); 166 layerTreeRoot->addChild(MockLayer::create(&layerImplDestructionList));
167 167
168 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl.get()); 168 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl->activeTree());
169 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm pl.get()); 169 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm pl->activeTree());
170 170
171 // Add a new layer to the Layer side 171 // Add a new layer to the Layer side
172 layerTreeRoot->children()[0]->addChild(MockLayer::create(&layerImplDestructi onList)); 172 layerTreeRoot->children()[0]->addChild(MockLayer::create(&layerImplDestructi onList));
173 // Remove one. 173 // Remove one.
174 layerTreeRoot->children()[1]->removeFromParent(); 174 layerTreeRoot->children()[1]->removeFromParent();
175 int secondLayerImplId = layerImplTreeRoot->children()[1]->id(); 175 int secondLayerImplId = layerImplTreeRoot->children()[1]->id();
176 176
177 // Synchronize again. After the sync the trees should be equivalent and we s hould have created and destroyed one LayerImpl. 177 // Synchronize again. After the sync the trees should be equivalent and we s hould have created and destroyed one LayerImpl.
178 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), hostImpl.get()); 178 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), hostImpl->activeTree());
179 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm pl.get()); 179 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm pl->activeTree());
180 180
181 ASSERT_EQ(1u, layerImplDestructionList.size()); 181 ASSERT_EQ(1u, layerImplDestructionList.size());
182 EXPECT_EQ(secondLayerImplId, layerImplDestructionList[0]); 182 EXPECT_EQ(secondLayerImplId, layerImplDestructionList[0]);
183 } 183 }
184 184
185 // Constructs a very simple tree and checks that a stacking-order change is trac ked properly. 185 // Constructs a very simple tree and checks that a stacking-order change is trac ked properly.
186 TEST(TreeSynchronizerTest, syncSimpleTreeAndTrackStackingOrderChange) 186 TEST(TreeSynchronizerTest, syncSimpleTreeAndTrackStackingOrderChange)
187 { 187 {
188 std::vector<int> layerImplDestructionList; 188 std::vector<int> layerImplDestructionList;
189 189
190 LayerTreeSettings settings; 190 LayerTreeSettings settings;
191 FakeProxy proxy(scoped_ptr<Thread>(NULL)); 191 FakeProxy proxy(scoped_ptr<Thread>(NULL));
192 DebugScopedSetImplThread impl(&proxy); 192 DebugScopedSetImplThread impl(&proxy);
193 scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0, &proxy); 193 scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0, &proxy);
194 194
195 // Set up the tree and sync once. child2 needs to be synced here, too, even though we 195 // Set up the tree and sync once. child2 needs to be synced here, too, even though we
196 // remove it to set up the intended scenario. 196 // remove it to set up the intended scenario.
197 scoped_refptr<Layer> layerTreeRoot = MockLayer::create(&layerImplDestruction List); 197 scoped_refptr<Layer> layerTreeRoot = MockLayer::create(&layerImplDestruction List);
198 scoped_refptr<Layer> child2 = MockLayer::create(&layerImplDestructionList); 198 scoped_refptr<Layer> child2 = MockLayer::create(&layerImplDestructionList);
199 layerTreeRoot->addChild(MockLayer::create(&layerImplDestructionList)); 199 layerTreeRoot->addChild(MockLayer::create(&layerImplDestructionList));
200 layerTreeRoot->addChild(child2); 200 layerTreeRoot->addChild(child2);
201 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl.get()); 201 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl->activeTree());
202 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm pl.get()); 202 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm pl->activeTree());
203 layerImplTreeRoot->resetAllChangeTrackingForSubtree(); 203 layerImplTreeRoot->resetAllChangeTrackingForSubtree();
204 204
205 // re-insert the layer and sync again. 205 // re-insert the layer and sync again.
206 child2->removeFromParent(); 206 child2->removeFromParent();
207 layerTreeRoot->addChild(child2); 207 layerTreeRoot->addChild(child2);
208 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), hostImpl.get()); 208 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), hostImpl->activeTree());
209 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm pl.get()); 209 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm pl->activeTree());
210 210
211 // Check that the impl thread properly tracked the change. 211 // Check that the impl thread properly tracked the change.
212 EXPECT_FALSE(layerImplTreeRoot->layerPropertyChanged()); 212 EXPECT_FALSE(layerImplTreeRoot->layerPropertyChanged());
213 EXPECT_FALSE(layerImplTreeRoot->children()[0]->layerPropertyChanged()); 213 EXPECT_FALSE(layerImplTreeRoot->children()[0]->layerPropertyChanged());
214 EXPECT_TRUE(layerImplTreeRoot->children()[1]->layerPropertyChanged()); 214 EXPECT_TRUE(layerImplTreeRoot->children()[1]->layerPropertyChanged());
215 } 215 }
216 216
217 TEST(TreeSynchronizerTest, syncSimpleTreeAndProperties) 217 TEST(TreeSynchronizerTest, syncSimpleTreeAndProperties)
218 { 218 {
219 LayerTreeSettings settings; 219 LayerTreeSettings settings;
220 FakeProxy proxy(scoped_ptr<Thread>(NULL)); 220 FakeProxy proxy(scoped_ptr<Thread>(NULL));
221 DebugScopedSetImplThread impl(&proxy); 221 DebugScopedSetImplThread impl(&proxy);
222 scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0, &proxy); 222 scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0, &proxy);
223 223
224 scoped_refptr<Layer> layerTreeRoot = Layer::create(); 224 scoped_refptr<Layer> layerTreeRoot = Layer::create();
225 layerTreeRoot->addChild(Layer::create()); 225 layerTreeRoot->addChild(Layer::create());
226 layerTreeRoot->addChild(Layer::create()); 226 layerTreeRoot->addChild(Layer::create());
227 227
228 // Pick some random properties to set. The values are not important, we're j ust testing that at least some properties are making it through. 228 // Pick some random properties to set. The values are not important, we're j ust testing that at least some properties are making it through.
229 gfx::PointF rootPosition = gfx::PointF(2.3f, 7.4f); 229 gfx::PointF rootPosition = gfx::PointF(2.3f, 7.4f);
230 layerTreeRoot->setPosition(rootPosition); 230 layerTreeRoot->setPosition(rootPosition);
231 231
232 float firstChildOpacity = 0.25f; 232 float firstChildOpacity = 0.25f;
233 layerTreeRoot->children()[0]->setOpacity(firstChildOpacity); 233 layerTreeRoot->children()[0]->setOpacity(firstChildOpacity);
234 234
235 gfx::Size secondChildBounds = gfx::Size(25, 53); 235 gfx::Size secondChildBounds = gfx::Size(25, 53);
236 layerTreeRoot->children()[1]->setBounds(secondChildBounds); 236 layerTreeRoot->children()[1]->setBounds(secondChildBounds);
237 237
238 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl.get()); 238 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl->activeTree());
239 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm pl.get()); 239 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm pl->activeTree());
240 240
241 // Check that the property values we set on the Layer tree are reflected in the LayerImpl tree. 241 // Check that the property values we set on the Layer tree are reflected in the LayerImpl tree.
242 gfx::PointF rootLayerImplPosition = layerImplTreeRoot->position(); 242 gfx::PointF rootLayerImplPosition = layerImplTreeRoot->position();
243 EXPECT_EQ(rootPosition.x(), rootLayerImplPosition.x()); 243 EXPECT_EQ(rootPosition.x(), rootLayerImplPosition.x());
244 EXPECT_EQ(rootPosition.y(), rootLayerImplPosition.y()); 244 EXPECT_EQ(rootPosition.y(), rootLayerImplPosition.y());
245 245
246 EXPECT_EQ(firstChildOpacity, layerImplTreeRoot->children()[0]->opacity()); 246 EXPECT_EQ(firstChildOpacity, layerImplTreeRoot->children()[0]->opacity());
247 247
248 gfx::Size secondLayerImplChildBounds = layerImplTreeRoot->children()[1]->bou nds(); 248 gfx::Size secondLayerImplChildBounds = layerImplTreeRoot->children()[1]->bou nds();
249 EXPECT_EQ(secondChildBounds.width(), secondLayerImplChildBounds.width()); 249 EXPECT_EQ(secondChildBounds.width(), secondLayerImplChildBounds.width());
(...skipping 19 matching lines...) Expand all
269 scoped_refptr<Layer> layerA = layerTreeRoot->children()[0].get(); 269 scoped_refptr<Layer> layerA = layerTreeRoot->children()[0].get();
270 layerA->addChild(MockLayer::create(&layerImplDestructionList)); 270 layerA->addChild(MockLayer::create(&layerImplDestructionList));
271 271
272 scoped_refptr<Layer> layerB = layerA->children()[0].get(); 272 scoped_refptr<Layer> layerB = layerA->children()[0].get();
273 layerB->addChild(MockLayer::create(&layerImplDestructionList)); 273 layerB->addChild(MockLayer::create(&layerImplDestructionList));
274 274
275 scoped_refptr<Layer> layerC = layerB->children()[0].get(); 275 scoped_refptr<Layer> layerC = layerB->children()[0].get();
276 layerB->addChild(MockLayer::create(&layerImplDestructionList)); 276 layerB->addChild(MockLayer::create(&layerImplDestructionList));
277 scoped_refptr<Layer> layerD = layerB->children()[1].get(); 277 scoped_refptr<Layer> layerD = layerB->children()[1].get();
278 278
279 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl.get()); 279 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl->activeTree());
280 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm pl.get()); 280 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm pl->activeTree());
281 281
282 // Now restructure the tree to look like this: 282 // Now restructure the tree to look like this:
283 // root --- D ---+--- A 283 // root --- D ---+--- A
284 // | 284 // |
285 // +--- C --- B 285 // +--- C --- B
286 layerTreeRoot->removeAllChildren(); 286 layerTreeRoot->removeAllChildren();
287 layerD->removeAllChildren(); 287 layerD->removeAllChildren();
288 layerTreeRoot->addChild(layerD); 288 layerTreeRoot->addChild(layerD);
289 layerA->removeAllChildren(); 289 layerA->removeAllChildren();
290 layerD->addChild(layerA); 290 layerD->addChild(layerA);
291 layerC->removeAllChildren(); 291 layerC->removeAllChildren();
292 layerD->addChild(layerC); 292 layerD->addChild(layerC);
293 layerB->removeAllChildren(); 293 layerB->removeAllChildren();
294 layerC->addChild(layerB); 294 layerC->addChild(layerB);
295 295
296 // After another synchronize our trees should match and we should not have d estroyed any LayerImpls 296 // After another synchronize our trees should match and we should not have d estroyed any LayerImpls
297 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), hostImpl.get()); 297 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), hostImpl->activeTree());
298 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm pl.get()); 298 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm pl->activeTree());
299 299
300 EXPECT_EQ(0u, layerImplDestructionList.size()); 300 EXPECT_EQ(0u, layerImplDestructionList.size());
301 } 301 }
302 302
303 // Constructs a very simple tree, synchronizes it, then synchronizes to a totall y new tree. All layers from the old tree should be deleted. 303 // Constructs a very simple tree, synchronizes it, then synchronizes to a totall y new tree. All layers from the old tree should be deleted.
304 TEST(TreeSynchronizerTest, syncSimpleTreeThenDestroy) 304 TEST(TreeSynchronizerTest, syncSimpleTreeThenDestroy)
305 { 305 {
306 std::vector<int> layerImplDestructionList; 306 std::vector<int> layerImplDestructionList;
307 307
308 LayerTreeSettings settings; 308 LayerTreeSettings settings;
309 FakeProxy proxy(scoped_ptr<Thread>(NULL)); 309 FakeProxy proxy(scoped_ptr<Thread>(NULL));
310 DebugScopedSetImplThread impl(&proxy); 310 DebugScopedSetImplThread impl(&proxy);
311 scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0, &proxy); 311 scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0, &proxy);
312 312
313 scoped_refptr<Layer> oldLayerTreeRoot = MockLayer::create(&layerImplDestruct ionList); 313 scoped_refptr<Layer> oldLayerTreeRoot = MockLayer::create(&layerImplDestruct ionList);
314 oldLayerTreeRoot->addChild(MockLayer::create(&layerImplDestructionList)); 314 oldLayerTreeRoot->addChild(MockLayer::create(&layerImplDestructionList));
315 oldLayerTreeRoot->addChild(MockLayer::create(&layerImplDestructionList)); 315 oldLayerTreeRoot->addChild(MockLayer::create(&layerImplDestructionList));
316 316
317 int oldTreeRootLayerId = oldLayerTreeRoot->id(); 317 int oldTreeRootLayerId = oldLayerTreeRoot->id();
318 int oldTreeFirstChildLayerId = oldLayerTreeRoot->children()[0]->id(); 318 int oldTreeFirstChildLayerId = oldLayerTreeRoot->children()[0]->id();
319 int oldTreeSecondChildLayerId = oldLayerTreeRoot->children()[1]->id(); 319 int oldTreeSecondChildLayerId = oldLayerTreeRoot->children()[1]->id();
320 320
321 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (oldLayerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl.get()); 321 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (oldLayerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl->activeTree());
322 expectTreesAreIdentical(oldLayerTreeRoot.get(), layerImplTreeRoot.get(), hos tImpl.get()); 322 expectTreesAreIdentical(oldLayerTreeRoot.get(), layerImplTreeRoot.get(), hos tImpl->activeTree());
323 323
324 // Remove all children on the Layer side. 324 // Remove all children on the Layer side.
325 oldLayerTreeRoot->removeAllChildren(); 325 oldLayerTreeRoot->removeAllChildren();
326 326
327 // Synchronize again. After the sync all LayerImpls from the old tree should be deleted. 327 // Synchronize again. After the sync all LayerImpls from the old tree should be deleted.
328 scoped_refptr<Layer> newLayerTreeRoot = Layer::create(); 328 scoped_refptr<Layer> newLayerTreeRoot = Layer::create();
329 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(newLayerTreeRoot.get( ), layerImplTreeRoot.Pass(), hostImpl.get()); 329 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(newLayerTreeRoot.get( ), layerImplTreeRoot.Pass(), hostImpl->activeTree());
330 expectTreesAreIdentical(newLayerTreeRoot.get(), layerImplTreeRoot.get(), hos tImpl.get()); 330 expectTreesAreIdentical(newLayerTreeRoot.get(), layerImplTreeRoot.get(), hos tImpl->activeTree());
331 331
332 ASSERT_EQ(3u, layerImplDestructionList.size()); 332 ASSERT_EQ(3u, layerImplDestructionList.size());
333 333
334 EXPECT_TRUE(std::find(layerImplDestructionList.begin(), layerImplDestruction List.end(), oldTreeRootLayerId) != layerImplDestructionList.end()); 334 EXPECT_TRUE(std::find(layerImplDestructionList.begin(), layerImplDestruction List.end(), oldTreeRootLayerId) != layerImplDestructionList.end());
335 EXPECT_TRUE(std::find(layerImplDestructionList.begin(), layerImplDestruction List.end(), oldTreeFirstChildLayerId) != layerImplDestructionList.end()); 335 EXPECT_TRUE(std::find(layerImplDestructionList.begin(), layerImplDestruction List.end(), oldTreeFirstChildLayerId) != layerImplDestructionList.end());
336 EXPECT_TRUE(std::find(layerImplDestructionList.begin(), layerImplDestruction List.end(), oldTreeSecondChildLayerId) != layerImplDestructionList.end()); 336 EXPECT_TRUE(std::find(layerImplDestructionList.begin(), layerImplDestruction List.end(), oldTreeSecondChildLayerId) != layerImplDestructionList.end());
337 } 337 }
338 338
339 // Constructs+syncs a tree with mask, replica, and replica mask layers. 339 // Constructs+syncs a tree with mask, replica, and replica mask layers.
340 TEST(TreeSynchronizerTest, syncMaskReplicaAndReplicaMaskLayers) 340 TEST(TreeSynchronizerTest, syncMaskReplicaAndReplicaMaskLayers)
(...skipping 15 matching lines...) Expand all
356 // Second child gets a replica layer. 356 // Second child gets a replica layer.
357 scoped_refptr<Layer> replicaLayer = Layer::create(); 357 scoped_refptr<Layer> replicaLayer = Layer::create();
358 layerTreeRoot->children()[1]->setReplicaLayer(replicaLayer.get()); 358 layerTreeRoot->children()[1]->setReplicaLayer(replicaLayer.get());
359 359
360 // Third child gets a replica layer with a mask layer. 360 // Third child gets a replica layer with a mask layer.
361 scoped_refptr<Layer> replicaLayerWithMask = Layer::create(); 361 scoped_refptr<Layer> replicaLayerWithMask = Layer::create();
362 scoped_refptr<Layer> replicaMaskLayer = Layer::create(); 362 scoped_refptr<Layer> replicaMaskLayer = Layer::create();
363 replicaLayerWithMask->setMaskLayer(replicaMaskLayer.get()); 363 replicaLayerWithMask->setMaskLayer(replicaMaskLayer.get());
364 layerTreeRoot->children()[2]->setReplicaLayer(replicaLayerWithMask.get()); 364 layerTreeRoot->children()[2]->setReplicaLayer(replicaLayerWithMask.get());
365 365
366 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl.get()); 366 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl->activeTree());
367 367
368 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm pl.get()); 368 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm pl->activeTree());
369 369
370 // Remove the mask layer. 370 // Remove the mask layer.
371 layerTreeRoot->children()[0]->setMaskLayer(0); 371 layerTreeRoot->children()[0]->setMaskLayer(0);
372 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), hostImpl.get()); 372 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), hostImpl->activeTree());
373 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm pl.get()); 373 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm pl->activeTree());
374 374
375 // Remove the replica layer. 375 // Remove the replica layer.
376 layerTreeRoot->children()[1]->setReplicaLayer(0); 376 layerTreeRoot->children()[1]->setReplicaLayer(0);
377 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), hostImpl.get()); 377 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), hostImpl->activeTree());
378 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm pl.get()); 378 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm pl->activeTree());
379 379
380 // Remove the replica mask. 380 // Remove the replica mask.
381 replicaLayerWithMask->setMaskLayer(0); 381 replicaLayerWithMask->setMaskLayer(0);
382 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), hostImpl.get()); 382 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), hostImpl->activeTree());
383 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm pl.get()); 383 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm pl->activeTree());
384 } 384 }
385 385
386 TEST(TreeSynchronizerTest, synchronizeAnimations) 386 TEST(TreeSynchronizerTest, synchronizeAnimations)
387 { 387 {
388 LayerTreeSettings settings; 388 LayerTreeSettings settings;
389 FakeProxy proxy(scoped_ptr<Thread>(NULL)); 389 FakeProxy proxy(scoped_ptr<Thread>(NULL));
390 DebugScopedSetImplThread impl(&proxy); 390 DebugScopedSetImplThread impl(&proxy);
391 scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0, &proxy); 391 scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0, &proxy);
392 392
393 scoped_refptr<Layer> layerTreeRoot = Layer::create(); 393 scoped_refptr<Layer> layerTreeRoot = Layer::create();
394 394
395 FakeLayerAnimationControllerClient dummy; 395 FakeLayerAnimationControllerClient dummy;
396 layerTreeRoot->setLayerAnimationController(FakeLayerAnimationController::cre ate(&dummy).PassAs<LayerAnimationController>()); 396 layerTreeRoot->setLayerAnimationController(FakeLayerAnimationController::cre ate(&dummy).PassAs<LayerAnimationController>());
397 397
398 EXPECT_FALSE(static_cast<FakeLayerAnimationController*>(layerTreeRoot->layer AnimationController())->synchronizedAnimations()); 398 EXPECT_FALSE(static_cast<FakeLayerAnimationController*>(layerTreeRoot->layer AnimationController())->synchronizedAnimations());
399 399
400 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl.get()); 400 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl->activeTree());
401 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), hostImpl.get()); 401 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), hostImpl->activeTree());
402 402
403 EXPECT_TRUE(static_cast<FakeLayerAnimationController*>(layerTreeRoot->layerA nimationController())->synchronizedAnimations()); 403 EXPECT_TRUE(static_cast<FakeLayerAnimationController*>(layerTreeRoot->layerA nimationController())->synchronizedAnimations());
404 } 404 }
405 405
406 } // namespace 406 } // namespace
407 } // namespace cc 407 } // namespace cc
OLDNEW
« cc/layer.h ('K') | « cc/tree_synchronizer.cc ('k') | cc/video_layer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698