| 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 16 matching lines...) Expand all Loading... |
| 27 #include "cc/layers/texture_layer_impl.h" | 27 #include "cc/layers/texture_layer_impl.h" |
| 28 #include "cc/output/context_provider.h" | 28 #include "cc/output/context_provider.h" |
| 29 #include "cc/resources/returned_resource.h" | 29 #include "cc/resources/returned_resource.h" |
| 30 #include "cc/test/fake_impl_task_runner_provider.h" | 30 #include "cc/test/fake_impl_task_runner_provider.h" |
| 31 #include "cc/test/fake_layer_tree_host_client.h" | 31 #include "cc/test/fake_layer_tree_host_client.h" |
| 32 #include "cc/test/fake_layer_tree_host_impl.h" | 32 #include "cc/test/fake_layer_tree_host_impl.h" |
| 33 #include "cc/test/fake_output_surface.h" | 33 #include "cc/test/fake_output_surface.h" |
| 34 #include "cc/test/layer_test_common.h" | 34 #include "cc/test/layer_test_common.h" |
| 35 #include "cc/test/layer_tree_test.h" | 35 #include "cc/test/layer_tree_test.h" |
| 36 #include "cc/test/stub_layer_tree_host_single_thread_client.h" | 36 #include "cc/test/stub_layer_tree_host_single_thread_client.h" |
| 37 #include "cc/test/test_delegating_output_surface.h" |
| 37 #include "cc/test/test_task_graph_runner.h" | 38 #include "cc/test/test_task_graph_runner.h" |
| 38 #include "cc/test/test_web_graphics_context_3d.h" | 39 #include "cc/test/test_web_graphics_context_3d.h" |
| 39 #include "cc/trees/blocking_task_runner.h" | 40 #include "cc/trees/blocking_task_runner.h" |
| 40 #include "cc/trees/layer_tree_host.h" | 41 #include "cc/trees/layer_tree_host.h" |
| 41 #include "cc/trees/layer_tree_impl.h" | 42 #include "cc/trees/layer_tree_impl.h" |
| 42 #include "cc/trees/single_thread_proxy.h" | 43 #include "cc/trees/single_thread_proxy.h" |
| 43 #include "gpu/GLES2/gl2extchromium.h" | 44 #include "gpu/GLES2/gl2extchromium.h" |
| 44 #include "testing/gmock/include/gmock/gmock.h" | 45 #include "testing/gmock/include/gmock/gmock.h" |
| 45 #include "testing/gtest/include/gtest/gtest.h" | 46 #include "testing/gtest/include/gtest/gtest.h" |
| 46 | 47 |
| (...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 624 main_thread_task_runner_.get()); | 625 main_thread_task_runner_.get()); |
| 625 | 626 |
| 626 stop_capture.Signal(); | 627 stop_capture.Signal(); |
| 627 Wait(main_thread_); | 628 Wait(main_thread_); |
| 628 | 629 |
| 629 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 630 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 630 } | 631 } |
| 631 | 632 |
| 632 class TextureLayerImplWithMailboxThreadedCallback : public LayerTreeTest { | 633 class TextureLayerImplWithMailboxThreadedCallback : public LayerTreeTest { |
| 633 public: | 634 public: |
| 634 TextureLayerImplWithMailboxThreadedCallback() | 635 TextureLayerImplWithMailboxThreadedCallback() = default; |
| 635 : callback_count_(0), | 636 |
| 636 commit_count_(0) {} | 637 std::unique_ptr<TestDelegatingOutputSurface> CreateDelegatingOutputSurface( |
| 638 scoped_refptr<ContextProvider> compositor_context_provider, |
| 639 scoped_refptr<ContextProvider> worker_context_provider) override { |
| 640 bool synchronous_composite = |
| 641 !HasImplThread() && |
| 642 !layer_tree_host()->settings().single_thread_proxy_scheduler; |
| 643 // Allow relaim resources for this test so that mailboxes in the display |
| 644 // will be returned inside the commit that replaces them. |
| 645 bool force_disable_reclaim_resources = false; |
| 646 return base::MakeUnique<TestDelegatingOutputSurface>( |
| 647 compositor_context_provider, std::move(worker_context_provider), |
| 648 CreateDisplayOutputSurface(compositor_context_provider), |
| 649 shared_bitmap_manager(), gpu_memory_buffer_manager(), |
| 650 layer_tree_host()->settings().renderer_settings, ImplThreadTaskRunner(), |
| 651 synchronous_composite, force_disable_reclaim_resources); |
| 652 } |
| 637 | 653 |
| 638 // Make sure callback is received on main and doesn't block the impl thread. | 654 // Make sure callback is received on main and doesn't block the impl thread. |
| 639 void ReleaseCallback(const gpu::SyncToken& sync_token, bool lost_resource) { | 655 void ReleaseCallback(char mailbox_char, |
| 656 const gpu::SyncToken& sync_token, |
| 657 bool lost_resource) { |
| 640 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); | 658 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); |
| 641 EXPECT_FALSE(lost_resource); | 659 EXPECT_FALSE(lost_resource); |
| 642 ++callback_count_; | 660 ++callback_count_; |
| 643 } | 661 } |
| 644 | 662 |
| 645 void SetMailbox(char mailbox_char) { | 663 void SetMailbox(char mailbox_char) { |
| 646 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); | 664 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); |
| 647 std::unique_ptr<SingleReleaseCallback> callback = | 665 std::unique_ptr<SingleReleaseCallback> callback = |
| 648 SingleReleaseCallback::Create(base::Bind( | 666 SingleReleaseCallback::Create(base::Bind( |
| 649 &TextureLayerImplWithMailboxThreadedCallback::ReleaseCallback, | 667 &TextureLayerImplWithMailboxThreadedCallback::ReleaseCallback, |
| 650 base::Unretained(this))); | 668 base::Unretained(this), mailbox_char)); |
| 651 layer_->SetTextureMailbox( | 669 layer_->SetTextureMailbox( |
| 652 TextureMailbox(MailboxFromChar(mailbox_char), | 670 TextureMailbox(MailboxFromChar(mailbox_char), |
| 653 SyncTokenFromUInt(static_cast<uint32_t>(mailbox_char)), | 671 SyncTokenFromUInt(static_cast<uint32_t>(mailbox_char)), |
| 654 GL_TEXTURE_2D), | 672 GL_TEXTURE_2D), |
| 655 std::move(callback)); | 673 std::move(callback)); |
| 674 // Damage the layer so we send a new frame with the new mailbox to the |
| 675 // Display compositor. |
| 676 layer_->SetNeedsDisplay(); |
| 656 } | 677 } |
| 657 | 678 |
| 658 void BeginTest() override { | 679 void BeginTest() override { |
| 659 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); | 680 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); |
| 660 | 681 |
| 661 gfx::Size bounds(100, 100); | 682 gfx::Size bounds(100, 100); |
| 662 root_ = Layer::Create(); | 683 root_ = Layer::Create(); |
| 663 root_->SetBounds(bounds); | 684 root_->SetBounds(bounds); |
| 664 | 685 |
| 665 layer_ = TextureLayer::CreateForMailbox(nullptr); | 686 layer_ = TextureLayer::CreateForMailbox(nullptr); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 696 layer_->SetBounds(gfx::Size()); | 717 layer_->SetBounds(gfx::Size()); |
| 697 SetMailbox('4'); | 718 SetMailbox('4'); |
| 698 break; | 719 break; |
| 699 case 3: | 720 case 3: |
| 700 EXPECT_EQ(3, callback_count_); | 721 EXPECT_EQ(3, callback_count_); |
| 701 // Case #4: release mailbox that was committed but never drawn. The | 722 // Case #4: release mailbox that was committed but never drawn. The |
| 702 // old mailbox should be released during the next commit. | 723 // old mailbox should be released during the next commit. |
| 703 layer_->SetTextureMailbox(TextureMailbox(), nullptr); | 724 layer_->SetTextureMailbox(TextureMailbox(), nullptr); |
| 704 break; | 725 break; |
| 705 case 4: | 726 case 4: |
| 706 // With impl painting, the texture mailbox will still be on the impl | |
| 707 // thread when the commit finishes, because the layer is not drawble | |
| 708 // when it has no texture mailbox, and thus does not block the commit | |
| 709 // on activation. So, we wait for activation. | |
| 710 // TODO(danakj): fix this. crbug.com/277953 | |
| 711 layer_tree_host()->SetNeedsCommit(); | |
| 712 break; | |
| 713 case 5: | |
| 714 EXPECT_EQ(4, callback_count_); | 727 EXPECT_EQ(4, callback_count_); |
| 715 // Restore a mailbox for the next step. | 728 // Restore a mailbox for the next step. |
| 716 SetMailbox('5'); | 729 SetMailbox('5'); |
| 717 break; | 730 break; |
| 718 case 6: | 731 case 5: |
| 719 // Case #5: remove layer from tree. Callback should *not* be called, the | 732 // Case #5: remove layer from tree. Callback should *not* be called, the |
| 720 // mailbox is returned to the main thread. | 733 // mailbox is returned to the main thread. |
| 721 EXPECT_EQ(4, callback_count_); | 734 EXPECT_EQ(4, callback_count_); |
| 722 layer_->RemoveFromParent(); | 735 layer_->RemoveFromParent(); |
| 723 break; | 736 break; |
| 724 case 7: | 737 case 6: |
| 725 // With impl painting, the texture mailbox will still be on the impl | |
| 726 // thread when the commit finishes, because the layer is not around to | |
| 727 // block the commit on activation anymore. So, we wait for activation. | |
| 728 // TODO(danakj): fix this. crbug.com/277953 | |
| 729 layer_tree_host()->SetNeedsCommit(); | |
| 730 break; | |
| 731 case 8: | |
| 732 EXPECT_EQ(4, callback_count_); | 738 EXPECT_EQ(4, callback_count_); |
| 733 // Resetting the mailbox will call the callback now. | 739 // Resetting the mailbox will call the callback now. |
| 734 layer_->SetTextureMailbox(TextureMailbox(), nullptr); | 740 layer_->SetTextureMailbox(TextureMailbox(), nullptr); |
| 735 EXPECT_EQ(5, callback_count_); | 741 EXPECT_EQ(5, callback_count_); |
| 736 EndTest(); | 742 EndTest(); |
| 737 break; | 743 break; |
| 738 default: | 744 default: |
| 739 NOTREACHED(); | 745 NOTREACHED(); |
| 740 break; | 746 break; |
| 741 } | 747 } |
| 742 } | 748 } |
| 743 | 749 |
| 744 void AfterTest() override {} | 750 void AfterTest() override {} |
| 745 | 751 |
| 746 private: | 752 private: |
| 747 base::ThreadChecker main_thread_; | 753 base::ThreadChecker main_thread_; |
| 748 int callback_count_; | 754 int callback_count_ = 0; |
| 749 int commit_count_; | 755 int commit_count_ = 0; |
| 750 scoped_refptr<Layer> root_; | 756 scoped_refptr<Layer> root_; |
| 751 scoped_refptr<TextureLayer> layer_; | 757 scoped_refptr<TextureLayer> layer_; |
| 752 }; | 758 }; |
| 753 | 759 |
| 754 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 760 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
| 755 TextureLayerImplWithMailboxThreadedCallback); | 761 TextureLayerImplWithMailboxThreadedCallback); |
| 756 | 762 |
| 757 | 763 |
| 758 class TextureLayerMailboxIsActivatedDuringCommit : public LayerTreeTest { | 764 class TextureLayerMailboxIsActivatedDuringCommit : public LayerTreeTest { |
| 759 protected: | 765 protected: |
| (...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1449 int callback_count_; | 1455 int callback_count_; |
| 1450 scoped_refptr<Layer> root_; | 1456 scoped_refptr<Layer> root_; |
| 1451 scoped_refptr<TextureLayer> layer_; | 1457 scoped_refptr<TextureLayer> layer_; |
| 1452 }; | 1458 }; |
| 1453 | 1459 |
| 1454 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 1460 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
| 1455 TextureLayerWithMailboxImplThreadDeleted); | 1461 TextureLayerWithMailboxImplThreadDeleted); |
| 1456 | 1462 |
| 1457 } // namespace | 1463 } // namespace |
| 1458 } // namespace cc | 1464 } // namespace cc |
| OLD | NEW |