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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
cc / tiles / tiling_set_raster_queue_all.cc [blame]
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "cc/tiles/tiling_set_raster_queue_all.h"
#include <stddef.h>
#include <utility>
#include "base/notreached.h"
#include "cc/base/features.h"
#include "cc/tiles/picture_layer_tiling_set.h"
#include "cc/tiles/tile.h"
#include "cc/tiles/tile_priority.h"
namespace cc {
TilingSetRasterQueueAll::IterationStage::IterationStage(
IteratorType type,
TilePriority::PriorityBin bin)
: iterator_type(type), tile_type(bin) {
}
// static
std::unique_ptr<TilingSetRasterQueueAll> TilingSetRasterQueueAll::Create(
PictureLayerTilingSet* tiling_set,
bool prioritize_low_res,
bool is_drawing_layer) {
DCHECK(tiling_set);
// Early out if the tiling set has no tiles needing raster.
if (features::IsCCSlimmingEnabled()) {
if (tiling_set->all_tiles_done()) {
return nullptr;
}
} else {
if (!tiling_set->num_tilings()) {
return base::WrapUnique(new TilingSetRasterQueueAll(
nullptr, nullptr, nullptr, is_drawing_layer));
}
}
const PictureLayerTilingClient* client = tiling_set->client();
WhichTree tree = tiling_set->tree();
// Find high and low res tilings and initialize the iterators.
PictureLayerTiling* high_res_tiling = nullptr;
PictureLayerTiling* low_res_tiling = nullptr;
// This variable would point to a tiling that has a NON_IDEAL_RESOLUTION or
// LOW_RESOLUTION on the active tree, but HIGH_RESOLUTION on the pending tree.
// These tilings are the only non-high res tilings that could have required
// for activation tiles, so they need to be considered for rasterization.
PictureLayerTiling* active_non_ideal_pending_high_res_tiling = nullptr;
for (size_t i = 0; i < tiling_set->num_tilings(); ++i) {
PictureLayerTiling* tiling = tiling_set->tiling_at(i);
if (tiling->resolution() == HIGH_RESOLUTION)
high_res_tiling = tiling;
if (prioritize_low_res && tiling->resolution() == LOW_RESOLUTION)
low_res_tiling = tiling;
if (tree == ACTIVE_TREE && tiling->resolution() != HIGH_RESOLUTION) {
const PictureLayerTiling* twin =
client->GetPendingOrActiveTwinTiling(tiling);
if (twin && twin->resolution() == HIGH_RESOLUTION)
active_non_ideal_pending_high_res_tiling = tiling;
}
}
bool use_low_res_tiling = low_res_tiling && low_res_tiling->has_tiles() &&
!low_res_tiling->all_tiles_done();
bool use_high_res_tiling = high_res_tiling && high_res_tiling->has_tiles() &&
!high_res_tiling->all_tiles_done();
bool use_active_non_ideal_pending_high_res_tiling =
active_non_ideal_pending_high_res_tiling &&
active_non_ideal_pending_high_res_tiling->has_tiles() &&
!active_non_ideal_pending_high_res_tiling->all_tiles_done();
if (!use_low_res_tiling && !use_high_res_tiling &&
!use_active_non_ideal_pending_high_res_tiling &&
features::IsCCSlimmingEnabled()) {
return nullptr;
}
return base::WrapUnique(new TilingSetRasterQueueAll(
use_high_res_tiling ? high_res_tiling : nullptr,
use_low_res_tiling ? low_res_tiling : nullptr,
use_active_non_ideal_pending_high_res_tiling
? active_non_ideal_pending_high_res_tiling
: nullptr,
is_drawing_layer));
}
TilingSetRasterQueueAll::TilingSetRasterQueueAll(
PictureLayerTiling* high_res_tiling,
PictureLayerTiling* low_res_tiling,
PictureLayerTiling* active_non_ideal_pending_high_res_tiling,
bool is_drawing_layer)
: current_stage_(0), is_drawing_layer_(is_drawing_layer) {
if (!high_res_tiling && !low_res_tiling &&
!active_non_ideal_pending_high_res_tiling) {
DCHECK(!features::IsCCSlimmingEnabled());
return;
}
// Make the tiling iterators.
if (low_res_tiling) {
MakeTilingIterator(LOW_RES, low_res_tiling);
} else if (!features::IsCCSlimmingEnabled()) {
iterators_[LOW_RES].emplace();
}
if (high_res_tiling) {
MakeTilingIterator(HIGH_RES, high_res_tiling);
} else if (!features::IsCCSlimmingEnabled()) {
iterators_[HIGH_RES].emplace();
}
if (active_non_ideal_pending_high_res_tiling) {
MakeTilingIterator(ACTIVE_NON_IDEAL_PENDING_HIGH_RES,
active_non_ideal_pending_high_res_tiling);
} else if (!features::IsCCSlimmingEnabled()) {
iterators_[ACTIVE_NON_IDEAL_PENDING_HIGH_RES].emplace();
}
// Set up the stages.
if (low_res_tiling) {
stages_.push_back(IterationStage(LOW_RES, TilePriority::NOW));
}
if (high_res_tiling) {
stages_.push_back(IterationStage(HIGH_RES, TilePriority::NOW));
}
if (active_non_ideal_pending_high_res_tiling) {
stages_.push_back(
IterationStage(ACTIVE_NON_IDEAL_PENDING_HIGH_RES, TilePriority::NOW));
stages_.push_back(
IterationStage(ACTIVE_NON_IDEAL_PENDING_HIGH_RES, TilePriority::SOON));
}
if (high_res_tiling) {
stages_.push_back(IterationStage(HIGH_RES, TilePriority::SOON));
stages_.push_back(IterationStage(HIGH_RES, TilePriority::EVENTUALLY));
}
DCHECK(!stages_.empty());
IteratorType index = stages_[current_stage_].iterator_type;
TilePriority::PriorityBin tile_type = stages_[current_stage_].tile_type;
if (!iterators_[index] || iterators_[index]->done() ||
iterators_[index]->type() != tile_type) {
AdvanceToNextStage();
}
}
TilingSetRasterQueueAll::~TilingSetRasterQueueAll() = default;
void TilingSetRasterQueueAll::MakeTilingIterator(IteratorType type,
PictureLayerTiling* tiling) {
iterators_[type].emplace(tiling, &tiling->tiling_data_);
if (iterators_[type]->done()) {
tiling->set_all_tiles_done(true);
// If we've marked the tiling as done, make sure we're actually done.
tiling->VerifyNoTileNeedsRaster();
}
}
bool TilingSetRasterQueueAll::IsEmpty() const {
return current_stage_ >= stages_.size();
}
void TilingSetRasterQueueAll::Pop() {
IteratorType index = stages_[current_stage_].iterator_type;
TilePriority::PriorityBin tile_type = stages_[current_stage_].tile_type;
// First advance the iterator.
DCHECK(iterators_[index]);
DCHECK(!iterators_[index]->done());
DCHECK(iterators_[index]->type() == tile_type);
++(*iterators_[index]);
if (!iterators_[index] || iterators_[index]->done() ||
iterators_[index]->type() != tile_type) {
AdvanceToNextStage();
}
}
const PrioritizedTile& TilingSetRasterQueueAll::Top() const {
DCHECK(!IsEmpty());
IteratorType index = stages_[current_stage_].iterator_type;
DCHECK(iterators_[index]);
DCHECK(!iterators_[index]->done());
DCHECK(iterators_[index]->type() == stages_[current_stage_].tile_type);
return **iterators_[index];
}
void TilingSetRasterQueueAll::AdvanceToNextStage() {
DCHECK_LT(current_stage_, stages_.size());
++current_stage_;
while (current_stage_ < stages_.size()) {
IteratorType index = stages_[current_stage_].iterator_type;
TilePriority::PriorityBin tile_type = stages_[current_stage_].tile_type;
if (iterators_[index] && !iterators_[index]->done() &&
iterators_[index]->type() == tile_type) {
break;
}
++current_stage_;
}
}
// OnePriorityRectIterator
TilingSetRasterQueueAll::OnePriorityRectIterator::OnePriorityRectIterator()
: tiling_(nullptr), tiling_data_(nullptr) {
}
TilingSetRasterQueueAll::OnePriorityRectIterator::OnePriorityRectIterator(
PictureLayerTiling* tiling,
TilingData* tiling_data,
PictureLayerTiling::PriorityRectType priority_rect_type)
: tiling_(tiling),
tiling_data_(tiling_data),
priority_rect_type_(priority_rect_type),
pending_visible_rect_(tiling->pending_visible_rect()) {
}
template <typename TilingIteratorType>
void TilingSetRasterQueueAll::OnePriorityRectIterator::AdvanceToNextTile(
TilingIteratorType* iterator) {
for (;;) {
++(*iterator);
if (!(*iterator)) {
current_tile_ = PrioritizedTile();
break;
}
Tile* tile = tiling_->TileAt(iterator->index_x(), iterator->index_y());
auto result = IsTileValid(tile);
if (result == kTileNotValid)
continue;
bool is_tile_occluded =
result != kTileNeedsRaster && tiling_->IsTileOccluded(tile);
current_tile_ = tiling_->MakePrioritizedTile(tile, priority_rect_type_,
is_tile_occluded);
break;
}
}
template <typename TilingIteratorType>
bool TilingSetRasterQueueAll::OnePriorityRectIterator::
GetFirstTileAndCheckIfValid(TilingIteratorType* iterator) {
Tile* tile = tiling_->TileAt(iterator->index_x(), iterator->index_y());
auto result = IsTileValid(tile);
if (result == kTileNotValid) {
current_tile_ = PrioritizedTile();
return false;
}
// Note that if tile needs raster then by definition it is not occluded.
bool is_tile_occluded =
result != kTileNeedsRaster && tiling_->IsTileOccluded(tile);
current_tile_ =
tiling_->MakePrioritizedTile(tile, priority_rect_type_, is_tile_occluded);
return true;
}
TilingSetRasterQueueAll::OnePriorityRectIterator::IsTileValidResult
TilingSetRasterQueueAll::OnePriorityRectIterator::IsTileValid(
const Tile* tile) const {
if (!tile)
return kTileNotValid;
// A tile is valid for raster if it needs raster and is unoccluded.
bool tile_is_valid_for_raster =
tile->draw_info().NeedsRaster() && !tiling_->IsTileOccluded(tile);
// A tile is not valid for the raster queue if it is not valid for raster or
// processing for checker-images.
IsTileValidResult result = kTileNeedsRaster;
if (!tile_is_valid_for_raster) {
// Note that we might need to re-raster the tile if it was checker imaged.
bool tile_is_valid_for_checker_images =
tile->draw_info().is_checker_imaged() &&
tiling_->ShouldDecodeCheckeredImagesForTile(tile);
if (!tile_is_valid_for_checker_images)
return kTileNotValid;
result = kTileNeedsCheckerImageReraster;
}
// After the pending visible rect has been processed, we must return false
// for pending visible rect tiles as tiling iterators do not ignore those
// tiles.
if (priority_rect_type_ > PictureLayerTiling::PENDING_VISIBLE_RECT) {
gfx::Rect tile_bounds = tiling_data_->TileBounds(tile->tiling_i_index(),
tile->tiling_j_index());
if (pending_visible_rect_.Intersects(tile_bounds))
return kTileNotValid;
}
return result;
}
// VisibleTilingIterator.
TilingSetRasterQueueAll::VisibleTilingIterator::VisibleTilingIterator(
PictureLayerTiling* tiling,
TilingData* tiling_data)
: OnePriorityRectIterator(tiling,
tiling_data,
PictureLayerTiling::VISIBLE_RECT) {
if (!tiling_->has_visible_rect_tiles())
return;
iterator_ =
TilingData::Iterator(tiling_data_, tiling_->current_visible_rect(),
false /* include_borders */);
if (!iterator_)
return;
if (!GetFirstTileAndCheckIfValid(&iterator_))
++(*this);
}
TilingSetRasterQueueAll::VisibleTilingIterator&
TilingSetRasterQueueAll::VisibleTilingIterator::
operator++() {
AdvanceToNextTile(&iterator_);
return *this;
}
// PendingVisibleTilingIterator.
TilingSetRasterQueueAll::PendingVisibleTilingIterator::
PendingVisibleTilingIterator(PictureLayerTiling* tiling,
TilingData* tiling_data)
: OnePriorityRectIterator(tiling,
tiling_data,
PictureLayerTiling::PENDING_VISIBLE_RECT) {
iterator_ = TilingData::DifferenceIterator(
tiling_data_, pending_visible_rect_, tiling_->current_visible_rect());
if (!iterator_)
return;
if (!GetFirstTileAndCheckIfValid(&iterator_))
++(*this);
}
TilingSetRasterQueueAll::PendingVisibleTilingIterator&
TilingSetRasterQueueAll::PendingVisibleTilingIterator::
operator++() {
AdvanceToNextTile(&iterator_);
return *this;
}
// SkewportTilingIterator.
TilingSetRasterQueueAll::SkewportTilingIterator::SkewportTilingIterator(
PictureLayerTiling* tiling,
TilingData* tiling_data)
: OnePriorityRectIterator(tiling,
tiling_data,
PictureLayerTiling::SKEWPORT_RECT) {
if (!tiling_->has_skewport_rect_tiles())
return;
iterator_ = TilingData::SpiralDifferenceIterator(
tiling_data_, tiling_->current_skewport_rect(),
tiling_->current_visible_rect(), tiling_->current_visible_rect());
if (!iterator_)
return;
if (!GetFirstTileAndCheckIfValid(&iterator_)) {
++(*this);
return;
}
}
TilingSetRasterQueueAll::SkewportTilingIterator&
TilingSetRasterQueueAll::SkewportTilingIterator::
operator++() {
AdvanceToNextTile(&iterator_);
return *this;
}
// SoonBorderTilingIterator.
TilingSetRasterQueueAll::SoonBorderTilingIterator::SoonBorderTilingIterator(
PictureLayerTiling* tiling,
TilingData* tiling_data)
: OnePriorityRectIterator(tiling,
tiling_data,
PictureLayerTiling::SOON_BORDER_RECT) {
if (!tiling_->has_soon_border_rect_tiles())
return;
iterator_ = TilingData::SpiralDifferenceIterator(
tiling_data_, tiling_->current_soon_border_rect(),
tiling_->current_skewport_rect(), tiling_->current_visible_rect());
if (!iterator_)
return;
if (!GetFirstTileAndCheckIfValid(&iterator_)) {
++(*this);
return;
}
}
TilingSetRasterQueueAll::SoonBorderTilingIterator&
TilingSetRasterQueueAll::SoonBorderTilingIterator::
operator++() {
AdvanceToNextTile(&iterator_);
return *this;
}
// EventuallyTilingIterator.
TilingSetRasterQueueAll::EventuallyTilingIterator::EventuallyTilingIterator(
PictureLayerTiling* tiling,
TilingData* tiling_data)
: OnePriorityRectIterator(tiling,
tiling_data,
PictureLayerTiling::EVENTUALLY_RECT) {
if (!tiling_->has_eventually_rect_tiles())
return;
iterator_ = TilingData::SpiralDifferenceIterator(
tiling_data_, tiling_->current_eventually_rect(),
tiling_->current_skewport_rect(), tiling_->current_soon_border_rect());
if (!iterator_)
return;
if (!GetFirstTileAndCheckIfValid(&iterator_)) {
++(*this);
return;
}
}
TilingSetRasterQueueAll::EventuallyTilingIterator&
TilingSetRasterQueueAll::EventuallyTilingIterator::
operator++() {
AdvanceToNextTile(&iterator_);
return *this;
}
// TilingIterator
TilingSetRasterQueueAll::TilingIterator::TilingIterator() : tiling_(nullptr) {
}
TilingSetRasterQueueAll::TilingIterator::TilingIterator(
PictureLayerTiling* tiling,
TilingData* tiling_data)
: tiling_(tiling), tiling_data_(tiling_data), phase_(Phase::VISIBLE_RECT) {
visible_iterator_ = VisibleTilingIterator(tiling_, tiling_data_);
if (visible_iterator_.done()) {
AdvancePhase();
return;
}
current_tile_ = *visible_iterator_;
}
TilingSetRasterQueueAll::TilingIterator::~TilingIterator() = default;
void TilingSetRasterQueueAll::TilingIterator::AdvancePhase() {
DCHECK_LT(phase_, Phase::EVENTUALLY_RECT);
current_tile_ = PrioritizedTile();
while (!current_tile_.tile() && phase_ < Phase::EVENTUALLY_RECT) {
phase_ = static_cast<Phase>(phase_ + 1);
switch (phase_) {
case Phase::VISIBLE_RECT:
NOTREACHED();
case Phase::PENDING_VISIBLE_RECT:
pending_visible_iterator_ =
PendingVisibleTilingIterator(tiling_, tiling_data_);
if (!pending_visible_iterator_.done())
current_tile_ = *pending_visible_iterator_;
break;
case Phase::SKEWPORT_RECT:
skewport_iterator_ = SkewportTilingIterator(tiling_, tiling_data_);
if (!skewport_iterator_.done())
current_tile_ = *skewport_iterator_;
break;
case Phase::SOON_BORDER_RECT:
soon_border_iterator_ = SoonBorderTilingIterator(tiling_, tiling_data_);
if (!soon_border_iterator_.done())
current_tile_ = *soon_border_iterator_;
break;
case Phase::EVENTUALLY_RECT:
eventually_iterator_ = EventuallyTilingIterator(tiling_, tiling_data_);
if (!eventually_iterator_.done())
current_tile_ = *eventually_iterator_;
break;
}
}
}
TilingSetRasterQueueAll::TilingIterator&
TilingSetRasterQueueAll::TilingIterator::
operator++() {
switch (phase_) {
case Phase::VISIBLE_RECT:
++visible_iterator_;
if (visible_iterator_.done()) {
AdvancePhase();
return *this;
}
current_tile_ = *visible_iterator_;
break;
case Phase::PENDING_VISIBLE_RECT:
++pending_visible_iterator_;
if (pending_visible_iterator_.done()) {
AdvancePhase();
return *this;
}
current_tile_ = *pending_visible_iterator_;
break;
case Phase::SKEWPORT_RECT:
++skewport_iterator_;
if (skewport_iterator_.done()) {
AdvancePhase();
return *this;
}
current_tile_ = *skewport_iterator_;
break;
case Phase::SOON_BORDER_RECT:
++soon_border_iterator_;
if (soon_border_iterator_.done()) {
AdvancePhase();
return *this;
}
current_tile_ = *soon_border_iterator_;
break;
case Phase::EVENTUALLY_RECT:
++eventually_iterator_;
if (eventually_iterator_.done()) {
current_tile_ = PrioritizedTile();
return *this;
}
current_tile_ = *eventually_iterator_;
break;
}
return *this;
}
} // namespace cc