OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_H_ | 5 #ifndef CC_RASTER_TASK_H_ |
6 #define CC_RASTER_TASK_H_ | 6 #define CC_RASTER_TASK_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "cc/base/cc_export.h" | 13 #include "cc/base/cc_export.h" |
14 | 14 |
15 namespace cc { | 15 namespace cc { |
| 16 class Task; |
| 17 |
| 18 // States to manage life cycle of a task. Task gets created with NEW state and |
| 19 // concludes either in FINISHED or CANCELLED state. So possible life cycle |
| 20 // paths for task are - |
| 21 // NEW -> SCHEDULED -> RUNNING -> FINISHED |
| 22 // NEW -> SCHEDULED -> CANCELED |
| 23 class CC_EXPORT TaskState { |
| 24 public: |
| 25 bool IsScheduled() const; |
| 26 bool IsRunning() const; |
| 27 bool IsFinished() const; |
| 28 bool IsCanceled() const; |
| 29 |
| 30 // Functions to change the state of task. These functions should be called |
| 31 // only from TaskGraphWorkQueue where the life cycle of a task is decided or |
| 32 // from tests. These functions are not thread-safe. Caller is responsible for |
| 33 // thread safety. |
| 34 void Reset(); // Sets state to NEW. |
| 35 void DidSchedule(); |
| 36 void DidStart(); |
| 37 void DidFinish(); |
| 38 void DidCancel(); |
| 39 |
| 40 private: |
| 41 friend class Task; |
| 42 |
| 43 // Let only Task class create the TaskState. |
| 44 TaskState(); |
| 45 ~TaskState(); |
| 46 |
| 47 enum class Value : uint16_t { NEW, SCHEDULED, RUNNING, FINISHED, CANCELED }; |
| 48 |
| 49 Value value_; |
| 50 }; |
16 | 51 |
17 // A task which can be run by a TaskGraphRunner. To run a Task, it should be | 52 // A task which can be run by a TaskGraphRunner. To run a Task, it should be |
18 // inserted into a TaskGraph, which can then be scheduled on the | 53 // inserted into a TaskGraph, which can then be scheduled on the |
19 // TaskGraphRunner. | 54 // TaskGraphRunner. |
20 class CC_EXPORT Task : public base::RefCountedThreadSafe<Task> { | 55 class CC_EXPORT Task : public base::RefCountedThreadSafe<Task> { |
21 public: | 56 public: |
22 typedef std::vector<scoped_refptr<Task>> Vector; | 57 typedef std::vector<scoped_refptr<Task>> Vector; |
23 | 58 |
| 59 TaskState& state() { return state_; } |
| 60 |
24 // Subclasses should implement this method. RunOnWorkerThread may be called | 61 // Subclasses should implement this method. RunOnWorkerThread may be called |
25 // on any thread, and subclasses are responsible for locking and thread | 62 // on any thread, and subclasses are responsible for locking and thread |
26 // safety. | 63 // safety. |
27 virtual void RunOnWorkerThread() = 0; | 64 virtual void RunOnWorkerThread() = 0; |
28 | 65 |
29 void WillRun(); | |
30 void DidRun(); | |
31 bool HasFinishedRunning() const; | |
32 | |
33 protected: | 66 protected: |
34 friend class base::RefCountedThreadSafe<Task>; | 67 friend class base::RefCountedThreadSafe<Task>; |
35 | 68 |
36 Task(); | 69 Task(); |
37 virtual ~Task(); | 70 virtual ~Task(); |
38 | 71 |
39 bool will_run_; | 72 private: |
40 bool did_run_; | 73 TaskState state_; |
41 }; | 74 }; |
42 | 75 |
43 // A task dependency graph describes the order in which to execute a set | 76 // A task dependency graph describes the order in which to execute a set |
44 // of tasks. Dependencies are represented as edges. Each node is assigned | 77 // of tasks. Dependencies are represented as edges. Each node is assigned |
45 // a category, a priority and a run count that matches the number of | 78 // a category, a priority and a run count that matches the number of |
46 // dependencies. Priority range from 0 (most favorable scheduling) to UINT16_MAX | 79 // dependencies. Priority range from 0 (most favorable scheduling) to UINT16_MAX |
47 // (least favorable). Categories range from 0 to UINT16_MAX. It is up to the | 80 // (least favorable). Categories range from 0 to UINT16_MAX. It is up to the |
48 // implementation and its consumer to determine the meaning (if any) of a | 81 // implementation and its consumer to determine the meaning (if any) of a |
49 // category. A TaskGraphRunner implementation may chose to prioritize certain | 82 // category. A TaskGraphRunner implementation may chose to prioritize certain |
50 // categories over others, regardless of the individual priorities of tasks. | 83 // categories over others, regardless of the individual priorities of tasks. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 void Swap(TaskGraph* other); | 117 void Swap(TaskGraph* other); |
85 void Reset(); | 118 void Reset(); |
86 | 119 |
87 Node::Vector nodes; | 120 Node::Vector nodes; |
88 Edge::Vector edges; | 121 Edge::Vector edges; |
89 }; | 122 }; |
90 | 123 |
91 } // namespace cc | 124 } // namespace cc |
92 | 125 |
93 #endif // CC_RASTER_TASK_H_ | 126 #endif // CC_RASTER_TASK_H_ |
OLD | NEW |