Enable right clicking on the applist doodle web contents and log the data.
[chromium-blink-merge.git] / cc / resources / tiling_set_raster_queue_all.cc
blobc4d949cb75ae3e164f90028411216c423ea8abe1
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"
7 #include <utility>
9 #include "cc/resources/picture_layer_tiling_set.h"
10 #include "cc/resources/tile.h"
11 #include "cc/resources/tile_priority.h"
13 namespace cc {
15 TilingSetRasterQueueAll::TilingSetRasterQueueAll(
16 PictureLayerTilingSet* tiling_set,
17 bool prioritize_low_res)
18 : tiling_set_(tiling_set), current_stage_(0) {
19 DCHECK(tiling_set_);
21 // Early out if the tiling set has no tilings.
22 if (!tiling_set_->num_tilings()) {
23 current_stage_ = arraysize(stages_);
24 return;
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;
42 } else {
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)
59 AdvanceToNextStage();
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);
76 ++iterators_[index];
78 if (iterators_[index].done() || iterators_[index].type() != tile_type)
79 AdvanceToNextStage();
82 Tile* TilingSetRasterQueueAll::Top() {
83 DCHECK(!IsEmpty());
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 {
93 DCHECK(!IsEmpty());
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_));
104 ++current_stage_;
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)
110 break;
111 ++current_stage_;
115 TilingSetRasterQueueAll::TilingIterator::TilingIterator()
116 : tiling_(NULL), current_tile_(NULL) {
119 TilingSetRasterQueueAll::TilingIterator::TilingIterator(
120 PictureLayerTiling* tiling,
121 TilingData* tiling_data)
122 : tiling_(tiling),
123 tiling_data_(tiling_data),
124 phase_(VISIBLE_RECT),
125 current_tile_(NULL) {
126 if (!tiling_->has_visible_rect_tiles()) {
127 AdvancePhase();
128 return;
131 visible_iterator_ =
132 TilingData::Iterator(tiling_data_, tiling_->current_visible_rect(),
133 false /* include_borders */);
134 if (!visible_iterator_) {
135 AdvancePhase();
136 return;
139 current_tile_ =
140 tiling_->TileAt(visible_iterator_.index_x(), visible_iterator_.index_y());
141 if (!current_tile_ || !TileNeedsRaster(current_tile_)) {
142 ++(*this);
143 return;
145 tiling_->UpdateTileAndTwinPriority(current_tile_);
148 TilingSetRasterQueueAll::TilingIterator::~TilingIterator() {
151 void TilingSetRasterQueueAll::TilingIterator::AdvancePhase() {
152 DCHECK_LT(phase_, EVENTUALLY_RECT);
154 do {
155 phase_ = static_cast<Phase>(phase_ + 1);
156 switch (phase_) {
157 case VISIBLE_RECT:
158 NOTREACHED();
159 return;
160 case SKEWPORT_RECT:
161 if (!tiling_->has_skewport_rect_tiles())
162 continue;
164 spiral_iterator_ = TilingData::SpiralDifferenceIterator(
165 tiling_data_, tiling_->current_skewport_rect(),
166 tiling_->current_visible_rect(), tiling_->current_visible_rect());
167 break;
168 case SOON_BORDER_RECT:
169 if (!tiling_->has_soon_border_rect_tiles())
170 continue;
172 spiral_iterator_ = TilingData::SpiralDifferenceIterator(
173 tiling_data_, tiling_->current_soon_border_rect(),
174 tiling_->current_skewport_rect(), tiling_->current_visible_rect());
175 break;
176 case EVENTUALLY_RECT:
177 if (!tiling_->has_eventually_rect_tiles()) {
178 current_tile_ = NULL;
179 return;
182 spiral_iterator_ = TilingData::SpiralDifferenceIterator(
183 tiling_data_, tiling_->current_eventually_rect(),
184 tiling_->current_skewport_rect(),
185 tiling_->current_soon_border_rect());
186 break;
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_))
193 break;
194 ++spiral_iterator_;
197 if (!spiral_iterator_ && phase_ == EVENTUALLY_RECT) {
198 current_tile_ = NULL;
199 break;
201 } while (!spiral_iterator_);
203 if (current_tile_)
204 tiling_->UpdateTileAndTwinPriority(current_tile_);
207 TilingSetRasterQueueAll::TilingIterator&
208 TilingSetRasterQueueAll::TilingIterator::
209 operator++() {
210 current_tile_ = NULL;
211 while (!current_tile_ || !TileNeedsRaster(current_tile_)) {
212 std::pair<int, int> next_index;
213 switch (phase_) {
214 case VISIBLE_RECT:
215 ++visible_iterator_;
216 if (!visible_iterator_) {
217 AdvancePhase();
218 return *this;
220 next_index = visible_iterator_.index();
221 break;
222 case SKEWPORT_RECT:
223 case SOON_BORDER_RECT:
224 ++spiral_iterator_;
225 if (!spiral_iterator_) {
226 AdvancePhase();
227 return *this;
229 next_index = spiral_iterator_.index();
230 break;
231 case EVENTUALLY_RECT:
232 ++spiral_iterator_;
233 if (!spiral_iterator_) {
234 current_tile_ = NULL;
235 return *this;
237 next_index = spiral_iterator_.index();
238 break;
240 current_tile_ = tiling_->TileAt(next_index.first, next_index.second);
243 if (current_tile_)
244 tiling_->UpdateTileAndTwinPriority(current_tile_);
245 return *this;
248 } // namespace cc