| 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 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 ResourceProvider* resource_provider) { | 283 ResourceProvider* resource_provider) { |
| 284 DCHECK(proxy_->IsImplThread()); | 284 DCHECK(proxy_->IsImplThread()); |
| 285 if (unlink_policy == UNLINK_BACKINGS) | 285 if (unlink_policy == UNLINK_BACKINGS) |
| 286 DCHECK(proxy_->IsMainThreadBlocked()); | 286 DCHECK(proxy_->IsMainThreadBlocked()); |
| 287 if (MemoryUseBytes() <= limit_bytes && | 287 if (MemoryUseBytes() <= limit_bytes && |
| 288 PriorityCalculator::AllowEverythingCutoff() == priority_cutoff) | 288 PriorityCalculator::AllowEverythingCutoff() == priority_cutoff) |
| 289 return false; | 289 return false; |
| 290 | 290 |
| 291 // Destroy backings until we are below the limit, | 291 // Destroy backings until we are below the limit, |
| 292 // or until all backings remaining are above the cutoff. | 292 // or until all backings remaining are above the cutoff. |
| 293 bool evicted_anything = false; |
| 293 while (backings_.size() > 0) { | 294 while (backings_.size() > 0) { |
| 294 PrioritizedResource::Backing* backing = backings_.front(); | 295 PrioritizedResource::Backing* backing = backings_.front(); |
| 295 if (MemoryUseBytes() <= limit_bytes && | 296 if (MemoryUseBytes() <= limit_bytes && |
| 296 PriorityCalculator::priority_is_higher( | 297 PriorityCalculator::priority_is_higher( |
| 297 backing->request_priority_at_last_priority_update(), | 298 backing->request_priority_at_last_priority_update(), |
| 298 priority_cutoff)) | 299 priority_cutoff)) |
| 299 break; | 300 break; |
| 300 if (eviction_policy == EVICT_ONLY_RECYCLABLE && !backing->CanBeRecycled()) | 301 if (eviction_policy == EVICT_ONLY_RECYCLABLE && !backing->CanBeRecycled()) |
| 301 break; | 302 break; |
| 302 if (unlink_policy == UNLINK_BACKINGS && backing->owner()) | 303 if (unlink_policy == UNLINK_BACKINGS && backing->owner()) |
| 303 backing->owner()->Unlink(); | 304 backing->owner()->Unlink(); |
| 304 EvictFirstBackingResource(resource_provider); | 305 EvictFirstBackingResource(resource_provider); |
| 306 evicted_anything = true; |
| 305 } | 307 } |
| 306 return true; | 308 return evicted_anything; |
| 307 } | 309 } |
| 308 | 310 |
| 309 void PrioritizedResourceManager::ReduceWastedMemory( | 311 void PrioritizedResourceManager::ReduceWastedMemory( |
| 310 ResourceProvider* resource_provider) { | 312 ResourceProvider* resource_provider) { |
| 311 // We currently collect backings from deleted textures for later recycling. | 313 // We currently collect backings from deleted textures for later recycling. |
| 312 // However, if we do that forever we will always use the max limit even if | 314 // However, if we do that forever we will always use the max limit even if |
| 313 // 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 |
| 314 // 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 |
| 315 // up" of unused backing textures (any more than 10%). | 317 // up" of unused backing textures (any more than 10%). |
| 316 size_t wasted_memory = 0; | 318 size_t wasted_memory = 0; |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 previous_backing = backing; | 541 previous_backing = backing; |
| 540 } | 542 } |
| 541 #endif | 543 #endif |
| 542 } | 544 } |
| 543 | 545 |
| 544 const Proxy* PrioritizedResourceManager::ProxyForDebug() const { | 546 const Proxy* PrioritizedResourceManager::ProxyForDebug() const { |
| 545 return proxy_; | 547 return proxy_; |
| 546 } | 548 } |
| 547 | 549 |
| 548 } // namespace cc | 550 } // namespace cc |
| OLD | NEW |