Chromium Code Reviews| Index: src/core/SkGlyphCache.cpp |
| diff --git a/src/core/SkGlyphCache.cpp b/src/core/SkGlyphCache.cpp |
| index 1cbfcd8e6e9fa235610a0c459b469a1e8a4ff718..6e253919e07123bf6db934e0f279640299594789 100755 |
| --- a/src/core/SkGlyphCache.cpp |
| +++ b/src/core/SkGlyphCache.cpp |
| @@ -1,4 +1,3 @@ |
| - |
| /* |
| * Copyright 2006 The Android Open Source Project |
| * |
| @@ -6,7 +5,6 @@ |
| * found in the LICENSE file. |
| */ |
| - |
| #include "SkGlyphCache.h" |
| #include "SkGlyphCache_Globals.h" |
| #include "SkGraphics.h" |
| @@ -18,7 +16,6 @@ |
| #include "SkTypeface.h" |
| //#define SPEW_PURGE_STATUS |
| -//#define RECORD_HASH_EFFICIENCY |
| namespace { |
| @@ -43,26 +40,12 @@ static SkGlyphCache_Globals& getGlobals() { |
| /////////////////////////////////////////////////////////////////////////////// |
| -#ifdef RECORD_HASH_EFFICIENCY |
| - static uint32_t gHashSuccess; |
| - static uint32_t gHashCollision; |
| - |
| - static void RecordHashSuccess() { |
| - gHashSuccess += 1; |
| - } |
| - |
| - static void RecordHashCollisionIf(bool pred) { |
| - if (pred) { |
| - gHashCollision += 1; |
| - |
| - uint32_t total = gHashSuccess + gHashCollision; |
| - SkDebugf("Font Cache Hash success rate: %d%%\n", |
| - 100 * gHashSuccess / total); |
| - } |
| - } |
| +#ifdef SK_GLYPHCACHE_TRACK_HASH_STATS |
| + #define RecordHashSuccess() fHashHitCount += 1 |
| + #define RecordHashCollisionIf(pred) do { if (pred) fHashMissCount += 1; } while (0) |
| #else |
| - #define RecordHashSuccess() (void)0 |
| - #define RecordHashCollisionIf(pred) (void)0 |
| + #define RecordHashSuccess() (void)0 |
| + #define RecordHashCollisionIf(pred) (void)0 |
| #endif |
| #define RecordHashCollision() RecordHashCollisionIf(true) |
| @@ -94,6 +77,10 @@ SkGlyphCache::SkGlyphCache(SkTypeface* typeface, const SkDescriptor* desc, SkSca |
| fGlyphArray.setReserve(kMinGlyphCount); |
| fAuxProcList = NULL; |
| + |
| +#ifdef SK_GLYPHCACHE_TRACK_HASH_STATS |
| + fHashHitCount = fHashMissCount = 1; |
|
mtklein
2015/01/27 17:10:12
0?
reed1
2015/01/27 18:33:33
Yea, OK. That will make it more complicated for me
|
| +#endif |
| } |
| SkGlyphCache::~SkGlyphCache() { |
| @@ -260,8 +247,7 @@ const SkGlyph& SkGlyphCache::getGlyphIDMetrics(uint16_t glyphID) { |
| return *glyph; |
| } |
| -const SkGlyph& SkGlyphCache::getGlyphIDMetrics(uint16_t glyphID, |
| - SkFixed x, SkFixed y) { |
| +const SkGlyph& SkGlyphCache::getGlyphIDMetrics(uint16_t glyphID, SkFixed x, SkFixed y) { |
| VALIDATE(); |
| uint32_t id = SkGlyph::MakeID(glyphID, x, y); |
| unsigned index = ID2HashIndex(id); |
| @@ -364,6 +350,27 @@ const SkPath* SkGlyphCache::findPath(const SkGlyph& glyph) { |
| return glyph.fPath; |
| } |
| +void SkGlyphCache::dump() const { |
| + const SkTypeface* face = fScalerContext->getTypeface(); |
| + const SkScalerContextRec& rec = fScalerContext->getRec(); |
| + SkMatrix matrix; |
| + rec.getSingleMatrixWithoutTextSize(&matrix); |
| + SkString name; |
| + face->getFamilyName(&name); |
| + |
| + SkString msg; |
| + msg.printf("cache typeface:%x %25s:%d size:%2g [%g %g %g %g] lum:%02X devG:%d pntG:%d cntr:%d glyphs:%3d", |
| + face->uniqueID(), name.c_str(), face->style(), rec.fTextSize, |
| + matrix[SkMatrix::kMScaleX], matrix[SkMatrix::kMSkewX], |
| + matrix[SkMatrix::kMSkewY], matrix[SkMatrix::kMScaleY], |
| + rec.fLumBits & 0xFF, rec.fDeviceGamma, rec.fPaintGamma, rec.fContrast, |
| + fGlyphArray.count()); |
| +#ifdef SK_GLYPHCACHE_TRACK_HASH_STATS |
| + msg.appendf(" hash:%2d\n", 100 * fHashHitCount / (fHashHitCount + fHashMissCount)); |
| +#endif |
| + SkDebugf("%s\n", msg.c_str()); |
| +} |
| + |
| /////////////////////////////////////////////////////////////////////////////// |
| bool SkGlyphCache::getAuxProcData(void (*proc)(void*), void** dataPtr) const { |
| @@ -520,6 +527,33 @@ void SkGlyphCache::AttachCache(SkGlyphCache* cache) { |
| getGlobals().attachCacheToHead(cache); |
| } |
| +void SkGlyphCache::Dump() { |
| + SkGlyphCache_Globals& globals = getGlobals(); |
| + SkAutoMutexAcquire ac(globals.fMutex); |
| + SkGlyphCache* cache; |
| + |
| + globals.validate(); |
| + |
| + SkDebugf("SkGlyphCache strikes:%d memory:%d\n", |
| + globals.getCacheCountUsed(), (int)globals.getTotalMemoryUsed()); |
| + |
| +#ifdef SK_GLYPHCACHE_TRACK_HASH_STATS |
| + int hitCount = 0; |
| + int missCount = 0; |
| +#endif |
| + |
| + for (cache = globals.internalGetHead(); cache != NULL; cache = cache->fNext) { |
| +#ifdef SK_GLYPHCACHE_TRACK_HASH_STATS |
| + hitCount += cache->fHashHitCount; |
| + missCount += cache->fHashMissCount; |
| +#endif |
| + cache->dump(); |
| + } |
| +#ifdef SK_GLYPHCACHE_TRACK_HASH_STATS |
| + SkDebugf("Hash hit percent:%2d\n", 100 * hitCount / (hitCount + missCount)); |
| +#endif |
| +} |
| + |
| /////////////////////////////////////////////////////////////////////////////// |
| void SkGlyphCache_Globals::attachCacheToHead(SkGlyphCache* cache) { |