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 <deque> | 8 #include <deque> |
| 9 | 9 |
| 10 #include "base/containers/scoped_ptr_map.h" | 10 #include "base/containers/scoped_ptr_map.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/trace_event/memory_dump_provider.h" | 12 #include "base/trace_event/memory_dump_provider.h" |
| 13 #include "cc/base/cc_export.h" | 13 #include "cc/base/cc_export.h" |
| 14 #include "cc/base/scoped_ptr_deque.h" | 14 #include "cc/base/scoped_ptr_deque.h" |
| 15 #include "cc/output/renderer.h" | 15 #include "cc/output/renderer.h" |
| 16 #include "cc/resources/resource.h" | 16 #include "cc/resources/resource.h" |
| 17 #include "cc/resources/resource_format.h" | 17 #include "cc/resources/resource_format.h" |
| 18 #include "cc/resources/scoped_resource.h" | 18 #include "cc/resources/scoped_resource.h" |
| 19 | 19 |
| 20 namespace cc { | 20 namespace cc { |
| 21 | 21 |
| 22 class CC_EXPORT ResourcePool : public base::trace_event::MemoryDumpProvider { | 22 class CC_EXPORT ResourcePool : public base::trace_event::MemoryDumpProvider { |
| 23 public: | 23 public: |
| 24 static scoped_ptr<ResourcePool> CreateForImageTextureTarget( | |
|
reveman
2015/10/29 14:11:39
I think this change will break the ongoing work to
ccameron
2015/10/29 19:08:29
Is there a reason that the texture target selectio
reveman
2015/10/29 19:41:57
There are some plans to allocate resources on work
| |
| 25 ResourceProvider* resource_provider, | |
| 26 base::SingleThreadTaskRunner* task_runner) { | |
| 27 return make_scoped_ptr( | |
| 28 new ResourcePool(resource_provider, task_runner, true)); | |
| 29 } | |
| 30 | |
| 24 static scoped_ptr<ResourcePool> Create( | 31 static scoped_ptr<ResourcePool> Create( |
| 25 ResourceProvider* resource_provider, | 32 ResourceProvider* resource_provider, |
| 26 base::SingleThreadTaskRunner* task_runner) { | 33 base::SingleThreadTaskRunner* task_runner) { |
| 27 return make_scoped_ptr( | 34 return make_scoped_ptr( |
| 28 new ResourcePool(resource_provider, task_runner, 0 /* target */)); | 35 new ResourcePool(resource_provider, task_runner, false)); |
| 29 } | |
| 30 | |
| 31 static scoped_ptr<ResourcePool> Create( | |
| 32 ResourceProvider* resource_provider, | |
| 33 base::SingleThreadTaskRunner* task_runner, | |
| 34 GLenum target) { | |
| 35 DCHECK_NE(0u, target); | |
| 36 return make_scoped_ptr( | |
| 37 new ResourcePool(resource_provider, task_runner, target)); | |
| 38 } | 36 } |
| 39 | 37 |
| 40 ~ResourcePool() override; | 38 ~ResourcePool() override; |
| 41 | 39 |
| 42 Resource* AcquireResource(const gfx::Size& size, ResourceFormat format); | 40 Resource* AcquireResource(const gfx::Size& size, ResourceFormat format); |
| 43 Resource* TryAcquireResourceWithContentId(uint64 content_id); | 41 Resource* TryAcquireResourceWithContentId(uint64 content_id); |
| 44 void ReleaseResource(Resource* resource, uint64_t content_id); | 42 void ReleaseResource(Resource* resource, uint64_t content_id); |
| 45 | 43 |
| 46 void SetResourceUsageLimits(size_t max_memory_usage_bytes, | 44 void SetResourceUsageLimits(size_t max_memory_usage_bytes, |
| 47 size_t max_resource_count); | 45 size_t max_resource_count); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 65 size_t GetBusyResourceCountForTesting() const { | 63 size_t GetBusyResourceCountForTesting() const { |
| 66 return busy_resources_.size(); | 64 return busy_resources_.size(); |
| 67 } | 65 } |
| 68 void SetResourceExpirationDelayForTesting(base::TimeDelta delay) { | 66 void SetResourceExpirationDelayForTesting(base::TimeDelta delay) { |
| 69 resource_expiration_delay_ = delay; | 67 resource_expiration_delay_ = delay; |
| 70 } | 68 } |
| 71 | 69 |
| 72 protected: | 70 protected: |
| 73 ResourcePool(ResourceProvider* resource_provider, | 71 ResourcePool(ResourceProvider* resource_provider, |
| 74 base::SingleThreadTaskRunner* task_runner, | 72 base::SingleThreadTaskRunner* task_runner, |
| 75 GLenum target); | 73 bool use_image_texture_target); |
| 76 | 74 |
| 77 bool ResourceUsageTooHigh(); | 75 bool ResourceUsageTooHigh(); |
| 78 | 76 |
| 79 private: | 77 private: |
| 80 class PoolResource : public ScopedResource { | 78 class PoolResource : public ScopedResource { |
| 81 public: | 79 public: |
| 82 static scoped_ptr<PoolResource> Create( | 80 static scoped_ptr<PoolResource> Create( |
| 83 ResourceProvider* resource_provider) { | 81 ResourceProvider* resource_provider) { |
| 84 return make_scoped_ptr(new PoolResource(resource_provider)); | 82 return make_scoped_ptr(new PoolResource(resource_provider)); |
| 85 } | 83 } |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 104 void DeleteResource(scoped_ptr<PoolResource> resource); | 102 void DeleteResource(scoped_ptr<PoolResource> resource); |
| 105 | 103 |
| 106 // Functions which manage periodic eviction of expired resources. | 104 // Functions which manage periodic eviction of expired resources. |
| 107 void ScheduleEvictExpiredResourcesIn(base::TimeDelta time_from_now); | 105 void ScheduleEvictExpiredResourcesIn(base::TimeDelta time_from_now); |
| 108 void EvictExpiredResources(); | 106 void EvictExpiredResources(); |
| 109 void EvictResourcesNotUsedSince(base::TimeTicks time_limit); | 107 void EvictResourcesNotUsedSince(base::TimeTicks time_limit); |
| 110 bool HasEvictableResources() const; | 108 bool HasEvictableResources() const; |
| 111 base::TimeTicks GetUsageTimeForLRUResource() const; | 109 base::TimeTicks GetUsageTimeForLRUResource() const; |
| 112 | 110 |
| 113 ResourceProvider* resource_provider_; | 111 ResourceProvider* resource_provider_; |
| 114 const GLenum target_; | 112 bool use_image_texture_target_; |
| 115 size_t max_memory_usage_bytes_; | 113 size_t max_memory_usage_bytes_; |
| 116 size_t max_resource_count_; | 114 size_t max_resource_count_; |
| 117 size_t in_use_memory_usage_bytes_; | 115 size_t in_use_memory_usage_bytes_; |
| 118 size_t total_memory_usage_bytes_; | 116 size_t total_memory_usage_bytes_; |
| 119 size_t total_resource_count_; | 117 size_t total_resource_count_; |
| 120 | 118 |
| 121 using ResourceDeque = ScopedPtrDeque<PoolResource>; | 119 using ResourceDeque = ScopedPtrDeque<PoolResource>; |
| 122 ResourceDeque unused_resources_; | 120 ResourceDeque unused_resources_; |
| 123 ResourceDeque busy_resources_; | 121 ResourceDeque busy_resources_; |
| 124 | 122 |
| 125 using ResourceMap = base::ScopedPtrMap<ResourceId, scoped_ptr<PoolResource>>; | 123 using ResourceMap = base::ScopedPtrMap<ResourceId, scoped_ptr<PoolResource>>; |
| 126 ResourceMap in_use_resources_; | 124 ResourceMap in_use_resources_; |
| 127 | 125 |
| 128 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 126 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 129 bool evict_expired_resources_pending_; | 127 bool evict_expired_resources_pending_; |
| 130 base::TimeDelta resource_expiration_delay_; | 128 base::TimeDelta resource_expiration_delay_; |
| 131 | 129 |
| 132 base::WeakPtrFactory<ResourcePool> weak_ptr_factory_; | 130 base::WeakPtrFactory<ResourcePool> weak_ptr_factory_; |
| 133 | 131 |
| 134 DISALLOW_COPY_AND_ASSIGN(ResourcePool); | 132 DISALLOW_COPY_AND_ASSIGN(ResourcePool); |
| 135 }; | 133 }; |
| 136 | 134 |
| 137 } // namespace cc | 135 } // namespace cc |
| 138 | 136 |
| 139 #endif // CC_RESOURCES_RESOURCE_POOL_H_ | 137 #endif // CC_RESOURCES_RESOURCE_POOL_H_ |
| OLD | NEW |