| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 ->property_trees() | 95 ->property_trees() |
| 96 ->GetAnimationScales(layer_impl->transform_tree_index(), | 96 ->GetAnimationScales(layer_impl->transform_tree_index(), |
| 97 layer_impl->layer_tree_impl()) | 97 layer_impl->layer_tree_impl()) |
| 98 .starting_animation_scale; | 98 .starting_animation_scale; |
| 99 } | 99 } |
| 100 | 100 |
| 101 void ExecuteCalculateDrawProperties(Layer* root_layer, | 101 void ExecuteCalculateDrawProperties(Layer* root_layer, |
| 102 float device_scale_factor, | 102 float device_scale_factor, |
| 103 float page_scale_factor, | 103 float page_scale_factor, |
| 104 Layer* page_scale_layer, | 104 Layer* page_scale_layer, |
| 105 Layer* inner_viewport_scroll_layer) { | 105 Layer* inner_viewport_scroll_layer, |
| 106 Layer* outer_viewport_scroll_layer) { |
| 106 PropertyTreeBuilder::PreCalculateMetaInformation(root_layer); | 107 PropertyTreeBuilder::PreCalculateMetaInformation(root_layer); |
| 107 | 108 |
| 108 EXPECT_TRUE(page_scale_layer || (page_scale_factor == 1.f)); | 109 EXPECT_TRUE(page_scale_layer || (page_scale_factor == 1.f)); |
| 109 gfx::Size device_viewport_size = | 110 gfx::Size device_viewport_size = |
| 110 gfx::Size(root_layer->bounds().width() * device_scale_factor, | 111 gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 111 root_layer->bounds().height() * device_scale_factor); | 112 root_layer->bounds().height() * device_scale_factor); |
| 112 | 113 |
| 113 // We are probably not testing what is intended if the root_layer bounds are | 114 // We are probably not testing what is intended if the root_layer bounds are |
| 114 // empty. | 115 // empty. |
| 115 DCHECK(!root_layer->bounds().IsEmpty()); | 116 DCHECK(!root_layer->bounds().IsEmpty()); |
| 116 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | 117 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 117 root_layer, device_viewport_size); | 118 root_layer, device_viewport_size); |
| 118 inputs.device_scale_factor = device_scale_factor; | 119 inputs.device_scale_factor = device_scale_factor; |
| 119 inputs.page_scale_factor = page_scale_factor; | 120 inputs.page_scale_factor = page_scale_factor; |
| 120 inputs.page_scale_layer = page_scale_layer; | 121 inputs.page_scale_layer = page_scale_layer; |
| 121 inputs.inner_viewport_scroll_layer = inner_viewport_scroll_layer; | 122 inputs.inner_viewport_scroll_layer = inner_viewport_scroll_layer; |
| 123 inputs.outer_viewport_scroll_layer = outer_viewport_scroll_layer; |
| 122 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); | 124 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
| 123 } | 125 } |
| 124 | 126 |
| 125 void ExecuteCalculateDrawProperties( | 127 void ExecuteCalculateDrawProperties( |
| 126 LayerImpl* root_layer, | 128 LayerImpl* root_layer, |
| 127 float device_scale_factor, | 129 float device_scale_factor, |
| 128 float page_scale_factor, | 130 float page_scale_factor, |
| 129 LayerImpl* page_scale_layer, | 131 LayerImpl* page_scale_layer, |
| 130 LayerImpl* inner_viewport_scroll_layer, | 132 LayerImpl* inner_viewport_scroll_layer, |
| 133 LayerImpl* outer_viewport_scroll_layer, |
| 131 bool skip_verify_visible_rect_calculations = false) { | 134 bool skip_verify_visible_rect_calculations = false) { |
| 132 if (device_scale_factor != | 135 if (device_scale_factor != |
| 133 root_layer->layer_tree_impl()->device_scale_factor()) | 136 root_layer->layer_tree_impl()->device_scale_factor()) |
| 134 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; | 137 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 135 | 138 |
| 136 root_layer->layer_tree_impl()->SetDeviceScaleFactor(device_scale_factor); | 139 root_layer->layer_tree_impl()->SetDeviceScaleFactor(device_scale_factor); |
| 137 | 140 |
| 138 EXPECT_TRUE(page_scale_layer || (page_scale_factor == 1.f)); | 141 EXPECT_TRUE(page_scale_layer || (page_scale_factor == 1.f)); |
| 139 | 142 |
| 140 gfx::Size device_viewport_size = | 143 gfx::Size device_viewport_size = |
| 141 gfx::Size(root_layer->bounds().width() * device_scale_factor, | 144 gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 142 root_layer->bounds().height() * device_scale_factor); | 145 root_layer->bounds().height() * device_scale_factor); |
| 143 | 146 |
| 144 render_surface_layer_list_impl_.reset(new LayerImplList); | 147 render_surface_layer_list_impl_.reset(new LayerImplList); |
| 145 | 148 |
| 146 // We are probably not testing what is intended if the root_layer bounds are | 149 // We are probably not testing what is intended if the root_layer bounds are |
| 147 // empty. | 150 // empty. |
| 148 DCHECK(!root_layer->bounds().IsEmpty()); | 151 DCHECK(!root_layer->bounds().IsEmpty()); |
| 149 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( | 152 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 150 root_layer, device_viewport_size, | 153 root_layer, device_viewport_size, |
| 151 render_surface_layer_list_impl_.get()); | 154 render_surface_layer_list_impl_.get()); |
| 152 inputs.device_scale_factor = device_scale_factor; | 155 inputs.device_scale_factor = device_scale_factor; |
| 153 inputs.page_scale_factor = page_scale_factor; | 156 inputs.page_scale_factor = page_scale_factor; |
| 154 inputs.page_scale_layer = page_scale_layer; | 157 inputs.page_scale_layer = page_scale_layer; |
| 155 inputs.inner_viewport_scroll_layer = inner_viewport_scroll_layer; | 158 inputs.inner_viewport_scroll_layer = inner_viewport_scroll_layer; |
| 159 inputs.outer_viewport_scroll_layer = outer_viewport_scroll_layer; |
| 156 inputs.can_adjust_raster_scales = true; | 160 inputs.can_adjust_raster_scales = true; |
| 157 if (skip_verify_visible_rect_calculations) | 161 if (skip_verify_visible_rect_calculations) |
| 158 inputs.verify_visible_rect_calculations = false; | 162 inputs.verify_visible_rect_calculations = false; |
| 159 | 163 |
| 160 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); | 164 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
| 161 } | 165 } |
| 162 | 166 |
| 163 template <class LayerType> | 167 template <class LayerType> |
| 164 void ExecuteCalculateDrawProperties(LayerType* root_layer) { | 168 void ExecuteCalculateDrawProperties(LayerType* root_layer) { |
| 165 LayerType* page_scale_application_layer = nullptr; | 169 LayerType* page_scale_application_layer = nullptr; |
| 166 LayerType* inner_viewport_scroll_layer = nullptr; | 170 LayerType* inner_viewport_scroll_layer = nullptr; |
| 167 ExecuteCalculateDrawProperties(root_layer, 1.f, 1.f, | 171 LayerType* outer_viewport_scroll_layer = nullptr; |
| 168 page_scale_application_layer, | 172 ExecuteCalculateDrawProperties( |
| 169 inner_viewport_scroll_layer); | 173 root_layer, 1.f, 1.f, page_scale_application_layer, |
| 174 inner_viewport_scroll_layer, outer_viewport_scroll_layer); |
| 170 } | 175 } |
| 171 | 176 |
| 172 template <class LayerType> | 177 template <class LayerType> |
| 173 void ExecuteCalculateDrawProperties(LayerType* root_layer, | 178 void ExecuteCalculateDrawProperties(LayerType* root_layer, |
| 174 float device_scale_factor) { | 179 float device_scale_factor) { |
| 175 LayerType* page_scale_application_layer = nullptr; | 180 LayerType* page_scale_application_layer = nullptr; |
| 176 LayerType* inner_viewport_scroll_layer = nullptr; | 181 LayerType* inner_viewport_scroll_layer = nullptr; |
| 177 ExecuteCalculateDrawProperties(root_layer, device_scale_factor, 1.f, | 182 LayerType* outer_viewport_scroll_layer = nullptr; |
| 178 page_scale_application_layer, | 183 ExecuteCalculateDrawProperties( |
| 179 inner_viewport_scroll_layer); | 184 root_layer, device_scale_factor, 1.f, page_scale_application_layer, |
| 185 inner_viewport_scroll_layer, outer_viewport_scroll_layer); |
| 180 } | 186 } |
| 181 | 187 |
| 182 const LayerList* GetUpdateLayerList() { return &update_layer_list_; } | 188 const LayerList* GetUpdateLayerList() { return &update_layer_list_; } |
| 183 | 189 |
| 184 void ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(Layer* root_layer) { | 190 void ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(Layer* root_layer) { |
| 185 DCHECK(root_layer->GetLayerTree()); | 191 DCHECK(root_layer->GetLayerTree()); |
| 186 PropertyTreeBuilder::PreCalculateMetaInformation(root_layer); | 192 PropertyTreeBuilder::PreCalculateMetaInformation(root_layer); |
| 187 | 193 |
| 188 bool can_render_to_separate_surface = true; | 194 bool can_render_to_separate_surface = true; |
| 189 | 195 |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 std::unique_ptr<LayerImpl> root( | 565 std::unique_ptr<LayerImpl> root( |
| 560 LayerImpl::Create(host_impl.active_tree(), 3)); | 566 LayerImpl::Create(host_impl.active_tree(), 3)); |
| 561 root->SetBounds(gfx::Size(3, 4)); | 567 root->SetBounds(gfx::Size(3, 4)); |
| 562 root->test_properties()->AddChild(std::move(clip_layer_scoped_ptr)); | 568 root->test_properties()->AddChild(std::move(clip_layer_scoped_ptr)); |
| 563 root->SetHasRenderSurface(true); | 569 root->SetHasRenderSurface(true); |
| 564 LayerImpl* root_layer = root.get(); | 570 LayerImpl* root_layer = root.get(); |
| 565 host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); | 571 host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
| 566 | 572 |
| 567 ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale, | 573 ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale, |
| 568 scroll_layer->test_properties()->parent, | 574 scroll_layer->test_properties()->parent, |
| 569 nullptr); | 575 nullptr, nullptr); |
| 570 gfx::Transform expected_transform; | 576 gfx::Transform expected_transform; |
| 571 gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta; | 577 gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta; |
| 572 expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x() * | 578 expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x() * |
| 573 page_scale * kDeviceScale), | 579 page_scale * kDeviceScale), |
| 574 MathUtil::Round(sub_layer_screen_position.y() * | 580 MathUtil::Round(sub_layer_screen_position.y() * |
| 575 page_scale * kDeviceScale)); | 581 page_scale * kDeviceScale)); |
| 576 expected_transform.Scale(page_scale * kDeviceScale, | 582 expected_transform.Scale(page_scale * kDeviceScale, |
| 577 page_scale * kDeviceScale); | 583 page_scale * kDeviceScale); |
| 578 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, | 584 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
| 579 sublayer->DrawTransform()); | 585 sublayer->DrawTransform()); |
| 580 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, | 586 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
| 581 sublayer->ScreenSpaceTransform()); | 587 sublayer->ScreenSpaceTransform()); |
| 582 | 588 |
| 583 gfx::Transform arbitrary_translate; | 589 gfx::Transform arbitrary_translate; |
| 584 const float kTranslateX = 10.6f; | 590 const float kTranslateX = 10.6f; |
| 585 const float kTranslateY = 20.6f; | 591 const float kTranslateY = 20.6f; |
| 586 arbitrary_translate.Translate(kTranslateX, kTranslateY); | 592 arbitrary_translate.Translate(kTranslateX, kTranslateY); |
| 587 scroll_layer->test_properties()->transform = arbitrary_translate; | 593 scroll_layer->test_properties()->transform = arbitrary_translate; |
| 588 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; | 594 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 589 ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale, | 595 ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale, |
| 590 scroll_layer->test_properties()->parent, | 596 scroll_layer->test_properties()->parent, |
| 591 nullptr); | 597 nullptr, nullptr); |
| 592 expected_transform.MakeIdentity(); | 598 expected_transform.MakeIdentity(); |
| 593 expected_transform.Translate( | 599 expected_transform.Translate( |
| 594 MathUtil::Round(kTranslateX * page_scale * kDeviceScale + | 600 MathUtil::Round(kTranslateX * page_scale * kDeviceScale + |
| 595 sub_layer_screen_position.x() * page_scale * | 601 sub_layer_screen_position.x() * page_scale * |
| 596 kDeviceScale), | 602 kDeviceScale), |
| 597 MathUtil::Round(kTranslateY * page_scale * kDeviceScale + | 603 MathUtil::Round(kTranslateY * page_scale * kDeviceScale + |
| 598 sub_layer_screen_position.y() * page_scale * | 604 sub_layer_screen_position.y() * page_scale * |
| 599 kDeviceScale)); | 605 kDeviceScale)); |
| 600 expected_transform.Scale(page_scale * kDeviceScale, | 606 expected_transform.Scale(page_scale * kDeviceScale, |
| 601 page_scale * kDeviceScale); | 607 page_scale * kDeviceScale); |
| 602 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, | 608 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
| 603 sublayer->DrawTransform()); | 609 sublayer->DrawTransform()); |
| 604 | 610 |
| 605 // Test that page scale is updated even when we don't rebuild property trees. | 611 // Test that page scale is updated even when we don't rebuild property trees. |
| 606 page_scale = 1.888f; | 612 page_scale = 1.888f; |
| 607 root_layer->layer_tree_impl()->SetViewportLayersFromIds( | 613 root_layer->layer_tree_impl()->SetViewportLayersFromIds( |
| 608 Layer::INVALID_ID, scroll_layer->test_properties()->parent->id(), | 614 Layer::INVALID_ID, scroll_layer->test_properties()->parent->id(), |
| 609 Layer::INVALID_ID, Layer::INVALID_ID); | 615 Layer::INVALID_ID, Layer::INVALID_ID); |
| 610 root_layer->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale); | 616 root_layer->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale); |
| 611 EXPECT_FALSE(root_layer->layer_tree_impl()->property_trees()->needs_rebuild); | 617 EXPECT_FALSE(root_layer->layer_tree_impl()->property_trees()->needs_rebuild); |
| 612 ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale, | 618 ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale, |
| 613 scroll_layer->test_properties()->parent, | 619 scroll_layer->test_properties()->parent, |
| 614 nullptr); | 620 nullptr, nullptr); |
| 615 | 621 |
| 616 expected_transform.MakeIdentity(); | 622 expected_transform.MakeIdentity(); |
| 617 expected_transform.Translate( | 623 expected_transform.Translate( |
| 618 MathUtil::Round(kTranslateX * page_scale * kDeviceScale + | 624 MathUtil::Round(kTranslateX * page_scale * kDeviceScale + |
| 619 sub_layer_screen_position.x() * page_scale * | 625 sub_layer_screen_position.x() * page_scale * |
| 620 kDeviceScale), | 626 kDeviceScale), |
| 621 MathUtil::Round(kTranslateY * page_scale * kDeviceScale + | 627 MathUtil::Round(kTranslateY * page_scale * kDeviceScale + |
| 622 sub_layer_screen_position.y() * page_scale * | 628 sub_layer_screen_position.y() * page_scale * |
| 623 kDeviceScale)); | 629 kDeviceScale)); |
| 624 expected_transform.Scale(page_scale * kDeviceScale, | 630 expected_transform.Scale(page_scale * kDeviceScale, |
| (...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1114 child->test_properties()->transform = child_transform; | 1120 child->test_properties()->transform = child_transform; |
| 1115 child->SetBounds(gfx::Size(10, 10)); | 1121 child->SetBounds(gfx::Size(10, 10)); |
| 1116 grand_child->test_properties()->transform = grand_child_transform; | 1122 grand_child->test_properties()->transform = grand_child_transform; |
| 1117 grand_child->SetBounds(gfx::Size(100, 100)); | 1123 grand_child->SetBounds(gfx::Size(100, 100)); |
| 1118 grand_child->test_properties()->should_flatten_transform = false; | 1124 grand_child->test_properties()->should_flatten_transform = false; |
| 1119 grand_child->SetDrawsContent(true); | 1125 grand_child->SetDrawsContent(true); |
| 1120 float device_scale_factor = 1.f; | 1126 float device_scale_factor = 1.f; |
| 1121 float page_scale_factor = 1.f; | 1127 float page_scale_factor = 1.f; |
| 1122 LayerImpl* page_scale_layer = nullptr; | 1128 LayerImpl* page_scale_layer = nullptr; |
| 1123 LayerImpl* inner_viewport_scroll_layer = nullptr; | 1129 LayerImpl* inner_viewport_scroll_layer = nullptr; |
| 1130 LayerImpl* outer_viewport_scroll_layer = nullptr; |
| 1124 // Visible rects computed by combining clips in target space and root space | 1131 // Visible rects computed by combining clips in target space and root space |
| 1125 // don't match because of rotation transforms. So, we skip | 1132 // don't match because of rotation transforms. So, we skip |
| 1126 // verify_visible_rect_calculations. | 1133 // verify_visible_rect_calculations. |
| 1127 bool skip_verify_visible_rect_calculations = true; | 1134 bool skip_verify_visible_rect_calculations = true; |
| 1128 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, | 1135 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, |
| 1129 page_scale_layer, inner_viewport_scroll_layer, | 1136 page_scale_layer, inner_viewport_scroll_layer, |
| 1137 outer_viewport_scroll_layer, |
| 1130 skip_verify_visible_rect_calculations); | 1138 skip_verify_visible_rect_calculations); |
| 1131 | 1139 |
| 1132 // Mapping grand_child's bounds to target space produces a non-empty rect | 1140 // Mapping grand_child's bounds to target space produces a non-empty rect |
| 1133 // that is fully contained within the target's bounds, so grand_child should | 1141 // that is fully contained within the target's bounds, so grand_child should |
| 1134 // be considered fully visible. | 1142 // be considered fully visible. |
| 1135 EXPECT_EQ(gfx::Rect(grand_child->bounds()), | 1143 EXPECT_EQ(gfx::Rect(grand_child->bounds()), |
| 1136 grand_child->visible_layer_rect()); | 1144 grand_child->visible_layer_rect()); |
| 1137 } | 1145 } |
| 1138 | 1146 |
| 1139 TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) { | 1147 TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) { |
| (...skipping 3377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4517 scale_surface->test_properties()->force_render_surface = true; | 4525 scale_surface->test_properties()->force_render_surface = true; |
| 4518 | 4526 |
| 4519 float device_scale_factor = 2.5f; | 4527 float device_scale_factor = 2.5f; |
| 4520 float page_scale_factor = 3.f; | 4528 float page_scale_factor = 3.f; |
| 4521 root->layer_tree_impl()->SetViewportLayersFromIds( | 4529 root->layer_tree_impl()->SetViewportLayersFromIds( |
| 4522 Layer::INVALID_ID, page_scale->id(), Layer::INVALID_ID, | 4530 Layer::INVALID_ID, page_scale->id(), Layer::INVALID_ID, |
| 4523 Layer::INVALID_ID); | 4531 Layer::INVALID_ID); |
| 4524 root->layer_tree_impl()->BuildLayerListAndPropertyTreesForTesting(); | 4532 root->layer_tree_impl()->BuildLayerListAndPropertyTreesForTesting(); |
| 4525 root->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale_factor); | 4533 root->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale_factor); |
| 4526 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, | 4534 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, |
| 4527 root, nullptr); | 4535 root, nullptr, nullptr); |
| 4528 | 4536 |
| 4529 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor, | 4537 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor, |
| 4530 parent->GetIdealContentsScale()); | 4538 parent->GetIdealContentsScale()); |
| 4531 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor, | 4539 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor, |
| 4532 perspective_surface->GetIdealContentsScale()); | 4540 perspective_surface->GetIdealContentsScale()); |
| 4533 // Ideal scale is the max 2d scale component of the combined transform up to | 4541 // Ideal scale is the max 2d scale component of the combined transform up to |
| 4534 // the nearest render target. Here this includes the layer transform as well | 4542 // the nearest render target. Here this includes the layer transform as well |
| 4535 // as the device and page scale factors. | 4543 // as the device and page scale factors. |
| 4536 gfx::Transform transform = scale_small_matrix; | 4544 gfx::Transform transform = scale_small_matrix; |
| 4537 transform.Scale(device_scale_factor * page_scale_factor, | 4545 transform.Scale(device_scale_factor * page_scale_factor, |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4603 child_scale->SetPosition(gfx::PointF(2.f, 2.f)); | 4611 child_scale->SetPosition(gfx::PointF(2.f, 2.f)); |
| 4604 child_scale->SetBounds(gfx::Size(10, 10)); | 4612 child_scale->SetBounds(gfx::Size(10, 10)); |
| 4605 child_scale->test_properties()->transform = child_scale_matrix; | 4613 child_scale->test_properties()->transform = child_scale_matrix; |
| 4606 child_scale->SetDrawsContent(true); | 4614 child_scale->SetDrawsContent(true); |
| 4607 | 4615 |
| 4608 float device_scale_factor = 2.5f; | 4616 float device_scale_factor = 2.5f; |
| 4609 float page_scale_factor = 0.01f; | 4617 float page_scale_factor = 0.01f; |
| 4610 | 4618 |
| 4611 { | 4619 { |
| 4612 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, | 4620 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, |
| 4613 root, nullptr); | 4621 root, nullptr, nullptr); |
| 4614 | 4622 |
| 4615 // The ideal scale is able to go below 1. | 4623 // The ideal scale is able to go below 1. |
| 4616 float expected_ideal_scale = | 4624 float expected_ideal_scale = |
| 4617 device_scale_factor * page_scale_factor * initial_parent_scale; | 4625 device_scale_factor * page_scale_factor * initial_parent_scale; |
| 4618 EXPECT_LT(expected_ideal_scale, 1.f); | 4626 EXPECT_LT(expected_ideal_scale, 1.f); |
| 4619 EXPECT_FLOAT_EQ(expected_ideal_scale, parent->GetIdealContentsScale()); | 4627 EXPECT_FLOAT_EQ(expected_ideal_scale, parent->GetIdealContentsScale()); |
| 4620 | 4628 |
| 4621 expected_ideal_scale = device_scale_factor * page_scale_factor * | 4629 expected_ideal_scale = device_scale_factor * page_scale_factor * |
| 4622 initial_parent_scale * initial_child_scale; | 4630 initial_parent_scale * initial_child_scale; |
| 4623 EXPECT_LT(expected_ideal_scale, 1.f); | 4631 EXPECT_LT(expected_ideal_scale, 1.f); |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4970 LayerImpl* root_ = nullptr; | 4978 LayerImpl* root_ = nullptr; |
| 4971 LayerImpl* child_ = nullptr; | 4979 LayerImpl* child_ = nullptr; |
| 4972 LayerImpl* grand_child_ = nullptr; | 4980 LayerImpl* grand_child_ = nullptr; |
| 4973 }; | 4981 }; |
| 4974 | 4982 |
| 4975 TEST_P(LCDTextTest, CanUseLCDText) { | 4983 TEST_P(LCDTextTest, CanUseLCDText) { |
| 4976 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; | 4984 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
| 4977 bool expect_not_lcd_text = layers_always_allowed_lcd_text_; | 4985 bool expect_not_lcd_text = layers_always_allowed_lcd_text_; |
| 4978 | 4986 |
| 4979 // Case 1: Identity transform. | 4987 // Case 1: Identity transform. |
| 4980 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr); | 4988 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
| 4981 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); | 4989 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 4982 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); | 4990 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 4983 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); | 4991 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
| 4984 | 4992 |
| 4985 // Case 2: Integral translation. | 4993 // Case 2: Integral translation. |
| 4986 gfx::Transform integral_translation; | 4994 gfx::Transform integral_translation; |
| 4987 integral_translation.Translate(1.0, 2.0); | 4995 integral_translation.Translate(1.0, 2.0); |
| 4988 child_->test_properties()->transform = integral_translation; | 4996 child_->test_properties()->transform = integral_translation; |
| 4989 child_->layer_tree_impl()->property_trees()->needs_rebuild = true; | 4997 child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 4990 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr); | 4998 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
| 4991 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); | 4999 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 4992 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); | 5000 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 4993 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); | 5001 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
| 4994 | 5002 |
| 4995 // Case 3: Non-integral translation. | 5003 // Case 3: Non-integral translation. |
| 4996 gfx::Transform non_integral_translation; | 5004 gfx::Transform non_integral_translation; |
| 4997 non_integral_translation.Translate(1.5, 2.5); | 5005 non_integral_translation.Translate(1.5, 2.5); |
| 4998 child_->test_properties()->transform = non_integral_translation; | 5006 child_->test_properties()->transform = non_integral_translation; |
| 4999 child_->layer_tree_impl()->property_trees()->needs_rebuild = true; | 5007 child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 5000 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr); | 5008 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
| 5001 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); | 5009 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5002 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); | 5010 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5003 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); | 5011 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
| 5004 | 5012 |
| 5005 // Case 4: Rotation. | 5013 // Case 4: Rotation. |
| 5006 gfx::Transform rotation; | 5014 gfx::Transform rotation; |
| 5007 rotation.Rotate(10.0); | 5015 rotation.Rotate(10.0); |
| 5008 child_->test_properties()->transform = rotation; | 5016 child_->test_properties()->transform = rotation; |
| 5009 child_->layer_tree_impl()->property_trees()->needs_rebuild = true; | 5017 child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 5010 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr); | 5018 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
| 5011 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); | 5019 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5012 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); | 5020 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5013 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); | 5021 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
| 5014 | 5022 |
| 5015 // Case 5: Scale. | 5023 // Case 5: Scale. |
| 5016 gfx::Transform scale; | 5024 gfx::Transform scale; |
| 5017 scale.Scale(2.0, 2.0); | 5025 scale.Scale(2.0, 2.0); |
| 5018 child_->test_properties()->transform = scale; | 5026 child_->test_properties()->transform = scale; |
| 5019 child_->layer_tree_impl()->property_trees()->needs_rebuild = true; | 5027 child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 5020 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr); | 5028 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
| 5021 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); | 5029 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5022 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); | 5030 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5023 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); | 5031 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
| 5024 | 5032 |
| 5025 // Case 6: Skew. | 5033 // Case 6: Skew. |
| 5026 gfx::Transform skew; | 5034 gfx::Transform skew; |
| 5027 skew.Skew(10.0, 0.0); | 5035 skew.Skew(10.0, 0.0); |
| 5028 child_->test_properties()->transform = skew; | 5036 child_->test_properties()->transform = skew; |
| 5029 child_->layer_tree_impl()->property_trees()->needs_rebuild = true; | 5037 child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 5030 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr); | 5038 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
| 5031 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); | 5039 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5032 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); | 5040 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5033 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); | 5041 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
| 5034 | 5042 |
| 5035 // Case 7: Translucent. | 5043 // Case 7: Translucent. |
| 5036 child_->test_properties()->transform = gfx::Transform(); | 5044 child_->test_properties()->transform = gfx::Transform(); |
| 5037 child_->layer_tree_impl()->property_trees()->needs_rebuild = true; | 5045 child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 5038 child_->test_properties()->opacity = 0.5f; | 5046 child_->test_properties()->opacity = 0.5f; |
| 5039 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr); | 5047 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
| 5040 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); | 5048 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5041 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); | 5049 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5042 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); | 5050 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
| 5043 | 5051 |
| 5044 // Case 8: Sanity check: restore transform and opacity. | 5052 // Case 8: Sanity check: restore transform and opacity. |
| 5045 child_->test_properties()->transform = gfx::Transform(); | 5053 child_->test_properties()->transform = gfx::Transform(); |
| 5046 child_->layer_tree_impl()->property_trees()->needs_rebuild = true; | 5054 child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 5047 child_->test_properties()->opacity = 1.f; | 5055 child_->test_properties()->opacity = 1.f; |
| 5048 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr); | 5056 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
| 5049 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); | 5057 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5050 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); | 5058 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 5051 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); | 5059 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
| 5052 | 5060 |
| 5053 // Case 9: Non-opaque content. | 5061 // Case 9: Non-opaque content. |
| 5054 child_->SetContentsOpaque(false); | 5062 child_->SetContentsOpaque(false); |
| 5055 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr); | 5063 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
| 5056 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); | 5064 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5057 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); | 5065 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5058 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); | 5066 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
| 5059 | 5067 |
| 5060 // Case 10: Sanity check: restore content opaqueness. | 5068 // Case 10: Sanity check: restore content opaqueness. |
| 5061 child_->SetContentsOpaque(true); | 5069 child_->SetContentsOpaque(true); |
| 5062 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr); | 5070 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
| 5063 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); | 5071 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5064 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); | 5072 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 5065 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); | 5073 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
| 5066 } | 5074 } |
| 5067 | 5075 |
| 5068 TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) { | 5076 TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) { |
| 5069 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; | 5077 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
| 5070 bool expect_not_lcd_text = layers_always_allowed_lcd_text_; | 5078 bool expect_not_lcd_text = layers_always_allowed_lcd_text_; |
| 5071 | 5079 |
| 5072 // Sanity check: Make sure can_use_lcd_text_ is set on each node. | 5080 // Sanity check: Make sure can_use_lcd_text_ is set on each node. |
| 5073 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr); | 5081 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
| 5074 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); | 5082 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5075 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); | 5083 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 5076 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); | 5084 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
| 5077 | 5085 |
| 5078 // Add opacity animation. | 5086 // Add opacity animation. |
| 5079 child_->test_properties()->opacity = 0.9f; | 5087 child_->test_properties()->opacity = 0.9f; |
| 5080 child_->layer_tree_impl()->property_trees()->needs_rebuild = true; | 5088 child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 5081 | 5089 |
| 5082 SetElementIdsForTesting(); | 5090 SetElementIdsForTesting(); |
| 5083 | 5091 |
| 5084 AddOpacityTransitionToElementWithPlayer(child_->element_id(), timeline(), | 5092 AddOpacityTransitionToElementWithPlayer(child_->element_id(), timeline(), |
| 5085 10.0, 0.9f, 0.1f, false); | 5093 10.0, 0.9f, 0.1f, false); |
| 5086 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr); | 5094 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
| 5087 // Text LCD should be adjusted while animation is active. | 5095 // Text LCD should be adjusted while animation is active. |
| 5088 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); | 5096 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5089 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); | 5097 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5090 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); | 5098 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
| 5091 } | 5099 } |
| 5092 | 5100 |
| 5093 TEST_P(LCDTextTest, CanUseLCDTextWithAnimationContentsOpaque) { | 5101 TEST_P(LCDTextTest, CanUseLCDTextWithAnimationContentsOpaque) { |
| 5094 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; | 5102 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
| 5095 bool expect_not_lcd_text = layers_always_allowed_lcd_text_; | 5103 bool expect_not_lcd_text = layers_always_allowed_lcd_text_; |
| 5096 | 5104 |
| 5097 // Sanity check: Make sure can_use_lcd_text_ is set on each node. | 5105 // Sanity check: Make sure can_use_lcd_text_ is set on each node. |
| 5098 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr); | 5106 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
| 5099 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); | 5107 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5100 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); | 5108 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 5101 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); | 5109 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
| 5102 SetElementIdsForTesting(); | 5110 SetElementIdsForTesting(); |
| 5103 | 5111 |
| 5104 // Mark contents non-opaque within the first animation frame. | 5112 // Mark contents non-opaque within the first animation frame. |
| 5105 child_->SetContentsOpaque(false); | 5113 child_->SetContentsOpaque(false); |
| 5106 AddOpacityTransitionToElementWithPlayer(child_->element_id(), timeline(), | 5114 AddOpacityTransitionToElementWithPlayer(child_->element_id(), timeline(), |
| 5107 10.0, 0.9f, 0.1f, false); | 5115 10.0, 0.9f, 0.1f, false); |
| 5108 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr); | 5116 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
| 5109 // LCD text should be disabled for non-opaque layers even during animations. | 5117 // LCD text should be disabled for non-opaque layers even during animations. |
| 5110 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); | 5118 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5111 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); | 5119 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5112 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); | 5120 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
| 5113 } | 5121 } |
| 5114 | 5122 |
| 5115 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, | 5123 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, |
| 5116 LCDTextTest, | 5124 LCDTextTest, |
| 5117 testing::Combine(testing::Bool(), | 5125 testing::Combine(testing::Bool(), |
| 5118 testing::Bool(), | 5126 testing::Bool(), |
| (...skipping 1853 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6972 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); | 6980 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6973 | 6981 |
| 6974 // Once we scroll past its initial location, it sticks there. | 6982 // Once we scroll past its initial location, it sticks there. |
| 6975 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 150.f)); | 6983 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 150.f)); |
| 6976 ExecuteCalculateDrawProperties(root_impl); | 6984 ExecuteCalculateDrawProperties(root_impl); |
| 6977 EXPECT_VECTOR2DF_EQ( | 6985 EXPECT_VECTOR2DF_EQ( |
| 6978 gfx::Vector2dF(0.f, 0.f), | 6986 gfx::Vector2dF(0.f, 0.f), |
| 6979 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); | 6987 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6980 } | 6988 } |
| 6981 | 6989 |
| 6982 TEST_F(LayerTreeHostCommonTest, StickyPositionBottomHideTopControls) { | 6990 TEST_F(LayerTreeHostCommonTest, StickyPositionBottomInnerViewportDelta) { |
| 6983 scoped_refptr<Layer> root = Layer::Create(); | 6991 scoped_refptr<Layer> root = Layer::Create(); |
| 6984 scoped_refptr<Layer> scroller = Layer::Create(); | 6992 scoped_refptr<Layer> scroller = Layer::Create(); |
| 6985 scoped_refptr<Layer> sticky_pos = Layer::Create(); | 6993 scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 6986 root->AddChild(scroller); | 6994 root->AddChild(scroller); |
| 6987 scroller->AddChild(sticky_pos); | 6995 scroller->AddChild(sticky_pos); |
| 6988 host()->SetRootLayer(root); | 6996 host()->SetRootLayer(root); |
| 6989 scroller->SetScrollClipLayerId(root->id()); | 6997 scroller->SetScrollClipLayerId(root->id()); |
| 6990 host()->GetLayerTree()->RegisterViewportLayers(nullptr, root, scroller, | 6998 host()->GetLayerTree()->RegisterViewportLayers(nullptr, root, scroller, |
| 6991 nullptr); | 6999 nullptr); |
| 6992 | 7000 |
| 6993 LayerStickyPositionConstraint sticky_position; | 7001 LayerStickyPositionConstraint sticky_position; |
| 6994 sticky_position.is_sticky = true; | 7002 sticky_position.is_sticky = true; |
| 6995 sticky_position.is_anchored_bottom = true; | 7003 sticky_position.is_anchored_bottom = true; |
| 6996 sticky_position.bottom_offset = 10.0f; | 7004 sticky_position.bottom_offset = 10.0f; |
| 6997 sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 150); | 7005 sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 70); |
| 6998 sticky_position.scroll_container_relative_sticky_box_rect = | 7006 sticky_position.scroll_container_relative_sticky_box_rect = |
| 6999 gfx::Rect(0, 150, 10, 10); | 7007 gfx::Rect(0, 70, 10, 10); |
| 7000 sticky_position.scroll_container_relative_containing_block_rect = | 7008 sticky_position.scroll_container_relative_containing_block_rect = |
| 7001 gfx::Rect(0, 0, 100, 1000); | 7009 gfx::Rect(0, 60, 100, 100); |
| 7002 sticky_pos->SetStickyPositionConstraint(sticky_position); | 7010 sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 7003 | 7011 |
| 7004 root->SetBounds(gfx::Size(100, 100)); | 7012 root->SetBounds(gfx::Size(100, 100)); |
| 7005 scroller->SetBounds(gfx::Size(100, 1000)); | 7013 scroller->SetBounds(gfx::Size(100, 1000)); |
| 7006 sticky_pos->SetBounds(gfx::Size(10, 10)); | 7014 sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 7007 sticky_pos->SetPosition(gfx::PointF(0, 150)); | 7015 sticky_pos->SetPosition(gfx::PointF(0, 70)); |
| 7008 | 7016 |
| 7009 ExecuteCalculateDrawProperties(root.get(), 1.f, 1.f, root.get(), | 7017 ExecuteCalculateDrawProperties(root.get(), 1.f, 1.f, root.get(), |
| 7010 scroller.get()); | 7018 scroller.get(), nullptr); |
| 7011 host()->CommitAndCreateLayerImplTree(); | 7019 host()->CommitAndCreateLayerImplTree(); |
| 7012 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); | 7020 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 7013 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); | 7021 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 7014 ASSERT_EQ(scroller->id(), layer_tree_impl->InnerViewportScrollLayer()->id()); | 7022 ASSERT_EQ(scroller->id(), layer_tree_impl->InnerViewportScrollLayer()->id()); |
| 7015 | 7023 |
| 7016 LayerImpl* inner_scroll = layer_tree_impl->InnerViewportScrollLayer(); | 7024 LayerImpl* inner_scroll = layer_tree_impl->InnerViewportScrollLayer(); |
| 7017 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); | 7025 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 7018 | 7026 |
| 7019 // Initially the sticky element is moved to the bottom of the container. | 7027 // Initially the sticky element is moved to the bottom of the container. |
| 7020 EXPECT_VECTOR2DF_EQ( | 7028 EXPECT_VECTOR2DF_EQ( |
| 7021 gfx::Vector2dF(0.f, 80.f), | 7029 gfx::Vector2dF(0.f, 70.f), |
| 7022 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); | 7030 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7023 | 7031 |
| 7024 // When we show the toolbar we hide part of the scroll container, this should | 7032 // We start to hide the toolbar, but not far enough that the sticky element |
| 7025 // move the sticky element up to remain at the bottom of the clipped | 7033 // should be moved up yet. |
| 7026 // container. | |
| 7027 root_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -10.f)); | 7034 root_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -10.f)); |
| 7028 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll); | 7035 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, |
| 7036 nullptr); |
| 7029 EXPECT_VECTOR2DF_EQ( | 7037 EXPECT_VECTOR2DF_EQ( |
| 7030 gfx::Vector2dF(0.f, 70.f), | 7038 gfx::Vector2dF(0.f, 70.f), |
| 7031 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); | 7039 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7040 |
| 7041 // On hiding more of the toolbar the sticky element starts to stick. |
| 7042 root_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -20.f)); |
| 7043 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, |
| 7044 nullptr); |
| 7045 EXPECT_VECTOR2DF_EQ( |
| 7046 gfx::Vector2dF(0.f, 60.f), |
| 7047 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7048 |
| 7049 // On hiding more the sticky element stops moving as it has reached its |
| 7050 // limit. |
| 7051 root_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -30.f)); |
| 7052 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, |
| 7053 nullptr); |
| 7054 EXPECT_VECTOR2DF_EQ( |
| 7055 gfx::Vector2dF(0.f, 60.f), |
| 7056 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7057 } |
| 7058 |
| 7059 TEST_F(LayerTreeHostCommonTest, StickyPositionBottomOuterViewportDelta) { |
| 7060 scoped_refptr<Layer> root = Layer::Create(); |
| 7061 scoped_refptr<Layer> scroller = Layer::Create(); |
| 7062 scoped_refptr<Layer> outer_clip = Layer::Create(); |
| 7063 scoped_refptr<Layer> outer_viewport = Layer::Create(); |
| 7064 scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 7065 root->AddChild(scroller); |
| 7066 scroller->AddChild(outer_clip); |
| 7067 outer_clip->AddChild(outer_viewport); |
| 7068 outer_viewport->AddChild(sticky_pos); |
| 7069 host()->SetRootLayer(root); |
| 7070 scroller->SetScrollClipLayerId(root->id()); |
| 7071 outer_viewport->SetScrollClipLayerId(outer_clip->id()); |
| 7072 host()->GetLayerTree()->RegisterViewportLayers(nullptr, root, scroller, |
| 7073 outer_viewport); |
| 7074 |
| 7075 LayerStickyPositionConstraint sticky_position; |
| 7076 sticky_position.is_sticky = true; |
| 7077 sticky_position.is_anchored_bottom = true; |
| 7078 sticky_position.bottom_offset = 10.0f; |
| 7079 sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 70); |
| 7080 sticky_position.scroll_container_relative_sticky_box_rect = |
| 7081 gfx::Rect(0, 70, 10, 10); |
| 7082 sticky_position.scroll_container_relative_containing_block_rect = |
| 7083 gfx::Rect(0, 60, 100, 100); |
| 7084 sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 7085 |
| 7086 root->SetBounds(gfx::Size(100, 100)); |
| 7087 scroller->SetBounds(gfx::Size(100, 1000)); |
| 7088 outer_clip->SetBounds(gfx::Size(100, 100)); |
| 7089 sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 7090 sticky_pos->SetPosition(gfx::PointF(0, 70)); |
| 7091 |
| 7092 ExecuteCalculateDrawProperties(root.get(), 1.f, 1.f, root.get(), |
| 7093 scroller.get(), outer_viewport.get()); |
| 7094 host()->CommitAndCreateLayerImplTree(); |
| 7095 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 7096 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 7097 ASSERT_EQ(outer_viewport->id(), |
| 7098 layer_tree_impl->OuterViewportScrollLayer()->id()); |
| 7099 |
| 7100 LayerImpl* inner_scroll = layer_tree_impl->InnerViewportScrollLayer(); |
| 7101 LayerImpl* outer_scroll = layer_tree_impl->OuterViewportScrollLayer(); |
| 7102 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 7103 LayerImpl* outer_clip_impl = layer_tree_impl->LayerById(outer_clip->id()); |
| 7104 |
| 7105 // Initially the sticky element is moved to the bottom of the container. |
| 7106 EXPECT_VECTOR2DF_EQ( |
| 7107 gfx::Vector2dF(0.f, 70.f), |
| 7108 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7109 |
| 7110 // We start to hide the toolbar, but not far enough that the sticky element |
| 7111 // should be moved up yet. |
| 7112 outer_clip_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -10.f)); |
| 7113 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, |
| 7114 outer_scroll); |
| 7115 EXPECT_VECTOR2DF_EQ( |
| 7116 gfx::Vector2dF(0.f, 70.f), |
| 7117 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7118 |
| 7119 // On hiding more of the toolbar the sticky element starts to stick. |
| 7120 outer_clip_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -20.f)); |
| 7121 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, |
| 7122 outer_scroll); |
| 7123 |
| 7124 // On hiding more the sticky element stops moving as it has reached its |
| 7125 // limit. |
| 7126 EXPECT_VECTOR2DF_EQ( |
| 7127 gfx::Vector2dF(0.f, 60.f), |
| 7128 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7129 |
| 7130 outer_clip_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -30.f)); |
| 7131 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, |
| 7132 outer_scroll); |
| 7133 |
| 7134 EXPECT_VECTOR2DF_EQ( |
| 7135 gfx::Vector2dF(0.f, 60.f), |
| 7136 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7032 } | 7137 } |
| 7033 | 7138 |
| 7034 TEST_F(LayerTreeHostCommonTest, StickyPositionLeftRight) { | 7139 TEST_F(LayerTreeHostCommonTest, StickyPositionLeftRight) { |
| 7035 scoped_refptr<Layer> root = Layer::Create(); | 7140 scoped_refptr<Layer> root = Layer::Create(); |
| 7036 scoped_refptr<Layer> container = Layer::Create(); | 7141 scoped_refptr<Layer> container = Layer::Create(); |
| 7037 scoped_refptr<Layer> scroller = Layer::Create(); | 7142 scoped_refptr<Layer> scroller = Layer::Create(); |
| 7038 scoped_refptr<Layer> sticky_pos = Layer::Create(); | 7143 scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 7039 root->AddChild(container); | 7144 root->AddChild(container); |
| 7040 container->AddChild(scroller); | 7145 container->AddChild(scroller); |
| 7041 scroller->AddChild(sticky_pos); | 7146 scroller->AddChild(sticky_pos); |
| (...skipping 2310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9352 render_surface->test_properties()->transform = transform2; | 9457 render_surface->test_properties()->transform = transform2; |
| 9353 render_surface->SetBounds(gfx::Size(30, 30)); | 9458 render_surface->SetBounds(gfx::Size(30, 30)); |
| 9354 render_surface->test_properties()->force_render_surface = true; | 9459 render_surface->test_properties()->force_render_surface = true; |
| 9355 test_layer->SetBounds(gfx::Size(30, 30)); | 9460 test_layer->SetBounds(gfx::Size(30, 30)); |
| 9356 test_layer->SetDrawsContent(true); | 9461 test_layer->SetDrawsContent(true); |
| 9357 | 9462 |
| 9358 float device_scale_factor = 1.f; | 9463 float device_scale_factor = 1.f; |
| 9359 float page_scale_factor = 1.f; | 9464 float page_scale_factor = 1.f; |
| 9360 LayerImpl* page_scale_layer = nullptr; | 9465 LayerImpl* page_scale_layer = nullptr; |
| 9361 LayerImpl* inner_viewport_scroll_layer = nullptr; | 9466 LayerImpl* inner_viewport_scroll_layer = nullptr; |
| 9467 LayerImpl* outer_viewport_scroll_layer = nullptr; |
| 9362 // Visible rects computed by combining clips in target space and root space | 9468 // Visible rects computed by combining clips in target space and root space |
| 9363 // don't match because of rotation transforms. So, we skip | 9469 // don't match because of rotation transforms. So, we skip |
| 9364 // verify_visible_rect_calculations. | 9470 // verify_visible_rect_calculations. |
| 9365 bool skip_verify_visible_rect_calculations = true; | 9471 bool skip_verify_visible_rect_calculations = true; |
| 9366 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, | 9472 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, |
| 9367 page_scale_layer, inner_viewport_scroll_layer, | 9473 page_scale_layer, inner_viewport_scroll_layer, |
| 9474 outer_viewport_scroll_layer, |
| 9368 skip_verify_visible_rect_calculations); | 9475 skip_verify_visible_rect_calculations); |
| 9369 | 9476 |
| 9370 TransformTree& transform_tree = | 9477 TransformTree& transform_tree = |
| 9371 root->layer_tree_impl()->property_trees()->transform_tree; | 9478 root->layer_tree_impl()->property_trees()->transform_tree; |
| 9372 TransformNode* transform_node = | 9479 TransformNode* transform_node = |
| 9373 transform_tree.Node(significant_transform->transform_tree_index()); | 9480 transform_tree.Node(significant_transform->transform_tree_index()); |
| 9374 EXPECT_EQ(transform_node->owner_id, significant_transform->id()); | 9481 EXPECT_EQ(transform_node->owner_id, significant_transform->id()); |
| 9375 | 9482 |
| 9376 EXPECT_TRUE(root->has_render_surface()); | 9483 EXPECT_TRUE(root->has_render_surface()); |
| 9377 EXPECT_FALSE(significant_transform->has_render_surface()); | 9484 EXPECT_FALSE(significant_transform->has_render_surface()); |
| (...skipping 996 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10374 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index()); | 10481 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index()); |
| 10375 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index()); | 10482 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index()); |
| 10376 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index()); | 10483 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index()); |
| 10377 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index()); | 10484 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index()); |
| 10378 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index()); | 10485 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index()); |
| 10379 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index()); | 10486 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index()); |
| 10380 } | 10487 } |
| 10381 | 10488 |
| 10382 } // namespace | 10489 } // namespace |
| 10383 } // namespace cc | 10490 } // namespace cc |
| OLD | NEW |