| 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/layers/texture_layer.h" | 5 #include "cc/layers/texture_layer.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 // will be returned inside the commit that replaces them. | 647 // will be returned inside the commit that replaces them. |
| 648 bool force_disable_reclaim_resources = false; | 648 bool force_disable_reclaim_resources = false; |
| 649 return base::MakeUnique<TestCompositorFrameSink>( | 649 return base::MakeUnique<TestCompositorFrameSink>( |
| 650 compositor_context_provider, std::move(worker_context_provider), | 650 compositor_context_provider, std::move(worker_context_provider), |
| 651 shared_bitmap_manager(), gpu_memory_buffer_manager(), | 651 shared_bitmap_manager(), gpu_memory_buffer_manager(), |
| 652 layer_tree_host()->GetSettings().renderer_settings, | 652 layer_tree_host()->GetSettings().renderer_settings, |
| 653 ImplThreadTaskRunner(), synchronous_composite, | 653 ImplThreadTaskRunner(), synchronous_composite, |
| 654 force_disable_reclaim_resources); | 654 force_disable_reclaim_resources); |
| 655 } | 655 } |
| 656 | 656 |
| 657 void AdvanceTestCase() { |
| 658 ++test_case_; |
| 659 switch (test_case_) { |
| 660 case 1: |
| 661 // Case #1: change mailbox before the commit. The old mailbox should be |
| 662 // released immediately. |
| 663 SetMailbox('2'); |
| 664 EXPECT_EQ(1, callback_count_); |
| 665 PostSetNeedsCommitToMainThread(); |
| 666 |
| 667 // Case 2 does not rely on callbacks to advance. |
| 668 pending_callback_ = false; |
| 669 break; |
| 670 case 2: |
| 671 // Case #2: change mailbox after the commit (and draw), where the |
| 672 // layer draws. The old mailbox should be released during the next |
| 673 // commit. |
| 674 SetMailbox('3'); |
| 675 EXPECT_EQ(1, callback_count_); |
| 676 |
| 677 // Cases 3-5 rely on a callback to advance. |
| 678 pending_callback_ = true; |
| 679 break; |
| 680 case 3: |
| 681 EXPECT_EQ(2, callback_count_); |
| 682 // Case #3: change mailbox when the layer doesn't draw. The old |
| 683 // mailbox should be released during the next commit. |
| 684 layer_->SetBounds(gfx::Size()); |
| 685 SetMailbox('4'); |
| 686 break; |
| 687 case 4: |
| 688 EXPECT_EQ(3, callback_count_); |
| 689 // Case #4: release mailbox that was committed but never drawn. The |
| 690 // old mailbox should be released during the next commit. |
| 691 layer_->SetTextureMailbox(TextureMailbox(), nullptr); |
| 692 break; |
| 693 case 5: |
| 694 EXPECT_EQ(4, callback_count_); |
| 695 // Restore a mailbox for the next step. |
| 696 SetMailbox('5'); |
| 697 |
| 698 // Cases 6 and 7 do not rely on callbacks to advance. |
| 699 pending_callback_ = false; |
| 700 break; |
| 701 case 6: |
| 702 // Case #5: remove layer from tree. Callback should *not* be called, the |
| 703 // mailbox is returned to the main thread. |
| 704 EXPECT_EQ(4, callback_count_); |
| 705 layer_->RemoveFromParent(); |
| 706 break; |
| 707 case 7: |
| 708 EXPECT_EQ(4, callback_count_); |
| 709 // Resetting the mailbox will call the callback now. |
| 710 layer_->SetTextureMailbox(TextureMailbox(), nullptr); |
| 711 EXPECT_EQ(5, callback_count_); |
| 712 EndTest(); |
| 713 break; |
| 714 default: |
| 715 NOTREACHED(); |
| 716 break; |
| 717 } |
| 718 } |
| 719 |
| 657 // Make sure callback is received on main and doesn't block the impl thread. | 720 // Make sure callback is received on main and doesn't block the impl thread. |
| 658 void ReleaseCallback(char mailbox_char, | 721 void ReleaseCallback(char mailbox_char, |
| 659 const gpu::SyncToken& sync_token, | 722 const gpu::SyncToken& sync_token, |
| 660 bool lost_resource) { | 723 bool lost_resource) { |
| 661 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); | 724 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); |
| 662 EXPECT_FALSE(lost_resource); | 725 EXPECT_FALSE(lost_resource); |
| 663 ++callback_count_; | 726 ++callback_count_; |
| 727 |
| 728 // If we are waiting on a callback, advance now. |
| 729 if (pending_callback_) |
| 730 AdvanceTestCase(); |
| 664 } | 731 } |
| 665 | 732 |
| 666 void SetMailbox(char mailbox_char) { | 733 void SetMailbox(char mailbox_char) { |
| 667 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); | 734 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); |
| 668 std::unique_ptr<SingleReleaseCallback> callback = | 735 std::unique_ptr<SingleReleaseCallback> callback = |
| 669 SingleReleaseCallback::Create(base::Bind( | 736 SingleReleaseCallback::Create(base::Bind( |
| 670 &TextureLayerImplWithMailboxThreadedCallback::ReleaseCallback, | 737 &TextureLayerImplWithMailboxThreadedCallback::ReleaseCallback, |
| 671 base::Unretained(this), mailbox_char)); | 738 base::Unretained(this), mailbox_char)); |
| 672 layer_->SetTextureMailbox( | 739 layer_->SetTextureMailbox( |
| 673 TextureMailbox(MailboxFromChar(mailbox_char), | 740 TextureMailbox(MailboxFromChar(mailbox_char), |
| (...skipping 15 matching lines...) Expand all Loading... |
| 689 layer_ = TextureLayer::CreateForMailbox(nullptr); | 756 layer_ = TextureLayer::CreateForMailbox(nullptr); |
| 690 layer_->SetIsDrawable(true); | 757 layer_->SetIsDrawable(true); |
| 691 layer_->SetBounds(bounds); | 758 layer_->SetBounds(bounds); |
| 692 | 759 |
| 693 root_->AddChild(layer_); | 760 root_->AddChild(layer_); |
| 694 layer_tree()->SetRootLayer(root_); | 761 layer_tree()->SetRootLayer(root_); |
| 695 layer_tree()->SetViewportSize(bounds); | 762 layer_tree()->SetViewportSize(bounds); |
| 696 SetMailbox('1'); | 763 SetMailbox('1'); |
| 697 EXPECT_EQ(0, callback_count_); | 764 EXPECT_EQ(0, callback_count_); |
| 698 | 765 |
| 699 // Case #1: change mailbox before the commit. The old mailbox should be | 766 // Setup is complete - advance to test case 1. |
| 700 // released immediately. | 767 AdvanceTestCase(); |
| 701 SetMailbox('2'); | |
| 702 EXPECT_EQ(1, callback_count_); | |
| 703 PostSetNeedsCommitToMainThread(); | |
| 704 } | 768 } |
| 705 | 769 |
| 706 void DidCommit() override { | 770 void DidCommit() override { |
| 707 ++commit_count_; | 771 // If we are not waiting on a callback, advance now. |
| 708 switch (commit_count_) { | 772 if (!pending_callback_) |
| 709 case 1: | 773 AdvanceTestCase(); |
| 710 // Case #2: change mailbox after the commit (and draw), where the | |
| 711 // layer draws. The old mailbox should be released during the next | |
| 712 // commit. | |
| 713 SetMailbox('3'); | |
| 714 EXPECT_EQ(1, callback_count_); | |
| 715 break; | |
| 716 case 2: | |
| 717 EXPECT_EQ(2, callback_count_); | |
| 718 // Case #3: change mailbox when the layer doesn't draw. The old | |
| 719 // mailbox should be released during the next commit. | |
| 720 layer_->SetBounds(gfx::Size()); | |
| 721 SetMailbox('4'); | |
| 722 break; | |
| 723 case 3: | |
| 724 EXPECT_EQ(3, callback_count_); | |
| 725 // Case #4: release mailbox that was committed but never drawn. The | |
| 726 // old mailbox should be released during the next commit. | |
| 727 layer_->SetTextureMailbox(TextureMailbox(), nullptr); | |
| 728 break; | |
| 729 case 4: | |
| 730 EXPECT_EQ(4, callback_count_); | |
| 731 // Restore a mailbox for the next step. | |
| 732 SetMailbox('5'); | |
| 733 break; | |
| 734 case 5: | |
| 735 // Case #5: remove layer from tree. Callback should *not* be called, the | |
| 736 // mailbox is returned to the main thread. | |
| 737 EXPECT_EQ(4, callback_count_); | |
| 738 layer_->RemoveFromParent(); | |
| 739 break; | |
| 740 case 6: | |
| 741 EXPECT_EQ(4, callback_count_); | |
| 742 // Resetting the mailbox will call the callback now. | |
| 743 layer_->SetTextureMailbox(TextureMailbox(), nullptr); | |
| 744 EXPECT_EQ(5, callback_count_); | |
| 745 EndTest(); | |
| 746 break; | |
| 747 default: | |
| 748 NOTREACHED(); | |
| 749 break; | |
| 750 } | |
| 751 } | 774 } |
| 752 | 775 |
| 753 void AfterTest() override {} | 776 void AfterTest() override {} |
| 754 | 777 |
| 755 private: | 778 private: |
| 756 base::ThreadChecker main_thread_; | 779 base::ThreadChecker main_thread_; |
| 757 int callback_count_ = 0; | 780 int callback_count_ = 0; |
| 758 int commit_count_ = 0; | 781 int test_case_ = 0; |
| 782 // Whether we are waiting on a callback to advance the test case. |
| 783 bool pending_callback_ = false; |
| 759 scoped_refptr<Layer> root_; | 784 scoped_refptr<Layer> root_; |
| 760 scoped_refptr<TextureLayer> layer_; | 785 scoped_refptr<TextureLayer> layer_; |
| 761 }; | 786 }; |
| 762 | 787 |
| 763 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerImplWithMailboxThreadedCallback); | 788 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerImplWithMailboxThreadedCallback); |
| 764 | 789 |
| 765 class TextureLayerMailboxIsActivatedDuringCommit : public LayerTreeTest { | 790 class TextureLayerMailboxIsActivatedDuringCommit : public LayerTreeTest { |
| 766 protected: | 791 protected: |
| 767 TextureLayerMailboxIsActivatedDuringCommit() : activate_count_(0) {} | 792 TextureLayerMailboxIsActivatedDuringCommit() : activate_count_(0) {} |
| 768 | 793 |
| (...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1454 base::ThreadChecker main_thread_; | 1479 base::ThreadChecker main_thread_; |
| 1455 int callback_count_; | 1480 int callback_count_; |
| 1456 scoped_refptr<Layer> root_; | 1481 scoped_refptr<Layer> root_; |
| 1457 scoped_refptr<TextureLayer> layer_; | 1482 scoped_refptr<TextureLayer> layer_; |
| 1458 }; | 1483 }; |
| 1459 | 1484 |
| 1460 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerWithMailboxImplThreadDeleted); | 1485 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerWithMailboxImplThreadDeleted); |
| 1461 | 1486 |
| 1462 } // namespace | 1487 } // namespace |
| 1463 } // namespace cc | 1488 } // namespace cc |
| OLD | NEW |