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.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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
220 tiling_data_.TileXIndexFromSrcCoord(live_tiles_rect_.right() - 1); | 220 tiling_data_.TileXIndexFromSrcCoord(live_tiles_rect_.right() - 1); |
221 after_bottom = | 221 after_bottom = |
222 tiling_data_.TileYIndexFromSrcCoord(live_tiles_rect_.bottom() - 1); | 222 tiling_data_.TileYIndexFromSrcCoord(live_tiles_rect_.bottom() - 1); |
223 } | 223 } |
224 | 224 |
225 // There is no recycled twin since this is run on the pending tiling | 225 // There is no recycled twin since this is run on the pending tiling |
226 // during commit, and on the active tree during activate. | 226 // during commit, and on the active tree during activate. |
227 // Drop tiles outside the new layer bounds if the layer shrank. | 227 // Drop tiles outside the new layer bounds if the layer shrank. |
228 for (int i = after_right + 1; i <= before_right; ++i) { | 228 for (int i = after_right + 1; i <= before_right; ++i) { |
229 for (int j = before_top; j <= before_bottom; ++j) | 229 for (int j = before_top; j <= before_bottom; ++j) |
230 RemoveTileAt(i, j); | 230 RemoveTileAt(i, j, nullptr); |
231 } | 231 } |
232 for (int i = before_left; i <= after_right; ++i) { | 232 for (int i = before_left; i <= after_right; ++i) { |
233 for (int j = after_bottom + 1; j <= before_bottom; ++j) | 233 for (int j = after_bottom + 1; j <= before_bottom; ++j) |
234 RemoveTileAt(i, j); | 234 RemoveTileAt(i, j, nullptr); |
235 } | 235 } |
236 | 236 |
237 if (after_right > before_right) { | 237 if (after_right > before_right) { |
238 DCHECK_EQ(after_right, before_right + 1); | 238 DCHECK_EQ(after_right, before_right + 1); |
239 for (int j = before_top; j <= after_bottom; ++j) { | 239 for (int j = before_top; j <= after_bottom; ++j) { |
240 if (ShouldCreateTileAt(after_right, j)) | 240 if (ShouldCreateTileAt(after_right, j)) |
241 CreateTile(after_right, j); | 241 CreateTile(after_right, j); |
242 } | 242 } |
243 } | 243 } |
244 if (after_bottom > before_bottom) { | 244 if (after_bottom > before_bottom) { |
(...skipping 10 matching lines...) Expand all Loading... | |
255 !client_->GetPendingOrActiveTwinTiling(this)); | 255 !client_->GetPendingOrActiveTwinTiling(this)); |
256 RemoveTilesInRegion(layer_invalidation, true /* recreate tiles */); | 256 RemoveTilesInRegion(layer_invalidation, true /* recreate tiles */); |
257 } | 257 } |
258 | 258 |
259 void PictureLayerTiling::RemoveTilesInRegion(const Region& layer_invalidation, | 259 void PictureLayerTiling::RemoveTilesInRegion(const Region& layer_invalidation, |
260 bool recreate_tiles) { | 260 bool recreate_tiles) { |
261 // We only invalidate the active tiling when it's orphaned: it has no pending | 261 // We only invalidate the active tiling when it's orphaned: it has no pending |
262 // twin, so it's slated for removal in the future. | 262 // twin, so it's slated for removal in the future. |
263 if (live_tiles_rect_.IsEmpty()) | 263 if (live_tiles_rect_.IsEmpty()) |
264 return; | 264 return; |
265 std::vector<TileMapKey> new_tile_keys; | 265 struct InvalidTiles { |
266 TileMapKey key; | |
267 gfx::Rect invalid_rect; | |
268 }; | |
269 std::vector<InvalidTiles> new_tile_keys; | |
vmpstr
2015/05/14 17:58:49
If you make this a (hash)map keyed by TileMapKey,
danakj
2015/05/14 19:59:47
enne@ just pointed out to me that I can just union
vmpstr
2015/05/14 20:08:34
You'd still need to record which tiles were invali
danakj
2015/05/14 20:10:18
The original vector of keys, yah. I have this chan
| |
266 gfx::Rect expanded_live_tiles_rect = | 270 gfx::Rect expanded_live_tiles_rect = |
267 tiling_data_.ExpandRectIgnoringBordersToTileBounds(live_tiles_rect_); | 271 tiling_data_.ExpandRectIgnoringBordersToTileBounds(live_tiles_rect_); |
268 for (Region::Iterator iter(layer_invalidation); iter.has_rect(); | 272 for (Region::Iterator iter(layer_invalidation); iter.has_rect(); |
269 iter.next()) { | 273 iter.next()) { |
270 gfx::Rect layer_rect = iter.rect(); | 274 gfx::Rect layer_rect = iter.rect(); |
271 gfx::Rect content_rect = | 275 gfx::Rect content_rect = |
272 gfx::ScaleToEnclosingRect(layer_rect, contents_scale_); | 276 gfx::ScaleToEnclosingRect(layer_rect, contents_scale_); |
273 // Consider tiles inside the live tiles rect even if only their border | 277 // Consider tiles inside the live tiles rect even if only their border |
274 // pixels intersect the invalidation. But don't consider tiles outside | 278 // pixels intersect the invalidation. But don't consider tiles outside |
275 // the live tiles rect with the same conditions, as they won't exist. | 279 // the live tiles rect with the same conditions, as they won't exist. |
276 int border_pixels = tiling_data_.border_texels(); | 280 int border_pixels = tiling_data_.border_texels(); |
277 content_rect.Inset(-border_pixels, -border_pixels); | 281 content_rect.Inset(-border_pixels, -border_pixels); |
278 // Avoid needless work by not bothering to invalidate where there aren't | 282 // Avoid needless work by not bothering to invalidate where there aren't |
279 // tiles. | 283 // tiles. |
280 content_rect.Intersect(expanded_live_tiles_rect); | 284 content_rect.Intersect(expanded_live_tiles_rect); |
281 if (content_rect.IsEmpty()) | 285 if (content_rect.IsEmpty()) |
282 continue; | 286 continue; |
283 // Since the content_rect includes border pixels already, don't include | 287 // Since the content_rect includes border pixels already, don't include |
284 // borders when iterating to avoid double counting them. | 288 // borders when iterating to avoid double counting them. |
285 bool include_borders = false; | 289 bool include_borders = false; |
286 for ( | 290 for ( |
287 TilingData::Iterator iter(&tiling_data_, content_rect, include_borders); | 291 TilingData::Iterator iter(&tiling_data_, content_rect, include_borders); |
288 iter; ++iter) { | 292 iter; ++iter) { |
289 if (RemoveTileAt(iter.index_x(), iter.index_y())) { | 293 auto it = std::find_if( |
290 if (recreate_tiles) | 294 new_tile_keys.begin(), new_tile_keys.end(), |
291 new_tile_keys.push_back(iter.index()); | 295 [&iter](const InvalidTiles& inv) { return inv.key == iter.index(); }); |
296 if (it == new_tile_keys.end()) { | |
297 InvalidTiles inv; | |
298 inv.key = iter.index(); | |
299 new_tile_keys.push_back(inv); | |
300 it = new_tile_keys.end() - 1; | |
292 } | 301 } |
302 it->invalid_rect.Union(content_rect); | |
293 } | 303 } |
294 } | 304 } |
295 | 305 |
296 for (const auto& key : new_tile_keys) | 306 for (const InvalidTiles& inv : new_tile_keys) { |
297 CreateTile(key.first, key.second); | 307 Tile::Id old_id; |
308 if (RemoveTileAt(inv.key.first, inv.key.second, &old_id) && | |
309 recreate_tiles) { | |
310 Tile* tile = CreateTile(inv.key.first, inv.key.second); | |
311 tile->SetInvalidated(inv.invalid_rect, old_id); | |
312 } | |
313 } | |
298 } | 314 } |
299 | 315 |
300 void PictureLayerTiling::SetRasterSourceOnTiles() { | 316 void PictureLayerTiling::SetRasterSourceOnTiles() { |
301 if (tree_ == PENDING_TREE) | 317 if (tree_ == PENDING_TREE) |
302 return; | 318 return; |
303 | 319 |
304 for (TileMap::value_type& tile_pair : tiles_) | 320 for (TileMap::value_type& tile_pair : tiles_) |
305 tile_pair.second->set_raster_source(raster_source_.get()); | 321 tile_pair.second->set_raster_source(raster_source_.get()); |
306 } | 322 } |
307 | 323 |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
493 texture_rect.Scale(dest_to_content_scale_, | 509 texture_rect.Scale(dest_to_content_scale_, |
494 dest_to_content_scale_); | 510 dest_to_content_scale_); |
495 texture_rect.Intersect(gfx::Rect(tiling_->tiling_size())); | 511 texture_rect.Intersect(gfx::Rect(tiling_->tiling_size())); |
496 if (texture_rect.IsEmpty()) | 512 if (texture_rect.IsEmpty()) |
497 return texture_rect; | 513 return texture_rect; |
498 texture_rect.Offset(-tex_origin.OffsetFromOrigin()); | 514 texture_rect.Offset(-tex_origin.OffsetFromOrigin()); |
499 | 515 |
500 return texture_rect; | 516 return texture_rect; |
501 } | 517 } |
502 | 518 |
503 bool PictureLayerTiling::RemoveTileAt(int i, int j) { | 519 bool PictureLayerTiling::RemoveTileAt(int i, int j, Tile::Id* id) { |
504 TileMap::iterator found = tiles_.find(TileMapKey(i, j)); | 520 TileMap::iterator found = tiles_.find(TileMapKey(i, j)); |
505 if (found == tiles_.end()) | 521 if (found == tiles_.end()) |
506 return false; | 522 return false; |
523 if (id) | |
524 *id = found->second->id(); | |
507 tiles_.erase(found); | 525 tiles_.erase(found); |
508 return true; | 526 return true; |
509 } | 527 } |
510 | 528 |
511 void PictureLayerTiling::Reset() { | 529 void PictureLayerTiling::Reset() { |
512 live_tiles_rect_ = gfx::Rect(); | 530 live_tiles_rect_ = gfx::Rect(); |
513 tiles_.clear(); | 531 tiles_.clear(); |
514 } | 532 } |
515 | 533 |
516 gfx::Rect PictureLayerTiling::ComputeSkewport( | 534 gfx::Rect PictureLayerTiling::ComputeSkewport( |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
654 gfx::Rect(tiling_size()).Contains(new_live_tiles_rect)) | 672 gfx::Rect(tiling_size()).Contains(new_live_tiles_rect)) |
655 << "tiling_size: " << tiling_size().ToString() | 673 << "tiling_size: " << tiling_size().ToString() |
656 << " new_live_tiles_rect: " << new_live_tiles_rect.ToString(); | 674 << " new_live_tiles_rect: " << new_live_tiles_rect.ToString(); |
657 if (live_tiles_rect_ == new_live_tiles_rect) | 675 if (live_tiles_rect_ == new_live_tiles_rect) |
658 return; | 676 return; |
659 | 677 |
660 // Iterate to delete all tiles outside of our new live_tiles rect. | 678 // Iterate to delete all tiles outside of our new live_tiles rect. |
661 for (TilingData::DifferenceIterator iter(&tiling_data_, live_tiles_rect_, | 679 for (TilingData::DifferenceIterator iter(&tiling_data_, live_tiles_rect_, |
662 new_live_tiles_rect); | 680 new_live_tiles_rect); |
663 iter; ++iter) { | 681 iter; ++iter) { |
664 RemoveTileAt(iter.index_x(), iter.index_y()); | 682 RemoveTileAt(iter.index_x(), iter.index_y(), nullptr); |
665 } | 683 } |
666 | 684 |
667 // Iterate to allocate new tiles for all regions with newly exposed area. | 685 // Iterate to allocate new tiles for all regions with newly exposed area. |
668 for (TilingData::DifferenceIterator iter(&tiling_data_, new_live_tiles_rect, | 686 for (TilingData::DifferenceIterator iter(&tiling_data_, new_live_tiles_rect, |
669 live_tiles_rect_); | 687 live_tiles_rect_); |
670 iter; ++iter) { | 688 iter; ++iter) { |
671 TileMapKey key(iter.index()); | 689 TileMapKey key(iter.index()); |
672 if (ShouldCreateTileAt(key.first, key.second)) | 690 if (ShouldCreateTileAt(key.first, key.second)) |
673 CreateTile(key.first, key.second); | 691 CreateTile(key.first, key.second); |
674 } | 692 } |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1053 break; | 1071 break; |
1054 } | 1072 } |
1055 | 1073 |
1056 gfx::Rect result(origin_x, origin_y, width, height); | 1074 gfx::Rect result(origin_x, origin_y, width, height); |
1057 if (cache) | 1075 if (cache) |
1058 cache->previous_result = result; | 1076 cache->previous_result = result; |
1059 return result; | 1077 return result; |
1060 } | 1078 } |
1061 | 1079 |
1062 } // namespace cc | 1080 } // namespace cc |
OLD | NEW |