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 <algorithm> | 7 #include <algorithm> |
8 #include "base/auto_reset.h" | 8 #include "base/auto_reset.h" |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/debug/trace_event_argument.h" | 10 #include "base/debug/trace_event_argument.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 base::TimeTicks frame_time) { | 72 base::TimeTicks frame_time) { |
73 base::TimeTicks deadline = time_source_->NextTickTime(); | 73 base::TimeTicks deadline = time_source_->NextTickTime(); |
74 return BeginFrameArgs::Create( | 74 return BeginFrameArgs::Create( |
75 frame_time, deadline, scheduler_->VSyncInterval()); | 75 frame_time, deadline, scheduler_->VSyncInterval()); |
76 } | 76 } |
77 | 77 |
78 Scheduler::Scheduler( | 78 Scheduler::Scheduler( |
79 SchedulerClient* client, | 79 SchedulerClient* client, |
80 const SchedulerSettings& scheduler_settings, | 80 const SchedulerSettings& scheduler_settings, |
81 int layer_tree_host_id, | 81 int layer_tree_host_id, |
82 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) | 82 const scoped_refptr<base::SingleThreadTaskRunner>& impl_task_runner) |
83 : settings_(scheduler_settings), | 83 : settings_(scheduler_settings), |
84 client_(client), | 84 client_(client), |
85 layer_tree_host_id_(layer_tree_host_id), | 85 layer_tree_host_id_(layer_tree_host_id), |
86 task_runner_(task_runner), | 86 impl_task_runner_(impl_task_runner), |
87 vsync_interval_(BeginFrameArgs::DefaultInterval()), | 87 vsync_interval_(BeginFrameArgs::DefaultInterval()), |
88 last_set_needs_begin_frame_(false), | 88 last_set_needs_begin_frame_(false), |
89 begin_unthrottled_frame_posted_(false), | 89 begin_unthrottled_frame_posted_(false), |
90 begin_retro_frame_posted_(false), | 90 begin_retro_frame_posted_(false), |
91 state_machine_(scheduler_settings), | 91 state_machine_(scheduler_settings), |
92 inside_process_scheduled_actions_(false), | 92 inside_process_scheduled_actions_(false), |
93 inside_action_(SchedulerStateMachine::ACTION_NONE), | 93 inside_action_(SchedulerStateMachine::ACTION_NONE), |
94 weak_factory_(this) { | 94 weak_factory_(this) { |
95 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), | 95 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), |
96 "Scheduler::Scheduler", | 96 "Scheduler::Scheduler", |
(...skipping 24 matching lines...) Expand all Loading... |
121 Scheduler::~Scheduler() { | 121 Scheduler::~Scheduler() { |
122 if (synthetic_begin_frame_source_) { | 122 if (synthetic_begin_frame_source_) { |
123 synthetic_begin_frame_source_->SetNeedsBeginFrame(false, | 123 synthetic_begin_frame_source_->SetNeedsBeginFrame(false, |
124 &begin_retro_frame_args_); | 124 &begin_retro_frame_args_); |
125 } | 125 } |
126 } | 126 } |
127 | 127 |
128 void Scheduler::SetupSyntheticBeginFrames() { | 128 void Scheduler::SetupSyntheticBeginFrames() { |
129 DCHECK(!synthetic_begin_frame_source_); | 129 DCHECK(!synthetic_begin_frame_source_); |
130 synthetic_begin_frame_source_.reset( | 130 synthetic_begin_frame_source_.reset( |
131 new SyntheticBeginFrameSource(this, task_runner_.get())); | 131 new SyntheticBeginFrameSource(this, impl_task_runner_.get())); |
132 } | 132 } |
133 | 133 |
134 void Scheduler::CommitVSyncParameters(base::TimeTicks timebase, | 134 void Scheduler::CommitVSyncParameters(base::TimeTicks timebase, |
135 base::TimeDelta interval) { | 135 base::TimeDelta interval) { |
136 // TODO(brianderson): We should not be receiving 0 intervals. | 136 // TODO(brianderson): We should not be receiving 0 intervals. |
137 if (interval == base::TimeDelta()) | 137 if (interval == base::TimeDelta()) |
138 interval = BeginFrameArgs::DefaultInterval(); | 138 interval = BeginFrameArgs::DefaultInterval(); |
139 vsync_interval_ = interval; | 139 vsync_interval_ = interval; |
140 if (!settings_.begin_frame_scheduling_enabled) | 140 if (!settings_.begin_frame_scheduling_enabled) |
141 synthetic_begin_frame_source_->CommitVSyncParameters(timebase, interval); | 141 synthetic_begin_frame_source_->CommitVSyncParameters(timebase, interval); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 begin_impl_frame_args_.deadline); | 267 begin_impl_frame_args_.deadline); |
268 int64 intervals = 1 + ((now - timebase) / begin_impl_frame_args_.interval); | 268 int64 intervals = 1 + ((now - timebase) / begin_impl_frame_args_.interval); |
269 return timebase + (begin_impl_frame_args_.interval * intervals); | 269 return timebase + (begin_impl_frame_args_.interval * intervals); |
270 } | 270 } |
271 | 271 |
272 base::TimeTicks Scheduler::LastBeginImplFrameTime() { | 272 base::TimeTicks Scheduler::LastBeginImplFrameTime() { |
273 return begin_impl_frame_args_.frame_time; | 273 return begin_impl_frame_args_.frame_time; |
274 } | 274 } |
275 | 275 |
276 void Scheduler::SetupNextBeginFrameIfNeeded() { | 276 void Scheduler::SetupNextBeginFrameIfNeeded() { |
277 if (!task_runner_) | |
278 return; | |
279 | |
280 bool needs_begin_frame = state_machine_.BeginFrameNeeded(); | 277 bool needs_begin_frame = state_machine_.BeginFrameNeeded(); |
281 | 278 |
282 if (settings_.throttle_frame_production) { | 279 if (settings_.throttle_frame_production) { |
283 SetupNextBeginFrameWhenVSyncThrottlingEnabled(needs_begin_frame); | 280 SetupNextBeginFrameWhenVSyncThrottlingEnabled(needs_begin_frame); |
284 } else { | 281 } else { |
285 SetupNextBeginFrameWhenVSyncThrottlingDisabled(needs_begin_frame); | 282 SetupNextBeginFrameWhenVSyncThrottlingDisabled(needs_begin_frame); |
286 } | 283 } |
287 SetupPollingMechanisms(needs_begin_frame); | 284 SetupPollingMechanisms(needs_begin_frame); |
288 } | 285 } |
289 | 286 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 return; | 321 return; |
325 | 322 |
326 if (state_machine_.begin_impl_frame_state() != | 323 if (state_machine_.begin_impl_frame_state() != |
327 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE && | 324 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE && |
328 state_machine_.begin_impl_frame_state() != | 325 state_machine_.begin_impl_frame_state() != |
329 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) { | 326 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) { |
330 return; | 327 return; |
331 } | 328 } |
332 | 329 |
333 begin_unthrottled_frame_posted_ = true; | 330 begin_unthrottled_frame_posted_ = true; |
334 task_runner_->PostTask(FROM_HERE, begin_unthrottled_frame_closure_); | 331 impl_task_runner_->PostTask(FROM_HERE, begin_unthrottled_frame_closure_); |
335 } | 332 } |
336 | 333 |
337 // BeginUnthrottledFrame is used when we aren't throttling frame production. | 334 // BeginUnthrottledFrame is used when we aren't throttling frame production. |
338 // This will usually be because VSync is disabled. | 335 // This will usually be because VSync is disabled. |
339 void Scheduler::BeginUnthrottledFrame() { | 336 void Scheduler::BeginUnthrottledFrame() { |
340 DCHECK(!settings_.throttle_frame_production); | 337 DCHECK(!settings_.throttle_frame_production); |
341 DCHECK(begin_retro_frame_args_.empty()); | 338 DCHECK(begin_retro_frame_args_.empty()); |
342 | 339 |
343 base::TimeTicks now = gfx::FrameTime::Now(); | 340 base::TimeTicks now = gfx::FrameTime::Now(); |
344 base::TimeTicks deadline = now + vsync_interval_; | 341 base::TimeTicks deadline = now + vsync_interval_; |
(...skipping 13 matching lines...) Expand all Loading... |
358 // aren't expecting any more BeginFrames. This should only be needed by | 355 // aren't expecting any more BeginFrames. This should only be needed by |
359 // the synchronous compositor when BeginFrameNeeded is false. | 356 // the synchronous compositor when BeginFrameNeeded is false. |
360 if (state_machine_.ShouldPollForAnticipatedDrawTriggers()) { | 357 if (state_machine_.ShouldPollForAnticipatedDrawTriggers()) { |
361 DCHECK(!state_machine_.SupportsProactiveBeginFrame()); | 358 DCHECK(!state_machine_.SupportsProactiveBeginFrame()); |
362 DCHECK(!needs_begin_frame); | 359 DCHECK(!needs_begin_frame); |
363 if (poll_for_draw_triggers_task_.IsCancelled()) { | 360 if (poll_for_draw_triggers_task_.IsCancelled()) { |
364 poll_for_draw_triggers_task_.Reset(poll_for_draw_triggers_closure_); | 361 poll_for_draw_triggers_task_.Reset(poll_for_draw_triggers_closure_); |
365 base::TimeDelta delay = begin_impl_frame_args_.IsValid() | 362 base::TimeDelta delay = begin_impl_frame_args_.IsValid() |
366 ? begin_impl_frame_args_.interval | 363 ? begin_impl_frame_args_.interval |
367 : BeginFrameArgs::DefaultInterval(); | 364 : BeginFrameArgs::DefaultInterval(); |
368 task_runner_->PostDelayedTask( | 365 impl_task_runner_->PostDelayedTask( |
369 FROM_HERE, poll_for_draw_triggers_task_.callback(), delay); | 366 FROM_HERE, poll_for_draw_triggers_task_.callback(), delay); |
370 } | 367 } |
371 } else { | 368 } else { |
372 poll_for_draw_triggers_task_.Cancel(); | 369 poll_for_draw_triggers_task_.Cancel(); |
373 | 370 |
374 // At this point we'd prefer to advance through the commit flow by | 371 // At this point we'd prefer to advance through the commit flow by |
375 // drawing a frame, however it's possible that the frame rate controller | 372 // drawing a frame, however it's possible that the frame rate controller |
376 // will not give us a BeginFrame until the commit completes. See | 373 // will not give us a BeginFrame until the commit completes. See |
377 // crbug.com/317430 for an example of a swap ack being held on commit. Thus | 374 // crbug.com/317430 for an example of a swap ack being held on commit. Thus |
378 // we set a repeating timer to poll on ProcessScheduledActions until we | 375 // we set a repeating timer to poll on ProcessScheduledActions until we |
379 // successfully reach BeginFrame. Synchronous compositor does not use | 376 // successfully reach BeginFrame. Synchronous compositor does not use |
380 // frame rate controller or have the circular wait in the bug. | 377 // frame rate controller or have the circular wait in the bug. |
381 if (IsBeginMainFrameSentOrStarted() && | 378 if (IsBeginMainFrameSentOrStarted() && |
382 !settings_.using_synchronous_renderer_compositor) { | 379 !settings_.using_synchronous_renderer_compositor) { |
383 needs_advance_commit_state_timer = true; | 380 needs_advance_commit_state_timer = true; |
384 } | 381 } |
385 } | 382 } |
386 | 383 |
387 if (needs_advance_commit_state_timer) { | 384 if (needs_advance_commit_state_timer) { |
388 if (advance_commit_state_task_.IsCancelled() && | 385 if (advance_commit_state_task_.IsCancelled() && |
389 begin_impl_frame_args_.IsValid()) { | 386 begin_impl_frame_args_.IsValid()) { |
390 // Since we'd rather get a BeginImplFrame by the normal mechanism, we | 387 // Since we'd rather get a BeginImplFrame by the normal mechanism, we |
391 // set the interval to twice the interval from the previous frame. | 388 // set the interval to twice the interval from the previous frame. |
392 advance_commit_state_task_.Reset(advance_commit_state_closure_); | 389 advance_commit_state_task_.Reset(advance_commit_state_closure_); |
393 task_runner_->PostDelayedTask(FROM_HERE, | 390 impl_task_runner_->PostDelayedTask(FROM_HERE, |
394 advance_commit_state_task_.callback(), | 391 advance_commit_state_task_.callback(), |
395 begin_impl_frame_args_.interval * 2); | 392 begin_impl_frame_args_.interval * 2); |
396 } | 393 } |
397 } else { | 394 } else { |
398 advance_commit_state_task_.Cancel(); | 395 advance_commit_state_task_.Cancel(); |
399 } | 396 } |
400 } | 397 } |
401 | 398 |
402 // BeginFrame is the mechanism that tells us that now is a good time to start | 399 // BeginFrame is the mechanism that tells us that now is a good time to start |
403 // making a frame. Usually this means that user input for the frame is complete. | 400 // making a frame. Usually this means that user input for the frame is complete. |
404 // If the scheduler is busy, we queue the BeginFrame to be handled later as | 401 // If the scheduler is busy, we queue the BeginFrame to be handled later as |
405 // a BeginRetroFrame. | 402 // a BeginRetroFrame. |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 | 484 |
488 // begin_retro_frame_args_ should always be empty for the | 485 // begin_retro_frame_args_ should always be empty for the |
489 // synchronous compositor. | 486 // synchronous compositor. |
490 DCHECK(!settings_.using_synchronous_renderer_compositor); | 487 DCHECK(!settings_.using_synchronous_renderer_compositor); |
491 | 488 |
492 if (state_machine_.begin_impl_frame_state() != | 489 if (state_machine_.begin_impl_frame_state() != |
493 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE) | 490 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE) |
494 return; | 491 return; |
495 | 492 |
496 begin_retro_frame_posted_ = true; | 493 begin_retro_frame_posted_ = true; |
497 task_runner_->PostTask(FROM_HERE, begin_retro_frame_closure_); | 494 impl_task_runner_->PostTask(FROM_HERE, begin_retro_frame_closure_); |
498 } | 495 } |
499 | 496 |
500 // BeginImplFrame starts a compositor frame that will wait up until a deadline | 497 // BeginImplFrame starts a compositor frame that will wait up until a deadline |
501 // for a BeginMainFrame+activation to complete before it times out and draws | 498 // for a BeginMainFrame+activation to complete before it times out and draws |
502 // any asynchronous animation and scroll/pinch updates. | 499 // any asynchronous animation and scroll/pinch updates. |
503 void Scheduler::BeginImplFrame(const BeginFrameArgs& args) { | 500 void Scheduler::BeginImplFrame(const BeginFrameArgs& args) { |
504 TRACE_EVENT1("cc", "Scheduler::BeginImplFrame", "args", args.AsValue()); | 501 TRACE_EVENT1("cc", "Scheduler::BeginImplFrame", "args", args.AsValue()); |
505 DCHECK_EQ(state_machine_.begin_impl_frame_state(), | 502 DCHECK(state_machine_.begin_impl_frame_state() == |
506 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); | 503 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); |
507 DCHECK(state_machine_.HasInitializedOutputSurface()); | 504 DCHECK(state_machine_.HasInitializedOutputSurface()); |
508 | 505 |
509 advance_commit_state_task_.Cancel(); | 506 advance_commit_state_task_.Cancel(); |
510 | 507 |
511 base::TimeDelta draw_duration_estimate = client_->DrawDurationEstimate(); | 508 base::TimeDelta draw_duration_estimate = client_->DrawDurationEstimate(); |
512 begin_impl_frame_args_ = args; | 509 begin_impl_frame_args_ = args; |
513 begin_impl_frame_args_.deadline -= draw_duration_estimate; | 510 begin_impl_frame_args_.deadline -= draw_duration_estimate; |
514 | 511 |
515 if (!state_machine_.smoothness_takes_priority() && | 512 if (!state_machine_.smoothness_takes_priority() && |
516 state_machine_.MainThreadIsInHighLatencyMode() && | 513 state_machine_.MainThreadIsInHighLatencyMode() && |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 // up the BeginImplFrame and deadline as well. | 560 // up the BeginImplFrame and deadline as well. |
564 OnBeginImplFrameDeadline(); | 561 OnBeginImplFrameDeadline(); |
565 return; | 562 return; |
566 } | 563 } |
567 begin_impl_frame_deadline_task_.Cancel(); | 564 begin_impl_frame_deadline_task_.Cancel(); |
568 begin_impl_frame_deadline_task_.Reset(begin_impl_frame_deadline_closure_); | 565 begin_impl_frame_deadline_task_.Reset(begin_impl_frame_deadline_closure_); |
569 | 566 |
570 base::TimeDelta delta = deadline - gfx::FrameTime::Now(); | 567 base::TimeDelta delta = deadline - gfx::FrameTime::Now(); |
571 if (delta <= base::TimeDelta()) | 568 if (delta <= base::TimeDelta()) |
572 delta = base::TimeDelta(); | 569 delta = base::TimeDelta(); |
573 task_runner_->PostDelayedTask( | 570 impl_task_runner_->PostDelayedTask( |
574 FROM_HERE, begin_impl_frame_deadline_task_.callback(), delta); | 571 FROM_HERE, begin_impl_frame_deadline_task_.callback(), delta); |
575 } | 572 } |
576 | 573 |
577 void Scheduler::OnBeginImplFrameDeadline() { | 574 void Scheduler::OnBeginImplFrameDeadline() { |
578 TRACE_EVENT0("cc", "Scheduler::OnBeginImplFrameDeadline"); | 575 TRACE_EVENT0("cc", "Scheduler::OnBeginImplFrameDeadline"); |
579 begin_impl_frame_deadline_task_.Cancel(); | 576 begin_impl_frame_deadline_task_.Cancel(); |
580 | 577 |
581 // We split the deadline actions up into two phases so the state machine | 578 // We split the deadline actions up into two phases so the state machine |
582 // has a chance to trigger actions that should occur durring and after | 579 // has a chance to trigger actions that should occur durring and after |
583 // the deadline separately. For example: | 580 // the deadline separately. For example: |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
755 } | 752 } |
756 | 753 |
757 bool Scheduler::IsBeginMainFrameSentOrStarted() const { | 754 bool Scheduler::IsBeginMainFrameSentOrStarted() const { |
758 return (state_machine_.commit_state() == | 755 return (state_machine_.commit_state() == |
759 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT || | 756 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT || |
760 state_machine_.commit_state() == | 757 state_machine_.commit_state() == |
761 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED); | 758 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED); |
762 } | 759 } |
763 | 760 |
764 } // namespace cc | 761 } // namespace cc |
OLD | NEW |