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 <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
(...skipping 18 matching lines...) Expand all Loading... | |
29 public: | 29 public: |
30 typedef std::vector<scoped_refptr<WorkerPoolTask> > TaskVector; | 30 typedef std::vector<scoped_refptr<WorkerPoolTask> > TaskVector; |
31 | 31 |
32 // Returns true if |buffer| was written to. False indicate that | 32 // Returns true if |buffer| was written to. False indicate that |
33 // the content of |buffer| is undefined and the resource doesn't | 33 // the content of |buffer| is undefined and the resource doesn't |
34 // need to be initialized. | 34 // need to be initialized. |
35 virtual bool RunOnWorkerThread(unsigned thread_index, | 35 virtual bool RunOnWorkerThread(unsigned thread_index, |
36 void* buffer, | 36 void* buffer, |
37 gfx::Size size, | 37 gfx::Size size, |
38 int stride) = 0; | 38 int stride) = 0; |
39 virtual void RunOnOriginThread() = 0; | |
39 virtual void CompleteOnOriginThread() = 0; | 40 virtual void CompleteOnOriginThread() = 0; |
40 | 41 |
41 void DidRun(bool was_canceled); | 42 void DidRun(bool was_canceled); |
42 bool HasFinishedRunning() const; | 43 bool HasFinishedRunning() const; |
43 bool WasCanceled() const; | 44 bool WasCanceled() const; |
44 void WillComplete(); | 45 void WillComplete(); |
45 void DidComplete(); | 46 void DidComplete(); |
46 bool HasCompleted() const; | 47 bool HasCompleted() const; |
47 | 48 |
48 const Resource* resource() const { return resource_; } | 49 const Resource* resource() const { return resource_; } |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 Queue(); | 138 Queue(); |
138 ~Queue(); | 139 ~Queue(); |
139 | 140 |
140 void Append(const RasterTask& task, bool required_for_activation); | 141 void Append(const RasterTask& task, bool required_for_activation); |
141 | 142 |
142 private: | 143 private: |
143 friend class RasterWorkerPool; | 144 friend class RasterWorkerPool; |
144 | 145 |
145 typedef std::vector<scoped_refptr<internal::RasterWorkerPoolTask> > | 146 typedef std::vector<scoped_refptr<internal::RasterWorkerPoolTask> > |
146 TaskVector; | 147 TaskVector; |
148 typedef base::hash_set<internal::RasterWorkerPoolTask*> TaskSet; | |
149 TaskVector origin_thread_tasks_; | |
reveman
2013/12/17 00:28:48
Maybe we should put all tasks in |tasks_| for now
alokp
2013/12/17 22:12:15
Done.
| |
150 // Worker thread tasks. | |
147 TaskVector tasks_; | 151 TaskVector tasks_; |
148 typedef base::hash_set<internal::RasterWorkerPoolTask*> TaskSet; | |
149 TaskSet tasks_required_for_activation_; | 152 TaskSet tasks_required_for_activation_; |
150 }; | 153 }; |
151 | 154 |
152 RasterTask(); | 155 RasterTask(); |
153 ~RasterTask(); | 156 ~RasterTask(); |
154 | 157 |
155 // Returns true if Task is null (doesn't refer to anything). | 158 // Returns true if Task is null (doesn't refer to anything). |
156 bool is_null() const { return !internal_.get(); } | 159 bool is_null() const { return !internal_.get(); } |
157 | 160 |
158 // Returns the Task into an uninitialized state. | 161 // Returns the Task into an uninitialized state. |
159 void Reset(); | 162 void Reset(); |
160 | 163 |
161 protected: | 164 protected: |
162 friend class RasterWorkerPool; | 165 friend class RasterWorkerPool; |
163 friend class RasterWorkerPoolTest; | 166 friend class RasterWorkerPoolTest; |
164 | 167 |
165 explicit RasterTask(internal::RasterWorkerPoolTask* internal); | 168 explicit RasterTask(internal::RasterWorkerPoolTask* internal, |
169 bool must_run_on_origin_thread); | |
166 | 170 |
167 scoped_refptr<internal::RasterWorkerPoolTask> internal_; | 171 scoped_refptr<internal::RasterWorkerPoolTask> internal_; |
172 // True if this task must be run on origin thread, | |
173 // not on a worker thread. | |
174 bool must_run_on_origin_thread_; | |
reveman
2013/12/17 00:28:48
Why must_run_on_origin_thread here but use_gpu_ras
alokp
2013/12/17 22:12:15
Done.
| |
168 }; | 175 }; |
169 | 176 |
170 virtual ~RasterWorkerPool(); | 177 virtual ~RasterWorkerPool(); |
171 | 178 |
172 void SetClient(RasterWorkerPoolClient* client); | 179 void SetClient(RasterWorkerPoolClient* client); |
173 | 180 |
174 // Tells the worker pool to shutdown after canceling all previously | 181 // Tells the worker pool to shutdown after canceling all previously |
175 // scheduled tasks. Reply callbacks are still guaranteed to run. | 182 // scheduled tasks. Reply callbacks are still guaranteed to run. |
176 virtual void Shutdown() OVERRIDE; | 183 virtual void Shutdown() OVERRIDE; |
177 | 184 |
178 // Schedule running of raster tasks in |queue| and all dependencies. | 185 // Schedule running of raster tasks in |queue| and all dependencies. |
179 // Previously scheduled tasks that are no longer needed to run | 186 // Previously scheduled tasks that are no longer needed to run |
180 // raster tasks in |queue| will be canceled unless already running. | 187 // raster tasks in |queue| will be canceled unless already running. |
181 // Once scheduled, reply callbacks are guaranteed to run for all tasks | 188 // Once scheduled, reply callbacks are guaranteed to run for all tasks |
182 // even if they later get canceled by another call to ScheduleTasks(). | 189 // even if they later get canceled by another call to ScheduleTasks(). |
183 virtual void ScheduleTasks(RasterTask::Queue* queue) = 0; | 190 virtual void ScheduleTasks(RasterTask::Queue* queue) = 0; |
184 | 191 |
185 // Returns the target that needs to be used for raster task resources. | 192 // Returns the target that needs to be used for raster task resources. |
186 virtual GLenum GetResourceTarget() const = 0; | 193 virtual GLenum GetResourceTarget() const = 0; |
187 | 194 |
188 // Returns the format that needs to be used for raster task resources. | 195 // Returns the format that needs to be used for raster task resources. |
189 virtual ResourceFormat GetResourceFormat() const = 0; | 196 virtual ResourceFormat GetResourceFormat() const = 0; |
190 | 197 |
191 // TODO(vmpstr): Figure out an elegant way to not pass this many parameters. | 198 // TODO(vmpstr): Figure out an elegant way to not pass this many parameters. |
192 static RasterTask CreateRasterTask( | 199 RasterTask CreateRasterTask( |
193 const Resource* resource, | 200 const Resource* resource, |
194 PicturePileImpl* picture_pile, | 201 PicturePileImpl* picture_pile, |
195 gfx::Rect content_rect, | 202 gfx::Rect content_rect, |
196 float contents_scale, | 203 float contents_scale, |
197 RasterMode raster_mode, | 204 RasterMode raster_mode, |
198 TileResolution tile_resolution, | 205 TileResolution tile_resolution, |
199 int layer_id, | 206 int layer_id, |
200 const void* tile_id, | 207 const void* tile_id, |
201 int source_frame_number, | 208 int source_frame_number, |
209 bool use_gpu_rasterization, | |
202 RenderingStatsInstrumentation* rendering_stats, | 210 RenderingStatsInstrumentation* rendering_stats, |
203 const RasterTask::Reply& reply, | 211 const RasterTask::Reply& reply, |
204 Task::Set* dependencies); | 212 Task::Set* dependencies); |
205 | 213 |
206 static Task CreateImageDecodeTask( | 214 static Task CreateImageDecodeTask( |
207 skia::LazyPixelRef* pixel_ref, | 215 skia::LazyPixelRef* pixel_ref, |
208 int layer_id, | 216 int layer_id, |
209 RenderingStatsInstrumentation* stats_instrumentation, | 217 RenderingStatsInstrumentation* stats_instrumentation, |
210 const Task::Reply& reply); | 218 const Task::Reply& reply); |
211 | 219 |
212 protected: | 220 protected: |
213 typedef std::vector<scoped_refptr<internal::WorkerPoolTask> > TaskVector; | 221 typedef std::vector<scoped_refptr<internal::WorkerPoolTask> > TaskVector; |
214 typedef std::vector<scoped_refptr<internal::RasterWorkerPoolTask> > | 222 typedef std::vector<scoped_refptr<internal::RasterWorkerPoolTask> > |
215 RasterTaskVector; | 223 RasterTaskVector; |
216 typedef base::hash_set<internal::RasterWorkerPoolTask*> RasterTaskSet; | 224 typedef base::hash_set<internal::RasterWorkerPoolTask*> RasterTaskSet; |
217 typedef internal::RasterWorkerPoolTask* TaskMapKey; | 225 typedef internal::RasterWorkerPoolTask* TaskMapKey; |
218 typedef base::hash_map<TaskMapKey, | 226 typedef base::hash_map<TaskMapKey, |
219 scoped_refptr<internal::WorkerPoolTask> > TaskMap; | 227 scoped_refptr<internal::WorkerPoolTask> > TaskMap; |
220 | 228 |
221 RasterWorkerPool(ResourceProvider* resource_provider, size_t num_threads); | 229 RasterWorkerPool(ResourceProvider* resource_provider, |
230 ContextProvider* context_provider, | |
231 size_t num_threads); | |
222 | 232 |
223 virtual void OnRasterTasksFinished() = 0; | 233 virtual void OnRasterTasksFinished() = 0; |
224 virtual void OnRasterTasksRequiredForActivationFinished() = 0; | 234 virtual void OnRasterTasksRequiredForActivationFinished() = 0; |
225 | 235 |
236 void CompleteOriginThreadTasks(RasterTask::Queue* queue); | |
reveman
2013/12/17 00:28:48
Do you have to pass a RasterTask::Queue* to this f
alokp
2013/12/17 22:12:15
Done.
| |
226 void SetRasterTasks(RasterTask::Queue* queue); | 237 void SetRasterTasks(RasterTask::Queue* queue); |
227 bool IsRasterTaskRequiredForActivation( | 238 bool IsRasterTaskRequiredForActivation( |
228 internal::RasterWorkerPoolTask* task) const; | 239 internal::RasterWorkerPoolTask* task) const; |
229 | 240 |
230 RasterWorkerPoolClient* client() const { return client_; } | 241 RasterWorkerPoolClient* client() const { return client_; } |
231 ResourceProvider* resource_provider() const { return resource_provider_; } | 242 ResourceProvider* resource_provider() const { return resource_provider_; } |
243 ContextProvider* context_provider() const { return context_provider_; } | |
232 const RasterTaskVector& raster_tasks() const { return raster_tasks_; } | 244 const RasterTaskVector& raster_tasks() const { return raster_tasks_; } |
233 const RasterTaskSet& raster_tasks_required_for_activation() const { | 245 const RasterTaskSet& raster_tasks_required_for_activation() const { |
234 return raster_tasks_required_for_activation_; | 246 return raster_tasks_required_for_activation_; |
235 } | 247 } |
236 void set_raster_finished_task( | 248 void set_raster_finished_task( |
237 scoped_refptr<internal::WorkerPoolTask> raster_finished_task) { | 249 scoped_refptr<internal::WorkerPoolTask> raster_finished_task) { |
238 raster_finished_task_ = raster_finished_task; | 250 raster_finished_task_ = raster_finished_task; |
239 } | 251 } |
240 void set_raster_required_for_activation_finished_task( | 252 void set_raster_required_for_activation_finished_task( |
241 scoped_refptr<internal::WorkerPoolTask> | 253 scoped_refptr<internal::WorkerPoolTask> |
(...skipping 19 matching lines...) Expand all Loading... | |
261 unsigned priority, | 273 unsigned priority, |
262 TaskGraph* graph); | 274 TaskGraph* graph); |
263 | 275 |
264 private: | 276 private: |
265 void OnRasterFinished(const internal::WorkerPoolTask* source); | 277 void OnRasterFinished(const internal::WorkerPoolTask* source); |
266 void OnRasterRequiredForActivationFinished( | 278 void OnRasterRequiredForActivationFinished( |
267 const internal::WorkerPoolTask* source); | 279 const internal::WorkerPoolTask* source); |
268 | 280 |
269 RasterWorkerPoolClient* client_; | 281 RasterWorkerPoolClient* client_; |
270 ResourceProvider* resource_provider_; | 282 ResourceProvider* resource_provider_; |
283 ContextProvider* context_provider_; | |
271 RasterTask::Queue::TaskVector raster_tasks_; | 284 RasterTask::Queue::TaskVector raster_tasks_; |
272 RasterTask::Queue::TaskSet raster_tasks_required_for_activation_; | 285 RasterTask::Queue::TaskSet raster_tasks_required_for_activation_; |
273 | 286 |
274 scoped_refptr<internal::WorkerPoolTask> raster_finished_task_; | 287 scoped_refptr<internal::WorkerPoolTask> raster_finished_task_; |
275 scoped_refptr<internal::WorkerPoolTask> | 288 scoped_refptr<internal::WorkerPoolTask> |
276 raster_required_for_activation_finished_task_; | 289 raster_required_for_activation_finished_task_; |
277 base::WeakPtrFactory<RasterWorkerPool> weak_ptr_factory_; | 290 base::WeakPtrFactory<RasterWorkerPool> weak_ptr_factory_; |
278 }; | 291 }; |
279 | 292 |
280 } // namespace cc | 293 } // namespace cc |
281 | 294 |
282 #endif // CC_RESOURCES_RASTER_WORKER_POOL_H_ | 295 #endif // CC_RESOURCES_RASTER_WORKER_POOL_H_ |
OLD | NEW |