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 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 gfx::Transform parentLayerTransform; | 330 gfx::Transform parentLayerTransform; |
331 parentLayerTransform.Scale3d(1, 0.9, 1); | 331 parentLayerTransform.Scale3d(1, 0.9, 1); |
332 gfx::Transform parentTranslationToAnchor; | 332 gfx::Transform parentTranslationToAnchor; |
333 parentTranslationToAnchor.Translate(25, 30); | 333 parentTranslationToAnchor.Translate(25, 30); |
334 gfx::Transform parentSublayerMatrix; | 334 gfx::Transform parentSublayerMatrix; |
335 parentSublayerMatrix.Scale3d(0.9, 1, 3.3); | 335 parentSublayerMatrix.Scale3d(0.9, 1, 3.3); |
336 gfx::Transform parentTranslationToCenter; | 336 gfx::Transform parentTranslationToCenter; |
337 parentTranslationToCenter.Translate(50, 60); | 337 parentTranslationToCenter.Translate(50, 60); |
338 gfx::Transform parentCompositeTransform = parentTranslationToAnchor * parent
LayerTransform * MathUtil::inverse(parentTranslationToAnchor) | 338 gfx::Transform parentCompositeTransform = parentTranslationToAnchor * parent
LayerTransform * MathUtil::inverse(parentTranslationToAnchor) |
339 * parentTranslationToCenter * parentSublayerMatrix * MathUtil::inver
se(parentTranslationToCenter); | 339 * parentTranslationToCenter * parentSublayerMatrix * MathUtil::inver
se(parentTranslationToCenter); |
340 gfx::Vector2dF parentCompositeScale = MathUtil::computeTransform2dScaleCompo
nents(parentCompositeTransform); | 340 gfx::Vector2dF parentCompositeScale = MathUtil::computeTransform2dScaleCompo
nents(parentCompositeTransform, 1.f); |
341 gfx::Transform surfaceSublayerTransform; | 341 gfx::Transform surfaceSublayerTransform; |
342 surfaceSublayerTransform.Scale(parentCompositeScale.x(), parentCompositeScal
e.y()); | 342 surfaceSublayerTransform.Scale(parentCompositeScale.x(), parentCompositeScal
e.y()); |
343 gfx::Transform surfaceSublayerCompositeTransform = parentCompositeTransform
* MathUtil::inverse(surfaceSublayerTransform); | 343 gfx::Transform surfaceSublayerCompositeTransform = parentCompositeTransform
* MathUtil::inverse(surfaceSublayerTransform); |
344 | 344 |
345 // Child's render surface should not exist yet. | 345 // Child's render surface should not exist yet. |
346 ASSERT_FALSE(child->renderSurface()); | 346 ASSERT_FALSE(child->renderSurface()); |
347 | 347 |
348 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla
yerMatrix, gfx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(100, 120), fals
e); | 348 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); | 349 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); | 350 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri
x, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(8, 10), false); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 gfx::Transform parentSublayerMatrix; | 393 gfx::Transform parentSublayerMatrix; |
394 parentSublayerMatrix.Scale3d(10, 10, 3.3); | 394 parentSublayerMatrix.Scale3d(10, 10, 3.3); |
395 gfx::Transform parentTranslationToCenter; | 395 gfx::Transform parentTranslationToCenter; |
396 parentTranslationToCenter.Translate(5, 6); | 396 parentTranslationToCenter.Translate(5, 6); |
397 gfx::Transform parentCompositeTransform = parentTranslationToAnchor * parent
LayerTransform * MathUtil::inverse(parentTranslationToAnchor) | 397 gfx::Transform parentCompositeTransform = parentTranslationToAnchor * parent
LayerTransform * MathUtil::inverse(parentTranslationToAnchor) |
398 * parentTranslationToCenter * parentSublayerMatrix * MathUtil::inver
se(parentTranslationToCenter); | 398 * parentTranslationToCenter * parentSublayerMatrix * MathUtil::inver
se(parentTranslationToCenter); |
399 gfx::Transform childTranslationToCenter; | 399 gfx::Transform childTranslationToCenter; |
400 childTranslationToCenter.Translate(8, 9); | 400 childTranslationToCenter.Translate(8, 9); |
401 gfx::Transform replicaLayerTransform; | 401 gfx::Transform replicaLayerTransform; |
402 replicaLayerTransform.Scale3d(3, 3, 1); | 402 replicaLayerTransform.Scale3d(3, 3, 1); |
403 gfx::Vector2dF parentCompositeScale = MathUtil::computeTransform2dScaleCompo
nents(parentCompositeTransform); | 403 gfx::Vector2dF parentCompositeScale = MathUtil::computeTransform2dScaleCompo
nents(parentCompositeTransform, 1.f); |
404 gfx::Transform surfaceSublayerTransform; | 404 gfx::Transform surfaceSublayerTransform; |
405 surfaceSublayerTransform.Scale(parentCompositeScale.x(), parentCompositeScal
e.y()); | 405 surfaceSublayerTransform.Scale(parentCompositeScale.x(), parentCompositeScal
e.y()); |
406 gfx::Transform replicaCompositeTransform = parentCompositeTransform * replic
aLayerTransform * MathUtil::inverse(surfaceSublayerTransform); | 406 gfx::Transform replicaCompositeTransform = parentCompositeTransform * replic
aLayerTransform * MathUtil::inverse(surfaceSublayerTransform); |
407 | 407 |
408 // Child's render surface should not exist yet. | 408 // Child's render surface should not exist yet. |
409 ASSERT_FALSE(child->renderSurface()); | 409 ASSERT_FALSE(child->renderSurface()); |
410 | 410 |
411 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla
yerMatrix, gfx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(10, 12), false)
; | 411 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla
yerMatrix, gfx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(10, 12), false)
; |
412 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf
x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(16, 18), false); | 412 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf
x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(16, 18), false); |
413 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri
x, gfx::PointF(0, 0), gfx::PointF(-0.5, -0.5), gfx::Size(1, 1), false); | 413 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri
x, gfx::PointF(0, 0), gfx::PointF(-0.5, -0.5), gfx::Size(1, 1), false); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 layerTransform.Translate(1, 1); | 478 layerTransform.Translate(1, 1); |
479 gfx::Transform sublayerTransform; | 479 gfx::Transform sublayerTransform; |
480 sublayerTransform.Scale3d(10, 1, 1); | 480 sublayerTransform.Scale3d(10, 1, 1); |
481 gfx::Transform replicaLayerTransform; | 481 gfx::Transform replicaLayerTransform; |
482 replicaLayerTransform.Scale3d(-2, 5, 1); | 482 replicaLayerTransform.Scale3d(-2, 5, 1); |
483 | 483 |
484 gfx::Transform A = translationToAnchor * layerTransform * MathUtil::inverse(
translationToAnchor); | 484 gfx::Transform A = translationToAnchor * layerTransform * MathUtil::inverse(
translationToAnchor); |
485 gfx::Transform B = translationToCenter * sublayerTransform * MathUtil::inver
se(translationToCenter); | 485 gfx::Transform B = translationToCenter * sublayerTransform * MathUtil::inver
se(translationToCenter); |
486 gfx::Transform R = A * translationToAnchor * replicaLayerTransform * MathUti
l::inverse(translationToAnchor); | 486 gfx::Transform R = A * translationToAnchor * replicaLayerTransform * MathUti
l::inverse(translationToAnchor); |
487 | 487 |
488 gfx::Vector2dF surface1ParentTransformScale = MathUtil::computeTransform2dSc
aleComponents(A * B); | 488 gfx::Vector2dF surface1ParentTransformScale = MathUtil::computeTransform2dSc
aleComponents(A * B, 1.f); |
489 gfx::Transform surface1SublayerTransform; | 489 gfx::Transform surface1SublayerTransform; |
490 surface1SublayerTransform.Scale(surface1ParentTransformScale.x(), surface1Pa
rentTransformScale.y()); | 490 surface1SublayerTransform.Scale(surface1ParentTransformScale.x(), surface1Pa
rentTransformScale.y()); |
491 | 491 |
492 // SS1 = transform given to the subtree of renderSurface1 | 492 // SS1 = transform given to the subtree of renderSurface1 |
493 gfx::Transform SS1 = surface1SublayerTransform; | 493 gfx::Transform SS1 = surface1SublayerTransform; |
494 // S1 = transform to move from renderSurface1 pixels to the layer space of t
he owning layer | 494 // S1 = transform to move from renderSurface1 pixels to the layer space of t
he owning layer |
495 gfx::Transform S1 = MathUtil::inverse(surface1SublayerTransform); | 495 gfx::Transform S1 = MathUtil::inverse(surface1SublayerTransform); |
496 | 496 |
497 gfx::Vector2dF surface2ParentTransformScale = MathUtil::computeTransform2dSc
aleComponents(SS1 * A * B); | 497 gfx::Vector2dF surface2ParentTransformScale = MathUtil::computeTransform2dSc
aleComponents(SS1 * A * B, 1.f); |
498 gfx::Transform surface2SublayerTransform; | 498 gfx::Transform surface2SublayerTransform; |
499 surface2SublayerTransform.Scale(surface2ParentTransformScale.x(), surface2Pa
rentTransformScale.y()); | 499 surface2SublayerTransform.Scale(surface2ParentTransformScale.x(), surface2Pa
rentTransformScale.y()); |
500 | 500 |
501 // SS2 = transform given to the subtree of renderSurface2 | 501 // SS2 = transform given to the subtree of renderSurface2 |
502 gfx::Transform SS2 = surface2SublayerTransform; | 502 gfx::Transform SS2 = surface2SublayerTransform; |
503 // S2 = transform to move from renderSurface2 pixels to the layer space of t
he owning layer | 503 // S2 = transform to move from renderSurface2 pixels to the layer space of t
he owning layer |
504 gfx::Transform S2 = MathUtil::inverse(surface2SublayerTransform); | 504 gfx::Transform S2 = MathUtil::inverse(surface2SublayerTransform); |
505 | 505 |
506 setLayerPropertiesForTesting(parent.get(), layerTransform, sublayerTransform
, gfx::PointF(0.25, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false); | 506 setLayerPropertiesForTesting(parent.get(), layerTransform, sublayerTransform
, gfx::PointF(0.25, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false); |
507 setLayerPropertiesForTesting(renderSurface1.get(), layerTransform, sublayerT
ransform, gfx::PointF(0.25, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false); | 507 setLayerPropertiesForTesting(renderSurface1.get(), layerTransform, sublayerT
ransform, gfx::PointF(0.25, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false); |
(...skipping 3566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4074 | 4074 |
4075 // Verify childNoScale transforms | 4075 // Verify childNoScale transforms |
4076 gfx::Transform expectedChildNoScaleTransform = child->drawTransform(); | 4076 gfx::Transform expectedChildNoScaleTransform = child->drawTransform(); |
4077 // All transforms operate on content rects. The child's content rect | 4077 // All transforms operate on content rects. The child's content rect |
4078 // incorporates device scale, but the childNoScale does not; add it here. | 4078 // incorporates device scale, but the childNoScale does not; add it here. |
4079 expectedChildNoScaleTransform.Scale(deviceScaleFactor, deviceScaleFactor); | 4079 expectedChildNoScaleTransform.Scale(deviceScaleFactor, deviceScaleFactor); |
4080 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildNoScaleTransform, childNoScale-
>drawTransform()); | 4080 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildNoScaleTransform, childNoScale-
>drawTransform()); |
4081 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildNoScaleTransform, childNoScale-
>screenSpaceTransform()); | 4081 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildNoScaleTransform, childNoScale-
>screenSpaceTransform()); |
4082 } | 4082 } |
4083 | 4083 |
| 4084 TEST(LayerTreeHostCommonTest, verifySurfaceLayerTransformsInHighDPI) |
| 4085 { |
| 4086 // Verify draw and screen space transforms of layers in a surface. |
| 4087 MockContentLayerClient delegate; |
| 4088 gfx::Transform identityMatrix; |
| 4089 |
| 4090 gfx::Transform perspectiveMatrix; |
| 4091 perspectiveMatrix.ApplyPerspectiveDepth(2); |
| 4092 |
| 4093 gfx::Transform scaleSmallMatrix; |
| 4094 scaleSmallMatrix.Scale(1.0 / 10.0, 1.0 / 12.0); |
| 4095 |
| 4096 scoped_refptr<ContentLayer> parent = createDrawableContentLayer(&delegate); |
| 4097 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g
fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), true); |
| 4098 |
| 4099 scoped_refptr<ContentLayer> perspectiveSurface = createDrawableContentLayer(
&delegate); |
| 4100 setLayerPropertiesForTesting(perspectiveSurface.get(), perspectiveMatrix * s
caleSmallMatrix, identityMatrix, gfx::PointF(0, 0), gfx::PointF(2, 2), gfx::Size
(10, 10), true); |
| 4101 |
| 4102 scoped_refptr<ContentLayer> scaleSurface = createDrawableContentLayer(&deleg
ate); |
| 4103 setLayerPropertiesForTesting(scaleSurface.get(), scaleSmallMatrix, identityM
atrix, gfx::PointF(0, 0), gfx::PointF(2, 2), gfx::Size(10, 10), true); |
| 4104 |
| 4105 perspectiveSurface->setForceRenderSurface(true); |
| 4106 scaleSurface->setForceRenderSurface(true); |
| 4107 |
| 4108 parent->addChild(perspectiveSurface); |
| 4109 parent->addChild(scaleSurface); |
| 4110 |
| 4111 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; |
| 4112 int dummyMaxTextureSize = 512; |
| 4113 |
| 4114 const double deviceScaleFactor = 2.5; |
| 4115 const double pageScaleFactor = 3; |
| 4116 |
| 4117 gfx::Transform pageScaleTransform; |
| 4118 pageScaleTransform.Scale(pageScaleFactor, pageScaleFactor); |
| 4119 parent->setImplTransform(pageScaleTransform); |
| 4120 |
| 4121 LayerTreeHostCommon::calculateDrawProperties(parent.get(), parent->bounds(),
deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, false, renderSurfaceLa
yerList); |
| 4122 |
| 4123 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor, parent); |
| 4124 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor, perspectiveSur
face); |
| 4125 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor, scaleSurface); |
| 4126 |
| 4127 EXPECT_EQ(3u, renderSurfaceLayerList.size()); |
| 4128 |
| 4129 gfx::Transform expectedParentDrawTransform; |
| 4130 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedParentDrawTransform, parent->drawTra
nsform()); |
| 4131 |
| 4132 // The scaled surface is rendered at its appropriate scale, and drawn 1:1 |
| 4133 // into its target. |
| 4134 gfx::Transform expectedScaleSurfaceDrawTransform; |
| 4135 expectedScaleSurfaceDrawTransform.Translate( |
| 4136 deviceScaleFactor * pageScaleFactor * scaleSurface->position().x(), |
| 4137 deviceScaleFactor * pageScaleFactor * scaleSurface->position().y()); |
| 4138 gfx::Transform expectedScaleSurfaceLayerDrawTransform; |
| 4139 expectedScaleSurfaceLayerDrawTransform.PreconcatTransform(scaleSmallMatrix); |
| 4140 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedScaleSurfaceDrawTransform, scaleSurf
ace->renderSurface()->drawTransform()); |
| 4141 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedScaleSurfaceLayerDrawTransform, scal
eSurface->drawTransform()); |
| 4142 |
| 4143 // The scale for the perspective surface is not known, so it is rendered 1:1 |
| 4144 // with the screen, and then scaled during drawing. |
| 4145 gfx::Transform expectedPerspectiveSurfaceDrawTransform; |
| 4146 expectedPerspectiveSurfaceDrawTransform.Translate( |
| 4147 deviceScaleFactor * pageScaleFactor * perspectiveSurface->position().x()
, |
| 4148 deviceScaleFactor * pageScaleFactor * perspectiveSurface->position().y()
); |
| 4149 expectedPerspectiveSurfaceDrawTransform.PreconcatTransform(perspectiveMatrix
); |
| 4150 expectedPerspectiveSurfaceDrawTransform.PreconcatTransform(scaleSmallMatrix)
; |
| 4151 gfx::Transform expectedPerspectiveSurfaceLayerDrawTransform; |
| 4152 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedPerspectiveSurfaceDrawTransform, per
spectiveSurface->renderSurface()->drawTransform()); |
| 4153 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedPerspectiveSurfaceLayerDrawTransform
, perspectiveSurface->drawTransform()); |
| 4154 } |
| 4155 |
4084 TEST(LayerTreeHostCommonTest, verifyLayerTransformsInHighDPIAccurateScaleZeroChi
ldPosition) | 4156 TEST(LayerTreeHostCommonTest, verifyLayerTransformsInHighDPIAccurateScaleZeroChi
ldPosition) |
4085 { | 4157 { |
4086 // Verify draw and screen space transforms of layers not in a surface. | 4158 // Verify draw and screen space transforms of layers not in a surface. |
4087 MockContentLayerClient delegate; | 4159 MockContentLayerClient delegate; |
4088 gfx::Transform identityMatrix; | 4160 gfx::Transform identityMatrix; |
4089 | 4161 |
4090 scoped_refptr<ContentLayer> parent = createDrawableContentLayer(&delegate); | 4162 scoped_refptr<ContentLayer> parent = createDrawableContentLayer(&delegate); |
4091 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g
fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(133, 133), true); | 4163 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g
fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(133, 133), true); |
4092 | 4164 |
4093 scoped_refptr<ContentLayer> child = createDrawableContentLayer(&delegate); | 4165 scoped_refptr<ContentLayer> child = createDrawableContentLayer(&delegate); |
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4803 EXPECT_EQ(m_canUseLCDText, m_grandChild->canUseLCDText()); | 4875 EXPECT_EQ(m_canUseLCDText, m_grandChild->canUseLCDText()); |
4804 } | 4876 } |
4805 | 4877 |
4806 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, | 4878 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, |
4807 LCDTextTest, | 4879 LCDTextTest, |
4808 testing::Combine(testing::Bool(), | 4880 testing::Combine(testing::Bool(), |
4809 testing::Bool())); | 4881 testing::Bool())); |
4810 | 4882 |
4811 } // namespace | 4883 } // namespace |
4812 } // namespace cc | 4884 } // namespace cc |
OLD | NEW |