| OLD | NEW |
| 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 #include "cc/worker_pool.h" | 5 #include "cc/worker_pool.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 } | 52 } |
| 53 | 53 |
| 54 void WorkerPoolTask::Completed() { | 54 void WorkerPoolTask::Completed() { |
| 55 reply_.Run(); | 55 reply_.Run(); |
| 56 } | 56 } |
| 57 | 57 |
| 58 } // namespace internal | 58 } // namespace internal |
| 59 | 59 |
| 60 WorkerPool::Worker::Worker( | 60 WorkerPool::Worker::Worker( |
| 61 WorkerPool* worker_pool, | 61 WorkerPool* worker_pool, |
| 62 const std::string name, | 62 const std::string name) |
| 63 scoped_ptr<RenderingStats> rendering_stats) | |
| 64 : base::Thread(name.c_str()), | 63 : base::Thread(name.c_str()), |
| 65 worker_pool_(worker_pool), | 64 worker_pool_(worker_pool), |
| 66 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 65 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 67 rendering_stats_(rendering_stats.Pass()) { | |
| 68 Start(); | 66 Start(); |
| 69 DCHECK(IsRunning()); | 67 DCHECK(IsRunning()); |
| 70 } | 68 } |
| 71 | 69 |
| 72 WorkerPool::Worker::~Worker() { | 70 WorkerPool::Worker::~Worker() { |
| 73 DCHECK(!IsRunning()); | 71 DCHECK(!IsRunning()); |
| 74 DCHECK_EQ(pending_tasks_.size(), 0); | 72 DCHECK_EQ(pending_tasks_.size(), 0); |
| 75 } | 73 } |
| 76 | 74 |
| 77 void WorkerPool::Worker::StopAfterCompletingAllPendingTasks() { | 75 void WorkerPool::Worker::StopAfterCompletingAllPendingTasks() { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 | 116 |
| 119 void WorkerPool::Worker::OnTaskCompleted() { | 117 void WorkerPool::Worker::OnTaskCompleted() { |
| 120 CHECK(!pending_tasks_.empty()); | 118 CHECK(!pending_tasks_.empty()); |
| 121 | 119 |
| 122 scoped_ptr<internal::WorkerPoolTask> task = pending_tasks_.take_front(); | 120 scoped_ptr<internal::WorkerPoolTask> task = pending_tasks_.take_front(); |
| 123 task->Completed(); | 121 task->Completed(); |
| 124 | 122 |
| 125 worker_pool_->DidNumPendingTasksChange(); | 123 worker_pool_->DidNumPendingTasksChange(); |
| 126 } | 124 } |
| 127 | 125 |
| 128 WorkerPool::WorkerPool(size_t num_threads, bool record_rendering_stats) | 126 WorkerPool::WorkerPool(size_t num_threads) |
| 129 : workers_need_sorting_(false), | 127 : workers_need_sorting_(false), |
| 130 shutdown_(false) { | 128 shutdown_(false) { |
| 131 const std::string thread_name_prefix = kWorkerThreadNamePrefix; | 129 const std::string thread_name_prefix = kWorkerThreadNamePrefix; |
| 132 while (workers_.size() < num_threads) { | 130 while (workers_.size() < num_threads) { |
| 133 int thread_number = workers_.size() + 1; | 131 int thread_number = workers_.size() + 1; |
| 134 scoped_ptr<RenderingStats> rendering_stats = record_rendering_stats ? | |
| 135 make_scoped_ptr(new RenderingStats) : scoped_ptr<RenderingStats>(); | |
| 136 workers_.push_back(new Worker( | 132 workers_.push_back(new Worker( |
| 137 this, | 133 this, |
| 138 thread_name_prefix + StringPrintf("Worker%d", thread_number).c_str(), | 134 thread_name_prefix + StringPrintf("Worker%d", thread_number).c_str())); |
| 139 rendering_stats.Pass())); | |
| 140 } | 135 } |
| 141 } | 136 } |
| 142 | 137 |
| 143 WorkerPool::~WorkerPool() { | 138 WorkerPool::~WorkerPool() { |
| 144 Shutdown(); | 139 Shutdown(); |
| 145 STLDeleteElements(&workers_); | 140 STLDeleteElements(&workers_); |
| 146 } | 141 } |
| 147 | 142 |
| 148 void WorkerPool::Shutdown() { | 143 void WorkerPool::Shutdown() { |
| 149 DCHECK(!shutdown_); | 144 DCHECK(!shutdown_); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 165 task, | 160 task, |
| 166 reply)).PassAs<internal::WorkerPoolTask>()); | 161 reply)).PassAs<internal::WorkerPoolTask>()); |
| 167 } | 162 } |
| 168 | 163 |
| 169 bool WorkerPool::IsBusy() { | 164 bool WorkerPool::IsBusy() { |
| 170 Worker* worker = GetWorkerForNextTask(); | 165 Worker* worker = GetWorkerForNextTask(); |
| 171 | 166 |
| 172 return worker->num_pending_tasks() >= kNumPendingTasksPerWorker; | 167 return worker->num_pending_tasks() >= kNumPendingTasksPerWorker; |
| 173 } | 168 } |
| 174 | 169 |
| 170 void WorkerPool::SetRecordRenderingStats(bool record_rendering_stats) { |
| 171 for (WorkerVector::iterator it = workers_.begin(); |
| 172 it != workers_.end(); ++it) { |
| 173 Worker* worker = *it; |
| 174 worker->SetRenderingStats(record_rendering_stats ? |
| 175 make_scoped_ptr(new RenderingStats) : scoped_ptr<RenderingStats>()); |
| 176 } |
| 177 } |
| 178 |
| 175 void WorkerPool::GetRenderingStats(RenderingStats* stats) { | 179 void WorkerPool::GetRenderingStats(RenderingStats* stats) { |
| 176 stats->totalRasterizeTime = base::TimeDelta(); | 180 stats->totalRasterizeTime = base::TimeDelta(); |
| 177 stats->totalPixelsRasterized = 0; | 181 stats->totalPixelsRasterized = 0; |
| 178 stats->totalDeferredImageDecodeCount = 0; | 182 stats->totalDeferredImageDecodeCount = 0; |
| 179 stats->totalDeferredImageDecodeTime = base::TimeDelta(); | 183 stats->totalDeferredImageDecodeTime = base::TimeDelta(); |
| 180 for (WorkerVector::iterator it = workers_.begin(); | 184 for (WorkerVector::iterator it = workers_.begin(); |
| 181 it != workers_.end(); ++it) { | 185 it != workers_.end(); ++it) { |
| 182 Worker* worker = *it; | 186 Worker* worker = *it; |
| 183 CHECK(worker->rendering_stats()); | 187 CHECK(worker->rendering_stats()); |
| 184 stats->totalRasterizeTime += | 188 stats->totalRasterizeTime += |
| (...skipping 19 matching lines...) Expand all Loading... |
| 204 | 208 |
| 205 void WorkerPool::SortWorkersIfNeeded() { | 209 void WorkerPool::SortWorkersIfNeeded() { |
| 206 if (!workers_need_sorting_) | 210 if (!workers_need_sorting_) |
| 207 return; | 211 return; |
| 208 | 212 |
| 209 std::sort(workers_.begin(), workers_.end(), NumPendingTasksComparator()); | 213 std::sort(workers_.begin(), workers_.end(), NumPendingTasksComparator()); |
| 210 workers_need_sorting_ = false; | 214 workers_need_sorting_ = false; |
| 211 } | 215 } |
| 212 | 216 |
| 213 } // namespace cc | 217 } // namespace cc |
| OLD | NEW |