Chromium Code Reviews| Index: cc/resources/tile_manager.cc |
| diff --git a/cc/resources/tile_manager.cc b/cc/resources/tile_manager.cc |
| index 47f0e520e44ad521b346ef81905f1ec03a5662d9..9afe21e661cacff7d172d276d0f97e7baa5c075d 100644 |
| --- a/cc/resources/tile_manager.cc |
| +++ b/cc/resources/tile_manager.cc |
| @@ -11,6 +11,7 @@ |
| #include "base/bind.h" |
| #include "base/debug/trace_event_argument.h" |
| #include "base/json/json_writer.h" |
| +#include "base/lazy_instance.h" |
|
reveman
2014/09/16 22:49:05
do we need this?
ernstm
2014/09/17 19:57:15
Done.
|
| #include "base/logging.h" |
| #include "base/metrics/histogram.h" |
| #include "cc/debug/devtools_instrumentation.h" |
| @@ -421,8 +422,11 @@ void TileManager::DidChangeTilePriority(Tile* tile) { |
| prioritized_tiles_dirty_ = true; |
| } |
| -bool TileManager::ShouldForceTasksRequiredForActivationToComplete() const { |
| - return global_state_.tree_priority != SMOOTHNESS_TAKES_PRIORITY; |
| +TaskSetCollection TileManager::TasksThatShouldBeForcedToComplete() const { |
| + TaskSetCollection tasks_that_should_be_forced_to_complete; |
| + if (global_state_.tree_priority != SMOOTHNESS_TAKES_PRIORITY) |
| + tasks_that_should_be_forced_to_complete[REQUIRED_FOR_ACTIVATION] = true; |
| + return tasks_that_should_be_forced_to_complete; |
| } |
| void TileManager::FreeResourcesForReleasedTiles() { |
| @@ -478,75 +482,76 @@ void TileManager::UpdatePrioritizedTileSetIfNeeded() { |
| prioritized_tiles_dirty_ = false; |
| } |
| -void TileManager::DidFinishRunningTasks() { |
| - TRACE_EVENT0("cc", "TileManager::DidFinishRunningTasks"); |
| +void TileManager::DidFinishRunningTasks(TaskSet task_set) { |
| + TRACE_EVENT1( |
| + "cc", "TileManager::DidFinishRunningTasks", "task_set", task_set); |
| - bool memory_usage_above_limit = resource_pool_->total_memory_usage_bytes() > |
| - global_state_.soft_memory_limit_in_bytes; |
| + if (task_set == ALL) { |
| + bool memory_usage_above_limit = resource_pool_->total_memory_usage_bytes() > |
| + global_state_.soft_memory_limit_in_bytes; |
| - // When OOM, keep re-assigning memory until we reach a steady state |
| - // where top-priority tiles are initialized. |
| - if (all_tiles_that_need_to_be_rasterized_have_memory_ && |
| - !memory_usage_above_limit) |
| - return; |
| + // When OOM, keep re-assigning memory until we reach a steady state |
| + // where top-priority tiles are initialized. |
| + if (all_tiles_that_need_to_be_rasterized_have_memory_ && |
| + !memory_usage_above_limit) |
| + return; |
| - rasterizer_->CheckForCompletedTasks(); |
| - did_check_for_completed_tasks_since_last_schedule_tasks_ = true; |
| + rasterizer_->CheckForCompletedTasks(); |
| + did_check_for_completed_tasks_since_last_schedule_tasks_ = true; |
| - TileVector tiles_that_need_to_be_rasterized; |
| - AssignGpuMemoryToTiles(&prioritized_tiles_, |
| - &tiles_that_need_to_be_rasterized); |
| + TileVector tiles_that_need_to_be_rasterized; |
| + AssignGpuMemoryToTiles(&prioritized_tiles_, |
| + &tiles_that_need_to_be_rasterized); |
| - // |tiles_that_need_to_be_rasterized| will be empty when we reach a |
| - // steady memory state. Keep scheduling tasks until we reach this state. |
| - if (!tiles_that_need_to_be_rasterized.empty()) { |
| - ScheduleTasks(tiles_that_need_to_be_rasterized); |
| - return; |
| - } |
| + // |tiles_that_need_to_be_rasterized| will be empty when we reach a |
| + // steady memory state. Keep scheduling tasks until we reach this state. |
| + if (!tiles_that_need_to_be_rasterized.empty()) { |
| + ScheduleTasks(tiles_that_need_to_be_rasterized); |
| + return; |
| + } |
| - FreeResourcesForReleasedTiles(); |
| + FreeResourcesForReleasedTiles(); |
| - resource_pool_->ReduceResourceUsage(); |
| + resource_pool_->ReduceResourceUsage(); |
| - // We don't reserve memory for required-for-activation tiles during |
| - // accelerated gestures, so we just postpone activation when we don't |
| - // have these tiles, and activate after the accelerated gesture. |
| - bool allow_rasterize_on_demand = |
| - global_state_.tree_priority != SMOOTHNESS_TAKES_PRIORITY; |
| + // We don't reserve memory for required-for-activation tiles during |
| + // accelerated gestures, so we just postpone activation when we don't |
| + // have these tiles, and activate after the accelerated gesture. |
| + bool allow_rasterize_on_demand = |
| + global_state_.tree_priority != SMOOTHNESS_TAKES_PRIORITY; |
| - // Use on-demand raster for any required-for-activation tiles that have not |
| - // been been assigned memory after reaching a steady memory state. This |
| - // ensures that we activate even when OOM. |
| - for (TileMap::iterator it = tiles_.begin(); it != tiles_.end(); ++it) { |
| - Tile* tile = it->second; |
| - ManagedTileState& mts = tile->managed_state(); |
| - ManagedTileState::TileVersion& tile_version = |
| - mts.tile_versions[mts.raster_mode]; |
| + // Use on-demand raster for any required-for-activation tiles that have not |
| + // been been assigned memory after reaching a steady memory state. This |
| + // ensures that we activate even when OOM. |
| + for (TileMap::iterator it = tiles_.begin(); it != tiles_.end(); ++it) { |
| + Tile* tile = it->second; |
| + ManagedTileState& mts = tile->managed_state(); |
| + ManagedTileState::TileVersion& tile_version = |
| + mts.tile_versions[mts.raster_mode]; |
| - if (tile->required_for_activation() && !tile_version.IsReadyToDraw()) { |
| - // If we can't raster on demand, give up early (and don't activate). |
| - if (!allow_rasterize_on_demand) |
| - return; |
| + if (tile->required_for_activation() && !tile_version.IsReadyToDraw()) { |
| + // If we can't raster on demand, give up early (and don't activate). |
| + if (!allow_rasterize_on_demand) |
| + return; |
| - tile_version.set_rasterize_on_demand(); |
| - client_->NotifyTileStateChanged(tile); |
| + tile_version.set_rasterize_on_demand(); |
| + client_->NotifyTileStateChanged(tile); |
| + } |
| } |
| - } |
| - |
| - DCHECK(IsReadyToActivate()); |
| - ready_to_activate_check_notifier_.Schedule(); |
| -} |
| -void TileManager::DidFinishRunningTasksRequiredForActivation() { |
| - // This is only a true indication that all tiles required for |
| - // activation are initialized when no tiles are OOM. We need to |
| - // wait for DidFinishRunningTasks() to be called, try to re-assign |
| - // memory and in worst case use on-demand raster when tiles |
| - // required for activation are OOM. |
| - if (!all_tiles_required_for_activation_have_memory_) |
| - return; |
| + DCHECK(IsReadyToActivate()); |
| + ready_to_activate_check_notifier_.Schedule(); |
| + } else if (task_set == REQUIRED_FOR_ACTIVATION) { |
|
reveman
2014/09/16 22:49:05
nit: I prefer early out instead of else-ifs when p
ernstm
2014/09/17 19:57:15
Done.
|
| + // This is only a true indication that all tiles required for |
| + // activation are initialized when no tiles are OOM. We need to |
| + // wait for DidFinishRunningTasks() to be called, try to re-assign |
| + // memory and in worst case use on-demand raster when tiles |
| + // required for activation are OOM. |
| + if (!all_tiles_required_for_activation_have_memory_) |
| + return; |
| - ready_to_activate_check_notifier_.Schedule(); |
| + ready_to_activate_check_notifier_.Schedule(); |
| + } |
| } |
| void TileManager::GetTilesWithAssignedBins(PrioritizedTileSet* tiles) { |
| @@ -976,8 +981,12 @@ void TileManager::ScheduleTasks( |
| if (!tile_version.raster_task_.get()) |
| tile_version.raster_task_ = CreateRasterTask(tile); |
| - raster_queue_.items.push_back(RasterTaskQueue::Item( |
| - tile_version.raster_task_.get(), tile->required_for_activation())); |
| + TaskSetCollection task_sets; |
| + if (tile->required_for_activation()) |
| + task_sets.set(REQUIRED_FOR_ACTIVATION); |
| + task_sets.set(ALL); |
| + raster_queue_.items.push_back( |
| + RasterTaskQueue::Item(tile_version.raster_task_.get(), task_sets)); |
| } |
| // We must reduce the amount of unused resoruces before calling |