1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CC_RESOURCES_RASTER_WORKER_POOL_H_
#define CC_RESOURCES_RASTER_WORKER_POOL_H_
#include <deque>
#include <vector>
#include "cc/debug/rendering_stats_instrumentation.h"
#include "cc/resources/picture_pile_impl.h"
#include "cc/resources/raster_mode.h"
#include "cc/resources/resource_format.h"
#include "cc/resources/task_graph_runner.h"
#include "cc/resources/tile_priority.h"
class SkPixelRef;
namespace cc {
class ContextProvider;
class Resource;
class ResourceProvider;
namespace internal {
class WorkerPoolTask;
class RasterWorkerPoolTask;
class CC_EXPORT WorkerPoolTaskClient {
public:
virtual SkCanvas* AcquireCanvasForRaster(RasterWorkerPoolTask* task) = 0;
virtual void OnRasterCompleted(RasterWorkerPoolTask* task,
const PicturePileImpl::Analysis& analysis) = 0;
virtual void OnImageDecodeCompleted(WorkerPoolTask* task) = 0;
protected:
virtual ~WorkerPoolTaskClient() {}
};
class CC_EXPORT WorkerPoolTask : public Task {
public:
typedef std::vector<scoped_refptr<WorkerPoolTask> > Vector;
virtual void ScheduleOnOriginThread(WorkerPoolTaskClient* client) = 0;
virtual void RunOnOriginThread() = 0;
virtual void CompleteOnOriginThread(WorkerPoolTaskClient* client) = 0;
virtual void RunReplyOnOriginThread() = 0;
void WillSchedule();
void DidSchedule();
bool HasBeenScheduled() const;
void WillComplete();
void DidComplete();
bool HasCompleted() const;
protected:
WorkerPoolTask();
virtual ~WorkerPoolTask();
bool did_schedule_;
bool did_complete_;
};
class CC_EXPORT RasterWorkerPoolTask : public WorkerPoolTask {
public:
const Resource* resource() const { return resource_; }
const internal::WorkerPoolTask::Vector& dependencies() const {
return dependencies_;
}
protected:
RasterWorkerPoolTask(const Resource* resource,
internal::WorkerPoolTask::Vector* dependencies);
virtual ~RasterWorkerPoolTask();
private:
const Resource* resource_;
WorkerPoolTask::Vector dependencies_;
};
} // namespace internal
class CC_EXPORT RasterWorkerPoolClient {
public:
virtual bool ShouldForceTasksRequiredForActivationToComplete() const = 0;
virtual void DidFinishRunningTasks() = 0;
virtual void DidFinishRunningTasksRequiredForActivation() = 0;
protected:
virtual ~RasterWorkerPoolClient() {}
};
struct CC_EXPORT RasterTaskQueue {
struct CC_EXPORT Item {
class TaskComparator {
public:
explicit TaskComparator(const internal::RasterWorkerPoolTask* task)
: task_(task) {}
bool operator()(const Item& item) const { return item.task == task_; }
private:
const internal::RasterWorkerPoolTask* task_;
};
typedef std::vector<Item> Vector;
Item(internal::RasterWorkerPoolTask* task, bool required_for_activation);
~Item();
static bool IsRequiredForActivation(const Item& item) {
return item.required_for_activation;
}
scoped_refptr<internal::RasterWorkerPoolTask> task;
bool required_for_activation;
};
RasterTaskQueue();
~RasterTaskQueue();
void Swap(RasterTaskQueue* other);
void Reset();
Item::Vector items;
size_t required_for_activation_count;
};
// A worker thread pool that runs raster tasks.
class CC_EXPORT RasterWorkerPool : public internal::WorkerPoolTaskClient {
public:
virtual ~RasterWorkerPool();
static void SetNumRasterThreads(int num_threads);
static int GetNumRasterThreads();
static internal::TaskGraphRunner* GetTaskGraphRunner();
static unsigned kOnDemandRasterTaskPriority;
static unsigned kRasterFinishedTaskPriority;
static unsigned kRasterRequiredForActivationFinishedTaskPriority;
static unsigned kRasterTaskPriorityBase;
// TODO(vmpstr): Figure out an elegant way to not pass this many parameters.
static scoped_refptr<internal::RasterWorkerPoolTask> CreateRasterTask(
const Resource* resource,
PicturePileImpl* picture_pile,
const gfx::Rect& content_rect,
float contents_scale,
RasterMode raster_mode,
TileResolution tile_resolution,
int layer_id,
const void* tile_id,
int source_frame_number,
RenderingStatsInstrumentation* rendering_stats,
const base::Callback<void(const PicturePileImpl::Analysis&, bool)>& reply,
internal::WorkerPoolTask::Vector* dependencies,
ContextProvider* context_provider);
static scoped_refptr<internal::WorkerPoolTask> CreateImageDecodeTask(
SkPixelRef* pixel_ref,
int layer_id,
RenderingStatsInstrumentation* rendering_stats,
const base::Callback<void(bool was_canceled)>& reply);
void SetClient(RasterWorkerPoolClient* client);
// Tells the worker pool to shutdown after canceling all previously
// scheduled tasks. Reply callbacks are still guaranteed to run.
virtual void Shutdown();
// Schedule running of raster tasks in |queue| and all dependencies.
// Previously scheduled tasks that are no longer needed to run
// raster tasks in |queue| will be canceled unless already running.
// Once scheduled, reply callbacks are guaranteed to run for all tasks
// even if they later get canceled by another call to ScheduleTasks().
virtual void ScheduleTasks(RasterTaskQueue* queue) = 0;
// Force a check for completed tasks.
virtual void CheckForCompletedTasks() = 0;
// Returns the target that needs to be used for raster task resources.
virtual unsigned GetResourceTarget() const = 0;
// Returns the format that needs to be used for raster task resources.
virtual ResourceFormat GetResourceFormat() const = 0;
protected:
typedef std::vector<scoped_refptr<internal::WorkerPoolTask> > TaskVector;
typedef std::deque<scoped_refptr<internal::WorkerPoolTask> > TaskDeque;
typedef std::vector<scoped_refptr<internal::RasterWorkerPoolTask> >
RasterTaskVector;
RasterWorkerPool(internal::TaskGraphRunner* task_graph_runner,
ResourceProvider* resource_provider);
virtual void OnRasterTasksFinished() = 0;
virtual void OnRasterTasksRequiredForActivationFinished() = 0;
void SetTaskGraph(internal::TaskGraph* graph);
void CollectCompletedWorkerPoolTasks(internal::Task::Vector* completed_tasks);
RasterWorkerPoolClient* client() const { return client_; }
ResourceProvider* resource_provider() const { return resource_provider_; }
void set_raster_finished_task(
internal::WorkerPoolTask* raster_finished_task) {
raster_finished_task_ = raster_finished_task;
}
internal::WorkerPoolTask* raster_finished_task() const {
return raster_finished_task_.get();
}
void set_raster_required_for_activation_finished_task(
internal::WorkerPoolTask* raster_required_for_activation_finished_task) {
raster_required_for_activation_finished_task_ =
raster_required_for_activation_finished_task;
}
internal::WorkerPoolTask* raster_required_for_activation_finished_task()
const {
return raster_required_for_activation_finished_task_.get();
}
scoped_refptr<internal::WorkerPoolTask> CreateRasterFinishedTask();
scoped_refptr<internal::WorkerPoolTask>
CreateRasterRequiredForActivationFinishedTask(
size_t tasks_required_for_activation_count);
void RunTaskOnOriginThread(internal::WorkerPoolTask* task);
static void InsertNodeForTask(internal::TaskGraph* graph,
internal::WorkerPoolTask* task,
unsigned priority,
size_t dependencies);
static void InsertNodeForRasterTask(
internal::TaskGraph* graph,
internal::WorkerPoolTask* task,
const internal::WorkerPoolTask::Vector& decode_tasks,
unsigned priority);
private:
void OnRasterFinished(const internal::WorkerPoolTask* source);
void OnRasterRequiredForActivationFinished(
const internal::WorkerPoolTask* source);
internal::TaskGraphRunner* task_graph_runner_;
internal::NamespaceToken namespace_token_;
RasterWorkerPoolClient* client_;
ResourceProvider* resource_provider_;
scoped_refptr<internal::WorkerPoolTask> raster_finished_task_;
scoped_refptr<internal::WorkerPoolTask>
raster_required_for_activation_finished_task_;
base::WeakPtrFactory<RasterWorkerPool> weak_ptr_factory_;
};
} // namespace cc
#endif // CC_RESOURCES_RASTER_WORKER_POOL_H_
|