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

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: 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 auto create = base::MakeUnique<TestContextProvider::DeferredCreate>();
132 FakeOutputSurface::Create3d(); 132 create->created_context = &context_provider_;
133 TestContextSupport* context_support = static_cast<TestContextSupport*>( 133 return FakeOutputSurface::Create3d(std::move(create));
134 output_surface->context_provider()->ContextSupport()); 134 }
135 context_support->set_out_of_order_callbacks(out_of_order_callbacks_); 135
136 return output_surface; 136 void InitializedRendererOnThread(LayerTreeHostImpl* host_impl,
137 bool success) override {
138 ASSERT_TRUE(success);
139 if (use_gl_renderer_) {
140 context_provider_->support()->set_out_of_order_callbacks(
141 out_of_order_callbacks_);
142 }
137 } 143 }
138 144
139 bool use_gl_renderer_; 145 bool use_gl_renderer_;
140 bool out_of_order_callbacks_ = false; 146 bool out_of_order_callbacks_ = false;
147 TestContextProvider* context_provider_ = nullptr;
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 };
147 154
148 // Readback can't be done with a delegating renderer. 155 // Readback can't be done with a delegating renderer.
149 TEST_F(LayerTreeHostCopyRequestTestMultipleRequests, 156 TEST_F(LayerTreeHostCopyRequestTestMultipleRequests,
150 GLRenderer_RunSingleThread) { 157 GLRenderer_RunSingleThread) {
(...skipping 549 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 std::unique_ptr<TestContextProvider::DeferredCreate> first_create(
711 return FakeOutputSurface::Create3d(first_context_provider_); 718 new TestContextProvider::DeferredCreate);
719 first_create->created_context = &first_context_provider_;
720 return FakeOutputSurface::Create3d(std::move(first_create));
712 } 721 }
713 722
714 EXPECT_FALSE(second_context_provider_); 723 EXPECT_FALSE(second_context_provider_);
715 second_context_provider_ = TestContextProvider::Create(); 724 std::unique_ptr<TestContextProvider::DeferredCreate> second_create(
716 return FakeOutputSurface::Create3d(second_context_provider_); 725 new TestContextProvider::DeferredCreate);
726 second_create->created_context = &second_context_provider_;
727 return FakeOutputSurface::Create3d(std::move(second_create));
717 } 728 }
718 729
719 void SetupTree() override { 730 void SetupTree() override {
720 root_ = FakePictureLayer::Create(&client_); 731 root_ = FakePictureLayer::Create(&client_);
721 root_->SetBounds(gfx::Size(20, 20)); 732 root_->SetBounds(gfx::Size(20, 20));
722 733
723 copy_layer_ = FakePictureLayer::Create(&client_); 734 copy_layer_ = FakePictureLayer::Create(&client_);
724 copy_layer_->SetBounds(gfx::Size(10, 10)); 735 copy_layer_->SetBounds(gfx::Size(10, 10));
725 root_->AddChild(copy_layer_); 736 root_->AddChild(copy_layer_);
726 737
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 FROM_HERE, base::Bind(&LayerTreeHostCopyRequestTestLostOutputSurface:: 771 FROM_HERE, base::Bind(&LayerTreeHostCopyRequestTestLostOutputSurface::
761 CheckNumTexturesAfterReadbackDestroyed, 772 CheckNumTexturesAfterReadbackDestroyed,
762 base::Unretained(this))); 773 base::Unretained(this)));
763 } 774 }
764 775
765 void CheckNumTexturesAfterReadbackDestroyed() { 776 void CheckNumTexturesAfterReadbackDestroyed() {
766 // After the loss we had |num_textures_after_loss_| many textures, but 777 // 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 778 // releasing the copy output request will cause the texture in the request
768 // to be released, so we should have 1 less by now. 779 // to be released, so we should have 1 less by now.
769 EXPECT_EQ(num_textures_after_loss_ - 1, 780 EXPECT_EQ(num_textures_after_loss_ - 1,
770 first_context_provider_->TestContext3d()->NumTextures()); 781 saved_first_context_provider_->TestContext3d()->NumTextures());
782 // Drop the saved reference on the compositor thread.
783 saved_first_context_provider_ = nullptr;
771 EndTest(); 784 EndTest();
772 } 785 }
773 786
774 void SwapBuffersOnThread(LayerTreeHostImpl* impl, bool result) override { 787 void SwapBuffersOnThread(LayerTreeHostImpl* impl, bool result) override {
775 switch (impl->active_tree()->source_frame_number()) { 788 switch (impl->active_tree()->source_frame_number()) {
776 case 0: 789 case 0:
790 EXPECT_TRUE(first_context_provider_);
791 EXPECT_FALSE(second_context_provider_);
792
777 // The layers have been drawn, so their textures have been allocated. 793 // The layers have been drawn, so their textures have been allocated.
778 EXPECT_FALSE(result_); 794 EXPECT_FALSE(result_);
779 num_textures_without_readback_ = 795 num_textures_without_readback_ =
780 first_context_provider_->TestContext3d()->NumTextures(); 796 first_context_provider_->TestContext3d()->NumTextures();
781 797
782 // Request a copy of the layer. This will use another texture. 798 // Request a copy of the layer. This will use another texture.
783 MainThreadTaskRunner()->PostTask( 799 MainThreadTaskRunner()->PostTask(
784 FROM_HERE, 800 FROM_HERE,
785 base::Bind(&LayerTreeHostCopyRequestTestLostOutputSurface:: 801 base::Bind(&LayerTreeHostCopyRequestTestLostOutputSurface::
786 InsertCopyRequest, 802 InsertCopyRequest,
787 base::Unretained(this))); 803 base::Unretained(this)));
788 break; 804 break;
789 case 1: 805 case 1:
806 EXPECT_TRUE(first_context_provider_);
807 EXPECT_FALSE(second_context_provider_);
808
790 // We did a readback, so there will be a readback texture around now. 809 // We did a readback, so there will be a readback texture around now.
791 EXPECT_LT(num_textures_without_readback_, 810 EXPECT_LT(num_textures_without_readback_,
792 first_context_provider_->TestContext3d()->NumTextures()); 811 first_context_provider_->TestContext3d()->NumTextures());
793 812
794 // The copy request will be serviced and the result sent to 813 // The copy request will be serviced and the result sent to
795 // ReceiveCopyRequestOutputAndCommit, which posts a new commit causing 814 // ReceiveCopyRequestOutputAndCommit, which posts a new commit causing
796 // the test to advance to the next case. 815 // the test to advance to the next case.
797 break; 816 break;
798 case 2: 817 case 2:
818 EXPECT_TRUE(first_context_provider_);
819 EXPECT_FALSE(second_context_provider_);
820
799 // The readback texture is collected. 821 // The readback texture is collected.
800 EXPECT_TRUE(result_); 822 EXPECT_TRUE(result_);
801 823
824 saved_first_context_provider_ =
825 make_scoped_refptr(first_context_provider_);
826
802 // Lose the output surface. 827 // Lose the output surface.
803 first_context_provider_->TestContext3d()->loseContextCHROMIUM( 828 first_context_provider_->TestContext3d()->loseContextCHROMIUM(
804 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB); 829 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB);
805 break; 830 break;
806 case 3: 831 case 3:
807 // The output surface has been recreated. 832 // The output surface has been recreated.
808 EXPECT_TRUE(second_context_provider_); 833 EXPECT_TRUE(second_context_provider_);
809 834
810 num_textures_after_loss_ = 835 num_textures_after_loss_ =
811 first_context_provider_->TestContext3d()->NumTextures(); 836 saved_first_context_provider_->TestContext3d()->NumTextures();
812 837
813 // Now destroy the CopyOutputResult, releasing the texture inside back 838 // Now destroy the CopyOutputResult, releasing the texture inside back
814 // to the compositor. Then check the resulting number of allocated 839 // to the compositor. Then check the resulting number of allocated
815 // textures. 840 // textures.
816 MainThreadTaskRunner()->PostTask( 841 MainThreadTaskRunner()->PostTask(
817 FROM_HERE, 842 FROM_HERE,
818 base::Bind(&LayerTreeHostCopyRequestTestLostOutputSurface:: 843 base::Bind(&LayerTreeHostCopyRequestTestLostOutputSurface::
819 DestroyCopyResultAndCheckNumTextures, 844 DestroyCopyResultAndCheckNumTextures,
820 base::Unretained(this))); 845 base::Unretained(this)));
821 break; 846 break;
822 } 847 }
823 } 848 }
824 849
825 void AfterTest() override {} 850 void AfterTest() override {}
826 851
827 scoped_refptr<TestContextProvider> first_context_provider_; 852 TestContextProvider* first_context_provider_ = nullptr;
828 scoped_refptr<TestContextProvider> second_context_provider_; 853 TestContextProvider* second_context_provider_ = nullptr;
854 // Keep the first_context_provider_ alive past this compositor instance being
855 // done with it.
856 scoped_refptr<TestContextProvider> saved_first_context_provider_;
829 size_t num_textures_without_readback_ = 0; 857 size_t num_textures_without_readback_ = 0;
830 size_t num_textures_after_loss_ = 0; 858 size_t num_textures_after_loss_ = 0;
831 FakeContentLayerClient client_; 859 FakeContentLayerClient client_;
832 scoped_refptr<FakePictureLayer> root_; 860 scoped_refptr<FakePictureLayer> root_;
833 scoped_refptr<FakePictureLayer> copy_layer_; 861 scoped_refptr<FakePictureLayer> copy_layer_;
834 std::unique_ptr<CopyOutputResult> result_; 862 std::unique_ptr<CopyOutputResult> result_;
835 }; 863 };
836 864
837 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( 865 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(
838 LayerTreeHostCopyRequestTestLostOutputSurface); 866 LayerTreeHostCopyRequestTestLostOutputSurface);
839 867
840 class LayerTreeHostCopyRequestTestCountTextures 868 class LayerTreeHostCopyRequestTestCountTextures
841 : public LayerTreeHostCopyRequestTest { 869 : public LayerTreeHostCopyRequestTest {
842 protected: 870 protected:
843 std::unique_ptr<FakeOutputSurface> CreateFakeOutputSurface() override { 871 std::unique_ptr<FakeOutputSurface> CreateFakeOutputSurface() override {
844 context_provider_ = TestContextProvider::Create(); 872 std::unique_ptr<TestContextProvider::DeferredCreate> create(
845 return FakeOutputSurface::Create3d(context_provider_); 873 new TestContextProvider::DeferredCreate);
874 create->created_context = &context_provider_;
875 return FakeOutputSurface::Create3d(std::move(create));
846 } 876 }
847 877
848 void SetupTree() override { 878 void SetupTree() override {
849 client_.set_fill_with_nonsolid_color(true); 879 client_.set_fill_with_nonsolid_color(true);
850 880
851 root_ = FakePictureLayer::Create(&client_); 881 root_ = FakePictureLayer::Create(&client_);
852 root_->SetBounds(gfx::Size(20, 20)); 882 root_->SetBounds(gfx::Size(20, 20));
853 883
854 copy_layer_ = FakePictureLayer::Create(&client_); 884 copy_layer_ = FakePictureLayer::Create(&client_);
855 copy_layer_->SetBounds(gfx::Size(10, 10)); 885 copy_layer_->SetBounds(gfx::Size(10, 10));
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 MainThreadTaskRunner()->PostTask( 926 MainThreadTaskRunner()->PostTask(
897 FROM_HERE, 927 FROM_HERE,
898 base::Bind(&LayerTreeHostCopyRequestTestCountTextures::DoEndTest, 928 base::Bind(&LayerTreeHostCopyRequestTestCountTextures::DoEndTest,
899 base::Unretained(this))); 929 base::Unretained(this)));
900 break; 930 break;
901 } 931 }
902 } 932 }
903 933
904 virtual void DoEndTest() { EndTest(); } 934 virtual void DoEndTest() { EndTest(); }
905 935
906 scoped_refptr<TestContextProvider> context_provider_; 936 TestContextProvider* context_provider_ = nullptr;
907 size_t num_textures_without_readback_; 937 size_t num_textures_without_readback_;
908 size_t num_textures_with_readback_; 938 size_t num_textures_with_readback_;
909 gpu::SyncToken waited_sync_token_after_readback_; 939 gpu::SyncToken waited_sync_token_after_readback_;
910 FakeContentLayerClient client_; 940 FakeContentLayerClient client_;
911 scoped_refptr<FakePictureLayer> root_; 941 scoped_refptr<FakePictureLayer> root_;
912 scoped_refptr<FakePictureLayer> copy_layer_; 942 scoped_refptr<FakePictureLayer> copy_layer_;
913 }; 943 };
914 944
915 class LayerTreeHostCopyRequestTestCreatesTexture 945 class LayerTreeHostCopyRequestTestCreatesTexture
916 : public LayerTreeHostCopyRequestTestCountTextures { 946 : public LayerTreeHostCopyRequestTestCountTextures {
(...skipping 27 matching lines...) Expand all
944 }; 974 };
945 975
946 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( 976 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(
947 LayerTreeHostCopyRequestTestCreatesTexture); 977 LayerTreeHostCopyRequestTestCreatesTexture);
948 978
949 class LayerTreeHostCopyRequestTestProvideTexture 979 class LayerTreeHostCopyRequestTestProvideTexture
950 : public LayerTreeHostCopyRequestTestCountTextures { 980 : public LayerTreeHostCopyRequestTestCountTextures {
951 protected: 981 protected:
952 void BeginTest() override { 982 void BeginTest() override {
953 external_context_provider_ = TestContextProvider::Create(); 983 external_context_provider_ = TestContextProvider::Create();
954 EXPECT_TRUE(external_context_provider_->BindToCurrentThread());
955 LayerTreeHostCopyRequestTestCountTextures::BeginTest(); 984 LayerTreeHostCopyRequestTestCountTextures::BeginTest();
956 } 985 }
957 986
958 void CopyOutputCallback(std::unique_ptr<CopyOutputResult> result) { 987 void CopyOutputCallback(std::unique_ptr<CopyOutputResult> result) {
959 EXPECT_FALSE(result->IsEmpty()); 988 EXPECT_FALSE(result->IsEmpty());
960 EXPECT_TRUE(result->HasTexture()); 989 EXPECT_TRUE(result->HasTexture());
961 990
962 TextureMailbox mailbox; 991 TextureMailbox mailbox;
963 std::unique_ptr<SingleReleaseCallback> release; 992 std::unique_ptr<SingleReleaseCallback> release;
964 result->TakeTexture(&mailbox, &release); 993 result->TakeTexture(&mailbox, &release);
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
1264 int num_draws_; 1293 int num_draws_;
1265 bool copy_happened_; 1294 bool copy_happened_;
1266 bool draw_happened_; 1295 bool draw_happened_;
1267 }; 1296 };
1268 1297
1269 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( 1298 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(
1270 LayerTreeHostCopyRequestTestMultipleDrawsHiddenCopyRequest); 1299 LayerTreeHostCopyRequestTestMultipleDrawsHiddenCopyRequest);
1271 1300
1272 } // namespace 1301 } // namespace
1273 } // namespace cc 1302 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698