| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/picture_layer_tiling_set.h" | 5 #include "cc/resources/picture_layer_tiling_set.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 return make_scoped_ptr(new PictureLayerTilingSet(client)); | 33 return make_scoped_ptr(new PictureLayerTilingSet(client)); |
| 34 } | 34 } |
| 35 | 35 |
| 36 PictureLayerTilingSet::PictureLayerTilingSet(PictureLayerTilingClient* client) | 36 PictureLayerTilingSet::PictureLayerTilingSet(PictureLayerTilingClient* client) |
| 37 : client_(client) { | 37 : client_(client) { |
| 38 } | 38 } |
| 39 | 39 |
| 40 PictureLayerTilingSet::~PictureLayerTilingSet() { | 40 PictureLayerTilingSet::~PictureLayerTilingSet() { |
| 41 } | 41 } |
| 42 | 42 |
| 43 void PictureLayerTilingSet::SetClient(PictureLayerTilingClient* client) { | 43 void PictureLayerTilingSet::UpdateTilingsToCurrentRasterSource( |
| 44 client_ = client; | 44 RasterSource* raster_source, |
| 45 for (size_t i = 0; i < tilings_.size(); ++i) | 45 const PictureLayerTilingSet* twin_set, |
| 46 tilings_[i]->SetClient(client_); | 46 const gfx::Size& layer_bounds, |
| 47 } | 47 const Region& layer_invalidation, |
| 48 float minimum_contents_scale) { |
| 49 RemoveTilingsBelowScale(minimum_contents_scale); |
| 48 | 50 |
| 49 void PictureLayerTilingSet::RemoveTilesInRegion(const Region& region) { | 51 // Copy over tilings that are shared with the |twin_set| tiling set (if it |
| 50 for (size_t i = 0; i < tilings_.size(); ++i) | 52 // exists). |
| 51 tilings_[i]->RemoveTilesInRegion(region); | 53 if (twin_set) { |
| 54 for (PictureLayerTiling* twin_tiling : twin_set->tilings_) { |
| 55 float contents_scale = twin_tiling->contents_scale(); |
| 56 DCHECK_GE(contents_scale, minimum_contents_scale); |
| 57 |
| 58 PictureLayerTiling* this_tiling = FindTilingWithScale(contents_scale); |
| 59 if (!this_tiling) { |
| 60 scoped_ptr<PictureLayerTiling> new_tiling = |
| 61 PictureLayerTiling::Create(contents_scale, layer_bounds, client_); |
| 62 tilings_.push_back(new_tiling.Pass()); |
| 63 this_tiling = tilings_.back(); |
| 64 } |
| 65 LOG(ERROR) << "Clone "; |
| 66 this_tiling->CloneTilesAndPropertiesFrom(*twin_tiling); |
| 67 } |
| 68 } |
| 69 |
| 70 // For unshared tilings, invalidate tiles and update them to the new raster |
| 71 // source. |
| 72 for (PictureLayerTiling* tiling : tilings_) { |
| 73 if (twin_set && twin_set->FindTilingWithScale(tiling->contents_scale())) |
| 74 continue; |
| 75 |
| 76 tiling->Resize(layer_bounds); |
| 77 LOG(ERROR) << "Invalidate " << layer_invalidation.ToString(); |
| 78 tiling->Invalidate(layer_invalidation); |
| 79 tiling->SetRasterSource(raster_source); |
| 80 // TODO(danakj): Is this needed anymore? Won't they already exist? |
| 81 tiling->CreateMissingTilesInLiveTilesRect(); |
| 82 |
| 83 // If |twin_set| is present, use the resolutions from there. Otherwise leave |
| 84 // all resolutions as they are. |
| 85 if (twin_set) |
| 86 tiling->set_resolution(NON_IDEAL_RESOLUTION); |
| 87 } |
| 88 |
| 89 tilings_.sort(LargestToSmallestScaleFunctor()); |
| 90 |
| 91 #if DCHECK_IS_ON |
| 92 for (PictureLayerTiling* tiling : tilings_) { |
| 93 DCHECK(tiling->tile_size() == |
| 94 client_->CalculateTileSize(tiling->tiling_size())) |
| 95 << "tile_size: " << tiling->tile_size().ToString() |
| 96 << " tiling_size: " << tiling->tiling_size().ToString() |
| 97 << " CalculateTileSize: " |
| 98 << client_->CalculateTileSize(tiling->tiling_size()).ToString(); |
| 99 } |
| 100 |
| 101 if (!tilings_.empty()) { |
| 102 size_t num_high_res = std::count_if(tilings_.begin(), tilings_.end(), |
| 103 [](PictureLayerTiling* tiling) { |
| 104 return tiling->resolution() == HIGH_RESOLUTION; |
| 105 }); |
| 106 DCHECK_EQ(1u, num_high_res); |
| 107 } |
| 108 #endif |
| 52 } | 109 } |
| 53 | 110 |
| 54 void PictureLayerTilingSet::CleanUpTilings( | 111 void PictureLayerTilingSet::CleanUpTilings( |
| 55 float min_acceptable_high_res_scale, | 112 float min_acceptable_high_res_scale, |
| 56 float max_acceptable_high_res_scale, | 113 float max_acceptable_high_res_scale, |
| 57 const std::vector<PictureLayerTiling*>& needed_tilings, | 114 const std::vector<PictureLayerTiling*>& needed_tilings, |
| 58 bool should_have_low_res, | 115 bool should_have_low_res, |
| 59 PictureLayerTilingSet* twin_set, | 116 PictureLayerTilingSet* twin_set, |
| 60 PictureLayerTilingSet* recycled_twin_set) { | 117 PictureLayerTilingSet* recycled_twin_set) { |
| 61 float twin_low_res_scale = 0.f; | 118 float twin_low_res_scale = 0.f; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 84 // Don't remove tilings that are required. | 141 // Don't remove tilings that are required. |
| 85 if (std::find(needed_tilings.begin(), needed_tilings.end(), tiling) != | 142 if (std::find(needed_tilings.begin(), needed_tilings.end(), tiling) != |
| 86 needed_tilings.end()) { | 143 needed_tilings.end()) { |
| 87 continue; | 144 continue; |
| 88 } | 145 } |
| 89 | 146 |
| 90 to_remove.push_back(tiling); | 147 to_remove.push_back(tiling); |
| 91 } | 148 } |
| 92 | 149 |
| 93 for (auto* tiling : to_remove) { | 150 for (auto* tiling : to_remove) { |
| 94 PictureLayerTiling* twin_tiling = | |
| 95 twin_set ? twin_set->FindTilingWithScale(tiling->contents_scale()) | |
| 96 : nullptr; | |
| 97 // Only remove tilings from the twin layer if they have | |
| 98 // NON_IDEAL_RESOLUTION. | |
| 99 if (twin_tiling && twin_tiling->resolution() == NON_IDEAL_RESOLUTION) | |
| 100 twin_set->Remove(twin_tiling); | |
| 101 | |
| 102 PictureLayerTiling* recycled_twin_tiling = | 151 PictureLayerTiling* recycled_twin_tiling = |
| 103 recycled_twin_set | 152 recycled_twin_set |
| 104 ? recycled_twin_set->FindTilingWithScale(tiling->contents_scale()) | 153 ? recycled_twin_set->FindTilingWithScale(tiling->contents_scale()) |
| 105 : nullptr; | 154 : nullptr; |
| 106 // Remove the tiling from the recycle tree. Note that we ignore resolution, | 155 // Remove the tiling from the recycle tree. Note that we ignore resolution, |
| 107 // since we don't need to maintain high/low res on the recycle set. | 156 // since we don't need to maintain high/low res on the recycle set. |
| 108 if (recycled_twin_tiling) | 157 if (recycled_twin_tiling) |
| 109 recycled_twin_set->Remove(recycled_twin_tiling); | 158 recycled_twin_set->Remove(recycled_twin_tiling); |
| 110 | 159 |
| 111 DCHECK_NE(HIGH_RESOLUTION, tiling->resolution()); | 160 DCHECK_NE(HIGH_RESOLUTION, tiling->resolution()); |
| 112 Remove(tiling); | 161 Remove(tiling); |
| 113 } | 162 } |
| 114 } | 163 } |
| 115 | 164 |
| 165 void PictureLayerTilingSet::RemoveNonIdealTilings() { |
| 166 auto to_remove = tilings_.remove_if([](PictureLayerTiling* t) -> bool { |
| 167 return t->resolution() == NON_IDEAL_RESOLUTION; |
| 168 }); |
| 169 tilings_.erase(to_remove, tilings_.end()); |
| 170 } |
| 171 |
| 116 void PictureLayerTilingSet::MarkAllTilingsNonIdeal() { | 172 void PictureLayerTilingSet::MarkAllTilingsNonIdeal() { |
| 117 for (auto* tiling : tilings_) | 173 for (auto* tiling : tilings_) |
| 118 tiling->set_resolution(NON_IDEAL_RESOLUTION); | 174 tiling->set_resolution(NON_IDEAL_RESOLUTION); |
| 119 } | 175 } |
| 120 | 176 |
| 121 bool PictureLayerTilingSet::SyncTilings(const PictureLayerTilingSet& other, | 177 bool PictureLayerTilingSet::SyncTilingsForTesting( |
| 122 const gfx::Size& new_layer_bounds, | 178 const PictureLayerTilingSet& other, |
| 123 const Region& layer_invalidation, | 179 const gfx::Size& new_layer_bounds, |
| 124 float minimum_contents_scale, | 180 const Region& layer_invalidation, |
| 125 RasterSource* raster_source) { | 181 float minimum_contents_scale, |
| 182 RasterSource* raster_source) { |
| 126 if (new_layer_bounds.IsEmpty()) { | 183 if (new_layer_bounds.IsEmpty()) { |
| 127 RemoveAllTilings(); | 184 RemoveAllTilings(); |
| 128 return false; | 185 return false; |
| 129 } | 186 } |
| 130 | 187 |
| 131 tilings_.reserve(other.tilings_.size()); | 188 tilings_.reserve(other.tilings_.size()); |
| 132 | 189 |
| 133 // Remove any tilings that aren't in |other| or don't meet the minimum. | 190 // Remove any tilings that aren't in |other| or don't meet the minimum. |
| 134 for (size_t i = 0; i < tilings_.size(); ++i) { | 191 for (size_t i = 0; i < tilings_.size(); ++i) { |
| 135 float scale = tilings_[i]->contents_scale(); | 192 float scale = tilings_[i]->contents_scale(); |
| 136 if (scale >= minimum_contents_scale && !!other.FindTilingWithScale(scale)) | 193 if (scale >= minimum_contents_scale && !!other.FindTilingWithScale(scale)) |
| 137 continue; | 194 continue; |
| 138 // Swap with the last element and remove it. | 195 // Swap with the last element and remove it. |
| 139 tilings_.swap(tilings_.begin() + i, tilings_.end() - 1); | 196 tilings_.swap(tilings_.begin() + i, tilings_.end() - 1); |
| 140 tilings_.pop_back(); | 197 tilings_.pop_back(); |
| 141 --i; | 198 --i; |
| 142 } | 199 } |
| 143 | 200 |
| 144 bool have_high_res_tiling = false; | 201 bool have_high_res_tiling = false; |
| 145 | 202 |
| 146 // Add any missing tilings from |other| that meet the minimum. | 203 // Add any missing tilings from |other| that meet the minimum. |
| 147 for (size_t i = 0; i < other.tilings_.size(); ++i) { | 204 for (size_t i = 0; i < other.tilings_.size(); ++i) { |
| 148 float contents_scale = other.tilings_[i]->contents_scale(); | 205 float contents_scale = other.tilings_[i]->contents_scale(); |
| 149 if (contents_scale < minimum_contents_scale) | 206 if (contents_scale < minimum_contents_scale) |
| 150 continue; | 207 continue; |
| 151 if (PictureLayerTiling* this_tiling = FindTilingWithScale(contents_scale)) { | 208 if (PictureLayerTiling* this_tiling = FindTilingWithScale(contents_scale)) { |
| 152 this_tiling->set_resolution(other.tilings_[i]->resolution()); | 209 this_tiling->set_resolution(other.tilings_[i]->resolution()); |
| 153 | 210 |
| 154 this_tiling->UpdateTilesToCurrentRasterSource( | 211 this_tiling->Resize(new_layer_bounds); |
| 155 raster_source, layer_invalidation, new_layer_bounds); | 212 this_tiling->Invalidate(layer_invalidation); |
| 213 this_tiling->SetRasterSource(raster_source); |
| 156 this_tiling->CreateMissingTilesInLiveTilesRect(); | 214 this_tiling->CreateMissingTilesInLiveTilesRect(); |
| 157 if (this_tiling->resolution() == HIGH_RESOLUTION) | 215 if (this_tiling->resolution() == HIGH_RESOLUTION) |
| 158 have_high_res_tiling = true; | 216 have_high_res_tiling = true; |
| 159 | 217 |
| 160 DCHECK(this_tiling->tile_size() == | 218 DCHECK(this_tiling->tile_size() == |
| 161 client_->CalculateTileSize(this_tiling->tiling_size())) | 219 client_->CalculateTileSize(this_tiling->tiling_size())) |
| 162 << "tile_size: " << this_tiling->tile_size().ToString() | 220 << "tile_size: " << this_tiling->tile_size().ToString() |
| 163 << " tiling_size: " << this_tiling->tiling_size().ToString() | 221 << " tiling_size: " << this_tiling->tiling_size().ToString() |
| 164 << " CalculateTileSize: " | 222 << " CalculateTileSize: " |
| 165 << client_->CalculateTileSize(this_tiling->tiling_size()).ToString(); | 223 << client_->CalculateTileSize(this_tiling->tiling_size()).ToString(); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 TileResolution resolution) const { | 273 TileResolution resolution) const { |
| 216 auto iter = std::find_if(tilings_.begin(), tilings_.end(), | 274 auto iter = std::find_if(tilings_.begin(), tilings_.end(), |
| 217 [resolution](const PictureLayerTiling* tiling) { | 275 [resolution](const PictureLayerTiling* tiling) { |
| 218 return tiling->resolution() == resolution; | 276 return tiling->resolution() == resolution; |
| 219 }); | 277 }); |
| 220 if (iter == tilings_.end()) | 278 if (iter == tilings_.end()) |
| 221 return NULL; | 279 return NULL; |
| 222 return *iter; | 280 return *iter; |
| 223 } | 281 } |
| 224 | 282 |
| 283 void PictureLayerTilingSet::RemoveTilingsBelowScale(float minimum_scale) { |
| 284 auto to_remove = |
| 285 tilings_.remove_if([minimum_scale](PictureLayerTiling* tiling) -> bool { |
| 286 return tiling->contents_scale() < minimum_scale; |
| 287 }); |
| 288 tilings_.erase(to_remove, tilings_.end()); |
| 289 } |
| 290 |
| 225 void PictureLayerTilingSet::RemoveAllTilings() { | 291 void PictureLayerTilingSet::RemoveAllTilings() { |
| 226 tilings_.clear(); | 292 tilings_.clear(); |
| 227 } | 293 } |
| 228 | 294 |
| 229 void PictureLayerTilingSet::Remove(PictureLayerTiling* tiling) { | 295 void PictureLayerTilingSet::Remove(PictureLayerTiling* tiling) { |
| 230 ScopedPtrVector<PictureLayerTiling>::iterator iter = | 296 ScopedPtrVector<PictureLayerTiling>::iterator iter = |
| 231 std::find(tilings_.begin(), tilings_.end(), tiling); | 297 std::find(tilings_.begin(), tilings_.end(), tiling); |
| 232 if (iter == tilings_.end()) | 298 if (iter == tilings_.end()) |
| 233 return; | 299 return; |
| 234 tilings_.erase(iter); | 300 tilings_.erase(iter); |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 case LOWER_THAN_LOW_RES: | 584 case LOWER_THAN_LOW_RES: |
| 519 range = TilingRange(low_res_range.end, tilings_.size()); | 585 range = TilingRange(low_res_range.end, tilings_.size()); |
| 520 break; | 586 break; |
| 521 } | 587 } |
| 522 | 588 |
| 523 DCHECK_LE(range.start, range.end); | 589 DCHECK_LE(range.start, range.end); |
| 524 return range; | 590 return range; |
| 525 } | 591 } |
| 526 | 592 |
| 527 } // namespace cc | 593 } // namespace cc |
| OLD | NEW |