Chromium Code Reviews| 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 "cc/resources/resource_provider.h" | 7 #include "cc/resources/resource_provider.h" |
| 8 | 8 |
| 9 namespace cc { | 9 namespace cc { |
| 10 | 10 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 41 ResourcePool::~ResourcePool() { | 41 ResourcePool::~ResourcePool() { |
| 42 SetResourceUsageLimits(0, 0, 0); | 42 SetResourceUsageLimits(0, 0, 0); |
| 43 } | 43 } |
| 44 | 44 |
| 45 scoped_ptr<ResourcePool::Resource> ResourcePool::AcquireResource( | 45 scoped_ptr<ResourcePool::Resource> ResourcePool::AcquireResource( |
| 46 gfx::Size size, ResourceFormat format) { | 46 gfx::Size size, ResourceFormat format) { |
| 47 for (ResourceList::iterator it = unused_resources_.begin(); | 47 for (ResourceList::iterator it = unused_resources_.begin(); |
| 48 it != unused_resources_.end(); ++it) { | 48 it != unused_resources_.end(); ++it) { |
| 49 Resource* resource = *it; | 49 Resource* resource = *it; |
| 50 | 50 |
| 51 if (!resource_provider_->CanLockForWrite(resource->id())) | 51 if (!resource_provider_->CanLockForWrite(resource->id())) |
|
reveman
2013/10/30 14:56:02
Do we still need this? What's the difference betwe
piman
2013/10/30 19:35:30
There's stronger things needed for CanLockForWrite
reveman
2013/10/30 21:10:28
Ok, thanks for explaining. Is there a reason we ne
piman
2013/10/30 21:41:12
My take is that from what we control in Chrome, th
| |
| 52 continue; | 52 continue; |
| 53 if (resource->size() != size) | 53 if (resource->size() != size) |
| 54 continue; | 54 continue; |
| 55 if (resource->format() != format) | 55 if (resource->format() != format) |
| 56 continue; | 56 continue; |
| 57 | 57 |
| 58 unused_resources_.erase(it); | 58 unused_resources_.erase(it); |
| 59 unused_memory_usage_bytes_ -= resource->bytes(); | 59 unused_memory_usage_bytes_ -= resource->bytes(); |
| 60 return make_scoped_ptr(resource); | 60 return make_scoped_ptr(resource); |
| 61 } | 61 } |
| 62 | 62 |
| 63 // Create new resource. | 63 // Create new resource. |
| 64 Resource* resource = new Resource(resource_provider_, size, format); | 64 Resource* resource = new Resource(resource_provider_, size, format); |
| 65 | 65 |
| 66 // Extend all read locks on all resources until the resource is | 66 // Extend all read locks on all resources until the resource is |
| 67 // finished being used, such that we know when resources are | 67 // finished being used, such that we know when resources are |
| 68 // truly safe to recycle. | 68 // truly safe to recycle. |
| 69 resource_provider_->EnableReadLockFences(resource->id(), true); | 69 resource_provider_->EnableReadLockFences(resource->id(), true); |
| 70 | 70 |
| 71 memory_usage_bytes_ += resource->bytes(); | 71 memory_usage_bytes_ += resource->bytes(); |
| 72 ++resource_count_; | 72 ++resource_count_; |
| 73 return make_scoped_ptr(resource); | 73 return make_scoped_ptr(resource); |
| 74 } | 74 } |
| 75 | 75 |
| 76 void ResourcePool::ReleaseResource( | 76 void ResourcePool::ReleaseResource( |
| 77 scoped_ptr<ResourcePool::Resource> resource) { | 77 scoped_ptr<ResourcePool::Resource> resource) { |
| 78 if (ResourceUsageTooHigh()) { | 78 if (ResourceUsageTooHigh()) { |
| 79 memory_usage_bytes_ -= resource->bytes(); | 79 memory_usage_bytes_ -= resource->bytes(); |
| 80 --resource_count_; | 80 --resource_count_; |
| 81 return; | 81 return; |
|
reveman
2013/10/30 14:56:02
This destroys the resource. Are we allowed to do t
piman
2013/10/30 19:35:30
It's absolutely legal (the RP holds on to the text
reveman
2013/10/30 21:10:28
Got it. I don't think we should be freeing the mem
jadahl
2013/10/31 08:38:42
How about deleting resources where |lock_for_read_
danakj
2013/10/31 17:27:52
Generally we should lock resources only while they
reveman
2013/10/31 19:41:49
The read locks are supposed to protect against usa
| |
| 82 } | 82 } |
| 83 | 83 |
| 84 unused_memory_usage_bytes_ += resource->bytes(); | 84 unused_memory_usage_bytes_ += resource->bytes(); |
|
reveman
2013/10/31 19:41:49
This needs to be moved to CheckConsumedResources()
| |
| 85 unused_resources_.push_back(resource.release()); | 85 |
| 86 if (resource_provider_->InUseByConsumer(resource->id())) | |
|
reveman
2013/10/30 14:56:02
Can we remove this check and always add released r
danakj
2013/10/30 15:12:40
Yes you can RP holds onto it until it comes back f
reveman
2013/10/30 18:50:47
I assume this is a reply to the above comment abou
jadahl
2013/10/31 08:38:42
As far as I can see, this should be fine, as we al
reveman
2013/10/31 19:41:49
Yes, let's remove the ResourceUsageTooHigh() code
| |
| 87 consumed_resources_.push_back(resource.release()); | |
| 88 else | |
| 89 unused_resources_.push_back(resource.release()); | |
| 86 } | 90 } |
| 87 | 91 |
| 88 void ResourcePool::SetResourceUsageLimits( | 92 void ResourcePool::SetResourceUsageLimits( |
| 89 size_t max_memory_usage_bytes, | 93 size_t max_memory_usage_bytes, |
| 90 size_t max_unused_memory_usage_bytes, | 94 size_t max_unused_memory_usage_bytes, |
| 91 size_t max_resource_count) { | 95 size_t max_resource_count) { |
| 92 max_memory_usage_bytes_ = max_memory_usage_bytes; | 96 max_memory_usage_bytes_ = max_memory_usage_bytes; |
| 93 max_unused_memory_usage_bytes_ = max_unused_memory_usage_bytes; | 97 max_unused_memory_usage_bytes_ = max_unused_memory_usage_bytes; |
| 94 max_resource_count_ = max_resource_count; | 98 max_resource_count_ = max_resource_count; |
| 95 | 99 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 120 bool ResourcePool::ResourceUsageTooHigh() { | 124 bool ResourcePool::ResourceUsageTooHigh() { |
| 121 if (resource_count_ > max_resource_count_) | 125 if (resource_count_ > max_resource_count_) |
| 122 return true; | 126 return true; |
| 123 if (memory_usage_bytes_ > max_memory_usage_bytes_) | 127 if (memory_usage_bytes_ > max_memory_usage_bytes_) |
| 124 return true; | 128 return true; |
| 125 if (unused_memory_usage_bytes_ > max_unused_memory_usage_bytes_) | 129 if (unused_memory_usage_bytes_ > max_unused_memory_usage_bytes_) |
| 126 return true; | 130 return true; |
| 127 return false; | 131 return false; |
| 128 } | 132 } |
| 129 | 133 |
| 134 void ResourcePool::CheckConsumedResources() { | |
| 135 ResourceList::iterator it = consumed_resources_.begin(); | |
| 136 while (it != consumed_resources_.end()) { | |
|
reveman
2013/10/30 14:56:02
nit: consider using a temporary "Resource* resourc
| |
| 137 if (!resource_provider_->InUseByConsumer((*it)->id())) { | |
| 138 unused_resources_.push_back(*it); | |
| 139 it = consumed_resources_.erase(it); | |
| 140 } else { | |
| 141 ++it; | |
| 142 } | |
| 143 } | |
| 144 } | |
| 145 | |
| 130 } // namespace cc | 146 } // namespace cc |
| OLD | NEW |