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 // Return the SkGlyph* associated with MakeID. The id parameter is the combi
ned glyph/x/y | 190 SkGlyph* lookupMetrics(uint32_t id, MetricsType); |
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 MaetricsType. | |
199 uint16_t lookupMetrics(uint32_t id, MetricsType type); | |
200 static bool DetachProc(const SkGlyphCache*, void*) { return true; } | 191 static bool DetachProc(const SkGlyphCache*, void*) { return true; } |
201 | 192 |
202 SkGlyphCache* fNext, *fPrev; | 193 SkGlyphCache* fNext, *fPrev; |
203 SkDescriptor* fDesc; | 194 SkDescriptor* fDesc; |
204 SkScalerContext* fScalerContext; | 195 SkScalerContext* fScalerContext; |
205 SkPaint::FontMetrics fFontMetrics; | 196 SkPaint::FontMetrics fFontMetrics; |
206 | 197 |
207 enum { | 198 enum { |
208 kHashBits = 8, | 199 kHashBits = 8, |
209 kHashCount = 1 << kHashBits, | 200 kHashCount = 1 << kHashBits, |
210 kHashMask = kHashCount - 1, | 201 kHashMask = kHashCount - 1 |
211 kSentinelGlyphIndex = 0, | |
212 kSentinelGlyphID = 0 | |
213 }; | 202 }; |
214 | 203 SkGlyph* fGlyphHash[kHashCount]; |
215 // A quick lookup to avoid the binary search looking for glyphs in fGlyphArr
ay. | 204 SkTDArray<SkGlyph*> fGlyphArray; |
216 uint16_t fGlyphHash[kHashCount]; | 205 SkChunkAlloc fGlyphAlloc; |
217 SkTDArray<SkGlyph> fGlyphArray; | |
218 SkChunkAlloc fGlyphAlloc; | |
219 | 206 |
220 struct CharGlyphRec { | 207 struct CharGlyphRec { |
221 uint32_t fID; // unichar + subpixel | 208 uint32_t fID; // unichar + subpixel |
222 uint16_t fGlyphIndex; | 209 SkGlyph* fGlyph; |
223 }; | 210 }; |
224 | |
225 // no reason to use the same kHashCount as fGlyphHash, but we do for now | 211 // no reason to use the same kHashCount as fGlyphHash, but we do for now |
226 // Dynamically allocated when chars are encountered. | 212 // Dynamically allocated when chars are encountered. |
227 SkAutoTArray<CharGlyphRec> fCharToGlyphHash; | 213 SkAutoTArray<CharGlyphRec> fCharToGlyphHash; |
228 | 214 |
229 // The id arg is a combined id generated by MakeID. | |
230 CharGlyphRec* getCharGlyphRec(uint32_t id); | 215 CharGlyphRec* getCharGlyphRec(uint32_t id); |
231 void adjustCaches(int insertion_index); | |
232 | 216 |
233 static inline unsigned ID2HashIndex(uint32_t h) { | 217 static inline unsigned ID2HashIndex(uint32_t h) { |
234 return SkChecksum::CheapMix(h) & kHashMask; | 218 return SkChecksum::CheapMix(h) & kHashMask; |
235 } | 219 } |
236 | 220 |
237 // used to track (approx) how much ram is tied-up in this cache | 221 // used to track (approx) how much ram is tied-up in this cache |
238 size_t fMemoryUsed; | 222 size_t fMemoryUsed; |
239 | 223 |
240 | 224 |
241 #ifdef SK_GLYPHCACHE_TRACK_HASH_STATS | 225 #ifdef SK_GLYPHCACHE_TRACK_HASH_STATS |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 const SkMatrix* matrix) { | 304 const SkMatrix* matrix) { |
321 fCache = paint.detachCache(deviceProperties, matrix, true); | 305 fCache = paint.detachCache(deviceProperties, matrix, true); |
322 } | 306 } |
323 | 307 |
324 private: | 308 private: |
325 SkAutoGlyphCacheNoGamma() : SkAutoGlyphCacheBase() {} | 309 SkAutoGlyphCacheNoGamma() : SkAutoGlyphCacheBase() {} |
326 }; | 310 }; |
327 #define SkAutoGlyphCacheNoGamma(...) SK_REQUIRE_LOCAL_VAR(SkAutoGlyphCacheNoGamm
a) | 311 #define SkAutoGlyphCacheNoGamma(...) SK_REQUIRE_LOCAL_VAR(SkAutoGlyphCacheNoGamm
a) |
328 | 312 |
329 #endif | 313 #endif |
OLD | NEW |