Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5924)

Unified Diff: cc/resources/prioritized_resource_manager.cc

Issue 1154393003: cc: Use CheckedNumeric for resource size calculations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: cc/resources/prioritized_resource_manager.cc
diff --git a/cc/resources/prioritized_resource_manager.cc b/cc/resources/prioritized_resource_manager.cc
index dc1786212370d55502c55e5494d53eb9d52a6a5b..871dad286ff2a7bd33d00cd074957e1de384fb9d 100644
--- a/cc/resources/prioritized_resource_manager.cc
+++ b/cc/resources/prioritized_resource_manager.cc
@@ -70,11 +70,13 @@ void PrioritizedResourceManager::PrioritizeTextures() {
if (PriorityCalculator::priority_is_higher(
texture->request_priority(),
PriorityCalculator::AllowVisibleOnlyCutoff()))
- memory_visible_bytes_ += texture->bytes();
+ memory_visible_bytes_ += Resource::UncheckedMemorySizeBytes(
+ texture->size(), texture->format());
if (PriorityCalculator::priority_is_higher(
texture->request_priority(),
PriorityCalculator::AllowVisibleAndNearbyCutoff()))
- memory_visible_and_nearby_bytes_ += texture->bytes();
+ memory_visible_and_nearby_bytes_ += Resource::UncheckedMemorySizeBytes(
+ texture->size(), texture->format());
}
std::sort(sorted_textures.begin(), sorted_textures.end(), CompareTextures);
@@ -85,18 +87,20 @@ void PrioritizedResourceManager::PrioritizeTextures() {
for (TextureVector::iterator it = sorted_textures.begin();
it != sorted_textures.end();
++it) {
+ size_t texture_bytes =
+ Resource::UncheckedMemorySizeBytes((*it)->size(), (*it)->format());
if ((*it)->is_self_managed()) {
// Account for self-managed memory immediately by reducing the memory
// available (since it never gets acquired).
- size_t new_memory_bytes = memory_bytes + (*it)->bytes();
+ size_t new_memory_bytes = memory_bytes + texture_bytes;
if (new_memory_bytes > memory_available_bytes_) {
priority_cutoff_ = (*it)->request_priority();
memory_available_bytes_ = memory_bytes;
break;
}
- memory_available_bytes_ -= (*it)->bytes();
+ memory_available_bytes_ -= texture_bytes;
} else {
- size_t new_memory_bytes = memory_bytes + (*it)->bytes();
+ size_t new_memory_bytes = memory_bytes + texture_bytes;
if (new_memory_bytes > memory_available_bytes_) {
priority_cutoff_ = (*it)->request_priority();
break;
@@ -130,9 +134,11 @@ void PrioritizedResourceManager::PrioritizeTextures() {
resource->request_priority(), priority_cutoff_);
resource->set_above_priority_cutoff(is_above_priority_cutoff);
if (!resource->is_self_managed()) {
- max_memory_needed_bytes_ += resource->bytes();
+ size_t resource_bytes = Resource::UncheckedMemorySizeBytes(
+ resource->size(), resource->format());
+ max_memory_needed_bytes_ += resource_bytes;
if (is_above_priority_cutoff)
- memory_above_cutoff_bytes_ += resource->bytes();
+ memory_above_cutoff_bytes_ += resource_bytes;
}
}
sorted_textures.clear();
@@ -216,7 +222,9 @@ bool PrioritizedResourceManager::RequestLate(PrioritizedResource* texture) {
external_priority_cutoff_))
return false;
- size_t new_memory_bytes = memory_above_cutoff_bytes_ + texture->bytes();
+ size_t new_memory_bytes =
+ memory_above_cutoff_bytes_ +
+ Resource::UncheckedMemorySizeBytes(texture->size(), texture->format());
if (new_memory_bytes > memory_available_bytes_)
return false;
@@ -254,11 +262,11 @@ void PrioritizedResourceManager::AcquireBackingTextureIfNeeded(
// Otherwise reduce memory and just allocate a new backing texures.
if (!backing) {
- EvictBackingsToReduceMemory(memory_available_bytes_ - texture->bytes(),
- PriorityCalculator::AllowEverythingCutoff(),
- EVICT_ONLY_RECYCLABLE,
- DO_NOT_UNLINK_BACKINGS,
- resource_provider);
+ EvictBackingsToReduceMemory(
+ memory_available_bytes_ - Resource::UncheckedMemorySizeBytes(
+ texture->size(), texture->format()),
+ PriorityCalculator::AllowEverythingCutoff(), EVICT_ONLY_RECYCLABLE,
+ DO_NOT_UNLINK_BACKINGS, resource_provider);
backing =
CreateBacking(texture->size(), texture->format(), resource_provider);
}
@@ -323,7 +331,8 @@ void PrioritizedResourceManager::ReduceWastedMemory(
break;
if ((*it)->in_parent_compositor())
continue;
- wasted_memory += (*it)->bytes();
+ wasted_memory +=
+ Resource::UncheckedMemorySizeBytes((*it)->size(), (*it)->format());
}
size_t wasted_memory_to_allow = memory_available_bytes_ / 10;
// If the external priority cutoff indicates that unused memory should be
@@ -454,7 +463,8 @@ PrioritizedResource::Backing* PrioritizedResourceManager::CreateBacking(
ResourceProvider::TEXTURE_HINT_IMMUTABLE, format);
PrioritizedResource::Backing* backing = new PrioritizedResource::Backing(
resource_id, resource_provider, size, format);
- memory_use_bytes_ += backing->bytes();
+ memory_use_bytes_ +=
+ Resource::UncheckedMemorySizeBytes(backing->size(), backing->format());
return backing;
}
@@ -470,7 +480,8 @@ void PrioritizedResourceManager::EvictFirstBackingResource(
// we can delete the resource while the main thread is running, but we cannot
// unlink backings while the main thread is running.
backing->DeleteResource(resource_provider);
- memory_use_bytes_ -= backing->bytes();
+ memory_use_bytes_ -=
+ Resource::UncheckedMemorySizeBytes(backing->size(), backing->format());
backings_.pop_front();
base::AutoLock scoped_lock(evicted_backings_lock_);
evicted_backings_.push_back(backing);

Powered by Google App Engine
This is Rietveld 408576698