| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/layers/layer_position_constraint.h" | 5 #include "cc/layers/layer_position_constraint.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "cc/layers/layer_impl.h" | 9 #include "cc/layers/layer_impl.h" |
| 10 #include "cc/test/fake_impl_proxy.h" | 10 #include "cc/test/fake_impl_proxy.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 gfx::Size device_viewport_size = | 43 gfx::Size device_viewport_size = |
| 44 gfx::Size(root_layer->bounds().width() * device_scale_factor, | 44 gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 45 root_layer->bounds().height() * device_scale_factor); | 45 root_layer->bounds().height() * device_scale_factor); |
| 46 | 46 |
| 47 // We are probably not testing what is intended if the root_layer bounds are | 47 // We are probably not testing what is intended if the root_layer bounds are |
| 48 // empty. | 48 // empty. |
| 49 DCHECK(!root_layer->bounds().IsEmpty()); | 49 DCHECK(!root_layer->bounds().IsEmpty()); |
| 50 LayerTreeHostCommon::CalculateDrawProperties( | 50 LayerTreeHostCommon::CalculateDrawProperties( |
| 51 root_layer, | 51 root_layer, |
| 52 device_viewport_size, | 52 device_viewport_size, |
| 53 gfx::Transform(), |
| 53 device_scale_factor, | 54 device_scale_factor, |
| 54 page_scale_factor, | 55 page_scale_factor, |
| 55 page_scale_application_layer, | 56 page_scale_application_layer, |
| 56 dummy_max_texture_size, | 57 dummy_max_texture_size, |
| 57 can_use_lcd_text, | 58 can_use_lcd_text, |
| 58 false, | 59 false, |
| 59 &dummy_render_surface_layer_list); | 60 &dummy_render_surface_layer_list); |
| 60 } | 61 } |
| 61 | 62 |
| 62 void ExecuteCalculateDrawProperties(LayerImpl* root_layer) { | 63 void ExecuteCalculateDrawProperties(LayerImpl* root_layer) { |
| (...skipping 964 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1027 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | 1028 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 1028 child->draw_transform()); | 1029 child->draw_transform()); |
| 1029 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, | 1030 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, |
| 1030 grand_child->draw_transform()); | 1031 grand_child->draw_transform()); |
| 1031 } | 1032 } |
| 1032 | 1033 |
| 1033 TEST_F(LayerPositionConstraintTest, | 1034 TEST_F(LayerPositionConstraintTest, |
| 1034 ScrollCompensationForFixedPositionLayerThatHasNoContainer) { | 1035 ScrollCompensationForFixedPositionLayerThatHasNoContainer) { |
| 1035 // This test checks scroll compensation when a fixed-position layer does not | 1036 // This test checks scroll compensation when a fixed-position layer does not |
| 1036 // find any ancestor that is a "containerForFixedPositionLayers". In this | 1037 // find any ancestor that is a "containerForFixedPositionLayers". In this |
| 1037 // situation, the layer should be fixed to the viewport -- not the root_layer, | 1038 // situation, the layer should be fixed to the root layer. |
| 1038 // which may have transforms of its own. | |
| 1039 LayerImpl* child = root_->children()[0]; | 1039 LayerImpl* child = root_->children()[0]; |
| 1040 LayerImpl* grand_child = child->children()[0]; | 1040 LayerImpl* grand_child = child->children()[0]; |
| 1041 | 1041 |
| 1042 gfx::Transform rotation_by_z; | 1042 gfx::Transform rotation_by_z; |
| 1043 rotation_by_z.RotateAboutZAxis(90.0); | 1043 rotation_by_z.RotateAboutZAxis(90.0); |
| 1044 | 1044 |
| 1045 root_->SetTransform(rotation_by_z); | 1045 root_->SetTransform(rotation_by_z); |
| 1046 grand_child->SetPositionConstraint(fixed_to_top_left_); | 1046 grand_child->SetPositionConstraint(fixed_to_top_left_); |
| 1047 | 1047 |
| 1048 // Case 1: root scroll delta of 0, 0 | 1048 // Case 1: root scroll delta of 0, 0 |
| 1049 root_->SetScrollDelta(gfx::Vector2d(0, 0)); | 1049 root_->SetScrollDelta(gfx::Vector2d(0, 0)); |
| 1050 ExecuteCalculateDrawProperties(root_.get()); | 1050 ExecuteCalculateDrawProperties(root_.get()); |
| 1051 | 1051 |
| 1052 gfx::Transform identity_matrix; | 1052 gfx::Transform identity_matrix; |
| 1053 | 1053 |
| 1054 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); | 1054 EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_by_z, child->draw_transform()); |
| 1055 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, | 1055 EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_by_z, |
| 1056 grand_child->draw_transform()); | 1056 grand_child->draw_transform()); |
| 1057 | 1057 |
| 1058 // Case 2: root scroll delta of 10, 10 | 1058 // Case 2: root scroll delta of 10, 10 |
| 1059 root_->SetScrollDelta(gfx::Vector2d(10, 20)); | 1059 root_->SetScrollDelta(gfx::Vector2d(10, 20)); |
| 1060 ExecuteCalculateDrawProperties(root_.get()); | 1060 ExecuteCalculateDrawProperties(root_.get()); |
| 1061 | 1061 |
| 1062 // The child is affected by scroll delta, but it is already implcitly | 1062 gfx::Transform expected_child_transform; |
| 1063 // accounted for by the child's target surface (i.e. the root render surface). | 1063 expected_child_transform.Translate(-10.0, -20.0); |
| 1064 // The grand_child is not affected by the scroll delta, so its draw transform | 1064 expected_child_transform.PreconcatTransform(rotation_by_z); |
| 1065 // needs to explicitly inverse-compensate for the scroll that's embedded in | |
| 1066 // the target surface. | |
| 1067 gfx::Transform expected_grand_child_transform; | |
| 1068 expected_grand_child_transform.PreconcatTransform(Inverse(rotation_by_z)); | |
| 1069 // explicit cancelling out the scroll delta that gets embedded in the fixed | |
| 1070 // position layer's surface. | |
| 1071 expected_grand_child_transform.Translate(10.0, 20.0); | |
| 1072 expected_grand_child_transform.PreconcatTransform(rotation_by_z); | |
| 1073 | 1065 |
| 1074 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); | 1066 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 1075 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, | 1067 child->draw_transform()); |
| 1068 EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_by_z, |
| 1076 grand_child->draw_transform()); | 1069 grand_child->draw_transform()); |
| 1077 | 1070 |
| 1078 | |
| 1079 // Case 3: fixed-container size delta of 20, 20 | 1071 // Case 3: fixed-container size delta of 20, 20 |
| 1080 root_->SetFixedContainerSizeDelta(gfx::Vector2d(20, 20)); | 1072 root_->SetFixedContainerSizeDelta(gfx::Vector2d(20, 20)); |
| 1081 ExecuteCalculateDrawProperties(root_.get()); | 1073 ExecuteCalculateDrawProperties(root_.get()); |
| 1082 | 1074 |
| 1083 // Top-left fixed-position layer should not be affected by container size. | 1075 // Top-left fixed-position layer should not be affected by container size. |
| 1084 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); | 1076 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 1085 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, | 1077 child->draw_transform()); |
| 1078 EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_by_z, |
| 1086 grand_child->draw_transform()); | 1079 grand_child->draw_transform()); |
| 1087 | 1080 |
| 1088 // Case 4: Bottom-right fixed-position layer. | 1081 // Case 4: Bottom-right fixed-position layer. |
| 1089 grand_child->SetPositionConstraint(fixed_to_bottom_right_); | 1082 grand_child->SetPositionConstraint(fixed_to_bottom_right_); |
| 1090 ExecuteCalculateDrawProperties(root_.get()); | 1083 ExecuteCalculateDrawProperties(root_.get()); |
| 1091 | 1084 |
| 1092 // Root layer is not the fixed-container anyway. | 1085 gfx::Transform expected_grand_child_transform; |
| 1093 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); | 1086 expected_grand_child_transform.Translate(-20.0, 20.0); |
| 1087 expected_grand_child_transform.PreconcatTransform(rotation_by_z); |
| 1088 |
| 1089 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 1090 child->draw_transform()); |
| 1094 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, | 1091 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, |
| 1095 grand_child->draw_transform()); | 1092 grand_child->draw_transform()); |
| 1096 } | 1093 } |
| 1097 | 1094 |
| 1098 } // namespace | 1095 } // namespace |
| 1099 } // namespace cc | 1096 } // namespace cc |
| OLD | NEW |