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 <string> | |
9 | |
10 #include "cc/base/worker_pool.h" | 8 #include "cc/base/worker_pool.h" |
11 | 9 |
12 namespace cc { | 10 namespace cc { |
13 class PicturePileImpl; | 11 class PicturePileImpl; |
14 | 12 |
15 // A worker thread pool that runs raster tasks. | 13 // A worker thread pool that runs raster tasks. |
16 class CC_EXPORT RasterWorkerPool : public WorkerPool { | 14 class CC_EXPORT RasterWorkerPool : public WorkerPool { |
17 public: | 15 public: |
18 typedef base::Callback<void(PicturePileImpl* picture_pile)> RasterCallback; | 16 class Task { |
| 17 public: |
| 18 typedef base::Callback<void(bool)> Reply; |
| 19 |
| 20 class Schedule { |
| 21 public: |
| 22 Schedule(); |
| 23 ~Schedule(); |
| 24 |
| 25 void Append(const Task& task); |
| 26 void AppendWithDependencies(const Task& task, Schedule* dependencies); |
| 27 |
| 28 private: |
| 29 friend class RasterWorkerPool; |
| 30 |
| 31 internal::WorkerPoolTaskGraph task_graph_; |
| 32 }; |
| 33 |
| 34 Task(); |
| 35 Task(const base::Closure& callback, const Reply& reply); |
| 36 ~Task(); |
| 37 |
| 38 // Returns true if Task is null (doesn't refer to anything). |
| 39 bool is_null() const { return !internal_; } |
| 40 |
| 41 // Returns the Task into an uninitialized state. |
| 42 void Reset(); |
| 43 |
| 44 protected: |
| 45 explicit Task(scoped_refptr<internal::WorkerPoolTask> internal); |
| 46 |
| 47 scoped_refptr<internal::WorkerPoolTask> internal_; |
| 48 }; |
| 49 |
| 50 class PictureTask : public Task { |
| 51 public: |
| 52 typedef base::Callback<void(PicturePileImpl*)> Callback; |
| 53 |
| 54 PictureTask(PicturePileImpl* picture_pile, |
| 55 const Callback& callback, |
| 56 const Reply& reply); |
| 57 }; |
19 | 58 |
20 virtual ~RasterWorkerPool(); | 59 virtual ~RasterWorkerPool(); |
21 | 60 |
22 static scoped_ptr<RasterWorkerPool> Create(size_t num_threads) { | 61 static scoped_ptr<RasterWorkerPool> Create(size_t num_threads) { |
23 return make_scoped_ptr(new RasterWorkerPool(num_threads)); | 62 return make_scoped_ptr(new RasterWorkerPool(num_threads)); |
24 } | 63 } |
25 | 64 |
26 void PostRasterTaskAndReply(PicturePileImpl* picture_pile, | 65 // Tells the worker pool to shutdown after canceling all previously |
27 const RasterCallback& task, | 66 // scheduled tasks. Reply callbacks are still guaranteed to run. |
28 const base::Closure& reply); | 67 virtual void Shutdown() OVERRIDE; |
| 68 |
| 69 // Schedule running of tasks in |schedule|. All tasks previously |
| 70 // scheduled but not present in |schedule| will be canceled. Once |
| 71 // scheduled, reply callbacks are guaranteed to run for all tasks even |
| 72 // if they later get canceled by another call to ScheduleTasks(). This |
| 73 // consumed all tasks and queue will be empty when function returns. |
| 74 void ScheduleTasks(Task::Schedule* schedule); |
29 | 75 |
30 private: | 76 private: |
31 explicit RasterWorkerPool(size_t num_threads); | 77 explicit RasterWorkerPool(size_t num_threads); |
32 | 78 |
33 DISALLOW_COPY_AND_ASSIGN(RasterWorkerPool); | 79 DISALLOW_COPY_AND_ASSIGN(RasterWorkerPool); |
34 }; | 80 }; |
35 | 81 |
36 } // namespace cc | 82 } // namespace cc |
37 | 83 |
38 #endif // CC_RESOURCES_RASTER_WORKER_POOL_H_ | 84 #endif // CC_RESOURCES_RASTER_WORKER_POOL_H_ |
OLD | NEW |