[M108 Migration][VD] Avoid pending frame counter becoming negative
[platform/framework/web/chromium-efl.git] / cc / tiles / tiles_with_resource_iterator.h
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.
4
5 #ifndef CC_TILES_TILES_WITH_RESOURCE_ITERATOR_H_
6 #define CC_TILES_TILES_WITH_RESOURCE_ITERATOR_H_
7
8 #include <set>
9 #include <vector>
10
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"
16
17 namespace cc {
18
19 class PictureLayerImpl;
20 class PictureLayerTilingSet;
21
22 // Iterates over all tiles that have a resource. The order of iteration is not
23 // defined.
24 class CC_EXPORT TilesWithResourceIterator {
25  public:
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&) =
31       delete;
32   ~TilesWithResourceIterator();
33
34   bool AtEnd() const;
35   void Next();
36   Tile* GetCurrent();
37
38   // Returns the PrioritizedTile for the current tile, null if at the end.
39   PrioritizedTile* GetCurrentAsPrioritizedTile();
40
41   // Returns true if the current tile is occluded, false if at the end.
42   bool IsCurrentTileOccluded();
43
44  private:
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();
52
53   PictureLayerTilingSet* CurrentPictureLayerTilingSet();
54   PictureLayerTiling* CurrentPictureLayerTiling();
55
56   // Iteration occurs over this vector first.
57   const raw_ptr<const std::vector<PictureLayerImpl*>> picture_layers_;
58
59   // The secondary set of layers to iterate through, may be null.
60   const raw_ptr<const std::vector<PictureLayerImpl*>> secondary_picture_layers_;
61
62   // Indicates whether `active_layers_` is referencing `picture_layers_` or
63   // `secondary_picture_layers_`.
64   bool is_active_layers_secondary_layers_ = false;
65
66   raw_ptr<const std::vector<PictureLayerImpl*>> active_layers_;
67
68   // Index into `active_layers_` the current tile comes from.
69   size_t current_picture_layer_index_ = 0;
70
71   // Index into the current PictureLayerTilingSet the current tile comes from.
72   size_t current_picture_layer_tiling_index_ = 0;
73
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_;
77
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_;
81
82   // Created when GetCurrentAsPrioritizedTile() is called.
83   absl::optional<PrioritizedTile> prioritized_tile_;
84 };
85
86 }  // namespace cc
87
88 #endif  // CC_TILES_TILES_WITH_RESOURCE_ITERATOR_H_