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 #ifndef CC_RASTER_TASK_GRAPH_WORK_QUEUE_H_ | 5 #ifndef CC_RASTER_TASK_GRAPH_WORK_QUEUE_H_ |
6 #define CC_RASTER_TASK_GRAPH_WORK_QUEUE_H_ | 6 #define CC_RASTER_TASK_GRAPH_WORK_QUEUE_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
11 #include <map> | 11 #include <map> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "cc/base/cc_export.h" | 14 #include "cc/base/cc_export.h" |
15 #include "cc/raster/task_graph_runner.h" | 15 #include "cc/raster/task_graph_runner.h" |
16 | 16 |
17 namespace cc { | 17 namespace cc { |
18 | 18 |
| 19 class CC_EXPORT TaskGraphWorkQueueClient { |
| 20 virtual void AdjustWorkerPriorityForTask(Task* task, |
| 21 uint16_t old_category, |
| 22 uint16_t new_category) = 0; |
| 23 }; |
| 24 |
19 // Implements a queue of incoming TaskGraph work. Designed for use by | 25 // Implements a queue of incoming TaskGraph work. Designed for use by |
20 // implementations of TaskGraphRunner. Not thread safe, so the caller is | 26 // implementations of TaskGraphRunner. Not thread safe, so the caller is |
21 // responsible for all necessary locking. | 27 // responsible for all necessary locking. |
22 // | 28 // |
23 // Tasks in the queue are divided into categories. Tasks from a single graph may | 29 // Tasks in the queue are divided into categories. Tasks from a single graph may |
24 // be put into different categories, each of which is prioritized independently | 30 // be put into different categories, each of which is prioritized independently |
25 // from the others. It is up to the implementation of TaskGraphRunner to | 31 // from the others. It is up to the implementation of TaskGraphRunner to |
26 // define the meaning of the categories and handle them appropriately. | 32 // define the meaning of the categories and handle them appropriately. |
27 class CC_EXPORT TaskGraphWorkQueue { | 33 class CC_EXPORT TaskGraphWorkQueue { |
28 public: | 34 public: |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 // category. | 69 // category. |
64 std::map<uint16_t, PrioritizedTask::Vector> ready_to_run_tasks; | 70 std::map<uint16_t, PrioritizedTask::Vector> ready_to_run_tasks; |
65 | 71 |
66 // Completed tasks not yet collected by origin thread. | 72 // Completed tasks not yet collected by origin thread. |
67 Task::Vector completed_tasks; | 73 Task::Vector completed_tasks; |
68 | 74 |
69 // This set contains all currently running tasks. | 75 // This set contains all currently running tasks. |
70 std::vector<CategorizedTask> running_tasks; | 76 std::vector<CategorizedTask> running_tasks; |
71 }; | 77 }; |
72 | 78 |
73 TaskGraphWorkQueue(); | 79 explicit TaskGraphWorkQueue(TaskGraphWorkQueueClient* client); |
74 virtual ~TaskGraphWorkQueue(); | 80 virtual ~TaskGraphWorkQueue(); |
75 | 81 |
76 // Gets a NamespaceToken which is guaranteed to be unique within this | 82 // Gets a NamespaceToken which is guaranteed to be unique within this |
77 // TaskGraphWorkQueue. | 83 // TaskGraphWorkQueue. |
78 NamespaceToken GetNamespaceToken(); | 84 NamespaceToken GetNamespaceToken(); |
79 | 85 |
80 // Updates a TaskNamespace with a new TaskGraph to run. This cancels any | 86 // Updates a TaskNamespace with a new TaskGraph to run. This cancels any |
81 // previous tasks in the graph being replaced. | 87 // previous tasks in the graph being replaced. |
82 void ScheduleTasks(NamespaceToken token, TaskGraph* graph); | 88 void ScheduleTasks(NamespaceToken token, TaskGraph* graph); |
83 | 89 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 private: | 174 private: |
169 // Helper class used to provide NamespaceToken comparison to TaskNamespaceMap. | 175 // Helper class used to provide NamespaceToken comparison to TaskNamespaceMap. |
170 class CompareToken { | 176 class CompareToken { |
171 public: | 177 public: |
172 bool operator()(const NamespaceToken& lhs, | 178 bool operator()(const NamespaceToken& lhs, |
173 const NamespaceToken& rhs) const { | 179 const NamespaceToken& rhs) const { |
174 return lhs.id_ < rhs.id_; | 180 return lhs.id_ < rhs.id_; |
175 } | 181 } |
176 }; | 182 }; |
177 | 183 |
| 184 TaskGraphWorkQueueClient* client_; |
| 185 |
178 using TaskNamespaceMap = | 186 using TaskNamespaceMap = |
179 std::map<NamespaceToken, TaskNamespace, CompareToken>; | 187 std::map<NamespaceToken, TaskNamespace, CompareToken>; |
180 | 188 |
181 TaskNamespaceMap namespaces_; | 189 TaskNamespaceMap namespaces_; |
182 | 190 |
183 // Map from category to a vector of ready to run namespaces for that category. | 191 // Map from category to a vector of ready to run namespaces for that category. |
184 std::map<uint16_t, TaskNamespace::Vector> ready_to_run_namespaces_; | 192 std::map<uint16_t, TaskNamespace::Vector> ready_to_run_namespaces_; |
185 | 193 |
186 // Provides a unique id to each NamespaceToken. | 194 // Provides a unique id to each NamespaceToken. |
187 int next_namespace_id_; | 195 int next_namespace_id_; |
188 }; | 196 }; |
189 | 197 |
190 } // namespace cc | 198 } // namespace cc |
191 | 199 |
192 #endif // CC_RASTER_TASK_GRAPH_WORK_QUEUE_H_ | 200 #endif // CC_RASTER_TASK_GRAPH_WORK_QUEUE_H_ |
OLD | NEW |