Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(806)

Side by Side Diff: cc/layer_tree_host_common_unittest.cc

Issue 11774005: Migrate more functions from MathUtil to gfx::Transform (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "cc/layer_impl.h" 11 #include "cc/layer_impl.h"
12 #include "cc/math_util.h" 12 #include "cc/math_util.h"
13 #include "cc/proxy.h" 13 #include "cc/proxy.h"
14 #include "cc/single_thread_proxy.h" 14 #include "cc/single_thread_proxy.h"
15 #include "cc/test/animation_test_common.h" 15 #include "cc/test/animation_test_common.h"
16 #include "cc/test/fake_impl_proxy.h" 16 #include "cc/test/fake_impl_proxy.h"
17 #include "cc/test/fake_layer_tree_host_impl.h" 17 #include "cc/test/fake_layer_tree_host_impl.h"
18 #include "cc/test/geometry_test_utils.h" 18 #include "cc/test/geometry_test_utils.h"
19 #include "cc/thread.h" 19 #include "cc/thread.h"
20 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
21 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
22 #include "ui/gfx/quad_f.h" 22 #include "ui/gfx/quad_f.h"
23 #include "ui/gfx/size_conversions.h" 23 #include "ui/gfx/size_conversions.h"
24 #include "ui/gfx/transform.h" 24 #include "ui/gfx/transform.h"
25 #include "ui/gfx/transform_util.h"
25 26
26 namespace cc { 27 namespace cc {
27 namespace { 28 namespace {
28 29
29 template<typename LayerType> 30 template<typename LayerType>
30 void setLayerPropertiesForTestingInternal(LayerType* layer, const gfx::Transform & transform, const gfx::Transform& sublayerTransform, const gfx::PointF& anchor, const gfx::PointF& position, const gfx::Size& bounds, bool preserves3D) 31 void setLayerPropertiesForTestingInternal(LayerType* layer, const gfx::Transform & transform, const gfx::Transform& sublayerTransform, const gfx::PointF& anchor, const gfx::PointF& position, const gfx::Size& bounds, bool preserves3D)
31 { 32 {
32 layer->setTransform(transform); 33 layer->setTransform(transform);
33 layer->setSublayerTransform(sublayerTransform); 34 layer->setSublayerTransform(sublayerTransform);
34 layer->setAnchorPoint(anchor); 35 layer->setAnchorPoint(anchor);
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 // scaling is used here again so that the correct sequence of transf orms is properly tested. 281 // 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. 282 // 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. 283 // 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; 284 gfx::Transform parentSublayerMatrix;
284 parentSublayerMatrix.Scale3d(10, 10, 3.3); 285 parentSublayerMatrix.Scale3d(10, 10, 3.3);
285 gfx::Transform parentTranslationToCenter; 286 gfx::Transform parentTranslationToCenter;
286 parentTranslationToCenter.Translate(5, 6); 287 parentTranslationToCenter.Translate(5, 6);
287 // Sublayer matrix is applied to the center of the parent layer. 288 // Sublayer matrix is applied to the center of the parent layer.
288 parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform * inverse(parentTranslationToAnchor) 289 parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform * inverse(parentTranslationToAnchor)
289 * parentTranslationToCenter * parentSublayerMatrix * inverse(parentT ranslationToCenter); 290 * parentTranslationToCenter * parentSublayerMatrix * inverse(parentT ranslationToCenter);
290 gfx::Transform flattenedCompositeTransform = MathUtil::to2dTransform(parentC ompositeTransform); 291 gfx::Transform flattenedCompositeTransform = gfx::CreateFlattenedTransform(p arentCompositeTransform);
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
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 expectedGrandChildScreenSpaceTransform = gfx::CreateFlattened Transform(rotationAboutYAxis) * rotationAboutYAxis;
639 640
640 executeCalculateDrawProperties(root.get()); 641 executeCalculateDrawProperties(root.get());
641 642
642 // The child's drawTransform should have been taken by its surface. 643 // The child's drawTransform should have been taken by its surface.
643 ASSERT_TRUE(child->renderSurface()); 644 ASSERT_TRUE(child->renderSurface());
644 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildDrawTransform, child->renderSur face()->drawTransform()); 645 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildDrawTransform, child->renderSur face()->drawTransform());
645 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildScreenSpaceTransform, child->re nderSurface()->screenSpaceTransform()); 646 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildScreenSpaceTransform, child->re nderSurface()->screenSpaceTransform());
646 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform()); 647 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform());
647 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildScreenSpaceTransform, child->sc reenSpaceTransform()); 648 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildScreenSpaceTransform, child->sc reenSpaceTransform());
648 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildDrawTransform, grandChild- >drawTransform()); 649 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildDrawTransform, grandChild- >drawTransform());
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 // is NOT the direct parent of the fixed-position layer, and the hierarchy h as various 905 // 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. 906 // transforms that have to be processed in the correct order.
906 FakeImplProxy proxy; 907 FakeImplProxy proxy;
907 FakeLayerTreeHostImpl hostImpl(&proxy); 908 FakeLayerTreeHostImpl hostImpl(&proxy);
908 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(&hostImpl); 909 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(&hostImpl);
909 LayerImpl* child = root->children()[0]; 910 LayerImpl* child = root->children()[0];
910 LayerImpl* grandChild = child->children()[0]; 911 LayerImpl* grandChild = child->children()[0];
911 LayerImpl* greatGrandChild = grandChild->children()[0]; 912 LayerImpl* greatGrandChild = grandChild->children()[0];
912 913
913 gfx::Transform rotationAboutZ; 914 gfx::Transform rotationAboutZ;
914 MathUtil::rotateEulerAngles(&rotationAboutZ, 0, 0, 90); 915 rotationAboutZ.RotateAboutZAxis(90);
915 916
916 child->setIsContainerForFixedPositionLayers(true); 917 child->setIsContainerForFixedPositionLayers(true);
917 child->setTransform(rotationAboutZ); 918 child->setTransform(rotationAboutZ);
918 grandChild->setPosition(gfx::PointF(8, 6)); 919 grandChild->setPosition(gfx::PointF(8, 6));
919 grandChild->setTransform(rotationAboutZ); 920 grandChild->setTransform(rotationAboutZ);
920 greatGrandChild->setFixedToContainerLayer(true); // greatGrandChild is posit ioned upside-down with respect to the renderTarget. 921 greatGrandChild->setFixedToContainerLayer(true); // greatGrandChild is posit ioned upside-down with respect to the renderTarget.
921 922
922 // Case 1: scrollDelta of 0, 0 923 // Case 1: scrollDelta of 0, 0
923 child->setScrollDelta(gfx::Vector2d(0, 0)); 924 child->setScrollDelta(gfx::Vector2d(0, 0));
924 executeCalculateDrawProperties(root.get()); 925 executeCalculateDrawProperties(root.get());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
966 // is NOT the direct parent of the fixed-position layer, and the hierarchy h as various 967 // 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. 968 // transforms that have to be processed in the correct order.
968 FakeImplProxy proxy; 969 FakeImplProxy proxy;
969 FakeLayerTreeHostImpl hostImpl(&proxy); 970 FakeLayerTreeHostImpl hostImpl(&proxy);
970 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(&hostImpl); 971 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(&hostImpl);
971 LayerImpl* child = root->children()[0]; 972 LayerImpl* child = root->children()[0];
972 LayerImpl* grandChild = child->children()[0]; 973 LayerImpl* grandChild = child->children()[0];
973 LayerImpl* greatGrandChild = grandChild->children()[0]; 974 LayerImpl* greatGrandChild = grandChild->children()[0];
974 975
975 gfx::Transform rotationAboutZ; 976 gfx::Transform rotationAboutZ;
976 MathUtil::rotateEulerAngles(&rotationAboutZ, 0, 0, 90); 977 rotationAboutZ.RotateAboutZAxis(90);
977 978
978 child->setIsContainerForFixedPositionLayers(true); 979 child->setIsContainerForFixedPositionLayers(true);
979 child->setTransform(rotationAboutZ); 980 child->setTransform(rotationAboutZ);
980 grandChild->setPosition(gfx::PointF(8, 6)); 981 grandChild->setPosition(gfx::PointF(8, 6));
981 grandChild->setTransform(rotationAboutZ); 982 grandChild->setTransform(rotationAboutZ);
982 greatGrandChild->setFixedToContainerLayer(true); // greatGrandChild is posit ioned upside-down with respect to the renderTarget. 983 greatGrandChild->setFixedToContainerLayer(true); // greatGrandChild is posit ioned upside-down with respect to the renderTarget.
983 984
984 // Case 1: scrollDelta of 0, 0 985 // Case 1: scrollDelta of 0, 0
985 child->setScrollDelta(gfx::Vector2d(0, 0)); 986 child->setScrollDelta(gfx::Vector2d(0, 0));
986 executeCalculateDrawProperties(root.get()); 987 executeCalculateDrawProperties(root.get());
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1034 LayerImpl* grandChild = child->children()[0]; 1035 LayerImpl* grandChild = child->children()[0];
1035 LayerImpl* greatGrandChild = grandChild->children()[0]; 1036 LayerImpl* greatGrandChild = grandChild->children()[0];
1036 1037
1037 child->setIsContainerForFixedPositionLayers(true); 1038 child->setIsContainerForFixedPositionLayers(true);
1038 grandChild->setPosition(gfx::PointF(8, 6)); 1039 grandChild->setPosition(gfx::PointF(8, 6));
1039 grandChild->setForceRenderSurface(true); 1040 grandChild->setForceRenderSurface(true);
1040 greatGrandChild->setFixedToContainerLayer(true); 1041 greatGrandChild->setFixedToContainerLayer(true);
1041 greatGrandChild->setDrawsContent(true); 1042 greatGrandChild->setDrawsContent(true);
1042 1043
1043 gfx::Transform rotationAboutZ; 1044 gfx::Transform rotationAboutZ;
1044 MathUtil::rotateEulerAngles(&rotationAboutZ, 0, 0, 90); 1045 rotationAboutZ.RotateAboutZAxis(90);
1045 grandChild->setTransform(rotationAboutZ); 1046 grandChild->setTransform(rotationAboutZ);
1046 1047
1047 // Case 1: scrollDelta of 0, 0 1048 // Case 1: scrollDelta of 0, 0
1048 child->setScrollDelta(gfx::Vector2d(0, 0)); 1049 child->setScrollDelta(gfx::Vector2d(0, 0));
1049 executeCalculateDrawProperties(root.get()); 1050 executeCalculateDrawProperties(root.get());
1050 1051
1051 gfx::Transform expectedChildTransform; 1052 gfx::Transform expectedChildTransform;
1052 gfx::Transform expectedSurfaceDrawTransform; 1053 gfx::Transform expectedSurfaceDrawTransform;
1053 expectedSurfaceDrawTransform.Translate(8, 6); 1054 expectedSurfaceDrawTransform.Translate(8, 6);
1054 expectedSurfaceDrawTransform.PreconcatTransform(rotationAboutZ); 1055 expectedSurfaceDrawTransform.PreconcatTransform(rotationAboutZ);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1124 greatGrandChild->setForceRenderSurface(true); 1125 greatGrandChild->setForceRenderSurface(true);
1125 fixedPositionChild->setFixedToContainerLayer(true); 1126 fixedPositionChild->setFixedToContainerLayer(true);
1126 fixedPositionChild->setDrawsContent(true); 1127 fixedPositionChild->setDrawsContent(true);
1127 1128
1128 // The additional rotations, which are non-commutative with translations, he lp to 1129 // 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. 1130 // 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 1131 // Note that rotating about the center of the layer ensures we do not accide ntally
1131 // clip away layers that we want to test. 1132 // clip away layers that we want to test.
1132 gfx::Transform rotationAboutZ; 1133 gfx::Transform rotationAboutZ;
1133 rotationAboutZ.Translate(50, 50); 1134 rotationAboutZ.Translate(50, 50);
1134 MathUtil::rotateEulerAngles(&rotationAboutZ, 0, 0, 90); 1135 rotationAboutZ.RotateAboutZAxis(90);
1135 rotationAboutZ.Translate(-50, -50); 1136 rotationAboutZ.Translate(-50, -50);
1136 grandChild->setTransform(rotationAboutZ); 1137 grandChild->setTransform(rotationAboutZ);
1137 greatGrandChild->setTransform(rotationAboutZ); 1138 greatGrandChild->setTransform(rotationAboutZ);
1138 1139
1139 // Case 1: scrollDelta of 0, 0 1140 // Case 1: scrollDelta of 0, 0
1140 child->setScrollDelta(gfx::Vector2d(0, 0)); 1141 child->setScrollDelta(gfx::Vector2d(0, 0));
1141 executeCalculateDrawProperties(root.get()); 1142 executeCalculateDrawProperties(root.get());
1142 1143
1143 gfx::Transform expectedChildTransform; 1144 gfx::Transform expectedChildTransform;
1144 1145
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
1295 // This test checks scroll compensation when a fixed-position layer does not find any 1296 // 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 1297 // 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. 1298 // be fixed to the viewport -- not the rootLayer, which may have transforms of its own.
1298 FakeImplProxy proxy; 1299 FakeImplProxy proxy;
1299 FakeLayerTreeHostImpl hostImpl(&proxy); 1300 FakeLayerTreeHostImpl hostImpl(&proxy);
1300 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(&hostImpl); 1301 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(&hostImpl);
1301 LayerImpl* child = root->children()[0]; 1302 LayerImpl* child = root->children()[0];
1302 LayerImpl* grandChild = child->children()[0]; 1303 LayerImpl* grandChild = child->children()[0];
1303 1304
1304 gfx::Transform rotationByZ; 1305 gfx::Transform rotationByZ;
1305 MathUtil::rotateEulerAngles(&rotationByZ, 0, 0, 90); 1306 rotationByZ.RotateAboutZAxis(90);
1306 1307
1307 root->setTransform(rotationByZ); 1308 root->setTransform(rotationByZ);
1308 grandChild->setFixedToContainerLayer(true); 1309 grandChild->setFixedToContainerLayer(true);
1309 1310
1310 // Case 1: root scrollDelta of 0, 0 1311 // Case 1: root scrollDelta of 0, 0
1311 root->setScrollDelta(gfx::Vector2d(0, 0)); 1312 root->setScrollDelta(gfx::Vector2d(0, 0));
1312 executeCalculateDrawProperties(root.get()); 1313 executeCalculateDrawProperties(root.get());
1313 1314
1314 gfx::Transform identityMatrix; 1315 gfx::Transform identityMatrix;
1315 1316
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after
1922 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor3dOrthographicTransform) 1923 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor3dOrthographicTransform)
1923 { 1924 {
1924 // Test that the calculateVisibleRect() function works correctly for 3d tran sforms. 1925 // Test that the calculateVisibleRect() function works correctly for 3d tran sforms.
1925 1926
1926 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100 )); 1927 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) ); 1928 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100) );
1928 gfx::Transform layerToSurfaceTransform; 1929 gfx::Transform layerToSurfaceTransform;
1929 1930
1930 // Case 1: Orthographic projection of a layer rotated about y-axis by 45 deg rees, should be fully contained in the renderSurface. 1931 // 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(); 1932 layerToSurfaceTransform.MakeIdentity();
1932 MathUtil::rotateEulerAngles(&layerToSurfaceTransform, 0, 45, 0); 1933 layerToSurfaceTransform.RotateAboutYAxis(45);
1933 gfx::Rect expected = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100)); 1934 gfx::Rect expected = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100));
1934 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe ct, layerContentRect, layerToSurfaceTransform); 1935 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe ct, layerContentRect, layerToSurfaceTransform);
1935 EXPECT_RECT_EQ(expected, actual); 1936 EXPECT_RECT_EQ(expected, actual);
1936 1937
1937 // Case 2: Orthographic projection of a layer rotated about y-axis by 45 deg rees, but 1938 // 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 1939 // shifted to the side so only the right-half the layer would be vis ible on
1939 // the surface. 1940 // 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. 1941 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(); 1942 layerToSurfaceTransform.MakeIdentity();
1942 layerToSurfaceTransform.Translate(-halfWidthOfRotatedLayer, 0); 1943 layerToSurfaceTransform.Translate(-halfWidthOfRotatedLayer, 0);
1943 MathUtil::rotateEulerAngles(&layerToSurfaceTransform, 0, 45, 0); // rotates about the left edge of the layer 1944 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. 1945 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); 1946 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform);
1946 EXPECT_RECT_EQ(expected, actual); 1947 EXPECT_RECT_EQ(expected, actual);
1947 } 1948 }
1948 1949
1949 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor3dPerspectiveTransform) 1950 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor3dPerspectiveTransform)
1950 { 1951 {
1951 // Test the calculateVisibleRect() function works correctly when the layer h as a 1952 // Test the calculateVisibleRect() function works correctly when the layer h as a
1952 // perspective projection onto the target surface. 1953 // perspective projection onto the target surface.
1953 1954
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1994 // flattened to the surface. 1995 // flattened to the surface.
1995 1996
1996 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100 )); 1997 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) ); 1998 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100) );
1998 gfx::Transform layerToSurfaceTransform; 1999 gfx::Transform layerToSurfaceTransform;
1999 2000
2000 // This sequence of transforms effectively rotates the layer about the y-axi s at the 2001 // This sequence of transforms effectively rotates the layer about the y-axi s at the
2001 // center of the layer. 2002 // center of the layer.
2002 layerToSurfaceTransform.MakeIdentity(); 2003 layerToSurfaceTransform.MakeIdentity();
2003 layerToSurfaceTransform.Translate(50, 0); 2004 layerToSurfaceTransform.Translate(50, 0);
2004 MathUtil::rotateEulerAngles(&layerToSurfaceTransform, 0, 45, 0); 2005 layerToSurfaceTransform.RotateAboutYAxis(45);
2005 layerToSurfaceTransform.Translate(-50, 0); 2006 layerToSurfaceTransform.Translate(-50, 0);
2006 2007
2007 gfx::Rect expected = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100)); 2008 gfx::Rect expected = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100));
2008 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe ct, layerContentRect, layerToSurfaceTransform); 2009 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe ct, layerContentRect, layerToSurfaceTransform);
2009 EXPECT_RECT_EQ(expected, actual); 2010 EXPECT_RECT_EQ(expected, actual);
2010 } 2011 }
2011 2012
2012 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor3dPerspectiveWhenClippedByW) 2013 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor3dPerspectiveWhenClippedByW)
2013 { 2014 {
2014 // Test the calculateVisibleRect() function works correctly when projecting a surface 2015 // 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 2016 // 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, 2017 // 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 2018 // 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. 2019 // w = 0 plane in homogeneous coordinates before converting to cartesian coo rdinates.
2019 2020
2020 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(-50, -50), gfx::Size(100, 100)); 2021 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) ); 2022 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(-10, -1), gfx::Size(20, 2) );
2022 gfx::Transform layerToSurfaceTransform; 2023 gfx::Transform layerToSurfaceTransform;
2023 2024
2024 // The layer is positioned so that the right half of the layer should be in front of 2025 // 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 2026 // 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 2027 // following sequence of transforms applies the perspective and rotation abo ut the
2027 // center of the layer. 2028 // center of the layer.
2028 layerToSurfaceTransform.MakeIdentity(); 2029 layerToSurfaceTransform.MakeIdentity();
2029 layerToSurfaceTransform.ApplyPerspectiveDepth(1); 2030 layerToSurfaceTransform.ApplyPerspectiveDepth(1);
2030 layerToSurfaceTransform.Translate3d(-2, 0, 1); 2031 layerToSurfaceTransform.Translate3d(-2, 0, 1);
2031 MathUtil::rotateEulerAngles(&layerToSurfaceTransform, 0, 45, 0); 2032 layerToSurfaceTransform.RotateAboutYAxis(45);
2032 2033
2033 // Sanity check that this transform does indeed cause w < 0 when applying th e 2034 // 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. 2035 // transform, otherwise this code is not testing the intended scenario.
2035 bool clipped = false; 2036 bool clipped = false;
2036 MathUtil::mapQuad(layerToSurfaceTransform, gfx::QuadF(gfx::RectF(layerConten tRect)), clipped); 2037 MathUtil::mapQuad(layerToSurfaceTransform, gfx::QuadF(gfx::RectF(layerConten tRect)), clipped);
2037 ASSERT_TRUE(clipped); 2038 ASSERT_TRUE(clipped);
2038 2039
2039 int expectedXPosition = 0; 2040 int expectedXPosition = 0;
2040 int expectedWidth = 10; 2041 int expectedWidth = 10;
2041 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe ct, layerContentRect, layerToSurfaceTransform); 2042 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe ct, layerContentRect, layerToSurfaceTransform);
2042 EXPECT_EQ(expectedXPosition, actual.x()); 2043 EXPECT_EQ(expectedXPosition, actual.x());
2043 EXPECT_EQ(expectedWidth, actual.width()); 2044 EXPECT_EQ(expectedWidth, actual.width());
2044 } 2045 }
2045 2046
2046 TEST(LayerTreeHostCommonTest, verifyVisibleRectForPerspectiveUnprojection) 2047 TEST(LayerTreeHostCommonTest, verifyVisibleRectForPerspectiveUnprojection)
2047 { 2048 {
2048 // To determine visibleRect in layer space, there needs to be an un-projecti on from 2049 // 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 2050 // 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. 2051 // projection that was clipped, it returns a rect that encloses the clipped bounds.
2051 // Un-projecting this new rect may require clipping again. 2052 // Un-projecting this new rect may require clipping again.
2052 2053
2053 // This sequence of transforms causes one corner of the layer to protrude ac ross the w = 0 plane, and should be clipped. 2054 // 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)); 2055 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)); 2056 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(-10, -10), gfx::Size(20, 2 0));
2056 gfx::Transform layerToSurfaceTransform; 2057 gfx::Transform layerToSurfaceTransform;
2057 layerToSurfaceTransform.MakeIdentity(); 2058 layerToSurfaceTransform.MakeIdentity();
2058 layerToSurfaceTransform.ApplyPerspectiveDepth(1); 2059 layerToSurfaceTransform.ApplyPerspectiveDepth(1);
2059 layerToSurfaceTransform.Translate3d(0, 0, -5); 2060 layerToSurfaceTransform.Translate3d(0, 0, -5);
2060 MathUtil::rotateEulerAngles(&layerToSurfaceTransform, 0, 45, 0); 2061 layerToSurfaceTransform.RotateAboutYAxis(45);
2061 MathUtil::rotateEulerAngles(&layerToSurfaceTransform, 80, 0, 0); 2062 layerToSurfaceTransform.RotateAboutXAxis(80);
2062 2063
2063 // Sanity check that un-projection does indeed cause w < 0, otherwise this c ode is not 2064 // Sanity check that un-projection does indeed cause w < 0, otherwise this c ode is not
2064 // testing the intended scenario. 2065 // testing the intended scenario.
2065 bool clipped = false; 2066 bool clipped = false;
2066 gfx::RectF clippedRect = MathUtil::mapClippedRect(layerToSurfaceTransform, l ayerContentRect); 2067 gfx::RectF clippedRect = MathUtil::mapClippedRect(layerToSurfaceTransform, l ayerContentRect);
2067 MathUtil::projectQuad(inverse(layerToSurfaceTransform), gfx::QuadF(clippedRe ct), clipped); 2068 MathUtil::projectQuad(inverse(layerToSurfaceTransform), gfx::QuadF(clippedRe ct), clipped);
2068 ASSERT_TRUE(clipped); 2069 ASSERT_TRUE(clipped);
2069 2070
2070 // Only the corner of the layer is not visible on the surface because of bei ng 2071 // 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 2072 // 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
2929 2930
2930 TEST(LayerTreeHostCommonTest, verifyHitTestingForSingleRotatedLayer) 2931 TEST(LayerTreeHostCommonTest, verifyHitTestingForSingleRotatedLayer)
2931 { 2932 {
2932 FakeImplProxy proxy; 2933 FakeImplProxy proxy;
2933 FakeLayerTreeHostImpl hostImpl(&proxy); 2934 FakeLayerTreeHostImpl hostImpl(&proxy);
2934 scoped_ptr<LayerImpl> root = LayerImpl::create(hostImpl.activeTree(), 12345) ; 2935 scoped_ptr<LayerImpl> root = LayerImpl::create(hostImpl.activeTree(), 12345) ;
2935 2936
2936 gfx::Transform identityMatrix; 2937 gfx::Transform identityMatrix;
2937 gfx::Transform rotation45DegreesAboutCenter; 2938 gfx::Transform rotation45DegreesAboutCenter;
2938 rotation45DegreesAboutCenter.Translate(50, 50); 2939 rotation45DegreesAboutCenter.Translate(50, 50);
2939 MathUtil::rotateEulerAngles(&rotation45DegreesAboutCenter, 0, 0, 45); 2940 rotation45DegreesAboutCenter.RotateAboutZAxis(45);
2940 rotation45DegreesAboutCenter.Translate(-50, -50); 2941 rotation45DegreesAboutCenter.Translate(-50, -50);
2941 gfx::PointF anchor(0, 0); 2942 gfx::PointF anchor(0, 0);
2942 gfx::PointF position(0, 0); 2943 gfx::PointF position(0, 0);
2943 gfx::Size bounds(100, 100); 2944 gfx::Size bounds(100, 100);
2944 setLayerPropertiesForTesting(root.get(), rotation45DegreesAboutCenter, ident ityMatrix, anchor, position, bounds, false); 2945 setLayerPropertiesForTesting(root.get(), rotation45DegreesAboutCenter, ident ityMatrix, anchor, position, bounds, false);
2945 root->setDrawsContent(true); 2946 root->setDrawsContent(true);
2946 2947
2947 std::vector<LayerImpl*> renderSurfaceLayerList; 2948 std::vector<LayerImpl*> renderSurfaceLayerList;
2948 int dummyMaxTextureSize = 512; 2949 int dummyMaxTextureSize = 512;
2949 LayerTreeHostCommon::calculateDrawProperties(root.get(), root->bounds(), 1, 1, dummyMaxTextureSize, false, renderSurfaceLayerList); 2950 LayerTreeHostCommon::calculateDrawProperties(root.get(), root->bounds(), 1, 1, dummyMaxTextureSize, false, renderSurfaceLayerList);
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
3188 scoped_ptr<LayerImpl> child = LayerImpl::create(hostImpl.activeTree(), 4 56); 3189 scoped_ptr<LayerImpl> child = LayerImpl::create(hostImpl.activeTree(), 4 56);
3189 scoped_ptr<LayerImpl> grandChild = LayerImpl::create(hostImpl.activeTree (), 789); 3190 scoped_ptr<LayerImpl> grandChild = LayerImpl::create(hostImpl.activeTree (), 789);
3190 scoped_ptr<LayerImpl> rotatedLeaf = LayerImpl::create(hostImpl.activeTre e(), 2468); 3191 scoped_ptr<LayerImpl> rotatedLeaf = LayerImpl::create(hostImpl.activeTre e(), 2468);
3191 3192
3192 position = gfx::PointF(10, 10); 3193 position = gfx::PointF(10, 10);
3193 bounds = gfx::Size(80, 80); 3194 bounds = gfx::Size(80, 80);
3194 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix , anchor, position, bounds, false); 3195 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix , anchor, position, bounds, false);
3195 child->setMasksToBounds(true); 3196 child->setMasksToBounds(true);
3196 3197
3197 gfx::Transform rotation45DegreesAboutCorner; 3198 gfx::Transform rotation45DegreesAboutCorner;
3198 MathUtil::rotateEulerAngles(&rotation45DegreesAboutCorner, 0, 0, 45); 3199 rotation45DegreesAboutCorner.RotateAboutZAxis(45);
3199 3200
3200 position = gfx::PointF(0, 0); // remember, positioned with respect to it s parent which is already at 10, 10 3201 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. 3202 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); 3203 setLayerPropertiesForTesting(grandChild.get(), rotation45DegreesAboutCor ner, identityMatrix, anchor, position, bounds, false);
3203 grandChild->setMasksToBounds(true); 3204 grandChild->setMasksToBounds(true);
3204 3205
3205 // Rotates about the center of the layer 3206 // Rotates about the center of the layer
3206 gfx::Transform rotatedLeafTransform; 3207 gfx::Transform rotatedLeafTransform;
3207 rotatedLeafTransform.Translate(-10, -10); // cancel out the grandParent' s position 3208 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. 3209 rotatedLeafTransform.RotateAboutZAxis(-45); // cancel out the corner 45- degree rotation of the parent.
3209 rotatedLeafTransform.Translate(50, 50); 3210 rotatedLeafTransform.Translate(50, 50);
3210 MathUtil::rotateEulerAngles(&rotatedLeafTransform, 0, 0, 45); 3211 rotatedLeafTransform.RotateAboutZAxis(45);
3211 rotatedLeafTransform.Translate(-50, -50); 3212 rotatedLeafTransform.Translate(-50, -50);
3212 position = gfx::PointF(0, 0); 3213 position = gfx::PointF(0, 0);
3213 bounds = gfx::Size(100, 100); 3214 bounds = gfx::Size(100, 100);
3214 setLayerPropertiesForTesting(rotatedLeaf.get(), rotatedLeafTransform, id entityMatrix, anchor, position, bounds, false); 3215 setLayerPropertiesForTesting(rotatedLeaf.get(), rotatedLeafTransform, id entityMatrix, anchor, position, bounds, false);
3215 rotatedLeaf->setDrawsContent(true); 3216 rotatedLeaf->setDrawsContent(true);
3216 3217
3217 grandChild->addChild(rotatedLeaf.Pass()); 3218 grandChild->addChild(rotatedLeaf.Pass());
3218 child->addChild(grandChild.Pass()); 3219 child->addChild(grandChild.Pass());
3219 root->addChild(child.Pass()); 3220 root->addChild(child.Pass());
3220 } 3221 }
(...skipping 1654 matching lines...) Expand 10 before | Expand all | Expand 10 after
4875 EXPECT_EQ(m_canUseLCDText, m_grandChild->canUseLCDText()); 4876 EXPECT_EQ(m_canUseLCDText, m_grandChild->canUseLCDText());
4876 } 4877 }
4877 4878
4878 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, 4879 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest,
4879 LCDTextTest, 4880 LCDTextTest,
4880 testing::Combine(testing::Bool(), 4881 testing::Combine(testing::Bool(),
4881 testing::Bool())); 4882 testing::Bool()));
4882 4883
4883 } // namespace 4884 } // namespace
4884 } // namespace cc 4885 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698