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

Side by Side 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: initialize var 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 unified diff | Download patch
« no previous file with comments | « cc/resources/prioritized_resource.cc ('k') | cc/resources/prioritized_resource_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/prioritized_resource_manager.h" 5 #include "cc/resources/prioritized_resource_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/trace_event/trace_event.h" 9 #include "base/trace_event/trace_event.h"
10 #include "cc/resources/prioritized_resource.h" 10 #include "cc/resources/prioritized_resource.h"
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 backing = (*it); 249 backing = (*it);
250 backings_.erase(it); 250 backings_.erase(it);
251 break; 251 break;
252 } 252 }
253 } 253 }
254 254
255 // Otherwise reduce memory and just allocate a new backing texures. 255 // Otherwise reduce memory and just allocate a new backing texures.
256 if (!backing) { 256 if (!backing) {
257 EvictBackingsToReduceMemory(memory_available_bytes_ - texture->bytes(), 257 EvictBackingsToReduceMemory(memory_available_bytes_ - texture->bytes(),
258 PriorityCalculator::AllowEverythingCutoff(), 258 PriorityCalculator::AllowEverythingCutoff(),
259 EVICT_ONLY_RECYCLABLE, 259 EVICT_ONLY_RECYCLABLE, DO_NOT_UNLINK_BACKINGS,
260 DO_NOT_UNLINK_BACKINGS,
261 resource_provider); 260 resource_provider);
262 backing = 261 backing =
263 CreateBacking(texture->size(), texture->format(), resource_provider); 262 CreateBacking(texture->size(), texture->format(), resource_provider);
264 } 263 }
265 264
266 // Move the used backing to the end of the eviction list, and note that 265 // Move the used backing to the end of the eviction list, and note that
267 // the tail is not sorted. 266 // the tail is not sorted.
268 if (backing->owner()) 267 if (backing->owner())
269 backing->owner()->Unlink(); 268 backing->owner()->Unlink();
270 texture->Link(backing); 269 texture->Link(backing);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 // we really need very little memory. This should probably be solved by 315 // we really need very little memory. This should probably be solved by
317 // reducing the limit externally, but until then this just does some "clean 316 // reducing the limit externally, but until then this just does some "clean
318 // up" of unused backing textures (any more than 10%). 317 // up" of unused backing textures (any more than 10%).
319 size_t wasted_memory = 0; 318 size_t wasted_memory = 0;
320 for (BackingList::iterator it = backings_.begin(); it != backings_.end(); 319 for (BackingList::iterator it = backings_.begin(); it != backings_.end();
321 ++it) { 320 ++it) {
322 if ((*it)->owner()) 321 if ((*it)->owner())
323 break; 322 break;
324 if ((*it)->in_parent_compositor()) 323 if ((*it)->in_parent_compositor())
325 continue; 324 continue;
326 wasted_memory += (*it)->bytes(); 325 wasted_memory +=
326 Resource::UncheckedMemorySizeBytes((*it)->size(), (*it)->format());
327 } 327 }
328 size_t wasted_memory_to_allow = memory_available_bytes_ / 10; 328 size_t wasted_memory_to_allow = memory_available_bytes_ / 10;
329 // If the external priority cutoff indicates that unused memory should be 329 // If the external priority cutoff indicates that unused memory should be
330 // freed, then do not allow any memory for texture recycling. 330 // freed, then do not allow any memory for texture recycling.
331 if (external_priority_cutoff_ != PriorityCalculator::AllowEverythingCutoff()) 331 if (external_priority_cutoff_ != PriorityCalculator::AllowEverythingCutoff())
332 wasted_memory_to_allow = 0; 332 wasted_memory_to_allow = 0;
333 if (wasted_memory > wasted_memory_to_allow) 333 if (wasted_memory > wasted_memory_to_allow)
334 EvictBackingsToReduceMemory(MemoryUseBytes() - 334 EvictBackingsToReduceMemory(MemoryUseBytes() -
335 (wasted_memory - wasted_memory_to_allow), 335 (wasted_memory - wasted_memory_to_allow),
336 PriorityCalculator::AllowEverythingCutoff(), 336 PriorityCalculator::AllowEverythingCutoff(),
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 const gfx::Size& size, 447 const gfx::Size& size,
448 ResourceFormat format, 448 ResourceFormat format,
449 ResourceProvider* resource_provider) { 449 ResourceProvider* resource_provider) {
450 DCHECK(proxy_->IsImplThread() && proxy_->IsMainThreadBlocked()); 450 DCHECK(proxy_->IsImplThread() && proxy_->IsMainThreadBlocked());
451 DCHECK(resource_provider); 451 DCHECK(resource_provider);
452 ResourceId resource_id = resource_provider->CreateManagedResource( 452 ResourceId resource_id = resource_provider->CreateManagedResource(
453 size, GL_TEXTURE_2D, GL_CLAMP_TO_EDGE, 453 size, GL_TEXTURE_2D, GL_CLAMP_TO_EDGE,
454 ResourceProvider::TEXTURE_HINT_IMMUTABLE, format); 454 ResourceProvider::TEXTURE_HINT_IMMUTABLE, format);
455 PrioritizedResource::Backing* backing = new PrioritizedResource::Backing( 455 PrioritizedResource::Backing* backing = new PrioritizedResource::Backing(
456 resource_id, resource_provider, size, format); 456 resource_id, resource_provider, size, format);
457 memory_use_bytes_ += backing->bytes(); 457 memory_use_bytes_ +=
458 Resource::UncheckedMemorySizeBytes(backing->size(), backing->format());
458 return backing; 459 return backing;
459 } 460 }
460 461
461 void PrioritizedResourceManager::EvictFirstBackingResource( 462 void PrioritizedResourceManager::EvictFirstBackingResource(
462 ResourceProvider* resource_provider) { 463 ResourceProvider* resource_provider) {
463 DCHECK(proxy_->IsImplThread()); 464 DCHECK(proxy_->IsImplThread());
464 DCHECK(resource_provider); 465 DCHECK(resource_provider);
465 DCHECK(!backings_.empty()); 466 DCHECK(!backings_.empty());
466 PrioritizedResource::Backing* backing = backings_.front(); 467 PrioritizedResource::Backing* backing = backings_.front();
467 468
468 // Note that we create a backing and its resource at the same time, but we 469 // Note that we create a backing and its resource at the same time, but we
469 // delete the backing structure and its resource in two steps. This is because 470 // delete the backing structure and its resource in two steps. This is because
470 // we can delete the resource while the main thread is running, but we cannot 471 // we can delete the resource while the main thread is running, but we cannot
471 // unlink backings while the main thread is running. 472 // unlink backings while the main thread is running.
472 backing->DeleteResource(resource_provider); 473 backing->DeleteResource(resource_provider);
473 memory_use_bytes_ -= backing->bytes(); 474 memory_use_bytes_ -=
475 Resource::UncheckedMemorySizeBytes(backing->size(), backing->format());
474 backings_.pop_front(); 476 backings_.pop_front();
475 base::AutoLock scoped_lock(evicted_backings_lock_); 477 base::AutoLock scoped_lock(evicted_backings_lock_);
476 evicted_backings_.push_back(backing); 478 evicted_backings_.push_back(backing);
477 } 479 }
478 480
479 void PrioritizedResourceManager::AssertInvariants() { 481 void PrioritizedResourceManager::AssertInvariants() {
480 #if DCHECK_IS_ON() 482 #if DCHECK_IS_ON()
481 DCHECK(proxy_->IsImplThread() && proxy_->IsMainThreadBlocked()); 483 DCHECK(proxy_->IsImplThread() && proxy_->IsMainThreadBlocked());
482 484
483 // If we hit any of these asserts, there is a bug in this class. To see 485 // If we hit any of these asserts, there is a bug in this class. To see
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 previous_backing = backing; 539 previous_backing = backing;
538 } 540 }
539 #endif // DCHECK_IS_ON() 541 #endif // DCHECK_IS_ON()
540 } 542 }
541 543
542 const Proxy* PrioritizedResourceManager::ProxyForDebug() const { 544 const Proxy* PrioritizedResourceManager::ProxyForDebug() const {
543 return proxy_; 545 return proxy_;
544 } 546 }
545 547
546 } // namespace cc 548 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/prioritized_resource.cc ('k') | cc/resources/prioritized_resource_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698