Chromium Code Reviews| 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/debug/trace_event_argument.h" | 10 #include "base/debug/trace_event_argument.h" |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 | 110 |
| 111 // Primary frame source | 111 // Primary frame source |
| 112 primary_frame_source_ = | 112 primary_frame_source_ = |
| 113 frame_sources_constructor->ConstructPrimaryFrameSource(this); | 113 frame_sources_constructor->ConstructPrimaryFrameSource(this); |
| 114 frame_source_->AddSource(primary_frame_source_); | 114 frame_source_->AddSource(primary_frame_source_); |
| 115 | 115 |
| 116 // Background ticking frame source | 116 // Background ticking frame source |
| 117 background_frame_source_ = | 117 background_frame_source_ = |
| 118 frame_sources_constructor->ConstructBackgroundFrameSource(this); | 118 frame_sources_constructor->ConstructBackgroundFrameSource(this); |
| 119 frame_source_->AddSource(background_frame_source_); | 119 frame_source_->AddSource(background_frame_source_); |
| 120 | |
| 121 SetupPowerMonitoring(); | |
| 120 } | 122 } |
| 121 | 123 |
| 122 Scheduler::~Scheduler() { | 124 Scheduler::~Scheduler() { |
| 125 TeardownPowerMonitoring(); | |
| 123 } | 126 } |
| 124 | 127 |
| 125 base::TimeTicks Scheduler::Now() const { | 128 base::TimeTicks Scheduler::Now() const { |
| 126 base::TimeTicks now = gfx::FrameTime::Now(); | 129 base::TimeTicks now = gfx::FrameTime::Now(); |
| 127 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.now"), | 130 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.now"), |
| 128 "Scheduler::Now", | 131 "Scheduler::Now", |
| 129 "now", | 132 "now", |
| 130 now); | 133 now); |
| 131 return now; | 134 return now; |
| 132 } | 135 } |
| 133 | 136 |
| 137 void Scheduler::SetupPowerMonitoring() { | |
| 138 if (settings_.prioritize_impl_latency_on_battery) { | |
| 139 base::PowerMonitor* power_monitor = client_->PowerMonitor(); | |
| 140 DCHECK(power_monitor); | |
| 141 power_monitor->AddObserver(this); | |
| 142 state_machine_.SetImplLatencyTakesPriorityOnBattery( | |
| 143 power_monitor->IsOnBatteryPower()); | |
| 144 } | |
| 145 } | |
| 146 | |
| 147 void Scheduler::TeardownPowerMonitoring() { | |
| 148 if (settings_.prioritize_impl_latency_on_battery) { | |
| 149 base::PowerMonitor* power_monitor = client_->PowerMonitor(); | |
| 150 DCHECK(power_monitor); | |
| 151 power_monitor->RemoveObserver(this); | |
| 152 } | |
| 153 } | |
| 154 | |
| 155 void Scheduler::OnPowerStateChange(bool on_battery_power) { | |
| 156 DCHECK(settings_.prioritize_impl_latency_on_battery); | |
| 157 state_machine_.SetImplLatencyTakesPriorityOnBattery(on_battery_power); | |
| 158 } | |
| 159 | |
| 134 void Scheduler::CommitVSyncParameters(base::TimeTicks timebase, | 160 void Scheduler::CommitVSyncParameters(base::TimeTicks timebase, |
| 135 base::TimeDelta interval) { | 161 base::TimeDelta interval) { |
| 136 // TODO(brianderson): We should not be receiving 0 intervals. | 162 // TODO(brianderson): We should not be receiving 0 intervals. |
| 137 if (interval == base::TimeDelta()) | 163 if (interval == base::TimeDelta()) |
| 138 interval = BeginFrameArgs::DefaultInterval(); | 164 interval = BeginFrameArgs::DefaultInterval(); |
| 139 | 165 |
| 140 if (vsync_observer_) | 166 if (vsync_observer_) |
| 141 vsync_observer_->OnUpdateVSyncParameters(timebase, interval); | 167 vsync_observer_->OnUpdateVSyncParameters(timebase, interval); |
| 142 } | 168 } |
| 143 | 169 |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 482 "args", | 508 "args", |
| 483 args.AsValue(), | 509 args.AsValue(), |
| 484 "main_thread_is_high_latency", | 510 "main_thread_is_high_latency", |
| 485 main_thread_is_in_high_latency_mode); | 511 main_thread_is_in_high_latency_mode); |
| 486 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), | 512 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), |
| 487 "MainThreadLatency", | 513 "MainThreadLatency", |
| 488 main_thread_is_in_high_latency_mode); | 514 main_thread_is_in_high_latency_mode); |
| 489 DCHECK_EQ(state_machine_.begin_impl_frame_state(), | 515 DCHECK_EQ(state_machine_.begin_impl_frame_state(), |
| 490 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); | 516 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); |
| 491 DCHECK(state_machine_.HasInitializedOutputSurface()); | 517 DCHECK(state_machine_.HasInitializedOutputSurface()); |
| 518 DCHECK(begin_impl_frame_deadline_task_.IsCancelled()); | |
|
sunnyps
2014/10/13 23:59:43
Will revert this too as it's not related to this c
| |
| 492 | 519 |
| 493 advance_commit_state_task_.Cancel(); | 520 advance_commit_state_task_.Cancel(); |
| 494 | 521 |
| 495 base::TimeDelta draw_duration_estimate = client_->DrawDurationEstimate(); | 522 base::TimeDelta draw_duration_estimate = client_->DrawDurationEstimate(); |
| 496 begin_impl_frame_args_ = args; | 523 begin_impl_frame_args_ = args; |
| 497 begin_impl_frame_args_.deadline -= draw_duration_estimate; | 524 begin_impl_frame_args_.deadline -= draw_duration_estimate; |
| 498 | 525 |
| 499 if (!state_machine_.impl_latency_takes_priority() && | 526 if (!state_machine_.impl_latency_takes_priority() && |
| 500 main_thread_is_in_high_latency_mode && | 527 main_thread_is_in_high_latency_mode && |
| 501 CanCommitAndActivateBeforeDeadline()) { | 528 CanCommitAndActivateBeforeDeadline()) { |
| 502 state_machine_.SetSkipNextBeginMainFrameToReduceLatency(); | 529 state_machine_.SetSkipNextBeginMainFrameToReduceLatency(); |
| 503 } | 530 } |
| 504 | 531 |
| 505 client_->WillBeginImplFrame(begin_impl_frame_args_); | 532 client_->WillBeginImplFrame(begin_impl_frame_args_); |
| 506 state_machine_.OnBeginImplFrame(begin_impl_frame_args_); | 533 state_machine_.OnBeginImplFrame(begin_impl_frame_args_); |
| 507 devtools_instrumentation::DidBeginFrame(layer_tree_host_id_); | 534 devtools_instrumentation::DidBeginFrame(layer_tree_host_id_); |
| 508 | 535 |
| 509 ProcessScheduledActions(); | 536 ProcessScheduledActions(); |
| 510 | 537 |
| 511 state_machine_.OnBeginImplFrameDeadlinePending(); | 538 state_machine_.OnBeginImplFrameDeadlinePending(); |
| 512 ScheduleBeginImplFrameDeadline( | 539 |
| 513 AdjustedBeginImplFrameDeadline(args, draw_duration_estimate)); | 540 if (!settings_.using_synchronous_renderer_compositor) { |
| 541 ScheduleBeginImplFrameDeadline( | |
| 542 AdjustedBeginImplFrameDeadline(args, draw_duration_estimate)); | |
| 543 } else { | |
| 544 OnBeginImplFrameDeadline(); | |
| 545 } | |
| 514 } | 546 } |
| 515 | 547 |
| 516 base::TimeTicks Scheduler::AdjustedBeginImplFrameDeadline( | 548 base::TimeTicks Scheduler::AdjustedBeginImplFrameDeadline( |
| 517 const BeginFrameArgs& args, | 549 const BeginFrameArgs& args, |
| 518 base::TimeDelta draw_duration_estimate) const { | 550 base::TimeDelta draw_duration_estimate) const { |
| 519 if (settings_.using_synchronous_renderer_compositor) { | 551 if (settings_.using_synchronous_renderer_compositor) { |
| 520 // The synchronous compositor needs to draw right away. | |
|
mithro-old
2014/10/13 23:25:57
Is this being removed in your CL, or was this remo
sunnyps
2014/10/13 23:59:43
I'll revert this and other changes around here tha
| |
| 521 return base::TimeTicks(); | 552 return base::TimeTicks(); |
| 522 } else if (state_machine_.ShouldTriggerBeginImplFrameDeadlineEarly()) { | 553 } else if (state_machine_.ShouldTriggerBeginImplFrameDeadlineEarly()) { |
| 523 // We are ready to draw a new active tree immediately. | 554 // We are ready to draw a new active tree immediately. |
| 524 return base::TimeTicks(); | 555 return base::TimeTicks(); |
| 525 } else if (state_machine_.needs_redraw()) { | 556 } else if (state_machine_.needs_redraw()) { |
| 526 // We have an animation or fast input path on the impl thread that wants | 557 // We have an animation or fast input path on the impl thread that wants |
| 527 // to draw, so don't wait too long for a new active tree. | 558 // to draw, so don't wait too long for a new active tree. |
| 528 return args.deadline - draw_duration_estimate; | 559 return args.deadline - draw_duration_estimate; |
| 529 } else { | 560 } else { |
| 530 // The impl thread doesn't have anything it wants to draw and we are just | 561 // The impl thread doesn't have anything it wants to draw and we are just |
| 531 // waiting for a new active tree, so post the deadline for the next | 562 // waiting for a new active tree, so post the deadline for the next |
| 532 // expected BeginImplFrame start. This allows us to draw immediately when | 563 // expected BeginImplFrame start. This allows us to draw immediately when |
| 533 // there is a new active tree, instead of waiting for the next | 564 // there is a new active tree, instead of waiting for the next |
| 534 // BeginImplFrame. | 565 // BeginImplFrame. |
| 535 // TODO(brianderson): Handle long deadlines (that are past the next frame's | 566 // TODO(brianderson): Handle long deadlines (that are past the next frame's |
| 536 // frame time) properly instead of using this hack. | 567 // frame time) properly instead of using this hack. |
| 537 return args.frame_time + args.interval; | 568 return args.frame_time + args.interval; |
| 538 } | 569 } |
| 539 } | 570 } |
| 540 | 571 |
| 541 void Scheduler::ScheduleBeginImplFrameDeadline(base::TimeTicks deadline) { | 572 void Scheduler::ScheduleBeginImplFrameDeadline(base::TimeTicks deadline) { |
| 542 TRACE_EVENT1( | 573 TRACE_EVENT1( |
| 543 "cc", "Scheduler::ScheduleBeginImplFrameDeadline", "deadline", deadline); | 574 "cc", "Scheduler::ScheduleBeginImplFrameDeadline", "deadline", deadline); |
| 544 if (settings_.using_synchronous_renderer_compositor) { | |
|
mithro-old
2014/10/13 23:25:57
Is this being removed in your CL, or was this remo
sunnyps
2014/10/13 23:59:43
Will revert this part.
| |
| 545 // The synchronous renderer compositor has to make its GL calls | |
| 546 // within this call. | |
| 547 // TODO(brianderson): Have the OutputSurface initiate the deadline tasks | |
| 548 // so the sychronous renderer compositor can take advantage of splitting | |
| 549 // up the BeginImplFrame and deadline as well. | |
| 550 OnBeginImplFrameDeadline(); | |
| 551 return; | |
| 552 } | |
| 553 begin_impl_frame_deadline_task_.Cancel(); | 575 begin_impl_frame_deadline_task_.Cancel(); |
| 554 begin_impl_frame_deadline_task_.Reset(begin_impl_frame_deadline_closure_); | 576 begin_impl_frame_deadline_task_.Reset(begin_impl_frame_deadline_closure_); |
| 555 | 577 |
| 556 base::TimeDelta delta = deadline - Now(); | 578 base::TimeDelta delta = deadline - Now(); |
| 557 if (delta <= base::TimeDelta()) | 579 if (delta <= base::TimeDelta()) |
| 558 delta = base::TimeDelta(); | 580 delta = base::TimeDelta(); |
| 559 task_runner_->PostDelayedTask( | 581 task_runner_->PostDelayedTask( |
| 560 FROM_HERE, begin_impl_frame_deadline_task_.callback(), delta); | 582 FROM_HERE, begin_impl_frame_deadline_task_.callback(), delta); |
| 561 } | 583 } |
| 562 | 584 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 739 } | 761 } |
| 740 | 762 |
| 741 bool Scheduler::IsBeginMainFrameSentOrStarted() const { | 763 bool Scheduler::IsBeginMainFrameSentOrStarted() const { |
| 742 return (state_machine_.commit_state() == | 764 return (state_machine_.commit_state() == |
| 743 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT || | 765 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT || |
| 744 state_machine_.commit_state() == | 766 state_machine_.commit_state() == |
| 745 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED); | 767 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED); |
| 746 } | 768 } |
| 747 | 769 |
| 748 } // namespace cc | 770 } // namespace cc |
| OLD | NEW |