| 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/tiles/eviction_tile_priority_queue.h" | 5 #include "cc/tiles/eviction_tile_priority_queue.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" |
| 8 |
| 7 namespace cc { | 9 namespace cc { |
| 8 | 10 |
| 9 namespace { | 11 namespace { |
| 10 | 12 |
| 11 class EvictionOrderComparator { | 13 class EvictionOrderComparator { |
| 12 public: | 14 public: |
| 13 explicit EvictionOrderComparator(TreePriority tree_priority) | 15 explicit EvictionOrderComparator(TreePriority tree_priority) |
| 14 : tree_priority_(tree_priority) {} | 16 : tree_priority_(tree_priority) {} |
| 15 | 17 |
| 16 bool operator()(const scoped_ptr<TilingSetEvictionQueue>& a_queue, | 18 bool operator()( |
| 17 const scoped_ptr<TilingSetEvictionQueue>& b_queue) const { | 19 const std::unique_ptr<TilingSetEvictionQueue>& a_queue, |
| 20 const std::unique_ptr<TilingSetEvictionQueue>& b_queue) const { |
| 18 // Note that in this function, we have to return true if and only if | 21 // Note that in this function, we have to return true if and only if |
| 19 // b is strictly lower priority than a. | 22 // b is strictly lower priority than a. |
| 20 const PrioritizedTile& a_tile = a_queue->Top(); | 23 const PrioritizedTile& a_tile = a_queue->Top(); |
| 21 const PrioritizedTile& b_tile = b_queue->Top(); | 24 const PrioritizedTile& b_tile = b_queue->Top(); |
| 22 | 25 |
| 23 const TilePriority& a_priority = a_tile.priority(); | 26 const TilePriority& a_priority = a_tile.priority(); |
| 24 const TilePriority& b_priority = b_tile.priority(); | 27 const TilePriority& b_priority = b_tile.priority(); |
| 25 bool prioritize_low_res = tree_priority_ == SMOOTHNESS_TAKES_PRIORITY; | 28 bool prioritize_low_res = tree_priority_ == SMOOTHNESS_TAKES_PRIORITY; |
| 26 | 29 |
| 27 // If the priority bin differs, b is lower priority if it has the higher | 30 // If the priority bin differs, b is lower priority if it has the higher |
| (...skipping 29 matching lines...) Expand all Loading... |
| 57 return b_priority.distance_to_visible > a_priority.distance_to_visible; | 60 return b_priority.distance_to_visible > a_priority.distance_to_visible; |
| 58 } | 61 } |
| 59 | 62 |
| 60 private: | 63 private: |
| 61 TreePriority tree_priority_; | 64 TreePriority tree_priority_; |
| 62 }; | 65 }; |
| 63 | 66 |
| 64 void CreateTilingSetEvictionQueues( | 67 void CreateTilingSetEvictionQueues( |
| 65 const std::vector<PictureLayerImpl*>& layers, | 68 const std::vector<PictureLayerImpl*>& layers, |
| 66 TreePriority tree_priority, | 69 TreePriority tree_priority, |
| 67 std::vector<scoped_ptr<TilingSetEvictionQueue>>* queues) { | 70 std::vector<std::unique_ptr<TilingSetEvictionQueue>>* queues) { |
| 68 DCHECK(queues->empty()); | 71 DCHECK(queues->empty()); |
| 69 | 72 |
| 70 for (auto* layer : layers) { | 73 for (auto* layer : layers) { |
| 71 scoped_ptr<TilingSetEvictionQueue> tiling_set_queue = make_scoped_ptr( | 74 std::unique_ptr<TilingSetEvictionQueue> tiling_set_queue = base::WrapUnique( |
| 72 new TilingSetEvictionQueue(layer->picture_layer_tiling_set())); | 75 new TilingSetEvictionQueue(layer->picture_layer_tiling_set())); |
| 73 // Queues will only contain non empty tiling sets. | 76 // Queues will only contain non empty tiling sets. |
| 74 if (!tiling_set_queue->IsEmpty()) | 77 if (!tiling_set_queue->IsEmpty()) |
| 75 queues->push_back(std::move(tiling_set_queue)); | 78 queues->push_back(std::move(tiling_set_queue)); |
| 76 } | 79 } |
| 77 std::make_heap(queues->begin(), queues->end(), | 80 std::make_heap(queues->begin(), queues->end(), |
| 78 EvictionOrderComparator(tree_priority)); | 81 EvictionOrderComparator(tree_priority)); |
| 79 } | 82 } |
| 80 | 83 |
| 81 } // namespace | 84 } // namespace |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 | 121 |
| 119 // Remove empty queues. | 122 // Remove empty queues. |
| 120 if (queue->IsEmpty()) { | 123 if (queue->IsEmpty()) { |
| 121 next_queues.pop_back(); | 124 next_queues.pop_back(); |
| 122 } else { | 125 } else { |
| 123 std::push_heap(next_queues.begin(), next_queues.end(), | 126 std::push_heap(next_queues.begin(), next_queues.end(), |
| 124 EvictionOrderComparator(tree_priority_)); | 127 EvictionOrderComparator(tree_priority_)); |
| 125 } | 128 } |
| 126 } | 129 } |
| 127 | 130 |
| 128 std::vector<scoped_ptr<TilingSetEvictionQueue>>& | 131 std::vector<std::unique_ptr<TilingSetEvictionQueue>>& |
| 129 EvictionTilePriorityQueue::GetNextQueues() { | 132 EvictionTilePriorityQueue::GetNextQueues() { |
| 130 const EvictionTilePriorityQueue* const_this = | 133 const EvictionTilePriorityQueue* const_this = |
| 131 static_cast<const EvictionTilePriorityQueue*>(this); | 134 static_cast<const EvictionTilePriorityQueue*>(this); |
| 132 const auto& const_queues = const_this->GetNextQueues(); | 135 const auto& const_queues = const_this->GetNextQueues(); |
| 133 return const_cast<std::vector<scoped_ptr<TilingSetEvictionQueue>>&>( | 136 return const_cast<std::vector<std::unique_ptr<TilingSetEvictionQueue>>&>( |
| 134 const_queues); | 137 const_queues); |
| 135 } | 138 } |
| 136 | 139 |
| 137 const std::vector<scoped_ptr<TilingSetEvictionQueue>>& | 140 const std::vector<std::unique_ptr<TilingSetEvictionQueue>>& |
| 138 EvictionTilePriorityQueue::GetNextQueues() const { | 141 EvictionTilePriorityQueue::GetNextQueues() const { |
| 139 DCHECK(!IsEmpty()); | 142 DCHECK(!IsEmpty()); |
| 140 | 143 |
| 141 // If we only have one queue with tiles, return it. | 144 // If we only have one queue with tiles, return it. |
| 142 if (active_queues_.empty()) | 145 if (active_queues_.empty()) |
| 143 return pending_queues_; | 146 return pending_queues_; |
| 144 if (pending_queues_.empty()) | 147 if (pending_queues_.empty()) |
| 145 return active_queues_; | 148 return active_queues_; |
| 146 | 149 |
| 147 const PrioritizedTile& active_tile = active_queues_.front()->Top(); | 150 const PrioritizedTile& active_tile = active_queues_.front()->Top(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 159 : active_queues_; | 162 : active_queues_; |
| 160 } | 163 } |
| 161 | 164 |
| 162 // Return tile with a lower priority. | 165 // Return tile with a lower priority. |
| 163 if (pending_priority.IsHigherPriorityThan(active_priority)) | 166 if (pending_priority.IsHigherPriorityThan(active_priority)) |
| 164 return active_queues_; | 167 return active_queues_; |
| 165 return pending_queues_; | 168 return pending_queues_; |
| 166 } | 169 } |
| 167 | 170 |
| 168 } // namespace cc | 171 } // namespace cc |
| OLD | NEW |