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

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

Issue 672283003: cc: ReadyToDraw notifications. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix counting of required for activation tiles. Created 6 years, 1 month 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
« no previous file with comments | « cc/trees/layer_tree_host_impl_unittest.cc ('k') | cc/trees/single_thread_proxy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 using testing::_; 62 using testing::_;
63 using testing::AnyNumber; 63 using testing::AnyNumber;
64 using testing::AtLeast; 64 using testing::AtLeast;
65 using testing::Mock; 65 using testing::Mock;
66 66
67 namespace cc { 67 namespace cc {
68 namespace { 68 namespace {
69 69
70 class LayerTreeHostTest : public LayerTreeTest {}; 70 class LayerTreeHostTest : public LayerTreeTest {};
71 71
72 // Test if the LTHI receives ReadyToActivate notifications from the TileManager
73 // when no raster tasks get scheduled.
74 class LayerTreeHostTestReadyToActivateEmpty : public LayerTreeHostTest {
75 public:
76 LayerTreeHostTestReadyToActivateEmpty()
77 : did_notify_ready_to_activate_(false),
78 all_tiles_required_for_activation_are_ready_to_draw_(false),
79 required_for_activation_count_(0) {}
80
81 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
82
83 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
84 const std::vector<PictureLayerImpl*>& layers = impl->GetPictureLayers();
85 required_for_activation_count_ = 0;
86 for (const auto& layer : layers) {
87 FakePictureLayerImpl* fake_layer =
88 static_cast<FakePictureLayerImpl*>(layer);
89 required_for_activation_count_ +=
90 fake_layer->CountTilesRequiredForActivation();
91 }
92 }
93
94 void NotifyReadyToActivateOnThread(LayerTreeHostImpl* impl) override {
95 did_notify_ready_to_activate_ = true;
96 const std::vector<PictureLayerImpl*>& layers = impl->GetPictureLayers();
97 all_tiles_required_for_activation_are_ready_to_draw_ = true;
98 for (const auto& layer : layers) {
99 if (!layer->AllTilesRequiredForActivationAreReadyToDraw())
100 all_tiles_required_for_activation_are_ready_to_draw_ = false;
101 }
102 EndTest();
103 }
104
105 void AfterTest() override {
106 EXPECT_TRUE(did_notify_ready_to_activate_);
107 EXPECT_TRUE(all_tiles_required_for_activation_are_ready_to_draw_);
108 EXPECT_EQ(size_t(0), required_for_activation_count_);
109 }
110
111 protected:
112 bool did_notify_ready_to_activate_;
113 bool all_tiles_required_for_activation_are_ready_to_draw_;
114 size_t required_for_activation_count_;
115 };
116
117 SINGLE_AND_MULTI_THREAD_IMPL_TEST_F(LayerTreeHostTestReadyToActivateEmpty);
118
119 // Test if the LTHI receives ReadyToActivate notifications from the TileManager
120 // when some raster tasks flagged as REQUIRED_FOR_ACTIVATION got scheduled.
121 class LayerTreeHostTestReadyToActivateNonEmpty
122 : public LayerTreeHostTestReadyToActivateEmpty {
123 public:
124 void SetupTree() override {
125 client_.set_fill_with_nonsolid_color(true);
126 scoped_refptr<FakePictureLayer> root_layer =
127 FakePictureLayer::Create(&client_);
128 root_layer->SetBounds(gfx::Size(1024, 1024));
129 root_layer->SetIsDrawable(true);
130
131 layer_tree_host()->SetRootLayer(root_layer);
132 LayerTreeHostTest::SetupTree();
133 }
134
135 void AfterTest() override {
136 EXPECT_TRUE(did_notify_ready_to_activate_);
137 EXPECT_TRUE(all_tiles_required_for_activation_are_ready_to_draw_);
138 EXPECT_LE(size_t(1), required_for_activation_count_);
139 }
140
141 private:
142 FakeContentLayerClient client_;
143 };
144
145 SINGLE_AND_MULTI_THREAD_IMPL_TEST_F(LayerTreeHostTestReadyToActivateNonEmpty);
146
147 // Test if the LTHI receives ReadyToDraw notifications from the TileManager when
148 // no raster tasks get scheduled.
149 class LayerTreeHostTestReadyToDrawEmpty : public LayerTreeHostTest {
150 public:
151 LayerTreeHostTestReadyToDrawEmpty()
152 : did_notify_ready_to_draw_(false),
153 all_tiles_required_for_draw_are_ready_to_draw_(false),
154 required_for_draw_count_(0) {}
155
156 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
157
158 void NotifyReadyToDrawOnThread(LayerTreeHostImpl* impl) override {
159 did_notify_ready_to_draw_ = true;
160 const std::vector<PictureLayerImpl*>& layers = impl->GetPictureLayers();
161 all_tiles_required_for_draw_are_ready_to_draw_ = true;
162 for (const auto& layer : layers) {
163 if (!layer->AllTilesRequiredForDrawAreReadyToDraw())
164 all_tiles_required_for_draw_are_ready_to_draw_ = false;
165 FakePictureLayerImpl* fake_layer =
166 static_cast<FakePictureLayerImpl*>(layer);
167 required_for_draw_count_ += fake_layer->CountTilesRequiredForDraw();
168 }
169
170 EndTest();
171 }
172
173 void AfterTest() override {
174 EXPECT_TRUE(did_notify_ready_to_draw_);
175 EXPECT_TRUE(all_tiles_required_for_draw_are_ready_to_draw_);
176 EXPECT_EQ(size_t(0), required_for_draw_count_);
177 }
178
179 protected:
180 bool did_notify_ready_to_draw_;
181 bool all_tiles_required_for_draw_are_ready_to_draw_;
182 size_t required_for_draw_count_;
183 };
184
185 SINGLE_AND_MULTI_THREAD_IMPL_TEST_F(LayerTreeHostTestReadyToDrawEmpty);
186
187 // Test if the LTHI receives ReadyToDraw notifications from the TileManager when
188 // some raster tasks flagged as REQUIRED_FOR_DRAW got scheduled.
189 class LayerTreeHostTestReadyToDrawNonEmpty
190 : public LayerTreeHostTestReadyToDrawEmpty {
191 public:
192 void SetupTree() override {
193 client_.set_fill_with_nonsolid_color(true);
194 scoped_refptr<FakePictureLayer> root_layer =
195 FakePictureLayer::Create(&client_);
196 root_layer->SetBounds(gfx::Size(1024, 1024));
197 root_layer->SetIsDrawable(true);
198
199 layer_tree_host()->SetRootLayer(root_layer);
200 LayerTreeHostTest::SetupTree();
201 }
202
203 void AfterTest() override {
204 EXPECT_TRUE(did_notify_ready_to_draw_);
205 EXPECT_TRUE(all_tiles_required_for_draw_are_ready_to_draw_);
206 EXPECT_LE(size_t(1), required_for_draw_count_);
207 }
208
209 private:
210 FakeContentLayerClient client_;
211 };
212
213 // Note: With this test setup, we only get tiles flagged as REQUIRED_FOR_DRAW in
214 // single threaded mode.
215 SINGLE_THREAD_IMPL_TEST_F(LayerTreeHostTestReadyToDrawNonEmpty);
216
72 // Two setNeedsCommits in a row should lead to at least 1 commit and at least 1 217 // Two setNeedsCommits in a row should lead to at least 1 commit and at least 1
73 // draw with frame 0. 218 // draw with frame 0.
74 class LayerTreeHostTestSetNeedsCommit1 : public LayerTreeHostTest { 219 class LayerTreeHostTestSetNeedsCommit1 : public LayerTreeHostTest {
75 public: 220 public:
76 LayerTreeHostTestSetNeedsCommit1() : num_commits_(0), num_draws_(0) {} 221 LayerTreeHostTestSetNeedsCommit1() : num_commits_(0), num_draws_(0) {}
77 222
78 void BeginTest() override { 223 void BeginTest() override {
79 PostSetNeedsCommitToMainThread(); 224 PostSetNeedsCommitToMainThread();
80 PostSetNeedsCommitToMainThread(); 225 PostSetNeedsCommitToMainThread();
81 } 226 }
(...skipping 5117 matching lines...) Expand 10 before | Expand all | Expand 10 after
5199 void AfterTest() override { 5344 void AfterTest() override {
5200 EXPECT_TRUE(deltas_sent_to_client_); 5345 EXPECT_TRUE(deltas_sent_to_client_);
5201 } 5346 }
5202 5347
5203 ScrollAndScaleSet info_; 5348 ScrollAndScaleSet info_;
5204 bool deltas_sent_to_client_; 5349 bool deltas_sent_to_client_;
5205 }; 5350 };
5206 5351
5207 MULTI_THREAD_TEST_F(LayerTreeHostAcceptsDeltasFromImplWithoutRootLayer); 5352 MULTI_THREAD_TEST_F(LayerTreeHostAcceptsDeltasFromImplWithoutRootLayer);
5208 } // namespace cc 5353 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_impl_unittest.cc ('k') | cc/trees/single_thread_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698