| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 DCHECK(!scheduler->vsync_observer_); | 42 DCHECK(!scheduler->vsync_observer_); |
| 43 scheduler->vsync_observer_ = synthetic_source.get(); | 43 scheduler->vsync_observer_ = synthetic_source.get(); |
| 44 | 44 |
| 45 DCHECK(!scheduler->primary_frame_source_internal_); | 45 DCHECK(!scheduler->primary_frame_source_internal_); |
| 46 scheduler->primary_frame_source_internal_ = synthetic_source.Pass(); | 46 scheduler->primary_frame_source_internal_ = synthetic_source.Pass(); |
| 47 return scheduler->primary_frame_source_internal_.get(); | 47 return scheduler->primary_frame_source_internal_.get(); |
| 48 } | 48 } |
| 49 } | 49 } |
| 50 | 50 |
| 51 BeginFrameSource* | 51 BeginFrameSource* |
| 52 SchedulerFrameSourcesConstructor::ConstructBackgroundFrameSource( | |
| 53 Scheduler* scheduler) { | |
| 54 TRACE_EVENT1("cc", | |
| 55 "Scheduler::Scheduler()", | |
| 56 "BackgroundFrameSource", | |
| 57 "SyntheticBeginFrameSource"); | |
| 58 DCHECK(!(scheduler->background_frame_source_internal_)); | |
| 59 scheduler->background_frame_source_internal_ = | |
| 60 SyntheticBeginFrameSource::Create( | |
| 61 scheduler->task_runner_.get(), scheduler->Now(), | |
| 62 scheduler->settings_.background_frame_interval); | |
| 63 return scheduler->background_frame_source_internal_.get(); | |
| 64 } | |
| 65 | |
| 66 BeginFrameSource* | |
| 67 SchedulerFrameSourcesConstructor::ConstructUnthrottledFrameSource( | 52 SchedulerFrameSourcesConstructor::ConstructUnthrottledFrameSource( |
| 68 Scheduler* scheduler) { | 53 Scheduler* scheduler) { |
| 69 TRACE_EVENT1("cc", "Scheduler::Scheduler()", "UnthrottledFrameSource", | 54 TRACE_EVENT1("cc", "Scheduler::Scheduler()", "UnthrottledFrameSource", |
| 70 "BackToBackBeginFrameSource"); | 55 "BackToBackBeginFrameSource"); |
| 71 DCHECK(!scheduler->unthrottled_frame_source_internal_); | 56 DCHECK(!scheduler->unthrottled_frame_source_internal_); |
| 72 scheduler->unthrottled_frame_source_internal_ = | 57 scheduler->unthrottled_frame_source_internal_ = |
| 73 BackToBackBeginFrameSource::Create(scheduler->task_runner_.get()); | 58 BackToBackBeginFrameSource::Create(scheduler->task_runner_.get()); |
| 74 return scheduler->unthrottled_frame_source_internal_.get(); | 59 return scheduler->unthrottled_frame_source_internal_.get(); |
| 75 } | 60 } |
| 76 | 61 |
| 77 Scheduler::Scheduler( | 62 Scheduler::Scheduler( |
| 78 SchedulerClient* client, | 63 SchedulerClient* client, |
| 79 const SchedulerSettings& scheduler_settings, | 64 const SchedulerSettings& scheduler_settings, |
| 80 int layer_tree_host_id, | 65 int layer_tree_host_id, |
| 81 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 66 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 82 scoped_ptr<BeginFrameSource> external_begin_frame_source, | 67 scoped_ptr<BeginFrameSource> external_begin_frame_source, |
| 83 SchedulerFrameSourcesConstructor* frame_sources_constructor) | 68 SchedulerFrameSourcesConstructor* frame_sources_constructor) |
| 84 : frame_source_(), | 69 : frame_source_(), |
| 85 primary_frame_source_(NULL), | 70 primary_frame_source_(NULL), |
| 86 background_frame_source_(NULL), | |
| 87 primary_frame_source_internal_(external_begin_frame_source.Pass()), | 71 primary_frame_source_internal_(external_begin_frame_source.Pass()), |
| 88 background_frame_source_internal_(), | |
| 89 vsync_observer_(NULL), | 72 vsync_observer_(NULL), |
| 90 authoritative_vsync_interval_(base::TimeDelta()), | 73 authoritative_vsync_interval_(base::TimeDelta()), |
| 91 last_vsync_timebase_(base::TimeTicks()), | 74 last_vsync_timebase_(base::TimeTicks()), |
| 92 throttle_frame_production_(scheduler_settings.throttle_frame_production), | 75 throttle_frame_production_(false), |
| 93 settings_(scheduler_settings), | 76 settings_(scheduler_settings), |
| 94 client_(client), | 77 client_(client), |
| 95 layer_tree_host_id_(layer_tree_host_id), | 78 layer_tree_host_id_(layer_tree_host_id), |
| 96 task_runner_(task_runner), | 79 task_runner_(task_runner), |
| 97 begin_impl_frame_deadline_mode_( | 80 begin_impl_frame_deadline_mode_( |
| 98 SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_NONE), | 81 SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_NONE), |
| 99 state_machine_(scheduler_settings), | 82 state_machine_(scheduler_settings), |
| 100 inside_process_scheduled_actions_(false), | 83 inside_process_scheduled_actions_(false), |
| 101 inside_action_(SchedulerStateMachine::ACTION_NONE), | 84 inside_action_(SchedulerStateMachine::ACTION_NONE), |
| 102 weak_factory_(this) { | 85 weak_factory_(this) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 116 | 99 |
| 117 frame_source_ = BeginFrameSourceMultiplexer::Create(); | 100 frame_source_ = BeginFrameSourceMultiplexer::Create(); |
| 118 frame_source_->AddObserver(this); | 101 frame_source_->AddObserver(this); |
| 119 | 102 |
| 120 // Primary frame source | 103 // Primary frame source |
| 121 primary_frame_source_ = | 104 primary_frame_source_ = |
| 122 frame_sources_constructor->ConstructPrimaryFrameSource(this); | 105 frame_sources_constructor->ConstructPrimaryFrameSource(this); |
| 123 frame_source_->AddSource(primary_frame_source_); | 106 frame_source_->AddSource(primary_frame_source_); |
| 124 primary_frame_source_->SetClientReady(); | 107 primary_frame_source_->SetClientReady(); |
| 125 | 108 |
| 126 // Background ticking frame source | |
| 127 background_frame_source_ = | |
| 128 frame_sources_constructor->ConstructBackgroundFrameSource(this); | |
| 129 frame_source_->AddSource(background_frame_source_); | |
| 130 | |
| 131 // Unthrottled frame source | 109 // Unthrottled frame source |
| 132 unthrottled_frame_source_ = | 110 unthrottled_frame_source_ = |
| 133 frame_sources_constructor->ConstructUnthrottledFrameSource(this); | 111 frame_sources_constructor->ConstructUnthrottledFrameSource(this); |
| 134 frame_source_->AddSource(unthrottled_frame_source_); | 112 frame_source_->AddSource(unthrottled_frame_source_); |
| 113 |
| 114 SetThrottleFrameProduction(scheduler_settings.throttle_frame_production); |
| 135 } | 115 } |
| 136 | 116 |
| 137 Scheduler::~Scheduler() { | 117 Scheduler::~Scheduler() { |
| 138 if (frame_source_->NeedsBeginFrames()) | 118 if (frame_source_->NeedsBeginFrames()) |
| 139 frame_source_->SetNeedsBeginFrames(false); | 119 frame_source_->SetNeedsBeginFrames(false); |
| 140 } | 120 } |
| 141 | 121 |
| 142 base::TimeTicks Scheduler::Now() const { | 122 base::TimeTicks Scheduler::Now() const { |
| 143 base::TimeTicks now = gfx::FrameTime::Now(); | 123 base::TimeTicks now = gfx::FrameTime::Now(); |
| 144 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.now"), | 124 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.now"), |
| (...skipping 21 matching lines...) Expand all Loading... |
| 166 void Scheduler::SetEstimatedParentDrawTime(base::TimeDelta draw_time) { | 146 void Scheduler::SetEstimatedParentDrawTime(base::TimeDelta draw_time) { |
| 167 DCHECK_GE(draw_time.ToInternalValue(), 0); | 147 DCHECK_GE(draw_time.ToInternalValue(), 0); |
| 168 estimated_parent_draw_time_ = draw_time; | 148 estimated_parent_draw_time_ = draw_time; |
| 169 } | 149 } |
| 170 | 150 |
| 171 void Scheduler::SetCanStart() { | 151 void Scheduler::SetCanStart() { |
| 172 state_machine_.SetCanStart(); | 152 state_machine_.SetCanStart(); |
| 173 ProcessScheduledActions(); | 153 ProcessScheduledActions(); |
| 174 } | 154 } |
| 175 | 155 |
| 176 void Scheduler::UpdateActiveFrameSource() { | |
| 177 if (state_machine_.visible()) { | |
| 178 if (throttle_frame_production_) { | |
| 179 frame_source_->SetActiveSource(primary_frame_source_); | |
| 180 } else { | |
| 181 frame_source_->SetActiveSource(unthrottled_frame_source_); | |
| 182 } | |
| 183 } else { | |
| 184 frame_source_->SetActiveSource(background_frame_source_); | |
| 185 } | |
| 186 ProcessScheduledActions(); | |
| 187 } | |
| 188 | |
| 189 void Scheduler::SetVisible(bool visible) { | 156 void Scheduler::SetVisible(bool visible) { |
| 190 state_machine_.SetVisible(visible); | 157 state_machine_.SetVisible(visible); |
| 191 UpdateActiveFrameSource(); | 158 ProcessScheduledActions(); |
| 192 } | 159 } |
| 193 | 160 |
| 194 void Scheduler::SetCanDraw(bool can_draw) { | 161 void Scheduler::SetCanDraw(bool can_draw) { |
| 195 state_machine_.SetCanDraw(can_draw); | 162 state_machine_.SetCanDraw(can_draw); |
| 196 ProcessScheduledActions(); | 163 ProcessScheduledActions(); |
| 197 } | 164 } |
| 198 | 165 |
| 199 void Scheduler::NotifyReadyToActivate() { | 166 void Scheduler::NotifyReadyToActivate() { |
| 200 state_machine_.NotifyReadyToActivate(); | 167 state_machine_.NotifyReadyToActivate(); |
| 201 ProcessScheduledActions(); | 168 ProcessScheduledActions(); |
| 202 } | 169 } |
| 203 | 170 |
| 204 void Scheduler::NotifyReadyToDraw() { | 171 void Scheduler::NotifyReadyToDraw() { |
| 205 // Empty for now, until we take action based on the notification as part of | 172 // Empty for now, until we take action based on the notification as part of |
| 206 // crbugs 352894, 383157, 421923. | 173 // crbugs 352894, 383157, 421923. |
| 207 } | 174 } |
| 208 | 175 |
| 209 void Scheduler::SetThrottleFrameProduction(bool throttle) { | 176 void Scheduler::SetThrottleFrameProduction(bool throttle) { |
| 210 throttle_frame_production_ = throttle; | 177 throttle_frame_production_ = throttle; |
| 211 UpdateActiveFrameSource(); | 178 if (throttle) { |
| 179 frame_source_->SetActiveSource(primary_frame_source_); |
| 180 } else { |
| 181 frame_source_->SetActiveSource(unthrottled_frame_source_); |
| 182 } |
| 183 ProcessScheduledActions(); |
| 212 } | 184 } |
| 213 | 185 |
| 214 void Scheduler::SetNeedsCommit() { | 186 void Scheduler::SetNeedsCommit() { |
| 215 state_machine_.SetNeedsCommit(); | 187 state_machine_.SetNeedsCommit(); |
| 216 ProcessScheduledActions(); | 188 ProcessScheduledActions(); |
| 217 } | 189 } |
| 218 | 190 |
| 219 void Scheduler::SetNeedsRedraw() { | 191 void Scheduler::SetNeedsRedraw() { |
| 220 state_machine_.SetNeedsRedraw(); | 192 state_machine_.SetNeedsRedraw(); |
| 221 ProcessScheduledActions(); | 193 ProcessScheduledActions(); |
| (...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 839 } | 811 } |
| 840 | 812 |
| 841 bool Scheduler::IsBeginMainFrameSentOrStarted() const { | 813 bool Scheduler::IsBeginMainFrameSentOrStarted() const { |
| 842 return (state_machine_.commit_state() == | 814 return (state_machine_.commit_state() == |
| 843 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT || | 815 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT || |
| 844 state_machine_.commit_state() == | 816 state_machine_.commit_state() == |
| 845 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED); | 817 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED); |
| 846 } | 818 } |
| 847 | 819 |
| 848 } // namespace cc | 820 } // namespace cc |
| OLD | NEW |