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 #ifndef CC_RESOURCES_RESOURCE_POOL_H_ | 5 #ifndef CC_RESOURCES_RESOURCE_POOL_H_ |
| 6 #define CC_RESOURCES_RESOURCE_POOL_H_ | 6 #define CC_RESOURCES_RESOURCE_POOL_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <map> | |
| 9 | 10 |
| 10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 11 #include "cc/base/cc_export.h" | 12 #include "cc/base/cc_export.h" |
| 12 #include "cc/output/renderer.h" | 13 #include "cc/output/renderer.h" |
| 13 #include "cc/resources/resource.h" | 14 #include "cc/resources/resource.h" |
| 14 #include "cc/resources/resource_format.h" | 15 #include "cc/resources/resource_format.h" |
| 15 | 16 |
| 16 namespace cc { | 17 namespace cc { |
| 17 class ScopedResource; | 18 class ScopedResource; |
| 18 | 19 |
| 19 class CC_EXPORT ResourcePool { | 20 class CC_EXPORT ResourcePool { |
| 20 public: | 21 public: |
| 21 static scoped_ptr<ResourcePool> Create(ResourceProvider* resource_provider, | 22 static scoped_ptr<ResourcePool> Create(ResourceProvider* resource_provider, |
| 22 GLenum target, | 23 GLenum target, |
| 23 ResourceFormat format) { | 24 bool use_memory_efficient_format) { |
|
reveman
2015/01/13 16:25:55
does the resource pool need to know about use_memo
peterp
2015/01/14 12:33:36
The problem then is that when the tile manager ask
| |
| 24 return make_scoped_ptr(new ResourcePool(resource_provider, target, format)); | 25 return make_scoped_ptr(new ResourcePool(resource_provider, |
| 26 target, | |
| 27 use_memory_efficient_format)); | |
| 25 } | 28 } |
| 26 | 29 |
| 27 virtual ~ResourcePool(); | 30 virtual ~ResourcePool(); |
| 28 | 31 |
| 29 scoped_ptr<ScopedResource> AcquireResource(const gfx::Size& size); | 32 scoped_ptr<ScopedResource> AcquireResource(const gfx::Size& size, |
| 33 ResourceFormat format); | |
| 34 scoped_ptr<ScopedResource> AcquireResource(const gfx::Size& size, | |
| 35 ResourceFormatUsage usage); | |
| 30 void ReleaseResource(scoped_ptr<ScopedResource>); | 36 void ReleaseResource(scoped_ptr<ScopedResource>); |
| 31 | 37 |
| 32 void SetResourceUsageLimits(size_t max_memory_usage_bytes, | 38 void SetResourceUsageLimits(size_t max_memory_usage_bytes, |
| 33 size_t max_unused_memory_usage_bytes, | 39 size_t max_unused_memory_usage_bytes, |
| 34 size_t max_resource_count); | 40 size_t max_resource_count); |
| 35 | 41 |
| 36 void ReduceResourceUsage(); | 42 void ReduceResourceUsage(); |
| 37 // This might block if |wait_if_needed| is true and one of the currently | 43 // This might block if |wait_if_needed| is true and one of the currently |
| 38 // busy resources has a read lock fence that needs to be waited upon before | 44 // busy resources has a read lock fence that needs to be waited upon before |
| 39 // it can be locked for write again. | 45 // it can be locked for write again. |
| 40 void CheckBusyResources(bool wait_if_needed); | 46 void CheckBusyResources(bool wait_if_needed); |
| 41 | 47 |
| 42 size_t total_memory_usage_bytes() const { return memory_usage_bytes_; } | 48 size_t total_memory_usage_bytes() const { return memory_usage_bytes_; } |
| 43 size_t acquired_memory_usage_bytes() const { | 49 size_t acquired_memory_usage_bytes() const { |
| 44 return memory_usage_bytes_ - unused_memory_usage_bytes_; | 50 return memory_usage_bytes_ - unused_memory_usage_bytes_; |
| 45 } | 51 } |
| 46 size_t total_resource_count() const { return resource_count_; } | 52 size_t total_resource_count() const { return resource_count_; } |
| 47 size_t acquired_resource_count() const { | 53 size_t acquired_resource_count() const; |
| 48 return resource_count_ - unused_resources_.size(); | |
| 49 } | |
| 50 size_t busy_resource_count() const { return busy_resources_.size(); } | 54 size_t busy_resource_count() const { return busy_resources_.size(); } |
| 51 | 55 |
| 52 ResourceFormat resource_format() const { return format_; } | 56 ResourceFormat resource_format(ResourceFormatUsage usage) const; |
| 53 | 57 |
| 54 protected: | 58 protected: |
| 55 ResourcePool(ResourceProvider* resource_provider, | 59 ResourcePool(ResourceProvider* resource_provider, |
| 56 GLenum target, | 60 GLenum target, |
| 57 ResourceFormat format); | 61 bool use_memory_efficient_format); |
| 58 | 62 |
| 59 bool ResourceUsageTooHigh(); | 63 bool ResourceUsageTooHigh(); |
| 60 | 64 |
| 61 private: | 65 private: |
| 62 void DidFinishUsingResource(ScopedResource* resource); | 66 void DidFinishUsingResource(ScopedResource* resource); |
| 63 | 67 |
| 64 ResourceProvider* resource_provider_; | 68 ResourceProvider* resource_provider_; |
| 65 const GLenum target_; | 69 const GLenum target_; |
| 66 const ResourceFormat format_; | 70 bool use_memory_efficient_format_; |
| 67 size_t max_memory_usage_bytes_; | 71 size_t max_memory_usage_bytes_; |
| 68 size_t max_unused_memory_usage_bytes_; | 72 size_t max_unused_memory_usage_bytes_; |
| 69 size_t max_resource_count_; | 73 size_t max_resource_count_; |
| 70 size_t memory_usage_bytes_; | 74 size_t memory_usage_bytes_; |
| 71 size_t unused_memory_usage_bytes_; | 75 size_t unused_memory_usage_bytes_; |
| 72 size_t resource_count_; | 76 size_t resource_count_; |
| 73 | 77 |
| 74 typedef std::list<ScopedResource*> ResourceList; | 78 typedef std::list<ScopedResource*> ResourceList; |
| 75 ResourceList unused_resources_; | 79 typedef std::map<ResourceFormat, ResourceList> UnusedMap; |
|
reveman
2015/01/13 16:25:55
do we need a map for this? can we instead just che
peterp
2015/01/14 12:33:36
You're right, good point. Patch updated.
| |
| 80 UnusedMap unused_resources_; | |
| 76 ResourceList busy_resources_; | 81 ResourceList busy_resources_; |
| 77 | 82 |
| 78 DISALLOW_COPY_AND_ASSIGN(ResourcePool); | 83 DISALLOW_COPY_AND_ASSIGN(ResourcePool); |
| 79 }; | 84 }; |
| 80 | 85 |
| 81 } // namespace cc | 86 } // namespace cc |
| 82 | 87 |
| 83 #endif // CC_RESOURCES_RESOURCE_POOL_H_ | 88 #endif // CC_RESOURCES_RESOURCE_POOL_H_ |
| OLD | NEW |