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 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 BeginFrameArgs adjusted_args = args; | 315 BeginFrameArgs adjusted_args = args; |
316 // Cancel the missed begin frame task in case the BFS sends a begin frame | 316 // Cancel the missed begin frame task in case the BFS sends a begin frame |
317 // before the missed frame task runs. | 317 // before the missed frame task runs. |
318 missed_begin_frame_task_.Cancel(); | 318 missed_begin_frame_task_.Cancel(); |
319 | 319 |
320 base::TimeTicks now = Now(); | 320 base::TimeTicks now = Now(); |
321 | 321 |
322 // Discard missed begin frames if they are too late. | 322 // Discard missed begin frames if they are too late. |
323 if (adjusted_args.type == BeginFrameArgs::MISSED && | 323 if (adjusted_args.type == BeginFrameArgs::MISSED && |
324 now > adjusted_args.deadline) { | 324 now > adjusted_args.deadline) { |
325 begin_frame_source_->DidFinishFrame(this, 0); | 325 // TODO(eseckler): Determine and set correct |ack.latest_confirmed_frame|. |
| 326 BeginFrameAck ack(adjusted_args.source_id, adjusted_args.sequence_number, |
| 327 adjusted_args.sequence_number, 0, false); |
| 328 begin_frame_source_->DidFinishFrame(this, ack); |
326 return; | 329 return; |
327 } | 330 } |
328 | 331 |
329 // Run the previous deadline if any. | 332 // Run the previous deadline if any. |
330 if (state_machine_.begin_impl_frame_state() == | 333 if (state_machine_.begin_impl_frame_state() == |
331 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME) { | 334 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME) { |
332 OnBeginImplFrameDeadline(); | 335 OnBeginImplFrameDeadline(); |
333 // We may not need begin frames any longer. | 336 // We may not need begin frames any longer. |
334 if (!observing_begin_frame_source_) { | 337 if (!observing_begin_frame_source_) { |
335 begin_frame_source_->DidFinishFrame(this, 0); | 338 // TODO(eseckler): Determine and set correct |ack.latest_confirmed_frame|. |
| 339 BeginFrameAck ack(adjusted_args.source_id, adjusted_args.sequence_number, |
| 340 adjusted_args.sequence_number, 0, false); |
| 341 begin_frame_source_->DidFinishFrame(this, ack); |
336 return; | 342 return; |
337 } | 343 } |
338 } | 344 } |
339 DCHECK_EQ(state_machine_.begin_impl_frame_state(), | 345 DCHECK_EQ(state_machine_.begin_impl_frame_state(), |
340 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); | 346 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); |
341 | 347 |
342 bool main_thread_is_in_high_latency_mode = | 348 bool main_thread_is_in_high_latency_mode = |
343 state_machine_.main_thread_missed_last_deadline(); | 349 state_machine_.main_thread_missed_last_deadline(); |
344 TRACE_EVENT2("cc,benchmark", "Scheduler::BeginImplFrame", "args", | 350 TRACE_EVENT2("cc,benchmark", "Scheduler::BeginImplFrame", "args", |
345 adjusted_args.AsValue(), "main_thread_missed_last_deadline", | 351 adjusted_args.AsValue(), "main_thread_missed_last_deadline", |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 bmf_to_activate_estimate, now); | 390 bmf_to_activate_estimate, now); |
385 | 391 |
386 if (ShouldRecoverMainLatency(adjusted_args, can_activate_before_deadline)) { | 392 if (ShouldRecoverMainLatency(adjusted_args, can_activate_before_deadline)) { |
387 TRACE_EVENT_INSTANT0("cc", "SkipBeginMainFrameToReduceLatency", | 393 TRACE_EVENT_INSTANT0("cc", "SkipBeginMainFrameToReduceLatency", |
388 TRACE_EVENT_SCOPE_THREAD); | 394 TRACE_EVENT_SCOPE_THREAD); |
389 state_machine_.SetSkipNextBeginMainFrameToReduceLatency(); | 395 state_machine_.SetSkipNextBeginMainFrameToReduceLatency(); |
390 } else if (ShouldRecoverImplLatency(adjusted_args, | 396 } else if (ShouldRecoverImplLatency(adjusted_args, |
391 can_activate_before_deadline)) { | 397 can_activate_before_deadline)) { |
392 TRACE_EVENT_INSTANT0("cc", "SkipBeginImplFrameToReduceLatency", | 398 TRACE_EVENT_INSTANT0("cc", "SkipBeginImplFrameToReduceLatency", |
393 TRACE_EVENT_SCOPE_THREAD); | 399 TRACE_EVENT_SCOPE_THREAD); |
394 if (begin_frame_source_) | 400 if (begin_frame_source_) { |
395 begin_frame_source_->DidFinishFrame(this, 0); | 401 // TODO(eseckler): Determine and set correct |ack.latest_confirmed_frame|. |
| 402 BeginFrameAck ack(adjusted_args.source_id, adjusted_args.sequence_number, |
| 403 adjusted_args.sequence_number, 0, false); |
| 404 begin_frame_source_->DidFinishFrame(this, ack); |
| 405 } |
396 return; | 406 return; |
397 } | 407 } |
398 | 408 |
399 BeginImplFrame(adjusted_args); | 409 BeginImplFrame(adjusted_args); |
400 } | 410 } |
401 | 411 |
402 void Scheduler::BeginImplFrameSynchronous(const BeginFrameArgs& args) { | 412 void Scheduler::BeginImplFrameSynchronous(const BeginFrameArgs& args) { |
403 TRACE_EVENT1("cc,benchmark", "Scheduler::BeginImplFrame", "args", | 413 TRACE_EVENT1("cc,benchmark", "Scheduler::BeginImplFrame", "args", |
404 args.AsValue()); | 414 args.AsValue()); |
405 | 415 |
406 // The main thread currently can't commit before we draw with the | 416 // The main thread currently can't commit before we draw with the |
407 // synchronous compositor, so never consider the BeginMainFrame fast. | 417 // synchronous compositor, so never consider the BeginMainFrame fast. |
408 state_machine_.SetCriticalBeginMainFrameToActivateIsFast(false); | 418 state_machine_.SetCriticalBeginMainFrameToActivateIsFast(false); |
409 begin_main_frame_args_ = args; | 419 begin_main_frame_args_ = args; |
410 begin_main_frame_args_.on_critical_path = !ImplLatencyTakesPriority(); | 420 begin_main_frame_args_.on_critical_path = !ImplLatencyTakesPriority(); |
411 | 421 |
412 BeginImplFrame(args); | 422 BeginImplFrame(args); |
413 compositor_timing_history_->WillFinishImplFrame( | 423 compositor_timing_history_->WillFinishImplFrame( |
414 state_machine_.needs_redraw()); | 424 state_machine_.needs_redraw()); |
415 FinishImplFrame(); | 425 FinishImplFrame(); |
416 } | 426 } |
417 | 427 |
418 void Scheduler::FinishImplFrame() { | 428 void Scheduler::FinishImplFrame() { |
419 state_machine_.OnBeginImplFrameIdle(); | 429 state_machine_.OnBeginImplFrameIdle(); |
420 ProcessScheduledActions(); | 430 ProcessScheduledActions(); |
421 | 431 |
422 client_->DidFinishImplFrame(); | 432 client_->DidFinishImplFrame(); |
423 if (begin_frame_source_) | 433 if (begin_frame_source_) { |
424 begin_frame_source_->DidFinishFrame(this, 0); | 434 // TODO(eseckler): Determine and set correct |ack.latest_confirmed_frame|. |
| 435 BeginFrameAck ack(begin_main_frame_args_.source_id, |
| 436 begin_main_frame_args_.sequence_number, |
| 437 begin_main_frame_args_.sequence_number, 0, |
| 438 state_machine_.did_submit_in_last_frame()); |
| 439 begin_frame_source_->DidFinishFrame(this, ack); |
| 440 } |
425 begin_impl_frame_tracker_.Finish(); | 441 begin_impl_frame_tracker_.Finish(); |
426 } | 442 } |
427 | 443 |
428 // BeginImplFrame starts a compositor frame that will wait up until a deadline | 444 // BeginImplFrame starts a compositor frame that will wait up until a deadline |
429 // for a BeginMainFrame+activation to complete before it times out and draws | 445 // for a BeginMainFrame+activation to complete before it times out and draws |
430 // any asynchronous animation and scroll/pinch updates. | 446 // any asynchronous animation and scroll/pinch updates. |
431 void Scheduler::BeginImplFrame(const BeginFrameArgs& args) { | 447 void Scheduler::BeginImplFrame(const BeginFrameArgs& args) { |
432 DCHECK_EQ(state_machine_.begin_impl_frame_state(), | 448 DCHECK_EQ(state_machine_.begin_impl_frame_state(), |
433 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); | 449 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); |
434 DCHECK(begin_impl_frame_deadline_task_.IsCancelled()); | 450 DCHECK(begin_impl_frame_deadline_task_.IsCancelled()); |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
751 } | 767 } |
752 | 768 |
753 bool Scheduler::IsBeginMainFrameSentOrStarted() const { | 769 bool Scheduler::IsBeginMainFrameSentOrStarted() const { |
754 return (state_machine_.begin_main_frame_state() == | 770 return (state_machine_.begin_main_frame_state() == |
755 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT || | 771 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT || |
756 state_machine_.begin_main_frame_state() == | 772 state_machine_.begin_main_frame_state() == |
757 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_STARTED); | 773 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_STARTED); |
758 } | 774 } |
759 | 775 |
760 } // namespace cc | 776 } // namespace cc |
OLD | NEW |