OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CC_RESOURCES_TILING_SET_EVICTION_QUEUE_H_ | 5 #ifndef CC_RESOURCES_TILING_SET_EVICTION_QUEUE_H_ |
6 #define CC_RESOURCES_TILING_SET_EVICTION_QUEUE_H_ | 6 #define CC_RESOURCES_TILING_SET_EVICTION_QUEUE_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "cc/base/cc_export.h" | 10 #include "cc/base/cc_export.h" |
11 #include "cc/resources/picture_layer_tiling_set.h" | 11 #include "cc/resources/picture_layer_tiling_set.h" |
12 | 12 |
13 namespace cc { | 13 namespace cc { |
14 | 14 |
15 // This eviction queue returned tiles from all tilings in a tiling set in | 15 // This eviction queue returned tiles from all tilings in a tiling set in |
16 // the following order: | 16 // the order in which the tiles should be evicted. It can be thought of as the |
17 // 1) Eventually rect tiles (EVENTUALLY tiles). | 17 // following: |
18 // 1) Eventually rect tiles not required for activation from each tiling in | 18 // for all phases: |
19 // the tiling set, in turn, in the following order: | 19 // for all ordered tilings: |
20 // 1) the first higher than high res tiling, the second one and so on | 20 // yield the next tile for the given phase from the given tiling |
21 // 2) the first lower than low res tiling, the second one and so on | |
22 // 3) the first between high and low res tiling, the second one and so on | |
23 // 4) low res tiling | |
24 // 5) high res tiling | |
25 // 2) Eventually rect tiles required for activation from the tiling with | |
26 // required for activation tiles. In the case of a pending tree tiling | |
27 // set that is the high res tiling. In the case of an active tree tiling | |
28 // set that is a tiling whose twin tiling is a pending tree high res | |
29 // tiling. | |
30 // 2) Soon border rect and skewport rect tiles (whose priority bin is SOON | |
31 // unless the max tile priority bin is lowered by PictureLayerTilingClient). | |
32 // 1) Soon border rect and skewport rect tiles not required for activation | |
33 // from each tiling in the tiling set. | |
34 // * Tilings are iterated in the same order as in the case of eventually | |
35 // rect tiles not required for activation. | |
36 // * For each tiling, first soon border rect tiles and then skewport | |
37 // rect tiles are returned. | |
38 // 2) Soon border rect and skewport rect tiles required for activation from | |
39 // the tiling with required for activation tiles. | |
40 // * First soon border rect tiles and then skewport rect tiles are | |
41 // returned. | |
42 // 3) Visible rect tiles (whose priority bin is NOW unless the max tile | |
43 // priority bin is lowered by PictureLayerTilingClient). | |
44 // 1) Visible rect tiles not required for activation from each tiling in | |
45 // the tiling set. | |
46 // * Tilings are iterated in the same order as in the case of eventually | |
47 // rect tiles not required for activation. | |
48 // * For each tiling, first occluded tiles and then unoccluded tiles | |
49 // are returned. | |
50 // 2) Visible rect tiles required for activation from the tiling with | |
51 // required for activation tiles. | |
52 // * First occluded tiles and then unoccluded tiles are returned. | |
53 // If the max tile priority bin is lowered by PictureLayerTilingClient, | |
54 // occlusion is not taken into account as occlusion is meaningful only for | |
55 // NOW tiles. | |
56 // | 21 // |
57 // Within each tiling and tile priority rect, tiles are returned in reverse | 22 // Phases are the following (in order in which they are processed): |
58 // spiral order i.e. in (mostly) decreasing distance-to-visible order. | 23 // EVENTUALLY_RECT - Tiles in the eventually region of the tiling. |
| 24 // SOON_BORDER_RECT - Tiles in the prepainting skirt of the tiling. |
| 25 // SKEWPORT_RECT - Tiles in the skewport of the tiling. |
| 26 // VISIBLE_RECT_OCCLUDED - Occluded, not required for activation, visible tiles. |
| 27 // VISIBLE_RECT_UNOCCLUDED - Unoccluded, not required for activation, visible |
| 28 // tiles. |
| 29 // VISIBLE_RECT_REQUIRED_FOR_ACTIVATION_OCCLUDED - Occluded, but required for |
| 30 // activation, visible tiles. This can happen when an active tree tile is |
| 31 // occluded, but is not occluded on the pending tree (and is required for |
| 32 // activation). |
| 33 // VISIBLE_RECT_REQUIRED_FOR_ACTIVATION_UNOCCLUDED - Unoccluded, required for |
| 34 // activation, tiles. |
59 // | 35 // |
60 // If the skip_shared_out_of_order_tiles value passed to the constructor is | 36 // The tilings are ordered as follows. Suppose we have tilings with the scales |
61 // true (like it should be when there is a twin layer with a twin tiling set), | 37 // below: |
62 // eviction queue does not return shared which are out of order because their | 38 // 2.0 1.5 1.0(HR) 0.8 0.5 0.25(LR) 0.2 0.1 |
63 // priority for tree priority is lowered or raised by a twin layer. | 39 // With HR referring to high res tiling and LR referring to low res tiling, |
64 // This happens for a tile specific lower priority tree eviction queue | 40 // then tilings are processed in this order: |
65 // (because eviction priority the combined priority). | 41 // 2.0 1.5 0.1 0.2 0.5 0.8 0.25(LR) 1.0(HR). |
66 // Those skipped shared out of order tiles are when returned only by the twin | 42 // |
67 // eviction queue. | 43 // To put it differently: |
| 44 // 1. Process the highest scale tiling down to, but not including, high res |
| 45 // tiling. |
| 46 // 2. Process the lowest scale tiling up to, but not including, the low res |
| 47 // tiling. In cases without a low res tiling, this is an empty set. |
| 48 // 3. Process low res tiling up to high res tiling, including neither high |
| 49 // nor low res tilings. In cases without a low res tiling, this set |
| 50 // includes all tilings with a lower scale than the high res tiling. |
| 51 // 4. Process the low res tiling. |
| 52 // 5. Process the high res tiling. |
| 53 // |
| 54 // Additional notes: |
| 55 // Since eventually the tiles are considered to have the priority which is the |
| 56 // higher of the two trees, we might visit a tile that should actually be |
| 57 // returned by its twin. In those situations, the tiles are not returned. That |
| 58 // is, since the twin has higher priority, it should return it when it gets to |
| 59 // it. This ensures that we don't block raster because we've returned a tile |
| 60 // with low priority on one tree, but high combined priority. |
68 class CC_EXPORT TilingSetEvictionQueue { | 61 class CC_EXPORT TilingSetEvictionQueue { |
69 public: | 62 public: |
70 TilingSetEvictionQueue(PictureLayerTilingSet* tiling_set, | 63 TilingSetEvictionQueue(PictureLayerTilingSet* tiling_set, |
71 bool skip_shared_out_of_order_tiles); | 64 bool skip_shared_out_of_order_tiles); |
72 ~TilingSetEvictionQueue(); | 65 ~TilingSetEvictionQueue(); |
73 | 66 |
74 Tile* Top(); | 67 Tile* Top(); |
75 const Tile* Top() const; | 68 const Tile* Top() const; |
76 void Pop(); | 69 void Pop(); |
77 bool IsEmpty() const; | 70 bool IsEmpty() const; |
78 | 71 |
79 private: | 72 private: |
80 bool AdvanceToNextEvictionTile(); | 73 enum Phase { |
81 bool AdvanceToNextPriorityBin(); | 74 EVENTUALLY_RECT, |
82 bool AdvanceToNextTilingRangeType(); | 75 SOON_BORDER_RECT, |
83 bool AdvanceToNextValidTiling(); | 76 SKEWPORT_RECT, |
| 77 VISIBLE_RECT_OCCLUDED, |
| 78 VISIBLE_RECT_UNOCCLUDED, |
| 79 VISIBLE_RECT_REQUIRED_FOR_ACTIVATION_OCCLUDED, |
| 80 VISIBLE_RECT_REQUIRED_FOR_ACTIVATION_UNOCCLUDED |
| 81 }; |
84 | 82 |
85 PictureLayerTilingSet::TilingRange CurrentTilingRange() const; | 83 void GenerateTilingOrder(PictureLayerTilingSet* tiling_set); |
86 size_t CurrentTilingIndex() const; | |
87 | 84 |
88 PictureLayerTilingSet* tiling_set_; | 85 // Helper base class for individual region iterators. |
| 86 class EvictionRectIterator { |
| 87 public: |
| 88 EvictionRectIterator(); |
| 89 EvictionRectIterator(std::vector<PictureLayerTiling*>* tilings, |
| 90 WhichTree tree, |
| 91 bool skip_shared_out_of_order_tiles); |
| 92 |
| 93 bool done() const { return !tile_; } |
| 94 Tile* operator*() const { return tile_; } |
| 95 |
| 96 protected: |
| 97 ~EvictionRectIterator() = default; |
| 98 |
| 99 template <typename TilingIteratorType> |
| 100 bool AdvanceToNextTile(TilingIteratorType* iterator); |
| 101 template <typename TilingIteratorType> |
| 102 bool GetFirstTileAndCheckIfValid(TilingIteratorType* iterator); |
| 103 |
| 104 Tile* tile_; |
| 105 std::vector<PictureLayerTiling*>* tilings_; |
| 106 WhichTree tree_; |
| 107 bool skip_shared_out_of_order_tiles_; |
| 108 size_t tiling_index_; |
| 109 }; |
| 110 |
| 111 class VisibleTilingIterator : public EvictionRectIterator { |
| 112 public: |
| 113 VisibleTilingIterator() = default; |
| 114 VisibleTilingIterator(std::vector<PictureLayerTiling*>* tilings, |
| 115 WhichTree tree, |
| 116 bool skip_shared_out_of_order_tiles, |
| 117 bool return_occluded_tiles, |
| 118 bool return_required_for_activation_tiles); |
| 119 |
| 120 VisibleTilingIterator& operator++(); |
| 121 |
| 122 private: |
| 123 bool TileMatchesRequiredFlags(const Tile* tile) const; |
| 124 |
| 125 TilingData::Iterator iterator_; |
| 126 bool return_occluded_tiles_; |
| 127 bool return_required_for_activation_tiles_; |
| 128 }; |
| 129 |
| 130 class SkewportTilingIterator : public EvictionRectIterator { |
| 131 public: |
| 132 SkewportTilingIterator() = default; |
| 133 SkewportTilingIterator(std::vector<PictureLayerTiling*>* tilings, |
| 134 WhichTree tree, |
| 135 bool skip_shared_out_of_order_tiles); |
| 136 |
| 137 SkewportTilingIterator& operator++(); |
| 138 |
| 139 private: |
| 140 TilingData::ReverseSpiralDifferenceIterator iterator_; |
| 141 }; |
| 142 |
| 143 class SoonBorderTilingIterator : public EvictionRectIterator { |
| 144 public: |
| 145 SoonBorderTilingIterator() = default; |
| 146 SoonBorderTilingIterator(std::vector<PictureLayerTiling*>* tilings, |
| 147 WhichTree tree, |
| 148 bool skip_shared_out_of_order_tiles); |
| 149 |
| 150 SoonBorderTilingIterator& operator++(); |
| 151 |
| 152 private: |
| 153 TilingData::ReverseSpiralDifferenceIterator iterator_; |
| 154 }; |
| 155 |
| 156 class EventuallyTilingIterator : public EvictionRectIterator { |
| 157 public: |
| 158 EventuallyTilingIterator() = default; |
| 159 EventuallyTilingIterator(std::vector<PictureLayerTiling*>* tilings, |
| 160 WhichTree tree, |
| 161 bool skip_shared_out_of_order_tiles); |
| 162 |
| 163 EventuallyTilingIterator& operator++(); |
| 164 |
| 165 private: |
| 166 TilingData::ReverseSpiralDifferenceIterator iterator_; |
| 167 }; |
| 168 |
| 169 void AdvancePhase(); |
| 170 |
89 WhichTree tree_; | 171 WhichTree tree_; |
90 bool skip_shared_out_of_order_tiles_; | 172 bool skip_shared_out_of_order_tiles_; |
91 bool processing_soon_border_rect_; | 173 Phase phase_; |
92 bool processing_required_for_activation_tiles_; | 174 Tile* current_tile_; |
| 175 std::vector<PictureLayerTiling*> tilings_; |
93 | 176 |
94 TilePriority::PriorityBin current_priority_bin_; | 177 EventuallyTilingIterator eventually_iterator_; |
95 PictureLayerTiling* current_tiling_; | 178 SoonBorderTilingIterator soon_iterator_; |
96 size_t current_tiling_index_; | 179 SkewportTilingIterator skewport_iterator_; |
97 PictureLayerTilingSet::TilingRangeType current_tiling_range_type_; | 180 VisibleTilingIterator visible_iterator_; |
98 Tile* current_eviction_tile_; | |
99 | |
100 TilingData::ReverseSpiralDifferenceIterator spiral_iterator_; | |
101 TilingData::Iterator visible_iterator_; | |
102 std::vector<Tile*> unoccluded_now_tiles_; | |
103 }; | 181 }; |
104 | 182 |
105 } // namespace cc | 183 } // namespace cc |
106 | 184 |
107 #endif // CC_RESOURCES_TILING_SET_EVICTION_QUEUE_H_ | 185 #endif // CC_RESOURCES_TILING_SET_EVICTION_QUEUE_H_ |
OLD | NEW |