1 // Copyright 2022 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CC_TILES_TILES_WITH_RESOURCE_ITERATOR_H_
6 #define CC_TILES_TILES_WITH_RESOURCE_ITERATOR_H_
11 #include "base/memory/raw_ptr.h"
12 #include "cc/cc_export.h"
13 #include "cc/tiles/picture_layer_tiling.h"
14 #include "cc/tiles/prioritized_tile.h"
15 #include "third_party/abseil-cpp/absl/types/optional.h"
19 class PictureLayerImpl;
20 class PictureLayerTilingSet;
22 // Iterates over all tiles that have a resource. The order of iteration is not
24 class CC_EXPORT TilesWithResourceIterator {
26 TilesWithResourceIterator(
27 const std::vector<PictureLayerImpl*>* picture_layers,
28 const std::vector<PictureLayerImpl*>* secondary_picture_layers);
29 TilesWithResourceIterator(const TilesWithResourceIterator&) = delete;
30 TilesWithResourceIterator& operator=(const TilesWithResourceIterator&) =
32 ~TilesWithResourceIterator();
38 // Returns the PrioritizedTile for the current tile, null if at the end.
39 PrioritizedTile* GetCurrentAsPrioritizedTile();
41 // Returns true if the current tile is occluded, false if at the end.
42 bool IsCurrentTileOccluded();
45 // The following functions start iterating at the *current* location.
46 // Each function returns true if a match is found, false indicates there
47 // are no more items to iterate through.
48 bool FindNextInPictureLayers();
49 bool FindNextInActiveLayers();
50 bool FindNextInPictureLayerTilingSet();
51 bool FindNextInTileIterator();
53 PictureLayerTilingSet* CurrentPictureLayerTilingSet();
54 PictureLayerTiling* CurrentPictureLayerTiling();
56 // Iteration occurs over this vector first.
57 const raw_ptr<const std::vector<PictureLayerImpl*>> picture_layers_;
59 // The secondary set of layers to iterate through, may be null.
60 const raw_ptr<const std::vector<PictureLayerImpl*>> secondary_picture_layers_;
62 // Indicates whether `active_layers_` is referencing `picture_layers_` or
63 // `secondary_picture_layers_`.
64 bool is_active_layers_secondary_layers_ = false;
66 raw_ptr<const std::vector<PictureLayerImpl*>> active_layers_;
68 // Index into `active_layers_` the current tile comes from.
69 size_t current_picture_layer_index_ = 0;
71 // Index into the current PictureLayerTilingSet the current tile comes from.
72 size_t current_picture_layer_tiling_index_ = 0;
74 // Iterates over the tiles from the current PictureLayerTiling. If this is
75 // not set, the end has been reached.
76 absl::optional<PictureLayerTiling::TileIterator> tile_iterator_;
78 // Set of tiles that have been visited. Used to ensure the same tile isn't
79 // visited more than once.
80 std::set<Tile*> visited_;
82 // Created when GetCurrentAsPrioritizedTile() is called.
83 absl::optional<PrioritizedTile> prioritized_tile_;
88 #endif // CC_TILES_TILES_WITH_RESOURCE_ITERATOR_H_