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 // returns true if glyph (or glyph+padding for distance field)
41 // is too large to ever fit in texture atlas subregions (GrPlots)
42 bool glyphTooLargeForAtlas(GrGlyph*);
43 // returns true if glyph successfully added to texture atlas, false otherwise
44 bool addGlyphToAtlas(GrGlyph*, GrFontScaler*);
47 int countGlyphs() const { return fCache.count(); }
49 // remove any references to this plot
50 void removePlot(const GrPlot* plot);
52 static const GrFontDescKey& GetKey(const GrTextStrike& ts) {
53 return *(ts.fFontScalerKey);
55 static uint32_t Hash(const GrFontDescKey& key) {
60 // for easy removal from list
65 SkTDynamicHash<GrGlyph, GrGlyph::PackedID> fCache;
66 const GrFontDescKey* fFontScalerKey;
67 GrTAllocPool<GrGlyph> fPool;
69 GrFontCache* fFontCache;
71 GrMaskFormat fMaskFormat;
72 bool fUseDistanceField;
74 GrAtlas::ClientPlotUsage fPlotUsage;
76 GrGlyph* generateGlyph(GrGlyph::PackedID packed, GrFontScaler* scaler);
78 friend class GrFontCache;
86 inline GrTextStrike* getStrike(GrFontScaler*, bool useDistanceField);
90 // make an unused plot available
91 bool freeUnusedPlot(GrTextStrike* preserveStrike);
94 int countStrikes() const { return fCache.count(); }
95 GrTextStrike* getHeadStrike() const { return fHead; }
97 void updateTextures() {
98 for (int i = 0; i < kAtlasCount; ++i) {
100 fAtlases[i]->uploadPlotsToTexture();
106 void validate() const;
108 void validate() const {}
114 kA8_AtlasType, //!< 1-byte per pixel
115 k565_AtlasType, //!< 2-bytes per pixel
116 k8888_AtlasType, //!< 4-bytes per pixel
118 kLast_AtlasType = k8888_AtlasType
120 static const int kAtlasCount = kLast_AtlasType + 1;
123 friend class GrFontPurgeListener;
125 SkTDynamicHash<GrTextStrike, GrFontDescKey> fCache;
131 GrAtlas* fAtlases[kAtlasCount];
133 GrTextStrike* generateStrike(GrFontScaler*);
134 inline void detachStrikeFromList(GrTextStrike*);
135 void purgeStrike(GrTextStrike* strike);