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
263
264
265
266
267
268
269
|
// 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 <vector>
#include "base/containers/hash_tables.h"
#include "cc/debug/rendering_stats_instrumentation.h"
#include "cc/resources/picture_pile_impl.h"
#include "cc/resources/resource_provider.h"
#include "cc/resources/tile_priority.h"
#include "cc/resources/worker_pool.h"
class SkDevice;
namespace skia {
class LazyPixelRef;
}
namespace cc {
class PicturePileImpl;
class PixelBufferRasterWorkerPool;
class Resource;
namespace internal {
class CC_EXPORT RasterWorkerPoolTask
: public base::RefCounted<RasterWorkerPoolTask> {
public:
typedef std::vector<scoped_refptr<RasterWorkerPoolTask> > TaskVector;
// Returns true if |device| was written to. False indicate that
// the content of |device| is undefined and the resource doesn't
// need to be initialized.
virtual bool RunOnThread(SkDevice* device, unsigned thread_index) = 0;
virtual void DispatchCompletionCallback() = 0;
void DidRun();
bool HasFinishedRunning() const;
void DidComplete();
bool HasCompleted() const;
const Resource* resource() const { return resource_; }
const WorkerPoolTask::TaskVector& dependencies() const {
return dependencies_;
}
protected:
friend class base::RefCounted<RasterWorkerPoolTask>;
RasterWorkerPoolTask(const Resource* resource,
WorkerPoolTask::TaskVector* dependencies);
virtual ~RasterWorkerPoolTask();
private:
bool did_run_;
bool did_complete_;
const Resource* resource_;
WorkerPoolTask::TaskVector dependencies_;
};
} // namespace internal
} // namespace cc
#if defined(COMPILER_GCC)
namespace BASE_HASH_NAMESPACE {
template <> struct hash<cc::internal::RasterWorkerPoolTask*> {
size_t operator()(cc::internal::RasterWorkerPoolTask* ptr) const {
return hash<size_t>()(reinterpret_cast<size_t>(ptr));
}
};
} // namespace BASE_HASH_NAMESPACE
#endif // COMPILER
namespace cc {
// Low quality implies no lcd test;
// high quality implies lcd text.
// Note that the order of these matters, from "better" to "worse" in terms of
// quality.
// TODO(vmpstr): Find a better place for this.
enum RasterMode {
HIGH_QUALITY_RASTER_MODE = 0,
HIGH_QUALITY_NO_LCD_RASTER_MODE = 1,
LOW_QUALITY_RASTER_MODE = 2,
NUM_RASTER_MODES = 3
};
// Data that is passed to raster tasks.
// TODO(vmpstr): Find a better place for this.
struct RasterTaskMetadata {
scoped_ptr<base::Value> AsValue() const;
bool is_tile_in_pending_tree_now_bin;
TileResolution tile_resolution;
int layer_id;
const void* tile_id;
int source_frame_number;
};
class CC_EXPORT RasterWorkerPoolClient {
public:
virtual bool ShouldForceTasksRequiredForActivationToComplete() const = 0;
protected:
virtual ~RasterWorkerPoolClient() {}
};
// A worker thread pool that runs raster tasks.
class CC_EXPORT RasterWorkerPool : public WorkerPool {
public:
class CC_EXPORT Task {
public:
typedef base::Callback<void()> Reply;
class CC_EXPORT Set {
public:
Set();
~Set();
void Insert(const Task& task);
private:
friend class RasterWorkerPool;
friend class RasterWorkerPoolTest;
typedef internal::WorkerPoolTask::TaskVector TaskVector;
TaskVector tasks_;
};
Task();
~Task();
// Returns true if Task is null (doesn't refer to anything).
bool is_null() const { return !internal_.get(); }
// Returns the Task into an uninitialized state.
void Reset();
protected:
friend class RasterWorkerPool;
friend class RasterWorkerPoolTest;
explicit Task(internal::WorkerPoolTask* internal);
scoped_refptr<internal::WorkerPoolTask> internal_;
};
class CC_EXPORT RasterTask {
public:
typedef base::Callback<void(const PicturePileImpl::Analysis& analysis,
bool was_canceled)> Reply;
class CC_EXPORT Queue {
public:
typedef internal::RasterWorkerPoolTask::TaskVector TaskVector;
Queue();
~Queue();
void Append(const RasterTask& task, bool required_for_activation);
private:
friend class RasterWorkerPool;
TaskVector tasks_;
typedef base::hash_set<internal::RasterWorkerPoolTask*> TaskSet;
TaskSet tasks_required_for_activation_;
};
RasterTask();
~RasterTask();
// Returns true if Task is null (doesn't refer to anything).
bool is_null() const { return !internal_.get(); }
// Returns the Task into an uninitialized state.
void Reset();
protected:
friend class PixelBufferRasterWorkerPool;
friend class RasterWorkerPool;
friend class RasterWorkerPoolTest;
explicit RasterTask(internal::RasterWorkerPoolTask* internal);
scoped_refptr<internal::RasterWorkerPoolTask> internal_;
};
virtual ~RasterWorkerPool();
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() OVERRIDE;
// 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(RasterTask::Queue* queue) = 0;
// TODO(vmpstr): Try to elimiate some variables.
static RasterTask CreateRasterTask(
const Resource* resource,
PicturePileImpl* picture_pile,
gfx::Rect content_rect,
float contents_scale,
RasterMode raster_mode,
bool use_color_estimator,
const RasterTaskMetadata& metadata,
RenderingStatsInstrumentation* rendering_stats,
const RasterTask::Reply& reply,
Task::Set& dependencies);
static Task CreateImageDecodeTask(
skia::LazyPixelRef* pixel_ref,
int layer_id,
RenderingStatsInstrumentation* stats_instrumentation);
protected:
class RootTask {
public:
RootTask();
explicit RootTask(internal::WorkerPoolTask::TaskVector* dependencies);
RootTask(const base::Closure& callback,
internal::WorkerPoolTask::TaskVector* dependencies);
~RootTask();
protected:
friend class RasterWorkerPool;
scoped_refptr<internal::WorkerPoolTask> internal_;
};
typedef internal::RasterWorkerPoolTask* TaskMapKey;
typedef base::hash_map<TaskMapKey,
scoped_refptr<internal::WorkerPoolTask> > TaskMap;
RasterWorkerPool(ResourceProvider* resource_provider, size_t num_threads);
void SetRasterTasks(RasterTask::Queue* queue);
void ScheduleRasterTasks(const RootTask& root);
bool IsRasterTaskRequiredForActivation(
internal::RasterWorkerPoolTask* task) const;
RasterWorkerPoolClient* client() const { return client_; }
ResourceProvider* resource_provider() const { return resource_provider_; }
const RasterTask::Queue::TaskVector& raster_tasks() const {
return raster_tasks_;
}
private:
RasterWorkerPoolClient* client_;
ResourceProvider* resource_provider_;
RasterTask::Queue::TaskVector raster_tasks_;
RasterTask::Queue::TaskSet raster_tasks_required_for_activation_;
// The root task that is a dependent of all other tasks.
scoped_refptr<internal::WorkerPoolTask> root_;
};
} // namespace cc
#endif // CC_RESOURCES_RASTER_WORKER_POOL_H_
|