| 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 BeginFrameAck ack( |
| 326 adjusted_args.source_id, adjusted_args.sequence_number, |
| 327 state_machine_.last_frame_number_compositor_frame_was_fresh(), 0, |
| 328 false); |
| 329 begin_frame_source_->DidFinishFrame(this, ack); |
| 326 return; | 330 return; |
| 327 } | 331 } |
| 328 | 332 |
| 329 // Run the previous deadline if any. | 333 // Run the previous deadline if any. |
| 330 if (state_machine_.begin_impl_frame_state() == | 334 if (state_machine_.begin_impl_frame_state() == |
| 331 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME) { | 335 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME) { |
| 332 OnBeginImplFrameDeadline(); | 336 OnBeginImplFrameDeadline(); |
| 333 // We may not need begin frames any longer. | 337 // We may not need begin frames any longer. |
| 334 if (!observing_begin_frame_source_) { | 338 if (!observing_begin_frame_source_) { |
| 335 begin_frame_source_->DidFinishFrame(this, 0); | 339 BeginFrameAck ack( |
| 340 adjusted_args.source_id, adjusted_args.sequence_number, |
| 341 state_machine_.last_frame_number_compositor_frame_was_fresh(), 0, |
| 342 false); |
| 343 begin_frame_source_->DidFinishFrame(this, ack); |
| 336 return; | 344 return; |
| 337 } | 345 } |
| 338 } | 346 } |
| 339 DCHECK_EQ(state_machine_.begin_impl_frame_state(), | 347 DCHECK_EQ(state_machine_.begin_impl_frame_state(), |
| 340 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); | 348 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); |
| 341 | 349 |
| 342 bool main_thread_is_in_high_latency_mode = | 350 bool main_thread_is_in_high_latency_mode = |
| 343 state_machine_.main_thread_missed_last_deadline(); | 351 state_machine_.main_thread_missed_last_deadline(); |
| 344 TRACE_EVENT2("cc,benchmark", "Scheduler::BeginImplFrame", "args", | 352 TRACE_EVENT2("cc,benchmark", "Scheduler::BeginImplFrame", "args", |
| 345 adjusted_args.AsValue(), "main_thread_missed_last_deadline", | 353 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); | 392 bmf_to_activate_estimate, now); |
| 385 | 393 |
| 386 if (ShouldRecoverMainLatency(adjusted_args, can_activate_before_deadline)) { | 394 if (ShouldRecoverMainLatency(adjusted_args, can_activate_before_deadline)) { |
| 387 TRACE_EVENT_INSTANT0("cc", "SkipBeginMainFrameToReduceLatency", | 395 TRACE_EVENT_INSTANT0("cc", "SkipBeginMainFrameToReduceLatency", |
| 388 TRACE_EVENT_SCOPE_THREAD); | 396 TRACE_EVENT_SCOPE_THREAD); |
| 389 state_machine_.SetSkipNextBeginMainFrameToReduceLatency(); | 397 state_machine_.SetSkipNextBeginMainFrameToReduceLatency(); |
| 390 } else if (ShouldRecoverImplLatency(adjusted_args, | 398 } else if (ShouldRecoverImplLatency(adjusted_args, |
| 391 can_activate_before_deadline)) { | 399 can_activate_before_deadline)) { |
| 392 TRACE_EVENT_INSTANT0("cc", "SkipBeginImplFrameToReduceLatency", | 400 TRACE_EVENT_INSTANT0("cc", "SkipBeginImplFrameToReduceLatency", |
| 393 TRACE_EVENT_SCOPE_THREAD); | 401 TRACE_EVENT_SCOPE_THREAD); |
| 394 if (begin_frame_source_) | 402 if (begin_frame_source_) { |
| 395 begin_frame_source_->DidFinishFrame(this, 0); | 403 BeginFrameAck ack( |
| 404 adjusted_args.source_id, adjusted_args.sequence_number, |
| 405 state_machine_.last_frame_number_compositor_frame_was_fresh(), 0, |
| 406 false); |
| 407 begin_frame_source_->DidFinishFrame(this, ack); |
| 408 } |
| 396 return; | 409 return; |
| 397 } | 410 } |
| 398 | 411 |
| 399 BeginImplFrame(adjusted_args); | 412 BeginImplFrame(adjusted_args); |
| 400 } | 413 } |
| 401 | 414 |
| 402 void Scheduler::BeginImplFrameSynchronous(const BeginFrameArgs& args) { | 415 void Scheduler::BeginImplFrameSynchronous(const BeginFrameArgs& args) { |
| 403 TRACE_EVENT1("cc,benchmark", "Scheduler::BeginImplFrame", "args", | 416 TRACE_EVENT1("cc,benchmark", "Scheduler::BeginImplFrame", "args", |
| 404 args.AsValue()); | 417 args.AsValue()); |
| 405 | 418 |
| 406 // The main thread currently can't commit before we draw with the | 419 // The main thread currently can't commit before we draw with the |
| 407 // synchronous compositor, so never consider the BeginMainFrame fast. | 420 // synchronous compositor, so never consider the BeginMainFrame fast. |
| 408 state_machine_.SetCriticalBeginMainFrameToActivateIsFast(false); | 421 state_machine_.SetCriticalBeginMainFrameToActivateIsFast(false); |
| 409 begin_main_frame_args_ = args; | 422 begin_main_frame_args_ = args; |
| 410 begin_main_frame_args_.on_critical_path = !ImplLatencyTakesPriority(); | 423 begin_main_frame_args_.on_critical_path = !ImplLatencyTakesPriority(); |
| 411 | 424 |
| 412 BeginImplFrame(args); | 425 BeginImplFrame(args); |
| 413 compositor_timing_history_->WillFinishImplFrame( | 426 compositor_timing_history_->WillFinishImplFrame( |
| 414 state_machine_.needs_redraw()); | 427 state_machine_.needs_redraw()); |
| 415 FinishImplFrame(); | 428 FinishImplFrame(); |
| 416 } | 429 } |
| 417 | 430 |
| 418 void Scheduler::FinishImplFrame() { | 431 void Scheduler::FinishImplFrame() { |
| 419 state_machine_.OnBeginImplFrameIdle(); | 432 state_machine_.OnBeginImplFrameIdle(); |
| 420 ProcessScheduledActions(); | 433 ProcessScheduledActions(); |
| 421 | 434 |
| 422 client_->DidFinishImplFrame(); | 435 client_->DidFinishImplFrame(); |
| 423 if (begin_frame_source_) | 436 if (begin_frame_source_) { |
| 424 begin_frame_source_->DidFinishFrame(this, 0); | 437 BeginFrameAck ack( |
| 438 begin_main_frame_args_.source_id, |
| 439 begin_main_frame_args_.sequence_number, |
| 440 state_machine_.last_frame_number_compositor_frame_was_fresh(), 0, |
| 441 state_machine_.did_submit_in_last_frame()); |
| 442 begin_frame_source_->DidFinishFrame(this, ack); |
| 443 } |
| 425 begin_impl_frame_tracker_.Finish(); | 444 begin_impl_frame_tracker_.Finish(); |
| 426 } | 445 } |
| 427 | 446 |
| 428 // BeginImplFrame starts a compositor frame that will wait up until a deadline | 447 // 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 | 448 // for a BeginMainFrame+activation to complete before it times out and draws |
| 430 // any asynchronous animation and scroll/pinch updates. | 449 // any asynchronous animation and scroll/pinch updates. |
| 431 void Scheduler::BeginImplFrame(const BeginFrameArgs& args) { | 450 void Scheduler::BeginImplFrame(const BeginFrameArgs& args) { |
| 432 DCHECK_EQ(state_machine_.begin_impl_frame_state(), | 451 DCHECK_EQ(state_machine_.begin_impl_frame_state(), |
| 433 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); | 452 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); |
| 434 DCHECK(begin_impl_frame_deadline_task_.IsCancelled()); | 453 DCHECK(begin_impl_frame_deadline_task_.IsCancelled()); |
| 435 DCHECK(state_machine_.HasInitializedCompositorFrameSink()); | 454 DCHECK(state_machine_.HasInitializedCompositorFrameSink()); |
| 436 | 455 |
| 437 begin_impl_frame_tracker_.Start(args); | 456 begin_impl_frame_tracker_.Start(args); |
| 438 state_machine_.OnBeginImplFrame(); | 457 state_machine_.OnBeginImplFrame(args.source_id, args.sequence_number); |
| 439 devtools_instrumentation::DidBeginFrame(layer_tree_host_id_); | 458 devtools_instrumentation::DidBeginFrame(layer_tree_host_id_); |
| 440 compositor_timing_history_->WillBeginImplFrame( | 459 compositor_timing_history_->WillBeginImplFrame( |
| 441 state_machine_.NewActiveTreeLikely()); | 460 state_machine_.NewActiveTreeLikely()); |
| 442 client_->WillBeginImplFrame(begin_impl_frame_tracker_.Current()); | 461 client_->WillBeginImplFrame(begin_impl_frame_tracker_.Current()); |
| 443 | 462 |
| 444 ProcessScheduledActions(); | 463 ProcessScheduledActions(); |
| 445 } | 464 } |
| 446 | 465 |
| 447 void Scheduler::ScheduleBeginImplFrameDeadline() { | 466 void Scheduler::ScheduleBeginImplFrameDeadline() { |
| 448 // The synchronous compositor does not post a deadline task. | 467 // The synchronous compositor does not post a deadline task. |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 750 return estimated_draw_time < args.deadline; | 769 return estimated_draw_time < args.deadline; |
| 751 } | 770 } |
| 752 | 771 |
| 753 bool Scheduler::IsBeginMainFrameSentOrStarted() const { | 772 bool Scheduler::IsBeginMainFrameSentOrStarted() const { |
| 754 return (state_machine_.begin_main_frame_state() == | 773 return (state_machine_.begin_main_frame_state() == |
| 755 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT || | 774 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT || |
| 756 state_machine_.begin_main_frame_state() == | 775 state_machine_.begin_main_frame_state() == |
| 757 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_STARTED); | 776 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_STARTED); |
| 758 } | 777 } |
| 759 | 778 |
| 779 uint64_t Scheduler::CurrentBeginFrameSourceId() { |
| 780 return begin_main_frame_args_.source_id; |
| 781 } |
| 782 |
| 783 uint64_t Scheduler::CurrentBeginFrameNumber() { |
| 784 return begin_main_frame_args_.sequence_number; |
| 785 } |
| 786 |
| 787 uint64_t Scheduler::LatestConfirmedFrameForActiveTree() { |
| 788 return state_machine_.last_frame_number_active_tree_was_fresh(); |
| 789 } |
| 790 |
| 760 } // namespace cc | 791 } // namespace cc |
| OLD | NEW |