| 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 "cc/tree_synchronizer.h" | 7 #include "cc/tree_synchronizer.h" |
| 8 | 8 |
| 9 #include "CCLayerAnimationController.h" | 9 #include "CCLayerAnimationController.h" |
| 10 #include "CCLayerImpl.h" | 10 #include "CCLayerImpl.h" |
| 11 #include "CCProxy.h" | 11 #include "CCProxy.h" |
| 12 #include "CCSingleThreadProxy.h" | 12 #include "CCSingleThreadProxy.h" |
| 13 #include "Region.h" | 13 #include "Region.h" |
| 14 #include "cc/layer.h" | 14 #include "cc/layer.h" |
| 15 #include "cc/test/animation_test_common.h" | 15 #include "cc/test/animation_test_common.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 MockLayerImpl : public LayerImpl { |
| 24 public: | 24 public: |
| 25 static scoped_ptr<MockCCLayerImpl> create(int layerId) | 25 static scoped_ptr<MockLayerImpl> create(int layerId) |
| 26 { | 26 { |
| 27 return make_scoped_ptr(new MockCCLayerImpl(layerId)); | 27 return make_scoped_ptr(new MockLayerImpl(layerId)); |
| 28 } | 28 } |
| 29 virtual ~MockCCLayerImpl() | 29 virtual ~MockLayerImpl() |
| 30 { | 30 { |
| 31 if (m_ccLayerDestructionList) | 31 if (m_layerImplDestructionList) |
| 32 m_ccLayerDestructionList->append(id()); | 32 m_layerImplDestructionList->append(id()); |
| 33 } | 33 } |
| 34 | 34 |
| 35 void setCCLayerDestructionList(Vector<int>* list) { m_ccLayerDestructionList
= list; } | 35 void setLayerImplDestructionList(Vector<int>* list) { m_layerImplDestruction
List = list; } |
| 36 | 36 |
| 37 private: | 37 private: |
| 38 MockCCLayerImpl(int layerId) | 38 MockLayerImpl(int layerId) |
| 39 : CCLayerImpl(layerId) | 39 : LayerImpl(layerId) |
| 40 , m_ccLayerDestructionList(0) | 40 , m_layerImplDestructionList(0) |
| 41 { | 41 { |
| 42 } | 42 } |
| 43 | 43 |
| 44 Vector<int>* m_ccLayerDestructionList; | 44 Vector<int>* m_layerImplDestructionList; |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 class MockLayerChromium : public LayerChromium { | 47 class MockLayer : public Layer { |
| 48 public: | 48 public: |
| 49 static scoped_refptr<MockLayerChromium> create(Vector<int>* ccLayerDestructi
onList) | 49 static scoped_refptr<MockLayer> create(Vector<int>* layerImplDestructionList
) |
| 50 { | 50 { |
| 51 return make_scoped_refptr(new MockLayerChromium(ccLayerDestructionList))
; | 51 return make_scoped_refptr(new MockLayer(layerImplDestructionList)); |
| 52 } | 52 } |
| 53 | 53 |
| 54 virtual scoped_ptr<CCLayerImpl> createCCLayerImpl() OVERRIDE | 54 virtual scoped_ptr<LayerImpl> createLayerImpl() OVERRIDE |
| 55 { | 55 { |
| 56 return MockCCLayerImpl::create(m_layerId).PassAs<CCLayerImpl>(); | 56 return MockLayerImpl::create(m_layerId).PassAs<LayerImpl>(); |
| 57 } | 57 } |
| 58 | 58 |
| 59 virtual void pushPropertiesTo(CCLayerImpl* ccLayer) OVERRIDE | 59 virtual void pushPropertiesTo(LayerImpl* layerImpl) OVERRIDE |
| 60 { | 60 { |
| 61 LayerChromium::pushPropertiesTo(ccLayer); | 61 Layer::pushPropertiesTo(layerImpl); |
| 62 | 62 |
| 63 MockCCLayerImpl* mockCCLayer = static_cast<MockCCLayerImpl*>(ccLayer); | 63 MockLayerImpl* mockLayerImpl = static_cast<MockLayerImpl*>(layerImpl); |
| 64 mockCCLayer->setCCLayerDestructionList(m_ccLayerDestructionList); | 64 mockLayerImpl->setLayerImplDestructionList(m_layerImplDestructionList); |
| 65 } | 65 } |
| 66 | 66 |
| 67 private: | 67 private: |
| 68 MockLayerChromium(Vector<int>* ccLayerDestructionList) | 68 MockLayer(Vector<int>* layerImplDestructionList) |
| 69 : LayerChromium() | 69 : Layer() |
| 70 , m_ccLayerDestructionList(ccLayerDestructionList) | 70 , m_layerImplDestructionList(layerImplDestructionList) |
| 71 { | 71 { |
| 72 } | 72 } |
| 73 virtual ~MockLayerChromium() { } | 73 virtual ~MockLayer() { } |
| 74 | 74 |
| 75 Vector<int>* m_ccLayerDestructionList; | 75 Vector<int>* m_layerImplDestructionList; |
| 76 }; | 76 }; |
| 77 | 77 |
| 78 class FakeLayerAnimationController : public CCLayerAnimationController { | 78 class FakeLayerAnimationController : public LayerAnimationController { |
| 79 public: | 79 public: |
| 80 static scoped_ptr<FakeLayerAnimationController> create(CCLayerAnimationContr
ollerClient* client) | 80 static scoped_ptr<FakeLayerAnimationController> create(LayerAnimationControl
lerClient* client) |
| 81 { | 81 { |
| 82 return make_scoped_ptr(new FakeLayerAnimationController(client)); | 82 return make_scoped_ptr(new FakeLayerAnimationController(client)); |
| 83 } | 83 } |
| 84 | 84 |
| 85 bool synchronizedAnimations() const { return m_synchronizedAnimations; } | 85 bool synchronizedAnimations() const { return m_synchronizedAnimations; } |
| 86 | 86 |
| 87 private: | 87 private: |
| 88 explicit FakeLayerAnimationController(CCLayerAnimationControllerClient* clie
nt) | 88 explicit FakeLayerAnimationController(LayerAnimationControllerClient* client
) |
| 89 : CCLayerAnimationController(client) | 89 : LayerAnimationController(client) |
| 90 , m_synchronizedAnimations(false) | 90 , m_synchronizedAnimations(false) |
| 91 { | 91 { |
| 92 } | 92 } |
| 93 | 93 |
| 94 virtual void pushAnimationUpdatesTo(CCLayerAnimationController* controllerIm
pl) | 94 virtual void pushAnimationUpdatesTo(LayerAnimationController* controllerImpl
) |
| 95 { | 95 { |
| 96 CCLayerAnimationController::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(LayerChromium* layer, CCLayerImpl* ccLayer, CCLayer
TreeHostImpl* hostImpl) | 103 void expectTreesAreIdentical(Layer* layer, LayerImpl* layerImpl, LayerTreeHostIm
pl* hostImpl) |
| 104 { | 104 { |
| 105 ASSERT_TRUE(layer); | 105 ASSERT_TRUE(layer); |
| 106 ASSERT_TRUE(ccLayer); | 106 ASSERT_TRUE(layerImpl); |
| 107 | 107 |
| 108 EXPECT_EQ(layer->id(), ccLayer->id()); | 108 EXPECT_EQ(layer->id(), layerImpl->id()); |
| 109 EXPECT_EQ(ccLayer->layerTreeHostImpl(), hostImpl); | 109 EXPECT_EQ(layerImpl->layerTreeHostImpl(), hostImpl); |
| 110 | 110 |
| 111 EXPECT_EQ(layer->nonFastScrollableRegion(), ccLayer->nonFastScrollableRegion
()); | 111 EXPECT_EQ(layer->nonFastScrollableRegion(), layerImpl->nonFastScrollableRegi
on()); |
| 112 | 112 |
| 113 ASSERT_EQ(!!layer->maskLayer(), !!ccLayer->maskLayer()); | 113 ASSERT_EQ(!!layer->maskLayer(), !!layerImpl->maskLayer()); |
| 114 if (layer->maskLayer()) | 114 if (layer->maskLayer()) |
| 115 expectTreesAreIdentical(layer->maskLayer(), ccLayer->maskLayer(), hostIm
pl); | 115 expectTreesAreIdentical(layer->maskLayer(), layerImpl->maskLayer(), host
Impl); |
| 116 | 116 |
| 117 ASSERT_EQ(!!layer->replicaLayer(), !!ccLayer->replicaLayer()); | 117 ASSERT_EQ(!!layer->replicaLayer(), !!layerImpl->replicaLayer()); |
| 118 if (layer->replicaLayer()) | 118 if (layer->replicaLayer()) |
| 119 expectTreesAreIdentical(layer->replicaLayer(), ccLayer->replicaLayer(),
hostImpl); | 119 expectTreesAreIdentical(layer->replicaLayer(), layerImpl->replicaLayer()
, hostImpl); |
| 120 | 120 |
| 121 const std::vector<scoped_refptr<LayerChromium> >& layerChildren = layer->chi
ldren(); | 121 const std::vector<scoped_refptr<Layer> >& layerChildren = layer->children(); |
| 122 const ScopedPtrVector<CCLayerImpl>& ccLayerChildren = ccLayer->children(); | 122 const ScopedPtrVector<LayerImpl>& layerImplChildren = layerImpl->children(); |
| 123 | 123 |
| 124 ASSERT_EQ(layerChildren.size(), ccLayerChildren.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(), ccLayerChildren[i], host
Impl); | 127 expectTreesAreIdentical(layerChildren[i].get(), layerImplChildren[i], ho
stImpl); |
| 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 scoped_ptr<CCLayerImpl> ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees
(0, scoped_ptr<CCLayerImpl>(), 0); | 136 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees
(0, scoped_ptr<LayerImpl>(), 0); |
| 137 | 137 |
| 138 EXPECT_TRUE(!ccLayerTreeRoot.get()); | 138 EXPECT_TRUE(!layerImplTreeRoot.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 LayerTreeSettings settings; |
| 147 scoped_ptr<CCLayerTreeHostImpl> hostImpl = CCLayerTreeHostImpl::create(setti
ngs, 0); | 147 scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings,
0); |
| 148 | 148 |
| 149 scoped_refptr<LayerChromium> layerTreeRoot = LayerChromium::create(); | 149 scoped_refptr<Layer> layerTreeRoot = Layer::create(); |
| 150 layerTreeRoot->addChild(LayerChromium::create()); | 150 layerTreeRoot->addChild(Layer::create()); |
| 151 layerTreeRoot->addChild(LayerChromium::create()); | 151 layerTreeRoot->addChild(Layer::create()); |
| 152 | 152 |
| 153 scoped_ptr<CCLayerImpl> ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees
(layerTreeRoot.get(), scoped_ptr<CCLayerImpl>(), hostImpl.get()); | 153 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees
(layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl.get()); |
| 154 | 154 |
| 155 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl
.get()); | 155 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm
pl.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> layerImplDestructionList; |
| 163 | 163 |
| 164 CCLayerTreeSettings settings; | 164 LayerTreeSettings settings; |
| 165 scoped_ptr<CCLayerTreeHostImpl> hostImpl = CCLayerTreeHostImpl::create(setti
ngs, 0); | 165 scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings,
0); |
| 166 | 166 |
| 167 scoped_refptr<LayerChromium> layerTreeRoot = MockLayerChromium::create(&ccLa
yerDestructionList); | 167 scoped_refptr<Layer> layerTreeRoot = MockLayer::create(&layerImplDestruction
List); |
| 168 layerTreeRoot->addChild(MockLayerChromium::create(&ccLayerDestructionList)); | 168 layerTreeRoot->addChild(MockLayer::create(&layerImplDestructionList)); |
| 169 layerTreeRoot->addChild(MockLayerChromium::create(&ccLayerDestructionList)); | 169 layerTreeRoot->addChild(MockLayer::create(&layerImplDestructionList)); |
| 170 | 170 |
| 171 scoped_ptr<CCLayerImpl> ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees
(layerTreeRoot.get(), scoped_ptr<CCLayerImpl>(), hostImpl.get()); | 171 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees
(layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl.get()); |
| 172 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl
.get()); | 172 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm
pl.get()); |
| 173 | 173 |
| 174 // Add a new layer to the LayerChromium side | 174 // Add a new layer to the Layer side |
| 175 layerTreeRoot->children()[0]->addChild(MockLayerChromium::create(&ccLayerDes
tructionList)); | 175 layerTreeRoot->children()[0]->addChild(MockLayer::create(&layerImplDestructi
onList)); |
| 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 secondLayerImplId = layerImplTreeRoot->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 LayerImpl. |
| 181 ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), cc
LayerTreeRoot.Pass(), hostImpl.get()); | 181 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(),
layerImplTreeRoot.Pass(), hostImpl.get()); |
| 182 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl
.get()); | 182 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm
pl.get()); |
| 183 | 183 |
| 184 ASSERT_EQ(1u, ccLayerDestructionList.size()); | 184 ASSERT_EQ(1u, layerImplDestructionList.size()); |
| 185 EXPECT_EQ(secondCCLayerId, ccLayerDestructionList[0]); | 185 EXPECT_EQ(secondLayerImplId, layerImplDestructionList[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> layerImplDestructionList; |
| 193 | 193 |
| 194 CCLayerTreeSettings settings; | 194 LayerTreeSettings settings; |
| 195 scoped_ptr<CCLayerTreeHostImpl> hostImpl = CCLayerTreeHostImpl::create(setti
ngs, 0); | 195 scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings,
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<Layer> layerTreeRoot = MockLayer::create(&layerImplDestruction
List); |
| 200 scoped_refptr<LayerChromium> child2 = MockLayerChromium::create(&ccLayerDest
ructionList); | 200 scoped_refptr<Layer> child2 = MockLayer::create(&layerImplDestructionList); |
| 201 layerTreeRoot->addChild(MockLayerChromium::create(&ccLayerDestructionList)); | 201 layerTreeRoot->addChild(MockLayer::create(&layerImplDestructionList)); |
| 202 layerTreeRoot->addChild(child2); | 202 layerTreeRoot->addChild(child2); |
| 203 scoped_ptr<CCLayerImpl> ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees
(layerTreeRoot.get(), scoped_ptr<CCLayerImpl>(), hostImpl.get()); | 203 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees
(layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl.get()); |
| 204 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl
.get()); | 204 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm
pl.get()); |
| 205 ccLayerTreeRoot->resetAllChangeTrackingForSubtree(); | 205 layerImplTreeRoot->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.Pass(), hostImpl.get()); | 210 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(),
layerImplTreeRoot.Pass(), hostImpl.get()); |
| 211 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl
.get()); | 211 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm
pl.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(layerImplTreeRoot->layerPropertyChanged()); |
| 215 EXPECT_FALSE(ccLayerTreeRoot->children()[0]->layerPropertyChanged()); | 215 EXPECT_FALSE(layerImplTreeRoot->children()[0]->layerPropertyChanged()); |
| 216 EXPECT_TRUE(ccLayerTreeRoot->children()[1]->layerPropertyChanged()); | 216 EXPECT_TRUE(layerImplTreeRoot->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 LayerTreeSettings settings; |
| 224 scoped_ptr<CCLayerTreeHostImpl> hostImpl = CCLayerTreeHostImpl::create(setti
ngs, 0); | 224 scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings,
0); |
| 225 | 225 |
| 226 scoped_refptr<LayerChromium> layerTreeRoot = LayerChromium::create(); | 226 scoped_refptr<Layer> layerTreeRoot = Layer::create(); |
| 227 layerTreeRoot->addChild(LayerChromium::create()); | 227 layerTreeRoot->addChild(Layer::create()); |
| 228 layerTreeRoot->addChild(LayerChromium::create()); | 228 layerTreeRoot->addChild(Layer::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 scoped_ptr<CCLayerImpl> ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees
(layerTreeRoot.get(), scoped_ptr<CCLayerImpl>(), hostImpl.get()); | 240 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees
(layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl.get()); |
| 241 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl
.get()); | 241 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm
pl.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 Layer tree are reflected in
the LayerImpl tree. |
| 244 FloatPoint rootCCLayerPosition = ccLayerTreeRoot->position(); | 244 FloatPoint rootLayerImplPosition = layerImplTreeRoot->position(); |
| 245 EXPECT_EQ(rootPosition.x(), rootCCLayerPosition.x()); | 245 EXPECT_EQ(rootPosition.x(), rootLayerImplPosition.x()); |
| 246 EXPECT_EQ(rootPosition.y(), rootCCLayerPosition.y()); | 246 EXPECT_EQ(rootPosition.y(), rootLayerImplPosition.y()); |
| 247 | 247 |
| 248 EXPECT_EQ(firstChildOpacity, ccLayerTreeRoot->children()[0]->opacity()); | 248 EXPECT_EQ(firstChildOpacity, layerImplTreeRoot->children()[0]->opacity()); |
| 249 | 249 |
| 250 IntSize secondCCLayerChildBounds = ccLayerTreeRoot->children()[1]->bounds(); | 250 IntSize secondLayerImplChildBounds = layerImplTreeRoot->children()[1]->bound
s(); |
| 251 EXPECT_EQ(secondChildBounds.width(), secondCCLayerChildBounds.width()); | 251 EXPECT_EQ(secondChildBounds.width(), secondLayerImplChildBounds.width()); |
| 252 EXPECT_EQ(secondChildBounds.height(), secondCCLayerChildBounds.height()); | 252 EXPECT_EQ(secondChildBounds.height(), secondLayerImplChildBounds.height()); |
| 253 } | 253 } |
| 254 | 254 |
| 255 TEST(TreeSynchronizerTest, reuseCCLayersAfterStructuralChange) | 255 TEST(TreeSynchronizerTest, reuseLayerImplsAfterStructuralChange) |
| 256 { | 256 { |
| 257 DebugScopedSetImplThread impl; | 257 DebugScopedSetImplThread impl; |
| 258 Vector<int> ccLayerDestructionList; | 258 Vector<int> layerImplDestructionList; |
| 259 | 259 |
| 260 CCLayerTreeSettings settings; | 260 LayerTreeSettings settings; |
| 261 scoped_ptr<CCLayerTreeHostImpl> hostImpl = CCLayerTreeHostImpl::create(setti
ngs, 0); | 261 scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings,
0); |
| 262 | 262 |
| 263 // Set up a tree with this sort of structure: | 263 // Set up a tree with this sort of structure: |
| 264 // root --- A --- B ---+--- C | 264 // root --- A --- B ---+--- C |
| 265 // | | 265 // | |
| 266 // +--- D | 266 // +--- D |
| 267 scoped_refptr<LayerChromium> layerTreeRoot = MockLayerChromium::create(&ccLa
yerDestructionList); | 267 scoped_refptr<Layer> layerTreeRoot = MockLayer::create(&layerImplDestruction
List); |
| 268 layerTreeRoot->addChild(MockLayerChromium::create(&ccLayerDestructionList)); | 268 layerTreeRoot->addChild(MockLayer::create(&layerImplDestructionList)); |
| 269 | 269 |
| 270 scoped_refptr<LayerChromium> layerA = layerTreeRoot->children()[0].get(); | 270 scoped_refptr<Layer> layerA = layerTreeRoot->children()[0].get(); |
| 271 layerA->addChild(MockLayerChromium::create(&ccLayerDestructionList)); | 271 layerA->addChild(MockLayer::create(&layerImplDestructionList)); |
| 272 | 272 |
| 273 scoped_refptr<LayerChromium> layerB = layerA->children()[0].get(); | 273 scoped_refptr<Layer> layerB = layerA->children()[0].get(); |
| 274 layerB->addChild(MockLayerChromium::create(&ccLayerDestructionList)); | 274 layerB->addChild(MockLayer::create(&layerImplDestructionList)); |
| 275 | 275 |
| 276 scoped_refptr<LayerChromium> layerC = layerB->children()[0].get(); | 276 scoped_refptr<Layer> layerC = layerB->children()[0].get(); |
| 277 layerB->addChild(MockLayerChromium::create(&ccLayerDestructionList)); | 277 layerB->addChild(MockLayer::create(&layerImplDestructionList)); |
| 278 scoped_refptr<LayerChromium> layerD = layerB->children()[1].get(); | 278 scoped_refptr<Layer> layerD = layerB->children()[1].get(); |
| 279 | 279 |
| 280 scoped_ptr<CCLayerImpl> ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees
(layerTreeRoot.get(), scoped_ptr<CCLayerImpl>(), hostImpl.get()); | 280 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees
(layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl.get()); |
| 281 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl
.get()); | 281 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm
pl.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 LayerImpls |
| 298 ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), cc
LayerTreeRoot.Pass(), hostImpl.get()); | 298 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(),
layerImplTreeRoot.Pass(), hostImpl.get()); |
| 299 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl
.get()); | 299 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm
pl.get()); |
| 300 | 300 |
| 301 EXPECT_EQ(0u, ccLayerDestructionList.size()); | 301 EXPECT_EQ(0u, layerImplDestructionList.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> layerImplDestructionList; |
| 309 | 309 |
| 310 CCLayerTreeSettings settings; | 310 LayerTreeSettings settings; |
| 311 scoped_ptr<CCLayerTreeHostImpl> hostImpl = CCLayerTreeHostImpl::create(setti
ngs, 0); | 311 scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings,
0); |
| 312 | 312 |
| 313 scoped_refptr<LayerChromium> oldLayerTreeRoot = MockLayerChromium::create(&c
cLayerDestructionList); | 313 scoped_refptr<Layer> oldLayerTreeRoot = MockLayer::create(&layerImplDestruct
ionList); |
| 314 oldLayerTreeRoot->addChild(MockLayerChromium::create(&ccLayerDestructionList
)); | 314 oldLayerTreeRoot->addChild(MockLayer::create(&layerImplDestructionList)); |
| 315 oldLayerTreeRoot->addChild(MockLayerChromium::create(&ccLayerDestructionList
)); | 315 oldLayerTreeRoot->addChild(MockLayer::create(&layerImplDestructionList)); |
| 316 | 316 |
| 317 int oldTreeRootLayerId = oldLayerTreeRoot->id(); | 317 int oldTreeRootLayerId = oldLayerTreeRoot->id(); |
| 318 int oldTreeFirstChildLayerId = oldLayerTreeRoot->children()[0]->id(); | 318 int oldTreeFirstChildLayerId = oldLayerTreeRoot->children()[0]->id(); |
| 319 int oldTreeSecondChildLayerId = oldLayerTreeRoot->children()[1]->id(); | 319 int oldTreeSecondChildLayerId = oldLayerTreeRoot->children()[1]->id(); |
| 320 | 320 |
| 321 scoped_ptr<CCLayerImpl> ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees
(oldLayerTreeRoot.get(), scoped_ptr<CCLayerImpl>(), hostImpl.get()); | 321 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees
(oldLayerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl.get()); |
| 322 expectTreesAreIdentical(oldLayerTreeRoot.get(), ccLayerTreeRoot.get(), hostI
mpl.get()); | 322 expectTreesAreIdentical(oldLayerTreeRoot.get(), layerImplTreeRoot.get(), hos
tImpl.get()); |
| 323 | 323 |
| 324 // Remove all children on the LayerChromium side. | 324 // Remove all children on the Layer 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 LayerImpls from the old tree should
be deleted. |
| 328 scoped_refptr<LayerChromium> newLayerTreeRoot = LayerChromium::create(); | 328 scoped_refptr<Layer> newLayerTreeRoot = Layer::create(); |
| 329 ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(newLayerTreeRoot.get(),
ccLayerTreeRoot.Pass(), hostImpl.get()); | 329 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(newLayerTreeRoot.get(
), layerImplTreeRoot.Pass(), hostImpl.get()); |
| 330 expectTreesAreIdentical(newLayerTreeRoot.get(), ccLayerTreeRoot.get(), hostI
mpl.get()); | 330 expectTreesAreIdentical(newLayerTreeRoot.get(), layerImplTreeRoot.get(), hos
tImpl.get()); |
| 331 | 331 |
| 332 ASSERT_EQ(3u, ccLayerDestructionList.size()); | 332 ASSERT_EQ(3u, layerImplDestructionList.size()); |
| 333 EXPECT_TRUE(ccLayerDestructionList.contains(oldTreeRootLayerId)); | 333 EXPECT_TRUE(layerImplDestructionList.contains(oldTreeRootLayerId)); |
| 334 EXPECT_TRUE(ccLayerDestructionList.contains(oldTreeFirstChildLayerId)); | 334 EXPECT_TRUE(layerImplDestructionList.contains(oldTreeFirstChildLayerId)); |
| 335 EXPECT_TRUE(ccLayerDestructionList.contains(oldTreeSecondChildLayerId)); | 335 EXPECT_TRUE(layerImplDestructionList.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) |
| 340 { | 340 { |
| 341 DebugScopedSetImplThread impl; | 341 DebugScopedSetImplThread impl; |
| 342 | 342 |
| 343 CCLayerTreeSettings settings; | 343 LayerTreeSettings settings; |
| 344 scoped_ptr<CCLayerTreeHostImpl> hostImpl = CCLayerTreeHostImpl::create(setti
ngs, 0); | 344 scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings,
0); |
| 345 | 345 |
| 346 scoped_refptr<LayerChromium> layerTreeRoot = LayerChromium::create(); | 346 scoped_refptr<Layer> layerTreeRoot = Layer::create(); |
| 347 layerTreeRoot->addChild(LayerChromium::create()); | 347 layerTreeRoot->addChild(Layer::create()); |
| 348 layerTreeRoot->addChild(LayerChromium::create()); | 348 layerTreeRoot->addChild(Layer::create()); |
| 349 layerTreeRoot->addChild(LayerChromium::create()); | 349 layerTreeRoot->addChild(Layer::create()); |
| 350 | 350 |
| 351 // First child gets a mask layer. | 351 // First child gets a mask layer. |
| 352 scoped_refptr<LayerChromium> maskLayer = LayerChromium::create(); | 352 scoped_refptr<Layer> maskLayer = Layer::create(); |
| 353 layerTreeRoot->children()[0]->setMaskLayer(maskLayer.get()); | 353 layerTreeRoot->children()[0]->setMaskLayer(maskLayer.get()); |
| 354 | 354 |
| 355 // Second child gets a replica layer. | 355 // Second child gets a replica layer. |
| 356 scoped_refptr<LayerChromium> replicaLayer = LayerChromium::create(); | 356 scoped_refptr<Layer> replicaLayer = Layer::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<Layer> replicaLayerWithMask = Layer::create(); |
| 361 scoped_refptr<LayerChromium> replicaMaskLayer = LayerChromium::create(); | 361 scoped_refptr<Layer> replicaMaskLayer = Layer::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 scoped_ptr<CCLayerImpl> ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees
(layerTreeRoot.get(), scoped_ptr<CCLayerImpl>(), hostImpl.get()); | 365 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees
(layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl.get()); |
| 366 | 366 |
| 367 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl
.get()); | 367 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm
pl.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.Pass(), hostImpl.get()); | 371 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(),
layerImplTreeRoot.Pass(), hostImpl.get()); |
| 372 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl
.get()); | 372 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm
pl.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.Pass(), hostImpl.get()); | 376 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(),
layerImplTreeRoot.Pass(), hostImpl.get()); |
| 377 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl
.get()); | 377 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm
pl.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.Pass(), hostImpl.get()); | 381 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(),
layerImplTreeRoot.Pass(), hostImpl.get()); |
| 382 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl
.get()); | 382 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostIm
pl.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 LayerTreeSettings settings; |
| 390 scoped_ptr<CCLayerTreeHostImpl> hostImpl = CCLayerTreeHostImpl::create(setti
ngs, 0); | 390 scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings,
0); |
| 391 | 391 |
| 392 scoped_refptr<LayerChromium> layerTreeRoot = LayerChromium::create(); | 392 scoped_refptr<Layer> layerTreeRoot = Layer::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<LayerAnimationController>()); |
| 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 scoped_ptr<CCLayerImpl> ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees
(layerTreeRoot.get(), scoped_ptr<CCLayerImpl>(), hostImpl.get()); | 399 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees
(layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl.get()); |
| 400 ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), cc
LayerTreeRoot.Pass(), hostImpl.get()); | 400 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(),
layerImplTreeRoot.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 |