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 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpace
Transform()); | 306 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpace
Transform()); |
307 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, grandChild->drawTr
ansform()); | 307 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, grandChild->drawTr
ansform()); |
308 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, grandChild->screen
SpaceTransform()); | 308 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, grandChild->screen
SpaceTransform()); |
309 | 309 |
310 // Case 4: parent's sublayerMatrix affects child and grandchild | 310 // Case 4: parent's sublayerMatrix affects child and grandchild |
311 // scaling is used here again so that the correct sequence of transf
orms is properly tested. | 311 // scaling is used here again so that the correct sequence of transf
orms is properly tested. |
312 // Note that preserves3D is false, but the sublayer matrix should re
tain its 3D properties when given to child. | 312 // Note that preserves3D is false, but the sublayer matrix should re
tain its 3D properties when given to child. |
313 // But then, the child also does not preserve3D. When it gives its h
ierarchy to the grandChild, it should be flattened to 2D. | 313 // But then, the child also does not preserve3D. When it gives its h
ierarchy to the grandChild, it should be flattened to 2D. |
314 gfx::Transform parentSublayerMatrix; | 314 gfx::Transform parentSublayerMatrix; |
315 parentSublayerMatrix.Scale3d(10, 10, 3.3); | 315 parentSublayerMatrix.Scale3d(10, 10, 3.3); |
316 gfx::Transform parentTranslationToCenter; | 316 // Sublayer matrix is applied to the anchor point of the parent layer. |
317 parentTranslationToCenter.Translate(5, 6); | |
318 // Sublayer matrix is applied to the center of the parent layer. | |
319 parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform
* inverse(parentTranslationToAnchor) | 317 parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform
* inverse(parentTranslationToAnchor) |
320 * parentTranslationToCenter * parentSublayerMatrix * inverse(parentT
ranslationToCenter); | 318 * parentTranslationToAnchor * parentSublayerMatrix * inverse(parentT
ranslationToAnchor); |
321 gfx::Transform flattenedCompositeTransform = parentCompositeTransform; | 319 gfx::Transform flattenedCompositeTransform = parentCompositeTransform; |
322 flattenedCompositeTransform.FlattenTo2d(); | 320 flattenedCompositeTransform.FlattenTo2d(); |
323 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla
yerMatrix, gfx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(10, 12), false)
; | 321 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla
yerMatrix, gfx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(10, 12), false)
; |
324 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf
x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(16, 18), false); | 322 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf
x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(16, 18), false); |
325 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri
x, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(76, 78), false); | 323 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri
x, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(76, 78), false); |
326 executeCalculateDrawProperties(root.get()); | 324 executeCalculateDrawProperties(root.get()); |
327 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->drawTransfo
rm()); | 325 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->drawTransfo
rm()); |
328 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpace
Transform()); | 326 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpace
Transform()); |
329 EXPECT_TRANSFORMATION_MATRIX_EQ(flattenedCompositeTransform, grandChild->dra
wTransform()); | 327 EXPECT_TRANSFORMATION_MATRIX_EQ(flattenedCompositeTransform, grandChild->dra
wTransform()); |
330 EXPECT_TRANSFORMATION_MATRIX_EQ(flattenedCompositeTransform, grandChild->scr
eenSpaceTransform()); | 328 EXPECT_TRANSFORMATION_MATRIX_EQ(flattenedCompositeTransform, grandChild->scr
eenSpaceTransform()); |
(...skipping 28 matching lines...) Expand all Loading... |
359 child->setOpacity(0.5); | 357 child->setOpacity(0.5); |
360 child->setForceRenderSurface(true); | 358 child->setForceRenderSurface(true); |
361 | 359 |
362 gfx::Transform parentLayerTransform; | 360 gfx::Transform parentLayerTransform; |
363 parentLayerTransform.Scale3d(1, 0.9, 1); | 361 parentLayerTransform.Scale3d(1, 0.9, 1); |
364 gfx::Transform parentTranslationToAnchor; | 362 gfx::Transform parentTranslationToAnchor; |
365 parentTranslationToAnchor.Translate(25, 30); | 363 parentTranslationToAnchor.Translate(25, 30); |
366 gfx::Transform parentSublayerMatrix; | 364 gfx::Transform parentSublayerMatrix; |
367 parentSublayerMatrix.Scale3d(0.9, 1, 3.3); | 365 parentSublayerMatrix.Scale3d(0.9, 1, 3.3); |
368 | 366 |
369 gfx::Transform parentTranslationToCenter; | |
370 parentTranslationToCenter.Translate(50, 60); | |
371 gfx::Transform parentCompositeTransform = parentTranslationToAnchor * parent
LayerTransform * inverse(parentTranslationToAnchor) | 367 gfx::Transform parentCompositeTransform = parentTranslationToAnchor * parent
LayerTransform * inverse(parentTranslationToAnchor) |
372 * parentTranslationToCenter * parentSublayerMatrix * inverse(parentT
ranslationToCenter); | 368 * parentTranslationToAnchor * parentSublayerMatrix * inverse(parentT
ranslationToAnchor); |
373 gfx::Vector2dF parentCompositeScale = MathUtil::computeTransform2dScaleCompo
nents(parentCompositeTransform, 1.0f); | 369 gfx::Vector2dF parentCompositeScale = MathUtil::computeTransform2dScaleCompo
nents(parentCompositeTransform, 1.0f); |
374 gfx::Transform surfaceSublayerTransform; | 370 gfx::Transform surfaceSublayerTransform; |
375 surfaceSublayerTransform.Scale(parentCompositeScale.x(), parentCompositeScal
e.y()); | 371 surfaceSublayerTransform.Scale(parentCompositeScale.x(), parentCompositeScal
e.y()); |
376 gfx::Transform surfaceSublayerCompositeTransform = parentCompositeTransform
* inverse(surfaceSublayerTransform); | 372 gfx::Transform surfaceSublayerCompositeTransform = parentCompositeTransform
* inverse(surfaceSublayerTransform); |
377 | 373 |
378 // Child's render surface should not exist yet. | 374 // Child's render surface should not exist yet. |
379 ASSERT_FALSE(child->renderSurface()); | 375 ASSERT_FALSE(child->renderSurface()); |
380 | 376 |
381 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla
yerMatrix, gfx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(100, 120), fals
e); | 377 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla
yerMatrix, gfx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(100, 120), fals
e); |
382 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf
x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(16, 18), false); | 378 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf
x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(16, 18), false); |
(...skipping 10 matching lines...) Expand all Loading... |
393 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpace
Transform()); | 389 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpace
Transform()); |
394 | 390 |
395 // Because the grandChild is the only drawable content, the child's renderSu
rface will tighten its bounds to the grandChild. | 391 // Because the grandChild is the only drawable content, the child's renderSu
rface will tighten its bounds to the grandChild. |
396 // The scale at which the surface's subtree is drawn must be removed from th
e composite transform. | 392 // The scale at which the surface's subtree is drawn must be removed from th
e composite transform. |
397 EXPECT_TRANSFORMATION_MATRIX_EQ(surfaceSublayerCompositeTransform, child->re
nderTarget()->renderSurface()->drawTransform()); | 393 EXPECT_TRANSFORMATION_MATRIX_EQ(surfaceSublayerCompositeTransform, child->re
nderTarget()->renderSurface()->drawTransform()); |
398 | 394 |
399 // The screen space is the same as the target since the child surface draws
into the root. | 395 // The screen space is the same as the target since the child surface draws
into the root. |
400 EXPECT_TRANSFORMATION_MATRIX_EQ(surfaceSublayerCompositeTransform, child->re
nderTarget()->renderSurface()->screenSpaceTransform()); | 396 EXPECT_TRANSFORMATION_MATRIX_EQ(surfaceSublayerCompositeTransform, child->re
nderTarget()->renderSurface()->screenSpaceTransform()); |
401 } | 397 } |
402 | 398 |
| 399 TEST(LayerTreeHostCommonTest, verifySublayerTransformWithAnchorPoint) |
| 400 { |
| 401 // crbug.com/157961 - we were always applying the sublayer transform about |
| 402 // the center of the layer, rather than the anchor point. |
| 403 |
| 404 scoped_refptr<Layer> root = Layer::create(); |
| 405 scoped_refptr<Layer> parent = Layer::create(); |
| 406 scoped_refptr<LayerWithForcedDrawsContent> child = make_scoped_refptr(new La
yerWithForcedDrawsContent()); |
| 407 root->addChild(parent); |
| 408 parent->addChild(child); |
| 409 |
| 410 gfx::Transform identityMatrix; |
| 411 gfx::Transform parentSublayerMatrix; |
| 412 parentSublayerMatrix.ApplyPerspectiveDepth(2.0); |
| 413 gfx::PointF parentAnchorPoint(0.2f, 0.8f); |
| 414 |
| 415 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx
::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(1, 2), false); |
| 416 setLayerPropertiesForTesting(parent.get(), identityMatrix, parentSublayerMat
rix, parentAnchorPoint, gfx::PointF(0, 0), gfx::Size(100, 100), false); |
| 417 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf
x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false); |
| 418 executeCalculateDrawProperties(root.get()); |
| 419 |
| 420 gfx::Transform expectedChildDrawTransform; |
| 421 expectedChildDrawTransform.Translate(20, 80); |
| 422 expectedChildDrawTransform.ApplyPerspectiveDepth(2.0); |
| 423 expectedChildDrawTransform.Translate(-20, -80); |
| 424 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildDrawTransform, child->drawTrans
form()); |
| 425 } |
| 426 |
| 427 |
403 TEST(LayerTreeHostCommonTest, verifySeparateRenderTargetRequirementWithClipping) | 428 TEST(LayerTreeHostCommonTest, verifySeparateRenderTargetRequirementWithClipping) |
404 { | 429 { |
405 scoped_refptr<Layer> root = Layer::create(); | 430 scoped_refptr<Layer> root = Layer::create(); |
406 scoped_refptr<Layer> parent = Layer::create(); | 431 scoped_refptr<Layer> parent = Layer::create(); |
407 scoped_refptr<Layer> child = Layer::create(); | 432 scoped_refptr<Layer> child = Layer::create(); |
408 scoped_refptr<Layer> grandChild = make_scoped_refptr(new LayerCanClipSelf())
; | 433 scoped_refptr<Layer> grandChild = make_scoped_refptr(new LayerCanClipSelf())
; |
409 root->addChild(parent); | 434 root->addChild(parent); |
410 parent->addChild(child); | 435 parent->addChild(child); |
411 child->addChild(grandChild); | 436 child->addChild(grandChild); |
412 parent->setMasksToBounds(true); | 437 parent->setMasksToBounds(true); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 | 528 |
504 // Child is set up so that a new render surface should be created. | 529 // Child is set up so that a new render surface should be created. |
505 child->setOpacity(0.5); | 530 child->setOpacity(0.5); |
506 | 531 |
507 gfx::Transform parentLayerTransform; | 532 gfx::Transform parentLayerTransform; |
508 parentLayerTransform.Scale3d(2, 2, 1); | 533 parentLayerTransform.Scale3d(2, 2, 1); |
509 gfx::Transform parentTranslationToAnchor; | 534 gfx::Transform parentTranslationToAnchor; |
510 parentTranslationToAnchor.Translate(2.5, 3); | 535 parentTranslationToAnchor.Translate(2.5, 3); |
511 gfx::Transform parentSublayerMatrix; | 536 gfx::Transform parentSublayerMatrix; |
512 parentSublayerMatrix.Scale3d(10, 10, 3.3); | 537 parentSublayerMatrix.Scale3d(10, 10, 3.3); |
513 gfx::Transform parentTranslationToCenter; | |
514 parentTranslationToCenter.Translate(5, 6); | |
515 gfx::Transform parentCompositeTransform = parentTranslationToAnchor * parent
LayerTransform * inverse(parentTranslationToAnchor) | 538 gfx::Transform parentCompositeTransform = parentTranslationToAnchor * parent
LayerTransform * inverse(parentTranslationToAnchor) |
516 * parentTranslationToCenter * parentSublayerMatrix * inverse(parentT
ranslationToCenter); | 539 * parentTranslationToAnchor * parentSublayerMatrix * inverse(parentT
ranslationToAnchor); |
517 gfx::Transform childTranslationToCenter; | |
518 childTranslationToCenter.Translate(8, 9); | |
519 gfx::Transform replicaLayerTransform; | 540 gfx::Transform replicaLayerTransform; |
520 replicaLayerTransform.Scale3d(3, 3, 1); | 541 replicaLayerTransform.Scale3d(3, 3, 1); |
521 gfx::Vector2dF parentCompositeScale = MathUtil::computeTransform2dScaleCompo
nents(parentCompositeTransform, 1.f); | 542 gfx::Vector2dF parentCompositeScale = MathUtil::computeTransform2dScaleCompo
nents(parentCompositeTransform, 1.f); |
522 gfx::Transform surfaceSublayerTransform; | 543 gfx::Transform surfaceSublayerTransform; |
523 surfaceSublayerTransform.Scale(parentCompositeScale.x(), parentCompositeScal
e.y()); | 544 surfaceSublayerTransform.Scale(parentCompositeScale.x(), parentCompositeScal
e.y()); |
524 gfx::Transform replicaCompositeTransform = parentCompositeTransform * replic
aLayerTransform * inverse(surfaceSublayerTransform); | 545 gfx::Transform replicaCompositeTransform = parentCompositeTransform * replic
aLayerTransform * inverse(surfaceSublayerTransform); |
525 | 546 |
526 // Child's render surface should not exist yet. | 547 // Child's render surface should not exist yet. |
527 ASSERT_FALSE(child->renderSurface()); | 548 ASSERT_FALSE(child->renderSurface()); |
528 | 549 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 | 604 |
584 // All layers in the tree are initialized with an anchor at .25 and a size o
f (10,10). | 605 // All layers in the tree are initialized with an anchor at .25 and a size o
f (10,10). |
585 // matrix "A" is the composite layer transform used in all layers, centered
about the anchor point | 606 // matrix "A" is the composite layer transform used in all layers, centered
about the anchor point |
586 // matrix "B" is the sublayer transform used in all layers, centered about t
he center position of the layer. | 607 // matrix "B" is the sublayer transform used in all layers, centered about t
he center position of the layer. |
587 // matrix "R" is the composite replica transform used in all replica layers. | 608 // matrix "R" is the composite replica transform used in all replica layers. |
588 // | 609 // |
589 // x component tests that layerTransform and sublayerTransform are done in t
he right order (translation and scale are noncommutative). | 610 // x component tests that layerTransform and sublayerTransform are done in t
he right order (translation and scale are noncommutative). |
590 // y component has a translation by 1 for every ancestor, which indicates th
e "depth" of the layer in the hierarchy. | 611 // y component has a translation by 1 for every ancestor, which indicates th
e "depth" of the layer in the hierarchy. |
591 gfx::Transform translationToAnchor; | 612 gfx::Transform translationToAnchor; |
592 translationToAnchor.Translate(2.5, 0); | 613 translationToAnchor.Translate(2.5, 0); |
593 gfx::Transform translationToCenter; | |
594 translationToCenter.Translate(5, 5); | |
595 gfx::Transform layerTransform; | 614 gfx::Transform layerTransform; |
596 layerTransform.Translate(1, 1); | 615 layerTransform.Translate(1, 1); |
597 gfx::Transform sublayerTransform; | 616 gfx::Transform sublayerTransform; |
598 sublayerTransform.Scale3d(10, 1, 1); | 617 sublayerTransform.Scale3d(10, 1, 1); |
599 gfx::Transform replicaLayerTransform; | 618 gfx::Transform replicaLayerTransform; |
600 replicaLayerTransform.Scale3d(-2, 5, 1); | 619 replicaLayerTransform.Scale3d(-2, 5, 1); |
601 | 620 |
602 gfx::Transform A = translationToAnchor * layerTransform * inverse(translatio
nToAnchor); | 621 gfx::Transform A = translationToAnchor * layerTransform * inverse(translatio
nToAnchor); |
603 gfx::Transform B = translationToCenter * sublayerTransform * inverse(transla
tionToCenter); | 622 gfx::Transform B = translationToAnchor * sublayerTransform * inverse(transla
tionToAnchor); |
604 gfx::Transform R = A * translationToAnchor * replicaLayerTransform * inverse
(translationToAnchor); | 623 gfx::Transform R = A * translationToAnchor * replicaLayerTransform * inverse
(translationToAnchor); |
605 | 624 |
606 gfx::Vector2dF surface1ParentTransformScale = MathUtil::computeTransform2dSc
aleComponents(A * B, 1.f); | 625 gfx::Vector2dF surface1ParentTransformScale = MathUtil::computeTransform2dSc
aleComponents(A * B, 1.f); |
607 gfx::Transform surface1SublayerTransform; | 626 gfx::Transform surface1SublayerTransform; |
608 surface1SublayerTransform.Scale(surface1ParentTransformScale.x(), surface1Pa
rentTransformScale.y()); | 627 surface1SublayerTransform.Scale(surface1ParentTransformScale.x(), surface1Pa
rentTransformScale.y()); |
609 | 628 |
610 // SS1 = transform given to the subtree of renderSurface1 | 629 // SS1 = transform given to the subtree of renderSurface1 |
611 gfx::Transform SS1 = surface1SublayerTransform; | 630 gfx::Transform SS1 = surface1SublayerTransform; |
612 // S1 = transform to move from renderSurface1 pixels to the layer space of t
he owning layer | 631 // S1 = transform to move from renderSurface1 pixels to the layer space of t
he owning layer |
613 gfx::Transform S1 = inverse(surface1SublayerTransform); | 632 gfx::Transform S1 = inverse(surface1SublayerTransform); |
(...skipping 4404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5018 EXPECT_EQ(m_canUseLCDText, m_grandChild->canUseLCDText()); | 5037 EXPECT_EQ(m_canUseLCDText, m_grandChild->canUseLCDText()); |
5019 } | 5038 } |
5020 | 5039 |
5021 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, | 5040 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, |
5022 LCDTextTest, | 5041 LCDTextTest, |
5023 testing::Combine(testing::Bool(), | 5042 testing::Combine(testing::Bool(), |
5024 testing::Bool())); | 5043 testing::Bool())); |
5025 | 5044 |
5026 } // namespace | 5045 } // namespace |
5027 } // namespace cc | 5046 } // namespace cc |
OLD | NEW |