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