| 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 "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "base/threading/thread_restrictions.h" | 8 #include "base/threading/thread_restrictions.h" |
| 9 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
| 10 #include "cc/raster/task_category.h" |
| 10 | 11 |
| 11 namespace content { | 12 namespace content { |
| 12 | 13 |
| 13 // A sequenced task runner which posts tasks to a RasterWorkerPool. | 14 // A sequenced task runner which posts tasks to a RasterWorkerPool. |
| 14 class RasterWorkerPool::RasterWorkerPoolSequencedTaskRunner | 15 class RasterWorkerPool::RasterWorkerPoolSequencedTaskRunner |
| 15 : public base::SequencedTaskRunner { | 16 : public base::SequencedTaskRunner { |
| 16 public: | 17 public: |
| 17 explicit RasterWorkerPoolSequencedTaskRunner( | 18 explicit RasterWorkerPoolSequencedTaskRunner( |
| 18 cc::TaskGraphRunner* task_graph_runner) | 19 cc::TaskGraphRunner* task_graph_runner) |
| 19 : task_graph_runner_(task_graph_runner), | 20 : task_graph_runner_(task_graph_runner), |
| (...skipping 20 matching lines...) Expand all Loading... |
| 40 | 41 |
| 41 tasks_.erase(tasks_.begin(), tasks_.begin() + completed_tasks_.size()); | 42 tasks_.erase(tasks_.begin(), tasks_.begin() + completed_tasks_.size()); |
| 42 | 43 |
| 43 tasks_.push_back(make_scoped_refptr(new ClosureTask(task))); | 44 tasks_.push_back(make_scoped_refptr(new ClosureTask(task))); |
| 44 graph_.Reset(); | 45 graph_.Reset(); |
| 45 for (const auto& graph_task : tasks_) { | 46 for (const auto& graph_task : tasks_) { |
| 46 int dependencies = 0; | 47 int dependencies = 0; |
| 47 if (!graph_.nodes.empty()) | 48 if (!graph_.nodes.empty()) |
| 48 dependencies = 1; | 49 dependencies = 1; |
| 49 | 50 |
| 50 cc::TaskGraph::Node node(graph_task.get(), 0, dependencies); | 51 cc::TaskGraph::Node node(graph_task.get(), |
| 52 cc::TASK_CATEGORY_HIGH_PRIORITY, |
| 53 0u /* priority */, dependencies); |
| 51 if (dependencies) { | 54 if (dependencies) { |
| 52 graph_.edges.push_back( | 55 graph_.edges.push_back( |
| 53 cc::TaskGraph::Edge(graph_.nodes.back().task, node.task)); | 56 cc::TaskGraph::Edge(graph_.nodes.back().task, node.task)); |
| 54 } | 57 } |
| 55 graph_.nodes.push_back(node); | 58 graph_.nodes.push_back(node); |
| 56 } | 59 } |
| 57 task_graph_runner_->ScheduleTasks(namespace_token_, &graph_); | 60 task_graph_runner_->ScheduleTasks(namespace_token_, &graph_); |
| 58 completed_tasks_.clear(); | 61 completed_tasks_.clear(); |
| 59 return true; | 62 return true; |
| 60 } | 63 } |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 tasks_.begin(), tasks_.end(), [this](const scoped_refptr<cc::Task>& e) { | 144 tasks_.begin(), tasks_.end(), [this](const scoped_refptr<cc::Task>& e) { |
| 142 return std::find(this->completed_tasks_.begin(), | 145 return std::find(this->completed_tasks_.begin(), |
| 143 this->completed_tasks_.end(), | 146 this->completed_tasks_.end(), |
| 144 e) != this->completed_tasks_.end(); | 147 e) != this->completed_tasks_.end(); |
| 145 }); | 148 }); |
| 146 tasks_.erase(end, tasks_.end()); | 149 tasks_.erase(end, tasks_.end()); |
| 147 | 150 |
| 148 tasks_.push_back(make_scoped_refptr(new ClosureTask(task))); | 151 tasks_.push_back(make_scoped_refptr(new ClosureTask(task))); |
| 149 graph_.Reset(); | 152 graph_.Reset(); |
| 150 for (const auto& graph_task : tasks_) | 153 for (const auto& graph_task : tasks_) |
| 151 graph_.nodes.push_back(cc::TaskGraph::Node(graph_task.get(), 0, 0)); | 154 graph_.nodes.push_back( |
| 155 cc::TaskGraph::Node(graph_task.get(), cc::TASK_CATEGORY_HIGH_PRIORITY, |
| 156 0u /* priority */, 0u /* dependencies */)); |
| 152 | 157 |
| 153 ScheduleTasksWithLockAcquired(namespace_token_, &graph_); | 158 ScheduleTasksWithLockAcquired(namespace_token_, &graph_); |
| 154 completed_tasks_.clear(); | 159 completed_tasks_.clear(); |
| 155 return true; | 160 return true; |
| 156 } | 161 } |
| 157 | 162 |
| 158 bool RasterWorkerPool::RunsTasksOnCurrentThread() const { | 163 bool RasterWorkerPool::RunsTasksOnCurrentThread() const { |
| 159 return true; | 164 return true; |
| 160 } | 165 } |
| 161 | 166 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 cc::Task::Vector* completed_tasks) { | 261 cc::Task::Vector* completed_tasks) { |
| 257 DCHECK(token.IsValid()); | 262 DCHECK(token.IsValid()); |
| 258 work_queue_.CollectCompletedTasks(token, completed_tasks); | 263 work_queue_.CollectCompletedTasks(token, completed_tasks); |
| 259 } | 264 } |
| 260 | 265 |
| 261 void RasterWorkerPool::RunTaskWithLockAcquired() { | 266 void RasterWorkerPool::RunTaskWithLockAcquired() { |
| 262 TRACE_EVENT0("toplevel", "TaskGraphRunner::RunTask"); | 267 TRACE_EVENT0("toplevel", "TaskGraphRunner::RunTask"); |
| 263 | 268 |
| 264 lock_.AssertAcquired(); | 269 lock_.AssertAcquired(); |
| 265 | 270 |
| 266 auto prioritized_task = work_queue_.GetNextTaskToRun(); | 271 // Find the first category with any tasks to run. Categories used by this task |
| 272 // graph runner are ordered by priority. |
| 273 // TODO(ericrk): Add more category/thread logic. |
| 274 uint16_t category; |
| 275 for (category = 0u; category < cc::kNumTaskCategories; ++category) { |
| 276 if (work_queue_.HasReadyToRunTasksForCategory(category)) |
| 277 break; |
| 278 } |
| 279 DCHECK(category < cc::kNumTaskCategories); |
| 280 |
| 281 auto prioritized_task = work_queue_.GetNextTaskToRun(category); |
| 267 cc::Task* task = prioritized_task.task; | 282 cc::Task* task = prioritized_task.task; |
| 268 | 283 |
| 269 // There may be more work available, so wake up another worker thread. | 284 // There may be more work available, so wake up another worker thread. |
| 270 if (work_queue_.HasReadyToRunTasks()) | 285 if (work_queue_.HasReadyToRunTasks()) |
| 271 has_ready_to_run_tasks_cv_.Signal(); | 286 has_ready_to_run_tasks_cv_.Signal(); |
| 272 | 287 |
| 273 // Call WillRun() before releasing |lock_| and running task. | 288 // Call WillRun() before releasing |lock_| and running task. |
| 274 task->WillRun(); | 289 task->WillRun(); |
| 275 | 290 |
| 276 { | 291 { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 295 | 310 |
| 296 // Overridden from cc::Task: | 311 // Overridden from cc::Task: |
| 297 void RasterWorkerPool::ClosureTask::RunOnWorkerThread() { | 312 void RasterWorkerPool::ClosureTask::RunOnWorkerThread() { |
| 298 closure_.Run(); | 313 closure_.Run(); |
| 299 closure_.Reset(); | 314 closure_.Reset(); |
| 300 } | 315 } |
| 301 | 316 |
| 302 RasterWorkerPool::ClosureTask::~ClosureTask() {} | 317 RasterWorkerPool::ClosureTask::~ClosureTask() {} |
| 303 | 318 |
| 304 } // namespace content | 319 } // namespace content |
| OLD | NEW |