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
,
25 uint64_t resource_content_id
,
26 uint64_t previous_content_id
) = 0;
27 virtual void ReleaseBufferForRaster(scoped_ptr
<RasterBuffer
> buffer
) = 0;
30 virtual ~TileTaskClient() {}
33 class CC_EXPORT TileTask
: public Task
{
35 typedef std::vector
<scoped_refptr
<TileTask
>> Vector
;
37 virtual void ScheduleOnOriginThread(TileTaskClient
* client
) = 0;
38 virtual void CompleteOnOriginThread(TileTaskClient
* client
) = 0;
39 virtual void RunReplyOnOriginThread() = 0;
41 // Type-checking downcast routines.
42 virtual ImageDecodeTask
* AsImageDecodeTask();
43 virtual RasterTask
* AsRasterTask();
47 bool HasBeenScheduled() const;
51 bool HasCompleted() const;
61 class CC_EXPORT ImageDecodeTask
: public TileTask
{
63 typedef std::vector
<scoped_refptr
<ImageDecodeTask
>> Vector
;
65 // Overridden from TileTask:
66 ImageDecodeTask
* AsImageDecodeTask() override
;
70 ~ImageDecodeTask() override
;
73 class CC_EXPORT RasterTask
: public TileTask
{
75 typedef std::vector
<scoped_refptr
<RasterTask
>> Vector
;
77 // Overridden from TileTask:
78 RasterTask
* AsRasterTask() override
;
80 const Resource
* resource() const { return resource_
; }
81 const ImageDecodeTask::Vector
& dependencies() const { return dependencies_
; }
84 RasterTask(const Resource
* resource
, ImageDecodeTask::Vector
* dependencies
);
85 ~RasterTask() override
;
88 const Resource
* resource_
;
89 ImageDecodeTask::Vector dependencies_
;
92 // kNumberOfTaskSets must be greater or equal to the number of values in
93 // TileManager::NamedTaskSet.
94 // TODO(reveman): Use template specialization to make it easy for client code to
95 // check at compile time that the number of supported task sets is correct.
96 static const size_t kNumberOfTaskSets
= 3;
97 typedef size_t TaskSet
;
98 typedef std::bitset
<kNumberOfTaskSets
> TaskSetCollection
;
100 class CC_EXPORT TileTaskRunnerClient
{
102 virtual void DidFinishRunningTileTasks(TaskSet task_set
) = 0;
103 virtual TaskSetCollection
TasksThatShouldBeForcedToComplete() const = 0;
106 virtual ~TileTaskRunnerClient() {}
109 struct CC_EXPORT TileTaskQueue
{
110 struct CC_EXPORT Item
{
111 class TaskComparator
{
113 explicit TaskComparator(const RasterTask
* task
) : task_(task
) {}
115 bool operator()(const Item
& item
) const { return item
.task
== task_
; }
118 const RasterTask
* task_
;
121 typedef std::vector
<Item
> Vector
;
123 Item(RasterTask
* task
, const TaskSetCollection
& task_sets
);
127 TaskSetCollection task_sets
;
133 void Swap(TileTaskQueue
* other
);
139 // This interface can be used to schedule and run tile tasks. The client will
140 // be notified asynchronously when the set of tasks marked as "required for
141 // activation" have finished running, when tasks marked "required for draw"
142 // have finished running, and when all scheduled tasks have finished running.
143 // The client can call CheckForCompletedTasks() at any time to dispatch
144 // pending completion callbacks for all tasks that have finished running.
145 class CC_EXPORT TileTaskRunner
{
147 // Set the client instance to be notified when finished running tasks.
148 virtual void SetClient(TileTaskRunnerClient
* client
) = 0;
150 // Tells the worker pool to shutdown after canceling all previously scheduled
151 // tasks. Reply callbacks are still guaranteed to run when
152 // CheckForCompletedTasks() is called.
153 virtual void Shutdown() = 0;
155 // Schedule running of tile tasks in |queue| and all dependencies.
156 // Previously scheduled tasks that are not in |queue| will be canceled unless
157 // already running. Once scheduled, reply callbacks are guaranteed to run for
158 // all tasks even if they later get canceled by another call to
160 virtual void ScheduleTasks(TileTaskQueue
* queue
) = 0;
162 // Check for completed tasks and dispatch reply callbacks.
163 virtual void CheckForCompletedTasks() = 0;
165 // Returns the format to use for the tiles.
166 virtual ResourceFormat
GetResourceFormat() const = 0;
168 // Determine if the resource requires swizzling.
169 virtual bool GetResourceRequiresSwizzle() const = 0;
172 virtual ~TileTaskRunner() {}
177 #endif // CC_RASTER_TILE_TASK_RUNNER_H_