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 } |
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 Loading... |
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 1897 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2265 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | 2279 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); |
2266 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2280 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
2267 client_->Reset(); | 2281 client_->Reset(); |
2268 | 2282 |
2269 task_runner().RunPendingTasks(); // Run posted deadline. | 2283 task_runner().RunPendingTasks(); // Run posted deadline. |
2270 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 0, 2); | 2284 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 0, 2); |
2271 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); | 2285 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); |
2272 client_->Reset(); | 2286 client_->Reset(); |
2273 } | 2287 } |
2274 | 2288 |
| 2289 TEST_F(SchedulerTest, UsingSynchronousCompositor) { |
| 2290 scheduler_settings_.using_synchronous_renderer_compositor = true; |
| 2291 scheduler_settings_.use_external_begin_frame_source = true; |
| 2292 scheduler_settings_.impl_side_painting = true; |
| 2293 SetUpScheduler(true); |
| 2294 |
| 2295 // Compositor thread initiated input/animation. |
| 2296 // -------------------------------------------- |
| 2297 scheduler_->SetNeedsAnimate(); |
| 2298 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
| 2299 client_->Reset(); |
| 2300 |
| 2301 // Next vsync. |
| 2302 AdvanceFrame(); |
| 2303 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); |
| 2304 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 3); |
| 2305 EXPECT_ACTION("ScheduledActionInvalidateOutputSurface", client_, 2, 3); |
| 2306 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2307 client_->Reset(); |
| 2308 |
| 2309 // Continue with animation. |
| 2310 scheduler_->SetNeedsAnimate(); |
| 2311 EXPECT_NO_ACTION(client_); |
| 2312 |
| 2313 // Android onDraw. |
| 2314 scheduler_->SetNeedsRedraw(); |
| 2315 scheduler_->OnDrawForOutputSurface(); |
| 2316 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); |
| 2317 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2318 client_->Reset(); |
| 2319 |
| 2320 // Next vsync. |
| 2321 AdvanceFrame(); |
| 2322 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); |
| 2323 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 3); |
| 2324 EXPECT_ACTION("ScheduledActionInvalidateOutputSurface", client_, 2, 3); |
| 2325 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2326 client_->Reset(); |
| 2327 |
| 2328 // Android onDraw. |
| 2329 scheduler_->SetNeedsRedraw(); |
| 2330 scheduler_->OnDrawForOutputSurface(); |
| 2331 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); |
| 2332 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2333 client_->Reset(); |
| 2334 |
| 2335 // Idle on next vsync. |
| 2336 AdvanceFrame(); |
| 2337 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); |
| 2338 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 1, 3); |
| 2339 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); |
| 2340 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2341 client_->Reset(); |
| 2342 |
| 2343 // Android onDraw after idle. |
| 2344 // -------------------------- |
| 2345 scheduler_->SetNeedsRedraw(); |
| 2346 scheduler_->OnDrawForOutputSurface(); |
| 2347 EXPECT_ACTION("SetNeedsBeginFrames(true)", client_, 0, 3); |
| 2348 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 3); |
| 2349 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 2, 3); |
| 2350 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2351 client_->Reset(); |
| 2352 |
| 2353 // Idle on next vsync. |
| 2354 AdvanceFrame(); |
| 2355 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); |
| 2356 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 1, 3); |
| 2357 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); |
| 2358 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2359 client_->Reset(); |
| 2360 |
| 2361 // Main thread initiated activity. |
| 2362 // ------------------------------- |
| 2363 scheduler_->SetNeedsCommit(); |
| 2364 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
| 2365 client_->Reset(); |
| 2366 |
| 2367 // Next vsync. |
| 2368 AdvanceFrame(); |
| 2369 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2370 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 2371 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2372 client_->Reset(); |
| 2373 |
| 2374 scheduler_->NotifyBeginMainFrameStarted(); |
| 2375 EXPECT_NO_ACTION(client_); |
| 2376 |
| 2377 // Next vsync. |
| 2378 AdvanceFrame(); |
| 2379 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); |
| 2380 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2381 client_->Reset(); |
| 2382 |
| 2383 scheduler_->NotifyReadyToCommit(); |
| 2384 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 2385 client_->Reset(); |
| 2386 |
| 2387 scheduler_->NotifyReadyToActivate(); |
| 2388 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); |
| 2389 client_->Reset(); |
| 2390 |
| 2391 // Next vsync. |
| 2392 AdvanceFrame(); |
| 2393 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); |
| 2394 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 3); |
| 2395 EXPECT_ACTION("ScheduledActionInvalidateOutputSurface", client_, 2, 3); |
| 2396 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2397 client_->Reset(); |
| 2398 |
| 2399 // Android onDraw. |
| 2400 scheduler_->SetNeedsRedraw(); |
| 2401 scheduler_->OnDrawForOutputSurface(); |
| 2402 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); |
| 2403 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2404 client_->Reset(); |
| 2405 |
| 2406 // Idle on next vsync. |
| 2407 AdvanceFrame(); |
| 2408 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); |
| 2409 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 1, 3); |
| 2410 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); |
| 2411 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2412 client_->Reset(); |
| 2413 } |
| 2414 |
2275 } // namespace | 2415 } // namespace |
2276 } // namespace cc | 2416 } // namespace cc |
OLD | NEW |