| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <deque> | 11 #include <deque> |
| 12 #include <map> | 12 #include <map> |
| 13 #include <memory> | 13 #include <memory> |
| 14 | 14 |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
| 17 #include "base/trace_event/memory_dump_provider.h" | 17 #include "base/trace_event/memory_dump_provider.h" |
| 18 #include "cc/base/cc_export.h" | 18 #include "cc/base/cc_export.h" |
| 19 #include "cc/resources/resource.h" | 19 #include "cc/resources/resource.h" |
| 20 #include "cc/resources/resource_format.h" | 20 #include "cc/resources/resource_format.h" |
| 21 #include "cc/resources/scoped_resource.h" | 21 #include "cc/resources/scoped_resource.h" |
| 22 #include "components/memory_coordinator/common/memory_coordinator_client.h" |
| 22 | 23 |
| 23 namespace cc { | 24 namespace cc { |
| 24 | 25 |
| 25 class CC_EXPORT ResourcePool : public base::trace_event::MemoryDumpProvider { | 26 class CC_EXPORT ResourcePool |
| 27 : public base::trace_event::MemoryDumpProvider, |
| 28 public memory_coordinator::MemoryCoordinatorClient { |
| 26 public: | 29 public: |
| 27 // Delay before a resource is considered expired. | 30 // Delay before a resource is considered expired. |
| 28 static base::TimeDelta kDefaultExpirationDelay; | 31 static base::TimeDelta kDefaultExpirationDelay; |
| 29 | 32 |
| 30 static std::unique_ptr<ResourcePool> CreateForGpuMemoryBufferResources( | 33 static std::unique_ptr<ResourcePool> CreateForGpuMemoryBufferResources( |
| 31 ResourceProvider* resource_provider, | 34 ResourceProvider* resource_provider, |
| 32 base::SingleThreadTaskRunner* task_runner, | 35 base::SingleThreadTaskRunner* task_runner, |
| 33 gfx::BufferUsage usage, | 36 gfx::BufferUsage usage, |
| 34 const base::TimeDelta& expiration_delay) { | 37 const base::TimeDelta& expiration_delay) { |
| 35 std::unique_ptr<ResourcePool> pool(new ResourcePool( | 38 std::unique_ptr<ResourcePool> pool(new ResourcePool( |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 uint64_t new_content_id, | 152 uint64_t new_content_id, |
| 150 const gfx::Rect& new_invalidated_rect); | 153 const gfx::Rect& new_invalidated_rect); |
| 151 | 154 |
| 152 // Functions which manage periodic eviction of expired resources. | 155 // Functions which manage periodic eviction of expired resources. |
| 153 void ScheduleEvictExpiredResourcesIn(base::TimeDelta time_from_now); | 156 void ScheduleEvictExpiredResourcesIn(base::TimeDelta time_from_now); |
| 154 void EvictExpiredResources(); | 157 void EvictExpiredResources(); |
| 155 void EvictResourcesNotUsedSince(base::TimeTicks time_limit); | 158 void EvictResourcesNotUsedSince(base::TimeTicks time_limit); |
| 156 bool HasEvictableResources() const; | 159 bool HasEvictableResources() const; |
| 157 base::TimeTicks GetUsageTimeForLRUResource() const; | 160 base::TimeTicks GetUsageTimeForLRUResource() const; |
| 158 | 161 |
| 162 // Overriden from memory_coordinator::MemoryCoordinatorClient. |
| 163 void OnMemoryStateChange( |
| 164 memory_coordinator::mojom::MemoryState state) override; |
| 165 |
| 159 ResourceProvider* resource_provider_; | 166 ResourceProvider* resource_provider_; |
| 160 bool use_gpu_memory_buffers_; | 167 bool use_gpu_memory_buffers_; |
| 161 gfx::BufferUsage usage_; | 168 gfx::BufferUsage usage_; |
| 162 size_t max_memory_usage_bytes_; | 169 size_t max_memory_usage_bytes_; |
| 163 size_t max_resource_count_; | 170 size_t max_resource_count_; |
| 164 size_t in_use_memory_usage_bytes_; | 171 size_t in_use_memory_usage_bytes_; |
| 165 size_t total_memory_usage_bytes_; | 172 size_t total_memory_usage_bytes_; |
| 166 size_t total_resource_count_; | 173 size_t total_resource_count_; |
| 167 | 174 |
| 168 // Holds most recently used resources at the front of the queue. | 175 // Holds most recently used resources at the front of the queue. |
| 169 using ResourceDeque = std::deque<std::unique_ptr<PoolResource>>; | 176 using ResourceDeque = std::deque<std::unique_ptr<PoolResource>>; |
| 170 ResourceDeque unused_resources_; | 177 ResourceDeque unused_resources_; |
| 171 ResourceDeque busy_resources_; | 178 ResourceDeque busy_resources_; |
| 172 | 179 |
| 173 using InUseResourceMap = std::map<ResourceId, std::unique_ptr<PoolResource>>; | 180 using InUseResourceMap = std::map<ResourceId, std::unique_ptr<PoolResource>>; |
| 174 InUseResourceMap in_use_resources_; | 181 InUseResourceMap in_use_resources_; |
| 175 | 182 |
| 176 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 183 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 177 bool evict_expired_resources_pending_; | 184 bool evict_expired_resources_pending_; |
| 178 const base::TimeDelta resource_expiration_delay_; | 185 const base::TimeDelta resource_expiration_delay_; |
| 179 | 186 |
| 180 base::WeakPtrFactory<ResourcePool> weak_ptr_factory_; | 187 base::WeakPtrFactory<ResourcePool> weak_ptr_factory_; |
| 181 | 188 |
| 182 DISALLOW_COPY_AND_ASSIGN(ResourcePool); | 189 DISALLOW_COPY_AND_ASSIGN(ResourcePool); |
| 183 }; | 190 }; |
| 184 | 191 |
| 185 } // namespace cc | 192 } // namespace cc |
| 186 | 193 |
| 187 #endif // CC_RESOURCES_RESOURCE_POOL_H_ | 194 #endif // CC_RESOURCES_RESOURCE_POOL_H_ |
| OLD | NEW |