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/tile_manager.h" | 5 #include "cc/resources/tile_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 382 base::Bind(&TileManager::CheckIfReadyToActivate, | 382 base::Bind(&TileManager::CheckIfReadyToActivate, |
| 383 base::Unretained(this))) { | 383 base::Unretained(this))) { |
| 384 rasterizer_->SetClient(this); | 384 rasterizer_->SetClient(this); |
| 385 } | 385 } |
| 386 | 386 |
| 387 TileManager::~TileManager() { | 387 TileManager::~TileManager() { |
| 388 // Reset global state and manage. This should cause | 388 // Reset global state and manage. This should cause |
| 389 // our memory usage to drop to zero. | 389 // our memory usage to drop to zero. |
| 390 global_state_ = GlobalStateThatImpactsTilePriority(); | 390 global_state_ = GlobalStateThatImpactsTilePriority(); |
| 391 | 391 |
| 392 CleanUpReleasedTiles(); | |
| 393 DCHECK_EQ(0u, tiles_.size()); | |
| 394 | |
| 395 RasterTaskQueue empty; | 392 RasterTaskQueue empty; |
| 396 rasterizer_->ScheduleTasks(&empty); | 393 rasterizer_->ScheduleTasks(&empty); |
| 397 orphan_raster_tasks_.clear(); | |
| 398 | 394 |
| 399 // This should finish all pending tasks and release any uninitialized | 395 // This should finish all pending tasks and release any uninitialized |
| 400 // resources. | 396 // resources. |
| 401 rasterizer_->Shutdown(); | 397 rasterizer_->Shutdown(); |
| 402 rasterizer_->CheckForCompletedTasks(); | 398 rasterizer_->CheckForCompletedTasks(); |
| 403 | 399 |
| 400 CleanUpReleasedTiles(); | |
| 401 | |
| 404 DCHECK_EQ(0u, bytes_releasable_); | 402 DCHECK_EQ(0u, bytes_releasable_); |
| 405 DCHECK_EQ(0u, resources_releasable_); | 403 DCHECK_EQ(0u, resources_releasable_); |
| 406 } | 404 } |
| 407 | 405 |
| 408 void TileManager::Release(Tile* tile) { | 406 void TileManager::Release(Tile* tile) { |
| 409 prioritized_tiles_dirty_ = true; | 407 prioritized_tiles_dirty_ = true; |
| 410 released_tiles_.push_back(tile); | 408 released_tiles_.push_back(tile); |
| 411 } | 409 } |
| 412 | 410 |
| 413 void TileManager::DidChangeTilePriority(Tile* tile) { | 411 void TileManager::DidChangeTilePriority(Tile* tile) { |
| 414 prioritized_tiles_dirty_ = true; | 412 prioritized_tiles_dirty_ = true; |
| 415 } | 413 } |
| 416 | 414 |
| 417 bool TileManager::ShouldForceTasksRequiredForActivationToComplete() const { | 415 bool TileManager::ShouldForceTasksRequiredForActivationToComplete() const { |
| 418 return global_state_.tree_priority != SMOOTHNESS_TAKES_PRIORITY; | 416 return global_state_.tree_priority != SMOOTHNESS_TAKES_PRIORITY; |
| 419 } | 417 } |
| 420 | 418 |
| 421 void TileManager::CleanUpReleasedTiles() { | 419 void TileManager::CleanUpReleasedTiles() { |
| 422 for (std::vector<Tile*>::iterator it = released_tiles_.begin(); | 420 std::vector<Tile*>::iterator it = released_tiles_.begin(); |
| 423 it != released_tiles_.end(); | 421 while (it != released_tiles_.end()) { |
| 424 ++it) { | |
| 425 Tile* tile = *it; | 422 Tile* tile = *it; |
| 426 ManagedTileState& mts = tile->managed_state(); | 423 ManagedTileState& mts = tile->managed_state(); |
| 424 bool tile_has_raster_task = false; | |
| 427 | 425 |
| 428 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { | 426 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { |
| 429 FreeResourceForTile(tile, static_cast<RasterMode>(mode)); | 427 FreeResourceForTile(tile, static_cast<RasterMode>(mode)); |
|
reveman
2014/07/09 14:15:30
What's the difference between this and only releas
sohanjg
2014/07/09 14:32:11
Hmm, 1 thing could be we optimize resource usage (
vmpstr
2014/07/09 18:41:21
I think at this point the tile is set to be delete
reveman
2014/07/09 20:09:43
Maybe we should make this a bit more explicit by a
vmpstr
2014/07/09 23:15:14
That sounds good to me.
sohanjg
2014/07/10 13:29:45
Done.
| |
| 430 orphan_raster_tasks_.push_back(mts.tile_versions[mode].raster_task_); | 428 if (mts.tile_versions[mode].raster_task_) |
| 429 tile_has_raster_task = true; | |
| 430 } | |
| 431 | |
| 432 if (tile_has_raster_task) { | |
| 433 ++it; | |
| 434 continue; | |
| 431 } | 435 } |
| 432 | 436 |
| 433 DCHECK(tiles_.find(tile->id()) != tiles_.end()); | 437 DCHECK(tiles_.find(tile->id()) != tiles_.end()); |
|
vmpstr
2014/07/09 23:15:14
Sorry to backtrack a bit. My previous comment alre
reveman
2014/07/10 11:23:03
I prefer to keep it in |tiles_| and change the "it
sohanjg
2014/07/10 13:29:45
Done.
| |
| 434 tiles_.erase(tile->id()); | 438 tiles_.erase(tile->id()); |
| 435 | 439 |
| 436 LayerCountMap::iterator layer_it = | 440 LayerCountMap::iterator layer_it = |
| 437 used_layer_counts_.find(tile->layer_id()); | 441 used_layer_counts_.find(tile->layer_id()); |
| 438 DCHECK_GT(layer_it->second, 0); | 442 DCHECK_GT(layer_it->second, 0); |
| 439 if (--layer_it->second == 0) { | 443 if (--layer_it->second == 0) { |
| 440 used_layer_counts_.erase(layer_it); | 444 used_layer_counts_.erase(layer_it); |
| 441 image_decode_tasks_.erase(tile->layer_id()); | 445 image_decode_tasks_.erase(tile->layer_id()); |
| 442 } | 446 } |
| 443 | 447 |
| 444 delete tile; | 448 delete tile; |
| 449 it = released_tiles_.erase(it); | |
| 445 } | 450 } |
| 446 | |
| 447 released_tiles_.clear(); | |
| 448 } | 451 } |
| 449 | 452 |
| 450 void TileManager::UpdatePrioritizedTileSetIfNeeded() { | 453 void TileManager::UpdatePrioritizedTileSetIfNeeded() { |
| 451 if (!prioritized_tiles_dirty_) | 454 if (!prioritized_tiles_dirty_) |
| 452 return; | 455 return; |
| 453 | 456 |
| 454 CleanUpReleasedTiles(); | 457 CleanUpReleasedTiles(); |
| 455 | 458 |
| 456 prioritized_tiles_.Clear(); | 459 prioritized_tiles_.Clear(); |
| 457 GetTilesWithAssignedBins(&prioritized_tiles_); | 460 GetTilesWithAssignedBins(&prioritized_tiles_); |
| (...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 963 | 966 |
| 964 // We must reduce the amount of unused resoruces before calling | 967 // We must reduce the amount of unused resoruces before calling |
| 965 // ScheduleTasks to prevent usage from rising above limits. | 968 // ScheduleTasks to prevent usage from rising above limits. |
| 966 resource_pool_->ReduceResourceUsage(); | 969 resource_pool_->ReduceResourceUsage(); |
| 967 | 970 |
| 968 // Schedule running of |raster_tasks_|. This replaces any previously | 971 // Schedule running of |raster_tasks_|. This replaces any previously |
| 969 // scheduled tasks and effectively cancels all tasks not present | 972 // scheduled tasks and effectively cancels all tasks not present |
| 970 // in |raster_tasks_|. | 973 // in |raster_tasks_|. |
| 971 rasterizer_->ScheduleTasks(&raster_queue_); | 974 rasterizer_->ScheduleTasks(&raster_queue_); |
| 972 | 975 |
| 973 // It's now safe to clean up orphan tasks as raster worker pool is not | |
| 974 // allowed to keep around unreferenced raster tasks after ScheduleTasks() has | |
| 975 // been called. | |
| 976 orphan_raster_tasks_.clear(); | |
| 977 | |
| 978 did_check_for_completed_tasks_since_last_schedule_tasks_ = false; | 976 did_check_for_completed_tasks_since_last_schedule_tasks_ = false; |
| 979 } | 977 } |
| 980 | 978 |
| 981 scoped_refptr<ImageDecodeTask> TileManager::CreateImageDecodeTask( | 979 scoped_refptr<ImageDecodeTask> TileManager::CreateImageDecodeTask( |
| 982 Tile* tile, | 980 Tile* tile, |
| 983 SkPixelRef* pixel_ref) { | 981 SkPixelRef* pixel_ref) { |
| 984 return make_scoped_refptr(new ImageDecodeTaskImpl( | 982 return make_scoped_refptr(new ImageDecodeTaskImpl( |
| 985 pixel_ref, | 983 pixel_ref, |
| 986 tile->layer_id(), | 984 tile->layer_id(), |
| 987 rendering_stats_instrumentation_, | 985 rendering_stats_instrumentation_, |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1071 TileMap::iterator it = tiles_.find(tile_id); | 1069 TileMap::iterator it = tiles_.find(tile_id); |
| 1072 if (it == tiles_.end()) { | 1070 if (it == tiles_.end()) { |
| 1073 ++update_visible_tiles_stats_.canceled_count; | 1071 ++update_visible_tiles_stats_.canceled_count; |
| 1074 resource_pool_->ReleaseResource(resource.Pass()); | 1072 resource_pool_->ReleaseResource(resource.Pass()); |
| 1075 return; | 1073 return; |
| 1076 } | 1074 } |
| 1077 | 1075 |
| 1078 Tile* tile = it->second; | 1076 Tile* tile = it->second; |
| 1079 ManagedTileState& mts = tile->managed_state(); | 1077 ManagedTileState& mts = tile->managed_state(); |
| 1080 ManagedTileState::TileVersion& tile_version = mts.tile_versions[raster_mode]; | 1078 ManagedTileState::TileVersion& tile_version = mts.tile_versions[raster_mode]; |
| 1081 DCHECK(tile_version.raster_task_); | |
| 1082 orphan_raster_tasks_.push_back(tile_version.raster_task_); | |
| 1083 tile_version.raster_task_ = NULL; | 1079 tile_version.raster_task_ = NULL; |
| 1084 | 1080 |
| 1085 if (was_canceled) { | 1081 if (was_canceled) { |
| 1086 ++update_visible_tiles_stats_.canceled_count; | 1082 ++update_visible_tiles_stats_.canceled_count; |
| 1087 resource_pool_->ReleaseResource(resource.Pass()); | 1083 resource_pool_->ReleaseResource(resource.Pass()); |
| 1088 return; | 1084 return; |
| 1089 } | 1085 } |
| 1090 | 1086 |
| 1091 ++update_visible_tiles_stats_.completed_count; | 1087 ++update_visible_tiles_stats_.completed_count; |
| 1092 | 1088 |
| (...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1576 TRACE_EVENT0("cc", "TileManager::CheckIfReadyToActivate"); | 1572 TRACE_EVENT0("cc", "TileManager::CheckIfReadyToActivate"); |
| 1577 | 1573 |
| 1578 rasterizer_->CheckForCompletedTasks(); | 1574 rasterizer_->CheckForCompletedTasks(); |
| 1579 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; | 1575 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; |
| 1580 | 1576 |
| 1581 if (IsReadyToActivate()) | 1577 if (IsReadyToActivate()) |
| 1582 client_->NotifyReadyToActivate(); | 1578 client_->NotifyReadyToActivate(); |
| 1583 } | 1579 } |
| 1584 | 1580 |
| 1585 } // namespace cc | 1581 } // namespace cc |
| OLD | NEW |