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 AdvancePhase() { | |
654 ++test_phase_; | |
655 switch (test_phase_) { | |
656 case 1: | |
657 // Case #2: change mailbox after the commit (and draw), where the | |
danakj
2017/01/18 20:35:03
Uh, it looks like Case #1 didn't make it, maybe u
ericrk
2017/01/18 23:18:23
Case 1 was in BeginTest - Moved it here so they're
| |
658 // layer draws. The old mailbox should be released during the next | |
659 // commit. | |
660 SetMailbox('3'); | |
661 EXPECT_EQ(1, callback_count_); | |
662 | |
663 // Phases 2-4 rely on a callback to advance. | |
664 pending_callback_ = true; | |
665 break; | |
666 case 2: | |
667 EXPECT_EQ(2, callback_count_); | |
668 // Case #3: change mailbox when the layer doesn't draw. The old | |
669 // mailbox should be released during the next commit. | |
670 layer_->SetBounds(gfx::Size()); | |
671 SetMailbox('4'); | |
672 break; | |
673 case 3: | |
674 EXPECT_EQ(3, callback_count_); | |
675 // Case #4: release mailbox that was committed but never drawn. The | |
676 // old mailbox should be released during the next commit. | |
677 layer_->SetTextureMailbox(TextureMailbox(), nullptr); | |
678 break; | |
679 case 4: | |
680 EXPECT_EQ(4, callback_count_); | |
681 // Restore a mailbox for the next step. | |
682 SetMailbox('5'); | |
683 | |
684 // Phases 5 and 6 do not rely on callbacks to advance. | |
685 pending_callback_ = false; | |
686 break; | |
687 case 5: | |
688 // Case #5: remove layer from tree. Callback should *not* be called, the | |
689 // mailbox is returned to the main thread. | |
690 EXPECT_EQ(4, callback_count_); | |
691 layer_->RemoveFromParent(); | |
692 break; | |
693 case 6: | |
694 EXPECT_EQ(4, callback_count_); | |
695 // Resetting the mailbox will call the callback now. | |
696 layer_->SetTextureMailbox(TextureMailbox(), nullptr); | |
697 EXPECT_EQ(5, callback_count_); | |
698 EndTest(); | |
699 break; | |
700 default: | |
701 NOTREACHED(); | |
702 break; | |
703 } | |
655 } | 704 } |
656 | 705 |
657 // Make sure callback is received on main and doesn't block the impl thread. | 706 // Make sure callback is received on main and doesn't block the impl thread. |
658 void ReleaseCallback(char mailbox_char, | 707 void ReleaseCallback(char mailbox_char, |
659 const gpu::SyncToken& sync_token, | 708 const gpu::SyncToken& sync_token, |
660 bool lost_resource) { | 709 bool lost_resource) { |
661 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); | 710 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); |
662 EXPECT_FALSE(lost_resource); | 711 EXPECT_FALSE(lost_resource); |
663 ++callback_count_; | 712 ++callback_count_; |
713 | |
714 // If we are waiting on a callback, advance now. | |
715 if (pending_callback_) | |
716 AdvancePhase(); | |
664 } | 717 } |
665 | 718 |
666 void SetMailbox(char mailbox_char) { | 719 void SetMailbox(char mailbox_char) { |
667 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); | 720 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); |
668 std::unique_ptr<SingleReleaseCallback> callback = | 721 std::unique_ptr<SingleReleaseCallback> callback = |
669 SingleReleaseCallback::Create(base::Bind( | 722 SingleReleaseCallback::Create(base::Bind( |
670 &TextureLayerImplWithMailboxThreadedCallback::ReleaseCallback, | 723 &TextureLayerImplWithMailboxThreadedCallback::ReleaseCallback, |
671 base::Unretained(this), mailbox_char)); | 724 base::Unretained(this), mailbox_char)); |
672 layer_->SetTextureMailbox( | 725 layer_->SetTextureMailbox( |
673 TextureMailbox(MailboxFromChar(mailbox_char), | 726 TextureMailbox(MailboxFromChar(mailbox_char), |
(...skipping 23 matching lines...) Expand all Loading... | |
697 EXPECT_EQ(0, callback_count_); | 750 EXPECT_EQ(0, callback_count_); |
698 | 751 |
699 // Case #1: change mailbox before the commit. The old mailbox should be | 752 // Case #1: change mailbox before the commit. The old mailbox should be |
700 // released immediately. | 753 // released immediately. |
701 SetMailbox('2'); | 754 SetMailbox('2'); |
702 EXPECT_EQ(1, callback_count_); | 755 EXPECT_EQ(1, callback_count_); |
703 PostSetNeedsCommitToMainThread(); | 756 PostSetNeedsCommitToMainThread(); |
704 } | 757 } |
705 | 758 |
706 void DidCommit() override { | 759 void DidCommit() override { |
707 ++commit_count_; | 760 // If we are not waiting on a callback, advance now. |
708 switch (commit_count_) { | 761 if (!pending_callback_) |
709 case 1: | 762 AdvancePhase(); |
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 } | 763 } |
752 | 764 |
753 void AfterTest() override {} | 765 void AfterTest() override {} |
754 | 766 |
755 private: | 767 private: |
756 base::ThreadChecker main_thread_; | 768 base::ThreadChecker main_thread_; |
757 int callback_count_ = 0; | 769 int callback_count_ = 0; |
758 int commit_count_ = 0; | 770 int test_phase_ = 0; |
771 // Whether we are waiting on a callback to advance the test phase. | |
772 bool pending_callback_ = false; | |
759 scoped_refptr<Layer> root_; | 773 scoped_refptr<Layer> root_; |
760 scoped_refptr<TextureLayer> layer_; | 774 scoped_refptr<TextureLayer> layer_; |
761 }; | 775 }; |
762 | 776 |
763 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerImplWithMailboxThreadedCallback); | 777 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerImplWithMailboxThreadedCallback); |
764 | 778 |
765 class TextureLayerMailboxIsActivatedDuringCommit : public LayerTreeTest { | 779 class TextureLayerMailboxIsActivatedDuringCommit : public LayerTreeTest { |
766 protected: | 780 protected: |
767 TextureLayerMailboxIsActivatedDuringCommit() : activate_count_(0) {} | 781 TextureLayerMailboxIsActivatedDuringCommit() : activate_count_(0) {} |
768 | 782 |
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1454 base::ThreadChecker main_thread_; | 1468 base::ThreadChecker main_thread_; |
1455 int callback_count_; | 1469 int callback_count_; |
1456 scoped_refptr<Layer> root_; | 1470 scoped_refptr<Layer> root_; |
1457 scoped_refptr<TextureLayer> layer_; | 1471 scoped_refptr<TextureLayer> layer_; |
1458 }; | 1472 }; |
1459 | 1473 |
1460 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerWithMailboxImplThreadDeleted); | 1474 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerWithMailboxImplThreadDeleted); |
1461 | 1475 |
1462 } // namespace | 1476 } // namespace |
1463 } // namespace cc | 1477 } // namespace cc |
OLD | NEW |