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/trees/layer_tree_host_common.h" | 5 #include "cc/trees/layer_tree_host_common.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "cc/animation/layer_animation_controller.h" | 10 #include "cc/animation/layer_animation_controller.h" |
(...skipping 988 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
999 TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) { | 999 TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) { |
1000 // For layers that flatten their subtree, there should be an orthographic | 1000 // For layers that flatten their subtree, there should be an orthographic |
1001 // projection (for x and y values) in the middle of the transform sequence. | 1001 // projection (for x and y values) in the middle of the transform sequence. |
1002 // Note that the way the code is currently implemented, it is not expected to | 1002 // Note that the way the code is currently implemented, it is not expected to |
1003 // use a canonical orthographic projection. | 1003 // use a canonical orthographic projection. |
1004 | 1004 |
1005 scoped_refptr<Layer> root = Layer::Create(); | 1005 scoped_refptr<Layer> root = Layer::Create(); |
1006 scoped_refptr<Layer> child = Layer::Create(); | 1006 scoped_refptr<Layer> child = Layer::Create(); |
1007 scoped_refptr<LayerWithForcedDrawsContent> grand_child = | 1007 scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
1008 make_scoped_refptr(new LayerWithForcedDrawsContent()); | 1008 make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1009 scoped_refptr<LayerWithForcedDrawsContent> great_grand_child = |
| 1010 make_scoped_refptr(new LayerWithForcedDrawsContent()); |
1009 | 1011 |
1010 gfx::Transform rotation_about_y_axis; | 1012 gfx::Transform rotation_about_y_axis; |
1011 rotation_about_y_axis.RotateAboutYAxis(30.0); | 1013 rotation_about_y_axis.RotateAboutYAxis(30.0); |
1012 | 1014 |
1013 const gfx::Transform identity_matrix; | 1015 const gfx::Transform identity_matrix; |
1014 SetLayerPropertiesForTesting(root.get(), | 1016 SetLayerPropertiesForTesting(root.get(), |
1015 identity_matrix, | 1017 identity_matrix, |
1016 gfx::Point3F(), | 1018 gfx::Point3F(), |
1017 gfx::PointF(), | 1019 gfx::PointF(), |
1018 gfx::Size(100, 100), | 1020 gfx::Size(100, 100), |
1019 true, | 1021 true, |
1020 false); | 1022 false); |
1021 SetLayerPropertiesForTesting(child.get(), | 1023 SetLayerPropertiesForTesting(child.get(), |
1022 rotation_about_y_axis, | 1024 rotation_about_y_axis, |
1023 gfx::Point3F(), | 1025 gfx::Point3F(), |
1024 gfx::PointF(), | 1026 gfx::PointF(), |
1025 gfx::Size(10, 10), | 1027 gfx::Size(10, 10), |
1026 true, | 1028 true, |
1027 false); | 1029 false); |
1028 SetLayerPropertiesForTesting(grand_child.get(), | 1030 SetLayerPropertiesForTesting(grand_child.get(), |
1029 rotation_about_y_axis, | 1031 rotation_about_y_axis, |
1030 gfx::Point3F(), | 1032 gfx::Point3F(), |
1031 gfx::PointF(), | 1033 gfx::PointF(), |
1032 gfx::Size(10, 10), | 1034 gfx::Size(10, 10), |
1033 true, | 1035 true, |
1034 false); | 1036 false); |
| 1037 SetLayerPropertiesForTesting(great_grand_child.get(), identity_matrix, |
| 1038 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), |
| 1039 true, false); |
1035 | 1040 |
1036 root->AddChild(child); | 1041 root->AddChild(child); |
1037 child->AddChild(grand_child); | 1042 child->AddChild(grand_child); |
| 1043 grand_child->AddChild(great_grand_child); |
1038 child->SetForceRenderSurface(true); | 1044 child->SetForceRenderSurface(true); |
1039 | 1045 |
1040 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | 1046 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
1041 host->SetRootLayer(root); | 1047 host->SetRootLayer(root); |
1042 | 1048 |
1043 // No layers in this test should preserve 3d. | 1049 // No layers in this test should preserve 3d. |
1044 ASSERT_TRUE(root->should_flatten_transform()); | 1050 ASSERT_TRUE(root->should_flatten_transform()); |
1045 ASSERT_TRUE(child->should_flatten_transform()); | 1051 ASSERT_TRUE(child->should_flatten_transform()); |
1046 ASSERT_TRUE(grand_child->should_flatten_transform()); | 1052 ASSERT_TRUE(grand_child->should_flatten_transform()); |
| 1053 ASSERT_TRUE(great_grand_child->should_flatten_transform()); |
1047 | 1054 |
1048 gfx::Transform expected_child_draw_transform = rotation_about_y_axis; | 1055 gfx::Transform expected_child_draw_transform = rotation_about_y_axis; |
1049 gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis; | 1056 gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis; |
1050 gfx::Transform expected_grand_child_draw_transform = | 1057 gfx::Transform expected_grand_child_draw_transform = |
1051 rotation_about_y_axis; // draws onto child's render surface | 1058 rotation_about_y_axis; // draws onto child's render surface |
1052 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis; | 1059 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis; |
1053 flattened_rotation_about_y.FlattenTo2d(); | 1060 flattened_rotation_about_y.FlattenTo2d(); |
1054 gfx::Transform expected_grand_child_screen_space_transform = | 1061 gfx::Transform expected_grand_child_screen_space_transform = |
1055 flattened_rotation_about_y * rotation_about_y_axis; | 1062 flattened_rotation_about_y * rotation_about_y_axis; |
| 1063 gfx::Transform expected_great_grand_child_draw_transform = |
| 1064 flattened_rotation_about_y; |
| 1065 gfx::Transform expected_great_grand_child_screen_space_transform = |
| 1066 flattened_rotation_about_y * flattened_rotation_about_y; |
1056 | 1067 |
1057 ExecuteCalculateDrawProperties(root.get()); | 1068 ExecuteCalculateDrawProperties(root.get()); |
1058 | 1069 |
1059 // The child's draw transform should have been taken by its surface. | 1070 // The child's draw transform should have been taken by its surface. |
1060 ASSERT_TRUE(child->render_surface()); | 1071 ASSERT_TRUE(child->render_surface()); |
1061 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform, | 1072 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform, |
1062 child->render_surface()->draw_transform()); | 1073 child->render_surface()->draw_transform()); |
1063 EXPECT_TRANSFORMATION_MATRIX_EQ( | 1074 EXPECT_TRANSFORMATION_MATRIX_EQ( |
1064 expected_child_screen_space_transform, | 1075 expected_child_screen_space_transform, |
1065 child->render_surface()->screen_space_transform()); | 1076 child->render_surface()->screen_space_transform()); |
1066 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); | 1077 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); |
1067 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform, | 1078 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform, |
1068 child->screen_space_transform()); | 1079 child->screen_space_transform()); |
1069 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform, | 1080 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform, |
1070 grand_child->draw_transform()); | 1081 grand_child->draw_transform()); |
1071 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, | 1082 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
1072 grand_child->screen_space_transform()); | 1083 grand_child->screen_space_transform()); |
| 1084 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_draw_transform, |
| 1085 great_grand_child->draw_transform()); |
| 1086 EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1087 expected_great_grand_child_screen_space_transform, |
| 1088 great_grand_child->screen_space_transform()); |
1073 } | 1089 } |
1074 | 1090 |
1075 TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) { | 1091 TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) { |
1076 // A layer that is empty in one axis, but not the other, was accidentally | 1092 // A layer that is empty in one axis, but not the other, was accidentally |
1077 // skipping a necessary translation. Without that translation, the coordinate | 1093 // skipping a necessary translation. Without that translation, the coordinate |
1078 // space of the layer's draw transform is incorrect. | 1094 // space of the layer's draw transform is incorrect. |
1079 // | 1095 // |
1080 // Normally this isn't a problem, because the layer wouldn't be drawn anyway, | 1096 // Normally this isn't a problem, because the layer wouldn't be drawn anyway, |
1081 // but if that layer becomes a render surface, then its draw transform is | 1097 // but if that layer becomes a render surface, then its draw transform is |
1082 // implicitly inherited by the rest of the subtree, which then is positioned | 1098 // implicitly inherited by the rest of the subtree, which then is positioned |
(...skipping 5925 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7008 | 7024 |
7009 { | 7025 { |
7010 LayerImplList render_surface_layer_list; | 7026 LayerImplList render_surface_layer_list; |
7011 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root.get()); | 7027 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root.get()); |
7012 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( | 7028 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
7013 root.get(), root->bounds(), &render_surface_layer_list); | 7029 root.get(), root->bounds(), &render_surface_layer_list); |
7014 inputs.can_render_to_separate_surface = true; | 7030 inputs.can_render_to_separate_surface = true; |
7015 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | 7031 LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
7016 | 7032 |
7017 EXPECT_EQ(2u, render_surface_layer_list.size()); | 7033 EXPECT_EQ(2u, render_surface_layer_list.size()); |
| 7034 |
| 7035 int count_represents_target_render_surface = 0; |
| 7036 int count_represents_contributing_render_surface = 0; |
| 7037 int count_represents_itself = 0; |
| 7038 auto end = LayerIterator<LayerImpl>::End(&render_surface_layer_list); |
| 7039 for (auto it = LayerIterator<LayerImpl>::Begin(&render_surface_layer_list); |
| 7040 it != end; ++it) { |
| 7041 if (it.represents_target_render_surface()) |
| 7042 count_represents_target_render_surface++; |
| 7043 if (it.represents_contributing_render_surface()) |
| 7044 count_represents_contributing_render_surface++; |
| 7045 if (it.represents_itself()) |
| 7046 count_represents_itself++; |
| 7047 } |
| 7048 |
| 7049 // Two render surfaces. |
| 7050 EXPECT_EQ(2, count_represents_target_render_surface); |
| 7051 // Second render surface contributes to root render surface. |
| 7052 EXPECT_EQ(1, count_represents_contributing_render_surface); |
| 7053 // All 4 layers represent itself. |
| 7054 EXPECT_EQ(4, count_represents_itself); |
7018 } | 7055 } |
7019 | 7056 |
7020 { | 7057 { |
7021 LayerImplList render_surface_layer_list; | 7058 LayerImplList render_surface_layer_list; |
7022 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( | 7059 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
7023 root.get(), root->bounds(), &render_surface_layer_list); | 7060 root.get(), root->bounds(), &render_surface_layer_list); |
7024 inputs.can_render_to_separate_surface = false; | 7061 inputs.can_render_to_separate_surface = false; |
7025 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | 7062 LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
7026 | 7063 |
7027 EXPECT_EQ(1u, render_surface_layer_list.size()); | 7064 EXPECT_EQ(1u, render_surface_layer_list.size()); |
| 7065 |
| 7066 int count_represents_target_render_surface = 0; |
| 7067 int count_represents_contributing_render_surface = 0; |
| 7068 int count_represents_itself = 0; |
| 7069 auto end = LayerIterator<LayerImpl>::End(&render_surface_layer_list); |
| 7070 for (auto it = LayerIterator<LayerImpl>::Begin(&render_surface_layer_list); |
| 7071 it != end; ++it) { |
| 7072 if (it.represents_target_render_surface()) |
| 7073 count_represents_target_render_surface++; |
| 7074 if (it.represents_contributing_render_surface()) |
| 7075 count_represents_contributing_render_surface++; |
| 7076 if (it.represents_itself()) |
| 7077 count_represents_itself++; |
| 7078 } |
| 7079 |
| 7080 // Only root layer has a render surface. |
| 7081 EXPECT_EQ(1, count_represents_target_render_surface); |
| 7082 // No layer contributes a render surface to root render surface. |
| 7083 EXPECT_EQ(0, count_represents_contributing_render_surface); |
| 7084 // All 4 layers represent itself. |
| 7085 EXPECT_EQ(4, count_represents_itself); |
7028 } | 7086 } |
7029 } | 7087 } |
7030 | 7088 |
7031 TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) { | 7089 TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) { |
7032 scoped_refptr<Layer> root = Layer::Create(); | 7090 scoped_refptr<Layer> root = Layer::Create(); |
7033 scoped_refptr<Layer> render_surface = Layer::Create(); | 7091 scoped_refptr<Layer> render_surface = Layer::Create(); |
7034 scoped_refptr<LayerWithForcedDrawsContent> child = | 7092 scoped_refptr<LayerWithForcedDrawsContent> child = |
7035 make_scoped_refptr(new LayerWithForcedDrawsContent); | 7093 make_scoped_refptr(new LayerWithForcedDrawsContent); |
7036 | 7094 |
7037 root->AddChild(render_surface); | 7095 root->AddChild(render_surface); |
(...skipping 1753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8791 surface->AddChild(box); | 8849 surface->AddChild(box); |
8792 | 8850 |
8793 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | 8851 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
8794 host->SetRootLayer(root); | 8852 host->SetRootLayer(root); |
8795 | 8853 |
8796 ExecuteCalculateDrawProperties(root.get()); | 8854 ExecuteCalculateDrawProperties(root.get()); |
8797 } | 8855 } |
8798 | 8856 |
8799 } // namespace | 8857 } // namespace |
8800 } // namespace cc | 8858 } // namespace cc |
OLD | NEW |