| 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 |
| 11 #include "SkBitmap.h" | 11 #include "SkBitmap.h" |
| 12 #include "SkChecksum.h" | 12 #include "SkChecksum.h" |
| 13 #include "SkChunkAlloc.h" | 13 #include "SkChunkAlloc.h" |
| 14 #include "SkDescriptor.h" | 14 #include "SkDescriptor.h" |
| 15 #include "SkGlyph.h" | 15 #include "SkGlyph.h" |
| 16 #include "SkScalerContext.h" | 16 #include "SkScalerContext.h" |
| 17 #include "SkTDArray.h" |
| 18 #include "SkTHash.h" |
| 17 #include "SkTemplates.h" | 19 #include "SkTemplates.h" |
| 18 #include "SkTDArray.h" | |
| 19 | 20 |
| 20 struct SkDeviceProperties; | 21 struct SkDeviceProperties; |
| 21 class SkPaint; | 22 class SkPaint; |
| 22 | 23 |
| 23 class SkGlyphCache_Globals; | 24 class SkGlyphCache_Globals; |
| 24 | 25 |
| 25 // Enable this locally to add stats for hash-table hit rates. It also extends th
e dump() | |
| 26 // output to show those stats. | |
| 27 //#define SK_GLYPHCACHE_TRACK_HASH_STATS | |
| 28 | |
| 29 /** \class SkGlyphCache | 26 /** \class SkGlyphCache |
| 30 | 27 |
| 31 This class represents a strike: a specific combination of typeface, size, | 28 This class represents a strike: a specific combination of typeface, size, |
| 32 matrix, etc., and holds the glyphs for that strike. Calling any of the | 29 matrix, etc., and holds the glyphs for that strike. Calling any of the |
| 33 getUnichar.../getGlyphID... methods will return the requested glyph, | 30 getUnichar.../getGlyphID... methods will return the requested glyph, |
| 34 either instantly if it is already cached, or by first generating it and then | 31 either instantly if it is already cached, or by first generating it and then |
| 35 adding it to the strike. | 32 adding it to the strike. |
| 36 | 33 |
| 37 The strikes are held in a global list, available to all threads. To interact | 34 The strikes are held in a global list, available to all threads. To interact |
| 38 with one, call either VisitCache() or DetachCache(). | 35 with one, call either VisitCache() or DetachCache(). |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 }; | 185 }; |
| 189 | 186 |
| 190 SkGlyph* lookupMetrics(uint32_t id, MetricsType); | 187 SkGlyph* lookupMetrics(uint32_t id, MetricsType); |
| 191 static bool DetachProc(const SkGlyphCache*, void*) { return true; } | 188 static bool DetachProc(const SkGlyphCache*, void*) { return true; } |
| 192 | 189 |
| 193 SkGlyphCache* fNext, *fPrev; | 190 SkGlyphCache* fNext, *fPrev; |
| 194 SkDescriptor* fDesc; | 191 SkDescriptor* fDesc; |
| 195 SkScalerContext* fScalerContext; | 192 SkScalerContext* fScalerContext; |
| 196 SkPaint::FontMetrics fFontMetrics; | 193 SkPaint::FontMetrics fFontMetrics; |
| 197 | 194 |
| 198 enum { | 195 static uint32_t HashGlyphID(uint32_t glyphID) { return SkChecksum::CheapMix
(glyphID); } |
| 199 kHashBits = 8, | 196 static uint32_t HashUnichar(SkUnichar unichar) { return SkChecksum::CheapMix
(unichar); } |
| 200 kHashCount = 1 << kHashBits, | |
| 201 kHashMask = kHashCount - 1 | |
| 202 }; | |
| 203 SkGlyph* fGlyphHash[kHashCount]; | |
| 204 SkTDArray<SkGlyph*> fGlyphArray; | |
| 205 SkChunkAlloc fGlyphAlloc; | |
| 206 | 197 |
| 207 struct CharGlyphRec { | 198 SkTHashMap<uint32_t, SkGlyph, HashGlyphID> fGlyphs; |
| 208 uint32_t fID; // unichar + subpixel | 199 SkTHashMap<SkUnichar, uint16_t, HashUnichar> fCharToGlyphID; |
| 209 SkGlyph* fGlyph; | |
| 210 }; | |
| 211 // no reason to use the same kHashCount as fGlyphHash, but we do for now | |
| 212 // Dynamically allocated when chars are encountered. | |
| 213 SkAutoTArray<CharGlyphRec> fCharToGlyphHash; | |
| 214 | |
| 215 CharGlyphRec* getCharGlyphRec(uint32_t id); | |
| 216 | 200 |
| 217 static inline unsigned ID2HashIndex(uint32_t h) { | 201 SkChunkAlloc fAlloc; |
| 218 return SkChecksum::CheapMix(h) & kHashMask; | |
| 219 } | |
| 220 | 202 |
| 221 // used to track (approx) how much ram is tied-up in this cache | 203 // used to track (approx) how much ram is tied-up in this cache |
| 222 size_t fMemoryUsed; | 204 size_t fMemoryUsed; |
| 223 | 205 |
| 224 | |
| 225 #ifdef SK_GLYPHCACHE_TRACK_HASH_STATS | |
| 226 int fHashHitCount; | |
| 227 int fHashMissCount; | |
| 228 #endif | |
| 229 | |
| 230 struct AuxProcRec { | 206 struct AuxProcRec { |
| 231 AuxProcRec* fNext; | 207 AuxProcRec* fNext; |
| 232 void (*fProc)(void*); | 208 void (*fProc)(void*); |
| 233 void* fData; | 209 void* fData; |
| 234 }; | 210 }; |
| 235 AuxProcRec* fAuxProcList; | 211 AuxProcRec* fAuxProcList; |
| 236 void invokeAndRemoveAuxProcs(); | 212 void invokeAndRemoveAuxProcs(); |
| 237 | 213 |
| 238 inline static SkGlyphCache* FindTail(SkGlyphCache* head); | 214 inline static SkGlyphCache* FindTail(SkGlyphCache* head); |
| 239 | 215 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 const SkMatrix* matrix) { | 280 const SkMatrix* matrix) { |
| 305 fCache = paint.detachCache(deviceProperties, matrix, true); | 281 fCache = paint.detachCache(deviceProperties, matrix, true); |
| 306 } | 282 } |
| 307 | 283 |
| 308 private: | 284 private: |
| 309 SkAutoGlyphCacheNoGamma() : SkAutoGlyphCacheBase() {} | 285 SkAutoGlyphCacheNoGamma() : SkAutoGlyphCacheBase() {} |
| 310 }; | 286 }; |
| 311 #define SkAutoGlyphCacheNoGamma(...) SK_REQUIRE_LOCAL_VAR(SkAutoGlyphCacheNoGamm
a) | 287 #define SkAutoGlyphCacheNoGamma(...) SK_REQUIRE_LOCAL_VAR(SkAutoGlyphCacheNoGamm
a) |
| 312 | 288 |
| 313 #endif | 289 #endif |
| OLD | NEW |