| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
| 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 "SkGlyphCache.h" | 8 #include "SkGlyphCache.h" |
| 9 #include "SkGlyphCache_Globals.h" | 9 #include "SkGlyphCache_Globals.h" |
| 10 #include "SkGraphics.h" | 10 #include "SkGraphics.h" |
| (...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 this->internalPurge(fTotalMemoryUsed); | 501 this->internalPurge(fTotalMemoryUsed); |
| 502 } | 502 } |
| 503 | 503 |
| 504 /* This guy calls the visitor from within the mutext lock, so the visitor | 504 /* This guy calls the visitor from within the mutext lock, so the visitor |
| 505 cannot: | 505 cannot: |
| 506 - take too much time | 506 - take too much time |
| 507 - try to acquire the mutext again | 507 - try to acquire the mutext again |
| 508 - call a fontscaler (which might call into the cache) | 508 - call a fontscaler (which might call into the cache) |
| 509 */ | 509 */ |
| 510 SkGlyphCache* SkGlyphCache::VisitCache(SkTypeface* typeface, | 510 SkGlyphCache* SkGlyphCache::VisitCache(SkTypeface* typeface, |
| 511 const SkScalerContextEffects& effects, | 511 const SkDescriptor* desc, |
| 512 const SkDescriptor* desc, | 512 bool (*proc)(const SkGlyphCache*, void*), |
| 513 bool (*proc)(const SkGlyphCache*, void*), | 513 void* context) { |
| 514 void* context) { | |
| 515 if (!typeface) { | 514 if (!typeface) { |
| 516 typeface = SkTypeface::GetDefaultTypeface(); | 515 typeface = SkTypeface::GetDefaultTypeface(); |
| 517 } | 516 } |
| 518 SkASSERT(desc); | 517 SkASSERT(desc); |
| 519 | 518 |
| 520 SkGlyphCache_Globals& globals = get_globals(); | 519 SkGlyphCache_Globals& globals = get_globals(); |
| 521 SkGlyphCache* cache; | 520 SkGlyphCache* cache; |
| 522 | 521 |
| 523 { | 522 { |
| 524 Exclusive ac(globals.fLock); | 523 Exclusive ac(globals.fLock); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 536 } | 535 } |
| 537 } | 536 } |
| 538 } | 537 } |
| 539 | 538 |
| 540 // Check if we can create a scaler-context before creating the glyphcache. | 539 // Check if we can create a scaler-context before creating the glyphcache. |
| 541 // If not, we may have exhausted OS/font resources, so try purging the | 540 // If not, we may have exhausted OS/font resources, so try purging the |
| 542 // cache once and try again. | 541 // cache once and try again. |
| 543 { | 542 { |
| 544 // pass true the first time, to notice if the scalercontext failed, | 543 // pass true the first time, to notice if the scalercontext failed, |
| 545 // so we can try the purge. | 544 // so we can try the purge. |
| 546 SkScalerContext* ctx = typeface->createScalerContext(effects, desc, true
); | 545 SkScalerContext* ctx = typeface->createScalerContext(desc, true); |
| 547 if (!ctx) { | 546 if (!ctx) { |
| 548 get_globals().purgeAll(); | 547 get_globals().purgeAll(); |
| 549 ctx = typeface->createScalerContext(effects, desc, false); | 548 ctx = typeface->createScalerContext(desc, false); |
| 550 SkASSERT(ctx); | 549 SkASSERT(ctx); |
| 551 } | 550 } |
| 552 cache = new SkGlyphCache(typeface, desc, ctx); | 551 cache = new SkGlyphCache(typeface, desc, ctx); |
| 553 } | 552 } |
| 554 | 553 |
| 555 AutoValidate av(cache); | 554 AutoValidate av(cache); |
| 556 | 555 |
| 557 if (!proc(cache, context)) { // need to reattach | 556 if (!proc(cache, context)) { // need to reattach |
| 558 globals.attachCacheToHead(cache); | 557 globals.attachCacheToHead(cache); |
| 559 cache = nullptr; | 558 cache = nullptr; |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 814 } | 813 } |
| 815 | 814 |
| 816 void SkGraphics::PurgeFontCache() { | 815 void SkGraphics::PurgeFontCache() { |
| 817 get_globals().purgeAll(); | 816 get_globals().purgeAll(); |
| 818 SkTypefaceCache::PurgeAll(); | 817 SkTypefaceCache::PurgeAll(); |
| 819 } | 818 } |
| 820 | 819 |
| 821 // TODO(herb): clean up TLS apis. | 820 // TODO(herb): clean up TLS apis. |
| 822 size_t SkGraphics::GetTLSFontCacheLimit() { return 0; } | 821 size_t SkGraphics::GetTLSFontCacheLimit() { return 0; } |
| 823 void SkGraphics::SetTLSFontCacheLimit(size_t bytes) { } | 822 void SkGraphics::SetTLSFontCacheLimit(size_t bytes) { } |
| OLD | NEW |