| 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/shared_tile_bundle.h" |
| 6 |
| 7 namespace cc { |
| 8 |
| 9 SharedTileBundle::SharedTileBundle() {} |
| 10 |
| 11 SharedTileBundle::SharedTileBundle(const TilePriority& active_priority, |
| 12 const TilePriority& pending_priority) |
| 13 : active_priority_(active_priority), pending_priority_(pending_priority) {} |
| 14 |
| 15 void SharedTileBundle::AddTileAt(int x, int y, Tile* tile) { |
| 16 TileMapKey key(x, y); |
| 17 DCHECK(tiles_.find(key) == tiles_.end()); |
| 18 tiles_[key] = tile; |
| 19 } |
| 20 |
| 21 SharedTileBundle::Iterator::Iterator(SharedTileBundle* bundle) |
| 22 : bundle_(bundle), iterator_(bundle_->tiles_.begin()) {} |
| 23 |
| 24 SharedTileBundle::Iterator::~Iterator() {} |
| 25 |
| 26 BundleSetIterator::BundleSetIterator(TileBundleMap* bundles) |
| 27 : bundles_(bundles), |
| 28 current_bundle_iterator_(bundles_->begin()), |
| 29 current_bundle_type_(eActivePriorityOnly), |
| 30 active_bundle_(NULL), |
| 31 pending_bundle_(NULL) { |
| 32 if (current_bundle_iterator_ == bundles_->end()) |
| 33 return; |
| 34 |
| 35 bool success = InitializeSharedBundles(); |
| 36 if (success) |
| 37 return; |
| 38 |
| 39 AdvanceBundleIterator(); |
| 40 } |
| 41 |
| 42 BundleSetIterator::~BundleSetIterator() {} |
| 43 |
| 44 SharedTileBundle* BundleSetIterator::operator*() { |
| 45 return ¤t_bundle_; |
| 46 } |
| 47 |
| 48 SharedTileBundle* BundleSetIterator::operator->() { |
| 49 return ¤t_bundle_; |
| 50 } |
| 51 |
| 52 BundleSetIterator::operator bool() const { |
| 53 return current_bundle_iterator_ != bundles_->end(); |
| 54 } |
| 55 |
| 56 BundleSetIterator& BundleSetIterator::operator++() { |
| 57 DCHECK(current_bundle_type_ != eMaxSharedBundleTypes); |
| 58 DCHECK(current_bundle_iterator_ != bundles_->end()); |
| 59 |
| 60 current_bundle_type_ = |
| 61 static_cast<SharedBundleType>(current_bundle_type_ + 1); |
| 62 while (current_bundle_type_ != eMaxSharedBundleTypes) { |
| 63 bool success = InitializeSharedBundle(current_bundle_type_); |
| 64 if (success) |
| 65 return *this; |
| 66 current_bundle_type_ = |
| 67 static_cast<SharedBundleType>(current_bundle_type_ + 1); |
| 68 } |
| 69 |
| 70 AdvanceBundleIterator(); |
| 71 return *this; |
| 72 } |
| 73 |
| 74 void BundleSetIterator::AdvanceBundleIterator() { |
| 75 DCHECK(current_bundle_iterator_ != bundles_->end()); |
| 76 |
| 77 ++current_bundle_iterator_; |
| 78 while (current_bundle_iterator_ != bundles_->end()) { |
| 79 bool success = InitializeSharedBundles(); |
| 80 if (success) |
| 81 break; |
| 82 ++current_bundle_iterator_; |
| 83 } |
| 84 } |
| 85 |
| 86 bool BundleSetIterator::InitializeSharedBundles() { |
| 87 active_bundle_ = NULL; |
| 88 pending_bundle_ = NULL; |
| 89 |
| 90 TileBundle* bundle = current_bundle_iterator_->second; |
| 91 if ((processed_bundles_.count(bundle->id()) != 0) || bundle->IsRecycled()) |
| 92 return false; |
| 93 |
| 94 DetermineActivePendingBundles(bundle, bundle->GetTwinBundle()); |
| 95 |
| 96 if (active_bundle_) |
| 97 processed_bundles_.insert(active_bundle_->id()); |
| 98 if (pending_bundle_) |
| 99 processed_bundles_.insert(pending_bundle_->id()); |
| 100 |
| 101 bool success = InitializeSharedBundle(current_bundle_type_); |
| 102 if (success) |
| 103 return true; |
| 104 |
| 105 current_bundle_type_ = |
| 106 static_cast<SharedBundleType>(current_bundle_type_ + 1); |
| 107 while (current_bundle_type_ != eMaxSharedBundleTypes) { |
| 108 success = InitializeSharedBundle(current_bundle_type_); |
| 109 if (success) |
| 110 return true; |
| 111 current_bundle_type_ = |
| 112 static_cast<SharedBundleType>(current_bundle_type_ + 1); |
| 113 } |
| 114 return false; |
| 115 } |
| 116 |
| 117 bool BundleSetIterator::InitializeSharedBundle(SharedBundleType type) { |
| 118 bool first_run = true; |
| 119 switch (type) { |
| 120 case eBothPriorities: |
| 121 if (!active_bundle_ || !pending_bundle_) |
| 122 return false; |
| 123 |
| 124 for (TileBundle::Iterator it(active_bundle_); it; ++it) { |
| 125 Tile* tile = pending_bundle_->TileAt(it.index_x(), it.index_y()); |
| 126 if (tile != *it) |
| 127 continue; |
| 128 |
| 129 if (first_run) { |
| 130 current_bundle_ = SharedTileBundle(active_bundle_->GetPriority(), |
| 131 pending_bundle_->GetPriority()); |
| 132 first_run = false; |
| 133 } |
| 134 current_bundle_.AddTileAt(it.index_x(), it.index_y(), tile); |
| 135 } |
| 136 break; |
| 137 case eActivePriorityOnly: |
| 138 if (!active_bundle_) |
| 139 return false; |
| 140 |
| 141 for (TileBundle::Iterator it(active_bundle_); it; ++it) { |
| 142 if (pending_bundle_ && |
| 143 pending_bundle_->TileAt(it.index_x(), it.index_y()) == *it) |
| 144 continue; |
| 145 |
| 146 if (first_run) { |
| 147 current_bundle_ = SharedTileBundle(active_bundle_->GetPriority(), |
| 148 TilePriority()); |
| 149 first_run = false; |
| 150 } |
| 151 current_bundle_.AddTileAt(it.index_x(), it.index_y(), *it); |
| 152 } |
| 153 break; |
| 154 case ePendingPriorityOnly: |
| 155 if (!pending_bundle_) |
| 156 return false; |
| 157 |
| 158 for (TileBundle::Iterator it(pending_bundle_); it; ++it) { |
| 159 if (active_bundle_ && |
| 160 active_bundle_->TileAt(it.index_x(), it.index_y()) == *it) |
| 161 continue; |
| 162 |
| 163 if (first_run) { |
| 164 current_bundle_ = SharedTileBundle(TilePriority(), |
| 165 pending_bundle_->GetPriority()); |
| 166 first_run = false; |
| 167 } |
| 168 current_bundle_.AddTileAt(it.index_x(), it.index_y(), *it); |
| 169 } |
| 170 break; |
| 171 case eMaxSharedBundleTypes: |
| 172 NOTREACHED(); |
| 173 break; |
| 174 } |
| 175 return !first_run; |
| 176 } |
| 177 |
| 178 void BundleSetIterator::DetermineActivePendingBundles(TileBundle* bundle, |
| 179 TileBundle* twin_bundle) { |
| 180 if (twin_bundle && !twin_bundle->IsRecycled()) { |
| 181 if (bundle->IsActive()) { |
| 182 active_bundle_ = bundle; |
| 183 pending_bundle_ = twin_bundle; |
| 184 } else { |
| 185 active_bundle_ = twin_bundle; |
| 186 pending_bundle_ = bundle; |
| 187 } |
| 188 current_bundle_type_ = eBothPriorities; |
| 189 } else if (bundle->IsActive()) { |
| 190 active_bundle_ = bundle; |
| 191 current_bundle_type_ = eActivePriorityOnly; |
| 192 } else { |
| 193 pending_bundle_ = bundle; |
| 194 current_bundle_type_ = ePendingPriorityOnly; |
| 195 } |
| 196 } |
| 197 |
| 198 } // namespace cc |
| OLD | NEW |