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 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 // scaling is used here again so that the correct sequence of transf
orms is properly tested. | 280 // scaling is used here again so that the correct sequence of transf
orms is properly tested. |
281 // Note that preserves3D is false, but the sublayer matrix should re
tain its 3D properties when given to child. | 281 // Note that preserves3D is false, but the sublayer matrix should re
tain its 3D properties when given to child. |
282 // But then, the child also does not preserve3D. When it gives its h
ierarchy to the grandChild, it should be flattened to 2D. | 282 // But then, the child also does not preserve3D. When it gives its h
ierarchy to the grandChild, it should be flattened to 2D. |
283 gfx::Transform parentSublayerMatrix; | 283 gfx::Transform parentSublayerMatrix; |
284 parentSublayerMatrix.Scale3d(10, 10, 3.3); | 284 parentSublayerMatrix.Scale3d(10, 10, 3.3); |
285 gfx::Transform parentTranslationToCenter; | 285 gfx::Transform parentTranslationToCenter; |
286 parentTranslationToCenter.Translate(5, 6); | 286 parentTranslationToCenter.Translate(5, 6); |
287 // Sublayer matrix is applied to the center of the parent layer. | 287 // Sublayer matrix is applied to the center of the parent layer. |
288 parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform
* inverse(parentTranslationToAnchor) | 288 parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform
* inverse(parentTranslationToAnchor) |
289 * parentTranslationToCenter * parentSublayerMatrix * inverse(parentT
ranslationToCenter); | 289 * parentTranslationToCenter * parentSublayerMatrix * inverse(parentT
ranslationToCenter); |
290 gfx::Transform flattenedCompositeTransform = MathUtil::to2dTransform(parentC
ompositeTransform); | 290 gfx::Transform flattenedCompositeTransform = parentCompositeTransform; |
| 291 flattenedCompositeTransform.FlattenTo2d(); |
291 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla
yerMatrix, gfx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(10, 12), false)
; | 292 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla
yerMatrix, gfx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(10, 12), false)
; |
292 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf
x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(16, 18), false); | 293 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf
x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(16, 18), false); |
293 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri
x, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(76, 78), false); | 294 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri
x, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(76, 78), false); |
294 executeCalculateDrawProperties(root.get()); | 295 executeCalculateDrawProperties(root.get()); |
295 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->drawTransfo
rm()); | 296 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->drawTransfo
rm()); |
296 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpace
Transform()); | 297 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpace
Transform()); |
297 EXPECT_TRANSFORMATION_MATRIX_EQ(flattenedCompositeTransform, grandChild->dra
wTransform()); | 298 EXPECT_TRANSFORMATION_MATRIX_EQ(flattenedCompositeTransform, grandChild->dra
wTransform()); |
298 EXPECT_TRANSFORMATION_MATRIX_EQ(flattenedCompositeTransform, grandChild->scr
eenSpaceTransform()); | 299 EXPECT_TRANSFORMATION_MATRIX_EQ(flattenedCompositeTransform, grandChild->scr
eenSpaceTransform()); |
299 | 300 |
300 // Case 5: same as Case 4, except that child does preserve 3D, so the grandC
hild should receive the non-flattened composite transform. | 301 // Case 5: same as Case 4, except that child does preserve 3D, so the grandC
hild should receive the non-flattened composite transform. |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 // For layers that flatten their subtree, there should be an orthographic pr
ojection | 610 // For layers that flatten their subtree, there should be an orthographic pr
ojection |
610 // (for x and y values) in the middle of the transform sequence. Note that t
he way the | 611 // (for x and y values) in the middle of the transform sequence. Note that t
he way the |
611 // code is currently implemented, it is not expected to use a canonical orth
ographic | 612 // code is currently implemented, it is not expected to use a canonical orth
ographic |
612 // projection. | 613 // projection. |
613 | 614 |
614 scoped_refptr<Layer> root = Layer::create(); | 615 scoped_refptr<Layer> root = Layer::create(); |
615 scoped_refptr<Layer> child = Layer::create(); | 616 scoped_refptr<Layer> child = Layer::create(); |
616 scoped_refptr<LayerWithForcedDrawsContent> grandChild = make_scoped_refptr(n
ew LayerWithForcedDrawsContent()); | 617 scoped_refptr<LayerWithForcedDrawsContent> grandChild = make_scoped_refptr(n
ew LayerWithForcedDrawsContent()); |
617 | 618 |
618 gfx::Transform rotationAboutYAxis; | 619 gfx::Transform rotationAboutYAxis; |
619 MathUtil::rotateEulerAngles(&rotationAboutYAxis, 0, 30, 0); | 620 rotationAboutYAxis.RotateAboutYAxis(30); |
620 | 621 |
621 const gfx::Transform identityMatrix; | 622 const gfx::Transform identityMatrix; |
622 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx
::PointF(), gfx::PointF(), gfx::Size(100, 100), false); | 623 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx
::PointF(), gfx::PointF(), gfx::Size(100, 100), false); |
623 setLayerPropertiesForTesting(child.get(), rotationAboutYAxis, identityMatrix
, gfx::PointF(), gfx::PointF(), gfx::Size(10, 10), false); | 624 setLayerPropertiesForTesting(child.get(), rotationAboutYAxis, identityMatrix
, gfx::PointF(), gfx::PointF(), gfx::Size(10, 10), false); |
624 setLayerPropertiesForTesting(grandChild.get(), rotationAboutYAxis, identityM
atrix, gfx::PointF(), gfx::PointF(), gfx::Size(10, 10), false); | 625 setLayerPropertiesForTesting(grandChild.get(), rotationAboutYAxis, identityM
atrix, gfx::PointF(), gfx::PointF(), gfx::Size(10, 10), false); |
625 | 626 |
626 root->addChild(child); | 627 root->addChild(child); |
627 child->addChild(grandChild); | 628 child->addChild(grandChild); |
628 child->setForceRenderSurface(true); | 629 child->setForceRenderSurface(true); |
629 | 630 |
630 // No layers in this test should preserve 3d. | 631 // No layers in this test should preserve 3d. |
631 ASSERT_FALSE(root->preserves3D()); | 632 ASSERT_FALSE(root->preserves3D()); |
632 ASSERT_FALSE(child->preserves3D()); | 633 ASSERT_FALSE(child->preserves3D()); |
633 ASSERT_FALSE(grandChild->preserves3D()); | 634 ASSERT_FALSE(grandChild->preserves3D()); |
634 | 635 |
635 gfx::Transform expectedChildDrawTransform = rotationAboutYAxis; | 636 gfx::Transform expectedChildDrawTransform = rotationAboutYAxis; |
636 gfx::Transform expectedChildScreenSpaceTransform = rotationAboutYAxis; | 637 gfx::Transform expectedChildScreenSpaceTransform = rotationAboutYAxis; |
637 gfx::Transform expectedGrandChildDrawTransform = rotationAboutYAxis; // draw
s onto child's renderSurface | 638 gfx::Transform expectedGrandChildDrawTransform = rotationAboutYAxis; // draw
s onto child's renderSurface |
638 gfx::Transform expectedGrandChildScreenSpaceTransform = MathUtil::to2dTransf
orm(rotationAboutYAxis) * rotationAboutYAxis; | 639 gfx::Transform flattenedRotationAboutY = rotationAboutYAxis; |
| 640 flattenedRotationAboutY.FlattenTo2d(); |
| 641 gfx::Transform expectedGrandChildScreenSpaceTransform = flattenedRotationAbo
utY * rotationAboutYAxis; |
639 | 642 |
640 executeCalculateDrawProperties(root.get()); | 643 executeCalculateDrawProperties(root.get()); |
641 | 644 |
642 // The child's drawTransform should have been taken by its surface. | 645 // The child's drawTransform should have been taken by its surface. |
643 ASSERT_TRUE(child->renderSurface()); | 646 ASSERT_TRUE(child->renderSurface()); |
644 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildDrawTransform, child->renderSur
face()->drawTransform()); | 647 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildDrawTransform, child->renderSur
face()->drawTransform()); |
645 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildScreenSpaceTransform, child->re
nderSurface()->screenSpaceTransform()); | 648 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildScreenSpaceTransform, child->re
nderSurface()->screenSpaceTransform()); |
646 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform()); | 649 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform()); |
647 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildScreenSpaceTransform, child->sc
reenSpaceTransform()); | 650 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildScreenSpaceTransform, child->sc
reenSpaceTransform()); |
648 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildDrawTransform, grandChild-
>drawTransform()); | 651 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildDrawTransform, grandChild-
>drawTransform()); |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
904 // is NOT the direct parent of the fixed-position layer, and the hierarchy h
as various | 907 // is NOT the direct parent of the fixed-position layer, and the hierarchy h
as various |
905 // transforms that have to be processed in the correct order. | 908 // transforms that have to be processed in the correct order. |
906 FakeImplProxy proxy; | 909 FakeImplProxy proxy; |
907 FakeLayerTreeHostImpl hostImpl(&proxy); | 910 FakeLayerTreeHostImpl hostImpl(&proxy); |
908 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(&hostImpl); | 911 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(&hostImpl); |
909 LayerImpl* child = root->children()[0]; | 912 LayerImpl* child = root->children()[0]; |
910 LayerImpl* grandChild = child->children()[0]; | 913 LayerImpl* grandChild = child->children()[0]; |
911 LayerImpl* greatGrandChild = grandChild->children()[0]; | 914 LayerImpl* greatGrandChild = grandChild->children()[0]; |
912 | 915 |
913 gfx::Transform rotationAboutZ; | 916 gfx::Transform rotationAboutZ; |
914 MathUtil::rotateEulerAngles(&rotationAboutZ, 0, 0, 90); | 917 rotationAboutZ.RotateAboutZAxis(90); |
915 | 918 |
916 child->setIsContainerForFixedPositionLayers(true); | 919 child->setIsContainerForFixedPositionLayers(true); |
917 child->setTransform(rotationAboutZ); | 920 child->setTransform(rotationAboutZ); |
918 grandChild->setPosition(gfx::PointF(8, 6)); | 921 grandChild->setPosition(gfx::PointF(8, 6)); |
919 grandChild->setTransform(rotationAboutZ); | 922 grandChild->setTransform(rotationAboutZ); |
920 greatGrandChild->setFixedToContainerLayer(true); // greatGrandChild is posit
ioned upside-down with respect to the renderTarget. | 923 greatGrandChild->setFixedToContainerLayer(true); // greatGrandChild is posit
ioned upside-down with respect to the renderTarget. |
921 | 924 |
922 // Case 1: scrollDelta of 0, 0 | 925 // Case 1: scrollDelta of 0, 0 |
923 child->setScrollDelta(gfx::Vector2d(0, 0)); | 926 child->setScrollDelta(gfx::Vector2d(0, 0)); |
924 executeCalculateDrawProperties(root.get()); | 927 executeCalculateDrawProperties(root.get()); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
966 // is NOT the direct parent of the fixed-position layer, and the hierarchy h
as various | 969 // is NOT the direct parent of the fixed-position layer, and the hierarchy h
as various |
967 // transforms that have to be processed in the correct order. | 970 // transforms that have to be processed in the correct order. |
968 FakeImplProxy proxy; | 971 FakeImplProxy proxy; |
969 FakeLayerTreeHostImpl hostImpl(&proxy); | 972 FakeLayerTreeHostImpl hostImpl(&proxy); |
970 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(&hostImpl); | 973 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(&hostImpl); |
971 LayerImpl* child = root->children()[0]; | 974 LayerImpl* child = root->children()[0]; |
972 LayerImpl* grandChild = child->children()[0]; | 975 LayerImpl* grandChild = child->children()[0]; |
973 LayerImpl* greatGrandChild = grandChild->children()[0]; | 976 LayerImpl* greatGrandChild = grandChild->children()[0]; |
974 | 977 |
975 gfx::Transform rotationAboutZ; | 978 gfx::Transform rotationAboutZ; |
976 MathUtil::rotateEulerAngles(&rotationAboutZ, 0, 0, 90); | 979 rotationAboutZ.RotateAboutZAxis(90); |
977 | 980 |
978 child->setIsContainerForFixedPositionLayers(true); | 981 child->setIsContainerForFixedPositionLayers(true); |
979 child->setTransform(rotationAboutZ); | 982 child->setTransform(rotationAboutZ); |
980 grandChild->setPosition(gfx::PointF(8, 6)); | 983 grandChild->setPosition(gfx::PointF(8, 6)); |
981 grandChild->setTransform(rotationAboutZ); | 984 grandChild->setTransform(rotationAboutZ); |
982 greatGrandChild->setFixedToContainerLayer(true); // greatGrandChild is posit
ioned upside-down with respect to the renderTarget. | 985 greatGrandChild->setFixedToContainerLayer(true); // greatGrandChild is posit
ioned upside-down with respect to the renderTarget. |
983 | 986 |
984 // Case 1: scrollDelta of 0, 0 | 987 // Case 1: scrollDelta of 0, 0 |
985 child->setScrollDelta(gfx::Vector2d(0, 0)); | 988 child->setScrollDelta(gfx::Vector2d(0, 0)); |
986 executeCalculateDrawProperties(root.get()); | 989 executeCalculateDrawProperties(root.get()); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1034 LayerImpl* grandChild = child->children()[0]; | 1037 LayerImpl* grandChild = child->children()[0]; |
1035 LayerImpl* greatGrandChild = grandChild->children()[0]; | 1038 LayerImpl* greatGrandChild = grandChild->children()[0]; |
1036 | 1039 |
1037 child->setIsContainerForFixedPositionLayers(true); | 1040 child->setIsContainerForFixedPositionLayers(true); |
1038 grandChild->setPosition(gfx::PointF(8, 6)); | 1041 grandChild->setPosition(gfx::PointF(8, 6)); |
1039 grandChild->setForceRenderSurface(true); | 1042 grandChild->setForceRenderSurface(true); |
1040 greatGrandChild->setFixedToContainerLayer(true); | 1043 greatGrandChild->setFixedToContainerLayer(true); |
1041 greatGrandChild->setDrawsContent(true); | 1044 greatGrandChild->setDrawsContent(true); |
1042 | 1045 |
1043 gfx::Transform rotationAboutZ; | 1046 gfx::Transform rotationAboutZ; |
1044 MathUtil::rotateEulerAngles(&rotationAboutZ, 0, 0, 90); | 1047 rotationAboutZ.RotateAboutZAxis(90); |
1045 grandChild->setTransform(rotationAboutZ); | 1048 grandChild->setTransform(rotationAboutZ); |
1046 | 1049 |
1047 // Case 1: scrollDelta of 0, 0 | 1050 // Case 1: scrollDelta of 0, 0 |
1048 child->setScrollDelta(gfx::Vector2d(0, 0)); | 1051 child->setScrollDelta(gfx::Vector2d(0, 0)); |
1049 executeCalculateDrawProperties(root.get()); | 1052 executeCalculateDrawProperties(root.get()); |
1050 | 1053 |
1051 gfx::Transform expectedChildTransform; | 1054 gfx::Transform expectedChildTransform; |
1052 gfx::Transform expectedSurfaceDrawTransform; | 1055 gfx::Transform expectedSurfaceDrawTransform; |
1053 expectedSurfaceDrawTransform.Translate(8, 6); | 1056 expectedSurfaceDrawTransform.Translate(8, 6); |
1054 expectedSurfaceDrawTransform.PreconcatTransform(rotationAboutZ); | 1057 expectedSurfaceDrawTransform.PreconcatTransform(rotationAboutZ); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1124 greatGrandChild->setForceRenderSurface(true); | 1127 greatGrandChild->setForceRenderSurface(true); |
1125 fixedPositionChild->setFixedToContainerLayer(true); | 1128 fixedPositionChild->setFixedToContainerLayer(true); |
1126 fixedPositionChild->setDrawsContent(true); | 1129 fixedPositionChild->setDrawsContent(true); |
1127 | 1130 |
1128 // The additional rotations, which are non-commutative with translations, he
lp to | 1131 // The additional rotations, which are non-commutative with translations, he
lp to |
1129 // verify that we have correct order-of-operations in the final scroll compe
nsation. | 1132 // verify that we have correct order-of-operations in the final scroll compe
nsation. |
1130 // Note that rotating about the center of the layer ensures we do not accide
ntally | 1133 // Note that rotating about the center of the layer ensures we do not accide
ntally |
1131 // clip away layers that we want to test. | 1134 // clip away layers that we want to test. |
1132 gfx::Transform rotationAboutZ; | 1135 gfx::Transform rotationAboutZ; |
1133 rotationAboutZ.Translate(50, 50); | 1136 rotationAboutZ.Translate(50, 50); |
1134 MathUtil::rotateEulerAngles(&rotationAboutZ, 0, 0, 90); | 1137 rotationAboutZ.RotateAboutZAxis(90); |
1135 rotationAboutZ.Translate(-50, -50); | 1138 rotationAboutZ.Translate(-50, -50); |
1136 grandChild->setTransform(rotationAboutZ); | 1139 grandChild->setTransform(rotationAboutZ); |
1137 greatGrandChild->setTransform(rotationAboutZ); | 1140 greatGrandChild->setTransform(rotationAboutZ); |
1138 | 1141 |
1139 // Case 1: scrollDelta of 0, 0 | 1142 // Case 1: scrollDelta of 0, 0 |
1140 child->setScrollDelta(gfx::Vector2d(0, 0)); | 1143 child->setScrollDelta(gfx::Vector2d(0, 0)); |
1141 executeCalculateDrawProperties(root.get()); | 1144 executeCalculateDrawProperties(root.get()); |
1142 | 1145 |
1143 gfx::Transform expectedChildTransform; | 1146 gfx::Transform expectedChildTransform; |
1144 | 1147 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1295 // This test checks scroll compensation when a fixed-position layer does not
find any | 1298 // This test checks scroll compensation when a fixed-position layer does not
find any |
1296 // ancestor that is a "containerForFixedPositionLayers". In this situation,
the layer should | 1299 // ancestor that is a "containerForFixedPositionLayers". In this situation,
the layer should |
1297 // be fixed to the viewport -- not the rootLayer, which may have transforms
of its own. | 1300 // be fixed to the viewport -- not the rootLayer, which may have transforms
of its own. |
1298 FakeImplProxy proxy; | 1301 FakeImplProxy proxy; |
1299 FakeLayerTreeHostImpl hostImpl(&proxy); | 1302 FakeLayerTreeHostImpl hostImpl(&proxy); |
1300 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(&hostImpl); | 1303 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(&hostImpl); |
1301 LayerImpl* child = root->children()[0]; | 1304 LayerImpl* child = root->children()[0]; |
1302 LayerImpl* grandChild = child->children()[0]; | 1305 LayerImpl* grandChild = child->children()[0]; |
1303 | 1306 |
1304 gfx::Transform rotationByZ; | 1307 gfx::Transform rotationByZ; |
1305 MathUtil::rotateEulerAngles(&rotationByZ, 0, 0, 90); | 1308 rotationByZ.RotateAboutZAxis(90); |
1306 | 1309 |
1307 root->setTransform(rotationByZ); | 1310 root->setTransform(rotationByZ); |
1308 grandChild->setFixedToContainerLayer(true); | 1311 grandChild->setFixedToContainerLayer(true); |
1309 | 1312 |
1310 // Case 1: root scrollDelta of 0, 0 | 1313 // Case 1: root scrollDelta of 0, 0 |
1311 root->setScrollDelta(gfx::Vector2d(0, 0)); | 1314 root->setScrollDelta(gfx::Vector2d(0, 0)); |
1312 executeCalculateDrawProperties(root.get()); | 1315 executeCalculateDrawProperties(root.get()); |
1313 | 1316 |
1314 gfx::Transform identityMatrix; | 1317 gfx::Transform identityMatrix; |
1315 | 1318 |
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1922 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor3dOrthographicTransform) | 1925 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor3dOrthographicTransform) |
1923 { | 1926 { |
1924 // Test that the calculateVisibleRect() function works correctly for 3d tran
sforms. | 1927 // Test that the calculateVisibleRect() function works correctly for 3d tran
sforms. |
1925 | 1928 |
1926 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100
)); | 1929 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100
)); |
1927 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100)
); | 1930 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100)
); |
1928 gfx::Transform layerToSurfaceTransform; | 1931 gfx::Transform layerToSurfaceTransform; |
1929 | 1932 |
1930 // Case 1: Orthographic projection of a layer rotated about y-axis by 45 deg
rees, should be fully contained in the renderSurface. | 1933 // Case 1: Orthographic projection of a layer rotated about y-axis by 45 deg
rees, should be fully contained in the renderSurface. |
1931 layerToSurfaceTransform.MakeIdentity(); | 1934 layerToSurfaceTransform.MakeIdentity(); |
1932 MathUtil::rotateEulerAngles(&layerToSurfaceTransform, 0, 45, 0); | 1935 layerToSurfaceTransform.RotateAboutYAxis(45); |
1933 gfx::Rect expected = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100)); | 1936 gfx::Rect expected = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100)); |
1934 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe
ct, layerContentRect, layerToSurfaceTransform); | 1937 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe
ct, layerContentRect, layerToSurfaceTransform); |
1935 EXPECT_RECT_EQ(expected, actual); | 1938 EXPECT_RECT_EQ(expected, actual); |
1936 | 1939 |
1937 // Case 2: Orthographic projection of a layer rotated about y-axis by 45 deg
rees, but | 1940 // Case 2: Orthographic projection of a layer rotated about y-axis by 45 deg
rees, but |
1938 // shifted to the side so only the right-half the layer would be vis
ible on | 1941 // shifted to the side so only the right-half the layer would be vis
ible on |
1939 // the surface. | 1942 // the surface. |
1940 double halfWidthOfRotatedLayer = (100 / sqrt(2.0)) * 0.5; // 100 is the un-r
otated layer width; divided by sqrt(2) is the rotated width. | 1943 double halfWidthOfRotatedLayer = (100 / sqrt(2.0)) * 0.5; // 100 is the un-r
otated layer width; divided by sqrt(2) is the rotated width. |
1941 layerToSurfaceTransform.MakeIdentity(); | 1944 layerToSurfaceTransform.MakeIdentity(); |
1942 layerToSurfaceTransform.Translate(-halfWidthOfRotatedLayer, 0); | 1945 layerToSurfaceTransform.Translate(-halfWidthOfRotatedLayer, 0); |
1943 MathUtil::rotateEulerAngles(&layerToSurfaceTransform, 0, 45, 0); // rotates
about the left edge of the layer | 1946 layerToSurfaceTransform.RotateAboutYAxis(45); // rotates about the left edge
of the layer |
1944 expected = gfx::Rect(gfx::Point(50, 0), gfx::Size(50, 100)); // right half o
f the layer. | 1947 expected = gfx::Rect(gfx::Point(50, 0), gfx::Size(50, 100)); // right half o
f the layer. |
1945 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC
ontentRect, layerToSurfaceTransform); | 1948 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC
ontentRect, layerToSurfaceTransform); |
1946 EXPECT_RECT_EQ(expected, actual); | 1949 EXPECT_RECT_EQ(expected, actual); |
1947 } | 1950 } |
1948 | 1951 |
1949 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor3dPerspectiveTransform) | 1952 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor3dPerspectiveTransform) |
1950 { | 1953 { |
1951 // Test the calculateVisibleRect() function works correctly when the layer h
as a | 1954 // Test the calculateVisibleRect() function works correctly when the layer h
as a |
1952 // perspective projection onto the target surface. | 1955 // perspective projection onto the target surface. |
1953 | 1956 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1994 // flattened to the surface. | 1997 // flattened to the surface. |
1995 | 1998 |
1996 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100
)); | 1999 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100
)); |
1997 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100)
); | 2000 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100)
); |
1998 gfx::Transform layerToSurfaceTransform; | 2001 gfx::Transform layerToSurfaceTransform; |
1999 | 2002 |
2000 // This sequence of transforms effectively rotates the layer about the y-axi
s at the | 2003 // This sequence of transforms effectively rotates the layer about the y-axi
s at the |
2001 // center of the layer. | 2004 // center of the layer. |
2002 layerToSurfaceTransform.MakeIdentity(); | 2005 layerToSurfaceTransform.MakeIdentity(); |
2003 layerToSurfaceTransform.Translate(50, 0); | 2006 layerToSurfaceTransform.Translate(50, 0); |
2004 MathUtil::rotateEulerAngles(&layerToSurfaceTransform, 0, 45, 0); | 2007 layerToSurfaceTransform.RotateAboutYAxis(45); |
2005 layerToSurfaceTransform.Translate(-50, 0); | 2008 layerToSurfaceTransform.Translate(-50, 0); |
2006 | 2009 |
2007 gfx::Rect expected = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100)); | 2010 gfx::Rect expected = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100)); |
2008 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe
ct, layerContentRect, layerToSurfaceTransform); | 2011 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe
ct, layerContentRect, layerToSurfaceTransform); |
2009 EXPECT_RECT_EQ(expected, actual); | 2012 EXPECT_RECT_EQ(expected, actual); |
2010 } | 2013 } |
2011 | 2014 |
2012 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor3dPerspectiveWhenClippedByW) | 2015 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor3dPerspectiveWhenClippedByW) |
2013 { | 2016 { |
2014 // Test the calculateVisibleRect() function works correctly when projecting
a surface | 2017 // Test the calculateVisibleRect() function works correctly when projecting
a surface |
2015 // onto a layer, but the layer is partially behind the camera (not just behi
nd the | 2018 // onto a layer, but the layer is partially behind the camera (not just behi
nd the |
2016 // projection plane). In this case, the cartesian coordinates may seem to be
valid, | 2019 // projection plane). In this case, the cartesian coordinates may seem to be
valid, |
2017 // but actually they are not. The visibleRect needs to be properly clipped b
y the | 2020 // but actually they are not. The visibleRect needs to be properly clipped b
y the |
2018 // w = 0 plane in homogeneous coordinates before converting to cartesian coo
rdinates. | 2021 // w = 0 plane in homogeneous coordinates before converting to cartesian coo
rdinates. |
2019 | 2022 |
2020 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(-50, -50), gfx::Size(100,
100)); | 2023 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(-50, -50), gfx::Size(100,
100)); |
2021 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(-10, -1), gfx::Size(20, 2)
); | 2024 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(-10, -1), gfx::Size(20, 2)
); |
2022 gfx::Transform layerToSurfaceTransform; | 2025 gfx::Transform layerToSurfaceTransform; |
2023 | 2026 |
2024 // The layer is positioned so that the right half of the layer should be in
front of | 2027 // The layer is positioned so that the right half of the layer should be in
front of |
2025 // the camera, while the other half is behind the surface's projection plane
. The | 2028 // the camera, while the other half is behind the surface's projection plane
. The |
2026 // following sequence of transforms applies the perspective and rotation abo
ut the | 2029 // following sequence of transforms applies the perspective and rotation abo
ut the |
2027 // center of the layer. | 2030 // center of the layer. |
2028 layerToSurfaceTransform.MakeIdentity(); | 2031 layerToSurfaceTransform.MakeIdentity(); |
2029 layerToSurfaceTransform.ApplyPerspectiveDepth(1); | 2032 layerToSurfaceTransform.ApplyPerspectiveDepth(1); |
2030 layerToSurfaceTransform.Translate3d(-2, 0, 1); | 2033 layerToSurfaceTransform.Translate3d(-2, 0, 1); |
2031 MathUtil::rotateEulerAngles(&layerToSurfaceTransform, 0, 45, 0); | 2034 layerToSurfaceTransform.RotateAboutYAxis(45); |
2032 | 2035 |
2033 // Sanity check that this transform does indeed cause w < 0 when applying th
e | 2036 // Sanity check that this transform does indeed cause w < 0 when applying th
e |
2034 // transform, otherwise this code is not testing the intended scenario. | 2037 // transform, otherwise this code is not testing the intended scenario. |
2035 bool clipped = false; | 2038 bool clipped = false; |
2036 MathUtil::mapQuad(layerToSurfaceTransform, gfx::QuadF(gfx::RectF(layerConten
tRect)), clipped); | 2039 MathUtil::mapQuad(layerToSurfaceTransform, gfx::QuadF(gfx::RectF(layerConten
tRect)), clipped); |
2037 ASSERT_TRUE(clipped); | 2040 ASSERT_TRUE(clipped); |
2038 | 2041 |
2039 int expectedXPosition = 0; | 2042 int expectedXPosition = 0; |
2040 int expectedWidth = 10; | 2043 int expectedWidth = 10; |
2041 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe
ct, layerContentRect, layerToSurfaceTransform); | 2044 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe
ct, layerContentRect, layerToSurfaceTransform); |
2042 EXPECT_EQ(expectedXPosition, actual.x()); | 2045 EXPECT_EQ(expectedXPosition, actual.x()); |
2043 EXPECT_EQ(expectedWidth, actual.width()); | 2046 EXPECT_EQ(expectedWidth, actual.width()); |
2044 } | 2047 } |
2045 | 2048 |
2046 TEST(LayerTreeHostCommonTest, verifyVisibleRectForPerspectiveUnprojection) | 2049 TEST(LayerTreeHostCommonTest, verifyVisibleRectForPerspectiveUnprojection) |
2047 { | 2050 { |
2048 // To determine visibleRect in layer space, there needs to be an un-projecti
on from | 2051 // To determine visibleRect in layer space, there needs to be an un-projecti
on from |
2049 // surface space to layer space. When the original transform was a perspecti
ve | 2052 // surface space to layer space. When the original transform was a perspecti
ve |
2050 // projection that was clipped, it returns a rect that encloses the clipped
bounds. | 2053 // projection that was clipped, it returns a rect that encloses the clipped
bounds. |
2051 // Un-projecting this new rect may require clipping again. | 2054 // Un-projecting this new rect may require clipping again. |
2052 | 2055 |
2053 // This sequence of transforms causes one corner of the layer to protrude ac
ross the w = 0 plane, and should be clipped. | 2056 // This sequence of transforms causes one corner of the layer to protrude ac
ross the w = 0 plane, and should be clipped. |
2054 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(-50, -50), gfx::Size(100,
100)); | 2057 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(-50, -50), gfx::Size(100,
100)); |
2055 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(-10, -10), gfx::Size(20, 2
0)); | 2058 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(-10, -10), gfx::Size(20, 2
0)); |
2056 gfx::Transform layerToSurfaceTransform; | 2059 gfx::Transform layerToSurfaceTransform; |
2057 layerToSurfaceTransform.MakeIdentity(); | 2060 layerToSurfaceTransform.MakeIdentity(); |
2058 layerToSurfaceTransform.ApplyPerspectiveDepth(1); | 2061 layerToSurfaceTransform.ApplyPerspectiveDepth(1); |
2059 layerToSurfaceTransform.Translate3d(0, 0, -5); | 2062 layerToSurfaceTransform.Translate3d(0, 0, -5); |
2060 MathUtil::rotateEulerAngles(&layerToSurfaceTransform, 0, 45, 0); | 2063 layerToSurfaceTransform.RotateAboutYAxis(45); |
2061 MathUtil::rotateEulerAngles(&layerToSurfaceTransform, 80, 0, 0); | 2064 layerToSurfaceTransform.RotateAboutXAxis(80); |
2062 | 2065 |
2063 // Sanity check that un-projection does indeed cause w < 0, otherwise this c
ode is not | 2066 // Sanity check that un-projection does indeed cause w < 0, otherwise this c
ode is not |
2064 // testing the intended scenario. | 2067 // testing the intended scenario. |
2065 bool clipped = false; | 2068 bool clipped = false; |
2066 gfx::RectF clippedRect = MathUtil::mapClippedRect(layerToSurfaceTransform, l
ayerContentRect); | 2069 gfx::RectF clippedRect = MathUtil::mapClippedRect(layerToSurfaceTransform, l
ayerContentRect); |
2067 MathUtil::projectQuad(inverse(layerToSurfaceTransform), gfx::QuadF(clippedRe
ct), clipped); | 2070 MathUtil::projectQuad(inverse(layerToSurfaceTransform), gfx::QuadF(clippedRe
ct), clipped); |
2068 ASSERT_TRUE(clipped); | 2071 ASSERT_TRUE(clipped); |
2069 | 2072 |
2070 // Only the corner of the layer is not visible on the surface because of bei
ng | 2073 // Only the corner of the layer is not visible on the surface because of bei
ng |
2071 // clipped. But, the net result of rounding visible region to an axis-aligne
d rect is | 2074 // clipped. But, the net result of rounding visible region to an axis-aligne
d rect is |
(...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2929 | 2932 |
2930 TEST(LayerTreeHostCommonTest, verifyHitTestingForSingleRotatedLayer) | 2933 TEST(LayerTreeHostCommonTest, verifyHitTestingForSingleRotatedLayer) |
2931 { | 2934 { |
2932 FakeImplProxy proxy; | 2935 FakeImplProxy proxy; |
2933 FakeLayerTreeHostImpl hostImpl(&proxy); | 2936 FakeLayerTreeHostImpl hostImpl(&proxy); |
2934 scoped_ptr<LayerImpl> root = LayerImpl::create(hostImpl.activeTree(), 12345)
; | 2937 scoped_ptr<LayerImpl> root = LayerImpl::create(hostImpl.activeTree(), 12345)
; |
2935 | 2938 |
2936 gfx::Transform identityMatrix; | 2939 gfx::Transform identityMatrix; |
2937 gfx::Transform rotation45DegreesAboutCenter; | 2940 gfx::Transform rotation45DegreesAboutCenter; |
2938 rotation45DegreesAboutCenter.Translate(50, 50); | 2941 rotation45DegreesAboutCenter.Translate(50, 50); |
2939 MathUtil::rotateEulerAngles(&rotation45DegreesAboutCenter, 0, 0, 45); | 2942 rotation45DegreesAboutCenter.RotateAboutZAxis(45); |
2940 rotation45DegreesAboutCenter.Translate(-50, -50); | 2943 rotation45DegreesAboutCenter.Translate(-50, -50); |
2941 gfx::PointF anchor(0, 0); | 2944 gfx::PointF anchor(0, 0); |
2942 gfx::PointF position(0, 0); | 2945 gfx::PointF position(0, 0); |
2943 gfx::Size bounds(100, 100); | 2946 gfx::Size bounds(100, 100); |
2944 setLayerPropertiesForTesting(root.get(), rotation45DegreesAboutCenter, ident
ityMatrix, anchor, position, bounds, false); | 2947 setLayerPropertiesForTesting(root.get(), rotation45DegreesAboutCenter, ident
ityMatrix, anchor, position, bounds, false); |
2945 root->setDrawsContent(true); | 2948 root->setDrawsContent(true); |
2946 | 2949 |
2947 std::vector<LayerImpl*> renderSurfaceLayerList; | 2950 std::vector<LayerImpl*> renderSurfaceLayerList; |
2948 int dummyMaxTextureSize = 512; | 2951 int dummyMaxTextureSize = 512; |
2949 LayerTreeHostCommon::calculateDrawProperties(root.get(), root->bounds(), 1,
1, dummyMaxTextureSize, false, renderSurfaceLayerList); | 2952 LayerTreeHostCommon::calculateDrawProperties(root.get(), root->bounds(), 1,
1, dummyMaxTextureSize, false, renderSurfaceLayerList); |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3188 scoped_ptr<LayerImpl> child = LayerImpl::create(hostImpl.activeTree(), 4
56); | 3191 scoped_ptr<LayerImpl> child = LayerImpl::create(hostImpl.activeTree(), 4
56); |
3189 scoped_ptr<LayerImpl> grandChild = LayerImpl::create(hostImpl.activeTree
(), 789); | 3192 scoped_ptr<LayerImpl> grandChild = LayerImpl::create(hostImpl.activeTree
(), 789); |
3190 scoped_ptr<LayerImpl> rotatedLeaf = LayerImpl::create(hostImpl.activeTre
e(), 2468); | 3193 scoped_ptr<LayerImpl> rotatedLeaf = LayerImpl::create(hostImpl.activeTre
e(), 2468); |
3191 | 3194 |
3192 position = gfx::PointF(10, 10); | 3195 position = gfx::PointF(10, 10); |
3193 bounds = gfx::Size(80, 80); | 3196 bounds = gfx::Size(80, 80); |
3194 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix
, anchor, position, bounds, false); | 3197 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix
, anchor, position, bounds, false); |
3195 child->setMasksToBounds(true); | 3198 child->setMasksToBounds(true); |
3196 | 3199 |
3197 gfx::Transform rotation45DegreesAboutCorner; | 3200 gfx::Transform rotation45DegreesAboutCorner; |
3198 MathUtil::rotateEulerAngles(&rotation45DegreesAboutCorner, 0, 0, 45); | 3201 rotation45DegreesAboutCorner.RotateAboutZAxis(45); |
3199 | 3202 |
3200 position = gfx::PointF(0, 0); // remember, positioned with respect to it
s parent which is already at 10, 10 | 3203 position = gfx::PointF(0, 0); // remember, positioned with respect to it
s parent which is already at 10, 10 |
3201 bounds = gfx::Size(200, 200); // to ensure it covers at least sqrt(2) *
100. | 3204 bounds = gfx::Size(200, 200); // to ensure it covers at least sqrt(2) *
100. |
3202 setLayerPropertiesForTesting(grandChild.get(), rotation45DegreesAboutCor
ner, identityMatrix, anchor, position, bounds, false); | 3205 setLayerPropertiesForTesting(grandChild.get(), rotation45DegreesAboutCor
ner, identityMatrix, anchor, position, bounds, false); |
3203 grandChild->setMasksToBounds(true); | 3206 grandChild->setMasksToBounds(true); |
3204 | 3207 |
3205 // Rotates about the center of the layer | 3208 // Rotates about the center of the layer |
3206 gfx::Transform rotatedLeafTransform; | 3209 gfx::Transform rotatedLeafTransform; |
3207 rotatedLeafTransform.Translate(-10, -10); // cancel out the grandParent'
s position | 3210 rotatedLeafTransform.Translate(-10, -10); // cancel out the grandParent'
s position |
3208 MathUtil::rotateEulerAngles(&rotatedLeafTransform, 0, 0, -45); // cancel
out the corner 45-degree rotation of the parent. | 3211 rotatedLeafTransform.RotateAboutZAxis(-45); // cancel out the corner 45-
degree rotation of the parent. |
3209 rotatedLeafTransform.Translate(50, 50); | 3212 rotatedLeafTransform.Translate(50, 50); |
3210 MathUtil::rotateEulerAngles(&rotatedLeafTransform, 0, 0, 45); | 3213 rotatedLeafTransform.RotateAboutZAxis(45); |
3211 rotatedLeafTransform.Translate(-50, -50); | 3214 rotatedLeafTransform.Translate(-50, -50); |
3212 position = gfx::PointF(0, 0); | 3215 position = gfx::PointF(0, 0); |
3213 bounds = gfx::Size(100, 100); | 3216 bounds = gfx::Size(100, 100); |
3214 setLayerPropertiesForTesting(rotatedLeaf.get(), rotatedLeafTransform, id
entityMatrix, anchor, position, bounds, false); | 3217 setLayerPropertiesForTesting(rotatedLeaf.get(), rotatedLeafTransform, id
entityMatrix, anchor, position, bounds, false); |
3215 rotatedLeaf->setDrawsContent(true); | 3218 rotatedLeaf->setDrawsContent(true); |
3216 | 3219 |
3217 grandChild->addChild(rotatedLeaf.Pass()); | 3220 grandChild->addChild(rotatedLeaf.Pass()); |
3218 child->addChild(grandChild.Pass()); | 3221 child->addChild(grandChild.Pass()); |
3219 root->addChild(child.Pass()); | 3222 root->addChild(child.Pass()); |
3220 } | 3223 } |
(...skipping 1654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4875 EXPECT_EQ(m_canUseLCDText, m_grandChild->canUseLCDText()); | 4878 EXPECT_EQ(m_canUseLCDText, m_grandChild->canUseLCDText()); |
4876 } | 4879 } |
4877 | 4880 |
4878 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, | 4881 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, |
4879 LCDTextTest, | 4882 LCDTextTest, |
4880 testing::Combine(testing::Bool(), | 4883 testing::Combine(testing::Bool(), |
4881 testing::Bool())); | 4884 testing::Bool())); |
4882 | 4885 |
4883 } // namespace | 4886 } // namespace |
4884 } // namespace cc | 4887 } // namespace cc |
OLD | NEW |