| 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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 public: | 215 public: |
| 216 GrResourceCache(int maxCount, size_t maxBytes); | 216 GrResourceCache(int maxCount, size_t maxBytes); |
| 217 ~GrResourceCache(); | 217 ~GrResourceCache(); |
| 218 | 218 |
| 219 /** | 219 /** |
| 220 * Return the current resource cache limits. | 220 * Return the current resource cache limits. |
| 221 * | 221 * |
| 222 * @param maxResource If non-null, returns maximum number of resources | 222 * @param maxResource If non-null, returns maximum number of resources |
| 223 * that can be held in the cache. | 223 * that can be held in the cache. |
| 224 * @param maxBytes If non-null, returns maximum number of bytes of | 224 * @param maxBytes If non-null, returns maximum number of bytes of |
| 225 * gpu memory that can be held in the cache. | 225 * gpu memory that can be held in the cache. |
| 226 */ | 226 */ |
| 227 void getLimits(int* maxResources, size_t* maxBytes) const; | 227 void getLimits(int* maxResources, size_t* maxBytes) const; |
| 228 | 228 |
| 229 /** | 229 /** |
| 230 * Specify the resource cache limits. If the current cache exceeds either | 230 * Specify the resource cache limits. If the current cache exceeds either |
| 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 maxResources, size_t maxResourceBytes); |
| 239 | 239 |
| 240 /** | 240 /** |
| 241 * The callback function used by the cache when it is still over budget | 241 * The callback function used by the cache when it is still over budget |
| 242 * after a purge. The passed in 'data' is the same 'data' handed to | 242 * after a purge. The passed in 'data' is the same 'data' handed to |
| 243 * setOverbudgetCallback. The callback returns true if some resources | 243 * setOverbudgetCallback. The callback returns true if some resources |
| 244 * have been freed. | 244 * have been freed. |
| 245 */ | 245 */ |
| 246 typedef bool (*PFOverbudgetCB)(void* data); | 246 typedef bool (*PFOverbudgetCB)(void* data); |
| 247 | 247 |
| 248 /** | 248 /** |
| 249 * Set the callback the cache should use when it is still over budget | 249 * Set the callback the cache should use when it is still over budget |
| 250 * after a purge. The 'data' provided here will be passed back to the | 250 * after a purge. The 'data' provided here will be passed back to the |
| 251 * callback. The cache will attempt to purge any resources newly freed | 251 * callback. Note that the cache will attempt to purge any resources newly |
| 252 * by the callback. | 252 * freed by the callback. |
| 253 */ | 253 */ |
| 254 void setOverbudgetCallback(PFOverbudgetCB overbudgetCB, void* data) { | 254 void setOverbudgetCallback(PFOverbudgetCB overbudgetCB, void* data) { |
| 255 fOverbudgetCB = overbudgetCB; | 255 fOverbudgetCB = overbudgetCB; |
| 256 fOverbudgetData = data; | 256 fOverbudgetData = data; |
| 257 } | 257 } |
| 258 | 258 |
| 259 /** | 259 /** |
| 260 * Returns the number of bytes consumed by cached resources. | 260 * Returns the number of bytes consumed by cached resources. |
| 261 */ | 261 */ |
| 262 size_t getCachedResourceBytes() const { return fEntryBytes; } | 262 size_t getCachedResourceBytes() const { return fEntryBytes; } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 * is called. | 294 * is called. |
| 295 */ | 295 */ |
| 296 void addResource(const GrResourceKey& key, | 296 void addResource(const GrResourceKey& key, |
| 297 GrResource* resource, | 297 GrResource* resource, |
| 298 uint32_t ownershipFlags = 0); | 298 uint32_t ownershipFlags = 0); |
| 299 | 299 |
| 300 /** | 300 /** |
| 301 * Determines if the cache contains an entry matching a key. If a matching | 301 * Determines if the cache contains an entry matching a key. If a matching |
| 302 * entry exists but was detached then it will not be found. | 302 * entry exists but was detached then it will not be found. |
| 303 */ | 303 */ |
| 304 bool hasKey(const GrResourceKey& key) const; | 304 bool hasKey(const GrResourceKey& key) const { return NULL != fCache.find(key
); } |
| 305 | 305 |
| 306 /** | 306 /** |
| 307 * Hide 'entry' so that future searches will not find it. Such | 307 * Hide 'entry' so that future searches will not find it. Such |
| 308 * hidden entries will not be purged. The entry still counts against | 308 * hidden entries will not be purged. The entry still counts against |
| 309 * the cache's budget and should be made non-exclusive when exclusive access | 309 * the cache's budget and should be made non-exclusive when exclusive access |
| 310 * is no longer needed. | 310 * is no longer needed. |
| 311 */ | 311 */ |
| 312 void makeExclusive(GrResourceEntry* entry); | 312 void makeExclusive(GrResourceEntry* entry); |
| 313 | 313 |
| 314 /** | 314 /** |
| 315 * Restore 'entry' so that it can be found by future searches. 'entry' | 315 * Restore 'entry' so that it can be found by future searches. 'entry' |
| 316 * will also be purgeable (provided its lock count is now 0.) | 316 * will also be purgeable (provided its lock count is now 0.) |
| 317 */ | 317 */ |
| 318 void makeNonExclusive(GrResourceEntry* entry); | 318 void makeNonExclusive(GrResourceEntry* entry); |
| 319 | 319 |
| 320 /** | 320 /** |
| 321 * Remove a resource from the cache and delete it! |
| 322 */ |
| 323 void deleteResource(GrResourceEntry* entry); |
| 324 |
| 325 /** |
| 321 * Removes every resource in the cache that isn't locked. | 326 * Removes every resource in the cache that isn't locked. |
| 322 */ | 327 */ |
| 323 void purgeAllUnlocked(); | 328 void purgeAllUnlocked(); |
| 324 | 329 |
| 325 /** | 330 /** |
| 326 * Allow cache to purge unused resources to obey resource limitations | 331 * Allow cache to purge unused resources to obey resource limitations |
| 327 * Note: this entry point will be hidden (again) once totally ref-driven | 332 * Note: this entry point will be hidden (again) once totally ref-driven |
| 328 * cache maintenance is implemented | 333 * cache maintenance is implemented. Note that the overbudget callback |
| 334 * will be called if the initial purge doesn't get the cache under |
| 335 * its budget. |
| 329 * | 336 * |
| 330 * extraCount and extraBytes are added to the current resource allocation | 337 * extraCount and extraBytes are added to the current resource allocation |
| 331 * to make sure enough room is available for future additions (e.g, | 338 * to make sure enough room is available for future additions (e.g, |
| 332 * 10MB across 10 textures is about to be added). | 339 * 10MB across 10 textures is about to be added). |
| 333 */ | 340 */ |
| 334 void purgeAsNeeded(int extraCount = 0, size_t extraBytes = 0); | 341 void purgeAsNeeded(int extraCount = 0, size_t extraBytes = 0); |
| 335 | 342 |
| 336 #if GR_DEBUG | 343 #if GR_DEBUG |
| 337 void validate() const; | 344 void validate() const; |
| 338 #else | 345 #else |
| (...skipping 12 matching lines...) Expand all Loading... |
| 351 | 358 |
| 352 void internalDetach(GrResourceEntry*, BudgetBehaviors behavior = kAccountFor
_BudgetBehavior); | 359 void internalDetach(GrResourceEntry*, BudgetBehaviors behavior = kAccountFor
_BudgetBehavior); |
| 353 void attachToHead(GrResourceEntry*, BudgetBehaviors behavior = kAccountFor_B
udgetBehavior); | 360 void attachToHead(GrResourceEntry*, BudgetBehaviors behavior = kAccountFor_B
udgetBehavior); |
| 354 | 361 |
| 355 void removeInvalidResource(GrResourceEntry* entry); | 362 void removeInvalidResource(GrResourceEntry* entry); |
| 356 | 363 |
| 357 GrTHashTable<GrResourceEntry, GrResourceKey, 8> fCache; | 364 GrTHashTable<GrResourceEntry, GrResourceKey, 8> fCache; |
| 358 | 365 |
| 359 // We're an internal doubly linked list | 366 // We're an internal doubly linked list |
| 360 typedef SkTInternalLList<GrResourceEntry> EntryList; | 367 typedef SkTInternalLList<GrResourceEntry> EntryList; |
| 361 EntryList fList; | 368 EntryList fList; |
| 362 | 369 |
| 363 #if GR_DEBUG | 370 #if GR_DEBUG |
| 364 // These objects cannot be returned by a search | 371 // These objects cannot be returned by a search |
| 365 EntryList fExclusiveList; | 372 EntryList fExclusiveList; |
| 366 #endif | 373 #endif |
| 367 | 374 |
| 368 // our budget, used in purgeAsNeeded() | 375 // our budget, used in purgeAsNeeded() |
| 369 int fMaxCount; | 376 int fMaxCount; |
| 370 size_t fMaxBytes; | 377 size_t fMaxBytes; |
| 371 | 378 |
| 372 // our current stats, related to our budget | 379 // our current stats, related to our budget |
| 373 #if GR_CACHE_STATS | 380 #if GR_CACHE_STATS |
| 374 int fHighWaterEntryCount; | 381 int fHighWaterEntryCount; |
| 375 size_t fHighWaterEntryBytes; | 382 size_t fHighWaterEntryBytes; |
| 376 int fHighWaterClientDetachedCount; | 383 int fHighWaterClientDetachedCount; |
| 377 size_t fHighWaterClientDetachedBytes; | 384 size_t fHighWaterClientDetachedBytes; |
| 378 #endif | 385 #endif |
| 379 | 386 |
| 380 int fEntryCount; | 387 int fEntryCount; |
| 381 size_t fEntryBytes; | 388 size_t fEntryBytes; |
| 382 int fClientDetachedCount; | 389 int fClientDetachedCount; |
| 383 size_t fClientDetachedBytes; | 390 size_t fClientDetachedBytes; |
| 384 | 391 |
| 385 // prevents recursive purging | 392 // prevents recursive purging |
| 386 bool fPurging; | 393 bool fPurging; |
| 387 | 394 |
| 388 PFOverbudgetCB fOverbudgetCB; | 395 PFOverbudgetCB fOverbudgetCB; |
| 389 void* fOverbudgetData; | 396 void* fOverbudgetData; |
| 390 | 397 |
| 391 void internalPurge(int extraCount, size_t extraBytes); | 398 void internalPurge(int extraCount, size_t extraBytes); |
| 392 | 399 |
| 393 #if GR_DEBUG | 400 #if GR_DEBUG |
| (...skipping 16 matching lines...) Expand all Loading... |
| 410 GrResourceCache* fCache; | 417 GrResourceCache* fCache; |
| 411 }; | 418 }; |
| 412 #else | 419 #else |
| 413 class GrAutoResourceCacheValidate { | 420 class GrAutoResourceCacheValidate { |
| 414 public: | 421 public: |
| 415 GrAutoResourceCacheValidate(GrResourceCache*) {} | 422 GrAutoResourceCacheValidate(GrResourceCache*) {} |
| 416 }; | 423 }; |
| 417 #endif | 424 #endif |
| 418 | 425 |
| 419 #endif | 426 #endif |
| OLD | NEW |