OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 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 #include "GrAtlas.h" | 8 #include "GrAtlas.h" |
9 #include "GrGpu.h" | 9 #include "GrGpu.h" |
10 #include "GrRectanizer.h" | 10 #include "GrRectanizer.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 GrTextStrike* strikeToPurge = strike; | 79 GrTextStrike* strikeToPurge = strike; |
80 strike = strikeToPurge->fPrev; | 80 strike = strikeToPurge->fPrev; |
81 if (purge) { | 81 if (purge) { |
82 // keep purging if we won't free up any atlases with this strike. | 82 // keep purging if we won't free up any atlases with this strike. |
83 purge = (NULL == strikeToPurge->fAtlas); | 83 purge = (NULL == strikeToPurge->fAtlas); |
84 int index = fCache.slowFindIndex(strikeToPurge); | 84 int index = fCache.slowFindIndex(strikeToPurge); |
85 GrAssert(index >= 0); | 85 GrAssert(index >= 0); |
86 fCache.removeAt(index, strikeToPurge->fFontScalerKey->getHash()); | 86 fCache.removeAt(index, strikeToPurge->fFontScalerKey->getHash()); |
87 this->detachStrikeFromList(strikeToPurge); | 87 this->detachStrikeFromList(strikeToPurge); |
88 delete strikeToPurge; | 88 delete strikeToPurge; |
89 } else { | |
90 // for the remaining strikes, we just mark them unused | |
91 GrAtlas::MarkAllUnused(strikeToPurge->fAtlas); | |
92 } | 89 } |
93 } | 90 } |
94 #if FONT_CACHE_STATS | 91 #if FONT_CACHE_STATS |
95 ++g_PurgeCount; | 92 ++g_PurgeCount; |
96 #endif | 93 #endif |
97 } | 94 } |
98 | 95 |
99 void GrFontCache::freeAtlasExceptFor(GrTextStrike* preserveStrike) { | 96 void GrFontCache::freeAtlasExceptFor(GrTextStrike* preserveStrike) { |
100 GrTextStrike* strike = fTail; | 97 GrTextStrike* strike = fTail; |
101 while (strike) { | 98 while (strike) { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 // GrPrintf(" GrTextStrike %p %d\n", this, gCounter); | 175 // GrPrintf(" GrTextStrike %p %d\n", this, gCounter); |
179 gCounter += 1; | 176 gCounter += 1; |
180 #endif | 177 #endif |
181 } | 178 } |
182 | 179 |
183 // these signatures are needed because they're used with | 180 // these signatures are needed because they're used with |
184 // SkTDArray::visitAll() (see destructor & removeUnusedAtlases()) | 181 // SkTDArray::visitAll() (see destructor & removeUnusedAtlases()) |
185 static void free_glyph(GrGlyph*& glyph) { glyph->free(); } | 182 static void free_glyph(GrGlyph*& glyph) { glyph->free(); } |
186 | 183 |
187 static void invalidate_glyph(GrGlyph*& glyph) { | 184 static void invalidate_glyph(GrGlyph*& glyph) { |
188 if (glyph->fAtlas && !glyph->fAtlas->used()) { | 185 if (glyph->fAtlas && glyph->fAtlas->drawToken().isIssued()) { |
189 glyph->fAtlas = NULL; | 186 glyph->fAtlas = NULL; |
190 } | 187 } |
191 } | 188 } |
192 | 189 |
193 GrTextStrike::~GrTextStrike() { | 190 GrTextStrike::~GrTextStrike() { |
194 GrAtlas::FreeLList(fAtlas); | 191 GrAtlas::FreeLList(fAtlas); |
195 fFontScalerKey->unref(); | 192 fFontScalerKey->unref(); |
196 fCache.getArray().visitAll(free_glyph); | 193 fCache.getArray().visitAll(free_glyph); |
197 | 194 |
198 #if GR_DEBUG | 195 #if GR_DEBUG |
(...skipping 11 matching lines...) Expand all Loading... |
210 | 207 |
211 GrGlyph* glyph = fPool.alloc(); | 208 GrGlyph* glyph = fPool.alloc(); |
212 glyph->init(packed, bounds); | 209 glyph->init(packed, bounds); |
213 fCache.insert(packed, glyph); | 210 fCache.insert(packed, glyph); |
214 return glyph; | 211 return glyph; |
215 } | 212 } |
216 | 213 |
217 bool GrTextStrike::removeUnusedAtlases() { | 214 bool GrTextStrike::removeUnusedAtlases() { |
218 fCache.getArray().visitAll(invalidate_glyph); | 215 fCache.getArray().visitAll(invalidate_glyph); |
219 return GrAtlas::RemoveUnusedAtlases(fAtlasMgr, &fAtlas); | 216 return GrAtlas::RemoveUnusedAtlases(fAtlasMgr, &fAtlas); |
220 | |
221 return false; | |
222 } | 217 } |
223 | 218 |
224 bool GrTextStrike::getGlyphAtlas(GrGlyph* glyph, GrFontScaler* scaler) { | 219 bool GrTextStrike::getGlyphAtlas(GrGlyph* glyph, GrFontScaler* scaler, |
| 220 GrDrawTarget::DrawToken currentDrawToken) { |
225 #if 0 // testing hack to force us to flush our cache often | 221 #if 0 // testing hack to force us to flush our cache often |
226 static int gCounter; | 222 static int gCounter; |
227 if ((++gCounter % 10) == 0) return false; | 223 if ((++gCounter % 10) == 0) return false; |
228 #endif | 224 #endif |
229 | 225 |
230 GrAssert(glyph); | 226 GrAssert(glyph); |
231 GrAssert(scaler); | 227 GrAssert(scaler); |
232 GrAssert(fCache.contains(glyph)); | 228 GrAssert(fCache.contains(glyph)); |
233 if (glyph->fAtlas) { | 229 if (glyph->fAtlas) { |
234 glyph->fAtlas->setUsed(true); | 230 glyph->fAtlas->setDrawToken(currentDrawToken); |
235 return true; | 231 return true; |
236 } | 232 } |
237 | 233 |
238 GrAutoRef ar(scaler); | 234 GrAutoRef ar(scaler); |
239 | 235 |
240 int bytesPerPixel = GrMaskFormatBytesPerPixel(fMaskFormat); | 236 int bytesPerPixel = GrMaskFormatBytesPerPixel(fMaskFormat); |
241 size_t size = glyph->fBounds.area() * bytesPerPixel; | 237 size_t size = glyph->fBounds.area() * bytesPerPixel; |
242 SkAutoSMalloc<1024> storage(size); | 238 SkAutoSMalloc<1024> storage(size); |
243 if (!scaler->getPackedGlyphImage(glyph->fPackedID, glyph->width(), | 239 if (!scaler->getPackedGlyphImage(glyph->fPackedID, glyph->width(), |
244 glyph->height(), | 240 glyph->height(), |
245 glyph->width() * bytesPerPixel, | 241 glyph->width() * bytesPerPixel, |
246 storage.get())) { | 242 storage.get())) { |
247 return false; | 243 return false; |
248 } | 244 } |
249 | 245 |
250 GrAtlas* atlas = fAtlasMgr->addToAtlas(&fAtlas, glyph->width(), | 246 GrAtlas* atlas = fAtlasMgr->addToAtlas(&fAtlas, glyph->width(), |
251 glyph->height(), storage.get(), | 247 glyph->height(), storage.get(), |
252 fMaskFormat, | 248 fMaskFormat, |
253 &glyph->fAtlasLocation); | 249 &glyph->fAtlasLocation); |
254 if (NULL == atlas) { | 250 if (NULL == atlas) { |
255 return false; | 251 return false; |
256 } | 252 } |
257 | 253 |
258 glyph->fAtlas = atlas; | 254 glyph->fAtlas = atlas; |
259 atlas->setUsed(true); | 255 atlas->setDrawToken(currentDrawToken); |
260 return true; | 256 return true; |
261 } | 257 } |
OLD | NEW |