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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
202 int after_right = -1; | 202 int after_right = -1; |
203 int after_bottom = -1; | 203 int after_bottom = -1; |
204 if (!live_tiles_rect_.IsEmpty()) { | 204 if (!live_tiles_rect_.IsEmpty()) { |
205 after_right = | 205 after_right = |
206 tiling_data_.TileXIndexFromSrcCoord(live_tiles_rect_.right() - 1); | 206 tiling_data_.TileXIndexFromSrcCoord(live_tiles_rect_.right() - 1); |
207 after_bottom = | 207 after_bottom = |
208 tiling_data_.TileYIndexFromSrcCoord(live_tiles_rect_.bottom() - 1); | 208 tiling_data_.TileYIndexFromSrcCoord(live_tiles_rect_.bottom() - 1); |
209 } | 209 } |
210 | 210 |
211 // There is no recycled twin since this is run on the pending tiling. | 211 // There is no recycled twin since this is run on the pending tiling. |
212 PictureLayerTiling* recycled_twin = NULL; | 212 PictureLayerTiling* recycled_twin = nullptr; |
213 DCHECK_EQ(recycled_twin, client_->GetRecycledTwinTiling(this)); | 213 DCHECK_EQ(recycled_twin, client_->GetRecycledTwinTiling(this)); |
214 DCHECK_EQ(PENDING_TREE, client_->GetTree()); | 214 DCHECK_EQ(PENDING_TREE, client_->GetTree()); |
215 | 215 |
216 // Drop tiles outside the new layer bounds if the layer shrank. | 216 // Drop tiles outside the new layer bounds if the layer shrank. |
217 for (int i = after_right + 1; i <= before_right; ++i) { | 217 for (int i = after_right + 1; i <= before_right; ++i) { |
218 for (int j = before_top; j <= before_bottom; ++j) | 218 for (int j = before_top; j <= before_bottom; ++j) |
219 RemoveTileAt(i, j, recycled_twin); | 219 RemoveTileAt(i, j, recycled_twin); |
220 } | 220 } |
221 for (int i = before_left; i <= after_right; ++i) { | 221 for (int i = before_left; i <= after_right; ++i) { |
222 for (int j = after_bottom + 1; j <= before_bottom; ++j) | 222 for (int j = after_bottom + 1; j <= before_bottom; ++j) |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
283 if (content_rect.IsEmpty()) | 283 if (content_rect.IsEmpty()) |
284 continue; | 284 continue; |
285 // Since the content_rect includes border pixels already, don't include | 285 // Since the content_rect includes border pixels already, don't include |
286 // borders when iterating to avoid double counting them. | 286 // borders when iterating to avoid double counting them. |
287 bool include_borders = false; | 287 bool include_borders = false; |
288 for (TilingData::Iterator iter( | 288 for (TilingData::Iterator iter( |
289 &tiling_data_, content_rect, include_borders); | 289 &tiling_data_, content_rect, include_borders); |
290 iter; | 290 iter; |
291 ++iter) { | 291 ++iter) { |
292 // There is no recycled twin since this is run on the pending tiling. | 292 // There is no recycled twin since this is run on the pending tiling. |
293 PictureLayerTiling* recycled_twin = NULL; | 293 PictureLayerTiling* recycled_twin = nullptr; |
294 DCHECK_EQ(recycled_twin, client_->GetRecycledTwinTiling(this)); | 294 DCHECK_EQ(recycled_twin, client_->GetRecycledTwinTiling(this)); |
295 DCHECK_EQ(PENDING_TREE, client_->GetTree()); | 295 DCHECK_EQ(PENDING_TREE, client_->GetTree()); |
296 if (RemoveTileAt(iter.index_x(), iter.index_y(), recycled_twin)) | 296 if (RemoveTileAt(iter.index_x(), iter.index_y(), recycled_twin)) |
297 new_tile_keys.push_back(iter.index()); | 297 new_tile_keys.push_back(iter.index()); |
298 } | 298 } |
299 } | 299 } |
300 | 300 |
301 if (recreate_invalidated_tiles && !new_tile_keys.empty()) { | 301 if (recreate_invalidated_tiles && !new_tile_keys.empty()) { |
302 for (size_t i = 0; i < new_tile_keys.size(); ++i) { | 302 for (size_t i = 0; i < new_tile_keys.size(); ++i) { |
303 // Don't try to share a tile with the twin layer, it's been invalidated so | 303 // Don't try to share a tile with the twin layer, it's been invalidated so |
304 // we have to make our own tile here. | 304 // we have to make our own tile here. |
305 const PictureLayerTiling* twin_tiling = NULL; | 305 const PictureLayerTiling* twin_tiling = nullptr; |
306 CreateTile(new_tile_keys[i].first, new_tile_keys[i].second, twin_tiling); | 306 CreateTile(new_tile_keys[i].first, new_tile_keys[i].second, twin_tiling); |
307 } | 307 } |
308 } | 308 } |
309 } | 309 } |
310 | 310 |
311 PictureLayerTiling::CoverageIterator::CoverageIterator() | 311 PictureLayerTiling::CoverageIterator::CoverageIterator() |
312 : tiling_(NULL), | 312 : tiling_(nullptr), |
313 current_tile_(NULL), | 313 current_tile_(nullptr), |
314 tile_i_(0), | 314 tile_i_(0), |
315 tile_j_(0), | 315 tile_j_(0), |
316 left_(0), | 316 left_(0), |
317 top_(0), | 317 top_(0), |
318 right_(-1), | 318 right_(-1), |
319 bottom_(-1) { | 319 bottom_(-1) { |
320 } | 320 } |
321 | 321 |
322 PictureLayerTiling::CoverageIterator::CoverageIterator( | 322 PictureLayerTiling::CoverageIterator::CoverageIterator( |
323 const PictureLayerTiling* tiling, | 323 const PictureLayerTiling* tiling, |
324 float dest_scale, | 324 float dest_scale, |
325 const gfx::Rect& dest_rect) | 325 const gfx::Rect& dest_rect) |
326 : tiling_(tiling), | 326 : tiling_(tiling), |
327 dest_rect_(dest_rect), | 327 dest_rect_(dest_rect), |
328 dest_to_content_scale_(0), | 328 dest_to_content_scale_(0), |
329 current_tile_(NULL), | 329 current_tile_(nullptr), |
330 tile_i_(0), | 330 tile_i_(0), |
331 tile_j_(0), | 331 tile_j_(0), |
332 left_(0), | 332 left_(0), |
333 top_(0), | 333 top_(0), |
334 right_(-1), | 334 right_(-1), |
335 bottom_(-1) { | 335 bottom_(-1) { |
336 DCHECK(tiling_); | 336 DCHECK(tiling_); |
337 if (dest_rect_.IsEmpty()) | 337 if (dest_rect_.IsEmpty()) |
338 return; | 338 return; |
339 | 339 |
(...skipping 30 matching lines...) Expand all Loading... | |
370 return *this; | 370 return *this; |
371 | 371 |
372 bool first_time = tile_i_ < left_; | 372 bool first_time = tile_i_ < left_; |
373 bool new_row = false; | 373 bool new_row = false; |
374 tile_i_++; | 374 tile_i_++; |
375 if (tile_i_ > right_) { | 375 if (tile_i_ > right_) { |
376 tile_i_ = left_; | 376 tile_i_ = left_; |
377 tile_j_++; | 377 tile_j_++; |
378 new_row = true; | 378 new_row = true; |
379 if (tile_j_ > bottom_) { | 379 if (tile_j_ > bottom_) { |
380 current_tile_ = NULL; | 380 current_tile_ = nullptr; |
381 return *this; | 381 return *this; |
382 } | 382 } |
383 } | 383 } |
384 | 384 |
385 current_tile_ = tiling_->TileAt(tile_i_, tile_j_); | 385 current_tile_ = tiling_->TileAt(tile_i_, tile_j_); |
386 | 386 |
387 // Calculate the current geometry rect. Due to floating point rounding | 387 // Calculate the current geometry rect. Due to floating point rounding |
388 // and ToEnclosingRect, tiles might overlap in destination space on the | 388 // and ToEnclosingRect, tiles might overlap in destination space on the |
389 // edges. | 389 // edges. |
390 gfx::Rect last_geometry_rect = current_geometry_rect_; | 390 gfx::Rect last_geometry_rect = current_geometry_rect_; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
460 | 460 |
461 bool PictureLayerTiling::RemoveTileAt(int i, | 461 bool PictureLayerTiling::RemoveTileAt(int i, |
462 int j, | 462 int j, |
463 PictureLayerTiling* recycled_twin) { | 463 PictureLayerTiling* recycled_twin) { |
464 TileMap::iterator found = tiles_.find(TileMapKey(i, j)); | 464 TileMap::iterator found = tiles_.find(TileMapKey(i, j)); |
465 if (found == tiles_.end()) | 465 if (found == tiles_.end()) |
466 return false; | 466 return false; |
467 found->second->set_shared(false); | 467 found->second->set_shared(false); |
468 tiles_.erase(found); | 468 tiles_.erase(found); |
469 if (recycled_twin) { | 469 if (recycled_twin) { |
470 // Recycled twin does not also have a recycled twin, so pass NULL. | 470 // Recycled twin does not also have a recycled twin, so pass nullptr. |
danakj
2014/10/10 17:28:45
just use null
| |
471 recycled_twin->RemoveTileAt(i, j, NULL); | 471 recycled_twin->RemoveTileAt(i, j, nullptr); |
472 } | 472 } |
473 return true; | 473 return true; |
474 } | 474 } |
475 | 475 |
476 void PictureLayerTiling::Reset() { | 476 void PictureLayerTiling::Reset() { |
477 live_tiles_rect_ = gfx::Rect(); | 477 live_tiles_rect_ = gfx::Rect(); |
478 PictureLayerTiling* recycled_twin = client_->GetRecycledTwinTiling(this); | 478 PictureLayerTiling* recycled_twin = client_->GetRecycledTwinTiling(this); |
479 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { | 479 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { |
480 it->second->set_shared(false); | 480 it->second->set_shared(false); |
481 if (recycled_twin) | 481 if (recycled_twin) |
482 recycled_twin->RemoveTileAt(it->first.first, it->first.second, NULL); | 482 recycled_twin->RemoveTileAt(it->first.first, it->first.second, nullptr); |
483 } | 483 } |
484 tiles_.clear(); | 484 tiles_.clear(); |
485 } | 485 } |
486 | 486 |
487 gfx::Rect PictureLayerTiling::ComputeSkewport( | 487 gfx::Rect PictureLayerTiling::ComputeSkewport( |
488 double current_frame_time_in_seconds, | 488 double current_frame_time_in_seconds, |
489 const gfx::Rect& visible_rect_in_content_space) const { | 489 const gfx::Rect& visible_rect_in_content_space) const { |
490 gfx::Rect skewport = visible_rect_in_content_space; | 490 gfx::Rect skewport = visible_rect_in_content_space; |
491 if (last_impl_frame_time_in_seconds_ == 0.0) | 491 if (last_impl_frame_time_in_seconds_ == 0.0) |
492 return skewport; | 492 return skewport; |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1044 case NOW: | 1044 case NOW: |
1045 return &eviction_tiles_now_; | 1045 return &eviction_tiles_now_; |
1046 case NOW_AND_REQUIRED_FOR_ACTIVATION: | 1046 case NOW_AND_REQUIRED_FOR_ACTIVATION: |
1047 return &eviction_tiles_now_and_required_for_activation_; | 1047 return &eviction_tiles_now_and_required_for_activation_; |
1048 } | 1048 } |
1049 NOTREACHED(); | 1049 NOTREACHED(); |
1050 return &eviction_tiles_eventually_; | 1050 return &eviction_tiles_eventually_; |
1051 } | 1051 } |
1052 | 1052 |
1053 PictureLayerTiling::TilingRasterTileIterator::TilingRasterTileIterator() | 1053 PictureLayerTiling::TilingRasterTileIterator::TilingRasterTileIterator() |
1054 : tiling_(NULL), current_tile_(NULL) {} | 1054 : tiling_(nullptr), current_tile_(nullptr) { |
1055 } | |
1055 | 1056 |
1056 PictureLayerTiling::TilingRasterTileIterator::TilingRasterTileIterator( | 1057 PictureLayerTiling::TilingRasterTileIterator::TilingRasterTileIterator( |
1057 PictureLayerTiling* tiling) | 1058 PictureLayerTiling* tiling) |
1058 : tiling_(tiling), phase_(VISIBLE_RECT), current_tile_(NULL) { | 1059 : tiling_(tiling), phase_(VISIBLE_RECT), current_tile_(nullptr) { |
1059 if (!tiling_->has_visible_rect_tiles_) { | 1060 if (!tiling_->has_visible_rect_tiles_) { |
1060 AdvancePhase(); | 1061 AdvancePhase(); |
1061 return; | 1062 return; |
1062 } | 1063 } |
1063 | 1064 |
1064 visible_iterator_ = TilingData::Iterator(&tiling_->tiling_data_, | 1065 visible_iterator_ = TilingData::Iterator(&tiling_->tiling_data_, |
1065 tiling_->current_visible_rect_, | 1066 tiling_->current_visible_rect_, |
1066 false /* include_borders */); | 1067 false /* include_borders */); |
1067 if (!visible_iterator_) { | 1068 if (!visible_iterator_) { |
1068 AdvancePhase(); | 1069 AdvancePhase(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1104 continue; | 1105 continue; |
1105 | 1106 |
1106 spiral_iterator_ = TilingData::SpiralDifferenceIterator( | 1107 spiral_iterator_ = TilingData::SpiralDifferenceIterator( |
1107 &tiling_->tiling_data_, | 1108 &tiling_->tiling_data_, |
1108 tiling_->current_soon_border_rect_, | 1109 tiling_->current_soon_border_rect_, |
1109 tiling_->current_skewport_rect_, | 1110 tiling_->current_skewport_rect_, |
1110 tiling_->current_visible_rect_); | 1111 tiling_->current_visible_rect_); |
1111 break; | 1112 break; |
1112 case EVENTUALLY_RECT: | 1113 case EVENTUALLY_RECT: |
1113 if (!tiling_->has_eventually_rect_tiles_) { | 1114 if (!tiling_->has_eventually_rect_tiles_) { |
1114 current_tile_ = NULL; | 1115 current_tile_ = nullptr; |
1115 return; | 1116 return; |
1116 } | 1117 } |
1117 | 1118 |
1118 spiral_iterator_ = TilingData::SpiralDifferenceIterator( | 1119 spiral_iterator_ = TilingData::SpiralDifferenceIterator( |
1119 &tiling_->tiling_data_, | 1120 &tiling_->tiling_data_, |
1120 tiling_->current_eventually_rect_, | 1121 tiling_->current_eventually_rect_, |
1121 tiling_->current_skewport_rect_, | 1122 tiling_->current_skewport_rect_, |
1122 tiling_->current_soon_border_rect_); | 1123 tiling_->current_soon_border_rect_); |
1123 break; | 1124 break; |
1124 } | 1125 } |
1125 | 1126 |
1126 while (spiral_iterator_) { | 1127 while (spiral_iterator_) { |
1127 current_tile_ = tiling_->TileAt(spiral_iterator_.index_x(), | 1128 current_tile_ = tiling_->TileAt(spiral_iterator_.index_x(), |
1128 spiral_iterator_.index_y()); | 1129 spiral_iterator_.index_y()); |
1129 if (current_tile_ && TileNeedsRaster(current_tile_)) | 1130 if (current_tile_ && TileNeedsRaster(current_tile_)) |
1130 break; | 1131 break; |
1131 ++spiral_iterator_; | 1132 ++spiral_iterator_; |
1132 } | 1133 } |
1133 | 1134 |
1134 if (!spiral_iterator_ && phase_ == EVENTUALLY_RECT) { | 1135 if (!spiral_iterator_ && phase_ == EVENTUALLY_RECT) { |
1135 current_tile_ = NULL; | 1136 current_tile_ = nullptr; |
1136 break; | 1137 break; |
1137 } | 1138 } |
1138 } while (!spiral_iterator_); | 1139 } while (!spiral_iterator_); |
1139 | 1140 |
1140 if (current_tile_) | 1141 if (current_tile_) |
1141 tiling_->UpdateTileAndTwinPriority(current_tile_); | 1142 tiling_->UpdateTileAndTwinPriority(current_tile_); |
1142 } | 1143 } |
1143 | 1144 |
1144 PictureLayerTiling::TilingRasterTileIterator& | 1145 PictureLayerTiling::TilingRasterTileIterator& |
1145 PictureLayerTiling::TilingRasterTileIterator:: | 1146 PictureLayerTiling::TilingRasterTileIterator:: |
1146 operator++() { | 1147 operator++() { |
1147 current_tile_ = NULL; | 1148 current_tile_ = nullptr; |
1148 while (!current_tile_ || !TileNeedsRaster(current_tile_)) { | 1149 while (!current_tile_ || !TileNeedsRaster(current_tile_)) { |
1149 std::pair<int, int> next_index; | 1150 std::pair<int, int> next_index; |
1150 switch (phase_) { | 1151 switch (phase_) { |
1151 case VISIBLE_RECT: | 1152 case VISIBLE_RECT: |
1152 ++visible_iterator_; | 1153 ++visible_iterator_; |
1153 if (!visible_iterator_) { | 1154 if (!visible_iterator_) { |
1154 AdvancePhase(); | 1155 AdvancePhase(); |
1155 return *this; | 1156 return *this; |
1156 } | 1157 } |
1157 next_index = visible_iterator_.index(); | 1158 next_index = visible_iterator_.index(); |
1158 break; | 1159 break; |
1159 case SKEWPORT_RECT: | 1160 case SKEWPORT_RECT: |
1160 case SOON_BORDER_RECT: | 1161 case SOON_BORDER_RECT: |
1161 ++spiral_iterator_; | 1162 ++spiral_iterator_; |
1162 if (!spiral_iterator_) { | 1163 if (!spiral_iterator_) { |
1163 AdvancePhase(); | 1164 AdvancePhase(); |
1164 return *this; | 1165 return *this; |
1165 } | 1166 } |
1166 next_index = spiral_iterator_.index(); | 1167 next_index = spiral_iterator_.index(); |
1167 break; | 1168 break; |
1168 case EVENTUALLY_RECT: | 1169 case EVENTUALLY_RECT: |
1169 ++spiral_iterator_; | 1170 ++spiral_iterator_; |
1170 if (!spiral_iterator_) { | 1171 if (!spiral_iterator_) { |
1171 current_tile_ = NULL; | 1172 current_tile_ = nullptr; |
1172 return *this; | 1173 return *this; |
1173 } | 1174 } |
1174 next_index = spiral_iterator_.index(); | 1175 next_index = spiral_iterator_.index(); |
1175 break; | 1176 break; |
1176 } | 1177 } |
1177 current_tile_ = tiling_->TileAt(next_index.first, next_index.second); | 1178 current_tile_ = tiling_->TileAt(next_index.first, next_index.second); |
1178 } | 1179 } |
1179 | 1180 |
1180 if (current_tile_) | 1181 if (current_tile_) |
1181 tiling_->UpdateTileAndTwinPriority(current_tile_); | 1182 tiling_->UpdateTileAndTwinPriority(current_tile_); |
1182 return *this; | 1183 return *this; |
1183 } | 1184 } |
1184 | 1185 |
1185 PictureLayerTiling::TilingEvictionTileIterator::TilingEvictionTileIterator() | 1186 PictureLayerTiling::TilingEvictionTileIterator::TilingEvictionTileIterator() |
1186 : eviction_tiles_(NULL), current_eviction_tiles_index_(0u) { | 1187 : eviction_tiles_(nullptr), current_eviction_tiles_index_(0u) { |
1187 } | 1188 } |
1188 | 1189 |
1189 PictureLayerTiling::TilingEvictionTileIterator::TilingEvictionTileIterator( | 1190 PictureLayerTiling::TilingEvictionTileIterator::TilingEvictionTileIterator( |
1190 PictureLayerTiling* tiling, | 1191 PictureLayerTiling* tiling, |
1191 TreePriority tree_priority, | 1192 TreePriority tree_priority, |
1192 EvictionCategory category) | 1193 EvictionCategory category) |
1193 : eviction_tiles_(tiling->GetEvictionTiles(tree_priority, category)), | 1194 : eviction_tiles_(tiling->GetEvictionTiles(tree_priority, category)), |
1194 // Note: initializing to "0 - 1" works as overflow is well defined for | 1195 // Note: initializing to "0 - 1" works as overflow is well defined for |
1195 // unsigned integers. | 1196 // unsigned integers. |
1196 current_eviction_tiles_index_(static_cast<size_t>(0) - 1) { | 1197 current_eviction_tiles_index_(static_cast<size_t>(0) - 1) { |
(...skipping 25 matching lines...) Expand all Loading... | |
1222 DCHECK(*this); | 1223 DCHECK(*this); |
1223 do { | 1224 do { |
1224 ++current_eviction_tiles_index_; | 1225 ++current_eviction_tiles_index_; |
1225 } while (current_eviction_tiles_index_ != eviction_tiles_->size() && | 1226 } while (current_eviction_tiles_index_ != eviction_tiles_->size() && |
1226 !(*eviction_tiles_)[current_eviction_tiles_index_]->HasResources()); | 1227 !(*eviction_tiles_)[current_eviction_tiles_index_]->HasResources()); |
1227 | 1228 |
1228 return *this; | 1229 return *this; |
1229 } | 1230 } |
1230 | 1231 |
1231 } // namespace cc | 1232 } // namespace cc |
OLD | NEW |