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

Side by Side Diff: webkit/compositor/TreeSynchronizerTest.cpp

Issue 10920056: Make cc_unittests and webkit_compositor_unittests executable always (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rename to webkit_compositor_bindings Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "config.h"
6
7 #include "TreeSynchronizer.h"
8
9 #include "CCAnimationTestCommon.h"
10 #include "CCLayerAnimationController.h"
11 #include "CCLayerImpl.h"
12 #include "CCProxy.h"
13 #include "CCSingleThreadProxy.h"
14 #include "LayerChromium.h"
15 #include "Region.h"
16 #include <gtest/gtest.h>
17
18 using namespace WebCore;
19 using namespace WebKitTests;
20
21 namespace {
22
23 class MockCCLayerImpl : public CCLayerImpl {
24 public:
25 static PassOwnPtr<MockCCLayerImpl> create(int layerId)
26 {
27 return adoptPtr(new MockCCLayerImpl(layerId));
28 }
29 virtual ~MockCCLayerImpl()
30 {
31 if (m_ccLayerDestructionList)
32 m_ccLayerDestructionList->append(id());
33 }
34
35 void setCCLayerDestructionList(Vector<int>* list) { m_ccLayerDestructionList = list; }
36
37 private:
38 MockCCLayerImpl(int layerId)
39 : CCLayerImpl(layerId)
40 , m_ccLayerDestructionList(0)
41 {
42 }
43
44 Vector<int>* m_ccLayerDestructionList;
45 };
46
47 class MockLayerChromium : public LayerChromium {
48 public:
49 static PassRefPtr<MockLayerChromium> create(Vector<int>* ccLayerDestructionL ist)
50 {
51 return adoptRef(new MockLayerChromium(ccLayerDestructionList));
52 }
53
54 virtual ~MockLayerChromium() { }
55
56 virtual PassOwnPtr<CCLayerImpl> createCCLayerImpl() OVERRIDE
57 {
58 return MockCCLayerImpl::create(m_layerId);
59 }
60
61 virtual void pushPropertiesTo(CCLayerImpl* ccLayer) OVERRIDE
62 {
63 LayerChromium::pushPropertiesTo(ccLayer);
64
65 MockCCLayerImpl* mockCCLayer = static_cast<MockCCLayerImpl*>(ccLayer);
66 mockCCLayer->setCCLayerDestructionList(m_ccLayerDestructionList);
67 }
68 private:
69 MockLayerChromium(Vector<int>* ccLayerDestructionList)
70 : LayerChromium()
71 , m_ccLayerDestructionList(ccLayerDestructionList)
72 {
73 }
74
75 Vector<int>* m_ccLayerDestructionList;
76 };
77
78 class FakeLayerAnimationController : public CCLayerAnimationController {
79 public:
80 static PassOwnPtr<FakeLayerAnimationController> create(CCLayerAnimationContr ollerClient* client)
81 {
82 return adoptPtr(new FakeLayerAnimationController(client));
83 }
84
85 bool synchronizedAnimations() const { return m_synchronizedAnimations; }
86
87 private:
88 explicit FakeLayerAnimationController(CCLayerAnimationControllerClient* clie nt)
89 : CCLayerAnimationController(client)
90 , m_synchronizedAnimations(false)
91 {
92 }
93
94 virtual void pushAnimationUpdatesTo(CCLayerAnimationController* controllerIm pl)
95 {
96 CCLayerAnimationController::pushAnimationUpdatesTo(controllerImpl);
97 m_synchronizedAnimations = true;
98 }
99
100 bool m_synchronizedAnimations;
101 };
102
103 void expectTreesAreIdentical(LayerChromium* layer, CCLayerImpl* ccLayer, CCLayer TreeHostImpl* hostImpl)
104 {
105 ASSERT_TRUE(layer);
106 ASSERT_TRUE(ccLayer);
107
108 EXPECT_EQ(layer->id(), ccLayer->id());
109 EXPECT_EQ(ccLayer->layerTreeHostImpl(), hostImpl);
110
111 EXPECT_EQ(layer->nonFastScrollableRegion(), ccLayer->nonFastScrollableRegion ());
112
113 ASSERT_EQ(!!layer->maskLayer(), !!ccLayer->maskLayer());
114 if (layer->maskLayer())
115 expectTreesAreIdentical(layer->maskLayer(), ccLayer->maskLayer(), hostIm pl);
116
117 ASSERT_EQ(!!layer->replicaLayer(), !!ccLayer->replicaLayer());
118 if (layer->replicaLayer())
119 expectTreesAreIdentical(layer->replicaLayer(), ccLayer->replicaLayer(), hostImpl);
120
121 const Vector<RefPtr<LayerChromium> >& layerChildren = layer->children();
122 const Vector<OwnPtr<CCLayerImpl> >& ccLayerChildren = ccLayer->children();
123
124 ASSERT_EQ(layerChildren.size(), ccLayerChildren.size());
125
126 for (size_t i = 0; i < layerChildren.size(); ++i)
127 expectTreesAreIdentical(layerChildren[i].get(), ccLayerChildren[i].get() , hostImpl);
128 }
129
130 // Attempts to synchronizes a null tree. This should not crash, and should
131 // return a null tree.
132 TEST(TreeSynchronizerTest, syncNullTree)
133 {
134 DebugScopedSetImplThread impl;
135
136 OwnPtr<CCLayerImpl> ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(0, nullptr, 0);
137
138 EXPECT_TRUE(!ccLayerTreeRoot.get());
139 }
140
141 // Constructs a very simple tree and synchronizes it without trying to reuse any preexisting layers.
142 TEST(TreeSynchronizerTest, syncSimpleTreeFromEmpty)
143 {
144 DebugScopedSetImplThread impl;
145
146 CCLayerTreeSettings settings;
147 OwnPtr<CCLayerTreeHostImpl> hostImpl = CCLayerTreeHostImpl::create(settings, 0);
148
149 RefPtr<LayerChromium> layerTreeRoot = LayerChromium::create();
150 layerTreeRoot->addChild(LayerChromium::create());
151 layerTreeRoot->addChild(LayerChromium::create());
152
153 OwnPtr<CCLayerImpl> ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(lay erTreeRoot.get(), nullptr, hostImpl.get());
154
155 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl .get());
156 }
157
158 // Constructs a very simple tree and synchronizes it attempting to reuse some la yers
159 TEST(TreeSynchronizerTest, syncSimpleTreeReusingLayers)
160 {
161 DebugScopedSetImplThread impl;
162 Vector<int> ccLayerDestructionList;
163
164 CCLayerTreeSettings settings;
165 OwnPtr<CCLayerTreeHostImpl> hostImpl = CCLayerTreeHostImpl::create(settings, 0);
166
167 RefPtr<LayerChromium> layerTreeRoot = MockLayerChromium::create(&ccLayerDest ructionList);
168 layerTreeRoot->addChild(MockLayerChromium::create(&ccLayerDestructionList));
169 layerTreeRoot->addChild(MockLayerChromium::create(&ccLayerDestructionList));
170
171 OwnPtr<CCLayerImpl> ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(lay erTreeRoot.get(), nullptr, hostImpl.get());
172 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl .get());
173
174 // Add a new layer to the LayerChromium side
175 layerTreeRoot->children()[0]->addChild(MockLayerChromium::create(&ccLayerDes tructionList));
176 // Remove one.
177 layerTreeRoot->children()[1]->removeFromParent();
178 int secondCCLayerId = ccLayerTreeRoot->children()[1]->id();
179
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());
182 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl .get());
183
184 ASSERT_EQ(1u, ccLayerDestructionList.size());
185 EXPECT_EQ(secondCCLayerId, ccLayerDestructionList[0]);
186 }
187
188 // Constructs a very simple tree and checks that a stacking-order change is trac ked properly.
189 TEST(TreeSynchronizerTest, syncSimpleTreeAndTrackStackingOrderChange)
190 {
191 DebugScopedSetImplThread impl;
192 Vector<int> ccLayerDestructionList;
193
194 CCLayerTreeSettings settings;
195 OwnPtr<CCLayerTreeHostImpl> hostImpl = CCLayerTreeHostImpl::create(settings, 0);
196
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.
199 RefPtr<LayerChromium> layerTreeRoot = MockLayerChromium::create(&ccLayerDest ructionList);
200 RefPtr<LayerChromium> child2 = MockLayerChromium::create(&ccLayerDestruction List);
201 layerTreeRoot->addChild(MockLayerChromium::create(&ccLayerDestructionList));
202 layerTreeRoot->addChild(child2);
203 OwnPtr<CCLayerImpl> ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(lay erTreeRoot.get(), nullptr, hostImpl.get());
204 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl .get());
205 ccLayerTreeRoot->resetAllChangeTrackingForSubtree();
206
207 // re-insert the layer and sync again.
208 child2->removeFromParent();
209 layerTreeRoot->addChild(child2);
210 ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), cc LayerTreeRoot.release(), hostImpl.get());
211 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl .get());
212
213 // Check that the impl thread properly tracked the change.
214 EXPECT_FALSE(ccLayerTreeRoot->layerPropertyChanged());
215 EXPECT_FALSE(ccLayerTreeRoot->children()[0]->layerPropertyChanged());
216 EXPECT_TRUE(ccLayerTreeRoot->children()[1]->layerPropertyChanged());
217 }
218
219 TEST(TreeSynchronizerTest, syncSimpleTreeAndProperties)
220 {
221 DebugScopedSetImplThread impl;
222
223 CCLayerTreeSettings settings;
224 OwnPtr<CCLayerTreeHostImpl> hostImpl = CCLayerTreeHostImpl::create(settings, 0);
225
226 RefPtr<LayerChromium> layerTreeRoot = LayerChromium::create();
227 layerTreeRoot->addChild(LayerChromium::create());
228 layerTreeRoot->addChild(LayerChromium::create());
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.
231 FloatPoint rootPosition = FloatPoint(2.3f, 7.4f);
232 layerTreeRoot->setPosition(rootPosition);
233
234 float firstChildOpacity = 0.25f;
235 layerTreeRoot->children()[0]->setOpacity(firstChildOpacity);
236
237 IntSize secondChildBounds = IntSize(25, 53);
238 layerTreeRoot->children()[1]->setBounds(secondChildBounds);
239
240 OwnPtr<CCLayerImpl> ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(lay erTreeRoot.get(), nullptr, hostImpl.get());
241 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl .get());
242
243 // Check that the property values we set on the LayerChromium tree are refle cted in the CCLayerImpl tree.
244 FloatPoint rootCCLayerPosition = ccLayerTreeRoot->position();
245 EXPECT_EQ(rootPosition.x(), rootCCLayerPosition.x());
246 EXPECT_EQ(rootPosition.y(), rootCCLayerPosition.y());
247
248 EXPECT_EQ(firstChildOpacity, ccLayerTreeRoot->children()[0]->opacity());
249
250 IntSize secondCCLayerChildBounds = ccLayerTreeRoot->children()[1]->bounds();
251 EXPECT_EQ(secondChildBounds.width(), secondCCLayerChildBounds.width());
252 EXPECT_EQ(secondChildBounds.height(), secondCCLayerChildBounds.height());
253 }
254
255 TEST(TreeSynchronizerTest, reuseCCLayersAfterStructuralChange)
256 {
257 DebugScopedSetImplThread impl;
258 Vector<int> ccLayerDestructionList;
259
260 CCLayerTreeSettings settings;
261 OwnPtr<CCLayerTreeHostImpl> hostImpl = CCLayerTreeHostImpl::create(settings, 0);
262
263 // Set up a tree with this sort of structure:
264 // root --- A --- B ---+--- C
265 // |
266 // +--- D
267 RefPtr<LayerChromium> layerTreeRoot = MockLayerChromium::create(&ccLayerDest ructionList);
268 layerTreeRoot->addChild(MockLayerChromium::create(&ccLayerDestructionList));
269
270 RefPtr<LayerChromium> layerA = layerTreeRoot->children()[0].get();
271 layerA->addChild(MockLayerChromium::create(&ccLayerDestructionList));
272
273 RefPtr<LayerChromium> layerB = layerA->children()[0].get();
274 layerB->addChild(MockLayerChromium::create(&ccLayerDestructionList));
275
276 RefPtr<LayerChromium> layerC = layerB->children()[0].get();
277 layerB->addChild(MockLayerChromium::create(&ccLayerDestructionList));
278 RefPtr<LayerChromium> layerD = layerB->children()[1].get();
279
280 OwnPtr<CCLayerImpl> ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(lay erTreeRoot.get(), nullptr, hostImpl.get());
281 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl .get());
282
283 // Now restructure the tree to look like this:
284 // root --- D ---+--- A
285 // |
286 // +--- C --- B
287 layerTreeRoot->removeAllChildren();
288 layerD->removeAllChildren();
289 layerTreeRoot->addChild(layerD);
290 layerA->removeAllChildren();
291 layerD->addChild(layerA);
292 layerC->removeAllChildren();
293 layerD->addChild(layerC);
294 layerB->removeAllChildren();
295 layerC->addChild(layerB);
296
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());
299 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl .get());
300
301 EXPECT_EQ(0u, ccLayerDestructionList.size());
302 }
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.
305 TEST(TreeSynchronizerTest, syncSimpleTreeThenDestroy)
306 {
307 DebugScopedSetImplThread impl;
308 Vector<int> ccLayerDestructionList;
309
310 CCLayerTreeSettings settings;
311 OwnPtr<CCLayerTreeHostImpl> hostImpl = CCLayerTreeHostImpl::create(settings, 0);
312
313 RefPtr<LayerChromium> oldLayerTreeRoot = MockLayerChromium::create(&ccLayerD estructionList);
314 oldLayerTreeRoot->addChild(MockLayerChromium::create(&ccLayerDestructionList ));
315 oldLayerTreeRoot->addChild(MockLayerChromium::create(&ccLayerDestructionList ));
316
317 int oldTreeRootLayerId = oldLayerTreeRoot->id();
318 int oldTreeFirstChildLayerId = oldLayerTreeRoot->children()[0]->id();
319 int oldTreeSecondChildLayerId = oldLayerTreeRoot->children()[1]->id();
320
321 OwnPtr<CCLayerImpl> ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(old LayerTreeRoot.get(), nullptr, hostImpl.get());
322 expectTreesAreIdentical(oldLayerTreeRoot.get(), ccLayerTreeRoot.get(), hostI mpl.get());
323
324 // Remove all children on the LayerChromium side.
325 oldLayerTreeRoot->removeAllChildren();
326
327 // Synchronize again. After the sync all CCLayerImpls from the old tree shou ld be deleted.
328 RefPtr<LayerChromium> newLayerTreeRoot = LayerChromium::create();
329 ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(newLayerTreeRoot.get(), ccLayerTreeRoot.release(), hostImpl.get());
330 expectTreesAreIdentical(newLayerTreeRoot.get(), ccLayerTreeRoot.get(), hostI mpl.get());
331
332 ASSERT_EQ(3u, ccLayerDestructionList.size());
333 EXPECT_TRUE(ccLayerDestructionList.contains(oldTreeRootLayerId));
334 EXPECT_TRUE(ccLayerDestructionList.contains(oldTreeFirstChildLayerId));
335 EXPECT_TRUE(ccLayerDestructionList.contains(oldTreeSecondChildLayerId));
336 }
337
338 // Constructs+syncs a tree with mask, replica, and replica mask layers.
339 TEST(TreeSynchronizerTest, syncMaskReplicaAndReplicaMaskLayers)
340 {
341 DebugScopedSetImplThread impl;
342
343 CCLayerTreeSettings settings;
344 OwnPtr<CCLayerTreeHostImpl> hostImpl = CCLayerTreeHostImpl::create(settings, 0);
345
346 RefPtr<LayerChromium> layerTreeRoot = LayerChromium::create();
347 layerTreeRoot->addChild(LayerChromium::create());
348 layerTreeRoot->addChild(LayerChromium::create());
349 layerTreeRoot->addChild(LayerChromium::create());
350
351 // First child gets a mask layer.
352 RefPtr<LayerChromium> maskLayer = LayerChromium::create();
353 layerTreeRoot->children()[0]->setMaskLayer(maskLayer.get());
354
355 // Second child gets a replica layer.
356 RefPtr<LayerChromium> replicaLayer = LayerChromium::create();
357 layerTreeRoot->children()[1]->setReplicaLayer(replicaLayer.get());
358
359 // Third child gets a replica layer with a mask layer.
360 RefPtr<LayerChromium> replicaLayerWithMask = LayerChromium::create();
361 RefPtr<LayerChromium> replicaMaskLayer = LayerChromium::create();
362 replicaLayerWithMask->setMaskLayer(replicaMaskLayer.get());
363 layerTreeRoot->children()[2]->setReplicaLayer(replicaLayerWithMask.get());
364
365 OwnPtr<CCLayerImpl> ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(lay erTreeRoot.get(), nullptr, hostImpl.get());
366
367 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl .get());
368
369 // Remove the mask layer.
370 layerTreeRoot->children()[0]->setMaskLayer(0);
371 ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), cc LayerTreeRoot.release(), hostImpl.get());
372 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl .get());
373
374 // Remove the replica layer.
375 layerTreeRoot->children()[1]->setReplicaLayer(0);
376 ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), cc LayerTreeRoot.release(), hostImpl.get());
377 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl .get());
378
379 // Remove the replica mask.
380 replicaLayerWithMask->setMaskLayer(0);
381 ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), cc LayerTreeRoot.release(), hostImpl.get());
382 expectTreesAreIdentical(layerTreeRoot.get(), ccLayerTreeRoot.get(), hostImpl .get());
383 }
384
385 TEST(TreeSynchronizerTest, synchronizeAnimations)
386 {
387 DebugScopedSetImplThread impl;
388
389 CCLayerTreeSettings settings;
390 OwnPtr<CCLayerTreeHostImpl> hostImpl = CCLayerTreeHostImpl::create(settings, 0);
391
392 RefPtr<LayerChromium> layerTreeRoot = LayerChromium::create();
393
394 FakeLayerAnimationControllerClient dummy;
395 layerTreeRoot->setLayerAnimationController(FakeLayerAnimationController::cre ate(&dummy));
396
397 EXPECT_FALSE(static_cast<FakeLayerAnimationController*>(layerTreeRoot->layer AnimationController())->synchronizedAnimations());
398
399 OwnPtr<CCLayerImpl> ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(lay erTreeRoot.get(), nullptr, hostImpl.get());
400 ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), cc LayerTreeRoot.release(), hostImpl.get());
401
402 EXPECT_TRUE(static_cast<FakeLayerAnimationController*>(layerTreeRoot->layerA nimationController())->synchronizedAnimations());
403 }
404
405 } // namespace
OLDNEW
« no previous file with comments | « webkit/compositor/TouchpadFlingPlatformGestureCurve.h ('k') | webkit/compositor/WebAnimationCurveCommon.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698