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_eviction_queue.h" | |
6 | |
7 namespace cc { | |
8 | |
9 TilingSetEvictionQueue::TilingSetEvictionQueue( | |
10 PictureLayerTilingSet* tiling_set, | |
11 TreePriority tree_priority) | |
12 : tiling_set_(tiling_set), | |
13 tree_priority_(tree_priority), | |
14 current_category_(PictureLayerTiling::EVENTUALLY), | |
15 current_tiling_index_(0u), | |
16 current_tiling_range_type_(PictureLayerTilingSet::HIGHER_THAN_HIGH_RES), | |
17 current_eviction_tiles_(nullptr), | |
18 current_eviction_tiles_index_(0u), | |
19 current_tile_(nullptr) { | |
20 DCHECK(tiling_set_); | |
21 | |
22 // Early out if the layer has no tilings. | |
23 if (!tiling_set_->num_tilings()) | |
24 return; | |
25 | |
26 current_tiling_index_ = CurrentTilingRange().start - 1u; | |
27 AdvanceToNextValidTiling(); | |
28 } | |
29 | |
30 TilingSetEvictionQueue::~TilingSetEvictionQueue() { | |
31 } | |
32 | |
33 bool TilingSetEvictionQueue::IsEmpty() const { | |
34 return !current_tile_; | |
35 } | |
36 | |
37 void TilingSetEvictionQueue::Pop() { | |
38 DCHECK(!IsEmpty()); | |
39 | |
40 current_tile_ = PopEvictionTile(); | |
41 if (!current_tile_) | |
42 AdvanceToNextValidTiling(); | |
43 } | |
44 | |
45 Tile* TilingSetEvictionQueue::Top() { | |
46 DCHECK(!IsEmpty()); | |
47 return current_tile_; | |
48 } | |
49 | |
50 const Tile* TilingSetEvictionQueue::Top() const { | |
51 DCHECK(!IsEmpty()); | |
52 return current_tile_; | |
53 } | |
54 | |
55 bool TilingSetEvictionQueue::AdvanceToNextCategory() { | |
56 switch (current_category_) { | |
57 case PictureLayerTiling::EVENTUALLY: | |
58 current_category_ = | |
59 PictureLayerTiling::EVENTUALLY_AND_REQUIRED_FOR_ACTIVATION; | |
60 return true; | |
61 case PictureLayerTiling::EVENTUALLY_AND_REQUIRED_FOR_ACTIVATION: | |
62 current_category_ = PictureLayerTiling::SOON; | |
63 return true; | |
64 case PictureLayerTiling::SOON: | |
65 current_category_ = PictureLayerTiling::SOON_AND_REQUIRED_FOR_ACTIVATION; | |
66 return true; | |
67 case PictureLayerTiling::SOON_AND_REQUIRED_FOR_ACTIVATION: | |
68 current_category_ = PictureLayerTiling::NOW; | |
69 return true; | |
70 case PictureLayerTiling::NOW: | |
71 current_category_ = PictureLayerTiling::NOW_AND_REQUIRED_FOR_ACTIVATION; | |
72 return true; | |
73 case PictureLayerTiling::NOW_AND_REQUIRED_FOR_ACTIVATION: | |
74 return false; | |
75 } | |
76 NOTREACHED(); | |
77 return false; | |
78 } | |
79 | |
80 bool TilingSetEvictionQueue::AdvanceToNextTilingRangeType() { | |
81 switch (current_tiling_range_type_) { | |
82 case PictureLayerTilingSet::HIGHER_THAN_HIGH_RES: | |
83 current_tiling_range_type_ = PictureLayerTilingSet::LOWER_THAN_LOW_RES; | |
84 return true; | |
85 case PictureLayerTilingSet::LOWER_THAN_LOW_RES: | |
86 current_tiling_range_type_ = | |
87 PictureLayerTilingSet::BETWEEN_HIGH_AND_LOW_RES; | |
88 return true; | |
89 case PictureLayerTilingSet::BETWEEN_HIGH_AND_LOW_RES: | |
90 current_tiling_range_type_ = PictureLayerTilingSet::LOW_RES; | |
91 return true; | |
92 case PictureLayerTilingSet::LOW_RES: | |
93 current_tiling_range_type_ = PictureLayerTilingSet::HIGH_RES; | |
94 return true; | |
95 case PictureLayerTilingSet::HIGH_RES: | |
96 if (!AdvanceToNextCategory()) | |
97 return false; | |
98 | |
99 current_tiling_range_type_ = PictureLayerTilingSet::HIGHER_THAN_HIGH_RES; | |
100 return true; | |
101 } | |
102 NOTREACHED(); | |
103 return false; | |
104 } | |
105 | |
106 bool TilingSetEvictionQueue::AdvanceToNextValidTiling() { | |
107 DCHECK(!current_tile_); | |
108 DCHECK_NE(current_tiling_index_, CurrentTilingRange().end); | |
109 | |
110 do { | |
111 ++current_tiling_index_; | |
112 while (current_tiling_index_ == CurrentTilingRange().end) { | |
113 if (!AdvanceToNextTilingRangeType()) | |
114 return false; | |
115 current_tiling_index_ = CurrentTilingRange().start; | |
116 } | |
117 | |
118 PictureLayerTiling* tiling = tiling_set_->tiling_at(CurrentTilingIndex()); | |
119 current_eviction_tiles_ = | |
120 tiling->GetEvictionTiles(tree_priority_, current_category_); | |
121 current_eviction_tiles_index_ = 0u; | |
122 current_tile_ = PopEvictionTile(); | |
123 } while (!current_tile_); | |
124 | |
125 return true; | |
126 } | |
127 | |
128 PictureLayerTilingSet::TilingRange | |
129 TilingSetEvictionQueue::CurrentTilingRange() const { | |
130 return tiling_set_->GetTilingRange(current_tiling_range_type_); | |
131 } | |
132 | |
133 size_t TilingSetEvictionQueue::CurrentTilingIndex() const { | |
134 DCHECK_NE(current_tiling_index_, CurrentTilingRange().end); | |
135 switch (current_tiling_range_type_) { | |
136 case PictureLayerTilingSet::HIGHER_THAN_HIGH_RES: | |
137 case PictureLayerTilingSet::LOW_RES: | |
138 case PictureLayerTilingSet::HIGH_RES: | |
139 return current_tiling_index_; | |
140 // Tilings in the following ranges are accessed in reverse order. | |
141 case PictureLayerTilingSet::BETWEEN_HIGH_AND_LOW_RES: | |
142 case PictureLayerTilingSet::LOWER_THAN_LOW_RES: { | |
143 PictureLayerTilingSet::TilingRange tiling_range = CurrentTilingRange(); | |
144 size_t current_tiling_range_offset = | |
145 current_tiling_index_ - tiling_range.start; | |
146 return tiling_range.end - 1 - current_tiling_range_offset; | |
147 } | |
148 } | |
149 NOTREACHED(); | |
150 return 0; | |
151 } | |
152 | |
153 Tile* TilingSetEvictionQueue::PopEvictionTile() { | |
vmpstr
2014/11/25 17:37:05
I think it would be a bit cleaner if we separate t
USE eero AT chromium.org
2014/11/26 14:20:46
I replaced PopEvictionTile with AdvanceToNextEvict
| |
154 while (current_eviction_tiles_index_ != current_eviction_tiles_->size()) { | |
vmpstr
2014/11/25 17:37:04
nit: <
USE eero AT chromium.org
2014/11/26 14:20:46
Done.
| |
155 Tile* tile = (*current_eviction_tiles_)[current_eviction_tiles_index_]; | |
156 ++current_eviction_tiles_index_; | |
157 if (tile->HasResources()) | |
158 return tile; | |
159 } | |
160 | |
161 return nullptr; | |
162 } | |
163 | |
164 } | |
OLD | NEW |