Index: cc/tiles/picture_layer_tiling.cc |
diff --git a/cc/tiles/picture_layer_tiling.cc b/cc/tiles/picture_layer_tiling.cc |
index 03bf211659a017c08cf3c8193b007b8992f6f8fd..fd64ce09a61e35c57d85b716727da292fa02f545 100644 |
--- a/cc/tiles/picture_layer_tiling.cc |
+++ b/cc/tiles/picture_layer_tiling.cc |
@@ -9,6 +9,8 @@ |
#include <limits> |
#include <set> |
+#include "base/containers/hash_tables.h" |
+#include "base/containers/small_map.h" |
#include "base/logging.h" |
#include "base/trace_event/trace_event.h" |
#include "base/trace_event/trace_event_argument.h" |
@@ -230,11 +232,11 @@ void PictureLayerTiling::SetRasterSourceAndResize( |
// Drop tiles outside the new layer bounds if the layer shrank. |
for (int i = after_right + 1; i <= before_right; ++i) { |
for (int j = before_top; j <= before_bottom; ++j) |
- RemoveTileAt(i, j); |
+ RemoveTileAt(i, j, nullptr); |
} |
for (int i = before_left; i <= after_right; ++i) { |
for (int j = after_bottom + 1; j <= before_bottom; ++j) |
- RemoveTileAt(i, j); |
+ RemoveTileAt(i, j, nullptr); |
} |
if (after_right > before_right) { |
@@ -265,39 +267,48 @@ void PictureLayerTiling::RemoveTilesInRegion(const Region& layer_invalidation, |
// twin, so it's slated for removal in the future. |
if (live_tiles_rect_.IsEmpty()) |
return; |
- std::vector<TileMapKey> new_tile_keys; |
+ base::SmallMap<base::hash_map<TileMapKey, gfx::Rect>, 16> remove_tiles; |
reveman
2015/05/28 05:07:25
why 16? can we remove this magic value or add a co
danakj
2015/05/28 18:54:47
Done.
|
gfx::Rect expanded_live_tiles_rect = |
tiling_data_.ExpandRectIgnoringBordersToTileBounds(live_tiles_rect_); |
for (Region::Iterator iter(layer_invalidation); iter.has_rect(); |
iter.next()) { |
gfx::Rect layer_rect = iter.rect(); |
- gfx::Rect content_rect = |
+ // The pixels which are invalid in content space. |
+ gfx::Rect invalid_content_rect = |
gfx::ScaleToEnclosingRect(layer_rect, contents_scale_); |
// Consider tiles inside the live tiles rect even if only their border |
// pixels intersect the invalidation. But don't consider tiles outside |
// the live tiles rect with the same conditions, as they won't exist. |
+ gfx::Rect coverage_content_rect = invalid_content_rect; |
int border_pixels = tiling_data_.border_texels(); |
- content_rect.Inset(-border_pixels, -border_pixels); |
+ coverage_content_rect.Inset(-border_pixels, -border_pixels); |
// Avoid needless work by not bothering to invalidate where there aren't |
// tiles. |
- content_rect.Intersect(expanded_live_tiles_rect); |
- if (content_rect.IsEmpty()) |
+ coverage_content_rect.Intersect(expanded_live_tiles_rect); |
+ if (coverage_content_rect.IsEmpty()) |
continue; |
// Since the content_rect includes border pixels already, don't include |
// borders when iterating to avoid double counting them. |
bool include_borders = false; |
- for ( |
- TilingData::Iterator iter(&tiling_data_, content_rect, include_borders); |
- iter; ++iter) { |
- if (RemoveTileAt(iter.index_x(), iter.index_y())) { |
- if (recreate_tiles) |
- new_tile_keys.push_back(TileMapKey(iter.index())); |
- } |
+ for (TilingData::Iterator iter(&tiling_data_, coverage_content_rect, |
+ include_borders); |
+ iter; ++iter) { |
+ // This also adds the TileMapKey to the map. |
+ remove_tiles[TileMapKey(iter.index())].Union(invalid_content_rect); |
} |
} |
- for (const auto& key : new_tile_keys) |
- CreateTile(key.index_x, key.index_y); |
+ for (const auto& pair : remove_tiles) { |
+ const TileMapKey& key = pair.first; |
+ const gfx::Rect& invalid_content_rect = pair.second; |
+ Tile::Id old_id(0); |
+ // TODO(danakj): This |old_id| will be empty if we are committing to a |
+ // pending tree since there is no tile there to remove. crbug.com/490847 |
+ if (RemoveTileAt(key.index_x, key.index_y, &old_id) && recreate_tiles) { |
+ if (Tile* tile = CreateTile(key.index_x, key.index_y)) |
+ tile->SetInvalidated(invalid_content_rect, old_id); |
+ } |
+ } |
} |
bool PictureLayerTiling::ShouldCreateTileAt(int i, int j) const { |
@@ -495,10 +506,12 @@ gfx::RectF PictureLayerTiling::CoverageIterator::texture_rect() const { |
return texture_rect; |
} |
-bool PictureLayerTiling::RemoveTileAt(int i, int j) { |
+bool PictureLayerTiling::RemoveTileAt(int i, int j, Tile::Id* id) { |
TileMap::iterator found = tiles_.find(TileMapKey(i, j)); |
if (found == tiles_.end()) |
return false; |
+ if (id) |
+ *id = found->second->id(); |
tiles_.erase(found); |
return true; |
} |
@@ -663,7 +676,7 @@ void PictureLayerTiling::SetLiveTilesRect( |
for (TilingData::DifferenceIterator iter(&tiling_data_, live_tiles_rect_, |
new_live_tiles_rect); |
iter; ++iter) { |
- RemoveTileAt(iter.index_x(), iter.index_y()); |
+ RemoveTileAt(iter.index_x(), iter.index_y(), nullptr); |
} |
// Iterate to allocate new tiles for all regions with newly exposed area. |