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_RESOURCES_RASTERIZER_H_ | 5 #ifndef CC_RESOURCES_TILE_TASK_RUNNER_H_ |
6 #define CC_RESOURCES_RASTERIZER_H_ | 6 #define CC_RESOURCES_TILE_TASK_RUNNER_H_ |
7 | 7 |
8 #include <bitset> | 8 #include <bitset> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "cc/resources/resource_format.h" | 12 #include "cc/resources/resource_format.h" |
13 #include "cc/resources/task_graph_runner.h" | 13 #include "cc/resources/task_graph_runner.h" |
14 | 14 |
15 namespace cc { | 15 namespace cc { |
16 class ImageDecodeTask; | 16 class ImageDecodeTask; |
17 class RasterTask; | 17 class RasterTask; |
18 class Resource; | 18 class Resource; |
19 class RasterBuffer; | 19 class RasterBuffer; |
20 | 20 |
21 class CC_EXPORT RasterizerTaskClient { | 21 class CC_EXPORT TileTaskClient { |
22 public: | 22 public: |
23 virtual scoped_ptr<RasterBuffer> AcquireBufferForRaster( | 23 virtual scoped_ptr<RasterBuffer> AcquireBufferForRaster( |
24 const Resource* resource) = 0; | 24 const Resource* resource) = 0; |
25 virtual void ReleaseBufferForRaster(scoped_ptr<RasterBuffer> buffer) = 0; | 25 virtual void ReleaseBufferForRaster(scoped_ptr<RasterBuffer> buffer) = 0; |
26 | 26 |
27 protected: | 27 protected: |
28 virtual ~RasterizerTaskClient() {} | 28 virtual ~TileTaskClient() {} |
29 }; | 29 }; |
30 | 30 |
31 class CC_EXPORT RasterizerTask : public Task { | 31 class CC_EXPORT TileTask : public Task { |
32 public: | 32 public: |
33 typedef std::vector<scoped_refptr<RasterizerTask>> Vector; | 33 typedef std::vector<scoped_refptr<TileTask>> Vector; |
34 | 34 |
35 virtual void ScheduleOnOriginThread(RasterizerTaskClient* client) = 0; | 35 virtual void ScheduleOnOriginThread(TileTaskClient* client) = 0; |
36 virtual void CompleteOnOriginThread(RasterizerTaskClient* client) = 0; | 36 virtual void CompleteOnOriginThread(TileTaskClient* client) = 0; |
37 virtual void RunReplyOnOriginThread() = 0; | 37 virtual void RunReplyOnOriginThread() = 0; |
38 | 38 |
39 // Type-checking downcast routines. | 39 // Type-checking downcast routines. |
40 virtual ImageDecodeTask* AsImageDecodeTask(); | 40 virtual ImageDecodeTask* AsImageDecodeTask(); |
41 virtual RasterTask* AsRasterTask(); | 41 virtual RasterTask* AsRasterTask(); |
42 | 42 |
43 void WillSchedule(); | 43 void WillSchedule(); |
44 void DidSchedule(); | 44 void DidSchedule(); |
45 bool HasBeenScheduled() const; | 45 bool HasBeenScheduled() const; |
46 | 46 |
47 void WillComplete(); | 47 void WillComplete(); |
48 void DidComplete(); | 48 void DidComplete(); |
49 bool HasCompleted() const; | 49 bool HasCompleted() const; |
50 | 50 |
51 protected: | 51 protected: |
52 RasterizerTask(); | 52 TileTask(); |
53 ~RasterizerTask() override; | 53 ~TileTask() override; |
54 | 54 |
55 bool did_schedule_; | 55 bool did_schedule_; |
56 bool did_complete_; | 56 bool did_complete_; |
57 }; | 57 }; |
58 | 58 |
59 class CC_EXPORT ImageDecodeTask : public RasterizerTask { | 59 class CC_EXPORT ImageDecodeTask : public TileTask { |
60 public: | 60 public: |
61 typedef std::vector<scoped_refptr<ImageDecodeTask>> Vector; | 61 typedef std::vector<scoped_refptr<ImageDecodeTask>> Vector; |
62 | 62 |
63 // Overridden from RasterizerTask: | 63 // Overridden from TileTask: |
64 ImageDecodeTask* AsImageDecodeTask() override; | 64 ImageDecodeTask* AsImageDecodeTask() override; |
65 | 65 |
66 protected: | 66 protected: |
67 ImageDecodeTask(); | 67 ImageDecodeTask(); |
68 ~ImageDecodeTask() override; | 68 ~ImageDecodeTask() override; |
69 }; | 69 }; |
70 | 70 |
71 class CC_EXPORT RasterTask : public RasterizerTask { | 71 class CC_EXPORT RasterTask : public TileTask { |
72 public: | 72 public: |
73 typedef std::vector<scoped_refptr<RasterTask>> Vector; | 73 typedef std::vector<scoped_refptr<RasterTask>> Vector; |
74 | 74 |
75 // Overridden from RasterizerTask: | 75 // Overridden from TileTask: |
76 RasterTask* AsRasterTask() override; | 76 RasterTask* AsRasterTask() override; |
77 | 77 |
78 const Resource* resource() const { return resource_; } | 78 const Resource* resource() const { return resource_; } |
79 const ImageDecodeTask::Vector& dependencies() const { return dependencies_; } | 79 const ImageDecodeTask::Vector& dependencies() const { return dependencies_; } |
80 | 80 |
81 protected: | 81 protected: |
82 RasterTask(const Resource* resource, ImageDecodeTask::Vector* dependencies); | 82 RasterTask(const Resource* resource, ImageDecodeTask::Vector* dependencies); |
83 ~RasterTask() override; | 83 ~RasterTask() override; |
84 | 84 |
85 private: | 85 private: |
86 const Resource* resource_; | 86 const Resource* resource_; |
87 ImageDecodeTask::Vector dependencies_; | 87 ImageDecodeTask::Vector dependencies_; |
88 }; | 88 }; |
89 | 89 |
90 // kNumberOfTaskSets must be greater or equal to the number of values in | 90 // kNumberOfTaskSets must be greater or equal to the number of values in |
91 // TileManager::NamedTaskSet. | 91 // TileManager::NamedTaskSet. |
92 // TODO(reveman): Use template specialization to make it easy for client code to | 92 // TODO(reveman): Use template specialization to make it easy for client code to |
93 // check at compile time that the number of supported task sets is correct. | 93 // check at compile time that the number of supported task sets is correct. |
94 static const size_t kNumberOfTaskSets = 3; | 94 static const size_t kNumberOfTaskSets = 3; |
95 typedef size_t TaskSet; | 95 typedef size_t TaskSet; |
96 typedef std::bitset<kNumberOfTaskSets> TaskSetCollection; | 96 typedef std::bitset<kNumberOfTaskSets> TaskSetCollection; |
97 | 97 |
98 class CC_EXPORT RasterizerClient { | 98 class CC_EXPORT TileTaskRunnerClient { |
99 public: | 99 public: |
100 virtual void DidFinishRunningTasks(TaskSet task_set) = 0; | 100 virtual void DidFinishRunningTileTasks(TaskSet task_set) = 0; |
101 virtual TaskSetCollection TasksThatShouldBeForcedToComplete() const = 0; | 101 virtual TaskSetCollection TasksThatShouldBeForcedToComplete() const = 0; |
102 | 102 |
103 protected: | 103 protected: |
104 virtual ~RasterizerClient() {} | 104 virtual ~TileTaskRunnerClient() {} |
105 }; | 105 }; |
106 | 106 |
107 struct CC_EXPORT RasterTaskQueue { | 107 struct CC_EXPORT TileTaskQueue { |
108 struct CC_EXPORT Item { | 108 struct CC_EXPORT Item { |
109 class TaskComparator { | 109 class TaskComparator { |
110 public: | 110 public: |
111 explicit TaskComparator(const RasterTask* task) : task_(task) {} | 111 explicit TaskComparator(const RasterTask* task) : task_(task) {} |
112 | 112 |
113 bool operator()(const Item& item) const { return item.task == task_; } | 113 bool operator()(const Item& item) const { return item.task == task_; } |
114 | 114 |
115 private: | 115 private: |
116 const RasterTask* task_; | 116 const RasterTask* task_; |
117 }; | 117 }; |
118 | 118 |
119 typedef std::vector<Item> Vector; | 119 typedef std::vector<Item> Vector; |
120 | 120 |
121 Item(RasterTask* task, const TaskSetCollection& task_sets); | 121 Item(RasterTask* task, const TaskSetCollection& task_sets); |
122 ~Item(); | 122 ~Item(); |
123 | 123 |
124 RasterTask* task; | 124 RasterTask* task; |
125 TaskSetCollection task_sets; | 125 TaskSetCollection task_sets; |
126 }; | 126 }; |
127 | 127 |
128 RasterTaskQueue(); | 128 TileTaskQueue(); |
129 ~RasterTaskQueue(); | 129 ~TileTaskQueue(); |
130 | 130 |
131 void Swap(RasterTaskQueue* other); | 131 void Swap(TileTaskQueue* other); |
132 void Reset(); | 132 void Reset(); |
133 | 133 |
134 Item::Vector items; | 134 Item::Vector items; |
135 }; | 135 }; |
136 | 136 |
137 // This interface can be used to schedule and run raster tasks. The client will | 137 // This interface can be used to schedule and run tile tasks. The client will |
138 // be notified asynchronously when the set of tasks marked as "required for | 138 // be notified asynchronously when the set of tasks marked as "required for |
139 // activation" have finished running and when all scheduled tasks have finished | 139 // activation" have finished running, when tasks marked "required for draw" |
140 // running. The client can call CheckForCompletedTasks() at any time to dispatch | 140 // have finished running, and when all scheduled tasks have finished running. |
| 141 // The client can call CheckForCompletedTasks() at any time to dispatch |
141 // pending completion callbacks for all tasks that have finished running. | 142 // pending completion callbacks for all tasks that have finished running. |
142 class CC_EXPORT Rasterizer { | 143 class CC_EXPORT TileTaskRunner { |
143 public: | 144 public: |
144 // Set the client instance to be notified when finished running tasks. | 145 // Set the client instance to be notified when finished running tasks. |
145 virtual void SetClient(RasterizerClient* client) = 0; | 146 virtual void SetClient(TileTaskRunnerClient* client) = 0; |
146 | 147 |
147 // Tells the worker pool to shutdown after canceling all previously scheduled | 148 // Tells the worker pool to shutdown after canceling all previously scheduled |
148 // tasks. Reply callbacks are still guaranteed to run when | 149 // tasks. Reply callbacks are still guaranteed to run when |
149 // CheckForCompletedTasks() is called. | 150 // CheckForCompletedTasks() is called. |
150 virtual void Shutdown() = 0; | 151 virtual void Shutdown() = 0; |
151 | 152 |
152 // Schedule running of raster tasks in |queue| and all dependencies. | 153 // Schedule running of tile tasks in |queue| and all dependencies. |
153 // Previously scheduled tasks that are not in |queue| will be canceled unless | 154 // Previously scheduled tasks that are not in |queue| will be canceled unless |
154 // already running. Once scheduled, reply callbacks are guaranteed to run for | 155 // already running. Once scheduled, reply callbacks are guaranteed to run for |
155 // all tasks even if they later get canceled by another call to | 156 // all tasks even if they later get canceled by another call to |
156 // ScheduleTasks(). | 157 // ScheduleTasks(). |
157 virtual void ScheduleTasks(RasterTaskQueue* queue) = 0; | 158 virtual void ScheduleTasks(TileTaskQueue* queue) = 0; |
158 | 159 |
159 // Check for completed tasks and dispatch reply callbacks. | 160 // Check for completed tasks and dispatch reply callbacks. |
160 virtual void CheckForCompletedTasks() = 0; | 161 virtual void CheckForCompletedTasks() = 0; |
161 | 162 |
162 protected: | 163 protected: |
163 virtual ~Rasterizer() {} | 164 virtual ~TileTaskRunner() {} |
164 }; | 165 }; |
165 | 166 |
166 } // namespace cc | 167 } // namespace cc |
167 | 168 |
168 #endif // CC_RESOURCES_RASTERIZER_H_ | 169 #endif // CC_RESOURCES_TILE_TASK_RUNNER_H_ |
OLD | NEW |