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 found in the LICENSE file. | 4 * Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 #ifndef SkGlyphCache_DEFINED | 7 #ifndef SkGlyphCache_DEFINED |
8 #define SkGlyphCache_DEFINED | 8 #define SkGlyphCache_DEFINED |
9 | 9 |
10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
11 #include "SkChecksum.h" | 11 #include "SkChecksum.h" |
12 #include "SkChunkAlloc.h" | 12 #include "SkChunkAlloc.h" |
13 #include "SkDescriptor.h" | 13 #include "SkDescriptor.h" |
14 #include "SkGlyph.h" | 14 #include "SkGlyph.h" |
15 #include "SkTHash.h" | |
15 #include "SkScalerContext.h" | 16 #include "SkScalerContext.h" |
16 #include "SkTemplates.h" | 17 #include "SkTemplates.h" |
17 #include "SkTDArray.h" | 18 #include "SkTDArray.h" |
18 | 19 |
19 class SkPaint; | 20 class SkPaint; |
20 | 21 |
21 class SkGlyphCache_Globals; | 22 class SkGlyphCache_Globals; |
22 | 23 |
24 class GlyphTrait { | |
mtklein
2015/06/30 16:20:47
Might want to call this SkGlyphHashTraits, or nest
herb_g
2015/07/06 16:32:19
Done.
| |
25 public: | |
26 static int32_t GetKey(const SkGlyph& glyph) { | |
reed1
2015/06/29 20:59:48
nit: do we really need signed -vs- unsigned 32 int
mtklein
2015/06/30 16:20:47
+1, particularly because fID is an uint32_t (and i
herb_g
2015/07/06 16:32:19
Done.
herb_g
2015/07/06 16:32:19
Done.
| |
27 return glyph.fID; | |
28 } | |
29 static uint32_t Hash(int32_t glyphId) { | |
30 return SkChecksum::CheapMix(glyphId); | |
31 } | |
32 }; | |
33 | |
23 // Enable this locally to add stats for hash-table hit rates. It also extends th e dump() output | 34 // Enable this locally to add stats for hash-table hit rates. It also extends th e dump() output |
24 // to show those stats. | 35 // to show those stats. |
25 //#define SK_GLYPHCACHE_TRACK_HASH_STATS | 36 //#define SK_GLYPHCACHE_TRACK_HASH_STATS |
26 | 37 |
27 /** \class SkGlyphCache | 38 /** \class SkGlyphCache |
28 | 39 |
29 This class represents a strike: a specific combination of typeface, size, ma trix, etc., and | 40 This class represents a strike: a specific combination of typeface, size, ma trix, etc., and |
30 holds the glyphs for that strike. Calling any of the getUnichar.../getGlyphI D... methods will | 41 holds the glyphs for that strike. Calling any of the getUnichar.../getGlyphI D... methods will |
31 return the requested glyph, either instantly if it is already cached, or by first generating | 42 return the requested glyph, either instantly if it is already cached, or by first generating |
32 it and then adding it to the strike. | 43 it and then adding it to the strike. |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
176 }; | 187 }; |
177 | 188 |
178 enum { | 189 enum { |
179 kHashBits = 8, | 190 kHashBits = 8, |
180 kHashCount = 1 << kHashBits, | 191 kHashCount = 1 << kHashBits, |
181 kHashMask = kHashCount - 1 | 192 kHashMask = kHashCount - 1 |
182 }; | 193 }; |
183 | 194 |
184 struct CharGlyphRec { | 195 struct CharGlyphRec { |
185 uint32_t fID; // unichar + subpixel | 196 uint32_t fID; // unichar + subpixel |
186 uint16_t fGlyphIndex; | 197 uint32_t fCombinedID; |
mtklein
2015/06/30 16:20:47
Boy this is getting confusing. Can we name these
herb_g
2015/07/06 16:32:19
This is really a glyphID and subpixel positioning.
| |
187 }; | 198 }; |
188 | 199 |
189 struct AuxProcRec { | 200 struct AuxProcRec { |
190 AuxProcRec* fNext; | 201 AuxProcRec* fNext; |
191 void (*fProc)(void*); | 202 void (*fProc)(void*); |
192 void* fData; | 203 void* fData; |
193 }; | 204 }; |
194 | 205 |
195 // SkGlyphCache takes ownership of the scalercontext. | 206 // SkGlyphCache takes ownership of the scalercontext. |
196 SkGlyphCache(SkTypeface*, const SkDescriptor*, SkScalerContext*); | 207 SkGlyphCache(SkTypeface*, const SkDescriptor*, SkScalerContext*); |
197 ~SkGlyphCache(); | 208 ~SkGlyphCache(); |
198 | 209 |
199 // Return the SkGlyph* associated with MakeID. The id parameter is the | 210 // Return the SkGlyph* associated with MakeID. The id parameter is the |
200 // combined glyph/x/y id generated by MakeID. If it is just a glyph id | 211 // combined glyph/x/y id generated by MakeID. If it is just a glyph id |
201 // then x and y are assumed to be zero. | 212 // then x and y are assumed to be zero. |
202 SkGlyph* lookupByCombinedID(uint32_t id, MetricsType type); | 213 SkGlyph* lookupByCombinedID(uint32_t id, MetricsType type); |
203 | 214 |
204 // Return a SkGlyph* associated with unicode id and position x and y. | 215 // Return a SkGlyph* associated with unicode id and position x and y. |
205 SkGlyph* lookupByChar(SkUnichar id, MetricsType type, SkFixed x = 0, SkFixed y = 0); | 216 SkGlyph* lookupByChar(SkUnichar id, MetricsType type, SkFixed x = 0, SkFixed y = 0); |
206 | 217 |
207 // Return the index of id in the fGlyphArray. If it does not exist, | 218 // Return the index of id in the fGlyphArray. If it does not exist, |
208 // create a new one using MetricsType. | 219 // create a new one using MetricsType. |
209 uint16_t lookupMetrics(uint32_t id, MetricsType type); | 220 SkGlyph* lookupMetrics(uint32_t id, MetricsType type); |
210 static bool DetachProc(const SkGlyphCache*, void*) { return true; } | 221 static bool DetachProc(const SkGlyphCache*, void*) { return true; } |
211 | 222 |
212 // The id arg is a combined id generated by MakeID. | 223 // The id arg is a combined id generated by MakeID. |
213 CharGlyphRec* getCharGlyphRec(uint32_t id); | 224 CharGlyphRec* getCharGlyphRec(uint32_t id); |
214 void adjustCaches(int insertion_index); | |
215 | 225 |
216 static inline unsigned ID2HashIndex(uint32_t h) { | 226 static inline unsigned ID2HashIndex(uint32_t h) { |
217 return SkChecksum::CheapMix(h) & kHashMask; | 227 return SkChecksum::CheapMix(h) & kHashMask; |
218 } | 228 } |
219 | 229 |
220 void invokeAndRemoveAuxProcs(); | 230 void invokeAndRemoveAuxProcs(); |
221 | 231 |
222 inline static SkGlyphCache* FindTail(SkGlyphCache* head); | 232 inline static SkGlyphCache* FindTail(SkGlyphCache* head); |
223 | 233 |
224 SkGlyphCache* fNext, *fPrev; | 234 SkGlyphCache* fNext, *fPrev; |
225 SkDescriptor* fDesc; | 235 SkDescriptor* fDesc; |
226 SkScalerContext* fScalerContext; | 236 SkScalerContext* fScalerContext; |
227 SkPaint::FontMetrics fFontMetrics; | 237 SkPaint::FontMetrics fFontMetrics; |
228 | 238 |
229 // A quick lookup to avoid the binary search looking for glyphs in fGlyphArr ay. | 239 // A quick lookup to avoid the binary search looking for glyphs in fGlyphArr ay. |
230 uint16_t fGlyphHash[kHashCount]; | 240 //uint16_t fGlyphHash[kHashCount]; |
231 | 241 |
232 // Contains the SkGlyphs that are used by fGlyphHash and fCharToGlyphHash. T he ~0 element is | 242 // Contains the SkGlyphs that are used by fGlyphHash and fCharToGlyphHash. T he ~0 element is |
233 // reserved for a sentinel SkGlyph that reduces the logic to check for colli sions in the hash | 243 // reserved for a sentinel SkGlyph that reduces the logic to check for colli sions in the hash |
234 // arrays. The ~0 element has an fID of SkGlyph::kImpossibleID which never m atches any | 244 // arrays. The ~0 element has an fID of SkGlyph::kImpossibleID which never m atches any |
235 // combined id generated for a char or a glyph. | 245 // combined id generated for a char or a glyph. |
236 SkTDArray<SkGlyph> fGlyphArray; | 246 //SkTDArray<SkGlyph> fGlyphArray; |
mtklein
2015/06/30 16:20:47
Let's kill off the dead code and update the commen
herb_g
2015/07/06 16:32:19
Done.
| |
247 SkTHashTable<SkGlyph, int32_t, GlyphTrait> fGlyphMap; | |
248 | |
237 SkChunkAlloc fGlyphAlloc; | 249 SkChunkAlloc fGlyphAlloc; |
238 | 250 |
239 // no reason to use the same kHashCount as fGlyphHash, but we do for now | 251 // no reason to use the same kHashCount as fGlyphHash, but we do for now |
240 // Dynamically allocated when chars are encountered. | 252 // Dynamically allocated when chars are encountered. |
241 SkAutoTArray<CharGlyphRec> fCharToGlyphHash; | 253 SkAutoTArray<CharGlyphRec> fCharToGlyphHash; |
242 | 254 |
243 // used to track (approx) how much ram is tied-up in this cache | 255 // used to track (approx) how much ram is tied-up in this cache |
244 size_t fMemoryUsed; | 256 size_t fMemoryUsed; |
245 | 257 |
246 #ifdef SK_GLYPHCACHE_TRACK_HASH_STATS | 258 #ifdef SK_GLYPHCACHE_TRACK_HASH_STATS |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
315 const SkMatrix* matrix) { | 327 const SkMatrix* matrix) { |
316 fCache = paint.detachCache(surfaceProps, matrix, true); | 328 fCache = paint.detachCache(surfaceProps, matrix, true); |
317 } | 329 } |
318 | 330 |
319 private: | 331 private: |
320 SkAutoGlyphCacheNoGamma() : SkAutoGlyphCacheBase() {} | 332 SkAutoGlyphCacheNoGamma() : SkAutoGlyphCacheBase() {} |
321 }; | 333 }; |
322 #define SkAutoGlyphCacheNoGamma(...) SK_REQUIRE_LOCAL_VAR(SkAutoGlyphCacheNoGamm a) | 334 #define SkAutoGlyphCacheNoGamma(...) SK_REQUIRE_LOCAL_VAR(SkAutoGlyphCacheNoGamm a) |
323 | 335 |
324 #endif | 336 #endif |
OLD | NEW |