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