OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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.h" | 5 #include "cc/trees/layer_tree_host.h" |
6 | 6 |
7 #include "cc/layers/layer.h" | 7 #include "cc/layers/layer.h" |
8 #include "cc/output/copy_output_request.h" | 8 #include "cc/output/copy_output_request.h" |
9 #include "cc/output/copy_output_result.h" | 9 #include "cc/output/copy_output_result.h" |
10 #include "cc/test/layer_tree_test.h" | 10 #include "cc/test/layer_tree_test.h" |
11 #include "cc/test/test_occlusion_tracker.h" | 11 #include "cc/test/test_occlusion_tracker.h" |
12 | 12 |
13 namespace cc { | 13 namespace cc { |
14 namespace { | 14 namespace { |
15 | 15 |
16 class TestLayer : public Layer { | 16 class TestLayer : public Layer { |
17 public: | 17 public: |
18 static scoped_refptr<TestLayer> Create() { | 18 static scoped_refptr<TestLayer> Create() { |
19 return make_scoped_refptr(new TestLayer()); | 19 return make_scoped_refptr(new TestLayer()); |
20 } | 20 } |
21 | 21 |
22 virtual bool Update(ResourceUpdateQueue* update_queue, | 22 virtual bool Update(ResourceUpdateQueue* update_queue, |
23 const OcclusionTracker<Layer>* occlusion) OVERRIDE { | 23 const OcclusionTracker<Layer>* occlusion) OVERRIDE { |
24 if (!occlusion) | 24 if (!occlusion) |
25 return false; | 25 return false; |
26 | 26 |
27 // Gain access to internals of the OcclusionTracker. | |
28 const TestOcclusionTracker<Layer>* test_occlusion = | 27 const TestOcclusionTracker<Layer>* test_occlusion = |
29 static_cast<const TestOcclusionTracker<Layer>*>(occlusion); | 28 static_cast<const TestOcclusionTracker<Layer>*>(occlusion); |
30 occlusion_ = UnionRegions( | 29 occlusion_ = UnionSimpleEnclosedRegions( |
31 test_occlusion->occlusion_from_inside_target(), | 30 test_occlusion->occlusion_from_inside_target(), |
32 test_occlusion->occlusion_from_outside_target()); | 31 test_occlusion->occlusion_from_outside_target()); |
33 return false; | 32 return false; |
34 } | 33 } |
35 | 34 |
36 const Region& occlusion() const { return occlusion_; } | 35 const SimpleEnclosedRegion& occlusion() const { return occlusion_; } |
37 const Region& expected_occlusion() const { return expected_occlusion_; } | 36 const SimpleEnclosedRegion& expected_occlusion() const { |
38 void set_expected_occlusion(const Region& occlusion) { | 37 return expected_occlusion_; |
39 expected_occlusion_ = occlusion; | 38 } |
| 39 void set_expected_occlusion(const gfx::Rect& occlusion) { |
| 40 expected_occlusion_ = SimpleEnclosedRegion(occlusion); |
40 } | 41 } |
41 | 42 |
42 private: | 43 private: |
43 TestLayer() : Layer() { | 44 TestLayer() : Layer() { |
44 SetIsDrawable(true); | 45 SetIsDrawable(true); |
45 } | 46 } |
46 virtual ~TestLayer() {} | 47 virtual ~TestLayer() {} |
47 | 48 |
48 Region occlusion_; | 49 SimpleEnclosedRegion occlusion_; |
49 Region expected_occlusion_; | 50 SimpleEnclosedRegion expected_occlusion_; |
50 }; | 51 }; |
51 | 52 |
52 class LayerTreeHostOcclusionTest : public LayerTreeTest { | 53 class LayerTreeHostOcclusionTest : public LayerTreeTest { |
53 public: | 54 public: |
54 LayerTreeHostOcclusionTest() | 55 LayerTreeHostOcclusionTest() |
55 : root_(TestLayer::Create()), | 56 : root_(TestLayer::Create()), |
56 child_(TestLayer::Create()), | 57 child_(TestLayer::Create()), |
57 child2_(TestLayer::Create()), | 58 child2_(TestLayer::Create()), |
58 grand_child_(TestLayer::Create()), | 59 grand_child_(TestLayer::Create()), |
59 mask_(TestLayer::Create()) { | 60 mask_(TestLayer::Create()) { |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 } | 409 } |
409 }; | 410 }; |
410 | 411 |
411 SINGLE_AND_MULTI_THREAD_TEST_F( | 412 SINGLE_AND_MULTI_THREAD_TEST_F( |
412 LayerTreeHostOcclusionTestOcclusionBlendingBelowOcclusion); | 413 LayerTreeHostOcclusionTestOcclusionBlendingBelowOcclusion); |
413 | 414 |
414 class LayerTreeHostOcclusionTestOcclusionOpacityFilter | 415 class LayerTreeHostOcclusionTestOcclusionOpacityFilter |
415 : public LayerTreeHostOcclusionTest { | 416 : public LayerTreeHostOcclusionTest { |
416 public: | 417 public: |
417 virtual void SetupTree() OVERRIDE { | 418 virtual void SetupTree() OVERRIDE { |
418 gfx::Transform child_transform; | |
419 child_transform.Translate(250.0, 250.0); | |
420 child_transform.Rotate(90.0); | |
421 child_transform.Translate(-250.0, -250.0); | |
422 | |
423 FilterOperations filters; | 419 FilterOperations filters; |
424 filters.Append(FilterOperation::CreateOpacityFilter(0.5f)); | 420 filters.Append(FilterOperation::CreateOpacityFilter(0.5f)); |
425 | 421 |
426 // If the child layer has a filter that changes alpha values, and is below | 422 // If the child layer has a filter that changes alpha values, and is below |
427 // child2, then child2 should contribute to occlusion on everything, | 423 // child2, then child2 should contribute to occlusion on everything, |
428 // and child shouldn't contribute to the root | 424 // and child shouldn't contribute to the root |
429 SetLayerPropertiesForTesting( | 425 SetLayerPropertiesForTesting( |
430 root_.get(), NULL, identity_matrix_, | 426 root_.get(), NULL, identity_matrix_, |
431 gfx::PointF(0.f, 0.f), gfx::Size(200, 200), true); | 427 gfx::PointF(0.f, 0.f), gfx::Size(200, 200), true); |
432 SetLayerPropertiesForTesting( | 428 SetLayerPropertiesForTesting(child_.get(), |
433 child_.get(), root_.get(), child_transform, | 429 root_.get(), |
434 gfx::PointF(30.f, 30.f), gfx::Size(500, 500), true); | 430 identity_matrix_, |
435 SetLayerPropertiesForTesting( | 431 gfx::PointF(0.f, 0.f), |
436 grand_child_.get(), child_.get(), identity_matrix_, | 432 gfx::Size(500, 500), |
437 gfx::PointF(10.f, 10.f), gfx::Size(500, 500), true); | 433 true); |
438 SetLayerPropertiesForTesting( | 434 SetLayerPropertiesForTesting(grand_child_.get(), |
439 child2_.get(), root_.get(), identity_matrix_, | 435 child_.get(), |
440 gfx::PointF(10.f, 70.f), gfx::Size(500, 500), true); | 436 identity_matrix_, |
| 437 gfx::PointF(0.f, 0.f), |
| 438 gfx::Size(500, 500), |
| 439 true); |
| 440 SetLayerPropertiesForTesting(child2_.get(), |
| 441 root_.get(), |
| 442 identity_matrix_, |
| 443 gfx::PointF(10.f, 10.f), |
| 444 gfx::Size(30, 30), |
| 445 true); |
441 | 446 |
442 child_->SetMasksToBounds(true); | 447 child_->SetMasksToBounds(true); |
443 child_->SetFilters(filters); | 448 child_->SetFilters(filters); |
444 | 449 |
445 grand_child_->set_expected_occlusion(gfx::Rect(40, 330, 130, 190)); | 450 // child2_ occludes grand_child_, showing it does occlude inside child_'s |
446 child_->set_expected_occlusion(UnionRegions( | 451 // subtree. |
447 gfx::Rect(10, 330, 160, 170), gfx::Rect(40, 500, 130, 20))); | 452 grand_child_->set_expected_occlusion(gfx::Rect(10, 10, 30, 30)); |
448 root_->set_expected_occlusion(gfx::Rect(10, 70, 190, 130)); | 453 // grand_child_ occludes child_, showing there is more occlusion in |
| 454 // child_'s subtree. |
| 455 child_->set_expected_occlusion(gfx::Rect(0, 0, 200, 200)); |
| 456 // child2_'s occlusion reaches the root, but child_'s subtree does not. |
| 457 root_->set_expected_occlusion(gfx::Rect(10, 10, 30, 30)); |
449 | 458 |
450 layer_tree_host()->SetRootLayer(root_); | 459 layer_tree_host()->SetRootLayer(root_); |
451 LayerTreeTest::SetupTree(); | 460 LayerTreeTest::SetupTree(); |
452 } | 461 } |
453 }; | 462 }; |
454 | 463 |
455 SINGLE_AND_MULTI_THREAD_TEST_F( | 464 SINGLE_AND_MULTI_THREAD_TEST_F( |
456 LayerTreeHostOcclusionTestOcclusionOpacityFilter); | 465 LayerTreeHostOcclusionTestOcclusionOpacityFilter); |
457 | 466 |
458 class LayerTreeHostOcclusionTestOcclusionBlurFilter | 467 class LayerTreeHostOcclusionTestOcclusionBlurFilter |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 | 620 |
612 layer_tree_host()->SetRootLayer(layers[0]); | 621 layer_tree_host()->SetRootLayer(layers[0]); |
613 LayerTreeTest::SetupTree(); | 622 LayerTreeTest::SetupTree(); |
614 } | 623 } |
615 }; | 624 }; |
616 | 625 |
617 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostOcclusionTestManySurfaces); | 626 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostOcclusionTestManySurfaces); |
618 | 627 |
619 } // namespace | 628 } // namespace |
620 } // namespace cc | 629 } // namespace cc |
OLD | NEW |