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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 } | 110 } |
111 | 111 |
112 void Scheduler::DidCreateAndInitializeOutputSurface() { | 112 void Scheduler::DidCreateAndInitializeOutputSurface() { |
113 TRACE_EVENT0("cc", "Scheduler::DidCreateAndInitializeOutputSurface"); | 113 TRACE_EVENT0("cc", "Scheduler::DidCreateAndInitializeOutputSurface"); |
114 DCHECK(!last_set_needs_begin_impl_frame_); | 114 DCHECK(!last_set_needs_begin_impl_frame_); |
115 DCHECK(begin_impl_frame_deadline_closure_.IsCancelled()); | 115 DCHECK(begin_impl_frame_deadline_closure_.IsCancelled()); |
116 state_machine_.DidCreateAndInitializeOutputSurface(); | 116 state_machine_.DidCreateAndInitializeOutputSurface(); |
117 ProcessScheduledActions(); | 117 ProcessScheduledActions(); |
118 } | 118 } |
119 | 119 |
120 base::TimeTicks Scheduler::AnticipatedDrawTime() { | 120 gfx::FrameTime Scheduler::AnticipatedDrawTime() { |
121 TRACE_EVENT0("cc", "Scheduler::AnticipatedDrawTime"); | 121 TRACE_EVENT0("cc", "Scheduler::AnticipatedDrawTime"); |
122 | 122 |
123 if (!last_set_needs_begin_impl_frame_ || | 123 if (!last_set_needs_begin_impl_frame_ || |
124 last_begin_impl_frame_args_.interval <= base::TimeDelta()) | 124 last_begin_impl_frame_args_.interval <= base::TimeDelta()) |
125 return base::TimeTicks(); | 125 return gfx::FrameTime(); |
126 | 126 |
127 base::TimeTicks now = gfx::FrameTime::Now(); | 127 gfx::FrameTime now = gfx::FrameTime::Now(); |
128 base::TimeTicks timebase = std::max(last_begin_impl_frame_args_.frame_time, | 128 gfx::FrameTime timebase = |
129 last_begin_impl_frame_args_.deadline); | 129 std::max<gfx::FrameTime>( |
| 130 last_begin_impl_frame_args_.frame_time, |
| 131 last_begin_impl_frame_args_.deadline); |
130 int64 intervals = | 132 int64 intervals = |
131 1 + ((now - timebase) / last_begin_impl_frame_args_.interval); | 133 1 + ((now - timebase) / last_begin_impl_frame_args_.interval); |
132 return timebase + (last_begin_impl_frame_args_.interval * intervals); | 134 return timebase + (last_begin_impl_frame_args_.interval * intervals); |
133 } | 135 } |
134 | 136 |
135 base::TimeTicks Scheduler::LastBeginImplFrameTime() { | 137 gfx::FrameTime Scheduler::LastBeginImplFrameTime() { |
136 return last_begin_impl_frame_args_.frame_time; | 138 return last_begin_impl_frame_args_.frame_time; |
137 } | 139 } |
138 | 140 |
139 void Scheduler::SetupNextBeginImplFrameIfNeeded() { | 141 void Scheduler::SetupNextBeginImplFrameIfNeeded() { |
140 bool needs_begin_impl_frame = | 142 bool needs_begin_impl_frame = |
141 state_machine_.BeginImplFrameNeeded(); | 143 state_machine_.BeginImplFrameNeeded(); |
142 | 144 |
143 bool at_end_of_deadline = | 145 bool at_end_of_deadline = |
144 state_machine_.begin_impl_frame_state() == | 146 state_machine_.begin_impl_frame_state() == |
145 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE; | 147 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE; |
(...skipping 29 matching lines...) Expand all Loading... |
175 poll_for_draw_triggers_closure_.Cancel(); | 177 poll_for_draw_triggers_closure_.Cancel(); |
176 } | 178 } |
177 } | 179 } |
178 | 180 |
179 void Scheduler::BeginImplFrame(const BeginFrameArgs& args) { | 181 void Scheduler::BeginImplFrame(const BeginFrameArgs& args) { |
180 TRACE_EVENT0("cc", "Scheduler::BeginImplFrame"); | 182 TRACE_EVENT0("cc", "Scheduler::BeginImplFrame"); |
181 DCHECK(state_machine_.begin_impl_frame_state() == | 183 DCHECK(state_machine_.begin_impl_frame_state() == |
182 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); | 184 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); |
183 DCHECK(state_machine_.HasInitializedOutputSurface()); | 185 DCHECK(state_machine_.HasInitializedOutputSurface()); |
184 last_begin_impl_frame_args_ = args; | 186 last_begin_impl_frame_args_ = args; |
185 last_begin_impl_frame_args_.deadline -= client_->DrawDurationEstimate(); | 187 last_begin_impl_frame_args_.deadline = |
| 188 last_begin_impl_frame_args_.deadline - client_->DrawDurationEstimate(); |
186 state_machine_.OnBeginImplFrame(last_begin_impl_frame_args_); | 189 state_machine_.OnBeginImplFrame(last_begin_impl_frame_args_); |
187 ProcessScheduledActions(); | 190 ProcessScheduledActions(); |
188 | 191 |
189 if (!state_machine_.HasInitializedOutputSurface()) | 192 if (!state_machine_.HasInitializedOutputSurface()) |
190 return; | 193 return; |
191 | 194 |
192 state_machine_.OnBeginImplFrameDeadlinePending(); | 195 state_machine_.OnBeginImplFrameDeadlinePending(); |
193 | 196 |
194 if (settings_.using_synchronous_renderer_compositor) { | 197 if (settings_.using_synchronous_renderer_compositor) { |
195 // The synchronous renderer compositor has to make its GL calls | 198 // The synchronous renderer compositor has to make its GL calls |
196 // within this call to BeginImplFrame. | 199 // within this call to BeginImplFrame. |
197 // TODO(brianderson): Have the OutputSurface initiate the deadline tasks | 200 // TODO(brianderson): Have the OutputSurface initiate the deadline tasks |
198 // so the sychronous renderer compositor can take advantage of splitting | 201 // so the sychronous renderer compositor can take advantage of splitting |
199 // up the BeginImplFrame and deadline as well. | 202 // up the BeginImplFrame and deadline as well. |
200 OnBeginImplFrameDeadline(); | 203 OnBeginImplFrameDeadline(); |
201 } else if (!settings_.deadline_scheduling_enabled) { | 204 } else if (!settings_.deadline_scheduling_enabled) { |
202 // We emulate the old non-deadline scheduler here by posting the | 205 // We emulate the old non-deadline scheduler here by posting the |
203 // deadline task without any delay. | 206 // deadline task without any delay. |
204 PostBeginImplFrameDeadline(base::TimeTicks()); | 207 PostBeginImplFrameDeadline(gfx::FrameTime()); |
205 } else if (state_machine_.ShouldTriggerBeginImplFrameDeadlineEarly()) { | 208 } else if (state_machine_.ShouldTriggerBeginImplFrameDeadlineEarly()) { |
206 // We are ready to draw a new active tree immediately. | 209 // We are ready to draw a new active tree immediately. |
207 PostBeginImplFrameDeadline(base::TimeTicks()); | 210 PostBeginImplFrameDeadline(gfx::FrameTime()); |
208 } else if (state_machine_.needs_redraw()) { | 211 } else if (state_machine_.needs_redraw()) { |
209 // We have an animation or fast input path on the impl thread that wants | 212 // We have an animation or fast input path on the impl thread that wants |
210 // to draw, so don't wait too long for a new active tree. | 213 // to draw, so don't wait too long for a new active tree. |
211 PostBeginImplFrameDeadline(last_begin_impl_frame_args_.deadline); | 214 PostBeginImplFrameDeadline(last_begin_impl_frame_args_.deadline); |
212 } else { | 215 } else { |
213 // The impl thread doesn't have anything it wants to draw and we are just | 216 // The impl thread doesn't have anything it wants to draw and we are just |
214 // waiting for a new active tree, so post the deadline for the next | 217 // waiting for a new active tree, so post the deadline for the next |
215 // expected BeginImplFrame start. This allows us to draw immediately when | 218 // expected BeginImplFrame start. This allows us to draw immediately when |
216 // there is a new active tree, instead of waiting for the next | 219 // there is a new active tree, instead of waiting for the next |
217 // BeginImplFrame. | 220 // BeginImplFrame. |
218 // TODO(brianderson): Handle long deadlines (that are past the next frame's | 221 // TODO(brianderson): Handle long deadlines (that are past the next frame's |
219 // frame time) properly instead of using this hack. | 222 // frame time) properly instead of using this hack. |
220 PostBeginImplFrameDeadline(last_begin_impl_frame_args_.frame_time + | 223 PostBeginImplFrameDeadline(last_begin_impl_frame_args_.frame_time + |
221 last_begin_impl_frame_args_.interval); | 224 last_begin_impl_frame_args_.interval); |
222 } | 225 } |
223 } | 226 } |
224 | 227 |
225 void Scheduler::PostBeginImplFrameDeadline(base::TimeTicks deadline) { | 228 void Scheduler::PostBeginImplFrameDeadline(gfx::FrameTime deadline) { |
226 begin_impl_frame_deadline_closure_.Cancel(); | 229 begin_impl_frame_deadline_closure_.Cancel(); |
227 begin_impl_frame_deadline_closure_.Reset( | 230 begin_impl_frame_deadline_closure_.Reset( |
228 base::Bind(&Scheduler::OnBeginImplFrameDeadline, | 231 base::Bind(&Scheduler::OnBeginImplFrameDeadline, |
229 weak_factory_.GetWeakPtr())); | 232 weak_factory_.GetWeakPtr())); |
230 client_->PostBeginImplFrameDeadline( | 233 client_->PostBeginImplFrameDeadline( |
231 begin_impl_frame_deadline_closure_.callback(), deadline); | 234 begin_impl_frame_deadline_closure_.callback(), deadline); |
232 } | 235 } |
233 | 236 |
234 void Scheduler::OnBeginImplFrameDeadline() { | 237 void Scheduler::OnBeginImplFrameDeadline() { |
235 TRACE_EVENT0("cc", "Scheduler::OnBeginImplFrameDeadline"); | 238 TRACE_EVENT0("cc", "Scheduler::OnBeginImplFrameDeadline"); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 case SchedulerStateMachine::ACTION_MANAGE_TILES: | 333 case SchedulerStateMachine::ACTION_MANAGE_TILES: |
331 client_->ScheduledActionManageTiles(); | 334 client_->ScheduledActionManageTiles(); |
332 break; | 335 break; |
333 } | 336 } |
334 } while (action != SchedulerStateMachine::ACTION_NONE); | 337 } while (action != SchedulerStateMachine::ACTION_NONE); |
335 | 338 |
336 SetupNextBeginImplFrameIfNeeded(); | 339 SetupNextBeginImplFrameIfNeeded(); |
337 client_->DidAnticipatedDrawTimeChange(AnticipatedDrawTime()); | 340 client_->DidAnticipatedDrawTimeChange(AnticipatedDrawTime()); |
338 | 341 |
339 if (state_machine_.ShouldTriggerBeginImplFrameDeadlineEarly()) | 342 if (state_machine_.ShouldTriggerBeginImplFrameDeadlineEarly()) |
340 PostBeginImplFrameDeadline(base::TimeTicks()); | 343 PostBeginImplFrameDeadline(gfx::FrameTime()); |
341 } | 344 } |
342 | 345 |
343 bool Scheduler::WillDrawIfNeeded() const { | 346 bool Scheduler::WillDrawIfNeeded() const { |
344 return !state_machine_.PendingDrawsShouldBeAborted(); | 347 return !state_machine_.PendingDrawsShouldBeAborted(); |
345 } | 348 } |
346 | 349 |
347 } // namespace cc | 350 } // namespace cc |
OLD | NEW |