Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Side by Side Diff: cc/raster/task_graph_work_queue.cc

Issue 1666283002: Reland - Refactor signaling in RWP (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: x++ > ++x Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 if (std::any_of(task_namespace.running_tasks.begin(),
101 task_namespace.running_tasks.end(), 101 task_namespace.running_tasks.end(),
102 node.task) != task_namespace.running_tasks.end()) 102 [&node](const CategorizedTask& task) {
103 return task.second == node.task;
104 }))
103 continue; 105 continue;
104 106
105 task_namespace.ready_to_run_tasks[node.category].push_back(PrioritizedTask( 107 task_namespace.ready_to_run_tasks[node.category].push_back(PrioritizedTask(
106 node.task, &task_namespace, node.category, node.priority)); 108 node.task, &task_namespace, node.category, node.priority));
107 } 109 }
108 110
109 // Rearrange the elements in each vector within |ready_to_run_tasks| in such a 111 // Rearrange the elements in each vector within |ready_to_run_tasks| in such a
110 // way that they form a heap. 112 // way that they form a heap.
111 for (auto& it : task_namespace.ready_to_run_tasks) { 113 for (auto& it : task_namespace.ready_to_run_tasks) {
112 auto& ready_to_run_tasks = it.second; 114 auto& ready_to_run_tasks = it.second;
113 std::make_heap(ready_to_run_tasks.begin(), ready_to_run_tasks.end(), 115 std::make_heap(ready_to_run_tasks.begin(), ready_to_run_tasks.end(),
114 CompareTaskPriority); 116 CompareTaskPriority);
115 } 117 }
116 118
117 // Swap task graph. 119 // Swap task graph.
118 task_namespace.graph.Swap(graph); 120 task_namespace.graph.Swap(graph);
119 121
120 // Determine what tasks in old graph need to be canceled. 122 // Determine what tasks in old graph need to be canceled.
121 for (TaskGraph::Node::Vector::iterator it = graph->nodes.begin(); 123 for (TaskGraph::Node::Vector::iterator it = graph->nodes.begin();
122 it != graph->nodes.end(); ++it) { 124 it != graph->nodes.end(); ++it) {
123 TaskGraph::Node& node = *it; 125 TaskGraph::Node& node = *it;
124 126
125 // Skip if already finished running task. 127 // Skip if already finished running task.
126 if (node.task->HasFinishedRunning()) 128 if (node.task->HasFinishedRunning())
127 continue; 129 continue;
128 130
129 // Skip if already running. 131 // Skip if already running.
130 if (std::find(task_namespace.running_tasks.begin(), 132 if (std::any_of(task_namespace.running_tasks.begin(),
131 task_namespace.running_tasks.end(), 133 task_namespace.running_tasks.end(),
132 node.task) != task_namespace.running_tasks.end()) 134 [&node](const CategorizedTask& task) {
135 return task.second == node.task;
136 }))
133 continue; 137 continue;
134 138
135 DCHECK(std::find(task_namespace.completed_tasks.begin(), 139 DCHECK(std::find(task_namespace.completed_tasks.begin(),
136 task_namespace.completed_tasks.end(), 140 task_namespace.completed_tasks.end(),
137 node.task) == task_namespace.completed_tasks.end()); 141 node.task) == task_namespace.completed_tasks.end());
138 task_namespace.completed_tasks.push_back(node.task); 142 task_namespace.completed_tasks.push_back(node.task);
139 } 143 }
140 144
141 // Build new "ready to run" task namespaces queue. 145 // Build new "ready to run" task namespaces queue.
142 for (auto& ready_to_run_namespaces_it : ready_to_run_namespaces_) { 146 for (auto& ready_to_run_namespaces_it : ready_to_run_namespaces_) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 // Add task namespace back to |ready_to_run_namespaces| if not empty after 192 // Add task namespace back to |ready_to_run_namespaces| if not empty after
189 // taking top priority task. 193 // taking top priority task.
190 if (!ready_to_run_tasks.empty()) { 194 if (!ready_to_run_tasks.empty()) {
191 ready_to_run_namespaces.push_back(task_namespace); 195 ready_to_run_namespaces.push_back(task_namespace);
192 std::push_heap(ready_to_run_namespaces.begin(), 196 std::push_heap(ready_to_run_namespaces.begin(),
193 ready_to_run_namespaces.end(), 197 ready_to_run_namespaces.end(),
194 CompareTaskNamespacePriority(category)); 198 CompareTaskNamespacePriority(category));
195 } 199 }
196 200
197 // Add task to |running_tasks|. 201 // Add task to |running_tasks|.
198 task_namespace->running_tasks.push_back(task.task); 202 task_namespace->running_tasks.push_back(
203 std::make_pair(task.category, task.task));
199 204
200 return task; 205 return task;
201 } 206 }
202 207
203 void TaskGraphWorkQueue::CompleteTask(const PrioritizedTask& completed_task) { 208 void TaskGraphWorkQueue::CompleteTask(const PrioritizedTask& completed_task) {
204 TaskNamespace* task_namespace = completed_task.task_namespace; 209 TaskNamespace* task_namespace = completed_task.task_namespace;
205 scoped_refptr<Task> task(completed_task.task); 210 scoped_refptr<Task> task(completed_task.task);
206 211
207 // Remove task from |running_tasks|. 212 // Remove task from |running_tasks|.
208 auto it = std::find(task_namespace->running_tasks.begin(), 213 auto it = std::find_if(task_namespace->running_tasks.begin(),
209 task_namespace->running_tasks.end(), task); 214 task_namespace->running_tasks.end(),
215 [&completed_task](const CategorizedTask& task) {
216 return task.second == completed_task.task;
217 });
210 DCHECK(it != task_namespace->running_tasks.end()); 218 DCHECK(it != task_namespace->running_tasks.end());
211 std::swap(*it, task_namespace->running_tasks.back()); 219 std::swap(*it, task_namespace->running_tasks.back());
212 task_namespace->running_tasks.pop_back(); 220 task_namespace->running_tasks.pop_back();
213 221
214 // Now iterate over all dependents to decrement dependencies and check if they 222 // Now iterate over all dependents to decrement dependencies and check if they
215 // are ready to run. 223 // are ready to run.
216 bool ready_to_run_namespaces_has_heap_properties = true; 224 bool ready_to_run_namespaces_has_heap_properties = true;
217 for (DependentIterator it(&task_namespace->graph, task.get()); it; ++it) { 225 for (DependentIterator it(&task_namespace->graph, task.get()); it; ++it) {
218 TaskGraph::Node& dependent_node = *it; 226 TaskGraph::Node& dependent_node = *it;
219 227
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 298
291 for (const TaskGraph::Node& node : graph->nodes) { 299 for (const TaskGraph::Node& node : graph->nodes) {
292 if (dependents[node.task] != node.dependencies) 300 if (dependents[node.task] != node.dependencies)
293 return true; 301 return true;
294 } 302 }
295 303
296 return false; 304 return false;
297 } 305 }
298 306
299 } // namespace cc 307 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698