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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 return root.Pass(); | 96 return root.Pass(); |
97 } | 97 } |
98 | 98 |
99 class LayerWithForcedDrawsContent : public Layer { | 99 class LayerWithForcedDrawsContent : public Layer { |
100 public: | 100 public: |
101 LayerWithForcedDrawsContent() | 101 LayerWithForcedDrawsContent() |
102 : Layer() | 102 : Layer() |
103 { | 103 { |
104 } | 104 } |
105 | 105 |
106 virtual bool drawsContent() const OVERRIDE { return true; } | 106 virtual bool drawsContent() const OVERRIDE; |
107 | 107 |
108 private: | 108 private: |
109 virtual ~LayerWithForcedDrawsContent() | 109 virtual ~LayerWithForcedDrawsContent() |
110 { | 110 { |
111 } | 111 } |
112 }; | 112 }; |
113 | 113 |
| 114 class LayerCanClipSelf : public Layer { |
| 115 public: |
| 116 LayerCanClipSelf() |
| 117 : Layer() |
| 118 { |
| 119 } |
| 120 |
| 121 virtual bool drawsContent() const OVERRIDE; |
| 122 virtual bool canClipSelf() const OVERRIDE; |
| 123 |
| 124 private: |
| 125 virtual ~LayerCanClipSelf() |
| 126 { |
| 127 } |
| 128 }; |
| 129 |
| 130 bool LayerWithForcedDrawsContent::drawsContent() const |
| 131 { |
| 132 return true; |
| 133 } |
| 134 |
| 135 bool LayerCanClipSelf::drawsContent() const |
| 136 { |
| 137 return true; |
| 138 } |
| 139 |
| 140 bool LayerCanClipSelf::canClipSelf() const |
| 141 { |
| 142 return true; |
| 143 } |
| 144 |
114 class MockContentLayerClient : public ContentLayerClient { | 145 class MockContentLayerClient : public ContentLayerClient { |
115 public: | 146 public: |
116 MockContentLayerClient() { } | 147 MockContentLayerClient() { } |
117 virtual ~MockContentLayerClient() { } | 148 virtual ~MockContentLayerClient() { } |
118 virtual void paintContents(SkCanvas*, const gfx::Rect& clip, gfx::RectF& opa
que) OVERRIDE { } | 149 virtual void paintContents(SkCanvas*, const gfx::Rect& clip, gfx::RectF& opa
que) OVERRIDE { } |
119 }; | 150 }; |
120 | 151 |
121 scoped_refptr<ContentLayer> createDrawableContentLayer(ContentLayerClient* deleg
ate) | 152 scoped_refptr<ContentLayer> createDrawableContentLayer(ContentLayerClient* deleg
ate) |
122 { | 153 { |
123 scoped_refptr<ContentLayer> toReturn = ContentLayer::create(delegate); | 154 scoped_refptr<ContentLayer> toReturn = ContentLayer::create(delegate); |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 // Child is set up so that a new render surface should be created. | 357 // Child is set up so that a new render surface should be created. |
327 child->setOpacity(0.5); | 358 child->setOpacity(0.5); |
328 child->setForceRenderSurface(true); | 359 child->setForceRenderSurface(true); |
329 | 360 |
330 gfx::Transform parentLayerTransform; | 361 gfx::Transform parentLayerTransform; |
331 parentLayerTransform.Scale3d(1, 0.9, 1); | 362 parentLayerTransform.Scale3d(1, 0.9, 1); |
332 gfx::Transform parentTranslationToAnchor; | 363 gfx::Transform parentTranslationToAnchor; |
333 parentTranslationToAnchor.Translate(25, 30); | 364 parentTranslationToAnchor.Translate(25, 30); |
334 gfx::Transform parentSublayerMatrix; | 365 gfx::Transform parentSublayerMatrix; |
335 parentSublayerMatrix.Scale3d(0.9, 1, 3.3); | 366 parentSublayerMatrix.Scale3d(0.9, 1, 3.3); |
| 367 |
336 gfx::Transform parentTranslationToCenter; | 368 gfx::Transform parentTranslationToCenter; |
337 parentTranslationToCenter.Translate(50, 60); | 369 parentTranslationToCenter.Translate(50, 60); |
338 gfx::Transform parentCompositeTransform = parentTranslationToAnchor * parent
LayerTransform * inverse(parentTranslationToAnchor) | 370 gfx::Transform parentCompositeTransform = parentTranslationToAnchor * parent
LayerTransform * inverse(parentTranslationToAnchor) |
339 * parentTranslationToCenter * parentSublayerMatrix * inverse(parentT
ranslationToCenter); | 371 * parentTranslationToCenter * parentSublayerMatrix * inverse(parentT
ranslationToCenter); |
340 gfx::Vector2dF parentCompositeScale = MathUtil::computeTransform2dScaleCompo
nents(parentCompositeTransform, 1.f); | 372 gfx::Vector2dF parentCompositeScale = MathUtil::computeTransform2dScaleCompo
nents(parentCompositeTransform, 1.0f); |
341 gfx::Transform surfaceSublayerTransform; | 373 gfx::Transform surfaceSublayerTransform; |
342 surfaceSublayerTransform.Scale(parentCompositeScale.x(), parentCompositeScal
e.y()); | 374 surfaceSublayerTransform.Scale(parentCompositeScale.x(), parentCompositeScal
e.y()); |
343 gfx::Transform surfaceSublayerCompositeTransform = parentCompositeTransform
* inverse(surfaceSublayerTransform); | 375 gfx::Transform surfaceSublayerCompositeTransform = parentCompositeTransform
* inverse(surfaceSublayerTransform); |
344 | 376 |
345 // Child's render surface should not exist yet. | 377 // Child's render surface should not exist yet. |
346 ASSERT_FALSE(child->renderSurface()); | 378 ASSERT_FALSE(child->renderSurface()); |
347 | 379 |
348 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla
yerMatrix, gfx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(100, 120), fals
e); | 380 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla
yerMatrix, gfx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(100, 120), fals
e); |
349 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf
x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(16, 18), false); | 381 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf
x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(16, 18), false); |
350 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri
x, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(8, 10), false); | 382 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri
x, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(8, 10), false); |
351 executeCalculateDrawProperties(root.get()); | 383 executeCalculateDrawProperties(root.get()); |
352 | 384 |
353 // Render surface should have been created now. | 385 // Render surface should have been created now. |
354 ASSERT_TRUE(child->renderSurface()); | 386 ASSERT_TRUE(child->renderSurface()); |
355 ASSERT_EQ(child, child->renderTarget()); | 387 ASSERT_EQ(child, child->renderTarget()); |
356 | 388 |
357 // The child layer's draw transform should refer to its new render surface. | 389 // The child layer's draw transform should refer to its new render surface. |
358 // The screen-space transform, however, should still refer to the root. | 390 // The screen-space transform, however, should still refer to the root. |
359 EXPECT_TRANSFORMATION_MATRIX_EQ(surfaceSublayerTransform, child->drawTransfo
rm()); | 391 EXPECT_TRANSFORMATION_MATRIX_EQ(surfaceSublayerTransform, child->drawTransfo
rm()); |
360 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpace
Transform()); | 392 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpace
Transform()); |
361 | 393 |
362 // Because the grandChild is the only drawable content, the child's renderSu
rface will tighten its bounds to the grandChild. | 394 // Because the grandChild is the only drawable content, the child's renderSu
rface will tighten its bounds to the grandChild. |
363 // The scale at which the surface's subtree is drawn must be removed from th
e composite transform. | 395 // The scale at which the surface's subtree is drawn must be removed from th
e composite transform. |
364 EXPECT_TRANSFORMATION_MATRIX_EQ(surfaceSublayerCompositeTransform, child->re
nderTarget()->renderSurface()->drawTransform()); | 396 EXPECT_TRANSFORMATION_MATRIX_EQ(surfaceSublayerCompositeTransform, child->re
nderTarget()->renderSurface()->drawTransform()); |
365 | 397 |
366 // The screen space is the same as the target since the child surface draws
into the root. | 398 // The screen space is the same as the target since the child surface draws
into the root. |
367 EXPECT_TRANSFORMATION_MATRIX_EQ(surfaceSublayerCompositeTransform, child->re
nderTarget()->renderSurface()->screenSpaceTransform()); | 399 EXPECT_TRANSFORMATION_MATRIX_EQ(surfaceSublayerCompositeTransform, child->re
nderTarget()->renderSurface()->screenSpaceTransform()); |
368 } | 400 } |
369 | 401 |
| 402 TEST(LayerTreeHostCommonTest, verifySeparateRenderTargetRequirementWithClipping) |
| 403 { |
| 404 scoped_refptr<Layer> root = Layer::create(); |
| 405 scoped_refptr<Layer> parent = Layer::create(); |
| 406 scoped_refptr<Layer> child = Layer::create(); |
| 407 scoped_refptr<Layer> grandChild = make_scoped_refptr(new LayerCanClipSelf())
; |
| 408 root->addChild(parent); |
| 409 parent->addChild(child); |
| 410 child->addChild(grandChild); |
| 411 parent->setMasksToBounds(true); |
| 412 child->setMasksToBounds(true); |
| 413 |
| 414 gfx::Transform identityMatrix; |
| 415 gfx::Transform parentLayerTransform; |
| 416 gfx::Transform parentSublayerMatrix; |
| 417 gfx::Transform childLayerMatrix; |
| 418 |
| 419 // No render surface should exist yet. |
| 420 EXPECT_FALSE(root->renderSurface()); |
| 421 EXPECT_FALSE(parent->renderSurface()); |
| 422 EXPECT_FALSE(child->renderSurface()); |
| 423 EXPECT_FALSE(grandChild->renderSurface()); |
| 424 |
| 425 // One-time setup of root layer |
| 426 parentLayerTransform.Scale3d(1, 0.9, 1); |
| 427 parentSublayerMatrix.Scale3d(0.9, 1, 3.3); |
| 428 childLayerMatrix.Rotate(20); |
| 429 |
| 430 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx
::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(1, 2), false); |
| 431 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla
yerMatrix, gfx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(100, 120), fals
e); |
| 432 setLayerPropertiesForTesting(child.get(), childLayerMatrix, identityMatrix,
gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(16, 18), false); |
| 433 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri
x, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(8, 10), false); |
| 434 |
| 435 executeCalculateDrawProperties(root.get()); |
| 436 |
| 437 // Render surfaces should have been created according to clipping rules now
(grandchild can clip self). |
| 438 EXPECT_TRUE(root->renderSurface()); |
| 439 EXPECT_FALSE(parent->renderSurface()); |
| 440 EXPECT_FALSE(child->renderSurface()); |
| 441 EXPECT_FALSE(grandChild->renderSurface()); |
| 442 } |
| 443 |
| 444 TEST(LayerTreeHostCommonTest, verifySeparateRenderTargetRequirementWithoutClippi
ng) |
| 445 { |
| 446 scoped_refptr<Layer> root = Layer::create(); |
| 447 scoped_refptr<Layer> parent = Layer::create(); |
| 448 scoped_refptr<Layer> child = Layer::create(); |
| 449 // This layer cannot clip itself, a feature we are testing here. |
| 450 scoped_refptr<Layer> grandChild = make_scoped_refptr(new LayerWithForcedDraw
sContent()); |
| 451 root->addChild(parent); |
| 452 parent->addChild(child); |
| 453 child->addChild(grandChild); |
| 454 parent->setMasksToBounds(true); |
| 455 child->setMasksToBounds(true); |
| 456 |
| 457 gfx::Transform identityMatrix; |
| 458 gfx::Transform parentLayerTransform; |
| 459 gfx::Transform parentSublayerMatrix; |
| 460 gfx::Transform childLayerMatrix; |
| 461 |
| 462 // No render surface should exist yet. |
| 463 EXPECT_FALSE(root->renderSurface()); |
| 464 EXPECT_FALSE(parent->renderSurface()); |
| 465 EXPECT_FALSE(child->renderSurface()); |
| 466 EXPECT_FALSE(grandChild->renderSurface()); |
| 467 |
| 468 // One-time setup of root layer |
| 469 parentLayerTransform.Scale3d(1, 0.9, 1); |
| 470 parentSublayerMatrix.Scale3d(0.9, 1, 3.3); |
| 471 childLayerMatrix.Rotate(20); |
| 472 |
| 473 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx
::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(1, 2), false); |
| 474 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla
yerMatrix, gfx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(100, 120), fals
e); |
| 475 setLayerPropertiesForTesting(child.get(), childLayerMatrix, identityMatrix,
gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(16, 18), false); |
| 476 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri
x, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(8, 10), false); |
| 477 |
| 478 executeCalculateDrawProperties(root.get()); |
| 479 |
| 480 // Render surfaces should have been created according to clipping rules now
(grandchild can't clip self). |
| 481 EXPECT_TRUE(root->renderSurface()); |
| 482 EXPECT_FALSE(parent->renderSurface()); |
| 483 EXPECT_TRUE(child->renderSurface()); |
| 484 EXPECT_FALSE(grandChild->renderSurface()); |
| 485 } |
| 486 |
370 TEST(LayerTreeHostCommonTest, verifyTransformsForReplica) | 487 TEST(LayerTreeHostCommonTest, verifyTransformsForReplica) |
371 { | 488 { |
372 scoped_refptr<Layer> root = Layer::create(); | 489 scoped_refptr<Layer> root = Layer::create(); |
373 scoped_refptr<Layer> parent = Layer::create(); | 490 scoped_refptr<Layer> parent = Layer::create(); |
374 scoped_refptr<Layer> child = Layer::create(); | 491 scoped_refptr<Layer> child = Layer::create(); |
375 scoped_refptr<Layer> childReplica = Layer::create(); | 492 scoped_refptr<Layer> childReplica = Layer::create(); |
376 scoped_refptr<LayerWithForcedDrawsContent> grandChild = make_scoped_refptr(n
ew LayerWithForcedDrawsContent()); | 493 scoped_refptr<LayerWithForcedDrawsContent> grandChild = make_scoped_refptr(n
ew LayerWithForcedDrawsContent()); |
377 root->addChild(parent); | 494 root->addChild(parent); |
378 parent->addChild(child); | 495 parent->addChild(child); |
379 child->addChild(grandChild); | 496 child->addChild(grandChild); |
(...skipping 4495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4875 EXPECT_EQ(m_canUseLCDText, m_grandChild->canUseLCDText()); | 4992 EXPECT_EQ(m_canUseLCDText, m_grandChild->canUseLCDText()); |
4876 } | 4993 } |
4877 | 4994 |
4878 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, | 4995 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, |
4879 LCDTextTest, | 4996 LCDTextTest, |
4880 testing::Combine(testing::Bool(), | 4997 testing::Combine(testing::Bool(), |
4881 testing::Bool())); | 4998 testing::Bool())); |
4882 | 4999 |
4883 } // namespace | 5000 } // namespace |
4884 } // namespace cc | 5001 } // namespace cc |
OLD | NEW |