| 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/resource_pool.h" | 5 #include "cc/resources/resource_pool.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 } | 88 } |
| 89 | 89 |
| 90 SetResourceUsageLimits(0, 0); | 90 SetResourceUsageLimits(0, 0); |
| 91 DCHECK_EQ(0u, unused_resources_.size()); | 91 DCHECK_EQ(0u, unused_resources_.size()); |
| 92 DCHECK_EQ(0u, in_use_memory_usage_bytes_); | 92 DCHECK_EQ(0u, in_use_memory_usage_bytes_); |
| 93 DCHECK_EQ(0u, total_memory_usage_bytes_); | 93 DCHECK_EQ(0u, total_memory_usage_bytes_); |
| 94 DCHECK_EQ(0u, total_resource_count_); | 94 DCHECK_EQ(0u, total_resource_count_); |
| 95 } | 95 } |
| 96 | 96 |
| 97 Resource* ResourcePool::AcquireResource(const gfx::Size& size, | 97 Resource* ResourcePool::AcquireResource(const gfx::Size& size, |
| 98 ResourceFormat format) { | 98 ResourceFormat format, |
| 99 const gfx::ColorSpace& color_space) { |
| 99 // Finding resources in |unused_resources_| from MRU to LRU direction, touches | 100 // Finding resources in |unused_resources_| from MRU to LRU direction, touches |
| 100 // LRU resources only if needed, which increases possibility of expiring more | 101 // LRU resources only if needed, which increases possibility of expiring more |
| 101 // LRU resources within kResourceExpirationDelayMs. | 102 // LRU resources within kResourceExpirationDelayMs. |
| 102 for (ResourceDeque::iterator it = unused_resources_.begin(); | 103 for (ResourceDeque::iterator it = unused_resources_.begin(); |
| 103 it != unused_resources_.end(); ++it) { | 104 it != unused_resources_.end(); ++it) { |
| 104 ScopedResource* resource = it->get(); | 105 ScopedResource* resource = it->get(); |
| 105 DCHECK(resource_provider_->CanLockForWrite(resource->id())); | 106 DCHECK(resource_provider_->CanLockForWrite(resource->id())); |
| 106 | 107 |
| 107 if (resource->format() != format) | 108 if (resource->format() != format) |
| 108 continue; | 109 continue; |
| 109 if (resource->size() != size) | 110 if (resource->size() != size) |
| 110 continue; | 111 continue; |
| 112 if (resource->color_space() != color_space) |
| 113 continue; |
| 111 | 114 |
| 112 // Transfer resource to |in_use_resources_|. | 115 // Transfer resource to |in_use_resources_|. |
| 113 in_use_resources_[resource->id()] = std::move(*it); | 116 in_use_resources_[resource->id()] = std::move(*it); |
| 114 unused_resources_.erase(it); | 117 unused_resources_.erase(it); |
| 115 in_use_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>( | 118 in_use_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>( |
| 116 resource->size(), resource->format()); | 119 resource->size(), resource->format()); |
| 117 return resource; | 120 return resource; |
| 118 } | 121 } |
| 119 | 122 |
| 120 std::unique_ptr<PoolResource> pool_resource = | 123 std::unique_ptr<PoolResource> pool_resource = |
| 121 PoolResource::Create(resource_provider_); | 124 PoolResource::Create(resource_provider_); |
| 122 | 125 |
| 123 if (use_gpu_memory_buffers_) { | 126 if (use_gpu_memory_buffers_) { |
| 124 pool_resource->AllocateWithGpuMemoryBuffer(size, format, usage_); | 127 pool_resource->AllocateWithGpuMemoryBuffer(size, format, usage_, |
| 128 color_space); |
| 125 } else { | 129 } else { |
| 126 pool_resource->Allocate(size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, | 130 pool_resource->Allocate(size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, |
| 127 format); | 131 format, color_space); |
| 128 } | 132 } |
| 129 | 133 |
| 130 DCHECK(ResourceUtil::VerifySizeInBytes<size_t>(pool_resource->size(), | 134 DCHECK(ResourceUtil::VerifySizeInBytes<size_t>(pool_resource->size(), |
| 131 pool_resource->format())); | 135 pool_resource->format())); |
| 132 total_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>( | 136 total_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>( |
| 133 pool_resource->size(), pool_resource->format()); | 137 pool_resource->size(), pool_resource->format()); |
| 134 ++total_resource_count_; | 138 ++total_resource_count_; |
| 135 | 139 |
| 136 // Clear the invalidated rect and content ID, as we are about to raster new | 140 // Clear the invalidated rect and content ID, as we are about to raster new |
| 137 // content. These will be re-set when rasterization completes successfully. | 141 // content. These will be re-set when rasterization completes successfully. |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 for (const auto& resource : busy_resources_) { | 436 for (const auto& resource : busy_resources_) { |
| 433 resource->OnMemoryDump(pmd, resource_provider_, false /* is_free */); | 437 resource->OnMemoryDump(pmd, resource_provider_, false /* is_free */); |
| 434 } | 438 } |
| 435 for (const auto& entry : in_use_resources_) { | 439 for (const auto& entry : in_use_resources_) { |
| 436 entry.second->OnMemoryDump(pmd, resource_provider_, false /* is_free */); | 440 entry.second->OnMemoryDump(pmd, resource_provider_, false /* is_free */); |
| 437 } | 441 } |
| 438 return true; | 442 return true; |
| 439 } | 443 } |
| 440 | 444 |
| 441 } // namespace cc | 445 } // namespace cc |
| OLD | NEW |