OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CC_RASTER_TASK_H_ |
| 6 #define CC_RASTER_TASK_H_ |
| 7 |
| 8 #include <stdint.h> |
| 9 |
| 10 #include <vector> |
| 11 |
| 12 #include "base/memory/ref_counted.h" |
| 13 #include "cc/base/cc_export.h" |
| 14 |
| 15 namespace cc { |
| 16 |
| 17 // 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 |
| 19 // TaskGraphRunner. |
| 20 class CC_EXPORT Task : public base::RefCountedThreadSafe<Task> { |
| 21 public: |
| 22 typedef std::vector<scoped_refptr<Task>> Vector; |
| 23 |
| 24 // Subclasses should implement this method. RunOnWorkerThread may be called |
| 25 // on any thread, and subclasses are responsible for locking and thread |
| 26 // safety. |
| 27 virtual void RunOnWorkerThread() = 0; |
| 28 |
| 29 void WillRun(); |
| 30 void DidRun(); |
| 31 bool HasFinishedRunning() const; |
| 32 |
| 33 protected: |
| 34 friend class base::RefCountedThreadSafe<Task>; |
| 35 |
| 36 Task(); |
| 37 virtual ~Task(); |
| 38 |
| 39 bool will_run_; |
| 40 bool did_run_; |
| 41 }; |
| 42 |
| 43 // 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 |
| 45 // 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 |
| 47 // (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 |
| 49 // category. A TaskGraphRunner implementation may chose to prioritize certain |
| 50 // categories over others, regardless of the individual priorities of tasks. |
| 51 struct CC_EXPORT TaskGraph { |
| 52 struct Node { |
| 53 typedef std::vector<Node> Vector; |
| 54 |
| 55 Node(Task* task, |
| 56 uint16_t category, |
| 57 uint16_t priority, |
| 58 uint32_t dependencies) |
| 59 : task(task), |
| 60 category(category), |
| 61 priority(priority), |
| 62 dependencies(dependencies) {} |
| 63 |
| 64 Task* task; |
| 65 uint16_t category; |
| 66 uint16_t priority; |
| 67 uint32_t dependencies; |
| 68 }; |
| 69 |
| 70 struct Edge { |
| 71 typedef std::vector<Edge> Vector; |
| 72 |
| 73 Edge(const Task* task, Task* dependent) |
| 74 : task(task), dependent(dependent) {} |
| 75 |
| 76 const Task* task; |
| 77 Task* dependent; |
| 78 }; |
| 79 |
| 80 TaskGraph(); |
| 81 TaskGraph(const TaskGraph& other); |
| 82 ~TaskGraph(); |
| 83 |
| 84 void Swap(TaskGraph* other); |
| 85 void Reset(); |
| 86 |
| 87 Node::Vector nodes; |
| 88 Edge::Vector edges; |
| 89 }; |
| 90 |
| 91 } // namespace cc |
| 92 |
| 93 #endif // CC_RASTER_TASK_H_ |
OLD | NEW |