| 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 |
| 11 #ifndef GrTextStrike_DEFINED | 11 #ifndef GrTextStrike_DEFINED |
| 12 #define GrTextStrike_DEFINED | 12 #define GrTextStrike_DEFINED |
| 13 | 13 |
| 14 #include "GrAllocPool.h" | 14 #include "GrAllocPool.h" |
| 15 #include "GrFontScaler.h" | 15 #include "GrFontScaler.h" |
| 16 #include "SkTDynamicHash.h" | 16 #include "SkTDynamicHash.h" |
| 17 #include "GrGlyph.h" | 17 #include "GrGlyph.h" |
| 18 #include "GrDrawTarget.h" | 18 #include "GrDrawTarget.h" |
| 19 #include "GrAtlas.h" | 19 #include "GrAtlas.h" |
| 20 | 20 |
| 21 class GrFontCache; | 21 class GrFontCache; |
| 22 class GrGpu; | 22 class GrGpu; |
| 23 class GrFontPurgeListener; | 23 class GrFontPurgeListener; |
| 24 | 24 |
| 25 /** | 25 /** |
| 26 * The textstrike maps a hostfontscaler instance to a dictionary of | 26 * The textcache maps a hostfontscaler instance to a dictionary of |
| 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, GrMaskFormat,
GrAtlas*); |
| 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 GrMaskFormat getMaskFormat() const { return fMaskFormat; } |
| 37 GrTexture* getTexture() const { return fAtlas->getTexture(); } |
| 36 | 38 |
| 37 inline GrGlyph* getGlyph(GrGlyph::PackedID, GrFontScaler*); | 39 inline GrGlyph* getGlyph(GrGlyph::PackedID, GrFontScaler*); |
| 38 // returns true if glyph (or glyph+padding for distance field) | 40 // returns true if glyph (or glyph+padding for distance field) |
| 39 // is too large to ever fit in texture atlas subregions (GrPlots) | 41 // is too large to ever fit in texture atlas subregions (GrPlots) |
| 40 bool glyphTooLargeForAtlas(GrGlyph*); | 42 bool glyphTooLargeForAtlas(GrGlyph*); |
| 41 // returns true if glyph successfully added to texture atlas, false otherwis
e | 43 // returns true if glyph successfully added to texture atlas, false otherwis
e |
| 42 bool addGlyphToAtlas(GrGlyph*, GrFontScaler*); | 44 bool addGlyphToAtlas(GrGlyph*, GrFontScaler*); |
| 43 | 45 |
| 44 // testing | 46 // testing |
| 45 int countGlyphs() const { return fCache.count(); } | 47 int countGlyphs() const { return fCache.count(); } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 58 // for easy removal from list | 60 // for easy removal from list |
| 59 GrTextStrike* fPrev; | 61 GrTextStrike* fPrev; |
| 60 GrTextStrike* fNext; | 62 GrTextStrike* fNext; |
| 61 | 63 |
| 62 private: | 64 private: |
| 63 SkTDynamicHash<GrGlyph, GrGlyph::PackedID> fCache; | 65 SkTDynamicHash<GrGlyph, GrGlyph::PackedID> fCache; |
| 64 const GrFontDescKey* fFontScalerKey; | 66 const GrFontDescKey* fFontScalerKey; |
| 65 GrTAllocPool<GrGlyph> fPool; | 67 GrTAllocPool<GrGlyph> fPool; |
| 66 | 68 |
| 67 GrFontCache* fFontCache; | 69 GrFontCache* fFontCache; |
| 70 GrAtlas* fAtlas; |
| 71 GrMaskFormat fMaskFormat; |
| 68 bool fUseDistanceField; | 72 bool fUseDistanceField; |
| 69 | 73 |
| 70 GrAtlas::ClientPlotUsage fPlotUsage; | 74 GrAtlas::ClientPlotUsage fPlotUsage; |
| 71 | 75 |
| 72 GrGlyph* generateGlyph(GrGlyph::PackedID packed, GrFontScaler* scaler); | 76 GrGlyph* generateGlyph(GrGlyph::PackedID packed, GrFontScaler* scaler); |
| 73 | 77 |
| 74 friend class GrFontCache; | 78 friend class GrFontCache; |
| 75 }; | 79 }; |
| 76 | 80 |
| 77 class GrFontCache { | 81 class GrFontCache { |
| 78 public: | 82 public: |
| 79 GrFontCache(GrGpu*); | 83 GrFontCache(GrGpu*); |
| 80 ~GrFontCache(); | 84 ~GrFontCache(); |
| 81 | 85 |
| 82 inline GrTextStrike* getStrike(GrFontScaler*, bool useDistanceField); | 86 inline GrTextStrike* getStrike(GrFontScaler*, bool useDistanceField); |
| 83 | 87 |
| 84 // add to texture atlas that matches this format | |
| 85 GrPlot* addToAtlas(GrMaskFormat format, GrAtlas::ClientPlotUsage* usage, | |
| 86 int width, int height, const void* image, | |
| 87 SkIPoint16* loc); | |
| 88 | |
| 89 void freeAll(); | 88 void freeAll(); |
| 90 | 89 |
| 91 // make an unused plot available for this glyph | 90 // make an unused plot available |
| 92 bool freeUnusedPlot(GrTextStrike* preserveStrike, const GrGlyph* glyph); | 91 bool freeUnusedPlot(GrTextStrike* preserveStrike); |
| 93 | 92 |
| 94 // testing | 93 // testing |
| 95 int countStrikes() const { return fCache.count(); } | 94 int countStrikes() const { return fCache.count(); } |
| 96 GrTextStrike* getHeadStrike() const { return fHead; } | 95 GrTextStrike* getHeadStrike() const { return fHead; } |
| 97 | 96 |
| 98 void updateTextures() { | 97 void updateTextures() { |
| 99 for (int i = 0; i < kAtlasCount; ++i) { | 98 for (int i = 0; i < kAtlasCount; ++i) { |
| 100 if (fAtlases[i]) { | 99 if (fAtlases[i]) { |
| 101 fAtlases[i]->uploadPlotsToTexture(); | 100 fAtlases[i]->uploadPlotsToTexture(); |
| 102 } | 101 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 130 | 129 |
| 131 GrGpu* fGpu; | 130 GrGpu* fGpu; |
| 132 GrAtlas* fAtlases[kAtlasCount]; | 131 GrAtlas* fAtlases[kAtlasCount]; |
| 133 | 132 |
| 134 GrTextStrike* generateStrike(GrFontScaler*); | 133 GrTextStrike* generateStrike(GrFontScaler*); |
| 135 inline void detachStrikeFromList(GrTextStrike*); | 134 inline void detachStrikeFromList(GrTextStrike*); |
| 136 void purgeStrike(GrTextStrike* strike); | 135 void purgeStrike(GrTextStrike* strike); |
| 137 }; | 136 }; |
| 138 | 137 |
| 139 #endif | 138 #endif |
| OLD | NEW |