| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
| 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 #include "SkGlyphCache.h" | 10 #include "SkGlyphCache.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 #endif | 45 #endif |
| 46 #define RecordHashCollision() RecordHashCollisionIf(true) | 46 #define RecordHashCollision() RecordHashCollisionIf(true) |
| 47 | 47 |
| 48 /////////////////////////////////////////////////////////////////////////////// | 48 /////////////////////////////////////////////////////////////////////////////// |
| 49 | 49 |
| 50 #define kMinGlphAlloc (sizeof(SkGlyph) * 64) | 50 #define kMinGlphAlloc (sizeof(SkGlyph) * 64) |
| 51 #define kMinImageAlloc (24 * 64) // should be pointsize-dependent | 51 #define kMinImageAlloc (24 * 64) // should be pointsize-dependent |
| 52 | 52 |
| 53 #define METRICS_RESERVE_COUNT 128 // so we don't grow this array a lot | 53 #define METRICS_RESERVE_COUNT 128 // so we don't grow this array a lot |
| 54 | 54 |
| 55 SkGlyphCache::SkGlyphCache(const SkDescriptor* desc) | 55 SkGlyphCache::SkGlyphCache(SkTypeface* typeface, const SkDescriptor* desc) |
| 56 : fGlyphAlloc(kMinGlphAlloc), fImageAlloc(kMinImageAlloc) { | 56 : fGlyphAlloc(kMinGlphAlloc), fImageAlloc(kMinImageAlloc) { |
| 57 fPrev = fNext = NULL; | 57 fPrev = fNext = NULL; |
| 58 | 58 |
| 59 fDesc = desc->copy(); | 59 fDesc = desc->copy(); |
| 60 fScalerContext = SkScalerContext::Create(desc); | 60 fScalerContext = typeface->createScalerContext(desc); |
| 61 fScalerContext->getFontMetrics(NULL, &fFontMetricsY); | 61 fScalerContext->getFontMetrics(NULL, &fFontMetricsY); |
| 62 | 62 |
| 63 // init to 0 so that all of the pointers will be null | 63 // init to 0 so that all of the pointers will be null |
| 64 memset(fGlyphHash, 0, sizeof(fGlyphHash)); | 64 memset(fGlyphHash, 0, sizeof(fGlyphHash)); |
| 65 // init with 0xFF so that the charCode field will be -1, which is invalid | 65 // init with 0xFF so that the charCode field will be -1, which is invalid |
| 66 memset(fCharToGlyphHash, 0xFF, sizeof(fCharToGlyphHash)); | 66 memset(fCharToGlyphHash, 0xFF, sizeof(fCharToGlyphHash)); |
| 67 | 67 |
| 68 fMemoryUsed = sizeof(*this) + kMinGlphAlloc + kMinImageAlloc; | 68 fMemoryUsed = sizeof(*this) + kMinGlphAlloc + kMinImageAlloc; |
| 69 | 69 |
| 70 fGlyphArray.setReserve(METRICS_RESERVE_COUNT); | 70 fGlyphArray.setReserve(METRICS_RESERVE_COUNT); |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 | 516 |
| 517 globals.validate(); | 517 globals.validate(); |
| 518 } | 518 } |
| 519 | 519 |
| 520 /* This guy calls the visitor from within the mutext lock, so the visitor | 520 /* This guy calls the visitor from within the mutext lock, so the visitor |
| 521 cannot: | 521 cannot: |
| 522 - take too much time | 522 - take too much time |
| 523 - try to acquire the mutext again | 523 - try to acquire the mutext again |
| 524 - call a fontscaler (which might call into the cache) | 524 - call a fontscaler (which might call into the cache) |
| 525 */ | 525 */ |
| 526 SkGlyphCache* SkGlyphCache::VisitCache(const SkDescriptor* desc, | 526 SkGlyphCache* SkGlyphCache::VisitCache(SkTypeface* typeface, |
| 527 const SkDescriptor* desc, |
| 527 bool (*proc)(const SkGlyphCache*, void*), | 528 bool (*proc)(const SkGlyphCache*, void*), |
| 528 void* context) { | 529 void* context) { |
| 529 SkASSERT(desc); | 530 SkASSERT(desc); |
| 530 | 531 |
| 531 SkGlyphCache_Globals& globals = getGlobals(); | 532 SkGlyphCache_Globals& globals = getGlobals(); |
| 532 SkAutoMutexAcquire ac(globals.fMutex); | 533 SkAutoMutexAcquire ac(globals.fMutex); |
| 533 SkGlyphCache* cache; | 534 SkGlyphCache* cache; |
| 534 bool insideMutex = true; | 535 bool insideMutex = true; |
| 535 | 536 |
| 536 globals.validate(); | 537 globals.validate(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 551 goto FOUND_IT; | 552 goto FOUND_IT; |
| 552 } | 553 } |
| 553 } | 554 } |
| 554 | 555 |
| 555 /* Release the mutex now, before we create a new entry (which might have | 556 /* Release the mutex now, before we create a new entry (which might have |
| 556 side-effects like trying to access the cache/mutex (yikes!) | 557 side-effects like trying to access the cache/mutex (yikes!) |
| 557 */ | 558 */ |
| 558 ac.release(); // release the mutex now | 559 ac.release(); // release the mutex now |
| 559 insideMutex = false; // can't use globals anymore | 560 insideMutex = false; // can't use globals anymore |
| 560 | 561 |
| 561 cache = SkNEW_ARGS(SkGlyphCache, (desc)); | 562 cache = SkNEW_ARGS(SkGlyphCache, (typeface, desc)); |
| 562 | 563 |
| 563 FOUND_IT: | 564 FOUND_IT: |
| 564 | 565 |
| 565 AutoValidate av(cache); | 566 AutoValidate av(cache); |
| 566 | 567 |
| 567 if (proc(cache, context)) { // stay detached | 568 if (proc(cache, context)) { // stay detached |
| 568 if (insideMutex) { | 569 if (insideMutex) { |
| 569 SkASSERT(globals.fTotalMemoryUsed >= cache->fMemoryUsed); | 570 SkASSERT(globals.fTotalMemoryUsed >= cache->fMemoryUsed); |
| 570 globals.fTotalMemoryUsed -= cache->fMemoryUsed; | 571 globals.fTotalMemoryUsed -= cache->fMemoryUsed; |
| 571 #ifdef USE_CACHE_HASH | 572 #ifdef USE_CACHE_HASH |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 734 return tls ? tls->getFontCacheLimit() : 0; | 735 return tls ? tls->getFontCacheLimit() : 0; |
| 735 } | 736 } |
| 736 | 737 |
| 737 void SkGraphics::SetTLSFontCacheLimit(size_t bytes) { | 738 void SkGraphics::SetTLSFontCacheLimit(size_t bytes) { |
| 738 if (0 == bytes) { | 739 if (0 == bytes) { |
| 739 SkGlyphCache_Globals::DeleteTLS(); | 740 SkGlyphCache_Globals::DeleteTLS(); |
| 740 } else { | 741 } else { |
| 741 SkGlyphCache_Globals::GetTLS().setFontCacheLimit(bytes); | 742 SkGlyphCache_Globals::GetTLS().setFontCacheLimit(bytes); |
| 742 } | 743 } |
| 743 } | 744 } |
| OLD | NEW |