| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 if (a_is_occluded != b_is_occluded) | 50 if (a_is_occluded != b_is_occluded) |
| 51 return a_is_occluded; | 51 return a_is_occluded; |
| 52 | 52 |
| 53 // Or if a is farther away from visible. | 53 // Or if a is farther away from visible. |
| 54 return a_priority.distance_to_visible > b_priority.distance_to_visible; | 54 return a_priority.distance_to_visible > b_priority.distance_to_visible; |
| 55 } | 55 } |
| 56 | 56 |
| 57 private: | 57 private: |
| 58 TreePriority tree_priority_; | 58 TreePriority tree_priority_; |
| 59 }; | 59 }; |
| 60 |
| 61 void ReleaseTile(Tile* tile, WhichTree tree) { |
| 62 // Reset priority as tile is ref-counted and might still be used |
| 63 // even though we no longer hold a reference to it here anymore. |
| 64 tile->SetPriority(tree, TilePriority()); |
| 65 } |
| 66 |
| 60 } // namespace | 67 } // namespace |
| 61 | 68 |
| 62 scoped_ptr<PictureLayerTiling> PictureLayerTiling::Create( | 69 scoped_ptr<PictureLayerTiling> PictureLayerTiling::Create( |
| 63 float contents_scale, | 70 float contents_scale, |
| 64 const gfx::Size& layer_bounds, | 71 const gfx::Size& layer_bounds, |
| 65 PictureLayerTilingClient* client) { | 72 PictureLayerTilingClient* client) { |
| 66 return make_scoped_ptr(new PictureLayerTiling(contents_scale, | 73 return make_scoped_ptr(new PictureLayerTiling(contents_scale, |
| 67 layer_bounds, | 74 layer_bounds, |
| 68 client)); | 75 client)); |
| 69 } | 76 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 87 gfx::ScaleSize(layer_bounds, contents_scale)).IsEmpty()) << | 94 gfx::ScaleSize(layer_bounds, contents_scale)).IsEmpty()) << |
| 88 "Tiling created with scale too small as contents become empty." << | 95 "Tiling created with scale too small as contents become empty." << |
| 89 " Layer bounds: " << layer_bounds.ToString() << | 96 " Layer bounds: " << layer_bounds.ToString() << |
| 90 " Contents scale: " << contents_scale; | 97 " Contents scale: " << contents_scale; |
| 91 | 98 |
| 92 tiling_data_.SetTilingSize(content_bounds); | 99 tiling_data_.SetTilingSize(content_bounds); |
| 93 tiling_data_.SetMaxTextureSize(tile_size); | 100 tiling_data_.SetMaxTextureSize(tile_size); |
| 94 } | 101 } |
| 95 | 102 |
| 96 PictureLayerTiling::~PictureLayerTiling() { | 103 PictureLayerTiling::~PictureLayerTiling() { |
| 104 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) |
| 105 ReleaseTile(it->second.get(), client_->GetTree()); |
| 97 } | 106 } |
| 98 | 107 |
| 99 void PictureLayerTiling::SetClient(PictureLayerTilingClient* client) { | 108 void PictureLayerTiling::SetClient(PictureLayerTilingClient* client) { |
| 100 client_ = client; | 109 client_ = client; |
| 101 } | 110 } |
| 102 | 111 |
| 103 Tile* PictureLayerTiling::CreateTile(int i, | 112 Tile* PictureLayerTiling::CreateTile(int i, |
| 104 int j, | 113 int j, |
| 105 const PictureLayerTiling* twin_tiling) { | 114 const PictureLayerTiling* twin_tiling) { |
| 106 TileMapKey key(i, j); | 115 TileMapKey key(i, j); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 continue; | 216 continue; |
| 208 bool include_borders = true; | 217 bool include_borders = true; |
| 209 for (TilingData::Iterator iter( | 218 for (TilingData::Iterator iter( |
| 210 &tiling_data_, content_rect, include_borders); | 219 &tiling_data_, content_rect, include_borders); |
| 211 iter; | 220 iter; |
| 212 ++iter) { | 221 ++iter) { |
| 213 TileMapKey key(iter.index()); | 222 TileMapKey key(iter.index()); |
| 214 TileMap::iterator find = tiles_.find(key); | 223 TileMap::iterator find = tiles_.find(key); |
| 215 if (find == tiles_.end()) | 224 if (find == tiles_.end()) |
| 216 continue; | 225 continue; |
| 226 |
| 227 ReleaseTile(find->second.get(), client_->GetTree()); |
| 228 |
| 217 tiles_.erase(find); | 229 tiles_.erase(find); |
| 218 new_tile_keys.push_back(key); | 230 new_tile_keys.push_back(key); |
| 219 } | 231 } |
| 220 } | 232 } |
| 221 | 233 |
| 222 if (recreate_invalidated_tiles && !new_tile_keys.empty()) { | 234 if (recreate_invalidated_tiles && !new_tile_keys.empty()) { |
| 223 for (size_t i = 0; i < new_tile_keys.size(); ++i) { | 235 for (size_t i = 0; i < new_tile_keys.size(); ++i) { |
| 224 // Don't try to share a tile with the twin layer, it's been invalidated so | 236 // Don't try to share a tile with the twin layer, it's been invalidated so |
| 225 // we have to make our own tile here. | 237 // we have to make our own tile here. |
| 226 const PictureLayerTiling* twin_tiling = NULL; | 238 const PictureLayerTiling* twin_tiling = NULL; |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 // Iterate to delete all tiles outside of our new live_tiles rect. | 603 // Iterate to delete all tiles outside of our new live_tiles rect. |
| 592 for (TilingData::DifferenceIterator iter(&tiling_data_, | 604 for (TilingData::DifferenceIterator iter(&tiling_data_, |
| 593 live_tiles_rect_, | 605 live_tiles_rect_, |
| 594 new_live_tiles_rect); | 606 new_live_tiles_rect); |
| 595 iter; | 607 iter; |
| 596 ++iter) { | 608 ++iter) { |
| 597 TileMapKey key(iter.index()); | 609 TileMapKey key(iter.index()); |
| 598 TileMap::iterator found = tiles_.find(key); | 610 TileMap::iterator found = tiles_.find(key); |
| 599 // If the tile was outside of the recorded region, it won't exist even | 611 // If the tile was outside of the recorded region, it won't exist even |
| 600 // though it was in the live rect. | 612 // though it was in the live rect. |
| 601 if (found != tiles_.end()) | 613 if (found != tiles_.end()) { |
| 614 ReleaseTile(found->second.get(), client_->GetTree()); |
| 602 tiles_.erase(found); | 615 tiles_.erase(found); |
| 616 } |
| 603 } | 617 } |
| 604 | 618 |
| 605 const PictureLayerTiling* twin_tiling = client_->GetTwinTiling(this); | 619 const PictureLayerTiling* twin_tiling = client_->GetTwinTiling(this); |
| 606 | 620 |
| 607 // Iterate to allocate new tiles for all regions with newly exposed area. | 621 // Iterate to allocate new tiles for all regions with newly exposed area. |
| 608 for (TilingData::DifferenceIterator iter(&tiling_data_, | 622 for (TilingData::DifferenceIterator iter(&tiling_data_, |
| 609 new_live_tiles_rect, | 623 new_live_tiles_rect, |
| 610 live_tiles_rect_); | 624 live_tiles_rect_); |
| 611 iter; | 625 iter; |
| 612 ++iter) { | 626 ++iter) { |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 987 tiling_->UpdateEvictionCacheIfNeeded(tree_priority_); | 1001 tiling_->UpdateEvictionCacheIfNeeded(tree_priority_); |
| 988 tile_iterator_ = tiling_->eviction_tiles_cache_.begin(); | 1002 tile_iterator_ = tiling_->eviction_tiles_cache_.begin(); |
| 989 is_valid_ = true; | 1003 is_valid_ = true; |
| 990 if (tile_iterator_ != tiling_->eviction_tiles_cache_.end() && | 1004 if (tile_iterator_ != tiling_->eviction_tiles_cache_.end() && |
| 991 !(*tile_iterator_)->HasResources()) { | 1005 !(*tile_iterator_)->HasResources()) { |
| 992 ++(*this); | 1006 ++(*this); |
| 993 } | 1007 } |
| 994 } | 1008 } |
| 995 | 1009 |
| 996 } // namespace cc | 1010 } // namespace cc |
| OLD | NEW |