OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CC_RESOURCES_RESOURCE_POOL_H_ |
| 6 #define CC_RESOURCES_RESOURCE_POOL_H_ |
| 7 |
| 8 #include <list> |
| 9 |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "cc/output/renderer.h" |
| 12 #include "cc/resources/resource.h" |
| 13 #include "cc/resources/resource_format.h" |
| 14 |
| 15 namespace cc { |
| 16 class ScopedResource; |
| 17 |
| 18 class ResourcePool { |
| 19 public: |
| 20 static scoped_ptr<ResourcePool> Create(ResourceProvider* resource_provider, |
| 21 GLenum target) { |
| 22 return make_scoped_ptr(new ResourcePool(resource_provider, target)); |
| 23 } |
| 24 |
| 25 virtual ~ResourcePool(); |
| 26 |
| 27 scoped_ptr<ScopedResource> AcquireResource(const gfx::Size& size, |
| 28 ResourceFormat format); |
| 29 void ReleaseResource(scoped_ptr<ScopedResource>); |
| 30 |
| 31 void SetResourceUsageLimits(size_t max_memory_usage_bytes, |
| 32 size_t max_unused_memory_usage_bytes, |
| 33 size_t max_resource_count); |
| 34 |
| 35 void ReduceResourceUsage(); |
| 36 // This might block if |wait_if_needed| is true and one of the currently |
| 37 // busy resources has a read lock fence that needs to be waited upon before |
| 38 // it can be locked for write again. |
| 39 void CheckBusyResources(bool wait_if_needed); |
| 40 |
| 41 size_t total_memory_usage_bytes() const { return memory_usage_bytes_; } |
| 42 size_t acquired_memory_usage_bytes() const { |
| 43 return memory_usage_bytes_ - unused_memory_usage_bytes_; |
| 44 } |
| 45 size_t total_resource_count() const { return resource_count_; } |
| 46 size_t acquired_resource_count() const { |
| 47 return resource_count_ - unused_resources_.size(); |
| 48 } |
| 49 size_t busy_resource_count() const { return busy_resources_.size(); } |
| 50 |
| 51 protected: |
| 52 ResourcePool(ResourceProvider* resource_provider, GLenum target); |
| 53 |
| 54 bool ResourceUsageTooHigh(); |
| 55 |
| 56 private: |
| 57 void DidFinishUsingResource(ScopedResource* resource); |
| 58 |
| 59 ResourceProvider* resource_provider_; |
| 60 const GLenum target_; |
| 61 size_t max_memory_usage_bytes_; |
| 62 size_t max_unused_memory_usage_bytes_; |
| 63 size_t max_resource_count_; |
| 64 size_t memory_usage_bytes_; |
| 65 size_t unused_memory_usage_bytes_; |
| 66 size_t resource_count_; |
| 67 |
| 68 typedef std::list<ScopedResource*> ResourceList; |
| 69 ResourceList unused_resources_; |
| 70 ResourceList busy_resources_; |
| 71 |
| 72 DISALLOW_COPY_AND_ASSIGN(ResourcePool); |
| 73 }; |
| 74 |
| 75 } // namespace cc |
| 76 |
| 77 #endif // CC_RESOURCES_RESOURCE_POOL_H_ |
OLD | NEW |