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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 Key fKey; | 141 Key fKey; |
142 }; | 142 }; |
143 | 143 |
144 /////////////////////////////////////////////////////////////////////////////// | 144 /////////////////////////////////////////////////////////////////////////////// |
145 | 145 |
146 class GrResourceEntry { | 146 class GrResourceEntry { |
147 public: | 147 public: |
148 GrResource* resource() const { return fResource; } | 148 GrResource* resource() const { return fResource; } |
149 const GrResourceKey& key() const { return fKey; } | 149 const GrResourceKey& key() const { return fKey; } |
150 | 150 |
151 #if GR_DEBUG | 151 #if SK_DEBUG |
152 void validate() const; | 152 void validate() const; |
153 #else | 153 #else |
154 void validate() const {} | 154 void validate() const {} |
155 #endif | 155 #endif |
156 | 156 |
157 private: | 157 private: |
158 GrResourceEntry(const GrResourceKey& key, GrResource* resource); | 158 GrResourceEntry(const GrResourceKey& key, GrResource* resource); |
159 ~GrResourceEntry(); | 159 ~GrResourceEntry(); |
160 | 160 |
161 GrResourceKey fKey; | 161 GrResourceKey fKey; |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 * cache maintenance is implemented. Note that the overbudget callback | 333 * cache maintenance is implemented. Note that the overbudget callback |
334 * will be called if the initial purge doesn't get the cache under | 334 * will be called if the initial purge doesn't get the cache under |
335 * its budget. | 335 * its budget. |
336 * | 336 * |
337 * extraCount and extraBytes are added to the current resource allocation | 337 * extraCount and extraBytes are added to the current resource allocation |
338 * 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, |
339 * 10MB across 10 textures is about to be added). | 339 * 10MB across 10 textures is about to be added). |
340 */ | 340 */ |
341 void purgeAsNeeded(int extraCount = 0, size_t extraBytes = 0); | 341 void purgeAsNeeded(int extraCount = 0, size_t extraBytes = 0); |
342 | 342 |
343 #if GR_DEBUG | 343 #if SK_DEBUG |
344 void validate() const; | 344 void validate() const; |
345 #else | 345 #else |
346 void validate() const {} | 346 void validate() const {} |
347 #endif | 347 #endif |
348 | 348 |
349 #if GR_CACHE_STATS | 349 #if GR_CACHE_STATS |
350 void printStats(); | 350 void printStats(); |
351 #endif | 351 #endif |
352 | 352 |
353 private: | 353 private: |
354 enum BudgetBehaviors { | 354 enum BudgetBehaviors { |
355 kAccountFor_BudgetBehavior, | 355 kAccountFor_BudgetBehavior, |
356 kIgnore_BudgetBehavior | 356 kIgnore_BudgetBehavior |
357 }; | 357 }; |
358 | 358 |
359 void internalDetach(GrResourceEntry*, BudgetBehaviors behavior = kAccountFor
_BudgetBehavior); | 359 void internalDetach(GrResourceEntry*, BudgetBehaviors behavior = kAccountFor
_BudgetBehavior); |
360 void attachToHead(GrResourceEntry*, BudgetBehaviors behavior = kAccountFor_B
udgetBehavior); | 360 void attachToHead(GrResourceEntry*, BudgetBehaviors behavior = kAccountFor_B
udgetBehavior); |
361 | 361 |
362 void removeInvalidResource(GrResourceEntry* entry); | 362 void removeInvalidResource(GrResourceEntry* entry); |
363 | 363 |
364 GrTHashTable<GrResourceEntry, GrResourceKey, 8> fCache; | 364 GrTHashTable<GrResourceEntry, GrResourceKey, 8> fCache; |
365 | 365 |
366 // We're an internal doubly linked list | 366 // We're an internal doubly linked list |
367 typedef SkTInternalLList<GrResourceEntry> EntryList; | 367 typedef SkTInternalLList<GrResourceEntry> EntryList; |
368 EntryList fList; | 368 EntryList fList; |
369 | 369 |
370 #if GR_DEBUG | 370 #if SK_DEBUG |
371 // These objects cannot be returned by a search | 371 // These objects cannot be returned by a search |
372 EntryList fExclusiveList; | 372 EntryList fExclusiveList; |
373 #endif | 373 #endif |
374 | 374 |
375 // our budget, used in purgeAsNeeded() | 375 // our budget, used in purgeAsNeeded() |
376 int fMaxCount; | 376 int fMaxCount; |
377 size_t fMaxBytes; | 377 size_t fMaxBytes; |
378 | 378 |
379 // our current stats, related to our budget | 379 // our current stats, related to our budget |
380 #if GR_CACHE_STATS | 380 #if GR_CACHE_STATS |
381 int fHighWaterEntryCount; | 381 int fHighWaterEntryCount; |
382 size_t fHighWaterEntryBytes; | 382 size_t fHighWaterEntryBytes; |
383 int fHighWaterClientDetachedCount; | 383 int fHighWaterClientDetachedCount; |
384 size_t fHighWaterClientDetachedBytes; | 384 size_t fHighWaterClientDetachedBytes; |
385 #endif | 385 #endif |
386 | 386 |
387 int fEntryCount; | 387 int fEntryCount; |
388 size_t fEntryBytes; | 388 size_t fEntryBytes; |
389 int fClientDetachedCount; | 389 int fClientDetachedCount; |
390 size_t fClientDetachedBytes; | 390 size_t fClientDetachedBytes; |
391 | 391 |
392 // prevents recursive purging | 392 // prevents recursive purging |
393 bool fPurging; | 393 bool fPurging; |
394 | 394 |
395 PFOverbudgetCB fOverbudgetCB; | 395 PFOverbudgetCB fOverbudgetCB; |
396 void* fOverbudgetData; | 396 void* fOverbudgetData; |
397 | 397 |
398 void internalPurge(int extraCount, size_t extraBytes); | 398 void internalPurge(int extraCount, size_t extraBytes); |
399 | 399 |
400 #if GR_DEBUG | 400 #if SK_DEBUG |
401 static size_t countBytes(const SkTInternalLList<GrResourceEntry>& list); | 401 static size_t countBytes(const SkTInternalLList<GrResourceEntry>& list); |
402 #endif | 402 #endif |
403 }; | 403 }; |
404 | 404 |
405 /////////////////////////////////////////////////////////////////////////////// | 405 /////////////////////////////////////////////////////////////////////////////// |
406 | 406 |
407 #if GR_DEBUG | 407 #if SK_DEBUG |
408 class GrAutoResourceCacheValidate { | 408 class GrAutoResourceCacheValidate { |
409 public: | 409 public: |
410 GrAutoResourceCacheValidate(GrResourceCache* cache) : fCache(cache) { | 410 GrAutoResourceCacheValidate(GrResourceCache* cache) : fCache(cache) { |
411 cache->validate(); | 411 cache->validate(); |
412 } | 412 } |
413 ~GrAutoResourceCacheValidate() { | 413 ~GrAutoResourceCacheValidate() { |
414 fCache->validate(); | 414 fCache->validate(); |
415 } | 415 } |
416 private: | 416 private: |
417 GrResourceCache* fCache; | 417 GrResourceCache* fCache; |
418 }; | 418 }; |
419 #else | 419 #else |
420 class GrAutoResourceCacheValidate { | 420 class GrAutoResourceCacheValidate { |
421 public: | 421 public: |
422 GrAutoResourceCacheValidate(GrResourceCache*) {} | 422 GrAutoResourceCacheValidate(GrResourceCache*) {} |
423 }; | 423 }; |
424 #endif | 424 #endif |
425 | 425 |
426 #endif | 426 #endif |
OLD | NEW |