Index: cc/resources/raster_worker_pool.h |
diff --git a/cc/resources/raster_worker_pool.h b/cc/resources/raster_worker_pool.h |
index 1a20c5c6a126b4fc3f5034da9cbef2f2ac6ddf47..ed42a760ad61dcf7d9843de4daf75350b297963e 100644 |
--- a/cc/resources/raster_worker_pool.h |
+++ b/cc/resources/raster_worker_pool.h |
@@ -5,38 +5,90 @@ |
#ifndef CC_RESOURCES_RASTER_WORKER_POOL_H_ |
#define CC_RESOURCES_RASTER_WORKER_POOL_H_ |
+#include <vector> |
+ |
+#include "base/hash_tables.h" |
#include "cc/base/worker_pool.h" |
+#include "cc/resources/resource_provider.h" |
+ |
+class SkDevice; |
namespace cc { |
class PicturePileImpl; |
+class PixelBufferRasterWorkerPool; |
+class Resource; |
+ |
+namespace internal { |
+ |
+class CC_EXPORT RasterWorkerPoolTask |
+ : public base::RefCounted<RasterWorkerPoolTask> { |
+ public: |
+ typedef std::vector<scoped_refptr<RasterWorkerPoolTask> > TaskVector; |
+ |
+ virtual bool RunOnThread(SkDevice* device, unsigned thread_index) = 0; |
+ virtual void DispatchCompletionCallback() = 0; |
+ |
+ void DidRun(); |
+ bool HasFinishedRunning() const; |
+ void DidComplete(); |
+ bool HasCompleted() const; |
+ |
+ const Resource* resource() const { return resource_; } |
+ const WorkerPoolTask::TaskVector& dependencies() const { |
+ return dependencies_; |
+ } |
+ |
+ protected: |
+ friend class base::RefCounted<RasterWorkerPoolTask>; |
+ |
+ RasterWorkerPoolTask(const Resource* resource, |
+ WorkerPoolTask::TaskVector* dependencies); |
+ virtual ~RasterWorkerPoolTask(); |
+ |
+ private: |
+ bool did_run_; |
+ bool did_complete_; |
+ const Resource* resource_; |
+ WorkerPoolTask::TaskVector dependencies_; |
+}; |
+ |
+} // namespace internal |
+} // namespace cc |
+ |
+#if defined(COMPILER_GCC) |
+namespace BASE_HASH_NAMESPACE { |
+template <> struct hash<cc::internal::RasterWorkerPoolTask*> { |
+ size_t operator()(cc::internal::RasterWorkerPoolTask* ptr) const { |
+ return hash<size_t>()(reinterpret_cast<size_t>(ptr)); |
+ } |
+}; |
+} // namespace BASE_HASH_NAMESPACE |
+#endif // COMPILER |
+ |
+namespace cc { |
// A worker thread pool that runs raster tasks. |
class CC_EXPORT RasterWorkerPool : public WorkerPool { |
public: |
- class Task { |
+ class CC_EXPORT Task { |
public: |
- typedef base::Callback<void(bool)> Reply; |
- |
- // Highest priority task first. Order of execution is not guaranteed. |
- class Queue { |
+ class CC_EXPORT Set { |
public: |
- Queue(); |
- ~Queue(); |
+ typedef internal::WorkerPoolTask::TaskVector TaskVector; |
- bool empty() const { return tasks_.empty(); } |
+ Set(); |
+ ~Set(); |
- // Add task to the back of the queue. |
- void Append(const Task& task); |
+ void Insert(const Task& task); |
private: |
friend class RasterWorkerPool; |
- internal::WorkerPoolTask::TaskVector tasks_; |
+ TaskVector tasks_; |
}; |
Task(); |
- Task(const base::Closure& callback, const Reply& reply); |
- explicit Task(Queue* dependencies); |
+ Task(const base::Closure& callback, const base::Closure& reply); |
~Task(); |
// Returns true if Task is null (doesn't refer to anything). |
@@ -48,42 +100,84 @@ class CC_EXPORT RasterWorkerPool : public WorkerPool { |
protected: |
friend class RasterWorkerPool; |
- explicit Task(scoped_refptr<internal::WorkerPoolTask> internal); |
- |
scoped_refptr<internal::WorkerPoolTask> internal_; |
}; |
- class PictureTask : public Task { |
+ class CC_EXPORT RasterTask { |
public: |
- typedef base::Callback<void(PicturePileImpl*)> Callback; |
+ // Returns true if |device| was written to. False indicate that |
+ // the content of |device| is undefined and the resource doesn't |
+ // need to be initialized. |
+ typedef base::Callback<bool(SkDevice* device, |
+ PicturePileImpl* picture_pile)> Callback; |
+ |
+ typedef base::Callback<void(bool was_canceled)> Reply; |
- PictureTask(PicturePileImpl* picture_pile, |
- const Callback& callback, |
- const Reply& reply, |
- Queue* dependencies); |
+ class CC_EXPORT Queue { |
+ public: |
+ typedef internal::RasterWorkerPoolTask::TaskVector TaskVector; |
+ |
+ Queue(); |
+ ~Queue(); |
+ |
+ void Append(const RasterTask& task); |
+ |
+ private: |
+ friend class RasterWorkerPool; |
+ |
+ TaskVector tasks_; |
+ }; |
+ |
+ RasterTask(); |
+ RasterTask(PicturePileImpl* picture_pile, |
+ const Resource* resource, |
+ const Callback& callback, |
+ const Reply& reply, |
+ Task::Set* dependencies); |
+ ~RasterTask(); |
+ |
+ // Returns true if Task is null (doesn't refer to anything). |
+ bool is_null() const { return !internal_; } |
+ |
+ // Returns the Task into an uninitialized state. |
+ void Reset(); |
+ |
+ protected: |
+ friend class PixelBufferRasterWorkerPool; |
+ friend class RasterWorkerPool; |
+ |
+ scoped_refptr<internal::RasterWorkerPoolTask> internal_; |
}; |
virtual ~RasterWorkerPool(); |
- static scoped_ptr<RasterWorkerPool> Create(size_t num_threads) { |
- return make_scoped_ptr(new RasterWorkerPool(num_threads)); |
- } |
- |
// Tells the worker pool to shutdown after canceling all previously |
// scheduled tasks. Reply callbacks are still guaranteed to run. |
virtual void Shutdown() OVERRIDE; |
- // Schedule running of |root| task and all its dependencies. Tasks |
- // previously scheduled but no longer needed to run |root| will be |
- // canceled unless already running. Once scheduled, reply callbacks |
- // are guaranteed to run for all tasks even if they later get |
- // canceled by another call to ScheduleTasks(). |
- void ScheduleTasks(Task* root); |
+ // Schedule running of raster tasks in |queue| and all dependencies. |
+ // Previously scheduled tasks that are no longer needed to run |
+ // raster tasks in |queue| will be canceled unless already running. |
+ // Once scheduled, reply callbacks are guaranteed to run for all tasks |
+ // even if they later get canceled by another call to ScheduleTasks(). |
+ virtual void ScheduleTasks(RasterTask::Queue* queue) = 0; |
- private: |
- explicit RasterWorkerPool(size_t num_threads); |
+ // Tells the raster worker pool to force any pending uploads for |
+ // |raster_task| to complete. Returns true when successful. |
+ virtual bool ForceUploadToComplete(const RasterTask& raster_task); |
+ |
+ protected: |
+ typedef internal::RasterWorkerPoolTask* TaskMapKey; |
+ typedef base::hash_map<TaskMapKey, |
+ scoped_refptr<internal::WorkerPoolTask> > TaskMap; |
+ |
+ RasterWorkerPool(ResourceProvider* resource_provider, size_t num_threads); |
+ |
+ void SetRasterTasks(RasterTask::Queue* queue); |
+ void ScheduleRasterTasks(internal::WorkerPoolTask::TaskVector* raster_tasks); |
- DISALLOW_COPY_AND_ASSIGN(RasterWorkerPool); |
+ ResourceProvider* resource_provider_; |
+ RasterTask::Queue::TaskVector raster_tasks_; |
}; |
} // namespace cc |