| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 scoped_ptr<CompositorTimingHistory> compositor_timing_history) | 57 scoped_ptr<CompositorTimingHistory> compositor_timing_history) |
| 58 : settings_(settings), | 58 : settings_(settings), |
| 59 client_(client), | 59 client_(client), |
| 60 layer_tree_host_id_(layer_tree_host_id), | 60 layer_tree_host_id_(layer_tree_host_id), |
| 61 task_runner_(task_runner), | 61 task_runner_(task_runner), |
| 62 external_frame_source_(external_frame_source), | 62 external_frame_source_(external_frame_source), |
| 63 synthetic_frame_source_(std::move(synthetic_frame_source)), | 63 synthetic_frame_source_(std::move(synthetic_frame_source)), |
| 64 unthrottled_frame_source_(std::move(unthrottled_frame_source)), | 64 unthrottled_frame_source_(std::move(unthrottled_frame_source)), |
| 65 frame_source_(BeginFrameSourceMultiplexer::Create()), | 65 frame_source_(BeginFrameSourceMultiplexer::Create()), |
| 66 observing_frame_source_(false), | 66 observing_frame_source_(false), |
| 67 throttle_frame_production_(false), | |
| 68 compositor_timing_history_(std::move(compositor_timing_history)), | 67 compositor_timing_history_(std::move(compositor_timing_history)), |
| 69 begin_impl_frame_deadline_mode_( | 68 begin_impl_frame_deadline_mode_( |
| 70 SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_NONE), | 69 SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_NONE), |
| 71 begin_impl_frame_tracker_(BEGINFRAMETRACKER_FROM_HERE), | 70 begin_impl_frame_tracker_(BEGINFRAMETRACKER_FROM_HERE), |
| 72 state_machine_(settings), | 71 state_machine_(settings), |
| 73 inside_process_scheduled_actions_(false), | 72 inside_process_scheduled_actions_(false), |
| 74 inside_action_(SchedulerStateMachine::ACTION_NONE), | 73 inside_action_(SchedulerStateMachine::ACTION_NONE), |
| 75 weak_factory_(this) { | 74 weak_factory_(this) { |
| 76 TRACE_EVENT1("cc", "Scheduler::Scheduler", "settings", settings_.AsValue()); | 75 TRACE_EVENT1("cc", "Scheduler::Scheduler", "settings", settings_.AsValue()); |
| 77 DCHECK(client_); | 76 DCHECK(client_); |
| 78 DCHECK(!state_machine_.BeginFrameNeeded()); | 77 DCHECK(!state_machine_.BeginFrameNeeded()); |
| 79 DCHECK(!settings_.use_external_begin_frame_source || external_frame_source_); | 78 DCHECK(!settings_.use_external_begin_frame_source || external_frame_source_); |
| 80 DCHECK(settings_.use_external_begin_frame_source || synthetic_frame_source_); | 79 DCHECK(settings_.use_external_begin_frame_source || synthetic_frame_source_); |
| 81 DCHECK(unthrottled_frame_source_); | 80 DCHECK(unthrottled_frame_source_); |
| 82 | 81 |
| 83 begin_retro_frame_closure_ = | 82 begin_retro_frame_closure_ = |
| 84 base::Bind(&Scheduler::BeginRetroFrame, weak_factory_.GetWeakPtr()); | 83 base::Bind(&Scheduler::BeginRetroFrame, weak_factory_.GetWeakPtr()); |
| 85 begin_impl_frame_deadline_closure_ = base::Bind( | 84 begin_impl_frame_deadline_closure_ = base::Bind( |
| 86 &Scheduler::OnBeginImplFrameDeadline, weak_factory_.GetWeakPtr()); | 85 &Scheduler::OnBeginImplFrameDeadline, weak_factory_.GetWeakPtr()); |
| 87 | 86 |
| 88 frame_source_->AddSource(primary_frame_source()); | 87 frame_source_->AddSource(primary_frame_source()); |
| 89 primary_frame_source()->SetClientReady(); | 88 primary_frame_source()->SetClientReady(); |
| 90 | 89 |
| 91 frame_source_->AddSource(unthrottled_frame_source_.get()); | 90 frame_source_->AddSource(unthrottled_frame_source_.get()); |
| 92 unthrottled_frame_source_->SetClientReady(); | 91 unthrottled_frame_source_->SetClientReady(); |
| 93 | 92 |
| 94 SetThrottleFrameProduction(settings_.throttle_frame_production); | 93 if (settings_.throttle_frame_production) { |
| 94 frame_source_->SetActiveSource(primary_frame_source()); |
| 95 } else { |
| 96 frame_source_->SetActiveSource(unthrottled_frame_source_.get()); |
| 97 } |
| 98 ProcessScheduledActions(); |
| 95 } | 99 } |
| 96 | 100 |
| 97 Scheduler::~Scheduler() { | 101 Scheduler::~Scheduler() { |
| 98 if (observing_frame_source_) | 102 if (observing_frame_source_) |
| 99 frame_source_->RemoveObserver(this); | 103 frame_source_->RemoveObserver(this); |
| 100 frame_source_->SetActiveSource(nullptr); | 104 frame_source_->SetActiveSource(nullptr); |
| 101 } | 105 } |
| 102 | 106 |
| 103 base::TimeTicks Scheduler::Now() const { | 107 base::TimeTicks Scheduler::Now() const { |
| 104 base::TimeTicks now = base::TimeTicks::Now(); | 108 base::TimeTicks now = base::TimeTicks::Now(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 state_machine_.NotifyReadyToActivate(); | 149 state_machine_.NotifyReadyToActivate(); |
| 146 ProcessScheduledActions(); | 150 ProcessScheduledActions(); |
| 147 } | 151 } |
| 148 | 152 |
| 149 void Scheduler::NotifyReadyToDraw() { | 153 void Scheduler::NotifyReadyToDraw() { |
| 150 // Future work might still needed for crbug.com/352894. | 154 // Future work might still needed for crbug.com/352894. |
| 151 state_machine_.NotifyReadyToDraw(); | 155 state_machine_.NotifyReadyToDraw(); |
| 152 ProcessScheduledActions(); | 156 ProcessScheduledActions(); |
| 153 } | 157 } |
| 154 | 158 |
| 155 void Scheduler::SetThrottleFrameProduction(bool throttle) { | |
| 156 throttle_frame_production_ = throttle; | |
| 157 if (throttle) { | |
| 158 frame_source_->SetActiveSource(primary_frame_source()); | |
| 159 } else { | |
| 160 frame_source_->SetActiveSource(unthrottled_frame_source_.get()); | |
| 161 } | |
| 162 ProcessScheduledActions(); | |
| 163 } | |
| 164 | |
| 165 void Scheduler::SetNeedsBeginMainFrame() { | 159 void Scheduler::SetNeedsBeginMainFrame() { |
| 166 state_machine_.SetNeedsBeginMainFrame(); | 160 state_machine_.SetNeedsBeginMainFrame(); |
| 167 ProcessScheduledActions(); | 161 ProcessScheduledActions(); |
| 168 } | 162 } |
| 169 | 163 |
| 170 void Scheduler::SetNeedsOneBeginImplFrame() { | 164 void Scheduler::SetNeedsOneBeginImplFrame() { |
| 171 state_machine_.SetNeedsOneBeginImplFrame(); | 165 state_machine_.SetNeedsOneBeginImplFrame(); |
| 172 ProcessScheduledActions(); | 166 ProcessScheduledActions(); |
| 173 } | 167 } |
| 174 | 168 |
| (...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 801 TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), | 795 TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), |
| 802 &frame_tracing_enabled); | 796 &frame_tracing_enabled); |
| 803 if (frame_tracing_enabled) { | 797 if (frame_tracing_enabled) { |
| 804 state->BeginDictionary("frame_source_"); | 798 state->BeginDictionary("frame_source_"); |
| 805 frame_source_->AsValueInto(state); | 799 frame_source_->AsValueInto(state); |
| 806 state->EndDictionary(); | 800 state->EndDictionary(); |
| 807 } | 801 } |
| 808 | 802 |
| 809 state->BeginDictionary("scheduler_state"); | 803 state->BeginDictionary("scheduler_state"); |
| 810 state->SetBoolean("external_frame_source_", !!external_frame_source_); | 804 state->SetBoolean("external_frame_source_", !!external_frame_source_); |
| 811 state->SetBoolean("throttle_frame_production_", throttle_frame_production_); | 805 state->SetBoolean("throttle_frame_production_", |
| 806 settings_.throttle_frame_production); |
| 812 state->SetDouble("authoritative_vsync_interval_ms", | 807 state->SetDouble("authoritative_vsync_interval_ms", |
| 813 authoritative_vsync_interval_.InMillisecondsF()); | 808 authoritative_vsync_interval_.InMillisecondsF()); |
| 814 state->SetDouble( | 809 state->SetDouble( |
| 815 "last_vsync_timebase_ms", | 810 "last_vsync_timebase_ms", |
| 816 (last_vsync_timebase_ - base::TimeTicks()).InMillisecondsF()); | 811 (last_vsync_timebase_ - base::TimeTicks()).InMillisecondsF()); |
| 817 state->SetDouble("estimated_parent_draw_time_ms", | 812 state->SetDouble("estimated_parent_draw_time_ms", |
| 818 estimated_parent_draw_time_.InMillisecondsF()); | 813 estimated_parent_draw_time_.InMillisecondsF()); |
| 819 state->SetBoolean("observing_frame_source", observing_frame_source_); | 814 state->SetBoolean("observing_frame_source", observing_frame_source_); |
| 820 state->SetInteger("begin_retro_frame_args", | 815 state->SetInteger("begin_retro_frame_args", |
| 821 static_cast<int>(begin_retro_frame_args_.size())); | 816 static_cast<int>(begin_retro_frame_args_.size())); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 863 } | 858 } |
| 864 | 859 |
| 865 bool Scheduler::ShouldRecoverImplLatency( | 860 bool Scheduler::ShouldRecoverImplLatency( |
| 866 const BeginFrameArgs& args, | 861 const BeginFrameArgs& args, |
| 867 bool can_activate_before_deadline) const { | 862 bool can_activate_before_deadline) const { |
| 868 DCHECK(!settings_.using_synchronous_renderer_compositor); | 863 DCHECK(!settings_.using_synchronous_renderer_compositor); |
| 869 | 864 |
| 870 // Disable impl thread latency recovery when using the unthrottled | 865 // Disable impl thread latency recovery when using the unthrottled |
| 871 // begin frame source since we will always get a BeginFrame before | 866 // begin frame source since we will always get a BeginFrame before |
| 872 // the swap ack and our heuristics below will not work. | 867 // the swap ack and our heuristics below will not work. |
| 873 if (!throttle_frame_production_) | 868 if (!settings_.throttle_frame_production) |
| 874 return false; | 869 return false; |
| 875 | 870 |
| 876 // If we are swap throttled at the BeginFrame, that means the impl thread is | 871 // If we are swap throttled at the BeginFrame, that means the impl thread is |
| 877 // very likely in a high latency mode. | 872 // very likely in a high latency mode. |
| 878 bool impl_thread_is_likely_high_latency = state_machine_.SwapThrottled(); | 873 bool impl_thread_is_likely_high_latency = state_machine_.SwapThrottled(); |
| 879 if (!impl_thread_is_likely_high_latency) | 874 if (!impl_thread_is_likely_high_latency) |
| 880 return false; | 875 return false; |
| 881 | 876 |
| 882 // The deadline may be in the past if our draw time is too long. | 877 // The deadline may be in the past if our draw time is too long. |
| 883 bool can_draw_before_deadline = args.frame_time < args.deadline; | 878 bool can_draw_before_deadline = args.frame_time < args.deadline; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 911 } | 906 } |
| 912 | 907 |
| 913 bool Scheduler::IsBeginMainFrameSentOrStarted() const { | 908 bool Scheduler::IsBeginMainFrameSentOrStarted() const { |
| 914 return (state_machine_.begin_main_frame_state() == | 909 return (state_machine_.begin_main_frame_state() == |
| 915 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT || | 910 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT || |
| 916 state_machine_.begin_main_frame_state() == | 911 state_machine_.begin_main_frame_state() == |
| 917 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_STARTED); | 912 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_STARTED); |
| 918 } | 913 } |
| 919 | 914 |
| 920 } // namespace cc | 915 } // namespace cc |
| OLD | NEW |