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 | |
5 #include "cc/scheduler/scheduler.h" | 4 #include "cc/scheduler/scheduler.h" |
6 | 5 |
7 #include <string> | 6 #include <string> |
8 #include <vector> | 7 #include <vector> |
9 | 8 |
10 #include "base/logging.h" | 9 #include "base/logging.h" |
11 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
12 #include "cc/test/scheduler_test_common.h" | 11 #include "cc/test/scheduler_test_common.h" |
13 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 13 matching lines...) Expand all Loading... |
28 | 27 |
29 namespace cc { | 28 namespace cc { |
30 namespace { | 29 namespace { |
31 | 30 |
32 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler) { | 31 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler) { |
33 scheduler->DidCreateAndInitializeOutputSurface(); | 32 scheduler->DidCreateAndInitializeOutputSurface(); |
34 scheduler->SetNeedsCommit(); | 33 scheduler->SetNeedsCommit(); |
35 scheduler->FinishCommit(); | 34 scheduler->FinishCommit(); |
36 // Go through the motions to draw the commit. | 35 // Go through the motions to draw the commit. |
37 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 36 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
38 // We need another BeginFrame so scheduler calls SetNeedsBeginFrame(false). | 37 scheduler->OnBeginFrameDeadline(); |
| 38 // We need another BeginFrame so Scheduler calls SetNeedsBeginFrame(false). |
39 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 39 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
40 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 40 scheduler->OnBeginFrameDeadline(); |
41 } | 41 } |
42 | 42 |
43 class FakeSchedulerClient : public SchedulerClient { | 43 class FakeSchedulerClient : public SchedulerClient { |
44 public: | 44 public: |
45 FakeSchedulerClient() | 45 FakeSchedulerClient() |
46 : needs_begin_frame_(false) { | 46 : needs_begin_frame_(false) { |
47 Reset(); | 47 Reset(); |
48 } | 48 } |
49 | 49 |
50 void Reset() { | 50 void Reset() { |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 virtual base::TimeDelta DrawDurationEstimate() OVERRIDE { | 141 virtual base::TimeDelta DrawDurationEstimate() OVERRIDE { |
142 return base::TimeDelta(); | 142 return base::TimeDelta(); |
143 } | 143 } |
144 virtual base::TimeDelta BeginFrameToCommitDurationEstimate() OVERRIDE { | 144 virtual base::TimeDelta BeginFrameToCommitDurationEstimate() OVERRIDE { |
145 return base::TimeDelta(); | 145 return base::TimeDelta(); |
146 } | 146 } |
147 virtual base::TimeDelta CommitToActivateDurationEstimate() OVERRIDE { | 147 virtual base::TimeDelta CommitToActivateDurationEstimate() OVERRIDE { |
148 return base::TimeDelta(); | 148 return base::TimeDelta(); |
149 } | 149 } |
150 | 150 |
| 151 virtual void PostBeginFrameDeadline(const base::Closure& closure, |
| 152 base::TimeTicks deadline) OVERRIDE { |
| 153 actions_.push_back("PostBeginFrameDeadlineTask"); |
| 154 states_.push_back(scheduler_->StateAsValue().release()); |
| 155 } |
| 156 |
| 157 virtual void DidBeginFrameDeadlineOnImplThread() OVERRIDE {} |
| 158 |
151 protected: | 159 protected: |
152 bool needs_begin_frame_; | 160 bool needs_begin_frame_; |
153 bool draw_will_happen_; | 161 bool draw_will_happen_; |
154 bool swap_will_happen_if_draw_happens_; | 162 bool swap_will_happen_if_draw_happens_; |
155 int num_draws_; | 163 int num_draws_; |
156 std::vector<const char*> actions_; | 164 std::vector<const char*> actions_; |
157 ScopedVector<base::Value> states_; | 165 ScopedVector<base::Value> states_; |
158 scoped_ptr<Scheduler> scheduler_; | 166 scoped_ptr<Scheduler> scheduler_; |
159 }; | 167 }; |
160 | 168 |
(...skipping 15 matching lines...) Expand all Loading... |
176 FakeSchedulerClient client; | 184 FakeSchedulerClient client; |
177 SchedulerSettings default_scheduler_settings; | 185 SchedulerSettings default_scheduler_settings; |
178 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 186 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
179 scheduler->SetCanStart(); | 187 scheduler->SetCanStart(); |
180 scheduler->SetVisible(true); | 188 scheduler->SetVisible(true); |
181 scheduler->SetCanDraw(true); | 189 scheduler->SetCanDraw(true); |
182 | 190 |
183 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 191 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
184 InitializeOutputSurfaceAndFirstCommit(scheduler); | 192 InitializeOutputSurfaceAndFirstCommit(scheduler); |
185 | 193 |
186 // SetNeedsCommit should begin the frame. | 194 // SetNeedsCommit should begin the frame on the next BeginFrame. |
187 client.Reset(); | 195 client.Reset(); |
188 scheduler->SetNeedsCommit(); | 196 scheduler->SetNeedsCommit(); |
189 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2); | |
190 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); | |
191 EXPECT_TRUE(client.needs_begin_frame()); | 197 EXPECT_TRUE(client.needs_begin_frame()); |
192 client.Reset(); | 198 client.Reset(); |
193 | 199 |
| 200 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 201 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2); |
| 202 EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2); |
| 203 EXPECT_TRUE(client.needs_begin_frame()); |
| 204 client.Reset(); |
| 205 |
| 206 // If we don't swap on the deadline, we need to request another BeginFrame. |
| 207 scheduler->OnBeginFrameDeadline(); |
| 208 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); |
| 209 EXPECT_TRUE(client.needs_begin_frame()); |
| 210 client.Reset(); |
| 211 |
194 // FinishCommit should commit | 212 // FinishCommit should commit |
195 scheduler->FinishCommit(); | 213 scheduler->FinishCommit(); |
196 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 214 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
197 EXPECT_TRUE(client.needs_begin_frame()); | 215 EXPECT_TRUE(client.needs_begin_frame()); |
198 client.Reset(); | 216 client.Reset(); |
199 | 217 |
200 // BeginFrame should draw. | 218 // BeginFrame should prepare the draw. |
201 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 219 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 220 EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client); |
| 221 EXPECT_TRUE(client.needs_begin_frame()); |
| 222 client.Reset(); |
| 223 |
| 224 // BeginFrame deadline should draw. |
| 225 scheduler->OnBeginFrameDeadline(); |
202 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); | 226 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); |
203 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); | 227 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); |
| 228 client.Reset(); |
| 229 |
| 230 // The following BeginFrame deadline should SetNeedsBeginFrame(false) to avoid |
| 231 // excessive toggles. |
| 232 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 233 EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client); |
| 234 client.Reset(); |
| 235 |
| 236 scheduler->OnBeginFrameDeadline(); |
| 237 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); |
204 EXPECT_FALSE(client.needs_begin_frame()); | 238 EXPECT_FALSE(client.needs_begin_frame()); |
205 client.Reset(); | 239 client.Reset(); |
206 } | 240 } |
207 | 241 |
208 TEST(SchedulerTest, RequestCommitAfterBeginFrameSentToMainThread) { | 242 TEST(SchedulerTest, RequestCommitAfterBeginFrameSentToMainThread) { |
209 FakeSchedulerClient client; | 243 FakeSchedulerClient client; |
210 SchedulerSettings default_scheduler_settings; | 244 SchedulerSettings default_scheduler_settings; |
211 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 245 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
212 scheduler->SetCanStart(); | 246 scheduler->SetCanStart(); |
213 scheduler->SetVisible(true); | 247 scheduler->SetVisible(true); |
214 scheduler->SetCanDraw(true); | 248 scheduler->SetCanDraw(true); |
215 | 249 |
216 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 250 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
217 InitializeOutputSurfaceAndFirstCommit(scheduler); | 251 InitializeOutputSurfaceAndFirstCommit(scheduler); |
218 client.Reset(); | 252 client.Reset(); |
219 | 253 |
220 // SetNedsCommit should begin the frame. | 254 // SetNeddsCommit should begin the frame. |
221 scheduler->SetNeedsCommit(); | 255 scheduler->SetNeedsCommit(); |
| 256 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); |
| 257 client.Reset(); |
| 258 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
222 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2); | 259 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2); |
| 260 EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2); |
| 261 EXPECT_TRUE(client.needs_begin_frame()); |
| 262 client.Reset(); |
| 263 |
| 264 // Now SetNeedsCommit again. Calling here means we need a second commit. |
| 265 scheduler->SetNeedsCommit(); |
| 266 EXPECT_EQ(client.num_actions_(), 0); |
| 267 client.Reset(); |
| 268 |
| 269 // Finish the first commit. |
| 270 scheduler->FinishCommit(); |
| 271 EXPECT_ACTION("ScheduledActionCommit", client, 0, 2); |
| 272 EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2); |
| 273 client.Reset(); |
| 274 scheduler->OnBeginFrameDeadline(); |
| 275 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); |
223 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); | 276 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); |
224 client.Reset(); | 277 client.Reset(); |
225 | 278 |
226 // Now SetNeedsCommit again. Calling here means we need a second frame. | 279 // Since another commit is needed, the next BeginFrame should initiate |
227 scheduler->SetNeedsCommit(); | 280 // the second commit. |
228 | 281 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
229 // Finish the commit for the first frame. | 282 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2); |
230 scheduler->FinishCommit(); | 283 EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2); |
231 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | |
232 client.Reset(); | 284 client.Reset(); |
233 | 285 |
234 // Tick should draw but then begin another frame for the second commit. | 286 // Finishing the commit before the deadline should post a new deadline task |
| 287 // to trigger the deadline early. |
| 288 scheduler->FinishCommit(); |
| 289 EXPECT_ACTION("ScheduledActionCommit", client, 0, 2); |
| 290 EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2); |
| 291 client.Reset(); |
| 292 scheduler->OnBeginFrameDeadline(); |
| 293 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); |
| 294 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); |
| 295 EXPECT_TRUE(client.needs_begin_frame()); |
| 296 |
| 297 // On the next BeginFrame, go back to quiescent state and verify we no longer |
| 298 // request BeginFrames. |
235 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 299 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
236 EXPECT_TRUE(client.needs_begin_frame()); | 300 scheduler->OnBeginFrameDeadline(); |
237 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 3); | 301 EXPECT_FALSE(client.needs_begin_frame()); |
238 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 1, 3); | |
239 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 2, 3); | |
240 client.Reset(); | 302 client.Reset(); |
241 | |
242 // Finish the second commit to go back to quiescent state and verify we no | |
243 // longer request BeginFrames. | |
244 scheduler->FinishCommit(); | |
245 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | |
246 EXPECT_FALSE(client.needs_begin_frame()); | |
247 } | 303 } |
248 | 304 |
249 TEST(SchedulerTest, TextureAcquisitionCausesCommitInsteadOfDraw) { | 305 TEST(SchedulerTest, TextureAcquisitionCausesCommitInsteadOfDraw) { |
250 FakeSchedulerClient client; | 306 FakeSchedulerClient client; |
251 SchedulerSettings default_scheduler_settings; | 307 SchedulerSettings default_scheduler_settings; |
252 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 308 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
253 scheduler->SetCanStart(); | 309 scheduler->SetCanStart(); |
254 scheduler->SetVisible(true); | 310 scheduler->SetVisible(true); |
255 scheduler->SetCanDraw(true); | 311 scheduler->SetCanDraw(true); |
256 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 312 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
257 | 313 |
258 InitializeOutputSurfaceAndFirstCommit(scheduler); | 314 InitializeOutputSurfaceAndFirstCommit(scheduler); |
259 client.Reset(); | 315 client.Reset(); |
260 scheduler->SetNeedsRedraw(); | 316 scheduler->SetNeedsRedraw(); |
261 EXPECT_TRUE(scheduler->RedrawPending()); | 317 EXPECT_TRUE(scheduler->RedrawPending()); |
262 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); | 318 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); |
263 EXPECT_TRUE(client.needs_begin_frame()); | 319 EXPECT_TRUE(client.needs_begin_frame()); |
264 | 320 |
265 client.Reset(); | 321 client.Reset(); |
266 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 322 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 323 EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client); |
| 324 |
| 325 client.Reset(); |
| 326 scheduler->OnBeginFrameDeadline(); |
267 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); | 327 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); |
268 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); | 328 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); |
269 EXPECT_FALSE(scheduler->RedrawPending()); | 329 EXPECT_FALSE(scheduler->RedrawPending()); |
270 EXPECT_FALSE(client.needs_begin_frame()); | |
271 | 330 |
272 client.Reset(); | 331 client.Reset(); |
273 scheduler->SetMainThreadNeedsLayerTextures(); | 332 scheduler->SetMainThreadNeedsLayerTextures(); |
274 EXPECT_SINGLE_ACTION("ScheduledActionAcquireLayerTexturesForMainThread", | 333 EXPECT_SINGLE_ACTION("ScheduledActionAcquireLayerTexturesForMainThread", |
275 client); | 334 client); |
276 | 335 |
277 // We should request a BeginFrame in anticipation of a draw. | 336 // We should request a BeginFrame in anticipation of a draw. |
278 client.Reset(); | 337 client.Reset(); |
279 scheduler->SetNeedsRedraw(); | 338 scheduler->SetNeedsRedraw(); |
280 EXPECT_TRUE(scheduler->RedrawPending()); | 339 EXPECT_TRUE(scheduler->RedrawPending()); |
281 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); | 340 EXPECT_EQ(0, client.num_actions_()); |
282 EXPECT_TRUE(client.needs_begin_frame()); | |
283 | 341 |
284 // No draw happens since the textures are acquired by the main thread. | 342 // No draw happens since the textures are acquired by the main thread. |
285 client.Reset(); | 343 client.Reset(); |
286 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 344 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 345 EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client); |
| 346 |
| 347 client.Reset(); |
| 348 scheduler->OnBeginFrameDeadline(); |
287 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); | 349 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); |
288 EXPECT_TRUE(scheduler->RedrawPending()); | 350 EXPECT_TRUE(scheduler->RedrawPending()); |
289 EXPECT_TRUE(client.needs_begin_frame()); | 351 EXPECT_TRUE(client.needs_begin_frame()); |
290 | 352 |
| 353 client.Reset(); |
291 scheduler->SetNeedsCommit(); | 354 scheduler->SetNeedsCommit(); |
292 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 0, 2); | 355 EXPECT_EQ(0, client.num_actions_()); |
293 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 1, 2); | 356 |
294 EXPECT_TRUE(client.needs_begin_frame()); | 357 client.Reset(); |
| 358 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 359 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2); |
| 360 EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2); |
295 | 361 |
296 // Commit will release the texture. | 362 // Commit will release the texture. |
297 client.Reset(); | 363 client.Reset(); |
298 scheduler->FinishCommit(); | 364 scheduler->FinishCommit(); |
299 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 365 EXPECT_ACTION("ScheduledActionCommit", client, 0, 2); |
| 366 EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2); |
300 EXPECT_TRUE(scheduler->RedrawPending()); | 367 EXPECT_TRUE(scheduler->RedrawPending()); |
301 EXPECT_TRUE(client.needs_begin_frame()); | |
302 | 368 |
303 // Now we can draw again after the commit happens. | 369 // Now we can draw again after the commit happens. |
304 client.Reset(); | 370 client.Reset(); |
305 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 371 scheduler->OnBeginFrameDeadline(); |
306 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); | 372 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); |
307 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); | 373 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); |
308 EXPECT_FALSE(scheduler->RedrawPending()); | 374 EXPECT_FALSE(scheduler->RedrawPending()); |
| 375 |
| 376 // SetNeedsBeginFrame(false) should be deferred to the end of the next |
| 377 // BeginFrame to avoid excessive toggling. |
| 378 EXPECT_TRUE(client.needs_begin_frame()); |
| 379 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 380 scheduler->OnBeginFrameDeadline(); |
309 EXPECT_FALSE(client.needs_begin_frame()); | 381 EXPECT_FALSE(client.needs_begin_frame()); |
310 client.Reset(); | |
311 } | 382 } |
312 | 383 |
313 TEST(SchedulerTest, TextureAcquisitionCollision) { | 384 TEST(SchedulerTest, TextureAcquisitionCollision) { |
314 FakeSchedulerClient client; | 385 FakeSchedulerClient client; |
315 SchedulerSettings default_scheduler_settings; | 386 SchedulerSettings default_scheduler_settings; |
316 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 387 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
317 scheduler->SetCanStart(); | 388 scheduler->SetCanStart(); |
318 scheduler->SetVisible(true); | 389 scheduler->SetVisible(true); |
319 scheduler->SetCanDraw(true); | 390 scheduler->SetCanDraw(true); |
320 | 391 |
321 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 392 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
322 InitializeOutputSurfaceAndFirstCommit(scheduler); | 393 InitializeOutputSurfaceAndFirstCommit(scheduler); |
323 | 394 |
324 client.Reset(); | 395 client.Reset(); |
325 scheduler->SetNeedsCommit(); | 396 scheduler->SetNeedsCommit(); |
326 scheduler->SetMainThreadNeedsLayerTextures(); | 397 scheduler->SetMainThreadNeedsLayerTextures(); |
327 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 3); | 398 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 0, 2); |
328 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 3); | |
329 EXPECT_ACTION( | 399 EXPECT_ACTION( |
330 "ScheduledActionAcquireLayerTexturesForMainThread", client, 2, 3); | 400 "ScheduledActionAcquireLayerTexturesForMainThread", client, 1, 2); |
| 401 |
331 client.Reset(); | 402 client.Reset(); |
| 403 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 404 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2); |
| 405 EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2); |
| 406 |
| 407 client.Reset(); |
| 408 scheduler->OnBeginFrameDeadline(); |
| 409 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); |
332 | 410 |
333 // Although the compositor cannot draw because textures are locked by main | 411 // Although the compositor cannot draw because textures are locked by main |
334 // thread, we continue requesting SetNeedsBeginFrame in anticipation of the | 412 // thread, we continue requesting SetNeedsBeginFrame in anticipation of the |
335 // unlock. | 413 // unlock. |
336 EXPECT_TRUE(client.needs_begin_frame()); | 414 EXPECT_TRUE(client.needs_begin_frame()); |
337 | 415 |
338 // Trigger the commit | 416 // Trigger the commit |
339 scheduler->FinishCommit(); | 417 scheduler->FinishCommit(); |
340 EXPECT_TRUE(client.needs_begin_frame()); | 418 EXPECT_TRUE(client.needs_begin_frame()); |
341 client.Reset(); | |
342 | 419 |
343 // Between commit and draw, texture acquisition for main thread delayed, | 420 // Between commit and draw, texture acquisition for main thread delayed, |
344 // and main thread blocks. | 421 // and main thread blocks. |
| 422 client.Reset(); |
345 scheduler->SetMainThreadNeedsLayerTextures(); | 423 scheduler->SetMainThreadNeedsLayerTextures(); |
346 EXPECT_EQ(0, client.num_actions_()); | 424 EXPECT_EQ(0, client.num_actions_()); |
347 client.Reset(); | |
348 | 425 |
349 // No implicit commit is expected. | 426 // No implicit commit is expected. |
| 427 client.Reset(); |
350 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 428 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 429 EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client); |
| 430 |
| 431 client.Reset(); |
| 432 scheduler->OnBeginFrameDeadline(); |
351 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 3); | 433 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 3); |
352 EXPECT_ACTION("ScheduledActionAcquireLayerTexturesForMainThread", | 434 EXPECT_ACTION( |
353 client, | 435 "ScheduledActionAcquireLayerTexturesForMainThread", client, 1, 3); |
354 1, | |
355 3); | |
356 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 2, 3); | 436 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 2, 3); |
357 client.Reset(); | |
358 | 437 |
359 // Compositor not scheduled to draw because textures are locked by main | 438 // Although the compositor is not scheduled to draw because textures are |
360 // thread. | 439 // locked by main thread, we proactively request the begin frame. |
361 EXPECT_FALSE(client.needs_begin_frame()); | 440 EXPECT_TRUE(client.needs_begin_frame()); |
362 | 441 |
363 // Needs an explicit commit from the main thread. | 442 // Needs an explicit commit from the main thread. |
| 443 client.Reset(); |
364 scheduler->SetNeedsCommit(); | 444 scheduler->SetNeedsCommit(); |
| 445 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
365 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2); | 446 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2); |
366 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); | 447 EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2); |
367 client.Reset(); | 448 client.Reset(); |
368 | 449 |
369 // Trigger the commit | 450 // Trigger the commit |
370 scheduler->FinishCommit(); | 451 scheduler->FinishCommit(); |
371 EXPECT_TRUE(client.needs_begin_frame()); | 452 EXPECT_TRUE(client.needs_begin_frame()); |
372 } | 453 } |
373 | 454 |
374 TEST(SchedulerTest, VisibilitySwitchWithTextureAcquisition) { | 455 TEST(SchedulerTest, VisibilitySwitchWithTextureAcquisition) { |
375 FakeSchedulerClient client; | 456 FakeSchedulerClient client; |
376 SchedulerSettings default_scheduler_settings; | 457 SchedulerSettings default_scheduler_settings; |
377 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 458 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
378 scheduler->SetCanStart(); | 459 scheduler->SetCanStart(); |
379 scheduler->SetVisible(true); | 460 scheduler->SetVisible(true); |
380 scheduler->SetCanDraw(true); | 461 scheduler->SetCanDraw(true); |
381 | 462 |
382 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 463 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
383 client.Reset(); | 464 client.Reset(); |
384 scheduler->DidCreateAndInitializeOutputSurface(); | 465 scheduler->DidCreateAndInitializeOutputSurface(); |
385 | 466 |
386 scheduler->SetNeedsCommit(); | 467 scheduler->SetNeedsCommit(); |
| 468 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 469 scheduler->OnBeginFrameDeadline(); |
387 scheduler->FinishCommit(); | 470 scheduler->FinishCommit(); |
388 scheduler->SetMainThreadNeedsLayerTextures(); | 471 scheduler->SetMainThreadNeedsLayerTextures(); |
389 scheduler->SetNeedsCommit(); | 472 scheduler->SetNeedsCommit(); |
390 client.Reset(); | 473 client.Reset(); |
391 // Verify that pending texture acquisition fires when visibility | 474 // Verify that pending texture acquisition fires when visibility |
392 // is lost in order to avoid a deadlock. | 475 // is lost in order to avoid a deadlock. |
393 scheduler->SetVisible(false); | 476 scheduler->SetVisible(false); |
394 EXPECT_SINGLE_ACTION("ScheduledActionAcquireLayerTexturesForMainThread", | 477 EXPECT_SINGLE_ACTION("ScheduledActionAcquireLayerTexturesForMainThread", |
395 client); | 478 client); |
396 client.Reset(); | |
397 | 479 |
398 // Already sent a begin frame on this current frame, so wait. | 480 // Already sent a begin frame on this current frame, so wait. |
| 481 client.Reset(); |
399 scheduler->SetVisible(true); | 482 scheduler->SetVisible(true); |
400 EXPECT_EQ(0, client.num_actions_()); | 483 EXPECT_EQ(0, client.num_actions_()); |
401 client.Reset(); | 484 EXPECT_TRUE(client.needs_begin_frame()); |
402 | 485 |
403 // Regaining visibility with textures acquired by main thread while | 486 // Regaining visibility with textures acquired by main thread while |
404 // compositor is waiting for first draw should result in a request | 487 // compositor is waiting for first draw should result in a request |
405 // for a new frame in order to escape a deadlock. | 488 // for a new frame in order to escape a deadlock. |
| 489 client.Reset(); |
406 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 490 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
407 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2); | 491 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2); |
408 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); | 492 EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2); |
409 } | 493 } |
410 | 494 |
411 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { | 495 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { |
412 public: | 496 public: |
413 virtual void ScheduledActionSendBeginFrameToMainThread() OVERRIDE {} | 497 virtual void ScheduledActionSendBeginFrameToMainThread() OVERRIDE {} |
414 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible() | 498 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible() |
415 OVERRIDE { | 499 OVERRIDE { |
416 // Only SetNeedsRedraw the first time this is called | 500 // Only SetNeedsRedraw the first time this is called |
417 if (!num_draws_) | 501 if (!num_draws_) |
418 scheduler_->SetNeedsRedraw(); | 502 scheduler_->SetNeedsRedraw(); |
(...skipping 26 matching lines...) Expand all Loading... |
445 scheduler->SetCanDraw(true); | 529 scheduler->SetCanDraw(true); |
446 InitializeOutputSurfaceAndFirstCommit(scheduler); | 530 InitializeOutputSurfaceAndFirstCommit(scheduler); |
447 client.Reset(); | 531 client.Reset(); |
448 | 532 |
449 scheduler->SetNeedsRedraw(); | 533 scheduler->SetNeedsRedraw(); |
450 EXPECT_TRUE(scheduler->RedrawPending()); | 534 EXPECT_TRUE(scheduler->RedrawPending()); |
451 EXPECT_TRUE(client.needs_begin_frame()); | 535 EXPECT_TRUE(client.needs_begin_frame()); |
452 EXPECT_EQ(0, client.num_draws()); | 536 EXPECT_EQ(0, client.num_draws()); |
453 | 537 |
454 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 538 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 539 scheduler->OnBeginFrameDeadline(); |
455 EXPECT_EQ(1, client.num_draws()); | 540 EXPECT_EQ(1, client.num_draws()); |
456 EXPECT_TRUE(scheduler->RedrawPending()); | 541 EXPECT_TRUE(scheduler->RedrawPending()); |
457 EXPECT_TRUE(client.needs_begin_frame()); | 542 EXPECT_TRUE(client.needs_begin_frame()); |
458 | 543 |
459 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 544 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 545 scheduler->OnBeginFrameDeadline(); |
460 EXPECT_EQ(2, client.num_draws()); | 546 EXPECT_EQ(2, client.num_draws()); |
461 EXPECT_FALSE(scheduler->RedrawPending()); | 547 EXPECT_FALSE(scheduler->RedrawPending()); |
| 548 EXPECT_TRUE(client.needs_begin_frame()); |
| 549 |
| 550 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 551 scheduler->OnBeginFrameDeadline(); |
462 EXPECT_FALSE(client.needs_begin_frame()); | 552 EXPECT_FALSE(client.needs_begin_frame()); |
463 } | 553 } |
464 | 554 |
465 // Test that requesting redraw inside a failed draw doesn't lose the request. | 555 // Test that requesting redraw inside a failed draw doesn't lose the request. |
466 TEST(SchedulerTest, RequestRedrawInsideFailedDraw) { | 556 TEST(SchedulerTest, RequestRedrawInsideFailedDraw) { |
467 SchedulerClientThatsetNeedsDrawInsideDraw client; | 557 SchedulerClientThatsetNeedsDrawInsideDraw client; |
468 SchedulerSettings default_scheduler_settings; | 558 SchedulerSettings default_scheduler_settings; |
469 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 559 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
470 scheduler->SetCanStart(); | 560 scheduler->SetCanStart(); |
471 scheduler->SetVisible(true); | 561 scheduler->SetVisible(true); |
472 scheduler->SetCanDraw(true); | 562 scheduler->SetCanDraw(true); |
473 InitializeOutputSurfaceAndFirstCommit(scheduler); | 563 InitializeOutputSurfaceAndFirstCommit(scheduler); |
474 client.Reset(); | 564 client.Reset(); |
475 | 565 |
476 client.SetDrawWillHappen(false); | 566 client.SetDrawWillHappen(false); |
477 | 567 |
478 scheduler->SetNeedsRedraw(); | 568 scheduler->SetNeedsRedraw(); |
479 EXPECT_TRUE(scheduler->RedrawPending()); | 569 EXPECT_TRUE(scheduler->RedrawPending()); |
480 EXPECT_TRUE(client.needs_begin_frame()); | 570 EXPECT_TRUE(client.needs_begin_frame()); |
481 EXPECT_EQ(0, client.num_draws()); | 571 EXPECT_EQ(0, client.num_draws()); |
482 | 572 |
483 // Fail the draw. | 573 // Fail the draw. |
484 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 574 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 575 scheduler->OnBeginFrameDeadline(); |
485 EXPECT_EQ(1, client.num_draws()); | 576 EXPECT_EQ(1, client.num_draws()); |
486 | 577 |
487 // We have a commit pending and the draw failed, and we didn't lose the redraw | 578 // We have a commit pending and the draw failed, and we didn't lose the redraw |
488 // request. | 579 // request. |
489 EXPECT_TRUE(scheduler->CommitPending()); | 580 EXPECT_TRUE(scheduler->CommitPending()); |
490 EXPECT_TRUE(scheduler->RedrawPending()); | 581 EXPECT_TRUE(scheduler->RedrawPending()); |
491 EXPECT_TRUE(client.needs_begin_frame()); | 582 EXPECT_TRUE(client.needs_begin_frame()); |
492 | 583 |
493 // Fail the draw again. | 584 // Fail the draw again. |
494 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 585 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 586 scheduler->OnBeginFrameDeadline(); |
495 EXPECT_EQ(2, client.num_draws()); | 587 EXPECT_EQ(2, client.num_draws()); |
496 EXPECT_TRUE(scheduler->CommitPending()); | 588 EXPECT_TRUE(scheduler->CommitPending()); |
497 EXPECT_TRUE(scheduler->RedrawPending()); | 589 EXPECT_TRUE(scheduler->RedrawPending()); |
498 EXPECT_TRUE(client.needs_begin_frame()); | 590 EXPECT_TRUE(client.needs_begin_frame()); |
499 | 591 |
500 // Draw successfully. | 592 // Draw successfully. |
501 client.SetDrawWillHappen(true); | 593 client.SetDrawWillHappen(true); |
502 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 594 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 595 scheduler->OnBeginFrameDeadline(); |
503 EXPECT_EQ(3, client.num_draws()); | 596 EXPECT_EQ(3, client.num_draws()); |
504 EXPECT_TRUE(scheduler->CommitPending()); | 597 EXPECT_TRUE(scheduler->CommitPending()); |
505 EXPECT_FALSE(scheduler->RedrawPending()); | 598 EXPECT_FALSE(scheduler->RedrawPending()); |
506 EXPECT_TRUE(client.needs_begin_frame()); | 599 EXPECT_TRUE(client.needs_begin_frame()); |
507 } | 600 } |
508 | 601 |
509 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient { | 602 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient { |
510 public: | 603 public: |
511 SchedulerClientThatSetNeedsCommitInsideDraw() | 604 SchedulerClientThatSetNeedsCommitInsideDraw() |
512 : set_needs_commit_on_next_draw_(false) {} | 605 : set_needs_commit_on_next_draw_(false) {} |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 TEST(SchedulerTest, RequestCommitInsideDraw) { | 638 TEST(SchedulerTest, RequestCommitInsideDraw) { |
546 SchedulerClientThatSetNeedsCommitInsideDraw client; | 639 SchedulerClientThatSetNeedsCommitInsideDraw client; |
547 SchedulerSettings default_scheduler_settings; | 640 SchedulerSettings default_scheduler_settings; |
548 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 641 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
549 scheduler->SetCanStart(); | 642 scheduler->SetCanStart(); |
550 scheduler->SetVisible(true); | 643 scheduler->SetVisible(true); |
551 scheduler->SetCanDraw(true); | 644 scheduler->SetCanDraw(true); |
552 InitializeOutputSurfaceAndFirstCommit(scheduler); | 645 InitializeOutputSurfaceAndFirstCommit(scheduler); |
553 client.Reset(); | 646 client.Reset(); |
554 | 647 |
| 648 EXPECT_FALSE(client.needs_begin_frame()); |
555 scheduler->SetNeedsRedraw(); | 649 scheduler->SetNeedsRedraw(); |
556 EXPECT_TRUE(scheduler->RedrawPending()); | 650 EXPECT_TRUE(scheduler->RedrawPending()); |
557 EXPECT_EQ(0, client.num_draws()); | 651 EXPECT_EQ(0, client.num_draws()); |
558 EXPECT_TRUE(client.needs_begin_frame()); | 652 EXPECT_TRUE(client.needs_begin_frame()); |
559 | 653 |
560 client.SetNeedsCommitOnNextDraw(); | 654 client.SetNeedsCommitOnNextDraw(); |
561 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 655 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 656 client.SetNeedsCommitOnNextDraw(); |
| 657 scheduler->OnBeginFrameDeadline(); |
562 EXPECT_EQ(1, client.num_draws()); | 658 EXPECT_EQ(1, client.num_draws()); |
563 EXPECT_TRUE(scheduler->CommitPending()); | 659 EXPECT_TRUE(scheduler->CommitPending()); |
564 EXPECT_TRUE(client.needs_begin_frame()); | 660 EXPECT_TRUE(client.needs_begin_frame()); |
565 scheduler->FinishCommit(); | 661 scheduler->FinishCommit(); |
566 | 662 |
567 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 663 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
568 EXPECT_EQ(2, client.num_draws());; | 664 scheduler->OnBeginFrameDeadline(); |
| 665 EXPECT_EQ(2, client.num_draws()); |
| 666 |
569 EXPECT_FALSE(scheduler->RedrawPending()); | 667 EXPECT_FALSE(scheduler->RedrawPending()); |
570 EXPECT_FALSE(scheduler->CommitPending()); | 668 EXPECT_FALSE(scheduler->CommitPending()); |
| 669 EXPECT_TRUE(client.needs_begin_frame()); |
| 670 |
| 671 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 672 scheduler->OnBeginFrameDeadline(); |
571 EXPECT_FALSE(client.needs_begin_frame()); | 673 EXPECT_FALSE(client.needs_begin_frame()); |
572 } | 674 } |
573 | 675 |
574 // Tests that when a draw fails then the pending commit should not be dropped. | 676 // Tests that when a draw fails then the pending commit should not be dropped. |
575 TEST(SchedulerTest, RequestCommitInsideFailedDraw) { | 677 TEST(SchedulerTest, RequestCommitInsideFailedDraw) { |
576 SchedulerClientThatsetNeedsDrawInsideDraw client; | 678 SchedulerClientThatsetNeedsDrawInsideDraw client; |
577 SchedulerSettings default_scheduler_settings; | 679 SchedulerSettings default_scheduler_settings; |
578 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 680 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
579 scheduler->SetCanStart(); | 681 scheduler->SetCanStart(); |
580 scheduler->SetVisible(true); | 682 scheduler->SetVisible(true); |
581 scheduler->SetCanDraw(true); | 683 scheduler->SetCanDraw(true); |
582 InitializeOutputSurfaceAndFirstCommit(scheduler); | 684 InitializeOutputSurfaceAndFirstCommit(scheduler); |
583 client.Reset(); | 685 client.Reset(); |
584 | 686 |
585 client.SetDrawWillHappen(false); | 687 client.SetDrawWillHappen(false); |
586 | 688 |
587 scheduler->SetNeedsRedraw(); | 689 scheduler->SetNeedsRedraw(); |
588 EXPECT_TRUE(scheduler->RedrawPending()); | 690 EXPECT_TRUE(scheduler->RedrawPending()); |
589 EXPECT_TRUE(client.needs_begin_frame()); | 691 EXPECT_TRUE(client.needs_begin_frame()); |
590 EXPECT_EQ(0, client.num_draws()); | 692 EXPECT_EQ(0, client.num_draws()); |
591 | 693 |
592 // Fail the draw. | 694 // Fail the draw. |
593 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 695 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 696 scheduler->OnBeginFrameDeadline(); |
594 EXPECT_EQ(1, client.num_draws()); | 697 EXPECT_EQ(1, client.num_draws()); |
595 | 698 |
596 // We have a commit pending and the draw failed, and we didn't lose the commit | 699 // We have a commit pending and the draw failed, and we didn't lose the commit |
597 // request. | 700 // request. |
598 EXPECT_TRUE(scheduler->CommitPending()); | 701 EXPECT_TRUE(scheduler->CommitPending()); |
599 EXPECT_TRUE(scheduler->RedrawPending()); | 702 EXPECT_TRUE(scheduler->RedrawPending()); |
600 EXPECT_TRUE(client.needs_begin_frame()); | 703 EXPECT_TRUE(client.needs_begin_frame()); |
601 | 704 |
602 // Fail the draw again. | 705 // Fail the draw again. |
603 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 706 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 707 scheduler->OnBeginFrameDeadline(); |
604 EXPECT_EQ(2, client.num_draws()); | 708 EXPECT_EQ(2, client.num_draws()); |
605 EXPECT_TRUE(scheduler->CommitPending()); | 709 EXPECT_TRUE(scheduler->CommitPending()); |
606 EXPECT_TRUE(scheduler->RedrawPending()); | 710 EXPECT_TRUE(scheduler->RedrawPending()); |
607 EXPECT_TRUE(client.needs_begin_frame()); | 711 EXPECT_TRUE(client.needs_begin_frame()); |
608 | 712 |
609 // Draw successfully. | 713 // Draw successfully. |
610 client.SetDrawWillHappen(true); | 714 client.SetDrawWillHappen(true); |
611 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 715 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 716 scheduler->OnBeginFrameDeadline(); |
612 EXPECT_EQ(3, client.num_draws()); | 717 EXPECT_EQ(3, client.num_draws()); |
613 EXPECT_TRUE(scheduler->CommitPending()); | 718 EXPECT_TRUE(scheduler->CommitPending()); |
614 EXPECT_FALSE(scheduler->RedrawPending()); | 719 EXPECT_FALSE(scheduler->RedrawPending()); |
615 EXPECT_TRUE(client.needs_begin_frame()); | 720 EXPECT_TRUE(client.needs_begin_frame()); |
616 } | 721 } |
617 | 722 |
618 TEST(SchedulerTest, NoSwapWhenDrawFails) { | 723 TEST(SchedulerTest, NoSwapWhenDrawFails) { |
619 SchedulerClientThatSetNeedsCommitInsideDraw client; | 724 SchedulerClientThatSetNeedsCommitInsideDraw client; |
620 SchedulerSettings default_scheduler_settings; | 725 SchedulerSettings default_scheduler_settings; |
621 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 726 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
622 scheduler->SetCanStart(); | 727 scheduler->SetCanStart(); |
623 scheduler->SetVisible(true); | 728 scheduler->SetVisible(true); |
624 scheduler->SetCanDraw(true); | 729 scheduler->SetCanDraw(true); |
625 InitializeOutputSurfaceAndFirstCommit(scheduler); | 730 InitializeOutputSurfaceAndFirstCommit(scheduler); |
626 client.Reset(); | 731 client.Reset(); |
627 | 732 |
628 scheduler->SetNeedsRedraw(); | 733 scheduler->SetNeedsRedraw(); |
629 EXPECT_TRUE(scheduler->RedrawPending()); | 734 EXPECT_TRUE(scheduler->RedrawPending()); |
630 EXPECT_TRUE(client.needs_begin_frame()); | 735 EXPECT_TRUE(client.needs_begin_frame()); |
631 EXPECT_EQ(0, client.num_draws()); | 736 EXPECT_EQ(0, client.num_draws()); |
632 | 737 |
633 // Draw successfully, this starts a new frame. | 738 // Draw successfully, this starts a new frame. |
634 client.SetNeedsCommitOnNextDraw(); | 739 client.SetNeedsCommitOnNextDraw(); |
635 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 740 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 741 scheduler->OnBeginFrameDeadline(); |
636 EXPECT_EQ(1, client.num_draws()); | 742 EXPECT_EQ(1, client.num_draws()); |
637 | 743 |
638 scheduler->SetNeedsRedraw(); | 744 scheduler->SetNeedsRedraw(); |
639 EXPECT_TRUE(scheduler->RedrawPending()); | 745 EXPECT_TRUE(scheduler->RedrawPending()); |
640 EXPECT_TRUE(client.needs_begin_frame()); | 746 EXPECT_TRUE(client.needs_begin_frame()); |
641 | 747 |
642 // Fail to draw, this should not start a frame. | 748 // Fail to draw, this should not start a frame. |
643 client.SetDrawWillHappen(false); | 749 client.SetDrawWillHappen(false); |
644 client.SetNeedsCommitOnNextDraw(); | 750 client.SetNeedsCommitOnNextDraw(); |
645 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 751 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 752 scheduler->OnBeginFrameDeadline(); |
646 EXPECT_EQ(2, client.num_draws()); | 753 EXPECT_EQ(2, client.num_draws()); |
647 } | 754 } |
648 | 755 |
649 TEST(SchedulerTest, NoSwapWhenSwapFailsDuringForcedCommit) { | 756 TEST(SchedulerTest, NoSwapWhenSwapFailsDuringForcedCommit) { |
650 FakeSchedulerClient client; | 757 FakeSchedulerClient client; |
651 SchedulerSettings default_scheduler_settings; | 758 SchedulerSettings default_scheduler_settings; |
652 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 759 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
653 | 760 |
654 // Tell the client that it will fail to swap. | 761 // Tell the client that it will fail to swap. |
655 client.SetDrawWillHappen(true); | 762 client.SetDrawWillHappen(true); |
(...skipping 27 matching lines...) Expand all Loading... |
683 scheduler->FinishCommit(); | 790 scheduler->FinishCommit(); |
684 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndReadback")); | 791 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndReadback")); |
685 | 792 |
686 // The replacement commit comes in after 2 readbacks. | 793 // The replacement commit comes in after 2 readbacks. |
687 client.Reset(); | 794 client.Reset(); |
688 scheduler->FinishCommit(); | 795 scheduler->FinishCommit(); |
689 } | 796 } |
690 | 797 |
691 } // namespace | 798 } // namespace |
692 } // namespace cc | 799 } // namespace cc |
OLD | NEW |