| 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 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 | 37 |
| 38 static std::unique_ptr<ResourcePool> Create( | 38 static std::unique_ptr<ResourcePool> Create( |
| 39 ResourceProvider* resource_provider, | 39 ResourceProvider* resource_provider, |
| 40 base::SingleThreadTaskRunner* task_runner) { | 40 base::SingleThreadTaskRunner* task_runner) { |
| 41 return base::WrapUnique( | 41 return base::WrapUnique( |
| 42 new ResourcePool(resource_provider, task_runner, false)); | 42 new ResourcePool(resource_provider, task_runner, false)); |
| 43 } | 43 } |
| 44 | 44 |
| 45 ~ResourcePool() override; | 45 ~ResourcePool() override; |
| 46 | 46 |
| 47 // Tries to reuse a resource. If none are available, makes a new one. |
| 47 Resource* AcquireResource(const gfx::Size& size, | 48 Resource* AcquireResource(const gfx::Size& size, |
| 48 ResourceFormat format, | 49 ResourceFormat format, |
| 49 const gfx::ColorSpace& color_space); | 50 const gfx::ColorSpace& color_space); |
| 50 | 51 |
| 51 // Tries to acquire the resource with |previous_content_id| for us in partial | 52 // Tries to acquire the resource with |previous_content_id| for us in partial |
| 52 // raster. If successful, this function will retun the invalidated rect which | 53 // raster. If successful, this function will retun the invalidated rect which |
| 53 // must be re-rastered in |total_invalidated_rect|. | 54 // must be re-rastered in |total_invalidated_rect|. |
| 54 Resource* TryAcquireResourceForPartialRaster( | 55 Resource* TryAcquireResourceForPartialRaster( |
| 55 uint64_t new_content_id, | 56 uint64_t new_content_id, |
| 56 const gfx::Rect& new_invalidated_rect, | 57 const gfx::Rect& new_invalidated_rect, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 } | 93 } |
| 93 | 94 |
| 94 protected: | 95 protected: |
| 95 ResourcePool(ResourceProvider* resource_provider, | 96 ResourcePool(ResourceProvider* resource_provider, |
| 96 base::SingleThreadTaskRunner* task_runner, | 97 base::SingleThreadTaskRunner* task_runner, |
| 97 bool use_gpu_memory_buffers); | 98 bool use_gpu_memory_buffers); |
| 98 | 99 |
| 99 bool ResourceUsageTooHigh(); | 100 bool ResourceUsageTooHigh(); |
| 100 | 101 |
| 101 private: | 102 private: |
| 103 FRIEND_TEST_ALL_PREFIXES(ResourcePoolTest, ReuseResource); |
| 102 class PoolResource : public ScopedResource { | 104 class PoolResource : public ScopedResource { |
| 103 public: | 105 public: |
| 104 static std::unique_ptr<PoolResource> Create( | 106 static std::unique_ptr<PoolResource> Create( |
| 105 ResourceProvider* resource_provider) { | 107 ResourceProvider* resource_provider) { |
| 106 return base::WrapUnique(new PoolResource(resource_provider)); | 108 return base::WrapUnique(new PoolResource(resource_provider)); |
| 107 } | 109 } |
| 108 void OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, | 110 void OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, |
| 109 const ResourceProvider* resource_provider, | 111 const ResourceProvider* resource_provider, |
| 110 bool is_free) const; | 112 bool is_free) const; |
| 111 | 113 |
| 112 uint64_t content_id() const { return content_id_; } | 114 uint64_t content_id() const { return content_id_; } |
| 113 void set_content_id(uint64_t content_id) { content_id_ = content_id; } | 115 void set_content_id(uint64_t content_id) { content_id_ = content_id; } |
| 114 | 116 |
| 115 base::TimeTicks last_usage() const { return last_usage_; } | 117 base::TimeTicks last_usage() const { return last_usage_; } |
| 116 void set_last_usage(base::TimeTicks time) { last_usage_ = time; } | 118 void set_last_usage(base::TimeTicks time) { last_usage_ = time; } |
| 117 | 119 |
| 118 gfx::Rect invalidated_rect() const { return invalidated_rect_; } | 120 gfx::Rect invalidated_rect() const { return invalidated_rect_; } |
| 119 void set_invalidated_rect(const gfx::Rect& invalidated_rect) { | 121 void set_invalidated_rect(const gfx::Rect& invalidated_rect) { |
| 120 invalidated_rect_ = invalidated_rect; | 122 invalidated_rect_ = invalidated_rect; |
| 121 } | 123 } |
| 122 | 124 |
| 123 private: | 125 private: |
| 124 explicit PoolResource(ResourceProvider* resource_provider) | 126 explicit PoolResource(ResourceProvider* resource_provider) |
| 125 : ScopedResource(resource_provider), content_id_(0) {} | 127 : ScopedResource(resource_provider), content_id_(0) {} |
| 126 uint64_t content_id_; | 128 uint64_t content_id_; |
| 127 base::TimeTicks last_usage_; | 129 base::TimeTicks last_usage_; |
| 128 gfx::Rect invalidated_rect_; | 130 gfx::Rect invalidated_rect_; |
| 129 }; | 131 }; |
| 130 | 132 |
| 133 // Tries to reuse a resource. Returns |nullptr| if none are available. |
| 134 Resource* ReuseResource(const gfx::Size& size, |
| 135 ResourceFormat format, |
| 136 const gfx::ColorSpace& color_space); |
| 137 |
| 138 // Creates a new resource without trying to reuse an old one. |
| 139 Resource* CreateResource(const gfx::Size& size, |
| 140 ResourceFormat format, |
| 141 const gfx::ColorSpace& color_space); |
| 142 |
| 131 void DidFinishUsingResource(std::unique_ptr<PoolResource> resource); | 143 void DidFinishUsingResource(std::unique_ptr<PoolResource> resource); |
| 132 void DeleteResource(std::unique_ptr<PoolResource> resource); | 144 void DeleteResource(std::unique_ptr<PoolResource> resource); |
| 133 static void UpdateResourceContentIdAndInvalidation( | 145 static void UpdateResourceContentIdAndInvalidation( |
| 134 PoolResource* resource, | 146 PoolResource* resource, |
| 135 uint64_t new_content_id, | 147 uint64_t new_content_id, |
| 136 const gfx::Rect& new_invalidated_rect); | 148 const gfx::Rect& new_invalidated_rect); |
| 137 | 149 |
| 138 // Functions which manage periodic eviction of expired resources. | 150 // Functions which manage periodic eviction of expired resources. |
| 139 void ScheduleEvictExpiredResourcesIn(base::TimeDelta time_from_now); | 151 void ScheduleEvictExpiredResourcesIn(base::TimeDelta time_from_now); |
| 140 void EvictExpiredResources(); | 152 void EvictExpiredResources(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 164 base::TimeDelta resource_expiration_delay_; | 176 base::TimeDelta resource_expiration_delay_; |
| 165 | 177 |
| 166 base::WeakPtrFactory<ResourcePool> weak_ptr_factory_; | 178 base::WeakPtrFactory<ResourcePool> weak_ptr_factory_; |
| 167 | 179 |
| 168 DISALLOW_COPY_AND_ASSIGN(ResourcePool); | 180 DISALLOW_COPY_AND_ASSIGN(ResourcePool); |
| 169 }; | 181 }; |
| 170 | 182 |
| 171 } // namespace cc | 183 } // namespace cc |
| 172 | 184 |
| 173 #endif // CC_RESOURCES_RESOURCE_POOL_H_ | 185 #endif // CC_RESOURCES_RESOURCE_POOL_H_ |
| OLD | NEW |