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

Side by Side Diff: cc/worker_pool.h

Issue 12194015: cc: Rasterize cheap tiles immediately (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Refactoring PostTask. Created 7 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
« no previous file with comments | « cc/tile_manager.cc ('k') | cc/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_WORKER_POOL_H_ 5 #ifndef CC_WORKER_POOL_H_
6 #define CC_WORKER_POOL_H_ 6 #define CC_WORKER_POOL_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/cancelable_callback.h" 12 #include "base/cancelable_callback.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "base/threading/thread.h" 15 #include "base/threading/thread.h"
16 #include "cc/rendering_stats.h" 16 #include "cc/rendering_stats.h"
17 #include "cc/scoped_ptr_deque.h" 17 #include "cc/scoped_ptr_deque.h"
18 18
19 namespace cc { 19 namespace cc {
20 namespace internal { 20 namespace internal {
21 21
22 class WorkerPoolTask { 22 class WorkerPoolTask {
23 public: 23 public:
24 virtual ~WorkerPoolTask(); 24 virtual ~WorkerPoolTask();
25 25
26 // Called when the task is scheduled to run on a thread that isn't the
27 // origin thread. Called on the origin thread.
28 virtual void WillRunOnThread(base::Thread* thread) = 0;
29
26 virtual void Run(RenderingStats* rendering_stats) = 0; 30 virtual void Run(RenderingStats* rendering_stats) = 0;
27 31
28 bool HasCompleted(); 32 bool HasCompleted();
29 void DidComplete(); 33 void DidComplete();
30 34
31 protected: 35 protected:
32 WorkerPoolTask(const base::Closure& reply); 36 WorkerPoolTask(const base::Closure& reply);
33 37
34 const base::Closure reply_; 38 const base::Closure reply_;
35 39
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 void OnTaskCompleted(); 117 void OnTaskCompleted();
114 118
115 WorkerPool* worker_pool_; 119 WorkerPool* worker_pool_;
116 ScopedPtrDeque<internal::WorkerPoolTask> pending_tasks_; 120 ScopedPtrDeque<internal::WorkerPoolTask> pending_tasks_;
117 scoped_ptr<RenderingStats> rendering_stats_; 121 scoped_ptr<RenderingStats> rendering_stats_;
118 bool record_rendering_stats_; 122 bool record_rendering_stats_;
119 }; 123 };
120 124
121 WorkerPool(WorkerPoolClient* client, size_t num_threads); 125 WorkerPool(WorkerPoolClient* client, size_t num_threads);
122 126
123 WorkerPool::Worker* GetWorkerForNextTask(); 127 void PostTask(scoped_ptr<internal::WorkerPoolTask> task, bool is_cheap);
124 128
125 private: 129 private:
126 class NumPendingTasksComparator { 130 class NumPendingTasksComparator {
127 public: 131 public:
128 bool operator() (const Worker* a, const Worker* b) const { 132 bool operator() (const Worker* a, const Worker* b) const {
129 return a->num_pending_tasks() < b->num_pending_tasks(); 133 return a->num_pending_tasks() < b->num_pending_tasks();
130 } 134 }
131 }; 135 };
132 136
133 // Schedule a completed tasks check if not already pending. 137 // Schedule a completed tasks check if not already pending.
134 void ScheduleCheckForCompletedTasks(); 138 void ScheduleCheckForCompletedTasks();
135 139
136 // Called on origin thread before posting task to worker.
137 void WillPostTask();
138
139 // Called on worker thread after completing work. 140 // Called on worker thread after completing work.
140 void OnWorkCompletedOnWorkerThread(); 141 void OnWorkCompletedOnWorkerThread();
141 142
142 // Called on origin thread after becoming idle. 143 // Called on origin thread after becoming idle.
143 void OnIdle(); 144 void OnIdle();
144 145
145 // Check for completed tasks and run reply callbacks. 146 // Check for completed tasks and run reply callbacks.
146 void CheckForCompletedTasks(); 147 void CheckForCompletedTasks();
147 148
148 // Called when processing task completion. 149 // Called when processing task completion.
149 void OnTaskCompleted(); 150 void OnTaskCompleted();
150 151
151 // Ensure workers are sorted by number of pending tasks. 152 // Ensure workers are sorted by number of pending tasks.
152 void SortWorkersIfNeeded(); 153 void SortWorkersIfNeeded();
153 154
155 // Schedule running cheap tasks on the origin thread unless already pending.
156 void ScheduleRunCheapTasks();
157
158 // Run pending cheap tasks on the origin thread. If the allotted time slot
159 // for cheap tasks runs out, the remaining tasks are deferred to the thread
160 // pool.
161 void RunCheapTasks();
162
163 WorkerPool::Worker* GetWorkerForNextTask();
164 bool CanPostCheapTask() const;
165
154 typedef std::vector<Worker*> WorkerVector; 166 typedef std::vector<Worker*> WorkerVector;
155 WorkerVector workers_; 167 WorkerVector workers_;
156 WorkerPoolClient* client_; 168 WorkerPoolClient* client_;
157 scoped_refptr<base::MessageLoopProxy> origin_loop_; 169 scoped_refptr<base::MessageLoopProxy> origin_loop_;
158 base::WeakPtrFactory<WorkerPool> weak_ptr_factory_; 170 base::WeakPtrFactory<WorkerPool> weak_ptr_factory_;
159 bool workers_need_sorting_; 171 bool workers_need_sorting_;
160 bool shutdown_; 172 bool shutdown_;
161 base::CancelableClosure check_for_completed_tasks_callback_; 173 base::CancelableClosure check_for_completed_tasks_callback_;
162 bool check_for_completed_tasks_pending_; 174 base::TimeTicks check_for_completed_tasks_deadline_;
163 base::Closure idle_callback_; 175 base::Closure idle_callback_;
176 base::Closure cheap_task_callback_;
164 // Accessed from multiple threads. 0 when worker pool is idle. 177 // Accessed from multiple threads. 0 when worker pool is idle.
165 base::subtle::Atomic32 pending_task_count_; 178 base::subtle::Atomic32 pending_task_count_;
166 179
180 bool run_cheap_tasks_pending_;
181 ScopedPtrDeque<internal::WorkerPoolTask> pending_cheap_tasks_;
182 ScopedPtrDeque<internal::WorkerPoolTask> completed_cheap_tasks_;
183 scoped_ptr<RenderingStats> cheap_rendering_stats_;
184
167 DISALLOW_COPY_AND_ASSIGN(WorkerPool); 185 DISALLOW_COPY_AND_ASSIGN(WorkerPool);
168 }; 186 };
169 187
170 } // namespace cc 188 } // namespace cc
171 189
172 #endif // CC_WORKER_POOL_H_ 190 #endif // CC_WORKER_POOL_H_
OLDNEW
« no previous file with comments | « cc/tile_manager.cc ('k') | cc/worker_pool.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698