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

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: Post a task to run cheap tasks. 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
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 virtual void Run(RenderingStats* rendering_stats) = 0; 26 virtual void Run(RenderingStats* rendering_stats) = 0;
27 virtual void DeferToThread(base::Thread* thread) = 0;
27 28
28 bool HasCompleted(); 29 bool HasCompleted();
29 void DidComplete(); 30 void DidComplete();
30 31
31 protected: 32 protected:
32 WorkerPoolTask(const base::Closure& reply); 33 WorkerPoolTask(const base::Closure& reply);
33 34
34 const base::Closure reply_; 35 const base::Closure reply_;
35 36
36 // Accessed from multiple threads. Set to 1 when task has completed. 37 // Accessed from multiple threads. Set to 1 when task has completed.
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 115
115 WorkerPool* worker_pool_; 116 WorkerPool* worker_pool_;
116 ScopedPtrDeque<internal::WorkerPoolTask> pending_tasks_; 117 ScopedPtrDeque<internal::WorkerPoolTask> pending_tasks_;
117 scoped_ptr<RenderingStats> rendering_stats_; 118 scoped_ptr<RenderingStats> rendering_stats_;
118 bool record_rendering_stats_; 119 bool record_rendering_stats_;
119 }; 120 };
120 121
121 WorkerPool(WorkerPoolClient* client, size_t num_threads); 122 WorkerPool(WorkerPoolClient* client, size_t num_threads);
122 123
123 WorkerPool::Worker* GetWorkerForNextTask(); 124 WorkerPool::Worker* GetWorkerForNextTask();
125 bool CanPostCheapTask() const;
126 void PostCheapTask(scoped_ptr<internal::WorkerPoolTask> task);
124 127
125 private: 128 private:
126 class NumPendingTasksComparator { 129 class NumPendingTasksComparator {
127 public: 130 public:
128 bool operator() (const Worker* a, const Worker* b) const { 131 bool operator() (const Worker* a, const Worker* b) const {
129 return a->num_pending_tasks() < b->num_pending_tasks(); 132 return a->num_pending_tasks() < b->num_pending_tasks();
130 } 133 }
131 }; 134 };
132 135
133 // Schedule a completed tasks check if not already pending. 136 // Schedule a completed tasks check if not already pending.
(...skipping 10 matching lines...) Expand all
144 147
145 // Check for completed tasks and run reply callbacks. 148 // Check for completed tasks and run reply callbacks.
146 void CheckForCompletedTasks(); 149 void CheckForCompletedTasks();
147 150
148 // Called when processing task completion. 151 // Called when processing task completion.
149 void OnTaskCompleted(); 152 void OnTaskCompleted();
150 153
151 // Ensure workers are sorted by number of pending tasks. 154 // Ensure workers are sorted by number of pending tasks.
152 void SortWorkersIfNeeded(); 155 void SortWorkersIfNeeded();
153 156
157 // Run pending cheap tasks on origin thread.
158 void RunCheapTasks();
159
154 typedef std::vector<Worker*> WorkerVector; 160 typedef std::vector<Worker*> WorkerVector;
155 WorkerVector workers_; 161 WorkerVector workers_;
156 WorkerPoolClient* client_; 162 WorkerPoolClient* client_;
157 scoped_refptr<base::MessageLoopProxy> origin_loop_; 163 scoped_refptr<base::MessageLoopProxy> origin_loop_;
158 base::WeakPtrFactory<WorkerPool> weak_ptr_factory_; 164 base::WeakPtrFactory<WorkerPool> weak_ptr_factory_;
159 bool workers_need_sorting_; 165 bool workers_need_sorting_;
160 bool shutdown_; 166 bool shutdown_;
161 base::CancelableClosure check_for_completed_tasks_callback_; 167 base::CancelableClosure check_for_completed_tasks_callback_;
162 bool check_for_completed_tasks_pending_; 168 bool check_for_completed_tasks_pending_;
163 base::Closure idle_callback_; 169 base::Closure idle_callback_;
170 base::Closure cheap_task_callback_;
164 // Accessed from multiple threads. 0 when worker pool is idle. 171 // Accessed from multiple threads. 0 when worker pool is idle.
165 base::subtle::Atomic32 pending_task_count_; 172 base::subtle::Atomic32 pending_task_count_;
166 173
174 bool cheap_tasks_allowed_;
175 bool run_cheap_tasks_pending_;
176 ScopedPtrDeque<internal::WorkerPoolTask> pending_cheap_tasks_;
177 scoped_ptr<RenderingStats> cheap_rendering_stats_;
178
167 DISALLOW_COPY_AND_ASSIGN(WorkerPool); 179 DISALLOW_COPY_AND_ASSIGN(WorkerPool);
168 }; 180 };
169 181
170 } // namespace cc 182 } // namespace cc
171 183
172 #endif // CC_WORKER_POOL_H_ 184 #endif // CC_WORKER_POOL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698