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

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

Issue 812543002: Update from https://crrev.com/308331 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: 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 11 matching lines...) Expand all
22 inline float LargerRatio(float float1, float float2) { 22 inline float LargerRatio(float float1, float float2) {
23 DCHECK_GT(float1, 0.f); 23 DCHECK_GT(float1, 0.f);
24 DCHECK_GT(float2, 0.f); 24 DCHECK_GT(float2, 0.f);
25 return float1 > float2 ? float1 / float2 : float2 / float1; 25 return float1 > float2 ? float1 / float2 : float2 / float1;
26 } 26 }
27 27
28 } // namespace 28 } // namespace
29 29
30 // static 30 // static
31 scoped_ptr<PictureLayerTilingSet> PictureLayerTilingSet::Create( 31 scoped_ptr<PictureLayerTilingSet> PictureLayerTilingSet::Create(
32 PictureLayerTilingClient* client) { 32 PictureLayerTilingClient* client,
33 return make_scoped_ptr(new PictureLayerTilingSet(client)); 33 size_t max_tiles_for_interest_area,
34 float skewport_target_time_in_seconds,
35 int skewport_extrapolation_limit_in_content_pixels) {
36 return make_scoped_ptr(new PictureLayerTilingSet(
37 client, max_tiles_for_interest_area, skewport_target_time_in_seconds,
38 skewport_extrapolation_limit_in_content_pixels));
34 } 39 }
35 40
36 PictureLayerTilingSet::PictureLayerTilingSet(PictureLayerTilingClient* client) 41 PictureLayerTilingSet::PictureLayerTilingSet(
37 : client_(client) { 42 PictureLayerTilingClient* client,
43 size_t max_tiles_for_interest_area,
44 float skewport_target_time_in_seconds,
45 int skewport_extrapolation_limit_in_content_pixels)
46 : max_tiles_for_interest_area_(max_tiles_for_interest_area),
47 skewport_target_time_in_seconds_(skewport_target_time_in_seconds),
48 skewport_extrapolation_limit_in_content_pixels_(
49 skewport_extrapolation_limit_in_content_pixels),
50 client_(client) {
38 } 51 }
39 52
40 PictureLayerTilingSet::~PictureLayerTilingSet() { 53 PictureLayerTilingSet::~PictureLayerTilingSet() {
41 } 54 }
42 55
43 void PictureLayerTilingSet::SetClient(PictureLayerTilingClient* client) { 56 void PictureLayerTilingSet::UpdateTilingsToCurrentRasterSource(
44 client_ = client; 57 RasterSource* raster_source,
45 for (size_t i = 0; i < tilings_.size(); ++i) 58 const PictureLayerTilingSet* twin_set,
46 tilings_[i]->SetClient(client_); 59 const gfx::Size& layer_bounds,
47 } 60 const Region& layer_invalidation,
61 float minimum_contents_scale) {
62 RemoveTilingsBelowScale(minimum_contents_scale);
48 63
49 void PictureLayerTilingSet::RemoveTilesInRegion(const Region& region) { 64 // Copy over tilings that are shared with the |twin_set| tiling set (if it
50 for (size_t i = 0; i < tilings_.size(); ++i) 65 // exists).
51 tilings_[i]->RemoveTilesInRegion(region); 66 if (twin_set) {
67 for (PictureLayerTiling* twin_tiling : twin_set->tilings_) {
68 float contents_scale = twin_tiling->contents_scale();
69 DCHECK_GE(contents_scale, minimum_contents_scale);
70
71 PictureLayerTiling* this_tiling = FindTilingWithScale(contents_scale);
72 if (!this_tiling) {
73 scoped_ptr<PictureLayerTiling> new_tiling = PictureLayerTiling::Create(
74 contents_scale, layer_bounds, client_, max_tiles_for_interest_area_,
75 skewport_target_time_in_seconds_,
76 skewport_extrapolation_limit_in_content_pixels_);
77 tilings_.push_back(new_tiling.Pass());
78 this_tiling = tilings_.back();
79 }
80 this_tiling->CloneTilesAndPropertiesFrom(*twin_tiling);
81 }
82 }
83
84 // For unshared tilings, invalidate tiles and update them to the new raster
85 // source.
86 for (PictureLayerTiling* tiling : tilings_) {
87 if (twin_set && twin_set->FindTilingWithScale(tiling->contents_scale()))
88 continue;
89
90 tiling->Resize(layer_bounds);
91 tiling->Invalidate(layer_invalidation);
92 tiling->SetRasterSource(raster_source);
93 // This is needed for cases where the live tiles rect didn't change but
94 // recordings exist in the raster source that did not exist on the last
95 // raster source.
96 tiling->CreateMissingTilesInLiveTilesRect();
97
98 // If |twin_set| is present, use the resolutions from there. Otherwise leave
99 // all resolutions as they are.
100 if (twin_set)
101 tiling->set_resolution(NON_IDEAL_RESOLUTION);
102 }
103
104 tilings_.sort(LargestToSmallestScaleFunctor());
105
106 #if DCHECK_IS_ON
107 for (PictureLayerTiling* tiling : tilings_) {
108 DCHECK(tiling->tile_size() ==
109 client_->CalculateTileSize(tiling->tiling_size()))
110 << "tile_size: " << tiling->tile_size().ToString()
111 << " tiling_size: " << tiling->tiling_size().ToString()
112 << " CalculateTileSize: "
113 << client_->CalculateTileSize(tiling->tiling_size()).ToString();
114 }
115
116 if (!tilings_.empty()) {
117 size_t num_high_res = std::count_if(tilings_.begin(), tilings_.end(),
118 [](PictureLayerTiling* tiling) {
119 return tiling->resolution() == HIGH_RESOLUTION;
120 });
121 DCHECK_EQ(1u, num_high_res);
122 }
123 #endif
52 } 124 }
53 125
54 void PictureLayerTilingSet::CleanUpTilings( 126 void PictureLayerTilingSet::CleanUpTilings(
55 float min_acceptable_high_res_scale, 127 float min_acceptable_high_res_scale,
56 float max_acceptable_high_res_scale, 128 float max_acceptable_high_res_scale,
57 const std::vector<PictureLayerTiling*>& needed_tilings, 129 const std::vector<PictureLayerTiling*>& needed_tilings,
58 bool should_have_low_res, 130 bool should_have_low_res,
59 PictureLayerTilingSet* twin_set, 131 PictureLayerTilingSet* twin_set,
60 PictureLayerTilingSet* recycled_twin_set) { 132 PictureLayerTilingSet* recycled_twin_set) {
61 float twin_low_res_scale = 0.f; 133 float twin_low_res_scale = 0.f;
(...skipping 22 matching lines...) Expand all
84 // Don't remove tilings that are required. 156 // Don't remove tilings that are required.
85 if (std::find(needed_tilings.begin(), needed_tilings.end(), tiling) != 157 if (std::find(needed_tilings.begin(), needed_tilings.end(), tiling) !=
86 needed_tilings.end()) { 158 needed_tilings.end()) {
87 continue; 159 continue;
88 } 160 }
89 161
90 to_remove.push_back(tiling); 162 to_remove.push_back(tiling);
91 } 163 }
92 164
93 for (auto* tiling : to_remove) { 165 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 = 166 PictureLayerTiling* recycled_twin_tiling =
103 recycled_twin_set 167 recycled_twin_set
104 ? recycled_twin_set->FindTilingWithScale(tiling->contents_scale()) 168 ? recycled_twin_set->FindTilingWithScale(tiling->contents_scale())
105 : nullptr; 169 : nullptr;
106 // Remove the tiling from the recycle tree. Note that we ignore resolution, 170 // 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. 171 // since we don't need to maintain high/low res on the recycle set.
108 if (recycled_twin_tiling) 172 if (recycled_twin_tiling)
109 recycled_twin_set->Remove(recycled_twin_tiling); 173 recycled_twin_set->Remove(recycled_twin_tiling);
110 174
111 DCHECK_NE(HIGH_RESOLUTION, tiling->resolution()); 175 DCHECK_NE(HIGH_RESOLUTION, tiling->resolution());
112 Remove(tiling); 176 Remove(tiling);
113 } 177 }
114 } 178 }
115 179
180 void PictureLayerTilingSet::RemoveNonIdealTilings() {
181 auto to_remove = tilings_.remove_if([](PictureLayerTiling* t) {
182 return t->resolution() == NON_IDEAL_RESOLUTION;
183 });
184 tilings_.erase(to_remove, tilings_.end());
185 }
186
116 void PictureLayerTilingSet::MarkAllTilingsNonIdeal() { 187 void PictureLayerTilingSet::MarkAllTilingsNonIdeal() {
117 for (auto* tiling : tilings_) 188 for (auto* tiling : tilings_)
118 tiling->set_resolution(NON_IDEAL_RESOLUTION); 189 tiling->set_resolution(NON_IDEAL_RESOLUTION);
119 } 190 }
120 191
121 bool PictureLayerTilingSet::SyncTilings(const PictureLayerTilingSet& other, 192 bool PictureLayerTilingSet::SyncTilingsForTesting(
122 const gfx::Size& new_layer_bounds, 193 const PictureLayerTilingSet& other,
123 const Region& layer_invalidation, 194 const gfx::Size& new_layer_bounds,
124 float minimum_contents_scale, 195 const Region& layer_invalidation,
125 RasterSource* raster_source) { 196 float minimum_contents_scale,
197 RasterSource* raster_source) {
126 if (new_layer_bounds.IsEmpty()) { 198 if (new_layer_bounds.IsEmpty()) {
127 RemoveAllTilings(); 199 RemoveAllTilings();
128 return false; 200 return false;
129 } 201 }
130 202
131 tilings_.reserve(other.tilings_.size()); 203 tilings_.reserve(other.tilings_.size());
132 204
133 // Remove any tilings that aren't in |other| or don't meet the minimum. 205 // Remove any tilings that aren't in |other| or don't meet the minimum.
134 for (size_t i = 0; i < tilings_.size(); ++i) { 206 for (size_t i = 0; i < tilings_.size(); ++i) {
135 float scale = tilings_[i]->contents_scale(); 207 float scale = tilings_[i]->contents_scale();
136 if (scale >= minimum_contents_scale && !!other.FindTilingWithScale(scale)) 208 if (scale >= minimum_contents_scale && !!other.FindTilingWithScale(scale))
137 continue; 209 continue;
138 // Swap with the last element and remove it. 210 // Swap with the last element and remove it.
139 tilings_.swap(tilings_.begin() + i, tilings_.end() - 1); 211 tilings_.swap(tilings_.begin() + i, tilings_.end() - 1);
140 tilings_.pop_back(); 212 tilings_.pop_back();
141 --i; 213 --i;
142 } 214 }
143 215
144 bool have_high_res_tiling = false; 216 bool have_high_res_tiling = false;
145 217
146 // Add any missing tilings from |other| that meet the minimum. 218 // Add any missing tilings from |other| that meet the minimum.
147 for (size_t i = 0; i < other.tilings_.size(); ++i) { 219 for (size_t i = 0; i < other.tilings_.size(); ++i) {
148 float contents_scale = other.tilings_[i]->contents_scale(); 220 float contents_scale = other.tilings_[i]->contents_scale();
149 if (contents_scale < minimum_contents_scale) 221 if (contents_scale < minimum_contents_scale)
150 continue; 222 continue;
151 if (PictureLayerTiling* this_tiling = FindTilingWithScale(contents_scale)) { 223 if (PictureLayerTiling* this_tiling = FindTilingWithScale(contents_scale)) {
152 this_tiling->set_resolution(other.tilings_[i]->resolution()); 224 this_tiling->set_resolution(other.tilings_[i]->resolution());
153 225
154 this_tiling->UpdateTilesToCurrentRasterSource( 226 this_tiling->Resize(new_layer_bounds);
155 raster_source, layer_invalidation, new_layer_bounds); 227 this_tiling->Invalidate(layer_invalidation);
228 this_tiling->SetRasterSource(raster_source);
156 this_tiling->CreateMissingTilesInLiveTilesRect(); 229 this_tiling->CreateMissingTilesInLiveTilesRect();
157 if (this_tiling->resolution() == HIGH_RESOLUTION) 230 if (this_tiling->resolution() == HIGH_RESOLUTION)
158 have_high_res_tiling = true; 231 have_high_res_tiling = true;
159 232
160 DCHECK(this_tiling->tile_size() == 233 DCHECK(this_tiling->tile_size() ==
161 client_->CalculateTileSize(this_tiling->tiling_size())) 234 client_->CalculateTileSize(this_tiling->tiling_size()))
162 << "tile_size: " << this_tiling->tile_size().ToString() 235 << "tile_size: " << this_tiling->tile_size().ToString()
163 << " tiling_size: " << this_tiling->tiling_size().ToString() 236 << " tiling_size: " << this_tiling->tiling_size().ToString()
164 << " CalculateTileSize: " 237 << " CalculateTileSize: "
165 << client_->CalculateTileSize(this_tiling->tiling_size()).ToString(); 238 << client_->CalculateTileSize(this_tiling->tiling_size()).ToString();
166 continue; 239 continue;
167 } 240 }
168 scoped_ptr<PictureLayerTiling> new_tiling = PictureLayerTiling::Create( 241 scoped_ptr<PictureLayerTiling> new_tiling = PictureLayerTiling::Create(
169 contents_scale, 242 contents_scale, new_layer_bounds, client_, max_tiles_for_interest_area_,
170 new_layer_bounds, 243 skewport_target_time_in_seconds_,
171 client_); 244 skewport_extrapolation_limit_in_content_pixels_);
172 new_tiling->set_resolution(other.tilings_[i]->resolution()); 245 new_tiling->set_resolution(other.tilings_[i]->resolution());
173 if (new_tiling->resolution() == HIGH_RESOLUTION) 246 if (new_tiling->resolution() == HIGH_RESOLUTION)
174 have_high_res_tiling = true; 247 have_high_res_tiling = true;
175 tilings_.push_back(new_tiling.Pass()); 248 tilings_.push_back(new_tiling.Pass());
176 } 249 }
177 tilings_.sort(LargestToSmallestScaleFunctor()); 250 tilings_.sort(LargestToSmallestScaleFunctor());
178 251
179 return have_high_res_tiling; 252 return have_high_res_tiling;
180 } 253 }
181 254
182 PictureLayerTiling* PictureLayerTilingSet::AddTiling( 255 PictureLayerTiling* PictureLayerTilingSet::AddTiling(
183 float contents_scale, 256 float contents_scale,
184 const gfx::Size& layer_bounds) { 257 const gfx::Size& layer_bounds) {
185 for (size_t i = 0; i < tilings_.size(); ++i) 258 for (size_t i = 0; i < tilings_.size(); ++i)
186 DCHECK_NE(tilings_[i]->contents_scale(), contents_scale); 259 DCHECK_NE(tilings_[i]->contents_scale(), contents_scale);
187 260
188 tilings_.push_back( 261 tilings_.push_back(PictureLayerTiling::Create(
189 PictureLayerTiling::Create(contents_scale, layer_bounds, client_)); 262 contents_scale, layer_bounds, client_, max_tiles_for_interest_area_,
263 skewport_target_time_in_seconds_,
264 skewport_extrapolation_limit_in_content_pixels_));
190 PictureLayerTiling* appended = tilings_.back(); 265 PictureLayerTiling* appended = tilings_.back();
191 266
192 tilings_.sort(LargestToSmallestScaleFunctor()); 267 tilings_.sort(LargestToSmallestScaleFunctor());
193 return appended; 268 return appended;
194 } 269 }
195 270
196 int PictureLayerTilingSet::NumHighResTilings() const { 271 int PictureLayerTilingSet::NumHighResTilings() const {
197 int num_high_res = 0; 272 int num_high_res = 0;
198 for (size_t i = 0; i < tilings_.size(); ++i) { 273 for (size_t i = 0; i < tilings_.size(); ++i) {
199 if (tilings_[i]->resolution() == HIGH_RESOLUTION) 274 if (tilings_[i]->resolution() == HIGH_RESOLUTION)
(...skipping 15 matching lines...) Expand all
215 TileResolution resolution) const { 290 TileResolution resolution) const {
216 auto iter = std::find_if(tilings_.begin(), tilings_.end(), 291 auto iter = std::find_if(tilings_.begin(), tilings_.end(),
217 [resolution](const PictureLayerTiling* tiling) { 292 [resolution](const PictureLayerTiling* tiling) {
218 return tiling->resolution() == resolution; 293 return tiling->resolution() == resolution;
219 }); 294 });
220 if (iter == tilings_.end()) 295 if (iter == tilings_.end())
221 return NULL; 296 return NULL;
222 return *iter; 297 return *iter;
223 } 298 }
224 299
300 void PictureLayerTilingSet::RemoveTilingsBelowScale(float minimum_scale) {
301 auto to_remove =
302 tilings_.remove_if([minimum_scale](PictureLayerTiling* tiling) {
303 return tiling->contents_scale() < minimum_scale;
304 });
305 tilings_.erase(to_remove, tilings_.end());
306 }
307
225 void PictureLayerTilingSet::RemoveAllTilings() { 308 void PictureLayerTilingSet::RemoveAllTilings() {
226 tilings_.clear(); 309 tilings_.clear();
227 } 310 }
228 311
229 void PictureLayerTilingSet::Remove(PictureLayerTiling* tiling) { 312 void PictureLayerTilingSet::Remove(PictureLayerTiling* tiling) {
230 ScopedPtrVector<PictureLayerTiling>::iterator iter = 313 ScopedPtrVector<PictureLayerTiling>::iterator iter =
231 std::find(tilings_.begin(), tilings_.end(), tiling); 314 std::find(tilings_.begin(), tilings_.end(), tiling);
232 if (iter == tilings_.end()) 315 if (iter == tilings_.end())
233 return; 316 return;
234 tilings_.erase(iter); 317 tilings_.erase(iter);
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 case LOWER_THAN_LOW_RES: 601 case LOWER_THAN_LOW_RES:
519 range = TilingRange(low_res_range.end, tilings_.size()); 602 range = TilingRange(low_res_range.end, tilings_.size());
520 break; 603 break;
521 } 604 }
522 605
523 DCHECK_LE(range.start, range.end); 606 DCHECK_LE(range.start, range.end);
524 return range; 607 return range;
525 } 608 }
526 609
527 } // namespace cc 610 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/picture_layer_tiling_set.h ('k') | cc/resources/picture_layer_tiling_set_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698