Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(268)

Side by Side Diff: content/renderer/scheduler/renderer_scheduler_impl.h

Issue 969373002: [content]: Add CanExceedIdleDeadlineIfRequired function to RendererScheduler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@long_idle_5
Patch Set: Sync with changes to long-idle CL. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 23 matching lines...) Expand all
34 scoped_refptr<base::SingleThreadTaskRunner> DefaultTaskRunner() override; 34 scoped_refptr<base::SingleThreadTaskRunner> DefaultTaskRunner() override;
35 scoped_refptr<base::SingleThreadTaskRunner> CompositorTaskRunner() override; 35 scoped_refptr<base::SingleThreadTaskRunner> CompositorTaskRunner() override;
36 scoped_refptr<SingleThreadIdleTaskRunner> IdleTaskRunner() override; 36 scoped_refptr<SingleThreadIdleTaskRunner> IdleTaskRunner() override;
37 scoped_refptr<base::SingleThreadTaskRunner> LoadingTaskRunner() override; 37 scoped_refptr<base::SingleThreadTaskRunner> LoadingTaskRunner() override;
38 void WillBeginFrame(const cc::BeginFrameArgs& args) override; 38 void WillBeginFrame(const cc::BeginFrameArgs& args) override;
39 void BeginFrameNotExpectedSoon() override; 39 void BeginFrameNotExpectedSoon() override;
40 void DidCommitFrameToCompositor() override; 40 void DidCommitFrameToCompositor() override;
41 void DidReceiveInputEventOnCompositorThread( 41 void DidReceiveInputEventOnCompositorThread(
42 const blink::WebInputEvent& web_input_event) override; 42 const blink::WebInputEvent& web_input_event) override;
43 void DidAnimateForInputOnCompositorThread() override; 43 void DidAnimateForInputOnCompositorThread() override;
44 bool CanExceedIdleDeadlineIfRequired() const override;
44 bool IsHighPriorityWorkAnticipated() override; 45 bool IsHighPriorityWorkAnticipated() override;
45 bool ShouldYieldForHighPriorityWork() override; 46 bool ShouldYieldForHighPriorityWork() override;
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
(...skipping 17 matching lines...) Expand all
71 COMPOSITOR_PRIORITY, 72 COMPOSITOR_PRIORITY,
72 TOUCHSTART_PRIORITY, 73 TOUCHSTART_PRIORITY,
73 }; 74 };
74 75
75 enum class InputStreamState { 76 enum class InputStreamState {
76 INACTIVE, 77 INACTIVE,
77 ACTIVE, 78 ACTIVE,
78 ACTIVE_AND_AWAITING_TOUCHSTART_RESPONSE 79 ACTIVE_AND_AWAITING_TOUCHSTART_RESPONSE
79 }; 80 };
80 81
82 enum class IdlePeriodState {
83 NOT_WITHIN_IDLE_PERIOD,
84 WITHIN_IDLE_PERIOD,
85 WITHIN_MAX_DEADLINE_IDLE_PERIOD
86 };
87
81 class PollableNeedsUpdateFlag { 88 class PollableNeedsUpdateFlag {
82 public: 89 public:
83 PollableNeedsUpdateFlag(base::Lock* write_lock); 90 PollableNeedsUpdateFlag(base::Lock* write_lock);
84 ~PollableNeedsUpdateFlag(); 91 ~PollableNeedsUpdateFlag();
85 92
86 // Set the flag. May only be called if |write_lock| is held. 93 // Set the flag. May only be called if |write_lock| is held.
87 void SetWhileLocked(bool value); 94 void SetWhileLocked(bool value);
88 95
89 // Returns true iff the flag is set to true. 96 // Returns true iff the flag is set to true.
90 bool IsSet() const; 97 bool IsSet() const;
91 98
92 private: 99 private:
93 base::subtle::Atomic32 flag_; 100 base::subtle::Atomic32 flag_;
94 base::Lock* write_lock_; // Not owned. 101 base::Lock* write_lock_; // Not owned.
95 102
96 DISALLOW_COPY_AND_ASSIGN(PollableNeedsUpdateFlag); 103 DISALLOW_COPY_AND_ASSIGN(PollableNeedsUpdateFlag);
97 }; 104 };
98 105
99 // Returns the serialized scheduler state for tracing. 106 // Returns the serialized scheduler state for tracing.
100 scoped_refptr<base::trace_event::ConvertableToTraceFormat> AsValueLocked( 107 scoped_refptr<base::trace_event::ConvertableToTraceFormat> AsValueLocked(
101 base::TimeTicks optional_now) const; 108 base::TimeTicks optional_now) const;
102 static const char* TaskQueueIdToString(QueueId queue_id); 109 static const char* TaskQueueIdToString(QueueId queue_id);
103 static const char* PolicyToString(Policy policy); 110 static const char* PolicyToString(Policy policy);
104 static const char* InputStreamStateToString(InputStreamState state); 111 static const char* InputStreamStateToString(InputStreamState state);
112 static const char* IdlePeriodStateToString(IdlePeriodState state);
105 113
106 static InputStreamState ComputeNewInputStreamState( 114 static InputStreamState ComputeNewInputStreamState(
107 InputStreamState current_state, 115 InputStreamState current_state,
108 blink::WebInputEvent::Type new_input_event, 116 blink::WebInputEvent::Type new_input_event,
109 blink::WebInputEvent::Type last_input_event); 117 blink::WebInputEvent::Type last_input_event);
110 118
111 // The time we should stay in a priority-escalated mode after an input event. 119 // The time we should stay in a priority-escalated mode after an input event.
112 static const int kPriorityEscalationAfterInputMillis = 100; 120 static const int kPriorityEscalationAfterInputMillis = 100;
113 121
114 // The maximum length of an idle period. 122 // The maximum length of an idle period.
(...skipping 29 matching lines...) Expand all
144 Policy ComputeNewPolicy(base::TimeDelta* new_policy_duration); 152 Policy ComputeNewPolicy(base::TimeDelta* new_policy_duration);
145 153
146 // An input event of some sort happened, the policy may need updating. 154 // An input event of some sort happened, the policy may need updating.
147 void UpdateForInputEvent(blink::WebInputEvent::Type type); 155 void UpdateForInputEvent(blink::WebInputEvent::Type type);
148 156
149 // Called when a previously queued input event was processed. 157 // Called when a previously queued input event was processed.
150 // |begin_frame_time|, if non-zero, identifies the frame time at which the 158 // |begin_frame_time|, if non-zero, identifies the frame time at which the
151 // input was processed. 159 // input was processed.
152 void DidProcessInputEvent(base::TimeTicks begin_frame_time); 160 void DidProcessInputEvent(base::TimeTicks begin_frame_time);
153 161
154 // Returns true if we should initiate a long idle time now. Fills in 162 // Returns the new idle period state for the next long idle period. Fills in
155 // |next_long_idle_period_delay_out| with the next time we should try to 163 // |next_long_idle_period_delay_out| with the next time we should try to
156 // initiate the next idle period. 164 // initiate the next idle period.
157 bool ShouldStartLongIdlePeriod( 165 IdlePeriodState ComputeNewLongIdlePeriodState(
158 const base::TimeTicks now, 166 const base::TimeTicks now,
159 base::TimeDelta* next_long_idle_period_delay_out); 167 base::TimeDelta* next_long_idle_period_delay);
160 168
161 // Initiate a long idle period. 169 // Initiate a long idle period.
162 void InitiateLongIdlePeriod(); 170 void InitiateLongIdlePeriod();
163 void InitiateLongIdlePeriodAfterWakeup(); 171 void InitiateLongIdlePeriodAfterWakeup();
164 172
165 // Start and end an idle period. 173 // Start and end an idle period.
166 void StartIdlePeriod(); 174 void StartIdlePeriod(IdlePeriodState new_idle_period_state);
167 void EndIdlePeriod(); 175 void EndIdlePeriod();
168 176
169 base::TimeTicks Now() const; 177 base::TimeTicks Now() const;
170 178
171 base::ThreadChecker main_thread_checker_; 179 base::ThreadChecker main_thread_checker_;
172 scoped_ptr<RendererTaskQueueSelector> renderer_task_queue_selector_; 180 scoped_ptr<RendererTaskQueueSelector> renderer_task_queue_selector_;
173 scoped_ptr<TaskQueueManager> task_queue_manager_; 181 scoped_ptr<TaskQueueManager> task_queue_manager_;
174 scoped_refptr<base::SingleThreadTaskRunner> control_task_runner_; 182 scoped_refptr<base::SingleThreadTaskRunner> control_task_runner_;
175 scoped_refptr<base::SingleThreadTaskRunner> control_task_after_wakeup_runner_; 183 scoped_refptr<base::SingleThreadTaskRunner> control_task_after_wakeup_runner_;
176 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_; 184 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_;
177 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; 185 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_;
178 scoped_refptr<base::SingleThreadTaskRunner> loading_task_runner_; 186 scoped_refptr<base::SingleThreadTaskRunner> loading_task_runner_;
179 scoped_refptr<SingleThreadIdleTaskRunner> idle_task_runner_; 187 scoped_refptr<SingleThreadIdleTaskRunner> idle_task_runner_;
180 188
181 base::Closure update_policy_closure_; 189 base::Closure update_policy_closure_;
182 CancelableClosureHolder end_idle_period_closure_; 190 CancelableClosureHolder end_idle_period_closure_;
183 CancelableClosureHolder initiate_next_long_idle_period_closure_; 191 CancelableClosureHolder initiate_next_long_idle_period_closure_;
184 CancelableClosureHolder initiate_next_long_idle_period_after_wakeup_closure_; 192 CancelableClosureHolder initiate_next_long_idle_period_after_wakeup_closure_;
185 193
186 // Don't access current_policy_ directly, instead use SchedulerPolicy(). 194 // Don't access current_policy_ directly, instead use SchedulerPolicy().
187 Policy current_policy_; 195 Policy current_policy_;
188 bool in_idle_period_; 196 IdlePeriodState idle_period_state_;
189 197
190 base::TimeTicks estimated_next_frame_begin_; 198 base::TimeTicks estimated_next_frame_begin_;
191 base::TimeTicks current_policy_expiration_time_; 199 base::TimeTicks current_policy_expiration_time_;
192 200
193 // The incoming_signals_lock_ mutex protects access to all variables in the 201 // The incoming_signals_lock_ mutex protects access to all variables in the
194 // (contiguous) block below. 202 // (contiguous) block below.
195 base::Lock incoming_signals_lock_; 203 base::Lock incoming_signals_lock_;
196 base::TimeTicks last_input_receipt_time_on_compositor_; 204 base::TimeTicks last_input_receipt_time_on_compositor_;
197 base::TimeTicks last_input_process_time_on_main_; 205 base::TimeTicks last_input_process_time_on_main_;
198 blink::WebInputEvent::Type last_input_type_; 206 blink::WebInputEvent::Type last_input_type_;
199 InputStreamState input_stream_state_; 207 InputStreamState input_stream_state_;
200 PollableNeedsUpdateFlag policy_may_need_update_; 208 PollableNeedsUpdateFlag policy_may_need_update_;
201 209
202 scoped_refptr<cc::TestNowSource> time_source_; 210 scoped_refptr<cc::TestNowSource> time_source_;
203 211
204 base::WeakPtr<RendererSchedulerImpl> weak_renderer_scheduler_ptr_; 212 base::WeakPtr<RendererSchedulerImpl> weak_renderer_scheduler_ptr_;
205 base::WeakPtrFactory<RendererSchedulerImpl> weak_factory_; 213 base::WeakPtrFactory<RendererSchedulerImpl> weak_factory_;
206 214
207 DISALLOW_COPY_AND_ASSIGN(RendererSchedulerImpl); 215 DISALLOW_COPY_AND_ASSIGN(RendererSchedulerImpl);
208 }; 216 };
209 217
210 } // namespace content 218 } // namespace content
211 219
212 #endif // CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_IMPL_H_ 220 #endif // CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698