| 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/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/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 return true; | 300 return true; |
| 301 } | 301 } |
| 302 | 302 |
| 303 void PrioritizedResourceManager::ReduceWastedMemory( | 303 void PrioritizedResourceManager::ReduceWastedMemory( |
| 304 ResourceProvider* resource_provider) { | 304 ResourceProvider* resource_provider) { |
| 305 // We currently collect backings from deleted textures for later recycling. | 305 // We currently collect backings from deleted textures for later recycling. |
| 306 // However, if we do that forever we will always use the max limit even if | 306 // However, if we do that forever we will always use the max limit even if |
| 307 // we really need very little memory. This should probably be solved by | 307 // we really need very little memory. This should probably be solved by |
| 308 // reducing the limit externally, but until then this just does some "clean | 308 // reducing the limit externally, but until then this just does some "clean |
| 309 // up" of unused backing textures (any more than 10%). | 309 // up" of unused backing textures (any more than 10%). |
| 310 size_t wastedMemory = 0; | 310 size_t wasted_memory = 0; |
| 311 for (BackingList::iterator it = backings_.begin(); it != backings_.end(); | 311 for (BackingList::iterator it = backings_.begin(); it != backings_.end(); |
| 312 ++it) { | 312 ++it) { |
| 313 if ((*it)->owner()) | 313 if ((*it)->owner()) |
| 314 break; | 314 break; |
| 315 wastedMemory += (*it)->bytes(); | 315 wasted_memory += (*it)->bytes(); |
| 316 } | 316 } |
| 317 size_t tenPercentOfMemory = memory_available_bytes_ / 10; | 317 size_t ten_percent_of_memory = memory_available_bytes_ / 10; |
| 318 if (wastedMemory > tenPercentOfMemory) | 318 if (wasted_memory > ten_percent_of_memory) |
| 319 EvictBackingsToReduceMemory(MemoryUseBytes() - | 319 EvictBackingsToReduceMemory(MemoryUseBytes() - |
| 320 (wastedMemory - tenPercentOfMemory), | 320 (wasted_memory - ten_percent_of_memory), |
| 321 PriorityCalculator::AllowEverythingCutoff(), | 321 PriorityCalculator::AllowEverythingCutoff(), |
| 322 EVICT_ONLY_RECYCLABLE, | 322 EVICT_ONLY_RECYCLABLE, |
| 323 DO_NOT_UNLINK_BACKINGS, | 323 DO_NOT_UNLINK_BACKINGS, |
| 324 resource_provider); | 324 resource_provider); |
| 325 } | 325 } |
| 326 | 326 |
| 327 void PrioritizedResourceManager::ReduceMemory( | 327 void PrioritizedResourceManager::ReduceMemory( |
| 328 ResourceProvider* resource_provider) { | 328 ResourceProvider* resource_provider) { |
| 329 DCHECK(proxy_->IsImplThread() && proxy_->IsMainThreadBlocked()); | 329 DCHECK(proxy_->IsImplThread() && proxy_->IsMainThreadBlocked()); |
| 330 EvictBackingsToReduceMemory(memory_available_bytes_, | 330 EvictBackingsToReduceMemory(memory_available_bytes_, |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 DCHECK(std::find(evicted_backings_.begin(), | 508 DCHECK(std::find(evicted_backings_.begin(), |
| 509 evicted_backings_.end(), | 509 evicted_backings_.end(), |
| 510 backing) == evicted_backings_.end()); | 510 backing) == evicted_backings_.end()); |
| 511 } | 511 } |
| 512 DCHECK(backing->owner() == texture); | 512 DCHECK(backing->owner() == texture); |
| 513 } | 513 } |
| 514 } | 514 } |
| 515 | 515 |
| 516 // At all times, backings that can be evicted must always come before | 516 // At all times, backings that can be evicted must always come before |
| 517 // backings that can't be evicted in the backing texture list (otherwise | 517 // backings that can't be evicted in the backing texture list (otherwise |
| 518 // reduceMemory will not find all textures available for eviction/recycling). | 518 // ReduceMemory will not find all textures available for eviction/recycling). |
| 519 bool reached_unrecyclable = false; | 519 bool reached_unrecyclable = false; |
| 520 PrioritizedResource::Backing* previous_backing = NULL; | 520 PrioritizedResource::Backing* previous_backing = NULL; |
| 521 for (BackingList::iterator it = backings_.begin(); it != backings_.end(); | 521 for (BackingList::iterator it = backings_.begin(); it != backings_.end(); |
| 522 ++it) { | 522 ++it) { |
| 523 PrioritizedResource::Backing* backing = *it; | 523 PrioritizedResource::Backing* backing = *it; |
| 524 if (previous_backing && | 524 if (previous_backing && |
| 525 (!backings_tail_not_sorted_ || | 525 (!backings_tail_not_sorted_ || |
| 526 !backing->was_above_priority_cutoff_at_last_priority_update())) | 526 !backing->was_above_priority_cutoff_at_last_priority_update())) |
| 527 DCHECK(CompareBackings(previous_backing, backing)); | 527 DCHECK(CompareBackings(previous_backing, backing)); |
| 528 if (!backing->CanBeRecycled()) | 528 if (!backing->CanBeRecycled()) |
| 529 reached_unrecyclable = true; | 529 reached_unrecyclable = true; |
| 530 if (reached_unrecyclable) | 530 if (reached_unrecyclable) |
| 531 DCHECK(!backing->CanBeRecycled()); | 531 DCHECK(!backing->CanBeRecycled()); |
| 532 else | 532 else |
| 533 DCHECK(backing->CanBeRecycled()); | 533 DCHECK(backing->CanBeRecycled()); |
| 534 previous_backing = backing; | 534 previous_backing = backing; |
| 535 } | 535 } |
| 536 #endif | 536 #endif |
| 537 } | 537 } |
| 538 | 538 |
| 539 const Proxy* PrioritizedResourceManager::ProxyForDebug() const { | 539 const Proxy* PrioritizedResourceManager::ProxyForDebug() const { |
| 540 return proxy_; | 540 return proxy_; |
| 541 } | 541 } |
| 542 | 542 |
| 543 } // namespace cc | 543 } // namespace cc |
| OLD | NEW |