OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 CC_RESOURCES_RASTER_WORKER_POOL_H_ | 5 #ifndef CC_RESOURCES_RASTER_WORKER_POOL_H_ |
6 #define CC_RESOURCES_RASTER_WORKER_POOL_H_ | 6 #define CC_RESOURCES_RASTER_WORKER_POOL_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 class CC_EXPORT RasterWorkerPoolClient { | 86 class CC_EXPORT RasterWorkerPoolClient { |
87 public: | 87 public: |
88 virtual bool ShouldForceTasksRequiredForActivationToComplete() const = 0; | 88 virtual bool ShouldForceTasksRequiredForActivationToComplete() const = 0; |
89 virtual void DidFinishRunningTasks() = 0; | 89 virtual void DidFinishRunningTasks() = 0; |
90 virtual void DidFinishRunningTasksRequiredForActivation() = 0; | 90 virtual void DidFinishRunningTasksRequiredForActivation() = 0; |
91 | 91 |
92 protected: | 92 protected: |
93 virtual ~RasterWorkerPoolClient() {} | 93 virtual ~RasterWorkerPoolClient() {} |
94 }; | 94 }; |
95 | 95 |
| 96 struct CC_EXPORT RasterTaskQueue { |
| 97 struct CC_EXPORT Item { |
| 98 class TaskComparator { |
| 99 public: |
| 100 explicit TaskComparator(const internal::RasterWorkerPoolTask* task) |
| 101 : task_(task) {} |
| 102 |
| 103 bool operator()(const Item& item) const { return item.task == task_; } |
| 104 |
| 105 private: |
| 106 const internal::RasterWorkerPoolTask* task_; |
| 107 }; |
| 108 |
| 109 typedef std::vector<Item> Vector; |
| 110 |
| 111 Item(internal::RasterWorkerPoolTask* task, bool required_for_activation); |
| 112 ~Item(); |
| 113 |
| 114 static bool IsRequiredForActivation(const Item& item) { |
| 115 return item.required_for_activation; |
| 116 } |
| 117 |
| 118 scoped_refptr<internal::RasterWorkerPoolTask> task; |
| 119 bool required_for_activation; |
| 120 }; |
| 121 |
| 122 RasterTaskQueue(); |
| 123 ~RasterTaskQueue(); |
| 124 |
| 125 void Swap(RasterTaskQueue* other); |
| 126 void Reset(); |
| 127 |
| 128 Item::Vector items; |
| 129 size_t required_for_activation_count; |
| 130 }; |
| 131 |
96 // A worker thread pool that runs raster tasks. | 132 // A worker thread pool that runs raster tasks. |
97 class CC_EXPORT RasterWorkerPool : public internal::WorkerPoolTaskClient { | 133 class CC_EXPORT RasterWorkerPool : public internal::WorkerPoolTaskClient { |
98 public: | 134 public: |
99 class CC_EXPORT Task { | |
100 public: | |
101 typedef base::Callback<void(bool was_canceled)> Reply; | |
102 | |
103 class CC_EXPORT Set { | |
104 public: | |
105 Set(); | |
106 ~Set(); | |
107 | |
108 void Insert(const Task& task); | |
109 | |
110 private: | |
111 friend class RasterWorkerPool; | |
112 | |
113 internal::WorkerPoolTask::Vector tasks_; | |
114 }; | |
115 | |
116 Task(); | |
117 ~Task(); | |
118 | |
119 // Returns true if Task is null (doesn't refer to anything). | |
120 bool is_null() const { return !internal_.get(); } | |
121 | |
122 // Returns the Task into an uninitialized state. | |
123 void Reset(); | |
124 | |
125 protected: | |
126 friend class RasterWorkerPool; | |
127 | |
128 explicit Task(internal::WorkerPoolTask* internal); | |
129 | |
130 scoped_refptr<internal::WorkerPoolTask> internal_; | |
131 }; | |
132 | |
133 class CC_EXPORT RasterTask { | |
134 public: | |
135 typedef base::Callback<void(const PicturePileImpl::Analysis& analysis, | |
136 bool was_canceled)> Reply; | |
137 | |
138 class CC_EXPORT Queue { | |
139 public: | |
140 Queue(); | |
141 ~Queue(); | |
142 | |
143 void Reset(); | |
144 void Append(const RasterTask& task, bool required_for_activation); | |
145 void Swap(Queue* other); | |
146 | |
147 size_t count() const { return tasks_.size(); } | |
148 size_t required_for_activation_count() const { | |
149 return required_for_activation_count_; | |
150 } | |
151 | |
152 private: | |
153 friend class RasterWorkerPool; | |
154 friend class DirectRasterWorkerPool; | |
155 | |
156 struct QueuedTask { | |
157 class TaskComparator { | |
158 public: | |
159 explicit TaskComparator(const internal::RasterWorkerPoolTask* task) | |
160 : task_(task) {} | |
161 | |
162 bool operator()(const QueuedTask& queued_task) const { | |
163 return queued_task.task == task_; | |
164 } | |
165 | |
166 private: | |
167 const internal::RasterWorkerPoolTask* task_; | |
168 }; | |
169 | |
170 typedef std::vector<QueuedTask> Vector; | |
171 | |
172 QueuedTask(internal::RasterWorkerPoolTask* task, | |
173 bool required_for_activation); | |
174 ~QueuedTask(); | |
175 | |
176 scoped_refptr<internal::RasterWorkerPoolTask> task; | |
177 bool required_for_activation; | |
178 }; | |
179 | |
180 QueuedTask::Vector tasks_; | |
181 size_t required_for_activation_count_; | |
182 }; | |
183 | |
184 RasterTask(); | |
185 ~RasterTask(); | |
186 | |
187 // Returns true if Task is null (doesn't refer to anything). | |
188 bool is_null() const { return !internal_.get(); } | |
189 | |
190 // Returns the Task into an uninitialized state. | |
191 void Reset(); | |
192 | |
193 protected: | |
194 friend class RasterWorkerPool; | |
195 | |
196 explicit RasterTask(internal::RasterWorkerPoolTask* internal); | |
197 | |
198 scoped_refptr<internal::RasterWorkerPoolTask> internal_; | |
199 }; | |
200 | |
201 virtual ~RasterWorkerPool(); | 135 virtual ~RasterWorkerPool(); |
202 | 136 |
203 static void SetNumRasterThreads(int num_threads); | 137 static void SetNumRasterThreads(int num_threads); |
204 static int GetNumRasterThreads(); | 138 static int GetNumRasterThreads(); |
205 | 139 |
206 static internal::TaskGraphRunner* GetTaskGraphRunner(); | 140 static internal::TaskGraphRunner* GetTaskGraphRunner(); |
207 | 141 |
208 static unsigned kOnDemandRasterTaskPriority; | 142 static unsigned kOnDemandRasterTaskPriority; |
209 static unsigned kRasterFinishedTaskPriority; | 143 static unsigned kRasterFinishedTaskPriority; |
210 static unsigned kRasterRequiredForActivationFinishedTaskPriority; | 144 static unsigned kRasterRequiredForActivationFinishedTaskPriority; |
211 static unsigned kRasterTaskPriorityBase; | 145 static unsigned kRasterTaskPriorityBase; |
212 | 146 |
213 // TODO(vmpstr): Figure out an elegant way to not pass this many parameters. | 147 // TODO(vmpstr): Figure out an elegant way to not pass this many parameters. |
214 static RasterTask CreateRasterTask( | 148 static scoped_refptr<internal::RasterWorkerPoolTask> CreateRasterTask( |
215 const Resource* resource, | 149 const Resource* resource, |
216 PicturePileImpl* picture_pile, | 150 PicturePileImpl* picture_pile, |
217 const gfx::Rect& content_rect, | 151 const gfx::Rect& content_rect, |
218 float contents_scale, | 152 float contents_scale, |
219 RasterMode raster_mode, | 153 RasterMode raster_mode, |
220 TileResolution tile_resolution, | 154 TileResolution tile_resolution, |
221 int layer_id, | 155 int layer_id, |
222 const void* tile_id, | 156 const void* tile_id, |
223 int source_frame_number, | 157 int source_frame_number, |
224 RenderingStatsInstrumentation* rendering_stats, | 158 RenderingStatsInstrumentation* rendering_stats, |
225 const RasterTask::Reply& reply, | 159 const base::Callback<void(const PicturePileImpl::Analysis&, bool)>& reply, |
226 Task::Set* dependencies, | 160 internal::WorkerPoolTask::Vector* dependencies, |
227 ContextProvider* context_provider); | 161 ContextProvider* context_provider); |
228 | 162 |
229 static Task CreateImageDecodeTask( | 163 static scoped_refptr<internal::WorkerPoolTask> CreateImageDecodeTask( |
230 SkPixelRef* pixel_ref, | 164 SkPixelRef* pixel_ref, |
231 int layer_id, | 165 int layer_id, |
232 RenderingStatsInstrumentation* rendering_stats, | 166 RenderingStatsInstrumentation* rendering_stats, |
233 const Task::Reply& reply); | 167 const base::Callback<void(bool was_canceled)>& reply); |
234 | 168 |
235 void SetClient(RasterWorkerPoolClient* client); | 169 void SetClient(RasterWorkerPoolClient* client); |
236 | 170 |
237 // Tells the worker pool to shutdown after canceling all previously | 171 // Tells the worker pool to shutdown after canceling all previously |
238 // scheduled tasks. Reply callbacks are still guaranteed to run. | 172 // scheduled tasks. Reply callbacks are still guaranteed to run. |
239 virtual void Shutdown(); | 173 virtual void Shutdown(); |
240 | 174 |
241 // Schedule running of raster tasks in |queue| and all dependencies. | 175 // Schedule running of raster tasks in |queue| and all dependencies. |
242 // Previously scheduled tasks that are no longer needed to run | 176 // Previously scheduled tasks that are no longer needed to run |
243 // raster tasks in |queue| will be canceled unless already running. | 177 // raster tasks in |queue| will be canceled unless already running. |
244 // Once scheduled, reply callbacks are guaranteed to run for all tasks | 178 // Once scheduled, reply callbacks are guaranteed to run for all tasks |
245 // even if they later get canceled by another call to ScheduleTasks(). | 179 // even if they later get canceled by another call to ScheduleTasks(). |
246 virtual void ScheduleTasks(RasterTask::Queue* queue) = 0; | 180 virtual void ScheduleTasks(RasterTaskQueue* queue) = 0; |
247 | 181 |
248 // Force a check for completed tasks. | 182 // Force a check for completed tasks. |
249 virtual void CheckForCompletedTasks() = 0; | 183 virtual void CheckForCompletedTasks() = 0; |
250 | 184 |
251 // Returns the target that needs to be used for raster task resources. | 185 // Returns the target that needs to be used for raster task resources. |
252 virtual unsigned GetResourceTarget() const = 0; | 186 virtual unsigned GetResourceTarget() const = 0; |
253 | 187 |
254 // Returns the format that needs to be used for raster task resources. | 188 // Returns the format that needs to be used for raster task resources. |
255 virtual ResourceFormat GetResourceFormat() const = 0; | 189 virtual ResourceFormat GetResourceFormat() const = 0; |
256 | 190 |
257 protected: | 191 protected: |
258 class RasterTaskQueueIterator { | |
259 public: | |
260 explicit RasterTaskQueueIterator(const RasterTask::Queue* queue) | |
261 : tasks_(&queue->tasks_), current_index_(0u) {} | |
262 ~RasterTaskQueueIterator() {} | |
263 | |
264 bool required_for_activation() const { | |
265 DCHECK_LT(current_index_, tasks_->size()); | |
266 return (*tasks_)[current_index_].required_for_activation; | |
267 } | |
268 | |
269 internal::RasterWorkerPoolTask* operator->() const { | |
270 DCHECK_LT(current_index_, tasks_->size()); | |
271 return (*tasks_)[current_index_].task.get(); | |
272 } | |
273 | |
274 internal::RasterWorkerPoolTask* operator*() const { | |
275 DCHECK_LT(current_index_, tasks_->size()); | |
276 return (*tasks_)[current_index_].task.get(); | |
277 } | |
278 | |
279 RasterTaskQueueIterator& operator++() { | |
280 DCHECK_LT(current_index_, tasks_->size()); | |
281 ++current_index_; | |
282 return *this; | |
283 } | |
284 | |
285 operator bool() const { return current_index_ < tasks_->size(); } | |
286 | |
287 private: | |
288 const RasterTask::Queue::QueuedTask::Vector* tasks_; | |
289 size_t current_index_; | |
290 }; | |
291 typedef std::vector<scoped_refptr<internal::WorkerPoolTask> > TaskVector; | 192 typedef std::vector<scoped_refptr<internal::WorkerPoolTask> > TaskVector; |
292 typedef std::deque<scoped_refptr<internal::WorkerPoolTask> > TaskDeque; | 193 typedef std::deque<scoped_refptr<internal::WorkerPoolTask> > TaskDeque; |
293 typedef std::vector<scoped_refptr<internal::RasterWorkerPoolTask> > | 194 typedef std::vector<scoped_refptr<internal::RasterWorkerPoolTask> > |
294 RasterTaskVector; | 195 RasterTaskVector; |
295 | 196 |
296 RasterWorkerPool(internal::TaskGraphRunner* task_graph_runner, | 197 RasterWorkerPool(internal::TaskGraphRunner* task_graph_runner, |
297 ResourceProvider* resource_provider); | 198 ResourceProvider* resource_provider); |
298 | 199 |
299 virtual void OnRasterTasksFinished() = 0; | 200 virtual void OnRasterTasksFinished() = 0; |
300 virtual void OnRasterTasksRequiredForActivationFinished() = 0; | 201 virtual void OnRasterTasksRequiredForActivationFinished() = 0; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 | 253 |
353 scoped_refptr<internal::WorkerPoolTask> raster_finished_task_; | 254 scoped_refptr<internal::WorkerPoolTask> raster_finished_task_; |
354 scoped_refptr<internal::WorkerPoolTask> | 255 scoped_refptr<internal::WorkerPoolTask> |
355 raster_required_for_activation_finished_task_; | 256 raster_required_for_activation_finished_task_; |
356 base::WeakPtrFactory<RasterWorkerPool> weak_ptr_factory_; | 257 base::WeakPtrFactory<RasterWorkerPool> weak_ptr_factory_; |
357 }; | 258 }; |
358 | 259 |
359 } // namespace cc | 260 } // namespace cc |
360 | 261 |
361 #endif // CC_RESOURCES_RASTER_WORKER_POOL_H_ | 262 #endif // CC_RESOURCES_RASTER_WORKER_POOL_H_ |
OLD | NEW |