Chromium Code Reviews| 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 | 90 |
| 91 // Task is not ready to run if dependencies are not yet satisfied. | 91 // Task is not ready to run if dependencies are not yet satisfied. |
| 92 if (node.dependencies) | 92 if (node.dependencies) |
| 93 continue; | 93 continue; |
| 94 | 94 |
| 95 // Skip if already finished running task. | 95 // Skip if already finished running task. |
| 96 if (node.task->HasFinishedRunning()) | 96 if (node.task->HasFinishedRunning()) |
| 97 continue; | 97 continue; |
| 98 | 98 |
| 99 // Skip if already running. | 99 // Skip if already running. |
| 100 if (std::find(task_namespace.running_tasks.begin(), | 100 const auto& running_tasks_for_category = |
| 101 task_namespace.running_tasks.end(), | 101 task_namespace.running_tasks.find(node.category); |
| 102 node.task) != task_namespace.running_tasks.end()) | 102 if (running_tasks_for_category != task_namespace.running_tasks.cend() && |
| 103 std::find(running_tasks_for_category->second.cbegin(), | |
| 104 running_tasks_for_category->second.cend(), | |
| 105 node.task) != running_tasks_for_category->second.cend()) | |
| 103 continue; | 106 continue; |
| 104 | 107 |
| 105 task_namespace.ready_to_run_tasks[node.category].push_back(PrioritizedTask( | 108 task_namespace.ready_to_run_tasks[node.category].push_back(PrioritizedTask( |
| 106 node.task, &task_namespace, node.category, node.priority)); | 109 node.task, &task_namespace, node.category, node.priority)); |
| 107 } | 110 } |
| 108 | 111 |
| 109 // Rearrange the elements in each vector within |ready_to_run_tasks| in such a | 112 // Rearrange the elements in each vector within |ready_to_run_tasks| in such a |
| 110 // way that they form a heap. | 113 // way that they form a heap. |
| 111 for (auto& it : task_namespace.ready_to_run_tasks) { | 114 for (auto& it : task_namespace.ready_to_run_tasks) { |
| 112 auto& ready_to_run_tasks = it.second; | 115 auto& ready_to_run_tasks = it.second; |
| 113 std::make_heap(ready_to_run_tasks.begin(), ready_to_run_tasks.end(), | 116 std::make_heap(ready_to_run_tasks.begin(), ready_to_run_tasks.end(), |
| 114 CompareTaskPriority); | 117 CompareTaskPriority); |
| 115 } | 118 } |
| 116 | 119 |
| 117 // Swap task graph. | 120 // Swap task graph. |
| 118 task_namespace.graph.Swap(graph); | 121 task_namespace.graph.Swap(graph); |
| 119 | 122 |
| 120 // Determine what tasks in old graph need to be canceled. | 123 // Determine what tasks in old graph need to be canceled. |
| 121 for (TaskGraph::Node::Vector::iterator it = graph->nodes.begin(); | 124 for (TaskGraph::Node::Vector::iterator it = graph->nodes.begin(); |
| 122 it != graph->nodes.end(); ++it) { | 125 it != graph->nodes.end(); ++it) { |
| 123 TaskGraph::Node& node = *it; | 126 TaskGraph::Node& node = *it; |
| 124 | 127 |
| 125 // Skip if already finished running task. | 128 // Skip if already finished running task. |
| 126 if (node.task->HasFinishedRunning()) | 129 if (node.task->HasFinishedRunning()) |
| 127 continue; | 130 continue; |
| 128 | 131 |
| 129 // Skip if already running. | 132 // Skip if already running. |
| 130 if (std::find(task_namespace.running_tasks.begin(), | 133 const auto& running_tasks_for_category = |
| 131 task_namespace.running_tasks.end(), | 134 task_namespace.running_tasks.find(node.category); |
| 132 node.task) != task_namespace.running_tasks.end()) | 135 if (running_tasks_for_category != task_namespace.running_tasks.cend() && |
| 136 std::find(running_tasks_for_category->second.cbegin(), | |
| 137 running_tasks_for_category->second.cend(), | |
| 138 node.task) != running_tasks_for_category->second.cend()) | |
| 133 continue; | 139 continue; |
| 134 | 140 |
| 135 DCHECK(std::find(task_namespace.completed_tasks.begin(), | 141 DCHECK(std::find(task_namespace.completed_tasks.begin(), |
| 136 task_namespace.completed_tasks.end(), | 142 task_namespace.completed_tasks.end(), |
| 137 node.task) == task_namespace.completed_tasks.end()); | 143 node.task) == task_namespace.completed_tasks.end()); |
| 138 task_namespace.completed_tasks.push_back(node.task); | 144 task_namespace.completed_tasks.push_back(node.task); |
| 139 } | 145 } |
| 140 | 146 |
| 141 // Build new "ready to run" task namespaces queue. | 147 // Build new "ready to run" task namespaces queue. |
| 142 for (auto& ready_to_run_namespaces_it : ready_to_run_namespaces_) { | 148 for (auto& ready_to_run_namespaces_it : ready_to_run_namespaces_) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 188 // Add task namespace back to |ready_to_run_namespaces| if not empty after | 194 // Add task namespace back to |ready_to_run_namespaces| if not empty after |
| 189 // taking top priority task. | 195 // taking top priority task. |
| 190 if (!ready_to_run_tasks.empty()) { | 196 if (!ready_to_run_tasks.empty()) { |
| 191 ready_to_run_namespaces.push_back(task_namespace); | 197 ready_to_run_namespaces.push_back(task_namespace); |
| 192 std::push_heap(ready_to_run_namespaces.begin(), | 198 std::push_heap(ready_to_run_namespaces.begin(), |
| 193 ready_to_run_namespaces.end(), | 199 ready_to_run_namespaces.end(), |
| 194 CompareTaskNamespacePriority(category)); | 200 CompareTaskNamespacePriority(category)); |
| 195 } | 201 } |
| 196 | 202 |
| 197 // Add task to |running_tasks|. | 203 // Add task to |running_tasks|. |
| 198 task_namespace->running_tasks.push_back(task.task); | 204 task_namespace->running_tasks[category].push_back(task.task); |
| 199 | 205 |
| 200 return task; | 206 return task; |
| 201 } | 207 } |
| 202 | 208 |
| 203 void TaskGraphWorkQueue::CompleteTask(const PrioritizedTask& completed_task) { | 209 void TaskGraphWorkQueue::CompleteTask(const PrioritizedTask& completed_task) { |
| 204 TaskNamespace* task_namespace = completed_task.task_namespace; | 210 TaskNamespace* task_namespace = completed_task.task_namespace; |
| 205 scoped_refptr<Task> task(completed_task.task); | 211 scoped_refptr<Task> task(completed_task.task); |
| 212 uint16_t category = completed_task.category; | |
| 206 | 213 |
| 207 // Remove task from |running_tasks|. | 214 // Remove task from |running_tasks|. |
| 208 auto it = std::find(task_namespace->running_tasks.begin(), | 215 auto& running_tasks_for_category = task_namespace->running_tasks[category]; |
| 209 task_namespace->running_tasks.end(), task); | 216 auto it = std::find(running_tasks_for_category.begin(), |
| 210 DCHECK(it != task_namespace->running_tasks.end()); | 217 running_tasks_for_category.end(), task); |
| 211 std::swap(*it, task_namespace->running_tasks.back()); | 218 DCHECK(it != running_tasks_for_category.end()); |
| 212 task_namespace->running_tasks.pop_back(); | 219 std::swap(*it, running_tasks_for_category.back()); |
| 220 running_tasks_for_category.pop_back(); | |
| 221 | |
| 222 // If |running_tasks_for_category| is empty, remove it from |running_tasks|. | |
|
reveman
2016/02/10 20:49:32
Is this necessary? Doesn't it cause some heap allo
ericrk
2016/02/10 22:30:04
I guess it's a trade-off - we either do this here
| |
| 223 if (running_tasks_for_category.size() == 0) | |
| 224 task_namespace->running_tasks.erase(category); | |
| 213 | 225 |
| 214 // Now iterate over all dependents to decrement dependencies and check if they | 226 // Now iterate over all dependents to decrement dependencies and check if they |
| 215 // are ready to run. | 227 // are ready to run. |
| 216 bool ready_to_run_namespaces_has_heap_properties = true; | 228 bool ready_to_run_namespaces_has_heap_properties = true; |
| 217 for (DependentIterator it(&task_namespace->graph, task.get()); it; ++it) { | 229 for (DependentIterator it(&task_namespace->graph, task.get()); it; ++it) { |
| 218 TaskGraph::Node& dependent_node = *it; | 230 TaskGraph::Node& dependent_node = *it; |
| 219 | 231 |
| 220 DCHECK_LT(0u, dependent_node.dependencies); | 232 DCHECK_LT(0u, dependent_node.dependencies); |
| 221 dependent_node.dependencies--; | 233 dependent_node.dependencies--; |
| 222 // Task is ready if it has no dependencies. Add it to |ready_to_run_tasks_|. | 234 // Task is ready if it has no dependencies. Add it to |ready_to_run_tasks_|. |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 | 302 |
| 291 for (const TaskGraph::Node& node : graph->nodes) { | 303 for (const TaskGraph::Node& node : graph->nodes) { |
| 292 if (dependents[node.task] != node.dependencies) | 304 if (dependents[node.task] != node.dependencies) |
| 293 return true; | 305 return true; |
| 294 } | 306 } |
| 295 | 307 |
| 296 return false; | 308 return false; |
| 297 } | 309 } |
| 298 | 310 |
| 299 } // namespace cc | 311 } // namespace cc |
| OLD | NEW |