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

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

Issue 799463005: cc: Mirror LiveTilesRect and tiles between active and recycled trees. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: noswap-ltr: . 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
« no previous file with comments | « cc/resources/picture_layer_tiling.h ('k') | cc/resources/picture_layer_tiling_set.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.h" 5 #include "cc/resources/picture_layer_tiling.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <limits> 9 #include <limits>
10 #include <set> 10 #include <set>
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 tiling_data_.SetMaxTextureSize(tile_size); 112 tiling_data_.SetMaxTextureSize(tile_size);
113 } 113 }
114 114
115 PictureLayerTiling::~PictureLayerTiling() { 115 PictureLayerTiling::~PictureLayerTiling() {
116 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) 116 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it)
117 it->second->set_shared(false); 117 it->second->set_shared(false);
118 } 118 }
119 119
120 Tile* PictureLayerTiling::CreateTile(int i, 120 Tile* PictureLayerTiling::CreateTile(int i,
121 int j, 121 int j,
122 const PictureLayerTiling* twin_tiling) { 122 const PictureLayerTiling* twin_tiling,
123 PictureLayerTiling* recycled_twin) {
124 // Can't have both a (pending or active) twin and a recycled twin tiling.
125 DCHECK_IMPLIES(twin_tiling, !recycled_twin);
126 DCHECK_IMPLIES(recycled_twin, !twin_tiling);
123 TileMapKey key(i, j); 127 TileMapKey key(i, j);
124 DCHECK(tiles_.find(key) == tiles_.end()); 128 DCHECK(tiles_.find(key) == tiles_.end());
125 129
126 gfx::Rect paint_rect = tiling_data_.TileBoundsWithBorder(i, j); 130 gfx::Rect paint_rect = tiling_data_.TileBoundsWithBorder(i, j);
127 gfx::Rect tile_rect = paint_rect; 131 gfx::Rect tile_rect = paint_rect;
128 tile_rect.set_size(tiling_data_.max_texture_size()); 132 tile_rect.set_size(tiling_data_.max_texture_size());
129 133
130 // Check our twin for a valid tile. 134 // Check our twin for a valid tile.
131 if (twin_tiling && 135 if (twin_tiling &&
132 tiling_data_.max_texture_size() == 136 tiling_data_.max_texture_size() ==
(...skipping 12 matching lines...) Expand all
145 } 149 }
146 } 150 }
147 } 151 }
148 152
149 // Create a new tile because our twin didn't have a valid one. 153 // Create a new tile because our twin didn't have a valid one.
150 scoped_refptr<Tile> tile = client_->CreateTile(this, tile_rect); 154 scoped_refptr<Tile> tile = client_->CreateTile(this, tile_rect);
151 if (tile.get()) { 155 if (tile.get()) {
152 DCHECK(!tile->is_shared()); 156 DCHECK(!tile->is_shared());
153 tile->set_tiling_index(i, j); 157 tile->set_tiling_index(i, j);
154 tiles_[key] = tile; 158 tiles_[key] = tile;
159
160 if (recycled_twin) {
161 DCHECK(recycled_twin->tiles_.find(key) == recycled_twin->tiles_.end());
162 // Do what recycled_twin->CreateTile() would do.
163 tile->set_shared(true);
164 recycled_twin->tiles_[key] = tile;
vmpstr 2014/12/12 18:01:34 What happens if this tile is outside of the recycl
danakj 2014/12/12 18:02:48 This is a good question.. we should maybe set the
165 }
155 } 166 }
156 eviction_tiles_cache_valid_ = false; 167 eviction_tiles_cache_valid_ = false;
157 return tile.get(); 168 return tile.get();
158 } 169 }
159 170
160 void PictureLayerTiling::CreateMissingTilesInLiveTilesRect() { 171 void PictureLayerTiling::CreateMissingTilesInLiveTilesRect() {
161 const PictureLayerTiling* twin_tiling = 172 const PictureLayerTiling* twin_tiling =
162 client_->GetPendingOrActiveTwinTiling(this); 173 client_->GetPendingOrActiveTwinTiling(this);
174 // There is no recycled twin during commit from the main thread which is when
175 // this occurs.
176 PictureLayerTiling* null_recycled_twin = nullptr;
177 DCHECK_EQ(null_recycled_twin, client_->GetRecycledTwinTiling(this));
163 bool include_borders = false; 178 bool include_borders = false;
164 for (TilingData::Iterator iter( 179 for (TilingData::Iterator iter(
165 &tiling_data_, live_tiles_rect_, include_borders); 180 &tiling_data_, live_tiles_rect_, include_borders);
166 iter; 181 iter;
167 ++iter) { 182 ++iter) {
168 TileMapKey key = iter.index(); 183 TileMapKey key = iter.index();
169 TileMap::iterator find = tiles_.find(key); 184 TileMap::iterator find = tiles_.find(key);
170 if (find != tiles_.end()) 185 if (find != tiles_.end())
171 continue; 186 continue;
172 CreateTile(key.first, key.second, twin_tiling); 187 CreateTile(key.first, key.second, twin_tiling, null_recycled_twin);
173 } 188 }
174 189
175 VerifyLiveTilesRect(); 190 VerifyLiveTilesRect();
176 } 191 }
177 192
178 void PictureLayerTiling::CloneTilesAndPropertiesFrom( 193 void PictureLayerTiling::CloneTilesAndPropertiesFrom(
179 const PictureLayerTiling& twin_tiling) { 194 const PictureLayerTiling& twin_tiling) {
180 DCHECK_EQ(&twin_tiling, client_->GetPendingOrActiveTwinTiling(this)); 195 DCHECK_EQ(&twin_tiling, client_->GetPendingOrActiveTwinTiling(this));
181 196
182 Resize(twin_tiling.layer_bounds_); 197 Resize(twin_tiling.layer_bounds_);
(...skipping 12 matching lines...) Expand all
195 Tile* tile = tile_map_pair.second.get(); 210 Tile* tile = tile_map_pair.second.get();
196 if (!tile->is_shared()) 211 if (!tile->is_shared())
197 to_remove.push_back(key); 212 to_remove.push_back(key);
198 } 213 }
199 // The recycled twin does not exist since there is a pending twin (which is 214 // The recycled twin does not exist since there is a pending twin (which is
200 // |twin_tiling|). 215 // |twin_tiling|).
201 PictureLayerTiling* null_recycled_twin = nullptr; 216 PictureLayerTiling* null_recycled_twin = nullptr;
202 DCHECK_EQ(null_recycled_twin, client_->GetRecycledTwinTiling(this)); 217 DCHECK_EQ(null_recycled_twin, client_->GetRecycledTwinTiling(this));
203 for (const auto& key : to_remove) { 218 for (const auto& key : to_remove) {
204 RemoveTileAt(key.first, key.second, null_recycled_twin); 219 RemoveTileAt(key.first, key.second, null_recycled_twin);
205 CreateTile(key.first, key.second, &twin_tiling); 220 CreateTile(key.first, key.second, &twin_tiling, null_recycled_twin);
221 }
222
223 // Create any missing tiles from the |twin_tiling|.
danakj 2014/12/11 23:38:08 I should write a test for this change: Activate wi
224 for (const auto& tile_map_pair : twin_tiling.tiles_) {
225 TileMapKey key = tile_map_pair.first;
226 Tile* tile = tile_map_pair.second.get();
227 if (!tile->is_shared())
228 CreateTile(key.first, key.second, &twin_tiling, null_recycled_twin);
206 } 229 }
207 230
208 DCHECK_EQ(twin_tiling.tiles_.size(), tiles_.size()); 231 DCHECK_EQ(twin_tiling.tiles_.size(), tiles_.size());
209 #if DCHECK_IS_ON 232 #if DCHECK_IS_ON
210 for (const auto& tile_map_pair : tiles_) 233 for (const auto& tile_map_pair : tiles_)
211 DCHECK(tile_map_pair.second->is_shared()); 234 DCHECK(tile_map_pair.second->is_shared());
235 VerifyLiveTilesRect();
212 #endif 236 #endif
213 237
214 UpdateTilePriorityRects(twin_tiling.current_content_to_screen_scale_, 238 UpdateTilePriorityRects(twin_tiling.current_content_to_screen_scale_,
215 twin_tiling.current_visible_rect_, 239 twin_tiling.current_visible_rect_,
216 twin_tiling.current_skewport_rect_, 240 twin_tiling.current_skewport_rect_,
217 twin_tiling.current_soon_border_rect_, 241 twin_tiling.current_soon_border_rect_,
218 twin_tiling.current_eventually_rect_, 242 twin_tiling.current_eventually_rect_,
219 twin_tiling.current_occlusion_in_layer_space_); 243 twin_tiling.current_occlusion_in_layer_space_);
220 } 244 }
221 245
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 int after_bottom = -1; 294 int after_bottom = -1;
271 if (!live_tiles_rect_.IsEmpty()) { 295 if (!live_tiles_rect_.IsEmpty()) {
272 after_right = 296 after_right =
273 tiling_data_.TileXIndexFromSrcCoord(live_tiles_rect_.right() - 1); 297 tiling_data_.TileXIndexFromSrcCoord(live_tiles_rect_.right() - 1);
274 after_bottom = 298 after_bottom =
275 tiling_data_.TileYIndexFromSrcCoord(live_tiles_rect_.bottom() - 1); 299 tiling_data_.TileYIndexFromSrcCoord(live_tiles_rect_.bottom() - 1);
276 } 300 }
277 301
278 // There is no recycled twin since this is run on the pending tiling 302 // There is no recycled twin since this is run on the pending tiling
279 // during commit, and on the active tree during activate. 303 // during commit, and on the active tree during activate.
280 PictureLayerTiling* recycled_twin = NULL; 304 PictureLayerTiling* null_recycled_twin = nullptr;
281 DCHECK_EQ(recycled_twin, client_->GetRecycledTwinTiling(this)); 305 DCHECK_EQ(null_recycled_twin, client_->GetRecycledTwinTiling(this));
282 306
283 // Drop tiles outside the new layer bounds if the layer shrank. 307 // Drop tiles outside the new layer bounds if the layer shrank.
284 for (int i = after_right + 1; i <= before_right; ++i) { 308 for (int i = after_right + 1; i <= before_right; ++i) {
285 for (int j = before_top; j <= before_bottom; ++j) 309 for (int j = before_top; j <= before_bottom; ++j)
286 RemoveTileAt(i, j, recycled_twin); 310 RemoveTileAt(i, j, null_recycled_twin);
287 } 311 }
288 for (int i = before_left; i <= after_right; ++i) { 312 for (int i = before_left; i <= after_right; ++i) {
289 for (int j = after_bottom + 1; j <= before_bottom; ++j) 313 for (int j = after_bottom + 1; j <= before_bottom; ++j)
290 RemoveTileAt(i, j, recycled_twin); 314 RemoveTileAt(i, j, null_recycled_twin);
291 } 315 }
292 316
293 // If the layer grew, the live_tiles_rect_ is not changed, but a new row 317 // If the layer grew, the live_tiles_rect_ is not changed, but a new row
294 // and/or column of tiles may now exist inside the same live_tiles_rect_. 318 // and/or column of tiles may now exist inside the same live_tiles_rect_.
295 const PictureLayerTiling* twin_tiling = 319 const PictureLayerTiling* twin_tiling =
296 client_->GetPendingOrActiveTwinTiling(this); 320 client_->GetPendingOrActiveTwinTiling(this);
297 if (after_right > before_right) { 321 if (after_right > before_right) {
298 DCHECK_EQ(after_right, before_right + 1); 322 DCHECK_EQ(after_right, before_right + 1);
299 for (int j = before_top; j <= after_bottom; ++j) 323 for (int j = before_top; j <= after_bottom; ++j)
300 CreateTile(after_right, j, twin_tiling); 324 CreateTile(after_right, j, twin_tiling, null_recycled_twin);
301 } 325 }
302 if (after_bottom > before_bottom) { 326 if (after_bottom > before_bottom) {
303 DCHECK_EQ(after_bottom, before_bottom + 1); 327 DCHECK_EQ(after_bottom, before_bottom + 1);
304 for (int i = before_left; i <= before_right; ++i) 328 for (int i = before_left; i <= before_right; ++i)
305 CreateTile(i, after_bottom, twin_tiling); 329 CreateTile(i, after_bottom, twin_tiling, null_recycled_twin);
306 } 330 }
307 } 331 }
308 332
309 void PictureLayerTiling::Invalidate(const Region& layer_invalidation) { 333 void PictureLayerTiling::Invalidate(const Region& layer_invalidation) {
310 if (live_tiles_rect_.IsEmpty()) 334 if (live_tiles_rect_.IsEmpty())
311 return; 335 return;
312 std::vector<TileMapKey> new_tile_keys; 336 std::vector<TileMapKey> new_tile_keys;
313 gfx::Rect expanded_live_tiles_rect = 337 gfx::Rect expanded_live_tiles_rect =
314 tiling_data_.ExpandRectIgnoringBordersToTileBounds(live_tiles_rect_); 338 tiling_data_.ExpandRectIgnoringBordersToTileBounds(live_tiles_rect_);
315 for (Region::Iterator iter(layer_invalidation); iter.has_rect(); 339 for (Region::Iterator iter(layer_invalidation); iter.has_rect();
(...skipping 13 matching lines...) Expand all
329 continue; 353 continue;
330 // Since the content_rect includes border pixels already, don't include 354 // Since the content_rect includes border pixels already, don't include
331 // borders when iterating to avoid double counting them. 355 // borders when iterating to avoid double counting them.
332 bool include_borders = false; 356 bool include_borders = false;
333 for (TilingData::Iterator iter( 357 for (TilingData::Iterator iter(
334 &tiling_data_, content_rect, include_borders); 358 &tiling_data_, content_rect, include_borders);
335 iter; 359 iter;
336 ++iter) { 360 ++iter) {
337 // There is no recycled twin for the pending tree during commit, or for 361 // There is no recycled twin for the pending tree during commit, or for
338 // the active tree during activation. 362 // the active tree during activation.
339 PictureLayerTiling* null_recycled_twin = NULL; 363 PictureLayerTiling* null_recycled_twin = nullptr;
340 DCHECK_EQ(null_recycled_twin, client_->GetRecycledTwinTiling(this)); 364 DCHECK_EQ(null_recycled_twin, client_->GetRecycledTwinTiling(this));
341 if (RemoveTileAt(iter.index_x(), iter.index_y(), null_recycled_twin)) 365 if (RemoveTileAt(iter.index_x(), iter.index_y(), null_recycled_twin))
342 new_tile_keys.push_back(iter.index()); 366 new_tile_keys.push_back(iter.index());
343 } 367 }
344 } 368 }
345 369
346 if (!new_tile_keys.empty()) { 370 if (!new_tile_keys.empty()) {
347 // During commit from the main thread, invalidations can never be shared 371 // During commit from the main thread, invalidations can never be shared
348 // with the active tree since the active tree has different content there. 372 // with the active tree since the active tree has different content there.
349 const PictureLayerTiling* twin_tiling = nullptr; 373 // And when invalidating an active-tree tiling, it means there was no
374 // pending tiling to clone from.
375 const PictureLayerTiling* null_twin_tiling = nullptr;
376 PictureLayerTiling* null_recycled_twin = nullptr;
377 DCHECK_EQ(null_recycled_twin, client_->GetRecycledTwinTiling(this));
350 for (size_t i = 0; i < new_tile_keys.size(); ++i) { 378 for (size_t i = 0; i < new_tile_keys.size(); ++i) {
351 CreateTile(new_tile_keys[i].first, new_tile_keys[i].second, twin_tiling); 379 CreateTile(new_tile_keys[i].first, new_tile_keys[i].second,
380 null_twin_tiling, null_recycled_twin);
352 } 381 }
353 } 382 }
354 } 383 }
355 384
356 void PictureLayerTiling::SetRasterSource( 385 void PictureLayerTiling::SetRasterSource(
357 scoped_refptr<RasterSource> raster_source) { 386 scoped_refptr<RasterSource> raster_source) {
358 // Shared (ie. non-invalidated) tiles on the pending tree are updated to use 387 // Shared (ie. non-invalidated) tiles on the pending tree are updated to use
359 // the new raster source. When this raster source is activated, the raster 388 // the new raster source. When this raster source is activated, the raster
360 // source will remain valid for shared tiles in the active tree. 389 // source will remain valid for shared tiles in the active tree.
361 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) 390 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it)
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 bool PictureLayerTiling::RemoveTileAt(int i, 545 bool PictureLayerTiling::RemoveTileAt(int i,
517 int j, 546 int j,
518 PictureLayerTiling* recycled_twin) { 547 PictureLayerTiling* recycled_twin) {
519 TileMap::iterator found = tiles_.find(TileMapKey(i, j)); 548 TileMap::iterator found = tiles_.find(TileMapKey(i, j));
520 if (found == tiles_.end()) 549 if (found == tiles_.end())
521 return false; 550 return false;
522 found->second->set_shared(false); 551 found->second->set_shared(false);
523 tiles_.erase(found); 552 tiles_.erase(found);
524 eviction_tiles_cache_valid_ = false; 553 eviction_tiles_cache_valid_ = false;
525 if (recycled_twin) { 554 if (recycled_twin) {
526 // Recycled twin does not also have a recycled twin, so pass NULL. 555 // Recycled twin does not also have a recycled twin, so pass null.
527 recycled_twin->RemoveTileAt(i, j, NULL); 556 recycled_twin->RemoveTileAt(i, j, nullptr);
528 } 557 }
529 return true; 558 return true;
530 } 559 }
531 560
532 void PictureLayerTiling::Reset() { 561 void PictureLayerTiling::Reset() {
533 live_tiles_rect_ = gfx::Rect(); 562 live_tiles_rect_ = gfx::Rect();
534 PictureLayerTiling* recycled_twin = client_->GetRecycledTwinTiling(this); 563 PictureLayerTiling* recycled_twin = client_->GetRecycledTwinTiling(this);
535 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { 564 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) {
536 it->second->set_shared(false); 565 it->second->set_shared(false);
537 if (recycled_twin) 566 if (recycled_twin)
538 recycled_twin->RemoveTileAt(it->first.first, it->first.second, NULL); 567 recycled_twin->RemoveTileAt(it->first.first, it->first.second, nullptr);
539 } 568 }
540 tiles_.clear(); 569 tiles_.clear();
541 eviction_tiles_cache_valid_ = false; 570 eviction_tiles_cache_valid_ = false;
542 } 571 }
543 572
544 gfx::Rect PictureLayerTiling::ComputeSkewport( 573 gfx::Rect PictureLayerTiling::ComputeSkewport(
545 double current_frame_time_in_seconds, 574 double current_frame_time_in_seconds,
546 const gfx::Rect& visible_rect_in_content_space) const { 575 const gfx::Rect& visible_rect_in_content_space) const {
547 gfx::Rect skewport = visible_rect_in_content_space; 576 gfx::Rect skewport = visible_rect_in_content_space;
548 if (last_impl_frame_time_in_seconds_ == 0.0) 577 if (last_impl_frame_time_in_seconds_ == 0.0)
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 const PictureLayerTiling* twin_tiling = 720 const PictureLayerTiling* twin_tiling =
692 client_->GetPendingOrActiveTwinTiling(this); 721 client_->GetPendingOrActiveTwinTiling(this);
693 722
694 // Iterate to allocate new tiles for all regions with newly exposed area. 723 // Iterate to allocate new tiles for all regions with newly exposed area.
695 for (TilingData::DifferenceIterator iter(&tiling_data_, 724 for (TilingData::DifferenceIterator iter(&tiling_data_,
696 new_live_tiles_rect, 725 new_live_tiles_rect,
697 live_tiles_rect_); 726 live_tiles_rect_);
698 iter; 727 iter;
699 ++iter) { 728 ++iter) {
700 TileMapKey key(iter.index()); 729 TileMapKey key(iter.index());
701 CreateTile(key.first, key.second, twin_tiling); 730 CreateTile(key.first, key.second, twin_tiling, recycled_twin);
702 } 731 }
703 732
704 live_tiles_rect_ = new_live_tiles_rect; 733 live_tiles_rect_ = new_live_tiles_rect;
705 VerifyLiveTilesRect(); 734 VerifyLiveTilesRect();
706 } 735 }
707 736
708 void PictureLayerTiling::VerifyLiveTilesRect() { 737 void PictureLayerTiling::VerifyLiveTilesRect() const {
709 #if DCHECK_IS_ON 738 #if DCHECK_IS_ON
710 for (TileMap::iterator it = tiles_.begin(); it != tiles_.end(); ++it) { 739 for (auto it = tiles_.begin(); it != tiles_.end(); ++it) {
711 if (!it->second.get()) 740 if (!it->second.get())
712 continue; 741 continue;
713 DCHECK(it->first.first < tiling_data_.num_tiles_x()) 742 DCHECK(it->first.first < tiling_data_.num_tiles_x())
714 << this << " " << it->first.first << "," << it->first.second 743 << this << " " << it->first.first << "," << it->first.second
715 << " num_tiles_x " << tiling_data_.num_tiles_x() << " live_tiles_rect " 744 << " num_tiles_x " << tiling_data_.num_tiles_x() << " live_tiles_rect "
716 << live_tiles_rect_.ToString(); 745 << live_tiles_rect_.ToString();
717 DCHECK(it->first.second < tiling_data_.num_tiles_y()) 746 DCHECK(it->first.second < tiling_data_.num_tiles_y())
718 << this << " " << it->first.first << "," << it->first.second 747 << this << " " << it->first.first << "," << it->first.second
719 << " num_tiles_y " << tiling_data_.num_tiles_y() << " live_tiles_rect " 748 << " num_tiles_y " << tiling_data_.num_tiles_y() << " live_tiles_rect "
720 << live_tiles_rect_.ToString(); 749 << live_tiles_rect_.ToString();
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
1267 } 1296 }
1268 current_tile_ = tiling_->TileAt(next_index.first, next_index.second); 1297 current_tile_ = tiling_->TileAt(next_index.first, next_index.second);
1269 } 1298 }
1270 1299
1271 if (current_tile_) 1300 if (current_tile_)
1272 tiling_->UpdateTileAndTwinPriority(current_tile_); 1301 tiling_->UpdateTileAndTwinPriority(current_tile_);
1273 return *this; 1302 return *this;
1274 } 1303 }
1275 1304
1276 } // namespace cc 1305 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/picture_layer_tiling.h ('k') | cc/resources/picture_layer_tiling_set.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698