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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 return scheduler->unthrottled_frame_source_internal_.get(); | 73 return scheduler->unthrottled_frame_source_internal_.get(); |
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>& 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 ProxyBeginFrameSource* proxy_begin_frame_source, |
83 SchedulerFrameSourcesConstructor* frame_sources_constructor) | 84 SchedulerFrameSourcesConstructor* frame_sources_constructor) |
84 : frame_source_(), | 85 : frame_source_(), |
85 primary_frame_source_(NULL), | 86 primary_frame_source_(NULL), |
86 background_frame_source_(NULL), | 87 background_frame_source_(NULL), |
87 primary_frame_source_internal_(external_begin_frame_source.Pass()), | 88 primary_frame_source_internal_(external_begin_frame_source.Pass()), |
88 background_frame_source_internal_(), | 89 background_frame_source_internal_(), |
89 vsync_observer_(NULL), | 90 vsync_observer_(NULL), |
90 throttle_frame_production_(scheduler_settings.throttle_frame_production), | 91 throttle_frame_production_(scheduler_settings.throttle_frame_production), |
91 settings_(scheduler_settings), | 92 settings_(scheduler_settings), |
92 client_(client), | 93 client_(client), |
93 layer_tree_host_id_(layer_tree_host_id), | 94 layer_tree_host_id_(layer_tree_host_id), |
94 task_runner_(task_runner), | 95 task_runner_(task_runner), |
95 power_monitor_(power_monitor), | 96 power_monitor_(power_monitor), |
96 state_machine_(scheduler_settings), | 97 state_machine_(scheduler_settings), |
97 inside_process_scheduled_actions_(false), | 98 inside_process_scheduled_actions_(false), |
98 inside_action_(SchedulerStateMachine::ACTION_NONE), | 99 inside_action_(SchedulerStateMachine::ACTION_NONE), |
| 100 proxy_begin_frame_source_(proxy_begin_frame_source), |
99 weak_factory_(this) { | 101 weak_factory_(this) { |
100 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), | 102 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), |
101 "Scheduler::Scheduler", | 103 "Scheduler::Scheduler", |
102 "settings", | 104 "settings", |
103 settings_.AsValue()); | 105 settings_.AsValue()); |
104 DCHECK(client_); | 106 DCHECK(client_); |
105 DCHECK(!state_machine_.BeginFrameNeeded()); | 107 DCHECK(!state_machine_.BeginFrameNeeded()); |
106 | 108 |
| 109 if (settings_.forward_begin_frames_to_children) { |
| 110 DCHECK(proxy_begin_frame_source_); |
| 111 proxy_begin_frame_source_->set_delegate(this); |
| 112 } |
| 113 |
107 begin_retro_frame_closure_ = | 114 begin_retro_frame_closure_ = |
108 base::Bind(&Scheduler::BeginRetroFrame, weak_factory_.GetWeakPtr()); | 115 base::Bind(&Scheduler::BeginRetroFrame, weak_factory_.GetWeakPtr()); |
109 begin_impl_frame_deadline_closure_ = base::Bind( | 116 begin_impl_frame_deadline_closure_ = base::Bind( |
110 &Scheduler::OnBeginImplFrameDeadline, weak_factory_.GetWeakPtr()); | 117 &Scheduler::OnBeginImplFrameDeadline, weak_factory_.GetWeakPtr()); |
111 poll_for_draw_triggers_closure_ = base::Bind( | 118 poll_for_draw_triggers_closure_ = base::Bind( |
112 &Scheduler::PollForAnticipatedDrawTriggers, weak_factory_.GetWeakPtr()); | 119 &Scheduler::PollForAnticipatedDrawTriggers, weak_factory_.GetWeakPtr()); |
113 advance_commit_state_closure_ = base::Bind( | 120 advance_commit_state_closure_ = base::Bind( |
114 &Scheduler::PollToAdvanceCommitState, weak_factory_.GetWeakPtr()); | 121 &Scheduler::PollToAdvanceCommitState, weak_factory_.GetWeakPtr()); |
115 | 122 |
116 frame_source_ = BeginFrameSourceMultiplexer::Create(); | 123 frame_source_ = BeginFrameSourceMultiplexer::Create(); |
(...skipping 15 matching lines...) Expand all Loading... |
132 frame_sources_constructor->ConstructUnthrottledFrameSource(this); | 139 frame_sources_constructor->ConstructUnthrottledFrameSource(this); |
133 frame_source_->AddSource(unthrottled_frame_source_); | 140 frame_source_->AddSource(unthrottled_frame_source_); |
134 | 141 |
135 SetupPowerMonitoring(); | 142 SetupPowerMonitoring(); |
136 } | 143 } |
137 | 144 |
138 Scheduler::~Scheduler() { | 145 Scheduler::~Scheduler() { |
139 TeardownPowerMonitoring(); | 146 TeardownPowerMonitoring(); |
140 if (frame_source_->NeedsBeginFrames()) | 147 if (frame_source_->NeedsBeginFrames()) |
141 frame_source_->SetNeedsBeginFrames(false); | 148 frame_source_->SetNeedsBeginFrames(false); |
| 149 |
| 150 if (proxy_begin_frame_source_) |
| 151 proxy_begin_frame_source_->set_delegate(nullptr); |
142 } | 152 } |
143 | 153 |
144 base::TimeTicks Scheduler::Now() const { | 154 base::TimeTicks Scheduler::Now() const { |
145 base::TimeTicks now = gfx::FrameTime::Now(); | 155 base::TimeTicks now = gfx::FrameTime::Now(); |
146 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.now"), | 156 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.now"), |
147 "Scheduler::Now", | 157 "Scheduler::Now", |
148 "now", | 158 "now", |
149 now); | 159 now); |
150 return now; | 160 return now; |
151 } | 161 } |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 state_machine_.children_need_begin_frames()) { | 416 state_machine_.children_need_begin_frames()) { |
407 BeginFrameArgs adjusted_args_for_children(args); | 417 BeginFrameArgs adjusted_args_for_children(args); |
408 // Adjust a deadline for child schedulers. | 418 // Adjust a deadline for child schedulers. |
409 // TODO(simonhong): Once we have commitless update, we can get rid of | 419 // TODO(simonhong): Once we have commitless update, we can get rid of |
410 // BeginMainFrameToCommitDurationEstimate() + | 420 // BeginMainFrameToCommitDurationEstimate() + |
411 // CommitToActivateDurationEstimate(). | 421 // CommitToActivateDurationEstimate(). |
412 adjusted_args_for_children.deadline -= | 422 adjusted_args_for_children.deadline -= |
413 (client_->BeginMainFrameToCommitDurationEstimate() + | 423 (client_->BeginMainFrameToCommitDurationEstimate() + |
414 client_->CommitToActivateDurationEstimate() + | 424 client_->CommitToActivateDurationEstimate() + |
415 client_->DrawDurationEstimate() + EstimatedParentDrawTime()); | 425 client_->DrawDurationEstimate() + EstimatedParentDrawTime()); |
416 client_->SendBeginFramesToChildren(adjusted_args_for_children); | 426 proxy_begin_frame_source_->BeginFrames(adjusted_args_for_children); |
417 } | 427 } |
418 | 428 |
419 // We have just called SetNeedsBeginFrame(true) and the BeginFrameSource has | 429 // We have just called SetNeedsBeginFrame(true) and the BeginFrameSource has |
420 // sent us the last BeginFrame we have missed. As we might not be able to | 430 // sent us the last BeginFrame we have missed. As we might not be able to |
421 // actually make rendering for this call, handle it like a "retro frame". | 431 // actually make rendering for this call, handle it like a "retro frame". |
422 // TODO(brainderson): Add a test for this functionality ASAP! | 432 // TODO(brainderson): Add a test for this functionality ASAP! |
423 if (args.type == BeginFrameArgs::MISSED) { | 433 if (args.type == BeginFrameArgs::MISSED) { |
424 begin_retro_frame_args_.push_back(args); | 434 begin_retro_frame_args_.push_back(args); |
425 PostBeginRetroFrameIfNeeded(); | 435 PostBeginRetroFrameIfNeeded(); |
426 return true; | 436 return true; |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
810 } | 820 } |
811 | 821 |
812 bool Scheduler::IsBeginMainFrameSentOrStarted() const { | 822 bool Scheduler::IsBeginMainFrameSentOrStarted() const { |
813 return (state_machine_.commit_state() == | 823 return (state_machine_.commit_state() == |
814 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT || | 824 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT || |
815 state_machine_.commit_state() == | 825 state_machine_.commit_state() == |
816 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED); | 826 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED); |
817 } | 827 } |
818 | 828 |
819 } // namespace cc | 829 } // namespace cc |
OLD | NEW |