OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_IMPL_H_ | 5 #ifndef CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_IMPL_H_ |
6 #define CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_IMPL_H_ | 6 #define CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_IMPL_H_ |
7 | 7 |
8 #include "base/atomicops.h" | 8 #include "base/atomicops.h" |
9 #include "base/synchronization/lock.h" | 9 #include "base/synchronization/lock.h" |
10 #include "base/threading/thread_checker.h" | 10 #include "base/threading/thread_checker.h" |
11 #include "cc/test/test_now_source.h" | 11 #include "cc/test/test_now_source.h" |
12 #include "content/renderer/scheduler/cancelable_closure_holder.h" | 12 #include "content/renderer/scheduler/cancelable_closure_holder.h" |
13 #include "content/renderer/scheduler/deadline_task_runner.h" | |
13 #include "content/renderer/scheduler/renderer_scheduler.h" | 14 #include "content/renderer/scheduler/renderer_scheduler.h" |
14 #include "content/renderer/scheduler/single_thread_idle_task_runner.h" | 15 #include "content/renderer/scheduler/single_thread_idle_task_runner.h" |
15 #include "content/renderer/scheduler/task_queue_manager.h" | 16 #include "content/renderer/scheduler/task_queue_manager.h" |
16 | 17 |
17 namespace base { | 18 namespace base { |
18 namespace trace_event { | 19 namespace trace_event { |
19 class ConvertableToTraceFormat; | 20 class ConvertableToTraceFormat; |
20 } | 21 } |
21 } | 22 } |
22 | 23 |
(...skipping 23 matching lines...) Expand all Loading... | |
46 void AddTaskObserver(base::MessageLoop::TaskObserver* task_observer) override; | 47 void AddTaskObserver(base::MessageLoop::TaskObserver* task_observer) override; |
47 void RemoveTaskObserver( | 48 void RemoveTaskObserver( |
48 base::MessageLoop::TaskObserver* task_observer) override; | 49 base::MessageLoop::TaskObserver* task_observer) override; |
49 void Shutdown() override; | 50 void Shutdown() override; |
50 | 51 |
51 void SetTimeSourceForTesting(scoped_refptr<cc::TestNowSource> time_source); | 52 void SetTimeSourceForTesting(scoped_refptr<cc::TestNowSource> time_source); |
52 void SetWorkBatchSizeForTesting(size_t work_batch_size); | 53 void SetWorkBatchSizeForTesting(size_t work_batch_size); |
53 | 54 |
54 private: | 55 private: |
55 friend class RendererSchedulerImplTest; | 56 friend class RendererSchedulerImplTest; |
57 friend class MockRendererSchedulerImpl; | |
56 | 58 |
57 // Keep RendererSchedulerImpl::TaskQueueIdToString in sync with this enum. | 59 // Keep RendererSchedulerImpl::TaskQueueIdToString in sync with this enum. |
58 enum QueueId { | 60 enum QueueId { |
59 DEFAULT_TASK_QUEUE, | 61 DEFAULT_TASK_QUEUE, |
60 COMPOSITOR_TASK_QUEUE, | 62 COMPOSITOR_TASK_QUEUE, |
61 LOADING_TASK_QUEUE, | 63 LOADING_TASK_QUEUE, |
62 IDLE_TASK_QUEUE, | 64 IDLE_TASK_QUEUE, |
63 CONTROL_TASK_QUEUE, | 65 CONTROL_TASK_QUEUE, |
64 CONTROL_TASK_AFTER_WAKEUP_QUEUE, | 66 CONTROL_TASK_AFTER_WAKEUP_QUEUE, |
65 // Must be the last entry. | 67 // Must be the last entry. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 | 112 |
111 // The time we should stay in a priority-escalated mode after an input event. | 113 // The time we should stay in a priority-escalated mode after an input event. |
112 static const int kPriorityEscalationAfterInputMillis = 100; | 114 static const int kPriorityEscalationAfterInputMillis = 100; |
113 | 115 |
114 // IdleTaskDeadlineSupplier Implementation: | 116 // IdleTaskDeadlineSupplier Implementation: |
115 void CurrentIdleTaskDeadlineCallback(base::TimeTicks* deadline_out) const; | 117 void CurrentIdleTaskDeadlineCallback(base::TimeTicks* deadline_out) const; |
116 | 118 |
117 // Returns the current scheduler policy. Must be called from the main thread. | 119 // Returns the current scheduler policy. Must be called from the main thread. |
118 Policy SchedulerPolicy() const; | 120 Policy SchedulerPolicy() const; |
119 | 121 |
120 // Posts a call to UpdatePolicy on the control runner to be run after |delay| | 122 // Schedules an immediate PolicyUpdate, if there isn't one already pending and |
121 void PostUpdatePolicyOnControlRunner(base::TimeDelta delay); | 123 // sets |policy_may_need_update_|. Note |incoming_signals_lock_| must be |
124 // locked. | |
125 void EnsureUgentPolicyUpdatePostedOnMainThread( | |
Sami
2015/03/12 18:15:22
s/Ugent/Urgent/
alex clarke (OOO till 29th)
2015/03/12 18:24:08
Done.
| |
126 const tracked_objects::Location& from_here); | |
122 | 127 |
123 // Update the policy if a new signal has arrived. Must be called from the main | 128 // Update the policy if a new signal has arrived. Must be called from the main |
124 // thread. | 129 // thread. |
125 void MaybeUpdatePolicy(); | 130 void MaybeUpdatePolicy(); |
126 | 131 |
127 // Updates the scheduler policy. Must be called from the main thread. | 132 // Locks |incoming_signals_lock_| and updates the scheduler policy. |
133 // Must be called from the main thread. | |
128 void UpdatePolicy(); | 134 void UpdatePolicy(); |
135 virtual void UpdatePolicyLocked(); | |
129 | 136 |
130 // Helper for computing the new policy. |new_policy_duration| will be filled | 137 // Helper for computing the new policy. |new_policy_duration| will be filled |
131 // with the amount of time after which the policy should be updated again. If | 138 // with the amount of time after which the policy should be updated again. If |
132 // the duration is zero, a new policy update will not be scheduled. Must be | 139 // the duration is zero, a new policy update will not be scheduled. Must be |
133 // called with |incoming_signals_lock_| held. | 140 // called with |incoming_signals_lock_| held. |
134 Policy ComputeNewPolicy(base::TimeDelta* new_policy_duration); | 141 Policy ComputeNewPolicy(base::TimeDelta* new_policy_duration, |
Sami
2015/03/12 18:15:22
nit: I'd swap the arguments so that the out argume
alex clarke (OOO till 29th)
2015/03/12 18:24:08
Good point, that's actually in the style guide.
| |
142 base::TimeTicks now); | |
135 | 143 |
136 // An input event of some sort happened, the policy may need updating. | 144 // An input event of some sort happened, the policy may need updating. |
137 void UpdateForInputEvent(blink::WebInputEvent::Type type); | 145 void UpdateForInputEvent(blink::WebInputEvent::Type type); |
138 | 146 |
139 // Called when a previously queued input event was processed. | 147 // Called when a previously queued input event was processed. |
140 // |begin_frame_time|, if non-zero, identifies the frame time at which the | 148 // |begin_frame_time|, if non-zero, identifies the frame time at which the |
141 // input was processed. | 149 // input was processed. |
142 void DidProcessInputEvent(base::TimeTicks begin_frame_time); | 150 void DidProcessInputEvent(base::TimeTicks begin_frame_time); |
143 | 151 |
144 // Start and end an idle period. | 152 // Start and end an idle period. |
145 void StartIdlePeriod(); | 153 void StartIdlePeriod(); |
146 void EndIdlePeriod(); | 154 void EndIdlePeriod(); |
147 | 155 |
148 base::TimeTicks Now() const; | 156 base::TimeTicks Now() const; |
149 | 157 |
150 base::ThreadChecker main_thread_checker_; | 158 base::ThreadChecker main_thread_checker_; |
151 scoped_ptr<RendererTaskQueueSelector> renderer_task_queue_selector_; | 159 scoped_ptr<RendererTaskQueueSelector> renderer_task_queue_selector_; |
152 scoped_ptr<TaskQueueManager> task_queue_manager_; | 160 scoped_ptr<TaskQueueManager> task_queue_manager_; |
153 scoped_refptr<base::SingleThreadTaskRunner> control_task_runner_; | 161 scoped_refptr<base::SingleThreadTaskRunner> control_task_runner_; |
154 scoped_refptr<base::SingleThreadTaskRunner> control_task_after_wakeup_runner_; | 162 scoped_refptr<base::SingleThreadTaskRunner> control_task_after_wakeup_runner_; |
155 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_; | 163 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_; |
156 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; | 164 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; |
157 scoped_refptr<base::SingleThreadTaskRunner> loading_task_runner_; | 165 scoped_refptr<base::SingleThreadTaskRunner> loading_task_runner_; |
158 scoped_refptr<SingleThreadIdleTaskRunner> idle_task_runner_; | 166 scoped_refptr<SingleThreadIdleTaskRunner> idle_task_runner_; |
159 | 167 |
160 base::Closure update_policy_closure_; | 168 base::Closure update_policy_closure_; |
169 DeadlineTaskRunner delayed_update_policy_runner_; | |
161 CancelableClosureHolder end_idle_period_closure_; | 170 CancelableClosureHolder end_idle_period_closure_; |
162 | 171 |
163 // Don't access current_policy_ directly, instead use SchedulerPolicy(). | 172 // Don't access current_policy_ directly, instead use SchedulerPolicy(). |
164 Policy current_policy_; | 173 Policy current_policy_; |
165 | 174 |
166 base::TimeTicks estimated_next_frame_begin_; | 175 base::TimeTicks estimated_next_frame_begin_; |
167 | 176 |
168 // The incoming_signals_lock_ mutex protects access to all variables in the | 177 // The incoming_signals_lock_ mutex protects access to all variables in the |
169 // (contiguous) block below. | 178 // (contiguous) block below. |
170 base::Lock incoming_signals_lock_; | 179 base::Lock incoming_signals_lock_; |
171 base::TimeTicks last_input_receipt_time_on_compositor_; | 180 base::TimeTicks last_input_receipt_time_on_compositor_; |
172 base::TimeTicks last_input_process_time_on_main_; | 181 base::TimeTicks last_input_process_time_on_main_; |
173 blink::WebInputEvent::Type last_input_type_; | 182 blink::WebInputEvent::Type last_input_type_; |
174 InputStreamState input_stream_state_; | 183 InputStreamState input_stream_state_; |
175 PollableNeedsUpdateFlag policy_may_need_update_; | 184 PollableNeedsUpdateFlag policy_may_need_update_; |
176 | 185 |
177 scoped_refptr<cc::TestNowSource> time_source_; | 186 scoped_refptr<cc::TestNowSource> time_source_; |
178 | 187 |
179 base::WeakPtr<RendererSchedulerImpl> weak_renderer_scheduler_ptr_; | 188 base::WeakPtr<RendererSchedulerImpl> weak_renderer_scheduler_ptr_; |
180 base::WeakPtrFactory<RendererSchedulerImpl> weak_factory_; | 189 base::WeakPtrFactory<RendererSchedulerImpl> weak_factory_; |
181 | 190 |
182 DISALLOW_COPY_AND_ASSIGN(RendererSchedulerImpl); | 191 DISALLOW_COPY_AND_ASSIGN(RendererSchedulerImpl); |
183 }; | 192 }; |
184 | 193 |
185 } // namespace content | 194 } // namespace content |
186 | 195 |
187 #endif // CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_IMPL_H_ | 196 #endif // CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_IMPL_H_ |
OLD | NEW |