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 #include "cc/resources/scoped_resource.h" | 8 #include "cc/resources/scoped_resource.h" |
9 | 9 |
10 namespace cc { | 10 namespace cc { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 DCHECK(resource_provider_->CanLockForWrite(resource->id())); | 44 DCHECK(resource_provider_->CanLockForWrite(resource->id())); |
45 | 45 |
46 if (resource->size() != size) | 46 if (resource->size() != size) |
47 continue; | 47 continue; |
48 | 48 |
49 unused_resources_.erase(it); | 49 unused_resources_.erase(it); |
50 unused_memory_usage_bytes_ -= resource->bytes(); | 50 unused_memory_usage_bytes_ -= resource->bytes(); |
51 return make_scoped_ptr(resource); | 51 return make_scoped_ptr(resource); |
52 } | 52 } |
53 | 53 |
54 // Create new resource. | |
55 scoped_ptr<ScopedResource> resource = | 54 scoped_ptr<ScopedResource> resource = |
56 ScopedResource::Create(resource_provider_); | 55 ScopedResource::Create(resource_provider_); |
57 resource->AllocateManaged(size, target_, format_); | 56 resource->AllocateManaged(size, target_, format_); |
58 | 57 |
59 // Extend all read locks on all resources until the resource is | |
60 // finished being used, such that we know when resources are | |
61 // truly safe to recycle. | |
62 resource_provider_->EnableReadLockFences(resource->id(), true); | |
63 | |
64 memory_usage_bytes_ += resource->bytes(); | 58 memory_usage_bytes_ += resource->bytes(); |
65 ++resource_count_; | 59 ++resource_count_; |
66 return resource.Pass(); | 60 return resource.Pass(); |
67 } | 61 } |
68 | 62 |
69 void ResourcePool::ReleaseResource(scoped_ptr<ScopedResource> resource) { | 63 void ResourcePool::ReleaseResource(scoped_ptr<ScopedResource> resource) { |
70 busy_resources_.push_back(resource.release()); | 64 busy_resources_.push_back(resource.release()); |
71 } | 65 } |
72 | 66 |
73 void ResourcePool::SetResourceUsageLimits(size_t max_memory_usage_bytes, | 67 void ResourcePool::SetResourceUsageLimits(size_t max_memory_usage_bytes, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 } | 119 } |
126 } | 120 } |
127 } | 121 } |
128 | 122 |
129 void ResourcePool::DidFinishUsingResource(ScopedResource* resource) { | 123 void ResourcePool::DidFinishUsingResource(ScopedResource* resource) { |
130 unused_memory_usage_bytes_ += resource->bytes(); | 124 unused_memory_usage_bytes_ += resource->bytes(); |
131 unused_resources_.push_back(resource); | 125 unused_resources_.push_back(resource); |
132 } | 126 } |
133 | 127 |
134 } // namespace cc | 128 } // namespace cc |
OLD | NEW |