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

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: Addressing Shawn's feedback. 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
338 gfx::Transform parentTranslationToCenter; 355 gfx::Transform parentTranslationToCenter;
339 parentTranslationToCenter.Translate(50, 60); 356 parentTranslationToCenter.Translate(50, 60);
340 gfx::Transform parentCompositeTransform = parentTranslationToAnchor * parent LayerTransform * MathUtil::inverse(parentTranslationToAnchor) 357 gfx::Transform parentCompositeTransform = parentTranslationToAnchor * parent LayerTransform * MathUtil::inverse(parentTranslationToAnchor)
341 * parentTranslationToCenter * parentSublayerMatrix * MathUtil::inver se(parentTranslationToCenter); 358 * parentTranslationToCenter * parentSublayerMatrix * MathUtil::inver se(parentTranslationToCenter);
342 gfx::Vector2dF parentCompositeScale = MathUtil::computeTransform2dScaleCompo nents(parentCompositeTransform); 359 gfx::Vector2dF parentCompositeScale = MathUtil::computeTransform2dScaleCompo nents(parentCompositeTransform);
343 gfx::Transform surfaceSublayerTransform; 360 gfx::Transform surfaceSublayerTransform;
344 surfaceSublayerTransform.Scale(parentCompositeScale.x(), parentCompositeScal e.y()); 361 surfaceSublayerTransform.Scale(parentCompositeScale.x(), parentCompositeScal e.y());
345 gfx::Transform surfaceSublayerCompositeTransform = parentCompositeTransform * MathUtil::inverse(surfaceSublayerTransform); 362 gfx::Transform surfaceSublayerCompositeTransform = parentCompositeTransform * MathUtil::inverse(surfaceSublayerTransform);
346 363
347 // Child's render surface should not exist yet. 364 // Child's render surface should not exist yet.
(...skipping 14 matching lines...) Expand all
362 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpace Transform()); 379 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpace Transform());
363 380
364 // Because the grandChild is the only drawable content, the child's renderSu rface will tighten its bounds to the grandChild. 381 // 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. 382 // 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()); 383 EXPECT_TRANSFORMATION_MATRIX_EQ(surfaceSublayerCompositeTransform, child->re nderTarget()->renderSurface()->drawTransform());
367 384
368 // The screen space is the same as the target since the child surface draws into the root. 385 // 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()); 386 EXPECT_TRANSFORMATION_MATRIX_EQ(surfaceSublayerCompositeTransform, child->re nderTarget()->renderSurface()->screenSpaceTransform());
370 } 387 }
371 388
389 TEST(LayerTreeHostCommonTest, verifySeparateRenderTargetRequirement)
390 {
391 {
392 scoped_refptr<Layer> root = Layer::create();
393 scoped_refptr<Layer> parent = Layer::create();
394 scoped_refptr<Layer> child = Layer::create();
395 scoped_refptr<Layer> grandChild = make_scoped_refptr(new LayerCanClipSelf( ));
396 root->addChild(parent);
397 parent->addChild(child);
398 child->addChild(grandChild);
399 parent->setMasksToBounds(true);
400 child->setMasksToBounds(true);
401
402 gfx::Transform identityMatrix;
403 gfx::Transform parentLayerTransform;
404 gfx::Transform parentSublayerMatrix;
405 gfx::Transform childLayerMatrix;
406
407 // No render surface should exist yet.
408 ASSERT_FALSE(root->renderSurface());
danakj 2012/12/19 22:46:56 nit: you can use EXPECT_ for these tests. generall
409 ASSERT_FALSE(parent->renderSurface());
410 ASSERT_FALSE(child->renderSurface());
411 ASSERT_FALSE(grandChild->renderSurface());
412
413 // One-time setup of root layer
414 parentLayerTransform.Scale3d(1, 0.9, 1);
415 parentSublayerMatrix.Scale3d(0.9, 1, 3.3);
416 childLayerMatrix.Rotate(20);
417
418 setLayerPropertiesForTesting(root .get(), identityMatrix , ident ityMatrix , gfx::PointF( 0, 0), gfx::PointF(0, 0), gfx::Size( 1, 2) , false);
danakj 2012/12/19 22:46:56 these extra spaces are funny, i'd remove them. lin
whunt 2013/01/04 19:12:27 I'm actually surprised about the push-back I get f
419 setLayerPropertiesForTesting(parent .get(), parentLayerTransform, paren tSublayerMatrix, gfx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(100, 120) , false);
420 setLayerPropertiesForTesting(child .get(), childLayerMatrix , ident ityMatrix , gfx::PointF( 0, 0), gfx::PointF(0, 0), gfx::Size( 16, 18) , false);
421 setLayerPropertiesForTesting(grandChild.get(), identityMatrix , ident ityMatrix , gfx::PointF( 0, 0), gfx::PointF(0, 0), gfx::Size( 8, 10) , false);
422
423 executeCalculateDrawProperties(root.get());
424
425 // Render surfaces should have been created according to clipping rules no w (grandchild can clip self).
426 ASSERT_TRUE(root->renderSurface());
427 ASSERT_FALSE(parent->renderSurface());
428 ASSERT_FALSE(child->renderSurface());
429 ASSERT_FALSE(grandChild->renderSurface());
430 }
431 {
danakj 2012/12/19 22:46:56 if you made LayerCanClipSelf let you change the ca
432 scoped_refptr<Layer> root = Layer::create();
433 scoped_refptr<Layer> parent = Layer::create();
434 scoped_refptr<Layer> child = Layer::create();
435 // This layer cannot clip itself, a feature we are testing here.
436 scoped_refptr<Layer> grandChild = make_scoped_refptr(new LayerWithForcedDr awsContent());
437 root->addChild(parent);
438 parent->addChild(child);
439 child->addChild(grandChild);
440 parent->setMasksToBounds(true);
441 child->setMasksToBounds(true);
442
443 gfx::Transform identityMatrix;
444 gfx::Transform parentLayerTransform;
445 gfx::Transform parentSublayerMatrix;
446 gfx::Transform childLayerMatrix;
447
448 // No render surface should exist yet.
449 ASSERT_FALSE(root->renderSurface());
450 ASSERT_FALSE(parent->renderSurface());
451 ASSERT_FALSE(child->renderSurface());
452 ASSERT_FALSE(grandChild->renderSurface());
453
454 // One-time setup of root layer
455 parentLayerTransform.Scale3d(1, 0.9, 1);
456 parentSublayerMatrix.Scale3d(0.9, 1, 3.3);
457 childLayerMatrix.Rotate(20);
458
459 setLayerPropertiesForTesting(root .get(), identityMatrix , ident ityMatrix , gfx::PointF( 0, 0), gfx::PointF(0, 0), gfx::Size( 1, 2) , false);
danakj 2012/12/19 22:46:56 same here
460 setLayerPropertiesForTesting(parent .get(), parentLayerTransform, paren tSublayerMatrix, gfx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(100, 120) , false);
461 setLayerPropertiesForTesting(child .get(), childLayerMatrix , ident ityMatrix , gfx::PointF( 0, 0), gfx::PointF(0, 0), gfx::Size( 16, 18) , false);
462 setLayerPropertiesForTesting(grandChild.get(), identityMatrix , ident ityMatrix , gfx::PointF( 0, 0), gfx::PointF(0, 0), gfx::Size( 8, 10) , false);
463
464 executeCalculateDrawProperties(root.get());
465
466 // Render surfaces should have been created according to clipping rules no w (grandchild can't clip self).
467 ASSERT_TRUE(root->renderSurface());
468 ASSERT_FALSE(parent->renderSurface());
469 ASSERT_TRUE(child->renderSurface());
470 ASSERT_FALSE(grandChild->renderSurface());
471 }
472 }
473
372 TEST(LayerTreeHostCommonTest, verifyTransformsForReplica) 474 TEST(LayerTreeHostCommonTest, verifyTransformsForReplica)
373 { 475 {
374 scoped_refptr<Layer> root = Layer::create(); 476 scoped_refptr<Layer> root = Layer::create();
375 scoped_refptr<Layer> parent = Layer::create(); 477 scoped_refptr<Layer> parent = Layer::create();
376 scoped_refptr<Layer> child = Layer::create(); 478 scoped_refptr<Layer> child = Layer::create();
377 scoped_refptr<Layer> childReplica = Layer::create(); 479 scoped_refptr<Layer> childReplica = Layer::create();
378 scoped_refptr<LayerWithForcedDrawsContent> grandChild = make_scoped_refptr(n ew LayerWithForcedDrawsContent()); 480 scoped_refptr<LayerWithForcedDrawsContent> grandChild = make_scoped_refptr(n ew LayerWithForcedDrawsContent());
379 root->addChild(parent); 481 root->addChild(parent);
380 parent->addChild(child); 482 parent->addChild(child);
381 child->addChild(grandChild); 483 child->addChild(grandChild);
(...skipping 4430 matching lines...) Expand 10 before | Expand all | Expand 10 after
4812 EXPECT_EQ(m_canUseLCDText, m_grandChild->canUseLCDText()); 4914 EXPECT_EQ(m_canUseLCDText, m_grandChild->canUseLCDText());
4813 } 4915 }
4814 4916
4815 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, 4917 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest,
4816 LCDTextTest, 4918 LCDTextTest,
4817 testing::Combine(testing::Bool(), 4919 testing::Combine(testing::Bool(),
4818 testing::Bool())); 4920 testing::Bool()));
4819 4921
4820 } // namespace 4922 } // namespace
4821 } // namespace cc 4923 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698