| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 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/prioritized_tile_set.h" | |
| 6 | |
| 7 #include <algorithm> | |
| 8 | |
| 9 #include "cc/resources/managed_tile_state.h" | |
| 10 #include "cc/resources/tile.h" | |
| 11 | |
| 12 namespace cc { | |
| 13 | |
| 14 class BinComparator { | |
| 15 public: | |
| 16 bool operator()(const Tile* a, | |
| 17 const Tile* b) const { | |
| 18 const ManagedTileState& ams = a->managed_state(); | |
| 19 const ManagedTileState& bms = b->managed_state(); | |
| 20 | |
| 21 if (ams.priority_bin != bms.priority_bin) | |
| 22 return ams.priority_bin < bms.priority_bin; | |
| 23 | |
| 24 if (ams.required_for_activation != bms.required_for_activation) | |
| 25 return ams.required_for_activation; | |
| 26 | |
| 27 if (ams.resolution != bms.resolution) | |
| 28 return ams.resolution < bms.resolution; | |
| 29 | |
| 30 if (ams.distance_to_visible != bms.distance_to_visible) | |
| 31 return ams.distance_to_visible < bms.distance_to_visible; | |
| 32 | |
| 33 gfx::Rect a_rect = a->content_rect(); | |
| 34 gfx::Rect b_rect = b->content_rect(); | |
| 35 if (a_rect.y() != b_rect.y()) | |
| 36 return a_rect.y() < b_rect.y(); | |
| 37 return a_rect.x() < b_rect.x(); | |
| 38 } | |
| 39 }; | |
| 40 | |
| 41 namespace { | |
| 42 | |
| 43 typedef std::vector<Tile*> TileVector; | |
| 44 | |
| 45 void SortBinTiles(ManagedTileBin bin, TileVector* tiles) { | |
| 46 switch (bin) { | |
| 47 case NOW_AND_READY_TO_DRAW_BIN: | |
| 48 case NEVER_BIN: | |
| 49 break; | |
| 50 case NOW_BIN: | |
| 51 case SOON_BIN: | |
| 52 case EVENTUALLY_AND_ACTIVE_BIN: | |
| 53 case EVENTUALLY_BIN: | |
| 54 case AT_LAST_AND_ACTIVE_BIN: | |
| 55 case AT_LAST_BIN: | |
| 56 std::sort(tiles->begin(), tiles->end(), BinComparator()); | |
| 57 break; | |
| 58 default: | |
| 59 NOTREACHED(); | |
| 60 } | |
| 61 } | |
| 62 | |
| 63 } // namespace | |
| 64 | |
| 65 PrioritizedTileSet::PrioritizedTileSet() { | |
| 66 for (int bin = 0; bin < NUM_BINS; ++bin) | |
| 67 bin_sorted_[bin] = true; | |
| 68 } | |
| 69 | |
| 70 PrioritizedTileSet::~PrioritizedTileSet() {} | |
| 71 | |
| 72 void PrioritizedTileSet::InsertTile(Tile* tile, ManagedTileBin bin) { | |
| 73 tiles_[bin].push_back(tile); | |
| 74 bin_sorted_[bin] = false; | |
| 75 } | |
| 76 | |
| 77 void PrioritizedTileSet::Clear() { | |
| 78 for (int bin = 0; bin < NUM_BINS; ++bin) { | |
| 79 tiles_[bin].clear(); | |
| 80 bin_sorted_[bin] = true; | |
| 81 } | |
| 82 } | |
| 83 | |
| 84 bool PrioritizedTileSet::IsEmpty() { | |
| 85 for (int bin = 0; bin < NUM_BINS; ++bin) | |
| 86 if (!tiles_[bin].empty()) | |
| 87 return false; | |
| 88 | |
| 89 return true; | |
| 90 } | |
| 91 | |
| 92 void PrioritizedTileSet::SortBinIfNeeded(ManagedTileBin bin) { | |
| 93 if (!bin_sorted_[bin]) { | |
| 94 SortBinTiles(bin, &tiles_[bin]); | |
| 95 bin_sorted_[bin] = true; | |
| 96 } | |
| 97 } | |
| 98 | |
| 99 PrioritizedTileSet::Iterator::Iterator( | |
| 100 PrioritizedTileSet* tile_set, bool use_priority_ordering) | |
| 101 : tile_set_(tile_set), | |
| 102 current_bin_(NOW_AND_READY_TO_DRAW_BIN), | |
| 103 use_priority_ordering_(use_priority_ordering) { | |
| 104 if (use_priority_ordering_) | |
| 105 tile_set_->SortBinIfNeeded(current_bin_); | |
| 106 iterator_ = tile_set->tiles_[current_bin_].begin(); | |
| 107 if (iterator_ == tile_set_->tiles_[current_bin_].end()) | |
| 108 AdvanceList(); | |
| 109 } | |
| 110 | |
| 111 PrioritizedTileSet::Iterator::~Iterator() {} | |
| 112 | |
| 113 void PrioritizedTileSet::Iterator::DisablePriorityOrdering() { | |
| 114 use_priority_ordering_ = false; | |
| 115 } | |
| 116 | |
| 117 PrioritizedTileSet::Iterator& | |
| 118 PrioritizedTileSet::Iterator::operator++() { | |
| 119 // We can't increment past the end of the tiles. | |
| 120 DCHECK(iterator_ != tile_set_->tiles_[current_bin_].end()); | |
| 121 | |
| 122 ++iterator_; | |
| 123 if (iterator_ == tile_set_->tiles_[current_bin_].end()) | |
| 124 AdvanceList(); | |
| 125 return *this; | |
| 126 } | |
| 127 | |
| 128 Tile* PrioritizedTileSet::Iterator::operator*() { | |
| 129 DCHECK(iterator_ != tile_set_->tiles_[current_bin_].end()); | |
| 130 return *iterator_; | |
| 131 } | |
| 132 | |
| 133 void PrioritizedTileSet::Iterator::AdvanceList() { | |
| 134 DCHECK(iterator_ == tile_set_->tiles_[current_bin_].end()); | |
| 135 | |
| 136 while (current_bin_ != NEVER_BIN) { | |
| 137 current_bin_ = static_cast<ManagedTileBin>(current_bin_ + 1); | |
| 138 | |
| 139 if (use_priority_ordering_) | |
| 140 tile_set_->SortBinIfNeeded(current_bin_); | |
| 141 | |
| 142 iterator_ = tile_set_->tiles_[current_bin_].begin(); | |
| 143 if (iterator_ != tile_set_->tiles_[current_bin_].end()) | |
| 144 break; | |
| 145 } | |
| 146 } | |
| 147 | |
| 148 } // namespace cc | |
| OLD | NEW |