From 1ae57b37bd718418f564e13675b5cfebe499f7db Mon Sep 17 00:00:00 2001 From: herb Date: Wed, 17 Aug 2016 13:51:54 -0700 Subject: [PATCH] Eagerly update the unichar to glyphID mapping. In addition, some small cleanups. BUG=chromium:635005 GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2249063005 Review-Url: https://codereview.chromium.org/2249063005 --- src/core/SkGlyphCache.cpp | 13 +++++++++---- src/core/SkGlyphCache.h | 5 +---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/core/SkGlyphCache.cpp b/src/core/SkGlyphCache.cpp index 6d978a6..40d5997 100644 --- a/src/core/SkGlyphCache.cpp +++ b/src/core/SkGlyphCache.cpp @@ -91,12 +91,17 @@ SkGlyphCache::CharGlyphRec* SkGlyphCache::getCharGlyphRec(PackedUnicharID packed uint16_t SkGlyphCache::unicharToGlyph(SkUnichar charCode) { VALIDATE(); PackedUnicharID packedUnicharID = SkGlyph::MakeID(charCode); - const CharGlyphRec& rec = *this->getCharGlyphRec(packedUnicharID); + CharGlyphRec* rec = this->getCharGlyphRec(packedUnicharID); - if (rec.fPackedUnicharID == packedUnicharID) { - return SkGlyph::ID2Code(rec.fPackedGlyphID); + if (rec->fPackedUnicharID == packedUnicharID) { + // The glyph exists in the unichar to glyph mapping cache. Return it. + return SkGlyph::ID2Code(rec->fPackedGlyphID); } else { - return fScalerContext->charToGlyphID(charCode); + // The glyph is not in the unichar to glyph mapping cache. Insert it. + rec->fPackedUnicharID = packedUnicharID; + uint16_t glyphID = fScalerContext->charToGlyphID(charCode); + rec->fPackedGlyphID = SkGlyph::MakeID(glyphID); + return glyphID; } } diff --git a/src/core/SkGlyphCache.h b/src/core/SkGlyphCache.h index 2a96370..84a32eb 100644 --- a/src/core/SkGlyphCache.h +++ b/src/core/SkGlyphCache.h @@ -227,8 +227,7 @@ private: SkGlyph* lookupByChar(SkUnichar id, MetricsType type, SkFixed x = 0, SkFixed y = 0); // Return a new SkGlyph for the glyph ID and subpixel position id. Limit the amount - // of work - // using type. + // of work using type. SkGlyph* allocateNewGlyph(PackedGlyphID packedGlyphID, MetricsType type); static bool DetachProc(const SkGlyphCache*, void*) { return true; } @@ -238,8 +237,6 @@ private: void invokeAndRemoveAuxProcs(); - inline static SkGlyphCache* FindTail(SkGlyphCache* head); - static void OffsetResults(const SkGlyph::Intercept* intercept, SkScalar scale, SkScalar xPos, SkScalar* array, int* count); static void AddInterval(SkScalar val, SkGlyph::Intercept* intercept); -- 2.7.4