Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: cc/trees/layer_tree_host_unittest_copyrequest.cc

Issue 1985973002: Defer compositor context creation to the thread. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: contextfactory: . Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "cc/layers/layer_iterator.h" 8 #include "cc/layers/layer_iterator.h"
9 #include "cc/output/copy_output_request.h" 9 #include "cc/output/copy_output_request.h"
10 #include "cc/output/copy_output_result.h" 10 #include "cc/output/copy_output_result.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 callbacks_[id] = result->size(); 121 callbacks_[id] = result->size();
122 } 122 }
123 123
124 void AfterTest() override { EXPECT_EQ(4u, callbacks_.size()); } 124 void AfterTest() override { EXPECT_EQ(4u, callbacks_.size()); }
125 125
126 std::unique_ptr<FakeOutputSurface> CreateFakeOutputSurface() override { 126 std::unique_ptr<FakeOutputSurface> CreateFakeOutputSurface() override {
127 if (!use_gl_renderer_) { 127 if (!use_gl_renderer_) {
128 return FakeOutputSurface::CreateSoftware( 128 return FakeOutputSurface::CreateSoftware(
129 base::WrapUnique(new SoftwareOutputDevice)); 129 base::WrapUnique(new SoftwareOutputDevice));
130 } 130 }
131 std::unique_ptr<FakeOutputSurface> output_surface = 131 return FakeOutputSurface::Create3d(
132 FakeOutputSurface::Create3d(); 132 base::MakeUnique<TestContextProvider::Factory>());
133 TestContextSupport* context_support = static_cast<TestContextSupport*>( 133 }
134 output_surface->context_provider()->ContextSupport()); 134
135 context_support->set_out_of_order_callbacks(out_of_order_callbacks_); 135 void InitializedRendererOnThread(LayerTreeHostImpl* impl,
136 return output_surface; 136 bool success) override {
137 ASSERT_TRUE(success);
138 if (use_gl_renderer_) {
139 auto* context_provider = static_cast<TestContextProvider*>(
140 impl->output_surface()->context_provider());
141 context_provider->support()->set_out_of_order_callbacks(
142 out_of_order_callbacks_);
143 }
137 } 144 }
138 145
139 bool use_gl_renderer_; 146 bool use_gl_renderer_;
140 bool out_of_order_callbacks_ = false; 147 bool out_of_order_callbacks_ = false;
141 std::map<size_t, gfx::Size> callbacks_; 148 std::map<size_t, gfx::Size> callbacks_;
142 FakeContentLayerClient client_; 149 FakeContentLayerClient client_;
143 scoped_refptr<FakePictureLayer> root; 150 scoped_refptr<FakePictureLayer> root;
144 scoped_refptr<FakePictureLayer> child; 151 scoped_refptr<FakePictureLayer> child;
145 scoped_refptr<FakePictureLayer> grand_child; 152 scoped_refptr<FakePictureLayer> grand_child;
146 }; 153 };
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 }; 707 };
701 708
702 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( 709 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(
703 LayerTreeHostTestAsyncTwoReadbacksWithoutDraw); 710 LayerTreeHostTestAsyncTwoReadbacksWithoutDraw);
704 711
705 class LayerTreeHostCopyRequestTestLostOutputSurface 712 class LayerTreeHostCopyRequestTestLostOutputSurface
706 : public LayerTreeHostCopyRequestTest { 713 : public LayerTreeHostCopyRequestTest {
707 protected: 714 protected:
708 std::unique_ptr<FakeOutputSurface> CreateFakeOutputSurface() override { 715 std::unique_ptr<FakeOutputSurface> CreateFakeOutputSurface() override {
709 if (!first_context_provider_) { 716 if (!first_context_provider_) {
710 first_context_provider_ = TestContextProvider::Create(); 717 return FakeOutputSurface::Create3d(
711 return FakeOutputSurface::Create3d(first_context_provider_); 718 base::MakeUnique<TestContextProvider::Factory>());
712 } 719 }
720 EXPECT_FALSE(second_context_provider_);
721 return FakeOutputSurface::Create3d(
722 base::MakeUnique<TestContextProvider::Factory>());
723 }
713 724
714 EXPECT_FALSE(second_context_provider_); 725 void InitializedRendererOnThread(LayerTreeHostImpl* impl,
715 second_context_provider_ = TestContextProvider::Create(); 726 bool success) override {
716 return FakeOutputSurface::Create3d(second_context_provider_); 727 ASSERT_TRUE(success);
728 if (!first_context_provider_) {
729 first_context_provider_ = static_cast<TestContextProvider*>(
730 impl->output_surface()->context_provider());
731 } else {
732 second_context_provider_ = static_cast<TestContextProvider*>(
733 impl->output_surface()->context_provider());
734 }
717 } 735 }
718 736
719 void SetupTree() override { 737 void SetupTree() override {
720 root_ = FakePictureLayer::Create(&client_); 738 root_ = FakePictureLayer::Create(&client_);
721 root_->SetBounds(gfx::Size(20, 20)); 739 root_->SetBounds(gfx::Size(20, 20));
722 740
723 copy_layer_ = FakePictureLayer::Create(&client_); 741 copy_layer_ = FakePictureLayer::Create(&client_);
724 copy_layer_->SetBounds(gfx::Size(10, 10)); 742 copy_layer_->SetBounds(gfx::Size(10, 10));
725 root_->AddChild(copy_layer_); 743 root_->AddChild(copy_layer_);
726 744
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 FROM_HERE, base::Bind(&LayerTreeHostCopyRequestTestLostOutputSurface:: 778 FROM_HERE, base::Bind(&LayerTreeHostCopyRequestTestLostOutputSurface::
761 CheckNumTexturesAfterReadbackDestroyed, 779 CheckNumTexturesAfterReadbackDestroyed,
762 base::Unretained(this))); 780 base::Unretained(this)));
763 } 781 }
764 782
765 void CheckNumTexturesAfterReadbackDestroyed() { 783 void CheckNumTexturesAfterReadbackDestroyed() {
766 // After the loss we had |num_textures_after_loss_| many textures, but 784 // After the loss we had |num_textures_after_loss_| many textures, but
767 // releasing the copy output request will cause the texture in the request 785 // releasing the copy output request will cause the texture in the request
768 // to be released, so we should have 1 less by now. 786 // to be released, so we should have 1 less by now.
769 EXPECT_EQ(num_textures_after_loss_ - 1, 787 EXPECT_EQ(num_textures_after_loss_ - 1,
770 first_context_provider_->TestContext3d()->NumTextures()); 788 saved_first_context_provider_->TestContext3d()->NumTextures());
789 // Drop the saved reference on the compositor thread.
790 saved_first_context_provider_ = nullptr;
771 EndTest(); 791 EndTest();
772 } 792 }
773 793
774 void SwapBuffersOnThread(LayerTreeHostImpl* impl, bool result) override { 794 void SwapBuffersOnThread(LayerTreeHostImpl* impl, bool result) override {
775 switch (impl->active_tree()->source_frame_number()) { 795 switch (impl->active_tree()->source_frame_number()) {
776 case 0: 796 case 0:
797 EXPECT_TRUE(first_context_provider_);
798 EXPECT_FALSE(second_context_provider_);
799
777 // The layers have been drawn, so their textures have been allocated. 800 // The layers have been drawn, so their textures have been allocated.
778 EXPECT_FALSE(result_); 801 EXPECT_FALSE(result_);
779 num_textures_without_readback_ = 802 num_textures_without_readback_ =
780 first_context_provider_->TestContext3d()->NumTextures(); 803 first_context_provider_->TestContext3d()->NumTextures();
781 804
782 // Request a copy of the layer. This will use another texture. 805 // Request a copy of the layer. This will use another texture.
783 MainThreadTaskRunner()->PostTask( 806 MainThreadTaskRunner()->PostTask(
784 FROM_HERE, 807 FROM_HERE,
785 base::Bind(&LayerTreeHostCopyRequestTestLostOutputSurface:: 808 base::Bind(&LayerTreeHostCopyRequestTestLostOutputSurface::
786 InsertCopyRequest, 809 InsertCopyRequest,
787 base::Unretained(this))); 810 base::Unretained(this)));
788 break; 811 break;
789 case 1: 812 case 1:
813 EXPECT_TRUE(first_context_provider_);
814 EXPECT_FALSE(second_context_provider_);
815
790 // We did a readback, so there will be a readback texture around now. 816 // We did a readback, so there will be a readback texture around now.
791 EXPECT_LT(num_textures_without_readback_, 817 EXPECT_LT(num_textures_without_readback_,
792 first_context_provider_->TestContext3d()->NumTextures()); 818 first_context_provider_->TestContext3d()->NumTextures());
793 819
794 // The copy request will be serviced and the result sent to 820 // The copy request will be serviced and the result sent to
795 // ReceiveCopyRequestOutputAndCommit, which posts a new commit causing 821 // ReceiveCopyRequestOutputAndCommit, which posts a new commit causing
796 // the test to advance to the next case. 822 // the test to advance to the next case.
797 break; 823 break;
798 case 2: 824 case 2:
825 EXPECT_TRUE(first_context_provider_);
826 EXPECT_FALSE(second_context_provider_);
827
799 // The readback texture is collected. 828 // The readback texture is collected.
800 EXPECT_TRUE(result_); 829 EXPECT_TRUE(result_);
801 830
831 saved_first_context_provider_ =
832 make_scoped_refptr(first_context_provider_);
833
802 // Lose the output surface. 834 // Lose the output surface.
803 first_context_provider_->TestContext3d()->loseContextCHROMIUM( 835 first_context_provider_->TestContext3d()->loseContextCHROMIUM(
804 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB); 836 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB);
805 break; 837 break;
806 case 3: 838 case 3:
807 // The output surface has been recreated. 839 // The output surface has been recreated.
808 EXPECT_TRUE(second_context_provider_); 840 EXPECT_TRUE(second_context_provider_);
809 841
810 num_textures_after_loss_ = 842 num_textures_after_loss_ =
811 first_context_provider_->TestContext3d()->NumTextures(); 843 saved_first_context_provider_->TestContext3d()->NumTextures();
812 844
813 // Now destroy the CopyOutputResult, releasing the texture inside back 845 // Now destroy the CopyOutputResult, releasing the texture inside back
814 // to the compositor. Then check the resulting number of allocated 846 // to the compositor. Then check the resulting number of allocated
815 // textures. 847 // textures.
816 MainThreadTaskRunner()->PostTask( 848 MainThreadTaskRunner()->PostTask(
817 FROM_HERE, 849 FROM_HERE,
818 base::Bind(&LayerTreeHostCopyRequestTestLostOutputSurface:: 850 base::Bind(&LayerTreeHostCopyRequestTestLostOutputSurface::
819 DestroyCopyResultAndCheckNumTextures, 851 DestroyCopyResultAndCheckNumTextures,
820 base::Unretained(this))); 852 base::Unretained(this)));
821 break; 853 break;
822 } 854 }
823 } 855 }
824 856
825 void AfterTest() override {} 857 void AfterTest() override {}
826 858
827 scoped_refptr<TestContextProvider> first_context_provider_; 859 TestContextProvider* first_context_provider_ = nullptr;
828 scoped_refptr<TestContextProvider> second_context_provider_; 860 TestContextProvider* second_context_provider_ = nullptr;
861 // Keep the first_context_provider_ alive past this compositor instance being
862 // done with it.
863 scoped_refptr<TestContextProvider> saved_first_context_provider_;
829 size_t num_textures_without_readback_ = 0; 864 size_t num_textures_without_readback_ = 0;
830 size_t num_textures_after_loss_ = 0; 865 size_t num_textures_after_loss_ = 0;
831 FakeContentLayerClient client_; 866 FakeContentLayerClient client_;
832 scoped_refptr<FakePictureLayer> root_; 867 scoped_refptr<FakePictureLayer> root_;
833 scoped_refptr<FakePictureLayer> copy_layer_; 868 scoped_refptr<FakePictureLayer> copy_layer_;
834 std::unique_ptr<CopyOutputResult> result_; 869 std::unique_ptr<CopyOutputResult> result_;
835 }; 870 };
836 871
837 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( 872 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(
838 LayerTreeHostCopyRequestTestLostOutputSurface); 873 LayerTreeHostCopyRequestTestLostOutputSurface);
839 874
840 class LayerTreeHostCopyRequestTestCountTextures 875 class LayerTreeHostCopyRequestTestCountTextures
841 : public LayerTreeHostCopyRequestTest { 876 : public LayerTreeHostCopyRequestTest {
842 protected: 877 protected:
843 std::unique_ptr<FakeOutputSurface> CreateFakeOutputSurface() override { 878 std::unique_ptr<FakeOutputSurface> CreateFakeOutputSurface() override {
844 context_provider_ = TestContextProvider::Create(); 879 return FakeOutputSurface::Create3d(
845 return FakeOutputSurface::Create3d(context_provider_); 880 base::MakeUnique<TestContextProvider::Factory>());
846 } 881 }
847 882
848 void SetupTree() override { 883 void SetupTree() override {
849 client_.set_fill_with_nonsolid_color(true); 884 client_.set_fill_with_nonsolid_color(true);
850 885
851 root_ = FakePictureLayer::Create(&client_); 886 root_ = FakePictureLayer::Create(&client_);
852 root_->SetBounds(gfx::Size(20, 20)); 887 root_->SetBounds(gfx::Size(20, 20));
853 888
854 copy_layer_ = FakePictureLayer::Create(&client_); 889 copy_layer_ = FakePictureLayer::Create(&client_);
855 copy_layer_->SetBounds(gfx::Size(10, 10)); 890 copy_layer_->SetBounds(gfx::Size(10, 10));
(...skipping 17 matching lines...) Expand all
873 switch (layer_tree_host()->source_frame_number()) { 908 switch (layer_tree_host()->source_frame_number()) {
874 case 1: 909 case 1:
875 // The layers have been pushed to the impl side. The layer textures have 910 // The layers have been pushed to the impl side. The layer textures have
876 // been allocated. 911 // been allocated.
877 RequestCopy(copy_layer_.get()); 912 RequestCopy(copy_layer_.get());
878 break; 913 break;
879 } 914 }
880 } 915 }
881 916
882 void SwapBuffersOnThread(LayerTreeHostImpl* impl, bool result) override { 917 void SwapBuffersOnThread(LayerTreeHostImpl* impl, bool result) override {
918 auto* context_provider = static_cast<TestContextProvider*>(
919 impl->output_surface()->context_provider());
920
883 switch (impl->active_tree()->source_frame_number()) { 921 switch (impl->active_tree()->source_frame_number()) {
884 case 0: 922 case 0:
885 // The layers have been drawn, so their textures have been allocated. 923 // The layers have been drawn, so their textures have been allocated.
886 num_textures_without_readback_ = 924 num_textures_without_readback_ =
887 context_provider_->TestContext3d()->NumTextures(); 925 context_provider->TestContext3d()->NumTextures();
888 break; 926 break;
889 case 1: 927 case 1:
890 // We did a readback, so there will be a readback texture around now. 928 // We did a readback, so there will be a readback texture around now.
891 num_textures_with_readback_ = 929 num_textures_with_readback_ =
892 context_provider_->TestContext3d()->NumTextures(); 930 context_provider->TestContext3d()->NumTextures();
893 waited_sync_token_after_readback_ = 931 waited_sync_token_after_readback_ =
894 context_provider_->TestContext3d()->last_waited_sync_token(); 932 context_provider->TestContext3d()->last_waited_sync_token();
895 933
896 MainThreadTaskRunner()->PostTask( 934 MainThreadTaskRunner()->PostTask(
897 FROM_HERE, 935 FROM_HERE,
898 base::Bind(&LayerTreeHostCopyRequestTestCountTextures::DoEndTest, 936 base::Bind(&LayerTreeHostCopyRequestTestCountTextures::DoEndTest,
899 base::Unretained(this))); 937 base::Unretained(this)));
900 break; 938 break;
901 } 939 }
902 } 940 }
903 941
904 virtual void DoEndTest() { EndTest(); } 942 virtual void DoEndTest() { EndTest(); }
905 943
906 scoped_refptr<TestContextProvider> context_provider_;
907 size_t num_textures_without_readback_; 944 size_t num_textures_without_readback_;
908 size_t num_textures_with_readback_; 945 size_t num_textures_with_readback_;
909 gpu::SyncToken waited_sync_token_after_readback_; 946 gpu::SyncToken waited_sync_token_after_readback_;
910 FakeContentLayerClient client_; 947 FakeContentLayerClient client_;
911 scoped_refptr<FakePictureLayer> root_; 948 scoped_refptr<FakePictureLayer> root_;
912 scoped_refptr<FakePictureLayer> copy_layer_; 949 scoped_refptr<FakePictureLayer> copy_layer_;
913 }; 950 };
914 951
915 class LayerTreeHostCopyRequestTestCreatesTexture 952 class LayerTreeHostCopyRequestTestCreatesTexture
916 : public LayerTreeHostCopyRequestTestCountTextures { 953 : public LayerTreeHostCopyRequestTestCountTextures {
(...skipping 27 matching lines...) Expand all
944 }; 981 };
945 982
946 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( 983 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(
947 LayerTreeHostCopyRequestTestCreatesTexture); 984 LayerTreeHostCopyRequestTestCreatesTexture);
948 985
949 class LayerTreeHostCopyRequestTestProvideTexture 986 class LayerTreeHostCopyRequestTestProvideTexture
950 : public LayerTreeHostCopyRequestTestCountTextures { 987 : public LayerTreeHostCopyRequestTestCountTextures {
951 protected: 988 protected:
952 void BeginTest() override { 989 void BeginTest() override {
953 external_context_provider_ = TestContextProvider::Create(); 990 external_context_provider_ = TestContextProvider::Create();
954 EXPECT_TRUE(external_context_provider_->BindToCurrentThread());
955 LayerTreeHostCopyRequestTestCountTextures::BeginTest(); 991 LayerTreeHostCopyRequestTestCountTextures::BeginTest();
956 } 992 }
957 993
958 void CopyOutputCallback(std::unique_ptr<CopyOutputResult> result) { 994 void CopyOutputCallback(std::unique_ptr<CopyOutputResult> result) {
959 EXPECT_FALSE(result->IsEmpty()); 995 EXPECT_FALSE(result->IsEmpty());
960 EXPECT_TRUE(result->HasTexture()); 996 EXPECT_TRUE(result->HasTexture());
961 997
962 TextureMailbox mailbox; 998 TextureMailbox mailbox;
963 std::unique_ptr<SingleReleaseCallback> release; 999 std::unique_ptr<SingleReleaseCallback> release;
964 result->TakeTexture(&mailbox, &release); 1000 result->TakeTexture(&mailbox, &release);
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
1264 int num_draws_; 1300 int num_draws_;
1265 bool copy_happened_; 1301 bool copy_happened_;
1266 bool draw_happened_; 1302 bool draw_happened_;
1267 }; 1303 };
1268 1304
1269 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( 1305 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(
1270 LayerTreeHostCopyRequestTestMultipleDrawsHiddenCopyRequest); 1306 LayerTreeHostCopyRequestTestMultipleDrawsHiddenCopyRequest);
1271 1307
1272 } // namespace 1308 } // namespace
1273 } // namespace cc 1309 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698