| 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_TILE_TASK_RUNNER_H_ | 5 #ifndef CC_RASTER_TILE_TASK_RUNNER_H_ |
| 6 #define CC_RASTER_TILE_TASK_RUNNER_H_ | 6 #define CC_RASTER_TILE_TASK_RUNNER_H_ |
| 7 | 7 |
| 8 #include <bitset> | |
| 9 #include <vector> | 8 #include <vector> |
| 10 | 9 |
| 11 #include "base/callback.h" | 10 #include "base/callback.h" |
| 12 #include "cc/raster/task_graph_runner.h" | 11 #include "cc/raster/task_graph_runner.h" |
| 13 #include "cc/resources/resource_format.h" | 12 #include "cc/resources/resource_format.h" |
| 14 | 13 |
| 15 namespace cc { | 14 namespace cc { |
| 16 class ImageDecodeTask; | 15 class ImageDecodeTask; |
| 17 class RasterTask; | 16 class RasterTask; |
| 18 class Resource; | 17 class Resource; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 const ImageDecodeTask::Vector& dependencies() const { return dependencies_; } | 68 const ImageDecodeTask::Vector& dependencies() const { return dependencies_; } |
| 70 | 69 |
| 71 protected: | 70 protected: |
| 72 explicit RasterTask(ImageDecodeTask::Vector* dependencies); | 71 explicit RasterTask(ImageDecodeTask::Vector* dependencies); |
| 73 ~RasterTask() override; | 72 ~RasterTask() override; |
| 74 | 73 |
| 75 private: | 74 private: |
| 76 ImageDecodeTask::Vector dependencies_; | 75 ImageDecodeTask::Vector dependencies_; |
| 77 }; | 76 }; |
| 78 | 77 |
| 79 // kNumberOfTaskSets must be greater or equal to the number of values in | 78 // This interface can be used to schedule and run tile tasks. |
| 80 // TileManager::NamedTaskSet. | |
| 81 // TODO(reveman): Use template specialization to make it easy for client code to | |
| 82 // check at compile time that the number of supported task sets is correct. | |
| 83 static const size_t kNumberOfTaskSets = 3; | |
| 84 typedef size_t TaskSet; | |
| 85 typedef std::bitset<kNumberOfTaskSets> TaskSetCollection; | |
| 86 | |
| 87 class CC_EXPORT TileTaskRunnerClient { | |
| 88 public: | |
| 89 virtual void DidFinishRunningTileTasks(TaskSet task_set) = 0; | |
| 90 | |
| 91 protected: | |
| 92 virtual ~TileTaskRunnerClient() {} | |
| 93 }; | |
| 94 | |
| 95 struct CC_EXPORT TileTaskQueue { | |
| 96 struct CC_EXPORT Item { | |
| 97 class TaskComparator { | |
| 98 public: | |
| 99 explicit TaskComparator(const RasterTask* task) : task_(task) {} | |
| 100 | |
| 101 bool operator()(const Item& item) const { return item.task == task_; } | |
| 102 | |
| 103 private: | |
| 104 const RasterTask* task_; | |
| 105 }; | |
| 106 | |
| 107 typedef std::vector<Item> Vector; | |
| 108 | |
| 109 Item(RasterTask* task, const TaskSetCollection& task_sets); | |
| 110 ~Item(); | |
| 111 | |
| 112 RasterTask* task; | |
| 113 TaskSetCollection task_sets; | |
| 114 }; | |
| 115 | |
| 116 TileTaskQueue(); | |
| 117 ~TileTaskQueue(); | |
| 118 | |
| 119 void Swap(TileTaskQueue* other); | |
| 120 void Reset(); | |
| 121 | |
| 122 Item::Vector items; | |
| 123 }; | |
| 124 | |
| 125 // This interface can be used to schedule and run tile tasks. The client will | |
| 126 // be notified asynchronously when the set of tasks marked as "required for | |
| 127 // activation" have finished running, when tasks marked "required for draw" | |
| 128 // have finished running, and when all scheduled tasks have finished running. | |
| 129 // The client can call CheckForCompletedTasks() at any time to dispatch | 79 // The client can call CheckForCompletedTasks() at any time to dispatch |
| 130 // pending completion callbacks for all tasks that have finished running. | 80 // pending completion callbacks for all tasks that have finished running. |
| 131 class CC_EXPORT TileTaskRunner { | 81 class CC_EXPORT TileTaskRunner { |
| 132 public: | 82 public: |
| 133 // Set the client instance to be notified when finished running tasks. | |
| 134 virtual void SetClient(TileTaskRunnerClient* client) = 0; | |
| 135 | |
| 136 // Tells the worker pool to shutdown after canceling all previously scheduled | 83 // Tells the worker pool to shutdown after canceling all previously scheduled |
| 137 // tasks. Reply callbacks are still guaranteed to run when | 84 // tasks. Reply callbacks are still guaranteed to run when |
| 138 // CheckForCompletedTasks() is called. | 85 // CheckForCompletedTasks() is called. |
| 139 virtual void Shutdown() = 0; | 86 virtual void Shutdown() = 0; |
| 140 | 87 |
| 141 // Schedule running of tile tasks in |queue| and all dependencies. | 88 // Schedule running of tile tasks in |graph| and all dependencies. |
| 142 // Previously scheduled tasks that are not in |queue| will be canceled unless | 89 // Previously scheduled tasks that are not in |graph| will be canceled unless |
| 143 // already running. Once scheduled, reply callbacks are guaranteed to run for | 90 // already running. Once scheduled, reply callbacks are guaranteed to run for |
| 144 // all tasks even if they later get canceled by another call to | 91 // all tasks even if they later get canceled by another call to |
| 145 // ScheduleTasks(). | 92 // ScheduleTasks(). |
| 146 virtual void ScheduleTasks(TileTaskQueue* queue) = 0; | 93 virtual void ScheduleTasks(scoped_ptr<TaskGraph> graph) = 0; |
| 147 | 94 |
| 148 // Check for completed tasks and dispatch reply callbacks. | 95 // Check for completed tasks and dispatch reply callbacks. |
| 149 virtual void CheckForCompletedTasks() = 0; | 96 virtual void CheckForCompletedTasks() = 0; |
| 150 | 97 |
| 151 // Returns the format to use for the tiles. | 98 // Returns the format to use for the tiles. |
| 152 virtual ResourceFormat GetResourceFormat(bool must_support_alpha) const = 0; | 99 virtual ResourceFormat GetResourceFormat(bool must_support_alpha) const = 0; |
| 153 | 100 |
| 154 // Determine if the resource requires swizzling. | 101 // Determine if the resource requires swizzling. |
| 155 virtual bool GetResourceRequiresSwizzle(bool must_support_alpha) const = 0; | 102 virtual bool GetResourceRequiresSwizzle(bool must_support_alpha) const = 0; |
| 156 | 103 |
| 157 protected: | 104 protected: |
| 158 virtual ~TileTaskRunner() {} | 105 virtual ~TileTaskRunner() {} |
| 159 }; | 106 }; |
| 160 | 107 |
| 161 } // namespace cc | 108 } // namespace cc |
| 162 | 109 |
| 163 #endif // CC_RASTER_TILE_TASK_RUNNER_H_ | 110 #endif // CC_RASTER_TILE_TASK_RUNNER_H_ |
| OLD | NEW |