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

Side by Side Diff: cc/scheduler/scheduler_unittest.cc

Issue 817603002: cc: Make scheduling be driven by vsync for android webview. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix rebase compile errors. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/scheduler/scheduler_state_machine.cc ('k') | cc/surfaces/display.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/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
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 }
144 void DidAnticipatedDrawTimeChange(base::TimeTicks) override { 148 void DidAnticipatedDrawTimeChange(base::TimeTicks) override {
145 if (log_anticipated_draw_time_change_) 149 if (log_anticipated_draw_time_change_)
146 PushAction("DidAnticipatedDrawTimeChange"); 150 PushAction("DidAnticipatedDrawTimeChange");
147 } 151 }
148 base::TimeDelta DrawDurationEstimate() override { return base::TimeDelta(); } 152 base::TimeDelta DrawDurationEstimate() override { return base::TimeDelta(); }
149 base::TimeDelta BeginMainFrameToCommitDurationEstimate() override { 153 base::TimeDelta BeginMainFrameToCommitDurationEstimate() override {
150 return base::TimeDelta(); 154 return base::TimeDelta();
151 } 155 }
152 base::TimeDelta CommitToActivateDurationEstimate() override { 156 base::TimeDelta CommitToActivateDurationEstimate() override {
153 return base::TimeDelta(); 157 return base::TimeDelta();
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); 303 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
300 client_->Reset(); 304 client_->Reset();
301 305
302 { 306 {
303 SCOPED_TRACE("Do first frame to commit after initialize."); 307 SCOPED_TRACE("Do first frame to commit after initialize.");
304 AdvanceFrame(); 308 AdvanceFrame();
305 309
306 scheduler_->NotifyBeginMainFrameStarted(); 310 scheduler_->NotifyBeginMainFrameStarted();
307 scheduler_->NotifyReadyToCommitThenActivateIfNeeded(); 311 scheduler_->NotifyReadyToCommitThenActivateIfNeeded();
308 312
309 // Run the posted deadline task. 313 EXPECT_FALSE(scheduler_->CommitPending());
310 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); 314
311 task_runner_->RunTasksWhile(client_->ImplFrameDeadlinePending(true)); 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
312 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); 324 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
313
314 EXPECT_FALSE(scheduler_->CommitPending());
315 } 325 }
316 326
317 client_->Reset(); 327 client_->Reset();
318 328
319 { 329 {
320 SCOPED_TRACE( 330 SCOPED_TRACE(
321 "Run second frame so Scheduler calls SetNeedsBeginFrame(false)."); 331 "Run second frame so Scheduler calls SetNeedsBeginFrame(false).");
322 AdvanceFrame(); 332 AdvanceFrame();
323 333
324 // Run the posted deadline task. 334 if (!scheduler_settings_.using_synchronous_renderer_compositor) {
325 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); 335 // Run the posted deadline task.
326 task_runner_->RunTasksWhile(client_->ImplFrameDeadlinePending(true)); 336 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
337 task_runner_->RunTasksWhile(client_->ImplFrameDeadlinePending(true));
338 }
339
327 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); 340 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
328 } 341 }
329 342
330 EXPECT_FALSE(client_->needs_begin_frames()); 343 EXPECT_FALSE(client_->needs_begin_frames());
331 client_->Reset(); 344 client_->Reset();
332 } 345 }
333 346
334 // As this function contains EXPECT macros, to allow debugging it should be 347 // As this function contains EXPECT macros, to allow debugging it should be
335 // called inside EXPECT_SCOPED like so; 348 // called inside EXPECT_SCOPED like so;
336 // EXPECT_SCOPED(client.AdvanceFrame()); 349 // EXPECT_SCOPED(client.AdvanceFrame());
337 void AdvanceFrame() { 350 void AdvanceFrame() {
338 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), 351 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"),
339 "FakeSchedulerClient::AdvanceFrame"); 352 "FakeSchedulerClient::AdvanceFrame");
340 // Consume any previous deadline first, if no deadline is currently 353 // Consume any previous deadline first, if no deadline is currently
341 // pending, ImplFrameDeadlinePending will return false straight away and we 354 // pending, ImplFrameDeadlinePending will return false straight away and we
342 // will run no tasks. 355 // will run no tasks.
343 task_runner_->RunTasksWhile(client_->ImplFrameDeadlinePending(true)); 356 task_runner_->RunTasksWhile(client_->ImplFrameDeadlinePending(true));
344 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); 357 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
345 358
346 // Send the next BeginFrame message if using an external source, otherwise 359 // Send the next BeginFrame message if using an external source, otherwise
347 // it will be already in the task queue. 360 // it will be already in the task queue.
348 if (scheduler_->settings().use_external_begin_frame_source && 361 if (scheduler_->settings().use_external_begin_frame_source &&
349 scheduler_->FrameProductionThrottled()) { 362 scheduler_->FrameProductionThrottled()) {
350 SendNextBeginFrame(); 363 SendNextBeginFrame();
364 }
365
366 if (!scheduler_->settings().using_synchronous_renderer_compositor) {
367 // Then run tasks until new deadline is scheduled.
368 EXPECT_TRUE(task_runner_->RunTasksWhile(
369 client_->ImplFrameDeadlinePending(false)));
351 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); 370 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
352 } 371 }
353
354 // Then run tasks until new deadline is scheduled.
355 EXPECT_TRUE(
356 task_runner_->RunTasksWhile(client_->ImplFrameDeadlinePending(false)));
357 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
358 } 372 }
359 373
360 void SendNextBeginFrame() { 374 void SendNextBeginFrame() {
361 DCHECK(scheduler_->settings().use_external_begin_frame_source); 375 DCHECK(scheduler_->settings().use_external_begin_frame_source);
362 // Creep the time forward so that any BeginFrameArgs is not equal to the 376 // Creep the time forward so that any BeginFrameArgs is not equal to the
363 // last one otherwise we violate the BeginFrameSource contract. 377 // last one otherwise we violate the BeginFrameSource contract.
364 now_src_->AdvanceNow(BeginFrameArgs::DefaultInterval()); 378 now_src_->AdvanceNow(BeginFrameArgs::DefaultInterval());
365 fake_external_begin_frame_source_->TestOnBeginFrame( 379 fake_external_begin_frame_source_->TestOnBeginFrame(
366 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src())); 380 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src()));
367 } 381 }
(...skipping 1980 matching lines...) Expand 10 before | Expand all | Expand 10 after
2348 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); 2362 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_);
2349 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); 2363 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
2350 client_->Reset(); 2364 client_->Reset();
2351 2365
2352 task_runner().RunPendingTasks(); // Run posted deadline. 2366 task_runner().RunPendingTasks(); // Run posted deadline.
2353 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 0, 2); 2367 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 0, 2);
2354 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); 2368 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2);
2355 client_->Reset(); 2369 client_->Reset();
2356 } 2370 }
2357 2371
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
2358 TEST_F(SchedulerTest, AuthoritativeVSyncInterval) { 2498 TEST_F(SchedulerTest, AuthoritativeVSyncInterval) {
2359 SetUpScheduler(true); 2499 SetUpScheduler(true);
2360 2500
2361 base::TimeDelta initial_interval = 2501 base::TimeDelta initial_interval =
2362 scheduler_->begin_impl_frame_args().interval; 2502 scheduler_->begin_impl_frame_args().interval;
2363 base::TimeDelta authoritative_interval = 2503 base::TimeDelta authoritative_interval =
2364 base::TimeDelta::FromMilliseconds(33); 2504 base::TimeDelta::FromMilliseconds(33);
2365 2505
2366 scheduler_->SetNeedsCommit(); 2506 scheduler_->SetNeedsCommit();
2367 EXPECT_SCOPED(AdvanceFrame()); 2507 EXPECT_SCOPED(AdvanceFrame());
(...skipping 10 matching lines...) Expand all
2378 2518
2379 // At the next BeginFrame, authoritative interval is used instead of previous 2519 // At the next BeginFrame, authoritative interval is used instead of previous
2380 // interval. 2520 // interval.
2381 EXPECT_NE(initial_interval, scheduler_->begin_impl_frame_args().interval); 2521 EXPECT_NE(initial_interval, scheduler_->begin_impl_frame_args().interval);
2382 EXPECT_EQ(authoritative_interval, 2522 EXPECT_EQ(authoritative_interval,
2383 scheduler_->begin_impl_frame_args().interval); 2523 scheduler_->begin_impl_frame_args().interval);
2384 } 2524 }
2385 2525
2386 } // namespace 2526 } // namespace
2387 } // namespace cc 2527 } // namespace cc
OLDNEW
« no previous file with comments | « cc/scheduler/scheduler_state_machine.cc ('k') | cc/surfaces/display.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698