OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/raster/task_graph_work_queue.h" | 5 #include "cc/raster/task_graph_work_queue.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 NamespaceToken TaskGraphWorkQueue::GetNamespaceToken() { | 58 NamespaceToken TaskGraphWorkQueue::GetNamespaceToken() { |
59 NamespaceToken token(next_namespace_id_++); | 59 NamespaceToken token(next_namespace_id_++); |
60 DCHECK(namespaces_.find(token) == namespaces_.end()); | 60 DCHECK(namespaces_.find(token) == namespaces_.end()); |
61 return token; | 61 return token; |
62 } | 62 } |
63 | 63 |
64 void TaskGraphWorkQueue::ScheduleTasks(NamespaceToken token, TaskGraph* graph) { | 64 void TaskGraphWorkQueue::ScheduleTasks(NamespaceToken token, TaskGraph* graph) { |
65 TaskNamespace& task_namespace = namespaces_[token]; | 65 TaskNamespace& task_namespace = namespaces_[token]; |
66 | 66 |
67 // First adjust number of dependencies to reflect completed tasks. | 67 // First adjust number of dependencies to reflect completed tasks. |
68 for (const scoped_refptr<Task>& task : task_namespace.completed_tasks) { | 68 for (const scoped_refptr<DependencyTask>& task : |
| 69 task_namespace.completed_tasks) { |
69 for (DependentIterator node_it(graph, task.get()); node_it; ++node_it) { | 70 for (DependentIterator node_it(graph, task.get()); node_it; ++node_it) { |
70 TaskGraph::Node& node = *node_it; | 71 TaskGraph::Node& node = *node_it; |
71 DCHECK_LT(0u, node.dependencies); | 72 DCHECK_LT(0u, node.dependencies); |
72 node.dependencies--; | 73 node.dependencies--; |
73 } | 74 } |
74 } | 75 } |
75 | 76 |
76 // Build new "ready to run" queue and remove nodes from old graph. | 77 // Build new "ready to run" queue and remove nodes from old graph. |
77 for (auto& ready_to_run_tasks_it : task_namespace.ready_to_run_tasks) { | 78 for (auto& ready_to_run_tasks_it : task_namespace.ready_to_run_tasks) { |
78 ready_to_run_tasks_it.second.clear(); | 79 ready_to_run_tasks_it.second.clear(); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 | 204 |
204 // Add task to |running_tasks|. | 205 // Add task to |running_tasks|. |
205 task_namespace->running_tasks.push_back( | 206 task_namespace->running_tasks.push_back( |
206 std::make_pair(task.category, task.task)); | 207 std::make_pair(task.category, task.task)); |
207 | 208 |
208 return task; | 209 return task; |
209 } | 210 } |
210 | 211 |
211 void TaskGraphWorkQueue::CompleteTask(const PrioritizedTask& completed_task) { | 212 void TaskGraphWorkQueue::CompleteTask(const PrioritizedTask& completed_task) { |
212 TaskNamespace* task_namespace = completed_task.task_namespace; | 213 TaskNamespace* task_namespace = completed_task.task_namespace; |
213 scoped_refptr<Task> task(completed_task.task); | 214 scoped_refptr<DependencyTask> task(completed_task.task); |
214 | 215 |
215 // Remove task from |running_tasks|. | 216 // Remove task from |running_tasks|. |
216 auto it = std::find_if(task_namespace->running_tasks.begin(), | 217 auto it = std::find_if(task_namespace->running_tasks.begin(), |
217 task_namespace->running_tasks.end(), | 218 task_namespace->running_tasks.end(), |
218 [&completed_task](const CategorizedTask& task) { | 219 [&completed_task](const CategorizedTask& task) { |
219 return task.second == completed_task.task; | 220 return task.second == completed_task.task; |
220 }); | 221 }); |
221 DCHECK(it != task_namespace->running_tasks.end()); | 222 DCHECK(it != task_namespace->running_tasks.end()); |
222 std::swap(*it, task_namespace->running_tasks.back()); | 223 std::swap(*it, task_namespace->running_tasks.back()); |
223 task_namespace->running_tasks.pop_back(); | 224 task_namespace->running_tasks.pop_back(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 std::make_heap(ready_to_run_namespaces.begin(), | 267 std::make_heap(ready_to_run_namespaces.begin(), |
267 ready_to_run_namespaces.end(), | 268 ready_to_run_namespaces.end(), |
268 CompareTaskNamespacePriority(category)); | 269 CompareTaskNamespacePriority(category)); |
269 } | 270 } |
270 } | 271 } |
271 | 272 |
272 // Finally add task to |completed_tasks_|. | 273 // Finally add task to |completed_tasks_|. |
273 task_namespace->completed_tasks.push_back(task); | 274 task_namespace->completed_tasks.push_back(task); |
274 } | 275 } |
275 | 276 |
276 void TaskGraphWorkQueue::CollectCompletedTasks(NamespaceToken token, | 277 void TaskGraphWorkQueue::CollectCompletedTasks( |
277 Task::Vector* completed_tasks) { | 278 NamespaceToken token, |
| 279 DependencyTask::Vector* completed_tasks) { |
278 TaskNamespaceMap::iterator it = namespaces_.find(token); | 280 TaskNamespaceMap::iterator it = namespaces_.find(token); |
279 if (it == namespaces_.end()) | 281 if (it == namespaces_.end()) |
280 return; | 282 return; |
281 | 283 |
282 TaskNamespace& task_namespace = it->second; | 284 TaskNamespace& task_namespace = it->second; |
283 | 285 |
284 DCHECK_EQ(0u, completed_tasks->size()); | 286 DCHECK_EQ(0u, completed_tasks->size()); |
285 completed_tasks->swap(task_namespace.completed_tasks); | 287 completed_tasks->swap(task_namespace.completed_tasks); |
286 if (!HasFinishedRunningTasksInNamespace(&task_namespace)) | 288 if (!HasFinishedRunningTasksInNamespace(&task_namespace)) |
287 return; | 289 return; |
288 | 290 |
289 // Remove namespace if finished running tasks. | 291 // Remove namespace if finished running tasks. |
290 DCHECK_EQ(0u, task_namespace.completed_tasks.size()); | 292 DCHECK_EQ(0u, task_namespace.completed_tasks.size()); |
291 DCHECK(!HasReadyToRunTasksInNamespace(&task_namespace)); | 293 DCHECK(!HasReadyToRunTasksInNamespace(&task_namespace)); |
292 DCHECK_EQ(0u, task_namespace.running_tasks.size()); | 294 DCHECK_EQ(0u, task_namespace.running_tasks.size()); |
293 namespaces_.erase(it); | 295 namespaces_.erase(it); |
294 } | 296 } |
295 | 297 |
296 bool TaskGraphWorkQueue::DependencyMismatch(const TaskGraph* graph) { | 298 bool TaskGraphWorkQueue::DependencyMismatch(const TaskGraph* graph) { |
297 // Value storage will be 0-initialized. | 299 // Value storage will be 0-initialized. |
298 std::unordered_map<const Task*, size_t> dependents; | 300 std::unordered_map<const DependencyTask*, size_t> dependents; |
299 for (const TaskGraph::Edge& edge : graph->edges) | 301 for (const TaskGraph::Edge& edge : graph->edges) |
300 dependents[edge.dependent]++; | 302 dependents[edge.dependent]++; |
301 | 303 |
302 for (const TaskGraph::Node& node : graph->nodes) { | 304 for (const TaskGraph::Node& node : graph->nodes) { |
303 if (dependents[node.task] != node.dependencies) | 305 if (dependents[node.task] != node.dependencies) |
304 return true; | 306 return true; |
305 } | 307 } |
306 | 308 |
307 return false; | 309 return false; |
308 } | 310 } |
309 | 311 |
310 } // namespace cc | 312 } // namespace cc |
OLD | NEW |