| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 contents_scale)).IsEmpty()) | 72 contents_scale)).IsEmpty()) |
| 73 << "Tiling created with scale too small as contents become empty." | 73 << "Tiling created with scale too small as contents become empty." |
| 74 << " Layer bounds: " << raster_source_->GetSize().ToString() | 74 << " Layer bounds: " << raster_source_->GetSize().ToString() |
| 75 << " Contents scale: " << contents_scale; | 75 << " Contents scale: " << contents_scale; |
| 76 | 76 |
| 77 tiling_data_.SetTilingSize(content_bounds); | 77 tiling_data_.SetTilingSize(content_bounds); |
| 78 tiling_data_.SetMaxTextureSize(tile_size); | 78 tiling_data_.SetMaxTextureSize(tile_size); |
| 79 } | 79 } |
| 80 | 80 |
| 81 PictureLayerTiling::~PictureLayerTiling() { | 81 PictureLayerTiling::~PictureLayerTiling() { |
| 82 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) |
| 83 it->second->set_shared(false); |
| 82 } | 84 } |
| 83 | 85 |
| 84 // static | 86 // static |
| 85 float PictureLayerTiling::CalculateSoonBorderDistance( | 87 float PictureLayerTiling::CalculateSoonBorderDistance( |
| 86 const gfx::Rect& visible_rect_in_content_space, | 88 const gfx::Rect& visible_rect_in_content_space, |
| 87 float content_to_screen_scale) { | 89 float content_to_screen_scale) { |
| 88 float max_dimension = std::max(visible_rect_in_content_space.width(), | 90 float max_dimension = std::max(visible_rect_in_content_space.width(), |
| 89 visible_rect_in_content_space.height()); | 91 visible_rect_in_content_space.height()); |
| 90 return std::min( | 92 return std::min( |
| 91 kMaxSoonBorderDistanceInScreenPixels / content_to_screen_scale, | 93 kMaxSoonBorderDistanceInScreenPixels / content_to_screen_scale, |
| 92 max_dimension * kSoonBorderDistanceViewportPercentage); | 94 max_dimension * kSoonBorderDistanceViewportPercentage); |
| 93 } | 95 } |
| 94 | 96 |
| 95 Tile* PictureLayerTiling::CreateTile(int i, int j) { | 97 Tile* PictureLayerTiling::CreateTile(int i, |
| 98 int j, |
| 99 const PictureLayerTiling* twin_tiling, |
| 100 PictureLayerTiling* recycled_twin) { |
| 101 // Can't have both a (pending or active) twin and a recycled twin tiling. |
| 102 DCHECK_IMPLIES(twin_tiling, !recycled_twin); |
| 103 DCHECK_IMPLIES(recycled_twin, !twin_tiling); |
| 96 TileMapKey key(i, j); | 104 TileMapKey key(i, j); |
| 97 DCHECK(tiles_.find(key) == tiles_.end()); | 105 DCHECK(tiles_.find(key) == tiles_.end()); |
| 98 | 106 |
| 99 gfx::Rect paint_rect = tiling_data_.TileBoundsWithBorder(i, j); | 107 gfx::Rect paint_rect = tiling_data_.TileBoundsWithBorder(i, j); |
| 100 gfx::Rect tile_rect = paint_rect; | 108 gfx::Rect tile_rect = paint_rect; |
| 101 tile_rect.set_size(tiling_data_.max_texture_size()); | 109 tile_rect.set_size(tiling_data_.max_texture_size()); |
| 102 | 110 |
| 111 // Check our twin for a valid tile. |
| 112 if (twin_tiling && |
| 113 tiling_data_.max_texture_size() == |
| 114 twin_tiling->tiling_data_.max_texture_size()) { |
| 115 if (Tile* candidate_tile = twin_tiling->TileAt(i, j)) { |
| 116 gfx::Rect rect = |
| 117 gfx::ScaleToEnclosingRect(paint_rect, 1.0f / contents_scale_); |
| 118 const Region* invalidation = client_->GetPendingInvalidation(); |
| 119 if (!invalidation || !invalidation->Intersects(rect)) { |
| 120 DCHECK(!candidate_tile->is_shared()); |
| 121 DCHECK_EQ(i, candidate_tile->tiling_i_index()); |
| 122 DCHECK_EQ(j, candidate_tile->tiling_j_index()); |
| 123 candidate_tile->set_shared(true); |
| 124 tiles_[key] = candidate_tile; |
| 125 return candidate_tile; |
| 126 } |
| 127 } |
| 128 } |
| 129 |
| 103 if (!raster_source_->CoversRect(tile_rect, contents_scale_)) | 130 if (!raster_source_->CoversRect(tile_rect, contents_scale_)) |
| 104 return nullptr; | 131 return nullptr; |
| 105 | 132 |
| 133 // Create a new tile because our twin didn't have a valid one. |
| 106 scoped_refptr<Tile> tile = client_->CreateTile(contents_scale_, tile_rect); | 134 scoped_refptr<Tile> tile = client_->CreateTile(contents_scale_, tile_rect); |
| 135 DCHECK(!tile->is_shared()); |
| 107 tile->set_tiling_index(i, j); | 136 tile->set_tiling_index(i, j); |
| 108 tiles_[key] = tile; | 137 tiles_[key] = tile; |
| 138 |
| 139 if (recycled_twin) { |
| 140 DCHECK(recycled_twin->tiles_.find(key) == recycled_twin->tiles_.end()); |
| 141 // Do what recycled_twin->CreateTile() would do. |
| 142 tile->set_shared(true); |
| 143 recycled_twin->tiles_[key] = tile; |
| 144 } |
| 109 return tile.get(); | 145 return tile.get(); |
| 110 } | 146 } |
| 111 | 147 |
| 112 void PictureLayerTiling::CreateMissingTilesInLiveTilesRect() { | 148 void PictureLayerTiling::CreateMissingTilesInLiveTilesRect() { |
| 149 const PictureLayerTiling* twin_tiling = |
| 150 client_->GetPendingOrActiveTwinTiling(this); |
| 151 // There is no recycled twin during commit from the main thread which is when |
| 152 // this occurs. |
| 153 PictureLayerTiling* null_recycled_twin = nullptr; |
| 154 DCHECK_EQ(null_recycled_twin, client_->GetRecycledTwinTiling(this)); |
| 113 bool include_borders = false; | 155 bool include_borders = false; |
| 114 for (TilingData::Iterator iter(&tiling_data_, live_tiles_rect_, | 156 for (TilingData::Iterator iter( |
| 115 include_borders); | 157 &tiling_data_, live_tiles_rect_, include_borders); |
| 116 iter; ++iter) { | 158 iter; |
| 159 ++iter) { |
| 117 TileMapKey key = iter.index(); | 160 TileMapKey key = iter.index(); |
| 118 TileMap::iterator find = tiles_.find(key); | 161 TileMap::iterator find = tiles_.find(key); |
| 119 if (find != tiles_.end()) | 162 if (find != tiles_.end()) |
| 120 continue; | 163 continue; |
| 164 CreateTile(key.first, key.second, twin_tiling, null_recycled_twin); |
| 165 } |
| 121 | 166 |
| 122 if (ShouldCreateTileAt(key.first, key.second)) | |
| 123 CreateTile(key.first, key.second); | |
| 124 } | |
| 125 VerifyLiveTilesRect(false); | 167 VerifyLiveTilesRect(false); |
| 126 } | 168 } |
| 127 | 169 |
| 128 void PictureLayerTiling::TakeTilesAndPropertiesFrom( | 170 void PictureLayerTiling::CloneTilesAndPropertiesFrom( |
| 129 PictureLayerTiling* pending_twin, | 171 const PictureLayerTiling& twin_tiling) { |
| 130 const Region& layer_invalidation) { | 172 DCHECK_EQ(&twin_tiling, client_->GetPendingOrActiveTwinTiling(this)); |
| 131 TRACE_EVENT0("cc", "TakeTilesAndPropertiesFrom"); | |
| 132 SetRasterSourceAndResize(pending_twin->raster_source_); | |
| 133 | 173 |
| 134 RemoveTilesInRegion(layer_invalidation, false /* recreate tiles */); | 174 SetRasterSourceAndResize(twin_tiling.raster_source_); |
| 175 DCHECK_EQ(twin_tiling.contents_scale_, contents_scale_); |
| 176 DCHECK_EQ(twin_tiling.raster_source_, raster_source_); |
| 177 DCHECK_EQ(twin_tiling.tile_size().ToString(), tile_size().ToString()); |
| 135 | 178 |
| 136 for (TileMap::value_type& tile_pair : tiles_) | 179 resolution_ = twin_tiling.resolution_; |
| 137 tile_pair.second->set_raster_source(raster_source_.get()); | |
| 138 | 180 |
| 139 resolution_ = pending_twin->resolution_; | 181 SetLiveTilesRect(twin_tiling.live_tiles_rect()); |
| 140 if (live_tiles_rect_.IsEmpty()) | |
| 141 live_tiles_rect_ = pending_twin->live_tiles_rect(); | |
| 142 else | |
| 143 SetLiveTilesRect(pending_twin->live_tiles_rect()); | |
| 144 | 182 |
| 145 if (tiles_.size() < pending_twin->tiles_.size()) { | 183 // Recreate unshared tiles. |
| 146 tiles_.swap(pending_twin->tiles_); | 184 std::vector<TileMapKey> to_remove; |
| 147 tiles_.insert(pending_twin->tiles_.begin(), pending_twin->tiles_.end()); | 185 for (const auto& tile_map_pair : tiles_) { |
| 148 } else { | 186 TileMapKey key = tile_map_pair.first; |
| 149 for (TileMap::value_type& tile_pair : pending_twin->tiles_) | 187 Tile* tile = tile_map_pair.second.get(); |
| 150 tiles_[tile_pair.first].swap(tile_pair.second); | 188 if (!tile->is_shared()) |
| 189 to_remove.push_back(key); |
| 151 } | 190 } |
| 152 pending_twin->tiles_.clear(); | 191 // The recycled twin does not exist since there is a pending twin (which is |
| 192 // |twin_tiling|). |
| 193 PictureLayerTiling* null_recycled_twin = nullptr; |
| 194 DCHECK_EQ(null_recycled_twin, client_->GetRecycledTwinTiling(this)); |
| 195 for (const auto& key : to_remove) { |
| 196 RemoveTileAt(key.first, key.second, null_recycled_twin); |
| 197 CreateTile(key.first, key.second, &twin_tiling, null_recycled_twin); |
| 198 } |
| 153 | 199 |
| 200 // Create any missing tiles from the |twin_tiling|. |
| 201 for (const auto& tile_map_pair : twin_tiling.tiles_) { |
| 202 TileMapKey key = tile_map_pair.first; |
| 203 Tile* tile = tile_map_pair.second.get(); |
| 204 if (!tile->is_shared()) |
| 205 CreateTile(key.first, key.second, &twin_tiling, null_recycled_twin); |
| 206 } |
| 207 |
| 208 DCHECK_EQ(twin_tiling.tiles_.size(), tiles_.size()); |
| 209 #if DCHECK_IS_ON() |
| 210 for (const auto& tile_map_pair : tiles_) |
| 211 DCHECK(tile_map_pair.second->is_shared()); |
| 154 VerifyLiveTilesRect(false); | 212 VerifyLiveTilesRect(false); |
| 213 #endif |
| 155 | 214 |
| 156 SetTilePriorityRects(pending_twin->current_content_to_screen_scale_, | 215 UpdateTilePriorityRects(twin_tiling.current_content_to_screen_scale_, |
| 157 pending_twin->current_visible_rect_, | 216 twin_tiling.current_visible_rect_, |
| 158 pending_twin->current_skewport_rect_, | 217 twin_tiling.current_skewport_rect_, |
| 159 pending_twin->current_soon_border_rect_, | 218 twin_tiling.current_soon_border_rect_, |
| 160 pending_twin->current_eventually_rect_, | 219 twin_tiling.current_eventually_rect_, |
| 161 pending_twin->current_occlusion_in_layer_space_); | 220 twin_tiling.current_occlusion_in_layer_space_); |
| 162 } | 221 } |
| 163 | 222 |
| 164 void PictureLayerTiling::SetRasterSourceAndResize( | 223 void PictureLayerTiling::SetRasterSourceAndResize( |
| 165 scoped_refptr<RasterSource> raster_source) { | 224 scoped_refptr<RasterSource> raster_source) { |
| 166 DCHECK(!raster_source->IsSolidColor()); | 225 DCHECK(!raster_source->IsSolidColor()); |
| 167 gfx::Size old_layer_bounds = raster_source_->GetSize(); | 226 gfx::Size old_layer_bounds = raster_source_->GetSize(); |
| 168 raster_source_.swap(raster_source); | 227 raster_source_.swap(raster_source); |
| 169 gfx::Size new_layer_bounds = raster_source_->GetSize(); | 228 gfx::Size new_layer_bounds = raster_source_->GetSize(); |
| 170 gfx::Size content_bounds = | 229 gfx::Size content_bounds = |
| 171 gfx::ToCeiledSize(gfx::ScaleSize(new_layer_bounds, contents_scale_)); | 230 gfx::ToCeiledSize(gfx::ScaleSize(new_layer_bounds, contents_scale_)); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 int after_bottom = -1; | 263 int after_bottom = -1; |
| 205 if (!live_tiles_rect_.IsEmpty()) { | 264 if (!live_tiles_rect_.IsEmpty()) { |
| 206 after_right = | 265 after_right = |
| 207 tiling_data_.TileXIndexFromSrcCoord(live_tiles_rect_.right() - 1); | 266 tiling_data_.TileXIndexFromSrcCoord(live_tiles_rect_.right() - 1); |
| 208 after_bottom = | 267 after_bottom = |
| 209 tiling_data_.TileYIndexFromSrcCoord(live_tiles_rect_.bottom() - 1); | 268 tiling_data_.TileYIndexFromSrcCoord(live_tiles_rect_.bottom() - 1); |
| 210 } | 269 } |
| 211 | 270 |
| 212 // There is no recycled twin since this is run on the pending tiling | 271 // There is no recycled twin since this is run on the pending tiling |
| 213 // during commit, and on the active tree during activate. | 272 // during commit, and on the active tree during activate. |
| 273 PictureLayerTiling* null_recycled_twin = nullptr; |
| 274 DCHECK_EQ(null_recycled_twin, client_->GetRecycledTwinTiling(this)); |
| 275 |
| 214 // Drop tiles outside the new layer bounds if the layer shrank. | 276 // Drop tiles outside the new layer bounds if the layer shrank. |
| 215 for (int i = after_right + 1; i <= before_right; ++i) { | 277 for (int i = after_right + 1; i <= before_right; ++i) { |
| 216 for (int j = before_top; j <= before_bottom; ++j) | 278 for (int j = before_top; j <= before_bottom; ++j) |
| 217 RemoveTileAt(i, j); | 279 RemoveTileAt(i, j, null_recycled_twin); |
| 218 } | 280 } |
| 219 for (int i = before_left; i <= after_right; ++i) { | 281 for (int i = before_left; i <= after_right; ++i) { |
| 220 for (int j = after_bottom + 1; j <= before_bottom; ++j) | 282 for (int j = after_bottom + 1; j <= before_bottom; ++j) |
| 221 RemoveTileAt(i, j); | 283 RemoveTileAt(i, j, null_recycled_twin); |
| 222 } | 284 } |
| 223 | 285 |
| 286 // If the layer grew, the live_tiles_rect_ is not changed, but a new row |
| 287 // and/or column of tiles may now exist inside the same live_tiles_rect_. |
| 288 const PictureLayerTiling* twin_tiling = |
| 289 client_->GetPendingOrActiveTwinTiling(this); |
| 224 if (after_right > before_right) { | 290 if (after_right > before_right) { |
| 225 DCHECK_EQ(after_right, before_right + 1); | 291 DCHECK_EQ(after_right, before_right + 1); |
| 226 for (int j = before_top; j <= after_bottom; ++j) { | 292 for (int j = before_top; j <= after_bottom; ++j) |
| 227 if (ShouldCreateTileAt(after_right, j)) | 293 CreateTile(after_right, j, twin_tiling, null_recycled_twin); |
| 228 CreateTile(after_right, j); | |
| 229 } | |
| 230 } | 294 } |
| 231 if (after_bottom > before_bottom) { | 295 if (after_bottom > before_bottom) { |
| 232 DCHECK_EQ(after_bottom, before_bottom + 1); | 296 DCHECK_EQ(after_bottom, before_bottom + 1); |
| 233 for (int i = before_left; i <= before_right; ++i) { | 297 for (int i = before_left; i <= before_right; ++i) |
| 234 if (ShouldCreateTileAt(i, after_bottom)) | 298 CreateTile(i, after_bottom, twin_tiling, null_recycled_twin); |
| 235 CreateTile(i, after_bottom); | |
| 236 } | |
| 237 } | 299 } |
| 238 } | 300 } |
| 239 | 301 |
| 240 void PictureLayerTiling::Invalidate(const Region& layer_invalidation) { | 302 void PictureLayerTiling::Invalidate(const Region& layer_invalidation) { |
| 241 // We don't need to invalidate the pending tiling, since | |
| 242 // CreateMissingTilesInLiveTilesRect will populate all the tiles that we need. | |
| 243 if (client_->GetTree() == PENDING_TREE) | |
| 244 return; | |
| 245 | |
| 246 DCHECK(!client_->GetPendingOrActiveTwinTiling(this)); | |
| 247 RemoveTilesInRegion(layer_invalidation, true /* recreate tiles */); | |
| 248 } | |
| 249 | |
| 250 void PictureLayerTiling::RemoveTilesInRegion(const Region& layer_invalidation, | |
| 251 bool recreate_tiles) { | |
| 252 // We only invalidate the active tiling when it's orphaned: it has no pending | |
| 253 // twin, so it's slated for removal in the future. | |
| 254 if (live_tiles_rect_.IsEmpty()) | 303 if (live_tiles_rect_.IsEmpty()) |
| 255 return; | 304 return; |
| 256 std::vector<TileMapKey> new_tile_keys; | 305 std::vector<TileMapKey> new_tile_keys; |
| 257 gfx::Rect expanded_live_tiles_rect = | 306 gfx::Rect expanded_live_tiles_rect = |
| 258 tiling_data_.ExpandRectIgnoringBordersToTileBounds(live_tiles_rect_); | 307 tiling_data_.ExpandRectIgnoringBordersToTileBounds(live_tiles_rect_); |
| 259 for (Region::Iterator iter(layer_invalidation); iter.has_rect(); | 308 for (Region::Iterator iter(layer_invalidation); iter.has_rect(); |
| 260 iter.next()) { | 309 iter.next()) { |
| 261 gfx::Rect layer_rect = iter.rect(); | 310 gfx::Rect layer_rect = iter.rect(); |
| 262 gfx::Rect content_rect = | 311 gfx::Rect content_rect = |
| 263 gfx::ScaleToEnclosingRect(layer_rect, contents_scale_); | 312 gfx::ScaleToEnclosingRect(layer_rect, contents_scale_); |
| 264 // Consider tiles inside the live tiles rect even if only their border | 313 // Consider tiles inside the live tiles rect even if only their border |
| 265 // pixels intersect the invalidation. But don't consider tiles outside | 314 // pixels intersect the invalidation. But don't consider tiles outside |
| 266 // the live tiles rect with the same conditions, as they won't exist. | 315 // the live tiles rect with the same conditions, as they won't exist. |
| 267 int border_pixels = tiling_data_.border_texels(); | 316 int border_pixels = tiling_data_.border_texels(); |
| 268 content_rect.Inset(-border_pixels, -border_pixels); | 317 content_rect.Inset(-border_pixels, -border_pixels); |
| 269 // Avoid needless work by not bothering to invalidate where there aren't | 318 // Avoid needless work by not bothering to invalidate where there aren't |
| 270 // tiles. | 319 // tiles. |
| 271 content_rect.Intersect(expanded_live_tiles_rect); | 320 content_rect.Intersect(expanded_live_tiles_rect); |
| 272 if (content_rect.IsEmpty()) | 321 if (content_rect.IsEmpty()) |
| 273 continue; | 322 continue; |
| 274 // Since the content_rect includes border pixels already, don't include | 323 // Since the content_rect includes border pixels already, don't include |
| 275 // borders when iterating to avoid double counting them. | 324 // borders when iterating to avoid double counting them. |
| 276 bool include_borders = false; | 325 bool include_borders = false; |
| 277 for ( | 326 for (TilingData::Iterator iter( |
| 278 TilingData::Iterator iter(&tiling_data_, content_rect, include_borders); | 327 &tiling_data_, content_rect, include_borders); |
| 279 iter; ++iter) { | 328 iter; |
| 280 if (RemoveTileAt(iter.index_x(), iter.index_y())) { | 329 ++iter) { |
| 281 if (recreate_tiles) | 330 // There is no recycled twin for the pending tree during commit, or for |
| 282 new_tile_keys.push_back(iter.index()); | 331 // the active tree during activation. |
| 283 } | 332 PictureLayerTiling* null_recycled_twin = nullptr; |
| 333 DCHECK_EQ(null_recycled_twin, client_->GetRecycledTwinTiling(this)); |
| 334 if (RemoveTileAt(iter.index_x(), iter.index_y(), null_recycled_twin)) |
| 335 new_tile_keys.push_back(iter.index()); |
| 284 } | 336 } |
| 285 } | 337 } |
| 286 | 338 |
| 287 for (const auto& key : new_tile_keys) | 339 if (!new_tile_keys.empty()) { |
| 288 CreateTile(key.first, key.second); | 340 // During commit from the main thread, invalidations can never be shared |
| 341 // with the active tree since the active tree has different content there. |
| 342 // And when invalidating an active-tree tiling, it means there was no |
| 343 // pending tiling to clone from. |
| 344 const PictureLayerTiling* null_twin_tiling = nullptr; |
| 345 PictureLayerTiling* null_recycled_twin = nullptr; |
| 346 DCHECK_EQ(null_recycled_twin, client_->GetRecycledTwinTiling(this)); |
| 347 for (size_t i = 0; i < new_tile_keys.size(); ++i) { |
| 348 CreateTile(new_tile_keys[i].first, new_tile_keys[i].second, |
| 349 null_twin_tiling, null_recycled_twin); |
| 350 } |
| 351 } |
| 289 } | 352 } |
| 290 | 353 |
| 291 void PictureLayerTiling::SetRasterSourceOnTiles() { | 354 void PictureLayerTiling::SetRasterSourceOnTiles() { |
| 292 if (client_->GetTree() == PENDING_TREE) | 355 // Shared (ie. non-invalidated) tiles on the pending tree are updated to use |
| 293 return; | 356 // the new raster source. When this raster source is activated, the raster |
| 294 | 357 // source will remain valid for shared tiles in the active tree. |
| 295 for (TileMap::value_type& tile_pair : tiles_) | 358 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) |
| 296 tile_pair.second->set_raster_source(raster_source_.get()); | 359 it->second->set_raster_source(raster_source_); |
| 297 } | 360 VerifyLiveTilesRect(false); |
| 298 | |
| 299 bool PictureLayerTiling::ShouldCreateTileAt(int i, int j) const { | |
| 300 // Active tree should always create a tile. The reason for this is that active | |
| 301 // tree represents content that we draw on screen, which means that whenever | |
| 302 // we check whether a tile should exist somewhere, the answer is yes. This | |
| 303 // doesn't mean it will actually be created (if raster source doesn't cover | |
| 304 // the tile for instance). Pending tree, on the other hand, should only be | |
| 305 // creating tiles that are different from the current active tree, which is | |
| 306 // represented by the logic in the rest of the function. | |
| 307 if (client_->GetTree() == ACTIVE_TREE) | |
| 308 return true; | |
| 309 | |
| 310 // If the pending tree has no active twin, then it needs to create all tiles. | |
| 311 const PictureLayerTiling* active_twin = | |
| 312 client_->GetPendingOrActiveTwinTiling(this); | |
| 313 if (!active_twin) | |
| 314 return true; | |
| 315 | |
| 316 // Pending tree will override the entire active tree if indices don't match. | |
| 317 if (!TilingMatchesTileIndices(active_twin)) | |
| 318 return true; | |
| 319 | |
| 320 gfx::Rect paint_rect = tiling_data_.TileBoundsWithBorder(i, j); | |
| 321 gfx::Rect tile_rect = paint_rect; | |
| 322 tile_rect.set_size(tiling_data_.max_texture_size()); | |
| 323 | |
| 324 // If the active tree can't create a tile, because of its raster source, then | |
| 325 // the pending tree should create one. | |
| 326 if (!active_twin->raster_source()->CoversRect(tile_rect, contents_scale())) | |
| 327 return true; | |
| 328 | |
| 329 const Region* layer_invalidation = client_->GetPendingInvalidation(); | |
| 330 gfx::Rect layer_rect = | |
| 331 gfx::ScaleToEnclosingRect(tile_rect, 1.f / contents_scale()); | |
| 332 | |
| 333 // If this tile is invalidated, then the pending tree should create one. | |
| 334 if (layer_invalidation && layer_invalidation->Intersects(layer_rect)) | |
| 335 return true; | |
| 336 | |
| 337 // If the active tree doesn't have a tile here, but it's in the pending tree's | |
| 338 // visible rect, then the pending tree should create a tile. This can happen | |
| 339 // if the pending visible rect is outside of the active tree's live tiles | |
| 340 // rect. In those situations, we need to block activation until we're ready to | |
| 341 // display content, which will have to come from the pending tree. | |
| 342 if (!active_twin->TileAt(i, j) && current_visible_rect_.Intersects(tile_rect)) | |
| 343 return true; | |
| 344 | |
| 345 // In all other cases, the pending tree doesn't need to create a tile. | |
| 346 return false; | |
| 347 } | |
| 348 | |
| 349 bool PictureLayerTiling::TilingMatchesTileIndices( | |
| 350 const PictureLayerTiling* twin) const { | |
| 351 return tiling_data_.max_texture_size() == | |
| 352 twin->tiling_data_.max_texture_size(); | |
| 353 } | 361 } |
| 354 | 362 |
| 355 PictureLayerTiling::CoverageIterator::CoverageIterator() | 363 PictureLayerTiling::CoverageIterator::CoverageIterator() |
| 356 : tiling_(NULL), | 364 : tiling_(NULL), |
| 357 current_tile_(NULL), | 365 current_tile_(NULL), |
| 358 tile_i_(0), | 366 tile_i_(0), |
| 359 tile_j_(0), | 367 tile_j_(0), |
| 360 left_(0), | 368 left_(0), |
| 361 top_(0), | 369 top_(0), |
| 362 right_(-1), | 370 right_(-1), |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 texture_rect.Scale(dest_to_content_scale_, | 492 texture_rect.Scale(dest_to_content_scale_, |
| 485 dest_to_content_scale_); | 493 dest_to_content_scale_); |
| 486 texture_rect.Intersect(gfx::Rect(tiling_->tiling_size())); | 494 texture_rect.Intersect(gfx::Rect(tiling_->tiling_size())); |
| 487 if (texture_rect.IsEmpty()) | 495 if (texture_rect.IsEmpty()) |
| 488 return texture_rect; | 496 return texture_rect; |
| 489 texture_rect.Offset(-tex_origin.OffsetFromOrigin()); | 497 texture_rect.Offset(-tex_origin.OffsetFromOrigin()); |
| 490 | 498 |
| 491 return texture_rect; | 499 return texture_rect; |
| 492 } | 500 } |
| 493 | 501 |
| 494 bool PictureLayerTiling::RemoveTileAt(int i, int j) { | 502 bool PictureLayerTiling::RemoveTileAt(int i, |
| 503 int j, |
| 504 PictureLayerTiling* recycled_twin) { |
| 495 TileMap::iterator found = tiles_.find(TileMapKey(i, j)); | 505 TileMap::iterator found = tiles_.find(TileMapKey(i, j)); |
| 496 if (found == tiles_.end()) | 506 if (found == tiles_.end()) |
| 497 return false; | 507 return false; |
| 508 found->second->set_shared(false); |
| 498 tiles_.erase(found); | 509 tiles_.erase(found); |
| 510 if (recycled_twin) { |
| 511 // Recycled twin does not also have a recycled twin, so pass null. |
| 512 recycled_twin->RemoveTileAt(i, j, nullptr); |
| 513 } |
| 499 return true; | 514 return true; |
| 500 } | 515 } |
| 501 | 516 |
| 502 void PictureLayerTiling::Reset() { | 517 void PictureLayerTiling::Reset() { |
| 503 live_tiles_rect_ = gfx::Rect(); | 518 live_tiles_rect_ = gfx::Rect(); |
| 519 PictureLayerTiling* recycled_twin = client_->GetRecycledTwinTiling(this); |
| 520 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { |
| 521 it->second->set_shared(false); |
| 522 if (recycled_twin) |
| 523 recycled_twin->RemoveTileAt(it->first.first, it->first.second, nullptr); |
| 524 } |
| 504 tiles_.clear(); | 525 tiles_.clear(); |
| 505 } | 526 } |
| 506 | 527 |
| 507 gfx::Rect PictureLayerTiling::ComputeSkewport( | 528 gfx::Rect PictureLayerTiling::ComputeSkewport( |
| 508 double current_frame_time_in_seconds, | 529 double current_frame_time_in_seconds, |
| 509 const gfx::Rect& visible_rect_in_content_space) const { | 530 const gfx::Rect& visible_rect_in_content_space) const { |
| 510 gfx::Rect skewport = visible_rect_in_content_space; | 531 gfx::Rect skewport = visible_rect_in_content_space; |
| 511 if (skewport.IsEmpty()) | 532 if (skewport.IsEmpty()) |
| 512 return skewport; | 533 return skewport; |
| 513 | 534 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 float content_to_screen_scale = ideal_contents_scale / contents_scale_; | 624 float content_to_screen_scale = ideal_contents_scale / contents_scale_; |
| 604 gfx::Rect soon_border_rect = visible_rect_in_content_space; | 625 gfx::Rect soon_border_rect = visible_rect_in_content_space; |
| 605 float border = CalculateSoonBorderDistance(visible_rect_in_content_space, | 626 float border = CalculateSoonBorderDistance(visible_rect_in_content_space, |
| 606 content_to_screen_scale); | 627 content_to_screen_scale); |
| 607 soon_border_rect.Inset(-border, -border, -border, -border); | 628 soon_border_rect.Inset(-border, -border, -border, -border); |
| 608 | 629 |
| 609 UpdateVisibleRectHistory(current_frame_time_in_seconds, | 630 UpdateVisibleRectHistory(current_frame_time_in_seconds, |
| 610 visible_rect_in_content_space); | 631 visible_rect_in_content_space); |
| 611 last_viewport_in_layer_space_ = viewport_in_layer_space; | 632 last_viewport_in_layer_space_ = viewport_in_layer_space; |
| 612 | 633 |
| 613 SetTilePriorityRects(content_to_screen_scale, visible_rect_in_content_space, | |
| 614 skewport, soon_border_rect, eventually_rect, | |
| 615 occlusion_in_layer_space); | |
| 616 SetLiveTilesRect(eventually_rect); | 634 SetLiveTilesRect(eventually_rect); |
| 635 UpdateTilePriorityRects( |
| 636 content_to_screen_scale, visible_rect_in_content_space, skewport, |
| 637 soon_border_rect, eventually_rect, occlusion_in_layer_space); |
| 617 return true; | 638 return true; |
| 618 } | 639 } |
| 619 | 640 |
| 620 void PictureLayerTiling::SetTilePriorityRects( | 641 void PictureLayerTiling::UpdateTilePriorityRects( |
| 621 float content_to_screen_scale, | 642 float content_to_screen_scale, |
| 622 const gfx::Rect& visible_rect_in_content_space, | 643 const gfx::Rect& visible_rect_in_content_space, |
| 623 const gfx::Rect& skewport, | 644 const gfx::Rect& skewport, |
| 624 const gfx::Rect& soon_border_rect, | 645 const gfx::Rect& soon_border_rect, |
| 625 const gfx::Rect& eventually_rect, | 646 const gfx::Rect& eventually_rect, |
| 626 const Occlusion& occlusion_in_layer_space) { | 647 const Occlusion& occlusion_in_layer_space) { |
| 627 current_visible_rect_ = visible_rect_in_content_space; | 648 current_visible_rect_ = visible_rect_in_content_space; |
| 628 current_skewport_rect_ = skewport; | 649 current_skewport_rect_ = skewport; |
| 629 current_soon_border_rect_ = soon_border_rect; | 650 current_soon_border_rect_ = soon_border_rect; |
| 630 current_eventually_rect_ = eventually_rect; | 651 current_eventually_rect_ = eventually_rect; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 641 | 662 |
| 642 void PictureLayerTiling::SetLiveTilesRect( | 663 void PictureLayerTiling::SetLiveTilesRect( |
| 643 const gfx::Rect& new_live_tiles_rect) { | 664 const gfx::Rect& new_live_tiles_rect) { |
| 644 DCHECK(new_live_tiles_rect.IsEmpty() || | 665 DCHECK(new_live_tiles_rect.IsEmpty() || |
| 645 gfx::Rect(tiling_size()).Contains(new_live_tiles_rect)) | 666 gfx::Rect(tiling_size()).Contains(new_live_tiles_rect)) |
| 646 << "tiling_size: " << tiling_size().ToString() | 667 << "tiling_size: " << tiling_size().ToString() |
| 647 << " new_live_tiles_rect: " << new_live_tiles_rect.ToString(); | 668 << " new_live_tiles_rect: " << new_live_tiles_rect.ToString(); |
| 648 if (live_tiles_rect_ == new_live_tiles_rect) | 669 if (live_tiles_rect_ == new_live_tiles_rect) |
| 649 return; | 670 return; |
| 650 | 671 |
| 672 PictureLayerTiling* recycled_twin = client_->GetRecycledTwinTiling(this); |
| 673 |
| 651 // Iterate to delete all tiles outside of our new live_tiles rect. | 674 // Iterate to delete all tiles outside of our new live_tiles rect. |
| 652 for (TilingData::DifferenceIterator iter(&tiling_data_, live_tiles_rect_, | 675 for (TilingData::DifferenceIterator iter(&tiling_data_, |
| 676 live_tiles_rect_, |
| 653 new_live_tiles_rect); | 677 new_live_tiles_rect); |
| 654 iter; ++iter) { | 678 iter; |
| 655 RemoveTileAt(iter.index_x(), iter.index_y()); | 679 ++iter) { |
| 680 RemoveTileAt(iter.index_x(), iter.index_y(), recycled_twin); |
| 656 } | 681 } |
| 657 | 682 |
| 683 const PictureLayerTiling* twin_tiling = |
| 684 client_->GetPendingOrActiveTwinTiling(this); |
| 685 |
| 658 // Iterate to allocate new tiles for all regions with newly exposed area. | 686 // Iterate to allocate new tiles for all regions with newly exposed area. |
| 659 for (TilingData::DifferenceIterator iter(&tiling_data_, new_live_tiles_rect, | 687 for (TilingData::DifferenceIterator iter(&tiling_data_, |
| 688 new_live_tiles_rect, |
| 660 live_tiles_rect_); | 689 live_tiles_rect_); |
| 661 iter; ++iter) { | 690 iter; |
| 691 ++iter) { |
| 662 TileMapKey key(iter.index()); | 692 TileMapKey key(iter.index()); |
| 663 if (ShouldCreateTileAt(key.first, key.second)) | 693 CreateTile(key.first, key.second, twin_tiling, recycled_twin); |
| 664 CreateTile(key.first, key.second); | |
| 665 } | 694 } |
| 666 | 695 |
| 667 live_tiles_rect_ = new_live_tiles_rect; | 696 live_tiles_rect_ = new_live_tiles_rect; |
| 668 VerifyLiveTilesRect(false); | 697 VerifyLiveTilesRect(false); |
| 698 if (recycled_twin) { |
| 699 recycled_twin->live_tiles_rect_ = live_tiles_rect_; |
| 700 recycled_twin->VerifyLiveTilesRect(true); |
| 701 } |
| 669 } | 702 } |
| 670 | 703 |
| 671 void PictureLayerTiling::VerifyLiveTilesRect(bool is_on_recycle_tree) const { | 704 void PictureLayerTiling::VerifyLiveTilesRect(bool is_on_recycle_tree) const { |
| 672 #if DCHECK_IS_ON() | 705 #if DCHECK_IS_ON() |
| 673 for (auto it = tiles_.begin(); it != tiles_.end(); ++it) { | 706 for (auto it = tiles_.begin(); it != tiles_.end(); ++it) { |
| 674 if (!it->second.get()) | 707 if (!it->second.get()) |
| 675 continue; | 708 continue; |
| 676 DCHECK(it->first.first < tiling_data_.num_tiles_x()) | 709 DCHECK(it->first.first < tiling_data_.num_tiles_x()) |
| 677 << this << " " << it->first.first << "," << it->first.second | 710 << this << " " << it->first.first << "," << it->first.second |
| 678 << " num_tiles_x " << tiling_data_.num_tiles_x() << " live_tiles_rect " | 711 << " num_tiles_x " << tiling_data_.num_tiles_x() << " live_tiles_rect " |
| 679 << live_tiles_rect_.ToString(); | 712 << live_tiles_rect_.ToString(); |
| 680 DCHECK(it->first.second < tiling_data_.num_tiles_y()) | 713 DCHECK(it->first.second < tiling_data_.num_tiles_y()) |
| 681 << this << " " << it->first.first << "," << it->first.second | 714 << this << " " << it->first.first << "," << it->first.second |
| 682 << " num_tiles_y " << tiling_data_.num_tiles_y() << " live_tiles_rect " | 715 << " num_tiles_y " << tiling_data_.num_tiles_y() << " live_tiles_rect " |
| 683 << live_tiles_rect_.ToString(); | 716 << live_tiles_rect_.ToString(); |
| 684 DCHECK(tiling_data_.TileBounds(it->first.first, it->first.second) | 717 DCHECK(tiling_data_.TileBounds(it->first.first, it->first.second) |
| 685 .Intersects(live_tiles_rect_)) | 718 .Intersects(live_tiles_rect_)) |
| 686 << this << " " << it->first.first << "," << it->first.second | 719 << this << " " << it->first.first << "," << it->first.second |
| 687 << " tile bounds " | 720 << " tile bounds " |
| 688 << tiling_data_.TileBounds(it->first.first, it->first.second).ToString() | 721 << tiling_data_.TileBounds(it->first.first, it->first.second).ToString() |
| 689 << " live_tiles_rect " << live_tiles_rect_.ToString(); | 722 << " live_tiles_rect " << live_tiles_rect_.ToString(); |
| 723 DCHECK_IMPLIES(is_on_recycle_tree, it->second->is_shared()); |
| 690 } | 724 } |
| 691 #endif | 725 #endif |
| 692 } | 726 } |
| 693 | 727 |
| 694 bool PictureLayerTiling::IsTileOccluded(const Tile* tile) const { | 728 bool PictureLayerTiling::IsTileOccluded(const Tile* tile) const { |
| 695 // If this tile is not occluded on this tree, then it is not occluded. | 729 DCHECK(tile); |
| 696 if (!IsTileOccludedOnCurrentTree(tile)) | 730 |
| 731 if (!current_occlusion_in_layer_space_.HasOcclusion()) |
| 697 return false; | 732 return false; |
| 698 | 733 |
| 699 // Otherwise, if this is the pending tree, we're done and the tile is | |
| 700 // occluded. | |
| 701 if (client_->GetTree() == PENDING_TREE) | |
| 702 return true; | |
| 703 | |
| 704 // On the active tree however, we need to check if this tile will be | |
| 705 // unoccluded upon activation, in which case it has to be considered | |
| 706 // unoccluded. | |
| 707 const PictureLayerTiling* pending_twin = | |
| 708 client_->GetPendingOrActiveTwinTiling(this); | |
| 709 if (pending_twin) { | |
| 710 // If there's a pending tile in the same position. Or if the pending twin | |
| 711 // would have to be creating all tiles, then we don't need to worry about | |
| 712 // occlusion on the twin. | |
| 713 if (!TilingMatchesTileIndices(pending_twin) || | |
| 714 pending_twin->TileAt(tile->tiling_i_index(), tile->tiling_j_index())) { | |
| 715 return true; | |
| 716 } | |
| 717 return pending_twin->IsTileOccludedOnCurrentTree(tile); | |
| 718 } | |
| 719 return true; | |
| 720 } | |
| 721 | |
| 722 bool PictureLayerTiling::IsTileOccludedOnCurrentTree(const Tile* tile) const { | |
| 723 if (!current_occlusion_in_layer_space_.HasOcclusion()) | |
| 724 return false; | |
| 725 gfx::Rect tile_query_rect = | 734 gfx::Rect tile_query_rect = |
| 726 gfx::IntersectRects(tile->content_rect(), current_visible_rect_); | 735 gfx::IntersectRects(tile->content_rect(), current_visible_rect_); |
| 736 |
| 727 // Explicitly check if the tile is outside the viewport. If so, we need to | 737 // Explicitly check if the tile is outside the viewport. If so, we need to |
| 728 // return false, since occlusion for this tile is unknown. | 738 // return false, since occlusion for this tile is unknown. |
| 739 // TODO(vmpstr): Since the current visible rect is really a viewport in |
| 740 // layer space, we should probably clip tile query rect to tiling bounds |
| 741 // or live tiles rect. |
| 729 if (tile_query_rect.IsEmpty()) | 742 if (tile_query_rect.IsEmpty()) |
| 730 return false; | 743 return false; |
| 731 | 744 |
| 732 if (contents_scale_ != 1.f) { | 745 if (contents_scale_ != 1.f) { |
| 733 tile_query_rect = | 746 tile_query_rect = |
| 734 gfx::ScaleToEnclosingRect(tile_query_rect, 1.f / contents_scale_); | 747 gfx::ScaleToEnclosingRect(tile_query_rect, 1.0f / contents_scale_); |
| 735 } | 748 } |
| 749 |
| 736 return current_occlusion_in_layer_space_.IsOccluded(tile_query_rect); | 750 return current_occlusion_in_layer_space_.IsOccluded(tile_query_rect); |
| 737 } | 751 } |
| 738 | 752 |
| 739 bool PictureLayerTiling::IsTileRequiredForActivation(const Tile* tile) const { | 753 bool PictureLayerTiling::IsTileRequiredForActivationIfVisible( |
| 740 if (client_->GetTree() == PENDING_TREE) { | 754 const Tile* tile) const { |
| 741 if (!can_require_tiles_for_activation_) | 755 DCHECK_EQ(PENDING_TREE, client_->GetTree()); |
| 742 return false; | |
| 743 | 756 |
| 744 if (resolution_ != HIGH_RESOLUTION) | 757 // This function assumes that the tile is visible (i.e. in the viewport). The |
| 745 return false; | 758 // caller needs to make sure that this condition is met to ensure we don't |
| 759 // block activation on tiles outside of the viewport. |
| 746 | 760 |
| 747 if (IsTileOccluded(tile)) | 761 // If we are not allowed to mark tiles as required for activation, then don't |
| 748 return false; | 762 // do it. |
| 749 | 763 if (!can_require_tiles_for_activation_) |
| 750 bool tile_is_visible = | |
| 751 tile->content_rect().Intersects(current_visible_rect_); | |
| 752 if (!tile_is_visible) | |
| 753 return false; | |
| 754 | |
| 755 if (client_->RequiresHighResToDraw()) | |
| 756 return true; | |
| 757 | |
| 758 const PictureLayerTiling* active_twin = | |
| 759 client_->GetPendingOrActiveTwinTiling(this); | |
| 760 if (!active_twin || !TilingMatchesTileIndices(active_twin)) | |
| 761 return true; | |
| 762 | |
| 763 if (active_twin->raster_source()->GetSize() != raster_source()->GetSize()) | |
| 764 return true; | |
| 765 | |
| 766 if (active_twin->current_visible_rect_ != current_visible_rect_) | |
| 767 return true; | |
| 768 | |
| 769 Tile* twin_tile = | |
| 770 active_twin->TileAt(tile->tiling_i_index(), tile->tiling_j_index()); | |
| 771 if (!twin_tile) | |
| 772 return false; | |
| 773 return true; | |
| 774 } | |
| 775 | |
| 776 DCHECK(client_->GetTree() == ACTIVE_TREE); | |
| 777 const PictureLayerTiling* pending_twin = | |
| 778 client_->GetPendingOrActiveTwinTiling(this); | |
| 779 // If we don't have a pending tree, or the pending tree will overwrite the | |
| 780 // given tile, then it is not required for activation. | |
| 781 if (!pending_twin || !TilingMatchesTileIndices(pending_twin) || | |
| 782 pending_twin->TileAt(tile->tiling_i_index(), tile->tiling_j_index())) { | |
| 783 return false; | |
| 784 } | |
| 785 // Otherwise, ask the pending twin if this tile is required for activation. | |
| 786 return pending_twin->IsTileRequiredForActivation(tile); | |
| 787 } | |
| 788 | |
| 789 bool PictureLayerTiling::IsTileRequiredForDraw(const Tile* tile) const { | |
| 790 if (client_->GetTree() == PENDING_TREE) | |
| 791 return false; | 764 return false; |
| 792 | 765 |
| 793 if (resolution_ != HIGH_RESOLUTION) | 766 if (resolution_ != HIGH_RESOLUTION) |
| 794 return false; | 767 return false; |
| 795 | 768 |
| 796 bool tile_is_visible = current_visible_rect_.Intersects(tile->content_rect()); | 769 if (IsTileOccluded(tile)) |
| 797 if (!tile_is_visible) | |
| 798 return false; | 770 return false; |
| 799 | 771 |
| 800 if (IsTileOccludedOnCurrentTree(tile)) | 772 if (client_->RequiresHighResToDraw()) |
| 773 return true; |
| 774 |
| 775 const PictureLayerTiling* twin_tiling = |
| 776 client_->GetPendingOrActiveTwinTiling(this); |
| 777 if (!twin_tiling) |
| 778 return true; |
| 779 |
| 780 if (twin_tiling->raster_source()->GetSize() != raster_source()->GetSize()) |
| 781 return true; |
| 782 |
| 783 if (twin_tiling->current_visible_rect_ != current_visible_rect_) |
| 784 return true; |
| 785 |
| 786 Tile* twin_tile = |
| 787 twin_tiling->TileAt(tile->tiling_i_index(), tile->tiling_j_index()); |
| 788 // If twin tile is missing, it might not have a recording, so we don't need |
| 789 // this tile to be required for activation. |
| 790 if (!twin_tile) |
| 801 return false; | 791 return false; |
| 792 |
| 793 return true; |
| 794 } |
| 795 |
| 796 bool PictureLayerTiling::IsTileRequiredForDrawIfVisible( |
| 797 const Tile* tile) const { |
| 798 DCHECK_EQ(ACTIVE_TREE, client_->GetTree()); |
| 799 |
| 800 // This function assumes that the tile is visible (i.e. in the viewport). |
| 801 |
| 802 if (resolution_ != HIGH_RESOLUTION) |
| 803 return false; |
| 804 |
| 805 if (IsTileOccluded(tile)) |
| 806 return false; |
| 807 |
| 802 return true; | 808 return true; |
| 803 } | 809 } |
| 804 | 810 |
| 805 void PictureLayerTiling::UpdateTileAndTwinPriority(Tile* tile) const { | 811 void PictureLayerTiling::UpdateTileAndTwinPriority(Tile* tile) const { |
| 806 tile->set_priority(ComputePriorityForTile(tile)); | 812 WhichTree tree = client_->GetTree(); |
| 807 tile->set_is_occluded(IsTileOccluded(tile)); | 813 WhichTree twin_tree = tree == ACTIVE_TREE ? PENDING_TREE : ACTIVE_TREE; |
| 808 tile->set_required_for_activation(IsTileRequiredForActivation(tile)); | 814 |
| 809 tile->set_required_for_draw(IsTileRequiredForDraw(tile)); | 815 tile->SetPriority(tree, ComputePriorityForTile(tile)); |
| 816 UpdateRequiredStateForTile(tile, tree); |
| 817 |
| 818 const PictureLayerTiling* twin_tiling = |
| 819 client_->GetPendingOrActiveTwinTiling(this); |
| 820 if (!tile->is_shared() || !twin_tiling) { |
| 821 tile->SetPriority(twin_tree, TilePriority()); |
| 822 tile->set_is_occluded(twin_tree, false); |
| 823 if (twin_tree == PENDING_TREE) |
| 824 tile->set_required_for_activation(false); |
| 825 else |
| 826 tile->set_required_for_draw(false); |
| 827 return; |
| 828 } |
| 829 |
| 830 tile->SetPriority(twin_tree, twin_tiling->ComputePriorityForTile(tile)); |
| 831 twin_tiling->UpdateRequiredStateForTile(tile, twin_tree); |
| 832 } |
| 833 |
| 834 void PictureLayerTiling::UpdateRequiredStateForTile(Tile* tile, |
| 835 WhichTree tree) const { |
| 836 if (tile->priority(tree).priority_bin == TilePriority::NOW) { |
| 837 if (tree == PENDING_TREE) { |
| 838 tile->set_required_for_activation( |
| 839 IsTileRequiredForActivationIfVisible(tile)); |
| 840 } else { |
| 841 tile->set_required_for_draw(IsTileRequiredForDrawIfVisible(tile)); |
| 842 } |
| 843 tile->set_is_occluded(tree, IsTileOccluded(tile)); |
| 844 return; |
| 845 } |
| 846 |
| 847 // Non-NOW bin tiles are not required or occluded. |
| 848 if (tree == PENDING_TREE) |
| 849 tile->set_required_for_activation(false); |
| 850 else |
| 851 tile->set_required_for_draw(false); |
| 852 tile->set_is_occluded(tree, false); |
| 810 } | 853 } |
| 811 | 854 |
| 812 void PictureLayerTiling::VerifyAllTilesHaveCurrentRasterSource() const { | 855 void PictureLayerTiling::VerifyAllTilesHaveCurrentRasterSource() const { |
| 813 #if DCHECK_IS_ON() | 856 #if DCHECK_IS_ON() |
| 814 for (const auto& tile_pair : tiles_) | 857 for (const auto& tile_pair : tiles_) |
| 815 DCHECK_EQ(raster_source_.get(), tile_pair.second->raster_source()); | 858 DCHECK_EQ(raster_source_.get(), tile_pair.second->raster_source()); |
| 816 #endif | 859 #endif |
| 817 } | 860 } |
| 818 | 861 |
| 819 TilePriority PictureLayerTiling::ComputePriorityForTile( | 862 TilePriority PictureLayerTiling::ComputePriorityForTile( |
| 820 const Tile* tile) const { | 863 const Tile* tile) const { |
| 821 // TODO(vmpstr): See if this can be moved to iterators. | 864 // TODO(vmpstr): See if this can be moved to iterators. |
| 822 TilePriority::PriorityBin max_tile_priority_bin = | 865 TilePriority::PriorityBin max_tile_priority_bin = |
| 823 client_->GetMaxTilePriorityBin(); | 866 client_->GetMaxTilePriorityBin(); |
| 824 | 867 |
| 825 DCHECK_EQ(TileAt(tile->tiling_i_index(), tile->tiling_j_index()), tile); | 868 DCHECK_EQ(TileAt(tile->tiling_i_index(), tile->tiling_j_index()), tile); |
| 826 gfx::Rect tile_bounds = | 869 gfx::Rect tile_bounds = |
| 827 tiling_data_.TileBounds(tile->tiling_i_index(), tile->tiling_j_index()); | 870 tiling_data_.TileBounds(tile->tiling_i_index(), tile->tiling_j_index()); |
| 828 | 871 |
| 829 if (max_tile_priority_bin <= TilePriority::NOW && | 872 if (max_tile_priority_bin <= TilePriority::NOW && |
| 830 current_visible_rect_.Intersects(tile_bounds)) { | 873 current_visible_rect_.Intersects(tile_bounds)) { |
| 831 return TilePriority(resolution_, TilePriority::NOW, 0); | 874 return TilePriority(resolution_, TilePriority::NOW, 0); |
| 832 } | 875 } |
| 833 | 876 |
| 834 if (max_tile_priority_bin <= TilePriority::SOON && | |
| 835 pending_visible_rect().Intersects(tile_bounds)) { | |
| 836 return TilePriority(resolution_, TilePriority::SOON, 0); | |
| 837 } | |
| 838 | |
| 839 DCHECK_GT(current_content_to_screen_scale_, 0.f); | 877 DCHECK_GT(current_content_to_screen_scale_, 0.f); |
| 840 float distance_to_visible = | 878 float distance_to_visible = |
| 841 current_visible_rect_.ManhattanInternalDistance(tile_bounds) * | 879 current_visible_rect_.ManhattanInternalDistance(tile_bounds) * |
| 842 current_content_to_screen_scale_; | 880 current_content_to_screen_scale_; |
| 843 | 881 |
| 844 if (max_tile_priority_bin <= TilePriority::SOON && | 882 if (max_tile_priority_bin <= TilePriority::SOON && |
| 845 (current_soon_border_rect_.Intersects(tile_bounds) || | 883 (current_soon_border_rect_.Intersects(tile_bounds) || |
| 846 current_skewport_rect_.Intersects(tile_bounds))) { | 884 current_skewport_rect_.Intersects(tile_bounds))) { |
| 847 return TilePriority(resolution_, TilePriority::SOON, distance_to_visible); | 885 return TilePriority(resolution_, TilePriority::SOON, distance_to_visible); |
| 848 } | 886 } |
| 849 | 887 |
| 850 return TilePriority(resolution_, TilePriority::EVENTUALLY, | 888 return TilePriority(resolution_, TilePriority::EVENTUALLY, |
| 851 distance_to_visible); | 889 distance_to_visible); |
| 852 } | 890 } |
| 853 | 891 |
| 854 void PictureLayerTiling::GetAllTilesAndPrioritiesForTracing( | 892 void PictureLayerTiling::GetAllTilesAndPrioritiesForTracing( |
| 855 std::map<const Tile*, TilePriority>* tile_map) const { | 893 std::map<const Tile*, TilePriority>* tile_map) const { |
| 894 const PictureLayerTiling* twin_tiling = |
| 895 client_->GetPendingOrActiveTwinTiling(this); |
| 856 for (const auto& tile_pair : tiles_) { | 896 for (const auto& tile_pair : tiles_) { |
| 857 const Tile* tile = tile_pair.second.get(); | 897 const Tile* tile = tile_pair.second.get(); |
| 858 const TilePriority& priority = ComputePriorityForTile(tile); | 898 const TilePriority& priority = ComputePriorityForTile(tile); |
| 899 // If the tile is shared, it means the twin also has the same tile. |
| 900 // Otherwise, use the default priority. |
| 901 const TilePriority& twin_priority = |
| 902 (twin_tiling && tile->is_shared()) |
| 903 ? twin_tiling->ComputePriorityForTile(tile) |
| 904 : TilePriority(); |
| 905 |
| 859 // Store combined priority. | 906 // Store combined priority. |
| 860 (*tile_map)[tile] = priority; | 907 (*tile_map)[tile] = TilePriority(priority, twin_priority); |
| 861 } | 908 } |
| 862 } | 909 } |
| 863 | 910 |
| 864 void PictureLayerTiling::AsValueInto( | 911 void PictureLayerTiling::AsValueInto( |
| 865 base::trace_event::TracedValue* state) const { | 912 base::trace_event::TracedValue* state) const { |
| 866 state->SetInteger("num_tiles", tiles_.size()); | 913 state->SetInteger("num_tiles", tiles_.size()); |
| 867 state->SetDouble("content_scale", contents_scale_); | 914 state->SetDouble("content_scale", contents_scale_); |
| 868 MathUtil::AddToTracedValue("visible_rect", current_visible_rect_, state); | 915 MathUtil::AddToTracedValue("visible_rect", current_visible_rect_, state); |
| 869 MathUtil::AddToTracedValue("skewport_rect", current_skewport_rect_, state); | 916 MathUtil::AddToTracedValue("skewport_rect", current_skewport_rect_, state); |
| 870 MathUtil::AddToTracedValue("soon_rect", current_soon_border_rect_, state); | 917 MathUtil::AddToTracedValue("soon_rect", current_soon_border_rect_, state); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1027 break; | 1074 break; |
| 1028 } | 1075 } |
| 1029 | 1076 |
| 1030 gfx::Rect result(origin_x, origin_y, width, height); | 1077 gfx::Rect result(origin_x, origin_y, width, height); |
| 1031 if (cache) | 1078 if (cache) |
| 1032 cache->previous_result = result; | 1079 cache->previous_result = result; |
| 1033 return result; | 1080 return result; |
| 1034 } | 1081 } |
| 1035 | 1082 |
| 1036 } // namespace cc | 1083 } // namespace cc |
| OLD | NEW |