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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 SchedulerClient* client, | 42 SchedulerClient* client, |
43 const SchedulerSettings& settings, | 43 const SchedulerSettings& settings, |
44 int layer_tree_host_id, | 44 int layer_tree_host_id, |
45 base::SingleThreadTaskRunner* task_runner, | 45 base::SingleThreadTaskRunner* task_runner, |
46 BeginFrameSource* begin_frame_source, | 46 BeginFrameSource* begin_frame_source, |
47 scoped_ptr<CompositorTimingHistory> compositor_timing_history) | 47 scoped_ptr<CompositorTimingHistory> compositor_timing_history) |
48 : settings_(settings), | 48 : settings_(settings), |
49 client_(client), | 49 client_(client), |
50 layer_tree_host_id_(layer_tree_host_id), | 50 layer_tree_host_id_(layer_tree_host_id), |
51 task_runner_(task_runner), | 51 task_runner_(task_runner), |
52 begin_frame_source_(begin_frame_source), | 52 begin_frame_source_(nullptr), |
53 observing_begin_frame_source_(false), | 53 observing_begin_frame_source_(false), |
54 compositor_timing_history_(std::move(compositor_timing_history)), | 54 compositor_timing_history_(std::move(compositor_timing_history)), |
55 begin_impl_frame_deadline_mode_( | 55 begin_impl_frame_deadline_mode_( |
56 SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_NONE), | 56 SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_NONE), |
57 begin_impl_frame_tracker_(BEGINFRAMETRACKER_FROM_HERE), | 57 begin_impl_frame_tracker_(BEGINFRAMETRACKER_FROM_HERE), |
58 state_machine_(settings), | 58 state_machine_(settings), |
59 inside_process_scheduled_actions_(false), | 59 inside_process_scheduled_actions_(false), |
60 inside_action_(SchedulerStateMachine::ACTION_NONE), | 60 inside_action_(SchedulerStateMachine::ACTION_NONE), |
61 weak_factory_(this) { | 61 weak_factory_(this) { |
62 TRACE_EVENT1("cc", "Scheduler::Scheduler", "settings", settings_.AsValue()); | 62 TRACE_EVENT1("cc", "Scheduler::Scheduler", "settings", settings_.AsValue()); |
63 DCHECK(client_); | 63 DCHECK(client_); |
64 DCHECK(!state_machine_.BeginFrameNeeded()); | 64 DCHECK(!state_machine_.BeginFrameNeeded()); |
65 | 65 |
66 begin_retro_frame_closure_ = | 66 begin_retro_frame_closure_ = |
67 base::Bind(&Scheduler::BeginRetroFrame, weak_factory_.GetWeakPtr()); | 67 base::Bind(&Scheduler::BeginRetroFrame, weak_factory_.GetWeakPtr()); |
68 begin_impl_frame_deadline_closure_ = base::Bind( | 68 begin_impl_frame_deadline_closure_ = base::Bind( |
69 &Scheduler::OnBeginImplFrameDeadline, weak_factory_.GetWeakPtr()); | 69 &Scheduler::OnBeginImplFrameDeadline, weak_factory_.GetWeakPtr()); |
70 | 70 |
| 71 SetBeginFrameSource(begin_frame_source); |
71 ProcessScheduledActions(); | 72 ProcessScheduledActions(); |
72 } | 73 } |
73 | 74 |
74 Scheduler::~Scheduler() { | 75 Scheduler::~Scheduler() { |
75 if (observing_begin_frame_source_) | 76 if (observing_begin_frame_source_) |
76 begin_frame_source_->RemoveObserver(this); | 77 begin_frame_source_->RemoveObserver(this); |
77 } | 78 } |
78 | 79 |
79 base::TimeTicks Scheduler::Now() const { | 80 base::TimeTicks Scheduler::Now() const { |
80 base::TimeTicks now = base::TimeTicks::Now(); | 81 base::TimeTicks now = base::TimeTicks::Now(); |
(...skipping 25 matching lines...) Expand all Loading... |
106 state_machine_.NotifyReadyToActivate(); | 107 state_machine_.NotifyReadyToActivate(); |
107 ProcessScheduledActions(); | 108 ProcessScheduledActions(); |
108 } | 109 } |
109 | 110 |
110 void Scheduler::NotifyReadyToDraw() { | 111 void Scheduler::NotifyReadyToDraw() { |
111 // Future work might still needed for crbug.com/352894. | 112 // Future work might still needed for crbug.com/352894. |
112 state_machine_.NotifyReadyToDraw(); | 113 state_machine_.NotifyReadyToDraw(); |
113 ProcessScheduledActions(); | 114 ProcessScheduledActions(); |
114 } | 115 } |
115 | 116 |
| 117 void Scheduler::SetBeginFrameSource(BeginFrameSource* source) { |
| 118 DCHECK(source); |
| 119 if (source == begin_frame_source_) |
| 120 return; |
| 121 if (begin_frame_source_ && observing_begin_frame_source_) |
| 122 begin_frame_source_->RemoveObserver(this); |
| 123 begin_frame_source_ = source; |
| 124 if (observing_begin_frame_source_) |
| 125 begin_frame_source_->AddObserver(this); |
| 126 } |
| 127 |
116 void Scheduler::SetNeedsBeginMainFrame() { | 128 void Scheduler::SetNeedsBeginMainFrame() { |
117 state_machine_.SetNeedsBeginMainFrame(); | 129 state_machine_.SetNeedsBeginMainFrame(); |
118 ProcessScheduledActions(); | 130 ProcessScheduledActions(); |
119 } | 131 } |
120 | 132 |
121 void Scheduler::SetNeedsOneBeginImplFrame() { | 133 void Scheduler::SetNeedsOneBeginImplFrame() { |
122 state_machine_.SetNeedsOneBeginImplFrame(); | 134 state_machine_.SetNeedsOneBeginImplFrame(); |
123 ProcessScheduledActions(); | 135 ProcessScheduledActions(); |
124 } | 136 } |
125 | 137 |
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
737 | 749 |
738 state->BeginDictionary("state_machine"); | 750 state->BeginDictionary("state_machine"); |
739 state_machine_.AsValueInto(state); | 751 state_machine_.AsValueInto(state); |
740 state->EndDictionary(); | 752 state->EndDictionary(); |
741 | 753 |
742 // Only trace frame sources when explicitly enabled - http://crbug.com/420607 | 754 // Only trace frame sources when explicitly enabled - http://crbug.com/420607 |
743 bool frame_tracing_enabled = false; | 755 bool frame_tracing_enabled = false; |
744 TRACE_EVENT_CATEGORY_GROUP_ENABLED( | 756 TRACE_EVENT_CATEGORY_GROUP_ENABLED( |
745 TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), | 757 TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), |
746 &frame_tracing_enabled); | 758 &frame_tracing_enabled); |
747 if (frame_tracing_enabled) { | 759 if (frame_tracing_enabled && begin_frame_source_) { |
748 state->BeginDictionary("begin_frame_source_"); | 760 state->BeginDictionary("begin_frame_source_"); |
749 begin_frame_source_->AsValueInto(state); | 761 begin_frame_source_->AsValueInto(state); |
750 state->EndDictionary(); | 762 state->EndDictionary(); |
751 } | 763 } |
752 | 764 |
753 state->BeginDictionary("scheduler_state"); | 765 state->BeginDictionary("scheduler_state"); |
754 state->SetBoolean("throttle_frame_production_", | 766 state->SetBoolean("throttle_frame_production_", |
755 settings_.throttle_frame_production); | 767 settings_.throttle_frame_production); |
756 state->SetDouble("estimated_parent_draw_time_ms", | 768 state->SetDouble("estimated_parent_draw_time_ms", |
757 estimated_parent_draw_time_.InMillisecondsF()); | 769 estimated_parent_draw_time_.InMillisecondsF()); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
851 } | 863 } |
852 | 864 |
853 bool Scheduler::IsBeginMainFrameSentOrStarted() const { | 865 bool Scheduler::IsBeginMainFrameSentOrStarted() const { |
854 return (state_machine_.begin_main_frame_state() == | 866 return (state_machine_.begin_main_frame_state() == |
855 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT || | 867 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT || |
856 state_machine_.begin_main_frame_state() == | 868 state_machine_.begin_main_frame_state() == |
857 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_STARTED); | 869 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_STARTED); |
858 } | 870 } |
859 | 871 |
860 } // namespace cc | 872 } // namespace cc |
OLD | NEW |