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

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

Issue 165603002: cc: Move GPU raster to DirectRasterWorkerPool. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix typo Created 6 years, 10 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 | Annotate | Revision Log
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 <deque> 8 #include <deque>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 23 matching lines...) Expand all
34 virtual void OnRasterCompleted(RasterWorkerPoolTask* task, 34 virtual void OnRasterCompleted(RasterWorkerPoolTask* task,
35 const PicturePileImpl::Analysis& analysis) = 0; 35 const PicturePileImpl::Analysis& analysis) = 0;
36 virtual void OnImageDecodeCompleted(WorkerPoolTask* task) = 0; 36 virtual void OnImageDecodeCompleted(WorkerPoolTask* task) = 0;
37 37
38 protected: 38 protected:
39 virtual ~WorkerPoolTaskClient() {} 39 virtual ~WorkerPoolTaskClient() {}
40 }; 40 };
41 41
42 class CC_EXPORT WorkerPoolTask : public Task { 42 class CC_EXPORT WorkerPoolTask : public Task {
43 public: 43 public:
44 typedef std::vector<scoped_refptr<WorkerPoolTask> > Vector;
45
44 virtual void ScheduleOnOriginThread(WorkerPoolTaskClient* client) = 0; 46 virtual void ScheduleOnOriginThread(WorkerPoolTaskClient* client) = 0;
47 virtual void RunOnOriginThread() = 0;
45 virtual void CompleteOnOriginThread(WorkerPoolTaskClient* client) = 0; 48 virtual void CompleteOnOriginThread(WorkerPoolTaskClient* client) = 0;
46 virtual void RunReplyOnOriginThread() = 0; 49 virtual void RunReplyOnOriginThread() = 0;
47 50
48 void WillSchedule(); 51 void WillSchedule();
49 void DidSchedule(); 52 void DidSchedule();
50 bool HasBeenScheduled() const; 53 bool HasBeenScheduled() const;
51 54
52 void WillComplete(); 55 void WillComplete();
53 void DidComplete(); 56 void DidComplete();
54 bool HasCompleted() const; 57 bool HasCompleted() const;
55 58
56 protected: 59 protected:
57 WorkerPoolTask(); 60 WorkerPoolTask();
58 virtual ~WorkerPoolTask(); 61 virtual ~WorkerPoolTask();
59 62
60 bool did_schedule_; 63 bool did_schedule_;
61 bool did_complete_; 64 bool did_complete_;
62 }; 65 };
63 66
64 class CC_EXPORT RasterWorkerPoolTask : public WorkerPoolTask { 67 class CC_EXPORT RasterWorkerPoolTask : public WorkerPoolTask {
65 public: 68 public:
66 virtual void RunOnOriginThread(ResourceProvider* resource_provider,
67 ContextProvider* context_provider) = 0;
68
69 const Resource* resource() const { return resource_; } 69 const Resource* resource() const { return resource_; }
70 const internal::Task::Vector& dependencies() const { return dependencies_; } 70 const internal::WorkerPoolTask::Vector& dependencies() const {
71 bool use_gpu_rasterization() const { return use_gpu_rasterization_; } 71 return dependencies_;
72 }
72 73
73 protected: 74 protected:
74 RasterWorkerPoolTask(const Resource* resource, 75 RasterWorkerPoolTask(const Resource* resource,
75 internal::Task::Vector* dependencies, 76 internal::WorkerPoolTask::Vector* dependencies);
76 bool use_gpu_rasterization);
77 virtual ~RasterWorkerPoolTask(); 77 virtual ~RasterWorkerPoolTask();
78 78
79 private: 79 private:
80 const Resource* resource_; 80 const Resource* resource_;
81 Task::Vector dependencies_; 81 WorkerPoolTask::Vector dependencies_;
82 bool use_gpu_rasterization_;
83 }; 82 };
84 83
85 } // namespace internal 84 } // namespace internal
86 85
87 class CC_EXPORT RasterWorkerPoolClient { 86 class CC_EXPORT RasterWorkerPoolClient {
88 public: 87 public:
89 virtual bool ShouldForceTasksRequiredForActivationToComplete() const = 0; 88 virtual bool ShouldForceTasksRequiredForActivationToComplete() const = 0;
90 virtual void DidFinishRunningTasks() = 0; 89 virtual void DidFinishRunningTasks() = 0;
91 virtual void DidFinishRunningTasksRequiredForActivation() = 0; 90 virtual void DidFinishRunningTasksRequiredForActivation() = 0;
92 91
(...skipping 11 matching lines...) Expand all
104 class CC_EXPORT Set { 103 class CC_EXPORT Set {
105 public: 104 public:
106 Set(); 105 Set();
107 ~Set(); 106 ~Set();
108 107
109 void Insert(const Task& task); 108 void Insert(const Task& task);
110 109
111 private: 110 private:
112 friend class RasterWorkerPool; 111 friend class RasterWorkerPool;
113 112
114 internal::Task::Vector tasks_; 113 internal::WorkerPoolTask::Vector tasks_;
115 }; 114 };
116 115
117 Task(); 116 Task();
118 ~Task(); 117 ~Task();
119 118
120 // Returns true if Task is null (doesn't refer to anything). 119 // Returns true if Task is null (doesn't refer to anything).
121 bool is_null() const { return !internal_.get(); } 120 bool is_null() const { return !internal_.get(); }
122 121
123 // Returns the Task into an uninitialized state. 122 // Returns the Task into an uninitialized state.
124 void Reset(); 123 void Reset();
(...skipping 20 matching lines...) Expand all
145 void Append(const RasterTask& task, bool required_for_activation); 144 void Append(const RasterTask& task, bool required_for_activation);
146 void Swap(Queue* other); 145 void Swap(Queue* other);
147 146
148 size_t count() const { return tasks_.size(); } 147 size_t count() const { return tasks_.size(); }
149 size_t required_for_activation_count() const { 148 size_t required_for_activation_count() const {
150 return required_for_activation_count_; 149 return required_for_activation_count_;
151 } 150 }
152 151
153 private: 152 private:
154 friend class RasterWorkerPool; 153 friend class RasterWorkerPool;
154 friend class DirectRasterWorkerPool;
155 155
156 struct QueuedTask { 156 struct QueuedTask {
157 class TaskComparator {
158 public:
159 explicit TaskComparator(const internal::RasterWorkerPoolTask* task)
160 : task_(task) {}
161
162 bool operator()(const QueuedTask& queued_task) const {
163 return queued_task.task == task_;
164 }
165
166 private:
167 const internal::RasterWorkerPoolTask* task_;
168 };
169
157 typedef std::vector<QueuedTask> Vector; 170 typedef std::vector<QueuedTask> Vector;
158 171
159 QueuedTask(internal::RasterWorkerPoolTask* task, 172 QueuedTask(internal::RasterWorkerPoolTask* task,
160 bool required_for_activation); 173 bool required_for_activation);
161 ~QueuedTask(); 174 ~QueuedTask();
162 175
163 scoped_refptr<internal::RasterWorkerPoolTask> task; 176 scoped_refptr<internal::RasterWorkerPoolTask> task;
164 bool required_for_activation; 177 bool required_for_activation;
165 }; 178 };
166 179
(...skipping 14 matching lines...) Expand all
181 friend class RasterWorkerPool; 194 friend class RasterWorkerPool;
182 195
183 explicit RasterTask(internal::RasterWorkerPoolTask* internal); 196 explicit RasterTask(internal::RasterWorkerPoolTask* internal);
184 197
185 scoped_refptr<internal::RasterWorkerPoolTask> internal_; 198 scoped_refptr<internal::RasterWorkerPoolTask> internal_;
186 }; 199 };
187 200
188 virtual ~RasterWorkerPool(); 201 virtual ~RasterWorkerPool();
189 202
190 static void SetNumRasterThreads(int num_threads); 203 static void SetNumRasterThreads(int num_threads);
191
192 static int GetNumRasterThreads(); 204 static int GetNumRasterThreads();
193 205
194 static internal::TaskGraphRunner* GetTaskGraphRunner(); 206 static internal::TaskGraphRunner* GetTaskGraphRunner();
195 207
196 static unsigned kOnDemandRasterTaskPriority; 208 static unsigned kOnDemandRasterTaskPriority;
197 static unsigned kRasterFinishedTaskPriority; 209 static unsigned kRasterFinishedTaskPriority;
198 static unsigned kRasterRequiredForActivationFinishedTaskPriority; 210 static unsigned kRasterRequiredForActivationFinishedTaskPriority;
199 static unsigned kRasterTaskPriorityBase; 211 static unsigned kRasterTaskPriorityBase;
200 212
201 // TODO(vmpstr): Figure out an elegant way to not pass this many parameters. 213 // TODO(vmpstr): Figure out an elegant way to not pass this many parameters.
202 static RasterTask CreateRasterTask( 214 static RasterTask CreateRasterTask(
203 const Resource* resource, 215 const Resource* resource,
204 PicturePileImpl* picture_pile, 216 PicturePileImpl* picture_pile,
205 const gfx::Rect& content_rect, 217 const gfx::Rect& content_rect,
206 float contents_scale, 218 float contents_scale,
207 RasterMode raster_mode, 219 RasterMode raster_mode,
208 TileResolution tile_resolution, 220 TileResolution tile_resolution,
209 int layer_id, 221 int layer_id,
210 const void* tile_id, 222 const void* tile_id,
211 int source_frame_number, 223 int source_frame_number,
212 bool use_gpu_rasterization,
213 RenderingStatsInstrumentation* rendering_stats, 224 RenderingStatsInstrumentation* rendering_stats,
214 const RasterTask::Reply& reply, 225 const RasterTask::Reply& reply,
215 Task::Set* dependencies); 226 Task::Set* dependencies,
227 ContextProvider* context_provider);
216 228
217 static Task CreateImageDecodeTask( 229 static Task CreateImageDecodeTask(
218 SkPixelRef* pixel_ref, 230 SkPixelRef* pixel_ref,
219 int layer_id, 231 int layer_id,
220 RenderingStatsInstrumentation* rendering_stats, 232 RenderingStatsInstrumentation* rendering_stats,
221 const Task::Reply& reply); 233 const Task::Reply& reply);
222 234
223 void SetClient(RasterWorkerPoolClient* client); 235 void SetClient(RasterWorkerPoolClient* client);
224 236
225 // Tells the worker pool to shutdown after canceling all previously 237 // Tells the worker pool to shutdown after canceling all previously
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 private: 287 private:
276 const RasterTask::Queue::QueuedTask::Vector* tasks_; 288 const RasterTask::Queue::QueuedTask::Vector* tasks_;
277 size_t current_index_; 289 size_t current_index_;
278 }; 290 };
279 typedef std::vector<scoped_refptr<internal::WorkerPoolTask> > TaskVector; 291 typedef std::vector<scoped_refptr<internal::WorkerPoolTask> > TaskVector;
280 typedef std::deque<scoped_refptr<internal::WorkerPoolTask> > TaskDeque; 292 typedef std::deque<scoped_refptr<internal::WorkerPoolTask> > TaskDeque;
281 typedef std::vector<scoped_refptr<internal::RasterWorkerPoolTask> > 293 typedef std::vector<scoped_refptr<internal::RasterWorkerPoolTask> >
282 RasterTaskVector; 294 RasterTaskVector;
283 295
284 RasterWorkerPool(internal::TaskGraphRunner* task_graph_runner, 296 RasterWorkerPool(internal::TaskGraphRunner* task_graph_runner,
285 ResourceProvider* resource_provider, 297 ResourceProvider* resource_provider);
286 ContextProvider* context_provider);
287 298
288 virtual void OnRasterTasksFinished() = 0; 299 virtual void OnRasterTasksFinished() = 0;
289 virtual void OnRasterTasksRequiredForActivationFinished() = 0; 300 virtual void OnRasterTasksRequiredForActivationFinished() = 0;
290 301
291 void SetTaskGraph(internal::TaskGraph* graph); 302 void SetTaskGraph(internal::TaskGraph* graph);
292 void CollectCompletedWorkerPoolTasks(internal::Task::Vector* completed_tasks); 303 void CollectCompletedWorkerPoolTasks(internal::Task::Vector* completed_tasks);
293 304
294 // Run raster tasks that use GPU on current thread.
295 void RunGpuRasterTasks(const RasterTaskVector& tasks);
296 void CheckForCompletedGpuRasterTasks();
297
298 RasterWorkerPoolClient* client() const { return client_; } 305 RasterWorkerPoolClient* client() const { return client_; }
299 ResourceProvider* resource_provider() const { return resource_provider_; } 306 ResourceProvider* resource_provider() const { return resource_provider_; }
300 ContextProvider* context_provider() const { return context_provider_; }
301 307
302 void set_raster_finished_task( 308 void set_raster_finished_task(
303 internal::WorkerPoolTask* raster_finished_task) { 309 internal::WorkerPoolTask* raster_finished_task) {
304 raster_finished_task_ = raster_finished_task; 310 raster_finished_task_ = raster_finished_task;
305 } 311 }
312 internal::WorkerPoolTask* raster_finished_task() const {
313 return raster_finished_task_.get();
314 }
306 void set_raster_required_for_activation_finished_task( 315 void set_raster_required_for_activation_finished_task(
307 internal::WorkerPoolTask* raster_required_for_activation_finished_task) { 316 internal::WorkerPoolTask* raster_required_for_activation_finished_task) {
308 raster_required_for_activation_finished_task_ = 317 raster_required_for_activation_finished_task_ =
309 raster_required_for_activation_finished_task; 318 raster_required_for_activation_finished_task;
310 } 319 }
320 internal::WorkerPoolTask* raster_required_for_activation_finished_task()
321 const {
322 return raster_required_for_activation_finished_task_.get();
323 }
311 324
312 scoped_refptr<internal::WorkerPoolTask> CreateRasterFinishedTask(); 325 scoped_refptr<internal::WorkerPoolTask> CreateRasterFinishedTask();
313 scoped_refptr<internal::WorkerPoolTask> 326 scoped_refptr<internal::WorkerPoolTask>
314 CreateRasterRequiredForActivationFinishedTask( 327 CreateRasterRequiredForActivationFinishedTask(
315 size_t tasks_required_for_activation_count); 328 size_t tasks_required_for_activation_count);
316 329
317 scoped_ptr<base::Value> ScheduledStateAsValue() const; 330 void RunTaskOnOriginThread(internal::WorkerPoolTask* task);
318 331
319 static void InsertNodeForTask(internal::TaskGraph* graph, 332 static void InsertNodeForTask(internal::TaskGraph* graph,
320 internal::WorkerPoolTask* task, 333 internal::WorkerPoolTask* task,
321 unsigned priority, 334 unsigned priority,
322 size_t dependencies); 335 size_t dependencies);
323 336
324 static void InsertNodeForRasterTask( 337 static void InsertNodeForRasterTask(
325 internal::TaskGraph* graph, 338 internal::TaskGraph* graph,
326 internal::WorkerPoolTask* task, 339 internal::WorkerPoolTask* task,
327 const internal::Task::Vector& decode_tasks, 340 const internal::WorkerPoolTask::Vector& decode_tasks,
328 unsigned priority); 341 unsigned priority);
329 342
330 private: 343 private:
331 void OnRasterFinished(const internal::WorkerPoolTask* source); 344 void OnRasterFinished(const internal::WorkerPoolTask* source);
332 void OnRasterRequiredForActivationFinished( 345 void OnRasterRequiredForActivationFinished(
333 const internal::WorkerPoolTask* source); 346 const internal::WorkerPoolTask* source);
334 347
335 internal::TaskGraphRunner* task_graph_runner_; 348 internal::TaskGraphRunner* task_graph_runner_;
336 internal::NamespaceToken namespace_token_; 349 internal::NamespaceToken namespace_token_;
337 RasterWorkerPoolClient* client_; 350 RasterWorkerPoolClient* client_;
338 ResourceProvider* resource_provider_; 351 ResourceProvider* resource_provider_;
339 ContextProvider* context_provider_;
340 TaskDeque completed_gpu_raster_tasks_;
341 352
342 scoped_refptr<internal::WorkerPoolTask> raster_finished_task_; 353 scoped_refptr<internal::WorkerPoolTask> raster_finished_task_;
343 scoped_refptr<internal::WorkerPoolTask> 354 scoped_refptr<internal::WorkerPoolTask>
344 raster_required_for_activation_finished_task_; 355 raster_required_for_activation_finished_task_;
345 base::WeakPtrFactory<RasterWorkerPool> weak_ptr_factory_; 356 base::WeakPtrFactory<RasterWorkerPool> weak_ptr_factory_;
346 }; 357 };
347 358
348 } // namespace cc 359 } // namespace cc
349 360
350 #endif // CC_RESOURCES_RASTER_WORKER_POOL_H_ 361 #endif // CC_RESOURCES_RASTER_WORKER_POOL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698