**
** Copyright 2006, The Android Open Source Project
**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
**
-** http://www.apache.org/licenses/LICENSE-2.0
+** http://www.apache.org/licenses/LICENSE-2.0
**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
** limitations under the License.
*/
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);
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) + kMinGlphAlloc + kMinImageAlloc;
-
+
fGlyphArray.setReserve(METRICS_RESERVE_COUNT);
fMetricsCount = 0;
VALIDATE();
uint32_t id = SkGlyph::MakeID(charCode);
const CharGlyphRec& rec = fCharToGlyphHash[ID2HashIndex(id)];
-
+
if (rec.fID == id) {
return rec.fGlyph->getGlyphID();
} else {
VALIDATE();
uint32_t id = SkGlyph::MakeID(charCode);
CharGlyphRec* rec = &fCharToGlyphHash[ID2HashIndex(id)];
-
+
if (rec->fID != id) {
// this ID is based on the UniChar
rec->fID = id;
VALIDATE();
uint32_t id = SkGlyph::MakeID(charCode);
CharGlyphRec* rec = &fCharToGlyphHash[ID2HashIndex(id)];
-
+
if (rec->fID != id) {
RecordHashCollisionIf(rec->fGlyph != NULL);
// this ID is based on the UniChar
VALIDATE();
uint32_t id = SkGlyph::MakeID(charCode, x, y);
CharGlyphRec* rec = &fCharToGlyphHash[ID2HashIndex(id)];
-
+
if (rec->fID != id) {
RecordHashCollisionIf(rec->fGlyph != NULL);
// this ID is based on the UniChar
uint32_t id = SkGlyph::MakeID(glyphID);
unsigned index = ID2HashIndex(id);
SkGlyph* glyph = fGlyphHash[index];
-
+
if (NULL == glyph || glyph->fID != id) {
RecordHashCollisionIf(glyph != NULL);
glyph = this->lookupMetrics(glyphID, kFull_MetricsType);
SkChunkAlloc::kThrow_AllocFailType);
glyph->init(id);
*fGlyphArray.insert(hi) = glyph;
-
+
if (kJustAdvance_MetricsType == mtype) {
fScalerContext->getAdvance(glyph);
fAdvanceCount += 1;
size_t size = glyph.computeImageSize();
const_cast<SkGlyph&>(glyph).fImage = fImageAlloc.alloc(size,
SkChunkAlloc::kReturnNil_AllocFailType);
- fScalerContext->getImage(glyph);
- fMemoryUsed += size;
+ // check that alloc() actually succeeded
+ if (glyph.fImage) {
+ fScalerContext->getImage(glyph);
+ fMemoryUsed += size;
+ }
}
}
return glyph.fImage;
#define HASH_BITCOUNT 6
#define HASH_COUNT (1 << HASH_BITCOUNT)
#define HASH_MASK (HASH_COUNT - 1)
-
+
static unsigned desc_to_hashindex(const SkDescriptor* desc)
{
SkASSERT(HASH_MASK < 256); // since our munging reduces to 8 bits
SkGlyphCache_Globals& globals = FIND_GC_GLOBALS();
SkAutoMutexAcquire ac(globals.fMutex);
SkGlyphCache* cache;
-
+
globals.validate();
-
+
for (cache = globals.fHead; cache != NULL; cache = cache->fNext) {
if (proc(cache, context)) {
break;
size_t SkGlyphCache::GetCacheUsed() {
SkGlyphCache_Globals& globals = FIND_GC_GLOBALS();
SkAutoMutexAcquire ac(globals.fMutex);
-
+
return SkGlyphCache::ComputeMemoryUsed(globals.fHead);
}
if (curr > bytesUsed) {
SkGlyphCache_Globals& globals = FIND_GC_GLOBALS();
SkAutoMutexAcquire ac(globals.fMutex);
-
+
return InternalFreeCache(&globals, curr - bytesUsed) > 0;
}
return false;
size_t SkGlyphCache::ComputeMemoryUsed(const SkGlyphCache* head) {
size_t size = 0;
-
+
while (head != NULL) {
size += head->fMemoryUsed;
head = head->fNext;