| 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 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 std::unique_ptr<LayerImpl> root( | 564 std::unique_ptr<LayerImpl> root( |
| 559 LayerImpl::Create(host_impl.active_tree(), 3)); | 565 LayerImpl::Create(host_impl.active_tree(), 3)); |
| 560 root->SetBounds(gfx::Size(3, 4)); | 566 root->SetBounds(gfx::Size(3, 4)); |
| 561 root->test_properties()->AddChild(std::move(clip_layer_scoped_ptr)); | 567 root->test_properties()->AddChild(std::move(clip_layer_scoped_ptr)); |
| 562 root->SetHasRenderSurface(true); | 568 root->SetHasRenderSurface(true); |
| 563 LayerImpl* root_layer = root.get(); | 569 LayerImpl* root_layer = root.get(); |
| 564 host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); | 570 host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
| 565 | 571 |
| 566 ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale, | 572 ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale, |
| 567 scroll_layer->test_properties()->parent, | 573 scroll_layer->test_properties()->parent, |
| 568 nullptr); | 574 nullptr, nullptr); |
| 569 gfx::Transform expected_transform; | 575 gfx::Transform expected_transform; |
| 570 gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta; | 576 gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta; |
| 571 expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x() * | 577 expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x() * |
| 572 page_scale * kDeviceScale), | 578 page_scale * kDeviceScale), |
| 573 MathUtil::Round(sub_layer_screen_position.y() * | 579 MathUtil::Round(sub_layer_screen_position.y() * |
| 574 page_scale * kDeviceScale)); | 580 page_scale * kDeviceScale)); |
| 575 expected_transform.Scale(page_scale * kDeviceScale, | 581 expected_transform.Scale(page_scale * kDeviceScale, |
| 576 page_scale * kDeviceScale); | 582 page_scale * kDeviceScale); |
| 577 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, | 583 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
| 578 sublayer->DrawTransform()); | 584 sublayer->DrawTransform()); |
| 579 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, | 585 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
| 580 sublayer->ScreenSpaceTransform()); | 586 sublayer->ScreenSpaceTransform()); |
| 581 | 587 |
| 582 gfx::Transform arbitrary_translate; | 588 gfx::Transform arbitrary_translate; |
| 583 const float kTranslateX = 10.6f; | 589 const float kTranslateX = 10.6f; |
| 584 const float kTranslateY = 20.6f; | 590 const float kTranslateY = 20.6f; |
| 585 arbitrary_translate.Translate(kTranslateX, kTranslateY); | 591 arbitrary_translate.Translate(kTranslateX, kTranslateY); |
| 586 scroll_layer->test_properties()->transform = arbitrary_translate; | 592 scroll_layer->test_properties()->transform = arbitrary_translate; |
| 587 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; | 593 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 588 ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale, | 594 ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale, |
| 589 scroll_layer->test_properties()->parent, | 595 scroll_layer->test_properties()->parent, |
| 590 nullptr); | 596 nullptr, nullptr); |
| 591 expected_transform.MakeIdentity(); | 597 expected_transform.MakeIdentity(); |
| 592 expected_transform.Translate( | 598 expected_transform.Translate( |
| 593 MathUtil::Round(kTranslateX * page_scale * kDeviceScale + | 599 MathUtil::Round(kTranslateX * page_scale * kDeviceScale + |
| 594 sub_layer_screen_position.x() * page_scale * | 600 sub_layer_screen_position.x() * page_scale * |
| 595 kDeviceScale), | 601 kDeviceScale), |
| 596 MathUtil::Round(kTranslateY * page_scale * kDeviceScale + | 602 MathUtil::Round(kTranslateY * page_scale * kDeviceScale + |
| 597 sub_layer_screen_position.y() * page_scale * | 603 sub_layer_screen_position.y() * page_scale * |
| 598 kDeviceScale)); | 604 kDeviceScale)); |
| 599 expected_transform.Scale(page_scale * kDeviceScale, | 605 expected_transform.Scale(page_scale * kDeviceScale, |
| 600 page_scale * kDeviceScale); | 606 page_scale * kDeviceScale); |
| 601 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, | 607 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
| 602 sublayer->DrawTransform()); | 608 sublayer->DrawTransform()); |
| 603 | 609 |
| 604 // Test that page scale is updated even when we don't rebuild property trees. | 610 // Test that page scale is updated even when we don't rebuild property trees. |
| 605 page_scale = 1.888f; | 611 page_scale = 1.888f; |
| 606 root_layer->layer_tree_impl()->SetViewportLayersFromIds( | 612 root_layer->layer_tree_impl()->SetViewportLayersFromIds( |
| 607 Layer::INVALID_ID, scroll_layer->test_properties()->parent->id(), | 613 Layer::INVALID_ID, scroll_layer->test_properties()->parent->id(), |
| 608 Layer::INVALID_ID, Layer::INVALID_ID); | 614 Layer::INVALID_ID, Layer::INVALID_ID); |
| 609 root_layer->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale); | 615 root_layer->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale); |
| 610 EXPECT_FALSE(root_layer->layer_tree_impl()->property_trees()->needs_rebuild); | 616 EXPECT_FALSE(root_layer->layer_tree_impl()->property_trees()->needs_rebuild); |
| 611 ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale, | 617 ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale, |
| 612 scroll_layer->test_properties()->parent, | 618 scroll_layer->test_properties()->parent, |
| 613 nullptr); | 619 nullptr, nullptr); |
| 614 | 620 |
| 615 expected_transform.MakeIdentity(); | 621 expected_transform.MakeIdentity(); |
| 616 expected_transform.Translate( | 622 expected_transform.Translate( |
| 617 MathUtil::Round(kTranslateX * page_scale * kDeviceScale + | 623 MathUtil::Round(kTranslateX * page_scale * kDeviceScale + |
| 618 sub_layer_screen_position.x() * page_scale * | 624 sub_layer_screen_position.x() * page_scale * |
| 619 kDeviceScale), | 625 kDeviceScale), |
| 620 MathUtil::Round(kTranslateY * page_scale * kDeviceScale + | 626 MathUtil::Round(kTranslateY * page_scale * kDeviceScale + |
| 621 sub_layer_screen_position.y() * page_scale * | 627 sub_layer_screen_position.y() * page_scale * |
| 622 kDeviceScale)); | 628 kDeviceScale)); |
| 623 expected_transform.Scale(page_scale * kDeviceScale, | 629 expected_transform.Scale(page_scale * kDeviceScale, |
| (...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1113 child->test_properties()->transform = child_transform; | 1119 child->test_properties()->transform = child_transform; |
| 1114 child->SetBounds(gfx::Size(10, 10)); | 1120 child->SetBounds(gfx::Size(10, 10)); |
| 1115 grand_child->test_properties()->transform = grand_child_transform; | 1121 grand_child->test_properties()->transform = grand_child_transform; |
| 1116 grand_child->SetBounds(gfx::Size(100, 100)); | 1122 grand_child->SetBounds(gfx::Size(100, 100)); |
| 1117 grand_child->test_properties()->should_flatten_transform = false; | 1123 grand_child->test_properties()->should_flatten_transform = false; |
| 1118 grand_child->SetDrawsContent(true); | 1124 grand_child->SetDrawsContent(true); |
| 1119 float device_scale_factor = 1.f; | 1125 float device_scale_factor = 1.f; |
| 1120 float page_scale_factor = 1.f; | 1126 float page_scale_factor = 1.f; |
| 1121 LayerImpl* page_scale_layer = nullptr; | 1127 LayerImpl* page_scale_layer = nullptr; |
| 1122 LayerImpl* inner_viewport_scroll_layer = nullptr; | 1128 LayerImpl* inner_viewport_scroll_layer = nullptr; |
| 1129 LayerImpl* outer_viewport_scroll_layer = nullptr; |
| 1123 // Visible rects computed by combining clips in target space and root space | 1130 // Visible rects computed by combining clips in target space and root space |
| 1124 // don't match because of rotation transforms. So, we skip | 1131 // don't match because of rotation transforms. So, we skip |
| 1125 // verify_visible_rect_calculations. | 1132 // verify_visible_rect_calculations. |
| 1126 bool skip_verify_visible_rect_calculations = true; | 1133 bool skip_verify_visible_rect_calculations = true; |
| 1127 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, | 1134 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, |
| 1128 page_scale_layer, inner_viewport_scroll_layer, | 1135 page_scale_layer, inner_viewport_scroll_layer, |
| 1136 outer_viewport_scroll_layer, |
| 1129 skip_verify_visible_rect_calculations); | 1137 skip_verify_visible_rect_calculations); |
| 1130 | 1138 |
| 1131 // Mapping grand_child's bounds to target space produces a non-empty rect | 1139 // Mapping grand_child's bounds to target space produces a non-empty rect |
| 1132 // that is fully contained within the target's bounds, so grand_child should | 1140 // that is fully contained within the target's bounds, so grand_child should |
| 1133 // be considered fully visible. | 1141 // be considered fully visible. |
| 1134 EXPECT_EQ(gfx::Rect(grand_child->bounds()), | 1142 EXPECT_EQ(gfx::Rect(grand_child->bounds()), |
| 1135 grand_child->visible_layer_rect()); | 1143 grand_child->visible_layer_rect()); |
| 1136 } | 1144 } |
| 1137 | 1145 |
| 1138 TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) { | 1146 TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) { |
| (...skipping 3418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4557 scale_surface->test_properties()->force_render_surface = true; | 4565 scale_surface->test_properties()->force_render_surface = true; |
| 4558 | 4566 |
| 4559 float device_scale_factor = 2.5f; | 4567 float device_scale_factor = 2.5f; |
| 4560 float page_scale_factor = 3.f; | 4568 float page_scale_factor = 3.f; |
| 4561 root->layer_tree_impl()->SetViewportLayersFromIds( | 4569 root->layer_tree_impl()->SetViewportLayersFromIds( |
| 4562 Layer::INVALID_ID, page_scale->id(), Layer::INVALID_ID, | 4570 Layer::INVALID_ID, page_scale->id(), Layer::INVALID_ID, |
| 4563 Layer::INVALID_ID); | 4571 Layer::INVALID_ID); |
| 4564 root->layer_tree_impl()->BuildLayerListAndPropertyTreesForTesting(); | 4572 root->layer_tree_impl()->BuildLayerListAndPropertyTreesForTesting(); |
| 4565 root->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale_factor); | 4573 root->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale_factor); |
| 4566 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, | 4574 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, |
| 4567 root, nullptr); | 4575 root, nullptr, nullptr); |
| 4568 | 4576 |
| 4569 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor, | 4577 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor, |
| 4570 parent->GetIdealContentsScale()); | 4578 parent->GetIdealContentsScale()); |
| 4571 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor, | 4579 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor, |
| 4572 perspective_surface->GetIdealContentsScale()); | 4580 perspective_surface->GetIdealContentsScale()); |
| 4573 // Ideal scale is the max 2d scale component of the combined transform up to | 4581 // Ideal scale is the max 2d scale component of the combined transform up to |
| 4574 // the nearest render target. Here this includes the layer transform as well | 4582 // the nearest render target. Here this includes the layer transform as well |
| 4575 // as the device and page scale factors. | 4583 // as the device and page scale factors. |
| 4576 gfx::Transform transform = scale_small_matrix; | 4584 gfx::Transform transform = scale_small_matrix; |
| 4577 transform.Scale(device_scale_factor * page_scale_factor, | 4585 transform.Scale(device_scale_factor * page_scale_factor, |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4643 child_scale->SetPosition(gfx::PointF(2.f, 2.f)); | 4651 child_scale->SetPosition(gfx::PointF(2.f, 2.f)); |
| 4644 child_scale->SetBounds(gfx::Size(10, 10)); | 4652 child_scale->SetBounds(gfx::Size(10, 10)); |
| 4645 child_scale->test_properties()->transform = child_scale_matrix; | 4653 child_scale->test_properties()->transform = child_scale_matrix; |
| 4646 child_scale->SetDrawsContent(true); | 4654 child_scale->SetDrawsContent(true); |
| 4647 | 4655 |
| 4648 float device_scale_factor = 2.5f; | 4656 float device_scale_factor = 2.5f; |
| 4649 float page_scale_factor = 0.01f; | 4657 float page_scale_factor = 0.01f; |
| 4650 | 4658 |
| 4651 { | 4659 { |
| 4652 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, | 4660 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, |
| 4653 root, nullptr); | 4661 root, nullptr, nullptr); |
| 4654 | 4662 |
| 4655 // The ideal scale is able to go below 1. | 4663 // The ideal scale is able to go below 1. |
| 4656 float expected_ideal_scale = | 4664 float expected_ideal_scale = |
| 4657 device_scale_factor * page_scale_factor * initial_parent_scale; | 4665 device_scale_factor * page_scale_factor * initial_parent_scale; |
| 4658 EXPECT_LT(expected_ideal_scale, 1.f); | 4666 EXPECT_LT(expected_ideal_scale, 1.f); |
| 4659 EXPECT_FLOAT_EQ(expected_ideal_scale, parent->GetIdealContentsScale()); | 4667 EXPECT_FLOAT_EQ(expected_ideal_scale, parent->GetIdealContentsScale()); |
| 4660 | 4668 |
| 4661 expected_ideal_scale = device_scale_factor * page_scale_factor * | 4669 expected_ideal_scale = device_scale_factor * page_scale_factor * |
| 4662 initial_parent_scale * initial_child_scale; | 4670 initial_parent_scale * initial_child_scale; |
| 4663 EXPECT_LT(expected_ideal_scale, 1.f); | 4671 EXPECT_LT(expected_ideal_scale, 1.f); |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5010 LayerImpl* root_ = nullptr; | 5018 LayerImpl* root_ = nullptr; |
| 5011 LayerImpl* child_ = nullptr; | 5019 LayerImpl* child_ = nullptr; |
| 5012 LayerImpl* grand_child_ = nullptr; | 5020 LayerImpl* grand_child_ = nullptr; |
| 5013 }; | 5021 }; |
| 5014 | 5022 |
| 5015 TEST_P(LCDTextTest, CanUseLCDText) { | 5023 TEST_P(LCDTextTest, CanUseLCDText) { |
| 5016 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; | 5024 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
| 5017 bool expect_not_lcd_text = layers_always_allowed_lcd_text_; | 5025 bool expect_not_lcd_text = layers_always_allowed_lcd_text_; |
| 5018 | 5026 |
| 5019 // Case 1: Identity transform. | 5027 // Case 1: Identity transform. |
| 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_lcd_text, child_->CanUseLCDText()); | 5030 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 5023 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); | 5031 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
| 5024 | 5032 |
| 5025 // Case 2: Integral translation. | 5033 // Case 2: Integral translation. |
| 5026 gfx::Transform integral_translation; | 5034 gfx::Transform integral_translation; |
| 5027 integral_translation.Translate(1.0, 2.0); | 5035 integral_translation.Translate(1.0, 2.0); |
| 5028 child_->test_properties()->transform = integral_translation; | 5036 child_->test_properties()->transform = integral_translation; |
| 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_lcd_text, child_->CanUseLCDText()); | 5040 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 5033 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); | 5041 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
| 5034 | 5042 |
| 5035 // Case 3: Non-integral translation. | 5043 // Case 3: Non-integral translation. |
| 5036 gfx::Transform non_integral_translation; | 5044 gfx::Transform non_integral_translation; |
| 5037 non_integral_translation.Translate(1.5, 2.5); | 5045 non_integral_translation.Translate(1.5, 2.5); |
| 5038 child_->test_properties()->transform = non_integral_translation; | 5046 child_->test_properties()->transform = non_integral_translation; |
| 5039 child_->layer_tree_impl()->property_trees()->needs_rebuild = true; | 5047 child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 5040 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr); | 5048 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
| 5041 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); | 5049 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5042 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); | 5050 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5043 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); | 5051 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
| 5044 | 5052 |
| 5045 // Case 4: Rotation. | 5053 // Case 4: Rotation. |
| 5046 gfx::Transform rotation; | 5054 gfx::Transform rotation; |
| 5047 rotation.Rotate(10.0); | 5055 rotation.Rotate(10.0); |
| 5048 child_->test_properties()->transform = rotation; | 5056 child_->test_properties()->transform = rotation; |
| 5049 child_->layer_tree_impl()->property_trees()->needs_rebuild = true; | 5057 child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 5050 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr); | 5058 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
| 5051 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); | 5059 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5052 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); | 5060 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5053 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); | 5061 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
| 5054 | 5062 |
| 5055 // Case 5: Scale. | 5063 // Case 5: Scale. |
| 5056 gfx::Transform scale; | 5064 gfx::Transform scale; |
| 5057 scale.Scale(2.0, 2.0); | 5065 scale.Scale(2.0, 2.0); |
| 5058 child_->test_properties()->transform = scale; | 5066 child_->test_properties()->transform = scale; |
| 5059 child_->layer_tree_impl()->property_trees()->needs_rebuild = true; | 5067 child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 5060 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr); | 5068 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
| 5061 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); | 5069 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5062 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); | 5070 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5063 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); | 5071 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
| 5064 | 5072 |
| 5065 // Case 6: Skew. | 5073 // Case 6: Skew. |
| 5066 gfx::Transform skew; | 5074 gfx::Transform skew; |
| 5067 skew.Skew(10.0, 0.0); | 5075 skew.Skew(10.0, 0.0); |
| 5068 child_->test_properties()->transform = skew; | 5076 child_->test_properties()->transform = skew; |
| 5069 child_->layer_tree_impl()->property_trees()->needs_rebuild = true; | 5077 child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 5070 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr); | 5078 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
| 5071 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); | 5079 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5072 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); | 5080 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5073 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); | 5081 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
| 5074 | 5082 |
| 5075 // Case 7: Translucent. | 5083 // Case 7: Translucent. |
| 5076 child_->test_properties()->transform = gfx::Transform(); | 5084 child_->test_properties()->transform = gfx::Transform(); |
| 5077 child_->layer_tree_impl()->property_trees()->needs_rebuild = true; | 5085 child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 5078 child_->test_properties()->opacity = 0.5f; | 5086 child_->test_properties()->opacity = 0.5f; |
| 5079 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr); | 5087 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
| 5080 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); | 5088 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5081 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); | 5089 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5082 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); | 5090 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
| 5083 | 5091 |
| 5084 // Case 8: Sanity check: restore transform and opacity. | 5092 // Case 8: Sanity check: restore transform and opacity. |
| 5085 child_->test_properties()->transform = gfx::Transform(); | 5093 child_->test_properties()->transform = gfx::Transform(); |
| 5086 child_->layer_tree_impl()->property_trees()->needs_rebuild = true; | 5094 child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 5087 child_->test_properties()->opacity = 1.f; | 5095 child_->test_properties()->opacity = 1.f; |
| 5088 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr); | 5096 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
| 5089 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); | 5097 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5090 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); | 5098 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 5091 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); | 5099 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
| 5092 | 5100 |
| 5093 // Case 9: Non-opaque content. | 5101 // Case 9: Non-opaque content. |
| 5094 child_->SetContentsOpaque(false); | 5102 child_->SetContentsOpaque(false); |
| 5095 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr); | 5103 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
| 5096 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); | 5104 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5097 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); | 5105 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5098 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); | 5106 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
| 5099 | 5107 |
| 5100 // Case 10: Sanity check: restore content opaqueness. | 5108 // Case 10: Sanity check: restore content opaqueness. |
| 5101 child_->SetContentsOpaque(true); | 5109 child_->SetContentsOpaque(true); |
| 5102 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr); | 5110 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
| 5103 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); | 5111 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5104 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); | 5112 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 5105 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); | 5113 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
| 5106 } | 5114 } |
| 5107 | 5115 |
| 5108 TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) { | 5116 TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) { |
| 5109 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; | 5117 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
| 5110 bool expect_not_lcd_text = layers_always_allowed_lcd_text_; | 5118 bool expect_not_lcd_text = layers_always_allowed_lcd_text_; |
| 5111 | 5119 |
| 5112 // Sanity check: Make sure can_use_lcd_text_ is set on each node. | 5120 // Sanity check: Make sure can_use_lcd_text_ is set on each node. |
| 5113 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr); | 5121 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
| 5114 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); | 5122 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5115 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); | 5123 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 5116 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); | 5124 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
| 5117 | 5125 |
| 5118 // Add opacity animation. | 5126 // Add opacity animation. |
| 5119 child_->test_properties()->opacity = 0.9f; | 5127 child_->test_properties()->opacity = 0.9f; |
| 5120 child_->layer_tree_impl()->property_trees()->needs_rebuild = true; | 5128 child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 5121 | 5129 |
| 5122 SetElementIdsForTesting(); | 5130 SetElementIdsForTesting(); |
| 5123 | 5131 |
| 5124 AddOpacityTransitionToElementWithPlayer(child_->element_id(), timeline(), | 5132 AddOpacityTransitionToElementWithPlayer(child_->element_id(), timeline(), |
| 5125 10.0, 0.9f, 0.1f, false); | 5133 10.0, 0.9f, 0.1f, false); |
| 5126 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr); | 5134 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
| 5127 // Text LCD should be adjusted while animation is active. | 5135 // Text LCD should be adjusted while animation is active. |
| 5128 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); | 5136 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5129 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); | 5137 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5130 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); | 5138 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
| 5131 } | 5139 } |
| 5132 | 5140 |
| 5133 TEST_P(LCDTextTest, CanUseLCDTextWithAnimationContentsOpaque) { | 5141 TEST_P(LCDTextTest, CanUseLCDTextWithAnimationContentsOpaque) { |
| 5134 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; | 5142 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
| 5135 bool expect_not_lcd_text = layers_always_allowed_lcd_text_; | 5143 bool expect_not_lcd_text = layers_always_allowed_lcd_text_; |
| 5136 | 5144 |
| 5137 // Sanity check: Make sure can_use_lcd_text_ is set on each node. | 5145 // Sanity check: Make sure can_use_lcd_text_ is set on each node. |
| 5138 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr); | 5146 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
| 5139 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); | 5147 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5140 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); | 5148 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 5141 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); | 5149 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
| 5142 SetElementIdsForTesting(); | 5150 SetElementIdsForTesting(); |
| 5143 | 5151 |
| 5144 // Mark contents non-opaque within the first animation frame. | 5152 // Mark contents non-opaque within the first animation frame. |
| 5145 child_->SetContentsOpaque(false); | 5153 child_->SetContentsOpaque(false); |
| 5146 AddOpacityTransitionToElementWithPlayer(child_->element_id(), timeline(), | 5154 AddOpacityTransitionToElementWithPlayer(child_->element_id(), timeline(), |
| 5147 10.0, 0.9f, 0.1f, false); | 5155 10.0, 0.9f, 0.1f, false); |
| 5148 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr); | 5156 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
| 5149 // LCD text should be disabled for non-opaque layers even during animations. | 5157 // LCD text should be disabled for non-opaque layers even during animations. |
| 5150 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); | 5158 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5151 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); | 5159 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5152 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); | 5160 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
| 5153 } | 5161 } |
| 5154 | 5162 |
| 5155 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, | 5163 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, |
| 5156 LCDTextTest, | 5164 LCDTextTest, |
| 5157 testing::Combine(testing::Bool(), | 5165 testing::Combine(testing::Bool(), |
| 5158 testing::Bool(), | 5166 testing::Bool(), |
| (...skipping 1853 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7012 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); | 7020 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7013 | 7021 |
| 7014 // Once we scroll past its initial location, it sticks there. | 7022 // Once we scroll past its initial location, it sticks there. |
| 7015 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 150.f)); | 7023 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 150.f)); |
| 7016 ExecuteCalculateDrawProperties(root_impl); | 7024 ExecuteCalculateDrawProperties(root_impl); |
| 7017 EXPECT_VECTOR2DF_EQ( | 7025 EXPECT_VECTOR2DF_EQ( |
| 7018 gfx::Vector2dF(0.f, 0.f), | 7026 gfx::Vector2dF(0.f, 0.f), |
| 7019 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); | 7027 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7020 } | 7028 } |
| 7021 | 7029 |
| 7022 TEST_F(LayerTreeHostCommonTest, StickyPositionBottomHideBrowserControls) { | 7030 TEST_F(LayerTreeHostCommonTest, StickyPositionBottomInnerViewportDelta) { |
| 7023 scoped_refptr<Layer> root = Layer::Create(); | 7031 scoped_refptr<Layer> root = Layer::Create(); |
| 7024 scoped_refptr<Layer> scroller = Layer::Create(); | 7032 scoped_refptr<Layer> scroller = Layer::Create(); |
| 7025 scoped_refptr<Layer> sticky_pos = Layer::Create(); | 7033 scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 7026 root->AddChild(scroller); | 7034 root->AddChild(scroller); |
| 7027 scroller->AddChild(sticky_pos); | 7035 scroller->AddChild(sticky_pos); |
| 7028 host()->SetRootLayer(root); | 7036 host()->SetRootLayer(root); |
| 7029 scroller->SetScrollClipLayerId(root->id()); | 7037 scroller->SetScrollClipLayerId(root->id()); |
| 7030 host()->GetLayerTree()->RegisterViewportLayers(nullptr, root, scroller, | 7038 host()->GetLayerTree()->RegisterViewportLayers(nullptr, root, scroller, |
| 7031 nullptr); | 7039 nullptr); |
| 7032 | 7040 |
| 7033 LayerStickyPositionConstraint sticky_position; | 7041 LayerStickyPositionConstraint sticky_position; |
| 7034 sticky_position.is_sticky = true; | 7042 sticky_position.is_sticky = true; |
| 7035 sticky_position.is_anchored_bottom = true; | 7043 sticky_position.is_anchored_bottom = true; |
| 7036 sticky_position.bottom_offset = 10.0f; | 7044 sticky_position.bottom_offset = 10.0f; |
| 7037 sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 150); | 7045 sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 70); |
| 7038 sticky_position.scroll_container_relative_sticky_box_rect = | 7046 sticky_position.scroll_container_relative_sticky_box_rect = |
| 7039 gfx::Rect(0, 150, 10, 10); | 7047 gfx::Rect(0, 70, 10, 10); |
| 7040 sticky_position.scroll_container_relative_containing_block_rect = | 7048 sticky_position.scroll_container_relative_containing_block_rect = |
| 7041 gfx::Rect(0, 0, 100, 1000); | 7049 gfx::Rect(0, 60, 100, 100); |
| 7042 sticky_pos->SetStickyPositionConstraint(sticky_position); | 7050 sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 7043 | 7051 |
| 7044 root->SetBounds(gfx::Size(100, 100)); | 7052 root->SetBounds(gfx::Size(100, 100)); |
| 7045 scroller->SetBounds(gfx::Size(100, 1000)); | 7053 scroller->SetBounds(gfx::Size(100, 1000)); |
| 7046 sticky_pos->SetBounds(gfx::Size(10, 10)); | 7054 sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 7047 sticky_pos->SetPosition(gfx::PointF(0, 150)); | 7055 sticky_pos->SetPosition(gfx::PointF(0, 70)); |
| 7048 | 7056 |
| 7049 ExecuteCalculateDrawProperties(root.get(), 1.f, 1.f, root.get(), | 7057 ExecuteCalculateDrawProperties(root.get(), 1.f, 1.f, root.get(), |
| 7050 scroller.get()); | 7058 scroller.get(), nullptr); |
| 7051 host()->CommitAndCreateLayerImplTree(); | 7059 host()->CommitAndCreateLayerImplTree(); |
| 7052 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); | 7060 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 7053 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); | 7061 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 7054 ASSERT_EQ(scroller->id(), layer_tree_impl->InnerViewportScrollLayer()->id()); | 7062 ASSERT_EQ(scroller->id(), layer_tree_impl->InnerViewportScrollLayer()->id()); |
| 7055 | 7063 |
| 7056 LayerImpl* inner_scroll = layer_tree_impl->InnerViewportScrollLayer(); | 7064 LayerImpl* inner_scroll = layer_tree_impl->InnerViewportScrollLayer(); |
| 7057 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); | 7065 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 7058 | 7066 |
| 7059 // Initially the sticky element is moved to the bottom of the container. | 7067 // Initially the sticky element is moved to the bottom of the container. |
| 7060 EXPECT_VECTOR2DF_EQ( | 7068 EXPECT_VECTOR2DF_EQ( |
| 7061 gfx::Vector2dF(0.f, 80.f), | 7069 gfx::Vector2dF(0.f, 70.f), |
| 7062 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); | 7070 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7063 | 7071 |
| 7064 // When we show the toolbar we hide part of the scroll container, this should | 7072 // We start to hide the toolbar, but not far enough that the sticky element |
| 7065 // move the sticky element up to remain at the bottom of the clipped | 7073 // should be moved up yet. |
| 7066 // container. | |
| 7067 root_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -10.f)); | 7074 root_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -10.f)); |
| 7068 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll); | 7075 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, |
| 7076 nullptr); |
| 7069 EXPECT_VECTOR2DF_EQ( | 7077 EXPECT_VECTOR2DF_EQ( |
| 7070 gfx::Vector2dF(0.f, 70.f), | 7078 gfx::Vector2dF(0.f, 70.f), |
| 7071 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); | 7079 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7080 |
| 7081 // On hiding more of the toolbar the sticky element starts to stick. |
| 7082 root_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -20.f)); |
| 7083 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, |
| 7084 nullptr); |
| 7085 EXPECT_VECTOR2DF_EQ( |
| 7086 gfx::Vector2dF(0.f, 60.f), |
| 7087 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7088 |
| 7089 // On hiding more the sticky element stops moving as it has reached its |
| 7090 // limit. |
| 7091 root_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -30.f)); |
| 7092 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, |
| 7093 nullptr); |
| 7094 EXPECT_VECTOR2DF_EQ( |
| 7095 gfx::Vector2dF(0.f, 60.f), |
| 7096 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7097 } |
| 7098 |
| 7099 TEST_F(LayerTreeHostCommonTest, StickyPositionBottomOuterViewportDelta) { |
| 7100 scoped_refptr<Layer> root = Layer::Create(); |
| 7101 scoped_refptr<Layer> scroller = Layer::Create(); |
| 7102 scoped_refptr<Layer> outer_clip = Layer::Create(); |
| 7103 scoped_refptr<Layer> outer_viewport = Layer::Create(); |
| 7104 scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 7105 root->AddChild(scroller); |
| 7106 scroller->AddChild(outer_clip); |
| 7107 outer_clip->AddChild(outer_viewport); |
| 7108 outer_viewport->AddChild(sticky_pos); |
| 7109 host()->SetRootLayer(root); |
| 7110 scroller->SetScrollClipLayerId(root->id()); |
| 7111 outer_viewport->SetScrollClipLayerId(outer_clip->id()); |
| 7112 host()->GetLayerTree()->RegisterViewportLayers(nullptr, root, scroller, |
| 7113 outer_viewport); |
| 7114 |
| 7115 LayerStickyPositionConstraint sticky_position; |
| 7116 sticky_position.is_sticky = true; |
| 7117 sticky_position.is_anchored_bottom = true; |
| 7118 sticky_position.bottom_offset = 10.0f; |
| 7119 sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 70); |
| 7120 sticky_position.scroll_container_relative_sticky_box_rect = |
| 7121 gfx::Rect(0, 70, 10, 10); |
| 7122 sticky_position.scroll_container_relative_containing_block_rect = |
| 7123 gfx::Rect(0, 60, 100, 100); |
| 7124 sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 7125 |
| 7126 root->SetBounds(gfx::Size(100, 100)); |
| 7127 scroller->SetBounds(gfx::Size(100, 1000)); |
| 7128 outer_clip->SetBounds(gfx::Size(100, 100)); |
| 7129 sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 7130 sticky_pos->SetPosition(gfx::PointF(0, 70)); |
| 7131 |
| 7132 ExecuteCalculateDrawProperties(root.get(), 1.f, 1.f, root.get(), |
| 7133 scroller.get(), outer_viewport.get()); |
| 7134 host()->CommitAndCreateLayerImplTree(); |
| 7135 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 7136 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 7137 ASSERT_EQ(outer_viewport->id(), |
| 7138 layer_tree_impl->OuterViewportScrollLayer()->id()); |
| 7139 |
| 7140 LayerImpl* inner_scroll = layer_tree_impl->InnerViewportScrollLayer(); |
| 7141 LayerImpl* outer_scroll = layer_tree_impl->OuterViewportScrollLayer(); |
| 7142 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 7143 LayerImpl* outer_clip_impl = layer_tree_impl->LayerById(outer_clip->id()); |
| 7144 |
| 7145 // Initially the sticky element is moved to the bottom of the container. |
| 7146 EXPECT_VECTOR2DF_EQ( |
| 7147 gfx::Vector2dF(0.f, 70.f), |
| 7148 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7149 |
| 7150 // We start to hide the toolbar, but not far enough that the sticky element |
| 7151 // should be moved up yet. |
| 7152 outer_clip_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -10.f)); |
| 7153 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, |
| 7154 outer_scroll); |
| 7155 EXPECT_VECTOR2DF_EQ( |
| 7156 gfx::Vector2dF(0.f, 70.f), |
| 7157 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7158 |
| 7159 // On hiding more of the toolbar the sticky element starts to stick. |
| 7160 outer_clip_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -20.f)); |
| 7161 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, |
| 7162 outer_scroll); |
| 7163 |
| 7164 // On hiding more the sticky element stops moving as it has reached its |
| 7165 // limit. |
| 7166 EXPECT_VECTOR2DF_EQ( |
| 7167 gfx::Vector2dF(0.f, 60.f), |
| 7168 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7169 |
| 7170 outer_clip_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -30.f)); |
| 7171 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, |
| 7172 outer_scroll); |
| 7173 |
| 7174 EXPECT_VECTOR2DF_EQ( |
| 7175 gfx::Vector2dF(0.f, 60.f), |
| 7176 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7072 } | 7177 } |
| 7073 | 7178 |
| 7074 TEST_F(LayerTreeHostCommonTest, StickyPositionLeftRight) { | 7179 TEST_F(LayerTreeHostCommonTest, StickyPositionLeftRight) { |
| 7075 scoped_refptr<Layer> root = Layer::Create(); | 7180 scoped_refptr<Layer> root = Layer::Create(); |
| 7076 scoped_refptr<Layer> container = Layer::Create(); | 7181 scoped_refptr<Layer> container = Layer::Create(); |
| 7077 scoped_refptr<Layer> scroller = Layer::Create(); | 7182 scoped_refptr<Layer> scroller = Layer::Create(); |
| 7078 scoped_refptr<Layer> sticky_pos = Layer::Create(); | 7183 scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 7079 root->AddChild(container); | 7184 root->AddChild(container); |
| 7080 container->AddChild(scroller); | 7185 container->AddChild(scroller); |
| 7081 scroller->AddChild(sticky_pos); | 7186 scroller->AddChild(sticky_pos); |
| (...skipping 2310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9392 render_surface->test_properties()->transform = transform2; | 9497 render_surface->test_properties()->transform = transform2; |
| 9393 render_surface->SetBounds(gfx::Size(30, 30)); | 9498 render_surface->SetBounds(gfx::Size(30, 30)); |
| 9394 render_surface->test_properties()->force_render_surface = true; | 9499 render_surface->test_properties()->force_render_surface = true; |
| 9395 test_layer->SetBounds(gfx::Size(30, 30)); | 9500 test_layer->SetBounds(gfx::Size(30, 30)); |
| 9396 test_layer->SetDrawsContent(true); | 9501 test_layer->SetDrawsContent(true); |
| 9397 | 9502 |
| 9398 float device_scale_factor = 1.f; | 9503 float device_scale_factor = 1.f; |
| 9399 float page_scale_factor = 1.f; | 9504 float page_scale_factor = 1.f; |
| 9400 LayerImpl* page_scale_layer = nullptr; | 9505 LayerImpl* page_scale_layer = nullptr; |
| 9401 LayerImpl* inner_viewport_scroll_layer = nullptr; | 9506 LayerImpl* inner_viewport_scroll_layer = nullptr; |
| 9507 LayerImpl* outer_viewport_scroll_layer = nullptr; |
| 9402 // Visible rects computed by combining clips in target space and root space | 9508 // Visible rects computed by combining clips in target space and root space |
| 9403 // don't match because of rotation transforms. So, we skip | 9509 // don't match because of rotation transforms. So, we skip |
| 9404 // verify_visible_rect_calculations. | 9510 // verify_visible_rect_calculations. |
| 9405 bool skip_verify_visible_rect_calculations = true; | 9511 bool skip_verify_visible_rect_calculations = true; |
| 9406 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, | 9512 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, |
| 9407 page_scale_layer, inner_viewport_scroll_layer, | 9513 page_scale_layer, inner_viewport_scroll_layer, |
| 9514 outer_viewport_scroll_layer, |
| 9408 skip_verify_visible_rect_calculations); | 9515 skip_verify_visible_rect_calculations); |
| 9409 | 9516 |
| 9410 TransformTree& transform_tree = | 9517 TransformTree& transform_tree = |
| 9411 root->layer_tree_impl()->property_trees()->transform_tree; | 9518 root->layer_tree_impl()->property_trees()->transform_tree; |
| 9412 TransformNode* transform_node = | 9519 TransformNode* transform_node = |
| 9413 transform_tree.Node(significant_transform->transform_tree_index()); | 9520 transform_tree.Node(significant_transform->transform_tree_index()); |
| 9414 EXPECT_EQ(transform_node->owner_id, significant_transform->id()); | 9521 EXPECT_EQ(transform_node->owner_id, significant_transform->id()); |
| 9415 | 9522 |
| 9416 EXPECT_TRUE(root->has_render_surface()); | 9523 EXPECT_TRUE(root->has_render_surface()); |
| 9417 EXPECT_FALSE(significant_transform->has_render_surface()); | 9524 EXPECT_FALSE(significant_transform->has_render_surface()); |
| (...skipping 962 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10380 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index()); | 10487 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index()); |
| 10381 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index()); | 10488 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index()); |
| 10382 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index()); | 10489 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index()); |
| 10383 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index()); | 10490 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index()); |
| 10384 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index()); | 10491 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index()); |
| 10385 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index()); | 10492 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index()); |
| 10386 } | 10493 } |
| 10387 | 10494 |
| 10388 } // namespace | 10495 } // namespace |
| 10389 } // namespace cc | 10496 } // namespace cc |
| OLD | NEW |