Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Side by Side Diff: cc/resources/resource_pool.h

Issue 2726263003: cc::ResourcePool - Re-use larger resources for smaller requests (Closed)
Patch Set: fix compile Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/raster/one_copy_raster_buffer_provider.cc ('k') | cc/resources/resource_pool.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 15 matching lines...) Expand all
26 class CC_EXPORT ResourcePool : public base::trace_event::MemoryDumpProvider, 26 class CC_EXPORT ResourcePool : public base::trace_event::MemoryDumpProvider,
27 public base::MemoryCoordinatorClient { 27 public base::MemoryCoordinatorClient {
28 public: 28 public:
29 // Delay before a resource is considered expired. 29 // Delay before a resource is considered expired.
30 static base::TimeDelta kDefaultExpirationDelay; 30 static base::TimeDelta kDefaultExpirationDelay;
31 31
32 static std::unique_ptr<ResourcePool> CreateForGpuMemoryBufferResources( 32 static std::unique_ptr<ResourcePool> CreateForGpuMemoryBufferResources(
33 ResourceProvider* resource_provider, 33 ResourceProvider* resource_provider,
34 base::SingleThreadTaskRunner* task_runner, 34 base::SingleThreadTaskRunner* task_runner,
35 gfx::BufferUsage usage, 35 gfx::BufferUsage usage,
36 const base::TimeDelta& expiration_delay) { 36 const base::TimeDelta& expiration_delay,
37 bool disallow_non_exact_reuse) {
37 return base::WrapUnique(new ResourcePool(resource_provider, task_runner, 38 return base::WrapUnique(new ResourcePool(resource_provider, task_runner,
38 usage, expiration_delay)); 39 usage, expiration_delay,
40 disallow_non_exact_reuse));
39 } 41 }
40 42
41 static std::unique_ptr<ResourcePool> Create( 43 static std::unique_ptr<ResourcePool> Create(
42 ResourceProvider* resource_provider, 44 ResourceProvider* resource_provider,
43 base::SingleThreadTaskRunner* task_runner, 45 base::SingleThreadTaskRunner* task_runner,
44 ResourceProvider::TextureHint hint, 46 ResourceProvider::TextureHint hint,
45 const base::TimeDelta& expiration_delay) { 47 const base::TimeDelta& expiration_delay,
48 bool disallow_non_exact_reuse) {
46 return base::WrapUnique(new ResourcePool(resource_provider, task_runner, 49 return base::WrapUnique(new ResourcePool(resource_provider, task_runner,
47 hint, expiration_delay)); 50 hint, expiration_delay,
51 disallow_non_exact_reuse));
48 } 52 }
49 53
50 ~ResourcePool() override; 54 ~ResourcePool() override;
51 55
52 // Tries to reuse a resource. If none are available, makes a new one. 56 // Tries to reuse a resource. If none are available, makes a new one.
53 Resource* AcquireResource(const gfx::Size& size, 57 Resource* AcquireResource(const gfx::Size& size,
54 ResourceFormat format, 58 ResourceFormat format,
55 const gfx::ColorSpace& color_space); 59 const gfx::ColorSpace& color_space);
56 60
57 // Tries to acquire the resource with |previous_content_id| for us in partial 61 // Tries to acquire the resource with |previous_content_id| for us in partial
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 } 99 }
96 size_t GetBusyResourceCountForTesting() const { 100 size_t GetBusyResourceCountForTesting() const {
97 return busy_resources_.size(); 101 return busy_resources_.size();
98 } 102 }
99 103
100 protected: 104 protected:
101 // Constructor for creating GPU memory buffer resources. 105 // Constructor for creating GPU memory buffer resources.
102 ResourcePool(ResourceProvider* resource_provider, 106 ResourcePool(ResourceProvider* resource_provider,
103 base::SingleThreadTaskRunner* task_runner, 107 base::SingleThreadTaskRunner* task_runner,
104 gfx::BufferUsage usage, 108 gfx::BufferUsage usage,
105 const base::TimeDelta& expiration_delay); 109 const base::TimeDelta& expiration_delay,
110 bool disallow_non_exact_reuse);
106 111
107 // Constructor for creating standard resources. 112 // Constructor for creating standard resources.
108 ResourcePool(ResourceProvider* resource_provider, 113 ResourcePool(ResourceProvider* resource_provider,
109 base::SingleThreadTaskRunner* task_runner, 114 base::SingleThreadTaskRunner* task_runner,
110 ResourceProvider::TextureHint hint, 115 ResourceProvider::TextureHint hint,
111 const base::TimeDelta& expiration_delay); 116 const base::TimeDelta& expiration_delay,
117 bool disallow_non_exact_reuse);
112 118
113 private: 119 private:
114 FRIEND_TEST_ALL_PREFIXES(ResourcePoolTest, ReuseResource); 120 FRIEND_TEST_ALL_PREFIXES(ResourcePoolTest, ReuseResource);
121 FRIEND_TEST_ALL_PREFIXES(ResourcePoolTest, ExactRequestsRespected);
115 class PoolResource : public ScopedResource { 122 class PoolResource : public ScopedResource {
116 public: 123 public:
117 static std::unique_ptr<PoolResource> Create( 124 static std::unique_ptr<PoolResource> Create(
118 ResourceProvider* resource_provider) { 125 ResourceProvider* resource_provider) {
119 return base::WrapUnique(new PoolResource(resource_provider)); 126 return base::WrapUnique(new PoolResource(resource_provider));
120 } 127 }
121 void OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, 128 void OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd,
122 const ResourceProvider* resource_provider, 129 const ResourceProvider* resource_provider,
123 bool is_free) const; 130 bool is_free) const;
124 131
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 using ResourceDeque = std::deque<std::unique_ptr<PoolResource>>; 186 using ResourceDeque = std::deque<std::unique_ptr<PoolResource>>;
180 ResourceDeque unused_resources_; 187 ResourceDeque unused_resources_;
181 ResourceDeque busy_resources_; 188 ResourceDeque busy_resources_;
182 189
183 using InUseResourceMap = std::map<ResourceId, std::unique_ptr<PoolResource>>; 190 using InUseResourceMap = std::map<ResourceId, std::unique_ptr<PoolResource>>;
184 InUseResourceMap in_use_resources_; 191 InUseResourceMap in_use_resources_;
185 192
186 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 193 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
187 bool evict_expired_resources_pending_ = false; 194 bool evict_expired_resources_pending_ = false;
188 const base::TimeDelta resource_expiration_delay_; 195 const base::TimeDelta resource_expiration_delay_;
196 const bool disallow_non_exact_reuse_ = false;
189 197
190 base::WeakPtrFactory<ResourcePool> weak_ptr_factory_; 198 base::WeakPtrFactory<ResourcePool> weak_ptr_factory_;
191 199
192 DISALLOW_COPY_AND_ASSIGN(ResourcePool); 200 DISALLOW_COPY_AND_ASSIGN(ResourcePool);
193 }; 201 };
194 202
195 } // namespace cc 203 } // namespace cc
196 204
197 #endif // CC_RESOURCES_RESOURCE_POOL_H_ 205 #endif // CC_RESOURCES_RESOURCE_POOL_H_
OLDNEW
« no previous file with comments | « cc/raster/one_copy_raster_buffer_provider.cc ('k') | cc/resources/resource_pool.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698