Index: cc/resources/tile_manager.cc |
diff --git a/cc/resources/tile_manager.cc b/cc/resources/tile_manager.cc |
index e569410e7631f923cfa00b1fa31511f8d80f0578..69ca52fa681444907032ed61262b30dd89506874 100644 |
--- a/cc/resources/tile_manager.cc |
+++ b/cc/resources/tile_manager.cc |
@@ -227,110 +227,6 @@ class ImageDecodeTaskImpl : public ImageDecodeTask { |
const size_t kScheduledRasterTasksLimit = 32u; |
-// Memory limit policy works by mapping some bin states to the NEVER bin. |
-const ManagedTileBin kBinPolicyMap[NUM_TILE_MEMORY_LIMIT_POLICIES][NUM_BINS] = { |
- // [ALLOW_NOTHING] |
- {NEVER_BIN, // [NOW_AND_READY_TO_DRAW_BIN] |
- NEVER_BIN, // [NOW_BIN] |
- NEVER_BIN, // [SOON_BIN] |
- NEVER_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] |
- NEVER_BIN, // [EVENTUALLY_BIN] |
- NEVER_BIN, // [AT_LAST_AND_ACTIVE_BIN] |
- NEVER_BIN, // [AT_LAST_BIN] |
- NEVER_BIN // [NEVER_BIN] |
- }, |
- // [ALLOW_ABSOLUTE_MINIMUM] |
- {NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN] |
- NOW_BIN, // [NOW_BIN] |
- NEVER_BIN, // [SOON_BIN] |
- NEVER_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] |
- NEVER_BIN, // [EVENTUALLY_BIN] |
- NEVER_BIN, // [AT_LAST_AND_ACTIVE_BIN] |
- NEVER_BIN, // [AT_LAST_BIN] |
- NEVER_BIN // [NEVER_BIN] |
- }, |
- // [ALLOW_PREPAINT_ONLY] |
- {NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN] |
- NOW_BIN, // [NOW_BIN] |
- SOON_BIN, // [SOON_BIN] |
- NEVER_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] |
- NEVER_BIN, // [EVENTUALLY_BIN] |
- NEVER_BIN, // [AT_LAST_AND_ACTIVE_BIN] |
- NEVER_BIN, // [AT_LAST_BIN] |
- NEVER_BIN // [NEVER_BIN] |
- }, |
- // [ALLOW_ANYTHING] |
- {NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN] |
- NOW_BIN, // [NOW_BIN] |
- SOON_BIN, // [SOON_BIN] |
- EVENTUALLY_AND_ACTIVE_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] |
- EVENTUALLY_BIN, // [EVENTUALLY_BIN] |
- AT_LAST_AND_ACTIVE_BIN, // [AT_LAST_AND_ACTIVE_BIN] |
- AT_LAST_BIN, // [AT_LAST_BIN] |
- NEVER_BIN // [NEVER_BIN] |
- }}; |
- |
-// Ready to draw works by mapping NOW_BIN to NOW_AND_READY_TO_DRAW_BIN. |
-const ManagedTileBin kBinReadyToDrawMap[2][NUM_BINS] = { |
- // Not ready |
- {NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN] |
- NOW_BIN, // [NOW_BIN] |
- SOON_BIN, // [SOON_BIN] |
- EVENTUALLY_AND_ACTIVE_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] |
- EVENTUALLY_BIN, // [EVENTUALLY_BIN] |
- AT_LAST_AND_ACTIVE_BIN, // [AT_LAST_AND_ACTIVE_BIN] |
- AT_LAST_BIN, // [AT_LAST_BIN] |
- NEVER_BIN // [NEVER_BIN] |
- }, |
- // Ready |
- {NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN] |
- NOW_AND_READY_TO_DRAW_BIN, // [NOW_BIN] |
- SOON_BIN, // [SOON_BIN] |
- EVENTUALLY_AND_ACTIVE_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] |
- EVENTUALLY_BIN, // [EVENTUALLY_BIN] |
- AT_LAST_AND_ACTIVE_BIN, // [AT_LAST_AND_ACTIVE_BIN] |
- AT_LAST_BIN, // [AT_LAST_BIN] |
- NEVER_BIN // [NEVER_BIN] |
- }}; |
- |
-// Active works by mapping some bin stats to equivalent _ACTIVE_BIN state. |
-const ManagedTileBin kBinIsActiveMap[2][NUM_BINS] = { |
- // Inactive |
- {NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN] |
- NOW_BIN, // [NOW_BIN] |
- SOON_BIN, // [SOON_BIN] |
- EVENTUALLY_AND_ACTIVE_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] |
- EVENTUALLY_BIN, // [EVENTUALLY_BIN] |
- AT_LAST_AND_ACTIVE_BIN, // [AT_LAST_AND_ACTIVE_BIN] |
- AT_LAST_BIN, // [AT_LAST_BIN] |
- NEVER_BIN // [NEVER_BIN] |
- }, |
- // Active |
- {NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN] |
- NOW_BIN, // [NOW_BIN] |
- SOON_BIN, // [SOON_BIN] |
- EVENTUALLY_AND_ACTIVE_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] |
- EVENTUALLY_AND_ACTIVE_BIN, // [EVENTUALLY_BIN] |
- AT_LAST_AND_ACTIVE_BIN, // [AT_LAST_AND_ACTIVE_BIN] |
- AT_LAST_AND_ACTIVE_BIN, // [AT_LAST_BIN] |
- NEVER_BIN // [NEVER_BIN] |
- }}; |
- |
-// Determine bin based on three categories of tiles: things we need now, |
-// things we need soon, and eventually. |
-inline ManagedTileBin BinFromTilePriority(const TilePriority& prio) { |
- if (prio.priority_bin == TilePriority::NOW) |
- return NOW_BIN; |
- |
- if (prio.priority_bin == TilePriority::SOON) |
- return SOON_BIN; |
- |
- if (prio.distance_to_visible == std::numeric_limits<float>::infinity()) |
- return NEVER_BIN; |
- |
- return EVENTUALLY_BIN; |
-} |
- |
} // namespace |
RasterTaskCompletionStats::RasterTaskCompletionStats() |
@@ -368,13 +264,10 @@ TileManager::TileManager( |
task_runner_(task_runner), |
resource_pool_(resource_pool), |
rasterizer_(rasterizer), |
- prioritized_tiles_dirty_(false), |
all_tiles_that_need_to_be_rasterized_have_memory_(true), |
- all_tiles_required_for_activation_have_memory_(true), |
- memory_required_bytes_(0), |
- memory_nice_to_have_bytes_(0), |
bytes_releasable_(0), |
resources_releasable_(0), |
+ bytes_required_but_not_allocated_(0), |
ever_exceeded_memory_budget_(false), |
rendering_stats_instrumentation_(rendering_stats_instrumentation), |
did_initialize_visible_tile_(false), |
@@ -408,14 +301,9 @@ TileManager::~TileManager() { |
} |
void TileManager::Release(Tile* tile) { |
- prioritized_tiles_dirty_ = true; |
released_tiles_.push_back(tile); |
} |
-void TileManager::DidChangeTilePriority(Tile* tile) { |
- prioritized_tiles_dirty_ = true; |
-} |
- |
bool TileManager::ShouldForceTasksRequiredForActivationToComplete() const { |
return global_state_.tree_priority != SMOOTHNESS_TAKES_PRIORITY; |
} |
@@ -449,17 +337,6 @@ void TileManager::CleanUpReleasedTiles() { |
released_tiles_.clear(); |
} |
-void TileManager::UpdatePrioritizedTileSetIfNeeded() { |
- if (!prioritized_tiles_dirty_) |
- return; |
- |
- CleanUpReleasedTiles(); |
- |
- prioritized_tiles_.Clear(); |
- GetTilesWithAssignedBins(&prioritized_tiles_); |
- prioritized_tiles_dirty_ = false; |
-} |
- |
void TileManager::DidFinishRunningTasks() { |
TRACE_EVENT0("cc", "TileManager::DidFinishRunningTasks"); |
@@ -476,8 +353,7 @@ void TileManager::DidFinishRunningTasks() { |
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); |
+ AssignGpuMemoryToTiles(&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. |
@@ -518,150 +394,18 @@ void TileManager::DidFinishRunningTasks() { |
} |
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; |
- |
ready_to_activate_check_notifier_.Schedule(); |
} |
-void TileManager::GetTilesWithAssignedBins(PrioritizedTileSet* tiles) { |
- TRACE_EVENT0("cc", "TileManager::GetTilesWithAssignedBins"); |
- |
- // Compute new stats to be return by GetMemoryStats(). |
- memory_required_bytes_ = 0; |
- memory_nice_to_have_bytes_ = 0; |
- |
- const TileMemoryLimitPolicy memory_policy = global_state_.memory_limit_policy; |
- const TreePriority tree_priority = global_state_.tree_priority; |
- |
- // For each tree, bin into different categories of tiles. |
- for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { |
- Tile* tile = it->second; |
- ManagedTileState& mts = tile->managed_state(); |
- |
- const ManagedTileState::TileVersion& tile_version = |
- tile->GetTileVersionForDrawing(); |
- bool tile_is_ready_to_draw = tile_version.IsReadyToDraw(); |
- bool tile_is_active = tile_is_ready_to_draw || |
- mts.tile_versions[mts.raster_mode].raster_task_; |
- |
- // Get the active priority and bin. |
- TilePriority active_priority = tile->priority(ACTIVE_TREE); |
- ManagedTileBin active_bin = BinFromTilePriority(active_priority); |
- |
- // Get the pending priority and bin. |
- TilePriority pending_priority = tile->priority(PENDING_TREE); |
- ManagedTileBin pending_bin = BinFromTilePriority(pending_priority); |
- |
- bool pending_is_low_res = pending_priority.resolution == LOW_RESOLUTION; |
- bool pending_is_non_ideal = |
- pending_priority.resolution == NON_IDEAL_RESOLUTION; |
- bool active_is_non_ideal = |
- active_priority.resolution == NON_IDEAL_RESOLUTION; |
- |
- // Adjust bin state based on if ready to draw. |
- active_bin = kBinReadyToDrawMap[tile_is_ready_to_draw][active_bin]; |
- pending_bin = kBinReadyToDrawMap[tile_is_ready_to_draw][pending_bin]; |
- |
- // Adjust bin state based on if active. |
- active_bin = kBinIsActiveMap[tile_is_active][active_bin]; |
- pending_bin = kBinIsActiveMap[tile_is_active][pending_bin]; |
- |
- // We never want to paint new non-ideal tiles, as we always have |
- // a high-res tile covering that content (paint that instead). |
- if (!tile_is_ready_to_draw && active_is_non_ideal) |
- active_bin = NEVER_BIN; |
- if (!tile_is_ready_to_draw && pending_is_non_ideal) |
- pending_bin = NEVER_BIN; |
- |
- if (!tile_is_ready_to_draw || tile_version.requires_resource()) { |
- // The bin that the tile would have if the GPU memory manager had |
- // a maximally permissive policy, send to the GPU memory manager |
- // to determine policy. |
- ManagedTileBin gpu_memmgr_stats_bin = std::min(active_bin, pending_bin); |
- if ((gpu_memmgr_stats_bin == NOW_BIN) || |
- (gpu_memmgr_stats_bin == NOW_AND_READY_TO_DRAW_BIN)) |
- memory_required_bytes_ += BytesConsumedIfAllocated(tile); |
- if (gpu_memmgr_stats_bin != NEVER_BIN) |
- memory_nice_to_have_bytes_ += BytesConsumedIfAllocated(tile); |
- } |
- |
- ManagedTileBin tree_bin[NUM_TREES]; |
- tree_bin[ACTIVE_TREE] = kBinPolicyMap[memory_policy][active_bin]; |
- tree_bin[PENDING_TREE] = kBinPolicyMap[memory_policy][pending_bin]; |
- |
- // Adjust pending bin state for low res tiles. This prevents pending tree |
- // low-res tiles from being initialized before high-res tiles. |
- if (pending_is_low_res) |
- tree_bin[PENDING_TREE] = std::max(tree_bin[PENDING_TREE], EVENTUALLY_BIN); |
- |
- TilePriority tile_priority; |
- switch (tree_priority) { |
- case SAME_PRIORITY_FOR_BOTH_TREES: |
- mts.bin = std::min(tree_bin[ACTIVE_TREE], tree_bin[PENDING_TREE]); |
- tile_priority = tile->combined_priority(); |
- break; |
- case SMOOTHNESS_TAKES_PRIORITY: |
- mts.bin = tree_bin[ACTIVE_TREE]; |
- tile_priority = active_priority; |
- break; |
- case NEW_CONTENT_TAKES_PRIORITY: |
- mts.bin = tree_bin[PENDING_TREE]; |
- tile_priority = pending_priority; |
- break; |
- } |
- |
- // Bump up the priority if we determined it's NEVER_BIN on one tree, |
- // but is still required on the other tree. |
- bool is_in_never_bin_on_both_trees = tree_bin[ACTIVE_TREE] == NEVER_BIN && |
- tree_bin[PENDING_TREE] == NEVER_BIN; |
- |
- if (mts.bin == NEVER_BIN && !is_in_never_bin_on_both_trees) |
- mts.bin = tile_is_active ? AT_LAST_AND_ACTIVE_BIN : AT_LAST_BIN; |
- |
- mts.resolution = tile_priority.resolution; |
- mts.priority_bin = tile_priority.priority_bin; |
- mts.distance_to_visible = tile_priority.distance_to_visible; |
- mts.required_for_activation = tile_priority.required_for_activation; |
- |
- mts.visible_and_ready_to_draw = |
- tree_bin[ACTIVE_TREE] == NOW_AND_READY_TO_DRAW_BIN; |
- |
- // Tiles that are required for activation shouldn't be in NEVER_BIN unless |
- // smoothness takes priority or memory policy allows nothing to be |
- // initialized. |
- DCHECK(!mts.required_for_activation || mts.bin != NEVER_BIN || |
- tree_priority == SMOOTHNESS_TAKES_PRIORITY || |
- memory_policy == ALLOW_NOTHING); |
- |
- // If the tile is in NEVER_BIN and it does not have an active task, then we |
- // can release the resources early. If it does have the task however, we |
- // should keep it in the prioritized tile set to ensure that AssignGpuMemory |
- // can visit it. |
- if (mts.bin == NEVER_BIN && |
- !mts.tile_versions[mts.raster_mode].raster_task_) { |
- FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(tile); |
- continue; |
- } |
- |
- // Insert the tile into a priority set. |
- tiles->InsertTile(tile, mts.bin); |
- } |
-} |
- |
void TileManager::ManageTiles(const GlobalStateThatImpactsTilePriority& state) { |
TRACE_EVENT0("cc", "TileManager::ManageTiles"); |
// Update internal state. |
- if (state != global_state_) { |
- global_state_ = state; |
- prioritized_tiles_dirty_ = true; |
- } |
+ global_state_ = state; |
+ |
+ // TODO(vmpstr): See if we still need to keep tiles alive when layers release |
+ // them. |
+ CleanUpReleasedTiles(); |
// We need to call CheckForCompletedTasks() once in-between each call |
// to ScheduleTasks() to prevent canceled tasks from being scheduled. |
@@ -670,11 +414,8 @@ void TileManager::ManageTiles(const GlobalStateThatImpactsTilePriority& state) { |
did_check_for_completed_tasks_since_last_schedule_tasks_ = true; |
} |
- UpdatePrioritizedTileSetIfNeeded(); |
- |
TileVector tiles_that_need_to_be_rasterized; |
- AssignGpuMemoryToTiles(&prioritized_tiles_, |
- &tiles_that_need_to_be_rasterized); |
+ AssignGpuMemoryToTiles(&tiles_that_need_to_be_rasterized); |
// Finally, schedule rasterizer tasks. |
ScheduleTasks(tiles_that_need_to_be_rasterized); |
@@ -716,8 +457,10 @@ void TileManager::GetMemoryStats(size_t* memory_required_bytes, |
size_t* memory_nice_to_have_bytes, |
size_t* memory_allocated_bytes, |
size_t* memory_used_bytes) const { |
reveman
2014/06/14 14:53:24
Let's remove this function completely in a separat
vmpstr
2014/06/16 18:18:19
Sounds good.
|
- *memory_required_bytes = memory_required_bytes_; |
- *memory_nice_to_have_bytes = memory_nice_to_have_bytes_; |
+ *memory_required_bytes = resource_pool_->total_memory_usage_bytes() + |
vmpstr
2014/06/13 21:08:38
ccameron@, can you please take a look to see if th
|
+ bytes_required_but_not_allocated_; |
+ *memory_nice_to_have_bytes = resource_pool_->total_memory_usage_bytes() + |
+ bytes_required_but_not_allocated_; |
*memory_allocated_bytes = resource_pool_->total_memory_usage_bytes(); |
*memory_used_bytes = resource_pool_->acquired_memory_usage_bytes(); |
} |
@@ -757,8 +500,67 @@ scoped_ptr<base::Value> TileManager::GetMemoryRequirementsAsValue() const { |
return requirements.PassAs<base::Value>(); |
} |
+bool TileManager::FreeTileResourcesUntilUsageIsWithinBudget( |
+ EvictionTileIterator* eviction_iterator, |
+ const MemoryBudget& required_budget, |
+ MemoryBudget* current_budget, |
+ const TilePriority& max_priority, |
+ bool evict_unconditionally) { |
+ bool evicted_tiles_required_for_activation = false; |
+ while (required_budget.Exceeds(*current_budget)) { |
+ if (!*eviction_iterator) |
+ break; |
+ |
+ Tile* eviction_tile = **eviction_iterator; |
+ DCHECK(eviction_tile); |
+ |
+ TilePriority eviction_priority = |
+ eviction_tile->priority_for_tree_priority(global_state_.tree_priority); |
+ |
+ if (!evict_unconditionally && |
+ !max_priority.IsHigherPriorityThan(eviction_priority)) |
+ break; |
+ |
+ size_t eviction_bytes_if_allocated = |
+ BytesConsumedIfAllocated(eviction_tile); |
+ ManagedTileState& eviction_mts = eviction_tile->managed_state(); |
+ for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { |
+ if (eviction_mts.tile_versions[mode].resource_) { |
+ current_budget->hard_memory_bytes += eviction_bytes_if_allocated; |
+ if (eviction_priority.priority_bin != TilePriority::NOW) |
+ current_budget->soft_memory_bytes += eviction_bytes_if_allocated; |
+ current_budget->resource_count++; |
+ } |
+ } |
+ FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(eviction_tile); |
+ ++(*eviction_iterator); |
+ |
+ evicted_tiles_required_for_activation |= |
+ eviction_tile->required_for_activation(); |
+ } |
+ return evicted_tiles_required_for_activation; |
+} |
+ |
+bool TileManager::TilePriorityViolatesMemoryPolicy( |
+ const TilePriority& priority) { |
+ switch (global_state_.memory_limit_policy) { |
+ case ALLOW_NOTHING: |
+ return true; |
+ case ALLOW_ABSOLUTE_MINIMUM: |
+ return priority.priority_bin > TilePriority::NOW; |
+ case ALLOW_PREPAINT_ONLY: |
+ return priority.priority_bin > TilePriority::SOON; |
+ case ALLOW_ANYTHING: |
+ return priority.distance_to_visible == |
+ std::numeric_limits<float>::infinity(); |
+ case NUM_TILE_MEMORY_LIMIT_POLICIES: |
reveman
2014/06/14 14:53:24
please move NOTREACHED below so it fails if some r
vmpstr
2014/06/16 18:18:19
Done.
|
+ NOTREACHED(); |
+ break; |
+ } |
+ return true; |
+} |
+ |
void TileManager::AssignGpuMemoryToTiles( |
- PrioritizedTileSet* tiles, |
TileVector* tiles_that_need_to_be_rasterized) { |
TRACE_EVENT0("cc", "TileManager::AssignGpuMemoryToTiles"); |
@@ -772,38 +574,47 @@ void TileManager::AssignGpuMemoryToTiles( |
// Now give memory out to the tiles until we're out, and build |
// the needs-to-be-rasterized queue. |
all_tiles_that_need_to_be_rasterized_have_memory_ = true; |
- all_tiles_required_for_activation_have_memory_ = true; |
+ MemoryBudget budget; |
// Cast to prevent overflow. |
- int64 soft_bytes_available = |
- static_cast<int64>(bytes_releasable_) + |
+ budget.soft_memory_bytes = |
static_cast<int64>(global_state_.soft_memory_limit_in_bytes) - |
static_cast<int64>(resource_pool_->acquired_memory_usage_bytes()); |
- int64 hard_bytes_available = |
- static_cast<int64>(bytes_releasable_) + |
+ budget.hard_memory_bytes = |
static_cast<int64>(global_state_.hard_memory_limit_in_bytes) - |
static_cast<int64>(resource_pool_->acquired_memory_usage_bytes()); |
- int resources_available = resources_releasable_ + |
- global_state_.num_resources_limit - |
- resource_pool_->acquired_resource_count(); |
- size_t soft_bytes_allocatable = |
- std::max(static_cast<int64>(0), soft_bytes_available); |
- size_t hard_bytes_allocatable = |
- std::max(static_cast<int64>(0), hard_bytes_available); |
- size_t resources_allocatable = std::max(0, resources_available); |
+ budget.resource_count = global_state_.num_resources_limit - |
+ resource_pool_->acquired_resource_count(); |
+ |
+ MemoryBudget initial_budget = budget; |
+ |
+ EvictionTileIterator eviction_it(this, global_state_.tree_priority); |
+ |
+ MemoryBudget required_budget; |
+ required_budget.soft_memory_bytes = 0; |
+ required_budget.hard_memory_bytes = 0; |
+ required_budget.resource_count = 0; |
+ |
+ bool evicted_tiles_required_for_activation = |
+ FreeTileResourcesUntilUsageIsWithinBudget( |
+ &eviction_it, required_budget, &budget, TilePriority(), true); |
size_t bytes_that_exceeded_memory_budget = 0; |
- size_t soft_bytes_left = soft_bytes_allocatable; |
- size_t hard_bytes_left = hard_bytes_allocatable; |
- size_t resources_left = resources_allocatable; |
bool oomed_soft = false; |
bool oomed_hard = false; |
bool have_hit_soft_memory = false; // Soft memory comes after hard. |
unsigned schedule_priority = 1u; |
- for (PrioritizedTileSet::Iterator it(tiles, true); it; ++it) { |
+ RasterTileIterator it(this, global_state_.tree_priority); |
+ for (; it; ++it) { |
Tile* tile = *it; |
+ TilePriority priority = |
+ tile->priority_for_tree_priority(global_state_.tree_priority); |
+ |
+ if (TilePriorityViolatesMemoryPolicy(priority)) |
+ break; |
+ |
ManagedTileState& mts = tile->managed_state(); |
mts.scheduled_priority = schedule_priority++; |
@@ -813,20 +624,13 @@ void TileManager::AssignGpuMemoryToTiles( |
ManagedTileState::TileVersion& tile_version = |
mts.tile_versions[mts.raster_mode]; |
- // If this tile doesn't need a resource, then nothing to do. |
- if (!tile_version.requires_resource()) |
+ // If this tile version is ready to draw, then nothing to do. |
+ if (tile_version.IsReadyToDraw()) |
continue; |
- // If the tile is not needed, free it up. |
- if (mts.bin == NEVER_BIN) { |
- FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(tile); |
- continue; |
- } |
- |
- const bool tile_uses_hard_limit = mts.bin <= NOW_BIN; |
+ const bool tile_uses_hard_limit = |
+ priority.priority_bin == TilePriority::NOW; |
const size_t bytes_if_allocated = BytesConsumedIfAllocated(tile); |
- const size_t tile_bytes_left = |
- (tile_uses_hard_limit) ? hard_bytes_left : soft_bytes_left; |
// Hard-limit is reserved for tiles that would cause a calamity |
// if they were to go away, so by definition they are the highest |
@@ -834,8 +638,8 @@ void TileManager::AssignGpuMemoryToTiles( |
DCHECK(!(have_hit_soft_memory && tile_uses_hard_limit)); |
have_hit_soft_memory |= !tile_uses_hard_limit; |
- size_t tile_bytes = 0; |
- size_t tile_resources = 0; |
+ int64 tile_bytes = 0; |
+ int tile_resources = 0; |
// It costs to maintain a resource. |
for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { |
@@ -845,25 +649,30 @@ void TileManager::AssignGpuMemoryToTiles( |
} |
} |
- // Allow lower priority tiles with initialized resources to keep |
- // their memory by only assigning memory to new raster tasks if |
- // they can be scheduled. |
- bool reached_scheduled_raster_tasks_limit = |
- tiles_that_need_to_be_rasterized->size() >= kScheduledRasterTasksLimit; |
- if (!reached_scheduled_raster_tasks_limit) { |
- // If we don't have the required version, and it's not in flight |
- // then we'll have to pay to create a new task. |
- if (!tile_version.resource_ && !tile_version.raster_task_) { |
- tile_bytes += bytes_if_allocated; |
- tile_resources++; |
- } |
+ // If we don't have the required version, and it's not in flight |
+ // then we'll have to pay to create a new task. |
+ if (!tile_version.resource_ && !tile_version.raster_task_) { |
+ tile_bytes += bytes_if_allocated; |
+ tile_resources++; |
} |
- // Tile is OOM. |
- if (tile_bytes > tile_bytes_left || tile_resources > resources_left) { |
- bool was_ready_to_draw = tile->IsReadyToDraw(); |
- |
- FreeResourcesForTile(tile); |
+ required_budget.soft_memory_bytes = 0; |
+ required_budget.hard_memory_bytes = 0; |
+ required_budget.resource_count = tile_resources; |
+ if (tile_uses_hard_limit) |
+ required_budget.hard_memory_bytes = tile_bytes; |
+ else |
+ required_budget.soft_memory_bytes = tile_bytes; |
+ |
+ // Handle OOM tiles. |
+ evicted_tiles_required_for_activation = |
+ FreeTileResourcesUntilUsageIsWithinBudget( |
+ &eviction_it, required_budget, &budget, priority, false) || |
+ evicted_tiles_required_for_activation; |
+ |
+ // Tile is still OOM. |
+ if (required_budget.Exceeds(budget)) { |
+ FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(tile); |
// This tile was already on screen and now its resources have been |
// released. In order to prevent checkerboarding, set this tile as |
@@ -871,19 +680,17 @@ void TileManager::AssignGpuMemoryToTiles( |
if (mts.visible_and_ready_to_draw) |
tile_version.set_rasterize_on_demand(); |
- if (was_ready_to_draw) |
- client_->NotifyTileStateChanged(tile); |
- |
oomed_soft = true; |
if (tile_uses_hard_limit) { |
oomed_hard = true; |
bytes_that_exceeded_memory_budget += tile_bytes; |
} |
} else { |
- resources_left -= tile_resources; |
- hard_bytes_left -= tile_bytes; |
- soft_bytes_left = |
- (soft_bytes_left > tile_bytes) ? soft_bytes_left - tile_bytes : 0; |
+ budget.resource_count -= tile_resources; |
+ budget.hard_memory_bytes -= tile_bytes; |
+ budget.soft_memory_bytes = (budget.soft_memory_bytes > tile_bytes) |
+ ? budget.soft_memory_bytes - tile_bytes |
+ : 0; |
if (tile_version.resource_) |
continue; |
} |
@@ -899,19 +706,44 @@ void TileManager::AssignGpuMemoryToTiles( |
// 2. Tiles with existing raster task could otherwise incorrectly |
// be added as they are not affected by |bytes_allocatable|. |
bool can_schedule_tile = |
- !oomed_soft && !reached_scheduled_raster_tasks_limit; |
+ !oomed_soft && |
+ tiles_that_need_to_be_rasterized->size() < kScheduledRasterTasksLimit; |
if (!can_schedule_tile) { |
all_tiles_that_need_to_be_rasterized_have_memory_ = false; |
- if (tile->required_for_activation()) |
- all_tiles_required_for_activation_have_memory_ = false; |
- it.DisablePriorityOrdering(); |
- continue; |
+ break; |
} |
tiles_that_need_to_be_rasterized->push_back(tile); |
} |
+ // Count up the memory that would be required on top of the allocated memory |
+ // in order to initialize all visible tiles. |
+ // TODO(vmpstr): Remove this once the memory manager doesn't need required |
+ // bytes. |
+ bytes_required_but_not_allocated_ = 0; |
+ for (; it; ++it) { |
+ Tile* tile = *it; |
+ TilePriority priority = |
+ tile->priority_for_tree_priority(global_state_.tree_priority); |
+ |
+ if (TilePriorityViolatesMemoryPolicy(priority) || |
+ priority.priority_bin != TilePriority::NOW) |
+ break; |
+ |
+ ManagedTileState& mts = tile->managed_state(); |
+ mts.raster_mode = tile->DetermineOverallRasterMode(); |
+ |
+ ManagedTileState::TileVersion& tile_version = |
+ mts.tile_versions[mts.raster_mode]; |
+ |
+ // If this tile version is ready to draw, then nothing to do. |
+ if (tile_version.IsReadyToDraw()) |
+ continue; |
+ |
+ bytes_required_but_not_allocated_ += BytesConsumedIfAllocated(tile); |
+ } |
+ |
// OOM reporting uses hard-limit, soft-OOM is normal depending on limit. |
ever_exceeded_memory_budget_ |= oomed_hard; |
if (ever_exceeded_memory_budget_) { |
@@ -926,7 +758,7 @@ void TileManager::AssignGpuMemoryToTiles( |
memory_stats_from_last_assign_.total_budget_in_bytes = |
global_state_.hard_memory_limit_in_bytes; |
memory_stats_from_last_assign_.bytes_allocated = |
- hard_bytes_allocatable - hard_bytes_left; |
+ initial_budget.hard_memory_bytes - budget.hard_memory_bytes; |
memory_stats_from_last_assign_.bytes_unreleasable = |
resource_pool_->acquired_memory_usage_bytes() - bytes_releasable_; |
memory_stats_from_last_assign_.bytes_over = bytes_that_exceeded_memory_budget; |
@@ -1178,7 +1010,6 @@ scoped_refptr<Tile> TileManager::CreateTile(PicturePileImpl* picture_pile, |
tiles_[tile->id()] = tile; |
used_layer_counts_[tile->layer_id()]++; |
- prioritized_tiles_dirty_ = true; |
return tile; |
} |
@@ -1578,12 +1409,27 @@ bool TileManager::EvictionTileIterator::EvictionOrderComparator::operator()( |
a_tile->priority_for_tree_priority(tree_priority_); |
const TilePriority& b_priority = |
b_tile->priority_for_tree_priority(tree_priority_); |
- bool prioritize_low_res = tree_priority_ != SMOOTHNESS_TAKES_PRIORITY; |
+ bool prioritize_low_res = tree_priority_ == SMOOTHNESS_TAKES_PRIORITY; |
+ |
+ // Now we have to return true iff b is lower priority than a. |
vmpstr
2014/06/13 21:08:38
This block is parallel to what landed for the rast
reveman
2014/06/14 14:53:24
Yes, I wouldn't mind that.
|
+ |
+ // If the bin is the same but the resolution is not, then the order will be |
+ // determined by whether we prioritize low res or not. |
+ // TODO(vmpstr): Remove this when TilePriority is no longer a member of Tile |
+ // class but instead produced by the iterators. |
+ if (b_priority.priority_bin == a_priority.priority_bin && |
+ b_priority.resolution != a_priority.resolution) { |
+ // Non ideal resolution should be sorted higher than other resolutions. |
+ if (a_priority.resolution == NON_IDEAL_RESOLUTION) |
+ return false; |
+ |
+ if (b_priority.resolution == NON_IDEAL_RESOLUTION) |
+ return true; |
+ |
+ if (prioritize_low_res) |
+ return a_priority.resolution == LOW_RESOLUTION; |
- if (b_priority.resolution != a_priority.resolution) { |
- return (prioritize_low_res && b_priority.resolution == LOW_RESOLUTION) || |
- (!prioritize_low_res && b_priority.resolution == HIGH_RESOLUTION) || |
- (a_priority.resolution == NON_IDEAL_RESOLUTION); |
+ return a_priority.resolution == HIGH_RESOLUTION; |
} |
return a_priority.IsHigherPriorityThan(b_priority); |
} |