| 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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 root_layer, device_scale_factor, 1.f, page_scale_application_layer, | 184 root_layer, device_scale_factor, 1.f, page_scale_application_layer, |
| 185 inner_viewport_scroll_layer, outer_viewport_scroll_layer); | 185 inner_viewport_scroll_layer, outer_viewport_scroll_layer); |
| 186 } | 186 } |
| 187 | 187 |
| 188 const LayerList* GetUpdateLayerList() { return &update_layer_list_; } | 188 const LayerList* GetUpdateLayerList() { return &update_layer_list_; } |
| 189 | 189 |
| 190 void ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(Layer* root_layer) { | 190 void ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(Layer* root_layer) { |
| 191 DCHECK(root_layer->layer_tree_host()); | 191 DCHECK(root_layer->layer_tree_host()); |
| 192 PropertyTreeBuilder::PreCalculateMetaInformation(root_layer); | 192 PropertyTreeBuilder::PreCalculateMetaInformation(root_layer); |
| 193 | 193 |
| 194 bool can_render_to_separate_surface = true; | |
| 195 | |
| 196 const Layer* page_scale_layer = | 194 const Layer* page_scale_layer = |
| 197 root_layer->layer_tree_host()->page_scale_layer(); | 195 root_layer->layer_tree_host()->page_scale_layer(); |
| 198 Layer* inner_viewport_scroll_layer = | 196 Layer* inner_viewport_scroll_layer = |
| 199 root_layer->layer_tree_host()->inner_viewport_scroll_layer(); | 197 root_layer->layer_tree_host()->inner_viewport_scroll_layer(); |
| 200 Layer* outer_viewport_scroll_layer = | 198 Layer* outer_viewport_scroll_layer = |
| 201 root_layer->layer_tree_host()->outer_viewport_scroll_layer(); | 199 root_layer->layer_tree_host()->outer_viewport_scroll_layer(); |
| 202 const Layer* overscroll_elasticity_layer = | 200 const Layer* overscroll_elasticity_layer = |
| 203 root_layer->layer_tree_host()->overscroll_elasticity_layer(); | 201 root_layer->layer_tree_host()->overscroll_elasticity_layer(); |
| 204 gfx::Vector2dF elastic_overscroll = | 202 gfx::Vector2dF elastic_overscroll = |
| 205 root_layer->layer_tree_host()->elastic_overscroll(); | 203 root_layer->layer_tree_host()->elastic_overscroll(); |
| 206 float page_scale_factor = 1.f; | 204 float page_scale_factor = 1.f; |
| 207 float device_scale_factor = 1.f; | 205 float device_scale_factor = 1.f; |
| 208 gfx::Size device_viewport_size = | 206 gfx::Size device_viewport_size = |
| 209 gfx::Size(root_layer->bounds().width() * device_scale_factor, | 207 gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 210 root_layer->bounds().height() * device_scale_factor); | 208 root_layer->bounds().height() * device_scale_factor); |
| 211 PropertyTrees* property_trees = | 209 PropertyTrees* property_trees = |
| 212 root_layer->layer_tree_host()->property_trees(); | 210 root_layer->layer_tree_host()->property_trees(); |
| 213 update_layer_list_.clear(); | 211 update_layer_list_.clear(); |
| 214 PropertyTreeBuilder::BuildPropertyTrees( | 212 PropertyTreeBuilder::BuildPropertyTrees( |
| 215 root_layer, page_scale_layer, inner_viewport_scroll_layer, | 213 root_layer, page_scale_layer, inner_viewport_scroll_layer, |
| 216 outer_viewport_scroll_layer, overscroll_elasticity_layer, | 214 outer_viewport_scroll_layer, overscroll_elasticity_layer, |
| 217 elastic_overscroll, page_scale_factor, device_scale_factor, | 215 elastic_overscroll, page_scale_factor, device_scale_factor, |
| 218 gfx::Rect(device_viewport_size), gfx::Transform(), property_trees); | 216 gfx::Rect(device_viewport_size), gfx::Transform(), property_trees); |
| 219 draw_property_utils::UpdatePropertyTrees(property_trees, | 217 draw_property_utils::UpdatePropertyTrees(property_trees); |
| 220 can_render_to_separate_surface); | |
| 221 draw_property_utils::FindLayersThatNeedUpdates( | 218 draw_property_utils::FindLayersThatNeedUpdates( |
| 222 root_layer->layer_tree_host(), property_trees, &update_layer_list_); | 219 root_layer->layer_tree_host(), property_trees, &update_layer_list_); |
| 223 } | 220 } |
| 224 | 221 |
| 225 void ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList( | 222 void ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList( |
| 226 LayerImpl* root_layer, | 223 LayerImpl* root_layer, |
| 227 bool skip_verify_visible_rect_calculations = false) { | 224 bool skip_verify_visible_rect_calculations = false) { |
| 228 DCHECK(root_layer->layer_tree_impl()); | 225 DCHECK(root_layer->layer_tree_impl()); |
| 229 PropertyTreeBuilder::PreCalculateMetaInformationForTesting(root_layer); | 226 PropertyTreeBuilder::PreCalculateMetaInformationForTesting(root_layer); |
| 230 | 227 |
| 231 bool can_render_to_separate_surface = true; | |
| 232 | |
| 233 LayerImpl* page_scale_layer = nullptr; | 228 LayerImpl* page_scale_layer = nullptr; |
| 234 LayerImpl* inner_viewport_scroll_layer = | 229 LayerImpl* inner_viewport_scroll_layer = |
| 235 root_layer->layer_tree_impl()->InnerViewportScrollLayer(); | 230 root_layer->layer_tree_impl()->InnerViewportScrollLayer(); |
| 236 LayerImpl* outer_viewport_scroll_layer = | 231 LayerImpl* outer_viewport_scroll_layer = |
| 237 root_layer->layer_tree_impl()->OuterViewportScrollLayer(); | 232 root_layer->layer_tree_impl()->OuterViewportScrollLayer(); |
| 238 LayerImpl* overscroll_elasticity_layer = | 233 LayerImpl* overscroll_elasticity_layer = |
| 239 root_layer->layer_tree_impl()->OverscrollElasticityLayer(); | 234 root_layer->layer_tree_impl()->OverscrollElasticityLayer(); |
| 240 gfx::Vector2dF elastic_overscroll = | 235 gfx::Vector2dF elastic_overscroll = |
| 241 root_layer->layer_tree_impl()->elastic_overscroll()->Current( | 236 root_layer->layer_tree_impl()->elastic_overscroll()->Current( |
| 242 root_layer->layer_tree_impl()->IsActiveTree()); | 237 root_layer->layer_tree_impl()->IsActiveTree()); |
| 243 float page_scale_factor = 1.f; | 238 float page_scale_factor = 1.f; |
| 244 float device_scale_factor = 1.f; | 239 float device_scale_factor = 1.f; |
| 245 gfx::Size device_viewport_size = | 240 gfx::Size device_viewport_size = |
| 246 gfx::Size(root_layer->bounds().width() * device_scale_factor, | 241 gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 247 root_layer->bounds().height() * device_scale_factor); | 242 root_layer->bounds().height() * device_scale_factor); |
| 248 update_layer_list_impl_.reset(new LayerImplList); | 243 update_layer_list_impl_.reset(new LayerImplList); |
| 249 root_layer->layer_tree_impl()->BuildLayerListForTesting(); | 244 root_layer->layer_tree_impl()->BuildLayerListForTesting(); |
| 250 PropertyTrees* property_trees = | 245 PropertyTrees* property_trees = |
| 251 root_layer->layer_tree_impl()->property_trees(); | 246 root_layer->layer_tree_impl()->property_trees(); |
| 252 draw_property_utils::BuildPropertyTreesAndComputeVisibleRects( | 247 draw_property_utils::BuildPropertyTreesAndComputeVisibleRects( |
| 253 root_layer, page_scale_layer, inner_viewport_scroll_layer, | 248 root_layer, page_scale_layer, inner_viewport_scroll_layer, |
| 254 outer_viewport_scroll_layer, overscroll_elasticity_layer, | 249 outer_viewport_scroll_layer, overscroll_elasticity_layer, |
| 255 elastic_overscroll, page_scale_factor, device_scale_factor, | 250 elastic_overscroll, page_scale_factor, device_scale_factor, |
| 256 gfx::Rect(device_viewport_size), gfx::Transform(), | 251 gfx::Rect(device_viewport_size), gfx::Transform(), property_trees, |
| 257 can_render_to_separate_surface, property_trees, | |
| 258 update_layer_list_impl_.get()); | 252 update_layer_list_impl_.get()); |
| 259 draw_property_utils::VerifyClipTreeCalculations(*update_layer_list_impl_, | 253 draw_property_utils::VerifyClipTreeCalculations(*update_layer_list_impl_, |
| 260 property_trees); | 254 property_trees); |
| 261 if (!skip_verify_visible_rect_calculations) | 255 if (!skip_verify_visible_rect_calculations) |
| 262 draw_property_utils::VerifyVisibleRectsCalculations( | 256 draw_property_utils::VerifyVisibleRectsCalculations( |
| 263 *update_layer_list_impl_, property_trees); | 257 *update_layer_list_impl_, property_trees); |
| 264 } | 258 } |
| 265 | 259 |
| 266 void ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces( | |
| 267 LayerImpl* root_layer) { | |
| 268 gfx::Size device_viewport_size = | |
| 269 gfx::Size(root_layer->bounds().width(), root_layer->bounds().height()); | |
| 270 render_surface_layer_list_impl_.reset(new LayerImplList); | |
| 271 | |
| 272 DCHECK(!root_layer->bounds().IsEmpty()); | |
| 273 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( | |
| 274 root_layer, device_viewport_size, | |
| 275 render_surface_layer_list_impl_.get()); | |
| 276 inputs.can_adjust_raster_scales = true; | |
| 277 inputs.can_render_to_separate_surface = false; | |
| 278 | |
| 279 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); | |
| 280 } | |
| 281 | |
| 282 bool UpdateLayerListImplContains(int id) const { | 260 bool UpdateLayerListImplContains(int id) const { |
| 283 for (auto* layer : *update_layer_list_impl_) { | 261 for (auto* layer : *update_layer_list_impl_) { |
| 284 if (layer->id() == id) | 262 if (layer->id() == id) |
| 285 return true; | 263 return true; |
| 286 } | 264 } |
| 287 return false; | 265 return false; |
| 288 } | 266 } |
| 289 | 267 |
| 290 bool UpdateLayerListContains(int id) const { | 268 bool UpdateLayerListContains(int id) const { |
| 291 for (const auto& layer : update_layer_list_) { | 269 for (const auto& layer : update_layer_list_) { |
| (...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 759 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_composite_transform, | 737 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_composite_transform, |
| 760 child->render_target()->draw_transform()); | 738 child->render_target()->draw_transform()); |
| 761 | 739 |
| 762 // The screen space is the same as the target since the child surface draws | 740 // The screen space is the same as the target since the child surface draws |
| 763 // into the root. | 741 // into the root. |
| 764 EXPECT_TRANSFORMATION_MATRIX_EQ( | 742 EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 765 surface_sublayer_composite_transform, | 743 surface_sublayer_composite_transform, |
| 766 child->render_target()->screen_space_transform()); | 744 child->render_target()->screen_space_transform()); |
| 767 } | 745 } |
| 768 | 746 |
| 769 TEST_F(LayerTreeHostCommonTest, TransformsWhenCannotRenderToSeparateSurface) { | |
| 770 LayerImpl* root = root_layer_for_testing(); | |
| 771 LayerImpl* parent = AddChildToRoot<LayerImpl>(); | |
| 772 LayerImpl* child = AddChild<LayerImpl>(parent); | |
| 773 LayerImpl* grand_child = AddChild<LayerImpl>(child); | |
| 774 | |
| 775 gfx::Transform parent_transform; | |
| 776 parent_transform.Translate(10.0, 10.0); | |
| 777 | |
| 778 gfx::Transform child_transform; | |
| 779 child_transform.Rotate(45.0); | |
| 780 | |
| 781 root->SetBounds(gfx::Size(100, 100)); | |
| 782 parent->test_properties()->transform = parent_transform; | |
| 783 parent->SetBounds(gfx::Size(10, 10)); | |
| 784 child->test_properties()->transform = child_transform; | |
| 785 child->SetBounds(gfx::Size(10, 10)); | |
| 786 child->test_properties()->force_render_surface = true; | |
| 787 grand_child->SetPosition(gfx::PointF(2.f, 2.f)); | |
| 788 grand_child->SetBounds(gfx::Size(20, 20)); | |
| 789 grand_child->SetDrawsContent(true); | |
| 790 | |
| 791 gfx::Transform expected_grand_child_screen_space_transform; | |
| 792 expected_grand_child_screen_space_transform.Translate(10.0, 10.0); | |
| 793 expected_grand_child_screen_space_transform.Rotate(45.0); | |
| 794 expected_grand_child_screen_space_transform.Translate(2.0, 2.0); | |
| 795 | |
| 796 // First compute draw properties with separate surfaces enabled. | |
| 797 ExecuteCalculateDrawProperties(root); | |
| 798 | |
| 799 // The grand child's draw transform should be its offset wrt the child. | |
| 800 gfx::Transform expected_grand_child_draw_transform; | |
| 801 expected_grand_child_draw_transform.Translate(2.0, 2.0); | |
| 802 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform, | |
| 803 grand_child->DrawTransform()); | |
| 804 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, | |
| 805 grand_child->ScreenSpaceTransform()); | |
| 806 | |
| 807 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); | |
| 808 | |
| 809 // With separate surfaces disabled, the grand child's draw transform should be | |
| 810 // the same as its screen space transform. | |
| 811 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, | |
| 812 grand_child->DrawTransform()); | |
| 813 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, | |
| 814 grand_child->ScreenSpaceTransform()); | |
| 815 } | |
| 816 | |
| 817 TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) { | 747 TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) { |
| 818 // This test creates a more complex tree and verifies it all at once. This | 748 // This test creates a more complex tree and verifies it all at once. This |
| 819 // covers the following cases: | 749 // covers the following cases: |
| 820 // - layers that are described w.r.t. a render surface: should have draw | 750 // - layers that are described w.r.t. a render surface: should have draw |
| 821 // transforms described w.r.t. that surface | 751 // transforms described w.r.t. that surface |
| 822 // - A render surface described w.r.t. an ancestor render surface: should | 752 // - A render surface described w.r.t. an ancestor render surface: should |
| 823 // have a draw transform described w.r.t. that ancestor surface | 753 // have a draw transform described w.r.t. that ancestor surface |
| 824 // - Sanity check on recursion: verify transforms of layers described w.r.t. | 754 // - Sanity check on recursion: verify transforms of layers described w.r.t. |
| 825 // a render surface that is described w.r.t. an ancestor render surface. | 755 // a render surface that is described w.r.t. an ancestor render surface. |
| 826 // - verifying that each layer has a reference to the correct render surface | 756 // - verifying that each layer has a reference to the correct render surface |
| (...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1604 | 1534 |
| 1605 ASSERT_TRUE(surface1->render_surface()); | 1535 ASSERT_TRUE(surface1->render_surface()); |
| 1606 ASSERT_FALSE(not_surface->render_surface()); | 1536 ASSERT_FALSE(not_surface->render_surface()); |
| 1607 ASSERT_TRUE(surface2->render_surface()); | 1537 ASSERT_TRUE(surface2->render_surface()); |
| 1608 EXPECT_EQ(0.5f, surface1->render_surface()->draw_opacity()); | 1538 EXPECT_EQ(0.5f, surface1->render_surface()->draw_opacity()); |
| 1609 // surface2's draw opacity should include the opacity of not-surface and | 1539 // surface2's draw opacity should include the opacity of not-surface and |
| 1610 // itself, but not the opacity of surface1. | 1540 // itself, but not the opacity of surface1. |
| 1611 EXPECT_EQ(0.25f, surface2->render_surface()->draw_opacity()); | 1541 EXPECT_EQ(0.25f, surface2->render_surface()->draw_opacity()); |
| 1612 } | 1542 } |
| 1613 | 1543 |
| 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) { | 1544 TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) { |
| 1675 LayerImpl* root = root_layer_for_testing(); | 1545 LayerImpl* root = root_layer_for_testing(); |
| 1676 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); | 1546 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 1677 LayerImpl* child = AddChild<LayerImpl>(render_surface1); | 1547 LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
| 1678 | 1548 |
| 1679 root->SetBounds(gfx::Size(10, 10)); | 1549 root->SetBounds(gfx::Size(10, 10)); |
| 1680 render_surface1->SetBounds(gfx::Size(10, 10)); | 1550 render_surface1->SetBounds(gfx::Size(10, 10)); |
| 1681 render_surface1->test_properties()->force_render_surface = true; | 1551 render_surface1->test_properties()->force_render_surface = true; |
| 1682 child->SetBounds(gfx::Size(10, 10)); | 1552 child->SetBounds(gfx::Size(10, 10)); |
| 1683 child->SetDrawsContent(true); | 1553 child->SetDrawsContent(true); |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1947 host_impl()->active_tree()->property_trees()->needs_rebuild = true; | 1817 host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 1948 | 1818 |
| 1949 ExecuteCalculateDrawProperties(root); | 1819 ExecuteCalculateDrawProperties(root); |
| 1950 | 1820 |
| 1951 EXPECT_FALSE(root->is_clipped()); | 1821 EXPECT_FALSE(root->is_clipped()); |
| 1952 EXPECT_TRUE(parent->is_clipped()); | 1822 EXPECT_TRUE(parent->is_clipped()); |
| 1953 EXPECT_TRUE(child->is_clipped()); | 1823 EXPECT_TRUE(child->is_clipped()); |
| 1954 EXPECT_EQ(gfx::Rect(), child->clip_rect()); | 1824 EXPECT_EQ(gfx::Rect(), child->clip_rect()); |
| 1955 } | 1825 } |
| 1956 | 1826 |
| 1957 TEST_F(LayerTreeHostCommonTest, IsClippedWhenCannotRenderToSeparateSurface) { | |
| 1958 // Tests that when separate surfaces are disabled, is_clipped is true exactly | |
| 1959 // when a layer or its ancestor has a clip; in particular, if a layer | |
| 1960 // is_clipped, so is its entire subtree (since there are no render surfaces | |
| 1961 // that can reset is_clipped). | |
| 1962 LayerImpl* root = root_layer_for_testing(); | |
| 1963 LayerImpl* parent = AddChild<LayerImpl>(root); | |
| 1964 LayerImpl* child1 = AddChild<LayerImpl>(parent); | |
| 1965 LayerImpl* child2 = AddChild<LayerImpl>(parent); | |
| 1966 LayerImpl* grand_child = AddChild<LayerImpl>(child1); | |
| 1967 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child); | |
| 1968 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2); | |
| 1969 | |
| 1970 root->SetBounds(gfx::Size(100, 100)); | |
| 1971 root->SetDrawsContent(true); | |
| 1972 parent->SetBounds(gfx::Size(100, 100)); | |
| 1973 parent->SetDrawsContent(true); | |
| 1974 child1->SetBounds(gfx::Size(100, 100)); | |
| 1975 child1->SetDrawsContent(true); | |
| 1976 child1->test_properties()->force_render_surface = true; | |
| 1977 child2->SetBounds(gfx::Size(100, 100)); | |
| 1978 child2->SetDrawsContent(true); | |
| 1979 grand_child->SetBounds(gfx::Size(100, 100)); | |
| 1980 grand_child->SetDrawsContent(true); | |
| 1981 grand_child->test_properties()->force_render_surface = true; | |
| 1982 leaf_node1->SetBounds(gfx::Size(100, 100)); | |
| 1983 leaf_node1->SetDrawsContent(true); | |
| 1984 leaf_node2->SetBounds(gfx::Size(100, 100)); | |
| 1985 leaf_node2->SetDrawsContent(true); | |
| 1986 | |
| 1987 // Case 1: Nothing is clipped. In this case, is_clipped is always false, with | |
| 1988 // or without surfaces. | |
| 1989 ExecuteCalculateDrawProperties(root); | |
| 1990 EXPECT_FALSE(root->is_clipped()); | |
| 1991 EXPECT_FALSE(parent->is_clipped()); | |
| 1992 EXPECT_FALSE(child1->is_clipped()); | |
| 1993 EXPECT_FALSE(child2->is_clipped()); | |
| 1994 EXPECT_FALSE(grand_child->is_clipped()); | |
| 1995 EXPECT_FALSE(leaf_node1->is_clipped()); | |
| 1996 EXPECT_FALSE(leaf_node2->is_clipped()); | |
| 1997 | |
| 1998 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); | |
| 1999 EXPECT_FALSE(root->is_clipped()); | |
| 2000 EXPECT_FALSE(parent->is_clipped()); | |
| 2001 EXPECT_FALSE(child1->is_clipped()); | |
| 2002 EXPECT_FALSE(child2->is_clipped()); | |
| 2003 EXPECT_FALSE(grand_child->is_clipped()); | |
| 2004 EXPECT_FALSE(leaf_node1->is_clipped()); | |
| 2005 EXPECT_FALSE(leaf_node2->is_clipped()); | |
| 2006 | |
| 2007 // Case 2: The root is clipped. With surfaces, this only persists until the | |
| 2008 // next render surface. Without surfaces, the entire tree is clipped. | |
| 2009 root->SetMasksToBounds(true); | |
| 2010 host_impl()->active_tree()->property_trees()->needs_rebuild = true; | |
| 2011 ExecuteCalculateDrawProperties(root); | |
| 2012 EXPECT_TRUE(root->is_clipped()); | |
| 2013 EXPECT_TRUE(parent->is_clipped()); | |
| 2014 EXPECT_FALSE(child1->is_clipped()); | |
| 2015 EXPECT_TRUE(child2->is_clipped()); | |
| 2016 EXPECT_FALSE(grand_child->is_clipped()); | |
| 2017 EXPECT_FALSE(leaf_node1->is_clipped()); | |
| 2018 EXPECT_TRUE(leaf_node2->is_clipped()); | |
| 2019 | |
| 2020 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); | |
| 2021 EXPECT_TRUE(root->is_clipped()); | |
| 2022 EXPECT_TRUE(parent->is_clipped()); | |
| 2023 EXPECT_TRUE(child1->is_clipped()); | |
| 2024 EXPECT_TRUE(child2->is_clipped()); | |
| 2025 EXPECT_TRUE(grand_child->is_clipped()); | |
| 2026 EXPECT_TRUE(leaf_node1->is_clipped()); | |
| 2027 EXPECT_TRUE(leaf_node2->is_clipped()); | |
| 2028 | |
| 2029 root->SetMasksToBounds(false); | |
| 2030 | |
| 2031 // Case 3: The parent is clipped. Again, with surfaces, this only persists | |
| 2032 // until the next render surface. Without surfaces, parent's entire subtree is | |
| 2033 // clipped. | |
| 2034 parent->SetMasksToBounds(true); | |
| 2035 host_impl()->active_tree()->property_trees()->needs_rebuild = true; | |
| 2036 ExecuteCalculateDrawProperties(root); | |
| 2037 EXPECT_FALSE(root->is_clipped()); | |
| 2038 EXPECT_TRUE(parent->is_clipped()); | |
| 2039 EXPECT_FALSE(child1->is_clipped()); | |
| 2040 EXPECT_TRUE(child2->is_clipped()); | |
| 2041 EXPECT_FALSE(grand_child->is_clipped()); | |
| 2042 EXPECT_FALSE(leaf_node1->is_clipped()); | |
| 2043 EXPECT_TRUE(leaf_node2->is_clipped()); | |
| 2044 | |
| 2045 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); | |
| 2046 EXPECT_FALSE(root->is_clipped()); | |
| 2047 EXPECT_TRUE(parent->is_clipped()); | |
| 2048 EXPECT_TRUE(child1->is_clipped()); | |
| 2049 EXPECT_TRUE(child2->is_clipped()); | |
| 2050 EXPECT_TRUE(grand_child->is_clipped()); | |
| 2051 EXPECT_TRUE(leaf_node1->is_clipped()); | |
| 2052 EXPECT_TRUE(leaf_node2->is_clipped()); | |
| 2053 | |
| 2054 parent->SetMasksToBounds(false); | |
| 2055 | |
| 2056 // Case 4: child1 is clipped. With surfaces, only child1 is_clipped, since it | |
| 2057 // has no non-surface children. Without surfaces, child1's entire subtree is | |
| 2058 // clipped. | |
| 2059 child1->SetMasksToBounds(true); | |
| 2060 host_impl()->active_tree()->property_trees()->needs_rebuild = true; | |
| 2061 ExecuteCalculateDrawProperties(root); | |
| 2062 EXPECT_FALSE(root->is_clipped()); | |
| 2063 EXPECT_FALSE(parent->is_clipped()); | |
| 2064 EXPECT_TRUE(child1->is_clipped()); | |
| 2065 EXPECT_FALSE(child2->is_clipped()); | |
| 2066 EXPECT_FALSE(grand_child->is_clipped()); | |
| 2067 EXPECT_FALSE(leaf_node1->is_clipped()); | |
| 2068 EXPECT_FALSE(leaf_node2->is_clipped()); | |
| 2069 | |
| 2070 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); | |
| 2071 EXPECT_FALSE(root->is_clipped()); | |
| 2072 EXPECT_FALSE(parent->is_clipped()); | |
| 2073 EXPECT_TRUE(child1->is_clipped()); | |
| 2074 EXPECT_FALSE(child2->is_clipped()); | |
| 2075 EXPECT_TRUE(grand_child->is_clipped()); | |
| 2076 EXPECT_TRUE(leaf_node1->is_clipped()); | |
| 2077 EXPECT_FALSE(leaf_node2->is_clipped()); | |
| 2078 | |
| 2079 child1->SetMasksToBounds(false); | |
| 2080 | |
| 2081 // Case 5: Only the leaf nodes are clipped. The behavior with and without | |
| 2082 // surfaces is the same. | |
| 2083 leaf_node1->SetMasksToBounds(true); | |
| 2084 leaf_node2->SetMasksToBounds(true); | |
| 2085 host_impl()->active_tree()->property_trees()->needs_rebuild = true; | |
| 2086 ExecuteCalculateDrawProperties(root); | |
| 2087 EXPECT_FALSE(root->is_clipped()); | |
| 2088 EXPECT_FALSE(parent->is_clipped()); | |
| 2089 EXPECT_FALSE(child1->is_clipped()); | |
| 2090 EXPECT_FALSE(child2->is_clipped()); | |
| 2091 EXPECT_FALSE(grand_child->is_clipped()); | |
| 2092 EXPECT_TRUE(leaf_node1->is_clipped()); | |
| 2093 EXPECT_TRUE(leaf_node2->is_clipped()); | |
| 2094 | |
| 2095 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); | |
| 2096 EXPECT_FALSE(root->is_clipped()); | |
| 2097 EXPECT_FALSE(parent->is_clipped()); | |
| 2098 EXPECT_FALSE(child1->is_clipped()); | |
| 2099 EXPECT_FALSE(child2->is_clipped()); | |
| 2100 EXPECT_FALSE(grand_child->is_clipped()); | |
| 2101 EXPECT_TRUE(leaf_node1->is_clipped()); | |
| 2102 EXPECT_TRUE(leaf_node2->is_clipped()); | |
| 2103 } | |
| 2104 | |
| 2105 TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) { | 1827 TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) { |
| 2106 // Verify that layers get the appropriate DrawableContentRect when their | 1828 // Verify that layers get the appropriate DrawableContentRect when their |
| 2107 // parent MasksToBounds is true. | 1829 // parent MasksToBounds is true. |
| 2108 // | 1830 // |
| 2109 // grand_child1 - completely inside the region; DrawableContentRect should | 1831 // grand_child1 - completely inside the region; DrawableContentRect should |
| 2110 // be the layer rect expressed in target space. | 1832 // be the layer rect expressed in target space. |
| 2111 // grand_child2 - partially clipped but NOT MasksToBounds; the clip rect | 1833 // grand_child2 - partially clipped but NOT MasksToBounds; the clip rect |
| 2112 // will be the intersection of layer bounds and the mask region. | 1834 // will be the intersection of layer bounds and the mask region. |
| 2113 // grand_child3 - partially clipped and MasksToBounds; the | 1835 // grand_child3 - partially clipped and MasksToBounds; the |
| 2114 // DrawableContentRect will still be the intersection of layer bounds and | 1836 // DrawableContentRect will still be the intersection of layer bounds and |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2204 // Surfaces are clipped by their parent, but un-affected by the owning layer's | 1926 // Surfaces are clipped by their parent, but un-affected by the owning layer's |
| 2205 // MasksToBounds. | 1927 // MasksToBounds. |
| 2206 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), | 1928 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
| 2207 grand_child1->render_surface()->clip_rect()); | 1929 grand_child1->render_surface()->clip_rect()); |
| 2208 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), | 1930 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
| 2209 grand_child2->render_surface()->clip_rect()); | 1931 grand_child2->render_surface()->clip_rect()); |
| 2210 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), | 1932 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
| 2211 grand_child3->render_surface()->clip_rect()); | 1933 grand_child3->render_surface()->clip_rect()); |
| 2212 } | 1934 } |
| 2213 | 1935 |
| 2214 TEST_F(LayerTreeHostCommonTest, ClipRectWhenCannotRenderToSeparateSurface) { | |
| 2215 // Tests that when separate surfaces are disabled, a layer's clip_rect is the | |
| 2216 // intersection of all ancestor clips in screen space; in particular, if a | |
| 2217 // layer masks to bounds, it contributes to the clip_rect of all layers in its | |
| 2218 // subtree (since there are no render surfaces that can reset the clip_rect). | |
| 2219 LayerImpl* root = root_layer_for_testing(); | |
| 2220 LayerImpl* parent = AddChild<LayerImpl>(root); | |
| 2221 LayerImpl* child1 = AddChild<LayerImpl>(parent); | |
| 2222 LayerImpl* child2 = AddChild<LayerImpl>(parent); | |
| 2223 LayerImpl* grand_child = AddChild<LayerImpl>(child1); | |
| 2224 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child); | |
| 2225 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2); | |
| 2226 | |
| 2227 root->SetBounds(gfx::Size(100, 100)); | |
| 2228 parent->SetPosition(gfx::PointF(2.f, 2.f)); | |
| 2229 parent->SetBounds(gfx::Size(400, 400)); | |
| 2230 child1->SetPosition(gfx::PointF(4.f, 4.f)); | |
| 2231 child1->SetBounds(gfx::Size(800, 800)); | |
| 2232 child2->SetPosition(gfx::PointF(3.f, 3.f)); | |
| 2233 child2->SetBounds(gfx::Size(800, 800)); | |
| 2234 grand_child->SetPosition(gfx::PointF(8.f, 8.f)); | |
| 2235 grand_child->SetBounds(gfx::Size(1500, 1500)); | |
| 2236 leaf_node1->SetPosition(gfx::PointF(16.f, 16.f)); | |
| 2237 leaf_node1->SetBounds(gfx::Size(2000, 2000)); | |
| 2238 leaf_node2->SetPosition(gfx::PointF(9.f, 9.f)); | |
| 2239 leaf_node2->SetBounds(gfx::Size(2000, 2000)); | |
| 2240 | |
| 2241 root->SetDrawsContent(true); | |
| 2242 parent->SetDrawsContent(true); | |
| 2243 child1->SetDrawsContent(true); | |
| 2244 child2->SetDrawsContent(true); | |
| 2245 grand_child->SetDrawsContent(true); | |
| 2246 leaf_node1->SetDrawsContent(true); | |
| 2247 leaf_node2->SetDrawsContent(true); | |
| 2248 | |
| 2249 root->test_properties()->force_render_surface = true; | |
| 2250 child1->test_properties()->force_render_surface = true; | |
| 2251 grand_child->test_properties()->force_render_surface = true; | |
| 2252 | |
| 2253 // Case 1: Nothing is clipped. In this case, each layer's clip rect is its | |
| 2254 // bounds in target space. The only thing that changes when surfaces are | |
| 2255 // disabled is that target space is always screen space. | |
| 2256 ExecuteCalculateDrawProperties(root); | |
| 2257 EXPECT_TRUE(root->has_render_surface()); | |
| 2258 EXPECT_FALSE(parent->has_render_surface()); | |
| 2259 EXPECT_TRUE(child1->has_render_surface()); | |
| 2260 EXPECT_FALSE(child2->has_render_surface()); | |
| 2261 EXPECT_TRUE(grand_child->has_render_surface()); | |
| 2262 EXPECT_FALSE(leaf_node1->has_render_surface()); | |
| 2263 EXPECT_FALSE(leaf_node2->has_render_surface()); | |
| 2264 EXPECT_FALSE(root->is_clipped()); | |
| 2265 EXPECT_FALSE(parent->is_clipped()); | |
| 2266 EXPECT_FALSE(child1->is_clipped()); | |
| 2267 EXPECT_FALSE(child2->is_clipped()); | |
| 2268 EXPECT_FALSE(grand_child->is_clipped()); | |
| 2269 EXPECT_FALSE(leaf_node1->is_clipped()); | |
| 2270 EXPECT_FALSE(leaf_node2->is_clipped()); | |
| 2271 EXPECT_TRUE(root->render_surface()->is_clipped()); | |
| 2272 EXPECT_FALSE(child1->render_surface()->is_clipped()); | |
| 2273 EXPECT_FALSE(grand_child->render_surface()->is_clipped()); | |
| 2274 EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect()); | |
| 2275 | |
| 2276 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); | |
| 2277 EXPECT_FALSE(root->is_clipped()); | |
| 2278 EXPECT_FALSE(parent->is_clipped()); | |
| 2279 EXPECT_FALSE(child1->is_clipped()); | |
| 2280 EXPECT_FALSE(child2->is_clipped()); | |
| 2281 EXPECT_FALSE(grand_child->is_clipped()); | |
| 2282 EXPECT_FALSE(leaf_node1->is_clipped()); | |
| 2283 EXPECT_FALSE(leaf_node2->is_clipped()); | |
| 2284 EXPECT_TRUE(root->render_surface()->is_clipped()); | |
| 2285 EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect()); | |
| 2286 | |
| 2287 // Case 2: The root is clipped. In this case, layers that draw into the root | |
| 2288 // render surface are clipped by the root's bounds. | |
| 2289 root->SetMasksToBounds(true); | |
| 2290 host_impl()->active_tree()->property_trees()->needs_rebuild = true; | |
| 2291 root->test_properties()->force_render_surface = true; | |
| 2292 child1->test_properties()->force_render_surface = true; | |
| 2293 grand_child->test_properties()->force_render_surface = true; | |
| 2294 ExecuteCalculateDrawProperties(root); | |
| 2295 EXPECT_TRUE(root->has_render_surface()); | |
| 2296 EXPECT_FALSE(parent->has_render_surface()); | |
| 2297 EXPECT_TRUE(child1->has_render_surface()); | |
| 2298 EXPECT_FALSE(child2->has_render_surface()); | |
| 2299 EXPECT_TRUE(grand_child->has_render_surface()); | |
| 2300 EXPECT_FALSE(leaf_node1->has_render_surface()); | |
| 2301 EXPECT_FALSE(leaf_node2->has_render_surface()); | |
| 2302 EXPECT_TRUE(root->is_clipped()); | |
| 2303 EXPECT_TRUE(parent->is_clipped()); | |
| 2304 EXPECT_FALSE(child1->is_clipped()); | |
| 2305 EXPECT_TRUE(child1->render_surface()->is_clipped()); | |
| 2306 EXPECT_TRUE(child2->is_clipped()); | |
| 2307 EXPECT_FALSE(grand_child->is_clipped()); | |
| 2308 EXPECT_FALSE(grand_child->render_surface()->is_clipped()); | |
| 2309 EXPECT_FALSE(leaf_node1->is_clipped()); | |
| 2310 EXPECT_TRUE(leaf_node2->is_clipped()); | |
| 2311 EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect()); | |
| 2312 EXPECT_EQ(gfx::Rect(100, 100), parent->clip_rect()); | |
| 2313 EXPECT_EQ(gfx::Rect(100, 100), child1->render_surface()->clip_rect()); | |
| 2314 EXPECT_EQ(gfx::Rect(100, 100), child2->clip_rect()); | |
| 2315 EXPECT_EQ(gfx::Rect(100, 100), leaf_node2->clip_rect()); | |
| 2316 | |
| 2317 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); | |
| 2318 EXPECT_TRUE(root->is_clipped()); | |
| 2319 EXPECT_TRUE(parent->is_clipped()); | |
| 2320 EXPECT_TRUE(child1->is_clipped()); | |
| 2321 EXPECT_TRUE(child2->is_clipped()); | |
| 2322 EXPECT_TRUE(grand_child->is_clipped()); | |
| 2323 EXPECT_TRUE(leaf_node1->is_clipped()); | |
| 2324 EXPECT_TRUE(leaf_node2->is_clipped()); | |
| 2325 EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect()); | |
| 2326 EXPECT_EQ(gfx::Rect(100, 100), parent->clip_rect()); | |
| 2327 EXPECT_EQ(gfx::Rect(100, 100), child1->clip_rect()); | |
| 2328 EXPECT_EQ(gfx::Rect(100, 100), child2->clip_rect()); | |
| 2329 EXPECT_EQ(gfx::Rect(100, 100), grand_child->clip_rect()); | |
| 2330 EXPECT_EQ(gfx::Rect(100, 100), leaf_node1->clip_rect()); | |
| 2331 EXPECT_EQ(gfx::Rect(100, 100), leaf_node2->clip_rect()); | |
| 2332 | |
| 2333 root->SetMasksToBounds(false); | |
| 2334 | |
| 2335 // Case 3: The parent and child1 are clipped. When surfaces are enabled, the | |
| 2336 // parent clip rect only contributes to the subtree rooted at child2, since | |
| 2337 // the subtree rooted at child1 renders into a separate surface. Similarly, | |
| 2338 // child1's clip rect doesn't contribute to its descendants, since its only | |
| 2339 // child is a render surface. However, without surfaces, these clip rects | |
| 2340 // contribute to all descendants. | |
| 2341 parent->SetMasksToBounds(true); | |
| 2342 child1->SetMasksToBounds(true); | |
| 2343 host_impl()->active_tree()->property_trees()->needs_rebuild = true; | |
| 2344 root->test_properties()->force_render_surface = true; | |
| 2345 child1->test_properties()->force_render_surface = true; | |
| 2346 grand_child->test_properties()->force_render_surface = true; | |
| 2347 ExecuteCalculateDrawProperties(root); | |
| 2348 EXPECT_TRUE(root->has_render_surface()); | |
| 2349 EXPECT_FALSE(parent->has_render_surface()); | |
| 2350 EXPECT_TRUE(child1->has_render_surface()); | |
| 2351 EXPECT_FALSE(child2->has_render_surface()); | |
| 2352 EXPECT_TRUE(grand_child->has_render_surface()); | |
| 2353 EXPECT_FALSE(leaf_node1->has_render_surface()); | |
| 2354 EXPECT_FALSE(leaf_node2->has_render_surface()); | |
| 2355 EXPECT_FALSE(root->is_clipped()); | |
| 2356 EXPECT_TRUE(root->render_surface()->is_clipped()); | |
| 2357 EXPECT_TRUE(parent->is_clipped()); | |
| 2358 EXPECT_TRUE(child1->is_clipped()); | |
| 2359 EXPECT_TRUE(child2->is_clipped()); | |
| 2360 EXPECT_FALSE(grand_child->is_clipped()); | |
| 2361 EXPECT_TRUE(grand_child->render_surface()->is_clipped()); | |
| 2362 EXPECT_FALSE(leaf_node1->is_clipped()); | |
| 2363 EXPECT_TRUE(leaf_node2->is_clipped()); | |
| 2364 EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect()); | |
| 2365 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect()); | |
| 2366 EXPECT_EQ(gfx::Rect(800, 800), child1->clip_rect()); | |
| 2367 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), child2->clip_rect()); | |
| 2368 EXPECT_EQ(gfx::Rect(800, 800), grand_child->render_surface()->clip_rect()); | |
| 2369 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), leaf_node2->clip_rect()); | |
| 2370 | |
| 2371 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); | |
| 2372 EXPECT_FALSE(root->is_clipped()); | |
| 2373 EXPECT_TRUE(root->render_surface()->is_clipped()); | |
| 2374 EXPECT_TRUE(parent->is_clipped()); | |
| 2375 EXPECT_TRUE(child1->is_clipped()); | |
| 2376 EXPECT_TRUE(child2->is_clipped()); | |
| 2377 EXPECT_TRUE(grand_child->is_clipped()); | |
| 2378 EXPECT_TRUE(leaf_node1->is_clipped()); | |
| 2379 EXPECT_TRUE(leaf_node2->is_clipped()); | |
| 2380 EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect()); | |
| 2381 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect()); | |
| 2382 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), child1->clip_rect()); | |
| 2383 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), child2->clip_rect()); | |
| 2384 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), grand_child->clip_rect()); | |
| 2385 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), leaf_node1->clip_rect()); | |
| 2386 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), leaf_node2->clip_rect()); | |
| 2387 } | |
| 2388 | |
| 2389 TEST_F(LayerTreeHostCommonTest, HitTestingWhenSurfacesDisabled) { | |
| 2390 LayerImpl* root = root_layer_for_testing(); | |
| 2391 LayerImpl* parent = AddChild<LayerImpl>(root); | |
| 2392 LayerImpl* child = AddChild<LayerImpl>(parent); | |
| 2393 LayerImpl* grand_child = AddChild<LayerImpl>(child); | |
| 2394 LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child); | |
| 2395 | |
| 2396 root->SetBounds(gfx::Size(100, 100)); | |
| 2397 parent->SetPosition(gfx::PointF(2.f, 2.f)); | |
| 2398 parent->SetBounds(gfx::Size(400, 400)); | |
| 2399 parent->SetMasksToBounds(true); | |
| 2400 child->SetPosition(gfx::PointF(4.f, 4.f)); | |
| 2401 child->SetBounds(gfx::Size(800, 800)); | |
| 2402 child->SetMasksToBounds(true); | |
| 2403 child->test_properties()->force_render_surface = true; | |
| 2404 grand_child->SetPosition(gfx::PointF(8.f, 8.f)); | |
| 2405 grand_child->SetBounds(gfx::Size(1500, 1500)); | |
| 2406 grand_child->test_properties()->force_render_surface = true; | |
| 2407 leaf_node->SetPosition(gfx::PointF(16.f, 16.f)); | |
| 2408 leaf_node->SetBounds(gfx::Size(2000, 2000)); | |
| 2409 | |
| 2410 root->SetDrawsContent(true); | |
| 2411 parent->SetDrawsContent(true); | |
| 2412 child->SetDrawsContent(true); | |
| 2413 grand_child->SetDrawsContent(true); | |
| 2414 leaf_node->SetDrawsContent(true); | |
| 2415 | |
| 2416 host_impl()->set_resourceless_software_draw_for_testing(); | |
| 2417 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); | |
| 2418 gfx::PointF test_point(90.f, 90.f); | |
| 2419 LayerImpl* result_layer = | |
| 2420 root->layer_tree_impl()->FindLayerThatIsHitByPoint(test_point); | |
| 2421 ASSERT_TRUE(result_layer); | |
| 2422 EXPECT_EQ(leaf_node, result_layer); | |
| 2423 } | |
| 2424 | |
| 2425 TEST_F(LayerTreeHostCommonTest, SurfacesDisabledAndReEnabled) { | |
| 2426 // Tests that draw properties are computed correctly when we disable and then | |
| 2427 // re-enable separate surfaces. | |
| 2428 LayerImpl* root = root_layer_for_testing(); | |
| 2429 LayerImpl* parent = AddChild<LayerImpl>(root); | |
| 2430 LayerImpl* child = AddChild<LayerImpl>(parent); | |
| 2431 LayerImpl* grand_child = AddChild<LayerImpl>(child); | |
| 2432 LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child); | |
| 2433 | |
| 2434 root->SetBounds(gfx::Size(100, 100)); | |
| 2435 parent->SetPosition(gfx::PointF(2.f, 2.f)); | |
| 2436 parent->SetBounds(gfx::Size(400, 400)); | |
| 2437 parent->SetMasksToBounds(true); | |
| 2438 child->SetPosition(gfx::PointF(4.f, 4.f)); | |
| 2439 child->SetBounds(gfx::Size(800, 800)); | |
| 2440 child->SetMasksToBounds(true); | |
| 2441 child->test_properties()->force_render_surface = true; | |
| 2442 grand_child->SetPosition(gfx::PointF(8.f, 8.f)); | |
| 2443 grand_child->SetBounds(gfx::Size(1500, 1500)); | |
| 2444 grand_child->test_properties()->force_render_surface = true; | |
| 2445 leaf_node->SetPosition(gfx::PointF(16.f, 16.f)); | |
| 2446 leaf_node->SetBounds(gfx::Size(2000, 2000)); | |
| 2447 | |
| 2448 root->SetDrawsContent(true); | |
| 2449 parent->SetDrawsContent(true); | |
| 2450 child->SetDrawsContent(true); | |
| 2451 grand_child->SetDrawsContent(true); | |
| 2452 leaf_node->SetDrawsContent(true); | |
| 2453 | |
| 2454 gfx::Transform expected_leaf_draw_transform_with_surfaces; | |
| 2455 expected_leaf_draw_transform_with_surfaces.Translate(16.0, 16.0); | |
| 2456 | |
| 2457 gfx::Transform expected_leaf_draw_transform_without_surfaces; | |
| 2458 expected_leaf_draw_transform_without_surfaces.Translate(30.0, 30.0); | |
| 2459 | |
| 2460 ExecuteCalculateDrawProperties(root); | |
| 2461 EXPECT_FALSE(leaf_node->is_clipped()); | |
| 2462 EXPECT_TRUE(leaf_node->render_target()->is_clipped()); | |
| 2463 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect()); | |
| 2464 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_leaf_draw_transform_with_surfaces, | |
| 2465 leaf_node->DrawTransform()); | |
| 2466 | |
| 2467 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); | |
| 2468 EXPECT_TRUE(leaf_node->is_clipped()); | |
| 2469 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), leaf_node->clip_rect()); | |
| 2470 EXPECT_EQ(gfx::Rect(30, 30, 372, 372), leaf_node->drawable_content_rect()); | |
| 2471 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_leaf_draw_transform_without_surfaces, | |
| 2472 leaf_node->DrawTransform()); | |
| 2473 | |
| 2474 ExecuteCalculateDrawProperties(root); | |
| 2475 EXPECT_FALSE(leaf_node->is_clipped()); | |
| 2476 EXPECT_TRUE(leaf_node->render_target()->is_clipped()); | |
| 2477 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect()); | |
| 2478 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_leaf_draw_transform_with_surfaces, | |
| 2479 leaf_node->DrawTransform()); | |
| 2480 } | |
| 2481 | |
| 2482 TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) { | 1936 TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) { |
| 2483 LayerImpl* root = root_layer_for_testing(); | 1937 LayerImpl* root = root_layer_for_testing(); |
| 2484 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); | 1938 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 2485 LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1); | 1939 LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1); |
| 2486 LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1); | 1940 LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1); |
| 2487 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); | 1941 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); |
| 2488 LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2); | 1942 LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2); |
| 2489 LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2); | 1943 LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2); |
| 2490 LayerImpl* child_of_root = AddChildToRoot<LayerImpl>(); | 1944 LayerImpl* child_of_root = AddChildToRoot<LayerImpl>(); |
| 2491 LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root); | 1945 LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root); |
| (...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3335 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); | 2789 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
| 3336 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect()); | 2790 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect()); |
| 3337 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child3->visible_layer_rect()); | 2791 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child3->visible_layer_rect()); |
| 3338 | 2792 |
| 3339 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); | 2793 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3340 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); | 2794 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3341 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); | 2795 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
| 3342 } | 2796 } |
| 3343 | 2797 |
| 3344 TEST_F(LayerTreeHostCommonTest, | 2798 TEST_F(LayerTreeHostCommonTest, |
| 3345 DrawableAndVisibleRectsWhenCannotRenderToSeparateSurface) { | |
| 3346 LayerImpl* root = root_layer_for_testing(); | |
| 3347 LayerImpl* parent = AddChild<LayerImpl>(root); | |
| 3348 LayerImpl* child1 = AddChild<LayerImpl>(parent); | |
| 3349 LayerImpl* child2 = AddChild<LayerImpl>(parent); | |
| 3350 LayerImpl* grand_child1 = AddChild<LayerImpl>(child1); | |
| 3351 LayerImpl* grand_child2 = AddChild<LayerImpl>(child2); | |
| 3352 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1); | |
| 3353 LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2); | |
| 3354 | |
| 3355 root->SetBounds(gfx::Size(100, 100)); | |
| 3356 parent->SetPosition(gfx::PointF(2.f, 2.f)); | |
| 3357 parent->SetBounds(gfx::Size(400, 400)); | |
| 3358 child1->SetPosition(gfx::PointF(4.f, 4.f)); | |
| 3359 child1->SetBounds(gfx::Size(800, 800)); | |
| 3360 child1->test_properties()->force_render_surface = true; | |
| 3361 child2->SetPosition(gfx::PointF(3.f, 3.f)); | |
| 3362 child2->SetBounds(gfx::Size(800, 800)); | |
| 3363 child2->test_properties()->force_render_surface = true; | |
| 3364 grand_child1->SetPosition(gfx::PointF(8.f, 8.f)); | |
| 3365 grand_child1->SetBounds(gfx::Size(1500, 1500)); | |
| 3366 grand_child2->SetPosition(gfx::PointF(7.f, 7.f)); | |
| 3367 grand_child2->SetBounds(gfx::Size(1500, 1500)); | |
| 3368 leaf_node1->SetPosition(gfx::PointF(16.f, 16.f)); | |
| 3369 leaf_node1->SetBounds(gfx::Size(2000, 2000)); | |
| 3370 leaf_node2->SetPosition(gfx::PointF(9.f, 9.f)); | |
| 3371 leaf_node2->SetBounds(gfx::Size(2000, 2000)); | |
| 3372 | |
| 3373 root->SetDrawsContent(true); | |
| 3374 parent->SetDrawsContent(true); | |
| 3375 child1->SetDrawsContent(true); | |
| 3376 child2->SetDrawsContent(true); | |
| 3377 grand_child1->SetDrawsContent(true); | |
| 3378 grand_child2->SetDrawsContent(true); | |
| 3379 leaf_node1->SetDrawsContent(true); | |
| 3380 leaf_node2->SetDrawsContent(true); | |
| 3381 | |
| 3382 // Case 1: No layers clip. Visible rects are clipped by the viewport. | |
| 3383 // Each layer's drawable content rect is its bounds in target space; the only | |
| 3384 // thing that changes with surfaces disabled is that target space is always | |
| 3385 // screen space. | |
| 3386 child1->test_properties()->force_render_surface = true; | |
| 3387 child2->test_properties()->force_render_surface = true; | |
| 3388 ExecuteCalculateDrawProperties(root); | |
| 3389 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); | |
| 3390 EXPECT_EQ(gfx::Rect(0, 0, 98, 98), parent->visible_layer_rect()); | |
| 3391 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); | |
| 3392 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); | |
| 3393 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); | |
| 3394 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); | |
| 3395 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); | |
| 3396 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); | |
| 3397 | |
| 3398 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); | |
| 3399 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); | |
| 3400 EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect()); | |
| 3401 EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect()); | |
| 3402 EXPECT_EQ(gfx::Rect(8, 8, 1500, 1500), grand_child1->drawable_content_rect()); | |
| 3403 EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect()); | |
| 3404 EXPECT_EQ(gfx::Rect(24, 24, 2000, 2000), leaf_node1->drawable_content_rect()); | |
| 3405 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node2->drawable_content_rect()); | |
| 3406 | |
| 3407 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); | |
| 3408 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); | |
| 3409 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); | |
| 3410 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); | |
| 3411 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); | |
| 3412 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); | |
| 3413 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); | |
| 3414 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); | |
| 3415 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); | |
| 3416 | |
| 3417 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); | |
| 3418 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); | |
| 3419 EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->drawable_content_rect()); | |
| 3420 EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->drawable_content_rect()); | |
| 3421 EXPECT_EQ(gfx::Rect(14, 14, 1500, 1500), | |
| 3422 grand_child1->drawable_content_rect()); | |
| 3423 EXPECT_EQ(gfx::Rect(12, 12, 1500, 1500), | |
| 3424 grand_child2->drawable_content_rect()); | |
| 3425 EXPECT_EQ(gfx::Rect(30, 30, 2000, 2000), leaf_node1->drawable_content_rect()); | |
| 3426 EXPECT_EQ(gfx::Rect(21, 21, 2000, 2000), leaf_node2->drawable_content_rect()); | |
| 3427 | |
| 3428 // Case 2: The parent clips. In this case, neither surface is unclipped, so | |
| 3429 // all visible layer rects are clipped by the intersection of all ancestor | |
| 3430 // clips, whether or not surfaces are disabled. However, drawable content | |
| 3431 // rects are clipped only until the next render surface is reached, so | |
| 3432 // descendants of parent have their drawable content rects clipped only when | |
| 3433 // surfaces are disabled. | |
| 3434 parent->SetMasksToBounds(true); | |
| 3435 host_impl()->active_tree()->property_trees()->needs_rebuild = true; | |
| 3436 ExecuteCalculateDrawProperties(root); | |
| 3437 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); | |
| 3438 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); | |
| 3439 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); | |
| 3440 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); | |
| 3441 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); | |
| 3442 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); | |
| 3443 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); | |
| 3444 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); | |
| 3445 | |
| 3446 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); | |
| 3447 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); | |
| 3448 EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect()); | |
| 3449 EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect()); | |
| 3450 EXPECT_EQ(gfx::Rect(8, 8, 1500, 1500), grand_child1->drawable_content_rect()); | |
| 3451 EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect()); | |
| 3452 EXPECT_EQ(gfx::Rect(24, 24, 2000, 2000), leaf_node1->drawable_content_rect()); | |
| 3453 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node2->drawable_content_rect()); | |
| 3454 | |
| 3455 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); | |
| 3456 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); | |
| 3457 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); | |
| 3458 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); | |
| 3459 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); | |
| 3460 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); | |
| 3461 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); | |
| 3462 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); | |
| 3463 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); | |
| 3464 | |
| 3465 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); | |
| 3466 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); | |
| 3467 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), child1->drawable_content_rect()); | |
| 3468 EXPECT_EQ(gfx::Rect(5, 5, 397, 397), child2->drawable_content_rect()); | |
| 3469 EXPECT_EQ(gfx::Rect(14, 14, 388, 388), grand_child1->drawable_content_rect()); | |
| 3470 EXPECT_EQ(gfx::Rect(12, 12, 390, 390), grand_child2->drawable_content_rect()); | |
| 3471 EXPECT_EQ(gfx::Rect(30, 30, 372, 372), leaf_node1->drawable_content_rect()); | |
| 3472 EXPECT_EQ(gfx::Rect(21, 21, 381, 381), leaf_node2->drawable_content_rect()); | |
| 3473 | |
| 3474 parent->SetMasksToBounds(false); | |
| 3475 | |
| 3476 // Case 3: child1 and grand_child2 clip. In this case, descendants of these | |
| 3477 // layers have their visible rects clipped by them; Similarly, descendants of | |
| 3478 // these layers have their drawable content rects clipped by them. | |
| 3479 child1->SetMasksToBounds(true); | |
| 3480 grand_child2->SetMasksToBounds(true); | |
| 3481 host_impl()->active_tree()->property_trees()->needs_rebuild = true; | |
| 3482 ExecuteCalculateDrawProperties(root); | |
| 3483 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); | |
| 3484 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); | |
| 3485 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); | |
| 3486 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); | |
| 3487 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); | |
| 3488 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); | |
| 3489 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); | |
| 3490 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); | |
| 3491 | |
| 3492 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); | |
| 3493 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); | |
| 3494 EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect()); | |
| 3495 EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect()); | |
| 3496 EXPECT_EQ(gfx::Rect(8, 8, 792, 792), grand_child1->drawable_content_rect()); | |
| 3497 EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect()); | |
| 3498 EXPECT_EQ(gfx::Rect(24, 24, 776, 776), leaf_node1->drawable_content_rect()); | |
| 3499 EXPECT_EQ(gfx::Rect(16, 16, 1491, 1491), leaf_node2->drawable_content_rect()); | |
| 3500 | |
| 3501 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); | |
| 3502 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); | |
| 3503 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); | |
| 3504 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); | |
| 3505 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); | |
| 3506 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); | |
| 3507 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); | |
| 3508 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); | |
| 3509 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); | |
| 3510 | |
| 3511 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); | |
| 3512 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); | |
| 3513 EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->drawable_content_rect()); | |
| 3514 EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->drawable_content_rect()); | |
| 3515 EXPECT_EQ(gfx::Rect(14, 14, 792, 792), grand_child1->drawable_content_rect()); | |
| 3516 EXPECT_EQ(gfx::Rect(12, 12, 1500, 1500), | |
| 3517 grand_child2->drawable_content_rect()); | |
| 3518 EXPECT_EQ(gfx::Rect(30, 30, 776, 776), leaf_node1->drawable_content_rect()); | |
| 3519 EXPECT_EQ(gfx::Rect(21, 21, 1491, 1491), leaf_node2->drawable_content_rect()); | |
| 3520 } | |
| 3521 | |
| 3522 TEST_F(LayerTreeHostCommonTest, | |
| 3523 VisibleContentRectsForClippedSurfaceWithEmptyClip) { | 2799 VisibleContentRectsForClippedSurfaceWithEmptyClip) { |
| 3524 LayerImpl* root = root_layer_for_testing(); | 2800 LayerImpl* root = root_layer_for_testing(); |
| 3525 LayerImpl* child1 = AddChild<LayerImpl>(root); | 2801 LayerImpl* child1 = AddChild<LayerImpl>(root); |
| 3526 LayerImpl* child2 = AddChild<LayerImpl>(root); | 2802 LayerImpl* child2 = AddChild<LayerImpl>(root); |
| 3527 LayerImpl* child3 = AddChild<LayerImpl>(root); | 2803 LayerImpl* child3 = AddChild<LayerImpl>(root); |
| 3528 | 2804 |
| 3529 root->SetBounds(gfx::Size(100, 100)); | 2805 root->SetBounds(gfx::Size(100, 100)); |
| 3530 child1->SetPosition(gfx::PointF(5.f, 5.f)); | 2806 child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 3531 child1->SetBounds(gfx::Size(50, 50)); | 2807 child1->SetBounds(gfx::Size(50, 50)); |
| 3532 child1->SetDrawsContent(true); | 2808 child1->SetDrawsContent(true); |
| (...skipping 2541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6074 child3->test_properties()->sorting_context_id = 1; | 5350 child3->test_properties()->sorting_context_id = 1; |
| 6075 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); | 5351 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
| 6076 | 5352 |
| 6077 // Verify which render surfaces were created. | 5353 // Verify which render surfaces were created. |
| 6078 EXPECT_TRUE(root->has_render_surface()); | 5354 EXPECT_TRUE(root->has_render_surface()); |
| 6079 EXPECT_FALSE(child1->has_render_surface()); | 5355 EXPECT_FALSE(child1->has_render_surface()); |
| 6080 EXPECT_TRUE(child2->has_render_surface()); | 5356 EXPECT_TRUE(child2->has_render_surface()); |
| 6081 EXPECT_FALSE(child3->has_render_surface()); | 5357 EXPECT_FALSE(child3->has_render_surface()); |
| 6082 } | 5358 } |
| 6083 | 5359 |
| 6084 TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) { | |
| 6085 FakeImplTaskRunnerProvider task_runner_provider; | |
| 6086 TestTaskGraphRunner task_graph_runner; | |
| 6087 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); | |
| 6088 | |
| 6089 std::unique_ptr<LayerImpl> root = | |
| 6090 LayerImpl::Create(host_impl.active_tree(), 12345); | |
| 6091 std::unique_ptr<LayerImpl> child1 = | |
| 6092 LayerImpl::Create(host_impl.active_tree(), 123456); | |
| 6093 std::unique_ptr<LayerImpl> child2 = | |
| 6094 LayerImpl::Create(host_impl.active_tree(), 1234567); | |
| 6095 std::unique_ptr<LayerImpl> child3 = | |
| 6096 LayerImpl::Create(host_impl.active_tree(), 12345678); | |
| 6097 | |
| 6098 gfx::Size bounds(100, 100); | |
| 6099 | |
| 6100 root->SetBounds(bounds); | |
| 6101 root->SetDrawsContent(true); | |
| 6102 | |
| 6103 // This layer structure normally forces render surface due to preserves3d | |
| 6104 // behavior. | |
| 6105 child1->SetBounds(bounds); | |
| 6106 child1->SetDrawsContent(true); | |
| 6107 child1->test_properties()->should_flatten_transform = false; | |
| 6108 child1->test_properties()->sorting_context_id = 1; | |
| 6109 child2->SetBounds(bounds); | |
| 6110 child2->SetDrawsContent(true); | |
| 6111 child2->test_properties()->sorting_context_id = 1; | |
| 6112 child3->SetBounds(bounds); | |
| 6113 child3->SetDrawsContent(true); | |
| 6114 child3->test_properties()->sorting_context_id = 1; | |
| 6115 | |
| 6116 child2->test_properties()->AddChild(std::move(child3)); | |
| 6117 child1->test_properties()->AddChild(std::move(child2)); | |
| 6118 root->test_properties()->AddChild(std::move(child1)); | |
| 6119 LayerImpl* root_layer = root.get(); | |
| 6120 root_layer->layer_tree_impl()->SetRootLayerForTesting(std::move(root)); | |
| 6121 | |
| 6122 { | |
| 6123 LayerImplList render_surface_layer_list; | |
| 6124 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root_layer); | |
| 6125 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( | |
| 6126 root_layer, root_layer->bounds(), &render_surface_layer_list); | |
| 6127 inputs.can_render_to_separate_surface = true; | |
| 6128 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); | |
| 6129 | |
| 6130 EXPECT_EQ(2u, render_surface_layer_list.size()); | |
| 6131 | |
| 6132 int count_represents_target_render_surface = 0; | |
| 6133 int count_represents_contributing_render_surface = 0; | |
| 6134 int count_represents_itself = 0; | |
| 6135 LayerIterator end = LayerIterator::End(&render_surface_layer_list); | |
| 6136 for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list); | |
| 6137 it != end; ++it) { | |
| 6138 if (it.represents_target_render_surface()) | |
| 6139 count_represents_target_render_surface++; | |
| 6140 if (it.represents_contributing_render_surface()) | |
| 6141 count_represents_contributing_render_surface++; | |
| 6142 if (it.represents_itself()) | |
| 6143 count_represents_itself++; | |
| 6144 } | |
| 6145 | |
| 6146 // Two render surfaces. | |
| 6147 EXPECT_EQ(2, count_represents_target_render_surface); | |
| 6148 // Second render surface contributes to root render surface. | |
| 6149 EXPECT_EQ(1, count_represents_contributing_render_surface); | |
| 6150 // All 4 layers represent itself. | |
| 6151 EXPECT_EQ(4, count_represents_itself); | |
| 6152 } | |
| 6153 | |
| 6154 { | |
| 6155 LayerImplList render_surface_layer_list; | |
| 6156 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( | |
| 6157 root_layer, root_layer->bounds(), &render_surface_layer_list); | |
| 6158 inputs.can_render_to_separate_surface = false; | |
| 6159 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); | |
| 6160 | |
| 6161 EXPECT_EQ(1u, render_surface_layer_list.size()); | |
| 6162 | |
| 6163 int count_represents_target_render_surface = 0; | |
| 6164 int count_represents_contributing_render_surface = 0; | |
| 6165 int count_represents_itself = 0; | |
| 6166 LayerIterator end = LayerIterator::End(&render_surface_layer_list); | |
| 6167 for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list); | |
| 6168 it != end; ++it) { | |
| 6169 if (it.represents_target_render_surface()) | |
| 6170 count_represents_target_render_surface++; | |
| 6171 if (it.represents_contributing_render_surface()) | |
| 6172 count_represents_contributing_render_surface++; | |
| 6173 if (it.represents_itself()) | |
| 6174 count_represents_itself++; | |
| 6175 } | |
| 6176 | |
| 6177 // Only root layer has a render surface. | |
| 6178 EXPECT_EQ(1, count_represents_target_render_surface); | |
| 6179 // No layer contributes a render surface to root render surface. | |
| 6180 EXPECT_EQ(0, count_represents_contributing_render_surface); | |
| 6181 // All 4 layers represent itself. | |
| 6182 EXPECT_EQ(4, count_represents_itself); | |
| 6183 } | |
| 6184 } | |
| 6185 | |
| 6186 TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) { | 5360 TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) { |
| 6187 LayerImpl* root = root_layer_for_testing(); | 5361 LayerImpl* root = root_layer_for_testing(); |
| 6188 LayerImpl* back_facing = AddChild<LayerImpl>(root); | 5362 LayerImpl* back_facing = AddChild<LayerImpl>(root); |
| 6189 | 5363 |
| 6190 LayerImpl* render_surface1 = AddChild<LayerImpl>(back_facing); | 5364 LayerImpl* render_surface1 = AddChild<LayerImpl>(back_facing); |
| 6191 LayerImpl* child1 = AddChild<LayerImpl>(render_surface1); | 5365 LayerImpl* child1 = AddChild<LayerImpl>(render_surface1); |
| 6192 | 5366 |
| 6193 LayerImpl* flattener = AddChild<LayerImpl>(back_facing); | 5367 LayerImpl* flattener = AddChild<LayerImpl>(back_facing); |
| 6194 LayerImpl* render_surface2 = AddChild<LayerImpl>(flattener); | 5368 LayerImpl* render_surface2 = AddChild<LayerImpl>(flattener); |
| 6195 LayerImpl* child2 = AddChild<LayerImpl>(render_surface2); | 5369 LayerImpl* child2 = AddChild<LayerImpl>(render_surface2); |
| (...skipping 4556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10752 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index()); | 9926 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index()); |
| 10753 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index()); | 9927 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index()); |
| 10754 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index()); | 9928 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index()); |
| 10755 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index()); | 9929 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index()); |
| 10756 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index()); | 9930 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index()); |
| 10757 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index()); | 9931 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index()); |
| 10758 } | 9932 } |
| 10759 | 9933 |
| 10760 } // namespace | 9934 } // namespace |
| 10761 } // namespace cc | 9935 } // namespace cc |
| OLD | NEW |