Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: cc/trees/layer_tree_host_unittest.cc

Issue 895853003: Update from https://crrev.com/314320 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/trees/layer_tree_host.h" 5 #include "cc/trees/layer_tree_host.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/synchronization/lock.h" 10 #include "base/synchronization/lock.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 for (const auto& layer : layers) { 87 for (const auto& layer : layers) {
88 FakePictureLayerImpl* fake_layer = 88 FakePictureLayerImpl* fake_layer =
89 static_cast<FakePictureLayerImpl*>(layer); 89 static_cast<FakePictureLayerImpl*>(layer);
90 required_for_activation_count_ += 90 required_for_activation_count_ +=
91 fake_layer->CountTilesRequiredForActivation(); 91 fake_layer->CountTilesRequiredForActivation();
92 } 92 }
93 } 93 }
94 94
95 void NotifyReadyToActivateOnThread(LayerTreeHostImpl* impl) override { 95 void NotifyReadyToActivateOnThread(LayerTreeHostImpl* impl) override {
96 did_notify_ready_to_activate_ = true; 96 did_notify_ready_to_activate_ = true;
97 const std::vector<PictureLayerImpl*>& layers = impl->GetPictureLayers(); 97 all_tiles_required_for_activation_are_ready_to_draw_ =
98 all_tiles_required_for_activation_are_ready_to_draw_ = true; 98 impl->tile_manager()->IsReadyToActivate();
99 for (const auto& layer : layers) {
100 if (!layer->AllTilesRequiredForActivationAreReadyToDraw())
101 all_tiles_required_for_activation_are_ready_to_draw_ = false;
102 }
103 EndTest(); 99 EndTest();
104 } 100 }
105 101
106 void AfterTest() override { 102 void AfterTest() override {
107 EXPECT_TRUE(did_notify_ready_to_activate_); 103 EXPECT_TRUE(did_notify_ready_to_activate_);
108 EXPECT_TRUE(all_tiles_required_for_activation_are_ready_to_draw_); 104 EXPECT_TRUE(all_tiles_required_for_activation_are_ready_to_draw_);
109 EXPECT_EQ(size_t(0), required_for_activation_count_); 105 EXPECT_EQ(size_t(0), required_for_activation_count_);
110 } 106 }
111 107
112 protected: 108 protected:
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 LayerTreeHostTestReadyToDrawEmpty() 148 LayerTreeHostTestReadyToDrawEmpty()
153 : did_notify_ready_to_draw_(false), 149 : did_notify_ready_to_draw_(false),
154 all_tiles_required_for_draw_are_ready_to_draw_(false), 150 all_tiles_required_for_draw_are_ready_to_draw_(false),
155 required_for_draw_count_(0) {} 151 required_for_draw_count_(0) {}
156 152
157 void BeginTest() override { PostSetNeedsCommitToMainThread(); } 153 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
158 154
159 void NotifyReadyToDrawOnThread(LayerTreeHostImpl* impl) override { 155 void NotifyReadyToDrawOnThread(LayerTreeHostImpl* impl) override {
160 did_notify_ready_to_draw_ = true; 156 did_notify_ready_to_draw_ = true;
161 const std::vector<PictureLayerImpl*>& layers = impl->GetPictureLayers(); 157 const std::vector<PictureLayerImpl*>& layers = impl->GetPictureLayers();
162 all_tiles_required_for_draw_are_ready_to_draw_ = true; 158 all_tiles_required_for_draw_are_ready_to_draw_ =
159 impl->tile_manager()->IsReadyToDraw();
163 for (const auto& layer : layers) { 160 for (const auto& layer : layers) {
164 if (!layer->AllTilesRequiredForDrawAreReadyToDraw())
165 all_tiles_required_for_draw_are_ready_to_draw_ = false;
166 FakePictureLayerImpl* fake_layer = 161 FakePictureLayerImpl* fake_layer =
167 static_cast<FakePictureLayerImpl*>(layer); 162 static_cast<FakePictureLayerImpl*>(layer);
168 required_for_draw_count_ += fake_layer->CountTilesRequiredForDraw(); 163 required_for_draw_count_ += fake_layer->CountTilesRequiredForDraw();
169 } 164 }
170 165
171 EndTest(); 166 EndTest();
172 } 167 }
173 168
174 void AfterTest() override { 169 void AfterTest() override {
175 EXPECT_TRUE(did_notify_ready_to_draw_); 170 EXPECT_TRUE(did_notify_ready_to_draw_);
(...skipping 1849 matching lines...) Expand 10 before | Expand all | Expand 10 after
2025 scoped_refptr<Layer> layer_; 2020 scoped_refptr<Layer> layer_;
2026 int num_commit_complete_; 2021 int num_commit_complete_;
2027 int num_draw_layers_; 2022 int num_draw_layers_;
2028 }; 2023 };
2029 2024
2030 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousInvalidate); 2025 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousInvalidate);
2031 2026
2032 class LayerTreeHostTestDeferCommits : public LayerTreeHostTest { 2027 class LayerTreeHostTestDeferCommits : public LayerTreeHostTest {
2033 public: 2028 public:
2034 LayerTreeHostTestDeferCommits() 2029 LayerTreeHostTestDeferCommits()
2035 : num_commits_deferred_(0), num_complete_commits_(0) {} 2030 : num_will_begin_impl_frame_(0),
2031 num_send_begin_main_frame_(0) {}
2036 2032
2037 void BeginTest() override { PostSetNeedsCommitToMainThread(); } 2033 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
2038 2034
2039 void DidDeferCommit() override { 2035 void WillBeginImplFrame(const BeginFrameArgs& args) override {
2040 num_commits_deferred_++; 2036 num_will_begin_impl_frame_++;
2041 layer_tree_host()->SetDeferCommits(false); 2037 switch (num_will_begin_impl_frame_) {
2038 case 1:
2039 break;
2040 case 2:
2041 PostSetNeedsCommitToMainThread();
2042 break;
2043 case 3:
2044 PostSetDeferCommitsToMainThread(false);
2045 break;
2046 default:
2047 // Sometimes |num_will_begin_impl_frame_| will be greater than 3 if the
2048 // main thread is slow to respond.
2049 break;
2050 }
2042 } 2051 }
2043 2052
2044 void DidCommit() override { 2053 void ScheduledActionSendBeginMainFrame() override {
2045 num_complete_commits_++; 2054 num_send_begin_main_frame_++;
2046 switch (num_complete_commits_) { 2055 switch (num_send_begin_main_frame_) {
2047 case 1: 2056 case 1:
2048 EXPECT_EQ(0, num_commits_deferred_); 2057 PostSetDeferCommitsToMainThread(true);
2049 layer_tree_host()->SetDeferCommits(true);
2050 PostSetNeedsCommitToMainThread();
2051 break; 2058 break;
2052 case 2: 2059 case 2:
2053 EndTest(); 2060 EndTest();
2054 break; 2061 break;
2055 default: 2062 default:
2056 NOTREACHED(); 2063 NOTREACHED();
2057 break; 2064 break;
2058 } 2065 }
2059 } 2066 }
2060 2067
2061 void AfterTest() override { 2068 void AfterTest() override {
2062 EXPECT_EQ(1, num_commits_deferred_); 2069 EXPECT_GE(3, num_will_begin_impl_frame_);
2063 EXPECT_EQ(2, num_complete_commits_); 2070 EXPECT_EQ(2, num_send_begin_main_frame_);
2064 } 2071 }
2065 2072
2066 private: 2073 private:
2067 int num_commits_deferred_; 2074 int num_will_begin_impl_frame_;
2068 int num_complete_commits_; 2075 int num_send_begin_main_frame_;
2069 }; 2076 };
2070 2077
2071 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestDeferCommits); 2078 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestDeferCommits);
2072 2079
2073 class LayerTreeHostWithProxy : public LayerTreeHost { 2080 class LayerTreeHostWithProxy : public LayerTreeHost {
2074 public: 2081 public:
2075 LayerTreeHostWithProxy(FakeLayerTreeHostClient* client, 2082 LayerTreeHostWithProxy(FakeLayerTreeHostClient* client,
2076 const LayerTreeSettings& settings, 2083 const LayerTreeSettings& settings,
2077 scoped_ptr<FakeProxy> proxy) 2084 scoped_ptr<FakeProxy> proxy)
2078 : LayerTreeHost(client, NULL, NULL, settings) { 2085 : LayerTreeHost(client, NULL, NULL, settings) {
(...skipping 2693 matching lines...) Expand 10 before | Expand all | Expand 10 after
4772 4779
4773 void AfterTest() override {} 4780 void AfterTest() override {}
4774 4781
4775 private: 4782 private:
4776 scoped_refptr<Layer> layer_; 4783 scoped_refptr<Layer> layer_;
4777 TestSwapPromiseResult swap_promise_result_; 4784 TestSwapPromiseResult swap_promise_result_;
4778 }; 4785 };
4779 4786
4780 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestKeepSwapPromise); 4787 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestKeepSwapPromise);
4781 4788
4782 class LayerTreeHostTestBreakSwapPromiseForVisibilityAbortedCommit 4789 class LayerTreeHostTestBreakSwapPromiseForVisibility
4783 : public LayerTreeHostTest { 4790 : public LayerTreeHostTest {
4784 protected: 4791 protected:
4785 void BeginTest() override { PostSetNeedsCommitToMainThread(); } 4792 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
4786 4793
4787 void DidCommit() override { 4794 void SetVisibleFalseAndQueueSwapPromise() {
4788 layer_tree_host()->SetDeferCommits(true);
4789 layer_tree_host()->SetNeedsCommit();
4790 }
4791
4792 void DidDeferCommit() override {
4793 layer_tree_host()->SetVisible(false); 4795 layer_tree_host()->SetVisible(false);
4794 scoped_ptr<SwapPromise> swap_promise( 4796 scoped_ptr<SwapPromise> swap_promise(
4795 new TestSwapPromise(&swap_promise_result_)); 4797 new TestSwapPromise(&swap_promise_result_));
4796 layer_tree_host()->QueueSwapPromise(swap_promise.Pass()); 4798 layer_tree_host()->QueueSwapPromise(swap_promise.Pass());
4797 layer_tree_host()->SetDeferCommits(false); 4799 }
4800
4801 void ScheduledActionWillSendBeginMainFrame() override {
4802 MainThreadTaskRunner()->PostTask(
4803 FROM_HERE,
4804 base::Bind(&LayerTreeHostTestBreakSwapPromiseForVisibility
4805 ::SetVisibleFalseAndQueueSwapPromise,
4806 base::Unretained(this)));
4798 } 4807 }
4799 4808
4800 void BeginMainFrameAbortedOnThread(LayerTreeHostImpl* host_impl, 4809 void BeginMainFrameAbortedOnThread(LayerTreeHostImpl* host_impl,
4801 CommitEarlyOutReason reason) override { 4810 CommitEarlyOutReason reason) override {
4802 EndTest(); 4811 EndTest();
4803 } 4812 }
4804 4813
4805 void AfterTest() override { 4814 void AfterTest() override {
4806 { 4815 {
4807 base::AutoLock lock(swap_promise_result_.lock); 4816 base::AutoLock lock(swap_promise_result_.lock);
4808 EXPECT_FALSE(swap_promise_result_.did_swap_called); 4817 EXPECT_FALSE(swap_promise_result_.did_swap_called);
4809 EXPECT_TRUE(swap_promise_result_.did_not_swap_called); 4818 EXPECT_TRUE(swap_promise_result_.did_not_swap_called);
4810 EXPECT_EQ(SwapPromise::COMMIT_FAILS, swap_promise_result_.reason); 4819 EXPECT_EQ(SwapPromise::COMMIT_FAILS, swap_promise_result_.reason);
4811 EXPECT_TRUE(swap_promise_result_.dtor_called); 4820 EXPECT_TRUE(swap_promise_result_.dtor_called);
4812 } 4821 }
4813 } 4822 }
4814 4823
4815 TestSwapPromiseResult swap_promise_result_; 4824 TestSwapPromiseResult swap_promise_result_;
4816 }; 4825 };
4817 4826
4818 SINGLE_AND_MULTI_THREAD_TEST_F( 4827 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestBreakSwapPromiseForVisibility);
4819 LayerTreeHostTestBreakSwapPromiseForVisibilityAbortedCommit);
4820 4828
4821 class LayerTreeHostTestBreakSwapPromiseForContextAbortedCommit 4829 class LayerTreeHostTestBreakSwapPromiseForContext : public LayerTreeHostTest {
4822 : public LayerTreeHostTest {
4823 protected: 4830 protected:
4831 LayerTreeHostTestBreakSwapPromiseForContext()
4832 : output_surface_lost_triggered_(false) {
4833 }
4834
4824 void BeginTest() override { PostSetNeedsCommitToMainThread(); } 4835 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
4825 4836
4826 void DidCommit() override { 4837 void LoseOutputSurfaceAndQueueSwapPromise() {
4827 if (TestEnded())
4828 return;
4829 layer_tree_host()->SetDeferCommits(true);
4830 layer_tree_host()->SetNeedsCommit();
4831 }
4832
4833 void DidDeferCommit() override {
4834 layer_tree_host()->DidLoseOutputSurface(); 4838 layer_tree_host()->DidLoseOutputSurface();
4835 scoped_ptr<SwapPromise> swap_promise( 4839 scoped_ptr<SwapPromise> swap_promise(
4836 new TestSwapPromise(&swap_promise_result_)); 4840 new TestSwapPromise(&swap_promise_result_));
4837 layer_tree_host()->QueueSwapPromise(swap_promise.Pass()); 4841 layer_tree_host()->QueueSwapPromise(swap_promise.Pass());
4838 layer_tree_host()->SetDeferCommits(false); 4842 }
4843
4844 void ScheduledActionWillSendBeginMainFrame() override {
4845 if (output_surface_lost_triggered_)
4846 return;
4847 output_surface_lost_triggered_ = true;
4848
4849 MainThreadTaskRunner()->PostTask(
4850 FROM_HERE,
4851 base::Bind(&LayerTreeHostTestBreakSwapPromiseForContext
4852 ::LoseOutputSurfaceAndQueueSwapPromise,
4853 base::Unretained(this)));
4839 } 4854 }
4840 4855
4841 void BeginMainFrameAbortedOnThread(LayerTreeHostImpl* host_impl, 4856 void BeginMainFrameAbortedOnThread(LayerTreeHostImpl* host_impl,
4842 CommitEarlyOutReason reason) override { 4857 CommitEarlyOutReason reason) override {
4843 // This is needed so that the impl-thread state matches main-thread state. 4858 // This is needed so that the impl-thread state matches main-thread state.
4844 host_impl->DidLoseOutputSurface(); 4859 host_impl->DidLoseOutputSurface();
4845 EndTest(); 4860 EndTest();
4846 } 4861 }
4847 4862
4848 void AfterTest() override { 4863 void AfterTest() override {
4849 { 4864 {
4850 base::AutoLock lock(swap_promise_result_.lock); 4865 base::AutoLock lock(swap_promise_result_.lock);
4851 EXPECT_FALSE(swap_promise_result_.did_swap_called); 4866 EXPECT_FALSE(swap_promise_result_.did_swap_called);
4852 EXPECT_TRUE(swap_promise_result_.did_not_swap_called); 4867 EXPECT_TRUE(swap_promise_result_.did_not_swap_called);
4853 EXPECT_EQ(SwapPromise::COMMIT_FAILS, swap_promise_result_.reason); 4868 EXPECT_EQ(SwapPromise::COMMIT_FAILS, swap_promise_result_.reason);
4854 EXPECT_TRUE(swap_promise_result_.dtor_called); 4869 EXPECT_TRUE(swap_promise_result_.dtor_called);
4855 } 4870 }
4856 } 4871 }
4857 4872
4873 bool output_surface_lost_triggered_;
4858 TestSwapPromiseResult swap_promise_result_; 4874 TestSwapPromiseResult swap_promise_result_;
4859 }; 4875 };
4860 4876
4861 SINGLE_AND_MULTI_THREAD_TEST_F( 4877 SINGLE_AND_MULTI_THREAD_TEST_F(
4862 LayerTreeHostTestBreakSwapPromiseForContextAbortedCommit); 4878 LayerTreeHostTestBreakSwapPromiseForContext);
4863 4879
4864 class SimpleSwapPromiseMonitor : public SwapPromiseMonitor { 4880 class SimpleSwapPromiseMonitor : public SwapPromiseMonitor {
4865 public: 4881 public:
4866 SimpleSwapPromiseMonitor(LayerTreeHost* layer_tree_host, 4882 SimpleSwapPromiseMonitor(LayerTreeHost* layer_tree_host,
4867 LayerTreeHostImpl* layer_tree_host_impl, 4883 LayerTreeHostImpl* layer_tree_host_impl,
4868 int* set_needs_commit_count, 4884 int* set_needs_commit_count,
4869 int* set_needs_redraw_count) 4885 int* set_needs_redraw_count)
4870 : SwapPromiseMonitor(layer_tree_host, layer_tree_host_impl), 4886 : SwapPromiseMonitor(layer_tree_host, layer_tree_host_impl),
4871 set_needs_commit_count_(set_needs_commit_count) {} 4887 set_needs_commit_count_(set_needs_commit_count) {}
4872 4888
(...skipping 1282 matching lines...) Expand 10 before | Expand all | Expand 10 after
6155 6171
6156 void AfterTest() override { EXPECT_TRUE(did_commit_); } 6172 void AfterTest() override { EXPECT_TRUE(did_commit_); }
6157 6173
6158 private: 6174 private:
6159 bool did_commit_; 6175 bool did_commit_;
6160 }; 6176 };
6161 6177
6162 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNoTasksBetweenWillAndDidCommit); 6178 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNoTasksBetweenWillAndDidCommit);
6163 6179
6164 } // namespace cc 6180 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_impl_unittest.cc ('k') | cc/trees/layer_tree_host_unittest_animation.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698