gfx/skia/trunk/src/gpu/GrTextStrike.h

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:02a3e0496c00
1
2 /*
3 * Copyright 2010 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9
10
11 #ifndef GrTextStrike_DEFINED
12 #define GrTextStrike_DEFINED
13
14 #include "GrAllocPool.h"
15 #include "GrFontScaler.h"
16 #include "GrTHashTable.h"
17 #include "GrPoint.h"
18 #include "GrGlyph.h"
19 #include "GrDrawTarget.h"
20 #include "GrAtlas.h"
21
22 class GrFontCache;
23 class GrGpu;
24 class GrFontPurgeListener;
25
26 /**
27 * The textcache maps a hostfontscaler instance to a dictionary of
28 * glyphid->strike
29 */
30 class GrTextStrike {
31 public:
32 GrTextStrike(GrFontCache*, const GrKey* fontScalerKey, GrMaskFormat, GrAtlasMgr*);
33 ~GrTextStrike();
34
35 const GrKey* getFontScalerKey() const { return fFontScalerKey; }
36 GrFontCache* getFontCache() const { return fFontCache; }
37 GrMaskFormat getMaskFormat() const { return fMaskFormat; }
38
39 inline GrGlyph* getGlyph(GrGlyph::PackedID, GrFontScaler*);
40 bool addGlyphToAtlas(GrGlyph*, GrFontScaler*);
41
42 SkISize getAtlasSize() const { return fAtlas.getSize(); }
43
44 // testing
45 int countGlyphs() const { return fCache.getArray().count(); }
46 const GrGlyph* glyphAt(int index) const {
47 return fCache.getArray()[index];
48 }
49
50 // remove any references to this plot
51 void removePlot(const GrPlot* plot);
52
53 public:
54 // for easy removal from list
55 GrTextStrike* fPrev;
56 GrTextStrike* fNext;
57
58 private:
59 class Key;
60 GrTHashTable<GrGlyph, Key, 7> fCache;
61 const GrKey* fFontScalerKey;
62 GrTAllocPool<GrGlyph> fPool;
63
64 GrFontCache* fFontCache;
65 GrAtlasMgr* fAtlasMgr;
66 GrMaskFormat fMaskFormat;
67 bool fUseDistanceField;
68
69 GrAtlas fAtlas;
70
71 GrGlyph* generateGlyph(GrGlyph::PackedID packed, GrFontScaler* scaler);
72
73 friend class GrFontCache;
74 };
75
76 class GrFontCache {
77 public:
78 GrFontCache(GrGpu*);
79 ~GrFontCache();
80
81 inline GrTextStrike* getStrike(GrFontScaler*, bool useDistanceField);
82
83 void freeAll();
84
85 // make an unused plot available
86 bool freeUnusedPlot(GrTextStrike* preserveStrike);
87
88 // testing
89 int countStrikes() const { return fCache.getArray().count(); }
90 const GrTextStrike* strikeAt(int index) const {
91 return fCache.getArray()[index];
92 }
93 GrTextStrike* getHeadStrike() const { return fHead; }
94
95 #ifdef SK_DEBUG
96 void validate() const;
97 #else
98 void validate() const {}
99 #endif
100
101 #ifdef SK_DEVELOPER
102 void dump() const;
103 #endif
104
105 enum AtlasType {
106 kA8_AtlasType, //!< 1-byte per pixel
107 k565_AtlasType, //!< 2-bytes per pixel
108 k8888_AtlasType, //!< 4-bytes per pixel
109
110 kLast_AtlasType = k8888_AtlasType
111 };
112 static const int kAtlasCount = kLast_AtlasType + 1;
113
114 private:
115 friend class GrFontPurgeListener;
116
117 class Key;
118 GrTHashTable<GrTextStrike, Key, 8> fCache;
119 // for LRU
120 GrTextStrike* fHead;
121 GrTextStrike* fTail;
122
123 GrGpu* fGpu;
124 GrAtlasMgr* fAtlasMgr[kAtlasCount];
125
126 GrTextStrike* generateStrike(GrFontScaler*, const Key&);
127 inline void detachStrikeFromList(GrTextStrike*);
128 void purgeStrike(GrTextStrike* strike);
129 };
130
131 #endif

mercurial