| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 TaskGraph::Node& node = *node_it; | 70 TaskGraph::Node& node = *node_it; |
| 71 DCHECK_LT(0u, node.dependencies); | 71 DCHECK_LT(0u, node.dependencies); |
| 72 node.dependencies--; | 72 node.dependencies--; |
| 73 } | 73 } |
| 74 } | 74 } |
| 75 | 75 |
| 76 // Build new "ready to run" queue and remove nodes from old graph. | 76 // 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) { | 77 for (auto& ready_to_run_tasks_it : task_namespace.ready_to_run_tasks) { |
| 78 ready_to_run_tasks_it.second.clear(); | 78 ready_to_run_tasks_it.second.clear(); |
| 79 } | 79 } |
| 80 |
| 81 for (const CategorizedTask& task : task_namespace.running_tasks) { |
| 82 task.second->cancelled = true; |
| 83 } |
| 84 |
| 80 for (const TaskGraph::Node& node : graph->nodes) { | 85 for (const TaskGraph::Node& node : graph->nodes) { |
| 81 // Remove any old nodes that are associated with this task. The result is | 86 // Remove any old nodes that are associated with this task. The result is |
| 82 // that the old graph is left with all nodes not present in this graph, | 87 // that the old graph is left with all nodes not present in this graph, |
| 83 // which we use below to determine what tasks need to be canceled. | 88 // which we use below to determine what tasks need to be canceled. |
| 84 TaskGraph::Node::Vector::iterator old_it = std::find_if( | 89 TaskGraph::Node::Vector::iterator old_it = std::find_if( |
| 85 task_namespace.graph.nodes.begin(), task_namespace.graph.nodes.end(), | 90 task_namespace.graph.nodes.begin(), task_namespace.graph.nodes.end(), |
| 86 [node](const TaskGraph::Node& other) { | 91 [node](const TaskGraph::Node& other) { |
| 87 return node.task == other.task; | 92 return node.task == other.task; |
| 88 }); | 93 }); |
| 89 if (old_it != task_namespace.graph.nodes.end()) { | 94 if (old_it != task_namespace.graph.nodes.end()) { |
| 90 std::swap(*old_it, task_namespace.graph.nodes.back()); | 95 std::swap(*old_it, task_namespace.graph.nodes.back()); |
| 91 task_namespace.graph.nodes.pop_back(); | 96 task_namespace.graph.nodes.pop_back(); |
| 92 } | 97 } |
| 93 | 98 |
| 94 // Task is not ready to run if dependencies are not yet satisfied. | 99 // Task is not ready to run if dependencies are not yet satisfied. |
| 95 if (node.dependencies) | 100 if (node.dependencies) |
| 96 continue; | 101 continue; |
| 97 | 102 |
| 98 // Skip if already finished running task. | 103 // Skip if already finished running task. |
| 99 if (node.task->HasFinishedRunning()) | 104 if (node.task->HasFinishedRunning()) |
| 100 continue; | 105 continue; |
| 101 | 106 |
| 102 // Skip if already running. | 107 // Skip if already running. |
| 103 if (std::any_of(task_namespace.running_tasks.begin(), | 108 if (std::any_of(task_namespace.running_tasks.begin(), |
| 104 task_namespace.running_tasks.end(), | 109 task_namespace.running_tasks.end(), |
| 105 [&node](const CategorizedTask& task) { | 110 [&node](const CategorizedTask& task) { |
| 111 if (task.second == node.task) { |
| 112 if (task.first > node.category) { |
| 113 TRACE_EVENT2("cc, pras", "Task::Rescheduled::Speedup", |
| 114 "Old Category", task.first, |
| 115 "New Category", node.category); |
| 116 } else if (task.first < node.category) { |
| 117 TRACE_EVENT2("cc, pras", |
| 118 "Task::Rescheduled::Slowdown", |
| 119 "Old Category", task.first, |
| 120 "New Category", node.category); |
| 121 } else { |
| 122 TRACE_EVENT2("cc, pras", "Task::Rescheduled::Same", |
| 123 "Old Category", task.first, |
| 124 "New Category", node.category); |
| 125 } |
| 126 |
| 127 task.second->cancelled = false; |
| 128 } |
| 129 |
| 106 return task.second == node.task; | 130 return task.second == node.task; |
| 107 })) | 131 })) |
| 108 continue; | 132 continue; |
| 109 | 133 |
| 134 { |
| 135 TRACE_EVENT1("cc, pras", "Task::Scheduled::New", "New Category", |
| 136 node.category); |
| 137 } |
| 138 |
| 110 task_namespace.ready_to_run_tasks[node.category].push_back(PrioritizedTask( | 139 task_namespace.ready_to_run_tasks[node.category].push_back(PrioritizedTask( |
| 111 node.task, &task_namespace, node.category, node.priority)); | 140 node.task, &task_namespace, node.category, node.priority)); |
| 112 } | 141 } |
| 113 | 142 |
| 143 for (const CategorizedTask& task : task_namespace.running_tasks) { |
| 144 if (task.second->cancelled) { |
| 145 TRACE_EVENT1("cc, pras", "Task::Rescheduled::Cancelled", "Old Category", |
| 146 task.first); |
| 147 } |
| 148 } |
| 149 |
| 114 // Rearrange the elements in each vector within |ready_to_run_tasks| in such a | 150 // Rearrange the elements in each vector within |ready_to_run_tasks| in such a |
| 115 // way that they form a heap. | 151 // way that they form a heap. |
| 116 for (auto& it : task_namespace.ready_to_run_tasks) { | 152 for (auto& it : task_namespace.ready_to_run_tasks) { |
| 117 auto& ready_to_run_tasks = it.second; | 153 auto& ready_to_run_tasks = it.second; |
| 118 std::make_heap(ready_to_run_tasks.begin(), ready_to_run_tasks.end(), | 154 std::make_heap(ready_to_run_tasks.begin(), ready_to_run_tasks.end(), |
| 119 CompareTaskPriority); | 155 CompareTaskPriority); |
| 120 } | 156 } |
| 121 | 157 |
| 122 // Swap task graph. | 158 // Swap task graph. |
| 123 task_namespace.graph.Swap(graph); | 159 task_namespace.graph.Swap(graph); |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 | 337 |
| 302 for (const TaskGraph::Node& node : graph->nodes) { | 338 for (const TaskGraph::Node& node : graph->nodes) { |
| 303 if (dependents[node.task] != node.dependencies) | 339 if (dependents[node.task] != node.dependencies) |
| 304 return true; | 340 return true; |
| 305 } | 341 } |
| 306 | 342 |
| 307 return false; | 343 return false; |
| 308 } | 344 } |
| 309 | 345 |
| 310 } // namespace cc | 346 } // namespace cc |
| OLD | NEW |