OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkGlyphCache_DEFINED | 8 #ifndef SkGlyphCache_DEFINED |
9 #define SkGlyphCache_DEFINED | 9 #define SkGlyphCache_DEFINED |
10 | 10 |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 private: | 180 private: |
181 // we take ownership of the scalercontext | 181 // we take ownership of the scalercontext |
182 SkGlyphCache(SkTypeface*, const SkDescriptor*, SkScalerContext*); | 182 SkGlyphCache(SkTypeface*, const SkDescriptor*, SkScalerContext*); |
183 ~SkGlyphCache(); | 183 ~SkGlyphCache(); |
184 | 184 |
185 enum MetricsType { | 185 enum MetricsType { |
186 kJustAdvance_MetricsType, | 186 kJustAdvance_MetricsType, |
187 kFull_MetricsType | 187 kFull_MetricsType |
188 }; | 188 }; |
189 | 189 |
190 SkGlyph* lookupMetrics(uint32_t id, MetricsType); | 190 // Return the SkGlyph* associated with MakeID. The id parameter is the combi
ned glyph/x/y |
| 191 // id generated by MakeID. If it is just a glyph id then x and y are assuemd
to be zero. |
| 192 SkGlyph* lookupByCombinedID(uint32_t id, MetricsType type); |
| 193 |
| 194 // Return a SkGlyph* associated with unicode id and position x and y. |
| 195 SkGlyph* lookupByChar(SkUnichar id, MetricsType type, SkFixed x = 0, SkFixed
y = 0); |
| 196 |
| 197 // Return the index of id in the fGlyphArray. If it does |
| 198 // not exist, create a new one using MetricsType. |
| 199 uint16_t lookupMetrics(uint32_t id, MetricsType type); |
191 static bool DetachProc(const SkGlyphCache*, void*) { return true; } | 200 static bool DetachProc(const SkGlyphCache*, void*) { return true; } |
192 | 201 |
193 SkGlyphCache* fNext, *fPrev; | 202 SkGlyphCache* fNext, *fPrev; |
194 SkDescriptor* fDesc; | 203 SkDescriptor* fDesc; |
195 SkScalerContext* fScalerContext; | 204 SkScalerContext* fScalerContext; |
196 SkPaint::FontMetrics fFontMetrics; | 205 SkPaint::FontMetrics fFontMetrics; |
197 | 206 |
198 enum { | 207 enum { |
199 kHashBits = 8, | 208 kHashBits = 8, |
200 kHashCount = 1 << kHashBits, | 209 kHashCount = 1 << kHashBits, |
201 kHashMask = kHashCount - 1 | 210 kHashMask = kHashCount - 1, |
| 211 kSentinelGlyphIndex = 0, |
| 212 kSentinelGlyphID = ~0 |
202 }; | 213 }; |
203 SkGlyph* fGlyphHash[kHashCount]; | 214 |
204 SkTDArray<SkGlyph*> fGlyphArray; | 215 // A quick lookup to avoid the binary search looking for glyphs in fGlyphArr
ay. |
205 SkChunkAlloc fGlyphAlloc; | 216 uint16_t fGlyphHash[kHashCount]; |
| 217 SkTDArray<SkGlyph> fGlyphArray; |
| 218 SkChunkAlloc fGlyphAlloc; |
206 | 219 |
207 struct CharGlyphRec { | 220 struct CharGlyphRec { |
208 uint32_t fID; // unichar + subpixel | 221 uint32_t fID; // unichar + subpixel |
209 SkGlyph* fGlyph; | 222 uint16_t fGlyphIndex; |
210 }; | 223 }; |
| 224 |
211 // no reason to use the same kHashCount as fGlyphHash, but we do for now | 225 // no reason to use the same kHashCount as fGlyphHash, but we do for now |
212 // Dynamically allocated when chars are encountered. | 226 // Dynamically allocated when chars are encountered. |
213 SkAutoTArray<CharGlyphRec> fCharToGlyphHash; | 227 SkAutoTArray<CharGlyphRec> fCharToGlyphHash; |
214 | 228 |
| 229 // The id arg is a combined id generated by MakeID. |
215 CharGlyphRec* getCharGlyphRec(uint32_t id); | 230 CharGlyphRec* getCharGlyphRec(uint32_t id); |
| 231 void adjustCaches(int insertion_index); |
216 | 232 |
217 static inline unsigned ID2HashIndex(uint32_t h) { | 233 static inline unsigned ID2HashIndex(uint32_t h) { |
218 return SkChecksum::CheapMix(h) & kHashMask; | 234 return SkChecksum::CheapMix(h) & kHashMask; |
219 } | 235 } |
220 | 236 |
221 // used to track (approx) how much ram is tied-up in this cache | 237 // used to track (approx) how much ram is tied-up in this cache |
222 size_t fMemoryUsed; | 238 size_t fMemoryUsed; |
223 | 239 |
224 | |
225 #ifdef SK_GLYPHCACHE_TRACK_HASH_STATS | 240 #ifdef SK_GLYPHCACHE_TRACK_HASH_STATS |
226 int fHashHitCount; | 241 int fHashHitCount; |
227 int fHashMissCount; | 242 int fHashMissCount; |
228 #endif | 243 #endif |
229 | 244 |
230 struct AuxProcRec { | 245 struct AuxProcRec { |
231 AuxProcRec* fNext; | 246 AuxProcRec* fNext; |
232 void (*fProc)(void*); | 247 void (*fProc)(void*); |
233 void* fData; | 248 void* fData; |
234 }; | 249 }; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 const SkMatrix* matrix) { | 319 const SkMatrix* matrix) { |
305 fCache = paint.detachCache(deviceProperties, matrix, true); | 320 fCache = paint.detachCache(deviceProperties, matrix, true); |
306 } | 321 } |
307 | 322 |
308 private: | 323 private: |
309 SkAutoGlyphCacheNoGamma() : SkAutoGlyphCacheBase() {} | 324 SkAutoGlyphCacheNoGamma() : SkAutoGlyphCacheBase() {} |
310 }; | 325 }; |
311 #define SkAutoGlyphCacheNoGamma(...) SK_REQUIRE_LOCAL_VAR(SkAutoGlyphCacheNoGamm
a) | 326 #define SkAutoGlyphCacheNoGamma(...) SK_REQUIRE_LOCAL_VAR(SkAutoGlyphCacheNoGamm
a) |
312 | 327 |
313 #endif | 328 #endif |
OLD | NEW |