Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Side by Side Diff: cc/resources/picture_layer_tiling_set.cc

Issue 640063010: cc: Don't swap PictureLayerTilingSet on activate. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: noswap: RemoveLOGERRORs Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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_) {
vmpstr 2014/12/09 00:10:19 I feel like we could do better in terms of speed..
danakj 2014/12/09 18:20:23 Writing something much faster here would be very c
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 this_tiling->CloneTilesAndPropertiesFrom(*twin_tiling);
66 }
67 }
68
69 // For unshared tilings, invalidate tiles and update them to the new raster
70 // source.
71 for (PictureLayerTiling* tiling : tilings_) {
72 if (twin_set && twin_set->FindTilingWithScale(tiling->contents_scale()))
73 continue;
74
75 tiling->Resize(layer_bounds);
76 tiling->Invalidate(layer_invalidation);
77 tiling->SetRasterSource(raster_source);
78 // TODO(danakj): Is this needed anymore? Won't they already exist?
79 tiling->CreateMissingTilesInLiveTilesRect();
80
81 // If |twin_set| is present, use the resolutions from there. Otherwise leave
82 // all resolutions as they are.
83 if (twin_set)
84 tiling->set_resolution(NON_IDEAL_RESOLUTION);
85 }
86
87 tilings_.sort(LargestToSmallestScaleFunctor());
88
89 #if DCHECK_IS_ON
90 for (PictureLayerTiling* tiling : tilings_) {
91 DCHECK(tiling->tile_size() ==
92 client_->CalculateTileSize(tiling->tiling_size()))
93 << "tile_size: " << tiling->tile_size().ToString()
94 << " tiling_size: " << tiling->tiling_size().ToString()
95 << " CalculateTileSize: "
96 << client_->CalculateTileSize(tiling->tiling_size()).ToString();
97 }
98
99 if (!tilings_.empty()) {
100 size_t num_high_res = std::count_if(tilings_.begin(), tilings_.end(),
101 [](PictureLayerTiling* tiling) {
102 return tiling->resolution() == HIGH_RESOLUTION;
103 });
104 DCHECK_EQ(1u, num_high_res);
105 }
106 #endif
52 } 107 }
53 108
54 void PictureLayerTilingSet::CleanUpTilings( 109 void PictureLayerTilingSet::CleanUpTilings(
55 float min_acceptable_high_res_scale, 110 float min_acceptable_high_res_scale,
56 float max_acceptable_high_res_scale, 111 float max_acceptable_high_res_scale,
57 const std::vector<PictureLayerTiling*>& needed_tilings, 112 const std::vector<PictureLayerTiling*>& needed_tilings,
58 bool should_have_low_res, 113 bool should_have_low_res,
59 PictureLayerTilingSet* twin_set, 114 PictureLayerTilingSet* twin_set,
60 PictureLayerTilingSet* recycled_twin_set) { 115 PictureLayerTilingSet* recycled_twin_set) {
61 float twin_low_res_scale = 0.f; 116 float twin_low_res_scale = 0.f;
(...skipping 22 matching lines...) Expand all
84 // Don't remove tilings that are required. 139 // Don't remove tilings that are required.
85 if (std::find(needed_tilings.begin(), needed_tilings.end(), tiling) != 140 if (std::find(needed_tilings.begin(), needed_tilings.end(), tiling) !=
86 needed_tilings.end()) { 141 needed_tilings.end()) {
87 continue; 142 continue;
88 } 143 }
89 144
90 to_remove.push_back(tiling); 145 to_remove.push_back(tiling);
91 } 146 }
92 147
93 for (auto* tiling : to_remove) { 148 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 = 149 PictureLayerTiling* recycled_twin_tiling =
103 recycled_twin_set 150 recycled_twin_set
104 ? recycled_twin_set->FindTilingWithScale(tiling->contents_scale()) 151 ? recycled_twin_set->FindTilingWithScale(tiling->contents_scale())
105 : nullptr; 152 : nullptr;
106 // Remove the tiling from the recycle tree. Note that we ignore resolution, 153 // 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. 154 // since we don't need to maintain high/low res on the recycle set.
108 if (recycled_twin_tiling) 155 if (recycled_twin_tiling)
109 recycled_twin_set->Remove(recycled_twin_tiling); 156 recycled_twin_set->Remove(recycled_twin_tiling);
110 157
111 DCHECK_NE(HIGH_RESOLUTION, tiling->resolution()); 158 DCHECK_NE(HIGH_RESOLUTION, tiling->resolution());
112 Remove(tiling); 159 Remove(tiling);
113 } 160 }
114 } 161 }
115 162
163 void PictureLayerTilingSet::RemoveNonIdealTilings() {
164 auto to_remove = tilings_.remove_if([](PictureLayerTiling* t) -> bool {
vmpstr 2014/12/09 00:10:19 -> bool is optional here? Or are we requiring it?
danakj 2014/12/09 18:20:23 "However, if a lambda has one statement and that s
165 return t->resolution() == NON_IDEAL_RESOLUTION;
166 });
167 tilings_.erase(to_remove, tilings_.end());
168 }
169
116 void PictureLayerTilingSet::MarkAllTilingsNonIdeal() { 170 void PictureLayerTilingSet::MarkAllTilingsNonIdeal() {
117 for (auto* tiling : tilings_) 171 for (auto* tiling : tilings_)
118 tiling->set_resolution(NON_IDEAL_RESOLUTION); 172 tiling->set_resolution(NON_IDEAL_RESOLUTION);
119 } 173 }
120 174
121 bool PictureLayerTilingSet::SyncTilings(const PictureLayerTilingSet& other, 175 bool PictureLayerTilingSet::SyncTilingsForTesting(
122 const gfx::Size& new_layer_bounds, 176 const PictureLayerTilingSet& other,
123 const Region& layer_invalidation, 177 const gfx::Size& new_layer_bounds,
124 float minimum_contents_scale, 178 const Region& layer_invalidation,
125 RasterSource* raster_source) { 179 float minimum_contents_scale,
180 RasterSource* raster_source) {
126 if (new_layer_bounds.IsEmpty()) { 181 if (new_layer_bounds.IsEmpty()) {
127 RemoveAllTilings(); 182 RemoveAllTilings();
128 return false; 183 return false;
129 } 184 }
130 185
131 tilings_.reserve(other.tilings_.size()); 186 tilings_.reserve(other.tilings_.size());
132 187
133 // Remove any tilings that aren't in |other| or don't meet the minimum. 188 // Remove any tilings that aren't in |other| or don't meet the minimum.
134 for (size_t i = 0; i < tilings_.size(); ++i) { 189 for (size_t i = 0; i < tilings_.size(); ++i) {
135 float scale = tilings_[i]->contents_scale(); 190 float scale = tilings_[i]->contents_scale();
136 if (scale >= minimum_contents_scale && !!other.FindTilingWithScale(scale)) 191 if (scale >= minimum_contents_scale && !!other.FindTilingWithScale(scale))
137 continue; 192 continue;
138 // Swap with the last element and remove it. 193 // Swap with the last element and remove it.
139 tilings_.swap(tilings_.begin() + i, tilings_.end() - 1); 194 tilings_.swap(tilings_.begin() + i, tilings_.end() - 1);
140 tilings_.pop_back(); 195 tilings_.pop_back();
141 --i; 196 --i;
142 } 197 }
143 198
144 bool have_high_res_tiling = false; 199 bool have_high_res_tiling = false;
145 200
146 // Add any missing tilings from |other| that meet the minimum. 201 // Add any missing tilings from |other| that meet the minimum.
147 for (size_t i = 0; i < other.tilings_.size(); ++i) { 202 for (size_t i = 0; i < other.tilings_.size(); ++i) {
148 float contents_scale = other.tilings_[i]->contents_scale(); 203 float contents_scale = other.tilings_[i]->contents_scale();
149 if (contents_scale < minimum_contents_scale) 204 if (contents_scale < minimum_contents_scale)
150 continue; 205 continue;
151 if (PictureLayerTiling* this_tiling = FindTilingWithScale(contents_scale)) { 206 if (PictureLayerTiling* this_tiling = FindTilingWithScale(contents_scale)) {
152 this_tiling->set_resolution(other.tilings_[i]->resolution()); 207 this_tiling->set_resolution(other.tilings_[i]->resolution());
153 208
154 this_tiling->UpdateTilesToCurrentRasterSource( 209 this_tiling->Resize(new_layer_bounds);
155 raster_source, layer_invalidation, new_layer_bounds); 210 this_tiling->Invalidate(layer_invalidation);
211 this_tiling->SetRasterSource(raster_source);
156 this_tiling->CreateMissingTilesInLiveTilesRect(); 212 this_tiling->CreateMissingTilesInLiveTilesRect();
157 if (this_tiling->resolution() == HIGH_RESOLUTION) 213 if (this_tiling->resolution() == HIGH_RESOLUTION)
158 have_high_res_tiling = true; 214 have_high_res_tiling = true;
159 215
160 DCHECK(this_tiling->tile_size() == 216 DCHECK(this_tiling->tile_size() ==
161 client_->CalculateTileSize(this_tiling->tiling_size())) 217 client_->CalculateTileSize(this_tiling->tiling_size()))
162 << "tile_size: " << this_tiling->tile_size().ToString() 218 << "tile_size: " << this_tiling->tile_size().ToString()
163 << " tiling_size: " << this_tiling->tiling_size().ToString() 219 << " tiling_size: " << this_tiling->tiling_size().ToString()
164 << " CalculateTileSize: " 220 << " CalculateTileSize: "
165 << client_->CalculateTileSize(this_tiling->tiling_size()).ToString(); 221 << client_->CalculateTileSize(this_tiling->tiling_size()).ToString();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 TileResolution resolution) const { 271 TileResolution resolution) const {
216 auto iter = std::find_if(tilings_.begin(), tilings_.end(), 272 auto iter = std::find_if(tilings_.begin(), tilings_.end(),
217 [resolution](const PictureLayerTiling* tiling) { 273 [resolution](const PictureLayerTiling* tiling) {
218 return tiling->resolution() == resolution; 274 return tiling->resolution() == resolution;
219 }); 275 });
220 if (iter == tilings_.end()) 276 if (iter == tilings_.end())
221 return NULL; 277 return NULL;
222 return *iter; 278 return *iter;
223 } 279 }
224 280
281 void PictureLayerTilingSet::RemoveTilingsBelowScale(float minimum_scale) {
282 auto to_remove =
283 tilings_.remove_if([minimum_scale](PictureLayerTiling* tiling) -> bool {
284 return tiling->contents_scale() < minimum_scale;
285 });
286 tilings_.erase(to_remove, tilings_.end());
287 }
288
225 void PictureLayerTilingSet::RemoveAllTilings() { 289 void PictureLayerTilingSet::RemoveAllTilings() {
226 tilings_.clear(); 290 tilings_.clear();
227 } 291 }
228 292
229 void PictureLayerTilingSet::Remove(PictureLayerTiling* tiling) { 293 void PictureLayerTilingSet::Remove(PictureLayerTiling* tiling) {
230 ScopedPtrVector<PictureLayerTiling>::iterator iter = 294 ScopedPtrVector<PictureLayerTiling>::iterator iter =
231 std::find(tilings_.begin(), tilings_.end(), tiling); 295 std::find(tilings_.begin(), tilings_.end(), tiling);
232 if (iter == tilings_.end()) 296 if (iter == tilings_.end())
233 return; 297 return;
234 tilings_.erase(iter); 298 tilings_.erase(iter);
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 case LOWER_THAN_LOW_RES: 582 case LOWER_THAN_LOW_RES:
519 range = TilingRange(low_res_range.end, tilings_.size()); 583 range = TilingRange(low_res_range.end, tilings_.size());
520 break; 584 break;
521 } 585 }
522 586
523 DCHECK_LE(range.start, range.end); 587 DCHECK_LE(range.start, range.end);
524 return range; 588 return range;
525 } 589 }
526 590
527 } // namespace cc 591 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698