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_RUNNER_H_ | 5 #ifndef CC_RASTER_TASK_GRAPH_RUNNER_H_ |
6 #define CC_RASTER_TASK_GRAPH_RUNNER_H_ | 6 #define CC_RASTER_TASK_GRAPH_RUNNER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <algorithm> | 11 #include <algorithm> |
12 #include <map> | 12 #include <map> |
13 #include <memory> | 13 #include <memory> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "base/logging.h" | 16 #include "base/logging.h" |
17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
18 #include "cc/base/cc_export.h" | 18 #include "cc/base/cc_export.h" |
| 19 #include "cc/raster/task.h" |
19 | 20 |
20 namespace cc { | 21 namespace cc { |
21 | 22 |
22 class TaskGraphRunner; | 23 class TaskGraphRunner; |
23 | 24 |
24 typedef uint32_t TaskTypeId; | |
25 const TaskTypeId kDefaultTaskTypeId = 0; | |
26 | |
27 // A task which can be run by a TaskGraphRunner. To run a Task, it should be | |
28 // inserted into a TaskGraph, which can then be scheduled on the | |
29 // TaskGraphRunner. | |
30 class CC_EXPORT Task : public base::RefCountedThreadSafe<Task> { | |
31 public: | |
32 typedef std::vector<scoped_refptr<Task>> Vector; | |
33 | |
34 TaskTypeId GetTaskTypeId(); | |
35 | |
36 // Subclasses should implement this method. RunOnWorkerThread may be called | |
37 // on any thread, and subclasses are responsible for locking and thread | |
38 // safety. | |
39 virtual void RunOnWorkerThread() = 0; | |
40 | |
41 void WillRun(); | |
42 void DidRun(); | |
43 bool HasFinishedRunning() const; | |
44 | |
45 protected: | |
46 friend class base::RefCountedThreadSafe<Task>; | |
47 | |
48 void SetTaskTypeId(TaskTypeId type_id); | |
49 | |
50 Task(); | |
51 virtual ~Task(); | |
52 | |
53 TaskTypeId type_id_; | |
54 bool will_run_; | |
55 bool did_run_; | |
56 }; | |
57 | |
58 // A task dependency graph describes the order in which to execute a set | 25 // A task dependency graph describes the order in which to execute a set |
59 // of tasks. Dependencies are represented as edges. Each node is assigned | 26 // of tasks. Dependencies are represented as edges. Each node is assigned |
60 // a category, a priority and a run count that matches the number of | 27 // a category, a priority and a run count that matches the number of |
61 // dependencies. Priority range from 0 (most favorable scheduling) to UINT16_MAX | 28 // dependencies. Priority range from 0 (most favorable scheduling) to UINT16_MAX |
62 // (least favorable). Categories range from 0 to UINT16_MAX. It is up to the | 29 // (least favorable). Categories range from 0 to UINT16_MAX. It is up to the |
63 // implementation and its consumer to determine the meaning (if any) of a | 30 // implementation and its consumer to determine the meaning (if any) of a |
64 // category. A TaskGraphRunner implementation may chose to prioritize certain | 31 // category. A TaskGraphRunner implementation may chose to prioritize certain |
65 // categories over others, regardless of the individual priorities of tasks. | 32 // categories over others, regardless of the individual priorities of tasks. |
66 struct CC_EXPORT TaskGraph { | 33 struct CC_EXPORT TaskGraph { |
67 struct Node { | 34 struct Node { |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 private: | 192 private: |
226 TaskGraph* graph_; | 193 TaskGraph* graph_; |
227 const Task* task_; | 194 const Task* task_; |
228 size_t current_index_; | 195 size_t current_index_; |
229 TaskGraph::Node* current_node_; | 196 TaskGraph::Node* current_node_; |
230 }; | 197 }; |
231 | 198 |
232 } // namespace cc | 199 } // namespace cc |
233 | 200 |
234 #endif // CC_RASTER_TASK_GRAPH_RUNNER_H_ | 201 #endif // CC_RASTER_TASK_GRAPH_RUNNER_H_ |
OLD | NEW |