| 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 | 10 |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 // Avoid needless work by not bothering to invalidate where there aren't | 216 // Avoid needless work by not bothering to invalidate where there aren't |
| 217 // tiles. | 217 // tiles. |
| 218 content_rect.Intersect(expanded_live_tiles_rect); | 218 content_rect.Intersect(expanded_live_tiles_rect); |
| 219 if (content_rect.IsEmpty()) | 219 if (content_rect.IsEmpty()) |
| 220 continue; | 220 continue; |
| 221 bool include_borders = true; | 221 bool include_borders = true; |
| 222 for (TilingData::Iterator iter( | 222 for (TilingData::Iterator iter( |
| 223 &tiling_data_, content_rect, include_borders); | 223 &tiling_data_, content_rect, include_borders); |
| 224 iter; | 224 iter; |
| 225 ++iter) { | 225 ++iter) { |
| 226 TileMapKey key(iter.index()); | 226 // There is no recycled twin since this is run on the pending tiling. |
| 227 TileMap::iterator find = tiles_.find(key); | 227 PictureLayerTiling* recycled_twin = NULL; |
| 228 if (find == tiles_.end()) | 228 DCHECK_EQ(recycled_twin, client_->GetRecycledTwinTiling(this)); |
| 229 continue; | 229 DCHECK_EQ(PENDING_TREE, client_->GetTree()); |
| 230 | 230 if (RemoveTileAt(iter.index_x(), iter.index_y(), recycled_twin)) |
| 231 ReleaseTile(find->second.get(), client_->GetTree()); | 231 new_tile_keys.push_back(iter.index()); |
| 232 | |
| 233 tiles_.erase(find); | |
| 234 new_tile_keys.push_back(key); | |
| 235 } | 232 } |
| 236 } | 233 } |
| 237 | 234 |
| 238 if (recreate_invalidated_tiles && !new_tile_keys.empty()) { | 235 if (recreate_invalidated_tiles && !new_tile_keys.empty()) { |
| 239 for (size_t i = 0; i < new_tile_keys.size(); ++i) { | 236 for (size_t i = 0; i < new_tile_keys.size(); ++i) { |
| 240 // Don't try to share a tile with the twin layer, it's been invalidated so | 237 // Don't try to share a tile with the twin layer, it's been invalidated so |
| 241 // we have to make our own tile here. | 238 // we have to make our own tile here. |
| 242 const PictureLayerTiling* twin_tiling = NULL; | 239 const PictureLayerTiling* twin_tiling = NULL; |
| 243 CreateTile(new_tile_keys[i].first, new_tile_keys[i].second, twin_tiling); | 240 CreateTile(new_tile_keys[i].first, new_tile_keys[i].second, twin_tiling); |
| 244 } | 241 } |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 return texture_rect; | 385 return texture_rect; |
| 389 texture_rect.Offset(-tex_origin.OffsetFromOrigin()); | 386 texture_rect.Offset(-tex_origin.OffsetFromOrigin()); |
| 390 | 387 |
| 391 return texture_rect; | 388 return texture_rect; |
| 392 } | 389 } |
| 393 | 390 |
| 394 gfx::Size PictureLayerTiling::CoverageIterator::texture_size() const { | 391 gfx::Size PictureLayerTiling::CoverageIterator::texture_size() const { |
| 395 return tiling_->tiling_data_.max_texture_size(); | 392 return tiling_->tiling_data_.max_texture_size(); |
| 396 } | 393 } |
| 397 | 394 |
| 395 bool PictureLayerTiling::RemoveTileAt(int i, |
| 396 int j, |
| 397 PictureLayerTiling* recycled_twin) { |
| 398 TileMap::iterator found = tiles_.find(TileMapKey(i, j)); |
| 399 if (found == tiles_.end()) |
| 400 return false; |
| 401 ReleaseTile(found->second.get(), client_->GetTree()); |
| 402 tiles_.erase(found); |
| 403 if (recycled_twin) { |
| 404 // Recycled twin does not also have a recycled twin, so pass NULL. |
| 405 recycled_twin->RemoveTileAt(i, j, NULL); |
| 406 } |
| 407 return true; |
| 408 } |
| 409 |
| 398 void PictureLayerTiling::Reset() { | 410 void PictureLayerTiling::Reset() { |
| 399 live_tiles_rect_ = gfx::Rect(); | 411 live_tiles_rect_ = gfx::Rect(); |
| 400 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) | 412 PictureLayerTiling* recycled_twin = client_->GetRecycledTwinTiling(this); |
| 413 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { |
| 401 ReleaseTile(it->second.get(), client_->GetTree()); | 414 ReleaseTile(it->second.get(), client_->GetTree()); |
| 415 if (recycled_twin) |
| 416 recycled_twin->RemoveTileAt(it->first.first, it->first.second, NULL); |
| 417 } |
| 402 tiles_.clear(); | 418 tiles_.clear(); |
| 403 } | 419 } |
| 404 | 420 |
| 405 gfx::Rect PictureLayerTiling::ComputeSkewport( | 421 gfx::Rect PictureLayerTiling::ComputeSkewport( |
| 406 double current_frame_time_in_seconds, | 422 double current_frame_time_in_seconds, |
| 407 const gfx::Rect& visible_rect_in_content_space) const { | 423 const gfx::Rect& visible_rect_in_content_space) const { |
| 408 gfx::Rect skewport = visible_rect_in_content_space; | 424 gfx::Rect skewport = visible_rect_in_content_space; |
| 409 if (last_impl_frame_time_in_seconds_ == 0.0) | 425 if (last_impl_frame_time_in_seconds_ == 0.0) |
| 410 return skewport; | 426 return skewport; |
| 411 | 427 |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 tile->SetPriority(tree, priority); | 616 tile->SetPriority(tree, priority); |
| 601 } | 617 } |
| 602 | 618 |
| 603 // Update iteration rects. | 619 // Update iteration rects. |
| 604 current_visible_rect_ = visible_rect_in_content_space; | 620 current_visible_rect_ = visible_rect_in_content_space; |
| 605 current_skewport_rect_ = skewport; | 621 current_skewport_rect_ = skewport; |
| 606 current_soon_border_rect_ = soon_border_rect; | 622 current_soon_border_rect_ = soon_border_rect; |
| 607 current_eventually_rect_ = eventually_rect; | 623 current_eventually_rect_ = eventually_rect; |
| 608 } | 624 } |
| 609 | 625 |
| 610 void PictureLayerTiling::RemoveTileAt(int i, int j) { | |
| 611 TileMapKey key(i, j); | |
| 612 TileMap::iterator found = tiles_.find(key); | |
| 613 if (found == tiles_.end()) | |
| 614 return; | |
| 615 ReleaseTile(found->second.get(), client_->GetTree()); | |
| 616 tiles_.erase(found); | |
| 617 } | |
| 618 | |
| 619 void PictureLayerTiling::SetLiveTilesRect( | 626 void PictureLayerTiling::SetLiveTilesRect( |
| 620 const gfx::Rect& new_live_tiles_rect) { | 627 const gfx::Rect& new_live_tiles_rect) { |
| 621 DCHECK(new_live_tiles_rect.IsEmpty() || | 628 DCHECK(new_live_tiles_rect.IsEmpty() || |
| 622 gfx::Rect(tiling_size()).Contains(new_live_tiles_rect)) | 629 gfx::Rect(tiling_size()).Contains(new_live_tiles_rect)) |
| 623 << "tiling_size: " << tiling_size().ToString() | 630 << "tiling_size: " << tiling_size().ToString() |
| 624 << " new_live_tiles_rect: " << new_live_tiles_rect.ToString(); | 631 << " new_live_tiles_rect: " << new_live_tiles_rect.ToString(); |
| 625 if (live_tiles_rect_ == new_live_tiles_rect) | 632 if (live_tiles_rect_ == new_live_tiles_rect) |
| 626 return; | 633 return; |
| 627 | 634 |
| 628 // Iterate to delete all tiles outside of our new live_tiles rect. | 635 // Iterate to delete all tiles outside of our new live_tiles rect. |
| 629 PictureLayerTiling* recycled_twin = client_->GetRecycledTwinTiling(this); | 636 PictureLayerTiling* recycled_twin = client_->GetRecycledTwinTiling(this); |
| 630 for (TilingData::DifferenceIterator iter(&tiling_data_, | 637 for (TilingData::DifferenceIterator iter(&tiling_data_, |
| 631 live_tiles_rect_, | 638 live_tiles_rect_, |
| 632 new_live_tiles_rect); | 639 new_live_tiles_rect); |
| 633 iter; | 640 iter; |
| 634 ++iter) { | 641 ++iter) { |
| 635 TileMapKey key(iter.index()); | 642 RemoveTileAt(iter.index_x(), iter.index_y(), recycled_twin); |
| 636 TileMap::iterator found = tiles_.find(key); | |
| 637 // If the tile was outside of the recorded region, it won't exist even | |
| 638 // though it was in the live rect. | |
| 639 if (found != tiles_.end()) { | |
| 640 ReleaseTile(found->second.get(), client_->GetTree()); | |
| 641 tiles_.erase(found); | |
| 642 if (recycled_twin) | |
| 643 recycled_twin->RemoveTileAt(iter.index_x(), iter.index_y()); | |
| 644 } | |
| 645 } | 643 } |
| 646 | 644 |
| 647 const PictureLayerTiling* twin_tiling = client_->GetTwinTiling(this); | 645 const PictureLayerTiling* twin_tiling = client_->GetTwinTiling(this); |
| 648 | 646 |
| 649 // Iterate to allocate new tiles for all regions with newly exposed area. | 647 // Iterate to allocate new tiles for all regions with newly exposed area. |
| 650 for (TilingData::DifferenceIterator iter(&tiling_data_, | 648 for (TilingData::DifferenceIterator iter(&tiling_data_, |
| 651 new_live_tiles_rect, | 649 new_live_tiles_rect, |
| 652 live_tiles_rect_); | 650 live_tiles_rect_); |
| 653 iter; | 651 iter; |
| 654 ++iter) { | 652 ++iter) { |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1101 DCHECK(*this); | 1099 DCHECK(*this); |
| 1102 do { | 1100 do { |
| 1103 ++current_eviction_tiles_index_; | 1101 ++current_eviction_tiles_index_; |
| 1104 } while (current_eviction_tiles_index_ != eviction_tiles_->size() && | 1102 } while (current_eviction_tiles_index_ != eviction_tiles_->size() && |
| 1105 !(*eviction_tiles_)[current_eviction_tiles_index_]->HasResources()); | 1103 !(*eviction_tiles_)[current_eviction_tiles_index_]->HasResources()); |
| 1106 | 1104 |
| 1107 return *this; | 1105 return *this; |
| 1108 } | 1106 } |
| 1109 | 1107 |
| 1110 } // namespace cc | 1108 } // namespace cc |
| OLD | NEW |