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

Side by Side Diff: cc/tree_synchronizer_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/tree_synchronizer.cc ('k') | cc/video_layer.h » ('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 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_impl_proxy.h" 15 #include "cc/test/fake_impl_proxy.h"
16 #include "cc/test/fake_layer_tree_host_impl.h" 16 #include "cc/test/fake_layer_tree_host_impl.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 18
19 namespace cc { 19 namespace cc {
20 namespace { 20 namespace {
21 21
22 class MockLayerImpl : public LayerImpl { 22 class MockLayerImpl : public LayerImpl {
23 public: 23 public:
24 static scoped_ptr<MockLayerImpl> create(LayerTreeImpl* treeImpl, int layerId ) 24 static scoped_ptr<MockLayerImpl> Create(LayerTreeImpl* treeImpl, int layerId )
25 { 25 {
26 return make_scoped_ptr(new MockLayerImpl(treeImpl, layerId)); 26 return make_scoped_ptr(new MockLayerImpl(treeImpl, layerId));
27 } 27 }
28 virtual ~MockLayerImpl() 28 virtual ~MockLayerImpl()
29 { 29 {
30 if (m_layerImplDestructionList) 30 if (m_layerImplDestructionList)
31 m_layerImplDestructionList->push_back(id()); 31 m_layerImplDestructionList->push_back(id());
32 } 32 }
33 33
34 void setLayerImplDestructionList(std::vector<int>* list) { m_layerImplDestru ctionList = list; } 34 void setLayerImplDestructionList(std::vector<int>* list) { m_layerImplDestru ctionList = list; }
35 35
36 private: 36 private:
37 MockLayerImpl(LayerTreeImpl* treeImpl, int layerId) 37 MockLayerImpl(LayerTreeImpl* treeImpl, int layerId)
38 : LayerImpl(treeImpl, layerId) 38 : LayerImpl(treeImpl, layerId)
39 , m_layerImplDestructionList(0) 39 , m_layerImplDestructionList(0)
40 { 40 {
41 } 41 }
42 42
43 std::vector<int>* m_layerImplDestructionList; 43 std::vector<int>* m_layerImplDestructionList;
44 }; 44 };
45 45
46 class MockLayer : public Layer { 46 class MockLayer : public Layer {
47 public: 47 public:
48 static scoped_refptr<MockLayer> create(std::vector<int>* layerImplDestructio nList) 48 static scoped_refptr<MockLayer> Create(std::vector<int>* layerImplDestructio nList)
49 { 49 {
50 return make_scoped_refptr(new MockLayer(layerImplDestructionList)); 50 return make_scoped_refptr(new MockLayer(layerImplDestructionList));
51 } 51 }
52 52
53 virtual scoped_ptr<LayerImpl> createLayerImpl(LayerTreeImpl* treeImpl) OVERR IDE 53 virtual scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* treeImpl) OVERR IDE
54 { 54 {
55 return MockLayerImpl::create(treeImpl, m_layerId).PassAs<LayerImpl>(); 55 return MockLayerImpl::Create(treeImpl, layer_id_).PassAs<LayerImpl>();
56 } 56 }
57 57
58 virtual void pushPropertiesTo(LayerImpl* layerImpl) OVERRIDE 58 virtual void PushPropertiesTo(LayerImpl* layerImpl) OVERRIDE
59 { 59 {
60 Layer::pushPropertiesTo(layerImpl); 60 Layer::PushPropertiesTo(layerImpl);
61 61
62 MockLayerImpl* mockLayerImpl = static_cast<MockLayerImpl*>(layerImpl); 62 MockLayerImpl* mockLayerImpl = static_cast<MockLayerImpl*>(layerImpl);
63 mockLayerImpl->setLayerImplDestructionList(m_layerImplDestructionList); 63 mockLayerImpl->setLayerImplDestructionList(m_layerImplDestructionList);
64 } 64 }
65 65
66 private: 66 private:
67 MockLayer(std::vector<int>* layerImplDestructionList) 67 MockLayer(std::vector<int>* layerImplDestructionList)
68 : Layer() 68 : Layer()
69 , m_layerImplDestructionList(layerImplDestructionList) 69 , m_layerImplDestructionList(layerImplDestructionList)
70 { 70 {
71 } 71 }
72 virtual ~MockLayer() { } 72 virtual ~MockLayer() { }
73 73
74 std::vector<int>* m_layerImplDestructionList; 74 std::vector<int>* m_layerImplDestructionList;
75 }; 75 };
76 76
77 class FakeLayerAnimationController : public LayerAnimationController { 77 class FakeLayerAnimationController : public LayerAnimationController {
78 public: 78 public:
79 static scoped_refptr<LayerAnimationController> create() 79 static scoped_refptr<LayerAnimationController> Create()
80 { 80 {
81 return static_cast<LayerAnimationController*>(new FakeLayerAnimationCont roller); 81 return static_cast<LayerAnimationController*>(new FakeLayerAnimationCont roller);
82 } 82 }
83 83
84 bool synchronizedAnimations() const { return m_synchronizedAnimations; } 84 bool synchronizedAnimations() const { return m_synchronizedAnimations; }
85 85
86 private: 86 private:
87 FakeLayerAnimationController() 87 FakeLayerAnimationController()
88 : LayerAnimationController(1) 88 : LayerAnimationController(1)
89 , m_synchronizedAnimations(false) 89 , m_synchronizedAnimations(false)
90 { } 90 { }
91 91
92 virtual ~FakeLayerAnimationController() { } 92 virtual ~FakeLayerAnimationController() { }
93 93
94 virtual void PushAnimationUpdatesTo(LayerAnimationController* controllerImpl ) OVERRIDE 94 virtual void PushAnimationUpdatesTo(LayerAnimationController* controllerImpl ) OVERRIDE
95 { 95 {
96 LayerAnimationController::PushAnimationUpdatesTo(controllerImpl); 96 LayerAnimationController::PushAnimationUpdatesTo(controllerImpl);
97 m_synchronizedAnimations = true; 97 m_synchronizedAnimations = true;
98 } 98 }
99 99
100 bool m_synchronizedAnimations; 100 bool m_synchronizedAnimations;
101 }; 101 };
102 102
103 void expectTreesAreIdentical(Layer* layer, LayerImpl* layerImpl, LayerTreeImpl* treeImpl) 103 void expectTreesAreIdentical(Layer* layer, LayerImpl* layerImpl, LayerTreeImpl* treeImpl)
104 { 104 {
105 ASSERT_TRUE(layer); 105 ASSERT_TRUE(layer);
106 ASSERT_TRUE(layerImpl); 106 ASSERT_TRUE(layerImpl);
107 107
108 EXPECT_EQ(layer->id(), layerImpl->id()); 108 EXPECT_EQ(layer->id(), layerImpl->id());
109 EXPECT_EQ(layerImpl->layerTreeImpl(), treeImpl); 109 EXPECT_EQ(layerImpl->layer_tree_impl(), treeImpl);
110 110
111 EXPECT_EQ(layer->nonFastScrollableRegion(), layerImpl->nonFastScrollableRegi on()); 111 EXPECT_EQ(layer->non_fast_scrollable_region(), layerImpl->non_fast_scrollabl e_region());
112 112
113 ASSERT_EQ(!!layer->maskLayer(), !!layerImpl->maskLayer()); 113 ASSERT_EQ(!!layer->mask_layer(), !!layerImpl->mask_layer());
114 if (layer->maskLayer()) 114 if (layer->mask_layer())
115 expectTreesAreIdentical(layer->maskLayer(), layerImpl->maskLayer(), tree Impl); 115 expectTreesAreIdentical(layer->mask_layer(), layerImpl->mask_layer(), tr eeImpl);
116 116
117 ASSERT_EQ(!!layer->replicaLayer(), !!layerImpl->replicaLayer()); 117 ASSERT_EQ(!!layer->replica_layer(), !!layerImpl->replica_layer());
118 if (layer->replicaLayer()) 118 if (layer->replica_layer())
119 expectTreesAreIdentical(layer->replicaLayer(), layerImpl->replicaLayer() , treeImpl); 119 expectTreesAreIdentical(layer->replica_layer(), layerImpl->replica_layer (), treeImpl);
120 120
121 const std::vector<scoped_refptr<Layer> >& layerChildren = layer->children(); 121 const std::vector<scoped_refptr<Layer> >& layerChildren = layer->children();
122 const ScopedPtrVector<LayerImpl>& layerImplChildren = layerImpl->children(); 122 const ScopedPtrVector<LayerImpl>& layerImplChildren = layerImpl->children();
123 123
124 ASSERT_EQ(layerChildren.size(), layerImplChildren.size()); 124 ASSERT_EQ(layerChildren.size(), layerImplChildren.size());
125 125
126 for (size_t i = 0; i < layerChildren.size(); ++i) 126 for (size_t i = 0; i < layerChildren.size(); ++i)
127 expectTreesAreIdentical(layerChildren[i].get(), layerImplChildren[i], tr eeImpl); 127 expectTreesAreIdentical(layerChildren[i].get(), layerImplChildren[i], tr eeImpl);
128 } 128 }
129 129
(...skipping 14 matching lines...) Expand all
144 TEST_F(TreeSynchronizerTest, syncNullTree) 144 TEST_F(TreeSynchronizerTest, syncNullTree)
145 { 145 {
146 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (static_cast<Layer*>(NULL), scoped_ptr<LayerImpl>(), m_hostImpl.activeTree()); 146 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (static_cast<Layer*>(NULL), scoped_ptr<LayerImpl>(), m_hostImpl.activeTree());
147 147
148 EXPECT_TRUE(!layerImplTreeRoot.get()); 148 EXPECT_TRUE(!layerImplTreeRoot.get());
149 } 149 }
150 150
151 // Constructs a very simple tree and synchronizes it without trying to reuse any preexisting layers. 151 // Constructs a very simple tree and synchronizes it without trying to reuse any preexisting layers.
152 TEST_F(TreeSynchronizerTest, syncSimpleTreeFromEmpty) 152 TEST_F(TreeSynchronizerTest, syncSimpleTreeFromEmpty)
153 { 153 {
154 scoped_refptr<Layer> layerTreeRoot = Layer::create(); 154 scoped_refptr<Layer> layerTreeRoot = Layer::Create();
155 layerTreeRoot->addChild(Layer::create()); 155 layerTreeRoot->AddChild(Layer::Create());
156 layerTreeRoot->addChild(Layer::create()); 156 layerTreeRoot->AddChild(Layer::Create());
157 157
158 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (layerTreeRoot.get(), scoped_ptr<LayerImpl>(), m_hostImpl.activeTree()); 158 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (layerTreeRoot.get(), scoped_ptr<LayerImpl>(), m_hostImpl.activeTree());
159 159
160 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), m_host Impl.activeTree()); 160 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), m_host Impl.activeTree());
161 } 161 }
162 162
163 // Constructs a very simple tree and synchronizes it attempting to reuse some la yers 163 // Constructs a very simple tree and synchronizes it attempting to reuse some la yers
164 TEST_F(TreeSynchronizerTest, syncSimpleTreeReusingLayers) 164 TEST_F(TreeSynchronizerTest, syncSimpleTreeReusingLayers)
165 { 165 {
166 std::vector<int> layerImplDestructionList; 166 std::vector<int> layerImplDestructionList;
167 167
168 scoped_refptr<Layer> layerTreeRoot = MockLayer::create(&layerImplDestruction List); 168 scoped_refptr<Layer> layerTreeRoot = MockLayer::Create(&layerImplDestruction List);
169 layerTreeRoot->addChild(MockLayer::create(&layerImplDestructionList)); 169 layerTreeRoot->AddChild(MockLayer::Create(&layerImplDestructionList));
170 layerTreeRoot->addChild(MockLayer::create(&layerImplDestructionList)); 170 layerTreeRoot->AddChild(MockLayer::Create(&layerImplDestructionList));
171 171
172 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (layerTreeRoot.get(), scoped_ptr<LayerImpl>(), m_hostImpl.activeTree()); 172 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (layerTreeRoot.get(), scoped_ptr<LayerImpl>(), m_hostImpl.activeTree());
173 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), m_host Impl.activeTree()); 173 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), m_host Impl.activeTree());
174 174
175 // We have to push properties to pick up the destruction list pointer. 175 // We have to push properties to pick up the destruction list pointer.
176 TreeSynchronizer::pushProperties(layerTreeRoot.get(), layerImplTreeRoot.get( )); 176 TreeSynchronizer::pushProperties(layerTreeRoot.get(), layerImplTreeRoot.get( ));
177 177
178 // Add a new layer to the Layer side 178 // Add a new layer to the Layer side
179 layerTreeRoot->children()[0]->addChild(MockLayer::create(&layerImplDestructi onList)); 179 layerTreeRoot->children()[0]->AddChild(MockLayer::Create(&layerImplDestructi onList));
180 // Remove one. 180 // Remove one.
181 layerTreeRoot->children()[1]->removeFromParent(); 181 layerTreeRoot->children()[1]->RemoveFromParent();
182 int secondLayerImplId = layerImplTreeRoot->children()[1]->id(); 182 int secondLayerImplId = layerImplTreeRoot->children()[1]->id();
183 183
184 // Synchronize again. After the sync the trees should be equivalent and we s hould have created and destroyed one LayerImpl. 184 // Synchronize again. After the sync the trees should be equivalent and we s hould have created and destroyed one LayerImpl.
185 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), m_hostImpl.activeTree()); 185 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), m_hostImpl.activeTree());
186 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), m_host Impl.activeTree()); 186 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), m_host Impl.activeTree());
187 187
188 ASSERT_EQ(1u, layerImplDestructionList.size()); 188 ASSERT_EQ(1u, layerImplDestructionList.size());
189 EXPECT_EQ(secondLayerImplId, layerImplDestructionList[0]); 189 EXPECT_EQ(secondLayerImplId, layerImplDestructionList[0]);
190 } 190 }
191 191
192 // Constructs a very simple tree and checks that a stacking-order change is trac ked properly. 192 // Constructs a very simple tree and checks that a stacking-order change is trac ked properly.
193 TEST_F(TreeSynchronizerTest, syncSimpleTreeAndTrackStackingOrderChange) 193 TEST_F(TreeSynchronizerTest, syncSimpleTreeAndTrackStackingOrderChange)
194 { 194 {
195 std::vector<int> layerImplDestructionList; 195 std::vector<int> layerImplDestructionList;
196 196
197 // Set up the tree and sync once. child2 needs to be synced here, too, even though we 197 // Set up the tree and sync once. child2 needs to be synced here, too, even though we
198 // remove it to set up the intended scenario. 198 // remove it to set up the intended scenario.
199 scoped_refptr<Layer> layerTreeRoot = MockLayer::create(&layerImplDestruction List); 199 scoped_refptr<Layer> layerTreeRoot = MockLayer::Create(&layerImplDestruction List);
200 scoped_refptr<Layer> child2 = MockLayer::create(&layerImplDestructionList); 200 scoped_refptr<Layer> child2 = MockLayer::Create(&layerImplDestructionList);
201 layerTreeRoot->addChild(MockLayer::create(&layerImplDestructionList)); 201 layerTreeRoot->AddChild(MockLayer::Create(&layerImplDestructionList));
202 layerTreeRoot->addChild(child2); 202 layerTreeRoot->AddChild(child2);
203 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (layerTreeRoot.get(), scoped_ptr<LayerImpl>(), m_hostImpl.activeTree()); 203 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (layerTreeRoot.get(), scoped_ptr<LayerImpl>(), m_hostImpl.activeTree());
204 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), m_host Impl.activeTree()); 204 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), m_host Impl.activeTree());
205 205
206 // We have to push properties to pick up the destruction list pointer. 206 // We have to push properties to pick up the destruction list pointer.
207 TreeSynchronizer::pushProperties(layerTreeRoot.get(), layerImplTreeRoot.get( )); 207 TreeSynchronizer::pushProperties(layerTreeRoot.get(), layerImplTreeRoot.get( ));
208 208
209 layerImplTreeRoot->resetAllChangeTrackingForSubtree(); 209 layerImplTreeRoot->ResetAllChangeTrackingForSubtree();
210 210
211 // re-insert the layer and sync again. 211 // re-insert the layer and sync again.
212 child2->removeFromParent(); 212 child2->RemoveFromParent();
213 layerTreeRoot->addChild(child2); 213 layerTreeRoot->AddChild(child2);
214 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), m_hostImpl.activeTree()); 214 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), m_hostImpl.activeTree());
215 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), m_host Impl.activeTree()); 215 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), m_host Impl.activeTree());
216 216
217 TreeSynchronizer::pushProperties(layerTreeRoot.get(), layerImplTreeRoot.get( )); 217 TreeSynchronizer::pushProperties(layerTreeRoot.get(), layerImplTreeRoot.get( ));
218 218
219 // Check that the impl thread properly tracked the change. 219 // Check that the impl thread properly tracked the change.
220 EXPECT_FALSE(layerImplTreeRoot->layerPropertyChanged()); 220 EXPECT_FALSE(layerImplTreeRoot->LayerPropertyChanged());
221 EXPECT_FALSE(layerImplTreeRoot->children()[0]->layerPropertyChanged()); 221 EXPECT_FALSE(layerImplTreeRoot->children()[0]->LayerPropertyChanged());
222 EXPECT_TRUE(layerImplTreeRoot->children()[1]->layerPropertyChanged()); 222 EXPECT_TRUE(layerImplTreeRoot->children()[1]->LayerPropertyChanged());
223 } 223 }
224 224
225 TEST_F(TreeSynchronizerTest, syncSimpleTreeAndProperties) 225 TEST_F(TreeSynchronizerTest, syncSimpleTreeAndProperties)
226 { 226 {
227 scoped_refptr<Layer> layerTreeRoot = Layer::create(); 227 scoped_refptr<Layer> layerTreeRoot = Layer::Create();
228 layerTreeRoot->addChild(Layer::create()); 228 layerTreeRoot->AddChild(Layer::Create());
229 layerTreeRoot->addChild(Layer::create()); 229 layerTreeRoot->AddChild(Layer::Create());
230 230
231 // 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. 231 // 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.
232 gfx::PointF rootPosition = gfx::PointF(2.3f, 7.4f); 232 gfx::PointF rootPosition = gfx::PointF(2.3f, 7.4f);
233 layerTreeRoot->setPosition(rootPosition); 233 layerTreeRoot->SetPosition(rootPosition);
234 234
235 float firstChildOpacity = 0.25f; 235 float firstChildOpacity = 0.25f;
236 layerTreeRoot->children()[0]->setOpacity(firstChildOpacity); 236 layerTreeRoot->children()[0]->SetOpacity(firstChildOpacity);
237 237
238 gfx::Size secondChildBounds = gfx::Size(25, 53); 238 gfx::Size secondChildBounds = gfx::Size(25, 53);
239 layerTreeRoot->children()[1]->setBounds(secondChildBounds); 239 layerTreeRoot->children()[1]->SetBounds(secondChildBounds);
240 240
241 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (layerTreeRoot.get(), scoped_ptr<LayerImpl>(), m_hostImpl.activeTree()); 241 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (layerTreeRoot.get(), scoped_ptr<LayerImpl>(), m_hostImpl.activeTree());
242 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), m_host Impl.activeTree()); 242 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), m_host Impl.activeTree());
243 243
244 TreeSynchronizer::pushProperties(layerTreeRoot.get(), layerImplTreeRoot.get( )); 244 TreeSynchronizer::pushProperties(layerTreeRoot.get(), layerImplTreeRoot.get( ));
245 245
246 // Check that the property values we set on the Layer tree are reflected in the LayerImpl tree. 246 // Check that the property values we set on the Layer tree are reflected in the LayerImpl tree.
247 gfx::PointF rootLayerImplPosition = layerImplTreeRoot->position(); 247 gfx::PointF rootLayerImplPosition = layerImplTreeRoot->position();
248 EXPECT_EQ(rootPosition.x(), rootLayerImplPosition.x()); 248 EXPECT_EQ(rootPosition.x(), rootLayerImplPosition.x());
249 EXPECT_EQ(rootPosition.y(), rootLayerImplPosition.y()); 249 EXPECT_EQ(rootPosition.y(), rootLayerImplPosition.y());
250 250
251 EXPECT_EQ(firstChildOpacity, layerImplTreeRoot->children()[0]->opacity()); 251 EXPECT_EQ(firstChildOpacity, layerImplTreeRoot->children()[0]->opacity());
252 252
253 gfx::Size secondLayerImplChildBounds = layerImplTreeRoot->children()[1]->bou nds(); 253 gfx::Size secondLayerImplChildBounds = layerImplTreeRoot->children()[1]->bou nds();
254 EXPECT_EQ(secondChildBounds.width(), secondLayerImplChildBounds.width()); 254 EXPECT_EQ(secondChildBounds.width(), secondLayerImplChildBounds.width());
255 EXPECT_EQ(secondChildBounds.height(), secondLayerImplChildBounds.height()); 255 EXPECT_EQ(secondChildBounds.height(), secondLayerImplChildBounds.height());
256 } 256 }
257 257
258 TEST_F(TreeSynchronizerTest, reuseLayerImplsAfterStructuralChange) 258 TEST_F(TreeSynchronizerTest, reuseLayerImplsAfterStructuralChange)
259 { 259 {
260 std::vector<int> layerImplDestructionList; 260 std::vector<int> layerImplDestructionList;
261 261
262 // Set up a tree with this sort of structure: 262 // Set up a tree with this sort of structure:
263 // root --- A --- B ---+--- C 263 // root --- A --- B ---+--- C
264 // | 264 // |
265 // +--- D 265 // +--- D
266 scoped_refptr<Layer> layerTreeRoot = MockLayer::create(&layerImplDestruction List); 266 scoped_refptr<Layer> layerTreeRoot = MockLayer::Create(&layerImplDestruction List);
267 layerTreeRoot->addChild(MockLayer::create(&layerImplDestructionList)); 267 layerTreeRoot->AddChild(MockLayer::Create(&layerImplDestructionList));
268 268
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>(), m_hostImpl.activeTree()); 279 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (layerTreeRoot.get(), scoped_ptr<LayerImpl>(), m_hostImpl.activeTree());
280 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), m_host Impl.activeTree()); 280 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), m_host Impl.activeTree());
281 281
282 // We have to push properties to pick up the destruction list pointer. 282 // We have to push properties to pick up the destruction list pointer.
283 TreeSynchronizer::pushProperties(layerTreeRoot.get(), layerImplTreeRoot.get( )); 283 TreeSynchronizer::pushProperties(layerTreeRoot.get(), layerImplTreeRoot.get( ));
284 284
285 // Now restructure the tree to look like this: 285 // Now restructure the tree to look like this:
286 // root --- D ---+--- A 286 // root --- D ---+--- A
287 // | 287 // |
288 // +--- C --- B 288 // +--- C --- B
289 layerTreeRoot->removeAllChildren(); 289 layerTreeRoot->RemoveAllChildren();
290 layerD->removeAllChildren(); 290 layerD->RemoveAllChildren();
291 layerTreeRoot->addChild(layerD); 291 layerTreeRoot->AddChild(layerD);
292 layerA->removeAllChildren(); 292 layerA->RemoveAllChildren();
293 layerD->addChild(layerA); 293 layerD->AddChild(layerA);
294 layerC->removeAllChildren(); 294 layerC->RemoveAllChildren();
295 layerD->addChild(layerC); 295 layerD->AddChild(layerC);
296 layerB->removeAllChildren(); 296 layerB->RemoveAllChildren();
297 layerC->addChild(layerB); 297 layerC->AddChild(layerB);
298 298
299 // After another synchronize our trees should match and we should not have d estroyed any LayerImpls 299 // After another synchronize our trees should match and we should not have d estroyed any LayerImpls
300 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), m_hostImpl.activeTree()); 300 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), m_hostImpl.activeTree());
301 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), m_host Impl.activeTree()); 301 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), m_host Impl.activeTree());
302 302
303 EXPECT_EQ(0u, layerImplDestructionList.size()); 303 EXPECT_EQ(0u, layerImplDestructionList.size());
304 } 304 }
305 305
306 // Constructs a very simple tree, synchronizes it, then synchronizes to a totall y new tree. All layers from the old tree should be deleted. 306 // Constructs a very simple tree, synchronizes it, then synchronizes to a totall y new tree. All layers from the old tree should be deleted.
307 TEST_F(TreeSynchronizerTest, syncSimpleTreeThenDestroy) 307 TEST_F(TreeSynchronizerTest, syncSimpleTreeThenDestroy)
308 { 308 {
309 std::vector<int> layerImplDestructionList; 309 std::vector<int> layerImplDestructionList;
310 310
311 scoped_refptr<Layer> oldLayerTreeRoot = MockLayer::create(&layerImplDestruct ionList); 311 scoped_refptr<Layer> oldLayerTreeRoot = MockLayer::Create(&layerImplDestruct ionList);
312 oldLayerTreeRoot->addChild(MockLayer::create(&layerImplDestructionList)); 312 oldLayerTreeRoot->AddChild(MockLayer::Create(&layerImplDestructionList));
313 oldLayerTreeRoot->addChild(MockLayer::create(&layerImplDestructionList)); 313 oldLayerTreeRoot->AddChild(MockLayer::Create(&layerImplDestructionList));
314 314
315 int oldTreeRootLayerId = oldLayerTreeRoot->id(); 315 int oldTreeRootLayerId = oldLayerTreeRoot->id();
316 int oldTreeFirstChildLayerId = oldLayerTreeRoot->children()[0]->id(); 316 int oldTreeFirstChildLayerId = oldLayerTreeRoot->children()[0]->id();
317 int oldTreeSecondChildLayerId = oldLayerTreeRoot->children()[1]->id(); 317 int oldTreeSecondChildLayerId = oldLayerTreeRoot->children()[1]->id();
318 318
319 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (oldLayerTreeRoot.get(), scoped_ptr<LayerImpl>(), m_hostImpl.activeTree()); 319 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (oldLayerTreeRoot.get(), scoped_ptr<LayerImpl>(), m_hostImpl.activeTree());
320 expectTreesAreIdentical(oldLayerTreeRoot.get(), layerImplTreeRoot.get(), m_h ostImpl.activeTree()); 320 expectTreesAreIdentical(oldLayerTreeRoot.get(), layerImplTreeRoot.get(), m_h ostImpl.activeTree());
321 321
322 // We have to push properties to pick up the destruction list pointer. 322 // We have to push properties to pick up the destruction list pointer.
323 TreeSynchronizer::pushProperties(oldLayerTreeRoot.get(), layerImplTreeRoot.g et()); 323 TreeSynchronizer::pushProperties(oldLayerTreeRoot.get(), layerImplTreeRoot.g et());
324 324
325 // Remove all children on the Layer side. 325 // Remove all children on the Layer side.
326 oldLayerTreeRoot->removeAllChildren(); 326 oldLayerTreeRoot->RemoveAllChildren();
327 327
328 // Synchronize again. After the sync all LayerImpls from the old tree should be deleted. 328 // Synchronize again. After the sync all LayerImpls from the old tree should be deleted.
329 scoped_refptr<Layer> newLayerTreeRoot = Layer::create(); 329 scoped_refptr<Layer> newLayerTreeRoot = Layer::Create();
330 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(newLayerTreeRoot.get( ), layerImplTreeRoot.Pass(), m_hostImpl.activeTree()); 330 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(newLayerTreeRoot.get( ), layerImplTreeRoot.Pass(), m_hostImpl.activeTree());
331 expectTreesAreIdentical(newLayerTreeRoot.get(), layerImplTreeRoot.get(), m_h ostImpl.activeTree()); 331 expectTreesAreIdentical(newLayerTreeRoot.get(), layerImplTreeRoot.get(), m_h ostImpl.activeTree());
332 332
333 ASSERT_EQ(3u, layerImplDestructionList.size()); 333 ASSERT_EQ(3u, layerImplDestructionList.size());
334 334
335 EXPECT_TRUE(std::find(layerImplDestructionList.begin(), layerImplDestruction List.end(), oldTreeRootLayerId) != layerImplDestructionList.end()); 335 EXPECT_TRUE(std::find(layerImplDestructionList.begin(), layerImplDestruction List.end(), oldTreeRootLayerId) != layerImplDestructionList.end());
336 EXPECT_TRUE(std::find(layerImplDestructionList.begin(), layerImplDestruction List.end(), oldTreeFirstChildLayerId) != layerImplDestructionList.end()); 336 EXPECT_TRUE(std::find(layerImplDestructionList.begin(), layerImplDestruction List.end(), oldTreeFirstChildLayerId) != layerImplDestructionList.end());
337 EXPECT_TRUE(std::find(layerImplDestructionList.begin(), layerImplDestruction List.end(), oldTreeSecondChildLayerId) != layerImplDestructionList.end()); 337 EXPECT_TRUE(std::find(layerImplDestructionList.begin(), layerImplDestruction List.end(), oldTreeSecondChildLayerId) != layerImplDestructionList.end());
338 } 338 }
339 339
340 // Constructs+syncs a tree with mask, replica, and replica mask layers. 340 // Constructs+syncs a tree with mask, replica, and replica mask layers.
341 TEST_F(TreeSynchronizerTest, syncMaskReplicaAndReplicaMaskLayers) 341 TEST_F(TreeSynchronizerTest, syncMaskReplicaAndReplicaMaskLayers)
342 { 342 {
343 scoped_refptr<Layer> layerTreeRoot = Layer::create(); 343 scoped_refptr<Layer> layerTreeRoot = Layer::Create();
344 layerTreeRoot->addChild(Layer::create()); 344 layerTreeRoot->AddChild(Layer::Create());
345 layerTreeRoot->addChild(Layer::create()); 345 layerTreeRoot->AddChild(Layer::Create());
346 layerTreeRoot->addChild(Layer::create()); 346 layerTreeRoot->AddChild(Layer::Create());
347 347
348 // First child gets a mask layer. 348 // First child gets a mask layer.
349 scoped_refptr<Layer> maskLayer = Layer::create(); 349 scoped_refptr<Layer> maskLayer = Layer::Create();
350 layerTreeRoot->children()[0]->setMaskLayer(maskLayer.get()); 350 layerTreeRoot->children()[0]->SetMaskLayer(maskLayer.get());
351 351
352 // Second child gets a replica layer. 352 // Second child gets a replica layer.
353 scoped_refptr<Layer> replicaLayer = Layer::create(); 353 scoped_refptr<Layer> replicaLayer = Layer::Create();
354 layerTreeRoot->children()[1]->setReplicaLayer(replicaLayer.get()); 354 layerTreeRoot->children()[1]->SetReplicaLayer(replicaLayer.get());
355 355
356 // Third child gets a replica layer with a mask layer. 356 // Third child gets a replica layer with a mask layer.
357 scoped_refptr<Layer> replicaLayerWithMask = Layer::create(); 357 scoped_refptr<Layer> replicaLayerWithMask = Layer::Create();
358 scoped_refptr<Layer> replicaMaskLayer = Layer::create(); 358 scoped_refptr<Layer> replicaMaskLayer = Layer::Create();
359 replicaLayerWithMask->setMaskLayer(replicaMaskLayer.get()); 359 replicaLayerWithMask->SetMaskLayer(replicaMaskLayer.get());
360 layerTreeRoot->children()[2]->setReplicaLayer(replicaLayerWithMask.get()); 360 layerTreeRoot->children()[2]->SetReplicaLayer(replicaLayerWithMask.get());
361 361
362 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (layerTreeRoot.get(), scoped_ptr<LayerImpl>(), m_hostImpl.activeTree()); 362 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (layerTreeRoot.get(), scoped_ptr<LayerImpl>(), m_hostImpl.activeTree());
363 363
364 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), m_host Impl.activeTree()); 364 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), m_host Impl.activeTree());
365 365
366 // Remove the mask layer. 366 // Remove the mask layer.
367 layerTreeRoot->children()[0]->setMaskLayer(0); 367 layerTreeRoot->children()[0]->SetMaskLayer(0);
368 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), m_hostImpl.activeTree()); 368 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), m_hostImpl.activeTree());
369 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), m_host Impl.activeTree()); 369 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), m_host Impl.activeTree());
370 370
371 // Remove the replica layer. 371 // Remove the replica layer.
372 layerTreeRoot->children()[1]->setReplicaLayer(0); 372 layerTreeRoot->children()[1]->SetReplicaLayer(0);
373 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), m_hostImpl.activeTree()); 373 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), m_hostImpl.activeTree());
374 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), m_host Impl.activeTree()); 374 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), m_host Impl.activeTree());
375 375
376 // Remove the replica mask. 376 // Remove the replica mask.
377 replicaLayerWithMask->setMaskLayer(0); 377 replicaLayerWithMask->SetMaskLayer(0);
378 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), m_hostImpl.activeTree()); 378 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), m_hostImpl.activeTree());
379 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), m_host Impl.activeTree()); 379 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), m_host Impl.activeTree());
380 } 380 }
381 381
382 TEST_F(TreeSynchronizerTest, synchronizeAnimations) 382 TEST_F(TreeSynchronizerTest, synchronizeAnimations)
383 { 383 {
384 LayerTreeSettings settings; 384 LayerTreeSettings settings;
385 FakeProxy proxy(scoped_ptr<Thread>(NULL)); 385 FakeProxy proxy(scoped_ptr<Thread>(NULL));
386 DebugScopedSetImplThread impl(&proxy); 386 DebugScopedSetImplThread impl(&proxy);
387 scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0, &proxy); 387 scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0, &proxy);
388 388
389 scoped_refptr<Layer> layerTreeRoot = Layer::create(); 389 scoped_refptr<Layer> layerTreeRoot = Layer::Create();
390 390
391 layerTreeRoot->setLayerAnimationController(FakeLayerAnimationController::cre ate()); 391 layerTreeRoot->SetLayerAnimationController(FakeLayerAnimationController::Cre ate());
392 392
393 EXPECT_FALSE(static_cast<FakeLayerAnimationController*>(layerTreeRoot->layer AnimationController())->synchronizedAnimations()); 393 EXPECT_FALSE(static_cast<FakeLayerAnimationController*>(layerTreeRoot->layer _animation_controller())->synchronizedAnimations());
394 394
395 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (layerTreeRoot.get(), scoped_ptr<LayerImpl>(), m_hostImpl.activeTree()); 395 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees (layerTreeRoot.get(), scoped_ptr<LayerImpl>(), m_hostImpl.activeTree());
396 TreeSynchronizer::pushProperties(layerTreeRoot.get(), layerImplTreeRoot.get( )); 396 TreeSynchronizer::pushProperties(layerTreeRoot.get(), layerImplTreeRoot.get( ));
397 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), m_hostImpl.activeTree()); 397 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), m_hostImpl.activeTree());
398 398
399 EXPECT_TRUE(static_cast<FakeLayerAnimationController*>(layerTreeRoot->layerA nimationController())->synchronizedAnimations()); 399 EXPECT_TRUE(static_cast<FakeLayerAnimationController*>(layerTreeRoot->layer_ animation_controller())->synchronizedAnimations());
400 } 400 }
401 401
402 } // namespace 402 } // namespace
403 } // namespace cc 403 } // namespace cc
OLDNEW
« no previous file with comments | « cc/tree_synchronizer.cc ('k') | cc/video_layer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698