Update V8 to version 4.7.42.
[chromium-blink-merge.git] / cc / raster / tile_task_runner.h
blob64c72f0235ec638905dabb8a8236e383bf18b976
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
3 // found in the LICENSE file.
5 #ifndef CC_RASTER_TILE_TASK_RUNNER_H_
6 #define CC_RASTER_TILE_TASK_RUNNER_H_
8 #include <bitset>
9 #include <vector>
11 #include "base/callback.h"
12 #include "cc/raster/task_graph_runner.h"
13 #include "cc/resources/resource_format.h"
15 namespace cc {
16 class ImageDecodeTask;
17 class RasterTask;
18 class Resource;
19 class RasterBuffer;
21 class CC_EXPORT TileTaskClient {
22 public:
23 virtual scoped_ptr<RasterBuffer> AcquireBufferForRaster(
24 const Resource* resource,
25 uint64_t resource_content_id,
26 uint64_t previous_content_id) = 0;
27 virtual void ReleaseBufferForRaster(scoped_ptr<RasterBuffer> buffer) = 0;
29 protected:
30 virtual ~TileTaskClient() {}
33 class CC_EXPORT TileTask : public Task {
34 public:
35 typedef std::vector<scoped_refptr<TileTask>> Vector;
37 virtual void ScheduleOnOriginThread(TileTaskClient* client) = 0;
38 virtual void CompleteOnOriginThread(TileTaskClient* client) = 0;
40 void WillSchedule();
41 void DidSchedule();
42 bool HasBeenScheduled() const;
44 void WillComplete();
45 void DidComplete();
46 bool HasCompleted() const;
48 protected:
49 TileTask();
50 ~TileTask() override;
52 bool did_schedule_;
53 bool did_complete_;
56 class CC_EXPORT ImageDecodeTask : public TileTask {
57 public:
58 typedef std::vector<scoped_refptr<ImageDecodeTask>> Vector;
60 protected:
61 ImageDecodeTask();
62 ~ImageDecodeTask() override;
65 class CC_EXPORT RasterTask : public TileTask {
66 public:
67 typedef std::vector<scoped_refptr<RasterTask>> Vector;
69 const ImageDecodeTask::Vector& dependencies() const { return dependencies_; }
71 protected:
72 explicit RasterTask(ImageDecodeTask::Vector* dependencies);
73 ~RasterTask() override;
75 private:
76 ImageDecodeTask::Vector dependencies_;
79 // kNumberOfTaskSets must be greater or equal to the number of values in
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;
87 class CC_EXPORT TileTaskRunnerClient {
88 public:
89 virtual void DidFinishRunningTileTasks(TaskSet task_set) = 0;
91 protected:
92 virtual ~TileTaskRunnerClient() {}
95 struct CC_EXPORT TileTaskQueue {
96 struct CC_EXPORT Item {
97 class TaskComparator {
98 public:
99 explicit TaskComparator(const RasterTask* task) : task_(task) {}
101 bool operator()(const Item& item) const { return item.task == task_; }
103 private:
104 const RasterTask* task_;
107 typedef std::vector<Item> Vector;
109 Item(RasterTask* task, const TaskSetCollection& task_sets);
110 ~Item();
112 RasterTask* task;
113 TaskSetCollection task_sets;
116 TileTaskQueue();
117 ~TileTaskQueue();
119 void Swap(TileTaskQueue* other);
120 void Reset();
122 Item::Vector items;
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
130 // pending completion callbacks for all tasks that have finished running.
131 class CC_EXPORT TileTaskRunner {
132 public:
133 // Set the client instance to be notified when finished running tasks.
134 virtual void SetClient(TileTaskRunnerClient* client) = 0;
136 // Tells the worker pool to shutdown after canceling all previously scheduled
137 // tasks. Reply callbacks are still guaranteed to run when
138 // CheckForCompletedTasks() is called.
139 virtual void Shutdown() = 0;
141 // Schedule running of tile tasks in |queue| and all dependencies.
142 // Previously scheduled tasks that are not in |queue| will be canceled unless
143 // already running. Once scheduled, reply callbacks are guaranteed to run for
144 // all tasks even if they later get canceled by another call to
145 // ScheduleTasks().
146 virtual void ScheduleTasks(TileTaskQueue* queue) = 0;
148 // Check for completed tasks and dispatch reply callbacks.
149 virtual void CheckForCompletedTasks() = 0;
151 // Returns the format to use for the tiles.
152 virtual ResourceFormat GetResourceFormat() const = 0;
154 // Determine if the resource requires swizzling.
155 virtual bool GetResourceRequiresSwizzle() const = 0;
157 protected:
158 virtual ~TileTaskRunner() {}
161 } // namespace cc
163 #endif // CC_RASTER_TILE_TASK_RUNNER_H_