3 * Copyright 2010 Google Inc.
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
11 #ifndef GrTextStrike_impl_DEFINED
12 #define GrTextStrike_impl_DEFINED
14 class GrFontCache::Key {
16 explicit Key(const GrKey* fontScalarKey) {
17 fFontScalerKey = fontScalarKey;
20 intptr_t getHash() const { return fFontScalerKey->getHash(); }
22 static bool LessThan(const GrTextStrike& strike, const Key& key) {
23 return *strike.getFontScalerKey() < *key.fFontScalerKey;
25 static bool Equals(const GrTextStrike& strike, const Key& key) {
26 return *strike.getFontScalerKey() == *key.fFontScalerKey;
30 const GrKey* fFontScalerKey;
33 void GrFontCache::detachStrikeFromList(GrTextStrike* strike) {
35 SkASSERT(fHead != strike);
36 strike->fPrev->fNext = strike->fNext;
38 SkASSERT(fHead == strike);
39 fHead = strike->fNext;
43 SkASSERT(fTail != strike);
44 strike->fNext->fPrev = strike->fPrev;
46 SkASSERT(fTail == strike);
47 fTail = strike->fPrev;
51 GrTextStrike* GrFontCache::getStrike(GrFontScaler* scaler, bool useDistanceField) {
54 const Key key(scaler->getKey());
55 GrTextStrike* strike = fCache.find(key);
57 strike = this->generateStrike(scaler, key);
58 } else if (strike->fPrev) {
59 // Need to put the strike at the head of its dllist, since that is how
60 // we age the strikes for purging (we purge from the back of the list)
61 this->detachStrikeFromList(strike);
63 fHead->fPrev = strike;
64 strike->fNext = fHead;
68 strike->fUseDistanceField = useDistanceField;
73 ///////////////////////////////////////////////////////////////////////////////
76 * This Key just wraps a glyphID, and matches the protocol need for
79 class GrTextStrike::Key {
81 Key(GrGlyph::PackedID id) : fPackedID(id) {}
83 uint32_t getHash() const { return fPackedID; }
85 static bool LessThan(const GrGlyph& glyph, const Key& key) {
86 return glyph.fPackedID < key.fPackedID;
88 static bool Equals(const GrGlyph& glyph, const Key& key) {
89 return glyph.fPackedID == key.fPackedID;
93 GrGlyph::PackedID fPackedID;
96 GrGlyph* GrTextStrike::getGlyph(GrGlyph::PackedID packed,
97 GrFontScaler* scaler) {
98 GrGlyph* glyph = fCache.find(packed);
100 glyph = this->generateGlyph(packed, scaler);