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

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

Issue 375923005: cc: Explicitly invalidate all dropped recordings on the main thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: invalid-resize: doublecall Created 6 years, 5 months 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 | Annotate | Revision Log
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 10
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 181 // Avoid needless work by not bothering to invalidate where there aren't
190 // tiles. 182 // tiles.
191 content_rect.Intersect(expanded_live_tiles_rect); 183 content_rect.Intersect(live_tiles_rect_);
enne (OOO) 2014/07/11 18:21:54 Are you sure this shouldn't be the expanded_live_t
danakj 2014/07/11 20:15:26 I'm pretty sure.. 1) Only tiles that intersect th
192 if (content_rect.IsEmpty()) 184 if (content_rect.IsEmpty())
193 continue; 185 continue;
194 bool include_borders = true; 186 bool include_borders = true;
195 for (TilingData::Iterator iter( 187 for (TilingData::Iterator iter(
196 &tiling_data_, content_rect, include_borders); 188 &tiling_data_, content_rect, include_borders);
197 iter; 189 iter;
198 ++iter) { 190 ++iter) {
199 TileMapKey key(iter.index()); 191 TileMapKey key(iter.index());
200 TileMap::iterator find = tiles_.find(key); 192 TileMap::iterator find = tiles_.find(key);
201 if (find == tiles_.end()) 193 if (find == tiles_.end())
202 continue; 194 continue;
203 tiles_.erase(find); 195 tiles_.erase(find);
204 if (recreate_tiles) 196 new_tile_keys.push_back(key);
205 new_tile_keys.push_back(key);
206 } 197 }
207 } 198 }
208 199
209 if (recreate_tiles) { 200 if (!new_tile_keys.empty()) {
210 const PictureLayerTiling* twin_tiling = client_->GetTwinTiling(this); 201 for (size_t i = 0; i < new_tile_keys.size(); ++i) {
211 for (size_t i = 0; i < new_tile_keys.size(); ++i) 202 // Don't try to share a tile with the twin layer, it's been invalidated so
203 // we have to make our own tile here.
204 PictureLayerTiling* twin_tiling = NULL;
212 CreateTile(new_tile_keys[i].first, new_tile_keys[i].second, twin_tiling); 205 CreateTile(new_tile_keys[i].first, new_tile_keys[i].second, twin_tiling);
206 }
213 } 207 }
214 } 208 }
215 209
216 PictureLayerTiling::CoverageIterator::CoverageIterator() 210 PictureLayerTiling::CoverageIterator::CoverageIterator()
217 : tiling_(NULL), 211 : tiling_(NULL),
218 current_tile_(NULL), 212 current_tile_(NULL),
219 tile_i_(0), 213 tile_i_(0),
220 tile_j_(0), 214 tile_j_(0),
221 left_(0), 215 left_(0),
222 top_(0), 216 top_(0),
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 // Tile holds a ref onto a picture pile. If the tile never gets invalidated 609 // 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 610 // 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 611 // 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 612 // will cause PicturePileImpls and their clones to get deleted once the
619 // corresponding PictureLayerImpl and any in flight raster jobs go out of 613 // corresponding PictureLayerImpl and any in flight raster jobs go out of
620 // scope. 614 // scope.
621 it->second->set_picture_pile(active_pile); 615 it->second->set_picture_pile(active_pile);
622 } 616 }
623 } 617 }
624 618
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 { 619 scoped_ptr<base::Value> PictureLayerTiling::AsValue() const {
633 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); 620 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue());
634 state->SetInteger("num_tiles", tiles_.size()); 621 state->SetInteger("num_tiles", tiles_.size());
635 state->SetDouble("content_scale", contents_scale_); 622 state->SetDouble("content_scale", contents_scale_);
636 state->Set("tiling_rect", MathUtil::AsValue(TilingRect()).release()); 623 state->Set("tiling_rect", MathUtil::AsValue(TilingRect()).release());
637 return state.PassAs<base::Value>(); 624 return state.PassAs<base::Value>();
638 } 625 }
639 626
640 size_t PictureLayerTiling::GPUMemoryUsageInBytes() const { 627 size_t PictureLayerTiling::GPUMemoryUsageInBytes() const {
641 size_t amount = 0; 628 size_t amount = 0;
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 tiling_->UpdateEvictionCacheIfNeeded(tree_priority_); 960 tiling_->UpdateEvictionCacheIfNeeded(tree_priority_);
974 tile_iterator_ = tiling_->eviction_tiles_cache_.begin(); 961 tile_iterator_ = tiling_->eviction_tiles_cache_.begin();
975 is_valid_ = true; 962 is_valid_ = true;
976 if (tile_iterator_ != tiling_->eviction_tiles_cache_.end() && 963 if (tile_iterator_ != tiling_->eviction_tiles_cache_.end() &&
977 !(*tile_iterator_)->HasResources()) { 964 !(*tile_iterator_)->HasResources()) {
978 ++(*this); 965 ++(*this);
979 } 966 }
980 } 967 }
981 968
982 } // namespace cc 969 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698