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 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 80 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
81 base::PowerMonitor* power_monitor, | 81 base::PowerMonitor* power_monitor, |
82 scoped_ptr<BeginFrameSource> external_begin_frame_source, | 82 scoped_ptr<BeginFrameSource> external_begin_frame_source, |
83 SchedulerFrameSourcesConstructor* frame_sources_constructor) | 83 SchedulerFrameSourcesConstructor* frame_sources_constructor) |
84 : frame_source_(), | 84 : frame_source_(), |
85 primary_frame_source_(NULL), | 85 primary_frame_source_(NULL), |
86 background_frame_source_(NULL), | 86 background_frame_source_(NULL), |
87 primary_frame_source_internal_(external_begin_frame_source.Pass()), | 87 primary_frame_source_internal_(external_begin_frame_source.Pass()), |
88 background_frame_source_internal_(), | 88 background_frame_source_internal_(), |
89 vsync_observer_(NULL), | 89 vsync_observer_(NULL), |
| 90 authoritative_vsync_interval_(base::TimeDelta()), |
| 91 last_vsync_timebase_(base::TimeTicks()), |
90 throttle_frame_production_(scheduler_settings.throttle_frame_production), | 92 throttle_frame_production_(scheduler_settings.throttle_frame_production), |
91 settings_(scheduler_settings), | 93 settings_(scheduler_settings), |
92 client_(client), | 94 client_(client), |
93 layer_tree_host_id_(layer_tree_host_id), | 95 layer_tree_host_id_(layer_tree_host_id), |
94 task_runner_(task_runner), | 96 task_runner_(task_runner), |
95 power_monitor_(power_monitor), | 97 power_monitor_(power_monitor), |
96 state_machine_(scheduler_settings), | 98 state_machine_(scheduler_settings), |
97 inside_process_scheduled_actions_(false), | 99 inside_process_scheduled_actions_(false), |
98 inside_action_(SchedulerStateMachine::ACTION_NONE), | 100 inside_action_(SchedulerStateMachine::ACTION_NONE), |
99 weak_factory_(this) { | 101 weak_factory_(this) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 } | 168 } |
167 } | 169 } |
168 | 170 |
169 void Scheduler::OnPowerStateChange(bool on_battery_power) { | 171 void Scheduler::OnPowerStateChange(bool on_battery_power) { |
170 DCHECK(settings_.disable_hi_res_timer_tasks_on_battery); | 172 DCHECK(settings_.disable_hi_res_timer_tasks_on_battery); |
171 state_machine_.SetImplLatencyTakesPriorityOnBattery(on_battery_power); | 173 state_machine_.SetImplLatencyTakesPriorityOnBattery(on_battery_power); |
172 } | 174 } |
173 | 175 |
174 void Scheduler::CommitVSyncParameters(base::TimeTicks timebase, | 176 void Scheduler::CommitVSyncParameters(base::TimeTicks timebase, |
175 base::TimeDelta interval) { | 177 base::TimeDelta interval) { |
176 // TODO(brianderson): We should not be receiving 0 intervals. | 178 if (authoritative_vsync_interval_ != base::TimeDelta()) { |
177 if (interval == base::TimeDelta()) | 179 interval = authoritative_vsync_interval_; |
| 180 } else if (interval == base::TimeDelta()) { |
| 181 // TODO(brianderson): We should not be receiving 0 intervals. |
178 interval = BeginFrameArgs::DefaultInterval(); | 182 interval = BeginFrameArgs::DefaultInterval(); |
| 183 } |
| 184 |
| 185 last_vsync_timebase_ = timebase; |
179 | 186 |
180 if (vsync_observer_) | 187 if (vsync_observer_) |
181 vsync_observer_->OnUpdateVSyncParameters(timebase, interval); | 188 vsync_observer_->OnUpdateVSyncParameters(timebase, interval); |
182 } | 189 } |
183 | 190 |
184 void Scheduler::SetEstimatedParentDrawTime(base::TimeDelta draw_time) { | 191 void Scheduler::SetEstimatedParentDrawTime(base::TimeDelta draw_time) { |
185 DCHECK_GE(draw_time.ToInternalValue(), 0); | 192 DCHECK_GE(draw_time.ToInternalValue(), 0); |
186 estimated_parent_draw_time_ = draw_time; | 193 estimated_parent_draw_time_ = draw_time; |
187 } | 194 } |
188 | 195 |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 } | 405 } |
399 | 406 |
400 // BeginFrame is the mechanism that tells us that now is a good time to start | 407 // 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. | 408 // 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 | 409 // If the scheduler is busy, we queue the BeginFrame to be handled later as |
403 // a BeginRetroFrame. | 410 // a BeginRetroFrame. |
404 bool Scheduler::OnBeginFrameMixInDelegate(const BeginFrameArgs& args) { | 411 bool Scheduler::OnBeginFrameMixInDelegate(const BeginFrameArgs& args) { |
405 TRACE_EVENT1("cc,benchmark", "Scheduler::BeginFrame", "args", args.AsValue()); | 412 TRACE_EVENT1("cc,benchmark", "Scheduler::BeginFrame", "args", args.AsValue()); |
406 | 413 |
407 // Deliver BeginFrames to children. | 414 // Deliver BeginFrames to children. |
408 if (settings_.forward_begin_frames_to_children && | 415 if (state_machine_.children_need_begin_frames()) { |
409 state_machine_.children_need_begin_frames()) { | |
410 BeginFrameArgs adjusted_args_for_children(args); | 416 BeginFrameArgs adjusted_args_for_children(args); |
411 // Adjust a deadline for child schedulers. | 417 // Adjust a deadline for child schedulers. |
412 // TODO(simonhong): Once we have commitless update, we can get rid of | 418 // TODO(simonhong): Once we have commitless update, we can get rid of |
413 // BeginMainFrameToCommitDurationEstimate() + | 419 // BeginMainFrameToCommitDurationEstimate() + |
414 // CommitToActivateDurationEstimate(). | 420 // CommitToActivateDurationEstimate(). |
415 adjusted_args_for_children.deadline -= | 421 adjusted_args_for_children.deadline -= |
416 (client_->BeginMainFrameToCommitDurationEstimate() + | 422 (client_->BeginMainFrameToCommitDurationEstimate() + |
417 client_->CommitToActivateDurationEstimate() + | 423 client_->CommitToActivateDurationEstimate() + |
418 client_->DrawDurationEstimate() + EstimatedParentDrawTime()); | 424 client_->DrawDurationEstimate() + EstimatedParentDrawTime()); |
419 client_->SendBeginFramesToChildren(adjusted_args_for_children); | 425 client_->SendBeginFramesToChildren(adjusted_args_for_children); |
(...skipping 29 matching lines...) Expand all Loading... |
449 TRACE_EVENT_INSTANT0( | 455 TRACE_EVENT_INSTANT0( |
450 "cc", "Scheduler::BeginFrame deferred", TRACE_EVENT_SCOPE_THREAD); | 456 "cc", "Scheduler::BeginFrame deferred", TRACE_EVENT_SCOPE_THREAD); |
451 // Queuing the frame counts as "using it", so we need to return true. | 457 // Queuing the frame counts as "using it", so we need to return true. |
452 } else { | 458 } else { |
453 BeginImplFrame(adjusted_args); | 459 BeginImplFrame(adjusted_args); |
454 } | 460 } |
455 return true; | 461 return true; |
456 } | 462 } |
457 | 463 |
458 void Scheduler::SetChildrenNeedBeginFrames(bool children_need_begin_frames) { | 464 void Scheduler::SetChildrenNeedBeginFrames(bool children_need_begin_frames) { |
459 DCHECK(settings_.forward_begin_frames_to_children); | |
460 state_machine_.SetChildrenNeedBeginFrames(children_need_begin_frames); | 465 state_machine_.SetChildrenNeedBeginFrames(children_need_begin_frames); |
461 ProcessScheduledActions(); | 466 ProcessScheduledActions(); |
462 } | 467 } |
463 | 468 |
| 469 void Scheduler::SetAuthoritativeVSyncInterval(const base::TimeDelta& interval) { |
| 470 authoritative_vsync_interval_ = interval; |
| 471 if (vsync_observer_) |
| 472 vsync_observer_->OnUpdateVSyncParameters(last_vsync_timebase_, interval); |
| 473 } |
| 474 |
464 // BeginRetroFrame is called for BeginFrames that we've deferred because | 475 // BeginRetroFrame is called for BeginFrames that we've deferred because |
465 // the scheduler was in the middle of processing a previous BeginFrame. | 476 // the scheduler was in the middle of processing a previous BeginFrame. |
466 void Scheduler::BeginRetroFrame() { | 477 void Scheduler::BeginRetroFrame() { |
467 TRACE_EVENT0("cc,benchmark", "Scheduler::BeginRetroFrame"); | 478 TRACE_EVENT0("cc,benchmark", "Scheduler::BeginRetroFrame"); |
468 DCHECK(!settings_.using_synchronous_renderer_compositor); | 479 DCHECK(!settings_.using_synchronous_renderer_compositor); |
469 DCHECK(!begin_retro_frame_args_.empty()); | 480 DCHECK(!begin_retro_frame_args_.empty()); |
470 DCHECK(!begin_retro_frame_task_.IsCancelled()); | 481 DCHECK(!begin_retro_frame_task_.IsCancelled()); |
471 DCHECK_EQ(state_machine_.begin_impl_frame_state(), | 482 DCHECK_EQ(state_machine_.begin_impl_frame_state(), |
472 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); | 483 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); |
473 | 484 |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
821 } | 832 } |
822 | 833 |
823 bool Scheduler::IsBeginMainFrameSentOrStarted() const { | 834 bool Scheduler::IsBeginMainFrameSentOrStarted() const { |
824 return (state_machine_.commit_state() == | 835 return (state_machine_.commit_state() == |
825 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT || | 836 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT || |
826 state_machine_.commit_state() == | 837 state_machine_.commit_state() == |
827 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED); | 838 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED); |
828 } | 839 } |
829 | 840 |
830 } // namespace cc | 841 } // namespace cc |
OLD | NEW |