| 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/eviction_tile_priority_queue.h" | 5 #include "cc/resources/eviction_tile_priority_queue.h" |
| 6 | 6 |
| 7 namespace cc { | 7 namespace cc { |
| 8 | 8 |
| 9 namespace { | 9 namespace { |
| 10 | 10 |
| 11 class EvictionOrderComparator { | 11 class EvictionOrderComparator { |
| 12 public: | 12 public: |
| 13 explicit EvictionOrderComparator(TreePriority tree_priority) | 13 explicit EvictionOrderComparator(TreePriority tree_priority) |
| 14 : tree_priority_(tree_priority) {} | 14 : tree_priority_(tree_priority) {} |
| 15 | 15 |
| 16 bool operator()( | 16 bool operator()( |
| 17 const EvictionTilePriorityQueue::PairedPictureLayerQueue& a, | 17 const EvictionTilePriorityQueue::PairedPictureLayerQueue* a, |
| 18 const EvictionTilePriorityQueue::PairedPictureLayerQueue& b) const { | 18 const EvictionTilePriorityQueue::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::LayerEvictionTileIterator* a_iterator = | 26 const PictureLayerImpl::LayerEvictionTileIterator* 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::LayerEvictionTileIterator* b_iterator = | 30 const PictureLayerImpl::LayerEvictionTileIterator* 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 | 89 |
| 90 void EvictionTilePriorityQueue::Build( | 90 void EvictionTilePriorityQueue::Build( |
| 91 const std::vector<PictureLayerImpl::Pair>& paired_layers, | 91 const std::vector<PictureLayerImpl::Pair>& paired_layers, |
| 92 TreePriority tree_priority) { | 92 TreePriority tree_priority) { |
| 93 tree_priority_ = tree_priority; | 93 tree_priority_ = tree_priority; |
| 94 | 94 |
| 95 for (std::vector<PictureLayerImpl::Pair>::const_iterator it = | 95 for (std::vector<PictureLayerImpl::Pair>::const_iterator it = |
| 96 paired_layers.begin(); | 96 paired_layers.begin(); |
| 97 it != paired_layers.end(); | 97 it != paired_layers.end(); |
| 98 ++it) { | 98 ++it) { |
| 99 paired_queues_.push_back(PairedPictureLayerQueue(*it, tree_priority_)); | 99 paired_queues_heap_.push_back( |
| 100 make_scoped_ptr(new PairedPictureLayerQueue(*it, tree_priority_))); |
| 100 } | 101 } |
| 101 | 102 |
| 102 std::make_heap(paired_queues_.begin(), | 103 paired_queues_heap_.make_heap(EvictionOrderComparator(tree_priority_)); |
| 103 paired_queues_.end(), | |
| 104 EvictionOrderComparator(tree_priority_)); | |
| 105 } | 104 } |
| 106 | 105 |
| 107 void EvictionTilePriorityQueue::Reset() { | 106 void EvictionTilePriorityQueue::Reset() { |
| 108 paired_queues_.clear(); | 107 paired_queues_heap_.clear(); |
| 109 } | 108 } |
| 110 | 109 |
| 111 bool EvictionTilePriorityQueue::IsEmpty() const { | 110 bool EvictionTilePriorityQueue::IsEmpty() const { |
| 112 return paired_queues_.empty() || paired_queues_.front().IsEmpty(); | 111 return paired_queues_heap_.empty() || paired_queues_heap_.front()->IsEmpty(); |
| 113 } | 112 } |
| 114 | 113 |
| 115 Tile* EvictionTilePriorityQueue::Top() { | 114 Tile* EvictionTilePriorityQueue::Top() { |
| 116 DCHECK(!IsEmpty()); | 115 DCHECK(!IsEmpty()); |
| 117 return paired_queues_.front().Top(tree_priority_); | 116 return paired_queues_heap_.front()->Top(tree_priority_); |
| 118 } | 117 } |
| 119 | 118 |
| 120 void EvictionTilePriorityQueue::Pop() { | 119 void EvictionTilePriorityQueue::Pop() { |
| 121 DCHECK(!IsEmpty()); | 120 DCHECK(!IsEmpty()); |
| 122 | 121 |
| 123 std::pop_heap(paired_queues_.begin(), | 122 paired_queues_heap_.pop_heap(EvictionOrderComparator(tree_priority_)); |
| 124 paired_queues_.end(), | 123 PairedPictureLayerQueue* paired_queue = paired_queues_heap_.back(); |
| 125 EvictionOrderComparator(tree_priority_)); | 124 paired_queue->Pop(tree_priority_); |
| 126 PairedPictureLayerQueue& paired_queue = paired_queues_.back(); | 125 paired_queues_heap_.push_heap(EvictionOrderComparator(tree_priority_)); |
| 127 paired_queue.Pop(tree_priority_); | |
| 128 std::push_heap(paired_queues_.begin(), | |
| 129 paired_queues_.end(), | |
| 130 EvictionOrderComparator(tree_priority_)); | |
| 131 } | 126 } |
| 132 | 127 |
| 133 EvictionTilePriorityQueue::PairedPictureLayerQueue::PairedPictureLayerQueue() { | 128 EvictionTilePriorityQueue::PairedPictureLayerQueue::PairedPictureLayerQueue() { |
| 134 } | 129 } |
| 135 | 130 |
| 136 EvictionTilePriorityQueue::PairedPictureLayerQueue::PairedPictureLayerQueue( | 131 EvictionTilePriorityQueue::PairedPictureLayerQueue::PairedPictureLayerQueue( |
| 137 const PictureLayerImpl::Pair& layer_pair, | 132 const PictureLayerImpl::Pair& layer_pair, |
| 138 TreePriority tree_priority) | 133 TreePriority tree_priority) |
| 139 : active_iterator( | 134 : active_iterator( |
| 140 layer_pair.active | 135 layer_pair.active |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 active_tile->priority_for_tree_priority(tree_priority); | 215 active_tile->priority_for_tree_priority(tree_priority); |
| 221 const TilePriority& pending_priority = | 216 const TilePriority& pending_priority = |
| 222 pending_tile->priority_for_tree_priority(tree_priority); | 217 pending_tile->priority_for_tree_priority(tree_priority); |
| 223 | 218 |
| 224 if (pending_priority.IsHigherPriorityThan(active_priority)) | 219 if (pending_priority.IsHigherPriorityThan(active_priority)) |
| 225 return ACTIVE_TREE; | 220 return ACTIVE_TREE; |
| 226 return PENDING_TREE; | 221 return PENDING_TREE; |
| 227 } | 222 } |
| 228 | 223 |
| 229 } // namespace cc | 224 } // namespace cc |
| OLD | NEW |