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