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 #include "cc/resources/tiling_set_raster_queue_all.h"
9 #include "cc/resources/picture_layer_tiling_set.h"
10 #include "cc/resources/tile.h"
11 #include "cc/resources/tile_priority.h"
15 TilingSetRasterQueueAll::TilingSetRasterQueueAll(
16 PictureLayerTilingSet
* tiling_set
,
17 bool prioritize_low_res
)
18 : tiling_set_(tiling_set
), current_stage_(0) {
21 // Early out if the tiling set has no tilings.
22 if (!tiling_set_
->num_tilings()) {
23 current_stage_
= arraysize(stages_
);
27 // Find high and low res tilings and initialize the iterators.
28 for (size_t i
= 0; i
< tiling_set_
->num_tilings(); ++i
) {
29 PictureLayerTiling
* tiling
= tiling_set_
->tiling_at(i
);
30 if (tiling
->resolution() == HIGH_RESOLUTION
)
31 iterators_
[HIGH_RES
] = TilingIterator(tiling
, &tiling
->tiling_data_
);
32 if (prioritize_low_res
&& tiling
->resolution() == LOW_RESOLUTION
)
33 iterators_
[LOW_RES
] = TilingIterator(tiling
, &tiling
->tiling_data_
);
36 if (prioritize_low_res
) {
37 stages_
[0].iterator_type
= LOW_RES
;
38 stages_
[0].tile_type
= TilePriority::NOW
;
40 stages_
[1].iterator_type
= HIGH_RES
;
41 stages_
[1].tile_type
= TilePriority::NOW
;
43 stages_
[0].iterator_type
= HIGH_RES
;
44 stages_
[0].tile_type
= TilePriority::NOW
;
46 stages_
[1].iterator_type
= LOW_RES
;
47 stages_
[1].tile_type
= TilePriority::NOW
;
50 stages_
[2].iterator_type
= HIGH_RES
;
51 stages_
[2].tile_type
= TilePriority::SOON
;
53 stages_
[3].iterator_type
= HIGH_RES
;
54 stages_
[3].tile_type
= TilePriority::EVENTUALLY
;
56 IteratorType index
= stages_
[current_stage_
].iterator_type
;
57 TilePriority::PriorityBin tile_type
= stages_
[current_stage_
].tile_type
;
58 if (iterators_
[index
].done() || iterators_
[index
].type() != tile_type
)
62 TilingSetRasterQueueAll::~TilingSetRasterQueueAll() {
65 bool TilingSetRasterQueueAll::IsEmpty() const {
66 return current_stage_
>= arraysize(stages_
);
69 void TilingSetRasterQueueAll::Pop() {
70 IteratorType index
= stages_
[current_stage_
].iterator_type
;
71 TilePriority::PriorityBin tile_type
= stages_
[current_stage_
].tile_type
;
73 // First advance the iterator.
74 DCHECK(!iterators_
[index
].done());
75 DCHECK(iterators_
[index
].type() == tile_type
);
78 if (iterators_
[index
].done() || iterators_
[index
].type() != tile_type
)
82 Tile
* TilingSetRasterQueueAll::Top() {
85 IteratorType index
= stages_
[current_stage_
].iterator_type
;
86 DCHECK(!iterators_
[index
].done());
87 DCHECK(iterators_
[index
].type() == stages_
[current_stage_
].tile_type
);
89 return *iterators_
[index
];
92 const Tile
* TilingSetRasterQueueAll::Top() const {
95 IteratorType index
= stages_
[current_stage_
].iterator_type
;
96 DCHECK(!iterators_
[index
].done());
97 DCHECK(iterators_
[index
].type() == stages_
[current_stage_
].tile_type
);
99 return *iterators_
[index
];
102 void TilingSetRasterQueueAll::AdvanceToNextStage() {
103 DCHECK_LT(current_stage_
, arraysize(stages_
));
105 while (current_stage_
< arraysize(stages_
)) {
106 IteratorType index
= stages_
[current_stage_
].iterator_type
;
107 TilePriority::PriorityBin tile_type
= stages_
[current_stage_
].tile_type
;
109 if (!iterators_
[index
].done() && iterators_
[index
].type() == tile_type
)
115 TilingSetRasterQueueAll::TilingIterator::TilingIterator()
116 : tiling_(NULL
), current_tile_(NULL
) {
119 TilingSetRasterQueueAll::TilingIterator::TilingIterator(
120 PictureLayerTiling
* tiling
,
121 TilingData
* tiling_data
)
123 tiling_data_(tiling_data
),
124 phase_(VISIBLE_RECT
),
125 current_tile_(NULL
) {
126 if (!tiling_
->has_visible_rect_tiles()) {
132 TilingData::Iterator(tiling_data_
, tiling_
->current_visible_rect(),
133 false /* include_borders */);
134 if (!visible_iterator_
) {
140 tiling_
->TileAt(visible_iterator_
.index_x(), visible_iterator_
.index_y());
141 if (!current_tile_
|| !TileNeedsRaster(current_tile_
)) {
145 tiling_
->UpdateTileAndTwinPriority(current_tile_
);
148 TilingSetRasterQueueAll::TilingIterator::~TilingIterator() {
151 void TilingSetRasterQueueAll::TilingIterator::AdvancePhase() {
152 DCHECK_LT(phase_
, EVENTUALLY_RECT
);
155 phase_
= static_cast<Phase
>(phase_
+ 1);
161 if (!tiling_
->has_skewport_rect_tiles())
164 spiral_iterator_
= TilingData::SpiralDifferenceIterator(
165 tiling_data_
, tiling_
->current_skewport_rect(),
166 tiling_
->current_visible_rect(), tiling_
->current_visible_rect());
168 case SOON_BORDER_RECT
:
169 if (!tiling_
->has_soon_border_rect_tiles())
172 spiral_iterator_
= TilingData::SpiralDifferenceIterator(
173 tiling_data_
, tiling_
->current_soon_border_rect(),
174 tiling_
->current_skewport_rect(), tiling_
->current_visible_rect());
176 case EVENTUALLY_RECT
:
177 if (!tiling_
->has_eventually_rect_tiles()) {
178 current_tile_
= NULL
;
182 spiral_iterator_
= TilingData::SpiralDifferenceIterator(
183 tiling_data_
, tiling_
->current_eventually_rect(),
184 tiling_
->current_skewport_rect(),
185 tiling_
->current_soon_border_rect());
189 while (spiral_iterator_
) {
190 current_tile_
= tiling_
->TileAt(spiral_iterator_
.index_x(),
191 spiral_iterator_
.index_y());
192 if (current_tile_
&& TileNeedsRaster(current_tile_
))
197 if (!spiral_iterator_
&& phase_
== EVENTUALLY_RECT
) {
198 current_tile_
= NULL
;
201 } while (!spiral_iterator_
);
204 tiling_
->UpdateTileAndTwinPriority(current_tile_
);
207 TilingSetRasterQueueAll::TilingIterator
&
208 TilingSetRasterQueueAll::TilingIterator::
210 current_tile_
= NULL
;
211 while (!current_tile_
|| !TileNeedsRaster(current_tile_
)) {
212 std::pair
<int, int> next_index
;
216 if (!visible_iterator_
) {
220 next_index
= visible_iterator_
.index();
223 case SOON_BORDER_RECT
:
225 if (!spiral_iterator_
) {
229 next_index
= spiral_iterator_
.index();
231 case EVENTUALLY_RECT
:
233 if (!spiral_iterator_
) {
234 current_tile_
= NULL
;
237 next_index
= spiral_iterator_
.index();
240 current_tile_
= tiling_
->TileAt(next_index
.first
, next_index
.second
);
244 tiling_
->UpdateTileAndTwinPriority(current_tile_
);