OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2014 Google Inc. | 3 * Copyright 2014 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #ifndef GrResourceCache2_DEFINED | 9 #ifndef GrResourceCache2_DEFINED |
10 #define GrResourceCache2_DEFINED | 10 #define GrResourceCache2_DEFINED |
(...skipping 29 matching lines...) Expand all Loading... |
40 /** Used to access functionality needed by GrGpuResource for lifetime manage
ment. */ | 40 /** Used to access functionality needed by GrGpuResource for lifetime manage
ment. */ |
41 class ResourceAccess; | 41 class ResourceAccess; |
42 ResourceAccess resourceAccess(); | 42 ResourceAccess resourceAccess(); |
43 | 43 |
44 /** | 44 /** |
45 * Sets the cache limits in terms of number of resources and max gpu memory
byte size. | 45 * Sets the cache limits in terms of number of resources and max gpu memory
byte size. |
46 */ | 46 */ |
47 void setLimits(int count, size_t bytes); | 47 void setLimits(int count, size_t bytes); |
48 | 48 |
49 /** | 49 /** |
50 * Returns the number of cached resources. | 50 * Returns the number of resources. |
51 */ | 51 */ |
52 int getResourceCount() const { return fCount; } | 52 int getResourceCount() const { return fCount; } |
53 | 53 |
54 /** | 54 /** |
55 * Returns the number of bytes consumed by cached resources. | 55 * Returns the number of resources that count against the budget. |
| 56 */ |
| 57 int getBudgetedResourceCount() const { return fBudgetedCount; } |
| 58 |
| 59 /** |
| 60 * Returns the number of bytes consumed by resources. |
56 */ | 61 */ |
57 size_t getResourceBytes() const { return fBytes; } | 62 size_t getResourceBytes() const { return fBytes; } |
58 | 63 |
59 /** | 64 /** |
| 65 * Returns the number of bytes consumed by budgeted resources. |
| 66 */ |
| 67 size_t getBudgetedResourceBytes() const { return fBudgetedBytes; } |
| 68 |
| 69 /** |
60 * Returns the cached resources count budget. | 70 * Returns the cached resources count budget. |
61 */ | 71 */ |
62 int getMaxResourceCount() const { return fMaxCount; } | 72 int getMaxResourceCount() const { return fMaxCount; } |
63 | 73 |
64 /** | 74 /** |
65 * Returns the number of bytes consumed by cached resources. | 75 * Returns the number of bytes consumed by cached resources. |
66 */ | 76 */ |
67 size_t getMaxResourceBytes() const { return fMaxBytes; } | 77 size_t getMaxResourceBytes() const { return fMaxBytes; } |
68 | 78 |
69 /** | 79 /** |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 //// | 158 //// |
149 void insertResource(GrGpuResource*); | 159 void insertResource(GrGpuResource*); |
150 void removeResource(GrGpuResource*); | 160 void removeResource(GrGpuResource*); |
151 void notifyPurgable(GrGpuResource*); | 161 void notifyPurgable(GrGpuResource*); |
152 void didChangeGpuMemorySize(const GrGpuResource*, size_t oldSize); | 162 void didChangeGpuMemorySize(const GrGpuResource*, size_t oldSize); |
153 bool didSetContentKey(GrGpuResource*); | 163 bool didSetContentKey(GrGpuResource*); |
154 void makeResourceMRU(GrGpuResource*); | 164 void makeResourceMRU(GrGpuResource*); |
155 /// @} | 165 /// @} |
156 | 166 |
157 void purgeAsNeeded() { | 167 void purgeAsNeeded() { |
158 if (fPurging || (fCount <= fMaxCount && fBytes < fMaxBytes)) { | 168 if (fPurging || (fBudgetedCount <= fMaxCount && fBudgetedBytes < fMaxByt
es)) { |
159 return; | 169 return; |
160 } | 170 } |
161 this->internalPurgeAsNeeded(); | 171 this->internalPurgeAsNeeded(); |
162 } | 172 } |
163 | 173 |
164 void internalPurgeAsNeeded(); | 174 void internalPurgeAsNeeded(); |
165 | 175 |
166 #ifdef SK_DEBUG | 176 #ifdef SK_DEBUG |
167 bool isInCache(const GrGpuResource* r) const { return fResources.isInList(r)
; } | 177 bool isInCache(const GrGpuResource* r) const { return fResources.isInList(r)
; } |
168 void validate() const; | 178 void validate() const; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 // This holds all resources that have content keys. | 210 // This holds all resources that have content keys. |
201 ContentHash fContentHash; | 211 ContentHash fContentHash; |
202 | 212 |
203 // our budget, used in purgeAsNeeded() | 213 // our budget, used in purgeAsNeeded() |
204 int fMaxCount; | 214 int fMaxCount; |
205 size_t fMaxBytes; | 215 size_t fMaxBytes; |
206 | 216 |
207 #if GR_CACHE_STATS | 217 #if GR_CACHE_STATS |
208 int fHighWaterCount; | 218 int fHighWaterCount; |
209 size_t fHighWaterBytes; | 219 size_t fHighWaterBytes; |
| 220 int fBudgetedHighWaterCount; |
| 221 size_t fBudgetedHighWaterBytes; |
210 #endif | 222 #endif |
211 | 223 |
212 // our current stats, related to our budget | 224 // our current stats for all resources |
213 int fCount; | 225 int fCount; |
214 size_t fBytes; | 226 size_t fBytes; |
215 | 227 |
| 228 // our current stats for resources that count against the budget |
| 229 int fBudgetedCount; |
| 230 size_t fBudgetedBytes; |
| 231 |
216 // prevents recursive purging | 232 // prevents recursive purging |
217 bool fPurging; | 233 bool fPurging; |
218 bool fNewlyPurgableResourceWhilePurging; | 234 bool fNewlyPurgableResourceWhilePurging; |
219 | 235 |
220 PFOverBudgetCB fOverBudgetCB; | 236 PFOverBudgetCB fOverBudgetCB; |
221 void* fOverBudgetData; | 237 void* fOverBudgetData; |
222 | 238 |
223 }; | 239 }; |
224 | 240 |
225 class GrResourceCache2::ResourceAccess { | 241 class GrResourceCache2::ResourceAccess { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 | 284 |
269 friend class GrGpuResource; // To access all the proxy inline methods. | 285 friend class GrGpuResource; // To access all the proxy inline methods. |
270 friend class GrResourceCache2; // To create this type. | 286 friend class GrResourceCache2; // To create this type. |
271 }; | 287 }; |
272 | 288 |
273 inline GrResourceCache2::ResourceAccess GrResourceCache2::resourceAccess() { | 289 inline GrResourceCache2::ResourceAccess GrResourceCache2::resourceAccess() { |
274 return ResourceAccess(this); | 290 return ResourceAccess(this); |
275 } | 291 } |
276 | 292 |
277 #endif | 293 #endif |
OLD | NEW |