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" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/power_monitor/power_monitor.h" | |
12 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
13 #include "cc/debug/devtools_instrumentation.h" | 14 #include "cc/debug/devtools_instrumentation.h" |
14 #include "cc/debug/traced_value.h" | 15 #include "cc/debug/traced_value.h" |
15 #include "cc/scheduler/delay_based_time_source.h" | 16 #include "cc/scheduler/delay_based_time_source.h" |
16 #include "ui/gfx/frame_time.h" | 17 #include "ui/gfx/frame_time.h" |
17 | 18 |
18 namespace cc { | 19 namespace cc { |
19 | 20 |
20 BeginFrameSource* SchedulerFrameSourcesConstructor::ConstructPrimaryFrameSource( | 21 BeginFrameSource* SchedulerFrameSourcesConstructor::ConstructPrimaryFrameSource( |
21 Scheduler* scheduler) { | 22 Scheduler* scheduler) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 base::TimeDelta::FromSeconds(1)); | 68 base::TimeDelta::FromSeconds(1)); |
68 return scheduler->background_frame_source_internal_.get(); | 69 return scheduler->background_frame_source_internal_.get(); |
69 } | 70 } |
70 | 71 |
71 Scheduler::Scheduler( | 72 Scheduler::Scheduler( |
72 SchedulerClient* client, | 73 SchedulerClient* client, |
73 const SchedulerSettings& scheduler_settings, | 74 const SchedulerSettings& scheduler_settings, |
74 int layer_tree_host_id, | 75 int layer_tree_host_id, |
75 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 76 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
76 SchedulerFrameSourcesConstructor* frame_sources_constructor) | 77 SchedulerFrameSourcesConstructor* frame_sources_constructor) |
77 : frame_source_(), | 78 : frame_source_(), |
danakj
2014/10/09 17:04:01
initialize your new bool to false
sunnyps
2014/10/09 21:03:38
Done.
| |
78 primary_frame_source_(NULL), | 79 primary_frame_source_(NULL), |
79 background_frame_source_(NULL), | 80 background_frame_source_(NULL), |
80 primary_frame_source_internal_(), | 81 primary_frame_source_internal_(), |
81 background_frame_source_internal_(), | 82 background_frame_source_internal_(), |
82 vsync_observer_(NULL), | 83 vsync_observer_(NULL), |
83 settings_(scheduler_settings), | 84 settings_(scheduler_settings), |
84 client_(client), | 85 client_(client), |
85 layer_tree_host_id_(layer_tree_host_id), | 86 layer_tree_host_id_(layer_tree_host_id), |
86 task_runner_(task_runner), | 87 task_runner_(task_runner), |
87 begin_retro_frame_posted_(false), | 88 begin_retro_frame_posted_(false), |
(...skipping 22 matching lines...) Expand all Loading... | |
110 | 111 |
111 // Primary frame source | 112 // Primary frame source |
112 primary_frame_source_ = | 113 primary_frame_source_ = |
113 frame_sources_constructor->ConstructPrimaryFrameSource(this); | 114 frame_sources_constructor->ConstructPrimaryFrameSource(this); |
114 frame_source_->AddSource(primary_frame_source_); | 115 frame_source_->AddSource(primary_frame_source_); |
115 | 116 |
116 // Background ticking frame source | 117 // Background ticking frame source |
117 background_frame_source_ = | 118 background_frame_source_ = |
118 frame_sources_constructor->ConstructBackgroundFrameSource(this); | 119 frame_sources_constructor->ConstructBackgroundFrameSource(this); |
119 frame_source_->AddSource(background_frame_source_); | 120 frame_source_->AddSource(background_frame_source_); |
121 | |
122 if (settings_.prioritize_impl_latency_on_battery) { | |
123 SetupPowerMonitoring(); | |
124 } | |
120 } | 125 } |
121 | 126 |
122 Scheduler::~Scheduler() { | 127 Scheduler::~Scheduler() { |
128 if (settings_.prioritize_impl_latency_on_battery) { | |
129 TeardownPowerMonitoring(); | |
130 } | |
123 } | 131 } |
124 | 132 |
125 base::TimeTicks Scheduler::Now() const { | 133 base::TimeTicks Scheduler::Now() const { |
126 base::TimeTicks now = gfx::FrameTime::Now(); | 134 base::TimeTicks now = gfx::FrameTime::Now(); |
127 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.now"), | 135 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.now"), |
128 "Scheduler::Now", | 136 "Scheduler::Now", |
129 "now", | 137 "now", |
130 now); | 138 now); |
131 return now; | 139 return now; |
132 } | 140 } |
133 | 141 |
142 void Scheduler::SetupPowerMonitoring() { | |
143 base::PowerMonitor* power_monitor = base::PowerMonitor::Get(); | |
144 DCHECK(power_monitor != NULL); | |
145 power_monitor->AddObserver(this); | |
146 on_battery_power_ = power_monitor->IsOnBatteryPower(); | |
147 } | |
148 | |
149 void Scheduler::TeardownPowerMonitoring() { | |
150 base::PowerMonitor* power_monitor = base::PowerMonitor::Get(); | |
151 DCHECK(power_monitor != NULL); | |
152 power_monitor->RemoveObserver(this); | |
153 } | |
154 | |
155 void Scheduler::OnPowerStateChange(bool on_battery_power) { | |
156 on_battery_power_ = on_battery_power; | |
157 } | |
158 | |
134 void Scheduler::CommitVSyncParameters(base::TimeTicks timebase, | 159 void Scheduler::CommitVSyncParameters(base::TimeTicks timebase, |
135 base::TimeDelta interval) { | 160 base::TimeDelta interval) { |
136 // TODO(brianderson): We should not be receiving 0 intervals. | 161 // TODO(brianderson): We should not be receiving 0 intervals. |
137 if (interval == base::TimeDelta()) | 162 if (interval == base::TimeDelta()) |
138 interval = BeginFrameArgs::DefaultInterval(); | 163 interval = BeginFrameArgs::DefaultInterval(); |
139 | 164 |
140 if (vsync_observer_) | 165 if (vsync_observer_) |
141 vsync_observer_->OnUpdateVSyncParameters(timebase, interval); | 166 vsync_observer_->OnUpdateVSyncParameters(timebase, interval); |
142 } | 167 } |
143 | 168 |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
482 "args", | 507 "args", |
483 args.AsValue(), | 508 args.AsValue(), |
484 "main_thread_is_high_latency", | 509 "main_thread_is_high_latency", |
485 main_thread_is_in_high_latency_mode); | 510 main_thread_is_in_high_latency_mode); |
486 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), | 511 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), |
487 "MainThreadLatency", | 512 "MainThreadLatency", |
488 main_thread_is_in_high_latency_mode); | 513 main_thread_is_in_high_latency_mode); |
489 DCHECK_EQ(state_machine_.begin_impl_frame_state(), | 514 DCHECK_EQ(state_machine_.begin_impl_frame_state(), |
490 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); | 515 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); |
491 DCHECK(state_machine_.HasInitializedOutputSurface()); | 516 DCHECK(state_machine_.HasInitializedOutputSurface()); |
517 DCHECK(begin_impl_frame_deadline_task_.IsCancelled()); | |
492 | 518 |
493 advance_commit_state_task_.Cancel(); | 519 advance_commit_state_task_.Cancel(); |
494 | 520 |
495 base::TimeDelta draw_duration_estimate = client_->DrawDurationEstimate(); | 521 base::TimeDelta draw_duration_estimate = client_->DrawDurationEstimate(); |
496 begin_impl_frame_args_ = args; | 522 begin_impl_frame_args_ = args; |
497 begin_impl_frame_args_.deadline -= draw_duration_estimate; | 523 begin_impl_frame_args_.deadline -= draw_duration_estimate; |
498 | 524 |
499 if (!state_machine_.impl_latency_takes_priority() && | 525 if (!state_machine_.impl_latency_takes_priority() && |
500 main_thread_is_in_high_latency_mode && | 526 main_thread_is_in_high_latency_mode && |
501 CanCommitAndActivateBeforeDeadline()) { | 527 CanCommitAndActivateBeforeDeadline()) { |
502 state_machine_.SetSkipNextBeginMainFrameToReduceLatency(); | 528 state_machine_.SetSkipNextBeginMainFrameToReduceLatency(); |
503 } | 529 } |
504 | 530 |
505 client_->WillBeginImplFrame(begin_impl_frame_args_); | 531 client_->WillBeginImplFrame(begin_impl_frame_args_); |
506 state_machine_.OnBeginImplFrame(begin_impl_frame_args_); | 532 state_machine_.OnBeginImplFrame(begin_impl_frame_args_); |
507 devtools_instrumentation::DidBeginFrame(layer_tree_host_id_); | 533 devtools_instrumentation::DidBeginFrame(layer_tree_host_id_); |
508 | 534 |
509 ProcessScheduledActions(); | 535 ProcessScheduledActions(); |
510 | 536 |
511 state_machine_.OnBeginImplFrameDeadlinePending(); | 537 state_machine_.OnBeginImplFrameDeadlinePending(); |
512 ScheduleBeginImplFrameDeadline( | 538 |
513 AdjustedBeginImplFrameDeadline(args, draw_duration_estimate)); | 539 if (!settings_.using_synchronous_renderer_compositor) { |
540 ScheduleBeginImplFrameDeadline( | |
541 AdjustedBeginImplFrameDeadline(args, draw_duration_estimate)); | |
542 } else { | |
543 OnBeginImplFrameDeadline(); | |
544 } | |
514 } | 545 } |
515 | 546 |
516 base::TimeTicks Scheduler::AdjustedBeginImplFrameDeadline( | 547 base::TimeTicks Scheduler::AdjustedBeginImplFrameDeadline( |
517 const BeginFrameArgs& args, | 548 const BeginFrameArgs& args, |
518 base::TimeDelta draw_duration_estimate) const { | 549 base::TimeDelta draw_duration_estimate) const { |
519 if (settings_.using_synchronous_renderer_compositor) { | 550 if (settings_.using_synchronous_renderer_compositor) { |
520 // The synchronous compositor needs to draw right away. | 551 return base::TimeTicks(); |
552 } else if (settings_.prioritize_impl_latency_on_battery && | |
danakj
2014/10/09 17:04:01
just if (on_battery_power_) should be enough?
| |
553 on_battery_power_) { | |
521 return base::TimeTicks(); | 554 return base::TimeTicks(); |
522 } else if (state_machine_.ShouldTriggerBeginImplFrameDeadlineEarly()) { | 555 } else if (state_machine_.ShouldTriggerBeginImplFrameDeadlineEarly()) { |
523 // We are ready to draw a new active tree immediately. | 556 // We are ready to draw a new active tree immediately. |
524 return base::TimeTicks(); | 557 return base::TimeTicks(); |
525 } else if (state_machine_.needs_redraw()) { | 558 } else if (state_machine_.needs_redraw()) { |
526 // We have an animation or fast input path on the impl thread that wants | 559 // 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. | 560 // to draw, so don't wait too long for a new active tree. |
528 return args.deadline - draw_duration_estimate; | 561 return args.deadline - draw_duration_estimate; |
529 } else { | 562 } else { |
530 // The impl thread doesn't have anything it wants to draw and we are just | 563 // 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 | 564 // waiting for a new active tree, so post the deadline for the next |
532 // expected BeginImplFrame start. This allows us to draw immediately when | 565 // expected BeginImplFrame start. This allows us to draw immediately when |
533 // there is a new active tree, instead of waiting for the next | 566 // there is a new active tree, instead of waiting for the next |
534 // BeginImplFrame. | 567 // BeginImplFrame. |
535 // TODO(brianderson): Handle long deadlines (that are past the next frame's | 568 // TODO(brianderson): Handle long deadlines (that are past the next frame's |
536 // frame time) properly instead of using this hack. | 569 // frame time) properly instead of using this hack. |
537 return args.frame_time + args.interval; | 570 return args.frame_time + args.interval; |
538 } | 571 } |
539 } | 572 } |
540 | 573 |
541 void Scheduler::ScheduleBeginImplFrameDeadline(base::TimeTicks deadline) { | 574 void Scheduler::ScheduleBeginImplFrameDeadline(base::TimeTicks deadline) { |
542 TRACE_EVENT1( | 575 TRACE_EVENT1( |
543 "cc", "Scheduler::ScheduleBeginImplFrameDeadline", "deadline", deadline); | 576 "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(); | 577 begin_impl_frame_deadline_task_.Cancel(); |
554 begin_impl_frame_deadline_task_.Reset(begin_impl_frame_deadline_closure_); | 578 begin_impl_frame_deadline_task_.Reset(begin_impl_frame_deadline_closure_); |
555 | 579 |
556 base::TimeDelta delta = deadline - Now(); | 580 base::TimeDelta delta = deadline - Now(); |
557 if (delta <= base::TimeDelta()) | 581 if (delta <= base::TimeDelta()) |
558 delta = base::TimeDelta(); | 582 delta = base::TimeDelta(); |
559 task_runner_->PostDelayedTask( | 583 task_runner_->PostDelayedTask( |
560 FROM_HERE, begin_impl_frame_deadline_task_.callback(), delta); | 584 FROM_HERE, begin_impl_frame_deadline_task_.callback(), delta); |
561 } | 585 } |
562 | 586 |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
694 state->SetBoolean("last_set_needs_begin_frame_", | 718 state->SetBoolean("last_set_needs_begin_frame_", |
695 frame_source_->NeedsBeginFrames()); | 719 frame_source_->NeedsBeginFrames()); |
696 state->SetBoolean("begin_retro_frame_posted_", begin_retro_frame_posted_); | 720 state->SetBoolean("begin_retro_frame_posted_", begin_retro_frame_posted_); |
697 state->SetInteger("begin_retro_frame_args_", begin_retro_frame_args_.size()); | 721 state->SetInteger("begin_retro_frame_args_", begin_retro_frame_args_.size()); |
698 state->SetBoolean("begin_impl_frame_deadline_task_", | 722 state->SetBoolean("begin_impl_frame_deadline_task_", |
699 !begin_impl_frame_deadline_task_.IsCancelled()); | 723 !begin_impl_frame_deadline_task_.IsCancelled()); |
700 state->SetBoolean("poll_for_draw_triggers_task_", | 724 state->SetBoolean("poll_for_draw_triggers_task_", |
701 !poll_for_draw_triggers_task_.IsCancelled()); | 725 !poll_for_draw_triggers_task_.IsCancelled()); |
702 state->SetBoolean("advance_commit_state_task_", | 726 state->SetBoolean("advance_commit_state_task_", |
703 !advance_commit_state_task_.IsCancelled()); | 727 !advance_commit_state_task_.IsCancelled()); |
728 if (settings_.prioritize_impl_latency_on_battery) { | |
729 state->SetBoolean("on_battery_power_", on_battery_power_); | |
730 } | |
704 state->BeginDictionary("begin_impl_frame_args"); | 731 state->BeginDictionary("begin_impl_frame_args"); |
705 begin_impl_frame_args_.AsValueInto(state); | 732 begin_impl_frame_args_.AsValueInto(state); |
706 state->EndDictionary(); | 733 state->EndDictionary(); |
707 | 734 |
708 state->EndDictionary(); | 735 state->EndDictionary(); |
709 | 736 |
710 state->BeginDictionary("client_state"); | 737 state->BeginDictionary("client_state"); |
711 state->SetDouble("draw_duration_estimate_ms", | 738 state->SetDouble("draw_duration_estimate_ms", |
712 client_->DrawDurationEstimate().InMillisecondsF()); | 739 client_->DrawDurationEstimate().InMillisecondsF()); |
713 state->SetDouble( | 740 state->SetDouble( |
(...skipping 25 matching lines...) Expand all Loading... | |
739 } | 766 } |
740 | 767 |
741 bool Scheduler::IsBeginMainFrameSentOrStarted() const { | 768 bool Scheduler::IsBeginMainFrameSentOrStarted() const { |
742 return (state_machine_.commit_state() == | 769 return (state_machine_.commit_state() == |
743 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT || | 770 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT || |
744 state_machine_.commit_state() == | 771 state_machine_.commit_state() == |
745 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED); | 772 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED); |
746 } | 773 } |
747 | 774 |
748 } // namespace cc | 775 } // namespace cc |
OLD | NEW |