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 #include "cc/resources/raster_tile_priority_queue.h" | 5 #include "cc/resources/raster_tile_priority_queue.h" |
6 | 6 |
7 namespace cc { | 7 namespace cc { |
8 | 8 |
9 namespace { | 9 namespace { |
10 | 10 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 return b_priority.resolution == LOW_RESOLUTION; | 56 return b_priority.resolution == LOW_RESOLUTION; |
57 return b_priority.resolution == HIGH_RESOLUTION; | 57 return b_priority.resolution == HIGH_RESOLUTION; |
58 } | 58 } |
59 return b_priority.IsHigherPriorityThan(a_priority); | 59 return b_priority.IsHigherPriorityThan(a_priority); |
60 } | 60 } |
61 | 61 |
62 private: | 62 private: |
63 TreePriority tree_priority_; | 63 TreePriority tree_priority_; |
64 }; | 64 }; |
65 | 65 |
66 const WhichTree kHigherPriorityTreeForSmoothnessTakesPriority = ACTIVE_TREE; | |
67 const WhichTree kHigherPriorityTreeForNewContentTakesPriority = PENDING_TREE; | |
68 | |
69 WhichTree HigherPriorityTree(TreePriority tree_priority, | |
70 const Tile* active_tile, | |
71 const Tile* pending_tile) { | |
reveman
2014/09/10 18:53:35
I don't understand why this can't include the tree
USE eero AT chromium.org
2014/09/11 06:55:24
If HigherPriorityTree included the tree_priority s
reveman
2014/09/11 12:59:53
Ok, thanks for explaining. Maybe the code in your
| |
72 // This function does not handle simple tree priorities for which constants | |
73 // can be used. | |
74 DCHECK(tree_priority == SAME_PRIORITY_FOR_BOTH_TREES); | |
75 | |
76 const TilePriority& active_priority = active_tile->priority(ACTIVE_TREE); | |
77 const TilePriority& pending_priority = pending_tile->priority(PENDING_TREE); | |
78 | |
79 if (active_priority.IsHigherPriorityThan(pending_priority)) | |
80 return ACTIVE_TREE; | |
81 return PENDING_TREE; | |
82 } | |
83 | |
84 WhichTree PrimaryTreeForSharedTile(TreePriority tree_priority, | |
85 const Tile* shared_tile) { | |
86 switch (tree_priority) { | |
87 case SMOOTHNESS_TAKES_PRIORITY: | |
88 return kHigherPriorityTreeForSmoothnessTakesPriority; | |
89 case NEW_CONTENT_TAKES_PRIORITY: | |
90 return kHigherPriorityTreeForNewContentTakesPriority; | |
91 case SAME_PRIORITY_FOR_BOTH_TREES: | |
92 return HigherPriorityTree(tree_priority, shared_tile, shared_tile); | |
93 default: | |
94 NOTREACHED(); | |
95 return ACTIVE_TREE; | |
96 } | |
97 } | |
98 | |
66 } // namespace | 99 } // namespace |
67 | 100 |
68 RasterTilePriorityQueue::RasterTilePriorityQueue() { | 101 RasterTilePriorityQueue::RasterTilePriorityQueue() { |
69 } | 102 } |
70 | 103 |
71 RasterTilePriorityQueue::~RasterTilePriorityQueue() { | 104 RasterTilePriorityQueue::~RasterTilePriorityQueue() { |
72 } | 105 } |
73 | 106 |
74 void RasterTilePriorityQueue::Build( | 107 void RasterTilePriorityQueue::Build( |
75 const std::vector<PictureLayerImpl::Pair>& paired_layers, | 108 const std::vector<PictureLayerImpl::Pair>& paired_layers, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 TreePriority tree_priority) | 148 TreePriority tree_priority) |
116 : active_iterator(layer_pair.active | 149 : active_iterator(layer_pair.active |
117 ? PictureLayerImpl::LayerRasterTileIterator( | 150 ? PictureLayerImpl::LayerRasterTileIterator( |
118 layer_pair.active, | 151 layer_pair.active, |
119 tree_priority == SMOOTHNESS_TAKES_PRIORITY) | 152 tree_priority == SMOOTHNESS_TAKES_PRIORITY) |
120 : PictureLayerImpl::LayerRasterTileIterator()), | 153 : PictureLayerImpl::LayerRasterTileIterator()), |
121 pending_iterator(layer_pair.pending | 154 pending_iterator(layer_pair.pending |
122 ? PictureLayerImpl::LayerRasterTileIterator( | 155 ? PictureLayerImpl::LayerRasterTileIterator( |
123 layer_pair.pending, | 156 layer_pair.pending, |
124 tree_priority == SMOOTHNESS_TAKES_PRIORITY) | 157 tree_priority == SMOOTHNESS_TAKES_PRIORITY) |
125 : PictureLayerImpl::LayerRasterTileIterator()) { | 158 : PictureLayerImpl::LayerRasterTileIterator()), |
159 has_both_layers(layer_pair.active && layer_pair.pending) { | |
126 } | 160 } |
127 | 161 |
128 RasterTilePriorityQueue::PairedPictureLayerQueue::~PairedPictureLayerQueue() { | 162 RasterTilePriorityQueue::PairedPictureLayerQueue::~PairedPictureLayerQueue() { |
129 } | 163 } |
130 | 164 |
131 bool RasterTilePriorityQueue::PairedPictureLayerQueue::IsEmpty() const { | 165 bool RasterTilePriorityQueue::PairedPictureLayerQueue::IsEmpty() const { |
132 return !active_iterator && !pending_iterator; | 166 return !active_iterator && !pending_iterator; |
133 } | 167 } |
134 | 168 |
135 Tile* RasterTilePriorityQueue::PairedPictureLayerQueue::Top( | 169 Tile* RasterTilePriorityQueue::PairedPictureLayerQueue::Top( |
136 TreePriority tree_priority) { | 170 TreePriority tree_priority) { |
137 DCHECK(!IsEmpty()); | 171 DCHECK(!IsEmpty()); |
138 | 172 |
139 WhichTree next_tree = NextTileIteratorTree(tree_priority); | 173 WhichTree next_tree = NextTileIteratorTree(tree_priority); |
140 PictureLayerImpl::LayerRasterTileIterator* next_iterator = | 174 PictureLayerImpl::LayerRasterTileIterator* next_iterator = |
141 next_tree == ACTIVE_TREE ? &active_iterator : &pending_iterator; | 175 next_tree == ACTIVE_TREE ? &active_iterator : &pending_iterator; |
142 DCHECK(*next_iterator); | 176 DCHECK(*next_iterator); |
143 Tile* tile = **next_iterator; | 177 Tile* tile = **next_iterator; |
144 DCHECK(std::find(returned_shared_tiles.begin(), | 178 DCHECK(returned_tiles_for_debug.find(tile) == returned_tiles_for_debug.end()); |
145 returned_shared_tiles.end(), | |
146 tile) == returned_shared_tiles.end()); | |
147 return tile; | 179 return tile; |
148 } | 180 } |
149 | 181 |
150 void RasterTilePriorityQueue::PairedPictureLayerQueue::Pop( | 182 void RasterTilePriorityQueue::PairedPictureLayerQueue::Pop( |
151 TreePriority tree_priority) { | 183 TreePriority tree_priority) { |
152 DCHECK(!IsEmpty()); | 184 DCHECK(!IsEmpty()); |
153 | 185 |
154 WhichTree next_tree = NextTileIteratorTree(tree_priority); | 186 WhichTree next_tree = NextTileIteratorTree(tree_priority); |
155 PictureLayerImpl::LayerRasterTileIterator* next_iterator = | 187 PictureLayerImpl::LayerRasterTileIterator* next_iterator = |
156 next_tree == ACTIVE_TREE ? &active_iterator : &pending_iterator; | 188 next_tree == ACTIVE_TREE ? &active_iterator : &pending_iterator; |
157 DCHECK(*next_iterator); | 189 DCHECK(*next_iterator); |
158 returned_shared_tiles.push_back(**next_iterator); | 190 DCHECK(returned_tiles_for_debug.insert(**next_iterator).second); |
159 ++(*next_iterator); | 191 ++(*next_iterator); |
USE eero AT chromium.org
2014/09/11 06:55:24
Here the next_iterator is advanced, which change t
reveman
2014/09/11 12:59:53
you'd have to move this into the loop.
| |
160 | 192 |
161 if (IsEmpty()) | 193 if (has_both_layers) { |
reveman
2014/09/10 18:53:35
Not sure it's worth DCHECKing when this is not the
| |
162 return; | 194 // We have both layers (active and pending) thus we can encounter shared |
195 // tiles twice (from the active iterator and from the pending iterator). | |
196 for (; !IsEmpty(); ++(*next_iterator)) { | |
197 next_tree = NextTileIteratorTree(tree_priority); | |
198 next_iterator = | |
199 next_tree == ACTIVE_TREE ? &active_iterator : &pending_iterator; | |
reveman
2014/09/10 18:53:35
I thinks it's a bit ugly that we compute these val
USE eero AT chromium.org
2014/09/11 06:55:25
We do not compute the same values again.
Instead o
reveman
2014/09/11 12:59:53
I see now that your code is consistent with the ol
| |
163 | 200 |
164 next_tree = NextTileIteratorTree(tree_priority); | 201 // Accept the tile if it is not shared or if it is shared and the next |
165 next_iterator = | 202 // tree is the primary one corresponding the iterator (active or pending) |
166 next_tree == ACTIVE_TREE ? &active_iterator : &pending_iterator; | 203 // which usually (but due to spiral iterators not always) returns the |
167 while (std::find(returned_shared_tiles.begin(), | 204 // shared tile first. |
168 returned_shared_tiles.end(), | 205 const Tile* tile = **next_iterator; |
169 **next_iterator) != returned_shared_tiles.end()) { | 206 if (!tile->is_shared() || |
170 ++(*next_iterator); | 207 next_tree == PrimaryTreeForSharedTile(tree_priority, tile)) |
171 if (IsEmpty()) | 208 break; |
172 break; | 209 } |
173 next_tree = NextTileIteratorTree(tree_priority); | |
174 next_iterator = | |
175 next_tree == ACTIVE_TREE ? &active_iterator : &pending_iterator; | |
176 } | 210 } |
211 | |
212 // If no empty, use Top to do DCHECK the next iterator. | |
213 DCHECK(IsEmpty() || Top(tree_priority)); | |
177 } | 214 } |
178 | 215 |
179 WhichTree | 216 WhichTree |
180 RasterTilePriorityQueue::PairedPictureLayerQueue::NextTileIteratorTree( | 217 RasterTilePriorityQueue::PairedPictureLayerQueue::NextTileIteratorTree( |
181 TreePriority tree_priority) const { | 218 TreePriority tree_priority) const { |
182 DCHECK(!IsEmpty()); | 219 DCHECK(!IsEmpty()); |
183 | 220 |
184 // If we only have one iterator with tiles, return it. | 221 // If we only have one iterator with tiles, return it. |
185 if (!active_iterator) | 222 if (!active_iterator) |
186 return PENDING_TREE; | 223 return PENDING_TREE; |
187 if (!pending_iterator) | 224 if (!pending_iterator) |
188 return ACTIVE_TREE; | 225 return ACTIVE_TREE; |
189 | 226 |
190 // Now both iterators have tiles, so we have to decide based on tree priority. | 227 // Now both iterators have tiles, so we have to decide based on tree priority. |
191 switch (tree_priority) { | 228 switch (tree_priority) { |
192 case SMOOTHNESS_TAKES_PRIORITY: | 229 case SMOOTHNESS_TAKES_PRIORITY: |
193 return ACTIVE_TREE; | 230 return kHigherPriorityTreeForSmoothnessTakesPriority; |
194 case NEW_CONTENT_TAKES_PRIORITY: | 231 case NEW_CONTENT_TAKES_PRIORITY: |
195 return PENDING_TREE; | 232 return kHigherPriorityTreeForNewContentTakesPriority; |
196 case SAME_PRIORITY_FOR_BOTH_TREES: { | 233 case SAME_PRIORITY_FOR_BOTH_TREES: |
197 const Tile* active_tile = *active_iterator; | 234 return HigherPriorityTree( |
198 const Tile* pending_tile = *pending_iterator; | 235 tree_priority, *active_iterator, *pending_iterator); |
199 if (active_tile == pending_tile) | |
200 return ACTIVE_TREE; | |
201 | |
202 const TilePriority& active_priority = active_tile->priority(ACTIVE_TREE); | |
203 const TilePriority& pending_priority = | |
204 pending_tile->priority(PENDING_TREE); | |
205 | |
206 if (active_priority.IsHigherPriorityThan(pending_priority)) | |
207 return ACTIVE_TREE; | |
208 return PENDING_TREE; | |
209 } | |
210 default: | 236 default: |
211 NOTREACHED(); | 237 NOTREACHED(); |
238 return ACTIVE_TREE; | |
212 } | 239 } |
213 | |
214 NOTREACHED(); | |
215 // Keep the compiler happy. | |
216 return ACTIVE_TREE; | |
217 } | 240 } |
218 | 241 |
219 } // namespace cc | 242 } // namespace cc |
OLD | NEW |