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 FreeResourcesForReleasedTiles(); | |
| 401 CleanUpReleasedTiles(); | |
| 402 DCHECK_EQ(0u, tiles_.size()); | |
| 403 | |
| 404 DCHECK_EQ(0u, bytes_releasable_); | 404 DCHECK_EQ(0u, bytes_releasable_); |
| 405 DCHECK_EQ(0u, resources_releasable_); | 405 DCHECK_EQ(0u, resources_releasable_); |
| 406 } | 406 } |
| 407 | 407 |
| 408 void TileManager::Release(Tile* tile) { | 408 void TileManager::Release(Tile* tile) { |
| 409 prioritized_tiles_dirty_ = true; | 409 prioritized_tiles_dirty_ = true; |
| 410 released_tiles_.push_back(tile); | 410 released_tiles_.push_back(tile); |
| 411 } | 411 } |
| 412 | 412 |
| 413 void TileManager::DidChangeTilePriority(Tile* tile) { | 413 void TileManager::DidChangeTilePriority(Tile* tile) { |
| 414 prioritized_tiles_dirty_ = true; | 414 prioritized_tiles_dirty_ = true; |
| 415 } | 415 } |
| 416 | 416 |
| 417 bool TileManager::ShouldForceTasksRequiredForActivationToComplete() const { | 417 bool TileManager::ShouldForceTasksRequiredForActivationToComplete() const { |
| 418 return global_state_.tree_priority != SMOOTHNESS_TAKES_PRIORITY; | 418 return global_state_.tree_priority != SMOOTHNESS_TAKES_PRIORITY; |
| 419 } | 419 } |
| 420 | 420 |
| 421 void TileManager::CleanUpReleasedTiles() { | 421 void TileManager::FreeResourcesForReleasedTiles() { |
| 422 for (std::vector<Tile*>::iterator it = released_tiles_.begin(); | 422 for (std::vector<Tile*>::iterator it = released_tiles_.begin(); |
| 423 it != released_tiles_.end(); | 423 it != released_tiles_.end(); |
| 424 ++it) { | 424 ++it) { |
| 425 Tile* tile = *it; | 425 Tile* tile = *it; |
| 426 ManagedTileState& mts = tile->managed_state(); | 426 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) |
| 427 FreeResourceForTile(tile, static_cast<RasterMode>(mode)); | |
| 428 } | |
| 429 } | |
| 427 | 430 |
| 428 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { | 431 void TileManager::CleanUpReleasedTiles() { |
|
reveman
2014/07/17 15:10:50
How about adding a DCHECK(prioritized_tiles_dirty_
sohanjg
2014/07/17 15:58:33
Done.
| |
| 429 FreeResourceForTile(tile, static_cast<RasterMode>(mode)); | 432 std::vector<Tile*>::iterator it = released_tiles_.begin(); |
| 430 orphan_raster_tasks_.push_back(mts.tile_versions[mode].raster_task_); | 433 while (it != released_tiles_.end()) { |
| 434 Tile* tile = *it; | |
| 435 | |
| 436 if (TileHasRasterTask(tile)) { | |
| 437 ++it; | |
| 438 continue; | |
| 431 } | 439 } |
| 432 | 440 |
| 441 DCHECK(!tile->HasResources()); | |
| 433 DCHECK(tiles_.find(tile->id()) != tiles_.end()); | 442 DCHECK(tiles_.find(tile->id()) != tiles_.end()); |
| 434 tiles_.erase(tile->id()); | 443 tiles_.erase(tile->id()); |
| 435 | 444 |
| 436 LayerCountMap::iterator layer_it = | 445 LayerCountMap::iterator layer_it = |
| 437 used_layer_counts_.find(tile->layer_id()); | 446 used_layer_counts_.find(tile->layer_id()); |
| 438 DCHECK_GT(layer_it->second, 0); | 447 DCHECK_GT(layer_it->second, 0); |
| 439 if (--layer_it->second == 0) { | 448 if (--layer_it->second == 0) { |
| 440 used_layer_counts_.erase(layer_it); | 449 used_layer_counts_.erase(layer_it); |
| 441 image_decode_tasks_.erase(tile->layer_id()); | 450 image_decode_tasks_.erase(tile->layer_id()); |
| 442 } | 451 } |
| 443 | 452 |
| 444 delete tile; | 453 delete tile; |
| 454 it = released_tiles_.erase(it); | |
| 445 } | 455 } |
| 446 | |
| 447 released_tiles_.clear(); | |
| 448 } | 456 } |
| 449 | 457 |
| 450 void TileManager::UpdatePrioritizedTileSetIfNeeded() { | 458 void TileManager::UpdatePrioritizedTileSetIfNeeded() { |
| 451 if (!prioritized_tiles_dirty_) | 459 if (!prioritized_tiles_dirty_) |
| 452 return; | 460 return; |
| 453 | 461 |
| 462 FreeResourcesForReleasedTiles(); | |
| 454 CleanUpReleasedTiles(); | 463 CleanUpReleasedTiles(); |
| 455 | 464 |
| 456 prioritized_tiles_.Clear(); | 465 prioritized_tiles_.Clear(); |
| 457 GetTilesWithAssignedBins(&prioritized_tiles_); | 466 GetTilesWithAssignedBins(&prioritized_tiles_); |
| 458 prioritized_tiles_dirty_ = false; | 467 prioritized_tiles_dirty_ = false; |
| 459 } | 468 } |
| 460 | 469 |
| 461 void TileManager::DidFinishRunningTasks() { | 470 void TileManager::DidFinishRunningTasks() { |
| 462 TRACE_EVENT0("cc", "TileManager::DidFinishRunningTasks"); | 471 TRACE_EVENT0("cc", "TileManager::DidFinishRunningTasks"); |
| 463 | 472 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 477 AssignGpuMemoryToTiles(&prioritized_tiles_, | 486 AssignGpuMemoryToTiles(&prioritized_tiles_, |
| 478 &tiles_that_need_to_be_rasterized); | 487 &tiles_that_need_to_be_rasterized); |
| 479 | 488 |
| 480 // |tiles_that_need_to_be_rasterized| will be empty when we reach a | 489 // |tiles_that_need_to_be_rasterized| will be empty when we reach a |
| 481 // steady memory state. Keep scheduling tasks until we reach this state. | 490 // steady memory state. Keep scheduling tasks until we reach this state. |
| 482 if (!tiles_that_need_to_be_rasterized.empty()) { | 491 if (!tiles_that_need_to_be_rasterized.empty()) { |
| 483 ScheduleTasks(tiles_that_need_to_be_rasterized); | 492 ScheduleTasks(tiles_that_need_to_be_rasterized); |
| 484 return; | 493 return; |
| 485 } | 494 } |
| 486 | 495 |
| 496 FreeResourcesForReleasedTiles(); | |
| 497 CleanUpReleasedTiles(); | |
|
reveman
2014/07/17 15:10:50
I don't think you should do the cleanup here as th
sohanjg
2014/07/17 15:58:33
Done.
| |
| 487 resource_pool_->ReduceResourceUsage(); | 498 resource_pool_->ReduceResourceUsage(); |
| 488 | 499 |
| 489 // We don't reserve memory for required-for-activation tiles during | 500 // We don't reserve memory for required-for-activation tiles during |
| 490 // accelerated gestures, so we just postpone activation when we don't | 501 // accelerated gestures, so we just postpone activation when we don't |
| 491 // have these tiles, and activate after the accelerated gesture. | 502 // have these tiles, and activate after the accelerated gesture. |
| 492 bool allow_rasterize_on_demand = | 503 bool allow_rasterize_on_demand = |
| 493 global_state_.tree_priority != SMOOTHNESS_TAKES_PRIORITY; | 504 global_state_.tree_priority != SMOOTHNESS_TAKES_PRIORITY; |
| 494 | 505 |
| 495 // Use on-demand raster for any required-for-activation tiles that have not | 506 // Use on-demand raster for any required-for-activation tiles that have not |
| 496 // been been assigned memory after reaching a steady memory state. This | 507 // been been assigned memory after reaching a steady memory state. This |
| (...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 964 | 975 |
| 965 // We must reduce the amount of unused resoruces before calling | 976 // We must reduce the amount of unused resoruces before calling |
| 966 // ScheduleTasks to prevent usage from rising above limits. | 977 // ScheduleTasks to prevent usage from rising above limits. |
| 967 resource_pool_->ReduceResourceUsage(); | 978 resource_pool_->ReduceResourceUsage(); |
| 968 | 979 |
| 969 // Schedule running of |raster_tasks_|. This replaces any previously | 980 // Schedule running of |raster_tasks_|. This replaces any previously |
| 970 // scheduled tasks and effectively cancels all tasks not present | 981 // scheduled tasks and effectively cancels all tasks not present |
| 971 // in |raster_tasks_|. | 982 // in |raster_tasks_|. |
| 972 rasterizer_->ScheduleTasks(&raster_queue_); | 983 rasterizer_->ScheduleTasks(&raster_queue_); |
| 973 | 984 |
| 974 // It's now safe to clean up orphan tasks as raster worker pool is not | |
| 975 // allowed to keep around unreferenced raster tasks after ScheduleTasks() has | |
| 976 // been called. | |
| 977 orphan_raster_tasks_.clear(); | |
| 978 | |
| 979 did_check_for_completed_tasks_since_last_schedule_tasks_ = false; | 985 did_check_for_completed_tasks_since_last_schedule_tasks_ = false; |
| 980 } | 986 } |
| 981 | 987 |
| 982 scoped_refptr<ImageDecodeTask> TileManager::CreateImageDecodeTask( | 988 scoped_refptr<ImageDecodeTask> TileManager::CreateImageDecodeTask( |
| 983 Tile* tile, | 989 Tile* tile, |
| 984 SkPixelRef* pixel_ref) { | 990 SkPixelRef* pixel_ref) { |
| 985 return make_scoped_refptr(new ImageDecodeTaskImpl( | 991 return make_scoped_refptr(new ImageDecodeTaskImpl( |
| 986 pixel_ref, | 992 pixel_ref, |
| 987 tile->layer_id(), | 993 tile->layer_id(), |
| 988 rendering_stats_instrumentation_, | 994 rendering_stats_instrumentation_, |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1063 pixel_ref_tasks.erase(task_it); | 1069 pixel_ref_tasks.erase(task_it); |
| 1064 } | 1070 } |
| 1065 | 1071 |
| 1066 void TileManager::OnRasterTaskCompleted( | 1072 void TileManager::OnRasterTaskCompleted( |
| 1067 Tile::Id tile_id, | 1073 Tile::Id tile_id, |
| 1068 scoped_ptr<ScopedResource> resource, | 1074 scoped_ptr<ScopedResource> resource, |
| 1069 RasterMode raster_mode, | 1075 RasterMode raster_mode, |
| 1070 const PicturePileImpl::Analysis& analysis, | 1076 const PicturePileImpl::Analysis& analysis, |
| 1071 bool was_canceled) { | 1077 bool was_canceled) { |
| 1072 TileMap::iterator it = tiles_.find(tile_id); | 1078 TileMap::iterator it = tiles_.find(tile_id); |
| 1073 if (it == tiles_.end()) { | 1079 DCHECK(it != tiles_.end()); |
| 1074 ++update_visible_tiles_stats_.canceled_count; | |
| 1075 resource_pool_->ReleaseResource(resource.Pass()); | |
| 1076 return; | |
| 1077 } | |
| 1078 | 1080 |
| 1079 Tile* tile = it->second; | 1081 Tile* tile = it->second; |
| 1080 ManagedTileState& mts = tile->managed_state(); | 1082 ManagedTileState& mts = tile->managed_state(); |
| 1081 ManagedTileState::TileVersion& tile_version = mts.tile_versions[raster_mode]; | 1083 ManagedTileState::TileVersion& tile_version = mts.tile_versions[raster_mode]; |
| 1082 DCHECK(tile_version.raster_task_); | 1084 DCHECK(tile_version.raster_task_); |
| 1083 orphan_raster_tasks_.push_back(tile_version.raster_task_); | |
| 1084 tile_version.raster_task_ = NULL; | 1085 tile_version.raster_task_ = NULL; |
| 1085 | 1086 |
| 1086 if (was_canceled) { | 1087 if (was_canceled) { |
| 1087 ++update_visible_tiles_stats_.canceled_count; | 1088 ++update_visible_tiles_stats_.canceled_count; |
| 1088 resource_pool_->ReleaseResource(resource.Pass()); | 1089 resource_pool_->ReleaseResource(resource.Pass()); |
| 1089 return; | 1090 return; |
| 1090 } | 1091 } |
| 1091 | 1092 |
| 1092 ++update_visible_tiles_stats_.completed_count; | 1093 ++update_visible_tiles_stats_.completed_count; |
| 1093 | 1094 |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1576 void TileManager::CheckIfReadyToActivate() { | 1577 void TileManager::CheckIfReadyToActivate() { |
| 1577 TRACE_EVENT0("cc", "TileManager::CheckIfReadyToActivate"); | 1578 TRACE_EVENT0("cc", "TileManager::CheckIfReadyToActivate"); |
| 1578 | 1579 |
| 1579 rasterizer_->CheckForCompletedTasks(); | 1580 rasterizer_->CheckForCompletedTasks(); |
| 1580 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; | 1581 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; |
| 1581 | 1582 |
| 1582 if (IsReadyToActivate()) | 1583 if (IsReadyToActivate()) |
| 1583 client_->NotifyReadyToActivate(); | 1584 client_->NotifyReadyToActivate(); |
| 1584 } | 1585 } |
| 1585 | 1586 |
| 1587 // static | |
| 1588 bool TileManager::TileHasRasterTask(const Tile* tile) { | |
| 1589 const ManagedTileState& mts = tile->managed_state(); | |
| 1590 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { | |
| 1591 if (mts.tile_versions[mode].raster_task_) | |
| 1592 return true; | |
| 1593 } | |
| 1594 return false; | |
| 1595 } | |
| 1596 | |
| 1586 } // namespace cc | 1597 } // namespace cc |
| OLD | NEW |