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 "SkTDynamicHash.h"
18 #include "GrDrawTarget.h"
23 class GrFontPurgeListener;
26 * The textcache maps a hostfontscaler instance to a dictionary of
31 GrTextStrike(GrFontCache*, const GrFontDescKey* fontScalerKey, GrMaskFormat, GrAtlas*);
34 const GrFontDescKey* getFontScalerKey() const { return fFontScalerKey; }
35 GrFontCache* getFontCache() const { return fFontCache; }
36 GrMaskFormat getMaskFormat() const { return fMaskFormat; }
37 GrTexture* getTexture() const { return fAtlas->getTexture(); }
39 inline GrGlyph* getGlyph(GrGlyph::PackedID, GrFontScaler*);
40 bool addGlyphToAtlas(GrGlyph*, GrFontScaler*);
43 int countGlyphs() const { return fCache.count(); }
45 // remove any references to this plot
46 void removePlot(const GrPlot* plot);
48 static const GrFontDescKey& GetKey(const GrTextStrike& ts) {
49 return *(ts.fFontScalerKey);
51 static uint32_t Hash(const GrFontDescKey& key) {
56 // for easy removal from list
61 SkTDynamicHash<GrGlyph, GrGlyph::PackedID> fCache;
62 const GrFontDescKey* fFontScalerKey;
63 GrTAllocPool<GrGlyph> fPool;
65 GrFontCache* fFontCache;
67 GrMaskFormat fMaskFormat;
68 bool fUseDistanceField;
70 GrAtlas::ClientPlotUsage fPlotUsage;
72 GrGlyph* generateGlyph(GrGlyph::PackedID packed, GrFontScaler* scaler);
74 friend class GrFontCache;
82 inline GrTextStrike* getStrike(GrFontScaler*, bool useDistanceField);
86 // make an unused plot available
87 bool freeUnusedPlot(GrTextStrike* preserveStrike);
90 int countStrikes() const { return fCache.count(); }
91 GrTextStrike* getHeadStrike() const { return fHead; }
93 void updateTextures() {
94 for (int i = 0; i < kAtlasCount; ++i) {
96 fAtlases[i]->uploadPlotsToTexture();
102 void validate() const;
104 void validate() const {}
110 kA8_AtlasType, //!< 1-byte per pixel
111 k565_AtlasType, //!< 2-bytes per pixel
112 k8888_AtlasType, //!< 4-bytes per pixel
114 kLast_AtlasType = k8888_AtlasType
116 static const int kAtlasCount = kLast_AtlasType + 1;
119 friend class GrFontPurgeListener;
121 SkTDynamicHash<GrTextStrike, GrFontDescKey> fCache;
127 GrAtlas* fAtlases[kAtlasCount];
129 GrTextStrike* generateStrike(GrFontScaler*);
130 inline void detachStrikeFromList(GrTextStrike*);
131 void purgeStrike(GrTextStrike* strike);