| 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 | 10 | 
| 10 namespace cc { | 11 namespace cc { | 
| 11 | 12 | 
| 12 namespace { | 13 namespace { | 
| 13 | 14 | 
| 14 class LargestToSmallestScaleFunctor { | 15 class LargestToSmallestScaleFunctor { | 
| 15  public: | 16  public: | 
| 16   bool operator() (PictureLayerTiling* left, PictureLayerTiling* right) { | 17   bool operator() (PictureLayerTiling* left, PictureLayerTiling* right) { | 
| 17     return left->contents_scale() > right->contents_scale(); | 18     return left->contents_scale() > right->contents_scale(); | 
| 18   } | 19   } | 
| (...skipping 24 matching lines...) Expand all  Loading... | 
| 43   client_ = client; | 44   client_ = client; | 
| 44   for (size_t i = 0; i < tilings_.size(); ++i) | 45   for (size_t i = 0; i < tilings_.size(); ++i) | 
| 45     tilings_[i]->SetClient(client_); | 46     tilings_[i]->SetClient(client_); | 
| 46 } | 47 } | 
| 47 | 48 | 
| 48 void PictureLayerTilingSet::RemoveTilesInRegion(const Region& region) { | 49 void PictureLayerTilingSet::RemoveTilesInRegion(const Region& region) { | 
| 49   for (size_t i = 0; i < tilings_.size(); ++i) | 50   for (size_t i = 0; i < tilings_.size(); ++i) | 
| 50     tilings_[i]->RemoveTilesInRegion(region); | 51     tilings_[i]->RemoveTilesInRegion(region); | 
| 51 } | 52 } | 
| 52 | 53 | 
|  | 54 void PictureLayerTilingSet::CleanUpTilings( | 
|  | 55     float min_acceptable_high_res_scale, | 
|  | 56     float max_acceptable_high_res_scale, | 
|  | 57     const std::vector<PictureLayerTiling*>& needed_tilings, | 
|  | 58     bool should_have_low_res, | 
|  | 59     PictureLayerTilingSet* twin_set, | 
|  | 60     PictureLayerTilingSet* recycled_twin_set) { | 
|  | 61   float twin_low_res_scale = 0.f; | 
|  | 62   if (twin_set) { | 
|  | 63     PictureLayerTiling* tiling = | 
|  | 64         twin_set->FindTilingWithResolution(LOW_RESOLUTION); | 
|  | 65     if (tiling) | 
|  | 66       twin_low_res_scale = tiling->contents_scale(); | 
|  | 67   } | 
|  | 68 | 
|  | 69   std::vector<PictureLayerTiling*> to_remove; | 
|  | 70   for (auto* tiling : tilings_) { | 
|  | 71     // Keep all tilings within the min/max scales. | 
|  | 72     if (tiling->contents_scale() >= min_acceptable_high_res_scale && | 
|  | 73         tiling->contents_scale() <= max_acceptable_high_res_scale) { | 
|  | 74       continue; | 
|  | 75     } | 
|  | 76 | 
|  | 77     // Keep low resolution tilings, if the tiling set should have them. | 
|  | 78     if (should_have_low_res && | 
|  | 79         (tiling->resolution() == LOW_RESOLUTION || | 
|  | 80          tiling->contents_scale() == twin_low_res_scale)) { | 
|  | 81       continue; | 
|  | 82     } | 
|  | 83 | 
|  | 84     // Don't remove tilings that are required. | 
|  | 85     if (std::find(needed_tilings.begin(), needed_tilings.end(), tiling) != | 
|  | 86         needed_tilings.end()) { | 
|  | 87       continue; | 
|  | 88     } | 
|  | 89 | 
|  | 90     to_remove.push_back(tiling); | 
|  | 91   } | 
|  | 92 | 
|  | 93   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 = | 
|  | 103         recycled_twin_set | 
|  | 104             ? recycled_twin_set->FindTilingWithScale(tiling->contents_scale()) | 
|  | 105             : nullptr; | 
|  | 106     // 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. | 
|  | 108     if (recycled_twin_tiling) | 
|  | 109       recycled_twin_set->Remove(recycled_twin_tiling); | 
|  | 110 | 
|  | 111     DCHECK_NE(HIGH_RESOLUTION, tiling->resolution()); | 
|  | 112     Remove(tiling); | 
|  | 113   } | 
|  | 114 } | 
|  | 115 | 
| 53 void PictureLayerTilingSet::MarkAllTilingsNonIdeal() { | 116 void PictureLayerTilingSet::MarkAllTilingsNonIdeal() { | 
| 54   for (auto* tiling : tilings_) | 117   for (auto* tiling : tilings_) | 
| 55     tiling->set_resolution(NON_IDEAL_RESOLUTION); | 118     tiling->set_resolution(NON_IDEAL_RESOLUTION); | 
| 56 } | 119 } | 
| 57 | 120 | 
| 58 bool PictureLayerTilingSet::SyncTilings(const PictureLayerTilingSet& other, | 121 bool PictureLayerTilingSet::SyncTilings(const PictureLayerTilingSet& other, | 
| 59                                         const gfx::Size& new_layer_bounds, | 122                                         const gfx::Size& new_layer_bounds, | 
| 60                                         const Region& layer_invalidation, | 123                                         const Region& layer_invalidation, | 
| 61                                         float minimum_contents_scale, | 124                                         float minimum_contents_scale, | 
| 62                                         RasterSource* raster_source) { | 125                                         RasterSource* raster_source) { | 
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 164 } | 227 } | 
| 165 | 228 | 
| 166 void PictureLayerTilingSet::Remove(PictureLayerTiling* tiling) { | 229 void PictureLayerTilingSet::Remove(PictureLayerTiling* tiling) { | 
| 167   ScopedPtrVector<PictureLayerTiling>::iterator iter = | 230   ScopedPtrVector<PictureLayerTiling>::iterator iter = | 
| 168     std::find(tilings_.begin(), tilings_.end(), tiling); | 231     std::find(tilings_.begin(), tilings_.end(), tiling); | 
| 169   if (iter == tilings_.end()) | 232   if (iter == tilings_.end()) | 
| 170     return; | 233     return; | 
| 171   tilings_.erase(iter); | 234   tilings_.erase(iter); | 
| 172 } | 235 } | 
| 173 | 236 | 
| 174 void PictureLayerTilingSet::RemoveTilingWithScale(float scale) { |  | 
| 175   auto iter = std::find_if(tilings_.begin(), tilings_.end(), |  | 
| 176                            [scale](const PictureLayerTiling* tiling) { |  | 
| 177     return tiling->contents_scale() == scale; |  | 
| 178   }); |  | 
| 179   if (iter == tilings_.end()) |  | 
| 180     return; |  | 
| 181   tilings_.erase(iter); |  | 
| 182 } |  | 
| 183 |  | 
| 184 void PictureLayerTilingSet::RemoveAllTiles() { | 237 void PictureLayerTilingSet::RemoveAllTiles() { | 
| 185   for (size_t i = 0; i < tilings_.size(); ++i) | 238   for (size_t i = 0; i < tilings_.size(); ++i) | 
| 186     tilings_[i]->Reset(); | 239     tilings_[i]->Reset(); | 
| 187 } | 240 } | 
| 188 | 241 | 
| 189 float PictureLayerTilingSet::GetSnappedContentsScale( | 242 float PictureLayerTilingSet::GetSnappedContentsScale( | 
| 190     float start_scale, | 243     float start_scale, | 
| 191     float snap_to_existing_tiling_ratio) const { | 244     float snap_to_existing_tiling_ratio) const { | 
| 192   // If a tiling exists within the max snapping ratio, snap to its scale. | 245   // If a tiling exists within the max snapping ratio, snap to its scale. | 
| 193   float snapped_contents_scale = start_scale; | 246   float snapped_contents_scale = start_scale; | 
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 465     case LOWER_THAN_LOW_RES: | 518     case LOWER_THAN_LOW_RES: | 
| 466       range = TilingRange(low_res_range.end, tilings_.size()); | 519       range = TilingRange(low_res_range.end, tilings_.size()); | 
| 467       break; | 520       break; | 
| 468   } | 521   } | 
| 469 | 522 | 
| 470   DCHECK_LE(range.start, range.end); | 523   DCHECK_LE(range.start, range.end); | 
| 471   return range; | 524   return range; | 
| 472 } | 525 } | 
| 473 | 526 | 
| 474 }  // namespace cc | 527 }  // namespace cc | 
| OLD | NEW | 
|---|