| 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 "cc/layers/layer_iterator.h" | 5 #include "cc/layers/layer_iterator.h" |
| 6 #include "cc/output/copy_output_request.h" | 6 #include "cc/output/copy_output_request.h" |
| 7 #include "cc/output/copy_output_result.h" | 7 #include "cc/output/copy_output_result.h" |
| 8 #include "cc/test/fake_content_layer_client.h" | 8 #include "cc/test/fake_content_layer_client.h" |
| 9 #include "cc/test/fake_output_surface.h" | 9 #include "cc/test/fake_output_surface.h" |
| 10 #include "cc/test/fake_picture_layer.h" | 10 #include "cc/test/fake_picture_layer.h" |
| (...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 copy_layer_->SetBounds(gfx::Size(10, 10)); | 721 copy_layer_->SetBounds(gfx::Size(10, 10)); |
| 722 root_->AddChild(copy_layer_); | 722 root_->AddChild(copy_layer_); |
| 723 | 723 |
| 724 layer_tree_host()->SetRootLayer(root_); | 724 layer_tree_host()->SetRootLayer(root_); |
| 725 LayerTreeHostCopyRequestTest::SetupTree(); | 725 LayerTreeHostCopyRequestTest::SetupTree(); |
| 726 } | 726 } |
| 727 | 727 |
| 728 void BeginTest() override { | 728 void BeginTest() override { |
| 729 num_textures_without_readback_ = 0; | 729 num_textures_without_readback_ = 0; |
| 730 num_textures_with_readback_ = 0; | 730 num_textures_with_readback_ = 0; |
| 731 waited_sync_point_after_readback_ = 0; | 731 waited_sync_token_after_readback_.Clear(); |
| 732 PostSetNeedsCommitToMainThread(); | 732 PostSetNeedsCommitToMainThread(); |
| 733 } | 733 } |
| 734 | 734 |
| 735 virtual void RequestCopy(Layer* layer) = 0; | 735 virtual void RequestCopy(Layer* layer) = 0; |
| 736 | 736 |
| 737 void DidCommitAndDrawFrame() override { | 737 void DidCommitAndDrawFrame() override { |
| 738 switch (layer_tree_host()->source_frame_number()) { | 738 switch (layer_tree_host()->source_frame_number()) { |
| 739 case 1: | 739 case 1: |
| 740 // The layers have been pushed to the impl side. The layer textures have | 740 // The layers have been pushed to the impl side. The layer textures have |
| 741 // been allocated. | 741 // been allocated. |
| 742 RequestCopy(copy_layer_.get()); | 742 RequestCopy(copy_layer_.get()); |
| 743 break; | 743 break; |
| 744 } | 744 } |
| 745 } | 745 } |
| 746 | 746 |
| 747 void SwapBuffersOnThread(LayerTreeHostImpl* impl, bool result) override { | 747 void SwapBuffersOnThread(LayerTreeHostImpl* impl, bool result) override { |
| 748 switch (impl->active_tree()->source_frame_number()) { | 748 switch (impl->active_tree()->source_frame_number()) { |
| 749 case 0: | 749 case 0: |
| 750 // The layers have been drawn, so their textures have been allocated. | 750 // The layers have been drawn, so their textures have been allocated. |
| 751 num_textures_without_readback_ = | 751 num_textures_without_readback_ = |
| 752 context_provider_->TestContext3d()->NumTextures(); | 752 context_provider_->TestContext3d()->NumTextures(); |
| 753 break; | 753 break; |
| 754 case 1: | 754 case 1: |
| 755 // We did a readback, so there will be a readback texture around now. | 755 // We did a readback, so there will be a readback texture around now. |
| 756 num_textures_with_readback_ = | 756 num_textures_with_readback_ = |
| 757 context_provider_->TestContext3d()->NumTextures(); | 757 context_provider_->TestContext3d()->NumTextures(); |
| 758 waited_sync_point_after_readback_ = | 758 waited_sync_token_after_readback_ = |
| 759 context_provider_->TestContext3d()->last_waited_sync_point(); | 759 context_provider_->TestContext3d()->last_waited_sync_token(); |
| 760 | 760 |
| 761 MainThreadTaskRunner()->PostTask( | 761 MainThreadTaskRunner()->PostTask( |
| 762 FROM_HERE, | 762 FROM_HERE, |
| 763 base::Bind(&LayerTreeHostCopyRequestTestCountTextures::DoEndTest, | 763 base::Bind(&LayerTreeHostCopyRequestTestCountTextures::DoEndTest, |
| 764 base::Unretained(this))); | 764 base::Unretained(this))); |
| 765 break; | 765 break; |
| 766 } | 766 } |
| 767 } | 767 } |
| 768 | 768 |
| 769 virtual void DoEndTest() { EndTest(); } | 769 virtual void DoEndTest() { EndTest(); } |
| 770 | 770 |
| 771 scoped_refptr<TestContextProvider> context_provider_; | 771 scoped_refptr<TestContextProvider> context_provider_; |
| 772 size_t num_textures_without_readback_; | 772 size_t num_textures_without_readback_; |
| 773 size_t num_textures_with_readback_; | 773 size_t num_textures_with_readback_; |
| 774 unsigned waited_sync_point_after_readback_; | 774 gpu::SyncToken waited_sync_token_after_readback_; |
| 775 FakeContentLayerClient client_; | 775 FakeContentLayerClient client_; |
| 776 scoped_refptr<FakePictureLayer> root_; | 776 scoped_refptr<FakePictureLayer> root_; |
| 777 scoped_refptr<FakePictureLayer> copy_layer_; | 777 scoped_refptr<FakePictureLayer> copy_layer_; |
| 778 }; | 778 }; |
| 779 | 779 |
| 780 class LayerTreeHostCopyRequestTestCreatesTexture | 780 class LayerTreeHostCopyRequestTestCreatesTexture |
| 781 : public LayerTreeHostCopyRequestTestCountTextures { | 781 : public LayerTreeHostCopyRequestTestCountTextures { |
| 782 protected: | 782 protected: |
| 783 void RequestCopy(Layer* layer) override { | 783 void RequestCopy(Layer* layer) override { |
| 784 // Request a normal texture copy. This should create a new texture. | 784 // Request a normal texture copy. This should create a new texture. |
| 785 copy_layer_->RequestCopyOfOutput( | 785 copy_layer_->RequestCopyOfOutput( |
| 786 CopyOutputRequest::CreateRequest(base::Bind( | 786 CopyOutputRequest::CreateRequest(base::Bind( |
| 787 &LayerTreeHostCopyRequestTestCreatesTexture::CopyOutputCallback, | 787 &LayerTreeHostCopyRequestTestCreatesTexture::CopyOutputCallback, |
| 788 base::Unretained(this)))); | 788 base::Unretained(this)))); |
| 789 } | 789 } |
| 790 | 790 |
| 791 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { | 791 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { |
| 792 EXPECT_FALSE(result->IsEmpty()); | 792 EXPECT_FALSE(result->IsEmpty()); |
| 793 EXPECT_TRUE(result->HasTexture()); | 793 EXPECT_TRUE(result->HasTexture()); |
| 794 | 794 |
| 795 TextureMailbox mailbox; | 795 TextureMailbox mailbox; |
| 796 scoped_ptr<SingleReleaseCallback> release; | 796 scoped_ptr<SingleReleaseCallback> release; |
| 797 result->TakeTexture(&mailbox, &release); | 797 result->TakeTexture(&mailbox, &release); |
| 798 EXPECT_TRUE(release); | 798 EXPECT_TRUE(release); |
| 799 | 799 |
| 800 release->Run(0, false); | 800 release->Run(gpu::SyncToken(), false); |
| 801 } | 801 } |
| 802 | 802 |
| 803 void AfterTest() override { | 803 void AfterTest() override { |
| 804 // No sync point was needed. | 804 // No sync point was needed. |
| 805 EXPECT_EQ(0u, waited_sync_point_after_readback_); | 805 EXPECT_FALSE(waited_sync_token_after_readback_.HasData()); |
| 806 // Except the copy to have made another texture. | 806 // Except the copy to have made another texture. |
| 807 EXPECT_EQ(num_textures_without_readback_ + 1, num_textures_with_readback_); | 807 EXPECT_EQ(num_textures_without_readback_ + 1, num_textures_with_readback_); |
| 808 } | 808 } |
| 809 }; | 809 }; |
| 810 | 810 |
| 811 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 811 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
| 812 LayerTreeHostCopyRequestTestCreatesTexture); | 812 LayerTreeHostCopyRequestTestCreatesTexture); |
| 813 | 813 |
| 814 class LayerTreeHostCopyRequestTestProvideTexture | 814 class LayerTreeHostCopyRequestTestProvideTexture |
| 815 : public LayerTreeHostCopyRequestTestCountTextures { | 815 : public LayerTreeHostCopyRequestTestCountTextures { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 834 // Request a copy to a provided texture. This should not create a new | 834 // Request a copy to a provided texture. This should not create a new |
| 835 // texture. | 835 // texture. |
| 836 scoped_ptr<CopyOutputRequest> request = | 836 scoped_ptr<CopyOutputRequest> request = |
| 837 CopyOutputRequest::CreateRequest(base::Bind( | 837 CopyOutputRequest::CreateRequest(base::Bind( |
| 838 &LayerTreeHostCopyRequestTestProvideTexture::CopyOutputCallback, | 838 &LayerTreeHostCopyRequestTestProvideTexture::CopyOutputCallback, |
| 839 base::Unretained(this))); | 839 base::Unretained(this))); |
| 840 | 840 |
| 841 gpu::gles2::GLES2Interface* gl = external_context_provider_->ContextGL(); | 841 gpu::gles2::GLES2Interface* gl = external_context_provider_->ContextGL(); |
| 842 gpu::Mailbox mailbox; | 842 gpu::Mailbox mailbox; |
| 843 gl->GenMailboxCHROMIUM(mailbox.name); | 843 gl->GenMailboxCHROMIUM(mailbox.name); |
| 844 sync_point_ = gl->InsertSyncPointCHROMIUM(); | 844 sync_token_ = gpu::SyncToken(gl->InsertSyncPointCHROMIUM()); |
| 845 request->SetTextureMailbox( | 845 request->SetTextureMailbox( |
| 846 TextureMailbox(mailbox, GL_TEXTURE_2D, sync_point_)); | 846 TextureMailbox(mailbox, sync_token_, GL_TEXTURE_2D)); |
| 847 EXPECT_TRUE(request->has_texture_mailbox()); | 847 EXPECT_TRUE(request->has_texture_mailbox()); |
| 848 | 848 |
| 849 copy_layer_->RequestCopyOfOutput(request.Pass()); | 849 copy_layer_->RequestCopyOfOutput(request.Pass()); |
| 850 } | 850 } |
| 851 | 851 |
| 852 void AfterTest() override { | 852 void AfterTest() override { |
| 853 // Expect the compositor to have waited for the sync point in the provided | 853 // Expect the compositor to have waited for the sync point in the provided |
| 854 // TextureMailbox. | 854 // TextureMailbox. |
| 855 EXPECT_EQ(sync_point_, waited_sync_point_after_readback_); | 855 EXPECT_EQ(sync_token_, waited_sync_token_after_readback_); |
| 856 // Except the copy to have *not* made another texture. | 856 // Except the copy to have *not* made another texture. |
| 857 EXPECT_EQ(num_textures_without_readback_, num_textures_with_readback_); | 857 EXPECT_EQ(num_textures_without_readback_, num_textures_with_readback_); |
| 858 } | 858 } |
| 859 | 859 |
| 860 scoped_refptr<TestContextProvider> external_context_provider_; | 860 scoped_refptr<TestContextProvider> external_context_provider_; |
| 861 unsigned sync_point_; | 861 gpu::SyncToken sync_token_; |
| 862 }; | 862 }; |
| 863 | 863 |
| 864 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 864 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
| 865 LayerTreeHostCopyRequestTestProvideTexture); | 865 LayerTreeHostCopyRequestTestProvideTexture); |
| 866 | 866 |
| 867 class LayerTreeHostCopyRequestTestDestroyBeforeCopy | 867 class LayerTreeHostCopyRequestTestDestroyBeforeCopy |
| 868 : public LayerTreeHostCopyRequestTest { | 868 : public LayerTreeHostCopyRequestTest { |
| 869 protected: | 869 protected: |
| 870 void SetupTree() override { | 870 void SetupTree() override { |
| 871 root_ = FakePictureLayer::Create(layer_settings(), &client_); | 871 root_ = FakePictureLayer::Create(layer_settings(), &client_); |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1123 int num_draws_; | 1123 int num_draws_; |
| 1124 bool copy_happened_; | 1124 bool copy_happened_; |
| 1125 bool draw_happened_; | 1125 bool draw_happened_; |
| 1126 }; | 1126 }; |
| 1127 | 1127 |
| 1128 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 1128 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
| 1129 LayerTreeHostCopyRequestTestMultipleDrawsHiddenCopyRequest); | 1129 LayerTreeHostCopyRequestTestMultipleDrawsHiddenCopyRequest); |
| 1130 | 1130 |
| 1131 } // namespace | 1131 } // namespace |
| 1132 } // namespace cc | 1132 } // namespace cc |
| OLD | NEW |