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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 LayerType* outer_viewport_scroll_layer = nullptr; | 174 LayerType* outer_viewport_scroll_layer = nullptr; |
175 ExecuteCalculateDrawProperties( | 175 ExecuteCalculateDrawProperties( |
176 root_layer, device_scale_factor, 1.f, page_scale_application_layer, | 176 root_layer, device_scale_factor, 1.f, page_scale_application_layer, |
177 inner_viewport_scroll_layer, outer_viewport_scroll_layer); | 177 inner_viewport_scroll_layer, outer_viewport_scroll_layer); |
178 } | 178 } |
179 | 179 |
180 const LayerList* GetUpdateLayerList() { return &update_layer_list_; } | 180 const LayerList* GetUpdateLayerList() { return &update_layer_list_; } |
181 | 181 |
182 void ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(Layer* root_layer) { | 182 void ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(Layer* root_layer) { |
183 DCHECK(root_layer->layer_tree_host()); | 183 DCHECK(root_layer->layer_tree_host()); |
184 bool can_render_to_separate_surface = true; | |
185 | |
186 const Layer* page_scale_layer = | 184 const Layer* page_scale_layer = |
187 root_layer->layer_tree_host()->page_scale_layer(); | 185 root_layer->layer_tree_host()->page_scale_layer(); |
188 Layer* inner_viewport_scroll_layer = | 186 Layer* inner_viewport_scroll_layer = |
189 root_layer->layer_tree_host()->inner_viewport_scroll_layer(); | 187 root_layer->layer_tree_host()->inner_viewport_scroll_layer(); |
190 Layer* outer_viewport_scroll_layer = | 188 Layer* outer_viewport_scroll_layer = |
191 root_layer->layer_tree_host()->outer_viewport_scroll_layer(); | 189 root_layer->layer_tree_host()->outer_viewport_scroll_layer(); |
192 const Layer* overscroll_elasticity_layer = | 190 const Layer* overscroll_elasticity_layer = |
193 root_layer->layer_tree_host()->overscroll_elasticity_layer(); | 191 root_layer->layer_tree_host()->overscroll_elasticity_layer(); |
194 gfx::Vector2dF elastic_overscroll = | 192 gfx::Vector2dF elastic_overscroll = |
195 root_layer->layer_tree_host()->elastic_overscroll(); | 193 root_layer->layer_tree_host()->elastic_overscroll(); |
196 float page_scale_factor = 1.f; | 194 float page_scale_factor = 1.f; |
197 float device_scale_factor = 1.f; | 195 float device_scale_factor = 1.f; |
198 gfx::Size device_viewport_size = | 196 gfx::Size device_viewport_size = |
199 gfx::Size(root_layer->bounds().width() * device_scale_factor, | 197 gfx::Size(root_layer->bounds().width() * device_scale_factor, |
200 root_layer->bounds().height() * device_scale_factor); | 198 root_layer->bounds().height() * device_scale_factor); |
201 PropertyTrees* property_trees = | 199 PropertyTrees* property_trees = |
202 root_layer->layer_tree_host()->property_trees(); | 200 root_layer->layer_tree_host()->property_trees(); |
203 update_layer_list_.clear(); | 201 update_layer_list_.clear(); |
204 PropertyTreeBuilder::BuildPropertyTrees( | 202 PropertyTreeBuilder::BuildPropertyTrees( |
205 root_layer, page_scale_layer, inner_viewport_scroll_layer, | 203 root_layer, page_scale_layer, inner_viewport_scroll_layer, |
206 outer_viewport_scroll_layer, overscroll_elasticity_layer, | 204 outer_viewport_scroll_layer, overscroll_elasticity_layer, |
207 elastic_overscroll, page_scale_factor, device_scale_factor, | 205 elastic_overscroll, page_scale_factor, device_scale_factor, |
208 gfx::Rect(device_viewport_size), gfx::Transform(), property_trees); | 206 gfx::Rect(device_viewport_size), gfx::Transform(), property_trees); |
209 draw_property_utils::UpdatePropertyTrees(root_layer->layer_tree_host(), | 207 draw_property_utils::UpdatePropertyTrees(root_layer->layer_tree_host(), |
210 property_trees, | 208 property_trees); |
211 can_render_to_separate_surface); | |
212 draw_property_utils::FindLayersThatNeedUpdates( | 209 draw_property_utils::FindLayersThatNeedUpdates( |
213 root_layer->layer_tree_host(), property_trees, &update_layer_list_); | 210 root_layer->layer_tree_host(), property_trees, &update_layer_list_); |
214 } | 211 } |
215 | 212 |
216 void ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList( | 213 void ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList( |
217 LayerImpl* root_layer) { | 214 LayerImpl* root_layer) { |
218 DCHECK(root_layer->layer_tree_impl()); | 215 DCHECK(root_layer->layer_tree_impl()); |
219 bool can_render_to_separate_surface = true; | |
220 bool can_adjust_raster_scales = true; | 216 bool can_adjust_raster_scales = true; |
221 | 217 |
222 const LayerImpl* page_scale_layer = nullptr; | 218 const LayerImpl* page_scale_layer = nullptr; |
223 LayerImpl* inner_viewport_scroll_layer = | 219 LayerImpl* inner_viewport_scroll_layer = |
224 root_layer->layer_tree_impl()->InnerViewportScrollLayer(); | 220 root_layer->layer_tree_impl()->InnerViewportScrollLayer(); |
225 LayerImpl* outer_viewport_scroll_layer = | 221 LayerImpl* outer_viewport_scroll_layer = |
226 root_layer->layer_tree_impl()->OuterViewportScrollLayer(); | 222 root_layer->layer_tree_impl()->OuterViewportScrollLayer(); |
227 const LayerImpl* overscroll_elasticity_layer = | 223 const LayerImpl* overscroll_elasticity_layer = |
228 root_layer->layer_tree_impl()->OverscrollElasticityLayer(); | 224 root_layer->layer_tree_impl()->OverscrollElasticityLayer(); |
229 gfx::Vector2dF elastic_overscroll = | 225 gfx::Vector2dF elastic_overscroll = |
230 root_layer->layer_tree_impl()->elastic_overscroll()->Current( | 226 root_layer->layer_tree_impl()->elastic_overscroll()->Current( |
231 root_layer->layer_tree_impl()->IsActiveTree()); | 227 root_layer->layer_tree_impl()->IsActiveTree()); |
232 float page_scale_factor = 1.f; | 228 float page_scale_factor = 1.f; |
233 float device_scale_factor = 1.f; | 229 float device_scale_factor = 1.f; |
234 gfx::Size device_viewport_size = | 230 gfx::Size device_viewport_size = |
235 gfx::Size(root_layer->bounds().width() * device_scale_factor, | 231 gfx::Size(root_layer->bounds().width() * device_scale_factor, |
236 root_layer->bounds().height() * device_scale_factor); | 232 root_layer->bounds().height() * device_scale_factor); |
237 update_layer_list_impl_.reset(new LayerImplList); | 233 update_layer_list_impl_.reset(new LayerImplList); |
238 root_layer->layer_tree_impl()->BuildLayerListForTesting(); | 234 root_layer->layer_tree_impl()->BuildLayerListForTesting(); |
239 PropertyTrees* property_trees = | 235 PropertyTrees* property_trees = |
240 root_layer->layer_tree_impl()->property_trees(); | 236 root_layer->layer_tree_impl()->property_trees(); |
241 PropertyTreeBuilder::BuildPropertyTrees( | 237 PropertyTreeBuilder::BuildPropertyTrees( |
242 root_layer, page_scale_layer, inner_viewport_scroll_layer, | 238 root_layer, page_scale_layer, inner_viewport_scroll_layer, |
243 outer_viewport_scroll_layer, overscroll_elasticity_layer, | 239 outer_viewport_scroll_layer, overscroll_elasticity_layer, |
244 elastic_overscroll, page_scale_factor, device_scale_factor, | 240 elastic_overscroll, page_scale_factor, device_scale_factor, |
245 gfx::Rect(device_viewport_size), gfx::Transform(), property_trees); | 241 gfx::Rect(device_viewport_size), gfx::Transform(), property_trees); |
246 draw_property_utils::UpdatePropertyTreesAndRenderSurfaces( | 242 draw_property_utils::UpdatePropertyTreesAndRenderSurfaces( |
247 root_layer, property_trees, can_render_to_separate_surface, | 243 root_layer, property_trees, can_adjust_raster_scales); |
248 can_adjust_raster_scales); | |
249 draw_property_utils::FindLayersThatNeedUpdates( | 244 draw_property_utils::FindLayersThatNeedUpdates( |
250 root_layer->layer_tree_impl(), property_trees, | 245 root_layer->layer_tree_impl(), property_trees, |
251 update_layer_list_impl_.get()); | 246 update_layer_list_impl_.get()); |
252 draw_property_utils::ComputeDrawPropertiesOfVisibleLayers( | 247 draw_property_utils::ComputeDrawPropertiesOfVisibleLayers( |
253 update_layer_list_impl(), property_trees); | 248 update_layer_list_impl(), property_trees); |
254 } | 249 } |
255 | 250 |
256 void ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces( | 251 void ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces( |
257 LayerImpl* root_layer) { | 252 LayerImpl* root_layer) { |
258 gfx::Size device_viewport_size = | 253 gfx::Size device_viewport_size = |
259 gfx::Size(root_layer->bounds().width(), root_layer->bounds().height()); | 254 gfx::Size(root_layer->bounds().width(), root_layer->bounds().height()); |
260 render_surface_list_impl_.reset(new RenderSurfaceList); | 255 render_surface_list_impl_.reset(new RenderSurfaceList); |
261 | 256 |
262 DCHECK(!root_layer->bounds().IsEmpty()); | 257 DCHECK(!root_layer->bounds().IsEmpty()); |
263 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( | 258 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
264 root_layer, device_viewport_size, render_surface_list_impl_.get()); | 259 root_layer, device_viewport_size, render_surface_list_impl_.get()); |
265 inputs.can_adjust_raster_scales = true; | 260 inputs.can_adjust_raster_scales = true; |
266 inputs.can_render_to_separate_surface = false; | |
267 | 261 |
268 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); | 262 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
269 } | 263 } |
270 | 264 |
271 void ExecuteCalculateDrawPropertiesWithoutAdjustingRasterScales( | 265 void ExecuteCalculateDrawPropertiesWithoutAdjustingRasterScales( |
272 LayerImpl* root_layer) { | 266 LayerImpl* root_layer) { |
273 gfx::Size device_viewport_size = | 267 gfx::Size device_viewport_size = |
274 gfx::Size(root_layer->bounds().width(), root_layer->bounds().height()); | 268 gfx::Size(root_layer->bounds().width(), root_layer->bounds().height()); |
275 render_surface_list_impl_.reset(new RenderSurfaceList); | 269 render_surface_list_impl_.reset(new RenderSurfaceList); |
276 | 270 |
277 DCHECK(!root_layer->bounds().IsEmpty()); | 271 DCHECK(!root_layer->bounds().IsEmpty()); |
278 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( | 272 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
279 root_layer, device_viewport_size, render_surface_list_impl_.get()); | 273 root_layer, device_viewport_size, render_surface_list_impl_.get()); |
280 inputs.can_render_to_separate_surface = true; | |
281 inputs.can_adjust_raster_scales = false; | 274 inputs.can_adjust_raster_scales = false; |
282 | 275 |
283 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); | 276 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
284 } | 277 } |
285 | 278 |
286 bool UpdateLayerListImplContains(int id) const { | 279 bool UpdateLayerListImplContains(int id) const { |
287 for (auto* layer : *update_layer_list_impl_) { | 280 for (auto* layer : *update_layer_list_impl_) { |
288 if (layer->id() == id) | 281 if (layer->id() == id) |
289 return true; | 282 return true; |
290 } | 283 } |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
763 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_composite_transform, | 756 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_composite_transform, |
764 child->render_target()->draw_transform()); | 757 child->render_target()->draw_transform()); |
765 | 758 |
766 // The screen space is the same as the target since the child surface draws | 759 // The screen space is the same as the target since the child surface draws |
767 // into the root. | 760 // into the root. |
768 EXPECT_TRANSFORMATION_MATRIX_EQ( | 761 EXPECT_TRANSFORMATION_MATRIX_EQ( |
769 surface_sublayer_composite_transform, | 762 surface_sublayer_composite_transform, |
770 child->render_target()->screen_space_transform()); | 763 child->render_target()->screen_space_transform()); |
771 } | 764 } |
772 | 765 |
773 TEST_F(LayerTreeHostCommonTest, TransformsWhenCannotRenderToSeparateSurface) { | |
774 LayerImpl* root = root_layer_for_testing(); | |
775 LayerImpl* parent = AddChildToRoot<LayerImpl>(); | |
776 LayerImpl* child = AddChild<LayerImpl>(parent); | |
777 LayerImpl* grand_child = AddChild<LayerImpl>(child); | |
778 | |
779 gfx::Transform parent_transform; | |
780 parent_transform.Translate(10.0, 10.0); | |
781 | |
782 gfx::Transform child_transform; | |
783 child_transform.Rotate(45.0); | |
784 | |
785 root->SetBounds(gfx::Size(100, 100)); | |
786 parent->test_properties()->transform = parent_transform; | |
787 parent->SetBounds(gfx::Size(10, 10)); | |
788 child->test_properties()->transform = child_transform; | |
789 child->SetBounds(gfx::Size(10, 10)); | |
790 child->test_properties()->force_render_surface = true; | |
791 grand_child->SetPosition(gfx::PointF(2.f, 2.f)); | |
792 grand_child->SetBounds(gfx::Size(20, 20)); | |
793 grand_child->SetDrawsContent(true); | |
794 | |
795 gfx::Transform expected_grand_child_screen_space_transform; | |
796 expected_grand_child_screen_space_transform.Translate(10.0, 10.0); | |
797 expected_grand_child_screen_space_transform.Rotate(45.0); | |
798 expected_grand_child_screen_space_transform.Translate(2.0, 2.0); | |
799 | |
800 // First compute draw properties with separate surfaces enabled. | |
801 ExecuteCalculateDrawProperties(root); | |
802 | |
803 // The grand child's draw transform should be its offset wrt the child. | |
804 gfx::Transform expected_grand_child_draw_transform; | |
805 expected_grand_child_draw_transform.Translate(2.0, 2.0); | |
806 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform, | |
807 grand_child->DrawTransform()); | |
808 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, | |
809 grand_child->ScreenSpaceTransform()); | |
810 | |
811 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); | |
812 | |
813 // With separate surfaces disabled, the grand child's draw transform should be | |
814 // the same as its screen space transform. | |
815 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, | |
816 grand_child->DrawTransform()); | |
817 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, | |
818 grand_child->ScreenSpaceTransform()); | |
819 } | |
820 | |
821 TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) { | 766 TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) { |
822 // This test creates a more complex tree and verifies it all at once. This | 767 // This test creates a more complex tree and verifies it all at once. This |
823 // covers the following cases: | 768 // covers the following cases: |
824 // - layers that are described w.r.t. a render surface: should have draw | 769 // - layers that are described w.r.t. a render surface: should have draw |
825 // transforms described w.r.t. that surface | 770 // transforms described w.r.t. that surface |
826 // - A render surface described w.r.t. an ancestor render surface: should | 771 // - A render surface described w.r.t. an ancestor render surface: should |
827 // have a draw transform described w.r.t. that ancestor surface | 772 // have a draw transform described w.r.t. that ancestor surface |
828 // - Sanity check on recursion: verify transforms of layers described w.r.t. | 773 // - Sanity check on recursion: verify transforms of layers described w.r.t. |
829 // a render surface that is described w.r.t. an ancestor render surface. | 774 // a render surface that is described w.r.t. an ancestor render surface. |
830 // - verifying that each layer has a reference to the correct render surface | 775 // - verifying that each layer has a reference to the correct render surface |
(...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1604 | 1549 |
1605 ASSERT_TRUE(GetRenderSurface(surface1)); | 1550 ASSERT_TRUE(GetRenderSurface(surface1)); |
1606 ASSERT_FALSE(GetRenderSurface(not_surface)); | 1551 ASSERT_FALSE(GetRenderSurface(not_surface)); |
1607 ASSERT_TRUE(GetRenderSurface(surface2)); | 1552 ASSERT_TRUE(GetRenderSurface(surface2)); |
1608 EXPECT_EQ(0.5f, GetRenderSurface(surface1)->draw_opacity()); | 1553 EXPECT_EQ(0.5f, GetRenderSurface(surface1)->draw_opacity()); |
1609 // surface2's draw opacity should include the opacity of not-surface and | 1554 // surface2's draw opacity should include the opacity of not-surface and |
1610 // itself, but not the opacity of surface1. | 1555 // itself, but not the opacity of surface1. |
1611 EXPECT_EQ(0.25f, GetRenderSurface(surface2)->draw_opacity()); | 1556 EXPECT_EQ(0.25f, GetRenderSurface(surface2)->draw_opacity()); |
1612 } | 1557 } |
1613 | 1558 |
1614 TEST_F(LayerTreeHostCommonTest, DrawOpacityWhenCannotRenderToSeparateSurface) { | |
1615 // Tests that when separate surfaces are disabled, a layer's draw opacity is | |
1616 // the product of all ancestor layer opacties and the layer's own opacity. | |
1617 // (Rendering will still be incorrect in situations where we really do need | |
1618 // surfaces to apply opacity, such as when we have overlapping layers with an | |
1619 // ancestor whose opacity is <1.) | |
1620 LayerImpl* root = root_layer_for_testing(); | |
1621 LayerImpl* parent = AddChild<LayerImpl>(root); | |
1622 LayerImpl* child1 = AddChild<LayerImpl>(parent); | |
1623 LayerImpl* child2 = AddChild<LayerImpl>(parent); | |
1624 LayerImpl* grand_child = AddChild<LayerImpl>(child1); | |
1625 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child); | |
1626 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2); | |
1627 | |
1628 root->SetBounds(gfx::Size(100, 100)); | |
1629 root->SetDrawsContent(true); | |
1630 parent->SetBounds(gfx::Size(100, 100)); | |
1631 parent->SetDrawsContent(true); | |
1632 child1->SetBounds(gfx::Size(100, 100)); | |
1633 child1->SetDrawsContent(true); | |
1634 child1->test_properties()->opacity = 0.5f; | |
1635 child1->test_properties()->force_render_surface = true; | |
1636 child2->SetBounds(gfx::Size(100, 100)); | |
1637 child2->SetDrawsContent(true); | |
1638 grand_child->SetBounds(gfx::Size(100, 100)); | |
1639 grand_child->SetDrawsContent(true); | |
1640 grand_child->test_properties()->opacity = 0.5f; | |
1641 grand_child->test_properties()->force_render_surface = true; | |
1642 leaf_node1->SetBounds(gfx::Size(100, 100)); | |
1643 leaf_node1->SetDrawsContent(true); | |
1644 leaf_node1->test_properties()->opacity = 0.5f; | |
1645 leaf_node2->SetBounds(gfx::Size(100, 100)); | |
1646 leaf_node2->SetDrawsContent(true); | |
1647 leaf_node2->test_properties()->opacity = 0.5f; | |
1648 | |
1649 // With surfaces enabled, each layer's draw opacity is the product of layer | |
1650 // opacities on the path from the layer to its render target, not including | |
1651 // the opacity of the layer that owns the target surface (since that opacity | |
1652 // is applied by the surface). | |
1653 ExecuteCalculateDrawProperties(root); | |
1654 EXPECT_EQ(1.f, root->draw_opacity()); | |
1655 EXPECT_EQ(1.f, parent->draw_opacity()); | |
1656 EXPECT_EQ(1.f, child1->draw_opacity()); | |
1657 EXPECT_EQ(1.f, child2->draw_opacity()); | |
1658 EXPECT_EQ(1.f, grand_child->draw_opacity()); | |
1659 EXPECT_EQ(0.5f, leaf_node1->draw_opacity()); | |
1660 EXPECT_EQ(0.5f, leaf_node2->draw_opacity()); | |
1661 | |
1662 // With surfaces disabled, each layer's draw opacity is the product of layer | |
1663 // opacities on the path from the layer to the root. | |
1664 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); | |
1665 EXPECT_EQ(1.f, root->draw_opacity()); | |
1666 EXPECT_EQ(1.f, parent->draw_opacity()); | |
1667 EXPECT_EQ(0.5f, child1->draw_opacity()); | |
1668 EXPECT_EQ(1.f, child2->draw_opacity()); | |
1669 EXPECT_EQ(0.25f, grand_child->draw_opacity()); | |
1670 EXPECT_EQ(0.125f, leaf_node1->draw_opacity()); | |
1671 EXPECT_EQ(0.5f, leaf_node2->draw_opacity()); | |
1672 } | |
1673 | |
1674 TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) { | 1559 TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) { |
1675 LayerImpl* root = root_layer_for_testing(); | 1560 LayerImpl* root = root_layer_for_testing(); |
1676 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); | 1561 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
1677 LayerImpl* child = AddChild<LayerImpl>(render_surface1); | 1562 LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
1678 | 1563 |
1679 root->SetBounds(gfx::Size(10, 10)); | 1564 root->SetBounds(gfx::Size(10, 10)); |
1680 render_surface1->SetBounds(gfx::Size(10, 10)); | 1565 render_surface1->SetBounds(gfx::Size(10, 10)); |
1681 render_surface1->test_properties()->force_render_surface = true; | 1566 render_surface1->test_properties()->force_render_surface = true; |
1682 child->SetBounds(gfx::Size(10, 10)); | 1567 child->SetBounds(gfx::Size(10, 10)); |
1683 child->SetDrawsContent(true); | 1568 child->SetDrawsContent(true); |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1946 host_impl()->active_tree()->property_trees()->needs_rebuild = true; | 1831 host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
1947 | 1832 |
1948 ExecuteCalculateDrawProperties(root); | 1833 ExecuteCalculateDrawProperties(root); |
1949 | 1834 |
1950 EXPECT_FALSE(root->is_clipped()); | 1835 EXPECT_FALSE(root->is_clipped()); |
1951 EXPECT_TRUE(parent->is_clipped()); | 1836 EXPECT_TRUE(parent->is_clipped()); |
1952 EXPECT_TRUE(child->is_clipped()); | 1837 EXPECT_TRUE(child->is_clipped()); |
1953 EXPECT_EQ(gfx::Rect(), child->clip_rect()); | 1838 EXPECT_EQ(gfx::Rect(), child->clip_rect()); |
1954 } | 1839 } |
1955 | 1840 |
1956 TEST_F(LayerTreeHostCommonTest, IsClippedWhenCannotRenderToSeparateSurface) { | |
1957 // Tests that when separate surfaces are disabled, is_clipped is true exactly | |
1958 // when a layer or its ancestor has a clip; in particular, if a layer | |
1959 // is_clipped, so is its entire subtree (since there are no render surfaces | |
1960 // that can reset is_clipped). | |
1961 LayerImpl* root = root_layer_for_testing(); | |
1962 LayerImpl* parent = AddChild<LayerImpl>(root); | |
1963 LayerImpl* child1 = AddChild<LayerImpl>(parent); | |
1964 LayerImpl* child2 = AddChild<LayerImpl>(parent); | |
1965 LayerImpl* grand_child = AddChild<LayerImpl>(child1); | |
1966 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child); | |
1967 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2); | |
1968 | |
1969 root->SetBounds(gfx::Size(100, 100)); | |
1970 root->SetDrawsContent(true); | |
1971 parent->SetBounds(gfx::Size(100, 100)); | |
1972 parent->SetDrawsContent(true); | |
1973 child1->SetBounds(gfx::Size(100, 100)); | |
1974 child1->SetDrawsContent(true); | |
1975 child1->test_properties()->force_render_surface = true; | |
1976 child2->SetBounds(gfx::Size(100, 100)); | |
1977 child2->SetDrawsContent(true); | |
1978 grand_child->SetBounds(gfx::Size(100, 100)); | |
1979 grand_child->SetDrawsContent(true); | |
1980 grand_child->test_properties()->force_render_surface = true; | |
1981 leaf_node1->SetBounds(gfx::Size(100, 100)); | |
1982 leaf_node1->SetDrawsContent(true); | |
1983 leaf_node2->SetBounds(gfx::Size(100, 100)); | |
1984 leaf_node2->SetDrawsContent(true); | |
1985 | |
1986 // Case 1: Nothing is clipped. In this case, is_clipped is always false, with | |
1987 // or without surfaces. | |
1988 ExecuteCalculateDrawProperties(root); | |
1989 EXPECT_FALSE(root->is_clipped()); | |
1990 EXPECT_FALSE(parent->is_clipped()); | |
1991 EXPECT_FALSE(child1->is_clipped()); | |
1992 EXPECT_FALSE(child2->is_clipped()); | |
1993 EXPECT_FALSE(grand_child->is_clipped()); | |
1994 EXPECT_FALSE(leaf_node1->is_clipped()); | |
1995 EXPECT_FALSE(leaf_node2->is_clipped()); | |
1996 | |
1997 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); | |
1998 EXPECT_FALSE(root->is_clipped()); | |
1999 EXPECT_FALSE(parent->is_clipped()); | |
2000 EXPECT_FALSE(child1->is_clipped()); | |
2001 EXPECT_FALSE(child2->is_clipped()); | |
2002 EXPECT_FALSE(grand_child->is_clipped()); | |
2003 EXPECT_FALSE(leaf_node1->is_clipped()); | |
2004 EXPECT_FALSE(leaf_node2->is_clipped()); | |
2005 | |
2006 // Case 2: The root is clipped. With surfaces, this only persists until the | |
2007 // next render surface. Without surfaces, the entire tree is clipped. | |
2008 root->SetMasksToBounds(true); | |
2009 host_impl()->active_tree()->property_trees()->needs_rebuild = true; | |
2010 ExecuteCalculateDrawProperties(root); | |
2011 EXPECT_TRUE(root->is_clipped()); | |
2012 EXPECT_TRUE(parent->is_clipped()); | |
2013 EXPECT_FALSE(child1->is_clipped()); | |
2014 EXPECT_TRUE(child2->is_clipped()); | |
2015 EXPECT_FALSE(grand_child->is_clipped()); | |
2016 EXPECT_FALSE(leaf_node1->is_clipped()); | |
2017 EXPECT_TRUE(leaf_node2->is_clipped()); | |
2018 | |
2019 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); | |
2020 EXPECT_TRUE(root->is_clipped()); | |
2021 EXPECT_TRUE(parent->is_clipped()); | |
2022 EXPECT_TRUE(child1->is_clipped()); | |
2023 EXPECT_TRUE(child2->is_clipped()); | |
2024 EXPECT_TRUE(grand_child->is_clipped()); | |
2025 EXPECT_TRUE(leaf_node1->is_clipped()); | |
2026 EXPECT_TRUE(leaf_node2->is_clipped()); | |
2027 | |
2028 root->SetMasksToBounds(false); | |
2029 | |
2030 // Case 3: The parent is clipped. Again, with surfaces, this only persists | |
2031 // until the next render surface. Without surfaces, parent's entire subtree is | |
2032 // clipped. | |
2033 parent->SetMasksToBounds(true); | |
2034 host_impl()->active_tree()->property_trees()->needs_rebuild = true; | |
2035 ExecuteCalculateDrawProperties(root); | |
2036 EXPECT_FALSE(root->is_clipped()); | |
2037 EXPECT_TRUE(parent->is_clipped()); | |
2038 EXPECT_FALSE(child1->is_clipped()); | |
2039 EXPECT_TRUE(child2->is_clipped()); | |
2040 EXPECT_FALSE(grand_child->is_clipped()); | |
2041 EXPECT_FALSE(leaf_node1->is_clipped()); | |
2042 EXPECT_TRUE(leaf_node2->is_clipped()); | |
2043 | |
2044 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); | |
2045 EXPECT_FALSE(root->is_clipped()); | |
2046 EXPECT_TRUE(parent->is_clipped()); | |
2047 EXPECT_TRUE(child1->is_clipped()); | |
2048 EXPECT_TRUE(child2->is_clipped()); | |
2049 EXPECT_TRUE(grand_child->is_clipped()); | |
2050 EXPECT_TRUE(leaf_node1->is_clipped()); | |
2051 EXPECT_TRUE(leaf_node2->is_clipped()); | |
2052 | |
2053 parent->SetMasksToBounds(false); | |
2054 | |
2055 // Case 4: child1 is clipped. With surfaces, only child1 is_clipped, since it | |
2056 // has no non-surface children. Without surfaces, child1's entire subtree is | |
2057 // clipped. | |
2058 child1->SetMasksToBounds(true); | |
2059 host_impl()->active_tree()->property_trees()->needs_rebuild = true; | |
2060 ExecuteCalculateDrawProperties(root); | |
2061 EXPECT_FALSE(root->is_clipped()); | |
2062 EXPECT_FALSE(parent->is_clipped()); | |
2063 EXPECT_TRUE(child1->is_clipped()); | |
2064 EXPECT_FALSE(child2->is_clipped()); | |
2065 EXPECT_FALSE(grand_child->is_clipped()); | |
2066 EXPECT_FALSE(leaf_node1->is_clipped()); | |
2067 EXPECT_FALSE(leaf_node2->is_clipped()); | |
2068 | |
2069 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); | |
2070 EXPECT_FALSE(root->is_clipped()); | |
2071 EXPECT_FALSE(parent->is_clipped()); | |
2072 EXPECT_TRUE(child1->is_clipped()); | |
2073 EXPECT_FALSE(child2->is_clipped()); | |
2074 EXPECT_TRUE(grand_child->is_clipped()); | |
2075 EXPECT_TRUE(leaf_node1->is_clipped()); | |
2076 EXPECT_FALSE(leaf_node2->is_clipped()); | |
2077 | |
2078 child1->SetMasksToBounds(false); | |
2079 | |
2080 // Case 5: Only the leaf nodes are clipped. The behavior with and without | |
2081 // surfaces is the same. | |
2082 leaf_node1->SetMasksToBounds(true); | |
2083 leaf_node2->SetMasksToBounds(true); | |
2084 host_impl()->active_tree()->property_trees()->needs_rebuild = true; | |
2085 ExecuteCalculateDrawProperties(root); | |
2086 EXPECT_FALSE(root->is_clipped()); | |
2087 EXPECT_FALSE(parent->is_clipped()); | |
2088 EXPECT_FALSE(child1->is_clipped()); | |
2089 EXPECT_FALSE(child2->is_clipped()); | |
2090 EXPECT_FALSE(grand_child->is_clipped()); | |
2091 EXPECT_TRUE(leaf_node1->is_clipped()); | |
2092 EXPECT_TRUE(leaf_node2->is_clipped()); | |
2093 | |
2094 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); | |
2095 EXPECT_FALSE(root->is_clipped()); | |
2096 EXPECT_FALSE(parent->is_clipped()); | |
2097 EXPECT_FALSE(child1->is_clipped()); | |
2098 EXPECT_FALSE(child2->is_clipped()); | |
2099 EXPECT_FALSE(grand_child->is_clipped()); | |
2100 EXPECT_TRUE(leaf_node1->is_clipped()); | |
2101 EXPECT_TRUE(leaf_node2->is_clipped()); | |
2102 } | |
2103 | |
2104 TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) { | 1841 TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) { |
2105 // Verify that layers get the appropriate DrawableContentRect when their | 1842 // Verify that layers get the appropriate DrawableContentRect when their |
2106 // parent MasksToBounds is true. | 1843 // parent MasksToBounds is true. |
2107 // | 1844 // |
2108 // grand_child1 - completely inside the region; DrawableContentRect should | 1845 // grand_child1 - completely inside the region; DrawableContentRect should |
2109 // be the layer rect expressed in target space. | 1846 // be the layer rect expressed in target space. |
2110 // grand_child2 - partially clipped but NOT MasksToBounds; the clip rect | 1847 // grand_child2 - partially clipped but NOT MasksToBounds; the clip rect |
2111 // will be the intersection of layer bounds and the mask region. | 1848 // will be the intersection of layer bounds and the mask region. |
2112 // grand_child3 - partially clipped and MasksToBounds; the | 1849 // grand_child3 - partially clipped and MasksToBounds; the |
2113 // DrawableContentRect will still be the intersection of layer bounds and | 1850 // DrawableContentRect will still be the intersection of layer bounds and |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2203 // Surfaces are clipped by their parent, but un-affected by the owning layer's | 1940 // Surfaces are clipped by their parent, but un-affected by the owning layer's |
2204 // MasksToBounds. | 1941 // MasksToBounds. |
2205 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), | 1942 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
2206 GetRenderSurface(grand_child1)->clip_rect()); | 1943 GetRenderSurface(grand_child1)->clip_rect()); |
2207 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), | 1944 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
2208 GetRenderSurface(grand_child2)->clip_rect()); | 1945 GetRenderSurface(grand_child2)->clip_rect()); |
2209 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), | 1946 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
2210 GetRenderSurface(grand_child3)->clip_rect()); | 1947 GetRenderSurface(grand_child3)->clip_rect()); |
2211 } | 1948 } |
2212 | 1949 |
2213 TEST_F(LayerTreeHostCommonTest, ClipRectWhenCannotRenderToSeparateSurface) { | |
2214 // Tests that when separate surfaces are disabled, a layer's clip_rect is the | |
2215 // intersection of all ancestor clips in screen space; in particular, if a | |
2216 // layer masks to bounds, it contributes to the clip_rect of all layers in its | |
2217 // subtree (since there are no render surfaces that can reset the clip_rect). | |
2218 LayerImpl* root = root_layer_for_testing(); | |
2219 LayerImpl* parent = AddChild<LayerImpl>(root); | |
2220 LayerImpl* child1 = AddChild<LayerImpl>(parent); | |
2221 LayerImpl* child2 = AddChild<LayerImpl>(parent); | |
2222 LayerImpl* grand_child = AddChild<LayerImpl>(child1); | |
2223 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child); | |
2224 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2); | |
2225 | |
2226 root->SetBounds(gfx::Size(100, 100)); | |
2227 parent->SetPosition(gfx::PointF(2.f, 2.f)); | |
2228 parent->SetBounds(gfx::Size(400, 400)); | |
2229 child1->SetPosition(gfx::PointF(4.f, 4.f)); | |
2230 child1->SetBounds(gfx::Size(800, 800)); | |
2231 child2->SetPosition(gfx::PointF(3.f, 3.f)); | |
2232 child2->SetBounds(gfx::Size(800, 800)); | |
2233 grand_child->SetPosition(gfx::PointF(8.f, 8.f)); | |
2234 grand_child->SetBounds(gfx::Size(1500, 1500)); | |
2235 leaf_node1->SetPosition(gfx::PointF(16.f, 16.f)); | |
2236 leaf_node1->SetBounds(gfx::Size(2000, 2000)); | |
2237 leaf_node2->SetPosition(gfx::PointF(9.f, 9.f)); | |
2238 leaf_node2->SetBounds(gfx::Size(2000, 2000)); | |
2239 | |
2240 root->SetDrawsContent(true); | |
2241 parent->SetDrawsContent(true); | |
2242 child1->SetDrawsContent(true); | |
2243 child2->SetDrawsContent(true); | |
2244 grand_child->SetDrawsContent(true); | |
2245 leaf_node1->SetDrawsContent(true); | |
2246 leaf_node2->SetDrawsContent(true); | |
2247 | |
2248 root->test_properties()->force_render_surface = true; | |
2249 child1->test_properties()->force_render_surface = true; | |
2250 grand_child->test_properties()->force_render_surface = true; | |
2251 | |
2252 // Case 1: Nothing is clipped. In this case, each layer's clip rect is its | |
2253 // bounds in target space. The only thing that changes when surfaces are | |
2254 // disabled is that target space is always screen space. | |
2255 ExecuteCalculateDrawProperties(root); | |
2256 EXPECT_TRUE(GetRenderSurface(root)); | |
2257 EXPECT_FALSE(GetRenderSurface(parent)); | |
2258 EXPECT_TRUE(GetRenderSurface(child1)); | |
2259 EXPECT_FALSE(GetRenderSurface(child2)); | |
2260 EXPECT_TRUE(GetRenderSurface(grand_child)); | |
2261 EXPECT_FALSE(GetRenderSurface(leaf_node1)); | |
2262 EXPECT_FALSE(GetRenderSurface(leaf_node2)); | |
2263 EXPECT_FALSE(root->is_clipped()); | |
2264 EXPECT_FALSE(parent->is_clipped()); | |
2265 EXPECT_FALSE(child1->is_clipped()); | |
2266 EXPECT_FALSE(child2->is_clipped()); | |
2267 EXPECT_FALSE(grand_child->is_clipped()); | |
2268 EXPECT_FALSE(leaf_node1->is_clipped()); | |
2269 EXPECT_FALSE(leaf_node2->is_clipped()); | |
2270 EXPECT_TRUE(GetRenderSurface(root)->is_clipped()); | |
2271 EXPECT_FALSE(GetRenderSurface(child1)->is_clipped()); | |
2272 EXPECT_FALSE(GetRenderSurface(grand_child)->is_clipped()); | |
2273 EXPECT_EQ(gfx::Rect(100, 100), GetRenderSurface(root)->clip_rect()); | |
2274 | |
2275 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); | |
2276 EXPECT_FALSE(root->is_clipped()); | |
2277 EXPECT_FALSE(parent->is_clipped()); | |
2278 EXPECT_FALSE(child1->is_clipped()); | |
2279 EXPECT_FALSE(child2->is_clipped()); | |
2280 EXPECT_FALSE(grand_child->is_clipped()); | |
2281 EXPECT_FALSE(leaf_node1->is_clipped()); | |
2282 EXPECT_FALSE(leaf_node2->is_clipped()); | |
2283 EXPECT_TRUE(GetRenderSurface(root)->is_clipped()); | |
2284 EXPECT_EQ(gfx::Rect(100, 100), GetRenderSurface(root)->clip_rect()); | |
2285 | |
2286 // Case 2: The root is clipped. In this case, layers that draw into the root | |
2287 // render surface are clipped by the root's bounds. | |
2288 root->SetMasksToBounds(true); | |
2289 host_impl()->active_tree()->property_trees()->needs_rebuild = true; | |
2290 root->test_properties()->force_render_surface = true; | |
2291 child1->test_properties()->force_render_surface = true; | |
2292 grand_child->test_properties()->force_render_surface = true; | |
2293 ExecuteCalculateDrawProperties(root); | |
2294 EXPECT_TRUE(GetRenderSurface(root)); | |
2295 EXPECT_FALSE(GetRenderSurface(parent)); | |
2296 EXPECT_TRUE(GetRenderSurface(child1)); | |
2297 EXPECT_FALSE(GetRenderSurface(child2)); | |
2298 EXPECT_TRUE(GetRenderSurface(grand_child)); | |
2299 EXPECT_FALSE(GetRenderSurface(leaf_node1)); | |
2300 EXPECT_FALSE(GetRenderSurface(leaf_node2)); | |
2301 EXPECT_TRUE(root->is_clipped()); | |
2302 EXPECT_TRUE(parent->is_clipped()); | |
2303 EXPECT_FALSE(child1->is_clipped()); | |
2304 EXPECT_TRUE(GetRenderSurface(child1)->is_clipped()); | |
2305 EXPECT_TRUE(child2->is_clipped()); | |
2306 EXPECT_FALSE(grand_child->is_clipped()); | |
2307 EXPECT_FALSE(GetRenderSurface(grand_child)->is_clipped()); | |
2308 EXPECT_FALSE(leaf_node1->is_clipped()); | |
2309 EXPECT_TRUE(leaf_node2->is_clipped()); | |
2310 EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect()); | |
2311 EXPECT_EQ(gfx::Rect(100, 100), parent->clip_rect()); | |
2312 EXPECT_EQ(gfx::Rect(100, 100), GetRenderSurface(child1)->clip_rect()); | |
2313 EXPECT_EQ(gfx::Rect(100, 100), child2->clip_rect()); | |
2314 EXPECT_EQ(gfx::Rect(100, 100), leaf_node2->clip_rect()); | |
2315 | |
2316 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); | |
2317 EXPECT_TRUE(root->is_clipped()); | |
2318 EXPECT_TRUE(parent->is_clipped()); | |
2319 EXPECT_TRUE(child1->is_clipped()); | |
2320 EXPECT_TRUE(child2->is_clipped()); | |
2321 EXPECT_TRUE(grand_child->is_clipped()); | |
2322 EXPECT_TRUE(leaf_node1->is_clipped()); | |
2323 EXPECT_TRUE(leaf_node2->is_clipped()); | |
2324 EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect()); | |
2325 EXPECT_EQ(gfx::Rect(100, 100), parent->clip_rect()); | |
2326 EXPECT_EQ(gfx::Rect(100, 100), child1->clip_rect()); | |
2327 EXPECT_EQ(gfx::Rect(100, 100), child2->clip_rect()); | |
2328 EXPECT_EQ(gfx::Rect(100, 100), grand_child->clip_rect()); | |
2329 EXPECT_EQ(gfx::Rect(100, 100), leaf_node1->clip_rect()); | |
2330 EXPECT_EQ(gfx::Rect(100, 100), leaf_node2->clip_rect()); | |
2331 | |
2332 root->SetMasksToBounds(false); | |
2333 | |
2334 // Case 3: The parent and child1 are clipped. When surfaces are enabled, the | |
2335 // parent clip rect only contributes to the subtree rooted at child2, since | |
2336 // the subtree rooted at child1 renders into a separate surface. Similarly, | |
2337 // child1's clip rect doesn't contribute to its descendants, since its only | |
2338 // child is a render surface. However, without surfaces, these clip rects | |
2339 // contribute to all descendants. | |
2340 parent->SetMasksToBounds(true); | |
2341 child1->SetMasksToBounds(true); | |
2342 host_impl()->active_tree()->property_trees()->needs_rebuild = true; | |
2343 root->test_properties()->force_render_surface = true; | |
2344 child1->test_properties()->force_render_surface = true; | |
2345 grand_child->test_properties()->force_render_surface = true; | |
2346 ExecuteCalculateDrawProperties(root); | |
2347 EXPECT_TRUE(GetRenderSurface(root)); | |
2348 EXPECT_FALSE(GetRenderSurface(parent)); | |
2349 EXPECT_TRUE(GetRenderSurface(child1)); | |
2350 EXPECT_FALSE(GetRenderSurface(child2)); | |
2351 EXPECT_TRUE(GetRenderSurface(grand_child)); | |
2352 EXPECT_FALSE(GetRenderSurface(leaf_node1)); | |
2353 EXPECT_FALSE(GetRenderSurface(leaf_node2)); | |
2354 EXPECT_FALSE(root->is_clipped()); | |
2355 EXPECT_TRUE(GetRenderSurface(root)->is_clipped()); | |
2356 EXPECT_TRUE(parent->is_clipped()); | |
2357 EXPECT_TRUE(child1->is_clipped()); | |
2358 EXPECT_TRUE(child2->is_clipped()); | |
2359 EXPECT_FALSE(grand_child->is_clipped()); | |
2360 EXPECT_TRUE(GetRenderSurface(grand_child)->is_clipped()); | |
2361 EXPECT_FALSE(leaf_node1->is_clipped()); | |
2362 EXPECT_TRUE(leaf_node2->is_clipped()); | |
2363 EXPECT_EQ(gfx::Rect(100, 100), GetRenderSurface(root)->clip_rect()); | |
2364 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect()); | |
2365 EXPECT_EQ(gfx::Rect(800, 800), child1->clip_rect()); | |
2366 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), child2->clip_rect()); | |
2367 EXPECT_EQ(gfx::Rect(800, 800), GetRenderSurface(grand_child)->clip_rect()); | |
2368 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), leaf_node2->clip_rect()); | |
2369 | |
2370 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); | |
2371 EXPECT_FALSE(root->is_clipped()); | |
2372 EXPECT_TRUE(GetRenderSurface(root)->is_clipped()); | |
2373 EXPECT_TRUE(parent->is_clipped()); | |
2374 EXPECT_TRUE(child1->is_clipped()); | |
2375 EXPECT_TRUE(child2->is_clipped()); | |
2376 EXPECT_TRUE(grand_child->is_clipped()); | |
2377 EXPECT_TRUE(leaf_node1->is_clipped()); | |
2378 EXPECT_TRUE(leaf_node2->is_clipped()); | |
2379 EXPECT_EQ(gfx::Rect(100, 100), GetRenderSurface(root)->clip_rect()); | |
2380 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect()); | |
2381 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), child1->clip_rect()); | |
2382 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), child2->clip_rect()); | |
2383 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), grand_child->clip_rect()); | |
2384 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), leaf_node1->clip_rect()); | |
2385 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), leaf_node2->clip_rect()); | |
2386 } | |
2387 | |
2388 TEST_F(LayerTreeHostCommonTest, HitTestingWhenSurfacesDisabled) { | |
2389 LayerImpl* root = root_layer_for_testing(); | |
2390 LayerImpl* parent = AddChild<LayerImpl>(root); | |
2391 LayerImpl* child = AddChild<LayerImpl>(parent); | |
2392 LayerImpl* grand_child = AddChild<LayerImpl>(child); | |
2393 LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child); | |
2394 | |
2395 root->SetBounds(gfx::Size(100, 100)); | |
2396 parent->SetPosition(gfx::PointF(2.f, 2.f)); | |
2397 parent->SetBounds(gfx::Size(400, 400)); | |
2398 parent->SetMasksToBounds(true); | |
2399 child->SetPosition(gfx::PointF(4.f, 4.f)); | |
2400 child->SetBounds(gfx::Size(800, 800)); | |
2401 child->SetMasksToBounds(true); | |
2402 child->test_properties()->force_render_surface = true; | |
2403 grand_child->SetPosition(gfx::PointF(8.f, 8.f)); | |
2404 grand_child->SetBounds(gfx::Size(1500, 1500)); | |
2405 grand_child->test_properties()->force_render_surface = true; | |
2406 leaf_node->SetPosition(gfx::PointF(16.f, 16.f)); | |
2407 leaf_node->SetBounds(gfx::Size(2000, 2000)); | |
2408 | |
2409 root->SetDrawsContent(true); | |
2410 parent->SetDrawsContent(true); | |
2411 child->SetDrawsContent(true); | |
2412 grand_child->SetDrawsContent(true); | |
2413 leaf_node->SetDrawsContent(true); | |
2414 | |
2415 host_impl()->set_resourceless_software_draw_for_testing(); | |
2416 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); | |
2417 gfx::PointF test_point(90.f, 90.f); | |
2418 LayerImpl* result_layer = | |
2419 root->layer_tree_impl()->FindLayerThatIsHitByPoint(test_point); | |
2420 ASSERT_TRUE(result_layer); | |
2421 EXPECT_EQ(leaf_node, result_layer); | |
2422 } | |
2423 | |
2424 TEST_F(LayerTreeHostCommonTest, SurfacesDisabledAndReEnabled) { | |
2425 // Tests that draw properties are computed correctly when we disable and then | |
2426 // re-enable separate surfaces. | |
2427 LayerImpl* root = root_layer_for_testing(); | |
2428 LayerImpl* parent = AddChild<LayerImpl>(root); | |
2429 LayerImpl* child = AddChild<LayerImpl>(parent); | |
2430 LayerImpl* grand_child = AddChild<LayerImpl>(child); | |
2431 LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child); | |
2432 | |
2433 root->SetBounds(gfx::Size(100, 100)); | |
2434 parent->SetPosition(gfx::PointF(2.f, 2.f)); | |
2435 parent->SetBounds(gfx::Size(400, 400)); | |
2436 parent->SetMasksToBounds(true); | |
2437 child->SetPosition(gfx::PointF(4.f, 4.f)); | |
2438 child->SetBounds(gfx::Size(800, 800)); | |
2439 child->SetMasksToBounds(true); | |
2440 child->test_properties()->force_render_surface = true; | |
2441 grand_child->SetPosition(gfx::PointF(8.f, 8.f)); | |
2442 grand_child->SetBounds(gfx::Size(1500, 1500)); | |
2443 grand_child->test_properties()->force_render_surface = true; | |
2444 leaf_node->SetPosition(gfx::PointF(16.f, 16.f)); | |
2445 leaf_node->SetBounds(gfx::Size(2000, 2000)); | |
2446 | |
2447 root->SetDrawsContent(true); | |
2448 parent->SetDrawsContent(true); | |
2449 child->SetDrawsContent(true); | |
2450 grand_child->SetDrawsContent(true); | |
2451 leaf_node->SetDrawsContent(true); | |
2452 | |
2453 gfx::Transform expected_leaf_draw_transform_with_surfaces; | |
2454 expected_leaf_draw_transform_with_surfaces.Translate(16.0, 16.0); | |
2455 | |
2456 gfx::Transform expected_leaf_draw_transform_without_surfaces; | |
2457 expected_leaf_draw_transform_without_surfaces.Translate(30.0, 30.0); | |
2458 | |
2459 ExecuteCalculateDrawProperties(root); | |
2460 EXPECT_FALSE(leaf_node->is_clipped()); | |
2461 EXPECT_TRUE(leaf_node->render_target()->is_clipped()); | |
2462 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect()); | |
2463 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_leaf_draw_transform_with_surfaces, | |
2464 leaf_node->DrawTransform()); | |
2465 | |
2466 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); | |
2467 EXPECT_TRUE(leaf_node->is_clipped()); | |
2468 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), leaf_node->clip_rect()); | |
2469 EXPECT_EQ(gfx::Rect(30, 30, 372, 372), leaf_node->drawable_content_rect()); | |
2470 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_leaf_draw_transform_without_surfaces, | |
2471 leaf_node->DrawTransform()); | |
2472 | |
2473 ExecuteCalculateDrawProperties(root); | |
2474 EXPECT_FALSE(leaf_node->is_clipped()); | |
2475 EXPECT_TRUE(leaf_node->render_target()->is_clipped()); | |
2476 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect()); | |
2477 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_leaf_draw_transform_with_surfaces, | |
2478 leaf_node->DrawTransform()); | |
2479 } | |
2480 | |
2481 TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) { | 1950 TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) { |
2482 LayerImpl* root = root_layer_for_testing(); | 1951 LayerImpl* root = root_layer_for_testing(); |
2483 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); | 1952 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
2484 LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1); | 1953 LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1); |
2485 LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1); | 1954 LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1); |
2486 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); | 1955 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); |
2487 LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2); | 1956 LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2); |
2488 LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2); | 1957 LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2); |
2489 LayerImpl* child_of_root = AddChildToRoot<LayerImpl>(); | 1958 LayerImpl* child_of_root = AddChildToRoot<LayerImpl>(); |
2490 LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root); | 1959 LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root); |
(...skipping 854 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3345 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); | 2814 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
3346 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect()); | 2815 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect()); |
3347 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child3->visible_layer_rect()); | 2816 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child3->visible_layer_rect()); |
3348 | 2817 |
3349 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); | 2818 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
3350 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); | 2819 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
3351 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); | 2820 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
3352 } | 2821 } |
3353 | 2822 |
3354 TEST_F(LayerTreeHostCommonTest, | 2823 TEST_F(LayerTreeHostCommonTest, |
3355 DrawableAndVisibleRectsWhenCannotRenderToSeparateSurface) { | |
3356 LayerImpl* root = root_layer_for_testing(); | |
3357 LayerImpl* parent = AddChild<LayerImpl>(root); | |
3358 LayerImpl* child1 = AddChild<LayerImpl>(parent); | |
3359 LayerImpl* child2 = AddChild<LayerImpl>(parent); | |
3360 LayerImpl* grand_child1 = AddChild<LayerImpl>(child1); | |
3361 LayerImpl* grand_child2 = AddChild<LayerImpl>(child2); | |
3362 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1); | |
3363 LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2); | |
3364 | |
3365 root->SetBounds(gfx::Size(100, 100)); | |
3366 parent->SetPosition(gfx::PointF(2.f, 2.f)); | |
3367 parent->SetBounds(gfx::Size(400, 400)); | |
3368 child1->SetPosition(gfx::PointF(4.f, 4.f)); | |
3369 child1->SetBounds(gfx::Size(800, 800)); | |
3370 child1->test_properties()->force_render_surface = true; | |
3371 child2->SetPosition(gfx::PointF(3.f, 3.f)); | |
3372 child2->SetBounds(gfx::Size(800, 800)); | |
3373 child2->test_properties()->force_render_surface = true; | |
3374 grand_child1->SetPosition(gfx::PointF(8.f, 8.f)); | |
3375 grand_child1->SetBounds(gfx::Size(1500, 1500)); | |
3376 grand_child2->SetPosition(gfx::PointF(7.f, 7.f)); | |
3377 grand_child2->SetBounds(gfx::Size(1500, 1500)); | |
3378 leaf_node1->SetPosition(gfx::PointF(16.f, 16.f)); | |
3379 leaf_node1->SetBounds(gfx::Size(2000, 2000)); | |
3380 leaf_node2->SetPosition(gfx::PointF(9.f, 9.f)); | |
3381 leaf_node2->SetBounds(gfx::Size(2000, 2000)); | |
3382 | |
3383 root->SetDrawsContent(true); | |
3384 parent->SetDrawsContent(true); | |
3385 child1->SetDrawsContent(true); | |
3386 child2->SetDrawsContent(true); | |
3387 grand_child1->SetDrawsContent(true); | |
3388 grand_child2->SetDrawsContent(true); | |
3389 leaf_node1->SetDrawsContent(true); | |
3390 leaf_node2->SetDrawsContent(true); | |
3391 | |
3392 // Case 1: No layers clip. Visible rects are clipped by the viewport. | |
3393 // Each layer's drawable content rect is its bounds in target space; the only | |
3394 // thing that changes with surfaces disabled is that target space is always | |
3395 // screen space. | |
3396 child1->test_properties()->force_render_surface = true; | |
3397 child2->test_properties()->force_render_surface = true; | |
3398 ExecuteCalculateDrawProperties(root); | |
3399 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); | |
3400 EXPECT_EQ(gfx::Rect(0, 0, 98, 98), parent->visible_layer_rect()); | |
3401 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); | |
3402 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); | |
3403 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); | |
3404 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); | |
3405 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); | |
3406 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); | |
3407 | |
3408 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); | |
3409 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); | |
3410 EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect()); | |
3411 EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect()); | |
3412 EXPECT_EQ(gfx::Rect(8, 8, 1500, 1500), grand_child1->drawable_content_rect()); | |
3413 EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect()); | |
3414 EXPECT_EQ(gfx::Rect(24, 24, 2000, 2000), leaf_node1->drawable_content_rect()); | |
3415 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node2->drawable_content_rect()); | |
3416 | |
3417 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); | |
3418 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); | |
3419 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); | |
3420 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); | |
3421 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); | |
3422 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); | |
3423 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); | |
3424 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); | |
3425 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); | |
3426 | |
3427 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); | |
3428 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); | |
3429 EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->drawable_content_rect()); | |
3430 EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->drawable_content_rect()); | |
3431 EXPECT_EQ(gfx::Rect(14, 14, 1500, 1500), | |
3432 grand_child1->drawable_content_rect()); | |
3433 EXPECT_EQ(gfx::Rect(12, 12, 1500, 1500), | |
3434 grand_child2->drawable_content_rect()); | |
3435 EXPECT_EQ(gfx::Rect(30, 30, 2000, 2000), leaf_node1->drawable_content_rect()); | |
3436 EXPECT_EQ(gfx::Rect(21, 21, 2000, 2000), leaf_node2->drawable_content_rect()); | |
3437 | |
3438 // Case 2: The parent clips. In this case, neither surface is unclipped, so | |
3439 // all visible layer rects are clipped by the intersection of all ancestor | |
3440 // clips, whether or not surfaces are disabled. However, drawable content | |
3441 // rects are clipped only until the next render surface is reached, so | |
3442 // descendants of parent have their drawable content rects clipped only when | |
3443 // surfaces are disabled. | |
3444 parent->SetMasksToBounds(true); | |
3445 host_impl()->active_tree()->property_trees()->needs_rebuild = true; | |
3446 ExecuteCalculateDrawProperties(root); | |
3447 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); | |
3448 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); | |
3449 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); | |
3450 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); | |
3451 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); | |
3452 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); | |
3453 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); | |
3454 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); | |
3455 | |
3456 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); | |
3457 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); | |
3458 EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect()); | |
3459 EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect()); | |
3460 EXPECT_EQ(gfx::Rect(8, 8, 1500, 1500), grand_child1->drawable_content_rect()); | |
3461 EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect()); | |
3462 EXPECT_EQ(gfx::Rect(24, 24, 2000, 2000), leaf_node1->drawable_content_rect()); | |
3463 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node2->drawable_content_rect()); | |
3464 | |
3465 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); | |
3466 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); | |
3467 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); | |
3468 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); | |
3469 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); | |
3470 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); | |
3471 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); | |
3472 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); | |
3473 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); | |
3474 | |
3475 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); | |
3476 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); | |
3477 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), child1->drawable_content_rect()); | |
3478 EXPECT_EQ(gfx::Rect(5, 5, 397, 397), child2->drawable_content_rect()); | |
3479 EXPECT_EQ(gfx::Rect(14, 14, 388, 388), grand_child1->drawable_content_rect()); | |
3480 EXPECT_EQ(gfx::Rect(12, 12, 390, 390), grand_child2->drawable_content_rect()); | |
3481 EXPECT_EQ(gfx::Rect(30, 30, 372, 372), leaf_node1->drawable_content_rect()); | |
3482 EXPECT_EQ(gfx::Rect(21, 21, 381, 381), leaf_node2->drawable_content_rect()); | |
3483 | |
3484 parent->SetMasksToBounds(false); | |
3485 | |
3486 // Case 3: child1 and grand_child2 clip. In this case, descendants of these | |
3487 // layers have their visible rects clipped by them; Similarly, descendants of | |
3488 // these layers have their drawable content rects clipped by them. | |
3489 child1->SetMasksToBounds(true); | |
3490 grand_child2->SetMasksToBounds(true); | |
3491 host_impl()->active_tree()->property_trees()->needs_rebuild = true; | |
3492 ExecuteCalculateDrawProperties(root); | |
3493 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); | |
3494 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); | |
3495 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); | |
3496 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); | |
3497 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); | |
3498 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); | |
3499 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); | |
3500 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); | |
3501 | |
3502 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); | |
3503 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); | |
3504 EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect()); | |
3505 EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect()); | |
3506 EXPECT_EQ(gfx::Rect(8, 8, 792, 792), grand_child1->drawable_content_rect()); | |
3507 EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect()); | |
3508 EXPECT_EQ(gfx::Rect(24, 24, 776, 776), leaf_node1->drawable_content_rect()); | |
3509 EXPECT_EQ(gfx::Rect(16, 16, 1491, 1491), leaf_node2->drawable_content_rect()); | |
3510 | |
3511 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); | |
3512 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); | |
3513 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); | |
3514 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); | |
3515 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); | |
3516 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); | |
3517 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); | |
3518 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); | |
3519 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); | |
3520 | |
3521 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); | |
3522 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); | |
3523 EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->drawable_content_rect()); | |
3524 EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->drawable_content_rect()); | |
3525 EXPECT_EQ(gfx::Rect(14, 14, 792, 792), grand_child1->drawable_content_rect()); | |
3526 EXPECT_EQ(gfx::Rect(12, 12, 1500, 1500), | |
3527 grand_child2->drawable_content_rect()); | |
3528 EXPECT_EQ(gfx::Rect(30, 30, 776, 776), leaf_node1->drawable_content_rect()); | |
3529 EXPECT_EQ(gfx::Rect(21, 21, 1491, 1491), leaf_node2->drawable_content_rect()); | |
3530 } | |
3531 | |
3532 TEST_F(LayerTreeHostCommonTest, | |
3533 VisibleContentRectsForClippedSurfaceWithEmptyClip) { | 2824 VisibleContentRectsForClippedSurfaceWithEmptyClip) { |
3534 LayerImpl* root = root_layer_for_testing(); | 2825 LayerImpl* root = root_layer_for_testing(); |
3535 LayerImpl* child1 = AddChild<LayerImpl>(root); | 2826 LayerImpl* child1 = AddChild<LayerImpl>(root); |
3536 LayerImpl* child2 = AddChild<LayerImpl>(root); | 2827 LayerImpl* child2 = AddChild<LayerImpl>(root); |
3537 LayerImpl* child3 = AddChild<LayerImpl>(root); | 2828 LayerImpl* child3 = AddChild<LayerImpl>(root); |
3538 | 2829 |
3539 root->SetBounds(gfx::Size(100, 100)); | 2830 root->SetBounds(gfx::Size(100, 100)); |
3540 child1->SetPosition(gfx::PointF(5.f, 5.f)); | 2831 child1->SetPosition(gfx::PointF(5.f, 5.f)); |
3541 child1->SetBounds(gfx::Size(50, 50)); | 2832 child1->SetBounds(gfx::Size(50, 50)); |
3542 child1->SetDrawsContent(true); | 2833 child1->SetDrawsContent(true); |
(...skipping 2590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6133 child3->test_properties()->sorting_context_id = 1; | 5424 child3->test_properties()->sorting_context_id = 1; |
6134 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); | 5425 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
6135 | 5426 |
6136 // Verify which render surfaces were created. | 5427 // Verify which render surfaces were created. |
6137 EXPECT_TRUE(GetRenderSurface(root)); | 5428 EXPECT_TRUE(GetRenderSurface(root)); |
6138 EXPECT_FALSE(GetRenderSurface(child1)); | 5429 EXPECT_FALSE(GetRenderSurface(child1)); |
6139 EXPECT_TRUE(GetRenderSurface(child2)); | 5430 EXPECT_TRUE(GetRenderSurface(child2)); |
6140 EXPECT_FALSE(GetRenderSurface(child3)); | 5431 EXPECT_FALSE(GetRenderSurface(child3)); |
6141 } | 5432 } |
6142 | 5433 |
6143 TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) { | |
6144 FakeImplTaskRunnerProvider task_runner_provider; | |
6145 TestTaskGraphRunner task_graph_runner; | |
6146 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); | |
6147 | |
6148 std::unique_ptr<LayerImpl> root = | |
6149 LayerImpl::Create(host_impl.active_tree(), 12345); | |
6150 std::unique_ptr<LayerImpl> child1 = | |
6151 LayerImpl::Create(host_impl.active_tree(), 123456); | |
6152 std::unique_ptr<LayerImpl> child2 = | |
6153 LayerImpl::Create(host_impl.active_tree(), 1234567); | |
6154 std::unique_ptr<LayerImpl> child3 = | |
6155 LayerImpl::Create(host_impl.active_tree(), 12345678); | |
6156 | |
6157 gfx::Size bounds(100, 100); | |
6158 | |
6159 root->SetBounds(bounds); | |
6160 root->SetDrawsContent(true); | |
6161 | |
6162 // This layer structure normally forces render surface due to preserves3d | |
6163 // behavior. | |
6164 child1->SetBounds(bounds); | |
6165 child1->SetDrawsContent(true); | |
6166 child1->test_properties()->should_flatten_transform = false; | |
6167 child1->test_properties()->sorting_context_id = 1; | |
6168 child2->SetBounds(bounds); | |
6169 child2->SetDrawsContent(true); | |
6170 child2->test_properties()->sorting_context_id = 1; | |
6171 child3->SetBounds(bounds); | |
6172 child3->SetDrawsContent(true); | |
6173 child3->test_properties()->sorting_context_id = 1; | |
6174 | |
6175 child2->test_properties()->AddChild(std::move(child3)); | |
6176 child1->test_properties()->AddChild(std::move(child2)); | |
6177 root->test_properties()->AddChild(std::move(child1)); | |
6178 LayerImpl* root_layer = root.get(); | |
6179 root_layer->layer_tree_impl()->SetRootLayerForTesting(std::move(root)); | |
6180 | |
6181 { | |
6182 RenderSurfaceList render_surface_list; | |
6183 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( | |
6184 root_layer, root_layer->bounds(), &render_surface_list); | |
6185 inputs.can_render_to_separate_surface = true; | |
6186 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); | |
6187 | |
6188 EXPECT_EQ(2u, render_surface_list.size()); | |
6189 | |
6190 int count_represents_target_render_surface = 0; | |
6191 int count_represents_contributing_render_surface = 0; | |
6192 int count_represents_itself = 0; | |
6193 for (EffectTreeLayerListIterator it(host_impl.active_tree()); | |
6194 it.state() != EffectTreeLayerListIterator::State::END; ++it) { | |
6195 if (it.state() == EffectTreeLayerListIterator::State::TARGET_SURFACE) { | |
6196 count_represents_target_render_surface++; | |
6197 } else if (it.state() == | |
6198 EffectTreeLayerListIterator::State::CONTRIBUTING_SURFACE) { | |
6199 count_represents_contributing_render_surface++; | |
6200 } else { | |
6201 count_represents_itself++; | |
6202 } | |
6203 } | |
6204 | |
6205 // Two render surfaces. | |
6206 EXPECT_EQ(2, count_represents_target_render_surface); | |
6207 // Second render surface contributes to root render surface. | |
6208 EXPECT_EQ(1, count_represents_contributing_render_surface); | |
6209 // All 4 layers represent itself. | |
6210 EXPECT_EQ(4, count_represents_itself); | |
6211 } | |
6212 | |
6213 { | |
6214 RenderSurfaceList render_surface_list; | |
6215 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( | |
6216 root_layer, root_layer->bounds(), &render_surface_list); | |
6217 inputs.can_render_to_separate_surface = false; | |
6218 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); | |
6219 | |
6220 EXPECT_EQ(1u, render_surface_list.size()); | |
6221 | |
6222 int count_represents_target_render_surface = 0; | |
6223 int count_represents_contributing_render_surface = 0; | |
6224 int count_represents_itself = 0; | |
6225 for (EffectTreeLayerListIterator it(host_impl.active_tree()); | |
6226 it.state() != EffectTreeLayerListIterator::State::END; ++it) { | |
6227 if (it.state() == EffectTreeLayerListIterator::State::TARGET_SURFACE) { | |
6228 count_represents_target_render_surface++; | |
6229 } else if (it.state() == | |
6230 EffectTreeLayerListIterator::State::CONTRIBUTING_SURFACE) { | |
6231 count_represents_contributing_render_surface++; | |
6232 } else { | |
6233 count_represents_itself++; | |
6234 } | |
6235 } | |
6236 | |
6237 // Only root layer has a render surface. | |
6238 EXPECT_EQ(1, count_represents_target_render_surface); | |
6239 // No layer contributes a render surface to root render surface. | |
6240 EXPECT_EQ(0, count_represents_contributing_render_surface); | |
6241 // All 4 layers represent itself. | |
6242 EXPECT_EQ(4, count_represents_itself); | |
6243 } | |
6244 } | |
6245 | |
6246 TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) { | 5434 TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) { |
6247 LayerImpl* root = root_layer_for_testing(); | 5435 LayerImpl* root = root_layer_for_testing(); |
6248 LayerImpl* back_facing = AddChild<LayerImpl>(root); | 5436 LayerImpl* back_facing = AddChild<LayerImpl>(root); |
6249 | 5437 |
6250 LayerImpl* render_surface1 = AddChild<LayerImpl>(back_facing); | 5438 LayerImpl* render_surface1 = AddChild<LayerImpl>(back_facing); |
6251 LayerImpl* child1 = AddChild<LayerImpl>(render_surface1); | 5439 LayerImpl* child1 = AddChild<LayerImpl>(render_surface1); |
6252 | 5440 |
6253 LayerImpl* flattener = AddChild<LayerImpl>(back_facing); | 5441 LayerImpl* flattener = AddChild<LayerImpl>(back_facing); |
6254 LayerImpl* render_surface2 = AddChild<LayerImpl>(flattener); | 5442 LayerImpl* render_surface2 = AddChild<LayerImpl>(flattener); |
6255 LayerImpl* child2 = AddChild<LayerImpl>(render_surface2); | 5443 LayerImpl* child2 = AddChild<LayerImpl>(render_surface2); |
(...skipping 4649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10905 | 10093 |
10906 // Check child layer draw properties. | 10094 // Check child layer draw properties. |
10907 EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect()); | 10095 EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect()); |
10908 EXPECT_EQ(gfx::Transform(), child->DrawTransform()); | 10096 EXPECT_EQ(gfx::Transform(), child->DrawTransform()); |
10909 EXPECT_EQ(gfx::Rect(10, 10), child->clip_rect()); | 10097 EXPECT_EQ(gfx::Rect(10, 10), child->clip_rect()); |
10910 EXPECT_EQ(gfx::Rect(10, 10), child->drawable_content_rect()); | 10098 EXPECT_EQ(gfx::Rect(10, 10), child->drawable_content_rect()); |
10911 } | 10099 } |
10912 | 10100 |
10913 } // namespace | 10101 } // namespace |
10914 } // namespace cc | 10102 } // namespace cc |
OLD | NEW |