Index: cc/resources/resource_pool.h |
diff --git a/cc/resources/resource_pool.h b/cc/resources/resource_pool.h |
index 20a66f06a4f964ef049f9a9d7060e9ef2cb047ae..c1db254e052e78627fdcb791aa01f528a69b1177 100644 |
--- a/cc/resources/resource_pool.h |
+++ b/cc/resources/resource_pool.h |
@@ -21,13 +21,20 @@ namespace cc { |
class CC_EXPORT ResourcePool : public base::trace_event::MemoryDumpProvider { |
public: |
- static scoped_ptr<ResourcePool> Create(ResourceProvider* resource_provider) { |
- return make_scoped_ptr(new ResourcePool(resource_provider)); |
+ static scoped_ptr<ResourcePool> Create( |
+ ResourceProvider* resource_provider, |
+ base::SingleThreadTaskRunner* task_runner) { |
+ return make_scoped_ptr( |
+ new ResourcePool(resource_provider, task_runner, 0 /* target */)); |
} |
- static scoped_ptr<ResourcePool> Create(ResourceProvider* resource_provider, |
- GLenum target) { |
- return make_scoped_ptr(new ResourcePool(resource_provider, target)); |
+ static scoped_ptr<ResourcePool> Create( |
+ ResourceProvider* resource_provider, |
+ base::SingleThreadTaskRunner* task_runner, |
+ GLenum target) { |
+ DCHECK_NE(0u, target); |
+ return make_scoped_ptr( |
+ new ResourcePool(resource_provider, task_runner, target)); |
} |
~ResourcePool() override; |
@@ -37,29 +44,35 @@ class CC_EXPORT ResourcePool : public base::trace_event::MemoryDumpProvider { |
void ReleaseResource(Resource* resource, uint64_t content_id); |
void SetResourceUsageLimits(size_t max_memory_usage_bytes, |
- size_t max_unused_memory_usage_bytes, |
size_t max_resource_count); |
void ReduceResourceUsage(); |
void CheckBusyResources(); |
- size_t total_memory_usage_bytes() const { return memory_usage_bytes_; } |
- size_t acquired_memory_usage_bytes() const { |
- return memory_usage_bytes_ - unused_memory_usage_bytes_; |
- } |
- size_t total_resource_count() const { return resource_count_; } |
- size_t acquired_resource_count() const { |
- return resource_count_ - unused_resources_.size(); |
- } |
- size_t busy_resource_count() const { return busy_resources_.size(); } |
+ size_t memory_usage_bytes() const { return in_use_memory_usage_bytes_; } |
+ size_t resource_count() const { return in_use_resources_.size(); } |
// Overridden from base::trace_event::MemoryDumpProvider: |
bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, |
base::trace_event::ProcessMemoryDump* pmd) override; |
+ size_t GetTotalMemoryUsageForTesting() const { |
+ return total_memory_usage_bytes_; |
+ } |
+ size_t GetTotalResourceCountForTesting() const { |
+ return total_resource_count_; |
+ } |
+ size_t GetBusyResourceCountForTesting() const { |
+ return busy_resources_.size(); |
+ } |
+ void SetResourceExpirationDelayForTesting(base::TimeDelta delay) { |
+ resource_expiration_delay_ = delay; |
+ } |
+ |
protected: |
- explicit ResourcePool(ResourceProvider* resource_provider); |
- ResourcePool(ResourceProvider* resource_provider, GLenum target); |
+ ResourcePool(ResourceProvider* resource_provider, |
+ base::SingleThreadTaskRunner* task_runner, |
+ GLenum target); |
bool ResourceUsageTooHigh(); |
@@ -77,23 +90,33 @@ class CC_EXPORT ResourcePool : public base::trace_event::MemoryDumpProvider { |
uint64_t content_id() const { return content_id_; } |
void set_content_id(uint64_t content_id) { content_id_ = content_id; } |
+ base::TimeTicks last_usage() const { return last_usage_; } |
+ void set_last_usage(base::TimeTicks time) { last_usage_ = time; } |
+ |
private: |
explicit PoolResource(ResourceProvider* resource_provider) |
: ScopedResource(resource_provider), content_id_(0) {} |
uint64_t content_id_; |
+ base::TimeTicks last_usage_; |
}; |
void DidFinishUsingResource(scoped_ptr<PoolResource> resource); |
void DeleteResource(scoped_ptr<PoolResource> resource); |
+ // Functions which manage periodic eviction of expired resources. |
+ void ScheduleEvictExpiredResourcesIn(base::TimeDelta time_from_now); |
+ void EvictExpiredResources(); |
+ void EvictResourcesNotUsedSince(base::TimeTicks time_limit); |
+ bool HasEvictableResources() const; |
+ base::TimeTicks GetUsageTimeForLRUResource() const; |
+ |
ResourceProvider* resource_provider_; |
const GLenum target_; |
size_t max_memory_usage_bytes_; |
- size_t max_unused_memory_usage_bytes_; |
size_t max_resource_count_; |
- size_t memory_usage_bytes_; |
- size_t unused_memory_usage_bytes_; |
- size_t resource_count_; |
+ size_t in_use_memory_usage_bytes_; |
+ size_t total_memory_usage_bytes_; |
+ size_t total_resource_count_; |
using ResourceDeque = ScopedPtrDeque<PoolResource>; |
ResourceDeque unused_resources_; |
@@ -102,6 +125,12 @@ class CC_EXPORT ResourcePool : public base::trace_event::MemoryDumpProvider { |
using ResourceMap = base::ScopedPtrMap<ResourceId, scoped_ptr<PoolResource>>; |
ResourceMap in_use_resources_; |
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
+ bool evict_expired_resources_pending_; |
+ base::TimeDelta resource_expiration_delay_; |
+ |
+ base::WeakPtrFactory<ResourcePool> weak_ptr_factory_; |
+ |
DISALLOW_COPY_AND_ASSIGN(ResourcePool); |
}; |