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_required.h"
9 #include "cc/resources/picture_layer_tiling_set.h"
10 #include "cc/resources/tile.h"
11 #include "cc/resources/tile_priority.h"
15 TilingSetRasterQueueRequired::TilingSetRasterQueueRequired(
16 PictureLayerTilingSet
* tiling_set
,
17 RasterTilePriorityQueue::Type type
)
19 DCHECK_NE(static_cast<int>(type
),
20 static_cast<int>(RasterTilePriorityQueue::Type::ALL
));
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.
34 iterator_
= TilingIterator(tiling
, &tiling
->tiling_data_
);
35 while (!iterator_
.done() && !IsTileRequired(*iterator_
))
39 TilingSetRasterQueueRequired::~TilingSetRasterQueueRequired() {
42 bool TilingSetRasterQueueRequired::IsEmpty() const {
43 return iterator_
.done();
46 void TilingSetRasterQueueRequired::Pop() {
49 while (!iterator_
.done() && !IsTileRequired(*iterator_
))
53 Tile
* TilingSetRasterQueueRequired::Top() {
58 const Tile
* TilingSetRasterQueueRequired::Top() const {
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());
70 TilingSetRasterQueueRequired::TilingIterator::TilingIterator()
71 : tiling_(nullptr), current_tile_(nullptr) {
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(),
87 TilingData::Iterator(tiling_data_
, tiling_
->current_visible_rect(),
88 false /* include_borders */);
89 if (!visible_iterator_
)
93 tiling_
->TileAt(visible_iterator_
.index_x(), visible_iterator_
.index_y());
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_
);
105 TilingSetRasterQueueRequired::TilingIterator::~TilingIterator() {
108 TilingSetRasterQueueRequired::TilingIterator
&
109 TilingSetRasterQueueRequired::TilingIterator::
113 if (!visible_iterator_
) {
114 current_tile_
= nullptr;
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())
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_
))
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.
137 tiling_
->UpdateTileAndTwinPriority(current_tile_
);