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> |
(...skipping 13 matching lines...) Expand all Loading... |
24 // be put into different categories, each of which is prioritized independently | 24 // be put into different categories, each of which is prioritized independently |
25 // from the others. It is up to the implementation of TaskGraphRunner to | 25 // from the others. It is up to the implementation of TaskGraphRunner to |
26 // define the meaning of the categories and handle them appropriately. | 26 // define the meaning of the categories and handle them appropriately. |
27 class CC_EXPORT TaskGraphWorkQueue { | 27 class CC_EXPORT TaskGraphWorkQueue { |
28 public: | 28 public: |
29 struct TaskNamespace; | 29 struct TaskNamespace; |
30 | 30 |
31 struct PrioritizedTask { | 31 struct PrioritizedTask { |
32 typedef std::vector<PrioritizedTask> Vector; | 32 typedef std::vector<PrioritizedTask> Vector; |
33 | 33 |
34 PrioritizedTask(Task* task, | 34 PrioritizedTask(DependencyTask* task, |
35 TaskNamespace* task_namespace, | 35 TaskNamespace* task_namespace, |
36 uint16_t category, | 36 uint16_t category, |
37 uint16_t priority) | 37 uint16_t priority) |
38 : task(task), | 38 : task(task), |
39 task_namespace(task_namespace), | 39 task_namespace(task_namespace), |
40 category(category), | 40 category(category), |
41 priority(priority) {} | 41 priority(priority) {} |
42 | 42 |
43 Task* task; | 43 DependencyTask* task; |
44 TaskNamespace* task_namespace; | 44 TaskNamespace* task_namespace; |
45 uint16_t category; | 45 uint16_t category; |
46 uint16_t priority; | 46 uint16_t priority; |
47 }; | 47 }; |
48 | 48 |
49 using CategorizedTask = std::pair<uint16_t, scoped_refptr<Task>>; | 49 using CategorizedTask = std::pair<uint16_t, scoped_refptr<DependencyTask>>; |
50 | 50 |
51 // Helper classes and static methods used by dependent classes. | 51 // Helper classes and static methods used by dependent classes. |
52 struct TaskNamespace { | 52 struct TaskNamespace { |
53 typedef std::vector<TaskNamespace*> Vector; | 53 typedef std::vector<TaskNamespace*> Vector; |
54 | 54 |
55 TaskNamespace(); | 55 TaskNamespace(); |
56 TaskNamespace(const TaskNamespace& other); | 56 TaskNamespace(const TaskNamespace& other); |
57 ~TaskNamespace(); | 57 ~TaskNamespace(); |
58 | 58 |
59 // Current task graph. | 59 // Current task graph. |
60 TaskGraph graph; | 60 TaskGraph graph; |
61 | 61 |
62 // Map from category to a vector of tasks that are ready to run for that | 62 // Map from category to a vector of tasks that are ready to run for that |
63 // category. | 63 // category. |
64 std::map<uint16_t, PrioritizedTask::Vector> ready_to_run_tasks; | 64 std::map<uint16_t, PrioritizedTask::Vector> ready_to_run_tasks; |
65 | 65 |
66 // Completed tasks not yet collected by origin thread. | 66 // Completed tasks not yet collected by origin thread. |
67 Task::Vector completed_tasks; | 67 DependencyTask::Vector completed_tasks; |
68 | 68 |
69 // This set contains all currently running tasks. | 69 // This set contains all currently running tasks. |
70 std::vector<CategorizedTask> running_tasks; | 70 std::vector<CategorizedTask> running_tasks; |
71 }; | 71 }; |
72 | 72 |
73 TaskGraphWorkQueue(); | 73 TaskGraphWorkQueue(); |
74 virtual ~TaskGraphWorkQueue(); | 74 virtual ~TaskGraphWorkQueue(); |
75 | 75 |
76 // Gets a NamespaceToken which is guaranteed to be unique within this | 76 // Gets a NamespaceToken which is guaranteed to be unique within this |
77 // TaskGraphWorkQueue. | 77 // TaskGraphWorkQueue. |
78 NamespaceToken GetNamespaceToken(); | 78 NamespaceToken GetNamespaceToken(); |
79 | 79 |
80 // Updates a TaskNamespace with a new TaskGraph to run. This cancels any | 80 // Updates a TaskNamespace with a new TaskGraph to run. This cancels any |
81 // previous tasks in the graph being replaced. | 81 // previous tasks in the graph being replaced. |
82 void ScheduleTasks(NamespaceToken token, TaskGraph* graph); | 82 void ScheduleTasks(NamespaceToken token, TaskGraph* graph); |
83 | 83 |
84 // Returns the next task to run for the given category. | 84 // Returns the next task to run for the given category. |
85 PrioritizedTask GetNextTaskToRun(uint16_t category); | 85 PrioritizedTask GetNextTaskToRun(uint16_t category); |
86 | 86 |
87 // Marks a task as completed, adding it to its namespace's list of completed | 87 // Marks a task as completed, adding it to its namespace's list of completed |
88 // tasks and updating the list of |ready_to_run_namespaces|. | 88 // tasks and updating the list of |ready_to_run_namespaces|. |
89 void CompleteTask(const PrioritizedTask& completed_task); | 89 void CompleteTask(const PrioritizedTask& completed_task); |
90 | 90 |
91 // Helper which populates a vector of completed tasks from the provided | 91 // Helper which populates a vector of completed tasks from the provided |
92 // namespace. | 92 // namespace. |
93 void CollectCompletedTasks(NamespaceToken token, | 93 void CollectCompletedTasks(NamespaceToken token, |
94 Task::Vector* completed_tasks); | 94 DependencyTask::Vector* completed_tasks); |
95 | 95 |
96 // Helper which returns the raw TaskNamespace* for the given token. Used to | 96 // Helper which returns the raw TaskNamespace* for the given token. Used to |
97 // allow callers to re-use a TaskNamespace*, reducing the number of lookups | 97 // allow callers to re-use a TaskNamespace*, reducing the number of lookups |
98 // needed. | 98 // needed. |
99 TaskNamespace* GetNamespaceForToken(NamespaceToken token) { | 99 TaskNamespace* GetNamespaceForToken(NamespaceToken token) { |
100 auto it = namespaces_.find(token); | 100 auto it = namespaces_.find(token); |
101 if (it == namespaces_.end()) | 101 if (it == namespaces_.end()) |
102 return nullptr; | 102 return nullptr; |
103 return &it->second; | 103 return &it->second; |
104 } | 104 } |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 // Map from category to a vector of ready to run namespaces for that category. | 183 // 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_; | 184 std::map<uint16_t, TaskNamespace::Vector> ready_to_run_namespaces_; |
185 | 185 |
186 // Provides a unique id to each NamespaceToken. | 186 // Provides a unique id to each NamespaceToken. |
187 int next_namespace_id_; | 187 int next_namespace_id_; |
188 }; | 188 }; |
189 | 189 |
190 } // namespace cc | 190 } // namespace cc |
191 | 191 |
192 #endif // CC_RASTER_TASK_GRAPH_WORK_QUEUE_H_ | 192 #endif // CC_RASTER_TASK_GRAPH_WORK_QUEUE_H_ |
OLD | NEW |