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

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

Issue 1055743002: Revert of cc: Make scheduling be driven by vsync for android webview. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 }
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
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 1894 matching lines...) Expand 10 before | Expand all | Expand 10 after
2276 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); 2262 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_);
2277 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); 2263 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
2278 client_->Reset(); 2264 client_->Reset();
2279 2265
2280 task_runner().RunPendingTasks(); // Run posted deadline. 2266 task_runner().RunPendingTasks(); // Run posted deadline.
2281 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 0, 2); 2267 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 0, 2);
2282 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); 2268 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2);
2283 client_->Reset(); 2269 client_->Reset();
2284 } 2270 }
2285 2271
2286 TEST_F(SchedulerTest, UsingSynchronousCompositor) {
2287 scheduler_settings_.using_synchronous_renderer_compositor = true;
2288 scheduler_settings_.use_external_begin_frame_source = true;
2289 scheduler_settings_.impl_side_painting = true;
2290 SetUpScheduler(true);
2291
2292 // Compositor thread initiated input/animation.
2293 // --------------------------------------------
2294 scheduler_->SetNeedsAnimate();
2295 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_);
2296 client_->Reset();
2297
2298 // Next vsync.
2299 AdvanceFrame();
2300 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3);
2301 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 3);
2302 EXPECT_ACTION("ScheduledActionInvalidateOutputSurface", client_, 2, 3);
2303 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
2304 client_->Reset();
2305
2306 // Continue with animation.
2307 scheduler_->SetNeedsAnimate();
2308 EXPECT_NO_ACTION(client_);
2309
2310 // Android onDraw.
2311 scheduler_->SetNeedsRedraw();
2312 scheduler_->OnDrawForOutputSurface();
2313 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_);
2314 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
2315 client_->Reset();
2316
2317 // Next vsync.
2318 AdvanceFrame();
2319 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3);
2320 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 3);
2321 EXPECT_ACTION("ScheduledActionInvalidateOutputSurface", client_, 2, 3);
2322 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
2323 client_->Reset();
2324
2325 // Android onDraw.
2326 scheduler_->SetNeedsRedraw();
2327 scheduler_->OnDrawForOutputSurface();
2328 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_);
2329 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
2330 client_->Reset();
2331
2332 // Idle on next vsync.
2333 AdvanceFrame();
2334 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3);
2335 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 1, 3);
2336 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3);
2337 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
2338 client_->Reset();
2339
2340 // Android onDraw after idle.
2341 // --------------------------
2342 scheduler_->SetNeedsRedraw();
2343 scheduler_->OnDrawForOutputSurface();
2344 EXPECT_ACTION("SetNeedsBeginFrames(true)", client_, 0, 3);
2345 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 3);
2346 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 2, 3);
2347 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
2348 client_->Reset();
2349
2350 // Idle on next vsync.
2351 AdvanceFrame();
2352 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3);
2353 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 1, 3);
2354 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3);
2355 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
2356 client_->Reset();
2357
2358 // Main thread initiated activity.
2359 // -------------------------------
2360 scheduler_->SetNeedsCommit();
2361 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_);
2362 client_->Reset();
2363
2364 // Next vsync.
2365 AdvanceFrame();
2366 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
2367 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2);
2368 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
2369 client_->Reset();
2370
2371 scheduler_->NotifyBeginMainFrameStarted();
2372 EXPECT_NO_ACTION(client_);
2373
2374 // Next vsync.
2375 AdvanceFrame();
2376 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_);
2377 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
2378 client_->Reset();
2379
2380 scheduler_->NotifyReadyToCommit();
2381 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_);
2382 client_->Reset();
2383
2384 scheduler_->NotifyReadyToActivate();
2385 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_);
2386 client_->Reset();
2387
2388 // Next vsync.
2389 AdvanceFrame();
2390 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3);
2391 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 3);
2392 EXPECT_ACTION("ScheduledActionInvalidateOutputSurface", client_, 2, 3);
2393 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
2394 client_->Reset();
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 // Idle on next vsync.
2404 AdvanceFrame();
2405 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3);
2406 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 1, 3);
2407 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3);
2408 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
2409 client_->Reset();
2410 }
2411
2412 TEST_F(SchedulerTest, AuthoritativeVSyncInterval) { 2272 TEST_F(SchedulerTest, AuthoritativeVSyncInterval) {
2413 SetUpScheduler(true); 2273 SetUpScheduler(true);
2414 2274
2415 base::TimeDelta initial_interval = 2275 base::TimeDelta initial_interval =
2416 scheduler_->begin_impl_frame_args().interval; 2276 scheduler_->begin_impl_frame_args().interval;
2417 base::TimeDelta authoritative_interval = 2277 base::TimeDelta authoritative_interval =
2418 base::TimeDelta::FromMilliseconds(33); 2278 base::TimeDelta::FromMilliseconds(33);
2419 2279
2420 scheduler_->SetNeedsCommit(); 2280 scheduler_->SetNeedsCommit();
2421 EXPECT_SCOPED(AdvanceFrame()); 2281 EXPECT_SCOPED(AdvanceFrame());
(...skipping 10 matching lines...) Expand all
2432 2292
2433 // At the next BeginFrame, authoritative interval is used instead of previous 2293 // At the next BeginFrame, authoritative interval is used instead of previous
2434 // interval. 2294 // interval.
2435 EXPECT_NE(initial_interval, scheduler_->begin_impl_frame_args().interval); 2295 EXPECT_NE(initial_interval, scheduler_->begin_impl_frame_args().interval);
2436 EXPECT_EQ(authoritative_interval, 2296 EXPECT_EQ(authoritative_interval,
2437 scheduler_->begin_impl_frame_args().interval); 2297 scheduler_->begin_impl_frame_args().interval);
2438 } 2298 }
2439 2299
2440 } // namespace 2300 } // namespace
2441 } // namespace cc 2301 } // 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