| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "cc/resources/tiling_set_raster_queue_required.h" | |
| 6 | |
| 7 #include <utility> | |
| 8 | |
| 9 #include "cc/resources/picture_layer_tiling_set.h" | |
| 10 #include "cc/resources/tile.h" | |
| 11 #include "cc/resources/tile_priority.h" | |
| 12 | |
| 13 namespace cc { | |
| 14 | |
| 15 TilingSetRasterQueueRequired::TilingSetRasterQueueRequired( | |
| 16 PictureLayerTilingSet* tiling_set, | |
| 17 RasterTilePriorityQueue::Type type) | |
| 18 : type_(type) { | |
| 19 DCHECK_NE(static_cast<int>(type), | |
| 20 static_cast<int>(RasterTilePriorityQueue::Type::ALL)); | |
| 21 | |
| 22 // Any type of required tile would only come from a high resolution tiling. | |
| 23 // The functions that determine this value is | |
| 24 // PictureLayerTiling::IsTileRequiredFor*, which all return false if the | |
| 25 // resolution is not HIGH_RESOLUTION. | |
| 26 PictureLayerTiling* tiling = | |
| 27 tiling_set->FindTilingWithResolution(HIGH_RESOLUTION); | |
| 28 // If we don't have a high res tiling, then this queue will yield no tiles. | |
| 29 // See PictureLayerImpl::CanHaveTilings for examples of when a HIGH_RESOLUTION | |
| 30 // tiling would not be generated. | |
| 31 if (!tiling) | |
| 32 return; | |
| 33 | |
| 34 iterator_ = TilingIterator(tiling, &tiling->tiling_data_); | |
| 35 while (!iterator_.done() && !IsTileRequired(*iterator_)) | |
| 36 ++iterator_; | |
| 37 } | |
| 38 | |
| 39 TilingSetRasterQueueRequired::~TilingSetRasterQueueRequired() { | |
| 40 } | |
| 41 | |
| 42 bool TilingSetRasterQueueRequired::IsEmpty() const { | |
| 43 return iterator_.done(); | |
| 44 } | |
| 45 | |
| 46 void TilingSetRasterQueueRequired::Pop() { | |
| 47 DCHECK(!IsEmpty()); | |
| 48 ++iterator_; | |
| 49 while (!iterator_.done() && !IsTileRequired(*iterator_)) | |
| 50 ++iterator_; | |
| 51 } | |
| 52 | |
| 53 Tile* TilingSetRasterQueueRequired::Top() { | |
| 54 DCHECK(!IsEmpty()); | |
| 55 return *iterator_; | |
| 56 } | |
| 57 | |
| 58 const Tile* TilingSetRasterQueueRequired::Top() const { | |
| 59 DCHECK(!IsEmpty()); | |
| 60 return *iterator_; | |
| 61 } | |
| 62 | |
| 63 bool TilingSetRasterQueueRequired::IsTileRequired(const Tile* tile) const { | |
| 64 return (type_ == RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION && | |
| 65 tile->required_for_activation()) || | |
| 66 (type_ == RasterTilePriorityQueue::Type::REQUIRED_FOR_DRAW && | |
| 67 tile->required_for_draw()); | |
| 68 } | |
| 69 | |
| 70 TilingSetRasterQueueRequired::TilingIterator::TilingIterator() | |
| 71 : tiling_(nullptr), current_tile_(nullptr) { | |
| 72 } | |
| 73 | |
| 74 TilingSetRasterQueueRequired::TilingIterator::TilingIterator( | |
| 75 PictureLayerTiling* tiling, | |
| 76 TilingData* tiling_data) | |
| 77 : tiling_(tiling), tiling_data_(tiling_data), current_tile_(nullptr) { | |
| 78 if (!tiling_->has_visible_rect_tiles()) { | |
| 79 // Verify that if we would create the iterator, then it would be empty (ie | |
| 80 // it would return false when evaluated as a bool). | |
| 81 DCHECK(!TilingData::Iterator(tiling_data_, tiling->current_visible_rect(), | |
| 82 false)); | |
| 83 return; | |
| 84 } | |
| 85 | |
| 86 visible_iterator_ = | |
| 87 TilingData::Iterator(tiling_data_, tiling_->current_visible_rect(), | |
| 88 false /* include_borders */); | |
| 89 if (!visible_iterator_) | |
| 90 return; | |
| 91 | |
| 92 current_tile_ = | |
| 93 tiling_->TileAt(visible_iterator_.index_x(), visible_iterator_.index_y()); | |
| 94 | |
| 95 // If this is a valid tile, return it. Note that we have to use a tiling check | |
| 96 // for occlusion, since the tile's internal state has not yet been updated. | |
| 97 if (current_tile_ && current_tile_->NeedsRaster() && | |
| 98 !tiling_->IsTileOccluded(current_tile_)) { | |
| 99 tiling_->UpdateTileAndTwinPriority(current_tile_); | |
| 100 return; | |
| 101 } | |
| 102 ++(*this); | |
| 103 } | |
| 104 | |
| 105 TilingSetRasterQueueRequired::TilingIterator::~TilingIterator() { | |
| 106 } | |
| 107 | |
| 108 TilingSetRasterQueueRequired::TilingIterator& | |
| 109 TilingSetRasterQueueRequired::TilingIterator:: | |
| 110 operator++() { | |
| 111 while (true) { | |
| 112 ++visible_iterator_; | |
| 113 if (!visible_iterator_) { | |
| 114 current_tile_ = nullptr; | |
| 115 return *this; | |
| 116 } | |
| 117 std::pair<int, int> next_index = visible_iterator_.index(); | |
| 118 current_tile_ = tiling_->TileAt(next_index.first, next_index.second); | |
| 119 // If the tile doesn't exist or if it exists but doesn't need raster work, | |
| 120 // we can move on to the next tile. | |
| 121 if (!current_tile_ || !current_tile_->NeedsRaster()) | |
| 122 continue; | |
| 123 | |
| 124 // If the tile is occluded, we also can skip it. Note that we use the tiling | |
| 125 // check for occlusion, since tile's internal state has not yet been updated | |
| 126 // (by UpdateTileAndTwinPriority). The tiling check does not rely on tile's | |
| 127 // internal state (it is, in fact, used to determine the tile's state). | |
| 128 if (tiling_->IsTileOccluded(current_tile_)) | |
| 129 continue; | |
| 130 | |
| 131 // If we get here, that means we have a valid tile that needs raster and is | |
| 132 // in the NOW bin, which means that it can be required. | |
| 133 break; | |
| 134 } | |
| 135 | |
| 136 if (current_tile_) | |
| 137 tiling_->UpdateTileAndTwinPriority(current_tile_); | |
| 138 return *this; | |
| 139 } | |
| 140 | |
| 141 } // namespace cc | |
| OLD | NEW |