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

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: resizedeletestiles 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
« no previous file with comments | « cc/resources/picture_layer_tiling.h ('k') | cc/resources/picture_layer_tiling_perftest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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( 177 // TODO(danakj): What we really want is to ignore border pixels that intersect
184 tiling_data_.ExpandRectToTileBoundsWithBorders(live_tiles_rect_)); 178 // the rect when choosing which tiles it covers, then expand to those tiles
179 // plus their border pixels.
180 gfx::Rect expanded_live_tiles_rect =
181 tiling_data_.ExpandRectToTileBounds(live_tiles_rect_);
185 for (Region::Iterator iter(layer_region); iter.has_rect(); iter.next()) { 182 for (Region::Iterator iter(layer_region); iter.has_rect(); iter.next()) {
186 gfx::Rect layer_rect = iter.rect(); 183 gfx::Rect layer_rect = iter.rect();
187 gfx::Rect content_rect = 184 gfx::Rect content_rect =
188 gfx::ScaleToEnclosingRect(layer_rect, contents_scale_); 185 gfx::ScaleToEnclosingRect(layer_rect, contents_scale_);
189 // Avoid needless work by not bothering to invalidate where there aren't 186 // Avoid needless work by not bothering to invalidate where there aren't
190 // tiles. 187 // tiles.
191 content_rect.Intersect(expanded_live_tiles_rect); 188 content_rect.Intersect(expanded_live_tiles_rect);
192 if (content_rect.IsEmpty()) 189 if (content_rect.IsEmpty())
193 continue; 190 continue;
194 bool include_borders = true; 191 bool include_borders = true;
195 for (TilingData::Iterator iter( 192 for (TilingData::Iterator iter(
196 &tiling_data_, content_rect, include_borders); 193 &tiling_data_, content_rect, include_borders);
197 iter; 194 iter;
198 ++iter) { 195 ++iter) {
199 TileMapKey key(iter.index()); 196 TileMapKey key(iter.index());
200 TileMap::iterator find = tiles_.find(key); 197 TileMap::iterator find = tiles_.find(key);
201 if (find == tiles_.end()) 198 if (find == tiles_.end())
202 continue; 199 continue;
203 tiles_.erase(find); 200 tiles_.erase(find);
204 if (recreate_tiles) 201 new_tile_keys.push_back(key);
205 new_tile_keys.push_back(key);
206 } 202 }
207 } 203 }
208 204
209 if (recreate_tiles) { 205 if (!new_tile_keys.empty()) {
210 const PictureLayerTiling* twin_tiling = client_->GetTwinTiling(this); 206 for (size_t i = 0; i < new_tile_keys.size(); ++i) {
211 for (size_t i = 0; i < new_tile_keys.size(); ++i) 207 // Don't try to share a tile with the twin layer, it's been invalidated so
208 // we have to make our own tile here.
209 PictureLayerTiling* twin_tiling = NULL;
212 CreateTile(new_tile_keys[i].first, new_tile_keys[i].second, twin_tiling); 210 CreateTile(new_tile_keys[i].first, new_tile_keys[i].second, twin_tiling);
211 }
213 } 212 }
214 } 213 }
215 214
216 PictureLayerTiling::CoverageIterator::CoverageIterator() 215 PictureLayerTiling::CoverageIterator::CoverageIterator()
217 : tiling_(NULL), 216 : tiling_(NULL),
218 current_tile_(NULL), 217 current_tile_(NULL),
219 tile_i_(0), 218 tile_i_(0),
220 tile_j_(0), 219 tile_j_(0),
221 left_(0), 220 left_(0),
222 top_(0), 221 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 614 // 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 615 // 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 616 // 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 617 // will cause PicturePileImpls and their clones to get deleted once the
619 // corresponding PictureLayerImpl and any in flight raster jobs go out of 618 // corresponding PictureLayerImpl and any in flight raster jobs go out of
620 // scope. 619 // scope.
621 it->second->set_picture_pile(active_pile); 620 it->second->set_picture_pile(active_pile);
622 } 621 }
623 } 622 }
624 623
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 { 624 scoped_ptr<base::Value> PictureLayerTiling::AsValue() const {
633 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); 625 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue());
634 state->SetInteger("num_tiles", tiles_.size()); 626 state->SetInteger("num_tiles", tiles_.size());
635 state->SetDouble("content_scale", contents_scale_); 627 state->SetDouble("content_scale", contents_scale_);
636 state->Set("tiling_rect", MathUtil::AsValue(TilingRect()).release()); 628 state->Set("tiling_rect", MathUtil::AsValue(TilingRect()).release());
637 return state.PassAs<base::Value>(); 629 return state.PassAs<base::Value>();
638 } 630 }
639 631
640 size_t PictureLayerTiling::GPUMemoryUsageInBytes() const { 632 size_t PictureLayerTiling::GPUMemoryUsageInBytes() const {
641 size_t amount = 0; 633 size_t amount = 0;
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 tiling_->UpdateEvictionCacheIfNeeded(tree_priority_); 965 tiling_->UpdateEvictionCacheIfNeeded(tree_priority_);
974 tile_iterator_ = tiling_->eviction_tiles_cache_.begin(); 966 tile_iterator_ = tiling_->eviction_tiles_cache_.begin();
975 is_valid_ = true; 967 is_valid_ = true;
976 if (tile_iterator_ != tiling_->eviction_tiles_cache_.end() && 968 if (tile_iterator_ != tiling_->eviction_tiles_cache_.end() &&
977 !(*tile_iterator_)->HasResources()) { 969 !(*tile_iterator_)->HasResources()) {
978 ++(*this); 970 ++(*this);
979 } 971 }
980 } 972 }
981 973
982 } // namespace cc 974 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/picture_layer_tiling.h ('k') | cc/resources/picture_layer_tiling_perftest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698