Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: cc/scheduler/scheduler.cc

Issue 2339633003: Reland of cc: Remove frame queuing from the scheduler. (Closed)
Patch Set: prevent draw if commit is pending Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_NONE), 57 SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_NONE),
58 begin_impl_frame_tracker_(BEGINFRAMETRACKER_FROM_HERE), 58 begin_impl_frame_tracker_(BEGINFRAMETRACKER_FROM_HERE),
59 state_machine_(settings), 59 state_machine_(settings),
60 inside_process_scheduled_actions_(false), 60 inside_process_scheduled_actions_(false),
61 inside_action_(SchedulerStateMachine::ACTION_NONE), 61 inside_action_(SchedulerStateMachine::ACTION_NONE),
62 weak_factory_(this) { 62 weak_factory_(this) {
63 TRACE_EVENT1("cc", "Scheduler::Scheduler", "settings", settings_.AsValue()); 63 TRACE_EVENT1("cc", "Scheduler::Scheduler", "settings", settings_.AsValue());
64 DCHECK(client_); 64 DCHECK(client_);
65 DCHECK(!state_machine_.BeginFrameNeeded()); 65 DCHECK(!state_machine_.BeginFrameNeeded());
66 66
67 begin_retro_frame_closure_ =
68 base::Bind(&Scheduler::BeginRetroFrame, weak_factory_.GetWeakPtr());
69 begin_impl_frame_deadline_closure_ = base::Bind( 67 begin_impl_frame_deadline_closure_ = base::Bind(
70 &Scheduler::OnBeginImplFrameDeadline, weak_factory_.GetWeakPtr()); 68 &Scheduler::OnBeginImplFrameDeadline, weak_factory_.GetWeakPtr());
71 69
72 SetBeginFrameSource(begin_frame_source); 70 SetBeginFrameSource(begin_frame_source);
73 ProcessScheduledActions(); 71 ProcessScheduledActions();
74 } 72 }
75 73
76 Scheduler::~Scheduler() { 74 Scheduler::~Scheduler() {
77 SetBeginFrameSource(nullptr); 75 SetBeginFrameSource(nullptr);
78 } 76 }
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 compositor_timing_history_->WillPrepareTiles(); 186 compositor_timing_history_->WillPrepareTiles();
189 } 187 }
190 188
191 void Scheduler::DidPrepareTiles() { 189 void Scheduler::DidPrepareTiles() {
192 compositor_timing_history_->DidPrepareTiles(); 190 compositor_timing_history_->DidPrepareTiles();
193 state_machine_.DidPrepareTiles(); 191 state_machine_.DidPrepareTiles();
194 } 192 }
195 193
196 void Scheduler::DidLoseCompositorFrameSink() { 194 void Scheduler::DidLoseCompositorFrameSink() {
197 TRACE_EVENT0("cc", "Scheduler::DidLoseCompositorFrameSink"); 195 TRACE_EVENT0("cc", "Scheduler::DidLoseCompositorFrameSink");
198 begin_retro_frame_args_.clear();
199 begin_retro_frame_task_.Cancel();
200 state_machine_.DidLoseCompositorFrameSink(); 196 state_machine_.DidLoseCompositorFrameSink();
201 UpdateCompositorTimingHistoryRecordingEnabled(); 197 UpdateCompositorTimingHistoryRecordingEnabled();
202 ProcessScheduledActions(); 198 ProcessScheduledActions();
203 } 199 }
204 200
205 void Scheduler::DidCreateAndInitializeCompositorFrameSink() { 201 void Scheduler::DidCreateAndInitializeCompositorFrameSink() {
206 TRACE_EVENT0("cc", "Scheduler::DidCreateAndInitializeCompositorFrameSink"); 202 TRACE_EVENT0("cc", "Scheduler::DidCreateAndInitializeCompositorFrameSink");
207 DCHECK(!observing_begin_frame_source_); 203 DCHECK(!observing_begin_frame_source_);
208 DCHECK(begin_impl_frame_deadline_task_.IsCancelled()); 204 DCHECK(begin_impl_frame_deadline_task_.IsCancelled());
209 state_machine_.DidCreateAndInitializeCompositorFrameSink(); 205 state_machine_.DidCreateAndInitializeCompositorFrameSink();
(...skipping 16 matching lines...) Expand all
226 void Scheduler::BeginImplFrameNotExpectedSoon() { 222 void Scheduler::BeginImplFrameNotExpectedSoon() {
227 compositor_timing_history_->BeginImplFrameNotExpectedSoon(); 223 compositor_timing_history_->BeginImplFrameNotExpectedSoon();
228 224
229 // Tying this to SendBeginMainFrameNotExpectedSoon will have some 225 // Tying this to SendBeginMainFrameNotExpectedSoon will have some
230 // false negatives, but we want to avoid running long idle tasks when 226 // false negatives, but we want to avoid running long idle tasks when
231 // we are actually active. 227 // we are actually active.
232 client_->SendBeginMainFrameNotExpectedSoon(); 228 client_->SendBeginMainFrameNotExpectedSoon();
233 } 229 }
234 230
235 void Scheduler::SetupNextBeginFrameIfNeeded() { 231 void Scheduler::SetupNextBeginFrameIfNeeded() {
236 // Never call SetNeedsBeginFrames if the frame source already has the right 232 if (state_machine_.begin_impl_frame_state() !=
237 // value. 233 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE) {
238 if (observing_begin_frame_source_ != state_machine_.BeginFrameNeeded()) { 234 return;
239 if (state_machine_.BeginFrameNeeded()) {
240 // Call AddObserver as soon as possible.
241 observing_begin_frame_source_ = true;
242 if (begin_frame_source_)
243 begin_frame_source_->AddObserver(this);
244 devtools_instrumentation::NeedsBeginFrameChanged(layer_tree_host_id_,
245 true);
246 } else if (state_machine_.begin_impl_frame_state() ==
247 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE) {
248 // Call RemoveObserver in between frames only.
249 observing_begin_frame_source_ = false;
250 if (begin_frame_source_)
251 begin_frame_source_->RemoveObserver(this);
252 BeginImplFrameNotExpectedSoon();
253 devtools_instrumentation::NeedsBeginFrameChanged(layer_tree_host_id_,
254 false);
255 }
256 } 235 }
257 236
258 PostBeginRetroFrameIfNeeded(); 237 bool needs_begin_frames = state_machine_.BeginFrameNeeded();
238 if (needs_begin_frames && !observing_begin_frame_source_) {
239 observing_begin_frame_source_ = true;
240 if (begin_frame_source_)
241 begin_frame_source_->AddObserver(this);
242 devtools_instrumentation::NeedsBeginFrameChanged(layer_tree_host_id_, true);
243 } else if (!needs_begin_frames && observing_begin_frame_source_) {
244 observing_begin_frame_source_ = false;
245 if (begin_frame_source_)
246 begin_frame_source_->RemoveObserver(this);
247 missed_begin_frame_task_.Cancel();
248 BeginImplFrameNotExpectedSoon();
249 devtools_instrumentation::NeedsBeginFrameChanged(layer_tree_host_id_,
250 false);
251 }
259 } 252 }
260 253
261 void Scheduler::OnBeginFrameSourcePausedChanged(bool paused) { 254 void Scheduler::OnBeginFrameSourcePausedChanged(bool paused) {
262 if (state_machine_.begin_frame_source_paused() == paused) 255 if (state_machine_.begin_frame_source_paused() == paused)
263 return; 256 return;
264 TRACE_EVENT_INSTANT1("cc", "Scheduler::SetBeginFrameSourcePaused", 257 TRACE_EVENT_INSTANT1("cc", "Scheduler::SetBeginFrameSourcePaused",
265 TRACE_EVENT_SCOPE_THREAD, "paused", paused); 258 TRACE_EVENT_SCOPE_THREAD, "paused", paused);
266 state_machine_.SetBeginFrameSourcePaused(paused); 259 state_machine_.SetBeginFrameSourcePaused(paused);
267 ProcessScheduledActions(); 260 ProcessScheduledActions();
268 } 261 }
269 262
270 // BeginFrame is the mechanism that tells us that now is a good time to start 263 // BeginFrame is the mechanism that tells us that now is a good time to start
271 // making a frame. Usually this means that user input for the frame is complete. 264 // making a frame. Usually this means that user input for the frame is complete.
272 // If the scheduler is busy, we queue the BeginFrame to be handled later as 265 // If the scheduler is busy, we queue the BeginFrame to be handled later as
273 // a BeginRetroFrame. 266 // a BeginRetroFrame.
274 bool Scheduler::OnBeginFrameDerivedImpl(const BeginFrameArgs& args) { 267 bool Scheduler::OnBeginFrameDerivedImpl(const BeginFrameArgs& args) {
275 TRACE_EVENT1("cc,benchmark", "Scheduler::BeginFrame", "args", args.AsValue()); 268 TRACE_EVENT1("cc,benchmark", "Scheduler::BeginFrame", "args", args.AsValue());
276 269
270 if (!state_machine_.BeginFrameNeeded()) {
271 TRACE_EVENT_INSTANT0("cc", "Scheduler::BeginFrameDropped",
272 TRACE_EVENT_SCOPE_THREAD);
273 return false;
274 }
275
277 // Trace this begin frame time through the Chrome stack 276 // Trace this begin frame time through the Chrome stack
278 TRACE_EVENT_FLOW_BEGIN0( 277 TRACE_EVENT_FLOW_BEGIN0(
279 TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), "BeginFrameArgs", 278 TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), "BeginFrameArgs",
280 args.frame_time.ToInternalValue()); 279 args.frame_time.ToInternalValue());
281 280
282 if (settings_.using_synchronous_renderer_compositor) { 281 if (settings_.using_synchronous_renderer_compositor) {
283 BeginImplFrameSynchronous(args); 282 BeginImplFrameSynchronous(args);
284 return true; 283 return true;
285 } 284 }
286 285
287 // We have just called SetNeedsBeginFrame(true) and the BeginFrameSource has 286 if (inside_process_scheduled_actions_) {
288 // sent us the last BeginFrame we have missed. As we might not be able to 287 // The BFS can send a missed begin frame inside AddObserver. We can't handle
289 // actually make rendering for this call, handle it like a "retro frame". 288 // a begin frame inside ProcessScheduledActions so post a task.
290 // TODO(brainderson): Add a test for this functionality ASAP! 289 DCHECK_EQ(args.type, BeginFrameArgs::MISSED);
291 if (args.type == BeginFrameArgs::MISSED) { 290 DCHECK(missed_begin_frame_task_.IsCancelled());
292 begin_retro_frame_args_.push_back(args); 291 missed_begin_frame_task_.Reset(base::Bind(
293 PostBeginRetroFrameIfNeeded(); 292 &Scheduler::BeginImplFrameWithDeadline, base::Unretained(this), args));
293 task_runner_->PostTask(FROM_HERE, missed_begin_frame_task_.callback());
294 return true; 294 return true;
295 } 295 }
296 296
297 bool should_defer_begin_frame = 297 BeginImplFrameWithDeadline(args);
298 !begin_retro_frame_args_.empty() ||
299 !begin_retro_frame_task_.IsCancelled() ||
300 !observing_begin_frame_source_ ||
301 (state_machine_.begin_impl_frame_state() !=
302 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE);
303
304 if (should_defer_begin_frame) {
305 begin_retro_frame_args_.push_back(args);
306 TRACE_EVENT_INSTANT0("cc", "Scheduler::BeginFrame deferred",
307 TRACE_EVENT_SCOPE_THREAD);
308 // Queuing the frame counts as "using it", so we need to return true.
309 } else {
310 BeginImplFrameWithDeadline(args);
311 }
312 return true; 298 return true;
313 } 299 }
314 300
315 void Scheduler::SetVideoNeedsBeginFrames(bool video_needs_begin_frames) { 301 void Scheduler::SetVideoNeedsBeginFrames(bool video_needs_begin_frames) {
316 state_machine_.SetVideoNeedsBeginFrames(video_needs_begin_frames); 302 state_machine_.SetVideoNeedsBeginFrames(video_needs_begin_frames);
317 ProcessScheduledActions(); 303 ProcessScheduledActions();
318 } 304 }
319 305
320 void Scheduler::OnDrawForCompositorFrameSink(bool resourceless_software_draw) { 306 void Scheduler::OnDrawForCompositorFrameSink(bool resourceless_software_draw) {
321 DCHECK(settings_.using_synchronous_renderer_compositor); 307 DCHECK(settings_.using_synchronous_renderer_compositor);
322 DCHECK_EQ(state_machine_.begin_impl_frame_state(), 308 DCHECK_EQ(state_machine_.begin_impl_frame_state(),
323 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); 309 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE);
324 DCHECK(begin_impl_frame_deadline_task_.IsCancelled()); 310 DCHECK(begin_impl_frame_deadline_task_.IsCancelled());
325 311
326 state_machine_.SetResourcelessSoftwareDraw(resourceless_software_draw); 312 state_machine_.SetResourcelessSoftwareDraw(resourceless_software_draw);
327 state_machine_.OnBeginImplFrameDeadline(); 313 state_machine_.OnBeginImplFrameDeadline();
328 ProcessScheduledActions(); 314 ProcessScheduledActions();
329 315
330 state_machine_.OnBeginImplFrameIdle(); 316 state_machine_.OnBeginImplFrameIdle();
331 ProcessScheduledActions(); 317 ProcessScheduledActions();
332 state_machine_.SetResourcelessSoftwareDraw(false); 318 state_machine_.SetResourcelessSoftwareDraw(false);
333 } 319 }
334 320
335 // BeginRetroFrame is called for BeginFrames that we've deferred because 321 void Scheduler::BeginImplFrameWithDeadline(const BeginFrameArgs& args) {
336 // the scheduler was in the middle of processing a previous BeginFrame. 322 // The storage for |args| is owned by the missed begin frame task. Therefore
337 void Scheduler::BeginRetroFrame() { 323 // save |args| before cancelling the task either here or in the deadline.
338 TRACE_EVENT0("cc,benchmark", "Scheduler::BeginRetroFrame"); 324 BeginFrameArgs adjusted_args = args;
339 DCHECK(!settings_.using_synchronous_renderer_compositor); 325 // Cancel the missed begin frame task in case the BFS sends a begin frame
340 DCHECK(!begin_retro_frame_args_.empty()); 326 // before the missed frame task runs.
341 DCHECK(!begin_retro_frame_task_.IsCancelled()); 327 missed_begin_frame_task_.Cancel();
328
329 // Discard missed begin frames if they are too late.
330 if (adjusted_args.type == BeginFrameArgs::MISSED &&
331 Now() > adjusted_args.deadline) {
332 begin_frame_source_->DidFinishFrame(this, 0);
333 return;
334 }
335
336 // Run the previous deadline if any.
337 if (state_machine_.begin_impl_frame_state() ==
338 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME) {
339 OnBeginImplFrameDeadline();
340 // We may not need begin frames any longer.
341 if (!observing_begin_frame_source_) {
342 begin_frame_source_->DidFinishFrame(this, 0);
343 return;
344 }
345 }
342 DCHECK_EQ(state_machine_.begin_impl_frame_state(), 346 DCHECK_EQ(state_machine_.begin_impl_frame_state(),
343 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); 347 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE);
344 348
345 begin_retro_frame_task_.Cancel();
346
347 // Discard expired BeginRetroFrames
348 // Today, we should always end up with at most one un-expired BeginRetroFrame
349 // because deadlines will not be greater than the next frame time. We don't
350 // DCHECK though because some systems don't always have monotonic timestamps.
351 // TODO(brianderson): In the future, long deadlines could result in us not
352 // draining the queue if we don't catch up. If we consistently can't catch
353 // up, our fallback should be to lower our frame rate.
354 base::TimeTicks now = Now();
355
356 while (!begin_retro_frame_args_.empty()) {
357 const BeginFrameArgs& args = begin_retro_frame_args_.front();
358 base::TimeTicks expiration_time = args.deadline;
359 if (now <= expiration_time)
360 break;
361 TRACE_EVENT_INSTANT2(
362 "cc", "Scheduler::BeginRetroFrame discarding", TRACE_EVENT_SCOPE_THREAD,
363 "expiration_time - now", (expiration_time - now).InMillisecondsF(),
364 "BeginFrameArgs", begin_retro_frame_args_.front().AsValue());
365 begin_retro_frame_args_.pop_front();
366 if (begin_frame_source_)
367 begin_frame_source_->DidFinishFrame(this, begin_retro_frame_args_.size());
368 }
369
370 if (begin_retro_frame_args_.empty()) {
371 TRACE_EVENT_INSTANT0("cc", "Scheduler::BeginRetroFrames all expired",
372 TRACE_EVENT_SCOPE_THREAD);
373 } else {
374 BeginFrameArgs front = begin_retro_frame_args_.front();
375 begin_retro_frame_args_.pop_front();
376 BeginImplFrameWithDeadline(front);
377 }
378 }
379
380 // There could be a race between the posted BeginRetroFrame and a new
381 // BeginFrame arriving via the normal mechanism. Scheduler::BeginFrame
382 // will check if there is a pending BeginRetroFrame to ensure we handle
383 // BeginFrames in FIFO order.
384 void Scheduler::PostBeginRetroFrameIfNeeded() {
385 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"),
386 "Scheduler::PostBeginRetroFrameIfNeeded", "state", AsValue());
387 if (!observing_begin_frame_source_)
388 return;
389
390 if (begin_retro_frame_args_.empty() || !begin_retro_frame_task_.IsCancelled())
391 return;
392
393 // begin_retro_frame_args_ should always be empty for the
394 // synchronous compositor.
395 DCHECK(!settings_.using_synchronous_renderer_compositor);
396
397 if (state_machine_.begin_impl_frame_state() !=
398 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE)
399 return;
400
401 begin_retro_frame_task_.Reset(begin_retro_frame_closure_);
402
403 task_runner_->PostTask(FROM_HERE, begin_retro_frame_task_.callback());
404 }
405
406 void Scheduler::BeginImplFrameWithDeadline(const BeginFrameArgs& args) {
407 bool main_thread_is_in_high_latency_mode = 349 bool main_thread_is_in_high_latency_mode =
408 state_machine_.main_thread_missed_last_deadline(); 350 state_machine_.main_thread_missed_last_deadline();
409 TRACE_EVENT2("cc,benchmark", "Scheduler::BeginImplFrame", "args", 351 TRACE_EVENT2("cc,benchmark", "Scheduler::BeginImplFrame", "args",
410 args.AsValue(), "main_thread_missed_last_deadline", 352 adjusted_args.AsValue(), "main_thread_missed_last_deadline",
411 main_thread_is_in_high_latency_mode); 353 main_thread_is_in_high_latency_mode);
412 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), 354 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"),
413 "MainThreadLatency", main_thread_is_in_high_latency_mode); 355 "MainThreadLatency", main_thread_is_in_high_latency_mode);
414 356
415 BeginFrameArgs adjusted_args = args; 357 DCHECK_EQ(state_machine_.begin_impl_frame_state(),
358 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE);
359
416 adjusted_args.deadline -= compositor_timing_history_->DrawDurationEstimate(); 360 adjusted_args.deadline -= compositor_timing_history_->DrawDurationEstimate();
417 adjusted_args.deadline -= kDeadlineFudgeFactor; 361 adjusted_args.deadline -= kDeadlineFudgeFactor;
418 362
419 base::TimeDelta bmf_start_to_activate = 363 base::TimeDelta bmf_start_to_activate =
420 compositor_timing_history_ 364 compositor_timing_history_
421 ->BeginMainFrameStartToCommitDurationEstimate() + 365 ->BeginMainFrameStartToCommitDurationEstimate() +
422 compositor_timing_history_->CommitToReadyToActivateDurationEstimate() + 366 compositor_timing_history_->CommitToReadyToActivateDurationEstimate() +
423 compositor_timing_history_->ActivateDurationEstimate(); 367 compositor_timing_history_->ActivateDurationEstimate();
424 368
425 base::TimeDelta bmf_to_activate_estimate_critical = 369 base::TimeDelta bmf_to_activate_estimate_critical =
426 bmf_start_to_activate + 370 bmf_start_to_activate +
427 compositor_timing_history_->BeginMainFrameQueueDurationCriticalEstimate(); 371 compositor_timing_history_->BeginMainFrameQueueDurationCriticalEstimate();
428 372
429 state_machine_.SetCriticalBeginMainFrameToActivateIsFast( 373 state_machine_.SetCriticalBeginMainFrameToActivateIsFast(
430 bmf_to_activate_estimate_critical < args.interval); 374 bmf_to_activate_estimate_critical < adjusted_args.interval);
431 375
432 // Update the BeginMainFrame args now that we know whether the main 376 // Update the BeginMainFrame args now that we know whether the main
433 // thread will be on the critical path or not. 377 // thread will be on the critical path or not.
434 begin_main_frame_args_ = adjusted_args; 378 begin_main_frame_args_ = adjusted_args;
435 begin_main_frame_args_.on_critical_path = !ImplLatencyTakesPriority(); 379 begin_main_frame_args_.on_critical_path = !ImplLatencyTakesPriority();
436 380
437 base::TimeDelta bmf_to_activate_estimate = bmf_to_activate_estimate_critical; 381 base::TimeDelta bmf_to_activate_estimate = bmf_to_activate_estimate_critical;
438 if (!begin_main_frame_args_.on_critical_path) { 382 if (!begin_main_frame_args_.on_critical_path) {
439 bmf_to_activate_estimate = 383 bmf_to_activate_estimate =
440 bmf_start_to_activate + 384 bmf_start_to_activate +
441 compositor_timing_history_ 385 compositor_timing_history_
442 ->BeginMainFrameQueueDurationNotCriticalEstimate(); 386 ->BeginMainFrameQueueDurationNotCriticalEstimate();
443 } 387 }
444 388
445 bool can_activate_before_deadline = 389 bool can_activate_before_deadline =
446 CanBeginMainFrameAndActivateBeforeDeadline(adjusted_args, 390 CanBeginMainFrameAndActivateBeforeDeadline(adjusted_args,
447 bmf_to_activate_estimate); 391 bmf_to_activate_estimate);
448 392
449 if (ShouldRecoverMainLatency(adjusted_args, can_activate_before_deadline)) { 393 if (ShouldRecoverMainLatency(adjusted_args, can_activate_before_deadline)) {
450 TRACE_EVENT_INSTANT0("cc", "SkipBeginMainFrameToReduceLatency", 394 TRACE_EVENT_INSTANT0("cc", "SkipBeginMainFrameToReduceLatency",
451 TRACE_EVENT_SCOPE_THREAD); 395 TRACE_EVENT_SCOPE_THREAD);
452 state_machine_.SetSkipNextBeginMainFrameToReduceLatency(); 396 state_machine_.SetSkipNextBeginMainFrameToReduceLatency();
453 } else if (ShouldRecoverImplLatency(adjusted_args, 397 } else if (ShouldRecoverImplLatency(adjusted_args,
454 can_activate_before_deadline)) { 398 can_activate_before_deadline)) {
455 TRACE_EVENT_INSTANT0("cc", "SkipBeginImplFrameToReduceLatency", 399 TRACE_EVENT_INSTANT0("cc", "SkipBeginImplFrameToReduceLatency",
456 TRACE_EVENT_SCOPE_THREAD); 400 TRACE_EVENT_SCOPE_THREAD);
457 if (begin_frame_source_) 401 if (begin_frame_source_)
458 begin_frame_source_->DidFinishFrame(this, begin_retro_frame_args_.size()); 402 begin_frame_source_->DidFinishFrame(this, 0);
459 return; 403 return;
460 } 404 }
461 405
462 BeginImplFrame(adjusted_args); 406 BeginImplFrame(adjusted_args);
463 } 407 }
464 408
465 void Scheduler::BeginImplFrameSynchronous(const BeginFrameArgs& args) { 409 void Scheduler::BeginImplFrameSynchronous(const BeginFrameArgs& args) {
466 TRACE_EVENT1("cc,benchmark", "Scheduler::BeginImplFrame", "args", 410 TRACE_EVENT1("cc,benchmark", "Scheduler::BeginImplFrame", "args",
467 args.AsValue()); 411 args.AsValue());
468 412
469 // The main thread currently can't commit before we draw with the 413 // The main thread currently can't commit before we draw with the
470 // synchronous compositor, so never consider the BeginMainFrame fast. 414 // synchronous compositor, so never consider the BeginMainFrame fast.
471 state_machine_.SetCriticalBeginMainFrameToActivateIsFast(false); 415 state_machine_.SetCriticalBeginMainFrameToActivateIsFast(false);
472 begin_main_frame_args_ = args; 416 begin_main_frame_args_ = args;
473 begin_main_frame_args_.on_critical_path = !ImplLatencyTakesPriority(); 417 begin_main_frame_args_.on_critical_path = !ImplLatencyTakesPriority();
474 418
475 BeginImplFrame(args); 419 BeginImplFrame(args);
476 compositor_timing_history_->WillFinishImplFrame( 420 compositor_timing_history_->WillFinishImplFrame(
477 state_machine_.needs_redraw()); 421 state_machine_.needs_redraw());
478 FinishImplFrame(); 422 FinishImplFrame();
479 } 423 }
480 424
481 void Scheduler::FinishImplFrame() { 425 void Scheduler::FinishImplFrame() {
482 state_machine_.OnBeginImplFrameIdle(); 426 state_machine_.OnBeginImplFrameIdle();
483 ProcessScheduledActions(); 427 ProcessScheduledActions();
484 428
485 client_->DidFinishImplFrame(); 429 client_->DidFinishImplFrame();
486 if (begin_frame_source_) 430 if (begin_frame_source_)
487 begin_frame_source_->DidFinishFrame(this, begin_retro_frame_args_.size()); 431 begin_frame_source_->DidFinishFrame(this, 0);
488 begin_impl_frame_tracker_.Finish(); 432 begin_impl_frame_tracker_.Finish();
489 } 433 }
490 434
491 // BeginImplFrame starts a compositor frame that will wait up until a deadline 435 // BeginImplFrame starts a compositor frame that will wait up until a deadline
492 // for a BeginMainFrame+activation to complete before it times out and draws 436 // for a BeginMainFrame+activation to complete before it times out and draws
493 // any asynchronous animation and scroll/pinch updates. 437 // any asynchronous animation and scroll/pinch updates.
494 void Scheduler::BeginImplFrame(const BeginFrameArgs& args) { 438 void Scheduler::BeginImplFrame(const BeginFrameArgs& args) {
495 DCHECK_EQ(state_machine_.begin_impl_frame_state(), 439 DCHECK_EQ(state_machine_.begin_impl_frame_state(),
496 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); 440 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE);
497 DCHECK(begin_impl_frame_deadline_task_.IsCancelled()); 441 DCHECK(begin_impl_frame_deadline_task_.IsCancelled());
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 new base::trace_event::TracedValue()); 646 new base::trace_event::TracedValue());
703 base::TimeTicks now = Now(); 647 base::TimeTicks now = Now();
704 648
705 state->BeginDictionary("state_machine"); 649 state->BeginDictionary("state_machine");
706 state_machine_.AsValueInto(state.get()); 650 state_machine_.AsValueInto(state.get());
707 state->EndDictionary(); 651 state->EndDictionary();
708 652
709 state->BeginDictionary("scheduler_state"); 653 state->BeginDictionary("scheduler_state");
710 state->SetBoolean("observing_begin_frame_source", 654 state->SetBoolean("observing_begin_frame_source",
711 observing_begin_frame_source_); 655 observing_begin_frame_source_);
712 state->SetInteger("begin_retro_frame_args",
713 static_cast<int>(begin_retro_frame_args_.size()));
714 state->SetBoolean("begin_retro_frame_task",
715 !begin_retro_frame_task_.IsCancelled());
716 state->SetBoolean("begin_impl_frame_deadline_task", 656 state->SetBoolean("begin_impl_frame_deadline_task",
717 !begin_impl_frame_deadline_task_.IsCancelled()); 657 !begin_impl_frame_deadline_task_.IsCancelled());
658 state->SetBoolean("missed_begin_frame_task",
659 !missed_begin_frame_task_.IsCancelled());
718 state->SetString("inside_action", 660 state->SetString("inside_action",
719 SchedulerStateMachine::ActionToString(inside_action_)); 661 SchedulerStateMachine::ActionToString(inside_action_));
720 662
721 state->BeginDictionary("begin_impl_frame_args"); 663 state->BeginDictionary("begin_impl_frame_args");
722 begin_impl_frame_tracker_.AsValueInto(now, state.get()); 664 begin_impl_frame_tracker_.AsValueInto(now, state.get());
723 state->EndDictionary(); 665 state->EndDictionary();
724 666
725 state->SetString("begin_impl_frame_deadline_mode_", 667 state->SetString("begin_impl_frame_deadline_mode_",
726 SchedulerStateMachine::BeginImplFrameDeadlineModeToString( 668 SchedulerStateMachine::BeginImplFrameDeadlineModeToString(
727 begin_impl_frame_deadline_mode_)); 669 begin_impl_frame_deadline_mode_));
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 } 754 }
813 755
814 bool Scheduler::IsBeginMainFrameSentOrStarted() const { 756 bool Scheduler::IsBeginMainFrameSentOrStarted() const {
815 return (state_machine_.begin_main_frame_state() == 757 return (state_machine_.begin_main_frame_state() ==
816 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT || 758 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT ||
817 state_machine_.begin_main_frame_state() == 759 state_machine_.begin_main_frame_state() ==
818 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_STARTED); 760 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_STARTED);
819 } 761 }
820 762
821 } // namespace cc 763 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698