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_DEFINED
12 #define GrTextStrike_DEFINED
14 #include "GrAllocPool.h"
15 #include "GrFontScaler.h"
16 #include "GrTHashTable.h"
19 #include "GrDrawTarget.h"
24 class GrFontPurgeListener;
27 * The textcache maps a hostfontscaler instance to a dictionary of
32 GrTextStrike(GrFontCache*, const GrKey* fontScalerKey, GrMaskFormat, GrAtlasMgr*);
35 const GrKey* getFontScalerKey() const { return fFontScalerKey; }
36 GrFontCache* getFontCache() const { return fFontCache; }
37 GrMaskFormat getMaskFormat() const { return fMaskFormat; }
39 inline GrGlyph* getGlyph(GrGlyph::PackedID, GrFontScaler*);
40 bool addGlyphToAtlas(GrGlyph*, GrFontScaler*);
43 int countGlyphs() const { return fCache.getArray().count(); }
44 const GrGlyph* glyphAt(int index) const {
45 return fCache.getArray()[index];
48 // remove any references to this plot
49 void removePlot(const GrPlot* plot);
52 // for easy removal from list
58 GrTHashTable<GrGlyph, Key, 7> fCache;
59 const GrKey* fFontScalerKey;
60 GrTAllocPool<GrGlyph> fPool;
62 GrFontCache* fFontCache;
63 GrAtlasMgr* fAtlasMgr;
64 GrMaskFormat fMaskFormat;
65 bool fUseDistanceField;
69 GrGlyph* generateGlyph(GrGlyph::PackedID packed, GrFontScaler* scaler);
71 friend class GrFontCache;
79 inline GrTextStrike* getStrike(GrFontScaler*, bool useDistanceField);
83 // make an unused plot available
84 bool freeUnusedPlot(GrTextStrike* preserveStrike);
87 int countStrikes() const { return fCache.getArray().count(); }
88 const GrTextStrike* strikeAt(int index) const {
89 return fCache.getArray()[index];
91 GrTextStrike* getHeadStrike() const { return fHead; }
94 void validate() const;
96 void validate() const {}
104 kA8_AtlasType, //!< 1-byte per pixel
105 k565_AtlasType, //!< 2-bytes per pixel
106 k8888_AtlasType, //!< 4-bytes per pixel
108 kLast_AtlasType = k8888_AtlasType
110 static const int kAtlasCount = kLast_AtlasType + 1;
113 friend class GrFontPurgeListener;
116 GrTHashTable<GrTextStrike, Key, 8> fCache;
122 GrAtlasMgr* fAtlasMgr[kAtlasCount];
124 GrTextStrike* generateStrike(GrFontScaler*, const Key&);
125 inline void detachStrikeFromList(GrTextStrike*);
126 void purgeStrike(GrTextStrike* strike);