| OLD | NEW |
| 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 "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "TreeSynchronizer.h" | 7 #include "TreeSynchronizer.h" |
| 8 | 8 |
| 9 #include "CCAnimationTestCommon.h" | 9 #include "CCAnimationTestCommon.h" |
| 10 #include "CCLayerAnimationController.h" | 10 #include "CCLayerAnimationController.h" |
| 11 #include "CCLayerImpl.h" | 11 #include "CCLayerImpl.h" |
| 12 #include "CCProxy.h" | 12 #include "CCProxy.h" |
| 13 #include "CCSingleThreadProxy.h" | 13 #include "CCSingleThreadProxy.h" |
| 14 #include "LayerChromium.h" | 14 #include "LayerChromium.h" |
| 15 #include "Region.h" | 15 #include "Region.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 17 |
| 18 using namespace cc; | 18 using namespace cc; |
| 19 using namespace WebKitTests; | 19 using namespace WebKitTests; |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 class MockCCLayerImpl : public CCLayerImpl { | 23 class MockCCLayerImpl : public CCLayerImpl { |
| 24 public: | 24 public: |
| 25 static PassOwnPtr<MockCCLayerImpl> create(int layerId) | 25 static scoped_ptr<MockCCLayerImpl> create(int layerId) |
| 26 { | 26 { |
| 27 return adoptPtr(new MockCCLayerImpl(layerId)); | 27 return make_scoped_ptr(new MockCCLayerImpl(layerId)); |
| 28 } | 28 } |
| 29 virtual ~MockCCLayerImpl() | 29 virtual ~MockCCLayerImpl() |
| 30 { | 30 { |
| 31 if (m_ccLayerDestructionList) | 31 if (m_ccLayerDestructionList) |
| 32 m_ccLayerDestructionList->append(id()); | 32 m_ccLayerDestructionList->append(id()); |
| 33 } | 33 } |
| 34 | 34 |
| 35 void setCCLayerDestructionList(Vector<int>* list) { m_ccLayerDestructionList
= list; } | 35 void setCCLayerDestructionList(Vector<int>* list) { m_ccLayerDestructionList
= list; } |
| 36 | 36 |
| 37 private: | 37 private: |
| 38 MockCCLayerImpl(int layerId) | 38 MockCCLayerImpl(int layerId) |
| 39 : CCLayerImpl(layerId) | 39 : CCLayerImpl(layerId) |
| 40 , m_ccLayerDestructionList(0) | 40 , m_ccLayerDestructionList(0) |
| 41 { | 41 { |
| 42 } | 42 } |
| 43 | 43 |
| 44 Vector<int>* m_ccLayerDestructionList; | 44 Vector<int>* m_ccLayerDestructionList; |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 class MockLayerChromium : public LayerChromium { | 47 class MockLayerChromium : public LayerChromium { |
| 48 public: | 48 public: |
| 49 static scoped_refptr<MockLayerChromium> create(Vector<int>* ccLayerDestructi
onList) | 49 static scoped_refptr<MockLayerChromium> create(Vector<int>* ccLayerDestructi
onList) |
| 50 { | 50 { |
| 51 return make_scoped_refptr(new MockLayerChromium(ccLayerDestructionList))
; | 51 return make_scoped_refptr(new MockLayerChromium(ccLayerDestructionList))
; |
| 52 } | 52 } |
| 53 | 53 |
| 54 virtual PassOwnPtr<CCLayerImpl> createCCLayerImpl() OVERRIDE | 54 virtual scoped_ptr<CCLayerImpl> createCCLayerImpl() OVERRIDE |
| 55 { | 55 { |
| 56 return MockCCLayerImpl::create(m_layerId); | 56 return MockCCLayerImpl::create(m_layerId).PassAs<CCLayerImpl>(); |
| 57 } | 57 } |
| 58 | 58 |
| 59 virtual void pushPropertiesTo(CCLayerImpl* ccLayer) OVERRIDE | 59 virtual void pushPropertiesTo(CCLayerImpl* ccLayer) OVERRIDE |
| 60 { | 60 { |
| 61 LayerChromium::pushPropertiesTo(ccLayer); | 61 LayerChromium::pushPropertiesTo(ccLayer); |
| 62 | 62 |
| 63 MockCCLayerImpl* mockCCLayer = static_cast<MockCCLayerImpl*>(ccLayer); | 63 MockCCLayerImpl* mockCCLayer = static_cast<MockCCLayerImpl*>(ccLayer); |
| 64 mockCCLayer->setCCLayerDestructionList(m_ccLayerDestructionList); | 64 mockCCLayer->setCCLayerDestructionList(m_ccLayerDestructionList); |
| 65 } | 65 } |
| 66 | 66 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 | 112 |
| 113 ASSERT_EQ(!!layer->maskLayer(), !!ccLayer->maskLayer()); | 113 ASSERT_EQ(!!layer->maskLayer(), !!ccLayer->maskLayer()); |
| 114 if (layer->maskLayer()) | 114 if (layer->maskLayer()) |
| 115 expectTreesAreIdentical(layer->maskLayer(), ccLayer->maskLayer(), hostIm
pl); | 115 expectTreesAreIdentical(layer->maskLayer(), ccLayer->maskLayer(), hostIm
pl); |
| 116 | 116 |
| 117 ASSERT_EQ(!!layer->replicaLayer(), !!ccLayer->replicaLayer()); | 117 ASSERT_EQ(!!layer->replicaLayer(), !!ccLayer->replicaLayer()); |
| 118 if (layer->replicaLayer()) | 118 if (layer->replicaLayer()) |
| 119 expectTreesAreIdentical(layer->replicaLayer(), ccLayer->replicaLayer(),
hostImpl); | 119 expectTreesAreIdentical(layer->replicaLayer(), ccLayer->replicaLayer(),
hostImpl); |
| 120 | 120 |
| 121 const std::vector<scoped_refptr<LayerChromium> >& layerChildren = layer->chi
ldren(); | 121 const std::vector<scoped_refptr<LayerChromium> >& layerChildren = layer->chi
ldren(); |
| 122 const OwnPtrVector<CCLayerImpl>& ccLayerChildren = ccLayer->children(); | 122 const ScopedPtrVector<CCLayerImpl>& ccLayerChildren = ccLayer->children(); |
| 123 | 123 |
| 124 ASSERT_EQ(layerChildren.size(), ccLayerChildren.size()); | 124 ASSERT_EQ(layerChildren.size(), ccLayerChildren.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(), ccLayerChildren[i], host
Impl); | 127 expectTreesAreIdentical(layerChildren[i].get(), ccLayerChildren[i], host
Impl); |
| 128 } | 128 } |
| 129 | 129 |
| 130 // Attempts to synchronizes a null tree. This should not crash, and should | 130 // Attempts to synchronizes a null tree. This should not crash, and should |
| 131 // return a null tree. | 131 // return a null tree. |
| 132 TEST(TreeSynchronizerTest, syncNullTree) | 132 TEST(TreeSynchronizerTest, syncNullTree) |
| 133 { | 133 { |
| 134 DebugScopedSetImplThread impl; | 134 DebugScopedSetImplThread impl; |
| 135 | 135 |
| 136 OwnPtr<CCLayerImpl> ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(0,
nullptr, 0); | 136 scoped_ptr<CCLayerImpl> ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees
(0, scoped_ptr<CCLayerImpl>(), 0); |
| 137 | 137 |
| 138 EXPECT_TRUE(!ccLayerTreeRoot.get()); | 138 EXPECT_TRUE(!ccLayerTreeRoot.get()); |
| 139 } | 139 } |
| 140 | 140 |
| 141 // Constructs a very simple tree and synchronizes it without trying to reuse any
preexisting layers. | 141 // Constructs a very simple tree and synchronizes it without trying to reuse any
preexisting layers. |
| 142 TEST(TreeSynchronizerTest, syncSimpleTreeFromEmpty) | 142 TEST(TreeSynchronizerTest, syncSimpleTreeFromEmpty) |
| 143 { | 143 { |
| 144 DebugScopedSetImplThread impl; | 144 DebugScopedSetImplThread impl; |
| 145 | 145 |
| 146 CCLayerTreeSettings settings; | 146 CCLayerTreeSettings settings; |
| 147 scoped_ptr<CCLayerTreeHostImpl> hostImpl = CCLayerTreeHostImpl::create(setti
ngs, 0); | 147 scoped_ptr<CCLayerTreeHostImpl> hostImpl = CCLayerTreeHostImpl::create(setti
ngs, 0); |
| 148 | 148 |
| 149 scoped_refptr<LayerChromium> layerTreeRoot = LayerChromium::create(); | 149 scoped_refptr<LayerChromium> layerTreeRoot = LayerChromium::create(); |
| 150 layerTreeRoot->addChild(LayerChromium::create()); | 150 layerTreeRoot->addChild(LayerChromium::create()); |
| 151 layerTreeRoot->addChild(LayerChromium::create()); | 151 layerTreeRoot->addChild(LayerChromium::create()); |
| 152 | 152 |
| 153 OwnPtr<CCLayerImpl> ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(lay
erTreeRoot.get(), nullptr, hostImpl.get()); | 153 scoped_ptr<CCLayerImpl> ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees
(layerTreeRoot.get(), scoped_ptr<CCLayerImpl>(), hostImpl.get()); |
| 154 | 154 |
| 155 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl
.get()); | 155 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl
.get()); |
| 156 } | 156 } |
| 157 | 157 |
| 158 // Constructs a very simple tree and synchronizes it attempting to reuse some la
yers | 158 // Constructs a very simple tree and synchronizes it attempting to reuse some la
yers |
| 159 TEST(TreeSynchronizerTest, syncSimpleTreeReusingLayers) | 159 TEST(TreeSynchronizerTest, syncSimpleTreeReusingLayers) |
| 160 { | 160 { |
| 161 DebugScopedSetImplThread impl; | 161 DebugScopedSetImplThread impl; |
| 162 Vector<int> ccLayerDestructionList; | 162 Vector<int> ccLayerDestructionList; |
| 163 | 163 |
| 164 CCLayerTreeSettings settings; | 164 CCLayerTreeSettings settings; |
| 165 scoped_ptr<CCLayerTreeHostImpl> hostImpl = CCLayerTreeHostImpl::create(setti
ngs, 0); | 165 scoped_ptr<CCLayerTreeHostImpl> hostImpl = CCLayerTreeHostImpl::create(setti
ngs, 0); |
| 166 | 166 |
| 167 scoped_refptr<LayerChromium> layerTreeRoot = MockLayerChromium::create(&ccLa
yerDestructionList); | 167 scoped_refptr<LayerChromium> layerTreeRoot = MockLayerChromium::create(&ccLa
yerDestructionList); |
| 168 layerTreeRoot->addChild(MockLayerChromium::create(&ccLayerDestructionList)); | 168 layerTreeRoot->addChild(MockLayerChromium::create(&ccLayerDestructionList)); |
| 169 layerTreeRoot->addChild(MockLayerChromium::create(&ccLayerDestructionList)); | 169 layerTreeRoot->addChild(MockLayerChromium::create(&ccLayerDestructionList)); |
| 170 | 170 |
| 171 OwnPtr<CCLayerImpl> ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(lay
erTreeRoot.get(), nullptr, hostImpl.get()); | 171 scoped_ptr<CCLayerImpl> ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees
(layerTreeRoot.get(), scoped_ptr<CCLayerImpl>(), hostImpl.get()); |
| 172 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl
.get()); | 172 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl
.get()); |
| 173 | 173 |
| 174 // Add a new layer to the LayerChromium side | 174 // Add a new layer to the LayerChromium side |
| 175 layerTreeRoot->children()[0]->addChild(MockLayerChromium::create(&ccLayerDes
tructionList)); | 175 layerTreeRoot->children()[0]->addChild(MockLayerChromium::create(&ccLayerDes
tructionList)); |
| 176 // Remove one. | 176 // Remove one. |
| 177 layerTreeRoot->children()[1]->removeFromParent(); | 177 layerTreeRoot->children()[1]->removeFromParent(); |
| 178 int secondCCLayerId = ccLayerTreeRoot->children()[1]->id(); | 178 int secondCCLayerId = ccLayerTreeRoot->children()[1]->id(); |
| 179 | 179 |
| 180 // Synchronize again. After the sync the trees should be equivalent and we s
hould have created and destroyed one CCLayerImpl. | 180 // Synchronize again. After the sync the trees should be equivalent and we s
hould have created and destroyed one CCLayerImpl. |
| 181 ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), cc
LayerTreeRoot.release(), hostImpl.get()); | 181 ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), cc
LayerTreeRoot.Pass(), hostImpl.get()); |
| 182 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl
.get()); | 182 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl
.get()); |
| 183 | 183 |
| 184 ASSERT_EQ(1u, ccLayerDestructionList.size()); | 184 ASSERT_EQ(1u, ccLayerDestructionList.size()); |
| 185 EXPECT_EQ(secondCCLayerId, ccLayerDestructionList[0]); | 185 EXPECT_EQ(secondCCLayerId, ccLayerDestructionList[0]); |
| 186 } | 186 } |
| 187 | 187 |
| 188 // 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. |
| 189 TEST(TreeSynchronizerTest, syncSimpleTreeAndTrackStackingOrderChange) | 189 TEST(TreeSynchronizerTest, syncSimpleTreeAndTrackStackingOrderChange) |
| 190 { | 190 { |
| 191 DebugScopedSetImplThread impl; | 191 DebugScopedSetImplThread impl; |
| 192 Vector<int> ccLayerDestructionList; | 192 Vector<int> ccLayerDestructionList; |
| 193 | 193 |
| 194 CCLayerTreeSettings settings; | 194 CCLayerTreeSettings settings; |
| 195 scoped_ptr<CCLayerTreeHostImpl> hostImpl = CCLayerTreeHostImpl::create(setti
ngs, 0); | 195 scoped_ptr<CCLayerTreeHostImpl> hostImpl = CCLayerTreeHostImpl::create(setti
ngs, 0); |
| 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<LayerChromium> layerTreeRoot = MockLayerChromium::create(&ccLa
yerDestructionList); | 199 scoped_refptr<LayerChromium> layerTreeRoot = MockLayerChromium::create(&ccLa
yerDestructionList); |
| 200 scoped_refptr<LayerChromium> child2 = MockLayerChromium::create(&ccLayerDest
ructionList); | 200 scoped_refptr<LayerChromium> child2 = MockLayerChromium::create(&ccLayerDest
ructionList); |
| 201 layerTreeRoot->addChild(MockLayerChromium::create(&ccLayerDestructionList)); | 201 layerTreeRoot->addChild(MockLayerChromium::create(&ccLayerDestructionList)); |
| 202 layerTreeRoot->addChild(child2); | 202 layerTreeRoot->addChild(child2); |
| 203 OwnPtr<CCLayerImpl> ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(lay
erTreeRoot.get(), nullptr, hostImpl.get()); | 203 scoped_ptr<CCLayerImpl> ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees
(layerTreeRoot.get(), scoped_ptr<CCLayerImpl>(), hostImpl.get()); |
| 204 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl
.get()); | 204 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl
.get()); |
| 205 ccLayerTreeRoot->resetAllChangeTrackingForSubtree(); | 205 ccLayerTreeRoot->resetAllChangeTrackingForSubtree(); |
| 206 | 206 |
| 207 // re-insert the layer and sync again. | 207 // re-insert the layer and sync again. |
| 208 child2->removeFromParent(); | 208 child2->removeFromParent(); |
| 209 layerTreeRoot->addChild(child2); | 209 layerTreeRoot->addChild(child2); |
| 210 ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), cc
LayerTreeRoot.release(), hostImpl.get()); | 210 ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), cc
LayerTreeRoot.Pass(), hostImpl.get()); |
| 211 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl
.get()); | 211 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl
.get()); |
| 212 | 212 |
| 213 // Check that the impl thread properly tracked the change. | 213 // Check that the impl thread properly tracked the change. |
| 214 EXPECT_FALSE(ccLayerTreeRoot->layerPropertyChanged()); | 214 EXPECT_FALSE(ccLayerTreeRoot->layerPropertyChanged()); |
| 215 EXPECT_FALSE(ccLayerTreeRoot->children()[0]->layerPropertyChanged()); | 215 EXPECT_FALSE(ccLayerTreeRoot->children()[0]->layerPropertyChanged()); |
| 216 EXPECT_TRUE(ccLayerTreeRoot->children()[1]->layerPropertyChanged()); | 216 EXPECT_TRUE(ccLayerTreeRoot->children()[1]->layerPropertyChanged()); |
| 217 } | 217 } |
| 218 | 218 |
| 219 TEST(TreeSynchronizerTest, syncSimpleTreeAndProperties) | 219 TEST(TreeSynchronizerTest, syncSimpleTreeAndProperties) |
| 220 { | 220 { |
| 221 DebugScopedSetImplThread impl; | 221 DebugScopedSetImplThread impl; |
| 222 | 222 |
| 223 CCLayerTreeSettings settings; | 223 CCLayerTreeSettings settings; |
| 224 scoped_ptr<CCLayerTreeHostImpl> hostImpl = CCLayerTreeHostImpl::create(setti
ngs, 0); | 224 scoped_ptr<CCLayerTreeHostImpl> hostImpl = CCLayerTreeHostImpl::create(setti
ngs, 0); |
| 225 | 225 |
| 226 scoped_refptr<LayerChromium> layerTreeRoot = LayerChromium::create(); | 226 scoped_refptr<LayerChromium> layerTreeRoot = LayerChromium::create(); |
| 227 layerTreeRoot->addChild(LayerChromium::create()); | 227 layerTreeRoot->addChild(LayerChromium::create()); |
| 228 layerTreeRoot->addChild(LayerChromium::create()); | 228 layerTreeRoot->addChild(LayerChromium::create()); |
| 229 | 229 |
| 230 // 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. | 230 // 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 FloatPoint rootPosition = FloatPoint(2.3f, 7.4f); | 231 FloatPoint rootPosition = FloatPoint(2.3f, 7.4f); |
| 232 layerTreeRoot->setPosition(rootPosition); | 232 layerTreeRoot->setPosition(rootPosition); |
| 233 | 233 |
| 234 float firstChildOpacity = 0.25f; | 234 float firstChildOpacity = 0.25f; |
| 235 layerTreeRoot->children()[0]->setOpacity(firstChildOpacity); | 235 layerTreeRoot->children()[0]->setOpacity(firstChildOpacity); |
| 236 | 236 |
| 237 IntSize secondChildBounds = IntSize(25, 53); | 237 IntSize secondChildBounds = IntSize(25, 53); |
| 238 layerTreeRoot->children()[1]->setBounds(secondChildBounds); | 238 layerTreeRoot->children()[1]->setBounds(secondChildBounds); |
| 239 | 239 |
| 240 OwnPtr<CCLayerImpl> ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(lay
erTreeRoot.get(), nullptr, hostImpl.get()); | 240 scoped_ptr<CCLayerImpl> ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees
(layerTreeRoot.get(), scoped_ptr<CCLayerImpl>(), hostImpl.get()); |
| 241 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl
.get()); | 241 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl
.get()); |
| 242 | 242 |
| 243 // Check that the property values we set on the LayerChromium tree are refle
cted in the CCLayerImpl tree. | 243 // Check that the property values we set on the LayerChromium tree are refle
cted in the CCLayerImpl tree. |
| 244 FloatPoint rootCCLayerPosition = ccLayerTreeRoot->position(); | 244 FloatPoint rootCCLayerPosition = ccLayerTreeRoot->position(); |
| 245 EXPECT_EQ(rootPosition.x(), rootCCLayerPosition.x()); | 245 EXPECT_EQ(rootPosition.x(), rootCCLayerPosition.x()); |
| 246 EXPECT_EQ(rootPosition.y(), rootCCLayerPosition.y()); | 246 EXPECT_EQ(rootPosition.y(), rootCCLayerPosition.y()); |
| 247 | 247 |
| 248 EXPECT_EQ(firstChildOpacity, ccLayerTreeRoot->children()[0]->opacity()); | 248 EXPECT_EQ(firstChildOpacity, ccLayerTreeRoot->children()[0]->opacity()); |
| 249 | 249 |
| 250 IntSize secondCCLayerChildBounds = ccLayerTreeRoot->children()[1]->bounds(); | 250 IntSize secondCCLayerChildBounds = ccLayerTreeRoot->children()[1]->bounds(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 270 scoped_refptr<LayerChromium> layerA = layerTreeRoot->children()[0].get(); | 270 scoped_refptr<LayerChromium> layerA = layerTreeRoot->children()[0].get(); |
| 271 layerA->addChild(MockLayerChromium::create(&ccLayerDestructionList)); | 271 layerA->addChild(MockLayerChromium::create(&ccLayerDestructionList)); |
| 272 | 272 |
| 273 scoped_refptr<LayerChromium> layerB = layerA->children()[0].get(); | 273 scoped_refptr<LayerChromium> layerB = layerA->children()[0].get(); |
| 274 layerB->addChild(MockLayerChromium::create(&ccLayerDestructionList)); | 274 layerB->addChild(MockLayerChromium::create(&ccLayerDestructionList)); |
| 275 | 275 |
| 276 scoped_refptr<LayerChromium> layerC = layerB->children()[0].get(); | 276 scoped_refptr<LayerChromium> layerC = layerB->children()[0].get(); |
| 277 layerB->addChild(MockLayerChromium::create(&ccLayerDestructionList)); | 277 layerB->addChild(MockLayerChromium::create(&ccLayerDestructionList)); |
| 278 scoped_refptr<LayerChromium> layerD = layerB->children()[1].get(); | 278 scoped_refptr<LayerChromium> layerD = layerB->children()[1].get(); |
| 279 | 279 |
| 280 OwnPtr<CCLayerImpl> ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(lay
erTreeRoot.get(), nullptr, hostImpl.get()); | 280 scoped_ptr<CCLayerImpl> ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees
(layerTreeRoot.get(), scoped_ptr<CCLayerImpl>(), hostImpl.get()); |
| 281 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl
.get()); | 281 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl
.get()); |
| 282 | 282 |
| 283 // Now restructure the tree to look like this: | 283 // Now restructure the tree to look like this: |
| 284 // root --- D ---+--- A | 284 // root --- D ---+--- A |
| 285 // | | 285 // | |
| 286 // +--- C --- B | 286 // +--- C --- B |
| 287 layerTreeRoot->removeAllChildren(); | 287 layerTreeRoot->removeAllChildren(); |
| 288 layerD->removeAllChildren(); | 288 layerD->removeAllChildren(); |
| 289 layerTreeRoot->addChild(layerD); | 289 layerTreeRoot->addChild(layerD); |
| 290 layerA->removeAllChildren(); | 290 layerA->removeAllChildren(); |
| 291 layerD->addChild(layerA); | 291 layerD->addChild(layerA); |
| 292 layerC->removeAllChildren(); | 292 layerC->removeAllChildren(); |
| 293 layerD->addChild(layerC); | 293 layerD->addChild(layerC); |
| 294 layerB->removeAllChildren(); | 294 layerB->removeAllChildren(); |
| 295 layerC->addChild(layerB); | 295 layerC->addChild(layerB); |
| 296 | 296 |
| 297 // After another synchronize our trees should match and we should not have d
estroyed any CCLayerImpls | 297 // After another synchronize our trees should match and we should not have d
estroyed any CCLayerImpls |
| 298 ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), cc
LayerTreeRoot.release(), hostImpl.get()); | 298 ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), cc
LayerTreeRoot.Pass(), hostImpl.get()); |
| 299 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl
.get()); | 299 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl
.get()); |
| 300 | 300 |
| 301 EXPECT_EQ(0u, ccLayerDestructionList.size()); | 301 EXPECT_EQ(0u, ccLayerDestructionList.size()); |
| 302 } | 302 } |
| 303 | 303 |
| 304 // 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 // Constructs a very simple tree, synchronizes it, then synchronizes to a totall
y new tree. All layers from the old tree should be deleted. |
| 305 TEST(TreeSynchronizerTest, syncSimpleTreeThenDestroy) | 305 TEST(TreeSynchronizerTest, syncSimpleTreeThenDestroy) |
| 306 { | 306 { |
| 307 DebugScopedSetImplThread impl; | 307 DebugScopedSetImplThread impl; |
| 308 Vector<int> ccLayerDestructionList; | 308 Vector<int> ccLayerDestructionList; |
| 309 | 309 |
| 310 CCLayerTreeSettings settings; | 310 CCLayerTreeSettings settings; |
| 311 scoped_ptr<CCLayerTreeHostImpl> hostImpl = CCLayerTreeHostImpl::create(setti
ngs, 0); | 311 scoped_ptr<CCLayerTreeHostImpl> hostImpl = CCLayerTreeHostImpl::create(setti
ngs, 0); |
| 312 | 312 |
| 313 scoped_refptr<LayerChromium> oldLayerTreeRoot = MockLayerChromium::create(&c
cLayerDestructionList); | 313 scoped_refptr<LayerChromium> oldLayerTreeRoot = MockLayerChromium::create(&c
cLayerDestructionList); |
| 314 oldLayerTreeRoot->addChild(MockLayerChromium::create(&ccLayerDestructionList
)); | 314 oldLayerTreeRoot->addChild(MockLayerChromium::create(&ccLayerDestructionList
)); |
| 315 oldLayerTreeRoot->addChild(MockLayerChromium::create(&ccLayerDestructionList
)); | 315 oldLayerTreeRoot->addChild(MockLayerChromium::create(&ccLayerDestructionList
)); |
| 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 OwnPtr<CCLayerImpl> ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(old
LayerTreeRoot.get(), nullptr, hostImpl.get()); | 321 scoped_ptr<CCLayerImpl> ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees
(oldLayerTreeRoot.get(), scoped_ptr<CCLayerImpl>(), hostImpl.get()); |
| 322 expectTreesAreIdentical(oldLayerTreeRoot.get(), ccLayerTreeRoot.get(), hostI
mpl.get()); | 322 expectTreesAreIdentical(oldLayerTreeRoot.get(), ccLayerTreeRoot.get(), hostI
mpl.get()); |
| 323 | 323 |
| 324 // Remove all children on the LayerChromium side. | 324 // Remove all children on the LayerChromium side. |
| 325 oldLayerTreeRoot->removeAllChildren(); | 325 oldLayerTreeRoot->removeAllChildren(); |
| 326 | 326 |
| 327 // Synchronize again. After the sync all CCLayerImpls from the old tree shou
ld be deleted. | 327 // Synchronize again. After the sync all CCLayerImpls from the old tree shou
ld be deleted. |
| 328 scoped_refptr<LayerChromium> newLayerTreeRoot = LayerChromium::create(); | 328 scoped_refptr<LayerChromium> newLayerTreeRoot = LayerChromium::create(); |
| 329 ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(newLayerTreeRoot.get(),
ccLayerTreeRoot.release(), hostImpl.get()); | 329 ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(newLayerTreeRoot.get(),
ccLayerTreeRoot.Pass(), hostImpl.get()); |
| 330 expectTreesAreIdentical(newLayerTreeRoot.get(), ccLayerTreeRoot.get(), hostI
mpl.get()); | 330 expectTreesAreIdentical(newLayerTreeRoot.get(), ccLayerTreeRoot.get(), hostI
mpl.get()); |
| 331 | 331 |
| 332 ASSERT_EQ(3u, ccLayerDestructionList.size()); | 332 ASSERT_EQ(3u, ccLayerDestructionList.size()); |
| 333 EXPECT_TRUE(ccLayerDestructionList.contains(oldTreeRootLayerId)); | 333 EXPECT_TRUE(ccLayerDestructionList.contains(oldTreeRootLayerId)); |
| 334 EXPECT_TRUE(ccLayerDestructionList.contains(oldTreeFirstChildLayerId)); | 334 EXPECT_TRUE(ccLayerDestructionList.contains(oldTreeFirstChildLayerId)); |
| 335 EXPECT_TRUE(ccLayerDestructionList.contains(oldTreeSecondChildLayerId)); | 335 EXPECT_TRUE(ccLayerDestructionList.contains(oldTreeSecondChildLayerId)); |
| 336 } | 336 } |
| 337 | 337 |
| 338 // Constructs+syncs a tree with mask, replica, and replica mask layers. | 338 // Constructs+syncs a tree with mask, replica, and replica mask layers. |
| 339 TEST(TreeSynchronizerTest, syncMaskReplicaAndReplicaMaskLayers) | 339 TEST(TreeSynchronizerTest, syncMaskReplicaAndReplicaMaskLayers) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 355 // Second child gets a replica layer. | 355 // Second child gets a replica layer. |
| 356 scoped_refptr<LayerChromium> replicaLayer = LayerChromium::create(); | 356 scoped_refptr<LayerChromium> replicaLayer = LayerChromium::create(); |
| 357 layerTreeRoot->children()[1]->setReplicaLayer(replicaLayer.get()); | 357 layerTreeRoot->children()[1]->setReplicaLayer(replicaLayer.get()); |
| 358 | 358 |
| 359 // Third child gets a replica layer with a mask layer. | 359 // Third child gets a replica layer with a mask layer. |
| 360 scoped_refptr<LayerChromium> replicaLayerWithMask = LayerChromium::create(); | 360 scoped_refptr<LayerChromium> replicaLayerWithMask = LayerChromium::create(); |
| 361 scoped_refptr<LayerChromium> replicaMaskLayer = LayerChromium::create(); | 361 scoped_refptr<LayerChromium> replicaMaskLayer = LayerChromium::create(); |
| 362 replicaLayerWithMask->setMaskLayer(replicaMaskLayer.get()); | 362 replicaLayerWithMask->setMaskLayer(replicaMaskLayer.get()); |
| 363 layerTreeRoot->children()[2]->setReplicaLayer(replicaLayerWithMask.get()); | 363 layerTreeRoot->children()[2]->setReplicaLayer(replicaLayerWithMask.get()); |
| 364 | 364 |
| 365 OwnPtr<CCLayerImpl> ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(lay
erTreeRoot.get(), nullptr, hostImpl.get()); | 365 scoped_ptr<CCLayerImpl> ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees
(layerTreeRoot.get(), scoped_ptr<CCLayerImpl>(), hostImpl.get()); |
| 366 | 366 |
| 367 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl
.get()); | 367 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl
.get()); |
| 368 | 368 |
| 369 // Remove the mask layer. | 369 // Remove the mask layer. |
| 370 layerTreeRoot->children()[0]->setMaskLayer(0); | 370 layerTreeRoot->children()[0]->setMaskLayer(0); |
| 371 ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), cc
LayerTreeRoot.release(), hostImpl.get()); | 371 ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), cc
LayerTreeRoot.Pass(), hostImpl.get()); |
| 372 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl
.get()); | 372 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl
.get()); |
| 373 | 373 |
| 374 // Remove the replica layer. | 374 // Remove the replica layer. |
| 375 layerTreeRoot->children()[1]->setReplicaLayer(0); | 375 layerTreeRoot->children()[1]->setReplicaLayer(0); |
| 376 ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), cc
LayerTreeRoot.release(), hostImpl.get()); | 376 ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), cc
LayerTreeRoot.Pass(), hostImpl.get()); |
| 377 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl
.get()); | 377 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl
.get()); |
| 378 | 378 |
| 379 // Remove the replica mask. | 379 // Remove the replica mask. |
| 380 replicaLayerWithMask->setMaskLayer(0); | 380 replicaLayerWithMask->setMaskLayer(0); |
| 381 ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), cc
LayerTreeRoot.release(), hostImpl.get()); | 381 ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), cc
LayerTreeRoot.Pass(), hostImpl.get()); |
| 382 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl
.get()); | 382 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl
.get()); |
| 383 } | 383 } |
| 384 | 384 |
| 385 TEST(TreeSynchronizerTest, synchronizeAnimations) | 385 TEST(TreeSynchronizerTest, synchronizeAnimations) |
| 386 { | 386 { |
| 387 DebugScopedSetImplThread impl; | 387 DebugScopedSetImplThread impl; |
| 388 | 388 |
| 389 CCLayerTreeSettings settings; | 389 CCLayerTreeSettings settings; |
| 390 scoped_ptr<CCLayerTreeHostImpl> hostImpl = CCLayerTreeHostImpl::create(setti
ngs, 0); | 390 scoped_ptr<CCLayerTreeHostImpl> hostImpl = CCLayerTreeHostImpl::create(setti
ngs, 0); |
| 391 | 391 |
| 392 scoped_refptr<LayerChromium> layerTreeRoot = LayerChromium::create(); | 392 scoped_refptr<LayerChromium> layerTreeRoot = LayerChromium::create(); |
| 393 | 393 |
| 394 FakeLayerAnimationControllerClient dummy; | 394 FakeLayerAnimationControllerClient dummy; |
| 395 layerTreeRoot->setLayerAnimationController(FakeLayerAnimationController::cre
ate(&dummy).PassAs<CCLayerAnimationController>()); | 395 layerTreeRoot->setLayerAnimationController(FakeLayerAnimationController::cre
ate(&dummy).PassAs<CCLayerAnimationController>()); |
| 396 | 396 |
| 397 EXPECT_FALSE(static_cast<FakeLayerAnimationController*>(layerTreeRoot->layer
AnimationController())->synchronizedAnimations()); | 397 EXPECT_FALSE(static_cast<FakeLayerAnimationController*>(layerTreeRoot->layer
AnimationController())->synchronizedAnimations()); |
| 398 | 398 |
| 399 OwnPtr<CCLayerImpl> ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(lay
erTreeRoot.get(), nullptr, hostImpl.get()); | 399 scoped_ptr<CCLayerImpl> ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees
(layerTreeRoot.get(), scoped_ptr<CCLayerImpl>(), hostImpl.get()); |
| 400 ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), cc
LayerTreeRoot.release(), hostImpl.get()); | 400 ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), cc
LayerTreeRoot.Pass(), hostImpl.get()); |
| 401 | 401 |
| 402 EXPECT_TRUE(static_cast<FakeLayerAnimationController*>(layerTreeRoot->layerA
nimationController())->synchronizedAnimations()); | 402 EXPECT_TRUE(static_cast<FakeLayerAnimationController*>(layerTreeRoot->layerA
nimationController())->synchronizedAnimations()); |
| 403 } | 403 } |
| 404 | 404 |
| 405 } // namespace | 405 } // namespace |
| OLD | NEW |