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 #include <set> | 10 #include <set> |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 67 | 67 |
| 68 PictureLayerTiling::PictureLayerTiling(float contents_scale, | 68 PictureLayerTiling::PictureLayerTiling(float contents_scale, |
| 69 const gfx::Size& layer_bounds, | 69 const gfx::Size& layer_bounds, |
| 70 PictureLayerTilingClient* client) | 70 PictureLayerTilingClient* client) |
| 71 : contents_scale_(contents_scale), | 71 : contents_scale_(contents_scale), |
| 72 layer_bounds_(layer_bounds), | 72 layer_bounds_(layer_bounds), |
| 73 resolution_(NON_IDEAL_RESOLUTION), | 73 resolution_(NON_IDEAL_RESOLUTION), |
| 74 client_(client), | 74 client_(client), |
| 75 tiling_data_(gfx::Size(), gfx::Size(), kBorderTexels), | 75 tiling_data_(gfx::Size(), gfx::Size(), kBorderTexels), |
| 76 last_impl_frame_time_in_seconds_(0.0), | 76 last_impl_frame_time_in_seconds_(0.0), |
| 77 content_to_screen_scale_(0.f), | |
| 78 can_require_tiles_for_activation_(false), | 77 can_require_tiles_for_activation_(false), |
| 78 current_content_to_screen_scale_(0.f), | |
| 79 has_visible_rect_tiles_(false), | 79 has_visible_rect_tiles_(false), |
| 80 has_skewport_rect_tiles_(false), | 80 has_skewport_rect_tiles_(false), |
| 81 has_soon_border_rect_tiles_(false), | 81 has_soon_border_rect_tiles_(false), |
| 82 has_eventually_rect_tiles_(false), | 82 has_eventually_rect_tiles_(false), |
| 83 eviction_tiles_cache_valid_(false), | 83 eviction_tiles_cache_valid_(false), |
| 84 eviction_cache_tree_priority_(SAME_PRIORITY_FOR_BOTH_TREES) { | 84 eviction_cache_tree_priority_(SAME_PRIORITY_FOR_BOTH_TREES) { |
| 85 gfx::Size content_bounds = | 85 gfx::Size content_bounds = |
| 86 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale)); | 86 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale)); |
| 87 gfx::Size tile_size = client_->CalculateTileSize(content_bounds); | 87 gfx::Size tile_size = client_->CalculateTileSize(content_bounds); |
| 88 if (tile_size.IsEmpty()) { | 88 if (tile_size.IsEmpty()) { |
| 89 layer_bounds_ = gfx::Size(); | 89 layer_bounds_ = gfx::Size(); |
| 90 content_bounds = gfx::Size(); | 90 content_bounds = gfx::Size(); |
| 91 } | 91 } |
| 92 | 92 |
| 93 DCHECK(!gfx::ToFlooredSize( | 93 DCHECK(!gfx::ToFlooredSize( |
| 94 gfx::ScaleSize(layer_bounds, contents_scale)).IsEmpty()) << | 94 gfx::ScaleSize(layer_bounds, contents_scale)).IsEmpty()) << |
| 95 "Tiling created with scale too small as contents become empty." << | 95 "Tiling created with scale too small as contents become empty." << |
| 96 " Layer bounds: " << layer_bounds.ToString() << | 96 " Layer bounds: " << layer_bounds.ToString() << |
| 97 " Contents scale: " << contents_scale; | 97 " Contents scale: " << contents_scale; |
| 98 | 98 |
| 99 tiling_data_.SetTilingSize(content_bounds); | 99 tiling_data_.SetTilingSize(content_bounds); |
| 100 tiling_data_.SetMaxTextureSize(tile_size); | 100 tiling_data_.SetMaxTextureSize(tile_size); |
| 101 } | 101 } |
| 102 | 102 |
| 103 PictureLayerTiling::~PictureLayerTiling() { | 103 PictureLayerTiling::~PictureLayerTiling() { |
| 104 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) | 104 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) |
| 105 it->second->set_shared(false); | 105 it->second->set_shared(false); |
| 106 } | 106 } |
| 107 | 107 |
| 108 void PictureLayerTiling::SetClient(PictureLayerTilingClient* client) { | |
| 109 client_ = client; | |
| 110 } | |
| 111 | |
| 112 Tile* PictureLayerTiling::CreateTile(int i, | 108 Tile* PictureLayerTiling::CreateTile(int i, |
| 113 int j, | 109 int j, |
| 114 const PictureLayerTiling* twin_tiling) { | 110 const PictureLayerTiling* twin_tiling) { |
| 115 TileMapKey key(i, j); | 111 TileMapKey key(i, j); |
| 116 DCHECK(tiles_.find(key) == tiles_.end()); | 112 DCHECK(tiles_.find(key) == tiles_.end()); |
| 117 | 113 |
| 118 gfx::Rect paint_rect = tiling_data_.TileBoundsWithBorder(i, j); | 114 gfx::Rect paint_rect = tiling_data_.TileBoundsWithBorder(i, j); |
| 119 gfx::Rect tile_rect = paint_rect; | 115 gfx::Rect tile_rect = paint_rect; |
| 120 tile_rect.set_size(tiling_data_.max_texture_size()); | 116 tile_rect.set_size(tiling_data_.max_texture_size()); |
| 121 | 117 |
| 122 // Check our twin for a valid tile. | 118 // Check our twin for a valid tile. |
| 123 if (twin_tiling && | 119 if (twin_tiling && |
| 124 tiling_data_.max_texture_size() == | 120 tiling_data_.max_texture_size() == |
| 125 twin_tiling->tiling_data_.max_texture_size()) { | 121 twin_tiling->tiling_data_.max_texture_size()) { |
| 126 if (Tile* candidate_tile = twin_tiling->TileAt(i, j)) { | 122 if (Tile* candidate_tile = twin_tiling->TileAt(i, j)) { |
| 127 gfx::Rect rect = | 123 gfx::Rect rect = |
| 128 gfx::ScaleToEnclosingRect(paint_rect, 1.0f / contents_scale_); | 124 gfx::ScaleToEnclosingRect(paint_rect, 1.0f / contents_scale_); |
| 129 const Region* invalidation = client_->GetPendingInvalidation(); | 125 const Region* invalidation = client_->GetPendingInvalidation(); |
| 126 if (invalidation) | |
| 127 LOG(ERROR) << "invalidation " << invalidation->ToString(); | |
| 130 if (!invalidation || !invalidation->Intersects(rect)) { | 128 if (!invalidation || !invalidation->Intersects(rect)) { |
| 129 LOG(ERROR) << "Create shared tile"; | |
| 131 DCHECK(!candidate_tile->is_shared()); | 130 DCHECK(!candidate_tile->is_shared()); |
| 132 DCHECK_EQ(i, candidate_tile->tiling_i_index()); | 131 DCHECK_EQ(i, candidate_tile->tiling_i_index()); |
| 133 DCHECK_EQ(j, candidate_tile->tiling_j_index()); | 132 DCHECK_EQ(j, candidate_tile->tiling_j_index()); |
| 134 candidate_tile->set_shared(true); | 133 candidate_tile->set_shared(true); |
| 135 tiles_[key] = candidate_tile; | 134 tiles_[key] = candidate_tile; |
| 136 return candidate_tile; | 135 return candidate_tile; |
| 137 } | 136 } |
| 138 } | 137 } |
| 139 } | 138 } |
| 139 LOG(ERROR) << "Create unshared tile"; | |
|
enne (OOO)
2014/12/08 23:22:37
<_<
danakj
2014/12/09 18:20:22
Removed
| |
| 140 | 140 |
| 141 // Create a new tile because our twin didn't have a valid one. | 141 // Create a new tile because our twin didn't have a valid one. |
| 142 scoped_refptr<Tile> tile = client_->CreateTile(this, tile_rect); | 142 scoped_refptr<Tile> tile = client_->CreateTile(this, tile_rect); |
| 143 if (tile.get()) { | 143 if (tile.get()) { |
| 144 DCHECK(!tile->is_shared()); | 144 DCHECK(!tile->is_shared()); |
| 145 tile->set_tiling_index(i, j); | 145 tile->set_tiling_index(i, j); |
| 146 tiles_[key] = tile; | 146 tiles_[key] = tile; |
| 147 } | 147 } |
| 148 eviction_tiles_cache_valid_ = false; | 148 eviction_tiles_cache_valid_ = false; |
| 149 return tile.get(); | 149 return tile.get(); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 160 TileMapKey key = iter.index(); | 160 TileMapKey key = iter.index(); |
| 161 TileMap::iterator find = tiles_.find(key); | 161 TileMap::iterator find = tiles_.find(key); |
| 162 if (find != tiles_.end()) | 162 if (find != tiles_.end()) |
| 163 continue; | 163 continue; |
| 164 CreateTile(key.first, key.second, twin_tiling); | 164 CreateTile(key.first, key.second, twin_tiling); |
| 165 } | 165 } |
| 166 | 166 |
| 167 VerifyLiveTilesRect(); | 167 VerifyLiveTilesRect(); |
| 168 } | 168 } |
| 169 | 169 |
| 170 void PictureLayerTiling::UpdateTilesToCurrentRasterSource( | 170 void PictureLayerTiling::CloneTilesAndPropertiesFrom( |
|
enne (OOO)
2014/12/08 23:22:37
Maybe to be consistent with other "push" functions
danakj
2014/12/09 18:20:22
This is called from PLTS::UpdateToCurrentRasterSou
| |
| 171 RasterSource* raster_source, | 171 const PictureLayerTiling& twin_tiling) { |
| 172 const Region& layer_invalidation, | 172 DCHECK_EQ(&twin_tiling, client_->GetPendingOrActiveTwinTiling(this)); |
| 173 const gfx::Size& new_layer_bounds) { | |
| 174 DCHECK(!new_layer_bounds.IsEmpty()); | |
| 175 | 173 |
| 174 Resize(twin_tiling.layer_bounds_); | |
| 175 DCHECK_EQ(twin_tiling.contents_scale_, contents_scale_); | |
| 176 DCHECK_EQ(twin_tiling.layer_bounds().ToString(), layer_bounds().ToString()); | |
| 177 DCHECK_EQ(twin_tiling.tile_size().ToString(), tile_size().ToString()); | |
| 178 | |
| 179 resolution_ = twin_tiling.resolution_; | |
| 180 | |
| 181 SetLiveTilesRect(twin_tiling.live_tiles_rect()); | |
| 182 | |
| 183 // Recreate unshared tiles. The |recycled_twin| does not exist since there | |
| 184 // is a pending twin (which is |twin_tiling|). | |
| 185 PictureLayerTiling* recycled_twin = nullptr; | |
| 186 DCHECK_EQ(recycled_twin, client_->GetRecycledTwinTiling(this)); | |
| 187 std::vector<TileMapKey> to_remove; | |
| 188 for (auto tile_map_pair : tiles_) { | |
| 189 TileMapKey key = tile_map_pair.first; | |
| 190 Tile* tile = tile_map_pair.second.get(); | |
| 191 if (!tile->is_shared()) | |
| 192 to_remove.push_back(key); | |
| 193 } | |
| 194 for (auto key : to_remove) { | |
| 195 RemoveTileAt(key.first, key.second, recycled_twin); | |
|
enne (OOO)
2014/12/08 23:22:37
It's a little awkward to call this recycled_twin,
danakj
2014/12/09 18:20:22
Just trying to give the nullptr a name, otherwise
enne (OOO)
2014/12/09 18:23:40
I think naming it only makes it more confusing. M
danakj
2014/12/09 18:26:07
I think an overload would make it too easy to not
| |
| 196 CreateTile(key.first, key.second, &twin_tiling); | |
| 197 } | |
| 198 | |
| 199 DCHECK_EQ(twin_tiling.tiles_.size(), tiles_.size()); | |
| 200 #if DCHECK_IS_ON | |
| 201 for (auto tile_map_pair : tiles_) | |
| 202 DCHECK(tile_map_pair.second->is_shared()); | |
| 203 #endif | |
| 204 | |
| 205 UpdateTilePriorityRects(twin_tiling.current_content_to_screen_scale_, | |
| 206 twin_tiling.current_visible_rect_, | |
| 207 twin_tiling.current_skewport_rect_, | |
| 208 twin_tiling.current_soon_border_rect_, | |
| 209 twin_tiling.current_eventually_rect_, | |
| 210 twin_tiling.current_occlusion_in_layer_space_); | |
| 211 } | |
| 212 | |
| 213 void PictureLayerTiling::Resize(const gfx::Size& new_layer_bounds) { | |
| 214 gfx::Size layer_bounds = new_layer_bounds; | |
| 176 gfx::Size content_bounds = | 215 gfx::Size content_bounds = |
| 177 gfx::ToCeiledSize(gfx::ScaleSize(new_layer_bounds, contents_scale_)); | 216 gfx::ToCeiledSize(gfx::ScaleSize(new_layer_bounds, contents_scale_)); |
| 178 gfx::Size tile_size = client_->CalculateTileSize(content_bounds); | 217 gfx::Size tile_size = client_->CalculateTileSize(content_bounds); |
| 179 | 218 |
| 180 if (new_layer_bounds != layer_bounds_) { | 219 if (tile_size.IsEmpty()) { |
| 181 if (tile_size.IsEmpty()) { | 220 layer_bounds = gfx::Size(); |
| 182 layer_bounds_ = gfx::Size(); | 221 content_bounds = gfx::Size(); |
| 183 content_bounds = gfx::Size(); | |
| 184 } else { | |
| 185 layer_bounds_ = new_layer_bounds; | |
| 186 } | |
| 187 | |
| 188 // The SetLiveTilesRect() method would drop tiles outside the new bounds, | |
| 189 // but may do so incorrectly if resizing the tiling causes the number of | |
| 190 // tiles in the tiling_data_ to change. | |
| 191 gfx::Rect content_rect(content_bounds); | |
| 192 int before_left = tiling_data_.TileXIndexFromSrcCoord(live_tiles_rect_.x()); | |
| 193 int before_top = tiling_data_.TileYIndexFromSrcCoord(live_tiles_rect_.y()); | |
| 194 int before_right = | |
| 195 tiling_data_.TileXIndexFromSrcCoord(live_tiles_rect_.right() - 1); | |
| 196 int before_bottom = | |
| 197 tiling_data_.TileYIndexFromSrcCoord(live_tiles_rect_.bottom() - 1); | |
| 198 | |
| 199 // The live_tiles_rect_ is clamped to stay within the tiling size as we | |
| 200 // change it. | |
| 201 live_tiles_rect_.Intersect(content_rect); | |
| 202 tiling_data_.SetTilingSize(content_bounds); | |
| 203 | |
| 204 int after_right = -1; | |
| 205 int after_bottom = -1; | |
| 206 if (!live_tiles_rect_.IsEmpty()) { | |
| 207 after_right = | |
| 208 tiling_data_.TileXIndexFromSrcCoord(live_tiles_rect_.right() - 1); | |
| 209 after_bottom = | |
| 210 tiling_data_.TileYIndexFromSrcCoord(live_tiles_rect_.bottom() - 1); | |
| 211 } | |
| 212 | |
| 213 // There is no recycled twin since this is run on the pending tiling. | |
| 214 PictureLayerTiling* recycled_twin = NULL; | |
| 215 DCHECK_EQ(recycled_twin, client_->GetRecycledTwinTiling(this)); | |
| 216 DCHECK_EQ(PENDING_TREE, client_->GetTree()); | |
| 217 | |
| 218 // Drop tiles outside the new layer bounds if the layer shrank. | |
| 219 for (int i = after_right + 1; i <= before_right; ++i) { | |
| 220 for (int j = before_top; j <= before_bottom; ++j) | |
| 221 RemoveTileAt(i, j, recycled_twin); | |
| 222 } | |
| 223 for (int i = before_left; i <= after_right; ++i) { | |
| 224 for (int j = after_bottom + 1; j <= before_bottom; ++j) | |
| 225 RemoveTileAt(i, j, recycled_twin); | |
| 226 } | |
| 227 | |
| 228 // If the layer grew, the live_tiles_rect_ is not changed, but a new row | |
| 229 // and/or column of tiles may now exist inside the same live_tiles_rect_. | |
| 230 const PictureLayerTiling* twin_tiling = | |
| 231 client_->GetPendingOrActiveTwinTiling(this); | |
| 232 if (after_right > before_right) { | |
| 233 DCHECK_EQ(after_right, before_right + 1); | |
| 234 for (int j = before_top; j <= after_bottom; ++j) | |
| 235 CreateTile(after_right, j, twin_tiling); | |
| 236 } | |
| 237 if (after_bottom > before_bottom) { | |
| 238 DCHECK_EQ(after_bottom, before_bottom + 1); | |
| 239 for (int i = before_left; i <= before_right; ++i) | |
| 240 CreateTile(i, after_bottom, twin_tiling); | |
| 241 } | |
| 242 } | 222 } |
| 243 | 223 |
| 224 // The layer bounds are only allowed to be empty when the tile size is empty. | |
| 225 // Otherwise we should not have such a tiling in the first place. | |
| 226 DCHECK_IMPLIES(!tile_size.IsEmpty(), !layer_bounds_.IsEmpty()); | |
| 227 | |
| 228 bool resized = layer_bounds != layer_bounds_; | |
| 229 layer_bounds_ = layer_bounds; | |
| 230 | |
| 244 if (tile_size != tiling_data_.max_texture_size()) { | 231 if (tile_size != tiling_data_.max_texture_size()) { |
| 232 tiling_data_.SetTilingSize(content_bounds); | |
| 245 tiling_data_.SetMaxTextureSize(tile_size); | 233 tiling_data_.SetMaxTextureSize(tile_size); |
| 246 // When the tile size changes, the TilingData positions no longer work | 234 // When the tile size changes, the TilingData positions no longer work |
| 247 // as valid keys to the TileMap, so just drop all tiles. | 235 // as valid keys to the TileMap, so just drop all tiles and clear the live |
| 236 // tiles rect. | |
| 248 Reset(); | 237 Reset(); |
| 249 } else { | 238 return; |
| 250 Invalidate(layer_invalidation); | |
| 251 } | 239 } |
| 252 | 240 |
| 253 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) | 241 if (!resized) |
| 254 it->second->set_raster_source(raster_source); | 242 return; |
| 255 VerifyLiveTilesRect(); | 243 |
| 244 // The SetLiveTilesRect() method would drop tiles outside the new bounds, | |
| 245 // but may do so incorrectly if resizing the tiling causes the number of | |
| 246 // tiles in the tiling_data_ to change. | |
| 247 gfx::Rect content_rect(content_bounds); | |
| 248 int before_left = tiling_data_.TileXIndexFromSrcCoord(live_tiles_rect_.x()); | |
| 249 int before_top = tiling_data_.TileYIndexFromSrcCoord(live_tiles_rect_.y()); | |
| 250 int before_right = | |
| 251 tiling_data_.TileXIndexFromSrcCoord(live_tiles_rect_.right() - 1); | |
| 252 int before_bottom = | |
| 253 tiling_data_.TileYIndexFromSrcCoord(live_tiles_rect_.bottom() - 1); | |
| 254 | |
| 255 // The live_tiles_rect_ is clamped to stay within the tiling size as we | |
| 256 // change it. | |
| 257 live_tiles_rect_.Intersect(content_rect); | |
| 258 tiling_data_.SetTilingSize(content_bounds); | |
| 259 | |
| 260 int after_right = -1; | |
| 261 int after_bottom = -1; | |
| 262 if (!live_tiles_rect_.IsEmpty()) { | |
| 263 after_right = | |
| 264 tiling_data_.TileXIndexFromSrcCoord(live_tiles_rect_.right() - 1); | |
| 265 after_bottom = | |
| 266 tiling_data_.TileYIndexFromSrcCoord(live_tiles_rect_.bottom() - 1); | |
| 267 } | |
| 268 | |
| 269 // There is no recycled twin since this is run on the pending tiling | |
| 270 // during commit, and on the active tree during activate. | |
| 271 PictureLayerTiling* recycled_twin = NULL; | |
| 272 DCHECK_EQ(recycled_twin, client_->GetRecycledTwinTiling(this)); | |
| 273 | |
| 274 // Drop tiles outside the new layer bounds if the layer shrank. | |
| 275 for (int i = after_right + 1; i <= before_right; ++i) { | |
| 276 for (int j = before_top; j <= before_bottom; ++j) | |
| 277 RemoveTileAt(i, j, recycled_twin); | |
| 278 } | |
| 279 for (int i = before_left; i <= after_right; ++i) { | |
| 280 for (int j = after_bottom + 1; j <= before_bottom; ++j) | |
| 281 RemoveTileAt(i, j, recycled_twin); | |
| 282 } | |
| 283 | |
| 284 // If the layer grew, the live_tiles_rect_ is not changed, but a new row | |
| 285 // and/or column of tiles may now exist inside the same live_tiles_rect_. | |
| 286 const PictureLayerTiling* twin_tiling = | |
| 287 client_->GetPendingOrActiveTwinTiling(this); | |
| 288 if (after_right > before_right) { | |
| 289 DCHECK_EQ(after_right, before_right + 1); | |
| 290 for (int j = before_top; j <= after_bottom; ++j) | |
| 291 CreateTile(after_right, j, twin_tiling); | |
| 292 } | |
| 293 if (after_bottom > before_bottom) { | |
| 294 DCHECK_EQ(after_bottom, before_bottom + 1); | |
| 295 for (int i = before_left; i <= before_right; ++i) | |
| 296 CreateTile(i, after_bottom, twin_tiling); | |
| 297 } | |
| 256 } | 298 } |
| 257 | 299 |
| 258 void PictureLayerTiling::RemoveTilesInRegion(const Region& layer_region) { | 300 void PictureLayerTiling::Invalidate(const Region& layer_invalidation) { |
| 259 bool recreate_invalidated_tiles = false; | 301 if (live_tiles_rect_.IsEmpty()) |
| 260 DoInvalidate(layer_region, recreate_invalidated_tiles); | 302 return; |
| 261 } | |
| 262 | |
| 263 void PictureLayerTiling::Invalidate(const Region& layer_region) { | |
| 264 bool recreate_invalidated_tiles = true; | |
| 265 DoInvalidate(layer_region, recreate_invalidated_tiles); | |
| 266 } | |
| 267 | |
| 268 void PictureLayerTiling::DoInvalidate(const Region& layer_region, | |
| 269 bool recreate_invalidated_tiles) { | |
| 270 std::vector<TileMapKey> new_tile_keys; | 303 std::vector<TileMapKey> new_tile_keys; |
| 271 gfx::Rect expanded_live_tiles_rect = | 304 gfx::Rect expanded_live_tiles_rect = |
| 272 tiling_data_.ExpandRectIgnoringBordersToTileBounds(live_tiles_rect_); | 305 tiling_data_.ExpandRectIgnoringBordersToTileBounds(live_tiles_rect_); |
| 273 for (Region::Iterator iter(layer_region); iter.has_rect(); iter.next()) { | 306 for (Region::Iterator iter(layer_invalidation); iter.has_rect(); |
| 307 iter.next()) { | |
| 274 gfx::Rect layer_rect = iter.rect(); | 308 gfx::Rect layer_rect = iter.rect(); |
| 275 gfx::Rect content_rect = | 309 gfx::Rect content_rect = |
| 276 gfx::ScaleToEnclosingRect(layer_rect, contents_scale_); | 310 gfx::ScaleToEnclosingRect(layer_rect, contents_scale_); |
| 277 // Consider tiles inside the live tiles rect even if only their border | 311 // Consider tiles inside the live tiles rect even if only their border |
| 278 // pixels intersect the invalidation. But don't consider tiles outside | 312 // pixels intersect the invalidation. But don't consider tiles outside |
| 279 // the live tiles rect with the same conditions, as they won't exist. | 313 // the live tiles rect with the same conditions, as they won't exist. |
| 280 int border_pixels = tiling_data_.border_texels(); | 314 int border_pixels = tiling_data_.border_texels(); |
| 281 content_rect.Inset(-border_pixels, -border_pixels); | 315 content_rect.Inset(-border_pixels, -border_pixels); |
| 282 // Avoid needless work by not bothering to invalidate where there aren't | 316 // Avoid needless work by not bothering to invalidate where there aren't |
| 283 // tiles. | 317 // tiles. |
| 284 content_rect.Intersect(expanded_live_tiles_rect); | 318 content_rect.Intersect(expanded_live_tiles_rect); |
| 285 if (content_rect.IsEmpty()) | 319 if (content_rect.IsEmpty()) |
| 286 continue; | 320 continue; |
| 287 // Since the content_rect includes border pixels already, don't include | 321 // Since the content_rect includes border pixels already, don't include |
| 288 // borders when iterating to avoid double counting them. | 322 // borders when iterating to avoid double counting them. |
| 289 bool include_borders = false; | 323 bool include_borders = false; |
| 290 for (TilingData::Iterator iter( | 324 for (TilingData::Iterator iter( |
| 291 &tiling_data_, content_rect, include_borders); | 325 &tiling_data_, content_rect, include_borders); |
| 292 iter; | 326 iter; |
| 293 ++iter) { | 327 ++iter) { |
| 294 // There is no recycled twin since this is run on the pending tiling. | 328 // There is no recycled twin for the peding tree during commit, or for the |
|
enne (OOO)
2014/12/08 23:22:37
typo
danakj
2014/12/09 18:20:22
Done.
| |
| 329 // active tree during activation. | |
| 295 PictureLayerTiling* recycled_twin = NULL; | 330 PictureLayerTiling* recycled_twin = NULL; |
| 296 DCHECK_EQ(recycled_twin, client_->GetRecycledTwinTiling(this)); | 331 DCHECK_EQ(recycled_twin, client_->GetRecycledTwinTiling(this)); |
| 297 DCHECK_EQ(PENDING_TREE, client_->GetTree()); | |
| 298 if (RemoveTileAt(iter.index_x(), iter.index_y(), recycled_twin)) | 332 if (RemoveTileAt(iter.index_x(), iter.index_y(), recycled_twin)) |
| 299 new_tile_keys.push_back(iter.index()); | 333 new_tile_keys.push_back(iter.index()); |
| 300 } | 334 } |
| 301 } | 335 } |
| 302 | 336 |
| 303 if (recreate_invalidated_tiles && !new_tile_keys.empty()) { | 337 if (!new_tile_keys.empty()) { |
| 338 // During commit to the pending tree, invalidations can never be shared with | |
| 339 // the active tree since the active tree has different content there. | |
| 340 // However, during activation, invalidations on the active tree can be | |
| 341 // shared with the pending tree always. | |
| 342 const PictureLayerTiling* twin_tiling = nullptr; | |
| 343 if (client_->GetTree() == ACTIVE_TREE) | |
| 344 twin_tiling = client_->GetPendingOrActiveTwinTiling(this); | |
|
enne (OOO)
2014/12/08 23:22:37
Is this required? It seems like for the activation
danakj
2014/12/09 18:20:22
Ya! Thanks this is no longer needed with the new s
| |
| 304 for (size_t i = 0; i < new_tile_keys.size(); ++i) { | 345 for (size_t i = 0; i < new_tile_keys.size(); ++i) { |
| 305 // Don't try to share a tile with the twin layer, it's been invalidated so | |
| 306 // we have to make our own tile here. | |
| 307 const PictureLayerTiling* twin_tiling = NULL; | |
| 308 CreateTile(new_tile_keys[i].first, new_tile_keys[i].second, twin_tiling); | 346 CreateTile(new_tile_keys[i].first, new_tile_keys[i].second, twin_tiling); |
| 309 } | 347 } |
| 310 } | 348 } |
| 311 } | 349 } |
| 312 | 350 |
| 351 void PictureLayerTiling::SetRasterSource( | |
| 352 scoped_refptr<RasterSource> raster_source) { | |
| 353 // Shared (ie. non-invalidated) tiles on the pending tree are updated to use | |
| 354 // the new raster source. When this raster source is activated, the raster | |
| 355 // source will remain valid for shared tiles in the active tree. | |
| 356 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) | |
| 357 it->second->set_raster_source(raster_source); | |
| 358 VerifyLiveTilesRect(); | |
| 359 } | |
| 360 | |
| 313 PictureLayerTiling::CoverageIterator::CoverageIterator() | 361 PictureLayerTiling::CoverageIterator::CoverageIterator() |
| 314 : tiling_(NULL), | 362 : tiling_(NULL), |
| 315 current_tile_(NULL), | 363 current_tile_(NULL), |
| 316 tile_i_(0), | 364 tile_i_(0), |
| 317 tile_j_(0), | 365 tile_j_(0), |
| 318 left_(0), | 366 left_(0), |
| 319 top_(0), | 367 top_(0), |
| 320 right_(-1), | 368 right_(-1), |
| 321 bottom_(-1) { | 369 bottom_(-1) { |
| 322 } | 370 } |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 575 eventually_rect_area, | 623 eventually_rect_area, |
| 576 gfx::Rect(tiling_size()), | 624 gfx::Rect(tiling_size()), |
| 577 &expansion_cache_); | 625 &expansion_cache_); |
| 578 | 626 |
| 579 DCHECK(eventually_rect.IsEmpty() || | 627 DCHECK(eventually_rect.IsEmpty() || |
| 580 gfx::Rect(tiling_size()).Contains(eventually_rect)) | 628 gfx::Rect(tiling_size()).Contains(eventually_rect)) |
| 581 << "tiling_size: " << tiling_size().ToString() | 629 << "tiling_size: " << tiling_size().ToString() |
| 582 << " eventually_rect: " << eventually_rect.ToString(); | 630 << " eventually_rect: " << eventually_rect.ToString(); |
| 583 | 631 |
| 584 // Calculate the soon border rect. | 632 // Calculate the soon border rect. |
| 585 content_to_screen_scale_ = ideal_contents_scale / contents_scale_; | 633 float content_to_screen_scale = ideal_contents_scale / contents_scale_; |
| 586 gfx::Rect soon_border_rect = visible_rect_in_content_space; | 634 gfx::Rect soon_border_rect = visible_rect_in_content_space; |
| 587 float border = kSoonBorderDistanceInScreenPixels / content_to_screen_scale_; | 635 float border = kSoonBorderDistanceInScreenPixels / content_to_screen_scale; |
| 588 soon_border_rect.Inset(-border, -border, -border, -border); | 636 soon_border_rect.Inset(-border, -border, -border, -border); |
| 589 | 637 |
| 590 // Update the tiling state. | |
| 591 SetLiveTilesRect(eventually_rect); | |
| 592 | |
| 593 last_impl_frame_time_in_seconds_ = current_frame_time_in_seconds; | 638 last_impl_frame_time_in_seconds_ = current_frame_time_in_seconds; |
| 594 last_viewport_in_layer_space_ = viewport_in_layer_space; | 639 last_viewport_in_layer_space_ = viewport_in_layer_space; |
| 595 last_visible_rect_in_content_space_ = visible_rect_in_content_space; | 640 last_visible_rect_in_content_space_ = visible_rect_in_content_space; |
| 596 | 641 |
| 597 eviction_tiles_cache_valid_ = false; | 642 SetLiveTilesRect(eventually_rect); |
| 643 UpdateTilePriorityRects( | |
| 644 content_to_screen_scale, visible_rect_in_content_space, skewport, | |
| 645 soon_border_rect, eventually_rect, occlusion_in_layer_space); | |
| 646 } | |
| 598 | 647 |
| 648 void PictureLayerTiling::UpdateTilePriorityRects( | |
| 649 float content_to_screen_scale, | |
| 650 const gfx::Rect& visible_rect_in_content_space, | |
| 651 const gfx::Rect& skewport, | |
| 652 const gfx::Rect& soon_border_rect, | |
| 653 const gfx::Rect& eventually_rect, | |
| 654 const Occlusion& occlusion_in_layer_space) { | |
| 599 current_visible_rect_ = visible_rect_in_content_space; | 655 current_visible_rect_ = visible_rect_in_content_space; |
| 600 current_skewport_rect_ = skewport; | 656 current_skewport_rect_ = skewport; |
| 601 current_soon_border_rect_ = soon_border_rect; | 657 current_soon_border_rect_ = soon_border_rect; |
| 602 current_eventually_rect_ = eventually_rect; | 658 current_eventually_rect_ = eventually_rect; |
| 603 current_occlusion_in_layer_space_ = occlusion_in_layer_space; | 659 current_occlusion_in_layer_space_ = occlusion_in_layer_space; |
| 660 current_content_to_screen_scale_ = content_to_screen_scale; | |
| 604 | 661 |
| 605 // Update has_*_tiles state. | |
| 606 gfx::Rect tiling_rect(tiling_size()); | 662 gfx::Rect tiling_rect(tiling_size()); |
| 607 | |
| 608 has_visible_rect_tiles_ = tiling_rect.Intersects(current_visible_rect_); | 663 has_visible_rect_tiles_ = tiling_rect.Intersects(current_visible_rect_); |
| 609 has_skewport_rect_tiles_ = tiling_rect.Intersects(current_skewport_rect_); | 664 has_skewport_rect_tiles_ = tiling_rect.Intersects(current_skewport_rect_); |
| 610 has_soon_border_rect_tiles_ = | 665 has_soon_border_rect_tiles_ = |
| 611 tiling_rect.Intersects(current_soon_border_rect_); | 666 tiling_rect.Intersects(current_soon_border_rect_); |
| 612 has_eventually_rect_tiles_ = tiling_rect.Intersects(current_eventually_rect_); | 667 has_eventually_rect_tiles_ = tiling_rect.Intersects(current_eventually_rect_); |
| 668 | |
| 669 eviction_tiles_cache_valid_ = false; | |
| 613 } | 670 } |
| 614 | 671 |
| 615 void PictureLayerTiling::SetLiveTilesRect( | 672 void PictureLayerTiling::SetLiveTilesRect( |
| 616 const gfx::Rect& new_live_tiles_rect) { | 673 const gfx::Rect& new_live_tiles_rect) { |
| 617 DCHECK(new_live_tiles_rect.IsEmpty() || | 674 DCHECK(new_live_tiles_rect.IsEmpty() || |
| 618 gfx::Rect(tiling_size()).Contains(new_live_tiles_rect)) | 675 gfx::Rect(tiling_size()).Contains(new_live_tiles_rect)) |
| 619 << "tiling_size: " << tiling_size().ToString() | 676 << "tiling_size: " << tiling_size().ToString() |
| 620 << " new_live_tiles_rect: " << new_live_tiles_rect.ToString(); | 677 << " new_live_tiles_rect: " << new_live_tiles_rect.ToString(); |
| 621 if (live_tiles_rect_ == new_live_tiles_rect) | 678 if (live_tiles_rect_ == new_live_tiles_rect) |
| 622 return; | 679 return; |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 798 tile->set_is_occluded(tree, IsTileOccluded(tile)); | 855 tile->set_is_occluded(tree, IsTileOccluded(tile)); |
| 799 return; | 856 return; |
| 800 } | 857 } |
| 801 | 858 |
| 802 if (tree == PENDING_TREE) | 859 if (tree == PENDING_TREE) |
| 803 tile->set_required_for_activation(false); | 860 tile->set_required_for_activation(false); |
| 804 else | 861 else |
| 805 tile->set_required_for_draw(false); | 862 tile->set_required_for_draw(false); |
| 806 tile->set_is_occluded(tree, false); | 863 tile->set_is_occluded(tree, false); |
| 807 | 864 |
| 808 DCHECK_GT(content_to_screen_scale_, 0.f); | 865 DCHECK_GT(current_content_to_screen_scale_, 0.f); |
| 809 float distance_to_visible = | 866 float distance_to_visible = |
| 810 current_visible_rect_.ManhattanInternalDistance(tile_bounds) * | 867 current_visible_rect_.ManhattanInternalDistance(tile_bounds) * |
| 811 content_to_screen_scale_; | 868 current_content_to_screen_scale_; |
| 812 | 869 |
| 813 if (max_tile_priority_bin <= TilePriority::SOON && | 870 if (max_tile_priority_bin <= TilePriority::SOON && |
| 814 (current_soon_border_rect_.Intersects(tile_bounds) || | 871 (current_soon_border_rect_.Intersects(tile_bounds) || |
| 815 current_skewport_rect_.Intersects(tile_bounds))) { | 872 current_skewport_rect_.Intersects(tile_bounds))) { |
| 816 tile->SetPriority( | 873 tile->SetPriority( |
| 817 tree, | 874 tree, |
| 818 TilePriority(resolution_, TilePriority::SOON, distance_to_visible)); | 875 TilePriority(resolution_, TilePriority::SOON, distance_to_visible)); |
| 819 return; | 876 return; |
| 820 } | 877 } |
| 821 | 878 |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1210 } | 1267 } |
| 1211 current_tile_ = tiling_->TileAt(next_index.first, next_index.second); | 1268 current_tile_ = tiling_->TileAt(next_index.first, next_index.second); |
| 1212 } | 1269 } |
| 1213 | 1270 |
| 1214 if (current_tile_) | 1271 if (current_tile_) |
| 1215 tiling_->UpdateTileAndTwinPriority(current_tile_); | 1272 tiling_->UpdateTileAndTwinPriority(current_tile_); |
| 1216 return *this; | 1273 return *this; |
| 1217 } | 1274 } |
| 1218 | 1275 |
| 1219 } // namespace cc | 1276 } // namespace cc |
| OLD | NEW |