Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 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 | 9 |
| 10 | 10 |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 231 * of these, it will be purged (LRU) to keep the cache within these limits. | 231 * of these, it will be purged (LRU) to keep the cache within these limits. |
| 232 * | 232 * |
| 233 * @param maxResources The maximum number of resources that can be held in | 233 * @param maxResources The maximum number of resources that can be held in |
| 234 * the cache. | 234 * the cache. |
| 235 * @param maxBytes The maximum number of bytes of resource memory that | 235 * @param maxBytes The maximum number of bytes of resource memory that |
| 236 * can be held in the cache. | 236 * can be held in the cache. |
| 237 */ | 237 */ |
| 238 void setLimits(int maxResource, size_t maxResourceBytes); | 238 void setLimits(int maxResource, size_t maxResourceBytes); |
| 239 | 239 |
| 240 /** | 240 /** |
| 241 * Set the callback the cache should use when it is still over budget | |
| 242 * after a purge. The 'data' provided here will be passed back to the | |
| 243 * callback. | |
|
bsalomon
2013/07/09 17:43:25
Maybe mention that the cache will attempt to purge
robertphillips
2013/07/10 10:15:13
Done.
I expanded the comment and made the CB now
| |
| 244 */ | |
| 245 typedef void (*PFOverbudgetCB)(void* data); | |
| 246 void setOverbudgetCallback(PFOverbudgetCB overbudgetCB, void* data) { | |
| 247 fOverbudgetCB = overbudgetCB; | |
| 248 fOverbudgetData = data; | |
| 249 } | |
| 250 | |
| 251 /** | |
| 241 * Returns the number of bytes consumed by cached resources. | 252 * Returns the number of bytes consumed by cached resources. |
| 242 */ | 253 */ |
| 243 size_t getCachedResourceBytes() const { return fEntryBytes; } | 254 size_t getCachedResourceBytes() const { return fEntryBytes; } |
| 244 | 255 |
| 245 // For a found or added resource to be completely exclusive to the caller | 256 // For a found or added resource to be completely exclusive to the caller |
| 246 // both the kNoOtherOwners and kHide flags need to be specified | 257 // both the kNoOtherOwners and kHide flags need to be specified |
| 247 enum OwnershipFlags { | 258 enum OwnershipFlags { |
| 248 kNoOtherOwners_OwnershipFlag = 0x1, // found/added resource has no other owners | 259 kNoOtherOwners_OwnershipFlag = 0x1, // found/added resource has no other owners |
| 249 kHide_OwnershipFlag = 0x2 // found/added resource is hidden from future 'find's | 260 kHide_OwnershipFlag = 0x2 // found/added resource is hidden from future 'find's |
| 250 }; | 261 }; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 353 int fHighWaterClientDetachedCount; | 364 int fHighWaterClientDetachedCount; |
| 354 size_t fHighWaterClientDetachedBytes; | 365 size_t fHighWaterClientDetachedBytes; |
| 355 #endif | 366 #endif |
| 356 | 367 |
| 357 int fEntryCount; | 368 int fEntryCount; |
| 358 size_t fEntryBytes; | 369 size_t fEntryBytes; |
| 359 int fClientDetachedCount; | 370 int fClientDetachedCount; |
| 360 size_t fClientDetachedBytes; | 371 size_t fClientDetachedBytes; |
| 361 | 372 |
| 362 // prevents recursive purging | 373 // prevents recursive purging |
| 363 bool fPurging; | 374 bool fPurging; |
| 375 | |
| 376 PFOverbudgetCB fOverbudgetCB; | |
| 377 void* fOverbudgetData; | |
| 378 | |
| 379 void internalPurge(); | |
| 364 | 380 |
| 365 #if GR_DEBUG | 381 #if GR_DEBUG |
| 366 static size_t countBytes(const SkTInternalLList<GrResourceEntry>& list); | 382 static size_t countBytes(const SkTInternalLList<GrResourceEntry>& list); |
| 367 #endif | 383 #endif |
| 368 }; | 384 }; |
| 369 | 385 |
| 370 /////////////////////////////////////////////////////////////////////////////// | 386 /////////////////////////////////////////////////////////////////////////////// |
| 371 | 387 |
| 372 #if GR_DEBUG | 388 #if GR_DEBUG |
| 373 class GrAutoResourceCacheValidate { | 389 class GrAutoResourceCacheValidate { |
| 374 public: | 390 public: |
| 375 GrAutoResourceCacheValidate(GrResourceCache* cache) : fCache(cache) { | 391 GrAutoResourceCacheValidate(GrResourceCache* cache) : fCache(cache) { |
| 376 cache->validate(); | 392 cache->validate(); |
| 377 } | 393 } |
| 378 ~GrAutoResourceCacheValidate() { | 394 ~GrAutoResourceCacheValidate() { |
| 379 fCache->validate(); | 395 fCache->validate(); |
| 380 } | 396 } |
| 381 private: | 397 private: |
| 382 GrResourceCache* fCache; | 398 GrResourceCache* fCache; |
| 383 }; | 399 }; |
| 384 #else | 400 #else |
| 385 class GrAutoResourceCacheValidate { | 401 class GrAutoResourceCacheValidate { |
| 386 public: | 402 public: |
| 387 GrAutoResourceCacheValidate(GrResourceCache*) {} | 403 GrAutoResourceCacheValidate(GrResourceCache*) {} |
| 388 }; | 404 }; |
| 389 #endif | 405 #endif |
| 390 | 406 |
| 391 #endif | 407 #endif |
| OLD | NEW |