| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 GrTextBlobCache_DEFINED | 8 #ifndef GrTextBlobCache_DEFINED |
| 9 #define GrTextBlobCache_DEFINED | 9 #define GrTextBlobCache_DEFINED |
| 10 | 10 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 fBlobList.addToHead(blob); | 58 fBlobList.addToHead(blob); |
| 59 | 59 |
| 60 // If we are overbudget, then unref until we are below budget again | 60 // If we are overbudget, then unref until we are below budget again |
| 61 if (fPool.size() > kBudget) { | 61 if (fPool.size() > kBudget) { |
| 62 BitmapBlobList::Iter iter; | 62 BitmapBlobList::Iter iter; |
| 63 iter.init(fBlobList, BitmapBlobList::Iter::kTail_IterStart); | 63 iter.init(fBlobList, BitmapBlobList::Iter::kTail_IterStart); |
| 64 BitmapTextBlob* lruBlob = iter.get(); | 64 BitmapTextBlob* lruBlob = iter.get(); |
| 65 SkASSERT(lruBlob); | 65 SkASSERT(lruBlob); |
| 66 while (fPool.size() > kBudget && (lruBlob = iter.get()) && lruBlob !
= blob) { | 66 while (fPool.size() > kBudget && (lruBlob = iter.get()) && lruBlob !
= blob) { |
| 67 fCache.remove(lruBlob->fUniqueID); | 67 fCache.remove(lruBlob->fUniqueID); |
| 68 |
| 69 // Backup the iterator before removing and unrefing the blob |
| 70 iter.prev(); |
| 68 fBlobList.remove(lruBlob); | 71 fBlobList.remove(lruBlob); |
| 69 iter.prev(); | |
| 70 lruBlob->unref(); | 72 lruBlob->unref(); |
| 71 } | 73 } |
| 72 | 74 |
| 73 // If we break out of the loop with lruBlob == blob, then we haven't
purged enough | 75 // If we break out of the loop with lruBlob == blob, then we haven't
purged enough |
| 74 // use the call back and try to free some more. If we are still ove
rbudget after this, | 76 // use the call back and try to free some more. If we are still ove
rbudget after this, |
| 75 // then this single textblob is over our budget | 77 // then this single textblob is over our budget |
| 76 if (lruBlob == blob) { | 78 if (lruBlob == blob) { |
| 77 (*fCallback)(fData); | 79 (*fCallback)(fData); |
| 78 } | 80 } |
| 79 | 81 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 static const int kMinGrowthSize = 1 << 17; | 113 static const int kMinGrowthSize = 1 << 17; |
| 112 static const int kBudget = 1 << 22; | 114 static const int kBudget = 1 << 22; |
| 113 BitmapBlobList fBlobList; | 115 BitmapBlobList fBlobList; |
| 114 SkTDynamicHash<BitmapTextBlob, uint32_t> fCache; | 116 SkTDynamicHash<BitmapTextBlob, uint32_t> fCache; |
| 115 GrMemoryPool fPool; | 117 GrMemoryPool fPool; |
| 116 PFOverBudgetCB fCallback; | 118 PFOverBudgetCB fCallback; |
| 117 void* fData; | 119 void* fData; |
| 118 }; | 120 }; |
| 119 | 121 |
| 120 #endif | 122 #endif |
| OLD | NEW |