| 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 "GrTHashTable.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 textcache 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, GrMaskFormat,
GrAtlas*); | 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; } | 36 GrMaskFormat getMaskFormat() const { return fMaskFormat; } |
| 37 | 37 |
| 38 inline GrGlyph* getGlyph(GrGlyph::PackedID, GrFontScaler*); | 38 inline GrGlyph* getGlyph(GrGlyph::PackedID, GrFontScaler*); |
| 39 bool addGlyphToAtlas(GrGlyph*, GrFontScaler*); | 39 bool addGlyphToAtlas(GrGlyph*, GrFontScaler*); |
| 40 | 40 |
| 41 // testing | 41 // testing |
| 42 int countGlyphs() const { return fCache.getArray().count(); } | 42 int countGlyphs() const { return fCache.count(); } |
| 43 const GrGlyph* glyphAt(int index) const { | |
| 44 return fCache.getArray()[index]; | |
| 45 } | |
| 46 | 43 |
| 47 // remove any references to this plot | 44 // remove any references to this plot |
| 48 void removePlot(const GrPlot* plot); | 45 void removePlot(const GrPlot* plot); |
| 49 | 46 |
| 47 static const GrFontDescKey& GetKey(const GrTextStrike& ts) { |
| 48 return *(ts.fFontScalerKey); |
| 49 } |
| 50 static uint32_t Hash(const GrFontDescKey& key) { |
| 51 return key.getHash(); |
| 52 } |
| 53 |
| 50 public: | 54 public: |
| 51 // for easy removal from list | 55 // for easy removal from list |
| 52 GrTextStrike* fPrev; | 56 GrTextStrike* fPrev; |
| 53 GrTextStrike* fNext; | 57 GrTextStrike* fNext; |
| 54 | 58 |
| 55 private: | 59 private: |
| 56 class Key; | 60 SkTDynamicHash<GrGlyph, GrGlyph::PackedID> fCache; |
| 57 GrTHashTable<GrGlyph, Key, 7> fCache; | |
| 58 const GrFontDescKey* fFontScalerKey; | 61 const GrFontDescKey* fFontScalerKey; |
| 59 GrTAllocPool<GrGlyph> fPool; | 62 GrTAllocPool<GrGlyph> fPool; |
| 60 | 63 |
| 61 GrFontCache* fFontCache; | 64 GrFontCache* fFontCache; |
| 62 GrAtlas* fAtlas; | 65 GrAtlas* fAtlas; |
| 63 GrMaskFormat fMaskFormat; | 66 GrMaskFormat fMaskFormat; |
| 64 bool fUseDistanceField; | 67 bool fUseDistanceField; |
| 65 | 68 |
| 66 GrAtlas::ClientPlotUsage fPlotUsage; | 69 GrAtlas::ClientPlotUsage fPlotUsage; |
| 67 | 70 |
| 68 GrGlyph* generateGlyph(GrGlyph::PackedID packed, GrFontScaler* scaler); | 71 GrGlyph* generateGlyph(GrGlyph::PackedID packed, GrFontScaler* scaler); |
| 69 | 72 |
| 70 friend class GrFontCache; | 73 friend class GrFontCache; |
| 71 }; | 74 }; |
| 72 | 75 |
| 73 class GrFontCache { | 76 class GrFontCache { |
| 74 public: | 77 public: |
| 75 GrFontCache(GrGpu*); | 78 GrFontCache(GrGpu*); |
| 76 ~GrFontCache(); | 79 ~GrFontCache(); |
| 77 | 80 |
| 78 inline GrTextStrike* getStrike(GrFontScaler*, bool useDistanceField); | 81 inline GrTextStrike* getStrike(GrFontScaler*, bool useDistanceField); |
| 79 | 82 |
| 80 void freeAll(); | 83 void freeAll(); |
| 81 | 84 |
| 82 // make an unused plot available | 85 // make an unused plot available |
| 83 bool freeUnusedPlot(GrTextStrike* preserveStrike); | 86 bool freeUnusedPlot(GrTextStrike* preserveStrike); |
| 84 | 87 |
| 85 // testing | 88 // testing |
| 86 int countStrikes() const { return fCache.getArray().count(); } | 89 int countStrikes() const { return fCache.count(); } |
| 87 const GrTextStrike* strikeAt(int index) const { | |
| 88 return fCache.getArray()[index]; | |
| 89 } | |
| 90 GrTextStrike* getHeadStrike() const { return fHead; } | 90 GrTextStrike* getHeadStrike() const { return fHead; } |
| 91 | 91 |
| 92 void updateTextures() { | 92 void updateTextures() { |
| 93 for (int i = 0; i < kAtlasCount; ++i) { | 93 for (int i = 0; i < kAtlasCount; ++i) { |
| 94 if (fAtlases[i]) { | 94 if (fAtlases[i]) { |
| 95 fAtlases[i]->uploadPlotsToTexture(); | 95 fAtlases[i]->uploadPlotsToTexture(); |
| 96 } | 96 } |
| 97 } | 97 } |
| 98 } | 98 } |
| 99 | 99 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 110 k565_AtlasType, //!< 2-bytes per pixel | 110 k565_AtlasType, //!< 2-bytes per pixel |
| 111 k8888_AtlasType, //!< 4-bytes per pixel | 111 k8888_AtlasType, //!< 4-bytes per pixel |
| 112 | 112 |
| 113 kLast_AtlasType = k8888_AtlasType | 113 kLast_AtlasType = k8888_AtlasType |
| 114 }; | 114 }; |
| 115 static const int kAtlasCount = kLast_AtlasType + 1; | 115 static const int kAtlasCount = kLast_AtlasType + 1; |
| 116 | 116 |
| 117 private: | 117 private: |
| 118 friend class GrFontPurgeListener; | 118 friend class GrFontPurgeListener; |
| 119 | 119 |
| 120 class Key; | 120 SkTDynamicHash<GrTextStrike, GrFontDescKey> fCache; |
| 121 GrTHashTable<GrTextStrike, Key, 8> fCache; | |
| 122 // for LRU | 121 // for LRU |
| 123 GrTextStrike* fHead; | 122 GrTextStrike* fHead; |
| 124 GrTextStrike* fTail; | 123 GrTextStrike* fTail; |
| 125 | 124 |
| 126 GrGpu* fGpu; | 125 GrGpu* fGpu; |
| 127 GrAtlas* fAtlases[kAtlasCount]; | 126 GrAtlas* fAtlases[kAtlasCount]; |
| 128 | 127 |
| 129 GrTextStrike* generateStrike(GrFontScaler*, const Key&); | 128 GrTextStrike* generateStrike(GrFontScaler*); |
| 130 inline void detachStrikeFromList(GrTextStrike*); | 129 inline void detachStrikeFromList(GrTextStrike*); |
| 131 void purgeStrike(GrTextStrike* strike); | 130 void purgeStrike(GrTextStrike* strike); |
| 132 }; | 131 }; |
| 133 | 132 |
| 134 #endif | 133 #endif |
| OLD | NEW |