| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 #include "ui/gfx/geometry/quad_f.h" | 55 #include "ui/gfx/geometry/quad_f.h" |
| 56 #include "ui/gfx/geometry/vector2d_conversions.h" | 56 #include "ui/gfx/geometry/vector2d_conversions.h" |
| 57 #include "ui/gfx/transform.h" | 57 #include "ui/gfx/transform.h" |
| 58 | 58 |
| 59 namespace cc { | 59 namespace cc { |
| 60 namespace { | 60 namespace { |
| 61 | 61 |
| 62 class VerifyTreeCalcsLayerTreeSettings : public LayerTreeSettings { | 62 class VerifyTreeCalcsLayerTreeSettings : public LayerTreeSettings { |
| 63 public: | 63 public: |
| 64 VerifyTreeCalcsLayerTreeSettings() { | 64 VerifyTreeCalcsLayerTreeSettings() { |
| 65 verify_clip_tree_calculations = true; | |
| 66 } | 65 } |
| 67 }; | 66 }; |
| 68 | 67 |
| 69 class LayerTreeHostCommonTestBase : public LayerTestCommon::LayerImplTest { | 68 class LayerTreeHostCommonTestBase : public LayerTestCommon::LayerImplTest { |
| 70 public: | 69 public: |
| 71 LayerTreeHostCommonTestBase() | 70 LayerTreeHostCommonTestBase() |
| 72 : LayerTestCommon::LayerImplTest(VerifyTreeCalcsLayerTreeSettings()) {} | 71 : LayerTestCommon::LayerImplTest(VerifyTreeCalcsLayerTreeSettings()) {} |
| 73 explicit LayerTreeHostCommonTestBase(const LayerTreeSettings& settings) | 72 explicit LayerTreeHostCommonTestBase(const LayerTreeSettings& settings) |
| 74 : LayerTestCommon::LayerImplTest(settings) {} | 73 : LayerTestCommon::LayerImplTest(settings) {} |
| 75 | 74 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | 116 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 118 root_layer, device_viewport_size); | 117 root_layer, device_viewport_size); |
| 119 inputs.device_scale_factor = device_scale_factor; | 118 inputs.device_scale_factor = device_scale_factor; |
| 120 inputs.page_scale_factor = page_scale_factor; | 119 inputs.page_scale_factor = page_scale_factor; |
| 121 inputs.page_scale_layer = page_scale_layer; | 120 inputs.page_scale_layer = page_scale_layer; |
| 122 inputs.inner_viewport_scroll_layer = inner_viewport_scroll_layer; | 121 inputs.inner_viewport_scroll_layer = inner_viewport_scroll_layer; |
| 123 inputs.outer_viewport_scroll_layer = outer_viewport_scroll_layer; | 122 inputs.outer_viewport_scroll_layer = outer_viewport_scroll_layer; |
| 124 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); | 123 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
| 125 } | 124 } |
| 126 | 125 |
| 127 void ExecuteCalculateDrawProperties( | 126 void ExecuteCalculateDrawProperties(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, | 131 LayerImpl* outer_viewport_scroll_layer) { |
| 133 LayerImpl* outer_viewport_scroll_layer, | |
| 134 bool skip_verify_visible_rect_calculations = false) { | |
| 135 if (device_scale_factor != | 132 if (device_scale_factor != |
| 136 root_layer->layer_tree_impl()->device_scale_factor()) | 133 root_layer->layer_tree_impl()->device_scale_factor()) |
| 137 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; | 134 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 138 | 135 |
| 139 root_layer->layer_tree_impl()->SetDeviceScaleFactor(device_scale_factor); | 136 root_layer->layer_tree_impl()->SetDeviceScaleFactor(device_scale_factor); |
| 140 | 137 |
| 141 EXPECT_TRUE(page_scale_layer || (page_scale_factor == 1.f)); | 138 EXPECT_TRUE(page_scale_layer || (page_scale_factor == 1.f)); |
| 142 | 139 |
| 143 gfx::Size device_viewport_size = | 140 gfx::Size device_viewport_size = |
| 144 gfx::Size(root_layer->bounds().width() * device_scale_factor, | 141 gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 145 root_layer->bounds().height() * device_scale_factor); | 142 root_layer->bounds().height() * device_scale_factor); |
| 146 | 143 |
| 147 render_surface_layer_list_impl_.reset(new LayerImplList); | 144 render_surface_layer_list_impl_.reset(new LayerImplList); |
| 148 | 145 |
| 149 // We are probably not testing what is intended if the root_layer bounds are | 146 // We are probably not testing what is intended if the root_layer bounds are |
| 150 // empty. | 147 // empty. |
| 151 DCHECK(!root_layer->bounds().IsEmpty()); | 148 DCHECK(!root_layer->bounds().IsEmpty()); |
| 152 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( | 149 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 153 root_layer, device_viewport_size, | 150 root_layer, device_viewport_size, |
| 154 render_surface_layer_list_impl_.get()); | 151 render_surface_layer_list_impl_.get()); |
| 155 inputs.device_scale_factor = device_scale_factor; | 152 inputs.device_scale_factor = device_scale_factor; |
| 156 inputs.page_scale_factor = page_scale_factor; | 153 inputs.page_scale_factor = page_scale_factor; |
| 157 inputs.page_scale_layer = page_scale_layer; | 154 inputs.page_scale_layer = page_scale_layer; |
| 158 inputs.inner_viewport_scroll_layer = inner_viewport_scroll_layer; | 155 inputs.inner_viewport_scroll_layer = inner_viewport_scroll_layer; |
| 159 inputs.outer_viewport_scroll_layer = outer_viewport_scroll_layer; | 156 inputs.outer_viewport_scroll_layer = outer_viewport_scroll_layer; |
| 160 inputs.can_adjust_raster_scales = true; | 157 inputs.can_adjust_raster_scales = true; |
| 161 if (skip_verify_visible_rect_calculations) | |
| 162 inputs.verify_visible_rect_calculations = false; | |
| 163 | 158 |
| 164 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); | 159 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
| 165 } | 160 } |
| 166 | 161 |
| 167 template <class LayerType> | 162 template <class LayerType> |
| 168 void ExecuteCalculateDrawProperties(LayerType* root_layer) { | 163 void ExecuteCalculateDrawProperties(LayerType* root_layer) { |
| 169 LayerType* page_scale_application_layer = nullptr; | 164 LayerType* page_scale_application_layer = nullptr; |
| 170 LayerType* inner_viewport_scroll_layer = nullptr; | 165 LayerType* inner_viewport_scroll_layer = nullptr; |
| 171 LayerType* outer_viewport_scroll_layer = nullptr; | 166 LayerType* outer_viewport_scroll_layer = nullptr; |
| 172 ExecuteCalculateDrawProperties( | 167 ExecuteCalculateDrawProperties( |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 elastic_overscroll, page_scale_factor, device_scale_factor, | 212 elastic_overscroll, page_scale_factor, device_scale_factor, |
| 218 gfx::Rect(device_viewport_size), gfx::Transform(), property_trees); | 213 gfx::Rect(device_viewport_size), gfx::Transform(), property_trees); |
| 219 draw_property_utils::UpdatePropertyTrees(root_layer->layer_tree_host(), | 214 draw_property_utils::UpdatePropertyTrees(root_layer->layer_tree_host(), |
| 220 property_trees, | 215 property_trees, |
| 221 can_render_to_separate_surface); | 216 can_render_to_separate_surface); |
| 222 draw_property_utils::FindLayersThatNeedUpdates( | 217 draw_property_utils::FindLayersThatNeedUpdates( |
| 223 root_layer->layer_tree_host(), property_trees, &update_layer_list_); | 218 root_layer->layer_tree_host(), property_trees, &update_layer_list_); |
| 224 } | 219 } |
| 225 | 220 |
| 226 void ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList( | 221 void ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList( |
| 227 LayerImpl* root_layer, | 222 LayerImpl* root_layer) { |
| 228 bool skip_verify_visible_rect_calculations = false) { | |
| 229 DCHECK(root_layer->layer_tree_impl()); | 223 DCHECK(root_layer->layer_tree_impl()); |
| 230 PropertyTreeBuilder::PreCalculateMetaInformationForTesting(root_layer); | 224 PropertyTreeBuilder::PreCalculateMetaInformationForTesting(root_layer); |
| 231 | 225 |
| 232 bool can_render_to_separate_surface = true; | 226 bool can_render_to_separate_surface = true; |
| 233 | 227 |
| 234 LayerImpl* page_scale_layer = nullptr; | 228 const LayerImpl* page_scale_layer = nullptr; |
| 235 LayerImpl* inner_viewport_scroll_layer = | 229 LayerImpl* inner_viewport_scroll_layer = |
| 236 root_layer->layer_tree_impl()->InnerViewportScrollLayer(); | 230 root_layer->layer_tree_impl()->InnerViewportScrollLayer(); |
| 237 LayerImpl* outer_viewport_scroll_layer = | 231 LayerImpl* outer_viewport_scroll_layer = |
| 238 root_layer->layer_tree_impl()->OuterViewportScrollLayer(); | 232 root_layer->layer_tree_impl()->OuterViewportScrollLayer(); |
| 239 LayerImpl* overscroll_elasticity_layer = | 233 const LayerImpl* overscroll_elasticity_layer = |
| 240 root_layer->layer_tree_impl()->OverscrollElasticityLayer(); | 234 root_layer->layer_tree_impl()->OverscrollElasticityLayer(); |
| 241 gfx::Vector2dF elastic_overscroll = | 235 gfx::Vector2dF elastic_overscroll = |
| 242 root_layer->layer_tree_impl()->elastic_overscroll()->Current( | 236 root_layer->layer_tree_impl()->elastic_overscroll()->Current( |
| 243 root_layer->layer_tree_impl()->IsActiveTree()); | 237 root_layer->layer_tree_impl()->IsActiveTree()); |
| 244 float page_scale_factor = 1.f; | 238 float page_scale_factor = 1.f; |
| 245 float device_scale_factor = 1.f; | 239 float device_scale_factor = 1.f; |
| 246 gfx::Size device_viewport_size = | 240 gfx::Size device_viewport_size = |
| 247 gfx::Size(root_layer->bounds().width() * device_scale_factor, | 241 gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 248 root_layer->bounds().height() * device_scale_factor); | 242 root_layer->bounds().height() * device_scale_factor); |
| 249 update_layer_list_impl_.reset(new LayerImplList); | 243 update_layer_list_impl_.reset(new LayerImplList); |
| 250 root_layer->layer_tree_impl()->BuildLayerListForTesting(); | 244 root_layer->layer_tree_impl()->BuildLayerListForTesting(); |
| 251 PropertyTrees* property_trees = | 245 PropertyTrees* property_trees = |
| 252 root_layer->layer_tree_impl()->property_trees(); | 246 root_layer->layer_tree_impl()->property_trees(); |
| 253 draw_property_utils::BuildPropertyTreesAndComputeVisibleRects( | 247 PropertyTreeBuilder::BuildPropertyTrees( |
| 254 root_layer, page_scale_layer, inner_viewport_scroll_layer, | 248 root_layer, page_scale_layer, inner_viewport_scroll_layer, |
| 255 outer_viewport_scroll_layer, overscroll_elasticity_layer, | 249 outer_viewport_scroll_layer, overscroll_elasticity_layer, |
| 256 elastic_overscroll, page_scale_factor, device_scale_factor, | 250 elastic_overscroll, page_scale_factor, device_scale_factor, |
| 257 gfx::Rect(device_viewport_size), gfx::Transform(), | 251 gfx::Rect(device_viewport_size), gfx::Transform(), property_trees); |
| 258 can_render_to_separate_surface, property_trees, | 252 draw_property_utils::UpdatePropertyTreesAndRenderSurfaces( |
| 253 root_layer, property_trees, can_render_to_separate_surface); |
| 254 draw_property_utils::FindLayersThatNeedUpdates( |
| 255 root_layer->layer_tree_impl(), property_trees, |
| 259 update_layer_list_impl_.get()); | 256 update_layer_list_impl_.get()); |
| 260 draw_property_utils::VerifyClipTreeCalculations(*update_layer_list_impl_, | 257 draw_property_utils::ComputeDrawPropertiesOfVisibleLayers( |
| 261 property_trees); | 258 update_layer_list_impl(), property_trees); |
| 262 if (!skip_verify_visible_rect_calculations) | |
| 263 draw_property_utils::VerifyVisibleRectsCalculations( | |
| 264 *update_layer_list_impl_, property_trees); | |
| 265 } | 259 } |
| 266 | 260 |
| 267 void ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces( | 261 void ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces( |
| 268 LayerImpl* root_layer) { | 262 LayerImpl* root_layer) { |
| 269 gfx::Size device_viewport_size = | 263 gfx::Size device_viewport_size = |
| 270 gfx::Size(root_layer->bounds().width(), root_layer->bounds().height()); | 264 gfx::Size(root_layer->bounds().width(), root_layer->bounds().height()); |
| 271 render_surface_layer_list_impl_.reset(new LayerImplList); | 265 render_surface_layer_list_impl_.reset(new LayerImplList); |
| 272 | 266 |
| 273 DCHECK(!root_layer->bounds().IsEmpty()); | 267 DCHECK(!root_layer->bounds().IsEmpty()); |
| 274 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( | 268 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| (...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1119 child->SetBounds(gfx::Size(10, 10)); | 1113 child->SetBounds(gfx::Size(10, 10)); |
| 1120 grand_child->test_properties()->transform = grand_child_transform; | 1114 grand_child->test_properties()->transform = grand_child_transform; |
| 1121 grand_child->SetBounds(gfx::Size(100, 100)); | 1115 grand_child->SetBounds(gfx::Size(100, 100)); |
| 1122 grand_child->test_properties()->should_flatten_transform = false; | 1116 grand_child->test_properties()->should_flatten_transform = false; |
| 1123 grand_child->SetDrawsContent(true); | 1117 grand_child->SetDrawsContent(true); |
| 1124 float device_scale_factor = 1.f; | 1118 float device_scale_factor = 1.f; |
| 1125 float page_scale_factor = 1.f; | 1119 float page_scale_factor = 1.f; |
| 1126 LayerImpl* page_scale_layer = nullptr; | 1120 LayerImpl* page_scale_layer = nullptr; |
| 1127 LayerImpl* inner_viewport_scroll_layer = nullptr; | 1121 LayerImpl* inner_viewport_scroll_layer = nullptr; |
| 1128 LayerImpl* outer_viewport_scroll_layer = nullptr; | 1122 LayerImpl* outer_viewport_scroll_layer = nullptr; |
| 1129 // Visible rects computed by combining clips in target space and root space | |
| 1130 // don't match because of rotation transforms. So, we skip | |
| 1131 // verify_visible_rect_calculations. | |
| 1132 bool skip_verify_visible_rect_calculations = true; | |
| 1133 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, | 1123 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, |
| 1134 page_scale_layer, inner_viewport_scroll_layer, | 1124 page_scale_layer, inner_viewport_scroll_layer, |
| 1135 outer_viewport_scroll_layer, | 1125 outer_viewport_scroll_layer); |
| 1136 skip_verify_visible_rect_calculations); | |
| 1137 | 1126 |
| 1138 // Mapping grand_child's bounds to target space produces a non-empty rect | 1127 // Mapping grand_child's bounds to screen space produces an empty rect so |
| 1139 // that is fully contained within the target's bounds, so grand_child should | 1128 // grand_child should be hidden. |
| 1140 // be considered fully visible. | 1129 EXPECT_EQ(gfx::Rect(), grand_child->visible_layer_rect()); |
| 1141 EXPECT_EQ(gfx::Rect(grand_child->bounds()), | |
| 1142 grand_child->visible_layer_rect()); | |
| 1143 } | 1130 } |
| 1144 | 1131 |
| 1145 TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) { | 1132 TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) { |
| 1146 // A layer that is empty in one axis, but not the other, was accidentally | 1133 // A layer that is empty in one axis, but not the other, was accidentally |
| 1147 // skipping a necessary translation. Without that translation, the coordinate | 1134 // skipping a necessary translation. Without that translation, the coordinate |
| 1148 // space of the layer's draw transform is incorrect. | 1135 // space of the layer's draw transform is incorrect. |
| 1149 // | 1136 // |
| 1150 // Normally this isn't a problem, because the layer wouldn't be drawn anyway, | 1137 // Normally this isn't a problem, because the layer wouldn't be drawn anyway, |
| 1151 // but if that layer becomes a render surface, then its draw transform is | 1138 // but if that layer becomes a render surface, then its draw transform is |
| 1152 // implicitly inherited by the rest of the subtree, which then is positioned | 1139 // implicitly inherited by the rest of the subtree, which then is positioned |
| (...skipping 2826 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3979 render_surface2->test_properties()->force_render_surface = true; | 3966 render_surface2->test_properties()->force_render_surface = true; |
| 3980 render_surface2->SetDrawsContent(true); | 3967 render_surface2->SetDrawsContent(true); |
| 3981 | 3968 |
| 3982 child1->SetMasksToBounds(true); | 3969 child1->SetMasksToBounds(true); |
| 3983 child2->SetMasksToBounds(true); | 3970 child2->SetMasksToBounds(true); |
| 3984 ExecuteCalculateDrawProperties(root); | 3971 ExecuteCalculateDrawProperties(root); |
| 3985 EXPECT_EQ(gfx::Rect(100, 100), child1->visible_layer_rect()); | 3972 EXPECT_EQ(gfx::Rect(100, 100), child1->visible_layer_rect()); |
| 3986 EXPECT_EQ(gfx::Rect(100, 100), render_surface2->visible_layer_rect()); | 3973 EXPECT_EQ(gfx::Rect(100, 100), render_surface2->visible_layer_rect()); |
| 3987 } | 3974 } |
| 3988 | 3975 |
| 3976 TEST_F(LayerTreeHostCommonTest, VisibleRectOfUnclippedRenderSurface) { |
| 3977 LayerImpl* root = root_layer_for_testing(); |
| 3978 LayerImpl* clip = AddChildToRoot<LayerImpl>(); |
| 3979 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip); |
| 3980 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); |
| 3981 |
| 3982 root->SetBounds(gfx::Size(100, 100)); |
| 3983 clip->SetBounds(gfx::Size(50, 50)); |
| 3984 clip->SetMasksToBounds(true); |
| 3985 render_surface1->SetBounds(gfx::Size(100, 100)); |
| 3986 render_surface1->test_properties()->force_render_surface = true; |
| 3987 render_surface2->SetBounds(gfx::Size(100, 100)); |
| 3988 render_surface2->test_properties()->force_render_surface = true; |
| 3989 render_surface2->SetDrawsContent(true); |
| 3990 |
| 3991 ExecuteCalculateDrawProperties(root); |
| 3992 // The clip should be handled by render_surface1 and render_surface2 should |
| 3993 // be unclipped and its visible rect should be clipped only by viewport clip. |
| 3994 EXPECT_FALSE(render_surface2->is_clipped()); |
| 3995 EXPECT_EQ(gfx::Rect(100, 100), render_surface2->visible_layer_rect()); |
| 3996 } |
| 3997 |
| 3989 TEST_F(LayerTreeHostCommonTest, | 3998 TEST_F(LayerTreeHostCommonTest, |
| 3990 VisibleRectsWhenClipChildIsBetweenTwoRenderSurfaces) { | 3999 VisibleRectsWhenClipChildIsBetweenTwoRenderSurfaces) { |
| 3991 LayerImpl* root = root_layer_for_testing(); | 4000 LayerImpl* root = root_layer_for_testing(); |
| 3992 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); | 4001 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 3993 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); | 4002 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
| 3994 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1); | 4003 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1); |
| 3995 LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child); | 4004 LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child); |
| 3996 | 4005 |
| 3997 root->SetBounds(gfx::Size(100, 100)); | 4006 root->SetBounds(gfx::Size(100, 100)); |
| 3998 | 4007 |
| (...skipping 2496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6495 | 6504 |
| 6496 EXPECT_EQ(scroll_child->effect_tree_index(), | 6505 EXPECT_EQ(scroll_child->effect_tree_index(), |
| 6497 scroll_child_target->effect_tree_index()); | 6506 scroll_child_target->effect_tree_index()); |
| 6498 EXPECT_EQ(scroll_child->visible_layer_rect(), gfx::Rect(10, 10, 40, 40)); | 6507 EXPECT_EQ(scroll_child->visible_layer_rect(), gfx::Rect(10, 10, 40, 40)); |
| 6499 EXPECT_EQ(scroll_child->clip_rect(), gfx::Rect(15, 15, 75, 75)); | 6508 EXPECT_EQ(scroll_child->clip_rect(), gfx::Rect(15, 15, 75, 75)); |
| 6500 gfx::Transform scale; | 6509 gfx::Transform scale; |
| 6501 scale.Scale(1.5f, 1.5f); | 6510 scale.Scale(1.5f, 1.5f); |
| 6502 EXPECT_TRANSFORMATION_MATRIX_EQ(scroll_child->DrawTransform(), scale); | 6511 EXPECT_TRANSFORMATION_MATRIX_EQ(scroll_child->DrawTransform(), scale); |
| 6503 } | 6512 } |
| 6504 | 6513 |
| 6505 TEST_F(LayerTreeHostCommonTest, TargetBetweenScrollChildandScrollParentTarget) { | |
| 6506 LayerImpl* root = root_layer_for_testing(); | |
| 6507 LayerImpl* scroll_child_target = AddChildToRoot<LayerImpl>(); | |
| 6508 LayerImpl* scroll_child = AddChild<LayerImpl>(scroll_child_target); | |
| 6509 LayerImpl* child_of_scroll_child = AddChild<LayerImpl>(scroll_child); | |
| 6510 LayerImpl* intervening_target = AddChild<LayerImpl>(scroll_child_target); | |
| 6511 LayerImpl* clip = AddChild<LayerImpl>(intervening_target); | |
| 6512 LayerImpl* scroll_parent_target = AddChild<LayerImpl>(clip); | |
| 6513 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_target); | |
| 6514 | |
| 6515 scroll_parent->SetDrawsContent(true); | |
| 6516 child_of_scroll_child->SetDrawsContent(true); | |
| 6517 | |
| 6518 scroll_child->test_properties()->scroll_parent = scroll_parent; | |
| 6519 scroll_parent->test_properties()->scroll_children = | |
| 6520 base::MakeUnique<std::set<LayerImpl*>>(); | |
| 6521 scroll_parent->test_properties()->scroll_children->insert(scroll_child); | |
| 6522 | |
| 6523 root->SetBounds(gfx::Size(50, 50)); | |
| 6524 scroll_child_target->SetBounds(gfx::Size(50, 50)); | |
| 6525 scroll_child_target->SetMasksToBounds(true); | |
| 6526 scroll_child_target->test_properties()->force_render_surface = true; | |
| 6527 scroll_child->SetBounds(gfx::Size(50, 50)); | |
| 6528 child_of_scroll_child->SetBounds(gfx::Size(50, 50)); | |
| 6529 child_of_scroll_child->test_properties()->force_render_surface = true; | |
| 6530 intervening_target->SetBounds(gfx::Size(50, 50)); | |
| 6531 intervening_target->test_properties()->force_render_surface = true; | |
| 6532 clip->SetBounds(gfx::Size(50, 50)); | |
| 6533 clip->SetMasksToBounds(true); | |
| 6534 scroll_parent_target->SetBounds(gfx::Size(50, 50)); | |
| 6535 scroll_parent_target->SetMasksToBounds(true); | |
| 6536 scroll_parent_target->test_properties()->force_render_surface = true; | |
| 6537 scroll_parent->SetBounds(gfx::Size(50, 50)); | |
| 6538 | |
| 6539 ExecuteCalculateDrawProperties(root); | |
| 6540 PropertyTrees* property_trees = root->layer_tree_impl()->property_trees(); | |
| 6541 ClipNode* clip_node = | |
| 6542 property_trees->clip_tree.Node(child_of_scroll_child->clip_tree_index()); | |
| 6543 ClipNode* parent_clip_node = property_trees->clip_tree.parent(clip_node); | |
| 6544 DCHECK_GT(parent_clip_node->target_transform_id, | |
| 6545 property_trees->transform_tree.TargetId( | |
| 6546 child_of_scroll_child->transform_tree_index())); | |
| 6547 } | |
| 6548 | |
| 6549 TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) { | 6514 TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) { |
| 6550 LayerImpl* root = root_layer_for_testing(); | 6515 LayerImpl* root = root_layer_for_testing(); |
| 6551 LayerImpl* parent = AddChildToRoot<LayerImpl>(); | 6516 LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
| 6552 LayerImpl* child = AddChild<LayerImpl>(parent); | 6517 LayerImpl* child = AddChild<LayerImpl>(parent); |
| 6553 | 6518 |
| 6554 root->SetBounds(gfx::Size(50, 50)); | 6519 root->SetBounds(gfx::Size(50, 50)); |
| 6555 root->SetDrawsContent(true); | 6520 root->SetDrawsContent(true); |
| 6556 root->test_properties()->sorting_context_id = 1; | 6521 root->test_properties()->sorting_context_id = 1; |
| 6557 parent->SetBounds(gfx::Size(30, 30)); | 6522 parent->SetBounds(gfx::Size(30, 30)); |
| 6558 parent->SetDrawsContent(true); | 6523 parent->SetDrawsContent(true); |
| (...skipping 2413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8972 | 8937 |
| 8973 // The singular transform on |animated| is flattened when inherited by | 8938 // The singular transform on |animated| is flattened when inherited by |
| 8974 // |surface|, and this happens to make it invertible. | 8939 // |surface|, and this happens to make it invertible. |
| 8975 EXPECT_EQ(gfx::Rect(2, 2), surface->visible_layer_rect()); | 8940 EXPECT_EQ(gfx::Rect(2, 2), surface->visible_layer_rect()); |
| 8976 EXPECT_EQ(gfx::Rect(2, 2), descendant_of_animation->visible_layer_rect()); | 8941 EXPECT_EQ(gfx::Rect(2, 2), descendant_of_animation->visible_layer_rect()); |
| 8977 | 8942 |
| 8978 gfx::Transform zero_matrix; | 8943 gfx::Transform zero_matrix; |
| 8979 zero_matrix.Scale3d(0.f, 0.f, 0.f); | 8944 zero_matrix.Scale3d(0.f, 0.f, 0.f); |
| 8980 root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated( | 8945 root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated( |
| 8981 zero_matrix, animated->transform_tree_index(), root->layer_tree_impl()); | 8946 zero_matrix, animated->transform_tree_index(), root->layer_tree_impl()); |
| 8982 // While computing visible rects by combining clips in screen space, we set | 8947 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
| 8983 // the entire layer as visible if the screen space transform is singular. This | |
| 8984 // is not always true when we combine clips in target space because if the | |
| 8985 // intersection of combined_clip in taret space with layer_rect projected to | |
| 8986 // target space is empty, we set it to an empty rect. | |
| 8987 bool skip_verify_visible_rect_calculations = true; | |
| 8988 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList( | |
| 8989 root, skip_verify_visible_rect_calculations); | |
| 8990 | |
| 8991 // The animated layer maps to the empty rect in clipped target space, so is | |
| 8992 // treated as having an empty visible rect. | |
| 8993 EXPECT_EQ(gfx::Rect(), animated->visible_layer_rect()); | |
| 8994 | 8948 |
| 8995 // The animated layer will be treated as fully visible when we combine clips | 8949 // The animated layer will be treated as fully visible when we combine clips |
| 8996 // in screen space. | 8950 // in screen space. |
| 8997 gfx::Rect visible_rect = draw_property_utils::ComputeLayerVisibleRectDynamic( | 8951 EXPECT_EQ(gfx::Rect(120, 120), animated->visible_layer_rect()); |
| 8998 root->layer_tree_impl()->property_trees(), animated); | |
| 8999 EXPECT_EQ(gfx::Rect(120, 120), visible_rect); | |
| 9000 | 8952 |
| 9001 // This time, flattening does not make |animated|'s transform invertible. This | 8953 // This time, flattening does not make |animated|'s transform invertible. This |
| 9002 // means the clip cannot be projected into |surface|'s space, so we treat | 8954 // means the clip cannot be projected into |surface|'s space, so we treat |
| 9003 // |surface| and layers that draw into it as having empty visible rect. | 8955 // |surface| and layers that draw into it as having empty visible rect. |
| 9004 EXPECT_EQ(gfx::Rect(), surface->visible_layer_rect()); | 8956 EXPECT_EQ(gfx::Rect(100, 100), surface->visible_layer_rect()); |
| 9005 EXPECT_EQ(gfx::Rect(), descendant_of_animation->visible_layer_rect()); | 8957 EXPECT_EQ(gfx::Rect(200, 200), descendant_of_animation->visible_layer_rect()); |
| 9006 } | 8958 } |
| 9007 | 8959 |
| 9008 // Verify that having animated opacity but current opacity 1 still creates | 8960 // Verify that having animated opacity but current opacity 1 still creates |
| 9009 // a render surface. | 8961 // a render surface. |
| 9010 TEST_F(LayerTreeHostCommonTest, AnimatedOpacityCreatesRenderSurface) { | 8962 TEST_F(LayerTreeHostCommonTest, AnimatedOpacityCreatesRenderSurface) { |
| 9011 LayerImpl* root = root_layer_for_testing(); | 8963 LayerImpl* root = root_layer_for_testing(); |
| 9012 LayerImpl* child = AddChild<LayerImpl>(root); | 8964 LayerImpl* child = AddChild<LayerImpl>(root); |
| 9013 LayerImpl* grandchild = AddChild<LayerImpl>(child); | 8965 LayerImpl* grandchild = AddChild<LayerImpl>(child); |
| 9014 | 8966 |
| 9015 root->SetBounds(gfx::Size(50, 50)); | 8967 root->SetBounds(gfx::Size(50, 50)); |
| (...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9792 render_surface->SetBounds(gfx::Size(30, 30)); | 9744 render_surface->SetBounds(gfx::Size(30, 30)); |
| 9793 render_surface->test_properties()->force_render_surface = true; | 9745 render_surface->test_properties()->force_render_surface = true; |
| 9794 test_layer->SetBounds(gfx::Size(30, 30)); | 9746 test_layer->SetBounds(gfx::Size(30, 30)); |
| 9795 test_layer->SetDrawsContent(true); | 9747 test_layer->SetDrawsContent(true); |
| 9796 | 9748 |
| 9797 float device_scale_factor = 1.f; | 9749 float device_scale_factor = 1.f; |
| 9798 float page_scale_factor = 1.f; | 9750 float page_scale_factor = 1.f; |
| 9799 LayerImpl* page_scale_layer = nullptr; | 9751 LayerImpl* page_scale_layer = nullptr; |
| 9800 LayerImpl* inner_viewport_scroll_layer = nullptr; | 9752 LayerImpl* inner_viewport_scroll_layer = nullptr; |
| 9801 LayerImpl* outer_viewport_scroll_layer = nullptr; | 9753 LayerImpl* outer_viewport_scroll_layer = nullptr; |
| 9802 // Visible rects computed by combining clips in target space and root space | |
| 9803 // don't match because of rotation transforms. So, we skip | |
| 9804 // verify_visible_rect_calculations. | |
| 9805 bool skip_verify_visible_rect_calculations = true; | |
| 9806 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, | 9754 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, |
| 9807 page_scale_layer, inner_viewport_scroll_layer, | 9755 page_scale_layer, inner_viewport_scroll_layer, |
| 9808 outer_viewport_scroll_layer, | 9756 outer_viewport_scroll_layer); |
| 9809 skip_verify_visible_rect_calculations); | |
| 9810 | 9757 |
| 9811 TransformTree& transform_tree = | 9758 TransformTree& transform_tree = |
| 9812 root->layer_tree_impl()->property_trees()->transform_tree; | 9759 root->layer_tree_impl()->property_trees()->transform_tree; |
| 9813 TransformNode* transform_node = | 9760 TransformNode* transform_node = |
| 9814 transform_tree.Node(significant_transform->transform_tree_index()); | 9761 transform_tree.Node(significant_transform->transform_tree_index()); |
| 9815 EXPECT_EQ(transform_node->owning_layer_id, significant_transform->id()); | 9762 EXPECT_EQ(transform_node->owning_layer_id, significant_transform->id()); |
| 9816 | 9763 |
| 9817 EXPECT_TRUE(root->GetRenderSurface()); | 9764 EXPECT_TRUE(root->GetRenderSurface()); |
| 9818 EXPECT_FALSE(significant_transform->GetRenderSurface()); | 9765 EXPECT_FALSE(significant_transform->GetRenderSurface()); |
| 9819 EXPECT_TRUE(layer_clips_subtree->GetRenderSurface()); | 9766 EXPECT_TRUE(layer_clips_subtree->GetRenderSurface()); |
| 9820 EXPECT_TRUE(render_surface->GetRenderSurface()); | 9767 EXPECT_TRUE(render_surface->GetRenderSurface()); |
| 9821 EXPECT_FALSE(test_layer->GetRenderSurface()); | 9768 EXPECT_FALSE(test_layer->GetRenderSurface()); |
| 9822 | 9769 |
| 9823 ClipTree& clip_tree = root->layer_tree_impl()->property_trees()->clip_tree; | 9770 EXPECT_EQ(gfx::Rect(30, 20), test_layer->visible_layer_rect()); |
| 9824 ClipNode* clip_node = clip_tree.Node(render_surface->clip_tree_index()); | |
| 9825 EXPECT_EQ(clip_node->clip_type, ClipNode::ClipType::NONE); | |
| 9826 EXPECT_EQ(gfx::Rect(20, 20), test_layer->visible_layer_rect()); | |
| 9827 | |
| 9828 // Also test the visible rects computed by combining clips in root space. | |
| 9829 gfx::Rect visible_rect = draw_property_utils::ComputeLayerVisibleRectDynamic( | |
| 9830 root->layer_tree_impl()->property_trees(), test_layer); | |
| 9831 EXPECT_EQ(gfx::Rect(30, 20), visible_rect); | |
| 9832 } | 9771 } |
| 9833 | 9772 |
| 9834 TEST_F(LayerTreeHostCommonTest, TransformOfParentClipNodeAncestorOfTarget) { | 9773 TEST_F(LayerTreeHostCommonTest, TransformOfParentClipNodeAncestorOfTarget) { |
| 9835 // Ensure that when parent clip node's transform is an ancestor of current | 9774 // Ensure that when parent clip node's transform is an ancestor of current |
| 9836 // clip node's target, clip is 'projected' from parent space to current | 9775 // clip node's target, clip is 'projected' from parent space to current |
| 9837 // target space and visible rects are calculated correctly. | 9776 // target space and visible rects are calculated correctly. |
| 9838 LayerImpl* root = root_layer_for_testing(); | 9777 LayerImpl* root = root_layer_for_testing(); |
| 9839 LayerImpl* clip_layer = AddChild<LayerImpl>(root); | 9778 LayerImpl* clip_layer = AddChild<LayerImpl>(root); |
| 9840 LayerImpl* target_layer = AddChild<LayerImpl>(clip_layer); | 9779 LayerImpl* target_layer = AddChild<LayerImpl>(clip_layer); |
| 9841 LayerImpl* test_layer = AddChild<LayerImpl>(target_layer); | 9780 LayerImpl* test_layer = AddChild<LayerImpl>(target_layer); |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10263 clip_child->SetBounds(gfx::Size(30, 30)); | 10202 clip_child->SetBounds(gfx::Size(30, 30)); |
| 10264 | 10203 |
| 10265 clip_child->test_properties()->clip_parent = root; | 10204 clip_child->test_properties()->clip_parent = root; |
| 10266 root->test_properties()->clip_children = | 10205 root->test_properties()->clip_children = |
| 10267 base::MakeUnique<std::set<LayerImpl*>>(); | 10206 base::MakeUnique<std::set<LayerImpl*>>(); |
| 10268 root->test_properties()->clip_children->insert(clip_child); | 10207 root->test_properties()->clip_children->insert(clip_child); |
| 10269 | 10208 |
| 10270 ExecuteCalculateDrawProperties(root); | 10209 ExecuteCalculateDrawProperties(root); |
| 10271 | 10210 |
| 10272 EXPECT_EQ(gfx::Rect(-10, -10, 30, 30), render_surface2->clip_rect()); | 10211 EXPECT_EQ(gfx::Rect(-10, -10, 30, 30), render_surface2->clip_rect()); |
| 10273 // A clip node is created for every render surface and for layers that have | |
| 10274 // local clip. So, here it should be craeted for every layer. | |
| 10275 EXPECT_EQ(root->layer_tree_impl()->property_trees()->clip_tree.size(), 5u); | |
| 10276 } | 10212 } |
| 10277 | 10213 |
| 10278 TEST_F(LayerTreeHostCommonTest, MaskLayerDrawProperties) { | 10214 TEST_F(LayerTreeHostCommonTest, MaskLayerDrawProperties) { |
| 10279 // Tests that a mask layer's draw properties are computed correctly. | 10215 // Tests that a mask layer's draw properties are computed correctly. |
| 10280 LayerImpl* root = root_layer_for_testing(); | 10216 LayerImpl* root = root_layer_for_testing(); |
| 10281 LayerImpl* child = AddChild<LayerImpl>(root); | 10217 LayerImpl* child = AddChild<LayerImpl>(root); |
| 10282 child->test_properties()->SetMaskLayer( | 10218 child->test_properties()->SetMaskLayer( |
| 10283 LayerImpl::Create(root->layer_tree_impl(), 100)); | 10219 LayerImpl::Create(root->layer_tree_impl(), 100)); |
| 10284 LayerImpl* mask = child->test_properties()->mask_layer; | 10220 LayerImpl* mask = child->test_properties()->mask_layer; |
| 10285 | 10221 |
| (...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10791 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index()); | 10727 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index()); |
| 10792 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index()); | 10728 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index()); |
| 10793 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index()); | 10729 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index()); |
| 10794 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index()); | 10730 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index()); |
| 10795 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index()); | 10731 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index()); |
| 10796 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index()); | 10732 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index()); |
| 10797 } | 10733 } |
| 10798 | 10734 |
| 10799 } // namespace | 10735 } // namespace |
| 10800 } // namespace cc | 10736 } // namespace cc |
| OLD | NEW |