OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_impl.h" | 5 #include "cc/trees/layer_tree_impl.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "cc/layers/heads_up_display_layer_impl.h" | 9 #include "cc/layers/heads_up_display_layer_impl.h" |
10 #include "cc/test/fake_layer_tree_host_impl.h" | 10 #include "cc/test/fake_layer_tree_host_impl.h" |
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 root->test_properties()->AddChild(std::move(clipping_layer)); | 566 root->test_properties()->AddChild(std::move(clipping_layer)); |
567 } | 567 } |
568 | 568 |
569 host_impl().SetViewportSize(root->bounds()); | 569 host_impl().SetViewportSize(root->bounds()); |
570 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); | 570 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); |
571 | 571 |
572 // Sanity check the scenario we just created. | 572 // Sanity check the scenario we just created. |
573 ASSERT_EQ(1u, GetRenderSurfaceList().size()); | 573 ASSERT_EQ(1u, GetRenderSurfaceList().size()); |
574 ASSERT_EQ(1, root_layer()->GetRenderSurface()->num_contributors()); | 574 ASSERT_EQ(1, root_layer()->GetRenderSurface()->num_contributors()); |
575 LayerImpl* child_layer = host_impl().active_tree()->LayerById(456); | 575 LayerImpl* child_layer = host_impl().active_tree()->LayerById(456); |
576 EXPECT_TRUE(child_layer->is_drawn_render_surface_layer_list_member()); | 576 EXPECT_TRUE(child_layer->contributes_to_drawn_render_surface()); |
577 | 577 |
578 // Hit testing for a point outside the layer should return a null pointer. | 578 // Hit testing for a point outside the layer should return a null pointer. |
579 // Despite the child layer being very large, it should be clipped to the root | 579 // Despite the child layer being very large, it should be clipped to the root |
580 // layer's bounds. | 580 // layer's bounds. |
581 gfx::PointF test_point(24.f, 24.f); | 581 gfx::PointF test_point(24.f, 24.f); |
582 LayerImpl* result_layer = | 582 LayerImpl* result_layer = |
583 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); | 583 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); |
584 EXPECT_FALSE(result_layer); | 584 EXPECT_FALSE(result_layer); |
585 | 585 |
586 // Even though the layer exists at (101, 101), it should not be visible there | 586 // Even though the layer exists at (101, 101), it should not be visible there |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
744 root->test_properties()->AddChild(std::move(intermediate_layer)); | 744 root->test_properties()->AddChild(std::move(intermediate_layer)); |
745 } | 745 } |
746 | 746 |
747 host_impl().SetViewportSize(root->bounds()); | 747 host_impl().SetViewportSize(root->bounds()); |
748 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); | 748 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); |
749 | 749 |
750 // Sanity check the scenario we just created. | 750 // Sanity check the scenario we just created. |
751 ASSERT_EQ(1u, GetRenderSurfaceList().size()); | 751 ASSERT_EQ(1u, GetRenderSurfaceList().size()); |
752 ASSERT_EQ(1, root_layer()->GetRenderSurface()->num_contributors()); | 752 ASSERT_EQ(1, root_layer()->GetRenderSurface()->num_contributors()); |
753 LayerImpl* child_layer = host_impl().active_tree()->LayerById(456); | 753 LayerImpl* child_layer = host_impl().active_tree()->LayerById(456); |
754 EXPECT_TRUE(child_layer->is_drawn_render_surface_layer_list_member()); | 754 EXPECT_TRUE(child_layer->contributes_to_drawn_render_surface()); |
755 | 755 |
756 // Hit testing for a point outside the layer should return a null pointer. | 756 // Hit testing for a point outside the layer should return a null pointer. |
757 gfx::PointF test_point(69.f, 69.f); | 757 gfx::PointF test_point(69.f, 69.f); |
758 LayerImpl* result_layer = | 758 LayerImpl* result_layer = |
759 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); | 759 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); |
760 EXPECT_FALSE(result_layer); | 760 EXPECT_FALSE(result_layer); |
761 | 761 |
762 test_point = gfx::PointF(91.f, 91.f); | 762 test_point = gfx::PointF(91.f, 91.f); |
763 result_layer = | 763 result_layer = |
764 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); | 764 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
826 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); | 826 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); |
827 | 827 |
828 // Sanity check the scenario we just created. | 828 // Sanity check the scenario we just created. |
829 ASSERT_TRUE(child1); | 829 ASSERT_TRUE(child1); |
830 ASSERT_TRUE(child2); | 830 ASSERT_TRUE(child2); |
831 ASSERT_TRUE(grand_child1); | 831 ASSERT_TRUE(grand_child1); |
832 ASSERT_EQ(1u, GetRenderSurfaceList().size()); | 832 ASSERT_EQ(1u, GetRenderSurfaceList().size()); |
833 | 833 |
834 RenderSurfaceImpl* root_render_surface = root->GetRenderSurface(); | 834 RenderSurfaceImpl* root_render_surface = root->GetRenderSurface(); |
835 ASSERT_EQ(4, root_render_surface->num_contributors()); | 835 ASSERT_EQ(4, root_render_surface->num_contributors()); |
836 EXPECT_TRUE(root_layer()->is_drawn_render_surface_layer_list_member()); | 836 EXPECT_TRUE(root_layer()->contributes_to_drawn_render_surface()); |
837 EXPECT_TRUE(child1->is_drawn_render_surface_layer_list_member()); | 837 EXPECT_TRUE(child1->contributes_to_drawn_render_surface()); |
838 EXPECT_TRUE(child2->is_drawn_render_surface_layer_list_member()); | 838 EXPECT_TRUE(child2->contributes_to_drawn_render_surface()); |
839 EXPECT_TRUE(grand_child1->is_drawn_render_surface_layer_list_member()); | 839 EXPECT_TRUE(grand_child1->contributes_to_drawn_render_surface()); |
840 | 840 |
841 // Nothing overlaps the root at (1, 1), so hit testing there should find | 841 // Nothing overlaps the root at (1, 1), so hit testing there should find |
842 // the root layer. | 842 // the root layer. |
843 gfx::PointF test_point = gfx::PointF(1.f, 1.f); | 843 gfx::PointF test_point = gfx::PointF(1.f, 1.f); |
844 LayerImpl* result_layer = | 844 LayerImpl* result_layer = |
845 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); | 845 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); |
846 ASSERT_TRUE(result_layer); | 846 ASSERT_TRUE(result_layer); |
847 EXPECT_EQ(1, result_layer->id()); | 847 EXPECT_EQ(1, result_layer->id()); |
848 | 848 |
849 // At (15, 15), child1 and root are the only layers. child1 is expected to be | 849 // At (15, 15), child1 and root are the only layers. child1 is expected to be |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1182 ASSERT_TRUE(child2->GetRenderSurface()); | 1182 ASSERT_TRUE(child2->GetRenderSurface()); |
1183 ASSERT_TRUE(grand_child1->GetRenderSurface()); | 1183 ASSERT_TRUE(grand_child1->GetRenderSurface()); |
1184 ASSERT_EQ(4u, GetRenderSurfaceList().size()); | 1184 ASSERT_EQ(4u, GetRenderSurfaceList().size()); |
1185 // The root surface has the root layer, and child1's and child2's render | 1185 // The root surface has the root layer, and child1's and child2's render |
1186 // surfaces. | 1186 // surfaces. |
1187 ASSERT_EQ(3, root->GetRenderSurface()->num_contributors()); | 1187 ASSERT_EQ(3, root->GetRenderSurface()->num_contributors()); |
1188 // The child1 surface has the child1 layer and grand_child1's render surface. | 1188 // The child1 surface has the child1 layer and grand_child1's render surface. |
1189 ASSERT_EQ(2, child1->GetRenderSurface()->num_contributors()); | 1189 ASSERT_EQ(2, child1->GetRenderSurface()->num_contributors()); |
1190 ASSERT_EQ(1, child2->GetRenderSurface()->num_contributors()); | 1190 ASSERT_EQ(1, child2->GetRenderSurface()->num_contributors()); |
1191 ASSERT_EQ(1, grand_child1->GetRenderSurface()->num_contributors()); | 1191 ASSERT_EQ(1, grand_child1->GetRenderSurface()->num_contributors()); |
1192 EXPECT_TRUE(root_layer()->is_drawn_render_surface_layer_list_member()); | 1192 EXPECT_TRUE(root_layer()->contributes_to_drawn_render_surface()); |
1193 EXPECT_TRUE(child1->is_drawn_render_surface_layer_list_member()); | 1193 EXPECT_TRUE(child1->contributes_to_drawn_render_surface()); |
1194 EXPECT_TRUE(grand_child1->is_drawn_render_surface_layer_list_member()); | 1194 EXPECT_TRUE(grand_child1->contributes_to_drawn_render_surface()); |
1195 EXPECT_TRUE(child2->is_drawn_render_surface_layer_list_member()); | 1195 EXPECT_TRUE(child2->contributes_to_drawn_render_surface()); |
1196 | 1196 |
1197 // Nothing overlaps the root at (1, 1), so hit testing there should find | 1197 // Nothing overlaps the root at (1, 1), so hit testing there should find |
1198 // the root layer. | 1198 // the root layer. |
1199 gfx::PointF test_point(1.f, 1.f); | 1199 gfx::PointF test_point(1.f, 1.f); |
1200 LayerImpl* result_layer = | 1200 LayerImpl* result_layer = |
1201 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); | 1201 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); |
1202 ASSERT_TRUE(result_layer); | 1202 ASSERT_TRUE(result_layer); |
1203 EXPECT_EQ(1, result_layer->id()); | 1203 EXPECT_EQ(1, result_layer->id()); |
1204 | 1204 |
1205 // At (15, 15), child1 and root are the only layers. child1 is expected to be | 1205 // At (15, 15), child1 and root are the only layers. child1 is expected to be |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1605 root->test_properties()->AddChild(std::move(clipping_layer)); | 1605 root->test_properties()->AddChild(std::move(clipping_layer)); |
1606 } | 1606 } |
1607 | 1607 |
1608 host_impl().SetViewportSize(root->bounds()); | 1608 host_impl().SetViewportSize(root->bounds()); |
1609 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); | 1609 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); |
1610 | 1610 |
1611 // Sanity check the scenario we just created. | 1611 // Sanity check the scenario we just created. |
1612 ASSERT_EQ(1u, GetRenderSurfaceList().size()); | 1612 ASSERT_EQ(1u, GetRenderSurfaceList().size()); |
1613 ASSERT_EQ(1, root->GetRenderSurface()->num_contributors()); | 1613 ASSERT_EQ(1, root->GetRenderSurface()->num_contributors()); |
1614 LayerImpl* child_layer = host_impl().active_tree()->LayerById(456); | 1614 LayerImpl* child_layer = host_impl().active_tree()->LayerById(456); |
1615 EXPECT_TRUE(child_layer->is_drawn_render_surface_layer_list_member()); | 1615 EXPECT_TRUE(child_layer->contributes_to_drawn_render_surface()); |
1616 | 1616 |
1617 // Hit checking for a point outside the layer should return a null pointer. | 1617 // Hit checking for a point outside the layer should return a null pointer. |
1618 // Despite the child layer being very large, it should be clipped to the root | 1618 // Despite the child layer being very large, it should be clipped to the root |
1619 // layer's bounds. | 1619 // layer's bounds. |
1620 gfx::PointF test_point(24.f, 24.f); | 1620 gfx::PointF test_point(24.f, 24.f); |
1621 LayerImpl* result_layer = | 1621 LayerImpl* result_layer = |
1622 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion( | 1622 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion( |
1623 test_point); | 1623 test_point); |
1624 EXPECT_FALSE(result_layer); | 1624 EXPECT_FALSE(result_layer); |
1625 | 1625 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1760 } | 1760 } |
1761 | 1761 |
1762 host_impl().SetViewportSize(root->bounds()); | 1762 host_impl().SetViewportSize(root->bounds()); |
1763 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); | 1763 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); |
1764 | 1764 |
1765 // Sanity check the scenario we just created. | 1765 // Sanity check the scenario we just created. |
1766 ASSERT_EQ(1u, GetRenderSurfaceList().size()); | 1766 ASSERT_EQ(1u, GetRenderSurfaceList().size()); |
1767 ASSERT_EQ(2, root->GetRenderSurface()->num_contributors()); | 1767 ASSERT_EQ(2, root->GetRenderSurface()->num_contributors()); |
1768 LayerImpl* touch_layer = host_impl().active_tree()->LayerById(123); | 1768 LayerImpl* touch_layer = host_impl().active_tree()->LayerById(123); |
1769 LayerImpl* notouch_layer = host_impl().active_tree()->LayerById(1234); | 1769 LayerImpl* notouch_layer = host_impl().active_tree()->LayerById(1234); |
1770 EXPECT_TRUE(touch_layer->is_drawn_render_surface_layer_list_member()); | 1770 EXPECT_TRUE(touch_layer->contributes_to_drawn_render_surface()); |
1771 EXPECT_TRUE(notouch_layer->is_drawn_render_surface_layer_list_member()); | 1771 EXPECT_TRUE(notouch_layer->contributes_to_drawn_render_surface()); |
1772 | 1772 |
1773 gfx::PointF test_point(35.f, 35.f); | 1773 gfx::PointF test_point(35.f, 35.f); |
1774 LayerImpl* result_layer = | 1774 LayerImpl* result_layer = |
1775 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion( | 1775 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion( |
1776 test_point); | 1776 test_point); |
1777 | 1777 |
1778 // We should have passed through the no-touch layer and found the layer | 1778 // We should have passed through the no-touch layer and found the layer |
1779 // behind it. | 1779 // behind it. |
1780 EXPECT_TRUE(result_layer); | 1780 EXPECT_TRUE(result_layer); |
1781 | 1781 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1817 test_layer->SetTouchEventHandlerRegion(touch_handler_region); | 1817 test_layer->SetTouchEventHandlerRegion(touch_handler_region); |
1818 root->test_properties()->AddChild(std::move(test_layer)); | 1818 root->test_properties()->AddChild(std::move(test_layer)); |
1819 } | 1819 } |
1820 host_impl().SetViewportSize(root->bounds()); | 1820 host_impl().SetViewportSize(root->bounds()); |
1821 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); | 1821 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); |
1822 | 1822 |
1823 LayerImpl* test_layer = root->test_properties()->children[0]; | 1823 LayerImpl* test_layer = root->test_properties()->children[0]; |
1824 // As test_layer doesn't draw content, it shouldn't contribute content to the | 1824 // As test_layer doesn't draw content, it shouldn't contribute content to the |
1825 // root surface. | 1825 // root surface. |
1826 ASSERT_EQ(1u, GetRenderSurfaceList().size()); | 1826 ASSERT_EQ(1u, GetRenderSurfaceList().size()); |
1827 EXPECT_FALSE(test_layer->is_drawn_render_surface_layer_list_member()); | 1827 EXPECT_FALSE(test_layer->contributes_to_drawn_render_surface()); |
1828 | 1828 |
1829 // Hit testing for a point outside the test layer should return null pointer. | 1829 // Hit testing for a point outside the test layer should return null pointer. |
1830 // We also implicitly check that the updated screen space transform of a layer | 1830 // We also implicitly check that the updated screen space transform of a layer |
1831 // that is not in drawn render surface layer list (test_layer) is used during | 1831 // that is not in drawn render surface layer list (test_layer) is used during |
1832 // hit testing (becuase the point is inside test_layer with respect to the old | 1832 // hit testing (becuase the point is inside test_layer with respect to the old |
1833 // screen space transform). | 1833 // screen space transform). |
1834 gfx::PointF test_point(24.f, 24.f); | 1834 gfx::PointF test_point(24.f, 24.f); |
1835 test_layer->SetPosition(gfx::PointF(25.f, 25.f)); | 1835 test_layer->SetPosition(gfx::PointF(25.f, 25.f)); |
1836 gfx::Transform expected_screen_space_transform; | 1836 gfx::Transform expected_screen_space_transform; |
1837 expected_screen_space_transform.Translate(25.f, 25.f); | 1837 expected_screen_space_transform.Translate(25.f, 25.f); |
1838 | 1838 |
1839 host_impl().active_tree()->property_trees()->needs_rebuild = true; | 1839 host_impl().active_tree()->property_trees()->needs_rebuild = true; |
1840 host_impl().active_tree()->BuildLayerListAndPropertyTreesForTesting(); | 1840 host_impl().active_tree()->BuildLayerListAndPropertyTreesForTesting(); |
1841 LayerImpl* result_layer = | 1841 LayerImpl* result_layer = |
1842 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion( | 1842 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion( |
1843 test_point); | 1843 test_point); |
1844 EXPECT_FALSE(result_layer); | 1844 EXPECT_FALSE(result_layer); |
1845 EXPECT_FALSE(test_layer->is_drawn_render_surface_layer_list_member()); | 1845 EXPECT_FALSE(test_layer->contributes_to_drawn_render_surface()); |
1846 EXPECT_TRANSFORMATION_MATRIX_EQ( | 1846 EXPECT_TRANSFORMATION_MATRIX_EQ( |
1847 expected_screen_space_transform, | 1847 expected_screen_space_transform, |
1848 draw_property_utils::ScreenSpaceTransform( | 1848 draw_property_utils::ScreenSpaceTransform( |
1849 test_layer, | 1849 test_layer, |
1850 host_impl().active_tree()->property_trees()->transform_tree)); | 1850 host_impl().active_tree()->property_trees()->transform_tree)); |
1851 | 1851 |
1852 // We change the position of the test layer such that the test point is now | 1852 // We change the position of the test layer such that the test point is now |
1853 // inside the test_layer. | 1853 // inside the test_layer. |
1854 test_layer = root->test_properties()->children[0]; | 1854 test_layer = root->test_properties()->children[0]; |
1855 test_layer->SetPosition(gfx::PointF(10.f, 10.f)); | 1855 test_layer->SetPosition(gfx::PointF(10.f, 10.f)); |
1856 test_layer->NoteLayerPropertyChanged(); | 1856 test_layer->NoteLayerPropertyChanged(); |
1857 expected_screen_space_transform.MakeIdentity(); | 1857 expected_screen_space_transform.MakeIdentity(); |
1858 expected_screen_space_transform.Translate(10.f, 10.f); | 1858 expected_screen_space_transform.Translate(10.f, 10.f); |
1859 | 1859 |
1860 host_impl().active_tree()->property_trees()->needs_rebuild = true; | 1860 host_impl().active_tree()->property_trees()->needs_rebuild = true; |
1861 host_impl().active_tree()->BuildLayerListAndPropertyTreesForTesting(); | 1861 host_impl().active_tree()->BuildLayerListAndPropertyTreesForTesting(); |
1862 result_layer = | 1862 result_layer = |
1863 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion( | 1863 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion( |
1864 test_point); | 1864 test_point); |
1865 ASSERT_TRUE(result_layer); | 1865 ASSERT_TRUE(result_layer); |
1866 ASSERT_EQ(test_layer, result_layer); | 1866 ASSERT_EQ(test_layer, result_layer); |
1867 EXPECT_FALSE(result_layer->is_drawn_render_surface_layer_list_member()); | 1867 EXPECT_FALSE(result_layer->contributes_to_drawn_render_surface()); |
1868 EXPECT_TRANSFORMATION_MATRIX_EQ( | 1868 EXPECT_TRANSFORMATION_MATRIX_EQ( |
1869 expected_screen_space_transform, | 1869 expected_screen_space_transform, |
1870 draw_property_utils::ScreenSpaceTransform( | 1870 draw_property_utils::ScreenSpaceTransform( |
1871 test_layer, | 1871 test_layer, |
1872 host_impl().active_tree()->property_trees()->transform_tree)); | 1872 host_impl().active_tree()->property_trees()->transform_tree)); |
1873 } | 1873 } |
1874 | 1874 |
1875 TEST_F(LayerTreeImplTest, SelectionBoundsForSingleLayer) { | 1875 TEST_F(LayerTreeImplTest, SelectionBoundsForSingleLayer) { |
1876 LayerImpl* root = root_layer(); | 1876 LayerImpl* root = root_layer(); |
1877 root->SetBounds(gfx::Size(100, 100)); | 1877 root->SetBounds(gfx::Size(100, 100)); |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2381 auto weak_promise = promise->AsWeakPtr(); | 2381 auto weak_promise = promise->AsWeakPtr(); |
2382 host_impl().active_tree()->QueueSwapPromise(std::move(promise)); | 2382 host_impl().active_tree()->QueueSwapPromise(std::move(promise)); |
2383 host_impl().active_tree()->BreakSwapPromises( | 2383 host_impl().active_tree()->BreakSwapPromises( |
2384 SwapPromise::DidNotSwapReason::SWAP_FAILS); | 2384 SwapPromise::DidNotSwapReason::SWAP_FAILS); |
2385 EXPECT_FALSE(weak_promise); | 2385 EXPECT_FALSE(weak_promise); |
2386 } | 2386 } |
2387 } | 2387 } |
2388 | 2388 |
2389 } // namespace | 2389 } // namespace |
2390 } // namespace cc | 2390 } // namespace cc |
OLD | NEW |