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" |
11 #include "cc/test/geometry_test_utils.h" | 11 #include "cc/test/geometry_test_utils.h" |
12 #include "cc/test/layer_test_common.h" | 12 #include "cc/test/layer_test_common.h" |
13 #include "cc/test/layer_tree_settings_for_testing.h" | |
14 #include "cc/trees/clip_node.h" | 13 #include "cc/trees/clip_node.h" |
15 #include "cc/trees/draw_property_utils.h" | 14 #include "cc/trees/draw_property_utils.h" |
16 #include "cc/trees/layer_tree_host_common.h" | 15 #include "cc/trees/layer_tree_host_common.h" |
17 #include "cc/trees/layer_tree_host_impl.h" | 16 #include "cc/trees/layer_tree_host_impl.h" |
18 #include "cc/trees/mutable_properties.h" | 17 #include "cc/trees/mutable_properties.h" |
19 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
21 | 20 |
22 namespace cc { | 21 namespace cc { |
23 namespace { | 22 namespace { |
24 | 23 |
25 class LayerTreeImplTestSettings : public LayerTreeSettingsForTesting { | 24 class LayerTreeImplTestSettings : public LayerTreeSettings { |
26 public: | 25 public: |
27 LayerTreeImplTestSettings() { | 26 LayerTreeImplTestSettings() { |
28 layer_transforms_should_scale_layer_contents = true; | 27 layer_transforms_should_scale_layer_contents = true; |
29 } | 28 } |
30 }; | 29 }; |
31 | 30 |
32 class LayerTreeImplTest : public testing::Test { | 31 class LayerTreeImplTest : public testing::Test { |
33 public: | 32 public: |
34 LayerTreeImplTest() : impl_test_(LayerTreeImplTestSettings()) {} | 33 LayerTreeImplTest() : impl_test_(LayerTreeImplTestSettings()) {} |
35 | 34 |
36 FakeLayerTreeHostImpl& host_impl() const { return *impl_test_.host_impl(); } | 35 FakeLayerTreeHostImpl& host_impl() const { return *impl_test_.host_impl(); } |
37 | 36 |
38 LayerImpl* root_layer() { return impl_test_.root_layer_for_testing(); } | 37 LayerImpl* root_layer() { return impl_test_.root_layer_for_testing(); } |
39 | 38 |
40 const LayerImplList& RenderSurfaceLayerList() const { | 39 const LayerImplList& RenderSurfaceLayerList() const { |
41 return host_impl().active_tree()->RenderSurfaceLayerList(); | 40 return host_impl().active_tree()->RenderSurfaceLayerList(); |
42 } | 41 } |
43 | 42 |
44 void ExecuteCalculateDrawProperties( | 43 void ExecuteCalculateDrawProperties(LayerImpl* root_layer) { |
45 LayerImpl* root_layer, | |
46 bool skip_verify_visible_rect_calculations = false) { | |
47 // We are probably not testing what is intended if the root_layer bounds are | 44 // We are probably not testing what is intended if the root_layer bounds are |
48 // empty. | 45 // empty. |
49 DCHECK(!root_layer->bounds().IsEmpty()); | 46 DCHECK(!root_layer->bounds().IsEmpty()); |
50 | 47 |
51 render_surface_layer_list_impl_.clear(); | 48 render_surface_layer_list_impl_.clear(); |
52 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( | 49 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
53 root_layer, root_layer->bounds(), &render_surface_layer_list_impl_); | 50 root_layer, root_layer->bounds(), &render_surface_layer_list_impl_); |
54 inputs.can_adjust_raster_scales = true; | 51 inputs.can_adjust_raster_scales = true; |
55 if (skip_verify_visible_rect_calculations) | |
56 inputs.verify_visible_rect_calculations = false; | |
57 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); | 52 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
58 } | 53 } |
59 | 54 |
60 int HitTestSimpleTree(int root_id, | 55 int HitTestSimpleTree(int root_id, |
61 int left_child_id, | 56 int left_child_id, |
62 int right_child_id, | 57 int right_child_id, |
63 int root_sorting_context, | 58 int root_sorting_context, |
64 int left_child_sorting_context, | 59 int left_child_sorting_context, |
65 int right_child_sorting_context, | 60 int right_child_sorting_context, |
66 float root_depth, | 61 float root_depth, |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 uninvertible_transform.matrix().set(2, 2, 0.0); | 235 uninvertible_transform.matrix().set(2, 2, 0.0); |
241 uninvertible_transform.matrix().set(3, 3, 0.0); | 236 uninvertible_transform.matrix().set(3, 3, 0.0); |
242 ASSERT_FALSE(uninvertible_transform.IsInvertible()); | 237 ASSERT_FALSE(uninvertible_transform.IsInvertible()); |
243 | 238 |
244 LayerImpl* root = root_layer(); | 239 LayerImpl* root = root_layer(); |
245 root->test_properties()->transform = uninvertible_transform; | 240 root->test_properties()->transform = uninvertible_transform; |
246 root->SetBounds(gfx::Size(100, 100)); | 241 root->SetBounds(gfx::Size(100, 100)); |
247 root->SetDrawsContent(true); | 242 root->SetDrawsContent(true); |
248 | 243 |
249 host_impl().SetViewportSize(root->bounds()); | 244 host_impl().SetViewportSize(root->bounds()); |
250 // While computing visible rects by combining clips in screen space, we set | 245 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); |
251 // the entire layer as visible if the screen space transform is singular. This | |
252 // is not always true when we combine clips in target space because if the | |
253 // intersection of combined_clip in taret space with layer_rect projected to | |
254 // target space is empty, we set it to an empty rect. | |
255 bool skip_verify_visible_rect_calculations = true; | |
256 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree( | |
257 skip_verify_visible_rect_calculations); | |
258 // Sanity check the scenario we just created. | 246 // Sanity check the scenario we just created. |
259 ASSERT_EQ(1u, RenderSurfaceLayerList().size()); | 247 ASSERT_EQ(1u, RenderSurfaceLayerList().size()); |
260 ASSERT_EQ(1u, root_layer()->GetRenderSurface()->layer_list().size()); | 248 ASSERT_EQ(1u, root_layer()->GetRenderSurface()->layer_list().size()); |
261 ASSERT_FALSE(root_layer()->ScreenSpaceTransform().IsInvertible()); | 249 ASSERT_FALSE(root_layer()->ScreenSpaceTransform().IsInvertible()); |
262 | 250 |
263 // Hit testing any point should not hit the layer. If the invertible matrix is | 251 // Hit testing any point should not hit the layer. If the invertible matrix is |
264 // accidentally ignored and treated like an identity, then the hit testing | 252 // accidentally ignored and treated like an identity, then the hit testing |
265 // will incorrectly hit the layer when it shouldn't. | 253 // will incorrectly hit the layer when it shouldn't. |
266 gfx::PointF test_point(1.f, 1.f); | 254 gfx::PointF test_point(1.f, 1.f); |
267 LayerImpl* result_layer = | 255 LayerImpl* result_layer = |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 gfx::PointF test_point(160.f, 160.f); | 422 gfx::PointF test_point(160.f, 160.f); |
435 LayerImpl* result_layer = | 423 LayerImpl* result_layer = |
436 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); | 424 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); |
437 EXPECT_FALSE(result_layer); | 425 EXPECT_FALSE(result_layer); |
438 | 426 |
439 test_point = gfx::PointF(140.f, 140.f); | 427 test_point = gfx::PointF(140.f, 140.f); |
440 result_layer = | 428 result_layer = |
441 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); | 429 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); |
442 ASSERT_TRUE(result_layer); | 430 ASSERT_TRUE(result_layer); |
443 EXPECT_EQ(5, result_layer->id()); | 431 EXPECT_EQ(5, result_layer->id()); |
444 | |
445 ClipTree& clip_tree = host_impl().active_tree()->property_trees()->clip_tree; | |
446 ClipNode* clip_node = clip_tree.Node(result_layer->clip_tree_index()); | |
447 EXPECT_NE(clip_node->transform_id, clip_node->target_transform_id); | |
448 } | 432 } |
449 | 433 |
450 TEST_F(LayerTreeImplTest, HitTestingSiblings) { | 434 TEST_F(LayerTreeImplTest, HitTestingSiblings) { |
451 // This tests hit testing when the test point hits only one of the siblings. | 435 // This tests hit testing when the test point hits only one of the siblings. |
452 LayerImpl* root = root_layer(); | 436 LayerImpl* root = root_layer(); |
453 root->SetBounds(gfx::Size(100, 100)); | 437 root->SetBounds(gfx::Size(100, 100)); |
454 | 438 |
455 std::unique_ptr<LayerImpl> child1 = | 439 std::unique_ptr<LayerImpl> child1 = |
456 LayerImpl::Create(host_impl().active_tree(), 2); | 440 LayerImpl::Create(host_impl().active_tree(), 2); |
457 child1->SetBounds(gfx::Size(25, 25)); | 441 child1->SetBounds(gfx::Size(25, 25)); |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 // the root + child clips combined create a triangle. The rotated_leaf will | 614 // the root + child clips combined create a triangle. The rotated_leaf will |
631 // only be visible where it overlaps this triangle. | 615 // only be visible where it overlaps this triangle. |
632 // | 616 // |
633 LayerImpl* root = root_layer(); | 617 LayerImpl* root = root_layer(); |
634 | 618 |
635 root->SetBounds(gfx::Size(100, 100)); | 619 root->SetBounds(gfx::Size(100, 100)); |
636 root->SetMasksToBounds(true); | 620 root->SetMasksToBounds(true); |
637 // Visible rects computed by combinig clips in target space and root space | 621 // Visible rects computed by combinig clips in target space and root space |
638 // don't match because of rotation transforms. So, we skip | 622 // don't match because of rotation transforms. So, we skip |
639 // verify_visible_rect_calculations. | 623 // verify_visible_rect_calculations. |
640 bool skip_verify_visible_rect_calculations = true; | |
641 { | 624 { |
642 std::unique_ptr<LayerImpl> child = | 625 std::unique_ptr<LayerImpl> child = |
643 LayerImpl::Create(host_impl().active_tree(), 456); | 626 LayerImpl::Create(host_impl().active_tree(), 456); |
644 std::unique_ptr<LayerImpl> grand_child = | 627 std::unique_ptr<LayerImpl> grand_child = |
645 LayerImpl::Create(host_impl().active_tree(), 789); | 628 LayerImpl::Create(host_impl().active_tree(), 789); |
646 std::unique_ptr<LayerImpl> rotated_leaf = | 629 std::unique_ptr<LayerImpl> rotated_leaf = |
647 LayerImpl::Create(host_impl().active_tree(), 2468); | 630 LayerImpl::Create(host_impl().active_tree(), 2468); |
648 | 631 |
649 child->SetPosition(gfx::PointF(10.f, 10.f)); | 632 child->SetPosition(gfx::PointF(10.f, 10.f)); |
650 child->SetBounds(gfx::Size(80, 80)); | 633 child->SetBounds(gfx::Size(80, 80)); |
(...skipping 19 matching lines...) Expand all Loading... |
670 rotated_leaf_transform.RotateAboutZAxis(45.0); | 653 rotated_leaf_transform.RotateAboutZAxis(45.0); |
671 rotated_leaf_transform.Translate(-50.0, -50.0); | 654 rotated_leaf_transform.Translate(-50.0, -50.0); |
672 rotated_leaf->SetBounds(gfx::Size(100, 100)); | 655 rotated_leaf->SetBounds(gfx::Size(100, 100)); |
673 rotated_leaf->test_properties()->transform = rotated_leaf_transform; | 656 rotated_leaf->test_properties()->transform = rotated_leaf_transform; |
674 rotated_leaf->SetDrawsContent(true); | 657 rotated_leaf->SetDrawsContent(true); |
675 | 658 |
676 grand_child->test_properties()->AddChild(std::move(rotated_leaf)); | 659 grand_child->test_properties()->AddChild(std::move(rotated_leaf)); |
677 child->test_properties()->AddChild(std::move(grand_child)); | 660 child->test_properties()->AddChild(std::move(grand_child)); |
678 root->test_properties()->AddChild(std::move(child)); | 661 root->test_properties()->AddChild(std::move(child)); |
679 | 662 |
680 ExecuteCalculateDrawProperties(root, skip_verify_visible_rect_calculations); | 663 ExecuteCalculateDrawProperties(root); |
681 } | 664 } |
682 | 665 |
683 host_impl().SetViewportSize(root->bounds()); | 666 host_impl().SetViewportSize(root->bounds()); |
684 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree( | 667 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); |
685 skip_verify_visible_rect_calculations); | |
686 // (11, 89) is close to the the bottom left corner within the clip, but it is | 668 // (11, 89) is close to the the bottom left corner within the clip, but it is |
687 // not inside the layer. | 669 // not inside the layer. |
688 gfx::PointF test_point(11.f, 89.f); | 670 gfx::PointF test_point(11.f, 89.f); |
689 LayerImpl* result_layer = | 671 LayerImpl* result_layer = |
690 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); | 672 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); |
691 EXPECT_FALSE(result_layer); | 673 EXPECT_FALSE(result_layer); |
692 | 674 |
693 // Closer inwards from the bottom left will overlap the layer. | 675 // Closer inwards from the bottom left will overlap the layer. |
694 test_point = gfx::PointF(25.f, 75.f); | 676 test_point = gfx::PointF(25.f, 75.f); |
695 result_layer = | 677 result_layer = |
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1336 | 1318 |
1337 Region touch_handler_region(gfx::Rect(10, 10, 50, 50)); | 1319 Region touch_handler_region(gfx::Rect(10, 10, 50, 50)); |
1338 | 1320 |
1339 LayerImpl* root = root_layer(); | 1321 LayerImpl* root = root_layer(); |
1340 root->test_properties()->transform = uninvertible_transform; | 1322 root->test_properties()->transform = uninvertible_transform; |
1341 root->SetBounds(gfx::Size(100, 100)); | 1323 root->SetBounds(gfx::Size(100, 100)); |
1342 root->SetDrawsContent(true); | 1324 root->SetDrawsContent(true); |
1343 root->SetTouchEventHandlerRegion(touch_handler_region); | 1325 root->SetTouchEventHandlerRegion(touch_handler_region); |
1344 | 1326 |
1345 host_impl().SetViewportSize(root->bounds()); | 1327 host_impl().SetViewportSize(root->bounds()); |
1346 // While computing visible rects by combining clips in screen space, we set | 1328 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); |
1347 // the entire layer as visible if the screen space transform is singular. This | |
1348 // is not always true when we combine clips in target space because if the | |
1349 // intersection of combined_clip in taret space with layer_rect projected to | |
1350 // target space is empty, we set it to an empty rect. | |
1351 bool skip_verify_visible_rect_calculations = true; | |
1352 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree( | |
1353 skip_verify_visible_rect_calculations); | |
1354 | 1329 |
1355 // Sanity check the scenario we just created. | 1330 // Sanity check the scenario we just created. |
1356 ASSERT_EQ(1u, RenderSurfaceLayerList().size()); | 1331 ASSERT_EQ(1u, RenderSurfaceLayerList().size()); |
1357 ASSERT_EQ(1u, root->GetRenderSurface()->layer_list().size()); | 1332 ASSERT_EQ(1u, root->GetRenderSurface()->layer_list().size()); |
1358 ASSERT_FALSE(root->ScreenSpaceTransform().IsInvertible()); | 1333 ASSERT_FALSE(root->ScreenSpaceTransform().IsInvertible()); |
1359 | 1334 |
1360 // Hit checking any point should not hit the touch handler region on the | 1335 // Hit checking any point should not hit the touch handler region on the |
1361 // layer. If the invertible matrix is accidentally ignored and treated like an | 1336 // layer. If the invertible matrix is accidentally ignored and treated like an |
1362 // identity, then the hit testing will incorrectly hit the layer when it | 1337 // identity, then the hit testing will incorrectly hit the layer when it |
1363 // shouldn't. | 1338 // shouldn't. |
(...skipping 1037 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2401 auto weak_promise = promise->AsWeakPtr(); | 2376 auto weak_promise = promise->AsWeakPtr(); |
2402 host_impl().active_tree()->QueueSwapPromise(std::move(promise)); | 2377 host_impl().active_tree()->QueueSwapPromise(std::move(promise)); |
2403 host_impl().active_tree()->BreakSwapPromises( | 2378 host_impl().active_tree()->BreakSwapPromises( |
2404 SwapPromise::DidNotSwapReason::SWAP_FAILS); | 2379 SwapPromise::DidNotSwapReason::SWAP_FAILS); |
2405 EXPECT_FALSE(weak_promise); | 2380 EXPECT_FALSE(weak_promise); |
2406 } | 2381 } |
2407 } | 2382 } |
2408 | 2383 |
2409 } // namespace | 2384 } // namespace |
2410 } // namespace cc | 2385 } // namespace cc |
OLD | NEW |