diff options
author | herb <herb@google.com> | 2015-01-28 14:12:12 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-01-28 14:12:12 -0800 |
commit | f8dd0765c04cd029f90cadd040b18a0724d2a2df (patch) | |
tree | 1c1df089684702dcabfd8a89936bb6958dfba7c6 /src | |
parent | d4dd58e43ca4551531ad6a9f54bfc5632ea45a80 (diff) |
Make char hash dynamic when needed.
BUG=skia:
Review URL: https://codereview.chromium.org/880383002
Diffstat (limited to 'src')
-rwxr-xr-x | src/core/SkGlyphCache.cpp | 27 | ||||
-rw-r--r-- | src/core/SkGlyphCache.h | 5 |
2 files changed, 22 insertions, 10 deletions
diff --git a/src/core/SkGlyphCache.cpp b/src/core/SkGlyphCache.cpp index a26e9f5cd0..57c54bfc1e 100755 --- a/src/core/SkGlyphCache.cpp +++ b/src/core/SkGlyphCache.cpp @@ -69,9 +69,7 @@ SkGlyphCache::SkGlyphCache(SkTypeface* typeface, const SkDescriptor* desc, SkSca // init to 0 so that all of the pointers will be null memset(fGlyphHash, 0, sizeof(fGlyphHash)); - // init with 0xFF so that the charCode field will be -1, which is invalid - memset(fCharToGlyphHash, 0xFF, sizeof(fCharToGlyphHash)); - + fMemoryUsed = sizeof(*this); fGlyphArray.setReserve(kMinGlyphCount); @@ -103,8 +101,8 @@ SkGlyphCache::~SkGlyphCache() { } } - printf("glyphPtrArray,%zu, Alloc,%zu, imageUsed,%zu, glyphUsed,%zu, glyphHashAlloc,%zu, glyphHashUsed,%zu, unicharHashAlloc,%zu, unicharHashUsed,%zu\n", - ptrMem, glyphAlloc, imageUsed, glyphUsed, sizeof(fGlyphHash), glyphHashUsed, sizeof(fCharToGlyphHash), uniHashUsed); + SkDebugf("glyphPtrArray,%zu, Alloc,%zu, imageUsed,%zu, glyphUsed,%zu, glyphHashAlloc,%zu, glyphHashUsed,%zu, unicharHashAlloc,%zu, unicharHashUsed,%zu\n", + ptrMem, glyphAlloc, imageUsed, glyphUsed, sizeof(fGlyphHash), glyphHashUsed, sizeof(CharGlyphRec) * kHashCount, uniHashUsed); } #endif @@ -122,6 +120,17 @@ SkGlyphCache::~SkGlyphCache() { this->invokeAndRemoveAuxProcs(); } +SkGlyphCache::CharGlyphRec* SkGlyphCache::getCharGlyphRec(uint32_t id) { + if (NULL == fCharToGlyphHash.get()) { + fCharToGlyphHash.reset(kHashCount); + // init with 0xFF so that the charCode field will be -1, which is invalid + memset(fCharToGlyphHash.get(), 0xFF, + sizeof(CharGlyphRec) * kHashCount); + } + + return &fCharToGlyphHash[ID2HashIndex(id)]; +} + /////////////////////////////////////////////////////////////////////////////// #ifdef SK_DEBUG @@ -133,7 +142,7 @@ SkGlyphCache::~SkGlyphCache() { uint16_t SkGlyphCache::unicharToGlyph(SkUnichar charCode) { VALIDATE(); uint32_t id = SkGlyph::MakeID(charCode); - const CharGlyphRec& rec = fCharToGlyphHash[ID2HashIndex(id)]; + const CharGlyphRec& rec = *this->getCharGlyphRec(id); if (rec.fID == id) { return rec.fGlyph->getGlyphID(); @@ -155,7 +164,7 @@ unsigned SkGlyphCache::getGlyphCount() { const SkGlyph& SkGlyphCache::getUnicharAdvance(SkUnichar charCode) { VALIDATE(); uint32_t id = SkGlyph::MakeID(charCode); - CharGlyphRec* rec = &fCharToGlyphHash[ID2HashIndex(id)]; + CharGlyphRec* rec = this->getCharGlyphRec(id); if (rec->fID != id) { // this ID is based on the UniChar @@ -185,7 +194,7 @@ const SkGlyph& SkGlyphCache::getGlyphIDAdvance(uint16_t glyphID) { const SkGlyph& SkGlyphCache::getUnicharMetrics(SkUnichar charCode) { VALIDATE(); uint32_t id = SkGlyph::MakeID(charCode); - CharGlyphRec* rec = &fCharToGlyphHash[ID2HashIndex(id)]; + CharGlyphRec* rec = this->getCharGlyphRec(id); if (rec->fID != id) { RecordHashCollisionIf(rec->fGlyph != NULL); @@ -208,7 +217,7 @@ const SkGlyph& SkGlyphCache::getUnicharMetrics(SkUnichar charCode, SkFixed x, SkFixed y) { VALIDATE(); uint32_t id = SkGlyph::MakeID(charCode, x, y); - CharGlyphRec* rec = &fCharToGlyphHash[ID2HashIndex(id)]; + CharGlyphRec* rec = this->getCharGlyphRec(id); if (rec->fID != id) { RecordHashCollisionIf(rec->fGlyph != NULL); diff --git a/src/core/SkGlyphCache.h b/src/core/SkGlyphCache.h index e11a46025e..b335d29d2d 100644 --- a/src/core/SkGlyphCache.h +++ b/src/core/SkGlyphCache.h @@ -209,7 +209,10 @@ private: SkGlyph* fGlyph; }; // no reason to use the same kHashCount as fGlyphHash, but we do for now - CharGlyphRec fCharToGlyphHash[kHashCount]; + // Dynamically allocated when chars are encountered. + SkAutoTArray<CharGlyphRec> fCharToGlyphHash; + + CharGlyphRec* getCharGlyphRec(uint32_t id); static inline unsigned ID2HashIndex(uint32_t h) { return SkChecksum::CheapMix(h) & kHashMask; |