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 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 | 633 |
634 class TextureLayerImplWithMailboxThreadedCallback : public LayerTreeTest { | 634 class TextureLayerImplWithMailboxThreadedCallback : public LayerTreeTest { |
635 public: | 635 public: |
636 TextureLayerImplWithMailboxThreadedCallback() = default; | 636 TextureLayerImplWithMailboxThreadedCallback() = default; |
637 | 637 |
638 std::unique_ptr<TestDelegatingOutputSurface> CreateDelegatingOutputSurface( | 638 std::unique_ptr<TestDelegatingOutputSurface> CreateDelegatingOutputSurface( |
639 scoped_refptr<ContextProvider> compositor_context_provider, | 639 scoped_refptr<ContextProvider> compositor_context_provider, |
640 scoped_refptr<ContextProvider> worker_context_provider) override { | 640 scoped_refptr<ContextProvider> worker_context_provider) override { |
641 bool synchronous_composite = | 641 bool synchronous_composite = |
642 !HasImplThread() && | 642 !HasImplThread() && |
643 !layer_tree_host()->settings().single_thread_proxy_scheduler; | 643 !layer_tree_host()->GetSettings().single_thread_proxy_scheduler; |
644 // Allow relaim resources for this test so that mailboxes in the display | 644 // Allow relaim resources for this test so that mailboxes in the display |
645 // will be returned inside the commit that replaces them. | 645 // will be returned inside the commit that replaces them. |
646 bool force_disable_reclaim_resources = false; | 646 bool force_disable_reclaim_resources = false; |
647 return base::MakeUnique<TestDelegatingOutputSurface>( | 647 return base::MakeUnique<TestDelegatingOutputSurface>( |
648 compositor_context_provider, std::move(worker_context_provider), | 648 compositor_context_provider, std::move(worker_context_provider), |
649 CreateDisplayOutputSurface(compositor_context_provider), | 649 CreateDisplayOutputSurface(compositor_context_provider), |
650 shared_bitmap_manager(), gpu_memory_buffer_manager(), | 650 shared_bitmap_manager(), gpu_memory_buffer_manager(), |
651 layer_tree_host()->settings().renderer_settings, ImplThreadTaskRunner(), | 651 layer_tree_host()->GetSettings().renderer_settings, |
652 synchronous_composite, force_disable_reclaim_resources); | 652 ImplThreadTaskRunner(), synchronous_composite, |
| 653 force_disable_reclaim_resources); |
653 } | 654 } |
654 | 655 |
655 // Make sure callback is received on main and doesn't block the impl thread. | 656 // Make sure callback is received on main and doesn't block the impl thread. |
656 void ReleaseCallback(char mailbox_char, | 657 void ReleaseCallback(char mailbox_char, |
657 const gpu::SyncToken& sync_token, | 658 const gpu::SyncToken& sync_token, |
658 bool lost_resource) { | 659 bool lost_resource) { |
659 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); | 660 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); |
660 EXPECT_FALSE(lost_resource); | 661 EXPECT_FALSE(lost_resource); |
661 ++callback_count_; | 662 ++callback_count_; |
662 } | 663 } |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 } | 799 } |
799 | 800 |
800 void WillActivateTreeOnThread(LayerTreeHostImpl* impl) override { | 801 void WillActivateTreeOnThread(LayerTreeHostImpl* impl) override { |
801 base::AutoLock lock(activate_count_lock_); | 802 base::AutoLock lock(activate_count_lock_); |
802 ++activate_count_; | 803 ++activate_count_; |
803 } | 804 } |
804 | 805 |
805 void DidCommit() override { | 806 void DidCommit() override { |
806 // The first frame doesn't cause anything to be returned so it does not | 807 // The first frame doesn't cause anything to be returned so it does not |
807 // need to wait for activation. | 808 // need to wait for activation. |
808 if (layer_tree_host()->source_frame_number() > 1) { | 809 if (layer_tree_host()->SourceFrameNumber() > 1) { |
809 base::AutoLock lock(activate_count_lock_); | 810 base::AutoLock lock(activate_count_lock_); |
810 // The activate happened before commit is done on the main side. | 811 // The activate happened before commit is done on the main side. |
811 EXPECT_EQ(activate_count_, layer_tree_host()->source_frame_number()); | 812 EXPECT_EQ(activate_count_, layer_tree_host()->SourceFrameNumber()); |
812 } | 813 } |
813 | 814 |
814 switch (layer_tree_host()->source_frame_number()) { | 815 switch (layer_tree_host()->SourceFrameNumber()) { |
815 case 1: | 816 case 1: |
816 // The first mailbox has been activated. Set a new mailbox, and | 817 // The first mailbox has been activated. Set a new mailbox, and |
817 // expect the next commit to finish *after* it is activated. | 818 // expect the next commit to finish *after* it is activated. |
818 SetMailbox('2'); | 819 SetMailbox('2'); |
819 break; | 820 break; |
820 case 2: | 821 case 2: |
821 // The second mailbox has been activated. Remove the layer from | 822 // The second mailbox has been activated. Remove the layer from |
822 // the tree to cause another commit/activation. The commit should | 823 // the tree to cause another commit/activation. The commit should |
823 // finish *after* the layer is removed from the active tree. | 824 // finish *after* the layer is removed from the active tree. |
824 layer_->RemoveFromParent(); | 825 layer_->RemoveFromParent(); |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1048 // Checks that TextureLayer::Update does not cause an extra commit when setting | 1049 // Checks that TextureLayer::Update does not cause an extra commit when setting |
1049 // the texture mailbox. | 1050 // the texture mailbox. |
1050 class TextureLayerNoExtraCommitForMailboxTest | 1051 class TextureLayerNoExtraCommitForMailboxTest |
1051 : public LayerTreeTest, | 1052 : public LayerTreeTest, |
1052 public TextureLayerClient { | 1053 public TextureLayerClient { |
1053 public: | 1054 public: |
1054 // TextureLayerClient implementation. | 1055 // TextureLayerClient implementation. |
1055 bool PrepareTextureMailbox( | 1056 bool PrepareTextureMailbox( |
1056 TextureMailbox* texture_mailbox, | 1057 TextureMailbox* texture_mailbox, |
1057 std::unique_ptr<SingleReleaseCallback>* release_callback) override { | 1058 std::unique_ptr<SingleReleaseCallback>* release_callback) override { |
1058 if (layer_tree_host()->source_frame_number() == 1) { | 1059 if (layer_tree_host()->SourceFrameNumber() == 1) { |
1059 // Once this has been committed, the mailbox will be released. | 1060 // Once this has been committed, the mailbox will be released. |
1060 *texture_mailbox = TextureMailbox(); | 1061 *texture_mailbox = TextureMailbox(); |
1061 return true; | 1062 return true; |
1062 } | 1063 } |
1063 | 1064 |
1064 *texture_mailbox = TextureMailbox(MailboxFromChar('1'), | 1065 *texture_mailbox = TextureMailbox(MailboxFromChar('1'), |
1065 SyncTokenFromUInt(0x123), GL_TEXTURE_2D); | 1066 SyncTokenFromUInt(0x123), GL_TEXTURE_2D); |
1066 *release_callback = SingleReleaseCallback::Create( | 1067 *release_callback = SingleReleaseCallback::Create( |
1067 base::Bind(&TextureLayerNoExtraCommitForMailboxTest::MailboxReleased, | 1068 base::Bind(&TextureLayerNoExtraCommitForMailboxTest::MailboxReleased, |
1068 base::Unretained(this))); | 1069 base::Unretained(this))); |
(...skipping 15 matching lines...) Expand all Loading... |
1084 texture_layer_->SetIsDrawable(true); | 1085 texture_layer_->SetIsDrawable(true); |
1085 root->AddChild(texture_layer_); | 1086 root->AddChild(texture_layer_); |
1086 | 1087 |
1087 layer_tree()->SetRootLayer(root); | 1088 layer_tree()->SetRootLayer(root); |
1088 LayerTreeTest::SetupTree(); | 1089 LayerTreeTest::SetupTree(); |
1089 } | 1090 } |
1090 | 1091 |
1091 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 1092 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
1092 | 1093 |
1093 void DidCommitAndDrawFrame() override { | 1094 void DidCommitAndDrawFrame() override { |
1094 switch (layer_tree_host()->source_frame_number()) { | 1095 switch (layer_tree_host()->SourceFrameNumber()) { |
1095 case 1: | 1096 case 1: |
1096 EXPECT_FALSE(proxy()->MainFrameWillHappenForTesting()); | 1097 EXPECT_FALSE(proxy()->MainFrameWillHappenForTesting()); |
1097 // Invalidate the texture layer to clear the mailbox before | 1098 // Invalidate the texture layer to clear the mailbox before |
1098 // ending the test. | 1099 // ending the test. |
1099 texture_layer_->SetNeedsDisplay(); | 1100 texture_layer_->SetNeedsDisplay(); |
1100 break; | 1101 break; |
1101 case 2: | 1102 case 2: |
1102 break; | 1103 break; |
1103 default: | 1104 default: |
1104 NOTREACHED(); | 1105 NOTREACHED(); |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1356 callback_count_ = 0; | 1357 callback_count_ = 0; |
1357 | 1358 |
1358 // Set the mailbox on the main thread. | 1359 // Set the mailbox on the main thread. |
1359 SetMailbox('1'); | 1360 SetMailbox('1'); |
1360 EXPECT_EQ(0, callback_count_); | 1361 EXPECT_EQ(0, callback_count_); |
1361 | 1362 |
1362 PostSetNeedsCommitToMainThread(); | 1363 PostSetNeedsCommitToMainThread(); |
1363 } | 1364 } |
1364 | 1365 |
1365 void DidCommitAndDrawFrame() override { | 1366 void DidCommitAndDrawFrame() override { |
1366 switch (layer_tree_host()->source_frame_number()) { | 1367 switch (layer_tree_host()->SourceFrameNumber()) { |
1367 case 1: | 1368 case 1: |
1368 // Delete the TextureLayer on the main thread while the mailbox is in | 1369 // Delete the TextureLayer on the main thread while the mailbox is in |
1369 // the impl tree. | 1370 // the impl tree. |
1370 layer_->RemoveFromParent(); | 1371 layer_->RemoveFromParent(); |
1371 layer_ = nullptr; | 1372 layer_ = nullptr; |
1372 break; | 1373 break; |
1373 } | 1374 } |
1374 } | 1375 } |
1375 | 1376 |
1376 void AfterTest() override { EXPECT_EQ(1, callback_count_); } | 1377 void AfterTest() override { EXPECT_EQ(1, callback_count_); } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1426 callback_count_ = 0; | 1427 callback_count_ = 0; |
1427 | 1428 |
1428 // Set the mailbox on the main thread. | 1429 // Set the mailbox on the main thread. |
1429 SetMailbox('1'); | 1430 SetMailbox('1'); |
1430 EXPECT_EQ(0, callback_count_); | 1431 EXPECT_EQ(0, callback_count_); |
1431 | 1432 |
1432 PostSetNeedsCommitToMainThread(); | 1433 PostSetNeedsCommitToMainThread(); |
1433 } | 1434 } |
1434 | 1435 |
1435 void DidCommitAndDrawFrame() override { | 1436 void DidCommitAndDrawFrame() override { |
1436 switch (layer_tree_host()->source_frame_number()) { | 1437 switch (layer_tree_host()->SourceFrameNumber()) { |
1437 case 1: | 1438 case 1: |
1438 // Remove the TextureLayer on the main thread while the mailbox is in | 1439 // Remove the TextureLayer on the main thread while the mailbox is in |
1439 // the impl tree, but don't delete the TextureLayer until after the impl | 1440 // the impl tree, but don't delete the TextureLayer until after the impl |
1440 // tree side is deleted. | 1441 // tree side is deleted. |
1441 layer_->RemoveFromParent(); | 1442 layer_->RemoveFromParent(); |
1442 break; | 1443 break; |
1443 case 2: | 1444 case 2: |
1444 layer_ = nullptr; | 1445 layer_ = nullptr; |
1445 break; | 1446 break; |
1446 } | 1447 } |
1447 } | 1448 } |
1448 | 1449 |
1449 void AfterTest() override { EXPECT_EQ(1, callback_count_); } | 1450 void AfterTest() override { EXPECT_EQ(1, callback_count_); } |
1450 | 1451 |
1451 private: | 1452 private: |
1452 base::ThreadChecker main_thread_; | 1453 base::ThreadChecker main_thread_; |
1453 int callback_count_; | 1454 int callback_count_; |
1454 scoped_refptr<Layer> root_; | 1455 scoped_refptr<Layer> root_; |
1455 scoped_refptr<TextureLayer> layer_; | 1456 scoped_refptr<TextureLayer> layer_; |
1456 }; | 1457 }; |
1457 | 1458 |
1458 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerWithMailboxImplThreadDeleted); | 1459 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerWithMailboxImplThreadDeleted); |
1459 | 1460 |
1460 } // namespace | 1461 } // namespace |
1461 } // namespace cc | 1462 } // namespace cc |
OLD | NEW |