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 23 matching lines...) Expand all Loading... | |
34 virtual void OnRasterCompleted(RasterWorkerPoolTask* task, | 34 virtual void OnRasterCompleted(RasterWorkerPoolTask* task, |
35 const PicturePileImpl::Analysis& analysis) = 0; | 35 const PicturePileImpl::Analysis& analysis) = 0; |
36 virtual void OnImageDecodeCompleted(WorkerPoolTask* task) = 0; | 36 virtual void OnImageDecodeCompleted(WorkerPoolTask* task) = 0; |
37 | 37 |
38 protected: | 38 protected: |
39 virtual ~WorkerPoolTaskClient() {} | 39 virtual ~WorkerPoolTaskClient() {} |
40 }; | 40 }; |
41 | 41 |
42 class CC_EXPORT WorkerPoolTask : public Task { | 42 class CC_EXPORT WorkerPoolTask : public Task { |
43 public: | 43 public: |
44 typedef std::vector<scoped_refptr<WorkerPoolTask> > Vector; | |
45 | |
44 virtual void ScheduleOnOriginThread(WorkerPoolTaskClient* client) = 0; | 46 virtual void ScheduleOnOriginThread(WorkerPoolTaskClient* client) = 0; |
47 virtual void RunOnOriginThread() = 0; | |
45 virtual void CompleteOnOriginThread(WorkerPoolTaskClient* client) = 0; | 48 virtual void CompleteOnOriginThread(WorkerPoolTaskClient* client) = 0; |
46 virtual void RunReplyOnOriginThread() = 0; | 49 virtual void RunReplyOnOriginThread() = 0; |
47 | 50 |
48 void WillSchedule(); | 51 void WillSchedule(); |
49 void DidSchedule(); | 52 void DidSchedule(); |
50 bool HasBeenScheduled() const; | 53 bool HasBeenScheduled() const; |
51 | 54 |
52 void WillComplete(); | 55 void WillComplete(); |
53 void DidComplete(); | 56 void DidComplete(); |
54 bool HasCompleted() const; | 57 bool HasCompleted() const; |
55 | 58 |
56 protected: | 59 protected: |
57 WorkerPoolTask(); | 60 WorkerPoolTask(); |
58 virtual ~WorkerPoolTask(); | 61 virtual ~WorkerPoolTask(); |
59 | 62 |
60 bool did_schedule_; | 63 bool did_schedule_; |
61 bool did_complete_; | 64 bool did_complete_; |
62 }; | 65 }; |
63 | 66 |
64 class CC_EXPORT RasterWorkerPoolTask : public WorkerPoolTask { | 67 class CC_EXPORT RasterWorkerPoolTask : public WorkerPoolTask { |
reveman
2014/02/14 16:11:53
should now be relatively easy to remove this class
| |
65 public: | 68 public: |
66 virtual void RunOnOriginThread(ResourceProvider* resource_provider, | |
67 ContextProvider* context_provider) = 0; | |
68 | |
69 const Resource* resource() const { return resource_; } | 69 const Resource* resource() const { return resource_; } |
70 const internal::Task::Vector& dependencies() const { return dependencies_; } | 70 const internal::WorkerPoolTask::Vector& dependencies() const { |
71 bool use_gpu_rasterization() const { return use_gpu_rasterization_; } | 71 return dependencies_; |
72 } | |
72 | 73 |
73 protected: | 74 protected: |
74 RasterWorkerPoolTask(const Resource* resource, | 75 RasterWorkerPoolTask(const Resource* resource, |
75 internal::Task::Vector* dependencies, | 76 internal::WorkerPoolTask::Vector* dependencies); |
76 bool use_gpu_rasterization); | |
77 virtual ~RasterWorkerPoolTask(); | 77 virtual ~RasterWorkerPoolTask(); |
78 | 78 |
79 private: | 79 private: |
80 const Resource* resource_; | 80 const Resource* resource_; |
81 Task::Vector dependencies_; | 81 WorkerPoolTask::Vector dependencies_; |
82 bool use_gpu_rasterization_; | |
83 }; | 82 }; |
84 | 83 |
85 } // namespace internal | 84 } // namespace internal |
86 | 85 |
87 class CC_EXPORT RasterWorkerPoolClient { | 86 class CC_EXPORT RasterWorkerPoolClient { |
88 public: | 87 public: |
89 virtual bool ShouldForceTasksRequiredForActivationToComplete() const = 0; | 88 virtual bool ShouldForceTasksRequiredForActivationToComplete() const = 0; |
90 virtual void DidFinishRunningTasks() = 0; | 89 virtual void DidFinishRunningTasks() = 0; |
91 virtual void DidFinishRunningTasksRequiredForActivation() = 0; | 90 virtual void DidFinishRunningTasksRequiredForActivation() = 0; |
92 | 91 |
93 protected: | 92 protected: |
94 virtual ~RasterWorkerPoolClient() {} | 93 virtual ~RasterWorkerPoolClient() {} |
95 }; | 94 }; |
96 | 95 |
96 struct CC_EXPORT RasterTaskQueue { | |
97 struct CC_EXPORT Task { | |
98 typedef std::vector<Task> Vector; | |
99 | |
100 Task(internal::RasterWorkerPoolTask* task, bool required_for_activation); | |
101 ~Task(); | |
102 | |
103 static bool IsRequiredForActivation(const Task& task) { | |
104 return task.required_for_activation; | |
105 } | |
106 | |
107 scoped_refptr<internal::RasterWorkerPoolTask> task; | |
108 bool required_for_activation; | |
109 }; | |
110 | |
111 RasterTaskQueue(); | |
112 ~RasterTaskQueue(); | |
113 | |
114 void Swap(RasterTaskQueue* other); | |
115 void Reset(); | |
116 | |
117 Task::Vector tasks; | |
118 size_t required_for_activation_count; | |
119 }; | |
120 | |
97 // A worker thread pool that runs raster tasks. | 121 // A worker thread pool that runs raster tasks. |
98 class CC_EXPORT RasterWorkerPool : public internal::WorkerPoolTaskClient { | 122 class CC_EXPORT RasterWorkerPool : public internal::WorkerPoolTaskClient { |
99 public: | 123 public: |
100 class CC_EXPORT Task { | |
101 public: | |
102 typedef base::Callback<void(bool was_canceled)> Reply; | |
103 | |
104 class CC_EXPORT Set { | |
105 public: | |
106 Set(); | |
107 ~Set(); | |
108 | |
109 void Insert(const Task& task); | |
110 | |
111 private: | |
112 friend class RasterWorkerPool; | |
113 | |
114 internal::Task::Vector tasks_; | |
115 }; | |
116 | |
117 Task(); | |
118 ~Task(); | |
119 | |
120 // Returns true if Task is null (doesn't refer to anything). | |
121 bool is_null() const { return !internal_.get(); } | |
122 | |
123 // Returns the Task into an uninitialized state. | |
124 void Reset(); | |
125 | |
126 protected: | |
127 friend class RasterWorkerPool; | |
128 | |
129 explicit Task(internal::WorkerPoolTask* internal); | |
130 | |
131 scoped_refptr<internal::WorkerPoolTask> internal_; | |
132 }; | |
133 | |
134 class CC_EXPORT RasterTask { | |
135 public: | |
136 typedef base::Callback<void(const PicturePileImpl::Analysis& analysis, | |
137 bool was_canceled)> Reply; | |
138 | |
139 class CC_EXPORT Queue { | |
140 public: | |
141 Queue(); | |
142 ~Queue(); | |
143 | |
144 void Reset(); | |
145 void Append(const RasterTask& task, bool required_for_activation); | |
146 void Swap(Queue* other); | |
147 | |
148 size_t count() const { return tasks_.size(); } | |
149 size_t required_for_activation_count() const { | |
150 return required_for_activation_count_; | |
151 } | |
152 | |
153 private: | |
154 friend class RasterWorkerPool; | |
155 | |
156 struct QueuedTask { | |
157 typedef std::vector<QueuedTask> Vector; | |
158 | |
159 QueuedTask(internal::RasterWorkerPoolTask* task, | |
160 bool required_for_activation); | |
161 ~QueuedTask(); | |
162 | |
163 scoped_refptr<internal::RasterWorkerPoolTask> task; | |
164 bool required_for_activation; | |
165 }; | |
166 | |
167 QueuedTask::Vector tasks_; | |
168 size_t required_for_activation_count_; | |
169 }; | |
170 | |
171 RasterTask(); | |
172 ~RasterTask(); | |
173 | |
174 // Returns true if Task is null (doesn't refer to anything). | |
175 bool is_null() const { return !internal_.get(); } | |
176 | |
177 // Returns the Task into an uninitialized state. | |
178 void Reset(); | |
179 | |
180 protected: | |
181 friend class RasterWorkerPool; | |
182 | |
183 explicit RasterTask(internal::RasterWorkerPoolTask* internal); | |
184 | |
185 scoped_refptr<internal::RasterWorkerPoolTask> internal_; | |
186 }; | |
187 | |
188 virtual ~RasterWorkerPool(); | 124 virtual ~RasterWorkerPool(); |
189 | 125 |
190 static void SetNumRasterThreads(int num_threads); | 126 static void SetNumRasterThreads(int num_threads); |
191 | |
192 static int GetNumRasterThreads(); | 127 static int GetNumRasterThreads(); |
193 | 128 |
194 static internal::TaskGraphRunner* GetTaskGraphRunner(); | 129 static internal::TaskGraphRunner* GetTaskGraphRunner(); |
195 | 130 |
196 static unsigned kOnDemandRasterTaskPriority; | 131 static unsigned kOnDemandRasterTaskPriority; |
197 static unsigned kRasterFinishedTaskPriority; | 132 static unsigned kRasterFinishedTaskPriority; |
198 static unsigned kRasterRequiredForActivationFinishedTaskPriority; | 133 static unsigned kRasterRequiredForActivationFinishedTaskPriority; |
199 static unsigned kRasterTaskPriorityBase; | 134 static unsigned kRasterTaskPriorityBase; |
200 | 135 |
201 // TODO(vmpstr): Figure out an elegant way to not pass this many parameters. | 136 // TODO(vmpstr): Figure out an elegant way to not pass this many parameters. |
202 static RasterTask CreateRasterTask( | 137 static scoped_refptr<internal::RasterWorkerPoolTask> CreateRasterTask( |
reveman
2014/02/14 16:11:53
Fyi, I'll remove this in follow up patch that make
vmpstr
2014/02/14 17:16:51
That would be awesome.
| |
203 const Resource* resource, | 138 const Resource* resource, |
204 PicturePileImpl* picture_pile, | 139 PicturePileImpl* picture_pile, |
205 const gfx::Rect& content_rect, | 140 const gfx::Rect& content_rect, |
206 float contents_scale, | 141 float contents_scale, |
207 RasterMode raster_mode, | 142 RasterMode raster_mode, |
208 TileResolution tile_resolution, | 143 TileResolution tile_resolution, |
209 int layer_id, | 144 int layer_id, |
210 const void* tile_id, | 145 const void* tile_id, |
211 int source_frame_number, | 146 int source_frame_number, |
212 bool use_gpu_rasterization, | |
213 RenderingStatsInstrumentation* rendering_stats, | 147 RenderingStatsInstrumentation* rendering_stats, |
214 const RasterTask::Reply& reply, | 148 const base::Callback<void(const PicturePileImpl::Analysis&, bool)>& reply, |
215 Task::Set* dependencies); | 149 internal::WorkerPoolTask::Vector* dependencies, |
150 ContextProvider* context_provider); | |
216 | 151 |
217 static Task CreateImageDecodeTask( | 152 static scoped_refptr<internal::WorkerPoolTask> CreateImageDecodeTask( |
218 SkPixelRef* pixel_ref, | 153 SkPixelRef* pixel_ref, |
219 int layer_id, | 154 int layer_id, |
220 RenderingStatsInstrumentation* rendering_stats, | 155 RenderingStatsInstrumentation* rendering_stats, |
221 const Task::Reply& reply); | 156 const base::Callback<void(bool was_canceled)>& reply); |
222 | 157 |
223 void SetClient(RasterWorkerPoolClient* client); | 158 void SetClient(RasterWorkerPoolClient* client); |
224 | 159 |
225 // Tells the worker pool to shutdown after canceling all previously | 160 // Tells the worker pool to shutdown after canceling all previously |
226 // scheduled tasks. Reply callbacks are still guaranteed to run. | 161 // scheduled tasks. Reply callbacks are still guaranteed to run. |
227 virtual void Shutdown(); | 162 virtual void Shutdown(); |
228 | 163 |
229 // Schedule running of raster tasks in |queue| and all dependencies. | 164 // Schedule running of raster tasks in |queue| and all dependencies. |
230 // Previously scheduled tasks that are no longer needed to run | 165 // Previously scheduled tasks that are no longer needed to run |
231 // raster tasks in |queue| will be canceled unless already running. | 166 // raster tasks in |queue| will be canceled unless already running. |
232 // Once scheduled, reply callbacks are guaranteed to run for all tasks | 167 // Once scheduled, reply callbacks are guaranteed to run for all tasks |
233 // even if they later get canceled by another call to ScheduleTasks(). | 168 // even if they later get canceled by another call to ScheduleTasks(). |
234 virtual void ScheduleTasks(RasterTask::Queue* queue) = 0; | 169 virtual void ScheduleTasks(RasterTaskQueue* queue) = 0; |
235 | 170 |
236 // Force a check for completed tasks. | 171 // Force a check for completed tasks. |
237 virtual void CheckForCompletedTasks() = 0; | 172 virtual void CheckForCompletedTasks() = 0; |
238 | 173 |
239 // Returns the target that needs to be used for raster task resources. | 174 // Returns the target that needs to be used for raster task resources. |
240 virtual unsigned GetResourceTarget() const = 0; | 175 virtual unsigned GetResourceTarget() const = 0; |
241 | 176 |
242 // Returns the format that needs to be used for raster task resources. | 177 // Returns the format that needs to be used for raster task resources. |
243 virtual ResourceFormat GetResourceFormat() const = 0; | 178 virtual ResourceFormat GetResourceFormat() const = 0; |
244 | 179 |
245 protected: | 180 protected: |
246 class RasterTaskQueueIterator { | 181 class RasterTaskQueueIterator { |
247 public: | 182 public: |
248 explicit RasterTaskQueueIterator(const RasterTask::Queue* queue) | 183 explicit RasterTaskQueueIterator(const RasterTaskQueue* queue) |
249 : tasks_(&queue->tasks_), current_index_(0u) {} | 184 : tasks_(&queue->tasks), current_index_(0u) {} |
250 ~RasterTaskQueueIterator() {} | 185 ~RasterTaskQueueIterator() {} |
251 | 186 |
252 bool required_for_activation() const { | 187 bool required_for_activation() const { |
253 DCHECK_LT(current_index_, tasks_->size()); | 188 DCHECK_LT(current_index_, tasks_->size()); |
254 return (*tasks_)[current_index_].required_for_activation; | 189 return (*tasks_)[current_index_].required_for_activation; |
255 } | 190 } |
256 | 191 |
257 internal::RasterWorkerPoolTask* operator->() const { | 192 internal::RasterWorkerPoolTask* operator->() const { |
258 DCHECK_LT(current_index_, tasks_->size()); | 193 DCHECK_LT(current_index_, tasks_->size()); |
259 return (*tasks_)[current_index_].task.get(); | 194 return (*tasks_)[current_index_].task.get(); |
260 } | 195 } |
261 | 196 |
262 internal::RasterWorkerPoolTask* operator*() const { | 197 internal::RasterWorkerPoolTask* operator*() const { |
263 DCHECK_LT(current_index_, tasks_->size()); | 198 DCHECK_LT(current_index_, tasks_->size()); |
264 return (*tasks_)[current_index_].task.get(); | 199 return (*tasks_)[current_index_].task.get(); |
265 } | 200 } |
266 | 201 |
267 RasterTaskQueueIterator& operator++() { | 202 RasterTaskQueueIterator& operator++() { |
268 DCHECK_LT(current_index_, tasks_->size()); | 203 DCHECK_LT(current_index_, tasks_->size()); |
269 ++current_index_; | 204 ++current_index_; |
270 return *this; | 205 return *this; |
271 } | 206 } |
272 | 207 |
273 operator bool() const { return current_index_ < tasks_->size(); } | 208 operator bool() const { return current_index_ < tasks_->size(); } |
274 | 209 |
275 private: | 210 private: |
276 const RasterTask::Queue::QueuedTask::Vector* tasks_; | 211 const RasterTaskQueue::Task::Vector* tasks_; |
277 size_t current_index_; | 212 size_t current_index_; |
278 }; | 213 }; |
279 typedef std::vector<scoped_refptr<internal::WorkerPoolTask> > TaskVector; | 214 typedef std::vector<scoped_refptr<internal::WorkerPoolTask> > TaskVector; |
280 typedef std::deque<scoped_refptr<internal::WorkerPoolTask> > TaskDeque; | 215 typedef std::deque<scoped_refptr<internal::WorkerPoolTask> > TaskDeque; |
281 typedef std::vector<scoped_refptr<internal::RasterWorkerPoolTask> > | 216 typedef std::vector<scoped_refptr<internal::RasterWorkerPoolTask> > |
282 RasterTaskVector; | 217 RasterTaskVector; |
283 | 218 |
284 RasterWorkerPool(internal::TaskGraphRunner* task_graph_runner, | 219 RasterWorkerPool(internal::TaskGraphRunner* task_graph_runner, |
285 ResourceProvider* resource_provider, | 220 ResourceProvider* resource_provider); |
286 ContextProvider* context_provider); | |
287 | 221 |
288 virtual void OnRasterTasksFinished() = 0; | 222 virtual void OnRasterTasksFinished() = 0; |
289 virtual void OnRasterTasksRequiredForActivationFinished() = 0; | 223 virtual void OnRasterTasksRequiredForActivationFinished() = 0; |
290 | 224 |
291 void SetTaskGraph(internal::TaskGraph* graph); | 225 void SetTaskGraph(internal::TaskGraph* graph); |
292 void CollectCompletedWorkerPoolTasks(internal::Task::Vector* completed_tasks); | 226 void CollectCompletedWorkerPoolTasks(internal::Task::Vector* completed_tasks); |
293 | 227 |
294 // Run raster tasks that use GPU on current thread. | |
295 void RunGpuRasterTasks(const RasterTaskVector& tasks); | |
296 void CheckForCompletedGpuRasterTasks(); | |
297 | |
298 RasterWorkerPoolClient* client() const { return client_; } | 228 RasterWorkerPoolClient* client() const { return client_; } |
299 ResourceProvider* resource_provider() const { return resource_provider_; } | 229 ResourceProvider* resource_provider() const { return resource_provider_; } |
300 ContextProvider* context_provider() const { return context_provider_; } | |
301 | 230 |
302 void set_raster_finished_task( | 231 void set_raster_finished_task( |
303 internal::WorkerPoolTask* raster_finished_task) { | 232 internal::WorkerPoolTask* raster_finished_task) { |
304 raster_finished_task_ = raster_finished_task; | 233 raster_finished_task_ = raster_finished_task; |
305 } | 234 } |
235 internal::WorkerPoolTask* raster_finished_task() const { | |
236 return raster_finished_task_.get(); | |
237 } | |
306 void set_raster_required_for_activation_finished_task( | 238 void set_raster_required_for_activation_finished_task( |
307 internal::WorkerPoolTask* raster_required_for_activation_finished_task) { | 239 internal::WorkerPoolTask* raster_required_for_activation_finished_task) { |
308 raster_required_for_activation_finished_task_ = | 240 raster_required_for_activation_finished_task_ = |
309 raster_required_for_activation_finished_task; | 241 raster_required_for_activation_finished_task; |
310 } | 242 } |
243 internal::WorkerPoolTask* raster_required_for_activation_finished_task() | |
244 const { | |
245 return raster_required_for_activation_finished_task_.get(); | |
246 } | |
311 | 247 |
312 scoped_refptr<internal::WorkerPoolTask> CreateRasterFinishedTask(); | 248 scoped_refptr<internal::WorkerPoolTask> CreateRasterFinishedTask(); |
313 scoped_refptr<internal::WorkerPoolTask> | 249 scoped_refptr<internal::WorkerPoolTask> |
314 CreateRasterRequiredForActivationFinishedTask( | 250 CreateRasterRequiredForActivationFinishedTask( |
315 size_t tasks_required_for_activation_count); | 251 size_t tasks_required_for_activation_count); |
316 | 252 |
317 scoped_ptr<base::Value> ScheduledStateAsValue() const; | 253 void RunTaskOnOriginThread(internal::WorkerPoolTask* task); |
318 | 254 |
319 static void InsertNodeForTask(internal::TaskGraph* graph, | 255 static void InsertNodeForTask(internal::TaskGraph* graph, |
320 internal::WorkerPoolTask* task, | 256 internal::WorkerPoolTask* task, |
321 unsigned priority, | 257 unsigned priority, |
322 size_t dependencies); | 258 size_t dependencies); |
323 | 259 |
324 static void InsertNodeForRasterTask( | 260 static void InsertNodeForRasterTask( |
325 internal::TaskGraph* graph, | 261 internal::TaskGraph* graph, |
326 internal::WorkerPoolTask* task, | 262 internal::WorkerPoolTask* task, |
327 const internal::Task::Vector& decode_tasks, | 263 const internal::WorkerPoolTask::Vector& decode_tasks, |
328 unsigned priority); | 264 unsigned priority); |
329 | 265 |
330 private: | 266 private: |
331 void OnRasterFinished(const internal::WorkerPoolTask* source); | 267 void OnRasterFinished(const internal::WorkerPoolTask* source); |
332 void OnRasterRequiredForActivationFinished( | 268 void OnRasterRequiredForActivationFinished( |
333 const internal::WorkerPoolTask* source); | 269 const internal::WorkerPoolTask* source); |
334 | 270 |
335 internal::TaskGraphRunner* task_graph_runner_; | 271 internal::TaskGraphRunner* task_graph_runner_; |
336 internal::NamespaceToken namespace_token_; | 272 internal::NamespaceToken namespace_token_; |
337 RasterWorkerPoolClient* client_; | 273 RasterWorkerPoolClient* client_; |
338 ResourceProvider* resource_provider_; | 274 ResourceProvider* resource_provider_; |
339 ContextProvider* context_provider_; | |
340 TaskDeque completed_gpu_raster_tasks_; | |
341 | 275 |
342 scoped_refptr<internal::WorkerPoolTask> raster_finished_task_; | 276 scoped_refptr<internal::WorkerPoolTask> raster_finished_task_; |
343 scoped_refptr<internal::WorkerPoolTask> | 277 scoped_refptr<internal::WorkerPoolTask> |
344 raster_required_for_activation_finished_task_; | 278 raster_required_for_activation_finished_task_; |
345 base::WeakPtrFactory<RasterWorkerPool> weak_ptr_factory_; | 279 base::WeakPtrFactory<RasterWorkerPool> weak_ptr_factory_; |
346 }; | 280 }; |
347 | 281 |
348 } // namespace cc | 282 } // namespace cc |
349 | 283 |
350 #endif // CC_RESOURCES_RASTER_WORKER_POOL_H_ | 284 #endif // CC_RESOURCES_RASTER_WORKER_POOL_H_ |
OLD | NEW |