| 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 // Gets the glyph index given the sub-pixel postion glyph ID, and maintains
the glyph cache. |
| 191 SkGlyph* maintainGlyphCache(uint32_t id, MetricsType type); |
| 192 SkGlyph* maintainCharCache(SkUnichar id, MetricsType type, SkFixed x = 0, Sk
Fixed y = 0); |
| 193 uint16_t lookupMetrics(uint32_t id, MetricsType); |
| 191 static bool DetachProc(const SkGlyphCache*, void*) { return true; } | 194 static bool DetachProc(const SkGlyphCache*, void*) { return true; } |
| 192 | 195 |
| 193 SkGlyphCache* fNext, *fPrev; | 196 SkGlyphCache* fNext, *fPrev; |
| 194 SkDescriptor* fDesc; | 197 SkDescriptor* fDesc; |
| 195 SkScalerContext* fScalerContext; | 198 SkScalerContext* fScalerContext; |
| 196 SkPaint::FontMetrics fFontMetrics; | 199 SkPaint::FontMetrics fFontMetrics; |
| 197 | 200 |
| 198 enum { | 201 enum { |
| 199 kHashBits = 8, | 202 kHashBits = 8, |
| 200 kHashCount = 1 << kHashBits, | 203 kHashCount = 1 << kHashBits, |
| 201 kHashMask = kHashCount - 1 | 204 kHashMask = kHashCount - 1, |
| 205 kInvalidGlyph = 0xFFFF |
| 202 }; | 206 }; |
| 203 SkGlyph* fGlyphHash[kHashCount]; | 207 |
| 204 SkTDArray<SkGlyph*> fGlyphArray; | 208 // A quick lookup to avoid the binary search looking for glyphs in fGlyphArr
ay. |
| 205 SkChunkAlloc fGlyphAlloc; | 209 uint16_t fGlyphHash[kHashCount]; |
| 210 SkTDArray<SkGlyph> fGlyphArray; |
| 211 SkChunkAlloc fGlyphAlloc; |
| 206 | 212 |
| 207 struct CharGlyphRec { | 213 struct CharGlyphRec { |
| 208 uint32_t fID; // unichar + subpixel | 214 uint32_t fID; // unichar + subpixel |
| 209 SkGlyph* fGlyph; | 215 uint16_t fGlyphIndex; |
| 210 }; | 216 }; |
| 211 // no reason to use the same kHashCount as fGlyphHash, but we do for now | 217 // no reason to use the same kHashCount as fGlyphHash, but we do for now |
| 212 // Dynamically allocated when chars are encountered. | 218 // Dynamically allocated when chars are encountered. |
| 213 SkAutoTArray<CharGlyphRec> fCharToGlyphHash; | 219 SkAutoTArray<CharGlyphRec> fCharToGlyphHash; |
| 214 | |
| 215 CharGlyphRec* getCharGlyphRec(uint32_t id); | 220 CharGlyphRec* getCharGlyphRec(uint32_t id); |
| 221 void adjustCaches(int16_t insertion_index); |
| 216 | 222 |
| 217 static inline unsigned ID2HashIndex(uint32_t h) { | 223 static inline unsigned ID2HashIndex(uint32_t h) { |
| 218 return SkChecksum::CheapMix(h) & kHashMask; | 224 return SkChecksum::CheapMix(h) & kHashMask; |
| 219 } | 225 } |
| 220 | 226 |
| 221 // used to track (approx) how much ram is tied-up in this cache | 227 // used to track (approx) how much ram is tied-up in this cache |
| 222 size_t fMemoryUsed; | 228 size_t fMemoryUsed; |
| 223 | 229 |
| 224 | 230 |
| 225 #ifdef SK_GLYPHCACHE_TRACK_HASH_STATS | 231 #ifdef SK_GLYPHCACHE_TRACK_HASH_STATS |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 const SkMatrix* matrix) { | 310 const SkMatrix* matrix) { |
| 305 fCache = paint.detachCache(deviceProperties, matrix, true); | 311 fCache = paint.detachCache(deviceProperties, matrix, true); |
| 306 } | 312 } |
| 307 | 313 |
| 308 private: | 314 private: |
| 309 SkAutoGlyphCacheNoGamma() : SkAutoGlyphCacheBase() {} | 315 SkAutoGlyphCacheNoGamma() : SkAutoGlyphCacheBase() {} |
| 310 }; | 316 }; |
| 311 #define SkAutoGlyphCacheNoGamma(...) SK_REQUIRE_LOCAL_VAR(SkAutoGlyphCacheNoGamm
a) | 317 #define SkAutoGlyphCacheNoGamma(...) SK_REQUIRE_LOCAL_VAR(SkAutoGlyphCacheNoGamm
a) |
| 312 | 318 |
| 313 #endif | 319 #endif |
| OLD | NEW |