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" |
11 #include "base/profiler/scoped_tracker.h" | 11 #include "base/profiler/scoped_tracker.h" |
12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
13 #include "base/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" |
14 #include "base/trace_event/trace_event_argument.h" | 14 #include "base/trace_event/trace_event_argument.h" |
15 #include "cc/debug/devtools_instrumentation.h" | 15 #include "cc/debug/devtools_instrumentation.h" |
16 #include "cc/debug/traced_value.h" | 16 #include "cc/debug/traced_value.h" |
17 #include "cc/scheduler/delay_based_time_source.h" | 17 #include "cc/scheduler/delay_based_time_source.h" |
18 | 18 |
19 namespace cc { | 19 namespace cc { |
20 | 20 |
21 BeginFrameSource* SchedulerFrameSourcesConstructor::ConstructPrimaryFrameSource( | 21 scoped_ptr<Scheduler> Scheduler::Create( |
22 Scheduler* scheduler) { | 22 SchedulerClient* client, |
23 if (scheduler->settings_.use_external_begin_frame_source) { | 23 const SchedulerSettings& settings, |
24 TRACE_EVENT1("cc", | 24 int layer_tree_host_id, |
25 "Scheduler::Scheduler()", | 25 base::SingleThreadTaskRunner* task_runner, |
26 "PrimaryFrameSource", | 26 BeginFrameSource* external_frame_source) { |
27 "ExternalBeginFrameSource"); | 27 scoped_ptr<SyntheticBeginFrameSource> synthetic_frame_source; |
28 DCHECK(scheduler->primary_frame_source_internal_) | 28 if (!settings.use_external_begin_frame_source) { |
mithro-old
2015/06/22 11:49:39
Can you please keep some type of tracing which sig
sunnyps
2015/06/22 20:32:41
I'm enabling the scheduler constructor trace which
| |
29 << "Need external BeginFrameSource"; | 29 synthetic_frame_source = SyntheticBeginFrameSource::Create( |
30 return scheduler->primary_frame_source_internal_.get(); | 30 task_runner, BeginFrameArgs::DefaultInterval()); |
31 } else { | |
32 TRACE_EVENT1("cc", | |
33 "Scheduler::Scheduler()", | |
34 "PrimaryFrameSource", | |
35 "SyntheticBeginFrameSource"); | |
36 scoped_ptr<SyntheticBeginFrameSource> synthetic_source = | |
37 SyntheticBeginFrameSource::Create(scheduler->task_runner_.get(), | |
38 scheduler->Now(), | |
39 BeginFrameArgs::DefaultInterval()); | |
40 | |
41 DCHECK(!scheduler->vsync_observer_); | |
42 scheduler->vsync_observer_ = synthetic_source.get(); | |
43 | |
44 DCHECK(!scheduler->primary_frame_source_internal_); | |
45 scheduler->primary_frame_source_internal_ = synthetic_source.Pass(); | |
46 return scheduler->primary_frame_source_internal_.get(); | |
47 } | 31 } |
48 } | 32 scoped_ptr<BackToBackBeginFrameSource> unthrottled_frame_source = |
49 | 33 BackToBackBeginFrameSource::Create(task_runner); |
50 BeginFrameSource* | 34 return make_scoped_ptr(new Scheduler( |
51 SchedulerFrameSourcesConstructor::ConstructUnthrottledFrameSource( | 35 client, settings, layer_tree_host_id, task_runner, external_frame_source, |
52 Scheduler* scheduler) { | 36 synthetic_frame_source.Pass(), unthrottled_frame_source.Pass())); |
mithro-old
2015/06/22 11:49:39
It's kind of weird that you can end up "passing a
sunnyps
2015/06/22 20:32:41
We're passing in a scoped_ptr that wraps a nullptr
| |
53 TRACE_EVENT1("cc", "Scheduler::Scheduler()", "UnthrottledFrameSource", | |
54 "BackToBackBeginFrameSource"); | |
55 DCHECK(!scheduler->unthrottled_frame_source_internal_); | |
56 scheduler->unthrottled_frame_source_internal_ = | |
57 BackToBackBeginFrameSource::Create(scheduler->task_runner_.get()); | |
58 return scheduler->unthrottled_frame_source_internal_.get(); | |
59 } | 37 } |
60 | 38 |
61 Scheduler::Scheduler( | 39 Scheduler::Scheduler( |
62 SchedulerClient* client, | 40 SchedulerClient* client, |
63 const SchedulerSettings& scheduler_settings, | 41 const SchedulerSettings& settings, |
64 int layer_tree_host_id, | 42 int layer_tree_host_id, |
65 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 43 base::SingleThreadTaskRunner* task_runner, |
66 scoped_ptr<BeginFrameSource> external_begin_frame_source, | 44 BeginFrameSource* external_frame_source, |
67 SchedulerFrameSourcesConstructor* frame_sources_constructor) | 45 scoped_ptr<SyntheticBeginFrameSource> synthetic_frame_source, |
68 : frame_source_(), | 46 scoped_ptr<BackToBackBeginFrameSource> unthrottled_frame_source) |
69 primary_frame_source_(NULL), | 47 : settings_(settings), |
70 primary_frame_source_internal_(external_begin_frame_source.Pass()), | |
71 vsync_observer_(NULL), | |
72 authoritative_vsync_interval_(base::TimeDelta()), | |
73 last_vsync_timebase_(base::TimeTicks()), | |
74 throttle_frame_production_(false), | |
75 settings_(scheduler_settings), | |
76 client_(client), | 48 client_(client), |
77 layer_tree_host_id_(layer_tree_host_id), | 49 layer_tree_host_id_(layer_tree_host_id), |
78 task_runner_(task_runner), | 50 task_runner_(task_runner), |
51 external_frame_source_(external_frame_source), | |
52 synthetic_frame_source_(synthetic_frame_source.Pass()), | |
53 unthrottled_frame_source_(unthrottled_frame_source.Pass()), | |
54 frame_source_(BeginFrameSourceMultiplexer::Create()), | |
55 throttle_frame_production_(false), | |
79 begin_impl_frame_deadline_mode_( | 56 begin_impl_frame_deadline_mode_( |
80 SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_NONE), | 57 SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_NONE), |
81 begin_impl_frame_tracker_(BEGINFRAMETRACKER_FROM_HERE), | 58 begin_impl_frame_tracker_(BEGINFRAMETRACKER_FROM_HERE), |
82 state_machine_(scheduler_settings), | 59 state_machine_(settings), |
83 inside_process_scheduled_actions_(false), | 60 inside_process_scheduled_actions_(false), |
84 inside_action_(SchedulerStateMachine::ACTION_NONE), | 61 inside_action_(SchedulerStateMachine::ACTION_NONE), |
85 weak_factory_(this) { | 62 weak_factory_(this) { |
86 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), | 63 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), |
87 "Scheduler::Scheduler", | 64 "Scheduler::Scheduler", |
88 "settings", | 65 "settings", |
89 settings_.AsValue()); | 66 settings_.AsValue()); |
90 DCHECK(client_); | 67 DCHECK(client_); |
91 DCHECK(!state_machine_.BeginFrameNeeded()); | 68 DCHECK(!state_machine_.BeginFrameNeeded()); |
69 DCHECK_IMPLIES(settings_.use_external_begin_frame_source, | |
70 external_frame_source_); | |
71 DCHECK_IMPLIES(!settings_.use_external_begin_frame_source, | |
72 synthetic_frame_source_.get()); | |
73 DCHECK(unthrottled_frame_source_.get()); | |
92 | 74 |
93 begin_retro_frame_closure_ = | 75 begin_retro_frame_closure_ = |
94 base::Bind(&Scheduler::BeginRetroFrame, weak_factory_.GetWeakPtr()); | 76 base::Bind(&Scheduler::BeginRetroFrame, weak_factory_.GetWeakPtr()); |
95 begin_impl_frame_deadline_closure_ = base::Bind( | 77 begin_impl_frame_deadline_closure_ = base::Bind( |
96 &Scheduler::OnBeginImplFrameDeadline, weak_factory_.GetWeakPtr()); | 78 &Scheduler::OnBeginImplFrameDeadline, weak_factory_.GetWeakPtr()); |
97 advance_commit_state_closure_ = base::Bind( | 79 advance_commit_state_closure_ = base::Bind( |
98 &Scheduler::PollToAdvanceCommitState, weak_factory_.GetWeakPtr()); | 80 &Scheduler::PollToAdvanceCommitState, weak_factory_.GetWeakPtr()); |
99 | 81 |
100 frame_source_ = BeginFrameSourceMultiplexer::Create(); | |
101 frame_source_->AddObserver(this); | 82 frame_source_->AddObserver(this); |
83 frame_source_->AddSource(primary_frame_source()); | |
84 primary_frame_source()->SetClientReady(); | |
102 | 85 |
103 // Primary frame source | 86 frame_source_->AddSource(unthrottled_frame_source_.get()); |
104 primary_frame_source_ = | 87 unthrottled_frame_source_->SetClientReady(); |
105 frame_sources_constructor->ConstructPrimaryFrameSource(this); | |
106 frame_source_->AddSource(primary_frame_source_); | |
107 primary_frame_source_->SetClientReady(); | |
108 | 88 |
109 // Unthrottled frame source | 89 SetThrottleFrameProduction(settings_.throttle_frame_production); |
110 unthrottled_frame_source_ = | |
111 frame_sources_constructor->ConstructUnthrottledFrameSource(this); | |
112 frame_source_->AddSource(unthrottled_frame_source_); | |
113 | |
114 SetThrottleFrameProduction(scheduler_settings.throttle_frame_production); | |
115 } | 90 } |
116 | 91 |
117 Scheduler::~Scheduler() { | 92 Scheduler::~Scheduler() { |
118 if (frame_source_->NeedsBeginFrames()) | 93 if (frame_source_->NeedsBeginFrames()) |
119 frame_source_->SetNeedsBeginFrames(false); | 94 frame_source_->SetNeedsBeginFrames(false); |
120 frame_source_->SetActiveSource(nullptr); | 95 frame_source_->SetActiveSource(nullptr); |
121 } | 96 } |
122 | 97 |
123 base::TimeTicks Scheduler::Now() const { | 98 base::TimeTicks Scheduler::Now() const { |
124 base::TimeTicks now = base::TimeTicks::Now(); | 99 base::TimeTicks now = base::TimeTicks::Now(); |
125 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.now"), | 100 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.now"), |
126 "Scheduler::Now", | 101 "Scheduler::Now", |
127 "now", | 102 "now", |
128 now); | 103 now); |
129 return now; | 104 return now; |
130 } | 105 } |
131 | 106 |
132 void Scheduler::CommitVSyncParameters(base::TimeTicks timebase, | 107 void Scheduler::CommitVSyncParameters(base::TimeTicks timebase, |
133 base::TimeDelta interval) { | 108 base::TimeDelta interval) { |
134 if (authoritative_vsync_interval_ != base::TimeDelta()) { | 109 if (authoritative_vsync_interval_ != base::TimeDelta()) { |
135 interval = authoritative_vsync_interval_; | 110 interval = authoritative_vsync_interval_; |
136 } else if (interval == base::TimeDelta()) { | 111 } else if (interval == base::TimeDelta()) { |
137 // TODO(brianderson): We should not be receiving 0 intervals. | 112 // TODO(brianderson): We should not be receiving 0 intervals. |
138 interval = BeginFrameArgs::DefaultInterval(); | 113 interval = BeginFrameArgs::DefaultInterval(); |
139 } | 114 } |
140 | 115 |
141 last_vsync_timebase_ = timebase; | 116 last_vsync_timebase_ = timebase; |
142 | 117 |
143 if (vsync_observer_) | 118 if (synthetic_frame_source_.get()) |
144 vsync_observer_->OnUpdateVSyncParameters(timebase, interval); | 119 synthetic_frame_source_->OnUpdateVSyncParameters(timebase, interval); |
145 } | 120 } |
146 | 121 |
147 void Scheduler::SetEstimatedParentDrawTime(base::TimeDelta draw_time) { | 122 void Scheduler::SetEstimatedParentDrawTime(base::TimeDelta draw_time) { |
148 DCHECK_GE(draw_time.ToInternalValue(), 0); | 123 DCHECK_GE(draw_time.ToInternalValue(), 0); |
149 estimated_parent_draw_time_ = draw_time; | 124 estimated_parent_draw_time_ = draw_time; |
150 } | 125 } |
151 | 126 |
152 void Scheduler::SetCanStart() { | 127 void Scheduler::SetCanStart() { |
153 state_machine_.SetCanStart(); | 128 state_machine_.SetCanStart(); |
154 ProcessScheduledActions(); | 129 ProcessScheduledActions(); |
(...skipping 16 matching lines...) Expand all Loading... | |
171 | 146 |
172 void Scheduler::NotifyReadyToDraw() { | 147 void Scheduler::NotifyReadyToDraw() { |
173 // Future work might still needed for crbug.com/352894. | 148 // Future work might still needed for crbug.com/352894. |
174 state_machine_.NotifyReadyToDraw(); | 149 state_machine_.NotifyReadyToDraw(); |
175 ProcessScheduledActions(); | 150 ProcessScheduledActions(); |
176 } | 151 } |
177 | 152 |
178 void Scheduler::SetThrottleFrameProduction(bool throttle) { | 153 void Scheduler::SetThrottleFrameProduction(bool throttle) { |
179 throttle_frame_production_ = throttle; | 154 throttle_frame_production_ = throttle; |
180 if (throttle) { | 155 if (throttle) { |
181 frame_source_->SetActiveSource(primary_frame_source_); | 156 frame_source_->SetActiveSource(primary_frame_source()); |
182 } else { | 157 } else { |
183 frame_source_->SetActiveSource(unthrottled_frame_source_); | 158 frame_source_->SetActiveSource(unthrottled_frame_source_.get()); |
184 } | 159 } |
185 ProcessScheduledActions(); | 160 ProcessScheduledActions(); |
186 } | 161 } |
187 | 162 |
188 void Scheduler::SetNeedsCommit() { | 163 void Scheduler::SetNeedsCommit() { |
189 state_machine_.SetNeedsCommit(); | 164 state_machine_.SetNeedsCommit(); |
190 ProcessScheduledActions(); | 165 ProcessScheduledActions(); |
191 } | 166 } |
192 | 167 |
193 void Scheduler::SetNeedsRedraw() { | 168 void Scheduler::SetNeedsRedraw() { |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
394 return true; | 369 return true; |
395 } | 370 } |
396 | 371 |
397 void Scheduler::SetChildrenNeedBeginFrames(bool children_need_begin_frames) { | 372 void Scheduler::SetChildrenNeedBeginFrames(bool children_need_begin_frames) { |
398 state_machine_.SetChildrenNeedBeginFrames(children_need_begin_frames); | 373 state_machine_.SetChildrenNeedBeginFrames(children_need_begin_frames); |
399 ProcessScheduledActions(); | 374 ProcessScheduledActions(); |
400 } | 375 } |
401 | 376 |
402 void Scheduler::SetAuthoritativeVSyncInterval(const base::TimeDelta& interval) { | 377 void Scheduler::SetAuthoritativeVSyncInterval(const base::TimeDelta& interval) { |
403 authoritative_vsync_interval_ = interval; | 378 authoritative_vsync_interval_ = interval; |
404 if (vsync_observer_) | 379 if (synthetic_frame_source_.get()) { |
405 vsync_observer_->OnUpdateVSyncParameters(last_vsync_timebase_, interval); | 380 synthetic_frame_source_->OnUpdateVSyncParameters(last_vsync_timebase_, |
381 interval); | |
382 } | |
406 } | 383 } |
407 | 384 |
408 void Scheduler::SetVideoNeedsBeginFrames(bool video_needs_begin_frames) { | 385 void Scheduler::SetVideoNeedsBeginFrames(bool video_needs_begin_frames) { |
409 state_machine_.SetVideoNeedsBeginFrames(video_needs_begin_frames); | 386 state_machine_.SetVideoNeedsBeginFrames(video_needs_begin_frames); |
410 ProcessScheduledActions(); | 387 ProcessScheduledActions(); |
411 } | 388 } |
412 | 389 |
413 void Scheduler::OnDrawForOutputSurface() { | 390 void Scheduler::OnDrawForOutputSurface() { |
414 DCHECK(settings_.using_synchronous_renderer_compositor); | 391 DCHECK(settings_.using_synchronous_renderer_compositor); |
415 DCHECK_EQ(state_machine_.begin_impl_frame_state(), | 392 DCHECK_EQ(state_machine_.begin_impl_frame_state(), |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
821 } | 798 } |
822 | 799 |
823 bool Scheduler::IsBeginMainFrameSentOrStarted() const { | 800 bool Scheduler::IsBeginMainFrameSentOrStarted() const { |
824 return (state_machine_.commit_state() == | 801 return (state_machine_.commit_state() == |
825 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT || | 802 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT || |
826 state_machine_.commit_state() == | 803 state_machine_.commit_state() == |
827 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED); | 804 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED); |
828 } | 805 } |
829 | 806 |
830 } // namespace cc | 807 } // namespace cc |
OLD | NEW |