| 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_all.h" |
| 6 | 6 |
| 7 #include "cc/resources/tiling_set_raster_queue_all.h" | 7 #include "cc/resources/tiling_set_raster_queue_all.h" |
| 8 #include "cc/resources/tiling_set_raster_queue_required.h" | 8 #include "cc/resources/tiling_set_raster_queue_required.h" |
| 9 | 9 |
| 10 namespace cc { | 10 namespace cc { |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 class RasterOrderComparator { | 14 class RasterOrderComparator { |
| 15 public: | 15 public: |
| 16 explicit RasterOrderComparator(TreePriority tree_priority) | 16 explicit RasterOrderComparator(TreePriority tree_priority) |
| 17 : tree_priority_(tree_priority) {} | 17 : tree_priority_(tree_priority) {} |
| 18 | 18 |
| 19 bool operator()( | 19 bool operator()( |
| 20 const RasterTilePriorityQueue::PairedTilingSetQueue* a, | 20 const RasterTilePriorityQueueAll::PairedTilingSetQueue* a, |
| 21 const RasterTilePriorityQueue::PairedTilingSetQueue* b) const { | 21 const RasterTilePriorityQueueAll::PairedTilingSetQueue* b) const { |
| 22 // Note that in this function, we have to return true if and only if | 22 // Note that in this function, we have to return true if and only if |
| 23 // a is strictly lower priority than b. Note that for the sake of | 23 // a is strictly lower priority than b. Note that for the sake of |
| 24 // completeness, empty queue is considered to have lowest priority. | 24 // completeness, empty queue is considered to have lowest priority. |
| 25 if (a->IsEmpty() || b->IsEmpty()) | 25 if (a->IsEmpty() || b->IsEmpty()) |
| 26 return b->IsEmpty() < a->IsEmpty(); | 26 return b->IsEmpty() < a->IsEmpty(); |
| 27 | 27 |
| 28 WhichTree a_tree = a->NextTileIteratorTree(tree_priority_); | 28 WhichTree a_tree = a->NextTileIteratorTree(tree_priority_); |
| 29 const TilingSetRasterQueue* a_queue = | 29 const TilingSetRasterQueue* a_queue = |
| 30 a_tree == ACTIVE_TREE ? a->active_queue() : a->pending_queue(); | 30 a_tree == ACTIVE_TREE ? a->active_queue() : a->pending_queue(); |
| 31 | 31 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 return PENDING_TREE; | 122 return PENDING_TREE; |
| 123 } | 123 } |
| 124 default: | 124 default: |
| 125 NOTREACHED(); | 125 NOTREACHED(); |
| 126 return ACTIVE_TREE; | 126 return ACTIVE_TREE; |
| 127 } | 127 } |
| 128 } | 128 } |
| 129 | 129 |
| 130 scoped_ptr<TilingSetRasterQueue> CreateTilingSetRasterQueue( | 130 scoped_ptr<TilingSetRasterQueue> CreateTilingSetRasterQueue( |
| 131 PictureLayerImpl* layer, | 131 PictureLayerImpl* layer, |
| 132 TreePriority tree_priority, | 132 TreePriority tree_priority) { |
| 133 RasterTilePriorityQueue::Type type) { | |
| 134 if (!layer) | 133 if (!layer) |
| 135 return nullptr; | 134 return nullptr; |
| 136 PictureLayerTilingSet* tiling_set = layer->picture_layer_tiling_set(); | 135 PictureLayerTilingSet* tiling_set = layer->picture_layer_tiling_set(); |
| 137 if (type == RasterTilePriorityQueue::Type::ALL) { | 136 bool prioritize_low_res = tree_priority == SMOOTHNESS_TAKES_PRIORITY; |
| 138 bool prioritize_low_res = tree_priority == SMOOTHNESS_TAKES_PRIORITY; | 137 return make_scoped_ptr( |
| 139 return make_scoped_ptr( | 138 new TilingSetRasterQueueAll(tiling_set, prioritize_low_res)); |
| 140 new TilingSetRasterQueueAll(tiling_set, prioritize_low_res)); | |
| 141 } | |
| 142 return make_scoped_ptr(new TilingSetRasterQueueRequired(tiling_set, type)); | |
| 143 } | 139 } |
| 144 | 140 |
| 145 } // namespace | 141 } // namespace |
| 146 | 142 |
| 147 RasterTilePriorityQueue::RasterTilePriorityQueue() { | 143 RasterTilePriorityQueueAll::RasterTilePriorityQueueAll() { |
| 148 } | 144 } |
| 149 | 145 |
| 150 RasterTilePriorityQueue::~RasterTilePriorityQueue() { | 146 RasterTilePriorityQueueAll::~RasterTilePriorityQueueAll() { |
| 151 } | 147 } |
| 152 | 148 |
| 153 void RasterTilePriorityQueue::Build( | 149 void RasterTilePriorityQueueAll::Build( |
| 154 const std::vector<PictureLayerImpl::Pair>& paired_layers, | 150 const std::vector<PictureLayerImpl::Pair>& paired_layers, |
| 155 TreePriority tree_priority, | 151 TreePriority tree_priority) { |
| 156 Type type) { | |
| 157 tree_priority_ = tree_priority; | 152 tree_priority_ = tree_priority; |
| 158 for (std::vector<PictureLayerImpl::Pair>::const_iterator it = | 153 for (std::vector<PictureLayerImpl::Pair>::const_iterator it = |
| 159 paired_layers.begin(); | 154 paired_layers.begin(); |
| 160 it != paired_layers.end(); | 155 it != paired_layers.end(); ++it) { |
| 161 ++it) { | |
| 162 paired_queues_.push_back( | 156 paired_queues_.push_back( |
| 163 make_scoped_ptr(new PairedTilingSetQueue(*it, tree_priority_, type))); | 157 make_scoped_ptr(new PairedTilingSetQueue(*it, tree_priority_))); |
| 164 } | 158 } |
| 165 paired_queues_.make_heap(RasterOrderComparator(tree_priority_)); | 159 paired_queues_.make_heap(RasterOrderComparator(tree_priority_)); |
| 166 } | 160 } |
| 167 | 161 |
| 168 void RasterTilePriorityQueue::Reset() { | 162 bool RasterTilePriorityQueueAll::IsEmpty() const { |
| 169 paired_queues_.clear(); | |
| 170 } | |
| 171 | |
| 172 bool RasterTilePriorityQueue::IsEmpty() const { | |
| 173 return paired_queues_.empty() || paired_queues_.front()->IsEmpty(); | 163 return paired_queues_.empty() || paired_queues_.front()->IsEmpty(); |
| 174 } | 164 } |
| 175 | 165 |
| 176 Tile* RasterTilePriorityQueue::Top() { | 166 Tile* RasterTilePriorityQueueAll::Top() { |
| 177 DCHECK(!IsEmpty()); | 167 DCHECK(!IsEmpty()); |
| 178 return paired_queues_.front()->Top(tree_priority_); | 168 return paired_queues_.front()->Top(tree_priority_); |
| 179 } | 169 } |
| 180 | 170 |
| 181 void RasterTilePriorityQueue::Pop() { | 171 void RasterTilePriorityQueueAll::Pop() { |
| 182 DCHECK(!IsEmpty()); | 172 DCHECK(!IsEmpty()); |
| 183 | 173 |
| 184 paired_queues_.pop_heap(RasterOrderComparator(tree_priority_)); | 174 paired_queues_.pop_heap(RasterOrderComparator(tree_priority_)); |
| 185 PairedTilingSetQueue* paired_queue = paired_queues_.back(); | 175 PairedTilingSetQueue* paired_queue = paired_queues_.back(); |
| 186 paired_queue->Pop(tree_priority_); | 176 paired_queue->Pop(tree_priority_); |
| 187 paired_queues_.push_heap(RasterOrderComparator(tree_priority_)); | 177 paired_queues_.push_heap(RasterOrderComparator(tree_priority_)); |
| 188 } | 178 } |
| 189 | 179 |
| 190 RasterTilePriorityQueue::PairedTilingSetQueue::PairedTilingSetQueue() { | 180 RasterTilePriorityQueueAll::PairedTilingSetQueue::PairedTilingSetQueue() { |
| 191 } | 181 } |
| 192 | 182 |
| 193 RasterTilePriorityQueue::PairedTilingSetQueue::PairedTilingSetQueue( | 183 RasterTilePriorityQueueAll::PairedTilingSetQueue::PairedTilingSetQueue( |
| 194 const PictureLayerImpl::Pair& layer_pair, | 184 const PictureLayerImpl::Pair& layer_pair, |
| 195 TreePriority tree_priority, | 185 TreePriority tree_priority) |
| 196 Type type) | 186 : active_queue_( |
| 197 : has_both_layers_(false) { | 187 CreateTilingSetRasterQueue(layer_pair.active, tree_priority)), |
| 198 switch (type) { | 188 pending_queue_( |
| 199 case RasterTilePriorityQueue::Type::ALL: | 189 CreateTilingSetRasterQueue(layer_pair.pending, tree_priority)), |
| 200 has_both_layers_ = layer_pair.active && layer_pair.pending; | 190 has_both_layers_(layer_pair.active && layer_pair.pending) { |
| 201 active_queue_ = | |
| 202 CreateTilingSetRasterQueue(layer_pair.active, tree_priority, type); | |
| 203 pending_queue_ = | |
| 204 CreateTilingSetRasterQueue(layer_pair.pending, tree_priority, type); | |
| 205 break; | |
| 206 case RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION: | |
| 207 pending_queue_ = | |
| 208 CreateTilingSetRasterQueue(layer_pair.pending, tree_priority, type); | |
| 209 break; | |
| 210 case RasterTilePriorityQueue::Type::REQUIRED_FOR_DRAW: | |
| 211 active_queue_ = | |
| 212 CreateTilingSetRasterQueue(layer_pair.active, tree_priority, type); | |
| 213 break; | |
| 214 } | |
| 215 DCHECK_IMPLIES(has_both_layers_, active_queue_ && pending_queue_); | |
| 216 | |
| 217 SkipTilesReturnedByTwin(tree_priority); | 191 SkipTilesReturnedByTwin(tree_priority); |
| 218 | 192 |
| 219 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 193 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
| 220 "PairedTilingSetQueue::PairedTilingSetQueue", | 194 "PairedTilingSetQueue::PairedTilingSetQueue", |
| 221 TRACE_EVENT_SCOPE_THREAD, "state", StateAsValue()); | 195 TRACE_EVENT_SCOPE_THREAD, "state", StateAsValue()); |
| 222 } | 196 } |
| 223 | 197 |
| 224 RasterTilePriorityQueue::PairedTilingSetQueue::~PairedTilingSetQueue() { | 198 RasterTilePriorityQueueAll::PairedTilingSetQueue::~PairedTilingSetQueue() { |
| 225 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 199 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
| 226 "PairedTilingSetQueue::~PairedTilingSetQueue", | 200 "PairedTilingSetQueue::~PairedTilingSetQueue", |
| 227 TRACE_EVENT_SCOPE_THREAD, "state", StateAsValue()); | 201 TRACE_EVENT_SCOPE_THREAD, "state", StateAsValue()); |
| 228 } | 202 } |
| 229 | 203 |
| 230 bool RasterTilePriorityQueue::PairedTilingSetQueue::IsEmpty() const { | 204 bool RasterTilePriorityQueueAll::PairedTilingSetQueue::IsEmpty() const { |
| 231 return (!active_queue_ || active_queue_->IsEmpty()) && | 205 return (!active_queue_ || active_queue_->IsEmpty()) && |
| 232 (!pending_queue_ || pending_queue_->IsEmpty()); | 206 (!pending_queue_ || pending_queue_->IsEmpty()); |
| 233 } | 207 } |
| 234 | 208 |
| 235 Tile* RasterTilePriorityQueue::PairedTilingSetQueue::Top( | 209 Tile* RasterTilePriorityQueueAll::PairedTilingSetQueue::Top( |
| 236 TreePriority tree_priority) { | 210 TreePriority tree_priority) { |
| 237 DCHECK(!IsEmpty()); | 211 DCHECK(!IsEmpty()); |
| 238 | 212 |
| 239 WhichTree next_tree = NextTileIteratorTree(tree_priority); | 213 WhichTree next_tree = NextTileIteratorTree(tree_priority); |
| 240 TilingSetRasterQueue* next_queue = | 214 TilingSetRasterQueue* next_queue = |
| 241 next_tree == ACTIVE_TREE ? active_queue_.get() : pending_queue_.get(); | 215 next_tree == ACTIVE_TREE ? active_queue_.get() : pending_queue_.get(); |
| 242 DCHECK(next_queue && !next_queue->IsEmpty()); | 216 DCHECK(next_queue && !next_queue->IsEmpty()); |
| 243 Tile* tile = next_queue->Top(); | 217 Tile* tile = next_queue->Top(); |
| 244 DCHECK(returned_tiles_for_debug_.find(tile) == | 218 DCHECK(returned_tiles_for_debug_.find(tile) == |
| 245 returned_tiles_for_debug_.end()); | 219 returned_tiles_for_debug_.end()); |
| 246 return tile; | 220 return tile; |
| 247 } | 221 } |
| 248 | 222 |
| 249 void RasterTilePriorityQueue::PairedTilingSetQueue::Pop( | 223 void RasterTilePriorityQueueAll::PairedTilingSetQueue::Pop( |
| 250 TreePriority tree_priority) { | 224 TreePriority tree_priority) { |
| 251 DCHECK(!IsEmpty()); | 225 DCHECK(!IsEmpty()); |
| 252 | 226 |
| 253 WhichTree next_tree = NextTileIteratorTree(tree_priority); | 227 WhichTree next_tree = NextTileIteratorTree(tree_priority); |
| 254 TilingSetRasterQueue* next_queue = | 228 TilingSetRasterQueue* next_queue = |
| 255 next_tree == ACTIVE_TREE ? active_queue_.get() : pending_queue_.get(); | 229 next_tree == ACTIVE_TREE ? active_queue_.get() : pending_queue_.get(); |
| 256 DCHECK(next_queue && !next_queue->IsEmpty()); | 230 DCHECK(next_queue && !next_queue->IsEmpty()); |
| 257 DCHECK(returned_tiles_for_debug_.insert(next_queue->Top()).second); | 231 DCHECK(returned_tiles_for_debug_.insert(next_queue->Top()).second); |
| 258 next_queue->Pop(); | 232 next_queue->Pop(); |
| 259 | 233 |
| 260 SkipTilesReturnedByTwin(tree_priority); | 234 SkipTilesReturnedByTwin(tree_priority); |
| 261 | 235 |
| 262 // If no empty, use Top to do DCHECK the next iterator. | 236 // If no empty, use Top to do DCHECK the next iterator. |
| 263 DCHECK(IsEmpty() || Top(tree_priority)); | 237 DCHECK(IsEmpty() || Top(tree_priority)); |
| 264 } | 238 } |
| 265 | 239 |
| 266 void RasterTilePriorityQueue::PairedTilingSetQueue::SkipTilesReturnedByTwin( | 240 void RasterTilePriorityQueueAll::PairedTilingSetQueue::SkipTilesReturnedByTwin( |
| 267 TreePriority tree_priority) { | 241 TreePriority tree_priority) { |
| 268 if (!has_both_layers_) | 242 if (!has_both_layers_) |
| 269 return; | 243 return; |
| 270 | 244 |
| 271 // We have both layers (active and pending) thus we can encounter shared | 245 // We have both layers (active and pending) thus we can encounter shared |
| 272 // tiles twice (from the active iterator and from the pending iterator). | 246 // tiles twice (from the active iterator and from the pending iterator). |
| 273 while (!IsEmpty()) { | 247 while (!IsEmpty()) { |
| 274 WhichTree next_tree = NextTileIteratorTree(tree_priority); | 248 WhichTree next_tree = NextTileIteratorTree(tree_priority); |
| 275 TilingSetRasterQueue* next_queue = | 249 TilingSetRasterQueue* next_queue = |
| 276 next_tree == ACTIVE_TREE ? active_queue_.get() : pending_queue_.get(); | 250 next_tree == ACTIVE_TREE ? active_queue_.get() : pending_queue_.get(); |
| 277 DCHECK(next_queue && !next_queue->IsEmpty()); | 251 DCHECK(next_queue && !next_queue->IsEmpty()); |
| 278 | 252 |
| 279 // Accept all non-shared tiles. | 253 // Accept all non-shared tiles. |
| 280 const Tile* tile = next_queue->Top(); | 254 const Tile* tile = next_queue->Top(); |
| 281 if (!tile->is_shared()) | 255 if (!tile->is_shared()) |
| 282 break; | 256 break; |
| 283 | 257 |
| 284 // Accept a shared tile if the next tree is the higher priority one | 258 // Accept a shared tile if the next tree is the higher priority one |
| 285 // corresponding the iterator (active or pending) which usually (but due | 259 // corresponding the iterator (active or pending) which usually (but due |
| 286 // to spiral iterators not always) returns the shared tile first. | 260 // to spiral iterators not always) returns the shared tile first. |
| 287 if (next_tree == HigherPriorityTree(tree_priority, nullptr, nullptr, tile)) | 261 if (next_tree == HigherPriorityTree(tree_priority, nullptr, nullptr, tile)) |
| 288 break; | 262 break; |
| 289 | 263 |
| 290 next_queue->Pop(); | 264 next_queue->Pop(); |
| 291 } | 265 } |
| 292 } | 266 } |
| 293 | 267 |
| 294 WhichTree RasterTilePriorityQueue::PairedTilingSetQueue::NextTileIteratorTree( | 268 WhichTree |
| 269 RasterTilePriorityQueueAll::PairedTilingSetQueue::NextTileIteratorTree( |
| 295 TreePriority tree_priority) const { | 270 TreePriority tree_priority) const { |
| 296 DCHECK(!IsEmpty()); | 271 DCHECK(!IsEmpty()); |
| 297 | 272 |
| 298 // If we only have one queue with tiles, return it. | 273 // If we only have one queue with tiles, return it. |
| 299 if (!active_queue_ || active_queue_->IsEmpty()) | 274 if (!active_queue_ || active_queue_->IsEmpty()) |
| 300 return PENDING_TREE; | 275 return PENDING_TREE; |
| 301 if (!pending_queue_ || pending_queue_->IsEmpty()) | 276 if (!pending_queue_ || pending_queue_->IsEmpty()) |
| 302 return ACTIVE_TREE; | 277 return ACTIVE_TREE; |
| 303 | 278 |
| 304 // Now both iterators have tiles, so we have to decide based on tree priority. | 279 // Now both iterators have tiles, so we have to decide based on tree priority. |
| 305 return HigherPriorityTree(tree_priority, active_queue_.get(), | 280 return HigherPriorityTree(tree_priority, active_queue_.get(), |
| 306 pending_queue_.get(), nullptr); | 281 pending_queue_.get(), nullptr); |
| 307 } | 282 } |
| 308 | 283 |
| 309 scoped_refptr<base::debug::ConvertableToTraceFormat> | 284 scoped_refptr<base::debug::ConvertableToTraceFormat> |
| 310 RasterTilePriorityQueue::PairedTilingSetQueue::StateAsValue() const { | 285 RasterTilePriorityQueueAll::PairedTilingSetQueue::StateAsValue() const { |
| 311 scoped_refptr<base::debug::TracedValue> state = | 286 scoped_refptr<base::debug::TracedValue> state = |
| 312 new base::debug::TracedValue(); | 287 new base::debug::TracedValue(); |
| 313 | 288 |
| 314 bool active_queue_has_tile = active_queue_ && !active_queue_->IsEmpty(); | 289 bool active_queue_has_tile = active_queue_ && !active_queue_->IsEmpty(); |
| 315 TilePriority::PriorityBin active_priority_bin = TilePriority::EVENTUALLY; | 290 TilePriority::PriorityBin active_priority_bin = TilePriority::EVENTUALLY; |
| 316 TilePriority::PriorityBin pending_priority_bin = TilePriority::EVENTUALLY; | 291 TilePriority::PriorityBin pending_priority_bin = TilePriority::EVENTUALLY; |
| 317 if (active_queue_has_tile) { | 292 if (active_queue_has_tile) { |
| 318 active_priority_bin = | 293 active_priority_bin = |
| 319 active_queue_->Top()->priority(ACTIVE_TREE).priority_bin; | 294 active_queue_->Top()->priority(ACTIVE_TREE).priority_bin; |
| 320 pending_priority_bin = | 295 pending_priority_bin = |
| (...skipping 18 matching lines...) Expand all Loading... |
| 339 | 314 |
| 340 state->BeginDictionary("pending_queue"); | 315 state->BeginDictionary("pending_queue"); |
| 341 state->SetBoolean("has_tile", active_queue_has_tile); | 316 state->SetBoolean("has_tile", active_queue_has_tile); |
| 342 state->SetInteger("active_priority_bin", active_priority_bin); | 317 state->SetInteger("active_priority_bin", active_priority_bin); |
| 343 state->SetInteger("pending_priority_bin", pending_priority_bin); | 318 state->SetInteger("pending_priority_bin", pending_priority_bin); |
| 344 state->EndDictionary(); | 319 state->EndDictionary(); |
| 345 return state; | 320 return state; |
| 346 } | 321 } |
| 347 | 322 |
| 348 } // namespace cc | 323 } // namespace cc |
| OLD | NEW |