Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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/test/layer_tree_test.h" | 5 #include "cc/test/layer_tree_test.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 717 this, mode_, client_.get(), nullptr, shared_bitmap_manager_.get(), | 717 this, mode_, client_.get(), nullptr, shared_bitmap_manager_.get(), |
| 718 gpu_memory_buffer_manager_.get(), task_graph_runner_.get(), settings_, | 718 gpu_memory_buffer_manager_.get(), task_graph_runner_.get(), settings_, |
| 719 base::ThreadTaskRunnerHandle::Get(), | 719 base::ThreadTaskRunnerHandle::Get(), |
| 720 impl_thread_ ? impl_thread_->task_runner() : NULL, | 720 impl_thread_ ? impl_thread_->task_runner() : NULL, |
| 721 std::move(external_begin_frame_source), | 721 std::move(external_begin_frame_source), |
| 722 image_serialization_processor_.get()); | 722 image_serialization_processor_.get()); |
| 723 } | 723 } |
| 724 | 724 |
| 725 ASSERT_TRUE(layer_tree_host_); | 725 ASSERT_TRUE(layer_tree_host_); |
| 726 | 726 |
| 727 main_task_runner_ = | |
| 728 layer_tree_host_->task_runner_provider()->MainThreadTaskRunner(); | |
|
vmpstr
2016/07/18 23:57:26
Also, this is probably a minor point, but this is
danakj
2016/07/19 00:03:27
Ya cc is a mess of raw pointers for task runners a
| |
| 729 impl_task_runner_ = | |
| 730 layer_tree_host_->task_runner_provider()->ImplThreadTaskRunner(); | |
| 731 if (!impl_task_runner_) { | |
| 732 // For tests, if there's no impl thread, make things easier by just giving | |
| 733 // the main thread task runner. | |
| 734 impl_task_runner_ = main_task_runner_; | |
| 735 } | |
| 736 | |
| 737 if (timeout_seconds_) { | |
| 738 timeout_.Reset(base::Bind(&LayerTreeTest::Timeout, base::Unretained(this))); | |
| 739 main_task_runner_->PostDelayedTask( | |
| 740 FROM_HERE, timeout_.callback(), | |
| 741 base::TimeDelta::FromSeconds(timeout_seconds_)); | |
| 742 } | |
| 743 | |
| 727 started_ = true; | 744 started_ = true; |
| 728 beginning_ = true; | 745 beginning_ = true; |
| 729 SetupTree(); | 746 SetupTree(); |
| 730 WillBeginTest(); | 747 WillBeginTest(); |
| 731 BeginTest(); | 748 BeginTest(); |
| 732 beginning_ = false; | 749 beginning_ = false; |
| 733 if (end_when_begin_returns_) | 750 if (end_when_begin_returns_) |
| 734 RealEndTest(); | 751 RealEndTest(); |
| 735 | 752 |
| 736 // Allow commits to happen once BeginTest() has had a chance to post tasks | 753 // Allow commits to happen once BeginTest() has had a chance to post tasks |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 779 base::Bind(&LayerTreeTest::RealEndTest, main_thread_weak_ptr_)); | 796 base::Bind(&LayerTreeTest::RealEndTest, main_thread_weak_ptr_)); |
| 780 return; | 797 return; |
| 781 } | 798 } |
| 782 | 799 |
| 783 base::MessageLoop::current()->QuitWhenIdle(); | 800 base::MessageLoop::current()->QuitWhenIdle(); |
| 784 } | 801 } |
| 785 | 802 |
| 786 void LayerTreeTest::DispatchAddAnimationToPlayer( | 803 void LayerTreeTest::DispatchAddAnimationToPlayer( |
| 787 AnimationPlayer* player_to_receive_animation, | 804 AnimationPlayer* player_to_receive_animation, |
| 788 double animation_duration) { | 805 double animation_duration) { |
| 789 DCHECK(!task_runner_provider() || task_runner_provider()->IsMainThread()); | 806 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 790 | 807 |
| 791 if (player_to_receive_animation) { | 808 if (player_to_receive_animation) { |
| 792 AddOpacityTransitionToPlayer(player_to_receive_animation, | 809 AddOpacityTransitionToPlayer(player_to_receive_animation, |
| 793 animation_duration, 0, 0.5, true); | 810 animation_duration, 0, 0.5, true); |
| 794 } | 811 } |
| 795 } | 812 } |
| 796 | 813 |
| 797 void LayerTreeTest::DispatchSetDeferCommits(bool defer_commits) { | 814 void LayerTreeTest::DispatchSetDeferCommits(bool defer_commits) { |
| 798 DCHECK(!task_runner_provider() || task_runner_provider()->IsMainThread()); | 815 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 799 | |
| 800 if (layer_tree_host_) | 816 if (layer_tree_host_) |
| 801 layer_tree_host_->SetDeferCommits(defer_commits); | 817 layer_tree_host_->SetDeferCommits(defer_commits); |
| 802 } | 818 } |
| 803 | 819 |
| 804 void LayerTreeTest::DispatchSetNeedsCommit() { | 820 void LayerTreeTest::DispatchSetNeedsCommit() { |
| 805 DCHECK(!task_runner_provider() || task_runner_provider()->IsMainThread()); | 821 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 806 | |
| 807 if (layer_tree_host_) | 822 if (layer_tree_host_) |
| 808 layer_tree_host_->SetNeedsCommit(); | 823 layer_tree_host_->SetNeedsCommit(); |
| 809 } | 824 } |
| 810 | 825 |
| 811 void LayerTreeTest::DispatchSetNeedsUpdateLayers() { | 826 void LayerTreeTest::DispatchSetNeedsUpdateLayers() { |
| 812 DCHECK(!task_runner_provider() || task_runner_provider()->IsMainThread()); | 827 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 813 | |
| 814 if (layer_tree_host_) | 828 if (layer_tree_host_) |
| 815 layer_tree_host_->SetNeedsUpdateLayers(); | 829 layer_tree_host_->SetNeedsUpdateLayers(); |
| 816 } | 830 } |
| 817 | 831 |
| 818 void LayerTreeTest::DispatchSetNeedsRedraw() { | 832 void LayerTreeTest::DispatchSetNeedsRedraw() { |
| 819 DCHECK(!task_runner_provider() || task_runner_provider()->IsMainThread()); | 833 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 820 | |
| 821 if (layer_tree_host_) | 834 if (layer_tree_host_) |
| 822 layer_tree_host_->SetNeedsRedraw(); | 835 layer_tree_host_->SetNeedsRedraw(); |
| 823 } | 836 } |
| 824 | 837 |
| 825 void LayerTreeTest::DispatchSetNeedsRedrawRect(const gfx::Rect& damage_rect) { | 838 void LayerTreeTest::DispatchSetNeedsRedrawRect(const gfx::Rect& damage_rect) { |
| 826 DCHECK(!task_runner_provider() || task_runner_provider()->IsMainThread()); | 839 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 827 | |
| 828 if (layer_tree_host_) | 840 if (layer_tree_host_) |
| 829 layer_tree_host_->SetNeedsRedrawRect(damage_rect); | 841 layer_tree_host_->SetNeedsRedrawRect(damage_rect); |
| 830 } | 842 } |
| 831 | 843 |
| 832 void LayerTreeTest::DispatchSetVisible(bool visible) { | 844 void LayerTreeTest::DispatchSetVisible(bool visible) { |
| 833 DCHECK(!task_runner_provider() || task_runner_provider()->IsMainThread()); | 845 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 834 if (layer_tree_host_) | 846 if (layer_tree_host_) |
| 835 SetVisibleOnLayerTreeHost(visible); | 847 SetVisibleOnLayerTreeHost(visible); |
| 836 } | 848 } |
| 837 | 849 |
| 838 void LayerTreeTest::DispatchSetNextCommitForcesRedraw() { | 850 void LayerTreeTest::DispatchSetNextCommitForcesRedraw() { |
| 839 DCHECK(!task_runner_provider() || task_runner_provider()->IsMainThread()); | 851 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 840 | |
| 841 if (layer_tree_host_) | 852 if (layer_tree_host_) |
| 842 layer_tree_host_->SetNextCommitForcesRedraw(); | 853 layer_tree_host_->SetNextCommitForcesRedraw(); |
| 843 } | 854 } |
| 844 | 855 |
| 845 void LayerTreeTest::DispatchCompositeImmediately() { | 856 void LayerTreeTest::DispatchCompositeImmediately() { |
| 846 DCHECK(!task_runner_provider() || task_runner_provider()->IsMainThread()); | 857 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 847 if (layer_tree_host_) | 858 if (layer_tree_host_) |
| 848 layer_tree_host_->Composite(base::TimeTicks::Now()); | 859 layer_tree_host_->Composite(base::TimeTicks::Now()); |
| 849 } | 860 } |
| 850 | 861 |
| 851 void LayerTreeTest::DispatchNextCommitWaitsForActivation() { | 862 void LayerTreeTest::DispatchNextCommitWaitsForActivation() { |
| 852 DCHECK(!task_runner_provider() || task_runner_provider()->IsMainThread()); | 863 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 853 if (layer_tree_host_) | 864 if (layer_tree_host_) |
| 854 layer_tree_host_->SetNextCommitWaitsForActivation(); | 865 layer_tree_host_->SetNextCommitWaitsForActivation(); |
| 855 } | 866 } |
| 856 | 867 |
| 857 void LayerTreeTest::RunTest(CompositorMode mode, bool delegating_renderer) { | 868 void LayerTreeTest::RunTest(CompositorMode mode, bool delegating_renderer) { |
| 858 mode_ = mode; | 869 mode_ = mode; |
| 859 if (mode_ == CompositorMode::THREADED || mode_ == CompositorMode::REMOTE) { | 870 if (mode_ == CompositorMode::THREADED || mode_ == CompositorMode::REMOTE) { |
| 860 impl_thread_.reset(new base::Thread("Compositor")); | 871 impl_thread_.reset(new base::Thread("Compositor")); |
| 861 ASSERT_TRUE(impl_thread_->Start()); | 872 ASSERT_TRUE(impl_thread_->Start()); |
| 862 } | 873 } |
| 863 | 874 |
| 864 main_task_runner_ = base::ThreadTaskRunnerHandle::Get(); | |
| 865 | |
| 866 shared_bitmap_manager_.reset(new TestSharedBitmapManager); | 875 shared_bitmap_manager_.reset(new TestSharedBitmapManager); |
| 867 gpu_memory_buffer_manager_.reset(new TestGpuMemoryBufferManager); | 876 gpu_memory_buffer_manager_.reset(new TestGpuMemoryBufferManager); |
| 868 task_graph_runner_.reset(new TestTaskGraphRunner); | 877 task_graph_runner_.reset(new TestTaskGraphRunner); |
| 869 | 878 |
| 870 delegating_renderer_ = delegating_renderer; | 879 delegating_renderer_ = delegating_renderer; |
| 871 | 880 |
| 872 // Spend less time waiting for BeginFrame because the output is | 881 // Spend less time waiting for BeginFrame because the output is |
| 873 // mocked out. | 882 // mocked out. |
| 874 settings_.renderer_settings.refresh_rate = 200.0; | 883 settings_.renderer_settings.refresh_rate = 200.0; |
| 875 settings_.background_animation_rate = 200.0; | 884 settings_.background_animation_rate = 200.0; |
| 876 settings_.verify_clip_tree_calculations = true; | 885 settings_.verify_clip_tree_calculations = true; |
| 877 settings_.verify_transform_tree_calculations = true; | 886 settings_.verify_transform_tree_calculations = true; |
| 878 InitializeSettings(&settings_); | 887 InitializeSettings(&settings_); |
| 879 | 888 |
| 880 main_task_runner_->PostTask( | 889 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 881 FROM_HERE, | 890 FROM_HERE, |
| 882 base::Bind(&LayerTreeTest::DoBeginTest, base::Unretained(this))); | 891 base::Bind(&LayerTreeTest::DoBeginTest, base::Unretained(this))); |
| 883 | 892 |
| 884 if (timeout_seconds_) { | |
| 885 timeout_.Reset(base::Bind(&LayerTreeTest::Timeout, base::Unretained(this))); | |
| 886 main_task_runner_->PostDelayedTask( | |
| 887 FROM_HERE, | |
| 888 timeout_.callback(), | |
| 889 base::TimeDelta::FromSeconds(timeout_seconds_)); | |
| 890 } | |
| 891 | |
| 892 base::RunLoop().Run(); | 893 base::RunLoop().Run(); |
| 893 DestroyLayerTreeHost(); | 894 DestroyLayerTreeHost(); |
| 894 | 895 |
| 895 timeout_.Cancel(); | 896 timeout_.Cancel(); |
| 896 | 897 |
| 897 ASSERT_FALSE(layer_tree_host_.get()); | 898 ASSERT_FALSE(layer_tree_host_.get()); |
| 898 client_ = nullptr; | 899 client_ = nullptr; |
| 899 if (timed_out_) { | 900 if (timed_out_) { |
| 900 FAIL() << "Test timed out"; | 901 FAIL() << "Test timed out"; |
| 901 return; | 902 return; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 912 } | 913 } |
| 913 | 914 |
| 914 std::unique_ptr<OutputSurface> LayerTreeTest::CreateOutputSurface() { | 915 std::unique_ptr<OutputSurface> LayerTreeTest::CreateOutputSurface() { |
| 915 return delegating_renderer_ ? FakeOutputSurface::CreateDelegating3d() | 916 return delegating_renderer_ ? FakeOutputSurface::CreateDelegating3d() |
| 916 : FakeOutputSurface::Create3d(); | 917 : FakeOutputSurface::Create3d(); |
| 917 } | 918 } |
| 918 | 919 |
| 919 void LayerTreeTest::DestroyLayerTreeHost() { | 920 void LayerTreeTest::DestroyLayerTreeHost() { |
| 920 if (layer_tree_host_ && layer_tree_host_->root_layer()) | 921 if (layer_tree_host_ && layer_tree_host_->root_layer()) |
| 921 layer_tree_host_->root_layer()->SetLayerTreeHost(NULL); | 922 layer_tree_host_->root_layer()->SetLayerTreeHost(NULL); |
| 922 layer_tree_host_ = nullptr; | 923 |
| 924 // Destroy the LayerTreeHost after making the member variable null to ensure | |
| 925 // that if tests try to use the layer_tree_host_ while we are destroying it | |
| 926 // they will for sure see null, as some std::unique_ptr implementations don't | |
| 927 // do this for us (*ahem* MSVC) since it is not required by the standard. | |
|
vmpstr
2016/07/18 23:26:12
Is the concern that something might access layer_t
danakj
2016/07/19 00:03:27
Yes. The LTH destructor joins the compositor threa
| |
| 928 { | |
| 929 auto temp = std::move(layer_tree_host_); | |
| 930 temp = nullptr; | |
| 931 } | |
| 923 | 932 |
| 924 DCHECK(!remote_proto_channel_bridge_.channel_main.HasReceiver()); | 933 DCHECK(!remote_proto_channel_bridge_.channel_main.HasReceiver()); |
| 925 | 934 |
| 926 // Destroying the LayerTreeHost should destroy the remote client | 935 // Destroying the LayerTreeHost should destroy the remote client |
| 927 // LayerTreeHost. | 936 // LayerTreeHost. |
| 928 DCHECK(!remote_client_layer_tree_host_); | 937 DCHECK(!remote_client_layer_tree_host_); |
| 929 } | 938 } |
| 930 | 939 |
| 931 void LayerTreeTest::DestroyRemoteClientHost() { | 940 void LayerTreeTest::DestroyRemoteClientHost() { |
| 932 DCHECK(IsRemoteTest()); | 941 DCHECK(IsRemoteTest()); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 960 | 969 |
| 961 TaskGraphRunner* LayerTreeTest::task_graph_runner() const { | 970 TaskGraphRunner* LayerTreeTest::task_graph_runner() const { |
| 962 return task_graph_runner_.get(); | 971 return task_graph_runner_.get(); |
| 963 } | 972 } |
| 964 | 973 |
| 965 TaskRunnerProvider* LayerTreeTest::task_runner_provider() const { | 974 TaskRunnerProvider* LayerTreeTest::task_runner_provider() const { |
| 966 // All LayerTreeTests can use the task runner provider to access the impl | 975 // All LayerTreeTests can use the task runner provider to access the impl |
| 967 // thread. In the remote mode, the impl thread of the compositor lives on | 976 // thread. In the remote mode, the impl thread of the compositor lives on |
| 968 // the client, so return the task runner provider owned by the remote client | 977 // the client, so return the task runner provider owned by the remote client |
| 969 // LayerTreeHost. | 978 // LayerTreeHost. |
| 970 if (IsRemoteTest()) { | 979 LayerTreeHost* host = IsRemoteTest() ? remote_client_layer_tree_host_.get() |
| 971 return remote_client_layer_tree_host_ | 980 : layer_tree_host_.get(); |
| 972 ? remote_client_layer_tree_host_->task_runner_provider() | 981 |
| 973 : nullptr; | 982 // If this fails, the test has ended and there is no task runners to find |
| 974 } | 983 // anymore. |
| 975 return layer_tree_host_ ? layer_tree_host_->task_runner_provider() : nullptr; | 984 DCHECK(host); |
| 985 | |
| 986 return host->task_runner_provider(); | |
| 976 } | 987 } |
| 977 | 988 |
| 978 LayerTreeHost* LayerTreeTest::layer_tree_host() { | 989 LayerTreeHost* LayerTreeTest::layer_tree_host() { |
| 979 // We check for a null task_runner_provider here as we sometimes ask for the | 990 DCHECK(task_runner_provider()->IsMainThread() || |
| 980 // layer tree host when the task_runner_provider does not exist, often for | |
| 981 // checking settings after a test has completed. For example, | |
| 982 // LTHPixelResourceTest::RunPixelResourceTest. See elsewhere in this file for | |
| 983 // other examples. | |
| 984 DCHECK(!task_runner_provider() || task_runner_provider()->IsMainThread() || | |
| 985 task_runner_provider()->IsMainThreadBlocked()); | 991 task_runner_provider()->IsMainThreadBlocked()); |
| 986 return layer_tree_host_.get(); | 992 return layer_tree_host_.get(); |
| 987 } | 993 } |
| 988 | 994 |
| 989 LayerTreeHost* LayerTreeTest::remote_client_layer_tree_host() { | 995 LayerTreeHost* LayerTreeTest::remote_client_layer_tree_host() { |
| 990 DCHECK(!task_runner_provider() || task_runner_provider()->IsMainThread() || | 996 DCHECK(IsRemoteTest()); |
| 997 DCHECK(task_runner_provider()->IsMainThread() || | |
| 991 task_runner_provider()->IsMainThreadBlocked()); | 998 task_runner_provider()->IsMainThreadBlocked()); |
| 992 DCHECK(IsRemoteTest()); | |
| 993 return remote_client_layer_tree_host_.get(); | 999 return remote_client_layer_tree_host_.get(); |
| 994 } | 1000 } |
| 995 | 1001 |
| 996 ProxyMainForTest* LayerTreeTest::GetProxyMainForTest() const { | 1002 ProxyMainForTest* LayerTreeTest::GetProxyMainForTest() const { |
| 997 DCHECK(HasImplThread()); | 1003 DCHECK(HasImplThread()); |
| 998 return static_cast<ProxyMainForTest*>(proxy()); | 1004 return static_cast<ProxyMainForTest*>(proxy()); |
| 999 } | 1005 } |
| 1000 | 1006 |
| 1001 ProxyImplForTest* LayerTreeTest::GetProxyImplForTest() const { | 1007 ProxyImplForTest* LayerTreeTest::GetProxyImplForTest() const { |
| 1002 DCHECK(HasImplThread()); | 1008 DCHECK(HasImplThread()); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 1022 | 1028 |
| 1023 RemoteChannelImplForTest* LayerTreeTest::GetRemoteChannelImplForTest() const { | 1029 RemoteChannelImplForTest* LayerTreeTest::GetRemoteChannelImplForTest() const { |
| 1024 DCHECK(IsRemoteTest()); | 1030 DCHECK(IsRemoteTest()); |
| 1025 DCHECK(remote_client_layer_tree_host_); | 1031 DCHECK(remote_client_layer_tree_host_); |
| 1026 | 1032 |
| 1027 return static_cast<RemoteChannelImplForTest*>( | 1033 return static_cast<RemoteChannelImplForTest*>( |
| 1028 remote_client_layer_tree_host_->proxy()); | 1034 remote_client_layer_tree_host_->proxy()); |
| 1029 } | 1035 } |
| 1030 | 1036 |
| 1031 } // namespace cc | 1037 } // namespace cc |
| OLD | NEW |