| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef GrResourceCache_DEFINED | 8 #ifndef GrResourceCache_DEFINED |
| 9 #define GrResourceCache_DEFINED | 9 #define GrResourceCache_DEFINED |
| 10 | 10 |
| 11 #include "GrGpuResource.h" | 11 #include "GrGpuResource.h" |
| 12 #include "GrGpuResourceCacheAccess.h" | 12 #include "GrGpuResourceCacheAccess.h" |
| 13 #include "GrGpuResourcePriv.h" | 13 #include "GrGpuResourcePriv.h" |
| 14 #include "GrResourceCache.h" | |
| 15 #include "GrResourceKey.h" | 14 #include "GrResourceKey.h" |
| 16 #include "SkMessageBus.h" | 15 #include "SkMessageBus.h" |
| 17 #include "SkRefCnt.h" | 16 #include "SkRefCnt.h" |
| 18 #include "SkTArray.h" | 17 #include "SkTArray.h" |
| 19 #include "SkTDPQueue.h" | 18 #include "SkTDPQueue.h" |
| 20 #include "SkTInternalLList.h" | 19 #include "SkTInternalLList.h" |
| 21 #include "SkTMultiMap.h" | 20 #include "SkTMultiMap.h" |
| 22 | 21 |
| 23 class GrCaps; | 22 class GrCaps; |
| 24 class SkString; | 23 class SkString; |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 return SkToBool(fUniqueHash.find(key)); | 156 return SkToBool(fUniqueHash.find(key)); |
| 158 } | 157 } |
| 159 | 158 |
| 160 /** Purges resources to become under budget and processes resources with inv
alidated unique | 159 /** Purges resources to become under budget and processes resources with inv
alidated unique |
| 161 keys. */ | 160 keys. */ |
| 162 void purgeAsNeeded(); | 161 void purgeAsNeeded(); |
| 163 | 162 |
| 164 /** Purges all resources that don't have external owners. */ | 163 /** Purges all resources that don't have external owners. */ |
| 165 void purgeAllUnlocked(); | 164 void purgeAllUnlocked(); |
| 166 | 165 |
| 167 /** Returns true if the cache would like a flush to occur in order to make m
ore resources | 166 /** |
| 168 purgeable. */ | 167 * The callback function used by the cache when it is still over budget afte
r a purge. The |
| 169 bool requestsFlush() const { return fRequestFlush; } | 168 * passed in 'data' is the same 'data' handed to setOverbudgetCallback. |
| 169 */ |
| 170 typedef void (*PFOverBudgetCB)(void* data); |
| 170 | 171 |
| 171 enum FlushType { | 172 /** |
| 172 kExternal, | 173 * Set the callback the cache should use when it is still over budget after
a purge. The 'data' |
| 173 kImmediateMode, | 174 * provided here will be passed back to the callback. Note that the cache wi
ll attempt to purge |
| 174 kCacheRequested, | 175 * any resources newly freed by the callback. |
| 175 }; | 176 */ |
| 176 void notifyFlushOccurred(FlushType); | 177 void setOverBudgetCallback(PFOverBudgetCB overBudgetCB, void* data) { |
| 178 fOverBudgetCB = overBudgetCB; |
| 179 fOverBudgetData = data; |
| 180 } |
| 181 |
| 182 void notifyFlushOccurred(); |
| 177 | 183 |
| 178 #if GR_CACHE_STATS | 184 #if GR_CACHE_STATS |
| 179 struct Stats { | 185 struct Stats { |
| 180 int fTotal; | 186 int fTotal; |
| 181 int fNumPurgeable; | 187 int fNumPurgeable; |
| 182 int fNumNonPurgeable; | 188 int fNumNonPurgeable; |
| 183 | 189 |
| 184 int fScratch; | 190 int fScratch; |
| 185 int fWrapped; | 191 int fWrapped; |
| 186 size_t fUnbudgetedSize; | 192 size_t fUnbudgetedSize; |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 #endif | 319 #endif |
| 314 | 320 |
| 315 // our current stats for all resources | 321 // our current stats for all resources |
| 316 SkDEBUGCODE(int fCount;) | 322 SkDEBUGCODE(int fCount;) |
| 317 size_t fBytes; | 323 size_t fBytes; |
| 318 | 324 |
| 319 // our current stats for resources that count against the budget | 325 // our current stats for resources that count against the budget |
| 320 int fBudgetedCount; | 326 int fBudgetedCount; |
| 321 size_t fBudgetedBytes; | 327 size_t fBudgetedBytes; |
| 322 | 328 |
| 323 bool fRequestFlush; | 329 PFOverBudgetCB fOverBudgetCB; |
| 330 void* fOverBudgetData; |
| 324 | 331 |
| 325 // We keep track of the "timestamps" of the last n flushes. If a resource ha
sn't been used in | 332 // We keep track of the "timestamps" of the last n flushes. If a resource ha
sn't been used in |
| 326 // that time then we well preemptively purge it to reduce memory usage. | 333 // that time then we well preemptively purge it to reduce memory usage. |
| 327 uint32_t* fFlushTimestamps; | 334 uint32_t* fFlushTimestamps; |
| 328 int fLastFlushTimestampIndex; | 335 int fLastFlushTimestampIndex; |
| 329 | 336 |
| 330 InvalidUniqueKeyInbox fInvalidUniqueKeyInbox; | 337 InvalidUniqueKeyInbox fInvalidUniqueKeyInbox; |
| 331 | 338 |
| 332 // This resource is allowed to be in the nonpurgeable array for the sake of
validate() because | 339 // This resource is allowed to be in the nonpurgeable array for the sake of
validate() because |
| 333 // we're in the midst of converting it to purgeable status. | 340 // we're in the midst of converting it to purgeable status. |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 | 420 |
| 414 friend class GrGpuResource; // To access all the proxy inline methods. | 421 friend class GrGpuResource; // To access all the proxy inline methods. |
| 415 friend class GrResourceCache; // To create this type. | 422 friend class GrResourceCache; // To create this type. |
| 416 }; | 423 }; |
| 417 | 424 |
| 418 inline GrResourceCache::ResourceAccess GrResourceCache::resourceAccess() { | 425 inline GrResourceCache::ResourceAccess GrResourceCache::resourceAccess() { |
| 419 return ResourceAccess(this); | 426 return ResourceAccess(this); |
| 420 } | 427 } |
| 421 | 428 |
| 422 #endif | 429 #endif |
| OLD | NEW |