| 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 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 void PrioritizedResourceManager::AcquireBackingTextureIfNeeded( | 229 void PrioritizedResourceManager::AcquireBackingTextureIfNeeded( |
| 230 PrioritizedResource* texture, | 230 PrioritizedResource* texture, |
| 231 ResourceProvider* resource_provider) { | 231 ResourceProvider* resource_provider) { |
| 232 DCHECK(proxy_->IsImplThread() && proxy_->IsMainThreadBlocked()); | 232 DCHECK(proxy_->IsImplThread() && proxy_->IsMainThreadBlocked()); |
| 233 DCHECK(!texture->is_self_managed()); | 233 DCHECK(!texture->is_self_managed()); |
| 234 DCHECK(texture->is_above_priority_cutoff()); | 234 DCHECK(texture->is_above_priority_cutoff()); |
| 235 if (texture->backing() || !texture->is_above_priority_cutoff()) | 235 if (texture->backing() || !texture->is_above_priority_cutoff()) |
| 236 return; | 236 return; |
| 237 | 237 |
| 238 // Find a backing below, by either recycling or allocating. | 238 // Find a backing below, by either recycling or allocating. |
| 239 PrioritizedResource::Backing* backing = NULL; | 239 PrioritizedResource::Backing* backing = nullptr; |
| 240 | 240 |
| 241 // First try to recycle | 241 // First try to recycle |
| 242 for (BackingList::iterator it = backings_.begin(); it != backings_.end(); | 242 for (BackingList::iterator it = backings_.begin(); it != backings_.end(); |
| 243 ++it) { | 243 ++it) { |
| 244 if (!(*it)->CanBeRecycledIfNotInExternalUse()) | 244 if (!(*it)->CanBeRecycledIfNotInExternalUse()) |
| 245 break; | 245 break; |
| 246 if (resource_provider->InUseByConsumer((*it)->id())) | 246 if (resource_provider->InUseByConsumer((*it)->id())) |
| 247 continue; | 247 continue; |
| 248 if ((*it)->size() == texture->size() && | 248 if ((*it)->size() == texture->size() && |
| 249 (*it)->format() == texture->format()) { | 249 (*it)->format() == texture->format()) { |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 } | 424 } |
| 425 | 425 |
| 426 void PrioritizedResourceManager::UnregisterTexture( | 426 void PrioritizedResourceManager::UnregisterTexture( |
| 427 PrioritizedResource* texture) { | 427 PrioritizedResource* texture) { |
| 428 DCHECK(proxy_->IsMainThread() || | 428 DCHECK(proxy_->IsMainThread() || |
| 429 (proxy_->IsImplThread() && proxy_->IsMainThreadBlocked())); | 429 (proxy_->IsImplThread() && proxy_->IsMainThreadBlocked())); |
| 430 DCHECK(texture); | 430 DCHECK(texture); |
| 431 DCHECK(ContainsKey(textures_, texture)); | 431 DCHECK(ContainsKey(textures_, texture)); |
| 432 | 432 |
| 433 ReturnBackingTexture(texture); | 433 ReturnBackingTexture(texture); |
| 434 texture->set_manager_internal(NULL); | 434 texture->set_manager_internal(nullptr); |
| 435 textures_.erase(texture); | 435 textures_.erase(texture); |
| 436 texture->set_above_priority_cutoff(false); | 436 texture->set_above_priority_cutoff(false); |
| 437 } | 437 } |
| 438 | 438 |
| 439 void PrioritizedResourceManager::ReturnBackingTexture( | 439 void PrioritizedResourceManager::ReturnBackingTexture( |
| 440 PrioritizedResource* texture) { | 440 PrioritizedResource* texture) { |
| 441 DCHECK(proxy_->IsMainThread() || | 441 DCHECK(proxy_->IsMainThread() || |
| 442 (proxy_->IsImplThread() && proxy_->IsMainThreadBlocked())); | 442 (proxy_->IsImplThread() && proxy_->IsMainThreadBlocked())); |
| 443 if (texture->backing()) | 443 if (texture->backing()) |
| 444 texture->Unlink(); | 444 texture->Unlink(); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 backing) == evicted_backings_.end()); | 518 backing) == evicted_backings_.end()); |
| 519 } | 519 } |
| 520 DCHECK(backing->owner() == texture); | 520 DCHECK(backing->owner() == texture); |
| 521 } | 521 } |
| 522 } | 522 } |
| 523 | 523 |
| 524 // At all times, backings that can be evicted must always come before | 524 // At all times, backings that can be evicted must always come before |
| 525 // backings that can't be evicted in the backing texture list (otherwise | 525 // backings that can't be evicted in the backing texture list (otherwise |
| 526 // ReduceMemory will not find all textures available for eviction/recycling). | 526 // ReduceMemory will not find all textures available for eviction/recycling). |
| 527 bool reached_unrecyclable = false; | 527 bool reached_unrecyclable = false; |
| 528 PrioritizedResource::Backing* previous_backing = NULL; | 528 PrioritizedResource::Backing* previous_backing = nullptr; |
| 529 for (BackingList::iterator it = backings_.begin(); it != backings_.end(); | 529 for (BackingList::iterator it = backings_.begin(); it != backings_.end(); |
| 530 ++it) { | 530 ++it) { |
| 531 PrioritizedResource::Backing* backing = *it; | 531 PrioritizedResource::Backing* backing = *it; |
| 532 if (previous_backing && | 532 if (previous_backing && |
| 533 (!backings_tail_not_sorted_ || | 533 (!backings_tail_not_sorted_ || |
| 534 !backing->was_above_priority_cutoff_at_last_priority_update())) | 534 !backing->was_above_priority_cutoff_at_last_priority_update())) |
| 535 DCHECK(CompareBackings(previous_backing, backing)); | 535 DCHECK(CompareBackings(previous_backing, backing)); |
| 536 if (!backing->CanBeRecycledIfNotInExternalUse()) | 536 if (!backing->CanBeRecycledIfNotInExternalUse()) |
| 537 reached_unrecyclable = true; | 537 reached_unrecyclable = true; |
| 538 if (reached_unrecyclable) | 538 if (reached_unrecyclable) |
| 539 DCHECK(!backing->CanBeRecycledIfNotInExternalUse()); | 539 DCHECK(!backing->CanBeRecycledIfNotInExternalUse()); |
| 540 else | 540 else |
| 541 DCHECK(backing->CanBeRecycledIfNotInExternalUse()); | 541 DCHECK(backing->CanBeRecycledIfNotInExternalUse()); |
| 542 previous_backing = backing; | 542 previous_backing = backing; |
| 543 } | 543 } |
| 544 #endif // DCHECK_IS_ON | 544 #endif // DCHECK_IS_ON |
| 545 } | 545 } |
| 546 | 546 |
| 547 const Proxy* PrioritizedResourceManager::ProxyForDebug() const { | 547 const Proxy* PrioritizedResourceManager::ProxyForDebug() const { |
| 548 return proxy_; | 548 return proxy_; |
| 549 } | 549 } |
| 550 | 550 |
| 551 } // namespace cc | 551 } // namespace cc |
| OLD | NEW |