blob: ab60d6f6a2e69726c84ac42d18805d6f26f9af79 [file] [log] [blame]
[email protected]c0dd24c2012-08-30 23:25:271// Copyright 2011 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "config.h"
6
[email protected]a8461d82012-10-16 21:11:147#include "cc/tree_synchronizer.h"
[email protected]c0dd24c2012-08-30 23:25:278
[email protected]ac7c7f52012-11-08 06:26:509#include <algorithm>
10
[email protected]a8461d82012-10-16 21:11:1411#include "cc/layer.h"
[email protected]d50c6862012-10-23 02:08:3112#include "cc/layer_animation_controller.h"
13#include "cc/layer_impl.h"
[email protected]55a124d02012-10-22 03:07:1314#include "cc/proxy.h"
[email protected]4456eee22012-10-19 18:16:3815#include "cc/single_thread_proxy.h"
[email protected]101441ce2012-10-16 01:45:0316#include "cc/test/animation_test_common.h"
[email protected]7f0c53db2012-10-02 00:23:1817#include "testing/gtest/include/gtest/gtest.h"
[email protected]c0dd24c2012-08-30 23:25:2718
[email protected]9c88e562012-09-14 22:21:3019using namespace cc;
[email protected]c0dd24c2012-08-30 23:25:2720using namespace WebKitTests;
21
22namespace {
23
[email protected]96baf3e2012-10-22 23:09:5524class MockLayerImpl : public LayerImpl {
[email protected]c0dd24c2012-08-30 23:25:2725public:
[email protected]96baf3e2012-10-22 23:09:5526 static scoped_ptr<MockLayerImpl> create(int layerId)
[email protected]c0dd24c2012-08-30 23:25:2727 {
[email protected]96baf3e2012-10-22 23:09:5528 return make_scoped_ptr(new MockLayerImpl(layerId));
[email protected]c0dd24c2012-08-30 23:25:2729 }
[email protected]96baf3e2012-10-22 23:09:5530 virtual ~MockLayerImpl()
[email protected]c0dd24c2012-08-30 23:25:2731 {
[email protected]96baf3e2012-10-22 23:09:5532 if (m_layerImplDestructionList)
[email protected]2cdbdba2012-10-28 13:15:0533 m_layerImplDestructionList->push_back(id());
[email protected]c0dd24c2012-08-30 23:25:2734 }
35
[email protected]2cdbdba2012-10-28 13:15:0536 void setLayerImplDestructionList(std::vector<int>* list) { m_layerImplDestructionList = list; }
[email protected]c0dd24c2012-08-30 23:25:2737
38private:
[email protected]96baf3e2012-10-22 23:09:5539 MockLayerImpl(int layerId)
40 : LayerImpl(layerId)
41 , m_layerImplDestructionList(0)
[email protected]c0dd24c2012-08-30 23:25:2742 {
43 }
44
[email protected]2cdbdba2012-10-28 13:15:0545 std::vector<int>* m_layerImplDestructionList;
[email protected]c0dd24c2012-08-30 23:25:2746};
47
[email protected]96baf3e2012-10-22 23:09:5548class MockLayer : public Layer {
[email protected]c0dd24c2012-08-30 23:25:2749public:
[email protected]2cdbdba2012-10-28 13:15:0550 static scoped_refptr<MockLayer> create(std::vector<int>* layerImplDestructionList)
[email protected]c0dd24c2012-08-30 23:25:2751 {
[email protected]96baf3e2012-10-22 23:09:5552 return make_scoped_refptr(new MockLayer(layerImplDestructionList));
[email protected]c0dd24c2012-08-30 23:25:2753 }
54
[email protected]96baf3e2012-10-22 23:09:5555 virtual scoped_ptr<LayerImpl> createLayerImpl() OVERRIDE
[email protected]c0dd24c2012-08-30 23:25:2756 {
[email protected]96baf3e2012-10-22 23:09:5557 return MockLayerImpl::create(m_layerId).PassAs<LayerImpl>();
[email protected]c0dd24c2012-08-30 23:25:2758 }
59
[email protected]96baf3e2012-10-22 23:09:5560 virtual void pushPropertiesTo(LayerImpl* layerImpl) OVERRIDE
[email protected]c0dd24c2012-08-30 23:25:2761 {
[email protected]96baf3e2012-10-22 23:09:5562 Layer::pushPropertiesTo(layerImpl);
[email protected]c0dd24c2012-08-30 23:25:2763
[email protected]96baf3e2012-10-22 23:09:5564 MockLayerImpl* mockLayerImpl = static_cast<MockLayerImpl*>(layerImpl);
65 mockLayerImpl->setLayerImplDestructionList(m_layerImplDestructionList);
[email protected]c0dd24c2012-08-30 23:25:2766 }
[email protected]d58499a2012-10-09 22:27:4767
[email protected]c0dd24c2012-08-30 23:25:2768private:
[email protected]2cdbdba2012-10-28 13:15:0569 MockLayer(std::vector<int>* layerImplDestructionList)
[email protected]96baf3e2012-10-22 23:09:5570 : Layer()
71 , m_layerImplDestructionList(layerImplDestructionList)
[email protected]c0dd24c2012-08-30 23:25:2772 {
73 }
[email protected]96baf3e2012-10-22 23:09:5574 virtual ~MockLayer() { }
[email protected]c0dd24c2012-08-30 23:25:2775
[email protected]2cdbdba2012-10-28 13:15:0576 std::vector<int>* m_layerImplDestructionList;
[email protected]c0dd24c2012-08-30 23:25:2777};
78
[email protected]96baf3e2012-10-22 23:09:5579class FakeLayerAnimationController : public LayerAnimationController {
[email protected]c0dd24c2012-08-30 23:25:2780public:
[email protected]96baf3e2012-10-22 23:09:5581 static scoped_ptr<FakeLayerAnimationController> create(LayerAnimationControllerClient* client)
[email protected]c0dd24c2012-08-30 23:25:2782 {
[email protected]9aca3592012-10-12 15:57:0983 return make_scoped_ptr(new FakeLayerAnimationController(client));
[email protected]c0dd24c2012-08-30 23:25:2784 }
85
86 bool synchronizedAnimations() const { return m_synchronizedAnimations; }
87
88private:
[email protected]96baf3e2012-10-22 23:09:5589 explicit FakeLayerAnimationController(LayerAnimationControllerClient* client)
90 : LayerAnimationController(client)
[email protected]c0dd24c2012-08-30 23:25:2791 , m_synchronizedAnimations(false)
92 {
93 }
94
[email protected]96baf3e2012-10-22 23:09:5595 virtual void pushAnimationUpdatesTo(LayerAnimationController* controllerImpl)
[email protected]c0dd24c2012-08-30 23:25:2796 {
[email protected]96baf3e2012-10-22 23:09:5597 LayerAnimationController::pushAnimationUpdatesTo(controllerImpl);
[email protected]c0dd24c2012-08-30 23:25:2798 m_synchronizedAnimations = true;
99 }
100
101 bool m_synchronizedAnimations;
102};
103
[email protected]96baf3e2012-10-22 23:09:55104void expectTreesAreIdentical(Layer* layer, LayerImpl* layerImpl, LayerTreeHostImpl* hostImpl)
[email protected]c0dd24c2012-08-30 23:25:27105{
106 ASSERT_TRUE(layer);
[email protected]96baf3e2012-10-22 23:09:55107 ASSERT_TRUE(layerImpl);
[email protected]c0dd24c2012-08-30 23:25:27108
[email protected]96baf3e2012-10-22 23:09:55109 EXPECT_EQ(layer->id(), layerImpl->id());
110 EXPECT_EQ(layerImpl->layerTreeHostImpl(), hostImpl);
[email protected]c0dd24c2012-08-30 23:25:27111
[email protected]96baf3e2012-10-22 23:09:55112 EXPECT_EQ(layer->nonFastScrollableRegion(), layerImpl->nonFastScrollableRegion());
[email protected]c0dd24c2012-08-30 23:25:27113
[email protected]96baf3e2012-10-22 23:09:55114 ASSERT_EQ(!!layer->maskLayer(), !!layerImpl->maskLayer());
[email protected]c0dd24c2012-08-30 23:25:27115 if (layer->maskLayer())
[email protected]96baf3e2012-10-22 23:09:55116 expectTreesAreIdentical(layer->maskLayer(), layerImpl->maskLayer(), hostImpl);
[email protected]c0dd24c2012-08-30 23:25:27117
[email protected]96baf3e2012-10-22 23:09:55118 ASSERT_EQ(!!layer->replicaLayer(), !!layerImpl->replicaLayer());
[email protected]c0dd24c2012-08-30 23:25:27119 if (layer->replicaLayer())
[email protected]96baf3e2012-10-22 23:09:55120 expectTreesAreIdentical(layer->replicaLayer(), layerImpl->replicaLayer(), hostImpl);
[email protected]c0dd24c2012-08-30 23:25:27121
[email protected]96baf3e2012-10-22 23:09:55122 const std::vector<scoped_refptr<Layer> >& layerChildren = layer->children();
123 const ScopedPtrVector<LayerImpl>& layerImplChildren = layerImpl->children();
[email protected]c0dd24c2012-08-30 23:25:27124
[email protected]96baf3e2012-10-22 23:09:55125 ASSERT_EQ(layerChildren.size(), layerImplChildren.size());
[email protected]c0dd24c2012-08-30 23:25:27126
127 for (size_t i = 0; i < layerChildren.size(); ++i)
[email protected]96baf3e2012-10-22 23:09:55128 expectTreesAreIdentical(layerChildren[i].get(), layerImplChildren[i], hostImpl);
[email protected]c0dd24c2012-08-30 23:25:27129}
130
131// Attempts to synchronizes a null tree. This should not crash, and should
132// return a null tree.
133TEST(TreeSynchronizerTest, syncNullTree)
134{
[email protected]068d7ef2012-11-05 07:17:46135 DebugScopedSetImplThread impl;
136
[email protected]96baf3e2012-10-22 23:09:55137 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(0, scoped_ptr<LayerImpl>(), 0);
[email protected]c0dd24c2012-08-30 23:25:27138
[email protected]96baf3e2012-10-22 23:09:55139 EXPECT_TRUE(!layerImplTreeRoot.get());
[email protected]c0dd24c2012-08-30 23:25:27140}
141
142// Constructs a very simple tree and synchronizes it without trying to reuse any preexisting layers.
143TEST(TreeSynchronizerTest, syncSimpleTreeFromEmpty)
144{
[email protected]068d7ef2012-11-05 07:17:46145 DebugScopedSetImplThread impl;
146
[email protected]96baf3e2012-10-22 23:09:55147 LayerTreeSettings settings;
[email protected]068d7ef2012-11-05 07:17:46148 scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0);
[email protected]c0dd24c2012-08-30 23:25:27149
[email protected]96baf3e2012-10-22 23:09:55150 scoped_refptr<Layer> layerTreeRoot = Layer::create();
151 layerTreeRoot->addChild(Layer::create());
152 layerTreeRoot->addChild(Layer::create());
[email protected]c0dd24c2012-08-30 23:25:27153
[email protected]96baf3e2012-10-22 23:09:55154 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl.get());
[email protected]c0dd24c2012-08-30 23:25:27155
[email protected]96baf3e2012-10-22 23:09:55156 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostImpl.get());
[email protected]c0dd24c2012-08-30 23:25:27157}
158
159// Constructs a very simple tree and synchronizes it attempting to reuse some layers
160TEST(TreeSynchronizerTest, syncSimpleTreeReusingLayers)
161{
[email protected]068d7ef2012-11-05 07:17:46162 DebugScopedSetImplThread impl;
[email protected]2cdbdba2012-10-28 13:15:05163 std::vector<int> layerImplDestructionList;
[email protected]c0dd24c2012-08-30 23:25:27164
[email protected]96baf3e2012-10-22 23:09:55165 LayerTreeSettings settings;
[email protected]068d7ef2012-11-05 07:17:46166 scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0);
[email protected]c0dd24c2012-08-30 23:25:27167
[email protected]96baf3e2012-10-22 23:09:55168 scoped_refptr<Layer> layerTreeRoot = MockLayer::create(&layerImplDestructionList);
169 layerTreeRoot->addChild(MockLayer::create(&layerImplDestructionList));
170 layerTreeRoot->addChild(MockLayer::create(&layerImplDestructionList));
[email protected]c0dd24c2012-08-30 23:25:27171
[email protected]96baf3e2012-10-22 23:09:55172 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl.get());
173 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostImpl.get());
[email protected]c0dd24c2012-08-30 23:25:27174
[email protected]96baf3e2012-10-22 23:09:55175 // Add a new layer to the Layer side
176 layerTreeRoot->children()[0]->addChild(MockLayer::create(&layerImplDestructionList));
[email protected]c0dd24c2012-08-30 23:25:27177 // Remove one.
178 layerTreeRoot->children()[1]->removeFromParent();
[email protected]96baf3e2012-10-22 23:09:55179 int secondLayerImplId = layerImplTreeRoot->children()[1]->id();
[email protected]c0dd24c2012-08-30 23:25:27180
[email protected]96baf3e2012-10-22 23:09:55181 // Synchronize again. After the sync the trees should be equivalent and we should have created and destroyed one LayerImpl.
182 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), hostImpl.get());
183 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostImpl.get());
[email protected]c0dd24c2012-08-30 23:25:27184
[email protected]96baf3e2012-10-22 23:09:55185 ASSERT_EQ(1u, layerImplDestructionList.size());
186 EXPECT_EQ(secondLayerImplId, layerImplDestructionList[0]);
[email protected]c0dd24c2012-08-30 23:25:27187}
188
189// Constructs a very simple tree and checks that a stacking-order change is tracked properly.
190TEST(TreeSynchronizerTest, syncSimpleTreeAndTrackStackingOrderChange)
191{
[email protected]068d7ef2012-11-05 07:17:46192 DebugScopedSetImplThread impl;
[email protected]2cdbdba2012-10-28 13:15:05193 std::vector<int> layerImplDestructionList;
[email protected]c0dd24c2012-08-30 23:25:27194
[email protected]96baf3e2012-10-22 23:09:55195 LayerTreeSettings settings;
[email protected]068d7ef2012-11-05 07:17:46196 scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0);
[email protected]c0dd24c2012-08-30 23:25:27197
198 // Set up the tree and sync once. child2 needs to be synced here, too, even though we
199 // remove it to set up the intended scenario.
[email protected]96baf3e2012-10-22 23:09:55200 scoped_refptr<Layer> layerTreeRoot = MockLayer::create(&layerImplDestructionList);
201 scoped_refptr<Layer> child2 = MockLayer::create(&layerImplDestructionList);
202 layerTreeRoot->addChild(MockLayer::create(&layerImplDestructionList));
[email protected]c0dd24c2012-08-30 23:25:27203 layerTreeRoot->addChild(child2);
[email protected]96baf3e2012-10-22 23:09:55204 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl.get());
205 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostImpl.get());
206 layerImplTreeRoot->resetAllChangeTrackingForSubtree();
[email protected]c0dd24c2012-08-30 23:25:27207
208 // re-insert the layer and sync again.
209 child2->removeFromParent();
210 layerTreeRoot->addChild(child2);
[email protected]96baf3e2012-10-22 23:09:55211 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), hostImpl.get());
212 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostImpl.get());
[email protected]c0dd24c2012-08-30 23:25:27213
214 // Check that the impl thread properly tracked the change.
[email protected]96baf3e2012-10-22 23:09:55215 EXPECT_FALSE(layerImplTreeRoot->layerPropertyChanged());
216 EXPECT_FALSE(layerImplTreeRoot->children()[0]->layerPropertyChanged());
217 EXPECT_TRUE(layerImplTreeRoot->children()[1]->layerPropertyChanged());
[email protected]c0dd24c2012-08-30 23:25:27218}
219
220TEST(TreeSynchronizerTest, syncSimpleTreeAndProperties)
221{
[email protected]068d7ef2012-11-05 07:17:46222 DebugScopedSetImplThread impl;
223
[email protected]96baf3e2012-10-22 23:09:55224 LayerTreeSettings settings;
[email protected]068d7ef2012-11-05 07:17:46225 scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0);
[email protected]c0dd24c2012-08-30 23:25:27226
[email protected]96baf3e2012-10-22 23:09:55227 scoped_refptr<Layer> layerTreeRoot = Layer::create();
228 layerTreeRoot->addChild(Layer::create());
229 layerTreeRoot->addChild(Layer::create());
[email protected]c0dd24c2012-08-30 23:25:27230
231 // Pick some random properties to set. The values are not important, we're just testing that at least some properties are making it through.
[email protected]aad0a0072012-11-01 18:15:58232 gfx::PointF rootPosition = gfx::PointF(2.3f, 7.4f);
[email protected]c0dd24c2012-08-30 23:25:27233 layerTreeRoot->setPosition(rootPosition);
234
235 float firstChildOpacity = 0.25f;
236 layerTreeRoot->children()[0]->setOpacity(firstChildOpacity);
237
[email protected]aad0a0072012-11-01 18:15:58238 gfx::Size secondChildBounds = gfx::Size(25, 53);
[email protected]c0dd24c2012-08-30 23:25:27239 layerTreeRoot->children()[1]->setBounds(secondChildBounds);
240
[email protected]96baf3e2012-10-22 23:09:55241 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl.get());
242 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostImpl.get());
[email protected]c0dd24c2012-08-30 23:25:27243
[email protected]96baf3e2012-10-22 23:09:55244 // Check that the property values we set on the Layer tree are reflected in the LayerImpl tree.
[email protected]aad0a0072012-11-01 18:15:58245 gfx::PointF rootLayerImplPosition = layerImplTreeRoot->position();
[email protected]96baf3e2012-10-22 23:09:55246 EXPECT_EQ(rootPosition.x(), rootLayerImplPosition.x());
247 EXPECT_EQ(rootPosition.y(), rootLayerImplPosition.y());
[email protected]c0dd24c2012-08-30 23:25:27248
[email protected]96baf3e2012-10-22 23:09:55249 EXPECT_EQ(firstChildOpacity, layerImplTreeRoot->children()[0]->opacity());
[email protected]c0dd24c2012-08-30 23:25:27250
[email protected]aad0a0072012-11-01 18:15:58251 gfx::Size secondLayerImplChildBounds = layerImplTreeRoot->children()[1]->bounds();
[email protected]96baf3e2012-10-22 23:09:55252 EXPECT_EQ(secondChildBounds.width(), secondLayerImplChildBounds.width());
253 EXPECT_EQ(secondChildBounds.height(), secondLayerImplChildBounds.height());
[email protected]c0dd24c2012-08-30 23:25:27254}
255
[email protected]96baf3e2012-10-22 23:09:55256TEST(TreeSynchronizerTest, reuseLayerImplsAfterStructuralChange)
[email protected]c0dd24c2012-08-30 23:25:27257{
[email protected]068d7ef2012-11-05 07:17:46258 DebugScopedSetImplThread impl;
[email protected]2cdbdba2012-10-28 13:15:05259 std::vector<int> layerImplDestructionList;
[email protected]c0dd24c2012-08-30 23:25:27260
[email protected]96baf3e2012-10-22 23:09:55261 LayerTreeSettings settings;
[email protected]068d7ef2012-11-05 07:17:46262 scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0);
[email protected]c0dd24c2012-08-30 23:25:27263
264 // Set up a tree with this sort of structure:
265 // root --- A --- B ---+--- C
266 // |
267 // +--- D
[email protected]96baf3e2012-10-22 23:09:55268 scoped_refptr<Layer> layerTreeRoot = MockLayer::create(&layerImplDestructionList);
269 layerTreeRoot->addChild(MockLayer::create(&layerImplDestructionList));
[email protected]c0dd24c2012-08-30 23:25:27270
[email protected]96baf3e2012-10-22 23:09:55271 scoped_refptr<Layer> layerA = layerTreeRoot->children()[0].get();
272 layerA->addChild(MockLayer::create(&layerImplDestructionList));
[email protected]c0dd24c2012-08-30 23:25:27273
[email protected]96baf3e2012-10-22 23:09:55274 scoped_refptr<Layer> layerB = layerA->children()[0].get();
275 layerB->addChild(MockLayer::create(&layerImplDestructionList));
[email protected]c0dd24c2012-08-30 23:25:27276
[email protected]96baf3e2012-10-22 23:09:55277 scoped_refptr<Layer> layerC = layerB->children()[0].get();
278 layerB->addChild(MockLayer::create(&layerImplDestructionList));
279 scoped_refptr<Layer> layerD = layerB->children()[1].get();
[email protected]c0dd24c2012-08-30 23:25:27280
[email protected]96baf3e2012-10-22 23:09:55281 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl.get());
282 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostImpl.get());
[email protected]c0dd24c2012-08-30 23:25:27283
284 // Now restructure the tree to look like this:
285 // root --- D ---+--- A
286 // |
287 // +--- C --- B
288 layerTreeRoot->removeAllChildren();
289 layerD->removeAllChildren();
290 layerTreeRoot->addChild(layerD);
291 layerA->removeAllChildren();
292 layerD->addChild(layerA);
293 layerC->removeAllChildren();
294 layerD->addChild(layerC);
295 layerB->removeAllChildren();
296 layerC->addChild(layerB);
297
[email protected]96baf3e2012-10-22 23:09:55298 // After another synchronize our trees should match and we should not have destroyed any LayerImpls
299 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), hostImpl.get());
300 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostImpl.get());
[email protected]c0dd24c2012-08-30 23:25:27301
[email protected]96baf3e2012-10-22 23:09:55302 EXPECT_EQ(0u, layerImplDestructionList.size());
[email protected]c0dd24c2012-08-30 23:25:27303}
304
305// Constructs a very simple tree, synchronizes it, then synchronizes to a totally new tree. All layers from the old tree should be deleted.
306TEST(TreeSynchronizerTest, syncSimpleTreeThenDestroy)
307{
[email protected]068d7ef2012-11-05 07:17:46308 DebugScopedSetImplThread impl;
[email protected]2cdbdba2012-10-28 13:15:05309 std::vector<int> layerImplDestructionList;
[email protected]c0dd24c2012-08-30 23:25:27310
[email protected]96baf3e2012-10-22 23:09:55311 LayerTreeSettings settings;
[email protected]068d7ef2012-11-05 07:17:46312 scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0);
[email protected]c0dd24c2012-08-30 23:25:27313
[email protected]96baf3e2012-10-22 23:09:55314 scoped_refptr<Layer> oldLayerTreeRoot = MockLayer::create(&layerImplDestructionList);
315 oldLayerTreeRoot->addChild(MockLayer::create(&layerImplDestructionList));
316 oldLayerTreeRoot->addChild(MockLayer::create(&layerImplDestructionList));
[email protected]c0dd24c2012-08-30 23:25:27317
318 int oldTreeRootLayerId = oldLayerTreeRoot->id();
319 int oldTreeFirstChildLayerId = oldLayerTreeRoot->children()[0]->id();
320 int oldTreeSecondChildLayerId = oldLayerTreeRoot->children()[1]->id();
321
[email protected]96baf3e2012-10-22 23:09:55322 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(oldLayerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl.get());
323 expectTreesAreIdentical(oldLayerTreeRoot.get(), layerImplTreeRoot.get(), hostImpl.get());
[email protected]c0dd24c2012-08-30 23:25:27324
[email protected]96baf3e2012-10-22 23:09:55325 // Remove all children on the Layer side.
[email protected]c0dd24c2012-08-30 23:25:27326 oldLayerTreeRoot->removeAllChildren();
327
[email protected]96baf3e2012-10-22 23:09:55328 // Synchronize again. After the sync all LayerImpls from the old tree should be deleted.
329 scoped_refptr<Layer> newLayerTreeRoot = Layer::create();
330 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(newLayerTreeRoot.get(), layerImplTreeRoot.Pass(), hostImpl.get());
331 expectTreesAreIdentical(newLayerTreeRoot.get(), layerImplTreeRoot.get(), hostImpl.get());
[email protected]c0dd24c2012-08-30 23:25:27332
[email protected]96baf3e2012-10-22 23:09:55333 ASSERT_EQ(3u, layerImplDestructionList.size());
[email protected]2cdbdba2012-10-28 13:15:05334
335 EXPECT_TRUE(std::find(layerImplDestructionList.begin(), layerImplDestructionList.end(), oldTreeRootLayerId) != layerImplDestructionList.end());
336 EXPECT_TRUE(std::find(layerImplDestructionList.begin(), layerImplDestructionList.end(), oldTreeFirstChildLayerId) != layerImplDestructionList.end());
337 EXPECT_TRUE(std::find(layerImplDestructionList.begin(), layerImplDestructionList.end(), oldTreeSecondChildLayerId) != layerImplDestructionList.end());
[email protected]c0dd24c2012-08-30 23:25:27338}
339
340// Constructs+syncs a tree with mask, replica, and replica mask layers.
341TEST(TreeSynchronizerTest, syncMaskReplicaAndReplicaMaskLayers)
342{
[email protected]068d7ef2012-11-05 07:17:46343 DebugScopedSetImplThread impl;
344
[email protected]96baf3e2012-10-22 23:09:55345 LayerTreeSettings settings;
[email protected]068d7ef2012-11-05 07:17:46346 scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0);
[email protected]c0dd24c2012-08-30 23:25:27347
[email protected]96baf3e2012-10-22 23:09:55348 scoped_refptr<Layer> layerTreeRoot = Layer::create();
349 layerTreeRoot->addChild(Layer::create());
350 layerTreeRoot->addChild(Layer::create());
351 layerTreeRoot->addChild(Layer::create());
[email protected]c0dd24c2012-08-30 23:25:27352
353 // First child gets a mask layer.
[email protected]96baf3e2012-10-22 23:09:55354 scoped_refptr<Layer> maskLayer = Layer::create();
[email protected]c0dd24c2012-08-30 23:25:27355 layerTreeRoot->children()[0]->setMaskLayer(maskLayer.get());
356
357 // Second child gets a replica layer.
[email protected]96baf3e2012-10-22 23:09:55358 scoped_refptr<Layer> replicaLayer = Layer::create();
[email protected]c0dd24c2012-08-30 23:25:27359 layerTreeRoot->children()[1]->setReplicaLayer(replicaLayer.get());
360
361 // Third child gets a replica layer with a mask layer.
[email protected]96baf3e2012-10-22 23:09:55362 scoped_refptr<Layer> replicaLayerWithMask = Layer::create();
363 scoped_refptr<Layer> replicaMaskLayer = Layer::create();
[email protected]c0dd24c2012-08-30 23:25:27364 replicaLayerWithMask->setMaskLayer(replicaMaskLayer.get());
365 layerTreeRoot->children()[2]->setReplicaLayer(replicaLayerWithMask.get());
366
[email protected]96baf3e2012-10-22 23:09:55367 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl.get());
[email protected]c0dd24c2012-08-30 23:25:27368
[email protected]96baf3e2012-10-22 23:09:55369 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostImpl.get());
[email protected]c0dd24c2012-08-30 23:25:27370
371 // Remove the mask layer.
372 layerTreeRoot->children()[0]->setMaskLayer(0);
[email protected]96baf3e2012-10-22 23:09:55373 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), hostImpl.get());
374 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostImpl.get());
[email protected]c0dd24c2012-08-30 23:25:27375
376 // Remove the replica layer.
377 layerTreeRoot->children()[1]->setReplicaLayer(0);
[email protected]96baf3e2012-10-22 23:09:55378 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), hostImpl.get());
379 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostImpl.get());
[email protected]c0dd24c2012-08-30 23:25:27380
381 // Remove the replica mask.
382 replicaLayerWithMask->setMaskLayer(0);
[email protected]96baf3e2012-10-22 23:09:55383 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), hostImpl.get());
384 expectTreesAreIdentical(layerTreeRoot.get(), layerImplTreeRoot.get(), hostImpl.get());
[email protected]c0dd24c2012-08-30 23:25:27385}
386
387TEST(TreeSynchronizerTest, synchronizeAnimations)
388{
[email protected]068d7ef2012-11-05 07:17:46389 DebugScopedSetImplThread impl;
390
[email protected]96baf3e2012-10-22 23:09:55391 LayerTreeSettings settings;
[email protected]068d7ef2012-11-05 07:17:46392 scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0);
[email protected]c0dd24c2012-08-30 23:25:27393
[email protected]96baf3e2012-10-22 23:09:55394 scoped_refptr<Layer> layerTreeRoot = Layer::create();
[email protected]c0dd24c2012-08-30 23:25:27395
396 FakeLayerAnimationControllerClient dummy;
[email protected]96baf3e2012-10-22 23:09:55397 layerTreeRoot->setLayerAnimationController(FakeLayerAnimationController::create(&dummy).PassAs<LayerAnimationController>());
[email protected]c0dd24c2012-08-30 23:25:27398
399 EXPECT_FALSE(static_cast<FakeLayerAnimationController*>(layerTreeRoot->layerAnimationController())->synchronizedAnimations());
400
[email protected]96baf3e2012-10-22 23:09:55401 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl.get());
402 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), hostImpl.get());
[email protected]c0dd24c2012-08-30 23:25:27403
404 EXPECT_TRUE(static_cast<FakeLayerAnimationController*>(layerTreeRoot->layerAnimationController())->synchronizedAnimations());
405}
406
[email protected]bc5e77c2012-11-05 20:00:49407} // anonymous namespace