| 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 GrResourceCache_DEFINED | 9 #ifndef GrResourceCache_DEFINED |
| 10 #define GrResourceCache_DEFINED | 10 #define GrResourceCache_DEFINED |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 ResourceAccess resourceAccess(); | 48 ResourceAccess resourceAccess(); |
| 49 | 49 |
| 50 /** | 50 /** |
| 51 * Sets the cache limits in terms of number of resources and max gpu memory
byte size. | 51 * Sets the cache limits in terms of number of resources and max gpu memory
byte size. |
| 52 */ | 52 */ |
| 53 void setLimits(int count, size_t bytes); | 53 void setLimits(int count, size_t bytes); |
| 54 | 54 |
| 55 /** | 55 /** |
| 56 * Returns the number of resources. | 56 * Returns the number of resources. |
| 57 */ | 57 */ |
| 58 int getResourceCount() const { return fCount; } | 58 int getResourceCount() const { |
| 59 return fPurgeableQueue.count() + fNonpurgeableResources.count(); |
| 60 } |
| 59 | 61 |
| 60 /** | 62 /** |
| 61 * Returns the number of resources that count against the budget. | 63 * Returns the number of resources that count against the budget. |
| 62 */ | 64 */ |
| 63 int getBudgetedResourceCount() const { return fBudgetedCount; } | 65 int getBudgetedResourceCount() const { return fBudgetedCount; } |
| 64 | 66 |
| 65 /** | 67 /** |
| 66 * Returns the number of bytes consumed by resources. | 68 * Returns the number of bytes consumed by resources. |
| 67 */ | 69 */ |
| 68 size_t getResourceBytes() const { return fBytes; } | 70 size_t getResourceBytes() const { return fBytes; } |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 void didChangeGpuMemorySize(const GrGpuResource*, size_t oldSize); | 180 void didChangeGpuMemorySize(const GrGpuResource*, size_t oldSize); |
| 179 bool didSetContentKey(GrGpuResource*); | 181 bool didSetContentKey(GrGpuResource*); |
| 180 void willRemoveScratchKey(const GrGpuResource*); | 182 void willRemoveScratchKey(const GrGpuResource*); |
| 181 void willRemoveContentKey(const GrGpuResource*); | 183 void willRemoveContentKey(const GrGpuResource*); |
| 182 void didChangeBudgetStatus(GrGpuResource*); | 184 void didChangeBudgetStatus(GrGpuResource*); |
| 183 void refAndMakeResourceMRU(GrGpuResource*); | 185 void refAndMakeResourceMRU(GrGpuResource*); |
| 184 /// @} | 186 /// @} |
| 185 | 187 |
| 186 void internalPurgeAsNeeded(); | 188 void internalPurgeAsNeeded(); |
| 187 void processInvalidContentKeys(const SkTArray<GrContentKeyInvalidatedMessage
>&); | 189 void processInvalidContentKeys(const SkTArray<GrContentKeyInvalidatedMessage
>&); |
| 190 void addToNonpurgeableArray(GrGpuResource*); |
| 191 void removeFromNonpurgeableArray(GrGpuResource*); |
| 192 bool overBudget() const { return fBudgetedBytes > fMaxBytes || fBudgetedCoun
t > fMaxCount; } |
| 188 | 193 |
| 189 #ifdef SK_DEBUG | 194 #ifdef SK_DEBUG |
| 190 bool isInCache(const GrGpuResource* r) const { return fResources.isInList(r)
; } | 195 bool isInCache(const GrGpuResource* r) const; |
| 191 void validate() const; | 196 void validate() const; |
| 192 #else | 197 #else |
| 193 void validate() const {} | 198 void validate() const {} |
| 194 #endif | 199 #endif |
| 195 | 200 |
| 196 class AutoValidate; | 201 class AutoValidate; |
| 197 | 202 |
| 198 class AvailableForScratchUse; | 203 class AvailableForScratchUse; |
| 199 | 204 |
| 200 struct ScratchMapTraits { | 205 struct ScratchMapTraits { |
| 201 static const GrScratchKey& GetKey(const GrGpuResource& r) { | 206 static const GrScratchKey& GetKey(const GrGpuResource& r) { |
| 202 return r.resourcePriv().getScratchKey(); | 207 return r.resourcePriv().getScratchKey(); |
| 203 } | 208 } |
| 204 | 209 |
| 205 static uint32_t Hash(const GrScratchKey& key) { return key.hash(); } | 210 static uint32_t Hash(const GrScratchKey& key) { return key.hash(); } |
| 206 }; | 211 }; |
| 207 typedef SkTMultiMap<GrGpuResource, GrScratchKey, ScratchMapTraits> ScratchMa
p; | 212 typedef SkTMultiMap<GrGpuResource, GrScratchKey, ScratchMapTraits> ScratchMa
p; |
| 208 | 213 |
| 209 struct ContentHashTraits { | 214 struct ContentHashTraits { |
| 210 static const GrContentKey& GetKey(const GrGpuResource& r) { | 215 static const GrContentKey& GetKey(const GrGpuResource& r) { |
| 211 return r.getContentKey(); | 216 return r.getContentKey(); |
| 212 } | 217 } |
| 213 | 218 |
| 214 static uint32_t Hash(const GrContentKey& key) { return key.hash(); } | 219 static uint32_t Hash(const GrContentKey& key) { return key.hash(); } |
| 215 }; | 220 }; |
| 216 typedef SkTDynamicHash<GrGpuResource, GrContentKey, ContentHashTraits> Conte
ntHash; | 221 typedef SkTDynamicHash<GrGpuResource, GrContentKey, ContentHashTraits> Conte
ntHash; |
| 217 | 222 |
| 218 typedef SkTInternalLList<GrGpuResource> ResourceList; | |
| 219 | |
| 220 static bool CompareTimestamp(GrGpuResource* const& a, GrGpuResource* const&
b) { | 223 static bool CompareTimestamp(GrGpuResource* const& a, GrGpuResource* const&
b) { |
| 221 return a->cacheAccess().timestamp() < b->cacheAccess().timestamp(); | 224 return a->cacheAccess().timestamp() < b->cacheAccess().timestamp(); |
| 222 } | 225 } |
| 223 | 226 |
| 224 static int* AccessResourceIndex(GrGpuResource* const& res) { | 227 static int* AccessResourceIndex(GrGpuResource* const& res) { |
| 225 return res->cacheAccess().accessCacheIndex(); | 228 return res->cacheAccess().accessCacheIndex(); |
| 226 } | 229 } |
| 227 | 230 |
| 228 typedef SkMessageBus<GrContentKeyInvalidatedMessage>::Inbox InvalidContentKe
yInbox; | 231 typedef SkMessageBus<GrContentKeyInvalidatedMessage>::Inbox InvalidContentKe
yInbox; |
| 229 typedef SkTDPQueue<GrGpuResource*, CompareTimestamp, AccessResourceIndex> Pu
rgeableQueue; | 232 typedef SkTDPQueue<GrGpuResource*, CompareTimestamp, AccessResourceIndex> Pu
rgeableQueue; |
| 233 typedef SkTDArray<GrGpuResource*> ResourceArray; |
| 230 | 234 |
| 231 // Whenever a resource is added to the cache or the result of a cache lookup
, fTimestamp is | 235 // Whenever a resource is added to the cache or the result of a cache lookup
, fTimestamp is |
| 232 // assigned as the resource's timestamp and then incremented. fPurgeableQueu
e orders the | 236 // assigned as the resource's timestamp and then incremented. fPurgeableQueu
e orders the |
| 233 // purgeable resources by this value, and thus is used to purge resources in
LRU order. | 237 // purgeable resources by this value, and thus is used to purge resources in
LRU order. |
| 234 uint32_t fTimestamp; | 238 uint32_t fTimestamp; |
| 235 PurgeableQueue fPurgeableQueue; | 239 PurgeableQueue fPurgeableQueue; |
| 236 | 240 ResourceArray fNonpurgeableResources; |
| 237 // TODO: Replace this with an array of nonpurgeable resources | |
| 238 ResourceList fResources; | |
| 239 | 241 |
| 240 // This map holds all resources that can be used as scratch resources. | 242 // This map holds all resources that can be used as scratch resources. |
| 241 ScratchMap fScratchMap; | 243 ScratchMap fScratchMap; |
| 242 // This holds all resources that have content keys. | 244 // This holds all resources that have content keys. |
| 243 ContentHash fContentHash; | 245 ContentHash fContentHash; |
| 244 | 246 |
| 245 // our budget, used in purgeAsNeeded() | 247 // our budget, used in purgeAsNeeded() |
| 246 int fMaxCount; | 248 int fMaxCount; |
| 247 size_t fMaxBytes; | 249 size_t fMaxBytes; |
| 248 | 250 |
| 249 #if GR_CACHE_STATS | 251 #if GR_CACHE_STATS |
| 250 int fHighWaterCount; | 252 int fHighWaterCount; |
| 251 size_t fHighWaterBytes; | 253 size_t fHighWaterBytes; |
| 252 int fBudgetedHighWaterCount; | 254 int fBudgetedHighWaterCount; |
| 253 size_t fBudgetedHighWaterBytes; | 255 size_t fBudgetedHighWaterBytes; |
| 254 #endif | 256 #endif |
| 255 | 257 |
| 256 // our current stats for all resources | 258 // our current stats for all resources |
| 257 int fCount; | 259 SkDEBUGCODE(int fCount;) |
| 258 size_t fBytes; | 260 size_t fBytes; |
| 259 | 261 |
| 260 // our current stats for resources that count against the budget | 262 // our current stats for resources that count against the budget |
| 261 int fBudgetedCount; | 263 int fBudgetedCount; |
| 262 size_t fBudgetedBytes; | 264 size_t fBudgetedBytes; |
| 263 | 265 |
| 264 PFOverBudgetCB fOverBudgetCB; | 266 PFOverBudgetCB fOverBudgetCB; |
| 265 void* fOverBudgetData; | 267 void* fOverBudgetData; |
| 266 | 268 |
| 267 InvalidContentKeyInbox fInvalidContentKeyInbox; | 269 InvalidContentKeyInbox fInvalidContentKeyInbox; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 | 334 |
| 333 friend class GrGpuResource; // To access all the proxy inline methods. | 335 friend class GrGpuResource; // To access all the proxy inline methods. |
| 334 friend class GrResourceCache; // To create this type. | 336 friend class GrResourceCache; // To create this type. |
| 335 }; | 337 }; |
| 336 | 338 |
| 337 inline GrResourceCache::ResourceAccess GrResourceCache::resourceAccess() { | 339 inline GrResourceCache::ResourceAccess GrResourceCache::resourceAccess() { |
| 338 return ResourceAccess(this); | 340 return ResourceAccess(this); |
| 339 } | 341 } |
| 340 | 342 |
| 341 #endif | 343 #endif |
| OLD | NEW |