| 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 769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 780 // Whether we are waiting on a callback to advance the test case. | 780 // Whether we are waiting on a callback to advance the test case. |
| 781 bool pending_callback_ = false; | 781 bool pending_callback_ = false; |
| 782 scoped_refptr<Layer> root_; | 782 scoped_refptr<Layer> root_; |
| 783 scoped_refptr<TextureLayer> layer_; | 783 scoped_refptr<TextureLayer> layer_; |
| 784 }; | 784 }; |
| 785 | 785 |
| 786 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerImplWithMailboxThreadedCallback); | 786 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerImplWithMailboxThreadedCallback); |
| 787 | 787 |
| 788 class TextureLayerMailboxIsActivatedDuringCommit : public LayerTreeTest { | 788 class TextureLayerMailboxIsActivatedDuringCommit : public LayerTreeTest { |
| 789 protected: | 789 protected: |
| 790 TextureLayerMailboxIsActivatedDuringCommit() : activate_count_(0) {} | 790 void ReleaseCallback(const gpu::SyncToken& original_sync_token, |
| 791 | 791 const gpu::SyncToken& release_sync_token, |
| 792 static void ReleaseCallback(const gpu::SyncToken& original_sync_token, | 792 bool lost_resource) { |
| 793 const gpu::SyncToken& release_sync_token, | 793 released_count_++; |
| 794 bool lost_resource) {} | 794 switch (released_count_) { |
| 795 case 1: |
| 796 break; |
| 797 case 2: |
| 798 EXPECT_EQ(3, layer_tree_host()->SourceFrameNumber()); |
| 799 EndTest(); |
| 800 break; |
| 801 default: |
| 802 NOTREACHED(); |
| 803 } |
| 804 } |
| 795 | 805 |
| 796 void SetMailbox(char mailbox_char) { | 806 void SetMailbox(char mailbox_char) { |
| 797 const gpu::SyncToken sync_token = | 807 const gpu::SyncToken sync_token = |
| 798 SyncTokenFromUInt(static_cast<uint32_t>(mailbox_char)); | 808 SyncTokenFromUInt(static_cast<uint32_t>(mailbox_char)); |
| 799 std::unique_ptr<SingleReleaseCallback> callback = | 809 std::unique_ptr<SingleReleaseCallback> callback = |
| 800 SingleReleaseCallback::Create(base::Bind( | 810 SingleReleaseCallback::Create(base::Bind( |
| 801 &TextureLayerMailboxIsActivatedDuringCommit::ReleaseCallback, | 811 &TextureLayerMailboxIsActivatedDuringCommit::ReleaseCallback, |
| 802 sync_token)); | 812 base::Unretained(this), sync_token)); |
| 803 layer_->SetTextureMailbox(TextureMailbox(MailboxFromChar(mailbox_char), | 813 layer_->SetTextureMailbox(TextureMailbox(MailboxFromChar(mailbox_char), |
| 804 sync_token, GL_TEXTURE_2D), | 814 sync_token, GL_TEXTURE_2D), |
| 805 std::move(callback)); | 815 std::move(callback)); |
| 806 } | 816 } |
| 807 | 817 |
| 808 void BeginTest() override { | 818 void BeginTest() override { |
| 809 gfx::Size bounds(100, 100); | 819 gfx::Size bounds(100, 100); |
| 810 root_ = Layer::Create(); | 820 root_ = Layer::Create(); |
| 811 root_->SetBounds(bounds); | 821 root_->SetBounds(bounds); |
| 812 | 822 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 842 // expect the next commit to finish *after* it is activated. | 852 // expect the next commit to finish *after* it is activated. |
| 843 SetMailbox('2'); | 853 SetMailbox('2'); |
| 844 break; | 854 break; |
| 845 case 2: | 855 case 2: |
| 846 // The second mailbox has been activated. Remove the layer from | 856 // The second mailbox has been activated. Remove the layer from |
| 847 // the tree to cause another commit/activation. The commit should | 857 // the tree to cause another commit/activation. The commit should |
| 848 // finish *after* the layer is removed from the active tree. | 858 // finish *after* the layer is removed from the active tree. |
| 849 layer_->RemoveFromParent(); | 859 layer_->RemoveFromParent(); |
| 850 break; | 860 break; |
| 851 case 3: | 861 case 3: |
| 852 EndTest(); | 862 // This ensures all texture mailboxes are released before the end of the |
| 863 // test. |
| 864 layer_->ClearClient(); |
| 853 break; | 865 break; |
| 866 default: |
| 867 NOTREACHED(); |
| 854 } | 868 } |
| 855 } | 869 } |
| 856 | 870 |
| 857 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { | 871 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { |
| 858 // The activate didn't happen before commit is done on the impl side (but it | 872 // The activate didn't happen before commit is done on the impl side (but it |
| 859 // should happen before the main thread is done). | 873 // should happen before the main thread is done). |
| 860 EXPECT_EQ(activate_count_, host_impl->sync_tree()->source_frame_number()); | 874 EXPECT_EQ(activate_count_, host_impl->sync_tree()->source_frame_number()); |
| 861 } | 875 } |
| 862 | 876 |
| 863 void AfterTest() override {} | 877 void AfterTest() override {} |
| 864 | 878 |
| 865 base::Lock activate_count_lock_; | 879 base::Lock activate_count_lock_; |
| 866 int activate_count_; | 880 int activate_count_ = 0; |
| 867 scoped_refptr<Layer> root_; | 881 scoped_refptr<Layer> root_; |
| 868 scoped_refptr<TextureLayer> layer_; | 882 scoped_refptr<TextureLayer> layer_; |
| 883 int released_count_ = 0; |
| 869 }; | 884 }; |
| 870 | 885 |
| 871 // Flaky on windows and linux. https://crbug.com/641613 | |
| 872 #if !defined(OS_WIN) && !defined(OS_LINUX) | |
| 873 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerMailboxIsActivatedDuringCommit); | 886 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerMailboxIsActivatedDuringCommit); |
| 874 #endif | |
| 875 | 887 |
| 876 class TextureLayerImplWithMailboxTest : public TextureLayerTest { | 888 class TextureLayerImplWithMailboxTest : public TextureLayerTest { |
| 877 protected: | 889 protected: |
| 878 void SetUp() override { | 890 void SetUp() override { |
| 879 TextureLayerTest::SetUp(); | 891 TextureLayerTest::SetUp(); |
| 880 layer_tree_host_ = MockLayerTreeHost::Create( | 892 layer_tree_host_ = MockLayerTreeHost::Create( |
| 881 &fake_client_, &task_graph_runner_, animation_host_.get()); | 893 &fake_client_, &task_graph_runner_, animation_host_.get()); |
| 882 host_impl_.SetVisible(true); | 894 host_impl_.SetVisible(true); |
| 883 EXPECT_TRUE(host_impl_.InitializeRenderer(compositor_frame_sink_.get())); | 895 EXPECT_TRUE(host_impl_.InitializeRenderer(compositor_frame_sink_.get())); |
| 884 } | 896 } |
| (...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1476 base::ThreadChecker main_thread_; | 1488 base::ThreadChecker main_thread_; |
| 1477 int callback_count_; | 1489 int callback_count_; |
| 1478 scoped_refptr<Layer> root_; | 1490 scoped_refptr<Layer> root_; |
| 1479 scoped_refptr<TextureLayer> layer_; | 1491 scoped_refptr<TextureLayer> layer_; |
| 1480 }; | 1492 }; |
| 1481 | 1493 |
| 1482 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerWithMailboxImplThreadDeleted); | 1494 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerWithMailboxImplThreadDeleted); |
| 1483 | 1495 |
| 1484 } // namespace | 1496 } // namespace |
| 1485 } // namespace cc | 1497 } // namespace cc |
| OLD | NEW |