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 |
11 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.h" |
12 #include "cc/debug/rendering_stats_instrumentation.h" | 12 #include "cc/debug/rendering_stats_instrumentation.h" |
13 #include "cc/resources/picture_pile_impl.h" | 13 #include "cc/resources/picture_pile_impl.h" |
14 #include "cc/resources/raster_mode.h" | 14 #include "cc/resources/raster_mode.h" |
15 #include "cc/resources/resource.h" | 15 #include "cc/resources/resource_format.h" |
16 #include "cc/resources/resource_provider.h" | 16 #include "cc/resources/task_graph_runner.h" |
17 #include "cc/resources/tile_priority.h" | 17 #include "cc/resources/tile_priority.h" |
18 #include "cc/resources/worker_pool.h" | |
19 #include "third_party/khronos/GLES2/gl2.h" | |
20 | 18 |
21 class SkPixelRef; | 19 class SkPixelRef; |
22 | 20 |
23 namespace cc { | 21 namespace cc { |
22 | |
23 class ContextProvider; | |
24 class Resource; | |
25 class ResourceProvider; | |
26 | |
24 namespace internal { | 27 namespace internal { |
25 | 28 |
29 class CC_EXPORT WorkerPoolTask : public Task { | |
vmpstr
2014/01/21 18:14:04
Do you think it's worth it to just merge the *Comp
alokp
2014/01/21 18:42:50
I agree. If Complete is the only extra, it seems w
reveman
2014/01/21 19:51:32
The raster tasks passed to the TaskGraphRunner by
vmpstr
2014/01/21 20:30:43
Right... I forgot about the uploads in PBRWP.
| |
30 public: | |
31 virtual void CompleteOnOriginThread() = 0; | |
32 | |
33 void WillComplete(); | |
34 void DidComplete(); | |
35 bool HasCompleted() const; | |
36 | |
37 protected: | |
38 WorkerPoolTask(); | |
39 virtual ~WorkerPoolTask(); | |
40 | |
41 private: | |
42 bool did_complete_; | |
43 }; | |
44 | |
26 class CC_EXPORT RasterWorkerPoolTask | 45 class CC_EXPORT RasterWorkerPoolTask |
27 : public base::RefCounted<RasterWorkerPoolTask> { | 46 : public base::RefCounted<RasterWorkerPoolTask> { |
28 public: | 47 public: |
29 typedef std::vector<scoped_refptr<WorkerPoolTask> > TaskVector; | |
30 | |
31 // Returns true if |buffer| was written to. False indicate that | 48 // Returns true if |buffer| was written to. False indicate that |
32 // the content of |buffer| is undefined and the resource doesn't | 49 // the content of |buffer| is undefined and the resource doesn't |
33 // need to be initialized. | 50 // need to be initialized. |
34 virtual bool RunOnWorkerThread(unsigned thread_index, | 51 virtual bool RunOnWorkerThread(unsigned thread_index, |
35 void* buffer, | 52 void* buffer, |
36 gfx::Size size, | 53 gfx::Size size, |
37 int stride) = 0; | 54 int stride) = 0; |
38 virtual void RunOnOriginThread(ResourceProvider* resource_provider, | 55 virtual void RunOnOriginThread(ResourceProvider* resource_provider, |
39 ContextProvider* context_provider) = 0; | 56 ContextProvider* context_provider) = 0; |
40 virtual void CompleteOnOriginThread() = 0; | 57 virtual void CompleteOnOriginThread() = 0; |
41 | 58 |
42 void DidRun(bool was_canceled); | 59 void DidRun(bool was_canceled); |
43 bool HasFinishedRunning() const; | 60 bool HasFinishedRunning() const; |
44 bool WasCanceled() const; | 61 bool WasCanceled() const; |
45 void WillComplete(); | 62 void WillComplete(); |
46 void DidComplete(); | 63 void DidComplete(); |
47 bool HasCompleted() const; | 64 bool HasCompleted() const; |
48 | 65 |
49 const Resource* resource() const { return resource_; } | 66 const Resource* resource() const { return resource_; } |
50 const TaskVector& dependencies() const { return dependencies_; } | 67 const internal::Task::Vector& dependencies() const { return dependencies_; } |
sohanjg
2014/01/21 09:41:08
How is it helpful to change WorkerPoolTask to Task
reveman
2014/01/21 15:37:48
First, there's no base WorkerPool class anymore so
| |
51 bool use_gpu_rasterization() const { return use_gpu_rasterization_; } | 68 bool use_gpu_rasterization() const { return use_gpu_rasterization_; } |
52 | 69 |
53 protected: | 70 protected: |
54 friend class base::RefCounted<RasterWorkerPoolTask>; | 71 friend class base::RefCounted<RasterWorkerPoolTask>; |
55 | 72 |
56 RasterWorkerPoolTask(const Resource* resource, | 73 RasterWorkerPoolTask(const Resource* resource, |
57 TaskVector* dependencies, | 74 internal::Task::Vector* dependencies, |
58 bool use_gpu_rasterization); | 75 bool use_gpu_rasterization); |
59 virtual ~RasterWorkerPoolTask(); | 76 virtual ~RasterWorkerPoolTask(); |
60 | 77 |
61 private: | 78 private: |
62 bool did_run_; | 79 bool did_run_; |
63 bool did_complete_; | 80 bool did_complete_; |
64 bool was_canceled_; | 81 bool was_canceled_; |
65 const Resource* resource_; | 82 const Resource* resource_; |
66 TaskVector dependencies_; | 83 Task::Vector dependencies_; |
67 bool use_gpu_rasterization_; | 84 bool use_gpu_rasterization_; |
68 }; | 85 }; |
69 | 86 |
70 } // namespace internal | 87 } // namespace internal |
71 } // namespace cc | 88 } // namespace cc |
72 | 89 |
73 #if defined(COMPILER_GCC) | 90 #if defined(COMPILER_GCC) |
74 namespace BASE_HASH_NAMESPACE { | 91 namespace BASE_HASH_NAMESPACE { |
75 template <> struct hash<cc::internal::RasterWorkerPoolTask*> { | 92 template <> struct hash<cc::internal::RasterWorkerPoolTask*> { |
76 size_t operator()(cc::internal::RasterWorkerPoolTask* ptr) const { | 93 size_t operator()(cc::internal::RasterWorkerPoolTask* ptr) const { |
77 return hash<size_t>()(reinterpret_cast<size_t>(ptr)); | 94 return hash<size_t>()(reinterpret_cast<size_t>(ptr)); |
78 } | 95 } |
79 }; | 96 }; |
80 } // namespace BASE_HASH_NAMESPACE | 97 } // namespace BASE_HASH_NAMESPACE |
81 #endif // COMPILER | 98 #endif // COMPILER |
82 | 99 |
83 namespace cc { | 100 namespace cc { |
84 | 101 |
85 class CC_EXPORT RasterWorkerPoolClient { | 102 class CC_EXPORT RasterWorkerPoolClient { |
86 public: | 103 public: |
87 virtual bool ShouldForceTasksRequiredForActivationToComplete() const = 0; | 104 virtual bool ShouldForceTasksRequiredForActivationToComplete() const = 0; |
88 virtual void DidFinishRunningTasks() = 0; | 105 virtual void DidFinishRunningTasks() = 0; |
89 virtual void DidFinishRunningTasksRequiredForActivation() = 0; | 106 virtual void DidFinishRunningTasksRequiredForActivation() = 0; |
90 | 107 |
91 protected: | 108 protected: |
92 virtual ~RasterWorkerPoolClient() {} | 109 virtual ~RasterWorkerPoolClient() {} |
93 }; | 110 }; |
94 | 111 |
95 // A worker thread pool that runs raster tasks. | 112 // A worker thread pool that runs raster tasks. |
96 class CC_EXPORT RasterWorkerPool : public WorkerPool { | 113 class CC_EXPORT RasterWorkerPool { |
97 public: | 114 public: |
98 class CC_EXPORT Task { | 115 class CC_EXPORT Task { |
99 public: | 116 public: |
100 typedef base::Callback<void(bool was_canceled)> Reply; | 117 typedef base::Callback<void(bool was_canceled)> Reply; |
101 | 118 |
102 class CC_EXPORT Set { | 119 class CC_EXPORT Set { |
103 public: | 120 public: |
104 Set(); | 121 Set(); |
105 ~Set(); | 122 ~Set(); |
106 | 123 |
107 void Insert(const Task& task); | 124 void Insert(const Task& task); |
108 | 125 |
109 private: | 126 private: |
110 friend class RasterWorkerPool; | 127 friend class RasterWorkerPool; |
111 friend class RasterWorkerPoolTest; | 128 friend class RasterWorkerPoolTest; |
112 | 129 |
113 typedef internal::RasterWorkerPoolTask::TaskVector TaskVector; | 130 internal::Task::Vector tasks_; |
sohanjg
2014/01/21 09:41:08
And here from RasterWorkerPoolTask to Task ?
reveman
2014/01/21 15:37:48
Type didn't change. Just removed confusing typedef
| |
114 TaskVector tasks_; | |
115 }; | 131 }; |
116 | 132 |
117 Task(); | 133 Task(); |
118 ~Task(); | 134 ~Task(); |
119 | 135 |
120 // Returns true if Task is null (doesn't refer to anything). | 136 // Returns true if Task is null (doesn't refer to anything). |
121 bool is_null() const { return !internal_.get(); } | 137 bool is_null() const { return !internal_.get(); } |
122 | 138 |
123 // Returns the Task into an uninitialized state. | 139 // Returns the Task into an uninitialized state. |
124 void Reset(); | 140 void Reset(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 friend class RasterWorkerPool; | 183 friend class RasterWorkerPool; |
168 friend class RasterWorkerPoolTest; | 184 friend class RasterWorkerPoolTest; |
169 | 185 |
170 explicit RasterTask(internal::RasterWorkerPoolTask* internal); | 186 explicit RasterTask(internal::RasterWorkerPoolTask* internal); |
171 | 187 |
172 scoped_refptr<internal::RasterWorkerPoolTask> internal_; | 188 scoped_refptr<internal::RasterWorkerPoolTask> internal_; |
173 }; | 189 }; |
174 | 190 |
175 virtual ~RasterWorkerPool(); | 191 virtual ~RasterWorkerPool(); |
176 | 192 |
177 void SetClient(RasterWorkerPoolClient* client); | 193 static void SetNumRasterThreads(int num_threads); |
178 | 194 |
179 // Overidden from WorkerPool: | 195 static int GetNumRasterThreads(); |
180 virtual void Shutdown() OVERRIDE; | |
181 | |
182 // Schedule running of raster tasks in |queue| and all dependencies. | |
183 // Previously scheduled tasks that are no longer needed to run | |
184 // raster tasks in |queue| will be canceled unless already running. | |
185 // Once scheduled, reply callbacks are guaranteed to run for all tasks | |
186 // even if they later get canceled by another call to ScheduleTasks(). | |
187 virtual void ScheduleTasks(RasterTask::Queue* queue) = 0; | |
188 | |
189 // Returns the target that needs to be used for raster task resources. | |
190 virtual GLenum GetResourceTarget() const = 0; | |
191 | |
192 // Returns the format that needs to be used for raster task resources. | |
193 virtual ResourceFormat GetResourceFormat() const = 0; | |
194 | |
195 // Force a check for completed raster tasks. | |
196 // Calls completion callbacks on completed tasks. | |
197 virtual void CheckForCompletedTasks(); | |
198 | 196 |
199 // TODO(vmpstr): Figure out an elegant way to not pass this many parameters. | 197 // TODO(vmpstr): Figure out an elegant way to not pass this many parameters. |
200 static RasterTask CreateRasterTask( | 198 static RasterTask CreateRasterTask( |
201 const Resource* resource, | 199 const Resource* resource, |
202 PicturePileImpl* picture_pile, | 200 PicturePileImpl* picture_pile, |
203 const gfx::Rect& content_rect, | 201 const gfx::Rect& content_rect, |
204 float contents_scale, | 202 float contents_scale, |
205 RasterMode raster_mode, | 203 RasterMode raster_mode, |
206 TileResolution tile_resolution, | 204 TileResolution tile_resolution, |
207 int layer_id, | 205 int layer_id, |
208 const void* tile_id, | 206 const void* tile_id, |
209 int source_frame_number, | 207 int source_frame_number, |
210 bool use_gpu_rasterization, | 208 bool use_gpu_rasterization, |
211 RenderingStatsInstrumentation* rendering_stats, | 209 RenderingStatsInstrumentation* rendering_stats, |
212 const RasterTask::Reply& reply, | 210 const RasterTask::Reply& reply, |
213 Task::Set* dependencies); | 211 Task::Set* dependencies); |
214 | 212 |
215 static Task CreateImageDecodeTask( | 213 static Task CreateImageDecodeTask( |
216 SkPixelRef* pixel_ref, | 214 SkPixelRef* pixel_ref, |
217 int layer_id, | 215 int layer_id, |
218 RenderingStatsInstrumentation* stats_instrumentation, | 216 RenderingStatsInstrumentation* stats_instrumentation, |
219 const Task::Reply& reply); | 217 const Task::Reply& reply); |
220 | 218 |
219 void SetClient(RasterWorkerPoolClient* client); | |
220 | |
221 // Tells the worker pool to shutdown after canceling all previously | |
222 // scheduled tasks. Reply callbacks are still guaranteed to run. | |
223 virtual void Shutdown(); | |
224 | |
225 // Schedule running of raster tasks in |queue| and all dependencies. | |
226 // Previously scheduled tasks that are no longer needed to run | |
227 // raster tasks in |queue| will be canceled unless already running. | |
228 // Once scheduled, reply callbacks are guaranteed to run for all tasks | |
229 // even if they later get canceled by another call to ScheduleTasks(). | |
230 virtual void ScheduleTasks(RasterTask::Queue* queue) = 0; | |
231 | |
232 // Force a check for completed tasks. | |
233 virtual void CheckForCompletedTasks(); | |
234 | |
235 // Returns the target that needs to be used for raster task resources. | |
236 virtual unsigned GetResourceTarget() const = 0; | |
237 | |
238 // Returns the format that needs to be used for raster task resources. | |
239 virtual ResourceFormat GetResourceFormat() const = 0; | |
240 | |
221 protected: | 241 protected: |
242 typedef internal::TaskGraphRunner::TaskGraph TaskGraph; | |
222 typedef std::vector<scoped_refptr<internal::WorkerPoolTask> > TaskVector; | 243 typedef std::vector<scoped_refptr<internal::WorkerPoolTask> > TaskVector; |
223 typedef std::vector<scoped_refptr<internal::RasterWorkerPoolTask> > | 244 typedef std::vector<scoped_refptr<internal::RasterWorkerPoolTask> > |
224 RasterTaskVector; | 245 RasterTaskVector; |
225 typedef std::deque<scoped_refptr<internal::RasterWorkerPoolTask> > | 246 typedef std::deque<scoped_refptr<internal::RasterWorkerPoolTask> > |
226 RasterTaskDeque; | 247 RasterTaskDeque; |
227 typedef base::hash_set<internal::RasterWorkerPoolTask*> RasterTaskSet; | 248 typedef base::hash_set<internal::RasterWorkerPoolTask*> RasterTaskSet; |
228 typedef internal::RasterWorkerPoolTask* TaskMapKey; | 249 typedef internal::RasterWorkerPoolTask* TaskMapKey; |
229 typedef base::hash_map<TaskMapKey, | 250 typedef base::hash_map<TaskMapKey, scoped_refptr<internal::WorkerPoolTask> > |
230 scoped_refptr<internal::WorkerPoolTask> > TaskMap; | 251 TaskMap; |
231 | 252 |
232 RasterWorkerPool(ResourceProvider* resource_provider, | 253 RasterWorkerPool(ResourceProvider* resource_provider, |
233 ContextProvider* context_provider); | 254 ContextProvider* context_provider); |
234 | 255 |
235 virtual void OnRasterTasksFinished() = 0; | 256 virtual void OnRasterTasksFinished() = 0; |
236 virtual void OnRasterTasksRequiredForActivationFinished() = 0; | 257 virtual void OnRasterTasksRequiredForActivationFinished() = 0; |
237 | 258 |
259 void CheckForCompletedWorkerPoolTasks(); | |
260 void SetTaskGraph(TaskGraph* graph); | |
261 | |
238 void SetRasterTasks(RasterTask::Queue* queue); | 262 void SetRasterTasks(RasterTask::Queue* queue); |
239 bool IsRasterTaskRequiredForActivation( | 263 bool IsRasterTaskRequiredForActivation( |
240 internal::RasterWorkerPoolTask* task) const; | 264 internal::RasterWorkerPoolTask* task) const; |
241 // Run raster tasks that use GPU on current thread. | 265 // Run raster tasks that use GPU on current thread. |
242 void RunGpuRasterTasks(const RasterTaskVector& tasks); | 266 void RunGpuRasterTasks(const RasterTaskVector& tasks); |
243 | 267 |
244 RasterWorkerPoolClient* client() const { return client_; } | 268 RasterWorkerPoolClient* client() const { return client_; } |
245 ResourceProvider* resource_provider() const { return resource_provider_; } | 269 ResourceProvider* resource_provider() const { return resource_provider_; } |
246 ContextProvider* context_provider() const { return context_provider_; } | 270 ContextProvider* context_provider() const { return context_provider_; } |
247 const RasterTaskVector& raster_tasks() const { return raster_tasks_; } | 271 const RasterTaskVector& raster_tasks() const { return raster_tasks_; } |
248 const RasterTaskSet& raster_tasks_required_for_activation() const { | 272 const RasterTaskSet& raster_tasks_required_for_activation() const { |
249 return raster_tasks_required_for_activation_; | 273 return raster_tasks_required_for_activation_; |
250 } | 274 } |
251 void set_raster_finished_task( | 275 void set_raster_finished_task( |
252 scoped_refptr<internal::WorkerPoolTask> raster_finished_task) { | 276 internal::WorkerPoolTask* raster_finished_task) { |
253 raster_finished_task_ = raster_finished_task; | 277 raster_finished_task_ = raster_finished_task; |
254 } | 278 } |
255 void set_raster_required_for_activation_finished_task( | 279 void set_raster_required_for_activation_finished_task( |
256 scoped_refptr<internal::WorkerPoolTask> | 280 internal::WorkerPoolTask* raster_required_for_activation_finished_task) { |
257 raster_required_for_activation_finished_task) { | |
258 raster_required_for_activation_finished_task_ = | 281 raster_required_for_activation_finished_task_ = |
259 raster_required_for_activation_finished_task; | 282 raster_required_for_activation_finished_task; |
260 } | 283 } |
261 | 284 |
262 scoped_refptr<internal::WorkerPoolTask> CreateRasterFinishedTask(); | 285 scoped_refptr<internal::WorkerPoolTask> CreateRasterFinishedTask(); |
263 scoped_refptr<internal::WorkerPoolTask> | 286 scoped_refptr<internal::WorkerPoolTask> |
264 CreateRasterRequiredForActivationFinishedTask( | 287 CreateRasterRequiredForActivationFinishedTask( |
265 size_t tasks_required_for_activation_count); | 288 size_t tasks_required_for_activation_count); |
266 | 289 |
267 scoped_ptr<base::Value> ScheduledStateAsValue() const; | 290 scoped_ptr<base::Value> ScheduledStateAsValue() const; |
268 | 291 |
269 static internal::GraphNode* CreateGraphNodeForTask( | 292 static internal::GraphNode* CreateGraphNodeForTask( |
270 internal::WorkerPoolTask* task, | 293 internal::WorkerPoolTask* task, |
271 unsigned priority, | 294 unsigned priority, |
272 TaskGraph* graph); | 295 TaskGraph* graph); |
273 | 296 |
274 static internal::GraphNode* CreateGraphNodeForRasterTask( | 297 static internal::GraphNode* CreateGraphNodeForRasterTask( |
275 internal::WorkerPoolTask* raster_task, | 298 internal::WorkerPoolTask* raster_task, |
276 const TaskVector& decode_tasks, | 299 const internal::Task::Vector& decode_tasks, |
277 unsigned priority, | 300 unsigned priority, |
278 TaskGraph* graph); | 301 TaskGraph* graph); |
279 | 302 |
280 private: | 303 private: |
281 void OnRasterFinished(const internal::WorkerPoolTask* source); | 304 void OnRasterFinished(const internal::WorkerPoolTask* source); |
282 void OnRasterRequiredForActivationFinished( | 305 void OnRasterRequiredForActivationFinished( |
283 const internal::WorkerPoolTask* source); | 306 const internal::WorkerPoolTask* source); |
284 | 307 |
308 internal::NamespaceToken namespace_token_; | |
285 RasterWorkerPoolClient* client_; | 309 RasterWorkerPoolClient* client_; |
286 ResourceProvider* resource_provider_; | 310 ResourceProvider* resource_provider_; |
287 ContextProvider* context_provider_; | 311 ContextProvider* context_provider_; |
288 RasterTask::Queue::TaskVector raster_tasks_; | 312 RasterTask::Queue::TaskVector raster_tasks_; |
289 RasterTask::Queue::TaskSet raster_tasks_required_for_activation_; | 313 RasterTask::Queue::TaskSet raster_tasks_required_for_activation_; |
290 RasterTaskDeque completed_gpu_raster_tasks_; | 314 RasterTaskDeque completed_gpu_raster_tasks_; |
291 | 315 |
292 scoped_refptr<internal::WorkerPoolTask> raster_finished_task_; | 316 scoped_refptr<internal::WorkerPoolTask> raster_finished_task_; |
293 scoped_refptr<internal::WorkerPoolTask> | 317 scoped_refptr<internal::WorkerPoolTask> |
294 raster_required_for_activation_finished_task_; | 318 raster_required_for_activation_finished_task_; |
295 base::WeakPtrFactory<RasterWorkerPool> weak_ptr_factory_; | 319 base::WeakPtrFactory<RasterWorkerPool> weak_ptr_factory_; |
296 }; | 320 }; |
297 | 321 |
298 } // namespace cc | 322 } // namespace cc |
299 | 323 |
300 #endif // CC_RESOURCES_RASTER_WORKER_POOL_H_ | 324 #endif // CC_RESOURCES_RASTER_WORKER_POOL_H_ |
OLD | NEW |