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

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: pass unit tests 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
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
8 #include "cc/base/worker_pool.h" 10 #include "cc/base/worker_pool.h"
11 #include "cc/resources/resource_provider.h"
9 12
10 namespace cc { 13 namespace cc {
11 class PicturePileImpl; 14 class PicturePileImpl;
15 class Resource;
16
17 namespace internal {
18
19 class CC_EXPORT RasterWorkerPoolTask
20 : public base::RefCounted<RasterWorkerPoolTask> {
21 public:
22 typedef std::vector<scoped_refptr<RasterWorkerPoolTask> > TaskVector;
23
24 virtual bool RunOnThread(uint8_t* buffer, unsigned thread_index) = 0;
25 virtual void DispatchCompletionCallback() = 0;
26
27 void DidRun();
28 bool HasFinishedRunning() const;
29 void DidComplete();
30 bool HasCompleted() const;
31
32 const Resource* resource() const { return resource_; }
33 const WorkerPoolTask::TaskVector& dependencies() const {
34 return dependencies_;
35 }
36
37 protected:
38 friend class base::RefCounted<RasterWorkerPoolTask>;
39
40 RasterWorkerPoolTask(const Resource* resource,
41 WorkerPoolTask::TaskVector* dependencies);
42 virtual ~RasterWorkerPoolTask();
43
44 private:
45 bool did_run_;
46 bool did_complete_;
47 const Resource* resource_;
48 WorkerPoolTask::TaskVector dependencies_;
49 };
50
51 } // namespace internal
52
53 class CC_EXPORT RasterWorkerPoolClient {
54 public:
55 virtual void DidFinishDispatchingRasterWorkerPoolCompletionCallbacks() = 0;
56
57 protected:
58 virtual ~RasterWorkerPoolClient() {}
59 };
12 60
13 // A worker thread pool that runs raster tasks. 61 // A worker thread pool that runs raster tasks.
14 class CC_EXPORT RasterWorkerPool : public WorkerPool { 62 class CC_EXPORT RasterWorkerPool : public WorkerPool {
15 public: 63 public:
16 class Task { 64 class Task {
17 public: 65 public:
18 typedef base::Callback<void(bool)> Reply; 66 class Set {
67 public:
68 typedef internal::WorkerPoolTask::TaskVector TaskVector;
19 69
20 // Highest priority task first. Order of execution is not guaranteed. 70 Set();
21 class Queue { 71 ~Set();
22 public:
23 Queue();
24 ~Queue();
25 72
26 bool empty() const { return tasks_.empty(); } 73 void Insert(const Task& task);
27
28 // Add task to the back of the queue.
29 void Append(const Task& task);
30 74
31 private: 75 private:
32 friend class RasterWorkerPool; 76 friend class RasterWorkerPool;
33 77
34 internal::WorkerPoolTask::TaskVector tasks_; 78 TaskVector tasks_;
35 }; 79 };
36 80
37 Task(); 81 Task();
38 Task(const base::Closure& callback, const Reply& reply); 82 Task(const base::Closure& callback, const base::Closure& reply);
39 explicit Task(Queue* dependencies);
40 ~Task(); 83 ~Task();
41 84
42 // Returns true if Task is null (doesn't refer to anything). 85 // Returns true if Task is null (doesn't refer to anything).
43 bool is_null() const { return !internal_; } 86 bool is_null() const { return !internal_; }
44 87
45 // Returns the Task into an uninitialized state. 88 // Returns the Task into an uninitialized state.
46 void Reset(); 89 void Reset();
47 90
48 protected: 91 protected:
49 friend class RasterWorkerPool; 92 friend class RasterWorkerPool;
50 93
51 explicit Task(scoped_refptr<internal::WorkerPoolTask> internal);
52
53 scoped_refptr<internal::WorkerPoolTask> internal_; 94 scoped_refptr<internal::WorkerPoolTask> internal_;
54 }; 95 };
55 96
56 class PictureTask : public Task { 97 class RasterTask {
57 public: 98 public:
58 typedef base::Callback<void(PicturePileImpl*)> Callback; 99 // Returns true if buffer was written to. False indicate that
100 // buffer is not needed to initialize the resource. A ResourceInitializer
101 // instance can use this to determine if an upload is necessary.
102 typedef base::Callback<bool(uint8_t*, PicturePileImpl*)> Callback;
59 103
60 PictureTask(PicturePileImpl* picture_pile, 104 // First callback parameter is true when task was canceled.
61 const Callback& callback, 105 typedef base::Callback<void(bool)> Reply;
62 const Reply& reply, 106
63 Queue* dependencies); 107 class Queue {
108 public:
109 typedef internal::RasterWorkerPoolTask::TaskVector TaskVector;
110
111 Queue();
112 ~Queue();
113
114 void Append(const RasterTask& task);
115
116 private:
117 friend class RasterWorkerPool;
118
119 TaskVector tasks_;
120 };
121
122 RasterTask();
123 RasterTask(PicturePileImpl* picture_pile,
124 const Resource* resource,
125 const Callback& callback,
126 const Reply& reply,
127 Task::Set* dependencies);
128 ~RasterTask();
129
130 // Returns true if Task is null (doesn't refer to anything).
131 bool is_null() const { return !internal_; }
132
133 // Returns the Task into an uninitialized state.
134 void Reset();
135
136 protected:
137 friend class RasterWorkerPool;
138
139 scoped_refptr<internal::RasterWorkerPoolTask> internal_;
64 }; 140 };
65 141
66 virtual ~RasterWorkerPool(); 142 virtual ~RasterWorkerPool();
67 143
68 static scoped_ptr<RasterWorkerPool> Create(size_t num_threads) { 144 void SetClient(RasterWorkerPoolClient* client);
69 return make_scoped_ptr(new RasterWorkerPool(num_threads));
70 }
71 145
72 // Tells the worker pool to shutdown after canceling all previously 146 // Tells the worker pool to shutdown after canceling all previously
73 // scheduled tasks. Reply callbacks are still guaranteed to run. 147 // scheduled tasks. Reply callbacks are still guaranteed to run.
74 virtual void Shutdown() OVERRIDE; 148 virtual void Shutdown() OVERRIDE;
75 149
76 // Schedule running of |root| task and all its dependencies. Tasks 150 // Schedule running of raster tasks in |queue| and all dependencies.
77 // previously scheduled but no longer needed to run |root| will be 151 // Previously scheduled tasks that are no longer needed to run
78 // canceled unless already running. Once scheduled, reply callbacks 152 // raster tasks in |queue| will be canceled unless already running.
79 // are guaranteed to run for all tasks even if they later get 153 // Once scheduled, reply callbacks are guaranteed to run for all tasks
80 // canceled by another call to ScheduleTasks(). 154 // even if they later get canceled by another call to ScheduleTasks().
81 void ScheduleTasks(Task* root); 155 virtual void ScheduleTasks(RasterTask::Queue* queue);
82 156
83 private: 157 // Tells the raster worker pool to force any pending uploads for
84 explicit RasterWorkerPool(size_t num_threads); 158 // |resource_id| to complete. Returns true when successful.
159 virtual bool ForceUploadToComplete(ResourceProvider::ResourceId resource_id);
85 160
86 DISALLOW_COPY_AND_ASSIGN(RasterWorkerPool); 161 protected:
162 RasterWorkerPool(ResourceProvider* resource_provider, size_t num_threads);
163
164 void SetRasterTasks(RasterTask::Queue* queue);
165
166 ResourceProvider* resource_provider_;
167 RasterWorkerPoolClient* client_;
168 RasterTask::Queue::TaskVector raster_tasks_;
87 }; 169 };
88 170
89 } // namespace cc 171 } // namespace cc
90 172
91 #endif // CC_RESOURCES_RASTER_WORKER_POOL_H_ 173 #endif // CC_RESOURCES_RASTER_WORKER_POOL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698