OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/compiler_specific.h" | 5 #include "base/compiler_specific.h" |
6 #include "base/macros.h" | 6 #include "base/macros.h" |
7 #include "cc/test/fake_content_layer_client.h" | 7 #include "cc/test/fake_content_layer_client.h" |
8 #include "cc/test/fake_picture_layer.h" | 8 #include "cc/test/fake_picture_layer.h" |
9 #include "cc/test/layer_tree_test.h" | 9 #include "cc/test/layer_tree_test.h" |
10 #include "cc/trees/proxy_impl.h" | 10 #include "cc/trees/proxy_impl.h" |
11 #include "cc/trees/proxy_main.h" | 11 #include "cc/trees/proxy_main.h" |
12 | 12 |
13 #define PROXY_MAIN_THREADED_TEST_F(TEST_FIXTURE_NAME) \ | |
14 TEST_F(TEST_FIXTURE_NAME, MultiThread) { Run(true); } | |
15 | |
16 // Do common tests for single thread proxy and proxy main in threaded mode. | |
17 // TODO(simonhong): Add SINGLE_THREAD_PROXY_TEST_F | |
18 #define PROXY_TEST_SCHEDULED_ACTION(TEST_FIXTURE_NAME) \ | |
19 PROXY_MAIN_THREADED_TEST_F(TEST_FIXTURE_NAME); | |
20 | |
21 namespace cc { | 13 namespace cc { |
22 | 14 |
23 class ProxyTest : public LayerTreeTest { | 15 class LayerTreeHostProxyTest : public LayerTreeTest { |
24 protected: | 16 protected: |
25 ProxyTest() {} | |
26 ~ProxyTest() override {} | |
27 | |
28 void Run(bool threaded) { | |
29 // We don't need to care about delegating mode. | |
30 bool delegating_renderer = true; | |
31 | |
32 CompositorMode mode = | |
33 threaded ? CompositorMode::THREADED : CompositorMode::SINGLE_THREADED; | |
34 RunTest(mode, delegating_renderer); | |
35 } | |
36 | |
37 void BeginTest() override {} | |
38 void AfterTest() override {} | |
39 | |
40 private: | |
41 DISALLOW_COPY_AND_ASSIGN(ProxyTest); | |
42 }; | |
43 | |
44 class ProxyTestScheduledActionsBasic : public ProxyTest { | |
45 protected: | |
46 void BeginTest() override { proxy()->SetNeedsCommit(); } | |
47 | |
48 void ScheduledActionBeginOutputSurfaceCreation() override { | |
49 EXPECT_EQ(0, action_phase_++); | |
50 } | |
51 | |
52 void ScheduledActionSendBeginMainFrame() override { | |
53 EXPECT_EQ(1, action_phase_++); | |
54 } | |
55 | |
56 void ScheduledActionCommit() override { EXPECT_EQ(2, action_phase_++); } | |
57 | |
58 void ScheduledActionDrawAndSwapIfPossible() override { | |
59 EXPECT_EQ(3, action_phase_++); | |
60 EndTest(); | |
61 } | |
62 | |
63 void AfterTest() override { EXPECT_EQ(4, action_phase_); } | |
64 | |
65 ProxyTestScheduledActionsBasic() : action_phase_(0) { | |
66 } | |
67 ~ProxyTestScheduledActionsBasic() override {} | |
68 | |
69 private: | |
70 int action_phase_; | |
71 | |
72 DISALLOW_COPY_AND_ASSIGN(ProxyTestScheduledActionsBasic); | |
73 }; | |
74 | |
75 PROXY_TEST_SCHEDULED_ACTION(ProxyTestScheduledActionsBasic); | |
76 | |
77 class ProxyMainThreaded : public ProxyTest { | |
78 protected: | |
79 ProxyMainThreaded() | |
80 : update_check_layer_(FakePictureLayer::Create(&client_)) {} | |
81 ~ProxyMainThreaded() override {} | |
82 | |
83 void SetupTree() override { | 17 void SetupTree() override { |
| 18 update_check_layer_ = FakePictureLayer::Create(&client_); |
84 layer_tree_host()->SetRootLayer(update_check_layer_); | 19 layer_tree_host()->SetRootLayer(update_check_layer_); |
85 ProxyTest::SetupTree(); | 20 LayerTreeTest::SetupTree(); |
86 client_.set_bounds(update_check_layer_->bounds()); | 21 client_.set_bounds(update_check_layer_->bounds()); |
87 } | 22 } |
88 | 23 |
89 protected: | 24 FakePictureLayer* update_check_layer() const { |
| 25 return update_check_layer_.get(); |
| 26 } |
| 27 |
| 28 ProxyMain* GetProxyMain() const { |
| 29 DCHECK(HasImplThread()); |
| 30 return static_cast<ProxyMain*>(proxy()); |
| 31 } |
| 32 |
| 33 private: |
90 FakeContentLayerClient client_; | 34 FakeContentLayerClient client_; |
91 scoped_refptr<FakePictureLayer> update_check_layer_; | 35 scoped_refptr<FakePictureLayer> update_check_layer_; |
92 | 36 }; |
93 private: | 37 |
94 DISALLOW_COPY_AND_ASSIGN(ProxyMainThreaded); | 38 class LayerTreeHostProxyTestSetNeedsCommit : public LayerTreeHostProxyTest { |
95 }; | 39 protected: |
96 | 40 LayerTreeHostProxyTestSetNeedsCommit() {} |
97 class ProxyMainThreadedSetNeedsCommit : public ProxyMainThreaded { | 41 ~LayerTreeHostProxyTestSetNeedsCommit() override {} |
98 protected: | |
99 ProxyMainThreadedSetNeedsCommit() {} | |
100 ~ProxyMainThreadedSetNeedsCommit() override {} | |
101 | 42 |
102 void BeginTest() override { | 43 void BeginTest() override { |
103 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, | 44 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, |
104 GetProxyMainForTest()->max_requested_pipeline_stage()); | 45 GetProxyMain()->max_requested_pipeline_stage()); |
105 | 46 |
106 proxy()->SetNeedsCommit(); | 47 proxy()->SetNeedsCommit(); |
107 | 48 |
108 EXPECT_EQ(ProxyMain::COMMIT_PIPELINE_STAGE, | 49 EXPECT_EQ(ProxyMain::COMMIT_PIPELINE_STAGE, |
109 GetProxyMainForTest()->max_requested_pipeline_stage()); | 50 GetProxyMain()->max_requested_pipeline_stage()); |
110 } | 51 } |
111 | 52 |
112 void DidBeginMainFrame() override { | 53 void DidBeginMainFrame() override { |
113 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, | 54 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, |
114 GetProxyMainForTest()->max_requested_pipeline_stage()); | 55 GetProxyMain()->max_requested_pipeline_stage()); |
115 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, | 56 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, |
116 GetProxyMainForTest()->current_pipeline_stage()); | 57 GetProxyMain()->current_pipeline_stage()); |
117 } | 58 } |
118 | 59 |
119 void DidCommit() override { | 60 void DidCommit() override { |
120 EXPECT_EQ(1, update_check_layer_->update_count()); | 61 EXPECT_EQ(1, update_check_layer()->update_count()); |
121 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, | 62 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, |
122 GetProxyMainForTest()->current_pipeline_stage()); | 63 GetProxyMain()->current_pipeline_stage()); |
123 EndTest(); | 64 EndTest(); |
124 } | 65 } |
125 | 66 |
126 private: | 67 void AfterTest() override {} |
127 DISALLOW_COPY_AND_ASSIGN(ProxyMainThreadedSetNeedsCommit); | 68 |
128 }; | 69 private: |
129 | 70 DISALLOW_COPY_AND_ASSIGN(LayerTreeHostProxyTestSetNeedsCommit); |
130 PROXY_MAIN_THREADED_TEST_F(ProxyMainThreadedSetNeedsCommit); | 71 }; |
131 | 72 |
132 class ProxyMainThreadedSetNeedsAnimate : public ProxyMainThreaded { | 73 MULTI_THREAD_TEST_F(LayerTreeHostProxyTestSetNeedsCommit); |
133 protected: | 74 |
134 ProxyMainThreadedSetNeedsAnimate() {} | 75 class LayerTreeHostProxyTestSetNeedsAnimate : public LayerTreeHostProxyTest { |
135 ~ProxyMainThreadedSetNeedsAnimate() override {} | 76 protected: |
| 77 LayerTreeHostProxyTestSetNeedsAnimate() {} |
| 78 ~LayerTreeHostProxyTestSetNeedsAnimate() override {} |
136 | 79 |
137 void BeginTest() override { | 80 void BeginTest() override { |
138 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, | 81 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, |
139 GetProxyMainForTest()->max_requested_pipeline_stage()); | 82 GetProxyMain()->max_requested_pipeline_stage()); |
140 | 83 |
141 proxy()->SetNeedsAnimate(); | 84 proxy()->SetNeedsAnimate(); |
142 | 85 |
143 EXPECT_EQ(ProxyMain::ANIMATE_PIPELINE_STAGE, | 86 EXPECT_EQ(ProxyMain::ANIMATE_PIPELINE_STAGE, |
144 GetProxyMainForTest()->max_requested_pipeline_stage()); | 87 GetProxyMain()->max_requested_pipeline_stage()); |
145 } | 88 } |
146 | 89 |
147 void DidBeginMainFrame() override { | 90 void DidBeginMainFrame() override { |
148 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, | 91 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, |
149 GetProxyMainForTest()->max_requested_pipeline_stage()); | 92 GetProxyMain()->max_requested_pipeline_stage()); |
150 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, | 93 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, |
151 GetProxyMainForTest()->current_pipeline_stage()); | 94 GetProxyMain()->current_pipeline_stage()); |
152 } | 95 } |
153 | 96 |
154 void DidCommit() override { | 97 void DidCommit() override { |
155 EXPECT_EQ(0, update_check_layer_->update_count()); | 98 EXPECT_EQ(0, update_check_layer()->update_count()); |
156 EndTest(); | 99 EndTest(); |
157 } | 100 } |
158 | 101 |
159 private: | 102 void AfterTest() override {} |
160 DISALLOW_COPY_AND_ASSIGN(ProxyMainThreadedSetNeedsAnimate); | 103 |
161 }; | 104 private: |
162 | 105 DISALLOW_COPY_AND_ASSIGN(LayerTreeHostProxyTestSetNeedsAnimate); |
163 PROXY_MAIN_THREADED_TEST_F(ProxyMainThreadedSetNeedsAnimate); | 106 }; |
164 | 107 |
165 class ProxyMainThreadedSetNeedsUpdateLayers : public ProxyMainThreaded { | 108 MULTI_THREAD_TEST_F(LayerTreeHostProxyTestSetNeedsAnimate); |
166 protected: | 109 |
167 ProxyMainThreadedSetNeedsUpdateLayers() {} | 110 class LayerTreeHostProxyTestSetNeedsUpdateLayers |
168 ~ProxyMainThreadedSetNeedsUpdateLayers() override {} | 111 : public LayerTreeHostProxyTest { |
| 112 protected: |
| 113 LayerTreeHostProxyTestSetNeedsUpdateLayers() {} |
| 114 ~LayerTreeHostProxyTestSetNeedsUpdateLayers() override {} |
169 | 115 |
170 void BeginTest() override { | 116 void BeginTest() override { |
171 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, | 117 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, |
172 GetProxyMainForTest()->max_requested_pipeline_stage()); | 118 GetProxyMain()->max_requested_pipeline_stage()); |
173 | 119 |
174 proxy()->SetNeedsUpdateLayers(); | 120 proxy()->SetNeedsUpdateLayers(); |
175 | 121 |
176 EXPECT_EQ(ProxyMain::UPDATE_LAYERS_PIPELINE_STAGE, | 122 EXPECT_EQ(ProxyMain::UPDATE_LAYERS_PIPELINE_STAGE, |
177 GetProxyMainForTest()->max_requested_pipeline_stage()); | 123 GetProxyMain()->max_requested_pipeline_stage()); |
178 } | 124 } |
179 | 125 |
180 void DidBeginMainFrame() override { | 126 void DidBeginMainFrame() override { |
181 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, | 127 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, |
182 GetProxyMainForTest()->max_requested_pipeline_stage()); | 128 GetProxyMain()->max_requested_pipeline_stage()); |
183 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, | 129 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, |
184 GetProxyMainForTest()->current_pipeline_stage()); | 130 GetProxyMain()->current_pipeline_stage()); |
185 } | 131 } |
186 | 132 |
187 void DidCommit() override { | 133 void DidCommit() override { |
188 EXPECT_EQ(1, update_check_layer_->update_count()); | 134 EXPECT_EQ(1, update_check_layer()->update_count()); |
189 EndTest(); | 135 EndTest(); |
190 } | 136 } |
191 | 137 |
192 private: | 138 void AfterTest() override {} |
193 DISALLOW_COPY_AND_ASSIGN(ProxyMainThreadedSetNeedsUpdateLayers); | 139 |
194 }; | 140 private: |
195 | 141 DISALLOW_COPY_AND_ASSIGN(LayerTreeHostProxyTestSetNeedsUpdateLayers); |
196 PROXY_MAIN_THREADED_TEST_F(ProxyMainThreadedSetNeedsUpdateLayers); | 142 }; |
197 | 143 |
198 class ProxyMainThreadedSetNeedsUpdateLayersWhileAnimating | 144 MULTI_THREAD_TEST_F(LayerTreeHostProxyTestSetNeedsUpdateLayers); |
199 : public ProxyMainThreaded { | 145 |
200 protected: | 146 class LayerTreeHostProxyTestSetNeedsUpdateLayersWhileAnimating |
201 ProxyMainThreadedSetNeedsUpdateLayersWhileAnimating() {} | 147 : public LayerTreeHostProxyTest { |
202 ~ProxyMainThreadedSetNeedsUpdateLayersWhileAnimating() override {} | 148 protected: |
| 149 LayerTreeHostProxyTestSetNeedsUpdateLayersWhileAnimating() {} |
| 150 ~LayerTreeHostProxyTestSetNeedsUpdateLayersWhileAnimating() override {} |
203 | 151 |
204 void BeginTest() override { proxy()->SetNeedsAnimate(); } | 152 void BeginTest() override { proxy()->SetNeedsAnimate(); } |
205 | 153 |
206 void WillBeginMainFrame() override { | 154 void WillBeginMainFrame() override { |
207 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, | 155 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, |
208 GetProxyMainForTest()->max_requested_pipeline_stage()); | 156 GetProxyMain()->max_requested_pipeline_stage()); |
209 EXPECT_EQ(ProxyMain::ANIMATE_PIPELINE_STAGE, | 157 EXPECT_EQ(ProxyMain::ANIMATE_PIPELINE_STAGE, |
210 GetProxyMainForTest()->current_pipeline_stage()); | 158 GetProxyMain()->current_pipeline_stage()); |
211 EXPECT_EQ(ProxyMain::ANIMATE_PIPELINE_STAGE, | 159 EXPECT_EQ(ProxyMain::ANIMATE_PIPELINE_STAGE, |
212 GetProxyMainForTest()->final_pipeline_stage()); | 160 GetProxyMain()->final_pipeline_stage()); |
213 | 161 |
214 proxy()->SetNeedsUpdateLayers(); | 162 proxy()->SetNeedsUpdateLayers(); |
215 | 163 |
216 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, | 164 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, |
217 GetProxyMainForTest()->max_requested_pipeline_stage()); | 165 GetProxyMain()->max_requested_pipeline_stage()); |
218 EXPECT_EQ(ProxyMain::UPDATE_LAYERS_PIPELINE_STAGE, | 166 EXPECT_EQ(ProxyMain::UPDATE_LAYERS_PIPELINE_STAGE, |
219 GetProxyMainForTest()->final_pipeline_stage()); | 167 GetProxyMain()->final_pipeline_stage()); |
220 } | 168 } |
221 | 169 |
222 void DidBeginMainFrame() override { | 170 void DidBeginMainFrame() override { |
223 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, | 171 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, |
224 GetProxyMainForTest()->max_requested_pipeline_stage()); | 172 GetProxyMain()->max_requested_pipeline_stage()); |
225 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, | 173 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, |
226 GetProxyMainForTest()->current_pipeline_stage()); | 174 GetProxyMain()->current_pipeline_stage()); |
227 } | 175 } |
228 | 176 |
229 void DidCommit() override { | 177 void DidCommit() override { |
230 EXPECT_EQ(1, update_check_layer_->update_count()); | 178 EXPECT_EQ(1, update_check_layer()->update_count()); |
231 EndTest(); | 179 EndTest(); |
232 } | 180 } |
233 | 181 |
234 private: | 182 void AfterTest() override {} |
235 DISALLOW_COPY_AND_ASSIGN(ProxyMainThreadedSetNeedsUpdateLayersWhileAnimating); | 183 |
236 }; | 184 private: |
237 | 185 DISALLOW_COPY_AND_ASSIGN( |
238 PROXY_MAIN_THREADED_TEST_F(ProxyMainThreadedSetNeedsUpdateLayersWhileAnimating); | 186 LayerTreeHostProxyTestSetNeedsUpdateLayersWhileAnimating); |
239 | 187 }; |
240 class ProxyMainThreadedSetNeedsCommitWhileAnimating : public ProxyMainThreaded { | 188 |
241 protected: | 189 MULTI_THREAD_TEST_F(LayerTreeHostProxyTestSetNeedsUpdateLayersWhileAnimating); |
242 ProxyMainThreadedSetNeedsCommitWhileAnimating() {} | 190 |
243 ~ProxyMainThreadedSetNeedsCommitWhileAnimating() override {} | 191 class LayerTreeHostProxyTestSetNeedsCommitWhileAnimating |
| 192 : public LayerTreeHostProxyTest { |
| 193 protected: |
| 194 LayerTreeHostProxyTestSetNeedsCommitWhileAnimating() {} |
| 195 ~LayerTreeHostProxyTestSetNeedsCommitWhileAnimating() override {} |
244 | 196 |
245 void BeginTest() override { proxy()->SetNeedsAnimate(); } | 197 void BeginTest() override { proxy()->SetNeedsAnimate(); } |
246 | 198 |
247 void WillBeginMainFrame() override { | 199 void WillBeginMainFrame() override { |
248 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, | 200 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, |
249 GetProxyMainForTest()->max_requested_pipeline_stage()); | 201 GetProxyMain()->max_requested_pipeline_stage()); |
250 EXPECT_EQ(ProxyMain::ANIMATE_PIPELINE_STAGE, | 202 EXPECT_EQ(ProxyMain::ANIMATE_PIPELINE_STAGE, |
251 GetProxyMainForTest()->current_pipeline_stage()); | 203 GetProxyMain()->current_pipeline_stage()); |
252 EXPECT_EQ(ProxyMain::ANIMATE_PIPELINE_STAGE, | 204 EXPECT_EQ(ProxyMain::ANIMATE_PIPELINE_STAGE, |
253 GetProxyMainForTest()->final_pipeline_stage()); | 205 GetProxyMain()->final_pipeline_stage()); |
254 | 206 |
255 proxy()->SetNeedsCommit(); | 207 proxy()->SetNeedsCommit(); |
256 | 208 |
257 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, | 209 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, |
258 GetProxyMainForTest()->max_requested_pipeline_stage()); | 210 GetProxyMain()->max_requested_pipeline_stage()); |
259 EXPECT_EQ(ProxyMain::COMMIT_PIPELINE_STAGE, | 211 EXPECT_EQ(ProxyMain::COMMIT_PIPELINE_STAGE, |
260 GetProxyMainForTest()->final_pipeline_stage()); | 212 GetProxyMain()->final_pipeline_stage()); |
261 } | 213 } |
262 | 214 |
263 void DidBeginMainFrame() override { | 215 void DidBeginMainFrame() override { |
264 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, | 216 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, |
265 GetProxyMainForTest()->max_requested_pipeline_stage()); | 217 GetProxyMain()->max_requested_pipeline_stage()); |
266 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, | 218 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, |
267 GetProxyMainForTest()->current_pipeline_stage()); | 219 GetProxyMain()->current_pipeline_stage()); |
268 } | 220 } |
269 | 221 |
270 void DidCommit() override { | 222 void DidCommit() override { |
271 EXPECT_EQ(1, update_check_layer_->update_count()); | 223 EXPECT_EQ(1, update_check_layer()->update_count()); |
272 EndTest(); | 224 EndTest(); |
273 } | 225 } |
274 | 226 |
275 private: | 227 void AfterTest() override {} |
276 DISALLOW_COPY_AND_ASSIGN(ProxyMainThreadedSetNeedsCommitWhileAnimating); | 228 |
277 }; | 229 private: |
278 | 230 DISALLOW_COPY_AND_ASSIGN(LayerTreeHostProxyTestSetNeedsCommitWhileAnimating); |
279 PROXY_MAIN_THREADED_TEST_F(ProxyMainThreadedSetNeedsCommitWhileAnimating); | 231 }; |
280 | 232 |
281 class ProxyMainThreadedCommitWaitsForActivation : public ProxyMainThreaded { | 233 MULTI_THREAD_TEST_F(LayerTreeHostProxyTestSetNeedsCommitWhileAnimating); |
282 protected: | 234 |
283 ProxyMainThreadedCommitWaitsForActivation() : num_commits_(0) {} | 235 class LayerTreeHostProxyTestCommitWaitsForActivation |
284 ~ProxyMainThreadedCommitWaitsForActivation() override {} | 236 : public LayerTreeHostProxyTest { |
285 | 237 protected: |
286 void BeginTest() override { proxy()->SetNeedsCommit(); } | 238 LayerTreeHostProxyTestCommitWaitsForActivation() = default; |
287 | 239 |
288 void ScheduledActionCommit() override { | 240 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
289 switch (num_commits_) { | 241 |
290 case 0: | 242 void BeginCommitOnThread(LayerTreeHostImpl* impl) override { |
291 // Set next commit waits for activation and start another commit. | 243 if (impl->sync_tree()->source_frame_number() < 0) |
292 PostNextCommitWaitsForActivationToMainThread(); | 244 return; // The initial commit, don't do anything here. |
293 PostSetNeedsCommitToMainThread(); | 245 |
294 break; | 246 // The main thread will request a commit, and may request that it does |
| 247 // not complete before activating. So make activation take a long time, to |
| 248 // verify that we waited. |
| 249 impl->BlockNotifyReadyToActivateForTesting(true); |
| 250 { |
| 251 base::AutoLock hold(activate_blocked_lock_); |
| 252 activate_blocked_ = true; |
| 253 } |
| 254 switch (impl->sync_tree()->source_frame_number()) { |
| 255 case 0: { |
| 256 // This is for case 1 in DidCommit. |
| 257 auto unblock = base::Bind( |
| 258 &LayerTreeHostProxyTestCommitWaitsForActivation::UnblockActivation, |
| 259 base::Unretained(this), impl); |
| 260 ImplThreadTaskRunner()->PostDelayedTask( |
| 261 FROM_HERE, unblock, |
| 262 // Use a delay to allow the main frame to start if it would. This |
| 263 // should cause failures (or flakiness) if we fail to wait for the |
| 264 // activation before starting the main frame. |
| 265 base::TimeDelta::FromMilliseconds(16 * 4)); |
| 266 break; |
| 267 } |
295 case 1: | 268 case 1: |
296 PostSetNeedsCommitToMainThread(); | 269 // This is for case 2 in DidCommit. |
297 break; | 270 // Here we don't ever unblock activation. Since the commit hasn't |
298 } | 271 // requested to wait, we can verify that activation is blocked when the |
299 num_commits_++; | 272 // commit completes (case 3 in DidCommit). |
300 } | 273 break; |
301 | 274 } |
302 void WillActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { | 275 } |
303 CompletionEvent* activation_completion_event = | 276 |
304 GetProxyImplForTest()->ActivationCompletionEventForTesting(); | 277 void DidCommit() override { |
305 switch (num_commits_) { | 278 switch (layer_tree_host()->source_frame_number()) { |
306 case 1: | 279 case 1: |
307 EXPECT_FALSE(activation_completion_event); | 280 // Request a new commit, but DidCommit will be delayed until activation |
308 break; | 281 // completes. |
309 case 2: | 282 layer_tree_host()->SetNextCommitWaitsForActivation(); |
310 EXPECT_TRUE(activation_completion_event); | 283 layer_tree_host()->SetNeedsCommit(); |
311 EXPECT_FALSE(activation_completion_event->IsSignaled()); | 284 break; |
312 break; | 285 case 2: { |
313 case 3: | 286 base::AutoLock hold(activate_blocked_lock_); |
314 EXPECT_FALSE(activation_completion_event); | 287 EXPECT_FALSE(activate_blocked_); |
| 288 } |
| 289 // Request a new commit, but DidCommit will not be delayed. |
| 290 layer_tree_host()->SetNeedsCommit(); |
| 291 break; |
| 292 case 3: { |
| 293 base::AutoLock hold(activate_blocked_lock_); |
| 294 EXPECT_TRUE(activate_blocked_); |
| 295 } |
| 296 // This commit completed before unblocking activation. |
315 EndTest(); | 297 EndTest(); |
316 break; | 298 break; |
317 } | 299 } |
318 } | 300 } |
319 | 301 |
320 void AfterTest() override { | 302 void UnblockActivation(LayerTreeHostImpl* impl) { |
321 // It is safe to read num_commits_ on the main thread now since AfterTest() | 303 { |
322 // runs after the LayerTreeHost is destroyed and the impl thread tear down | 304 base::AutoLock hold(activate_blocked_lock_); |
323 // is finished. | 305 activate_blocked_ = false; |
324 EXPECT_EQ(3, num_commits_); | 306 } |
325 } | 307 impl->BlockNotifyReadyToActivateForTesting(false); |
326 | 308 } |
327 private: | 309 |
328 int num_commits_; | 310 void AfterTest() override {} |
329 | 311 |
330 DISALLOW_COPY_AND_ASSIGN(ProxyMainThreadedCommitWaitsForActivation); | 312 private: |
331 }; | 313 base::Lock activate_blocked_lock_; |
332 | 314 bool activate_blocked_ = false; |
333 PROXY_MAIN_THREADED_TEST_F(ProxyMainThreadedCommitWaitsForActivation); | 315 |
| 316 DISALLOW_COPY_AND_ASSIGN(LayerTreeHostProxyTestCommitWaitsForActivation); |
| 317 }; |
| 318 |
| 319 MULTI_THREAD_TEST_F(LayerTreeHostProxyTestCommitWaitsForActivation); |
334 | 320 |
335 // Test for a corner case of main frame before activation (MFBA) and commit | 321 // Test for a corner case of main frame before activation (MFBA) and commit |
336 // waits for activation. If a commit (with wait for activation flag set) | 322 // waits for activation. If a commit (with wait for activation flag set) |
337 // is ready before the activation for a previous commit then the activation | 323 // is ready before the activation for a previous commit then the activation |
338 // should not signal the completion event of the second commit. | 324 // should not signal the completion event of the second commit. |
339 class ProxyMainThreadedCommitWaitsForActivationMFBA : public ProxyMainThreaded { | 325 class LayerTreeHostProxyTestCommitWaitsForActivationMFBA |
340 protected: | 326 : public LayerTreeHostProxyTest { |
341 ProxyMainThreadedCommitWaitsForActivationMFBA() : num_commits_(0) {} | 327 protected: |
342 ~ProxyMainThreadedCommitWaitsForActivationMFBA() override {} | 328 LayerTreeHostProxyTestCommitWaitsForActivationMFBA() = default; |
343 | 329 |
344 void InitializeSettings(LayerTreeSettings* settings) override { | 330 void InitializeSettings(LayerTreeSettings* settings) override { |
345 settings->main_frame_before_activation_enabled = true; | 331 settings->main_frame_before_activation_enabled = true; |
346 ProxyMainThreaded::InitializeSettings(settings); | 332 LayerTreeHostProxyTest::InitializeSettings(settings); |
347 } | 333 } |
348 | 334 |
349 void BeginTest() override { proxy()->SetNeedsCommit(); } | 335 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
350 | 336 |
351 // This is called right before NotifyReadyToCommit. | 337 void ReadyToCommitOnThread(LayerTreeHostImpl* impl) override { |
352 void StartCommitOnImpl() override { | 338 switch (impl->sync_tree()->source_frame_number()) { |
353 switch (num_commits_) { | 339 case -1: |
354 case 0: | 340 // Block the activation of the initial commit until the second main |
355 // Block activation until next commit is ready. | 341 // frame is ready. |
356 GetProxyImplForTest()->BlockNotifyReadyToActivateForTesting(true); | 342 impl->BlockNotifyReadyToActivateForTesting(true); |
357 break; | 343 break; |
| 344 case 0: { |
| 345 // This is the main frame with SetNextCommitWaitsForActivation(). |
| 346 // Activation is currently blocked for the previous main frame (from the |
| 347 // case above). We unblock activate to allow this main frame to commit. |
| 348 auto unblock = |
| 349 base::Bind(&LayerTreeHostImpl::BlockNotifyReadyToActivateForTesting, |
| 350 base::Unretained(impl), false); |
| 351 // Post the unblock instead of doing it immediately so that the main |
| 352 // frame is fully processed by the compositor thread, and it has a full |
| 353 // opportunity to wrongly unblock the main thread. |
| 354 ImplThreadTaskRunner()->PostTask(FROM_HERE, unblock); |
| 355 // Once activation completes, we'll begin the commit for frame 1. |
| 356 break; |
| 357 } |
| 358 } |
| 359 } |
| 360 |
| 361 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { |
| 362 if (impl->active_tree()->source_frame_number() == 0) { |
| 363 // The main thread requests a commit does not complete before activating. |
| 364 // So make activation take a long time, to verify that we waited. |
| 365 impl->BlockNotifyReadyToActivateForTesting(true); |
| 366 { |
| 367 base::AutoLock hold(activate_blocked_lock_); |
| 368 // Record that we've blocked activation for this frame of interest. |
| 369 activate_blocked_ = true; |
| 370 } |
| 371 // Then unblock activation eventually to complete the test. We use a |
| 372 // delay to allow the main frame to start if it would. This should cause |
| 373 // failures (or flakiness) if we fail to wait for the activation before |
| 374 // starting the main frame. |
| 375 auto unblock = |
| 376 base::Bind(&LayerTreeHostProxyTestCommitWaitsForActivationMFBA:: |
| 377 UnblockActivation, |
| 378 base::Unretained(this), impl); |
| 379 ImplThreadTaskRunner()->PostDelayedTask( |
| 380 FROM_HERE, unblock, base::TimeDelta::FromMilliseconds(16 * 4)); |
| 381 } |
| 382 } |
| 383 |
| 384 void DidCommit() override { |
| 385 switch (layer_tree_host()->source_frame_number()) { |
358 case 1: | 386 case 1: |
359 // Unblock activation of first commit after second commit is ready. | 387 // Request a new commit, but DidCommit will be delayed until activation |
360 ImplThreadTaskRunner()->PostTask( | 388 // completes. |
361 FROM_HERE, | 389 layer_tree_host()->SetNextCommitWaitsForActivation(); |
362 base::Bind(&ProxyImplForTest::BlockNotifyReadyToActivateForTesting, | 390 layer_tree_host()->SetNeedsCommit(); |
363 base::Unretained(GetProxyImplForTest()), false)); | |
364 break; | |
365 } | |
366 } | |
367 | |
368 void ScheduledActionCommit() override { | |
369 switch (num_commits_) { | |
370 case 0: | |
371 // Set next commit waits for activation and start another commit. | |
372 PostNextCommitWaitsForActivationToMainThread(); | |
373 PostSetNeedsCommitToMainThread(); | |
374 break; | |
375 case 1: | |
376 PostSetNeedsCommitToMainThread(); | |
377 break; | |
378 } | |
379 num_commits_++; | |
380 } | |
381 | |
382 void WillActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { | |
383 CompletionEvent* activation_completion_event = | |
384 GetProxyImplForTest()->ActivationCompletionEventForTesting(); | |
385 switch (num_commits_) { | |
386 case 1: | |
387 EXPECT_FALSE(activation_completion_event); | |
388 break; | 391 break; |
389 case 2: | 392 case 2: |
390 EXPECT_TRUE(activation_completion_event); | 393 // This DidCommit should not happen until activation is done for the |
391 EXPECT_FALSE(activation_completion_event->IsSignaled()); | 394 // frame. |
392 break; | 395 { |
393 case 3: | 396 base::AutoLock hold(activate_blocked_lock_); |
394 EXPECT_FALSE(activation_completion_event); | 397 EXPECT_FALSE(activate_blocked_); |
| 398 } |
395 EndTest(); | 399 EndTest(); |
396 break; | 400 break; |
397 } | 401 } |
398 } | 402 } |
399 | 403 |
400 void AfterTest() override { | 404 void UnblockActivation(LayerTreeHostImpl* impl) { |
401 // It is safe to read num_commits_ on the main thread now since AfterTest() | 405 { |
402 // runs after the LayerTreeHost is destroyed and the impl thread tear down | 406 base::AutoLock hold(activate_blocked_lock_); |
403 // is finished. | 407 activate_blocked_ = false; |
404 EXPECT_EQ(3, num_commits_); | 408 } |
405 } | 409 impl->BlockNotifyReadyToActivateForTesting(false); |
406 | 410 } |
407 private: | 411 |
408 int num_commits_; | 412 void AfterTest() override {} |
409 | 413 |
410 DISALLOW_COPY_AND_ASSIGN(ProxyMainThreadedCommitWaitsForActivationMFBA); | 414 private: |
411 }; | 415 base::Lock activate_blocked_lock_; |
412 | 416 bool activate_blocked_ = false; |
413 PROXY_MAIN_THREADED_TEST_F(ProxyMainThreadedCommitWaitsForActivationMFBA); | 417 |
| 418 DISALLOW_COPY_AND_ASSIGN(LayerTreeHostProxyTestCommitWaitsForActivationMFBA); |
| 419 }; |
| 420 |
| 421 MULTI_THREAD_TEST_F(LayerTreeHostProxyTestCommitWaitsForActivationMFBA); |
414 | 422 |
415 } // namespace cc | 423 } // namespace cc |
OLD | NEW |