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 base::PowerMonitor* power_monitor = client_->PowerMonitor(); | |
139 DCHECK_IMPLIES(settings_.prioritize_impl_latency_on_battery, | |
140 power_monitor != NULL); | |
danakj
2014/10/09 21:18:02
!= NULL is redundant here and below
sunnyps
2014/10/09 22:04:39
I don't think it is. The tests which deal the sche
danakj
2014/10/09 22:08:27
Sorry, what I meant is if (a != NULL) is more simp
| |
141 if (power_monitor != NULL) { | |
142 power_monitor->AddObserver(this); | |
143 state_machine_.SetOnBatteryPower(power_monitor->IsOnBatteryPower()); | |
144 } | |
145 } | |
146 | |
147 void Scheduler::TeardownPowerMonitoring() { | |
148 base::PowerMonitor* power_monitor = client_->PowerMonitor(); | |
149 if (power_monitor != NULL) { | |
150 power_monitor->RemoveObserver(this); | |
151 } | |
152 } | |
153 | |
154 void Scheduler::OnPowerStateChange(bool on_battery_power) { | |
155 state_machine_.SetOnBatteryPower(on_battery_power); | |
156 } | |
157 | |
134 void Scheduler::CommitVSyncParameters(base::TimeTicks timebase, | 158 void Scheduler::CommitVSyncParameters(base::TimeTicks timebase, |
135 base::TimeDelta interval) { | 159 base::TimeDelta interval) { |
136 // TODO(brianderson): We should not be receiving 0 intervals. | 160 // TODO(brianderson): We should not be receiving 0 intervals. |
137 if (interval == base::TimeDelta()) | 161 if (interval == base::TimeDelta()) |
138 interval = BeginFrameArgs::DefaultInterval(); | 162 interval = BeginFrameArgs::DefaultInterval(); |
139 | 163 |
140 if (vsync_observer_) | 164 if (vsync_observer_) |
141 vsync_observer_->OnUpdateVSyncParameters(timebase, interval); | 165 vsync_observer_->OnUpdateVSyncParameters(timebase, interval); |
142 } | 166 } |
143 | 167 |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
482 "args", | 506 "args", |
483 args.AsValue(), | 507 args.AsValue(), |
484 "main_thread_is_high_latency", | 508 "main_thread_is_high_latency", |
485 main_thread_is_in_high_latency_mode); | 509 main_thread_is_in_high_latency_mode); |
486 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), | 510 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), |
487 "MainThreadLatency", | 511 "MainThreadLatency", |
488 main_thread_is_in_high_latency_mode); | 512 main_thread_is_in_high_latency_mode); |
489 DCHECK_EQ(state_machine_.begin_impl_frame_state(), | 513 DCHECK_EQ(state_machine_.begin_impl_frame_state(), |
490 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); | 514 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); |
491 DCHECK(state_machine_.HasInitializedOutputSurface()); | 515 DCHECK(state_machine_.HasInitializedOutputSurface()); |
516 DCHECK(begin_impl_frame_deadline_task_.IsCancelled()); | |
492 | 517 |
493 advance_commit_state_task_.Cancel(); | 518 advance_commit_state_task_.Cancel(); |
494 | 519 |
495 base::TimeDelta draw_duration_estimate = client_->DrawDurationEstimate(); | 520 base::TimeDelta draw_duration_estimate = client_->DrawDurationEstimate(); |
496 begin_impl_frame_args_ = args; | 521 begin_impl_frame_args_ = args; |
497 begin_impl_frame_args_.deadline -= draw_duration_estimate; | 522 begin_impl_frame_args_.deadline -= draw_duration_estimate; |
498 | 523 |
499 if (!state_machine_.impl_latency_takes_priority() && | 524 if (!state_machine_.impl_latency_takes_priority() && |
500 main_thread_is_in_high_latency_mode && | 525 main_thread_is_in_high_latency_mode && |
501 CanCommitAndActivateBeforeDeadline()) { | 526 CanCommitAndActivateBeforeDeadline()) { |
502 state_machine_.SetSkipNextBeginMainFrameToReduceLatency(); | 527 state_machine_.SetSkipNextBeginMainFrameToReduceLatency(); |
503 } | 528 } |
504 | 529 |
505 client_->WillBeginImplFrame(begin_impl_frame_args_); | 530 client_->WillBeginImplFrame(begin_impl_frame_args_); |
506 state_machine_.OnBeginImplFrame(begin_impl_frame_args_); | 531 state_machine_.OnBeginImplFrame(begin_impl_frame_args_); |
507 devtools_instrumentation::DidBeginFrame(layer_tree_host_id_); | 532 devtools_instrumentation::DidBeginFrame(layer_tree_host_id_); |
508 | 533 |
509 ProcessScheduledActions(); | 534 ProcessScheduledActions(); |
510 | 535 |
511 state_machine_.OnBeginImplFrameDeadlinePending(); | 536 state_machine_.OnBeginImplFrameDeadlinePending(); |
512 ScheduleBeginImplFrameDeadline( | 537 |
513 AdjustedBeginImplFrameDeadline(args, draw_duration_estimate)); | 538 if (!settings_.using_synchronous_renderer_compositor) { |
539 ScheduleBeginImplFrameDeadline( | |
540 AdjustedBeginImplFrameDeadline(args, draw_duration_estimate)); | |
541 } else { | |
542 OnBeginImplFrameDeadline(); | |
543 } | |
514 } | 544 } |
515 | 545 |
516 base::TimeTicks Scheduler::AdjustedBeginImplFrameDeadline( | 546 base::TimeTicks Scheduler::AdjustedBeginImplFrameDeadline( |
517 const BeginFrameArgs& args, | 547 const BeginFrameArgs& args, |
518 base::TimeDelta draw_duration_estimate) const { | 548 base::TimeDelta draw_duration_estimate) const { |
519 if (settings_.using_synchronous_renderer_compositor) { | 549 if (settings_.using_synchronous_renderer_compositor) { |
520 // The synchronous compositor needs to draw right away. | |
521 return base::TimeTicks(); | 550 return base::TimeTicks(); |
522 } else if (state_machine_.ShouldTriggerBeginImplFrameDeadlineEarly()) { | 551 } else if (state_machine_.ShouldTriggerBeginImplFrameDeadlineEarly()) { |
523 // We are ready to draw a new active tree immediately. | 552 // We are ready to draw a new active tree immediately. |
524 return base::TimeTicks(); | 553 return base::TimeTicks(); |
525 } else if (state_machine_.needs_redraw()) { | 554 } else if (state_machine_.needs_redraw()) { |
526 // We have an animation or fast input path on the impl thread that wants | 555 // 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. | 556 // to draw, so don't wait too long for a new active tree. |
528 return args.deadline - draw_duration_estimate; | 557 return args.deadline - draw_duration_estimate; |
529 } else { | 558 } else { |
530 // The impl thread doesn't have anything it wants to draw and we are just | 559 // 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 | 560 // waiting for a new active tree, so post the deadline for the next |
532 // expected BeginImplFrame start. This allows us to draw immediately when | 561 // expected BeginImplFrame start. This allows us to draw immediately when |
533 // there is a new active tree, instead of waiting for the next | 562 // there is a new active tree, instead of waiting for the next |
534 // BeginImplFrame. | 563 // BeginImplFrame. |
535 // TODO(brianderson): Handle long deadlines (that are past the next frame's | 564 // TODO(brianderson): Handle long deadlines (that are past the next frame's |
536 // frame time) properly instead of using this hack. | 565 // frame time) properly instead of using this hack. |
537 return args.frame_time + args.interval; | 566 return args.frame_time + args.interval; |
538 } | 567 } |
539 } | 568 } |
540 | 569 |
541 void Scheduler::ScheduleBeginImplFrameDeadline(base::TimeTicks deadline) { | 570 void Scheduler::ScheduleBeginImplFrameDeadline(base::TimeTicks deadline) { |
542 TRACE_EVENT1( | 571 TRACE_EVENT1( |
543 "cc", "Scheduler::ScheduleBeginImplFrameDeadline", "deadline", deadline); | 572 "cc", "Scheduler::ScheduleBeginImplFrameDeadline", "deadline", deadline); |
544 if (settings_.using_synchronous_renderer_compositor) { | |
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(); | 573 begin_impl_frame_deadline_task_.Cancel(); |
554 begin_impl_frame_deadline_task_.Reset(begin_impl_frame_deadline_closure_); | 574 begin_impl_frame_deadline_task_.Reset(begin_impl_frame_deadline_closure_); |
555 | 575 |
556 base::TimeDelta delta = deadline - Now(); | 576 base::TimeDelta delta = deadline - Now(); |
557 if (delta <= base::TimeDelta()) | 577 if (delta <= base::TimeDelta()) |
558 delta = base::TimeDelta(); | 578 delta = base::TimeDelta(); |
559 task_runner_->PostDelayedTask( | 579 task_runner_->PostDelayedTask( |
560 FROM_HERE, begin_impl_frame_deadline_task_.callback(), delta); | 580 FROM_HERE, begin_impl_frame_deadline_task_.callback(), delta); |
561 } | 581 } |
562 | 582 |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
739 } | 759 } |
740 | 760 |
741 bool Scheduler::IsBeginMainFrameSentOrStarted() const { | 761 bool Scheduler::IsBeginMainFrameSentOrStarted() const { |
742 return (state_machine_.commit_state() == | 762 return (state_machine_.commit_state() == |
743 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT || | 763 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT || |
744 state_machine_.commit_state() == | 764 state_machine_.commit_state() == |
745 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED); | 765 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED); |
746 } | 766 } |
747 | 767 |
748 } // namespace cc | 768 } // namespace cc |
OLD | NEW |