Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(127)

Side by Side Diff: cc/resources/raster_worker_pool.h

Issue 16190002: cc: Add new RasterWorkerPool interface. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: rebase Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/resources/pixel_buffer_raster_worker_pool.cc ('k') | cc/resources/raster_worker_pool.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
9
10 #include "base/hash_tables.h"
8 #include "cc/base/worker_pool.h" 11 #include "cc/base/worker_pool.h"
12 #include "cc/resources/resource_provider.h"
13
14 class SkDevice;
9 15
10 namespace cc { 16 namespace cc {
11 class PicturePileImpl; 17 class PicturePileImpl;
18 class PixelBufferRasterWorkerPool;
19 class Resource;
20
21 namespace internal {
22
23 class CC_EXPORT RasterWorkerPoolTask
24 : public base::RefCounted<RasterWorkerPoolTask> {
25 public:
26 typedef std::vector<scoped_refptr<RasterWorkerPoolTask> > TaskVector;
27
28 virtual bool RunOnThread(SkDevice* device, unsigned thread_index) = 0;
29 virtual void DispatchCompletionCallback() = 0;
30
31 void DidRun();
32 bool HasFinishedRunning() const;
33 void DidComplete();
34 bool HasCompleted() const;
35
36 const Resource* resource() const { return resource_; }
37 const WorkerPoolTask::TaskVector& dependencies() const {
38 return dependencies_;
39 }
40
41 protected:
42 friend class base::RefCounted<RasterWorkerPoolTask>;
43
44 RasterWorkerPoolTask(const Resource* resource,
45 WorkerPoolTask::TaskVector* dependencies);
46 virtual ~RasterWorkerPoolTask();
47
48 private:
49 bool did_run_;
50 bool did_complete_;
51 const Resource* resource_;
52 WorkerPoolTask::TaskVector dependencies_;
53 };
54
55 } // namespace internal
56 } // namespace cc
57
58 #if defined(COMPILER_GCC)
59 namespace BASE_HASH_NAMESPACE {
60 template <> struct hash<cc::internal::RasterWorkerPoolTask*> {
61 size_t operator()(cc::internal::RasterWorkerPoolTask* ptr) const {
62 return hash<size_t>()(reinterpret_cast<size_t>(ptr));
63 }
64 };
65 } // namespace BASE_HASH_NAMESPACE
66 #endif // COMPILER
67
68 namespace cc {
12 69
13 // A worker thread pool that runs raster tasks. 70 // A worker thread pool that runs raster tasks.
14 class CC_EXPORT RasterWorkerPool : public WorkerPool { 71 class CC_EXPORT RasterWorkerPool : public WorkerPool {
15 public: 72 public:
16 class Task { 73 class CC_EXPORT Task {
17 public: 74 public:
18 typedef base::Callback<void(bool)> Reply; 75 class CC_EXPORT Set {
76 public:
77 typedef internal::WorkerPoolTask::TaskVector TaskVector;
19 78
20 // Highest priority task first. Order of execution is not guaranteed. 79 Set();
21 class Queue { 80 ~Set();
22 public:
23 Queue();
24 ~Queue();
25 81
26 bool empty() const { return tasks_.empty(); } 82 void Insert(const Task& task);
27
28 // Add task to the back of the queue.
29 void Append(const Task& task);
30 83
31 private: 84 private:
32 friend class RasterWorkerPool; 85 friend class RasterWorkerPool;
33 86
34 internal::WorkerPoolTask::TaskVector tasks_; 87 TaskVector tasks_;
35 }; 88 };
36 89
37 Task(); 90 Task();
38 Task(const base::Closure& callback, const Reply& reply); 91 Task(const base::Closure& callback, const base::Closure& reply);
39 explicit Task(Queue* dependencies);
40 ~Task(); 92 ~Task();
41 93
42 // Returns true if Task is null (doesn't refer to anything). 94 // Returns true if Task is null (doesn't refer to anything).
43 bool is_null() const { return !internal_.get(); } 95 bool is_null() const { return !internal_.get(); }
44 96
45 // Returns the Task into an uninitialized state. 97 // Returns the Task into an uninitialized state.
46 void Reset(); 98 void Reset();
47 99
48 protected: 100 protected:
49 friend class RasterWorkerPool; 101 friend class RasterWorkerPool;
50 102
51 explicit Task(scoped_refptr<internal::WorkerPoolTask> internal);
52
53 scoped_refptr<internal::WorkerPoolTask> internal_; 103 scoped_refptr<internal::WorkerPoolTask> internal_;
54 }; 104 };
55 105
56 class PictureTask : public Task { 106 class CC_EXPORT RasterTask {
57 public: 107 public:
58 typedef base::Callback<void(PicturePileImpl*)> Callback; 108 // Returns true if |device| was written to. False indicate that
109 // the content of |device| is undefined and the resource doesn't
110 // need to be initialized.
111 typedef base::Callback<bool(SkDevice* device,
112 PicturePileImpl* picture_pile)> Callback;
59 113
60 PictureTask(PicturePileImpl* picture_pile, 114 typedef base::Callback<void(bool was_canceled)> Reply;
61 const Callback& callback, 115
62 const Reply& reply, 116 class CC_EXPORT Queue {
63 Queue* dependencies); 117 public:
118 typedef internal::RasterWorkerPoolTask::TaskVector TaskVector;
119
120 Queue();
121 ~Queue();
122
123 void Append(const RasterTask& task);
124
125 private:
126 friend class RasterWorkerPool;
127
128 TaskVector tasks_;
129 };
130
131 RasterTask();
132 RasterTask(PicturePileImpl* picture_pile,
133 const Resource* resource,
134 const Callback& callback,
135 const Reply& reply,
136 Task::Set* dependencies);
137 ~RasterTask();
138
139 // Returns true if Task is null (doesn't refer to anything).
140 bool is_null() const { return !internal_; }
141
142 // Returns the Task into an uninitialized state.
143 void Reset();
144
145 protected:
146 friend class PixelBufferRasterWorkerPool;
147 friend class RasterWorkerPool;
148
149 scoped_refptr<internal::RasterWorkerPoolTask> internal_;
64 }; 150 };
65 151
66 virtual ~RasterWorkerPool(); 152 virtual ~RasterWorkerPool();
67 153
68 static scoped_ptr<RasterWorkerPool> Create(size_t num_threads) {
69 return make_scoped_ptr(new RasterWorkerPool(num_threads));
70 }
71
72 // Tells the worker pool to shutdown after canceling all previously 154 // Tells the worker pool to shutdown after canceling all previously
73 // scheduled tasks. Reply callbacks are still guaranteed to run. 155 // scheduled tasks. Reply callbacks are still guaranteed to run.
74 virtual void Shutdown() OVERRIDE; 156 virtual void Shutdown() OVERRIDE;
75 157
76 // Schedule running of |root| task and all its dependencies. Tasks 158 // Schedule running of raster tasks in |queue| and all dependencies.
77 // previously scheduled but no longer needed to run |root| will be 159 // Previously scheduled tasks that are no longer needed to run
78 // canceled unless already running. Once scheduled, reply callbacks 160 // raster tasks in |queue| will be canceled unless already running.
79 // are guaranteed to run for all tasks even if they later get 161 // Once scheduled, reply callbacks are guaranteed to run for all tasks
80 // canceled by another call to ScheduleTasks(). 162 // even if they later get canceled by another call to ScheduleTasks().
81 void ScheduleTasks(Task* root); 163 virtual void ScheduleTasks(RasterTask::Queue* queue) = 0;
82 164
83 private: 165 // Tells the raster worker pool to force any pending uploads for
84 explicit RasterWorkerPool(size_t num_threads); 166 // |raster_task| to complete. Returns true when successful.
167 virtual bool ForceUploadToComplete(const RasterTask& raster_task);
85 168
86 DISALLOW_COPY_AND_ASSIGN(RasterWorkerPool); 169 protected:
170 typedef internal::RasterWorkerPoolTask* TaskMapKey;
171 typedef base::hash_map<TaskMapKey,
172 scoped_refptr<internal::WorkerPoolTask> > TaskMap;
173
174 RasterWorkerPool(ResourceProvider* resource_provider, size_t num_threads);
175
176 void SetRasterTasks(RasterTask::Queue* queue);
177 void ScheduleRasterTasks(internal::WorkerPoolTask::TaskVector* raster_tasks);
178
179 ResourceProvider* resource_provider_;
180 RasterTask::Queue::TaskVector raster_tasks_;
87 }; 181 };
88 182
89 } // namespace cc 183 } // namespace cc
90 184
91 #endif // CC_RESOURCES_RASTER_WORKER_POOL_H_ 185 #endif // CC_RESOURCES_RASTER_WORKER_POOL_H_
OLDNEW
« no previous file with comments | « cc/resources/pixel_buffer_raster_worker_pool.cc ('k') | cc/resources/raster_worker_pool.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698