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_
11 #include "base/callback.h"
12 #include "cc/raster/task_graph_runner.h"
13 #include "cc/resources/resource_format.h"
16 class ImageDecodeTask
;
21 class CC_EXPORT TileTaskClient
{
23 virtual scoped_ptr
<RasterBuffer
> AcquireBufferForRaster(
24 const Resource
* resource
) = 0;
25 virtual void ReleaseBufferForRaster(scoped_ptr
<RasterBuffer
> buffer
) = 0;
28 virtual ~TileTaskClient() {}
31 class CC_EXPORT TileTask
: public Task
{
33 typedef std::vector
<scoped_refptr
<TileTask
>> Vector
;
35 virtual void ScheduleOnOriginThread(TileTaskClient
* client
) = 0;
36 virtual void CompleteOnOriginThread(TileTaskClient
* client
) = 0;
37 virtual void RunReplyOnOriginThread() = 0;
39 // Type-checking downcast routines.
40 virtual ImageDecodeTask
* AsImageDecodeTask();
41 virtual RasterTask
* AsRasterTask();
45 bool HasBeenScheduled() const;
49 bool HasCompleted() const;
59 class CC_EXPORT ImageDecodeTask
: public TileTask
{
61 typedef std::vector
<scoped_refptr
<ImageDecodeTask
>> Vector
;
63 // Overridden from TileTask:
64 ImageDecodeTask
* AsImageDecodeTask() override
;
68 ~ImageDecodeTask() override
;
71 class CC_EXPORT RasterTask
: public TileTask
{
73 typedef std::vector
<scoped_refptr
<RasterTask
>> Vector
;
75 // Overridden from TileTask:
76 RasterTask
* AsRasterTask() override
;
78 const Resource
* resource() const { return resource_
; }
79 const ImageDecodeTask::Vector
& dependencies() const { return dependencies_
; }
82 RasterTask(const Resource
* resource
, ImageDecodeTask::Vector
* dependencies
);
83 ~RasterTask() override
;
86 const Resource
* resource_
;
87 ImageDecodeTask::Vector dependencies_
;
90 // kNumberOfTaskSets must be greater or equal to the number of values in
91 // TileManager::NamedTaskSet.
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.
94 static const size_t kNumberOfTaskSets
= 3;
95 typedef size_t TaskSet
;
96 typedef std::bitset
<kNumberOfTaskSets
> TaskSetCollection
;
98 class CC_EXPORT TileTaskRunnerClient
{
100 virtual void DidFinishRunningTileTasks(TaskSet task_set
) = 0;
101 virtual TaskSetCollection
TasksThatShouldBeForcedToComplete() const = 0;
104 virtual ~TileTaskRunnerClient() {}
107 struct CC_EXPORT TileTaskQueue
{
108 struct CC_EXPORT Item
{
109 class TaskComparator
{
111 explicit TaskComparator(const RasterTask
* task
) : task_(task
) {}
113 bool operator()(const Item
& item
) const { return item
.task
== task_
; }
116 const RasterTask
* task_
;
119 typedef std::vector
<Item
> Vector
;
121 Item(RasterTask
* task
, const TaskSetCollection
& task_sets
);
125 TaskSetCollection task_sets
;
131 void Swap(TileTaskQueue
* other
);
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
139 // activation" have finished running, when tasks marked "required for draw"
140 // have finished running, and when all scheduled tasks have finished running.
141 // The client can call CheckForCompletedTasks() at any time to dispatch
142 // pending completion callbacks for all tasks that have finished running.
143 class CC_EXPORT TileTaskRunner
{
145 // Set the client instance to be notified when finished running tasks.
146 virtual void SetClient(TileTaskRunnerClient
* client
) = 0;
148 // Tells the worker pool to shutdown after canceling all previously scheduled
149 // tasks. Reply callbacks are still guaranteed to run when
150 // CheckForCompletedTasks() is called.
151 virtual void Shutdown() = 0;
153 // Schedule running of tile tasks in |queue| and all dependencies.
154 // Previously scheduled tasks that are not in |queue| will be canceled unless
155 // already running. Once scheduled, reply callbacks are guaranteed to run for
156 // all tasks even if they later get canceled by another call to
158 virtual void ScheduleTasks(TileTaskQueue
* queue
) = 0;
160 // Check for completed tasks and dispatch reply callbacks.
161 virtual void CheckForCompletedTasks() = 0;
163 // Returns the format to use for the tiles.
164 virtual ResourceFormat
GetResourceFormat() = 0;
167 virtual ~TileTaskRunner() {}
172 #endif // CC_RASTER_TILE_TASK_RUNNER_H_