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 "cc/layers/heads_up_display_layer_impl.h" | 7 #include "cc/layers/heads_up_display_layer_impl.h" |
8 #include "cc/layers/layer.h" | 8 #include "cc/layers/layer.h" |
9 #include "cc/layers/solid_color_scrollbar_layer_impl.h" | 9 #include "cc/layers/solid_color_scrollbar_layer_impl.h" |
10 #include "cc/test/fake_impl_task_runner_provider.h" | 10 #include "cc/test/fake_impl_task_runner_provider.h" |
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 // the hit testing algorithm needs to recognize that multiple parent layers | 641 // the hit testing algorithm needs to recognize that multiple parent layers |
642 // may clip the layer, and should not actually hit those clipped areas. | 642 // may clip the layer, and should not actually hit those clipped areas. |
643 // | 643 // |
644 // The child and grand_child layers are both initialized to clip the | 644 // The child and grand_child layers are both initialized to clip the |
645 // rotated_leaf. The child layer is rotated about the top-left corner, so that | 645 // rotated_leaf. The child layer is rotated about the top-left corner, so that |
646 // the root + child clips combined create a triangle. The rotated_leaf will | 646 // the root + child clips combined create a triangle. The rotated_leaf will |
647 // only be visible where it overlaps this triangle. | 647 // only be visible where it overlaps this triangle. |
648 // | 648 // |
649 scoped_ptr<LayerImpl> root = | 649 scoped_ptr<LayerImpl> root = |
650 LayerImpl::Create(host_impl().active_tree(), 123); | 650 LayerImpl::Create(host_impl().active_tree(), 123); |
| 651 LayerImpl* root_layer = root.get(); |
651 | 652 |
652 gfx::Transform identity_matrix; | 653 gfx::Transform identity_matrix; |
653 gfx::Point3F transform_origin; | 654 gfx::Point3F transform_origin; |
654 gfx::PointF position; | 655 gfx::PointF position; |
655 gfx::Size bounds(100, 100); | 656 gfx::Size bounds(100, 100); |
656 SetLayerPropertiesForTesting(root.get(), identity_matrix, transform_origin, | 657 SetLayerPropertiesForTesting(root.get(), identity_matrix, transform_origin, |
657 position, bounds, true, false, true); | 658 position, bounds, true, false, true); |
658 root->SetMasksToBounds(true); | 659 root->SetMasksToBounds(true); |
659 { | 660 { |
660 scoped_ptr<LayerImpl> child = | 661 scoped_ptr<LayerImpl> child = |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
695 position = gfx::PointF(); | 696 position = gfx::PointF(); |
696 bounds = gfx::Size(100, 100); | 697 bounds = gfx::Size(100, 100); |
697 SetLayerPropertiesForTesting(rotated_leaf.get(), rotated_leaf_transform, | 698 SetLayerPropertiesForTesting(rotated_leaf.get(), rotated_leaf_transform, |
698 transform_origin, position, bounds, true, | 699 transform_origin, position, bounds, true, |
699 false, false); | 700 false, false); |
700 rotated_leaf->SetDrawsContent(true); | 701 rotated_leaf->SetDrawsContent(true); |
701 | 702 |
702 grand_child->AddChild(std::move(rotated_leaf)); | 703 grand_child->AddChild(std::move(rotated_leaf)); |
703 child->AddChild(std::move(grand_child)); | 704 child->AddChild(std::move(grand_child)); |
704 root->AddChild(std::move(child)); | 705 root->AddChild(std::move(child)); |
| 706 host_impl().active_tree()->SetRootLayer(std::move(root)); |
705 | 707 |
706 ExecuteCalculateDrawProperties(root.get()); | 708 ExecuteCalculateDrawProperties(root_layer); |
707 } | 709 } |
708 | 710 |
709 host_impl().SetViewportSize(root->bounds()); | 711 host_impl().SetViewportSize(root_layer->bounds()); |
710 host_impl().active_tree()->SetRootLayer(std::move(root)); | |
711 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); | 712 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); |
712 // (11, 89) is close to the the bottom left corner within the clip, but it is | 713 // (11, 89) is close to the the bottom left corner within the clip, but it is |
713 // not inside the layer. | 714 // not inside the layer. |
714 gfx::PointF test_point(11.f, 89.f); | 715 gfx::PointF test_point(11.f, 89.f); |
715 LayerImpl* result_layer = | 716 LayerImpl* result_layer = |
716 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); | 717 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); |
717 EXPECT_FALSE(result_layer); | 718 EXPECT_FALSE(result_layer); |
718 | 719 |
719 // Closer inwards from the bottom left will overlap the layer. | 720 // Closer inwards from the bottom left will overlap the layer. |
720 test_point = gfx::PointF(25.f, 75.f); | 721 test_point = gfx::PointF(25.f, 75.f); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
823 | 824 |
824 test_point = gfx::PointF(89.f, 89.f); | 825 test_point = gfx::PointF(89.f, 89.f); |
825 result_layer = | 826 result_layer = |
826 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); | 827 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); |
827 ASSERT_TRUE(result_layer); | 828 ASSERT_TRUE(result_layer); |
828 EXPECT_EQ(456, result_layer->id()); | 829 EXPECT_EQ(456, result_layer->id()); |
829 } | 830 } |
830 | 831 |
831 TEST_F(LayerTreeImplTest, HitTestingForMultipleLayers) { | 832 TEST_F(LayerTreeImplTest, HitTestingForMultipleLayers) { |
832 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl().active_tree(), 1); | 833 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl().active_tree(), 1); |
| 834 LayerImpl* root_layer = root.get(); |
833 | 835 |
834 gfx::Transform identity_matrix; | 836 gfx::Transform identity_matrix; |
835 gfx::Point3F transform_origin; | 837 gfx::Point3F transform_origin; |
836 gfx::PointF position; | 838 gfx::PointF position; |
837 gfx::Size bounds(100, 100); | 839 gfx::Size bounds(100, 100); |
838 SetLayerPropertiesForTesting(root.get(), identity_matrix, transform_origin, | 840 SetLayerPropertiesForTesting(root.get(), identity_matrix, transform_origin, |
839 position, bounds, true, false, true); | 841 position, bounds, true, false, true); |
840 root->SetDrawsContent(true); | 842 root->SetDrawsContent(true); |
841 { | 843 { |
842 // child 1 and child2 are initialized to overlap between x=50 and x=60. | 844 // child 1 and child2 are initialized to overlap between x=50 and x=60. |
(...skipping 29 matching lines...) Expand all Loading... |
872 position = gfx::PointF(0.f, 40.f); | 874 position = gfx::PointF(0.f, 40.f); |
873 bounds = gfx::Size(100, 50); | 875 bounds = gfx::Size(100, 50); |
874 SetLayerPropertiesForTesting(grand_child1.get(), identity_matrix, | 876 SetLayerPropertiesForTesting(grand_child1.get(), identity_matrix, |
875 transform_origin, position, bounds, true, | 877 transform_origin, position, bounds, true, |
876 false, false); | 878 false, false); |
877 grand_child1->SetDrawsContent(true); | 879 grand_child1->SetDrawsContent(true); |
878 | 880 |
879 child1->AddChild(std::move(grand_child1)); | 881 child1->AddChild(std::move(grand_child1)); |
880 root->AddChild(std::move(child1)); | 882 root->AddChild(std::move(child1)); |
881 root->AddChild(std::move(child2)); | 883 root->AddChild(std::move(child2)); |
| 884 host_impl().active_tree()->SetRootLayer(std::move(root)); |
882 | 885 |
883 ExecuteCalculateDrawProperties(root.get()); | 886 ExecuteCalculateDrawProperties(root_layer); |
884 } | 887 } |
885 | 888 |
886 LayerImpl* child1 = root->children()[0]; | 889 LayerImpl* child1 = root_layer->children()[0]; |
887 LayerImpl* child2 = root->children()[1]; | 890 LayerImpl* child2 = root_layer->children()[1]; |
888 LayerImpl* grand_child1 = child1->children()[0]; | 891 LayerImpl* grand_child1 = child1->children()[0]; |
889 | 892 |
890 host_impl().SetViewportSize(root->bounds()); | 893 host_impl().SetViewportSize(root_layer->bounds()); |
891 host_impl().active_tree()->SetRootLayer(std::move(root)); | |
892 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); | 894 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); |
893 | 895 |
894 // Sanity check the scenario we just created. | 896 // Sanity check the scenario we just created. |
895 ASSERT_TRUE(child1); | 897 ASSERT_TRUE(child1); |
896 ASSERT_TRUE(child2); | 898 ASSERT_TRUE(child2); |
897 ASSERT_TRUE(grand_child1); | 899 ASSERT_TRUE(grand_child1); |
898 ASSERT_EQ(1u, RenderSurfaceLayerList().size()); | 900 ASSERT_EQ(1u, RenderSurfaceLayerList().size()); |
899 | 901 |
900 RenderSurfaceImpl* root_render_surface = root_layer()->render_surface(); | 902 RenderSurfaceImpl* root_render_surface = root_layer->render_surface(); |
901 ASSERT_EQ(4u, root_render_surface->layer_list().size()); | 903 ASSERT_EQ(4u, root_render_surface->layer_list().size()); |
902 ASSERT_EQ(1, root_render_surface->layer_list().at(0)->id()); // root layer | 904 ASSERT_EQ(1, root_render_surface->layer_list().at(0)->id()); // root layer |
903 ASSERT_EQ(2, root_render_surface->layer_list().at(1)->id()); // child1 | 905 ASSERT_EQ(2, root_render_surface->layer_list().at(1)->id()); // child1 |
904 ASSERT_EQ(4, root_render_surface->layer_list().at(2)->id()); // grand_child1 | 906 ASSERT_EQ(4, root_render_surface->layer_list().at(2)->id()); // grand_child1 |
905 ASSERT_EQ(3, root_render_surface->layer_list().at(3)->id()); // child2 | 907 ASSERT_EQ(3, root_render_surface->layer_list().at(3)->id()); // child2 |
906 | 908 |
907 // Nothing overlaps the root_layer at (1, 1), so hit testing there should find | 909 // Nothing overlaps the root_layer at (1, 1), so hit testing there should find |
908 // the root layer. | 910 // the root layer. |
909 gfx::PointF test_point = gfx::PointF(1.f, 1.f); | 911 gfx::PointF test_point = gfx::PointF(1.f, 1.f); |
910 LayerImpl* result_layer = | 912 LayerImpl* result_layer = |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1285 // parent, so the only thing that should be hit is |root|. | 1287 // parent, so the only thing that should be hit is |root|. |
1286 ASSERT_TRUE(result_layer); | 1288 ASSERT_TRUE(result_layer); |
1287 ASSERT_EQ(1, result_layer->id()); | 1289 ASSERT_EQ(1, result_layer->id()); |
1288 } | 1290 } |
1289 TEST_F(LayerTreeImplTest, HitTestingForMultipleLayerLists) { | 1291 TEST_F(LayerTreeImplTest, HitTestingForMultipleLayerLists) { |
1290 // | 1292 // |
1291 // The geometry is set up similarly to the previous case, but | 1293 // The geometry is set up similarly to the previous case, but |
1292 // all layers are forced to be render surfaces now. | 1294 // all layers are forced to be render surfaces now. |
1293 // | 1295 // |
1294 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl().active_tree(), 1); | 1296 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl().active_tree(), 1); |
| 1297 LayerImpl* root_layer = root.get(); |
1295 | 1298 |
1296 gfx::Transform identity_matrix; | 1299 gfx::Transform identity_matrix; |
1297 gfx::Point3F transform_origin; | 1300 gfx::Point3F transform_origin; |
1298 gfx::PointF position; | 1301 gfx::PointF position; |
1299 gfx::Size bounds(100, 100); | 1302 gfx::Size bounds(100, 100); |
1300 SetLayerPropertiesForTesting(root.get(), identity_matrix, transform_origin, | 1303 SetLayerPropertiesForTesting(root.get(), identity_matrix, transform_origin, |
1301 position, bounds, true, false, true); | 1304 position, bounds, true, false, true); |
1302 root->SetDrawsContent(true); | 1305 root->SetDrawsContent(true); |
1303 { | 1306 { |
1304 // child 1 and child2 are initialized to overlap between x=50 and x=60. | 1307 // child 1 and child2 are initialized to overlap between x=50 and x=60. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1337 bounds = gfx::Size(100, 50); | 1340 bounds = gfx::Size(100, 50); |
1338 SetLayerPropertiesForTesting(grand_child1.get(), identity_matrix, | 1341 SetLayerPropertiesForTesting(grand_child1.get(), identity_matrix, |
1339 transform_origin, position, bounds, true, | 1342 transform_origin, position, bounds, true, |
1340 false, false); | 1343 false, false); |
1341 grand_child1->SetDrawsContent(true); | 1344 grand_child1->SetDrawsContent(true); |
1342 grand_child1->SetForceRenderSurface(true); | 1345 grand_child1->SetForceRenderSurface(true); |
1343 | 1346 |
1344 child1->AddChild(std::move(grand_child1)); | 1347 child1->AddChild(std::move(grand_child1)); |
1345 root->AddChild(std::move(child1)); | 1348 root->AddChild(std::move(child1)); |
1346 root->AddChild(std::move(child2)); | 1349 root->AddChild(std::move(child2)); |
| 1350 host_impl().active_tree()->SetRootLayer(std::move(root)); |
1347 | 1351 |
1348 ExecuteCalculateDrawProperties(root.get()); | 1352 ExecuteCalculateDrawProperties(root_layer); |
1349 } | 1353 } |
1350 | 1354 |
1351 LayerImpl* child1 = root->children()[0]; | 1355 LayerImpl* child1 = root_layer->children()[0]; |
1352 LayerImpl* child2 = root->children()[1]; | 1356 LayerImpl* child2 = root_layer->children()[1]; |
1353 LayerImpl* grand_child1 = child1->children()[0]; | 1357 LayerImpl* grand_child1 = child1->children()[0]; |
1354 | 1358 |
1355 host_impl().SetViewportSize(root->bounds()); | 1359 host_impl().SetViewportSize(root_layer->bounds()); |
1356 host_impl().active_tree()->SetRootLayer(std::move(root)); | |
1357 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); | 1360 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); |
1358 | 1361 |
1359 // Sanity check the scenario we just created. | 1362 // Sanity check the scenario we just created. |
1360 ASSERT_TRUE(child1); | 1363 ASSERT_TRUE(child1); |
1361 ASSERT_TRUE(child2); | 1364 ASSERT_TRUE(child2); |
1362 ASSERT_TRUE(grand_child1); | 1365 ASSERT_TRUE(grand_child1); |
1363 ASSERT_TRUE(child1->render_surface()); | 1366 ASSERT_TRUE(child1->render_surface()); |
1364 ASSERT_TRUE(child2->render_surface()); | 1367 ASSERT_TRUE(child2->render_surface()); |
1365 ASSERT_TRUE(grand_child1->render_surface()); | 1368 ASSERT_TRUE(grand_child1->render_surface()); |
1366 ASSERT_EQ(4u, RenderSurfaceLayerList().size()); | 1369 ASSERT_EQ(4u, RenderSurfaceLayerList().size()); |
1367 // The root surface has the root layer, and child1's and child2's render | 1370 // The root surface has the root layer, and child1's and child2's render |
1368 // surfaces. | 1371 // surfaces. |
1369 ASSERT_EQ(3u, root_layer()->render_surface()->layer_list().size()); | 1372 ASSERT_EQ(3u, root_layer->render_surface()->layer_list().size()); |
1370 // The child1 surface has the child1 layer and grand_child1's render surface. | 1373 // The child1 surface has the child1 layer and grand_child1's render surface. |
1371 ASSERT_EQ(2u, child1->render_surface()->layer_list().size()); | 1374 ASSERT_EQ(2u, child1->render_surface()->layer_list().size()); |
1372 ASSERT_EQ(1u, child2->render_surface()->layer_list().size()); | 1375 ASSERT_EQ(1u, child2->render_surface()->layer_list().size()); |
1373 ASSERT_EQ(1u, grand_child1->render_surface()->layer_list().size()); | 1376 ASSERT_EQ(1u, grand_child1->render_surface()->layer_list().size()); |
1374 ASSERT_EQ(1, RenderSurfaceLayerList().at(0)->id()); // root layer | 1377 ASSERT_EQ(1, RenderSurfaceLayerList().at(0)->id()); // root layer |
1375 ASSERT_EQ(2, RenderSurfaceLayerList()[1]->id()); // child1 | 1378 ASSERT_EQ(2, RenderSurfaceLayerList()[1]->id()); // child1 |
1376 ASSERT_EQ(4, RenderSurfaceLayerList().at(2)->id()); // grand_child1 | 1379 ASSERT_EQ(4, RenderSurfaceLayerList().at(2)->id()); // grand_child1 |
1377 ASSERT_EQ(3, RenderSurfaceLayerList()[3]->id()); // child2 | 1380 ASSERT_EQ(3, RenderSurfaceLayerList()[3]->id()); // child2 |
1378 | 1381 |
1379 // Nothing overlaps the root_layer at (1, 1), so hit testing there should find | 1382 // Nothing overlaps the root_layer at (1, 1), so hit testing there should find |
(...skipping 997 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2377 TEST_F(LayerTreeImplTest, DeviceScaleFactorNeedsDrawPropertiesUpdate) { | 2380 TEST_F(LayerTreeImplTest, DeviceScaleFactorNeedsDrawPropertiesUpdate) { |
2378 host_impl().active_tree()->SetDeviceScaleFactor(1.f); | 2381 host_impl().active_tree()->SetDeviceScaleFactor(1.f); |
2379 host_impl().active_tree()->UpdateDrawProperties(false); | 2382 host_impl().active_tree()->UpdateDrawProperties(false); |
2380 EXPECT_FALSE(host_impl().active_tree()->needs_update_draw_properties()); | 2383 EXPECT_FALSE(host_impl().active_tree()->needs_update_draw_properties()); |
2381 host_impl().active_tree()->SetDeviceScaleFactor(2.f); | 2384 host_impl().active_tree()->SetDeviceScaleFactor(2.f); |
2382 EXPECT_TRUE(host_impl().active_tree()->needs_update_draw_properties()); | 2385 EXPECT_TRUE(host_impl().active_tree()->needs_update_draw_properties()); |
2383 } | 2386 } |
2384 | 2387 |
2385 } // namespace | 2388 } // namespace |
2386 } // namespace cc | 2389 } // namespace cc |
OLD | NEW |