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 "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 Loading... |
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 Loading... |
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 Loading... |
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, verifySeparateRenderTargetRequirementWithClipping) |
| 390 { |
| 391 scoped_refptr<Layer> root = Layer::create(); |
| 392 scoped_refptr<Layer> parent = Layer::create(); |
| 393 scoped_refptr<Layer> child = Layer::create(); |
| 394 scoped_refptr<Layer> grandChild = make_scoped_refptr(new LayerCanClipSelf())
; |
| 395 root->addChild(parent); |
| 396 parent->addChild(child); |
| 397 child->addChild(grandChild); |
| 398 parent->setMasksToBounds(true); |
| 399 child->setMasksToBounds(true); |
| 400 |
| 401 gfx::Transform identityMatrix; |
| 402 gfx::Transform parentLayerTransform; |
| 403 gfx::Transform parentSublayerMatrix; |
| 404 gfx::Transform childLayerMatrix; |
| 405 |
| 406 // No render surface should exist yet. |
| 407 EXPECT_FALSE(root->renderSurface()); |
| 408 EXPECT_FALSE(parent->renderSurface()); |
| 409 EXPECT_FALSE(child->renderSurface()); |
| 410 EXPECT_FALSE(grandChild->renderSurface()); |
| 411 |
| 412 // One-time setup of root layer |
| 413 parentLayerTransform.Scale3d(1, 0.9, 1); |
| 414 parentSublayerMatrix.Scale3d(0.9, 1, 3.3); |
| 415 childLayerMatrix.Rotate(20); |
| 416 |
| 417 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx
::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(1, 2), false); |
| 418 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla
yerMatrix, gfx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(100, 120), fals
e); |
| 419 setLayerPropertiesForTesting(child.get(), childLayerMatrix, identityMatrix,
gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(16, 18), false); |
| 420 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri
x, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(8, 10), false); |
| 421 |
| 422 executeCalculateDrawProperties(root.get()); |
| 423 |
| 424 // Render surfaces should have been created according to clipping rules now
(grandchild can clip self). |
| 425 EXPECT_TRUE(root->renderSurface()); |
| 426 EXPECT_FALSE(parent->renderSurface()); |
| 427 EXPECT_FALSE(child->renderSurface()); |
| 428 EXPECT_FALSE(grandChild->renderSurface()); |
| 429 } |
| 430 |
| 431 TEST(LayerTreeHostCommonTest, verifySeparateRenderTargetRequirementWithoutClippi
ng) |
| 432 { |
| 433 scoped_refptr<Layer> root = Layer::create(); |
| 434 scoped_refptr<Layer> parent = Layer::create(); |
| 435 scoped_refptr<Layer> child = Layer::create(); |
| 436 // This layer cannot clip itself, a feature we are testing here. |
| 437 scoped_refptr<Layer> grandChild = make_scoped_refptr(new LayerWithForcedDraw
sContent()); |
| 438 root->addChild(parent); |
| 439 parent->addChild(child); |
| 440 child->addChild(grandChild); |
| 441 parent->setMasksToBounds(true); |
| 442 child->setMasksToBounds(true); |
| 443 |
| 444 gfx::Transform identityMatrix; |
| 445 gfx::Transform parentLayerTransform; |
| 446 gfx::Transform parentSublayerMatrix; |
| 447 gfx::Transform childLayerMatrix; |
| 448 |
| 449 // No render surface should exist yet. |
| 450 EXPECT_FALSE(root->renderSurface()); |
| 451 EXPECT_FALSE(parent->renderSurface()); |
| 452 EXPECT_FALSE(child->renderSurface()); |
| 453 EXPECT_FALSE(grandChild->renderSurface()); |
| 454 |
| 455 // One-time setup of root layer |
| 456 parentLayerTransform.Scale3d(1, 0.9, 1); |
| 457 parentSublayerMatrix.Scale3d(0.9, 1, 3.3); |
| 458 childLayerMatrix.Rotate(20); |
| 459 |
| 460 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx
::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(1, 2), false); |
| 461 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla
yerMatrix, gfx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(100, 120), fals
e); |
| 462 setLayerPropertiesForTesting(child.get(), childLayerMatrix, identityMatrix,
gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(16, 18), false); |
| 463 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri
x, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(8, 10), false); |
| 464 |
| 465 executeCalculateDrawProperties(root.get()); |
| 466 |
| 467 // Render surfaces should have been created according to clipping rules now
(grandchild can't clip self). |
| 468 EXPECT_TRUE(root->renderSurface()); |
| 469 EXPECT_FALSE(parent->renderSurface()); |
| 470 EXPECT_TRUE(child->renderSurface()); |
| 471 EXPECT_FALSE(grandChild->renderSurface()); |
| 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 Loading... |
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 |
OLD | NEW |