aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2015-01-27 15:10:17 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2015-01-27 15:10:17 -0800
commit95faa61d63a6f62916f6f7be58c4624da8357e3b (patch)
treeff55faa6c29f4e5c80caaeda20daba623b30ab47 /src
parent62bd1a69ea49318aa5022151262c842887e0ecf4 (diff)
patch from issue 885453002 at patchset 20001 (http://crrev.com/885453002#ps20001)
Make the char cache dynamic in SkGlyphCache because it is rarely used. Landing on behalf of Herb. BUG=skia: Review URL: https://codereview.chromium.org/881953002
Diffstat (limited to 'src')
-rwxr-xr-xsrc/core/SkGlyphCache.cpp26
-rw-r--r--src/core/SkGlyphCache.h5
2 files changed, 21 insertions, 10 deletions
diff --git a/src/core/SkGlyphCache.cpp b/src/core/SkGlyphCache.cpp
index 1cbfcd8e6e..bf63ab26ea 100755
--- a/src/core/SkGlyphCache.cpp
+++ b/src/core/SkGlyphCache.cpp
@@ -86,9 +86,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);
@@ -116,8 +114,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
@@ -135,6 +133,16 @@ SkGlyphCache::~SkGlyphCache() {
this->invokeAndRemoveAuxProcs();
}
+SkGlyphCache::CharGlyphRec* SkGlyphCache::getCharGlyphRec(uint32_t id) {
+ if (NULL == fCharToGlyphHash) {
+ fCharToGlyphHash.reset(new CharGlyphRec[kHashCount]);
+ // init with 0xFF so that the charCode field will be -1, which is invalid
+ memset(fCharToGlyphHash, 0xFF, sizeof(CharGlyphRec) * kHashCount);
+ }
+
+ return &fCharToGlyphHash[ID2HashIndex(id)];
+}
+
///////////////////////////////////////////////////////////////////////////////
#ifdef SK_DEBUG
@@ -146,7 +154,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();
@@ -168,7 +176,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
@@ -198,7 +206,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);
@@ -221,7 +229,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 bb34a7d977..a0d4afbc46 100644
--- a/src/core/SkGlyphCache.h
+++ b/src/core/SkGlyphCache.h
@@ -202,7 +202,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.
+ SkAutoTDelete<CharGlyphRec> fCharToGlyphHash;
+
+ CharGlyphRec* getCharGlyphRec(uint32_t id);
static inline unsigned ID2HashIndex(uint32_t id) {
id ^= id >> 16;