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

Side by Side Diff: cc/tree_synchronizer_unittest.cc

Issue 11583009: cc: Refactor shared code in tree sync unit tests (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
« no previous file with comments | « cc/tree_synchronizer.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_impl_proxy.h"
16 #include "cc/test/fake_layer_tree_host_impl.h"
16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
17 18
18 namespace cc { 19 namespace cc {
19 namespace { 20 namespace {
20 21
21 class MockLayerImpl : public LayerImpl { 22 class MockLayerImpl : public LayerImpl {
22 public: 23 public:
23 static scoped_ptr<MockLayerImpl> create(LayerTreeImpl* treeImpl, int layerId ) 24 static scoped_ptr<MockLayerImpl> create(LayerTreeImpl* treeImpl, int layerId )
24 { 25 {
25 return make_scoped_ptr(new MockLayerImpl(treeImpl, layerId)); 26 return make_scoped_ptr(new MockLayerImpl(treeImpl, layerId));
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 119
119 const std::vector<scoped_refptr<Layer> >& layerChildren = layer->children(); 120 const std::vector<scoped_refptr<Layer> >& layerChildren = layer->children();
120 const ScopedPtrVector<LayerImpl>& layerImplChildren = layerImpl->children(); 121 const ScopedPtrVector<LayerImpl>& layerImplChildren = layerImpl->children();
121 122
122 ASSERT_EQ(layerChildren.size(), layerImplChildren.size()); 123 ASSERT_EQ(layerChildren.size(), layerImplChildren.size());
123 124
124 for (size_t i = 0; i < layerChildren.size(); ++i) 125 for (size_t i = 0; i < layerChildren.size(); ++i)
125 expectTreesAreIdentical(layerChildren[i].get(), layerImplChildren[i], tr eeImpl); 126 expectTreesAreIdentical(layerChildren[i].get(), layerImplChildren[i], tr eeImpl);
126 } 127 }
127 128
129 class TreeSynchronizerTest : public testing::Test {
130 public:
131 TreeSynchronizerTest()
132 : m_hostImpl(&m_proxy)
133 {
134 }
135
136 protected:
137 FakeImplProxy m_proxy;
138 FakeLayerTreeHostImpl m_hostImpl;
139 };
140
128 // Attempts to synchronizes a null tree. This should not crash, and should 141 // Attempts to synchronizes a null tree. This should not crash, and should
129 // return a null tree. 142 // return a null tree.
130 TEST(TreeSynchronizerTest, syncNullTree) 143 TEST_F(TreeSynchronizerTest, syncNullTree)
131 { 144 {
132 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (0, scoped_ptr<LayerImpl>(), 0); 145 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (0, scoped_ptr<LayerImpl>(), m_hostImpl.activeTree());
133 146
134 EXPECT_TRUE(!layerImplTreeRoot.get()); 147 EXPECT_TRUE(!layerImplTreeRoot.get());
135 } 148 }
136 149
137 // Constructs a very simple tree and synchronizes it without trying to reuse any preexisting layers. 150 // Constructs a very simple tree and synchronizes it without trying to reuse any preexisting layers.
138 TEST(TreeSynchronizerTest, syncSimpleTreeFromEmpty) 151 TEST_F(TreeSynchronizerTest, syncSimpleTreeFromEmpty)
139 { 152 {
140 LayerTreeSettings settings;
141 FakeProxy proxy(scoped_ptr<Thread>(NULL));
142 DebugScopedSetImplThread impl(&proxy);
143 scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0, &proxy);
144
145 scoped_refptr<Layer> layerTreeRoot = Layer::create(); 153 scoped_refptr<Layer> layerTreeRoot = Layer::create();
146 layerTreeRoot->addChild(Layer::create()); 154 layerTreeRoot->addChild(Layer::create());
147 layerTreeRoot->addChild(Layer::create()); 155 layerTreeRoot->addChild(Layer::create());
148 156
149 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl->activeTree()); 157 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (layerTreeRoot.get(), scoped_ptr<LayerImpl>(), m_hostImpl.activeTree());
150 158
151 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm pl->activeTree()); 159 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), m_host Impl.activeTree());
152 } 160 }
153 161
154 // Constructs a very simple tree and synchronizes it attempting to reuse some la yers 162 // Constructs a very simple tree and synchronizes it attempting to reuse some la yers
155 TEST(TreeSynchronizerTest, syncSimpleTreeReusingLayers) 163 TEST_F(TreeSynchronizerTest, syncSimpleTreeReusingLayers)
156 { 164 {
157 std::vector<int> layerImplDestructionList; 165 std::vector<int> layerImplDestructionList;
158 166
159 LayerTreeSettings settings;
160 FakeProxy proxy(scoped_ptr<Thread>(NULL));
161 DebugScopedSetImplThread impl(&proxy);
162 scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0, &proxy);
163
164 scoped_refptr<Layer> layerTreeRoot = MockLayer::create(&layerImplDestruction List); 167 scoped_refptr<Layer> layerTreeRoot = MockLayer::create(&layerImplDestruction List);
165 layerTreeRoot->addChild(MockLayer::create(&layerImplDestructionList)); 168 layerTreeRoot->addChild(MockLayer::create(&layerImplDestructionList));
166 layerTreeRoot->addChild(MockLayer::create(&layerImplDestructionList)); 169 layerTreeRoot->addChild(MockLayer::create(&layerImplDestructionList));
167 170
168 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl->activeTree()); 171 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (layerTreeRoot.get(), scoped_ptr<LayerImpl>(), m_hostImpl.activeTree());
169 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm pl->activeTree()); 172 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), m_host Impl.activeTree());
170 173
171 // Add a new layer to the Layer side 174 // Add a new layer to the Layer side
172 layerTreeRoot->children()[0]->addChild(MockLayer::create(&layerImplDestructi onList)); 175 layerTreeRoot->children()[0]->addChild(MockLayer::create(&layerImplDestructi onList));
173 // Remove one. 176 // Remove one.
174 layerTreeRoot->children()[1]->removeFromParent(); 177 layerTreeRoot->children()[1]->removeFromParent();
175 int secondLayerImplId = layerImplTreeRoot->children()[1]->id(); 178 int secondLayerImplId = layerImplTreeRoot->children()[1]->id();
176 179
177 // Synchronize again. After the sync the trees should be equivalent and we s hould have created and destroyed one LayerImpl. 180 // 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->activeTree()); 181 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), m_hostImpl.activeTree());
179 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm pl->activeTree()); 182 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), m_host Impl.activeTree());
180 183
181 ASSERT_EQ(1u, layerImplDestructionList.size()); 184 ASSERT_EQ(1u, layerImplDestructionList.size());
182 EXPECT_EQ(secondLayerImplId, layerImplDestructionList[0]); 185 EXPECT_EQ(secondLayerImplId, layerImplDestructionList[0]);
183 } 186 }
184 187
185 // Constructs a very simple tree and checks that a stacking-order change is trac ked properly. 188 // Constructs a very simple tree and checks that a stacking-order change is trac ked properly.
186 TEST(TreeSynchronizerTest, syncSimpleTreeAndTrackStackingOrderChange) 189 TEST_F(TreeSynchronizerTest, syncSimpleTreeAndTrackStackingOrderChange)
187 { 190 {
188 std::vector<int> layerImplDestructionList; 191 std::vector<int> layerImplDestructionList;
189 192
190 LayerTreeSettings settings;
191 FakeProxy proxy(scoped_ptr<Thread>(NULL));
192 DebugScopedSetImplThread impl(&proxy);
193 scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0, &proxy);
194
195 // Set up the tree and sync once. child2 needs to be synced here, too, even though we 193 // 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. 194 // remove it to set up the intended scenario.
197 scoped_refptr<Layer> layerTreeRoot = MockLayer::create(&layerImplDestruction List); 195 scoped_refptr<Layer> layerTreeRoot = MockLayer::create(&layerImplDestruction List);
198 scoped_refptr<Layer> child2 = MockLayer::create(&layerImplDestructionList); 196 scoped_refptr<Layer> child2 = MockLayer::create(&layerImplDestructionList);
199 layerTreeRoot->addChild(MockLayer::create(&layerImplDestructionList)); 197 layerTreeRoot->addChild(MockLayer::create(&layerImplDestructionList));
200 layerTreeRoot->addChild(child2); 198 layerTreeRoot->addChild(child2);
201 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl->activeTree()); 199 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (layerTreeRoot.get(), scoped_ptr<LayerImpl>(), m_hostImpl.activeTree());
202 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm pl->activeTree()); 200 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), m_host Impl.activeTree());
203 layerImplTreeRoot->resetAllChangeTrackingForSubtree(); 201 layerImplTreeRoot->resetAllChangeTrackingForSubtree();
204 202
205 // re-insert the layer and sync again. 203 // re-insert the layer and sync again.
206 child2->removeFromParent(); 204 child2->removeFromParent();
207 layerTreeRoot->addChild(child2); 205 layerTreeRoot->addChild(child2);
208 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), hostImpl->activeTree()); 206 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), m_hostImpl.activeTree());
209 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm pl->activeTree()); 207 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), m_host Impl.activeTree());
210 208
211 // Check that the impl thread properly tracked the change. 209 // Check that the impl thread properly tracked the change.
212 EXPECT_FALSE(layerImplTreeRoot->layerPropertyChanged()); 210 EXPECT_FALSE(layerImplTreeRoot->layerPropertyChanged());
213 EXPECT_FALSE(layerImplTreeRoot->children()[0]->layerPropertyChanged()); 211 EXPECT_FALSE(layerImplTreeRoot->children()[0]->layerPropertyChanged());
214 EXPECT_TRUE(layerImplTreeRoot->children()[1]->layerPropertyChanged()); 212 EXPECT_TRUE(layerImplTreeRoot->children()[1]->layerPropertyChanged());
215 } 213 }
216 214
217 TEST(TreeSynchronizerTest, syncSimpleTreeAndProperties) 215 TEST_F(TreeSynchronizerTest, syncSimpleTreeAndProperties)
218 { 216 {
219 LayerTreeSettings settings;
220 FakeProxy proxy(scoped_ptr<Thread>(NULL));
221 DebugScopedSetImplThread impl(&proxy);
222 scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0, &proxy);
223
224 scoped_refptr<Layer> layerTreeRoot = Layer::create(); 217 scoped_refptr<Layer> layerTreeRoot = Layer::create();
225 layerTreeRoot->addChild(Layer::create()); 218 layerTreeRoot->addChild(Layer::create());
226 layerTreeRoot->addChild(Layer::create()); 219 layerTreeRoot->addChild(Layer::create());
227 220
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. 221 // 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); 222 gfx::PointF rootPosition = gfx::PointF(2.3f, 7.4f);
230 layerTreeRoot->setPosition(rootPosition); 223 layerTreeRoot->setPosition(rootPosition);
231 224
232 float firstChildOpacity = 0.25f; 225 float firstChildOpacity = 0.25f;
233 layerTreeRoot->children()[0]->setOpacity(firstChildOpacity); 226 layerTreeRoot->children()[0]->setOpacity(firstChildOpacity);
234 227
235 gfx::Size secondChildBounds = gfx::Size(25, 53); 228 gfx::Size secondChildBounds = gfx::Size(25, 53);
236 layerTreeRoot->children()[1]->setBounds(secondChildBounds); 229 layerTreeRoot->children()[1]->setBounds(secondChildBounds);
237 230
238 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl->activeTree()); 231 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (layerTreeRoot.get(), scoped_ptr<LayerImpl>(), m_hostImpl.activeTree());
239 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm pl->activeTree()); 232 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), m_host Impl.activeTree());
240 233
241 // Check that the property values we set on the Layer tree are reflected in the LayerImpl tree. 234 // Check that the property values we set on the Layer tree are reflected in the LayerImpl tree.
242 gfx::PointF rootLayerImplPosition = layerImplTreeRoot->position(); 235 gfx::PointF rootLayerImplPosition = layerImplTreeRoot->position();
243 EXPECT_EQ(rootPosition.x(), rootLayerImplPosition.x()); 236 EXPECT_EQ(rootPosition.x(), rootLayerImplPosition.x());
244 EXPECT_EQ(rootPosition.y(), rootLayerImplPosition.y()); 237 EXPECT_EQ(rootPosition.y(), rootLayerImplPosition.y());
245 238
246 EXPECT_EQ(firstChildOpacity, layerImplTreeRoot->children()[0]->opacity()); 239 EXPECT_EQ(firstChildOpacity, layerImplTreeRoot->children()[0]->opacity());
247 240
248 gfx::Size secondLayerImplChildBounds = layerImplTreeRoot->children()[1]->bou nds(); 241 gfx::Size secondLayerImplChildBounds = layerImplTreeRoot->children()[1]->bou nds();
249 EXPECT_EQ(secondChildBounds.width(), secondLayerImplChildBounds.width()); 242 EXPECT_EQ(secondChildBounds.width(), secondLayerImplChildBounds.width());
250 EXPECT_EQ(secondChildBounds.height(), secondLayerImplChildBounds.height()); 243 EXPECT_EQ(secondChildBounds.height(), secondLayerImplChildBounds.height());
251 } 244 }
252 245
253 TEST(TreeSynchronizerTest, reuseLayerImplsAfterStructuralChange) 246 TEST_F(TreeSynchronizerTest, reuseLayerImplsAfterStructuralChange)
254 { 247 {
255 std::vector<int> layerImplDestructionList; 248 std::vector<int> layerImplDestructionList;
256 249
257 LayerTreeSettings settings;
258 FakeProxy proxy(scoped_ptr<Thread>(NULL));
259 DebugScopedSetImplThread impl(&proxy);
260 scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0, &proxy);
261
262 // Set up a tree with this sort of structure: 250 // Set up a tree with this sort of structure:
263 // root --- A --- B ---+--- C 251 // root --- A --- B ---+--- C
264 // | 252 // |
265 // +--- D 253 // +--- D
266 scoped_refptr<Layer> layerTreeRoot = MockLayer::create(&layerImplDestruction List); 254 scoped_refptr<Layer> layerTreeRoot = MockLayer::create(&layerImplDestruction List);
267 layerTreeRoot->addChild(MockLayer::create(&layerImplDestructionList)); 255 layerTreeRoot->addChild(MockLayer::create(&layerImplDestructionList));
268 256
269 scoped_refptr<Layer> layerA = layerTreeRoot->children()[0].get(); 257 scoped_refptr<Layer> layerA = layerTreeRoot->children()[0].get();
270 layerA->addChild(MockLayer::create(&layerImplDestructionList)); 258 layerA->addChild(MockLayer::create(&layerImplDestructionList));
271 259
272 scoped_refptr<Layer> layerB = layerA->children()[0].get(); 260 scoped_refptr<Layer> layerB = layerA->children()[0].get();
273 layerB->addChild(MockLayer::create(&layerImplDestructionList)); 261 layerB->addChild(MockLayer::create(&layerImplDestructionList));
274 262
275 scoped_refptr<Layer> layerC = layerB->children()[0].get(); 263 scoped_refptr<Layer> layerC = layerB->children()[0].get();
276 layerB->addChild(MockLayer::create(&layerImplDestructionList)); 264 layerB->addChild(MockLayer::create(&layerImplDestructionList));
277 scoped_refptr<Layer> layerD = layerB->children()[1].get(); 265 scoped_refptr<Layer> layerD = layerB->children()[1].get();
278 266
279 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl->activeTree()); 267 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (layerTreeRoot.get(), scoped_ptr<LayerImpl>(), m_hostImpl.activeTree());
280 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm pl->activeTree()); 268 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), m_host Impl.activeTree());
281 269
282 // Now restructure the tree to look like this: 270 // Now restructure the tree to look like this:
283 // root --- D ---+--- A 271 // root --- D ---+--- A
284 // | 272 // |
285 // +--- C --- B 273 // +--- C --- B
286 layerTreeRoot->removeAllChildren(); 274 layerTreeRoot->removeAllChildren();
287 layerD->removeAllChildren(); 275 layerD->removeAllChildren();
288 layerTreeRoot->addChild(layerD); 276 layerTreeRoot->addChild(layerD);
289 layerA->removeAllChildren(); 277 layerA->removeAllChildren();
290 layerD->addChild(layerA); 278 layerD->addChild(layerA);
291 layerC->removeAllChildren(); 279 layerC->removeAllChildren();
292 layerD->addChild(layerC); 280 layerD->addChild(layerC);
293 layerB->removeAllChildren(); 281 layerB->removeAllChildren();
294 layerC->addChild(layerB); 282 layerC->addChild(layerB);
295 283
296 // After another synchronize our trees should match and we should not have d estroyed any LayerImpls 284 // 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->activeTree()); 285 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), m_hostImpl.activeTree());
298 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm pl->activeTree()); 286 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), m_host Impl.activeTree());
299 287
300 EXPECT_EQ(0u, layerImplDestructionList.size()); 288 EXPECT_EQ(0u, layerImplDestructionList.size());
301 } 289 }
302 290
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. 291 // 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) 292 TEST_F(TreeSynchronizerTest, syncSimpleTreeThenDestroy)
305 { 293 {
306 std::vector<int> layerImplDestructionList; 294 std::vector<int> layerImplDestructionList;
307 295
308 LayerTreeSettings settings;
309 FakeProxy proxy(scoped_ptr<Thread>(NULL));
310 DebugScopedSetImplThread impl(&proxy);
311 scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0, &proxy);
312
313 scoped_refptr<Layer> oldLayerTreeRoot = MockLayer::create(&layerImplDestruct ionList); 296 scoped_refptr<Layer> oldLayerTreeRoot = MockLayer::create(&layerImplDestruct ionList);
314 oldLayerTreeRoot->addChild(MockLayer::create(&layerImplDestructionList)); 297 oldLayerTreeRoot->addChild(MockLayer::create(&layerImplDestructionList));
315 oldLayerTreeRoot->addChild(MockLayer::create(&layerImplDestructionList)); 298 oldLayerTreeRoot->addChild(MockLayer::create(&layerImplDestructionList));
316 299
317 int oldTreeRootLayerId = oldLayerTreeRoot->id(); 300 int oldTreeRootLayerId = oldLayerTreeRoot->id();
318 int oldTreeFirstChildLayerId = oldLayerTreeRoot->children()[0]->id(); 301 int oldTreeFirstChildLayerId = oldLayerTreeRoot->children()[0]->id();
319 int oldTreeSecondChildLayerId = oldLayerTreeRoot->children()[1]->id(); 302 int oldTreeSecondChildLayerId = oldLayerTreeRoot->children()[1]->id();
320 303
321 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (oldLayerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl->activeTree()); 304 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (oldLayerTreeRoot.get(), scoped_ptr<LayerImpl>(), m_hostImpl.activeTree());
322 expectTreesAreIdentical(oldLayerTreeRoot.get(), layerImplTreeRoot.get(), hos tImpl->activeTree()); 305 expectTreesAreIdentical(oldLayerTreeRoot.get(), layerImplTreeRoot.get(), m_h ostImpl.activeTree());
323 306
324 // Remove all children on the Layer side. 307 // Remove all children on the Layer side.
325 oldLayerTreeRoot->removeAllChildren(); 308 oldLayerTreeRoot->removeAllChildren();
326 309
327 // Synchronize again. After the sync all LayerImpls from the old tree should be deleted. 310 // Synchronize again. After the sync all LayerImpls from the old tree should be deleted.
328 scoped_refptr<Layer> newLayerTreeRoot = Layer::create(); 311 scoped_refptr<Layer> newLayerTreeRoot = Layer::create();
329 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(newLayerTreeRoot.get( ), layerImplTreeRoot.Pass(), hostImpl->activeTree()); 312 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(newLayerTreeRoot.get( ), layerImplTreeRoot.Pass(), m_hostImpl.activeTree());
330 expectTreesAreIdentical(newLayerTreeRoot.get(), layerImplTreeRoot.get(), hos tImpl->activeTree()); 313 expectTreesAreIdentical(newLayerTreeRoot.get(), layerImplTreeRoot.get(), m_h ostImpl.activeTree());
331 314
332 ASSERT_EQ(3u, layerImplDestructionList.size()); 315 ASSERT_EQ(3u, layerImplDestructionList.size());
333 316
334 EXPECT_TRUE(std::find(layerImplDestructionList.begin(), layerImplDestruction List.end(), oldTreeRootLayerId) != layerImplDestructionList.end()); 317 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()); 318 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()); 319 EXPECT_TRUE(std::find(layerImplDestructionList.begin(), layerImplDestruction List.end(), oldTreeSecondChildLayerId) != layerImplDestructionList.end());
337 } 320 }
338 321
339 // Constructs+syncs a tree with mask, replica, and replica mask layers. 322 // Constructs+syncs a tree with mask, replica, and replica mask layers.
340 TEST(TreeSynchronizerTest, syncMaskReplicaAndReplicaMaskLayers) 323 TEST_F(TreeSynchronizerTest, syncMaskReplicaAndReplicaMaskLayers)
341 { 324 {
342 LayerTreeSettings settings;
343 FakeProxy proxy(scoped_ptr<Thread>(NULL));
344 DebugScopedSetImplThread impl(&proxy);
345 scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0, &proxy);
346
347 scoped_refptr<Layer> layerTreeRoot = Layer::create(); 325 scoped_refptr<Layer> layerTreeRoot = Layer::create();
348 layerTreeRoot->addChild(Layer::create()); 326 layerTreeRoot->addChild(Layer::create());
349 layerTreeRoot->addChild(Layer::create()); 327 layerTreeRoot->addChild(Layer::create());
350 layerTreeRoot->addChild(Layer::create()); 328 layerTreeRoot->addChild(Layer::create());
351 329
352 // First child gets a mask layer. 330 // First child gets a mask layer.
353 scoped_refptr<Layer> maskLayer = Layer::create(); 331 scoped_refptr<Layer> maskLayer = Layer::create();
354 layerTreeRoot->children()[0]->setMaskLayer(maskLayer.get()); 332 layerTreeRoot->children()[0]->setMaskLayer(maskLayer.get());
355 333
356 // Second child gets a replica layer. 334 // Second child gets a replica layer.
357 scoped_refptr<Layer> replicaLayer = Layer::create(); 335 scoped_refptr<Layer> replicaLayer = Layer::create();
358 layerTreeRoot->children()[1]->setReplicaLayer(replicaLayer.get()); 336 layerTreeRoot->children()[1]->setReplicaLayer(replicaLayer.get());
359 337
360 // Third child gets a replica layer with a mask layer. 338 // Third child gets a replica layer with a mask layer.
361 scoped_refptr<Layer> replicaLayerWithMask = Layer::create(); 339 scoped_refptr<Layer> replicaLayerWithMask = Layer::create();
362 scoped_refptr<Layer> replicaMaskLayer = Layer::create(); 340 scoped_refptr<Layer> replicaMaskLayer = Layer::create();
363 replicaLayerWithMask->setMaskLayer(replicaMaskLayer.get()); 341 replicaLayerWithMask->setMaskLayer(replicaMaskLayer.get());
364 layerTreeRoot->children()[2]->setReplicaLayer(replicaLayerWithMask.get()); 342 layerTreeRoot->children()[2]->setReplicaLayer(replicaLayerWithMask.get());
365 343
366 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl->activeTree()); 344 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (layerTreeRoot.get(), scoped_ptr<LayerImpl>(), m_hostImpl.activeTree());
367 345
368 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm pl->activeTree()); 346 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), m_host Impl.activeTree());
369 347
370 // Remove the mask layer. 348 // Remove the mask layer.
371 layerTreeRoot->children()[0]->setMaskLayer(0); 349 layerTreeRoot->children()[0]->setMaskLayer(0);
372 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), hostImpl->activeTree()); 350 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), m_hostImpl.activeTree());
373 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm pl->activeTree()); 351 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), m_host Impl.activeTree());
374 352
375 // Remove the replica layer. 353 // Remove the replica layer.
376 layerTreeRoot->children()[1]->setReplicaLayer(0); 354 layerTreeRoot->children()[1]->setReplicaLayer(0);
377 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), hostImpl->activeTree()); 355 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), m_hostImpl.activeTree());
378 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm pl->activeTree()); 356 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), m_host Impl.activeTree());
379 357
380 // Remove the replica mask. 358 // Remove the replica mask.
381 replicaLayerWithMask->setMaskLayer(0); 359 replicaLayerWithMask->setMaskLayer(0);
382 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), hostImpl->activeTree()); 360 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), m_hostImpl.activeTree());
383 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm pl->activeTree()); 361 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), m_host Impl.activeTree());
384 } 362 }
385 363
386 TEST(TreeSynchronizerTest, synchronizeAnimations) 364 TEST_F(TreeSynchronizerTest, synchronizeAnimations)
387 { 365 {
388 LayerTreeSettings settings; 366 LayerTreeSettings settings;
389 FakeProxy proxy(scoped_ptr<Thread>(NULL)); 367 FakeProxy proxy(scoped_ptr<Thread>(NULL));
390 DebugScopedSetImplThread impl(&proxy); 368 DebugScopedSetImplThread impl(&proxy);
391 scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0, &proxy); 369 scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0, &proxy);
392 370
393 scoped_refptr<Layer> layerTreeRoot = Layer::create(); 371 scoped_refptr<Layer> layerTreeRoot = Layer::create();
394 372
395 FakeLayerAnimationControllerClient dummy; 373 FakeLayerAnimationControllerClient dummy;
396 layerTreeRoot->setLayerAnimationController(FakeLayerAnimationController::cre ate(&dummy).PassAs<LayerAnimationController>()); 374 layerTreeRoot->setLayerAnimationController(FakeLayerAnimationController::cre ate(&dummy).PassAs<LayerAnimationController>());
397 375
398 EXPECT_FALSE(static_cast<FakeLayerAnimationController*>(layerTreeRoot->layer AnimationController())->synchronizedAnimations()); 376 EXPECT_FALSE(static_cast<FakeLayerAnimationController*>(layerTreeRoot->layer AnimationController())->synchronizedAnimations());
399 377
400 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl->activeTree()); 378 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (layerTreeRoot.get(), scoped_ptr<LayerImpl>(), m_hostImpl.activeTree());
401 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), hostImpl->activeTree()); 379 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), m_hostImpl.activeTree());
402 380
403 EXPECT_TRUE(static_cast<FakeLayerAnimationController*>(layerTreeRoot->layerA nimationController())->synchronizedAnimations()); 381 EXPECT_TRUE(static_cast<FakeLayerAnimationController*>(layerTreeRoot->layerA nimationController())->synchronizedAnimations());
404 } 382 }
405 383
406 } // namespace 384 } // namespace
407 } // namespace cc 385 } // namespace cc
OLDNEW
« no previous file with comments | « cc/tree_synchronizer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698