Chromium Code Reviews| 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 return SkGlyph::ID2Code(rec.fPackedGlyphID); | 97 return SkGlyph::ID2Code(rec.fPackedGlyphID); |
| 98 } else { | 98 } else { |
| 99 return fScalerContext->charToGlyphID(charCode); | 99 return fScalerContext->charToGlyphID(charCode); |
| 100 } | 100 } |
| 101 } | 101 } |
| 102 | 102 |
| 103 SkUnichar SkGlyphCache::glyphToUnichar(uint16_t glyphID) { | 103 SkUnichar SkGlyphCache::glyphToUnichar(uint16_t glyphID) { |
| 104 return fScalerContext->glyphIDToChar(glyphID); | 104 return fScalerContext->glyphIDToChar(glyphID); |
| 105 } | 105 } |
| 106 | 106 |
| 107 unsigned SkGlyphCache::getGlyphCount() { | 107 unsigned SkGlyphCache::getGlyphCount() const { |
| 108 return fScalerContext->getGlyphCount(); | 108 return fScalerContext->getGlyphCount(); |
| 109 } | 109 } |
| 110 | 110 |
| 111 int SkGlyphCache::countCachedGlyphs() const { | |
| 112 return fGlyphMap.count(); | |
| 113 } | |
| 114 | |
| 111 /////////////////////////////////////////////////////////////////////////////// | 115 /////////////////////////////////////////////////////////////////////////////// |
| 112 | 116 |
| 113 const SkGlyph& SkGlyphCache::getUnicharAdvance(SkUnichar charCode) { | 117 const SkGlyph& SkGlyphCache::getUnicharAdvance(SkUnichar charCode) { |
| 114 VALIDATE(); | 118 VALIDATE(); |
| 115 return *this->lookupByChar(charCode, kJustAdvance_MetricsType); | 119 return *this->lookupByChar(charCode, kJustAdvance_MetricsType); |
| 116 } | 120 } |
| 117 | 121 |
| 118 const SkGlyph& SkGlyphCache::getGlyphIDAdvance(uint16_t glyphID) { | 122 const SkGlyph& SkGlyphCache::getGlyphIDAdvance(uint16_t glyphID) { |
| 119 VALIDATE(); | 123 VALIDATE(); |
| 120 PackedGlyphID packedGlyphID = SkGlyph::MakeID(glyphID); | 124 PackedGlyphID packedGlyphID = SkGlyph::MakeID(glyphID); |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 395 return cache; | 399 return cache; |
| 396 } | 400 } |
| 397 | 401 |
| 398 void SkGlyphCache::AttachCache(SkGlyphCache* cache) { | 402 void SkGlyphCache::AttachCache(SkGlyphCache* cache) { |
| 399 SkASSERT(cache); | 403 SkASSERT(cache); |
| 400 SkASSERT(cache->fNext == NULL); | 404 SkASSERT(cache->fNext == NULL); |
| 401 | 405 |
| 402 get_globals().attachCacheToHead(cache); | 406 get_globals().attachCacheToHead(cache); |
| 403 } | 407 } |
| 404 | 408 |
| 409 static void dump_visitor(const SkGlyphCache& cache, void* context) { | |
| 410 int* counter = (int*)context; | |
| 411 int index = *counter; | |
| 412 *counter += 1; | |
| 413 | |
| 414 const SkScalerContextRec& rec = cache.getScalerContext()->getRec(); | |
| 415 | |
| 416 SkDebugf("[%3d] ID %3d, glyphs %3d, size %g, scale %g, skew %g, [%g %g %g %g ]\n", | |
| 417 index, rec.fFontID, cache.countCachedGlyphs(), | |
| 418 rec.fTextSize, rec.fPreScaleX, rec.fPreSkewX, | |
| 419 rec.fPost2x2[0][0], rec.fPost2x2[0][1], rec.fPost2x2[1][0], rec.fPo st2x2[1][1]); | |
| 420 } | |
| 421 | |
| 405 void SkGlyphCache::Dump() { | 422 void SkGlyphCache::Dump() { |
| 423 SkDebugf("GlyphCache [ used budget ]\n"); | |
|
ssid
2015/08/07 23:42:11
We are looking to add these memory statistics to c
reed1
2015/08/11 13:44:19
SkGlyphCache::Dump() exists just as a client of th
| |
| 424 SkDebugf(" bytes [ %8zu %8zu ]\n", | |
| 425 SkGraphics::GetFontCacheUsed(), SkGraphics::GetFontCacheLimit()); | |
| 426 SkDebugf(" count [ %8zu %8zu ]\n", | |
| 427 SkGraphics::GetFontCacheCountUsed(), SkGraphics::GetFontCacheCountL imit()); | |
| 428 | |
| 429 int counter = 0; | |
| 430 SkGlyphCache::VisitAll(dump_visitor, &counter); | |
| 431 } | |
| 432 | |
| 433 void SkGlyphCache::VisitAll(Visitor visitor, void* context) { | |
| 406 SkGlyphCache_Globals& globals = get_globals(); | 434 SkGlyphCache_Globals& globals = get_globals(); |
| 407 AutoAcquire ac(globals.fLock); | 435 AutoAcquire ac(globals.fLock); |
| 408 SkGlyphCache* cache; | 436 SkGlyphCache* cache; |
| 409 | 437 |
| 410 globals.validate(); | 438 globals.validate(); |
| 411 | 439 |
| 412 SkDebugf("SkGlyphCache strikes:%d memory:%d\n", | |
| 413 globals.getCacheCountUsed(), (int)globals.getTotalMemoryUsed()); | |
| 414 | |
| 415 for (cache = globals.internalGetHead(); cache != NULL; cache = cache->fNext) { | 440 for (cache = globals.internalGetHead(); cache != NULL; cache = cache->fNext) { |
| 416 cache->dump(); | 441 visitor(*cache, context); |
| 417 } | 442 } |
| 418 } | 443 } |
| 419 | 444 |
| 420 /////////////////////////////////////////////////////////////////////////////// | 445 /////////////////////////////////////////////////////////////////////////////// |
| 421 | 446 |
| 422 void SkGlyphCache_Globals::attachCacheToHead(SkGlyphCache* cache) { | 447 void SkGlyphCache_Globals::attachCacheToHead(SkGlyphCache* cache) { |
| 423 AutoAcquire ac(fLock); | 448 AutoAcquire ac(fLock); |
| 424 | 449 |
| 425 this->validate(); | 450 this->validate(); |
| 426 cache->validate(); | 451 cache->validate(); |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 587 } | 612 } |
| 588 | 613 |
| 589 void SkGraphics::PurgeFontCache() { | 614 void SkGraphics::PurgeFontCache() { |
| 590 get_globals().purgeAll(); | 615 get_globals().purgeAll(); |
| 591 SkTypefaceCache::PurgeAll(); | 616 SkTypefaceCache::PurgeAll(); |
| 592 } | 617 } |
| 593 | 618 |
| 594 // TODO(herb): clean up TLS apis. | 619 // TODO(herb): clean up TLS apis. |
| 595 size_t SkGraphics::GetTLSFontCacheLimit() { return 0; } | 620 size_t SkGraphics::GetTLSFontCacheLimit() { return 0; } |
| 596 void SkGraphics::SetTLSFontCacheLimit(size_t bytes) { } | 621 void SkGraphics::SetTLSFontCacheLimit(size_t bytes) { } |
| OLD | NEW |