| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2010 Google Inc. | 3 * Copyright 2010 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 | 10 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 * glyphid->strike | 27 * glyphid->strike |
| 28 */ | 28 */ |
| 29 class GrTextStrike { | 29 class GrTextStrike { |
| 30 public: | 30 public: |
| 31 GrTextStrike(GrFontCache*, const GrFontDescKey* fontScalerKey); | 31 GrTextStrike(GrFontCache*, const GrFontDescKey* fontScalerKey); |
| 32 ~GrTextStrike(); | 32 ~GrTextStrike(); |
| 33 | 33 |
| 34 const GrFontDescKey* getFontScalerKey() const { return fFontScalerKey; } | 34 const GrFontDescKey* getFontScalerKey() const { return fFontScalerKey; } |
| 35 GrFontCache* getFontCache() const { return fFontCache; } | 35 GrFontCache* getFontCache() const { return fFontCache; } |
| 36 | 36 |
| 37 inline GrGlyph* getGlyph(GrGlyph::PackedID, GrFontScaler*); | 37 inline GrGlyph* getGlyph(GrGlyph::PackedID packed, GrFontScaler* scaler) { |
| 38 GrGlyph* glyph = fCache.find(packed); |
| 39 if (NULL == glyph) { |
| 40 glyph = this->generateGlyph(packed, scaler); |
| 41 } |
| 42 return glyph; |
| 43 } |
| 44 |
| 38 // returns true if glyph (or glyph+padding for distance field) | 45 // returns true if glyph (or glyph+padding for distance field) |
| 39 // is too large to ever fit in texture atlas subregions (GrPlots) | 46 // is too large to ever fit in texture atlas subregions (GrPlots) |
| 40 bool glyphTooLargeForAtlas(GrGlyph*); | 47 bool glyphTooLargeForAtlas(GrGlyph*); |
| 41 // returns true if glyph successfully added to texture atlas, false otherwis
e | 48 // returns true if glyph successfully added to texture atlas, false otherwis
e |
| 42 bool addGlyphToAtlas(GrGlyph*, GrFontScaler*); | 49 bool addGlyphToAtlas(GrGlyph*, GrFontScaler*); |
| 43 | 50 |
| 44 // testing | 51 // testing |
| 45 int countGlyphs() const { return fCache.count(); } | 52 int countGlyphs() const { return fCache.count(); } |
| 46 | 53 |
| 47 // remove any references to this plot | 54 // remove any references to this plot |
| (...skipping 24 matching lines...) Expand all Loading... |
| 72 GrGlyph* generateGlyph(GrGlyph::PackedID packed, GrFontScaler* scaler); | 79 GrGlyph* generateGlyph(GrGlyph::PackedID packed, GrFontScaler* scaler); |
| 73 | 80 |
| 74 friend class GrFontCache; | 81 friend class GrFontCache; |
| 75 }; | 82 }; |
| 76 | 83 |
| 77 class GrFontCache { | 84 class GrFontCache { |
| 78 public: | 85 public: |
| 79 GrFontCache(GrGpu*); | 86 GrFontCache(GrGpu*); |
| 80 ~GrFontCache(); | 87 ~GrFontCache(); |
| 81 | 88 |
| 82 inline GrTextStrike* getStrike(GrFontScaler*, bool useDistanceField); | 89 inline GrTextStrike* getStrike(GrFontScaler* scaler, bool useDistanceField)
{ |
| 90 this->validate(); |
| 91 |
| 92 GrTextStrike* strike = fCache.find(*(scaler->getKey())); |
| 93 if (NULL == strike) { |
| 94 strike = this->generateStrike(scaler); |
| 95 } else if (strike->fPrev) { |
| 96 // Need to put the strike at the head of its dllist, since that is h
ow |
| 97 // we age the strikes for purging (we purge from the back of the lis
t) |
| 98 this->detachStrikeFromList(strike); |
| 99 // attach at the head |
| 100 fHead->fPrev = strike; |
| 101 strike->fNext = fHead; |
| 102 strike->fPrev = NULL; |
| 103 fHead = strike; |
| 104 } |
| 105 strike->fUseDistanceField = useDistanceField; |
| 106 this->validate(); |
| 107 return strike; |
| 108 } |
| 83 | 109 |
| 84 // add to texture atlas that matches this format | 110 // add to texture atlas that matches this format |
| 85 GrPlot* addToAtlas(GrMaskFormat format, GrAtlas::ClientPlotUsage* usage, | 111 GrPlot* addToAtlas(GrMaskFormat format, GrAtlas::ClientPlotUsage* usage, |
| 86 int width, int height, const void* image, | 112 int width, int height, const void* image, |
| 87 SkIPoint16* loc); | 113 SkIPoint16* loc); |
| 88 | 114 |
| 89 void freeAll(); | 115 void freeAll(); |
| 90 | 116 |
| 91 // make an unused plot available for this glyph | 117 // make an unused plot available for this glyph |
| 92 bool freeUnusedPlot(GrTextStrike* preserveStrike, const GrGlyph* glyph); | 118 bool freeUnusedPlot(GrTextStrike* preserveStrike, const GrGlyph* glyph); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 | 151 |
| 126 SkTDynamicHash<GrTextStrike, GrFontDescKey> fCache; | 152 SkTDynamicHash<GrTextStrike, GrFontDescKey> fCache; |
| 127 // for LRU | 153 // for LRU |
| 128 GrTextStrike* fHead; | 154 GrTextStrike* fHead; |
| 129 GrTextStrike* fTail; | 155 GrTextStrike* fTail; |
| 130 | 156 |
| 131 GrGpu* fGpu; | 157 GrGpu* fGpu; |
| 132 GrAtlas* fAtlases[kAtlasCount]; | 158 GrAtlas* fAtlases[kAtlasCount]; |
| 133 | 159 |
| 134 GrTextStrike* generateStrike(GrFontScaler*); | 160 GrTextStrike* generateStrike(GrFontScaler*); |
| 135 inline void detachStrikeFromList(GrTextStrike*); | 161 |
| 162 inline void detachStrikeFromList(GrTextStrike* strike) { |
| 163 if (strike->fPrev) { |
| 164 SkASSERT(fHead != strike); |
| 165 strike->fPrev->fNext = strike->fNext; |
| 166 } else { |
| 167 SkASSERT(fHead == strike); |
| 168 fHead = strike->fNext; |
| 169 } |
| 170 |
| 171 if (strike->fNext) { |
| 172 SkASSERT(fTail != strike); |
| 173 strike->fNext->fPrev = strike->fPrev; |
| 174 } else { |
| 175 SkASSERT(fTail == strike); |
| 176 fTail = strike->fPrev; |
| 177 } |
| 178 } |
| 179 |
| 136 void purgeStrike(GrTextStrike* strike); | 180 void purgeStrike(GrTextStrike* strike); |
| 137 }; | 181 }; |
| 138 | 182 |
| 139 #endif | 183 #endif |
| OLD | NEW |