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 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 result_layer = | 373 result_layer = |
374 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); | 374 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); |
375 ASSERT_FALSE(result_layer); | 375 ASSERT_FALSE(result_layer); |
376 | 376 |
377 test_point = gfx::PointF(-1.f, 50.f); | 377 test_point = gfx::PointF(-1.f, 50.f); |
378 result_layer = | 378 result_layer = |
379 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); | 379 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); |
380 ASSERT_FALSE(result_layer); | 380 ASSERT_FALSE(result_layer); |
381 } | 381 } |
382 | 382 |
| 383 TEST_F(LayerTreeImplTest, HitTestingClipNodeDifferentTransformAndTargetIds) { |
| 384 // Tests hit testing on a layer whose clip node has different transform and |
| 385 // target id. |
| 386 gfx::Transform identity_matrix; |
| 387 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl().active_tree(), 1); |
| 388 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 389 gfx::PointF(), gfx::Size(500, 500), true, false, |
| 390 true); |
| 391 gfx::Transform translation; |
| 392 translation.Translate(100, 100); |
| 393 scoped_ptr<LayerImpl> render_surface = |
| 394 LayerImpl::Create(host_impl().active_tree(), 2); |
| 395 SetLayerPropertiesForTesting(render_surface.get(), translation, |
| 396 gfx::Point3F(), gfx::PointF(), |
| 397 gfx::Size(100, 100), true, false, true); |
| 398 |
| 399 gfx::Transform scale_matrix; |
| 400 scale_matrix.Scale(2, 2); |
| 401 scoped_ptr<LayerImpl> scale = LayerImpl::Create(host_impl().active_tree(), 3); |
| 402 SetLayerPropertiesForTesting(scale.get(), scale_matrix, gfx::Point3F(), |
| 403 gfx::PointF(), gfx::Size(50, 50), true, false, |
| 404 false); |
| 405 |
| 406 scoped_ptr<LayerImpl> clip = LayerImpl::Create(host_impl().active_tree(), 4); |
| 407 SetLayerPropertiesForTesting(clip.get(), identity_matrix, gfx::Point3F(), |
| 408 gfx::PointF(), gfx::Size(25, 25), true, false, |
| 409 false); |
| 410 clip->SetMasksToBounds(true); |
| 411 |
| 412 scoped_ptr<LayerImpl> test = LayerImpl::Create(host_impl().active_tree(), 5); |
| 413 SetLayerPropertiesForTesting(test.get(), identity_matrix, gfx::Point3F(), |
| 414 gfx::PointF(), gfx::Size(100, 100), true, false, |
| 415 false); |
| 416 test->SetDrawsContent(true); |
| 417 |
| 418 clip->AddChild(std::move(test)); |
| 419 scale->AddChild(std::move(clip)); |
| 420 render_surface->AddChild(std::move(scale)); |
| 421 root->AddChild(std::move(render_surface)); |
| 422 |
| 423 host_impl().SetViewportSize(root->bounds()); |
| 424 host_impl().active_tree()->SetRootLayer(std::move(root)); |
| 425 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); |
| 426 |
| 427 gfx::PointF test_point(160.f, 160.f); |
| 428 LayerImpl* result_layer = |
| 429 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); |
| 430 EXPECT_FALSE(result_layer); |
| 431 |
| 432 test_point = gfx::PointF(140.f, 140.f); |
| 433 result_layer = |
| 434 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); |
| 435 ASSERT_TRUE(result_layer); |
| 436 EXPECT_EQ(5, result_layer->id()); |
| 437 |
| 438 ClipTree clip_tree = host_impl().active_tree()->property_trees()->clip_tree; |
| 439 ClipNode* clip_node = clip_tree.Node(result_layer->clip_tree_index()); |
| 440 EXPECT_NE(clip_node->data.transform_id, clip_node->data.target_id); |
| 441 } |
| 442 |
| 443 TEST_F(LayerTreeImplTest, HitTestingSiblings) { |
| 444 // This tests hit testing when the test point hits only one of the siblings. |
| 445 gfx::Transform identity_matrix; |
| 446 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl().active_tree(), 1); |
| 447 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 448 gfx::PointF(), gfx::Size(100, 100), true, false, |
| 449 true); |
| 450 scoped_ptr<LayerImpl> child1 = |
| 451 LayerImpl::Create(host_impl().active_tree(), 2); |
| 452 SetLayerPropertiesForTesting(child1.get(), identity_matrix, gfx::Point3F(), |
| 453 gfx::PointF(), gfx::Size(25, 25), true, false, |
| 454 false); |
| 455 child1->SetMasksToBounds(true); |
| 456 child1->SetDrawsContent(true); |
| 457 scoped_ptr<LayerImpl> child2 = |
| 458 LayerImpl::Create(host_impl().active_tree(), 3); |
| 459 SetLayerPropertiesForTesting(child2.get(), identity_matrix, gfx::Point3F(), |
| 460 gfx::PointF(), gfx::Size(75, 75), true, false, |
| 461 false); |
| 462 child2->SetMasksToBounds(true); |
| 463 child2->SetDrawsContent(true); |
| 464 root->AddChild(std::move(child1)); |
| 465 root->AddChild(std::move(child2)); |
| 466 |
| 467 host_impl().SetViewportSize(root->bounds()); |
| 468 host_impl().active_tree()->SetRootLayer(std::move(root)); |
| 469 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); |
| 470 |
| 471 gfx::PointF test_point(50.f, 50.f); |
| 472 LayerImpl* result_layer = |
| 473 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); |
| 474 ASSERT_TRUE(result_layer); |
| 475 EXPECT_EQ(3, result_layer->id()); |
| 476 } |
| 477 |
| 478 TEST_F(LayerTreeImplTest, HitTestingPointOutsideMaxTextureSize) { |
| 479 gfx::Transform identity_matrix; |
| 480 int max_texture_size = |
| 481 host_impl().active_tree()->resource_provider()->max_texture_size(); |
| 482 gfx::Size bounds(max_texture_size + 100, max_texture_size + 100); |
| 483 |
| 484 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl().active_tree(), 1); |
| 485 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 486 gfx::PointF(), bounds, true, false, true); |
| 487 |
| 488 scoped_ptr<LayerImpl> surface = |
| 489 LayerImpl::Create(host_impl().active_tree(), 2); |
| 490 SetLayerPropertiesForTesting(surface.get(), identity_matrix, gfx::Point3F(), |
| 491 gfx::PointF(), bounds, true, false, true); |
| 492 surface->SetMasksToBounds(true); |
| 493 surface->SetDrawsContent(true); |
| 494 |
| 495 root->AddChild(std::move(surface)); |
| 496 host_impl().SetViewportSize(root->bounds()); |
| 497 host_impl().active_tree()->SetRootLayer(std::move(root)); |
| 498 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); |
| 499 |
| 500 gfx::PointF test_point(max_texture_size - 50, max_texture_size - 50); |
| 501 LayerImpl* result_layer = |
| 502 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); |
| 503 EXPECT_TRUE(result_layer); |
| 504 |
| 505 test_point = gfx::PointF(max_texture_size + 50, max_texture_size + 50); |
| 506 result_layer = |
| 507 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); |
| 508 EXPECT_FALSE(result_layer); |
| 509 } |
| 510 |
383 TEST_F(LayerTreeImplTest, HitTestingForSinglePerspectiveLayer) { | 511 TEST_F(LayerTreeImplTest, HitTestingForSinglePerspectiveLayer) { |
384 scoped_ptr<LayerImpl> root = | 512 scoped_ptr<LayerImpl> root = |
385 LayerImpl::Create(host_impl().active_tree(), 12345); | 513 LayerImpl::Create(host_impl().active_tree(), 12345); |
386 | 514 |
387 gfx::Transform identity_matrix; | 515 gfx::Transform identity_matrix; |
388 | 516 |
389 // perspective_projection_about_center * translation_by_z is designed so that | 517 // perspective_projection_about_center * translation_by_z is designed so that |
390 // the 100 x 100 layer becomes 50 x 50, and remains centered at (50, 50). | 518 // the 100 x 100 layer becomes 50 x 50, and remains centered at (50, 50). |
391 gfx::Transform perspective_projection_about_center; | 519 gfx::Transform perspective_projection_about_center; |
392 perspective_projection_about_center.Translate(50.0, 50.0); | 520 perspective_projection_about_center.Translate(50.0, 50.0); |
(...skipping 1844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2237 EXPECT_EQ(0u, host_impl().active_tree()->NumLayers()); | 2365 EXPECT_EQ(0u, host_impl().active_tree()->NumLayers()); |
2238 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl().active_tree(), 1); | 2366 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl().active_tree(), 1); |
2239 root->AddChild(LayerImpl::Create(host_impl().active_tree(), 2)); | 2367 root->AddChild(LayerImpl::Create(host_impl().active_tree(), 2)); |
2240 root->AddChild(LayerImpl::Create(host_impl().active_tree(), 3)); | 2368 root->AddChild(LayerImpl::Create(host_impl().active_tree(), 3)); |
2241 root->child_at(1)->AddChild(LayerImpl::Create(host_impl().active_tree(), 4)); | 2369 root->child_at(1)->AddChild(LayerImpl::Create(host_impl().active_tree(), 4)); |
2242 EXPECT_EQ(4u, host_impl().active_tree()->NumLayers()); | 2370 EXPECT_EQ(4u, host_impl().active_tree()->NumLayers()); |
2243 } | 2371 } |
2244 | 2372 |
2245 } // namespace | 2373 } // namespace |
2246 } // namespace cc | 2374 } // namespace cc |
OLD | NEW |