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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 DidFinishUsingResource(PopBack(&busy_resources_)); | 83 DidFinishUsingResource(PopBack(&busy_resources_)); |
84 } | 84 } |
85 | 85 |
86 SetResourceUsageLimits(0, 0); | 86 SetResourceUsageLimits(0, 0); |
87 DCHECK_EQ(0u, unused_resources_.size()); | 87 DCHECK_EQ(0u, unused_resources_.size()); |
88 DCHECK_EQ(0u, in_use_memory_usage_bytes_); | 88 DCHECK_EQ(0u, in_use_memory_usage_bytes_); |
89 DCHECK_EQ(0u, total_memory_usage_bytes_); | 89 DCHECK_EQ(0u, total_memory_usage_bytes_); |
90 DCHECK_EQ(0u, total_resource_count_); | 90 DCHECK_EQ(0u, total_resource_count_); |
91 } | 91 } |
92 | 92 |
93 Resource* ResourcePool::AcquireResource(const gfx::Size& size, | 93 Resource* ResourcePool::AcquireResource(const gfx::Size& desired_size, |
94 ResourceFormat format) { | 94 ResourceFormat format) { |
| 95 gfx::Size size = desired_size; |
| 96 if (IsResourceFormatCompressed(format) && |
| 97 (size.width() % 4 != 0 || size.height() % 4 != 0)) { |
| 98 // Round the size up to the nearest multiple of four. |
| 99 size.SetSize(4 * std::ceil(static_cast<float>(size.width()) / 4), |
| 100 4 * std::ceil(static_cast<float>(size.height()) / 4)); |
| 101 } |
| 102 |
95 // Finding resources in |unused_resources_| from MRU to LRU direction, touches | 103 // Finding resources in |unused_resources_| from MRU to LRU direction, touches |
96 // LRU resources only if needed, which increases possibility of expiring more | 104 // LRU resources only if needed, which increases possibility of expiring more |
97 // LRU resources within kResourceExpirationDelayMs. | 105 // LRU resources within kResourceExpirationDelayMs. |
98 for (ResourceDeque::iterator it = unused_resources_.begin(); | 106 for (ResourceDeque::iterator it = unused_resources_.begin(); |
99 it != unused_resources_.end(); ++it) { | 107 it != unused_resources_.end(); ++it) { |
100 ScopedResource* resource = it->get(); | 108 ScopedResource* resource = it->get(); |
101 DCHECK(resource_provider_->CanLockForWrite(resource->id())); | 109 DCHECK(resource_provider_->CanLockForWrite(resource->id())); |
102 | 110 |
103 if (resource->format() != format) | 111 if (resource->format() != format) |
104 continue; | 112 continue; |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 for (const auto& resource : busy_resources_) { | 318 for (const auto& resource : busy_resources_) { |
311 resource->OnMemoryDump(pmd, resource_provider_, false /* is_free */); | 319 resource->OnMemoryDump(pmd, resource_provider_, false /* is_free */); |
312 } | 320 } |
313 for (const auto& entry : in_use_resources_) { | 321 for (const auto& entry : in_use_resources_) { |
314 entry.second->OnMemoryDump(pmd, resource_provider_, false /* is_free */); | 322 entry.second->OnMemoryDump(pmd, resource_provider_, false /* is_free */); |
315 } | 323 } |
316 return true; | 324 return true; |
317 } | 325 } |
318 | 326 |
319 } // namespace cc | 327 } // namespace cc |
OLD | NEW |