| 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 16 matching lines...) Expand all Loading... |
| 27 public: | 27 public: |
| 28 typedef std::vector<scoped_refptr<WorkerPoolTask> > TaskVector; | 28 typedef std::vector<scoped_refptr<WorkerPoolTask> > TaskVector; |
| 29 | 29 |
| 30 // Returns true if |buffer| was written to. False indicate that | 30 // Returns true if |buffer| was written to. False indicate that |
| 31 // the content of |buffer| is undefined and the resource doesn't | 31 // the content of |buffer| is undefined and the resource doesn't |
| 32 // need to be initialized. | 32 // need to be initialized. |
| 33 virtual bool RunOnWorkerThread(unsigned thread_index, | 33 virtual bool RunOnWorkerThread(unsigned thread_index, |
| 34 void* buffer, | 34 void* buffer, |
| 35 gfx::Size size, | 35 gfx::Size size, |
| 36 int stride) = 0; | 36 int stride) = 0; |
| 37 virtual void RunOnOriginThread(ResourceProvider* resource_provider, |
| 38 ContextProvider* context_provider) = 0; |
| 37 virtual void CompleteOnOriginThread() = 0; | 39 virtual void CompleteOnOriginThread() = 0; |
| 38 | 40 |
| 39 void DidRun(bool was_canceled); | 41 void DidRun(bool was_canceled); |
| 40 bool HasFinishedRunning() const; | 42 bool HasFinishedRunning() const; |
| 41 bool WasCanceled() const; | 43 bool WasCanceled() const; |
| 42 void WillComplete(); | 44 void WillComplete(); |
| 43 void DidComplete(); | 45 void DidComplete(); |
| 44 bool HasCompleted() const; | 46 bool HasCompleted() const; |
| 45 | 47 |
| 46 const Resource* resource() const { return resource_; } | 48 const Resource* resource() const { return resource_; } |
| 47 const TaskVector& dependencies() const { return dependencies_; } | 49 const TaskVector& dependencies() const { return dependencies_; } |
| 50 bool use_gpu_rasterization() const { return use_gpu_rasterization_; } |
| 48 | 51 |
| 49 protected: | 52 protected: |
| 50 friend class base::RefCounted<RasterWorkerPoolTask>; | 53 friend class base::RefCounted<RasterWorkerPoolTask>; |
| 51 | 54 |
| 52 RasterWorkerPoolTask(const Resource* resource, TaskVector* dependencies); | 55 RasterWorkerPoolTask(const Resource* resource, |
| 56 TaskVector* dependencies, |
| 57 bool use_gpu_rasterization); |
| 53 virtual ~RasterWorkerPoolTask(); | 58 virtual ~RasterWorkerPoolTask(); |
| 54 | 59 |
| 55 private: | 60 private: |
| 56 bool did_run_; | 61 bool did_run_; |
| 57 bool did_complete_; | 62 bool did_complete_; |
| 58 bool was_canceled_; | 63 bool was_canceled_; |
| 59 const Resource* resource_; | 64 const Resource* resource_; |
| 60 TaskVector dependencies_; | 65 TaskVector dependencies_; |
| 66 bool use_gpu_rasterization_; |
| 61 }; | 67 }; |
| 62 | 68 |
| 63 } // namespace internal | 69 } // namespace internal |
| 64 } // namespace cc | 70 } // namespace cc |
| 65 | 71 |
| 66 #if defined(COMPILER_GCC) | 72 #if defined(COMPILER_GCC) |
| 67 namespace BASE_HASH_NAMESPACE { | 73 namespace BASE_HASH_NAMESPACE { |
| 68 template <> struct hash<cc::internal::RasterWorkerPoolTask*> { | 74 template <> struct hash<cc::internal::RasterWorkerPoolTask*> { |
| 69 size_t operator()(cc::internal::RasterWorkerPoolTask* ptr) const { | 75 size_t operator()(cc::internal::RasterWorkerPoolTask* ptr) const { |
| 70 return hash<size_t>()(reinterpret_cast<size_t>(ptr)); | 76 return hash<size_t>()(reinterpret_cast<size_t>(ptr)); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 | 168 |
| 163 explicit RasterTask(internal::RasterWorkerPoolTask* internal); | 169 explicit RasterTask(internal::RasterWorkerPoolTask* internal); |
| 164 | 170 |
| 165 scoped_refptr<internal::RasterWorkerPoolTask> internal_; | 171 scoped_refptr<internal::RasterWorkerPoolTask> internal_; |
| 166 }; | 172 }; |
| 167 | 173 |
| 168 virtual ~RasterWorkerPool(); | 174 virtual ~RasterWorkerPool(); |
| 169 | 175 |
| 170 void SetClient(RasterWorkerPoolClient* client); | 176 void SetClient(RasterWorkerPoolClient* client); |
| 171 | 177 |
| 172 // Tells the worker pool to shutdown after canceling all previously | 178 // Overidden from WorkerPool: |
| 173 // scheduled tasks. Reply callbacks are still guaranteed to run. | |
| 174 virtual void Shutdown() OVERRIDE; | 179 virtual void Shutdown() OVERRIDE; |
| 175 | 180 |
| 176 // Schedule running of raster tasks in |queue| and all dependencies. | 181 // Schedule running of raster tasks in |queue| and all dependencies. |
| 177 // Previously scheduled tasks that are no longer needed to run | 182 // Previously scheduled tasks that are no longer needed to run |
| 178 // raster tasks in |queue| will be canceled unless already running. | 183 // raster tasks in |queue| will be canceled unless already running. |
| 179 // Once scheduled, reply callbacks are guaranteed to run for all tasks | 184 // Once scheduled, reply callbacks are guaranteed to run for all tasks |
| 180 // even if they later get canceled by another call to ScheduleTasks(). | 185 // even if they later get canceled by another call to ScheduleTasks(). |
| 181 virtual void ScheduleTasks(RasterTask::Queue* queue) = 0; | 186 virtual void ScheduleTasks(RasterTask::Queue* queue) = 0; |
| 182 | 187 |
| 183 // Returns the target that needs to be used for raster task resources. | 188 // Returns the target that needs to be used for raster task resources. |
| 184 virtual GLenum GetResourceTarget() const = 0; | 189 virtual GLenum GetResourceTarget() const = 0; |
| 185 | 190 |
| 186 // Returns the format that needs to be used for raster task resources. | 191 // Returns the format that needs to be used for raster task resources. |
| 187 virtual ResourceFormat GetResourceFormat() const = 0; | 192 virtual ResourceFormat GetResourceFormat() const = 0; |
| 188 | 193 |
| 194 // Force a check for completed raster tasks. |
| 195 // Calls completion callbacks on completed tasks. |
| 196 virtual void CheckForCompletedTasks(); |
| 197 |
| 189 // 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. |
| 190 static RasterTask CreateRasterTask( | 199 static RasterTask CreateRasterTask( |
| 191 const Resource* resource, | 200 const Resource* resource, |
| 192 PicturePileImpl* picture_pile, | 201 PicturePileImpl* picture_pile, |
| 193 gfx::Rect content_rect, | 202 gfx::Rect content_rect, |
| 194 float contents_scale, | 203 float contents_scale, |
| 195 RasterMode raster_mode, | 204 RasterMode raster_mode, |
| 196 TileResolution tile_resolution, | 205 TileResolution tile_resolution, |
| 197 int layer_id, | 206 int layer_id, |
| 198 const void* tile_id, | 207 const void* tile_id, |
| 199 int source_frame_number, | 208 int source_frame_number, |
| 209 bool use_gpu_rasterization, |
| 200 RenderingStatsInstrumentation* rendering_stats, | 210 RenderingStatsInstrumentation* rendering_stats, |
| 201 const RasterTask::Reply& reply, | 211 const RasterTask::Reply& reply, |
| 202 Task::Set* dependencies); | 212 Task::Set* dependencies); |
| 203 | 213 |
| 204 static Task CreateImageDecodeTask( | 214 static Task CreateImageDecodeTask( |
| 205 SkPixelRef* pixel_ref, | 215 SkPixelRef* pixel_ref, |
| 206 int layer_id, | 216 int layer_id, |
| 207 RenderingStatsInstrumentation* stats_instrumentation, | 217 RenderingStatsInstrumentation* stats_instrumentation, |
| 208 const Task::Reply& reply); | 218 const Task::Reply& reply); |
| 209 | 219 |
| 210 protected: | 220 protected: |
| 211 typedef std::vector<scoped_refptr<internal::WorkerPoolTask> > TaskVector; | 221 typedef std::vector<scoped_refptr<internal::WorkerPoolTask> > TaskVector; |
| 212 typedef std::vector<scoped_refptr<internal::RasterWorkerPoolTask> > | 222 typedef std::vector<scoped_refptr<internal::RasterWorkerPoolTask> > |
| 213 RasterTaskVector; | 223 RasterTaskVector; |
| 224 typedef std::deque<scoped_refptr<internal::RasterWorkerPoolTask> > |
| 225 RasterTaskDeque; |
| 214 typedef base::hash_set<internal::RasterWorkerPoolTask*> RasterTaskSet; | 226 typedef base::hash_set<internal::RasterWorkerPoolTask*> RasterTaskSet; |
| 215 typedef internal::RasterWorkerPoolTask* TaskMapKey; | 227 typedef internal::RasterWorkerPoolTask* TaskMapKey; |
| 216 typedef base::hash_map<TaskMapKey, | 228 typedef base::hash_map<TaskMapKey, |
| 217 scoped_refptr<internal::WorkerPoolTask> > TaskMap; | 229 scoped_refptr<internal::WorkerPoolTask> > TaskMap; |
| 218 | 230 |
| 219 RasterWorkerPool(ResourceProvider* resource_provider, size_t num_threads); | 231 RasterWorkerPool(ResourceProvider* resource_provider, |
| 232 ContextProvider* context_provider, |
| 233 size_t num_threads); |
| 220 | 234 |
| 221 virtual void OnRasterTasksFinished() = 0; | 235 virtual void OnRasterTasksFinished() = 0; |
| 222 virtual void OnRasterTasksRequiredForActivationFinished() = 0; | 236 virtual void OnRasterTasksRequiredForActivationFinished() = 0; |
| 223 | 237 |
| 224 void SetRasterTasks(RasterTask::Queue* queue); | 238 void SetRasterTasks(RasterTask::Queue* queue); |
| 225 bool IsRasterTaskRequiredForActivation( | 239 bool IsRasterTaskRequiredForActivation( |
| 226 internal::RasterWorkerPoolTask* task) const; | 240 internal::RasterWorkerPoolTask* task) const; |
| 241 // Run raster tasks that use GPU on current thread. |
| 242 void RunGpuRasterTasks(const RasterTaskVector& tasks); |
| 227 | 243 |
| 228 RasterWorkerPoolClient* client() const { return client_; } | 244 RasterWorkerPoolClient* client() const { return client_; } |
| 229 ResourceProvider* resource_provider() const { return resource_provider_; } | 245 ResourceProvider* resource_provider() const { return resource_provider_; } |
| 246 ContextProvider* context_provider() const { return context_provider_; } |
| 230 const RasterTaskVector& raster_tasks() const { return raster_tasks_; } | 247 const RasterTaskVector& raster_tasks() const { return raster_tasks_; } |
| 231 const RasterTaskSet& raster_tasks_required_for_activation() const { | 248 const RasterTaskSet& raster_tasks_required_for_activation() const { |
| 232 return raster_tasks_required_for_activation_; | 249 return raster_tasks_required_for_activation_; |
| 233 } | 250 } |
| 234 void set_raster_finished_task( | 251 void set_raster_finished_task( |
| 235 scoped_refptr<internal::WorkerPoolTask> raster_finished_task) { | 252 scoped_refptr<internal::WorkerPoolTask> raster_finished_task) { |
| 236 raster_finished_task_ = raster_finished_task; | 253 raster_finished_task_ = raster_finished_task; |
| 237 } | 254 } |
| 238 void set_raster_required_for_activation_finished_task( | 255 void set_raster_required_for_activation_finished_task( |
| 239 scoped_refptr<internal::WorkerPoolTask> | 256 scoped_refptr<internal::WorkerPoolTask> |
| (...skipping 19 matching lines...) Expand all Loading... |
| 259 unsigned priority, | 276 unsigned priority, |
| 260 TaskGraph* graph); | 277 TaskGraph* graph); |
| 261 | 278 |
| 262 private: | 279 private: |
| 263 void OnRasterFinished(const internal::WorkerPoolTask* source); | 280 void OnRasterFinished(const internal::WorkerPoolTask* source); |
| 264 void OnRasterRequiredForActivationFinished( | 281 void OnRasterRequiredForActivationFinished( |
| 265 const internal::WorkerPoolTask* source); | 282 const internal::WorkerPoolTask* source); |
| 266 | 283 |
| 267 RasterWorkerPoolClient* client_; | 284 RasterWorkerPoolClient* client_; |
| 268 ResourceProvider* resource_provider_; | 285 ResourceProvider* resource_provider_; |
| 286 ContextProvider* context_provider_; |
| 269 RasterTask::Queue::TaskVector raster_tasks_; | 287 RasterTask::Queue::TaskVector raster_tasks_; |
| 270 RasterTask::Queue::TaskSet raster_tasks_required_for_activation_; | 288 RasterTask::Queue::TaskSet raster_tasks_required_for_activation_; |
| 289 RasterTaskDeque completed_gpu_raster_tasks_; |
| 271 | 290 |
| 272 scoped_refptr<internal::WorkerPoolTask> raster_finished_task_; | 291 scoped_refptr<internal::WorkerPoolTask> raster_finished_task_; |
| 273 scoped_refptr<internal::WorkerPoolTask> | 292 scoped_refptr<internal::WorkerPoolTask> |
| 274 raster_required_for_activation_finished_task_; | 293 raster_required_for_activation_finished_task_; |
| 275 base::WeakPtrFactory<RasterWorkerPool> weak_ptr_factory_; | 294 base::WeakPtrFactory<RasterWorkerPool> weak_ptr_factory_; |
| 276 }; | 295 }; |
| 277 | 296 |
| 278 } // namespace cc | 297 } // namespace cc |
| 279 | 298 |
| 280 #endif // CC_RESOURCES_RASTER_WORKER_POOL_H_ | 299 #endif // CC_RESOURCES_RASTER_WORKER_POOL_H_ |
| OLD | NEW |