のねのBlog

パソコンの問題や、ソフトウェアの開発で起きた問題など書いていきます。よろしくお願いします^^。

getAdvanced

  236 SkGlyph* SkGlyphCache::lookupMetrics(uint32_t id, MetricsType mtype) {
    237     SkGlyph* glyph;
    238 
    239     int     hi = 0;
    240     int     count = fGlyphArray.count();
    241 
    242     if (count) {
    243         SkGlyph**   gptr = fGlyphArray.begin();
    244         int     lo = 0;
    245 
    246         hi = count - 1;
    247         while (lo < hi) {
    248             int mid = (hi + lo) >> 1;
    249             if (gptr[mid]->fID < id) {
    250                 lo = mid + 1;
    251             } else {
    252                 hi = mid;
    253             }
    254         }
    255         glyph = gptr[hi];
    256         if (glyph->fID == id) {
    257             if (kFull_MetricsType == mtype && glyph->isJustAdvance()) {
    258                 fScalerContext->getMetrics(glyph);
    259             }
    260             return glyph;
    261         }
    262 
    263         // check if we need to bump hi before falling though to the allocator
    264         if (glyph->fID < id) {
    265             hi += 1;
    266         }
    267     }
    268 
    269     // not found, but hi tells us where to inser the new glyph
    270     fMemoryUsed += sizeof(SkGlyph);
    271 
    272     glyph = (SkGlyph*)fGlyphAlloc.alloc(sizeof(SkGlyph),
    273                                         SkChunkAlloc::kThrow_AllocFailType);
    274     glyph->init(id);
    275     *fGlyphArray.insert(hi) = glyph;
    276 
    277     if (kJustAdvance_MetricsType == mtype) {
    278         fScalerContext->getAdvance(glyph); <=================== Advance
    279         fAdvanceCount += 1;
    280     } else {
    281         SkASSERT(kFull_MetricsType == mtype);
    282         fScalerContext->getMetrics(glyph); <=================== Metrics
    283         fMetricsCount += 1;
    284     }
    285 
    286     return glyph;
    287 }
    /external/skia/src/core/SkGlyphCache.h
    202     enum MetricsType {
    203         kJustAdvance_MetricsType,
    204         kFull_MetricsType
    205     };

    118 ///////////////////////////////////////////////////////////////////////////////
    119 
    120 const SkGlyph& SkGlyphCache::getUnicharAdvance(SkUnichar charCode) {
    121     VALIDATE();
    122     uint32_t id = SkGlyph::MakeID(charCode);
    123     CharGlyphRec* rec = &fCharToGlyphHash[ID2HashIndex(id)];
    124 
    125     if (rec->fID != id) {
    126         // this ID is based on the UniChar
    127         rec->fID = id;
    128         // this ID is based on the glyph index
    129         id = SkGlyph::MakeID(fScalerContext->charToGlyphID(charCode));
    130         rec->fGlyph = this->lookupMetrics(id, kJustAdvance_MetricsType); <===========
    131     }
    132     return *rec->fGlyph;
    133 }
    134 
    135 const SkGlyph& SkGlyphCache::getGlyphIDAdvance(uint16_t glyphID) {
    136     VALIDATE();
    137     uint32_t id = SkGlyph::MakeID(glyphID);
    138     unsigned index = ID2HashIndex(id);
    139     SkGlyph* glyph = fGlyphHash[index];
    140 
    141     if (NULL == glyph || glyph->fID != id) {
    142         glyph = this->lookupMetrics(glyphID, kJustAdvance_MetricsType); <==========
    143         fGlyphHash[index] = glyph;
    144     }
    145     return *glyph;
    146 }

    148 ///////////////////////////////////////////////////////////////////////////////
    149 
    150 const SkGlyph& SkGlyphCache::getUnicharMetrics(SkUnichar charCode) {
    151     VALIDATE();
    152     uint32_t id = SkGlyph::MakeID(charCode);
    153     CharGlyphRec* rec = &fCharToGlyphHash[ID2HashIndex(id)];
    154 
    155     if (rec->fID != id) {
    156         RecordHashCollisionIf(rec->fGlyph != NULL);
    157         // this ID is based on the UniChar
    158         rec->fID = id;
    159         // this ID is based on the glyph index
    160         id = SkGlyph::MakeID(fScalerContext->charToGlyphID(charCode));
    161         rec->fGlyph = this->lookupMetrics(id, kFull_MetricsType); <==============
    162     } else {
    163         RecordHashSuccess();
    164         if (rec->fGlyph->isJustAdvance()) {
    165             fScalerContext->getMetrics(rec->fGlyph);
    166         }
    167     }
    168     SkASSERT(rec->fGlyph->isFullMetrics());
    169     return *rec->fGlyph;
    170 }
    171 
    172 const SkGlyph& SkGlyphCache::getUnicharMetrics(SkUnichar charCode,
    173                                                SkFixed x, SkFixed y) {
    174     VALIDATE();
    175     uint32_t id = SkGlyph::MakeID(charCode, x, y);
    176     CharGlyphRec* rec = &fCharToGlyphHash[ID2HashIndex(id)];
    177 
    178     if (rec->fID != id) {
    179         RecordHashCollisionIf(rec->fGlyph != NULL);
    180         // this ID is based on the UniChar
    181         rec->fID = id;
    182         // this ID is based on the glyph index
    183         id = SkGlyph::MakeID(fScalerContext->charToGlyphID(charCode), x, y);
    184         rec->fGlyph = this->lookupMetrics(id, kFull_MetricsType); <=================
    185     } else {
    186         RecordHashSuccess();
    187         if (rec->fGlyph->isJustAdvance()) {
    188             fScalerContext->getMetrics(rec->fGlyph);
    189         }
    190     }
    191     SkASSERT(rec->fGlyph->isFullMetrics());
    192     return *rec->fGlyph;
    193 }
    194 
    195 const SkGlyph& SkGlyphCache::getGlyphIDMetrics(uint16_t glyphID) {
    196     VALIDATE();
    197     uint32_t id = SkGlyph::MakeID(glyphID);
    198     unsigned index = ID2HashIndex(id);
    199     SkGlyph* glyph = fGlyphHash[index];
    200 
    201     if (NULL == glyph || glyph->fID != id) {
    202         RecordHashCollisionIf(glyph != NULL);
    203         glyph = this->lookupMetrics(glyphID, kFull_MetricsType); <================
    204         fGlyphHash[index] = glyph;
    205     } else {
    206         RecordHashSuccess();
    207         if (glyph->isJustAdvance()) {
    208             fScalerContext->getMetrics(glyph);
    209         }
    210     }
    211     SkASSERT(glyph->isFullMetrics());
    212     return *glyph;
    213 }
    214 
    215 const SkGlyph& SkGlyphCache::getGlyphIDMetrics(uint16_t glyphID,
    216                                                SkFixed x, SkFixed y) {
    217     VALIDATE();
    218     uint32_t id = SkGlyph::MakeID(glyphID, x, y);
    219     unsigned index = ID2HashIndex(id);
    220     SkGlyph* glyph = fGlyphHash[index];
    221 
    222     if (NULL == glyph || glyph->fID != id) {
    223         RecordHashCollisionIf(glyph != NULL);
    224         glyph = this->lookupMetrics(id, kFull_MetricsType); <=====================
    225         fGlyphHash[index] = glyph;
    226     } else {
    227         RecordHashSuccess();
    228         if (glyph->isJustAdvance()) {
    229             fScalerContext->getMetrics(glyph);
    230         }
    231     }
    232     SkASSERT(glyph->isFullMetrics());
    233     return *glyph;
    234 }