Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "cc/resources/eviction_tile_priority_queue.h" | |
| 6 | |
| 7 namespace cc { | |
| 8 | |
| 9 namespace { | |
| 10 | |
| 11 class EvictionOrderComparator { | |
| 12 public: | |
| 13 explicit EvictionOrderComparator(TreePriority tree_priority) | |
| 14 : tree_priority_(tree_priority) {} | |
| 15 | |
| 16 bool operator()(EvictionTilePriorityQueue::PairedPictureLayerQueue& a, | |
| 17 EvictionTilePriorityQueue::PairedPictureLayerQueue& b) const { | |
| 18 if (a.IsEmpty()) | |
| 19 return true; | |
| 20 | |
| 21 if (b.IsEmpty()) | |
| 22 return false; | |
| 23 | |
| 24 PictureLayerImpl::LayerEvictionTileIterator* a_iterator = | |
| 25 a.NextTileIterator(tree_priority_); | |
| 26 PictureLayerImpl::LayerEvictionTileIterator* b_iterator = | |
| 27 b.NextTileIterator(tree_priority_); | |
| 28 | |
| 29 Tile* a_tile = **a_iterator; | |
| 30 Tile* b_tile = **b_iterator; | |
| 31 | |
| 32 const TilePriority& a_priority = | |
| 33 a_tile->priority_for_tree_priority(tree_priority_); | |
| 34 const TilePriority& b_priority = | |
| 35 b_tile->priority_for_tree_priority(tree_priority_); | |
| 36 bool prioritize_low_res = tree_priority_ == SMOOTHNESS_TAKES_PRIORITY; | |
| 37 | |
| 38 // Now we have to return true iff b is lower priority than a. | |
| 39 | |
| 40 // If the priority bin differs, b is lower priority if it has the higher | |
| 41 // priority bin. | |
| 42 if (a_priority.priority_bin != b_priority.priority_bin) | |
| 43 return b_priority.priority_bin > a_priority.priority_bin; | |
| 44 | |
| 45 // Otherwise if the resolution differs, then the order will be determined by | |
| 46 // whether we prioritize low res or not. | |
| 47 // TODO(vmpstr): Remove this when TilePriority is no longer a member of Tile | |
| 48 // class but instead produced by the iterators. | |
| 49 if (b_priority.resolution != a_priority.resolution) { | |
| 50 // Non ideal resolution should be sorted higher than other resolutions. | |
| 51 if (a_priority.resolution == NON_IDEAL_RESOLUTION) | |
| 52 return false; | |
| 53 | |
| 54 if (b_priority.resolution == NON_IDEAL_RESOLUTION) | |
| 55 return true; | |
| 56 | |
| 57 if (prioritize_low_res) | |
| 58 return a_priority.resolution == LOW_RESOLUTION; | |
| 59 | |
| 60 return a_priority.resolution == HIGH_RESOLUTION; | |
| 61 } | |
| 62 | |
| 63 // Otherwise if the occlusion differs, b is lower priority if it is | |
| 64 // occluded. | |
| 65 bool a_is_occluded = a_tile->is_occluded_for_tree_priority(tree_priority_); | |
| 66 bool b_is_occluded = b_tile->is_occluded_for_tree_priority(tree_priority_); | |
| 67 if (a_is_occluded != b_is_occluded) | |
| 68 return b_is_occluded; | |
| 69 | |
| 70 // b is lower priorty if it is farther from visible. | |
| 71 return b_priority.distance_to_visible > a_priority.distance_to_visible; | |
| 72 } | |
| 73 | |
| 74 private: | |
| 75 TreePriority tree_priority_; | |
| 76 }; | |
| 77 | |
| 78 } // namespace | |
| 79 | |
| 80 EvictionTilePriorityQueue::EvictionTilePriorityQueue() { | |
| 81 } | |
| 82 | |
| 83 EvictionTilePriorityQueue::~EvictionTilePriorityQueue() { | |
| 84 } | |
| 85 | |
| 86 void EvictionTilePriorityQueue::Build( | |
| 87 const std::vector<PictureLayerImpl::Pair>& paired_layers, | |
| 88 TreePriority tree_priority) { | |
| 89 tree_priority_ = tree_priority; | |
| 90 | |
| 91 for (std::vector<PictureLayerImpl::Pair>::const_iterator it = | |
| 92 paired_layers.begin(); | |
| 93 it != paired_layers.end(); | |
| 94 ++it) { | |
| 95 paired_queues_.push_back(PairedPictureLayerQueue(*it, tree_priority_)); | |
| 96 } | |
| 97 | |
| 98 std::make_heap(paired_queues_.begin(), | |
| 99 paired_queues_.end(), | |
| 100 EvictionOrderComparator(tree_priority_)); | |
| 101 } | |
| 102 | |
| 103 void EvictionTilePriorityQueue::Reset() { | |
| 104 paired_queues_.clear(); | |
| 105 } | |
| 106 | |
| 107 bool EvictionTilePriorityQueue::IsEmpty() const { | |
| 108 return paired_queues_.empty() || paired_queues_.front().IsEmpty(); | |
| 109 } | |
| 110 | |
| 111 Tile* EvictionTilePriorityQueue::Top() { | |
| 112 DCHECK(!IsEmpty()); | |
| 113 return paired_queues_.front().Top(tree_priority_); | |
| 114 } | |
| 115 | |
| 116 void EvictionTilePriorityQueue::Pop() { | |
| 117 DCHECK(!IsEmpty()); | |
| 118 | |
| 119 std::pop_heap(paired_queues_.begin(), | |
| 120 paired_queues_.end(), | |
| 121 EvictionOrderComparator(tree_priority_)); | |
| 122 PairedPictureLayerQueue& paired_queue = paired_queues_.back(); | |
| 123 paired_queue.Pop(tree_priority_); | |
| 124 std::push_heap(paired_queues_.begin(), | |
| 125 paired_queues_.end(), | |
| 126 EvictionOrderComparator(tree_priority_)); | |
| 127 } | |
| 128 | |
| 129 EvictionTilePriorityQueue::PairedPictureLayerQueue::PairedPictureLayerQueue() { | |
| 130 } | |
| 131 | |
| 132 EvictionTilePriorityQueue::PairedPictureLayerQueue::PairedPictureLayerQueue( | |
| 133 const PictureLayerImpl::Pair& layer_pair, | |
| 134 TreePriority tree_priority) { | |
| 135 if (layer_pair.active) { | |
| 136 active_iterator = PictureLayerImpl::LayerEvictionTileIterator( | |
| 137 layer_pair.active, tree_priority); | |
|
reveman
2014/07/21 01:39:06
nit: consider moving this to the initialization li
vmpstr
2014/07/21 16:33:49
Done.
| |
| 138 } | |
| 139 | |
| 140 if (layer_pair.pending) { | |
| 141 pending_iterator = PictureLayerImpl::LayerEvictionTileIterator( | |
| 142 layer_pair.pending, tree_priority); | |
|
reveman
2014/07/21 01:39:06
nit: consider moving this to the initialization li
vmpstr
2014/07/21 16:33:49
Done.
| |
| 143 } | |
| 144 } | |
| 145 | |
| 146 EvictionTilePriorityQueue::PairedPictureLayerQueue::~PairedPictureLayerQueue() { | |
| 147 } | |
| 148 | |
| 149 bool EvictionTilePriorityQueue::PairedPictureLayerQueue::IsEmpty() const { | |
| 150 return !active_iterator && !pending_iterator; | |
| 151 } | |
| 152 | |
| 153 Tile* EvictionTilePriorityQueue::PairedPictureLayerQueue::Top( | |
| 154 TreePriority tree_priority) { | |
| 155 DCHECK(!IsEmpty()); | |
| 156 | |
| 157 PictureLayerImpl::LayerEvictionTileIterator* next_iterator = | |
| 158 NextTileIterator(tree_priority); | |
| 159 DCHECK(*next_iterator); | |
| 160 | |
| 161 Tile* tile = **next_iterator; | |
| 162 DCHECK(std::find(returned_shared_tiles.begin(), | |
| 163 returned_shared_tiles.end(), | |
| 164 tile) == returned_shared_tiles.end()); | |
| 165 return tile; | |
| 166 } | |
| 167 | |
| 168 void EvictionTilePriorityQueue::PairedPictureLayerQueue::Pop( | |
| 169 TreePriority tree_priority) { | |
| 170 DCHECK(!IsEmpty()); | |
| 171 | |
| 172 PictureLayerImpl::LayerEvictionTileIterator* next_iterator = | |
| 173 NextTileIterator(tree_priority); | |
| 174 DCHECK(*next_iterator); | |
| 175 returned_shared_tiles.push_back(**next_iterator); | |
| 176 ++(*next_iterator); | |
| 177 | |
| 178 if (IsEmpty()) | |
| 179 return; | |
| 180 | |
| 181 next_iterator = NextTileIterator(tree_priority); | |
| 182 while (std::find(returned_shared_tiles.begin(), | |
| 183 returned_shared_tiles.end(), | |
| 184 **next_iterator) != returned_shared_tiles.end()) { | |
| 185 ++(*next_iterator); | |
| 186 if (IsEmpty()) | |
| 187 break; | |
| 188 next_iterator = NextTileIterator(tree_priority); | |
| 189 } | |
| 190 } | |
| 191 | |
| 192 PictureLayerImpl::LayerEvictionTileIterator* | |
| 193 EvictionTilePriorityQueue::PairedPictureLayerQueue::NextTileIterator( | |
| 194 TreePriority tree_priority) { | |
| 195 DCHECK(!IsEmpty()); | |
| 196 | |
| 197 // If we only have one iterator with tiles, return it. | |
| 198 if (!active_iterator) | |
| 199 return &pending_iterator; | |
| 200 if (!pending_iterator) | |
| 201 return &active_iterator; | |
| 202 | |
| 203 Tile* active_tile = *active_iterator; | |
| 204 Tile* pending_tile = *pending_iterator; | |
| 205 if (active_tile == pending_tile) | |
| 206 return &active_iterator; | |
| 207 | |
| 208 const TilePriority& active_priority = | |
| 209 active_tile->priority_for_tree_priority(tree_priority); | |
| 210 const TilePriority& pending_priority = | |
| 211 pending_tile->priority_for_tree_priority(tree_priority); | |
| 212 | |
| 213 if (pending_priority.IsHigherPriorityThan(active_priority)) | |
| 214 return &active_iterator; | |
| 215 return &pending_iterator; | |
| 216 } | |
| 217 | |
| 218 } // namespace cc | |
| OLD | NEW |