Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "content/renderer/raster_worker_pool.h" | 5 #include "content/renderer/raster_worker_pool.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 cc::Task::Vector completed_tasks_; | 117 cc::Task::Vector completed_tasks_; |
| 118 }; | 118 }; |
| 119 | 119 |
| 120 RasterWorkerPool::RasterWorkerPool() | 120 RasterWorkerPool::RasterWorkerPool() |
| 121 : namespace_token_(GetNamespaceToken()), | 121 : namespace_token_(GetNamespaceToken()), |
| 122 has_ready_to_run_foreground_tasks_cv_(&lock_), | 122 has_ready_to_run_foreground_tasks_cv_(&lock_), |
| 123 has_ready_to_run_background_tasks_cv_(&lock_), | 123 has_ready_to_run_background_tasks_cv_(&lock_), |
| 124 has_namespaces_with_finished_running_tasks_cv_(&lock_), | 124 has_namespaces_with_finished_running_tasks_cv_(&lock_), |
| 125 shutdown_(false) {} | 125 shutdown_(false) {} |
| 126 | 126 |
| 127 void RasterWorkerPool::CreateAndStartRasterWorkerPoolThread( | |
| 128 const base::SimpleThread::Options& thread_options, | |
| 129 const std::vector<cc::TaskCategory>& categories, | |
| 130 base::ConditionVariable* has_ready_to_run_tasks_cv) { | |
| 131 scoped_ptr<base::SimpleThread> thread(new RasterWorkerPoolThread( | |
| 132 base::StringPrintf( | |
| 133 "CompositorTileWorker%u(%s)", | |
| 134 static_cast<unsigned>(threads_.size() + 1), | |
| 135 base::GetThreadPriorityAbbr(thread_options.priority()).c_str()) | |
| 136 .c_str(), | |
| 137 thread_options, this, categories, has_ready_to_run_tasks_cv)); | |
| 138 thread->Start(); | |
| 139 threads_.push_back(std::move(thread)); | |
| 140 } | |
| 141 | |
| 127 void RasterWorkerPool::Start(int num_threads) { | 142 void RasterWorkerPool::Start(int num_threads) { |
| 128 DCHECK(threads_.empty()); | 143 DCHECK(threads_.empty()); |
| 129 | 144 |
| 145 base::SimpleThread::Options thread_options; | |
| 146 | |
| 130 // Start |num_threads| threads for foreground work, including nonconcurrent | 147 // Start |num_threads| threads for foreground work, including nonconcurrent |
| 131 // foreground work. | 148 // foreground work. |
| 132 std::vector<cc::TaskCategory> foreground_categories; | 149 std::vector<cc::TaskCategory> foreground_categories; |
| 133 foreground_categories.push_back(cc::TASK_CATEGORY_NONCONCURRENT_FOREGROUND); | 150 foreground_categories.push_back(cc::TASK_CATEGORY_NONCONCURRENT_FOREGROUND); |
| 134 foreground_categories.push_back(cc::TASK_CATEGORY_FOREGROUND); | 151 foreground_categories.push_back(cc::TASK_CATEGORY_FOREGROUND); |
| 135 | |
| 136 for (int i = 0; i < num_threads; i++) { | 152 for (int i = 0; i < num_threads; i++) { |
| 137 scoped_ptr<base::SimpleThread> thread(new RasterWorkerPoolThread( | 153 CreateAndStartRasterWorkerPoolThread( |
| 138 base::StringPrintf("CompositorTileWorker%u", | 154 thread_options, foreground_categories, |
| 139 static_cast<unsigned>(threads_.size() + 1)) | 155 &has_ready_to_run_foreground_tasks_cv_); |
| 140 .c_str(), | |
| 141 base::SimpleThread::Options(), this, foreground_categories, | |
| 142 &has_ready_to_run_foreground_tasks_cv_)); | |
| 143 thread->Start(); | |
| 144 threads_.push_back(std::move(thread)); | |
| 145 } | 156 } |
| 146 | 157 |
| 158 // Use background priority for background thread. | |
| 159 #if !defined(OS_MACOSX) | |
| 160 thread_options.set_priority(base::ThreadPriority::BACKGROUND); | |
| 161 #endif | |
| 147 // Start a single thread for background work. | 162 // Start a single thread for background work. |
| 148 std::vector<cc::TaskCategory> background_categories; | 163 std::vector<cc::TaskCategory> background_categories; |
| 149 background_categories.push_back(cc::TASK_CATEGORY_BACKGROUND); | 164 background_categories.push_back(cc::TASK_CATEGORY_BACKGROUND); |
| 150 | 165 CreateAndStartRasterWorkerPoolThread(thread_options, background_categories, |
| 151 // Use background priority for background thread. | 166 &has_ready_to_run_background_tasks_cv_); |
| 152 base::SimpleThread::Options thread_options; | |
| 153 #if !defined(OS_MACOSX) | |
| 154 thread_options.set_priority(base::ThreadPriority::BACKGROUND); | |
| 155 #endif | |
| 156 | |
| 157 scoped_ptr<base::SimpleThread> thread(new RasterWorkerPoolThread( | |
| 158 base::StringPrintf("CompositorTileWorker%u", | |
|
reveman
2016/03/24 15:40:46
Can we reduce this patch to a one line change here
prashant.n
2016/03/24 17:13:29
Okay. I'll reduce the patch. May be later we can a
| |
| 159 static_cast<unsigned>(threads_.size() + 1)) | |
| 160 .c_str(), | |
| 161 thread_options, this, background_categories, | |
| 162 &has_ready_to_run_background_tasks_cv_)); | |
| 163 thread->Start(); | |
| 164 threads_.push_back(std::move(thread)); | |
| 165 } | 167 } |
| 166 | 168 |
| 167 void RasterWorkerPool::Shutdown() { | 169 void RasterWorkerPool::Shutdown() { |
| 168 WaitForTasksToFinishRunning(namespace_token_); | 170 WaitForTasksToFinishRunning(namespace_token_); |
| 169 CollectCompletedTasks(namespace_token_, &completed_tasks_); | 171 CollectCompletedTasks(namespace_token_, &completed_tasks_); |
| 170 // Shutdown raster threads. | 172 // Shutdown raster threads. |
| 171 { | 173 { |
| 172 base::AutoLock lock(lock_); | 174 base::AutoLock lock(lock_); |
| 173 | 175 |
| 174 DCHECK(!work_queue_.HasReadyToRunTasks()); | 176 DCHECK(!work_queue_.HasReadyToRunTasks()); |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 427 | 429 |
| 428 // Overridden from cc::Task: | 430 // Overridden from cc::Task: |
| 429 void RasterWorkerPool::ClosureTask::RunOnWorkerThread() { | 431 void RasterWorkerPool::ClosureTask::RunOnWorkerThread() { |
| 430 closure_.Run(); | 432 closure_.Run(); |
| 431 closure_.Reset(); | 433 closure_.Reset(); |
| 432 } | 434 } |
| 433 | 435 |
| 434 RasterWorkerPool::ClosureTask::~ClosureTask() {} | 436 RasterWorkerPool::ClosureTask::~ClosureTask() {} |
| 435 | 437 |
| 436 } // namespace content | 438 } // namespace content |
| OLD | NEW |