OLD | NEW |
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/location.h" | 7 #include "base/location.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
(...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
767 | 767 |
768 void CheckNumTexturesAfterReadbackDestroyed() { | 768 void CheckNumTexturesAfterReadbackDestroyed() { |
769 // After the loss we had |num_textures_after_loss_| many textures, but | 769 // After the loss we had |num_textures_after_loss_| many textures, but |
770 // releasing the copy output request will cause the texture in the request | 770 // releasing the copy output request will cause the texture in the request |
771 // to be released, so we should have 1 less by now. | 771 // to be released, so we should have 1 less by now. |
772 EXPECT_EQ(num_textures_after_loss_ - 1, | 772 EXPECT_EQ(num_textures_after_loss_ - 1, |
773 first_context_provider_->TestContext3d()->NumTextures()); | 773 first_context_provider_->TestContext3d()->NumTextures()); |
774 EndTest(); | 774 EndTest(); |
775 } | 775 } |
776 | 776 |
777 void SwapBuffersOnThread(LayerTreeHostImpl* impl, bool result) override { | 777 void SwapBuffersCompleteOnThread() override { |
778 switch (impl->active_tree()->source_frame_number()) { | 778 switch (num_swaps_++) { |
779 case 0: | 779 case 0: |
780 // The layers have been drawn, so their textures have been allocated. | 780 // The layers have been drawn, so their textures have been allocated. |
781 EXPECT_FALSE(result_); | 781 EXPECT_FALSE(result_); |
782 num_textures_without_readback_ = | 782 num_textures_without_readback_ = |
783 first_context_provider_->TestContext3d()->NumTextures(); | 783 first_context_provider_->TestContext3d()->NumTextures(); |
784 | 784 |
785 // Request a copy of the layer. This will use another texture. | 785 // Request a copy of the layer. This will use another texture. |
786 MainThreadTaskRunner()->PostTask( | 786 MainThreadTaskRunner()->PostTask( |
787 FROM_HERE, | 787 FROM_HERE, |
788 base::Bind(&LayerTreeHostCopyRequestTestLostOutputSurface:: | 788 base::Bind(&LayerTreeHostCopyRequestTestLostOutputSurface:: |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
822 DestroyCopyResultAndCheckNumTextures, | 822 DestroyCopyResultAndCheckNumTextures, |
823 base::Unretained(this))); | 823 base::Unretained(this))); |
824 break; | 824 break; |
825 } | 825 } |
826 } | 826 } |
827 | 827 |
828 void AfterTest() override {} | 828 void AfterTest() override {} |
829 | 829 |
830 scoped_refptr<TestContextProvider> first_context_provider_; | 830 scoped_refptr<TestContextProvider> first_context_provider_; |
831 scoped_refptr<TestContextProvider> second_context_provider_; | 831 scoped_refptr<TestContextProvider> second_context_provider_; |
| 832 int num_swaps_ = 0; |
832 size_t num_textures_without_readback_ = 0; | 833 size_t num_textures_without_readback_ = 0; |
833 size_t num_textures_after_loss_ = 0; | 834 size_t num_textures_after_loss_ = 0; |
834 FakeContentLayerClient client_; | 835 FakeContentLayerClient client_; |
835 scoped_refptr<FakePictureLayer> root_; | 836 scoped_refptr<FakePictureLayer> root_; |
836 scoped_refptr<FakePictureLayer> copy_layer_; | 837 scoped_refptr<FakePictureLayer> copy_layer_; |
837 std::unique_ptr<CopyOutputResult> result_; | 838 std::unique_ptr<CopyOutputResult> result_; |
838 }; | 839 }; |
839 | 840 |
840 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 841 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
841 LayerTreeHostCopyRequestTestLostOutputSurface); | 842 LayerTreeHostCopyRequestTestLostOutputSurface); |
(...skipping 15 matching lines...) Expand all Loading... |
857 copy_layer_ = FakePictureLayer::Create(&client_); | 858 copy_layer_ = FakePictureLayer::Create(&client_); |
858 copy_layer_->SetBounds(gfx::Size(10, 10)); | 859 copy_layer_->SetBounds(gfx::Size(10, 10)); |
859 root_->AddChild(copy_layer_); | 860 root_->AddChild(copy_layer_); |
860 | 861 |
861 layer_tree_host()->SetRootLayer(root_); | 862 layer_tree_host()->SetRootLayer(root_); |
862 LayerTreeHostCopyRequestTest::SetupTree(); | 863 LayerTreeHostCopyRequestTest::SetupTree(); |
863 client_.set_bounds(root_->bounds()); | 864 client_.set_bounds(root_->bounds()); |
864 } | 865 } |
865 | 866 |
866 void BeginTest() override { | 867 void BeginTest() override { |
867 num_textures_without_readback_ = 0; | |
868 num_textures_with_readback_ = 0; | |
869 waited_sync_token_after_readback_.Clear(); | 868 waited_sync_token_after_readback_.Clear(); |
870 PostSetNeedsCommitToMainThread(); | 869 PostSetNeedsCommitToMainThread(); |
871 } | 870 } |
872 | 871 |
873 virtual void RequestCopy(Layer* layer) = 0; | 872 virtual void RequestCopy(Layer* layer) = 0; |
874 | 873 |
875 void DidCommit() override { | 874 void DidCommit() override { |
876 switch (layer_tree_host()->source_frame_number()) { | 875 switch (layer_tree_host()->source_frame_number()) { |
877 case 1: | 876 case 1: |
878 // The layers have been pushed to the impl side. The layer textures have | 877 // The layers have been pushed to the impl side. The layer textures have |
879 // been allocated. | 878 // been allocated. |
880 RequestCopy(copy_layer_.get()); | 879 RequestCopy(copy_layer_.get()); |
881 break; | 880 break; |
882 } | 881 } |
883 } | 882 } |
884 | 883 |
885 void SwapBuffersOnThread(LayerTreeHostImpl* impl, bool result) override { | 884 void SwapBuffersCompleteOnThread() override { |
886 switch (impl->active_tree()->source_frame_number()) { | 885 switch (num_swaps_++) { |
887 case 0: | 886 case 0: |
888 // The layers have been drawn, so their textures have been allocated. | 887 // The layers have been drawn, so their textures have been allocated. |
889 num_textures_without_readback_ = | 888 num_textures_without_readback_ = |
890 context_provider_->TestContext3d()->NumTextures(); | 889 context_provider_->TestContext3d()->NumTextures(); |
891 break; | 890 break; |
892 case 1: | 891 case 1: |
893 // We did a readback, so there will be a readback texture around now. | 892 // We did a readback, so there will be a readback texture around now. |
894 num_textures_with_readback_ = | 893 num_textures_with_readback_ = |
895 context_provider_->TestContext3d()->NumTextures(); | 894 context_provider_->TestContext3d()->NumTextures(); |
896 waited_sync_token_after_readback_ = | 895 waited_sync_token_after_readback_ = |
897 context_provider_->TestContext3d()->last_waited_sync_token(); | 896 context_provider_->TestContext3d()->last_waited_sync_token(); |
898 | 897 |
899 MainThreadTaskRunner()->PostTask( | 898 MainThreadTaskRunner()->PostTask( |
900 FROM_HERE, | 899 FROM_HERE, |
901 base::Bind(&LayerTreeHostCopyRequestTestCountTextures::DoEndTest, | 900 base::Bind(&LayerTreeHostCopyRequestTestCountTextures::DoEndTest, |
902 base::Unretained(this))); | 901 base::Unretained(this))); |
903 break; | 902 break; |
904 } | 903 } |
905 } | 904 } |
906 | 905 |
907 virtual void DoEndTest() { EndTest(); } | 906 virtual void DoEndTest() { EndTest(); } |
908 | 907 |
909 scoped_refptr<TestContextProvider> context_provider_; | 908 scoped_refptr<TestContextProvider> context_provider_; |
910 size_t num_textures_without_readback_; | 909 int num_swaps_ = 0; |
911 size_t num_textures_with_readback_; | 910 size_t num_textures_without_readback_ = 0; |
| 911 size_t num_textures_with_readback_ = 0; |
912 gpu::SyncToken waited_sync_token_after_readback_; | 912 gpu::SyncToken waited_sync_token_after_readback_; |
913 FakeContentLayerClient client_; | 913 FakeContentLayerClient client_; |
914 scoped_refptr<FakePictureLayer> root_; | 914 scoped_refptr<FakePictureLayer> root_; |
915 scoped_refptr<FakePictureLayer> copy_layer_; | 915 scoped_refptr<FakePictureLayer> copy_layer_; |
916 }; | 916 }; |
917 | 917 |
918 class LayerTreeHostCopyRequestTestCreatesTexture | 918 class LayerTreeHostCopyRequestTestCreatesTexture |
919 : public LayerTreeHostCopyRequestTestCountTextures { | 919 : public LayerTreeHostCopyRequestTestCountTextures { |
920 protected: | 920 protected: |
921 void RequestCopy(Layer* layer) override { | 921 void RequestCopy(Layer* layer) override { |
922 // Request a normal texture copy. This should create a new texture. | 922 // Request a normal texture copy. This should create a new texture. |
923 copy_layer_->RequestCopyOfOutput( | 923 copy_layer_->RequestCopyOfOutput( |
924 CopyOutputRequest::CreateRequest(base::Bind( | 924 CopyOutputRequest::CreateRequest(base::Bind( |
925 &LayerTreeHostCopyRequestTestCreatesTexture::CopyOutputCallback, | 925 &LayerTreeHostCopyRequestTestCreatesTexture::CopyOutputCallback, |
926 base::Unretained(this)))); | 926 base::Unretained(this)))); |
927 } | 927 } |
928 | 928 |
929 void CopyOutputCallback(std::unique_ptr<CopyOutputResult> result) { | 929 void CopyOutputCallback(std::unique_ptr<CopyOutputResult> result) { |
930 EXPECT_FALSE(result->IsEmpty()); | 930 EXPECT_FALSE(result->IsEmpty()); |
931 EXPECT_TRUE(result->HasTexture()); | 931 EXPECT_TRUE(result->HasTexture()); |
932 | 932 |
933 TextureMailbox mailbox; | 933 TextureMailbox mailbox; |
934 std::unique_ptr<SingleReleaseCallback> release; | 934 result->TakeTexture(&mailbox, &release_); |
935 result->TakeTexture(&mailbox, &release); | 935 EXPECT_TRUE(release_); |
936 EXPECT_TRUE(release); | |
937 | |
938 release->Run(gpu::SyncToken(), false); | |
939 } | 936 } |
940 | 937 |
941 void AfterTest() override { | 938 void AfterTest() override { |
| 939 release_->Run(gpu::SyncToken(), false); |
| 940 |
942 // No sync point was needed. | 941 // No sync point was needed. |
943 EXPECT_FALSE(waited_sync_token_after_readback_.HasData()); | 942 EXPECT_FALSE(waited_sync_token_after_readback_.HasData()); |
944 // Except the copy to have made another texture. | 943 // Except the copy to have made another texture. |
945 EXPECT_EQ(num_textures_without_readback_ + 1, num_textures_with_readback_); | 944 EXPECT_EQ(num_textures_without_readback_ + 1, num_textures_with_readback_); |
946 } | 945 } |
| 946 |
| 947 std::unique_ptr<SingleReleaseCallback> release_; |
947 }; | 948 }; |
948 | 949 |
949 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 950 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
950 LayerTreeHostCopyRequestTestCreatesTexture); | 951 LayerTreeHostCopyRequestTestCreatesTexture); |
951 | 952 |
952 class LayerTreeHostCopyRequestTestProvideTexture | 953 class LayerTreeHostCopyRequestTestProvideTexture |
953 : public LayerTreeHostCopyRequestTestCountTextures { | 954 : public LayerTreeHostCopyRequestTestCountTextures { |
954 protected: | 955 protected: |
955 void BeginTest() override { | 956 void BeginTest() override { |
956 external_context_provider_ = TestContextProvider::Create(); | 957 external_context_provider_ = TestContextProvider::Create(); |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1267 int num_draws_; | 1268 int num_draws_; |
1268 bool copy_happened_; | 1269 bool copy_happened_; |
1269 bool draw_happened_; | 1270 bool draw_happened_; |
1270 }; | 1271 }; |
1271 | 1272 |
1272 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 1273 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
1273 LayerTreeHostCopyRequestTestMultipleDrawsHiddenCopyRequest); | 1274 LayerTreeHostCopyRequestTestMultipleDrawsHiddenCopyRequest); |
1274 | 1275 |
1275 } // namespace | 1276 } // namespace |
1276 } // namespace cc | 1277 } // namespace cc |
OLD | NEW |