Chromium Code Reviews| 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 iter; | 131 iter; |
| 132 ++iter) { | 132 ++iter) { |
| 133 TileMapKey key = iter.index(); | 133 TileMapKey key = iter.index(); |
| 134 TileMap::iterator find = tiles_.find(key); | 134 TileMap::iterator find = tiles_.find(key); |
| 135 if (find != tiles_.end()) | 135 if (find != tiles_.end()) |
| 136 continue; | 136 continue; |
| 137 CreateTile(key.first, key.second, twin_tiling); | 137 CreateTile(key.first, key.second, twin_tiling); |
| 138 } | 138 } |
| 139 } | 139 } |
| 140 | 140 |
| 141 void PictureLayerTiling::SetLayerBounds(const gfx::Size& layer_bounds) { | 141 void PictureLayerTiling::UpdateTilesToCurrentPile( |
| 142 if (layer_bounds_ == layer_bounds) | 142 const Region& layer_invalidation, |
| 143 return; | 143 const gfx::Size& new_layer_bounds) { |
| 144 | 144 DCHECK(!new_layer_bounds.IsEmpty()); |
| 145 DCHECK(!layer_bounds.IsEmpty()); | |
| 146 | 145 |
| 147 gfx::Size old_layer_bounds = layer_bounds_; | 146 gfx::Size old_layer_bounds = layer_bounds_; |
| 148 layer_bounds_ = layer_bounds; | 147 layer_bounds_ = new_layer_bounds; |
| 148 | |
| 149 gfx::Size content_bounds = | 149 gfx::Size content_bounds = |
| 150 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds_, contents_scale_)); | 150 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds_, contents_scale_)); |
| 151 gfx::Size tile_size = tiling_data_.max_texture_size(); | |
| 151 | 152 |
| 152 gfx::Size tile_size = client_->CalculateTileSize(content_bounds); | 153 if (layer_bounds_ != old_layer_bounds) { |
| 153 if (tile_size != tiling_data_.max_texture_size()) { | 154 // Drop tiles outside the new layer bounds if the layer shrank. |
| 155 SetLiveTilesRect( | |
| 156 gfx::IntersectRects(live_tiles_rect_, gfx::Rect(content_bounds))); | |
| 154 tiling_data_.SetTilingRect(gfx::Rect(content_bounds)); | 157 tiling_data_.SetTilingRect(gfx::Rect(content_bounds)); |
| 155 tiling_data_.SetMaxTextureSize(tile_size); | 158 tile_size = client_->CalculateTileSize(content_bounds); |
| 156 Reset(); | |
| 157 return; | |
| 158 } | 159 } |
| 159 | 160 |
| 160 // Any tiles outside our new bounds are invalid and should be dropped. | 161 if (tile_size != tiling_data_.max_texture_size()) { |
| 161 gfx::Rect bounded_live_tiles_rect(live_tiles_rect_); | 162 tiling_data_.SetMaxTextureSize(tile_size); |
| 162 bounded_live_tiles_rect.Intersect(gfx::Rect(content_bounds)); | 163 // When the tile size changes, the TilingData positions no longer work |
| 163 SetLiveTilesRect(bounded_live_tiles_rect); | 164 // as valid keys to the TileMap, so just drop all tiles. |
| 164 tiling_data_.SetTilingRect(gfx::Rect(content_bounds)); | 165 Reset(); |
| 166 } else { | |
| 167 Invalidate(layer_invalidation); | |
| 168 } | |
| 165 | 169 |
| 166 // Create tiles for newly exposed areas. | 170 PicturePileImpl* pile = client_->GetPile(); |
| 167 Region layer_region((gfx::Rect(layer_bounds_))); | 171 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) |
| 168 layer_region.Subtract(gfx::Rect(old_layer_bounds)); | 172 it->second->set_picture_pile(pile); |
| 169 Invalidate(layer_region); | |
| 170 } | |
| 171 | |
| 172 void PictureLayerTiling::RemoveTilesInRegion(const Region& layer_region) { | |
| 173 DoInvalidate(layer_region, false /* recreate_tiles */); | |
| 174 } | 173 } |
| 175 | 174 |
| 176 void PictureLayerTiling::Invalidate(const Region& layer_region) { | 175 void PictureLayerTiling::Invalidate(const Region& layer_region) { |
| 177 DoInvalidate(layer_region, true /* recreate_tiles */); | |
| 178 } | |
| 179 | |
| 180 void PictureLayerTiling::DoInvalidate(const Region& layer_region, | |
| 181 bool recreate_tiles) { | |
| 182 std::vector<TileMapKey> new_tile_keys; | 176 std::vector<TileMapKey> new_tile_keys; |
| 183 gfx::Rect expanded_live_tiles_rect( | |
| 184 tiling_data_.ExpandRectToTileBoundsWithBorders(live_tiles_rect_)); | |
| 185 for (Region::Iterator iter(layer_region); iter.has_rect(); iter.next()) { | 177 for (Region::Iterator iter(layer_region); iter.has_rect(); iter.next()) { |
| 186 gfx::Rect layer_rect = iter.rect(); | 178 gfx::Rect layer_rect = iter.rect(); |
| 187 gfx::Rect content_rect = | 179 gfx::Rect content_rect = |
| 188 gfx::ScaleToEnclosingRect(layer_rect, contents_scale_); | 180 gfx::ScaleToEnclosingRect(layer_rect, contents_scale_); |
| 189 // Avoid needless work by not bothering to invalidate where there aren't | |
| 190 // tiles. | |
| 191 content_rect.Intersect(expanded_live_tiles_rect); | |
|
enne (OOO)
2014/07/11 00:12:04
What happened to this code? Should there be an int
| |
| 192 if (content_rect.IsEmpty()) | |
| 193 continue; | |
| 194 bool include_borders = true; | 181 bool include_borders = true; |
| 195 for (TilingData::Iterator iter( | 182 for (TilingData::Iterator iter( |
| 196 &tiling_data_, content_rect, include_borders); | 183 &tiling_data_, content_rect, include_borders); |
| 197 iter; | 184 iter; |
| 198 ++iter) { | 185 ++iter) { |
| 199 TileMapKey key(iter.index()); | 186 TileMapKey key(iter.index()); |
| 200 TileMap::iterator find = tiles_.find(key); | 187 TileMap::iterator find = tiles_.find(key); |
| 201 if (find == tiles_.end()) | 188 if (find == tiles_.end()) |
| 202 continue; | 189 continue; |
| 203 tiles_.erase(find); | 190 tiles_.erase(find); |
| 204 if (recreate_tiles) | 191 gfx::Rect tile_rect = tiling_data_.TileBounds(key.first, key.second); |
| 192 if (tile_rect.Intersects(live_tiles_rect_)) | |
| 205 new_tile_keys.push_back(key); | 193 new_tile_keys.push_back(key); |
| 206 } | 194 } |
| 207 } | 195 } |
| 208 | 196 |
| 209 if (recreate_tiles) { | 197 if (!new_tile_keys.empty()) { |
| 210 const PictureLayerTiling* twin_tiling = client_->GetTwinTiling(this); | 198 for (size_t i = 0; i < new_tile_keys.size(); ++i) { |
| 211 for (size_t i = 0; i < new_tile_keys.size(); ++i) | 199 // Don't try to share a tile with the twin layer, it's been invalidated so |
| 200 // we have to make our own tile here. | |
| 201 PictureLayerTiling* twin_tiling = NULL; | |
| 212 CreateTile(new_tile_keys[i].first, new_tile_keys[i].second, twin_tiling); | 202 CreateTile(new_tile_keys[i].first, new_tile_keys[i].second, twin_tiling); |
| 203 } | |
| 213 } | 204 } |
| 214 } | 205 } |
| 215 | 206 |
| 216 PictureLayerTiling::CoverageIterator::CoverageIterator() | 207 PictureLayerTiling::CoverageIterator::CoverageIterator() |
| 217 : tiling_(NULL), | 208 : tiling_(NULL), |
| 218 current_tile_(NULL), | 209 current_tile_(NULL), |
| 219 tile_i_(0), | 210 tile_i_(0), |
| 220 tile_j_(0), | 211 tile_j_(0), |
| 221 left_(0), | 212 left_(0), |
| 222 top_(0), | 213 top_(0), |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 615 // Tile holds a ref onto a picture pile. If the tile never gets invalidated | 606 // Tile holds a ref onto a picture pile. If the tile never gets invalidated |
| 616 // and recreated, then that picture pile ref could exist indefinitely. To | 607 // and recreated, then that picture pile ref could exist indefinitely. To |
| 617 // prevent this, ask the client to update the pile to its own ref. This | 608 // prevent this, ask the client to update the pile to its own ref. This |
| 618 // will cause PicturePileImpls and their clones to get deleted once the | 609 // will cause PicturePileImpls and their clones to get deleted once the |
| 619 // corresponding PictureLayerImpl and any in flight raster jobs go out of | 610 // corresponding PictureLayerImpl and any in flight raster jobs go out of |
| 620 // scope. | 611 // scope. |
| 621 it->second->set_picture_pile(active_pile); | 612 it->second->set_picture_pile(active_pile); |
| 622 } | 613 } |
| 623 } | 614 } |
| 624 | 615 |
| 625 void PictureLayerTiling::UpdateTilesToCurrentPile() { | |
| 626 PicturePileImpl* pile = client_->GetPile(); | |
| 627 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { | |
| 628 it->second->set_picture_pile(pile); | |
| 629 } | |
| 630 } | |
| 631 | |
| 632 scoped_ptr<base::Value> PictureLayerTiling::AsValue() const { | 616 scoped_ptr<base::Value> PictureLayerTiling::AsValue() const { |
| 633 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); | 617 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); |
| 634 state->SetInteger("num_tiles", tiles_.size()); | 618 state->SetInteger("num_tiles", tiles_.size()); |
| 635 state->SetDouble("content_scale", contents_scale_); | 619 state->SetDouble("content_scale", contents_scale_); |
| 636 state->Set("tiling_rect", MathUtil::AsValue(TilingRect()).release()); | 620 state->Set("tiling_rect", MathUtil::AsValue(TilingRect()).release()); |
| 637 return state.PassAs<base::Value>(); | 621 return state.PassAs<base::Value>(); |
| 638 } | 622 } |
| 639 | 623 |
| 640 size_t PictureLayerTiling::GPUMemoryUsageInBytes() const { | 624 size_t PictureLayerTiling::GPUMemoryUsageInBytes() const { |
| 641 size_t amount = 0; | 625 size_t amount = 0; |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 973 tiling_->UpdateEvictionCacheIfNeeded(tree_priority_); | 957 tiling_->UpdateEvictionCacheIfNeeded(tree_priority_); |
| 974 tile_iterator_ = tiling_->eviction_tiles_cache_.begin(); | 958 tile_iterator_ = tiling_->eviction_tiles_cache_.begin(); |
| 975 is_valid_ = true; | 959 is_valid_ = true; |
| 976 if (tile_iterator_ != tiling_->eviction_tiles_cache_.end() && | 960 if (tile_iterator_ != tiling_->eviction_tiles_cache_.end() && |
| 977 !(*tile_iterator_)->HasResources()) { | 961 !(*tile_iterator_)->HasResources()) { |
| 978 ++(*this); | 962 ++(*this); |
| 979 } | 963 } |
| 980 } | 964 } |
| 981 | 965 |
| 982 } // namespace cc | 966 } // namespace cc |
| OLD | NEW |