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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 } | 105 } |
106 | 106 |
107 void setBudget(size_t budget) { | 107 void setBudget(size_t budget) { |
108 fBudget = budget; | 108 fBudget = budget; |
109 this->checkPurge(); | 109 this->checkPurge(); |
110 } | 110 } |
111 | 111 |
112 private: | 112 private: |
113 typedef SkTInternalLList<GrAtlasTextBlob> BitmapBlobList; | 113 typedef SkTInternalLList<GrAtlasTextBlob> BitmapBlobList; |
114 | 114 |
115 void checkPurge(GrAtlasTextBlob* blob = NULL) { | 115 void checkPurge(GrAtlasTextBlob* blob = nullptr) { |
116 // If we are overbudget, then unref until we are below budget again | 116 // If we are overbudget, then unref until we are below budget again |
117 if (fPool.size() > fBudget) { | 117 if (fPool.size() > fBudget) { |
118 BitmapBlobList::Iter iter; | 118 BitmapBlobList::Iter iter; |
119 iter.init(fBlobList, BitmapBlobList::Iter::kTail_IterStart); | 119 iter.init(fBlobList, BitmapBlobList::Iter::kTail_IterStart); |
120 GrAtlasTextBlob* lruBlob = NULL; | 120 GrAtlasTextBlob* lruBlob = nullptr; |
121 while (fPool.size() > fBudget && (lruBlob = iter.get()) && lruBlob !
= blob) { | 121 while (fPool.size() > fBudget && (lruBlob = iter.get()) && lruBlob !
= blob) { |
122 fCache.remove(lruBlob->fKey); | 122 fCache.remove(lruBlob->fKey); |
123 | 123 |
124 // Backup the iterator before removing and unrefing the blob | 124 // Backup the iterator before removing and unrefing the blob |
125 iter.prev(); | 125 iter.prev(); |
126 fBlobList.remove(lruBlob); | 126 fBlobList.remove(lruBlob); |
127 lruBlob->unref(); | 127 lruBlob->unref(); |
128 } | 128 } |
129 | 129 |
130 // If we break out of the loop with lruBlob == blob, then we haven't
purged enough | 130 // If we break out of the loop with lruBlob == blob, then we haven't
purged enough |
(...skipping 18 matching lines...) Expand all Loading... |
149 static const int kDefaultBudget = 1 << 22; | 149 static const int kDefaultBudget = 1 << 22; |
150 BitmapBlobList fBlobList; | 150 BitmapBlobList fBlobList; |
151 SkTDynamicHash<GrAtlasTextBlob, GrAtlasTextBlob::Key> fCache; | 151 SkTDynamicHash<GrAtlasTextBlob, GrAtlasTextBlob::Key> fCache; |
152 GrMemoryPool fPool; | 152 GrMemoryPool fPool; |
153 PFOverBudgetCB fCallback; | 153 PFOverBudgetCB fCallback; |
154 void* fData; | 154 void* fData; |
155 size_t fBudget; | 155 size_t fBudget; |
156 }; | 156 }; |
157 | 157 |
158 #endif | 158 #endif |
OLD | NEW |