OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2015 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
8 #ifndef GrBatchFontCache_DEFINED | |
9 #define GrBatchFontCache_DEFINED | |
10 | |
11 #include "GrBatchAtlas.h" | |
12 #include "GrDrawTarget.h" | |
13 #include "GrFontScaler.h" | |
14 #include "GrGlyph.h" | |
15 #include "SkTDynamicHash.h" | |
16 #include "SkVarAlloc.h" | |
17 | |
18 class GrBatchFontCache; | |
19 class GrBatchTarget; | |
20 class GrGpu; | |
21 | |
22 /** | |
23 * The textstrike maps a hostfontscaler instance to a dictionary of | |
24 * glyphid->strike | |
bsalomon
2015/03/26 17:06:56
I don't understand the gr or sk font code much at
joshualitt
2015/03/26 18:21:43
I added a comment. I think we need to overhaul ho
| |
25 */ | |
26 class GrBatchTextStrike { | |
27 public: | |
28 SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrBatchTextStrike); | |
29 GrBatchTextStrike(GrBatchFontCache*, const GrFontDescKey* fontScalerKey); | |
30 ~GrBatchTextStrike(); | |
31 | |
32 const GrFontDescKey* getFontScalerKey() const { return fFontScalerKey; } | |
33 GrBatchFontCache* getBatchFontCache() const { return fBatchFontCache; } | |
34 | |
35 inline GrGlyph* getGlyph(GrGlyph::PackedID packed, GrFontScaler* scaler) { | |
36 GrGlyph* glyph = fCache.find(packed); | |
37 if (NULL == glyph) { | |
38 glyph = this->generateGlyph(packed, scaler); | |
39 } | |
40 return glyph; | |
41 } | |
42 | |
43 // returns true if glyph (or glyph+padding for distance field) | |
44 // is too large to ever fit in texture atlas subregions (GrPlots) | |
45 bool glyphTooLargeForAtlas(GrGlyph*); | |
46 // returns true if glyph successfully added to texture atlas, false otherwis e | |
47 bool addGlyphToAtlas(GrBatchTarget*, GrGlyph*, GrFontScaler*); | |
48 | |
49 // testing | |
50 int countGlyphs() const { return fCache.count(); } | |
51 | |
52 // remove any references to this plot | |
53 void removeID(GrBatchAtlas::AtlasID); | |
54 | |
55 static const GrFontDescKey& GetKey(const GrBatchTextStrike& ts) { | |
56 return *(ts.fFontScalerKey); | |
57 } | |
58 static uint32_t Hash(const GrFontDescKey& key) { | |
59 return key.getHash(); | |
60 } | |
61 | |
62 private: | |
63 SkTDynamicHash<GrGlyph, GrGlyph::PackedID> fCache; | |
64 SkAutoTUnref<const GrFontDescKey> fFontScalerKey; | |
65 SkVarAlloc fPool; | |
66 | |
67 GrBatchFontCache* fBatchFontCache; | |
68 int fAtlasedGlyphs; | |
69 | |
70 GrGlyph* generateGlyph(GrGlyph::PackedID packed, GrFontScaler* scaler); | |
71 | |
72 friend class GrBatchFontCache; | |
73 }; | |
74 | |
75 class GrBatchFontCache { | |
bsalomon
2015/03/26 17:06:56
/** This class manages a set GrBatchAtlases that s
joshualitt
2015/03/26 18:21:43
Acknowledged.
| |
76 public: | |
77 GrBatchFontCache(GrContext*); | |
78 ~GrBatchFontCache(); | |
79 | |
80 inline GrBatchTextStrike* getStrike(GrFontScaler* scaler) { | |
81 SkDEBUGCODE(this->validate();) | |
82 | |
83 GrBatchTextStrike* strike = fCache.find(*(scaler->getKey())); | |
84 if (NULL == strike) { | |
85 strike = this->generateStrike(scaler); | |
86 } else { | |
87 this->makeMRU(strike); | |
88 } | |
89 SkDEBUGCODE(this->validate();) | |
90 return strike; | |
91 } | |
92 | |
93 bool hasGlyph(GrGlyph* glyph); | |
94 void refGlyph(GrGlyph*, GrBatchAtlas::BatchToken); | |
bsalomon
2015/03/26 17:06:56
I think ref has a pretty specific meaning in Skia
joshualitt
2015/03/26 18:21:43
Acknowledged.
| |
95 | |
96 // add to texture atlas that matches this format | |
97 bool addToAtlas(GrBatchTextStrike*, GrBatchAtlas::AtlasID*, GrBatchTarget*, | |
98 GrMaskFormat, int width, int height, const void* image, | |
99 SkIPoint16* loc); | |
100 | |
101 uint32_t atlasGeneration(GrMaskFormat) const; | |
bsalomon
2015/03/26 17:06:56
doc?
joshualitt
2015/03/26 18:21:43
Acknowledged.
| |
102 | |
103 void freeAll(); | |
104 | |
105 inline void makeMRU(GrBatchTextStrike* strike) { | |
106 if (fStrikeList.head() == strike) { | |
107 return; | |
108 } | |
109 | |
110 fStrikeList.remove(strike); | |
111 fStrikeList.addToHead(strike); | |
112 } | |
113 | |
114 GrTexture* getTexture(GrMaskFormat); | |
115 GrPixelConfig getPixelConfig(GrMaskFormat) const; | |
116 | |
117 SkDEBUGCODE(void validate() const;) | |
118 | |
119 void dump() const; | |
120 | |
121 private: | |
122 enum AtlasType { | |
bsalomon
2015/03/26 17:06:56
Maybe comment about how this relates to mask type?
joshualitt
2015/03/26 18:21:43
I deleted this enum
| |
123 kA8_AtlasType, //!< 1-byte per pixel | |
124 k565_AtlasType, //!< 2-bytes per pixel | |
125 k8888_AtlasType, //!< 4-bytes per pixel | |
126 | |
127 kLast_AtlasType = k8888_AtlasType | |
128 }; | |
129 | |
130 static const int kAtlasCount = kLast_AtlasType + 1; | |
131 | |
132 static int MaskFormatToAtlasIndex(GrMaskFormat); | |
133 static GrMaskFormat AtlasIndexToMaskFormat(int atlasIndex); | |
bsalomon
2015/03/26 17:06:56
Is this 1 to 1?
joshualitt
2015/03/26 18:21:43
Acknowledged.
| |
134 | |
135 GrBatchTextStrike* generateStrike(GrFontScaler*); | |
136 | |
137 void purgeStrike(GrBatchTextStrike* strike); | |
138 inline GrBatchAtlas* getAtlas(GrMaskFormat) const; | |
139 | |
140 static void HandleEviction(GrBatchAtlas::AtlasID, void*); | |
141 | |
142 typedef SkTInternalLList<GrBatchTextStrike> GrBatchStrikeList; | |
143 | |
144 SkTDynamicHash<GrBatchTextStrike, GrFontDescKey> fCache; | |
145 GrBatchStrikeList fStrikeList; | |
146 | |
147 GrBatchAtlas* fAtlases[kAtlasCount]; | |
148 GrBatchTextStrike* fPreserveStrike; | |
149 }; | |
150 | |
151 #endif | |
OLD | NEW |