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

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

Issue 17244003: cc: Move task graph construction to RasterWorkerPool classes. (Closed) Base URL: http://git.chromium.org/chromium/src.git@wp-run-count
Patch Set: add missing CC_EXPORT 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> 8 #include <vector>
9 9
10 #include "base/containers/hash_tables.h" 10 #include "base/containers/hash_tables.h"
(...skipping 12 matching lines...) Expand all
23 namespace cc { 23 namespace cc {
24 class PicturePileImpl; 24 class PicturePileImpl;
25 class PixelBufferRasterWorkerPool; 25 class PixelBufferRasterWorkerPool;
26 class Resource; 26 class Resource;
27 27
28 namespace internal { 28 namespace internal {
29 29
30 class CC_EXPORT RasterWorkerPoolTask 30 class CC_EXPORT RasterWorkerPoolTask
31 : public base::RefCounted<RasterWorkerPoolTask> { 31 : public base::RefCounted<RasterWorkerPoolTask> {
32 public: 32 public:
33 typedef std::vector<scoped_refptr<RasterWorkerPoolTask> > TaskVector; 33 typedef std::vector<scoped_refptr<WorkerPoolTask> > TaskVector;
34 34
35 // Returns true if |device| was written to. False indicate that 35 // Returns true if |device| was written to. False indicate that
36 // the content of |device| is undefined and the resource doesn't 36 // the content of |device| is undefined and the resource doesn't
37 // need to be initialized. 37 // need to be initialized.
38 virtual bool RunOnThread(SkDevice* device, unsigned thread_index) = 0; 38 virtual bool RunOnThread(SkDevice* device, unsigned thread_index) = 0;
39 virtual void DispatchCompletionCallback() = 0; 39 virtual void DispatchCompletionCallback() = 0;
40 40
41 void DidRun(bool was_canceled); 41 void DidRun(bool was_canceled);
42 bool HasFinishedRunning() const; 42 bool HasFinishedRunning() const;
43 bool WasCanceled() const; 43 bool WasCanceled() const;
44 void DidComplete(); 44 void DidComplete();
45 bool HasCompleted() const; 45 bool HasCompleted() const;
46 46
47 const Resource* resource() const { return resource_; } 47 const Resource* resource() const { return resource_; }
48 const WorkerPoolTask::TaskVector& dependencies() const { 48 const TaskVector& dependencies() const { return dependencies_; }
49 return dependencies_;
50 }
51 49
52 protected: 50 protected:
53 friend class base::RefCounted<RasterWorkerPoolTask>; 51 friend class base::RefCounted<RasterWorkerPoolTask>;
54 52
55 RasterWorkerPoolTask(const Resource* resource, 53 RasterWorkerPoolTask(const Resource* resource, TaskVector* dependencies);
56 WorkerPoolTask::TaskVector* dependencies);
57 virtual ~RasterWorkerPoolTask(); 54 virtual ~RasterWorkerPoolTask();
58 55
59 private: 56 private:
60 bool did_run_; 57 bool did_run_;
61 bool did_complete_; 58 bool did_complete_;
62 bool was_canceled_; 59 bool was_canceled_;
63 const Resource* resource_; 60 const Resource* resource_;
64 WorkerPoolTask::TaskVector dependencies_; 61 TaskVector dependencies_;
65 }; 62 };
66 63
67 } // namespace internal 64 } // namespace internal
68 } // namespace cc 65 } // namespace cc
69 66
70 #if defined(COMPILER_GCC) 67 #if defined(COMPILER_GCC)
71 namespace BASE_HASH_NAMESPACE { 68 namespace BASE_HASH_NAMESPACE {
72 template <> struct hash<cc::internal::RasterWorkerPoolTask*> { 69 template <> struct hash<cc::internal::RasterWorkerPoolTask*> {
73 size_t operator()(cc::internal::RasterWorkerPoolTask* ptr) const { 70 size_t operator()(cc::internal::RasterWorkerPoolTask* ptr) const {
74 return hash<size_t>()(reinterpret_cast<size_t>(ptr)); 71 return hash<size_t>()(reinterpret_cast<size_t>(ptr));
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 public: 118 public:
122 Set(); 119 Set();
123 ~Set(); 120 ~Set();
124 121
125 void Insert(const Task& task); 122 void Insert(const Task& task);
126 123
127 private: 124 private:
128 friend class RasterWorkerPool; 125 friend class RasterWorkerPool;
129 friend class RasterWorkerPoolTest; 126 friend class RasterWorkerPoolTest;
130 127
131 typedef internal::WorkerPoolTask::TaskVector TaskVector; 128 typedef internal::RasterWorkerPoolTask::TaskVector TaskVector;
132 TaskVector tasks_; 129 TaskVector tasks_;
133 }; 130 };
134 131
135 Task(); 132 Task();
136 ~Task(); 133 ~Task();
137 134
138 // Returns true if Task is null (doesn't refer to anything). 135 // Returns true if Task is null (doesn't refer to anything).
139 bool is_null() const { return !internal_.get(); } 136 bool is_null() const { return !internal_.get(); }
140 137
141 // Returns the Task into an uninitialized state. 138 // Returns the Task into an uninitialized state.
142 void Reset(); 139 void Reset();
143 140
144 protected: 141 protected:
145 friend class RasterWorkerPool; 142 friend class RasterWorkerPool;
146 friend class RasterWorkerPoolTest; 143 friend class RasterWorkerPoolTest;
147 144
148 explicit Task(internal::WorkerPoolTask* internal); 145 explicit Task(internal::WorkerPoolTask* internal);
149 146
150 scoped_refptr<internal::WorkerPoolTask> internal_; 147 scoped_refptr<internal::WorkerPoolTask> internal_;
151 }; 148 };
152 149
153 class CC_EXPORT RasterTask { 150 class CC_EXPORT RasterTask {
154 public: 151 public:
155 typedef base::Callback<void(const PicturePileImpl::Analysis& analysis, 152 typedef base::Callback<void(const PicturePileImpl::Analysis& analysis,
156 bool was_canceled)> Reply; 153 bool was_canceled)> Reply;
157 154
158 class CC_EXPORT Queue { 155 class CC_EXPORT Queue {
159 public: 156 public:
160 typedef internal::RasterWorkerPoolTask::TaskVector TaskVector;
161
162 Queue(); 157 Queue();
163 ~Queue(); 158 ~Queue();
164 159
165 void Append(const RasterTask& task, bool required_for_activation); 160 void Append(const RasterTask& task, bool required_for_activation);
166 161
167 private: 162 private:
168 friend class RasterWorkerPool; 163 friend class RasterWorkerPool;
169 164
165 typedef std::vector<scoped_refptr<internal::RasterWorkerPoolTask> >
166 TaskVector;
170 TaskVector tasks_; 167 TaskVector tasks_;
171 typedef base::hash_set<internal::RasterWorkerPoolTask*> TaskSet; 168 typedef base::hash_set<internal::RasterWorkerPoolTask*> TaskSet;
172 TaskSet tasks_required_for_activation_; 169 TaskSet tasks_required_for_activation_;
173 }; 170 };
174 171
175 RasterTask(); 172 RasterTask();
176 ~RasterTask(); 173 ~RasterTask();
177 174
178 // Returns true if Task is null (doesn't refer to anything). 175 // Returns true if Task is null (doesn't refer to anything).
179 bool is_null() const { return !internal_.get(); } 176 bool is_null() const { return !internal_.get(); }
180 177
181 // Returns the Task into an uninitialized state. 178 // Returns the Task into an uninitialized state.
182 void Reset(); 179 void Reset();
183 180
184 protected: 181 protected:
185 friend class PixelBufferRasterWorkerPool;
186 friend class RasterWorkerPool; 182 friend class RasterWorkerPool;
187 friend class RasterWorkerPoolTest; 183 friend class RasterWorkerPoolTest;
188 184
189 explicit RasterTask(internal::RasterWorkerPoolTask* internal); 185 explicit RasterTask(internal::RasterWorkerPoolTask* internal);
190 186
191 scoped_refptr<internal::RasterWorkerPoolTask> internal_; 187 scoped_refptr<internal::RasterWorkerPoolTask> internal_;
192 }; 188 };
193 189
194 virtual ~RasterWorkerPool(); 190 virtual ~RasterWorkerPool();
195 191
(...skipping 14 matching lines...) Expand all
210 static RasterTask CreateRasterTask( 206 static RasterTask CreateRasterTask(
211 const Resource* resource, 207 const Resource* resource,
212 PicturePileImpl* picture_pile, 208 PicturePileImpl* picture_pile,
213 gfx::Rect content_rect, 209 gfx::Rect content_rect,
214 float contents_scale, 210 float contents_scale,
215 RasterMode raster_mode, 211 RasterMode raster_mode,
216 bool use_color_estimator, 212 bool use_color_estimator,
217 const RasterTaskMetadata& metadata, 213 const RasterTaskMetadata& metadata,
218 RenderingStatsInstrumentation* rendering_stats, 214 RenderingStatsInstrumentation* rendering_stats,
219 const RasterTask::Reply& reply, 215 const RasterTask::Reply& reply,
220 Task::Set& dependencies); 216 Task::Set* dependencies);
221 217
222 static Task CreateImageDecodeTask( 218 static Task CreateImageDecodeTask(
223 skia::LazyPixelRef* pixel_ref, 219 skia::LazyPixelRef* pixel_ref,
224 int layer_id, 220 int layer_id,
225 RenderingStatsInstrumentation* stats_instrumentation, 221 RenderingStatsInstrumentation* stats_instrumentation,
226 const Task::Reply& reply); 222 const Task::Reply& reply);
227 223
228 protected: 224 protected:
229 class RootTask { 225 typedef std::vector<scoped_refptr<internal::WorkerPoolTask> > TaskVector;
230 public: 226 typedef std::vector<scoped_refptr<internal::RasterWorkerPoolTask> >
231 RootTask(); 227 RasterTaskVector;
232 explicit RootTask(internal::WorkerPoolTask::TaskVector* dependencies);
233 RootTask(const base::Closure& callback,
234 internal::WorkerPoolTask::TaskVector* dependencies);
235 ~RootTask();
236
237 protected:
238 friend class RasterWorkerPool;
239
240 scoped_refptr<internal::WorkerPoolTask> internal_;
241 };
242
243 typedef internal::RasterWorkerPoolTask* TaskMapKey; 228 typedef internal::RasterWorkerPoolTask* TaskMapKey;
244 typedef base::hash_map<TaskMapKey, 229 typedef base::hash_map<TaskMapKey,
245 scoped_refptr<internal::WorkerPoolTask> > TaskMap; 230 scoped_refptr<internal::WorkerPoolTask> > TaskMap;
246 231
232 class CC_EXPORT RasterTaskGraph {
233 public:
234 RasterTaskGraph();
235 ~RasterTaskGraph();
236
237 void InsertRasterTask(internal::WorkerPoolTask* raster_task,
238 const TaskVector& decode_tasks);
239
240 private:
241 friend class RasterWorkerPool;
242
243 TaskGraph graph_;
244 scoped_refptr<internal::WorkerPoolTask> raster_finished_task_;
245 scoped_ptr<GraphNode> raster_finished_node_;
246 unsigned next_priority_;
247
248 DISALLOW_COPY_AND_ASSIGN(RasterTaskGraph);
249 };
250
247 RasterWorkerPool(ResourceProvider* resource_provider, size_t num_threads); 251 RasterWorkerPool(ResourceProvider* resource_provider, size_t num_threads);
248 252
253 virtual void OnRasterTasksFinished() {}
254
249 void SetRasterTasks(RasterTask::Queue* queue); 255 void SetRasterTasks(RasterTask::Queue* queue);
250 void ScheduleRasterTasks(const RootTask& root); 256 void SetRasterTaskGraph(RasterTaskGraph* graph);
251 bool IsRasterTaskRequiredForActivation( 257 bool IsRasterTaskRequiredForActivation(
252 internal::RasterWorkerPoolTask* task) const; 258 internal::RasterWorkerPoolTask* task) const;
253 259
254 RasterWorkerPoolClient* client() const { return client_; } 260 RasterWorkerPoolClient* client() const { return client_; }
255 ResourceProvider* resource_provider() const { return resource_provider_; } 261 ResourceProvider* resource_provider() const { return resource_provider_; }
256 const RasterTask::Queue::TaskVector& raster_tasks() const { 262 const RasterTask::Queue::TaskVector& raster_tasks() const {
257 return raster_tasks_; 263 return raster_tasks_;
258 } 264 }
259 265
260 private: 266 private:
267 void OnRasterFinished(int64 schedule_raster_tasks_count);
268
261 RasterWorkerPoolClient* client_; 269 RasterWorkerPoolClient* client_;
262 ResourceProvider* resource_provider_; 270 ResourceProvider* resource_provider_;
263 RasterTask::Queue::TaskVector raster_tasks_; 271 RasterTask::Queue::TaskVector raster_tasks_;
264 RasterTask::Queue::TaskSet raster_tasks_required_for_activation_; 272 RasterTask::Queue::TaskSet raster_tasks_required_for_activation_;
265 273
266 // The root task that is a dependent of all other tasks. 274 base::WeakPtrFactory<RasterWorkerPool> weak_ptr_factory_;
267 scoped_refptr<internal::WorkerPoolTask> root_; 275 scoped_refptr<internal::WorkerPoolTask> raster_finished_task_;
276 int64 schedule_raster_tasks_count_;
268 }; 277 };
269 278
270 } // namespace cc 279 } // namespace cc
271 280
272 #endif // CC_RESOURCES_RASTER_WORKER_POOL_H_ 281 #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