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