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

Side by Side Diff: cc/layer_tree_host_common_unittest.cc

Issue 11567034: Changes subtreeShouldRenderToSeparateSurface logic to account for explicit clipping (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: adding a unit test and renaming adding a unit test and renaming can_clip_self" Created 8 years 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
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/layer_tree_host_common.h" 5 #include "cc/layer_tree_host_common.h"
6 6
7 #include "cc/content_layer.h" 7 #include "cc/content_layer.h"
8 #include "cc/content_layer_client.h" 8 #include "cc/content_layer_client.h"
9 #include "cc/layer.h" 9 #include "cc/layer.h"
10 #include "cc/layer_animation_controller.h" 10 #include "cc/layer_animation_controller.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 } 106 }
107 107
108 virtual bool drawsContent() const OVERRIDE { return true; } 108 virtual bool drawsContent() const OVERRIDE { return true; }
109 109
110 private: 110 private:
111 virtual ~LayerWithForcedDrawsContent() 111 virtual ~LayerWithForcedDrawsContent()
112 { 112 {
113 } 113 }
114 }; 114 };
115 115
116 class LayerCanClipSelf : public Layer {
117 public:
118 LayerCanClipSelf()
119 : Layer()
120 {
121 }
122
123 virtual bool drawsContent() const OVERRIDE { return true; }
124 virtual bool canClipSelf() const OVERRIDE { return true; }
125
126 private:
127 virtual ~LayerCanClipSelf()
128 {
129 }
130 };
131
116 class MockContentLayerClient : public ContentLayerClient { 132 class MockContentLayerClient : public ContentLayerClient {
117 public: 133 public:
118 MockContentLayerClient() { } 134 MockContentLayerClient() { }
119 virtual ~MockContentLayerClient() { } 135 virtual ~MockContentLayerClient() { }
120 virtual void paintContents(SkCanvas*, const gfx::Rect& clip, gfx::RectF& opa que) OVERRIDE { } 136 virtual void paintContents(SkCanvas*, const gfx::Rect& clip, gfx::RectF& opa que) OVERRIDE { }
121 }; 137 };
122 138
123 scoped_refptr<ContentLayer> createDrawableContentLayer(ContentLayerClient* deleg ate) 139 scoped_refptr<ContentLayer> createDrawableContentLayer(ContentLayerClient* deleg ate)
124 { 140 {
125 scoped_refptr<ContentLayer> toReturn = ContentLayer::create(delegate); 141 scoped_refptr<ContentLayer> toReturn = ContentLayer::create(delegate);
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 // Child is set up so that a new render surface should be created. 344 // Child is set up so that a new render surface should be created.
329 child->setOpacity(0.5); 345 child->setOpacity(0.5);
330 child->setForceRenderSurface(true); 346 child->setForceRenderSurface(true);
331 347
332 gfx::Transform parentLayerTransform; 348 gfx::Transform parentLayerTransform;
333 parentLayerTransform.Scale3d(1, 0.9, 1); 349 parentLayerTransform.Scale3d(1, 0.9, 1);
334 gfx::Transform parentTranslationToAnchor; 350 gfx::Transform parentTranslationToAnchor;
335 parentTranslationToAnchor.Translate(25, 30); 351 parentTranslationToAnchor.Translate(25, 30);
336 gfx::Transform parentSublayerMatrix; 352 gfx::Transform parentSublayerMatrix;
337 parentSublayerMatrix.Scale3d(0.9, 1, 3.3); 353 parentSublayerMatrix.Scale3d(0.9, 1, 3.3);
354
shawnsingh 2012/12/18 19:11:00 Did you add these empty lines here with the intent
whunt 2012/12/18 19:48:15 Just trying to read the code, I'll remove them. O
338 gfx::Transform parentTranslationToCenter; 355 gfx::Transform parentTranslationToCenter;
339 parentTranslationToCenter.Translate(50, 60); 356 parentTranslationToCenter.Translate(50, 60);
357
340 gfx::Transform parentCompositeTransform = parentTranslationToAnchor * parent LayerTransform * MathUtil::inverse(parentTranslationToAnchor) 358 gfx::Transform parentCompositeTransform = parentTranslationToAnchor * parent LayerTransform * MathUtil::inverse(parentTranslationToAnchor)
341 * parentTranslationToCenter * parentSublayerMatrix * MathUtil::inver se(parentTranslationToCenter); 359 * parentTranslationToCenter * parentSublayerMatrix * MathUtil::inver se(parentTranslationToCenter);
360
342 gfx::Vector2dF parentCompositeScale = MathUtil::computeTransform2dScaleCompo nents(parentCompositeTransform); 361 gfx::Vector2dF parentCompositeScale = MathUtil::computeTransform2dScaleCompo nents(parentCompositeTransform);
362
343 gfx::Transform surfaceSublayerTransform; 363 gfx::Transform surfaceSublayerTransform;
344 surfaceSublayerTransform.Scale(parentCompositeScale.x(), parentCompositeScal e.y()); 364 surfaceSublayerTransform.Scale(parentCompositeScale.x(), parentCompositeScal e.y());
365
345 gfx::Transform surfaceSublayerCompositeTransform = parentCompositeTransform * MathUtil::inverse(surfaceSublayerTransform); 366 gfx::Transform surfaceSublayerCompositeTransform = parentCompositeTransform * MathUtil::inverse(surfaceSublayerTransform);
346 367
347 // Child's render surface should not exist yet. 368 // Child's render surface should not exist yet.
348 ASSERT_FALSE(child->renderSurface()); 369 ASSERT_FALSE(child->renderSurface());
349 370
350 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla yerMatrix, gfx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(100, 120), fals e); 371 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla yerMatrix, gfx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(100, 120), fals e);
351 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(16, 18), false); 372 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(16, 18), false);
352 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(8, 10), false); 373 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(8, 10), false);
353 executeCalculateDrawProperties(root.get()); 374 executeCalculateDrawProperties(root.get());
354 375
355 // Render surface should have been created now. 376 // Render surface should have been created now.
356 ASSERT_TRUE(child->renderSurface()); 377 ASSERT_TRUE(child->renderSurface());
357 ASSERT_EQ(child, child->renderTarget()); 378 ASSERT_EQ(child, child->renderTarget());
358 379
359 // The child layer's draw transform should refer to its new render surface. 380 // The child layer's draw transform should refer to its new render surface.
360 // The screen-space transform, however, should still refer to the root. 381 // The screen-space transform, however, should still refer to the root.
361 EXPECT_TRANSFORMATION_MATRIX_EQ(surfaceSublayerTransform, child->drawTransfo rm()); 382 EXPECT_TRANSFORMATION_MATRIX_EQ(surfaceSublayerTransform, child->drawTransfo rm());
362 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpace Transform()); 383 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpace Transform());
363 384
364 // Because the grandChild is the only drawable content, the child's renderSu rface will tighten its bounds to the grandChild. 385 // Because the grandChild is the only drawable content, the child's renderSu rface will tighten its bounds to the grandChild.
365 // The scale at which the surface's subtree is drawn must be removed from th e composite transform. 386 // The scale at which the surface's subtree is drawn must be removed from th e composite transform.
366 EXPECT_TRANSFORMATION_MATRIX_EQ(surfaceSublayerCompositeTransform, child->re nderTarget()->renderSurface()->drawTransform()); 387 EXPECT_TRANSFORMATION_MATRIX_EQ(surfaceSublayerCompositeTransform, child->re nderTarget()->renderSurface()->drawTransform());
367 388
368 // The screen space is the same as the target since the child surface draws into the root. 389 // The screen space is the same as the target since the child surface draws into the root.
369 EXPECT_TRANSFORMATION_MATRIX_EQ(surfaceSublayerCompositeTransform, child->re nderTarget()->renderSurface()->screenSpaceTransform()); 390 EXPECT_TRANSFORMATION_MATRIX_EQ(surfaceSublayerCompositeTransform, child->re nderTarget()->renderSurface()->screenSpaceTransform());
370 } 391 }
371 392
393 TEST(LayerTreeHostCommonTest, verifySeparateRenderTargetRequirement)
394 {
395 {
396 scoped_refptr<Layer> root = Layer::create();
397 scoped_refptr<Layer> parent = Layer::create();
398 scoped_refptr<Layer> child = Layer::create();
399 scoped_refptr<Layer> grandChild = make_scoped_refptr(new LayerCanClipSelf( ));
400 root->addChild(parent);
401 parent->addChild(child);
402 child->addChild(grandChild);
403 parent->setMasksToBounds(true);
404 child->setMasksToBounds(true);
405
406 gfx::Transform identityMatrix;
407 gfx::Transform parentLayerTransform;
408 gfx::Transform parentSublayerMatrix;
shawnsingh 2012/12/18 19:11:00 This is unmodified; how about we just use identity
409 gfx::Transform childLayerMatrix;
410
411 // No render surface should exist yet.
412 ASSERT_FALSE(root->renderSurface());
413 ASSERT_FALSE(parent->renderSurface());
414 ASSERT_FALSE(child->renderSurface());
415 ASSERT_FALSE(grandChild->renderSurface());
416
417 // One-time setup of root layer
418 parentLayerTransform.Scale3d(1, 0.9, 1);
419 childLayerMatrix.Scale3d(0.9, 1, 3.3);
420 childLayerMatrix.Rotate(20);
421
422 setLayerPropertiesForTesting(root .get(), identityMatrix , ident ityMatrix , gfx::PointF( 0, 0), gfx::PointF(0, 0), gfx::Size( 1, 2) , false);
423 setLayerPropertiesForTesting(parent .get(), parentLayerTransform, paren tSublayerMatrix, gfx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(100, 120) , false);
424 setLayerPropertiesForTesting(child .get(), childLayerMatrix , ident ityMatrix , gfx::PointF( 0, 0), gfx::PointF(0, 0), gfx::Size( 16, 18) , false);
425 setLayerPropertiesForTesting(grandChild.get(), identityMatrix , ident ityMatrix , gfx::PointF( 0, 0), gfx::PointF(0, 0), gfx::Size( 8, 10) , false);
426
427 executeCalculateDrawProperties(root.get());
428
429 // Render surface should have been created now.
shawnsingh 2012/12/18 19:11:00 We probably want to update this comment, should pr
430 ASSERT_TRUE(root->renderSurface());
431 ASSERT_FALSE(parent->renderSurface());
432 ASSERT_FALSE(child->renderSurface());
433 ASSERT_FALSE(grandChild->renderSurface());
434 }
435 {
436 scoped_refptr<Layer> root = Layer::create();
437 scoped_refptr<Layer> parent = Layer::create();
438 scoped_refptr<Layer> child = Layer::create();
439 scoped_refptr<Layer> grandChild = make_scoped_refptr(new LayerWithForcedDr awsContent());
440 root->addChild(parent);
441 parent->addChild(child);
442 child->addChild(grandChild);
443 parent->setMasksToBounds(true);
444 child->setMasksToBounds(true);
445
446 gfx::Transform identityMatrix;
447 gfx::Transform parentLayerTransform;
448 gfx::Transform parentSublayerMatrix;
shawnsingh 2012/12/18 19:11:00 This is unmodified; how about we just use identity
449 gfx::Transform childLayerMatrix;
450
451 // No render surface should exist yet.
452 ASSERT_FALSE(root->renderSurface());
453 ASSERT_FALSE(parent->renderSurface());
454 ASSERT_FALSE(child->renderSurface());
455 ASSERT_FALSE(grandChild->renderSurface());
456
457 // One-time setup of root layer
458 parentLayerTransform.Scale3d(1, 0.9, 1);
459 childLayerMatrix.Scale3d(0.9, 1, 3.3);
460 childLayerMatrix.Rotate(20);
461
462 setLayerPropertiesForTesting(root .get(), identityMatrix , ident ityMatrix , gfx::PointF( 0, 0), gfx::PointF(0, 0), gfx::Size( 1, 2) , false);
463 setLayerPropertiesForTesting(parent .get(), parentLayerTransform, paren tSublayerMatrix, gfx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(100, 120) , false);
464 setLayerPropertiesForTesting(child .get(), childLayerMatrix , ident ityMatrix , gfx::PointF( 0, 0), gfx::PointF(0, 0), gfx::Size( 16, 18) , false);
465 setLayerPropertiesForTesting(grandChild.get(), identityMatrix , ident ityMatrix , gfx::PointF( 0, 0), gfx::PointF(0, 0), gfx::Size( 8, 10) , false);
466
467 executeCalculateDrawProperties(root.get());
468
469 // Render surface should have been created now.
shawnsingh 2012/12/18 19:11:00 We probably want to update this comment, something
470 ASSERT_TRUE(root->renderSurface());
471 ASSERT_FALSE(parent->renderSurface());
472 ASSERT_TRUE(child->renderSurface());
473 ASSERT_FALSE(grandChild->renderSurface());
474 }
475 }
476
372 TEST(LayerTreeHostCommonTest, verifyTransformsForReplica) 477 TEST(LayerTreeHostCommonTest, verifyTransformsForReplica)
373 { 478 {
374 scoped_refptr<Layer> root = Layer::create(); 479 scoped_refptr<Layer> root = Layer::create();
375 scoped_refptr<Layer> parent = Layer::create(); 480 scoped_refptr<Layer> parent = Layer::create();
376 scoped_refptr<Layer> child = Layer::create(); 481 scoped_refptr<Layer> child = Layer::create();
377 scoped_refptr<Layer> childReplica = Layer::create(); 482 scoped_refptr<Layer> childReplica = Layer::create();
378 scoped_refptr<LayerWithForcedDrawsContent> grandChild = make_scoped_refptr(n ew LayerWithForcedDrawsContent()); 483 scoped_refptr<LayerWithForcedDrawsContent> grandChild = make_scoped_refptr(n ew LayerWithForcedDrawsContent());
379 root->addChild(parent); 484 root->addChild(parent);
380 parent->addChild(child); 485 parent->addChild(child);
381 child->addChild(grandChild); 486 child->addChild(grandChild);
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 FakeLayerTreeHostImpl hostImpl(&proxy); 970 FakeLayerTreeHostImpl hostImpl(&proxy);
866 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(&hostImpl); 971 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(&hostImpl);
867 LayerImpl* child = root->children()[0]; 972 LayerImpl* child = root->children()[0];
868 LayerImpl* grandChild = child->children()[0]; 973 LayerImpl* grandChild = child->children()[0];
869 LayerImpl* greatGrandChild = grandChild->children()[0]; 974 LayerImpl* greatGrandChild = grandChild->children()[0];
870 975
871 child->setIsContainerForFixedPositionLayers(true); 976 child->setIsContainerForFixedPositionLayers(true);
872 grandChild->setPosition(gfx::PointF(8, 6)); 977 grandChild->setPosition(gfx::PointF(8, 6));
873 greatGrandChild->setFixedToContainerLayer(true); 978 greatGrandChild->setFixedToContainerLayer(true);
874 979
980
shawnsingh 2012/12/18 19:11:00 another empty line
875 // Case 1: scrollDelta of 0, 0 981 // Case 1: scrollDelta of 0, 0
876 child->setScrollDelta(gfx::Vector2d(0, 0)); 982 child->setScrollDelta(gfx::Vector2d(0, 0));
877 executeCalculateDrawProperties(root.get()); 983 executeCalculateDrawProperties(root.get());
878 984
879 gfx::Transform expectedChildTransform; 985 gfx::Transform expectedChildTransform;
880 gfx::Transform expectedGrandChildTransform; 986 gfx::Transform expectedGrandChildTransform;
881 expectedGrandChildTransform.Translate(8, 6); 987 expectedGrandChildTransform.Translate(8, 6);
882 988
883 gfx::Transform expectedGreatGrandChildTransform = expectedGrandChildTransfor m; 989 gfx::Transform expectedGreatGrandChildTransform = expectedGrandChildTransfor m;
884 990
(...skipping 3927 matching lines...) Expand 10 before | Expand all | Expand 10 after
4812 EXPECT_EQ(m_canUseLCDText, m_grandChild->canUseLCDText()); 4918 EXPECT_EQ(m_canUseLCDText, m_grandChild->canUseLCDText());
4813 } 4919 }
4814 4920
4815 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, 4921 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest,
4816 LCDTextTest, 4922 LCDTextTest,
4817 testing::Combine(testing::Bool(), 4923 testing::Combine(testing::Bool(),
4818 testing::Bool())); 4924 testing::Bool()));
4819 4925
4820 } // namespace 4926 } // namespace
4821 } // namespace cc 4927 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698