OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/scheduler/scheduler.h" | 5 #include "cc/scheduler/scheduler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 void ScheduledActionCommit() override { PushAction("ScheduledActionCommit"); } | 134 void ScheduledActionCommit() override { PushAction("ScheduledActionCommit"); } |
135 void ScheduledActionActivateSyncTree() override { | 135 void ScheduledActionActivateSyncTree() override { |
136 PushAction("ScheduledActionActivateSyncTree"); | 136 PushAction("ScheduledActionActivateSyncTree"); |
137 } | 137 } |
138 void ScheduledActionBeginOutputSurfaceCreation() override { | 138 void ScheduledActionBeginOutputSurfaceCreation() override { |
139 PushAction("ScheduledActionBeginOutputSurfaceCreation"); | 139 PushAction("ScheduledActionBeginOutputSurfaceCreation"); |
140 } | 140 } |
141 void ScheduledActionPrepareTiles() override { | 141 void ScheduledActionPrepareTiles() override { |
142 PushAction("ScheduledActionPrepareTiles"); | 142 PushAction("ScheduledActionPrepareTiles"); |
143 } | 143 } |
144 void ScheduledActionInvalidateOutputSurface() override { | |
145 actions_.push_back("ScheduledActionInvalidateOutputSurface"); | |
146 states_.push_back(scheduler_->AsValue()); | |
147 } | |
148 void DidAnticipatedDrawTimeChange(base::TimeTicks) override { | 144 void DidAnticipatedDrawTimeChange(base::TimeTicks) override { |
149 if (log_anticipated_draw_time_change_) | 145 if (log_anticipated_draw_time_change_) |
150 PushAction("DidAnticipatedDrawTimeChange"); | 146 PushAction("DidAnticipatedDrawTimeChange"); |
151 } | 147 } |
152 base::TimeDelta DrawDurationEstimate() override { return base::TimeDelta(); } | 148 base::TimeDelta DrawDurationEstimate() override { return base::TimeDelta(); } |
153 base::TimeDelta BeginMainFrameToCommitDurationEstimate() override { | 149 base::TimeDelta BeginMainFrameToCommitDurationEstimate() override { |
154 return base::TimeDelta(); | 150 return base::TimeDelta(); |
155 } | 151 } |
156 base::TimeDelta CommitToActivateDurationEstimate() override { | 152 base::TimeDelta CommitToActivateDurationEstimate() override { |
157 return base::TimeDelta(); | 153 return base::TimeDelta(); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 299 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
304 client_->Reset(); | 300 client_->Reset(); |
305 | 301 |
306 { | 302 { |
307 SCOPED_TRACE("Do first frame to commit after initialize."); | 303 SCOPED_TRACE("Do first frame to commit after initialize."); |
308 AdvanceFrame(); | 304 AdvanceFrame(); |
309 | 305 |
310 scheduler_->NotifyBeginMainFrameStarted(); | 306 scheduler_->NotifyBeginMainFrameStarted(); |
311 scheduler_->NotifyReadyToCommitThenActivateIfNeeded(); | 307 scheduler_->NotifyReadyToCommitThenActivateIfNeeded(); |
312 | 308 |
| 309 // Run the posted deadline task. |
| 310 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 311 task_runner_->RunTasksWhile(client_->ImplFrameDeadlinePending(true)); |
| 312 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 313 |
313 EXPECT_FALSE(scheduler_->CommitPending()); | 314 EXPECT_FALSE(scheduler_->CommitPending()); |
314 | |
315 if (scheduler_settings_.using_synchronous_renderer_compositor) { | |
316 scheduler_->SetNeedsRedraw(); | |
317 scheduler_->OnDrawForOutputSurface(); | |
318 } else { | |
319 // Run the posted deadline task. | |
320 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | |
321 task_runner_->RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | |
322 } | |
323 | |
324 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | |
325 } | 315 } |
326 | 316 |
327 client_->Reset(); | 317 client_->Reset(); |
328 | 318 |
329 { | 319 { |
330 SCOPED_TRACE( | 320 SCOPED_TRACE( |
331 "Run second frame so Scheduler calls SetNeedsBeginFrame(false)."); | 321 "Run second frame so Scheduler calls SetNeedsBeginFrame(false)."); |
332 AdvanceFrame(); | 322 AdvanceFrame(); |
333 | 323 |
334 if (!scheduler_settings_.using_synchronous_renderer_compositor) { | 324 // Run the posted deadline task. |
335 // Run the posted deadline task. | 325 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
336 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 326 task_runner_->RunTasksWhile(client_->ImplFrameDeadlinePending(true)); |
337 task_runner_->RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | |
338 } | |
339 | |
340 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 327 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
341 } | 328 } |
342 | 329 |
343 EXPECT_FALSE(client_->needs_begin_frames()); | 330 EXPECT_FALSE(client_->needs_begin_frames()); |
344 client_->Reset(); | 331 client_->Reset(); |
345 } | 332 } |
346 | 333 |
347 // As this function contains EXPECT macros, to allow debugging it should be | 334 // As this function contains EXPECT macros, to allow debugging it should be |
348 // called inside EXPECT_SCOPED like so; | 335 // called inside EXPECT_SCOPED like so; |
349 // EXPECT_SCOPED(client.AdvanceFrame()); | 336 // EXPECT_SCOPED(client.AdvanceFrame()); |
350 void AdvanceFrame() { | 337 void AdvanceFrame() { |
351 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), | 338 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), |
352 "FakeSchedulerClient::AdvanceFrame"); | 339 "FakeSchedulerClient::AdvanceFrame"); |
353 // Consume any previous deadline first, if no deadline is currently | 340 // Consume any previous deadline first, if no deadline is currently |
354 // pending, ImplFrameDeadlinePending will return false straight away and we | 341 // pending, ImplFrameDeadlinePending will return false straight away and we |
355 // will run no tasks. | 342 // will run no tasks. |
356 task_runner_->RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 343 task_runner_->RunTasksWhile(client_->ImplFrameDeadlinePending(true)); |
357 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 344 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
358 | 345 |
359 // Send the next BeginFrame message if using an external source, otherwise | 346 // Send the next BeginFrame message if using an external source, otherwise |
360 // it will be already in the task queue. | 347 // it will be already in the task queue. |
361 if (scheduler_->settings().use_external_begin_frame_source && | 348 if (scheduler_->settings().use_external_begin_frame_source && |
362 scheduler_->FrameProductionThrottled()) { | 349 scheduler_->FrameProductionThrottled()) { |
363 SendNextBeginFrame(); | 350 SendNextBeginFrame(); |
| 351 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
364 } | 352 } |
365 | 353 |
366 if (!scheduler_->settings().using_synchronous_renderer_compositor) { | 354 // Then run tasks until new deadline is scheduled. |
367 // Then run tasks until new deadline is scheduled. | 355 EXPECT_TRUE( |
368 EXPECT_TRUE(task_runner_->RunTasksWhile( | 356 task_runner_->RunTasksWhile(client_->ImplFrameDeadlinePending(false))); |
369 client_->ImplFrameDeadlinePending(false))); | 357 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
370 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | |
371 } | |
372 } | 358 } |
373 | 359 |
374 void SendNextBeginFrame() { | 360 void SendNextBeginFrame() { |
375 DCHECK(scheduler_->settings().use_external_begin_frame_source); | 361 DCHECK(scheduler_->settings().use_external_begin_frame_source); |
376 // Creep the time forward so that any BeginFrameArgs is not equal to the | 362 // Creep the time forward so that any BeginFrameArgs is not equal to the |
377 // last one otherwise we violate the BeginFrameSource contract. | 363 // last one otherwise we violate the BeginFrameSource contract. |
378 now_src_->AdvanceNow(BeginFrameArgs::DefaultInterval()); | 364 now_src_->AdvanceNow(BeginFrameArgs::DefaultInterval()); |
379 fake_external_begin_frame_source_->TestOnBeginFrame( | 365 fake_external_begin_frame_source_->TestOnBeginFrame( |
380 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src())); | 366 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src())); |
381 } | 367 } |
(...skipping 1980 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2362 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | 2348 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); |
2363 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2349 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
2364 client_->Reset(); | 2350 client_->Reset(); |
2365 | 2351 |
2366 task_runner().RunPendingTasks(); // Run posted deadline. | 2352 task_runner().RunPendingTasks(); // Run posted deadline. |
2367 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 0, 2); | 2353 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 0, 2); |
2368 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); | 2354 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); |
2369 client_->Reset(); | 2355 client_->Reset(); |
2370 } | 2356 } |
2371 | 2357 |
2372 TEST_F(SchedulerTest, UsingSynchronousCompositor) { | |
2373 scheduler_settings_.using_synchronous_renderer_compositor = true; | |
2374 scheduler_settings_.use_external_begin_frame_source = true; | |
2375 scheduler_settings_.impl_side_painting = true; | |
2376 SetUpScheduler(true); | |
2377 | |
2378 // Compositor thread initiated input/animation. | |
2379 // -------------------------------------------- | |
2380 scheduler_->SetNeedsAnimate(); | |
2381 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | |
2382 client_->Reset(); | |
2383 | |
2384 // Next vsync. | |
2385 AdvanceFrame(); | |
2386 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); | |
2387 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 3); | |
2388 EXPECT_ACTION("ScheduledActionInvalidateOutputSurface", client_, 2, 3); | |
2389 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | |
2390 client_->Reset(); | |
2391 | |
2392 // Continue with animation. | |
2393 scheduler_->SetNeedsAnimate(); | |
2394 EXPECT_NO_ACTION(client_); | |
2395 | |
2396 // Android onDraw. | |
2397 scheduler_->SetNeedsRedraw(); | |
2398 scheduler_->OnDrawForOutputSurface(); | |
2399 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | |
2400 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | |
2401 client_->Reset(); | |
2402 | |
2403 // Next vsync. | |
2404 AdvanceFrame(); | |
2405 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); | |
2406 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 3); | |
2407 EXPECT_ACTION("ScheduledActionInvalidateOutputSurface", client_, 2, 3); | |
2408 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | |
2409 client_->Reset(); | |
2410 | |
2411 // Android onDraw. | |
2412 scheduler_->SetNeedsRedraw(); | |
2413 scheduler_->OnDrawForOutputSurface(); | |
2414 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | |
2415 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | |
2416 client_->Reset(); | |
2417 | |
2418 // Idle on next vsync. | |
2419 AdvanceFrame(); | |
2420 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); | |
2421 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 1, 3); | |
2422 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); | |
2423 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | |
2424 client_->Reset(); | |
2425 | |
2426 // Android onDraw after idle. | |
2427 // -------------------------- | |
2428 scheduler_->SetNeedsRedraw(); | |
2429 scheduler_->OnDrawForOutputSurface(); | |
2430 EXPECT_ACTION("SetNeedsBeginFrames(true)", client_, 0, 3); | |
2431 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 3); | |
2432 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 2, 3); | |
2433 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | |
2434 client_->Reset(); | |
2435 | |
2436 // Idle on next vsync. | |
2437 AdvanceFrame(); | |
2438 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); | |
2439 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 1, 3); | |
2440 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); | |
2441 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | |
2442 client_->Reset(); | |
2443 | |
2444 // Main thread initiated activity. | |
2445 // ------------------------------- | |
2446 scheduler_->SetNeedsCommit(); | |
2447 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | |
2448 client_->Reset(); | |
2449 | |
2450 // Next vsync. | |
2451 AdvanceFrame(); | |
2452 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | |
2453 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | |
2454 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | |
2455 client_->Reset(); | |
2456 | |
2457 scheduler_->NotifyBeginMainFrameStarted(); | |
2458 EXPECT_NO_ACTION(client_); | |
2459 | |
2460 // Next vsync. | |
2461 AdvanceFrame(); | |
2462 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | |
2463 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | |
2464 client_->Reset(); | |
2465 | |
2466 scheduler_->NotifyReadyToCommit(); | |
2467 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | |
2468 client_->Reset(); | |
2469 | |
2470 scheduler_->NotifyReadyToActivate(); | |
2471 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); | |
2472 client_->Reset(); | |
2473 | |
2474 // Next vsync. | |
2475 AdvanceFrame(); | |
2476 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); | |
2477 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 3); | |
2478 EXPECT_ACTION("ScheduledActionInvalidateOutputSurface", client_, 2, 3); | |
2479 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | |
2480 client_->Reset(); | |
2481 | |
2482 // Android onDraw. | |
2483 scheduler_->SetNeedsRedraw(); | |
2484 scheduler_->OnDrawForOutputSurface(); | |
2485 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | |
2486 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | |
2487 client_->Reset(); | |
2488 | |
2489 // Idle on next vsync. | |
2490 AdvanceFrame(); | |
2491 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); | |
2492 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 1, 3); | |
2493 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); | |
2494 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | |
2495 client_->Reset(); | |
2496 } | |
2497 | |
2498 TEST_F(SchedulerTest, AuthoritativeVSyncInterval) { | 2358 TEST_F(SchedulerTest, AuthoritativeVSyncInterval) { |
2499 SetUpScheduler(true); | 2359 SetUpScheduler(true); |
2500 | 2360 |
2501 base::TimeDelta initial_interval = | 2361 base::TimeDelta initial_interval = |
2502 scheduler_->begin_impl_frame_args().interval; | 2362 scheduler_->begin_impl_frame_args().interval; |
2503 base::TimeDelta authoritative_interval = | 2363 base::TimeDelta authoritative_interval = |
2504 base::TimeDelta::FromMilliseconds(33); | 2364 base::TimeDelta::FromMilliseconds(33); |
2505 | 2365 |
2506 scheduler_->SetNeedsCommit(); | 2366 scheduler_->SetNeedsCommit(); |
2507 EXPECT_SCOPED(AdvanceFrame()); | 2367 EXPECT_SCOPED(AdvanceFrame()); |
(...skipping 10 matching lines...) Expand all Loading... |
2518 | 2378 |
2519 // At the next BeginFrame, authoritative interval is used instead of previous | 2379 // At the next BeginFrame, authoritative interval is used instead of previous |
2520 // interval. | 2380 // interval. |
2521 EXPECT_NE(initial_interval, scheduler_->begin_impl_frame_args().interval); | 2381 EXPECT_NE(initial_interval, scheduler_->begin_impl_frame_args().interval); |
2522 EXPECT_EQ(authoritative_interval, | 2382 EXPECT_EQ(authoritative_interval, |
2523 scheduler_->begin_impl_frame_args().interval); | 2383 scheduler_->begin_impl_frame_args().interval); |
2524 } | 2384 } |
2525 | 2385 |
2526 } // namespace | 2386 } // namespace |
2527 } // namespace cc | 2387 } // namespace cc |
OLD | NEW |