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"
18 #include "GrDrawTarget.h"
23 class GrFontPurgeListener;
26 * The textcache maps a hostfontscaler instance to a dictionary of
31 GrTextStrike(GrFontCache*, const GrKey* fontScalerKey, GrMaskFormat, GrAtlasMgr*);
34 const GrKey* getFontScalerKey() const { return fFontScalerKey; }
35 GrFontCache* getFontCache() const { return fFontCache; }
36 GrMaskFormat getMaskFormat() const { return fMaskFormat; }
38 inline GrGlyph* getGlyph(GrGlyph::PackedID, GrFontScaler*);
39 bool addGlyphToAtlas(GrGlyph*, GrFontScaler*);
42 int countGlyphs() const { return fCache.getArray().count(); }
43 const GrGlyph* glyphAt(int index) const {
44 return fCache.getArray()[index];
47 // remove any references to this plot
48 void removePlot(const GrPlot* plot);
51 // for easy removal from list
57 GrTHashTable<GrGlyph, Key, 7> fCache;
58 const GrKey* fFontScalerKey;
59 GrTAllocPool<GrGlyph> fPool;
61 GrFontCache* fFontCache;
62 GrAtlasMgr* fAtlasMgr;
63 GrMaskFormat fMaskFormat;
64 bool fUseDistanceField;
68 GrGlyph* generateGlyph(GrGlyph::PackedID packed, GrFontScaler* scaler);
70 friend class GrFontCache;
78 inline GrTextStrike* getStrike(GrFontScaler*, bool useDistanceField);
82 // make an unused plot available
83 bool freeUnusedPlot(GrTextStrike* preserveStrike);
86 int countStrikes() const { return fCache.getArray().count(); }
87 const GrTextStrike* strikeAt(int index) const {
88 return fCache.getArray()[index];
90 GrTextStrike* getHeadStrike() const { return fHead; }
92 void updateTextures() {
93 for (int i = 0; i < kAtlasCount; ++i) {
95 fAtlasMgr[i]->uploadPlotsToTexture();
101 void validate() const;
103 void validate() const {}
109 kA8_AtlasType, //!< 1-byte per pixel
110 k565_AtlasType, //!< 2-bytes per pixel
111 k8888_AtlasType, //!< 4-bytes per pixel
113 kLast_AtlasType = k8888_AtlasType
115 static const int kAtlasCount = kLast_AtlasType + 1;
118 friend class GrFontPurgeListener;
121 GrTHashTable<GrTextStrike, Key, 8> fCache;
127 GrAtlasMgr* fAtlasMgr[kAtlasCount];
129 GrTextStrike* generateStrike(GrFontScaler*, const Key&);
130 inline void detachStrikeFromList(GrTextStrike*);
131 void purgeStrike(GrTextStrike* strike);