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 <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/threading/simple_thread.h" |
| 19 #include "base/time/time.h" |
18 #include "cc/base/cc_export.h" | 20 #include "cc/base/cc_export.h" |
| 21 #include "cc/raster/task_category.h" |
19 | 22 |
20 namespace cc { | 23 namespace cc { |
21 | 24 |
22 class TaskGraphRunner; | 25 class TaskGraphRunner; |
23 | 26 |
| 27 class CC_EXPORT TaskWorker { |
| 28 public: |
| 29 // TODO(prashant.n): Find better names. |
| 30 virtual bool TaskSpeedup() = 0; |
| 31 virtual bool TaskSlowdown() = 0; |
| 32 virtual bool TaskDone() = 0; |
| 33 }; |
| 34 |
24 // A task which can be run by a TaskGraphRunner. To run a Task, it should be | 35 // A task which can be run by a TaskGraphRunner. To run a Task, it should be |
25 // inserted into a TaskGraph, which can then be scheduled on the | 36 // inserted into a TaskGraph, which can then be scheduled on the |
26 // TaskGraphRunner. | 37 // TaskGraphRunner. |
27 class CC_EXPORT Task : public base::RefCountedThreadSafe<Task> { | 38 class CC_EXPORT Task : public base::RefCountedThreadSafe<Task> { |
28 public: | 39 public: |
29 typedef std::vector<scoped_refptr<Task>> Vector; | 40 typedef std::vector<scoped_refptr<Task>> Vector; |
30 | 41 |
31 // Subclasses should implement this method. RunOnWorkerThread may be called | 42 // Subclasses should implement this method. RunOnWorkerThread may be called |
32 // on any thread, and subclasses are responsible for locking and thread | 43 // on any thread, and subclasses are responsible for locking and thread |
33 // safety. | 44 // safety. |
34 virtual void RunOnWorkerThread() = 0; | 45 virtual void RunOnWorkerThread() = 0; |
35 | 46 |
| 47 TaskWorker* GetTaskWorker() { return worker_; } |
| 48 void AttachTaskWorker(TaskWorker* worker); |
| 49 void DetachTaskWorker(); |
| 50 |
36 void WillRun(); | 51 void WillRun(); |
37 void DidRun(); | 52 void DidRun(); |
38 bool HasFinishedRunning() const; | 53 bool HasFinishedRunning() const; |
39 | 54 |
40 protected: | 55 protected: |
41 friend class base::RefCountedThreadSafe<Task>; | 56 friend class base::RefCountedThreadSafe<Task>; |
42 | 57 |
43 Task(); | 58 Task(); |
44 virtual ~Task(); | 59 virtual ~Task(); |
45 | 60 |
| 61 TaskWorker* worker_; |
46 bool will_run_; | 62 bool will_run_; |
47 bool did_run_; | 63 bool did_run_; |
48 }; | 64 }; |
49 | 65 |
| 66 class CC_EXPORT AutoDetachTaskWorker { |
| 67 public: |
| 68 explicit AutoDetachTaskWorker(Task& task, TaskWorker* worker) : task_(task) { |
| 69 DCHECK(worker); |
| 70 task_.AttachTaskWorker(worker); |
| 71 } |
| 72 |
| 73 ~AutoDetachTaskWorker() { task_.DetachTaskWorker(); } |
| 74 |
| 75 private: |
| 76 Task& task_; |
| 77 DISALLOW_COPY_AND_ASSIGN(AutoDetachTaskWorker); |
| 78 }; |
| 79 |
50 // A task dependency graph describes the order in which to execute a set | 80 // A task dependency graph describes the order in which to execute a set |
51 // of tasks. Dependencies are represented as edges. Each node is assigned | 81 // of tasks. Dependencies are represented as edges. Each node is assigned |
52 // a category, a priority and a run count that matches the number of | 82 // a category, a priority and a run count that matches the number of |
53 // dependencies. Priority range from 0 (most favorable scheduling) to UINT16_MAX | 83 // dependencies. Priority range from 0 (most favorable scheduling) to UINT16_MAX |
54 // (least favorable). Categories range from 0 to UINT16_MAX. It is up to the | 84 // (least favorable). Categories range from 0 to UINT16_MAX. It is up to the |
55 // implementation and its consumer to determine the meaning (if any) of a | 85 // implementation and its consumer to determine the meaning (if any) of a |
56 // category. A TaskGraphRunner implementation may chose to prioritize certain | 86 // category. A TaskGraphRunner implementation may chose to prioritize certain |
57 // categories over others, regardless of the individual priorities of tasks. | 87 // categories over others, regardless of the individual priorities of tasks. |
58 struct CC_EXPORT TaskGraph { | 88 struct CC_EXPORT TaskGraph { |
59 struct Node { | 89 struct Node { |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 private: | 247 private: |
218 TaskGraph* graph_; | 248 TaskGraph* graph_; |
219 const Task* task_; | 249 const Task* task_; |
220 size_t current_index_; | 250 size_t current_index_; |
221 TaskGraph::Node* current_node_; | 251 TaskGraph::Node* current_node_; |
222 }; | 252 }; |
223 | 253 |
224 } // namespace cc | 254 } // namespace cc |
225 | 255 |
226 #endif // CC_RASTER_TASK_GRAPH_RUNNER_H_ | 256 #endif // CC_RASTER_TASK_GRAPH_RUNNER_H_ |
OLD | NEW |