| 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 |
| 11 class RasterOrderComparator { | 11 class RasterOrderComparator { |
| 12 public: | 12 public: |
| 13 explicit RasterOrderComparator(TreePriority tree_priority) | 13 explicit RasterOrderComparator(TreePriority tree_priority) |
| 14 : tree_priority_(tree_priority) {} | 14 : tree_priority_(tree_priority) {} |
| 15 | 15 |
| 16 bool operator()( | 16 bool operator()( |
| 17 const RasterTilePriorityQueue::PairedPictureLayerQueue& a, | 17 const RasterTilePriorityQueue::PairedPictureLayerQueue* a, |
| 18 const RasterTilePriorityQueue::PairedPictureLayerQueue& b) const { | 18 const RasterTilePriorityQueue::PairedPictureLayerQueue* b) const { |
| 19 if (a.IsEmpty()) | 19 if (a->IsEmpty()) |
| 20 return true; | 20 return true; |
| 21 | 21 |
| 22 if (b.IsEmpty()) | 22 if (b->IsEmpty()) |
| 23 return false; | 23 return false; |
| 24 | 24 |
| 25 WhichTree a_tree = a.NextTileIteratorTree(tree_priority_); | 25 WhichTree a_tree = a->NextTileIteratorTree(tree_priority_); |
| 26 const PictureLayerImpl::LayerRasterTileIterator* a_iterator = | 26 const PictureLayerImpl::LayerRasterTileIterator* a_iterator = |
| 27 a_tree == ACTIVE_TREE ? &a.active_iterator : &a.pending_iterator; | 27 a_tree == ACTIVE_TREE ? &a->active_iterator : &a->pending_iterator; |
| 28 | 28 |
| 29 WhichTree b_tree = b.NextTileIteratorTree(tree_priority_); | 29 WhichTree b_tree = b->NextTileIteratorTree(tree_priority_); |
| 30 const PictureLayerImpl::LayerRasterTileIterator* b_iterator = | 30 const PictureLayerImpl::LayerRasterTileIterator* b_iterator = |
| 31 b_tree == ACTIVE_TREE ? &b.active_iterator : &b.pending_iterator; | 31 b_tree == ACTIVE_TREE ? &b->active_iterator : &b->pending_iterator; |
| 32 | 32 |
| 33 const Tile* a_tile = **a_iterator; | 33 const Tile* a_tile = **a_iterator; |
| 34 const Tile* b_tile = **b_iterator; | 34 const Tile* b_tile = **b_iterator; |
| 35 | 35 |
| 36 const TilePriority& a_priority = | 36 const TilePriority& a_priority = |
| 37 a_tile->priority_for_tree_priority(tree_priority_); | 37 a_tile->priority_for_tree_priority(tree_priority_); |
| 38 const TilePriority& b_priority = | 38 const TilePriority& b_priority = |
| 39 b_tile->priority_for_tree_priority(tree_priority_); | 39 b_tile->priority_for_tree_priority(tree_priority_); |
| 40 bool prioritize_low_res = tree_priority_ == SMOOTHNESS_TAKES_PRIORITY; | 40 bool prioritize_low_res = tree_priority_ == SMOOTHNESS_TAKES_PRIORITY; |
| 41 | 41 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 } | 76 } |
| 77 | 77 |
| 78 void RasterTilePriorityQueue::Build( | 78 void RasterTilePriorityQueue::Build( |
| 79 const std::vector<PictureLayerImpl::Pair>& paired_layers, | 79 const std::vector<PictureLayerImpl::Pair>& paired_layers, |
| 80 TreePriority tree_priority) { | 80 TreePriority tree_priority) { |
| 81 tree_priority_ = tree_priority; | 81 tree_priority_ = tree_priority; |
| 82 for (std::vector<PictureLayerImpl::Pair>::const_iterator it = | 82 for (std::vector<PictureLayerImpl::Pair>::const_iterator it = |
| 83 paired_layers.begin(); | 83 paired_layers.begin(); |
| 84 it != paired_layers.end(); | 84 it != paired_layers.end(); |
| 85 ++it) { | 85 ++it) { |
| 86 paired_queues_.push_back(PairedPictureLayerQueue(*it, tree_priority_)); | 86 paired_queues_heap_.push_back( |
| 87 make_scoped_ptr(new PairedPictureLayerQueue(*it, tree_priority_))); |
| 87 } | 88 } |
| 88 | 89 |
| 89 std::make_heap(paired_queues_.begin(), | 90 paired_queues_heap_.make_heap(RasterOrderComparator(tree_priority_)); |
| 90 paired_queues_.end(), | |
| 91 RasterOrderComparator(tree_priority_)); | |
| 92 } | 91 } |
| 93 | 92 |
| 94 void RasterTilePriorityQueue::Reset() { | 93 void RasterTilePriorityQueue::Reset() { |
| 95 paired_queues_.clear(); | 94 paired_queues_heap_.clear(); |
| 96 } | 95 } |
| 97 | 96 |
| 98 bool RasterTilePriorityQueue::IsEmpty() const { | 97 bool RasterTilePriorityQueue::IsEmpty() const { |
| 99 return paired_queues_.empty() || paired_queues_.front().IsEmpty(); | 98 return paired_queues_heap_.empty() || paired_queues_heap_.front()->IsEmpty(); |
| 100 } | 99 } |
| 101 | 100 |
| 102 Tile* RasterTilePriorityQueue::Top() { | 101 Tile* RasterTilePriorityQueue::Top() { |
| 103 DCHECK(!IsEmpty()); | 102 DCHECK(!IsEmpty()); |
| 104 return paired_queues_.front().Top(tree_priority_); | 103 return paired_queues_heap_.front()->Top(tree_priority_); |
| 105 } | 104 } |
| 106 | 105 |
| 107 void RasterTilePriorityQueue::Pop() { | 106 void RasterTilePriorityQueue::Pop() { |
| 108 DCHECK(!IsEmpty()); | 107 DCHECK(!IsEmpty()); |
| 109 | 108 |
| 110 std::pop_heap(paired_queues_.begin(), | 109 paired_queues_heap_.pop_heap(RasterOrderComparator(tree_priority_)); |
| 111 paired_queues_.end(), | 110 PairedPictureLayerQueue* paired_queue = paired_queues_heap_.back(); |
| 112 RasterOrderComparator(tree_priority_)); | 111 paired_queue->Pop(tree_priority_); |
| 113 PairedPictureLayerQueue& paired_queue = paired_queues_.back(); | 112 paired_queues_heap_.push_heap(RasterOrderComparator(tree_priority_)); |
| 114 paired_queue.Pop(tree_priority_); | |
| 115 std::push_heap(paired_queues_.begin(), | |
| 116 paired_queues_.end(), | |
| 117 RasterOrderComparator(tree_priority_)); | |
| 118 } | 113 } |
| 119 | 114 |
| 120 RasterTilePriorityQueue::PairedPictureLayerQueue::PairedPictureLayerQueue() { | 115 RasterTilePriorityQueue::PairedPictureLayerQueue::PairedPictureLayerQueue() { |
| 121 } | 116 } |
| 122 | 117 |
| 123 RasterTilePriorityQueue::PairedPictureLayerQueue::PairedPictureLayerQueue( | 118 RasterTilePriorityQueue::PairedPictureLayerQueue::PairedPictureLayerQueue( |
| 124 const PictureLayerImpl::Pair& layer_pair, | 119 const PictureLayerImpl::Pair& layer_pair, |
| 125 TreePriority tree_priority) | 120 TreePriority tree_priority) |
| 126 : active_iterator(layer_pair.active | 121 : active_iterator(layer_pair.active |
| 127 ? PictureLayerImpl::LayerRasterTileIterator( | 122 ? PictureLayerImpl::LayerRasterTileIterator( |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 default: | 215 default: |
| 221 NOTREACHED(); | 216 NOTREACHED(); |
| 222 } | 217 } |
| 223 | 218 |
| 224 NOTREACHED(); | 219 NOTREACHED(); |
| 225 // Keep the compiler happy. | 220 // Keep the compiler happy. |
| 226 return ACTIVE_TREE; | 221 return ACTIVE_TREE; |
| 227 } | 222 } |
| 228 | 223 |
| 229 } // namespace cc | 224 } // namespace cc |
| OLD | NEW |