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 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 gfx::Transform parentTranslationToCenter; |
317 parentTranslationToCenter.Translate(5, 6); | 317 parentTranslationToCenter.Translate(5, 6); |
318 // Sublayer matrix is applied to the center of the parent layer. | 318 // Sublayer matrix is applied to the center of the parent layer. |
319 parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform
* inverse(parentTranslationToAnchor) | 319 parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform
* inverse(parentTranslationToAnchor) |
320 * parentTranslationToCenter * parentSublayerMatrix * inverse(parentT
ranslationToCenter); | 320 * parentTranslationToCenter * parentSublayerMatrix * inverse(parentT
ranslationToCenter); |
321 gfx::Transform flattenedCompositeTransform = MathUtil::to2dTransform(parentC
ompositeTransform); | 321 gfx::Transform flattenedCompositeTransform = parentCompositeTransform; |
| 322 flattenedCompositeTransform.FlattenTo2d(); |
322 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla
yerMatrix, gfx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(10, 12), false)
; | 323 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla
yerMatrix, gfx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(10, 12), false)
; |
323 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf
x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(16, 18), false); | 324 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf
x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(16, 18), false); |
324 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri
x, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(76, 78), false); | 325 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri
x, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(76, 78), false); |
325 executeCalculateDrawProperties(root.get()); | 326 executeCalculateDrawProperties(root.get()); |
326 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->drawTransfo
rm()); | 327 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->drawTransfo
rm()); |
327 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpace
Transform()); | 328 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpace
Transform()); |
328 EXPECT_TRANSFORMATION_MATRIX_EQ(flattenedCompositeTransform, grandChild->dra
wTransform()); | 329 EXPECT_TRANSFORMATION_MATRIX_EQ(flattenedCompositeTransform, grandChild->dra
wTransform()); |
329 EXPECT_TRANSFORMATION_MATRIX_EQ(flattenedCompositeTransform, grandChild->scr
eenSpaceTransform()); | 330 EXPECT_TRANSFORMATION_MATRIX_EQ(flattenedCompositeTransform, grandChild->scr
eenSpaceTransform()); |
330 | 331 |
331 // Case 5: same as Case 4, except that child does preserve 3D, so the grandC
hild should receive the non-flattened composite transform. | 332 // Case 5: same as Case 4, except that child does preserve 3D, so the grandC
hild should receive the non-flattened composite transform. |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
726 // For layers that flatten their subtree, there should be an orthographic pr
ojection | 727 // For layers that flatten their subtree, there should be an orthographic pr
ojection |
727 // (for x and y values) in the middle of the transform sequence. Note that t
he way the | 728 // (for x and y values) in the middle of the transform sequence. Note that t
he way the |
728 // code is currently implemented, it is not expected to use a canonical orth
ographic | 729 // code is currently implemented, it is not expected to use a canonical orth
ographic |
729 // projection. | 730 // projection. |
730 | 731 |
731 scoped_refptr<Layer> root = Layer::create(); | 732 scoped_refptr<Layer> root = Layer::create(); |
732 scoped_refptr<Layer> child = Layer::create(); | 733 scoped_refptr<Layer> child = Layer::create(); |
733 scoped_refptr<LayerWithForcedDrawsContent> grandChild = make_scoped_refptr(n
ew LayerWithForcedDrawsContent()); | 734 scoped_refptr<LayerWithForcedDrawsContent> grandChild = make_scoped_refptr(n
ew LayerWithForcedDrawsContent()); |
734 | 735 |
735 gfx::Transform rotationAboutYAxis; | 736 gfx::Transform rotationAboutYAxis; |
736 MathUtil::rotateEulerAngles(&rotationAboutYAxis, 0, 30, 0); | 737 rotationAboutYAxis.RotateAboutYAxis(30); |
737 | 738 |
738 const gfx::Transform identityMatrix; | 739 const gfx::Transform identityMatrix; |
739 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx
::PointF(), gfx::PointF(), gfx::Size(100, 100), false); | 740 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx
::PointF(), gfx::PointF(), gfx::Size(100, 100), false); |
740 setLayerPropertiesForTesting(child.get(), rotationAboutYAxis, identityMatrix
, gfx::PointF(), gfx::PointF(), gfx::Size(10, 10), false); | 741 setLayerPropertiesForTesting(child.get(), rotationAboutYAxis, identityMatrix
, gfx::PointF(), gfx::PointF(), gfx::Size(10, 10), false); |
741 setLayerPropertiesForTesting(grandChild.get(), rotationAboutYAxis, identityM
atrix, gfx::PointF(), gfx::PointF(), gfx::Size(10, 10), false); | 742 setLayerPropertiesForTesting(grandChild.get(), rotationAboutYAxis, identityM
atrix, gfx::PointF(), gfx::PointF(), gfx::Size(10, 10), false); |
742 | 743 |
743 root->addChild(child); | 744 root->addChild(child); |
744 child->addChild(grandChild); | 745 child->addChild(grandChild); |
745 child->setForceRenderSurface(true); | 746 child->setForceRenderSurface(true); |
746 | 747 |
747 // No layers in this test should preserve 3d. | 748 // No layers in this test should preserve 3d. |
748 ASSERT_FALSE(root->preserves3D()); | 749 ASSERT_FALSE(root->preserves3D()); |
749 ASSERT_FALSE(child->preserves3D()); | 750 ASSERT_FALSE(child->preserves3D()); |
750 ASSERT_FALSE(grandChild->preserves3D()); | 751 ASSERT_FALSE(grandChild->preserves3D()); |
751 | 752 |
752 gfx::Transform expectedChildDrawTransform = rotationAboutYAxis; | 753 gfx::Transform expectedChildDrawTransform = rotationAboutYAxis; |
753 gfx::Transform expectedChildScreenSpaceTransform = rotationAboutYAxis; | 754 gfx::Transform expectedChildScreenSpaceTransform = rotationAboutYAxis; |
754 gfx::Transform expectedGrandChildDrawTransform = rotationAboutYAxis; // draw
s onto child's renderSurface | 755 gfx::Transform expectedGrandChildDrawTransform = rotationAboutYAxis; // draw
s onto child's renderSurface |
755 gfx::Transform expectedGrandChildScreenSpaceTransform = MathUtil::to2dTransf
orm(rotationAboutYAxis) * rotationAboutYAxis; | 756 gfx::Transform flattenedRotationAboutY = rotationAboutYAxis; |
| 757 flattenedRotationAboutY.FlattenTo2d(); |
| 758 gfx::Transform expectedGrandChildScreenSpaceTransform = flattenedRotationAbo
utY * rotationAboutYAxis; |
756 | 759 |
757 executeCalculateDrawProperties(root.get()); | 760 executeCalculateDrawProperties(root.get()); |
758 | 761 |
759 // The child's drawTransform should have been taken by its surface. | 762 // The child's drawTransform should have been taken by its surface. |
760 ASSERT_TRUE(child->renderSurface()); | 763 ASSERT_TRUE(child->renderSurface()); |
761 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildDrawTransform, child->renderSur
face()->drawTransform()); | 764 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildDrawTransform, child->renderSur
face()->drawTransform()); |
762 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildScreenSpaceTransform, child->re
nderSurface()->screenSpaceTransform()); | 765 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildScreenSpaceTransform, child->re
nderSurface()->screenSpaceTransform()); |
763 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform()); | 766 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform()); |
764 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildScreenSpaceTransform, child->sc
reenSpaceTransform()); | 767 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildScreenSpaceTransform, child->sc
reenSpaceTransform()); |
765 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildDrawTransform, grandChild-
>drawTransform()); | 768 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildDrawTransform, grandChild-
>drawTransform()); |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1021 // is NOT the direct parent of the fixed-position layer, and the hierarchy h
as various | 1024 // is NOT the direct parent of the fixed-position layer, and the hierarchy h
as various |
1022 // transforms that have to be processed in the correct order. | 1025 // transforms that have to be processed in the correct order. |
1023 FakeImplProxy proxy; | 1026 FakeImplProxy proxy; |
1024 FakeLayerTreeHostImpl hostImpl(&proxy); | 1027 FakeLayerTreeHostImpl hostImpl(&proxy); |
1025 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(&hostImpl); | 1028 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(&hostImpl); |
1026 LayerImpl* child = root->children()[0]; | 1029 LayerImpl* child = root->children()[0]; |
1027 LayerImpl* grandChild = child->children()[0]; | 1030 LayerImpl* grandChild = child->children()[0]; |
1028 LayerImpl* greatGrandChild = grandChild->children()[0]; | 1031 LayerImpl* greatGrandChild = grandChild->children()[0]; |
1029 | 1032 |
1030 gfx::Transform rotationAboutZ; | 1033 gfx::Transform rotationAboutZ; |
1031 MathUtil::rotateEulerAngles(&rotationAboutZ, 0, 0, 90); | 1034 rotationAboutZ.RotateAboutZAxis(90); |
1032 | 1035 |
1033 child->setIsContainerForFixedPositionLayers(true); | 1036 child->setIsContainerForFixedPositionLayers(true); |
1034 child->setTransform(rotationAboutZ); | 1037 child->setTransform(rotationAboutZ); |
1035 grandChild->setPosition(gfx::PointF(8, 6)); | 1038 grandChild->setPosition(gfx::PointF(8, 6)); |
1036 grandChild->setTransform(rotationAboutZ); | 1039 grandChild->setTransform(rotationAboutZ); |
1037 greatGrandChild->setFixedToContainerLayer(true); // greatGrandChild is posit
ioned upside-down with respect to the renderTarget. | 1040 greatGrandChild->setFixedToContainerLayer(true); // greatGrandChild is posit
ioned upside-down with respect to the renderTarget. |
1038 | 1041 |
1039 // Case 1: scrollDelta of 0, 0 | 1042 // Case 1: scrollDelta of 0, 0 |
1040 child->setScrollDelta(gfx::Vector2d(0, 0)); | 1043 child->setScrollDelta(gfx::Vector2d(0, 0)); |
1041 executeCalculateDrawProperties(root.get()); | 1044 executeCalculateDrawProperties(root.get()); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1083 // is NOT the direct parent of the fixed-position layer, and the hierarchy h
as various | 1086 // is NOT the direct parent of the fixed-position layer, and the hierarchy h
as various |
1084 // transforms that have to be processed in the correct order. | 1087 // transforms that have to be processed in the correct order. |
1085 FakeImplProxy proxy; | 1088 FakeImplProxy proxy; |
1086 FakeLayerTreeHostImpl hostImpl(&proxy); | 1089 FakeLayerTreeHostImpl hostImpl(&proxy); |
1087 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(&hostImpl); | 1090 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(&hostImpl); |
1088 LayerImpl* child = root->children()[0]; | 1091 LayerImpl* child = root->children()[0]; |
1089 LayerImpl* grandChild = child->children()[0]; | 1092 LayerImpl* grandChild = child->children()[0]; |
1090 LayerImpl* greatGrandChild = grandChild->children()[0]; | 1093 LayerImpl* greatGrandChild = grandChild->children()[0]; |
1091 | 1094 |
1092 gfx::Transform rotationAboutZ; | 1095 gfx::Transform rotationAboutZ; |
1093 MathUtil::rotateEulerAngles(&rotationAboutZ, 0, 0, 90); | 1096 rotationAboutZ.RotateAboutZAxis(90); |
1094 | 1097 |
1095 child->setIsContainerForFixedPositionLayers(true); | 1098 child->setIsContainerForFixedPositionLayers(true); |
1096 child->setTransform(rotationAboutZ); | 1099 child->setTransform(rotationAboutZ); |
1097 grandChild->setPosition(gfx::PointF(8, 6)); | 1100 grandChild->setPosition(gfx::PointF(8, 6)); |
1098 grandChild->setTransform(rotationAboutZ); | 1101 grandChild->setTransform(rotationAboutZ); |
1099 greatGrandChild->setFixedToContainerLayer(true); // greatGrandChild is posit
ioned upside-down with respect to the renderTarget. | 1102 greatGrandChild->setFixedToContainerLayer(true); // greatGrandChild is posit
ioned upside-down with respect to the renderTarget. |
1100 | 1103 |
1101 // Case 1: scrollDelta of 0, 0 | 1104 // Case 1: scrollDelta of 0, 0 |
1102 child->setScrollDelta(gfx::Vector2d(0, 0)); | 1105 child->setScrollDelta(gfx::Vector2d(0, 0)); |
1103 executeCalculateDrawProperties(root.get()); | 1106 executeCalculateDrawProperties(root.get()); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1151 LayerImpl* grandChild = child->children()[0]; | 1154 LayerImpl* grandChild = child->children()[0]; |
1152 LayerImpl* greatGrandChild = grandChild->children()[0]; | 1155 LayerImpl* greatGrandChild = grandChild->children()[0]; |
1153 | 1156 |
1154 child->setIsContainerForFixedPositionLayers(true); | 1157 child->setIsContainerForFixedPositionLayers(true); |
1155 grandChild->setPosition(gfx::PointF(8, 6)); | 1158 grandChild->setPosition(gfx::PointF(8, 6)); |
1156 grandChild->setForceRenderSurface(true); | 1159 grandChild->setForceRenderSurface(true); |
1157 greatGrandChild->setFixedToContainerLayer(true); | 1160 greatGrandChild->setFixedToContainerLayer(true); |
1158 greatGrandChild->setDrawsContent(true); | 1161 greatGrandChild->setDrawsContent(true); |
1159 | 1162 |
1160 gfx::Transform rotationAboutZ; | 1163 gfx::Transform rotationAboutZ; |
1161 MathUtil::rotateEulerAngles(&rotationAboutZ, 0, 0, 90); | 1164 rotationAboutZ.RotateAboutZAxis(90); |
1162 grandChild->setTransform(rotationAboutZ); | 1165 grandChild->setTransform(rotationAboutZ); |
1163 | 1166 |
1164 // Case 1: scrollDelta of 0, 0 | 1167 // Case 1: scrollDelta of 0, 0 |
1165 child->setScrollDelta(gfx::Vector2d(0, 0)); | 1168 child->setScrollDelta(gfx::Vector2d(0, 0)); |
1166 executeCalculateDrawProperties(root.get()); | 1169 executeCalculateDrawProperties(root.get()); |
1167 | 1170 |
1168 gfx::Transform expectedChildTransform; | 1171 gfx::Transform expectedChildTransform; |
1169 gfx::Transform expectedSurfaceDrawTransform; | 1172 gfx::Transform expectedSurfaceDrawTransform; |
1170 expectedSurfaceDrawTransform.Translate(8, 6); | 1173 expectedSurfaceDrawTransform.Translate(8, 6); |
1171 expectedSurfaceDrawTransform.PreconcatTransform(rotationAboutZ); | 1174 expectedSurfaceDrawTransform.PreconcatTransform(rotationAboutZ); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1241 greatGrandChild->setForceRenderSurface(true); | 1244 greatGrandChild->setForceRenderSurface(true); |
1242 fixedPositionChild->setFixedToContainerLayer(true); | 1245 fixedPositionChild->setFixedToContainerLayer(true); |
1243 fixedPositionChild->setDrawsContent(true); | 1246 fixedPositionChild->setDrawsContent(true); |
1244 | 1247 |
1245 // The additional rotations, which are non-commutative with translations, he
lp to | 1248 // The additional rotations, which are non-commutative with translations, he
lp to |
1246 // verify that we have correct order-of-operations in the final scroll compe
nsation. | 1249 // verify that we have correct order-of-operations in the final scroll compe
nsation. |
1247 // Note that rotating about the center of the layer ensures we do not accide
ntally | 1250 // Note that rotating about the center of the layer ensures we do not accide
ntally |
1248 // clip away layers that we want to test. | 1251 // clip away layers that we want to test. |
1249 gfx::Transform rotationAboutZ; | 1252 gfx::Transform rotationAboutZ; |
1250 rotationAboutZ.Translate(50, 50); | 1253 rotationAboutZ.Translate(50, 50); |
1251 MathUtil::rotateEulerAngles(&rotationAboutZ, 0, 0, 90); | 1254 rotationAboutZ.RotateAboutZAxis(90); |
1252 rotationAboutZ.Translate(-50, -50); | 1255 rotationAboutZ.Translate(-50, -50); |
1253 grandChild->setTransform(rotationAboutZ); | 1256 grandChild->setTransform(rotationAboutZ); |
1254 greatGrandChild->setTransform(rotationAboutZ); | 1257 greatGrandChild->setTransform(rotationAboutZ); |
1255 | 1258 |
1256 // Case 1: scrollDelta of 0, 0 | 1259 // Case 1: scrollDelta of 0, 0 |
1257 child->setScrollDelta(gfx::Vector2d(0, 0)); | 1260 child->setScrollDelta(gfx::Vector2d(0, 0)); |
1258 executeCalculateDrawProperties(root.get()); | 1261 executeCalculateDrawProperties(root.get()); |
1259 | 1262 |
1260 gfx::Transform expectedChildTransform; | 1263 gfx::Transform expectedChildTransform; |
1261 | 1264 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1412 // This test checks scroll compensation when a fixed-position layer does not
find any | 1415 // This test checks scroll compensation when a fixed-position layer does not
find any |
1413 // ancestor that is a "containerForFixedPositionLayers". In this situation,
the layer should | 1416 // ancestor that is a "containerForFixedPositionLayers". In this situation,
the layer should |
1414 // be fixed to the viewport -- not the rootLayer, which may have transforms
of its own. | 1417 // be fixed to the viewport -- not the rootLayer, which may have transforms
of its own. |
1415 FakeImplProxy proxy; | 1418 FakeImplProxy proxy; |
1416 FakeLayerTreeHostImpl hostImpl(&proxy); | 1419 FakeLayerTreeHostImpl hostImpl(&proxy); |
1417 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(&hostImpl); | 1420 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(&hostImpl); |
1418 LayerImpl* child = root->children()[0]; | 1421 LayerImpl* child = root->children()[0]; |
1419 LayerImpl* grandChild = child->children()[0]; | 1422 LayerImpl* grandChild = child->children()[0]; |
1420 | 1423 |
1421 gfx::Transform rotationByZ; | 1424 gfx::Transform rotationByZ; |
1422 MathUtil::rotateEulerAngles(&rotationByZ, 0, 0, 90); | 1425 rotationByZ.RotateAboutZAxis(90); |
1423 | 1426 |
1424 root->setTransform(rotationByZ); | 1427 root->setTransform(rotationByZ); |
1425 grandChild->setFixedToContainerLayer(true); | 1428 grandChild->setFixedToContainerLayer(true); |
1426 | 1429 |
1427 // Case 1: root scrollDelta of 0, 0 | 1430 // Case 1: root scrollDelta of 0, 0 |
1428 root->setScrollDelta(gfx::Vector2d(0, 0)); | 1431 root->setScrollDelta(gfx::Vector2d(0, 0)); |
1429 executeCalculateDrawProperties(root.get()); | 1432 executeCalculateDrawProperties(root.get()); |
1430 | 1433 |
1431 gfx::Transform identityMatrix; | 1434 gfx::Transform identityMatrix; |
1432 | 1435 |
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2039 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor3dOrthographicTransform) | 2042 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor3dOrthographicTransform) |
2040 { | 2043 { |
2041 // Test that the calculateVisibleRect() function works correctly for 3d tran
sforms. | 2044 // Test that the calculateVisibleRect() function works correctly for 3d tran
sforms. |
2042 | 2045 |
2043 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100
)); | 2046 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100
)); |
2044 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100)
); | 2047 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100)
); |
2045 gfx::Transform layerToSurfaceTransform; | 2048 gfx::Transform layerToSurfaceTransform; |
2046 | 2049 |
2047 // Case 1: Orthographic projection of a layer rotated about y-axis by 45 deg
rees, should be fully contained in the renderSurface. | 2050 // Case 1: Orthographic projection of a layer rotated about y-axis by 45 deg
rees, should be fully contained in the renderSurface. |
2048 layerToSurfaceTransform.MakeIdentity(); | 2051 layerToSurfaceTransform.MakeIdentity(); |
2049 MathUtil::rotateEulerAngles(&layerToSurfaceTransform, 0, 45, 0); | 2052 layerToSurfaceTransform.RotateAboutYAxis(45); |
2050 gfx::Rect expected = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100)); | 2053 gfx::Rect expected = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100)); |
2051 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe
ct, layerContentRect, layerToSurfaceTransform); | 2054 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe
ct, layerContentRect, layerToSurfaceTransform); |
2052 EXPECT_RECT_EQ(expected, actual); | 2055 EXPECT_RECT_EQ(expected, actual); |
2053 | 2056 |
2054 // Case 2: Orthographic projection of a layer rotated about y-axis by 45 deg
rees, but | 2057 // Case 2: Orthographic projection of a layer rotated about y-axis by 45 deg
rees, but |
2055 // shifted to the side so only the right-half the layer would be vis
ible on | 2058 // shifted to the side so only the right-half the layer would be vis
ible on |
2056 // the surface. | 2059 // the surface. |
2057 double halfWidthOfRotatedLayer = (100 / sqrt(2.0)) * 0.5; // 100 is the un-r
otated layer width; divided by sqrt(2) is the rotated width. | 2060 double halfWidthOfRotatedLayer = (100 / sqrt(2.0)) * 0.5; // 100 is the un-r
otated layer width; divided by sqrt(2) is the rotated width. |
2058 layerToSurfaceTransform.MakeIdentity(); | 2061 layerToSurfaceTransform.MakeIdentity(); |
2059 layerToSurfaceTransform.Translate(-halfWidthOfRotatedLayer, 0); | 2062 layerToSurfaceTransform.Translate(-halfWidthOfRotatedLayer, 0); |
2060 MathUtil::rotateEulerAngles(&layerToSurfaceTransform, 0, 45, 0); // rotates
about the left edge of the layer | 2063 layerToSurfaceTransform.RotateAboutYAxis(45); // rotates about the left edge
of the layer |
2061 expected = gfx::Rect(gfx::Point(50, 0), gfx::Size(50, 100)); // right half o
f the layer. | 2064 expected = gfx::Rect(gfx::Point(50, 0), gfx::Size(50, 100)); // right half o
f the layer. |
2062 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC
ontentRect, layerToSurfaceTransform); | 2065 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC
ontentRect, layerToSurfaceTransform); |
2063 EXPECT_RECT_EQ(expected, actual); | 2066 EXPECT_RECT_EQ(expected, actual); |
2064 } | 2067 } |
2065 | 2068 |
2066 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor3dPerspectiveTransform) | 2069 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor3dPerspectiveTransform) |
2067 { | 2070 { |
2068 // Test the calculateVisibleRect() function works correctly when the layer h
as a | 2071 // Test the calculateVisibleRect() function works correctly when the layer h
as a |
2069 // perspective projection onto the target surface. | 2072 // perspective projection onto the target surface. |
2070 | 2073 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2111 // flattened to the surface. | 2114 // flattened to the surface. |
2112 | 2115 |
2113 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100
)); | 2116 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100
)); |
2114 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100)
); | 2117 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100)
); |
2115 gfx::Transform layerToSurfaceTransform; | 2118 gfx::Transform layerToSurfaceTransform; |
2116 | 2119 |
2117 // This sequence of transforms effectively rotates the layer about the y-axi
s at the | 2120 // This sequence of transforms effectively rotates the layer about the y-axi
s at the |
2118 // center of the layer. | 2121 // center of the layer. |
2119 layerToSurfaceTransform.MakeIdentity(); | 2122 layerToSurfaceTransform.MakeIdentity(); |
2120 layerToSurfaceTransform.Translate(50, 0); | 2123 layerToSurfaceTransform.Translate(50, 0); |
2121 MathUtil::rotateEulerAngles(&layerToSurfaceTransform, 0, 45, 0); | 2124 layerToSurfaceTransform.RotateAboutYAxis(45); |
2122 layerToSurfaceTransform.Translate(-50, 0); | 2125 layerToSurfaceTransform.Translate(-50, 0); |
2123 | 2126 |
2124 gfx::Rect expected = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100)); | 2127 gfx::Rect expected = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100)); |
2125 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe
ct, layerContentRect, layerToSurfaceTransform); | 2128 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe
ct, layerContentRect, layerToSurfaceTransform); |
2126 EXPECT_RECT_EQ(expected, actual); | 2129 EXPECT_RECT_EQ(expected, actual); |
2127 } | 2130 } |
2128 | 2131 |
2129 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor3dPerspectiveWhenClippedByW) | 2132 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor3dPerspectiveWhenClippedByW) |
2130 { | 2133 { |
2131 // Test the calculateVisibleRect() function works correctly when projecting
a surface | 2134 // Test the calculateVisibleRect() function works correctly when projecting
a surface |
2132 // onto a layer, but the layer is partially behind the camera (not just behi
nd the | 2135 // onto a layer, but the layer is partially behind the camera (not just behi
nd the |
2133 // projection plane). In this case, the cartesian coordinates may seem to be
valid, | 2136 // projection plane). In this case, the cartesian coordinates may seem to be
valid, |
2134 // but actually they are not. The visibleRect needs to be properly clipped b
y the | 2137 // but actually they are not. The visibleRect needs to be properly clipped b
y the |
2135 // w = 0 plane in homogeneous coordinates before converting to cartesian coo
rdinates. | 2138 // w = 0 plane in homogeneous coordinates before converting to cartesian coo
rdinates. |
2136 | 2139 |
2137 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(-50, -50), gfx::Size(100,
100)); | 2140 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(-50, -50), gfx::Size(100,
100)); |
2138 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(-10, -1), gfx::Size(20, 2)
); | 2141 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(-10, -1), gfx::Size(20, 2)
); |
2139 gfx::Transform layerToSurfaceTransform; | 2142 gfx::Transform layerToSurfaceTransform; |
2140 | 2143 |
2141 // The layer is positioned so that the right half of the layer should be in
front of | 2144 // The layer is positioned so that the right half of the layer should be in
front of |
2142 // the camera, while the other half is behind the surface's projection plane
. The | 2145 // the camera, while the other half is behind the surface's projection plane
. The |
2143 // following sequence of transforms applies the perspective and rotation abo
ut the | 2146 // following sequence of transforms applies the perspective and rotation abo
ut the |
2144 // center of the layer. | 2147 // center of the layer. |
2145 layerToSurfaceTransform.MakeIdentity(); | 2148 layerToSurfaceTransform.MakeIdentity(); |
2146 layerToSurfaceTransform.ApplyPerspectiveDepth(1); | 2149 layerToSurfaceTransform.ApplyPerspectiveDepth(1); |
2147 layerToSurfaceTransform.Translate3d(-2, 0, 1); | 2150 layerToSurfaceTransform.Translate3d(-2, 0, 1); |
2148 MathUtil::rotateEulerAngles(&layerToSurfaceTransform, 0, 45, 0); | 2151 layerToSurfaceTransform.RotateAboutYAxis(45); |
2149 | 2152 |
2150 // Sanity check that this transform does indeed cause w < 0 when applying th
e | 2153 // Sanity check that this transform does indeed cause w < 0 when applying th
e |
2151 // transform, otherwise this code is not testing the intended scenario. | 2154 // transform, otherwise this code is not testing the intended scenario. |
2152 bool clipped = false; | 2155 bool clipped = false; |
2153 MathUtil::mapQuad(layerToSurfaceTransform, gfx::QuadF(gfx::RectF(layerConten
tRect)), clipped); | 2156 MathUtil::mapQuad(layerToSurfaceTransform, gfx::QuadF(gfx::RectF(layerConten
tRect)), clipped); |
2154 ASSERT_TRUE(clipped); | 2157 ASSERT_TRUE(clipped); |
2155 | 2158 |
2156 int expectedXPosition = 0; | 2159 int expectedXPosition = 0; |
2157 int expectedWidth = 10; | 2160 int expectedWidth = 10; |
2158 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe
ct, layerContentRect, layerToSurfaceTransform); | 2161 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe
ct, layerContentRect, layerToSurfaceTransform); |
2159 EXPECT_EQ(expectedXPosition, actual.x()); | 2162 EXPECT_EQ(expectedXPosition, actual.x()); |
2160 EXPECT_EQ(expectedWidth, actual.width()); | 2163 EXPECT_EQ(expectedWidth, actual.width()); |
2161 } | 2164 } |
2162 | 2165 |
2163 TEST(LayerTreeHostCommonTest, verifyVisibleRectForPerspectiveUnprojection) | 2166 TEST(LayerTreeHostCommonTest, verifyVisibleRectForPerspectiveUnprojection) |
2164 { | 2167 { |
2165 // To determine visibleRect in layer space, there needs to be an un-projecti
on from | 2168 // To determine visibleRect in layer space, there needs to be an un-projecti
on from |
2166 // surface space to layer space. When the original transform was a perspecti
ve | 2169 // surface space to layer space. When the original transform was a perspecti
ve |
2167 // projection that was clipped, it returns a rect that encloses the clipped
bounds. | 2170 // projection that was clipped, it returns a rect that encloses the clipped
bounds. |
2168 // Un-projecting this new rect may require clipping again. | 2171 // Un-projecting this new rect may require clipping again. |
2169 | 2172 |
2170 // This sequence of transforms causes one corner of the layer to protrude ac
ross the w = 0 plane, and should be clipped. | 2173 // This sequence of transforms causes one corner of the layer to protrude ac
ross the w = 0 plane, and should be clipped. |
2171 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(-50, -50), gfx::Size(100,
100)); | 2174 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(-50, -50), gfx::Size(100,
100)); |
2172 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(-10, -10), gfx::Size(20, 2
0)); | 2175 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(-10, -10), gfx::Size(20, 2
0)); |
2173 gfx::Transform layerToSurfaceTransform; | 2176 gfx::Transform layerToSurfaceTransform; |
2174 layerToSurfaceTransform.MakeIdentity(); | 2177 layerToSurfaceTransform.MakeIdentity(); |
2175 layerToSurfaceTransform.ApplyPerspectiveDepth(1); | 2178 layerToSurfaceTransform.ApplyPerspectiveDepth(1); |
2176 layerToSurfaceTransform.Translate3d(0, 0, -5); | 2179 layerToSurfaceTransform.Translate3d(0, 0, -5); |
2177 MathUtil::rotateEulerAngles(&layerToSurfaceTransform, 0, 45, 0); | 2180 layerToSurfaceTransform.RotateAboutYAxis(45); |
2178 MathUtil::rotateEulerAngles(&layerToSurfaceTransform, 80, 0, 0); | 2181 layerToSurfaceTransform.RotateAboutXAxis(80); |
2179 | 2182 |
2180 // Sanity check that un-projection does indeed cause w < 0, otherwise this c
ode is not | 2183 // Sanity check that un-projection does indeed cause w < 0, otherwise this c
ode is not |
2181 // testing the intended scenario. | 2184 // testing the intended scenario. |
2182 bool clipped = false; | 2185 bool clipped = false; |
2183 gfx::RectF clippedRect = MathUtil::mapClippedRect(layerToSurfaceTransform, l
ayerContentRect); | 2186 gfx::RectF clippedRect = MathUtil::mapClippedRect(layerToSurfaceTransform, l
ayerContentRect); |
2184 MathUtil::projectQuad(inverse(layerToSurfaceTransform), gfx::QuadF(clippedRe
ct), clipped); | 2187 MathUtil::projectQuad(inverse(layerToSurfaceTransform), gfx::QuadF(clippedRe
ct), clipped); |
2185 ASSERT_TRUE(clipped); | 2188 ASSERT_TRUE(clipped); |
2186 | 2189 |
2187 // Only the corner of the layer is not visible on the surface because of bei
ng | 2190 // Only the corner of the layer is not visible on the surface because of bei
ng |
2188 // clipped. But, the net result of rounding visible region to an axis-aligne
d rect is | 2191 // 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... |
3046 | 3049 |
3047 TEST(LayerTreeHostCommonTest, verifyHitTestingForSingleRotatedLayer) | 3050 TEST(LayerTreeHostCommonTest, verifyHitTestingForSingleRotatedLayer) |
3048 { | 3051 { |
3049 FakeImplProxy proxy; | 3052 FakeImplProxy proxy; |
3050 FakeLayerTreeHostImpl hostImpl(&proxy); | 3053 FakeLayerTreeHostImpl hostImpl(&proxy); |
3051 scoped_ptr<LayerImpl> root = LayerImpl::create(hostImpl.activeTree(), 12345)
; | 3054 scoped_ptr<LayerImpl> root = LayerImpl::create(hostImpl.activeTree(), 12345)
; |
3052 | 3055 |
3053 gfx::Transform identityMatrix; | 3056 gfx::Transform identityMatrix; |
3054 gfx::Transform rotation45DegreesAboutCenter; | 3057 gfx::Transform rotation45DegreesAboutCenter; |
3055 rotation45DegreesAboutCenter.Translate(50, 50); | 3058 rotation45DegreesAboutCenter.Translate(50, 50); |
3056 MathUtil::rotateEulerAngles(&rotation45DegreesAboutCenter, 0, 0, 45); | 3059 rotation45DegreesAboutCenter.RotateAboutZAxis(45); |
3057 rotation45DegreesAboutCenter.Translate(-50, -50); | 3060 rotation45DegreesAboutCenter.Translate(-50, -50); |
3058 gfx::PointF anchor(0, 0); | 3061 gfx::PointF anchor(0, 0); |
3059 gfx::PointF position(0, 0); | 3062 gfx::PointF position(0, 0); |
3060 gfx::Size bounds(100, 100); | 3063 gfx::Size bounds(100, 100); |
3061 setLayerPropertiesForTesting(root.get(), rotation45DegreesAboutCenter, ident
ityMatrix, anchor, position, bounds, false); | 3064 setLayerPropertiesForTesting(root.get(), rotation45DegreesAboutCenter, ident
ityMatrix, anchor, position, bounds, false); |
3062 root->setDrawsContent(true); | 3065 root->setDrawsContent(true); |
3063 | 3066 |
3064 std::vector<LayerImpl*> renderSurfaceLayerList; | 3067 std::vector<LayerImpl*> renderSurfaceLayerList; |
3065 int dummyMaxTextureSize = 512; | 3068 int dummyMaxTextureSize = 512; |
3066 LayerTreeHostCommon::calculateDrawProperties(root.get(), root->bounds(), 1,
1, dummyMaxTextureSize, false, renderSurfaceLayerList); | 3069 LayerTreeHostCommon::calculateDrawProperties(root.get(), root->bounds(), 1,
1, dummyMaxTextureSize, false, renderSurfaceLayerList); |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3305 scoped_ptr<LayerImpl> child = LayerImpl::create(hostImpl.activeTree(), 4
56); | 3308 scoped_ptr<LayerImpl> child = LayerImpl::create(hostImpl.activeTree(), 4
56); |
3306 scoped_ptr<LayerImpl> grandChild = LayerImpl::create(hostImpl.activeTree
(), 789); | 3309 scoped_ptr<LayerImpl> grandChild = LayerImpl::create(hostImpl.activeTree
(), 789); |
3307 scoped_ptr<LayerImpl> rotatedLeaf = LayerImpl::create(hostImpl.activeTre
e(), 2468); | 3310 scoped_ptr<LayerImpl> rotatedLeaf = LayerImpl::create(hostImpl.activeTre
e(), 2468); |
3308 | 3311 |
3309 position = gfx::PointF(10, 10); | 3312 position = gfx::PointF(10, 10); |
3310 bounds = gfx::Size(80, 80); | 3313 bounds = gfx::Size(80, 80); |
3311 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix
, anchor, position, bounds, false); | 3314 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix
, anchor, position, bounds, false); |
3312 child->setMasksToBounds(true); | 3315 child->setMasksToBounds(true); |
3313 | 3316 |
3314 gfx::Transform rotation45DegreesAboutCorner; | 3317 gfx::Transform rotation45DegreesAboutCorner; |
3315 MathUtil::rotateEulerAngles(&rotation45DegreesAboutCorner, 0, 0, 45); | 3318 rotation45DegreesAboutCorner.RotateAboutZAxis(45); |
3316 | 3319 |
3317 position = gfx::PointF(0, 0); // remember, positioned with respect to it
s parent which is already at 10, 10 | 3320 position = gfx::PointF(0, 0); // remember, positioned with respect to it
s parent which is already at 10, 10 |
3318 bounds = gfx::Size(200, 200); // to ensure it covers at least sqrt(2) *
100. | 3321 bounds = gfx::Size(200, 200); // to ensure it covers at least sqrt(2) *
100. |
3319 setLayerPropertiesForTesting(grandChild.get(), rotation45DegreesAboutCor
ner, identityMatrix, anchor, position, bounds, false); | 3322 setLayerPropertiesForTesting(grandChild.get(), rotation45DegreesAboutCor
ner, identityMatrix, anchor, position, bounds, false); |
3320 grandChild->setMasksToBounds(true); | 3323 grandChild->setMasksToBounds(true); |
3321 | 3324 |
3322 // Rotates about the center of the layer | 3325 // Rotates about the center of the layer |
3323 gfx::Transform rotatedLeafTransform; | 3326 gfx::Transform rotatedLeafTransform; |
3324 rotatedLeafTransform.Translate(-10, -10); // cancel out the grandParent'
s position | 3327 rotatedLeafTransform.Translate(-10, -10); // cancel out the grandParent'
s position |
3325 MathUtil::rotateEulerAngles(&rotatedLeafTransform, 0, 0, -45); // cancel
out the corner 45-degree rotation of the parent. | 3328 rotatedLeafTransform.RotateAboutZAxis(-45); // cancel out the corner 45-
degree rotation of the parent. |
3326 rotatedLeafTransform.Translate(50, 50); | 3329 rotatedLeafTransform.Translate(50, 50); |
3327 MathUtil::rotateEulerAngles(&rotatedLeafTransform, 0, 0, 45); | 3330 rotatedLeafTransform.RotateAboutZAxis(45); |
3328 rotatedLeafTransform.Translate(-50, -50); | 3331 rotatedLeafTransform.Translate(-50, -50); |
3329 position = gfx::PointF(0, 0); | 3332 position = gfx::PointF(0, 0); |
3330 bounds = gfx::Size(100, 100); | 3333 bounds = gfx::Size(100, 100); |
3331 setLayerPropertiesForTesting(rotatedLeaf.get(), rotatedLeafTransform, id
entityMatrix, anchor, position, bounds, false); | 3334 setLayerPropertiesForTesting(rotatedLeaf.get(), rotatedLeafTransform, id
entityMatrix, anchor, position, bounds, false); |
3332 rotatedLeaf->setDrawsContent(true); | 3335 rotatedLeaf->setDrawsContent(true); |
3333 | 3336 |
3334 grandChild->addChild(rotatedLeaf.Pass()); | 3337 grandChild->addChild(rotatedLeaf.Pass()); |
3335 child->addChild(grandChild.Pass()); | 3338 child->addChild(grandChild.Pass()); |
3336 root->addChild(child.Pass()); | 3339 root->addChild(child.Pass()); |
3337 } | 3340 } |
(...skipping 1654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4992 EXPECT_EQ(m_canUseLCDText, m_grandChild->canUseLCDText()); | 4995 EXPECT_EQ(m_canUseLCDText, m_grandChild->canUseLCDText()); |
4993 } | 4996 } |
4994 | 4997 |
4995 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, | 4998 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, |
4996 LCDTextTest, | 4999 LCDTextTest, |
4997 testing::Combine(testing::Bool(), | 5000 testing::Combine(testing::Bool(), |
4998 testing::Bool())); | 5001 testing::Bool())); |
4999 | 5002 |
5000 } // namespace | 5003 } // namespace |
5001 } // namespace cc | 5004 } // namespace cc |
OLD | NEW |