1 2 /* 3 * Copyright 2010 Google Inc. 4 * 5 * Use of this source code is governed by a BSD-style license that can be 6 * found in the LICENSE file. 7 */ 8 9 10 11 #ifndef GrTextStrike_DEFINED 12 #define GrTextStrike_DEFINED 13 14 #include "GrAllocPool.h" 15 #include "GrFontScaler.h" 16 #include "GrTHashCache.h" 17 #include "GrPoint.h" 18 #include "GrGlyph.h" 19 20 class GrAtlasMgr; 21 class GrFontCache; 22 class GrGpu; 23 class GrFontPurgeListener; 24 25 /** 26 * The textcache maps a hostfontscaler instance to a dictionary of 27 * glyphid->strike 28 */ 29 class GrTextStrike { 30 public: 31 GrTextStrike(GrFontCache*, const GrKey* fontScalerKey, GrMaskFormat, 32 GrAtlasMgr*); 33 ~GrTextStrike(); 34 35 const GrKey* getFontScalerKey() const { return fFontScalerKey; } 36 GrFontCache* getFontCache() const { return fFontCache; } 37 GrMaskFormat getMaskFormat() const { return fMaskFormat; } 38 39 inline GrGlyph* getGlyph(GrGlyph::PackedID, GrFontScaler*); 40 bool getGlyphAtlas(GrGlyph*, GrFontScaler*); 41 42 // testing 43 int countGlyphs() const { return fCache.getArray().count(); } 44 const GrGlyph* glyphAt(int index) const { 45 return fCache.getArray()[index]; 46 } 47 GrAtlas* getAtlas() const { return fAtlas; } 48 49 public: 50 // for LRU 51 GrTextStrike* fPrev; 52 GrTextStrike* fNext; 53 54 private: 55 class Key; 56 GrTHashTable<GrGlyph, Key, 7> fCache; 57 const GrKey* fFontScalerKey; 58 GrTAllocPool<GrGlyph> fPool; 59 60 GrFontCache* fFontCache; 61 GrAtlasMgr* fAtlasMgr; 62 GrAtlas* fAtlas; // linklist 63 64 GrMaskFormat fMaskFormat; 65 66 GrGlyph* generateGlyph(GrGlyph::PackedID packed, GrFontScaler* scaler); 67 // returns true if after the purge, the strike is empty 68 bool purgeAtlasAtY(GrAtlas* atlas, int yCoord); 69 70 friend class GrFontCache; 71 }; 72 73 class GrFontCache { 74 public: 75 GrFontCache(GrGpu*); 76 ~GrFontCache(); 77 78 inline GrTextStrike* getStrike(GrFontScaler*); 79 80 void freeAll(); 81 82 void purgeExceptFor(GrTextStrike*); 83 84 // testing 85 int countStrikes() const { return fCache.getArray().count(); } 86 const GrTextStrike* strikeAt(int index) const { 87 return fCache.getArray()[index]; 88 } 89 GrTextStrike* getHeadStrike() const { return fHead; } 90 91 #if GR_DEBUG 92 void validate() const; 93 #else 94 void validate() const {} 95 #endif 96 97 private: 98 friend class GrFontPurgeListener; 99 100 class Key; 101 GrTHashTable<GrTextStrike, Key, 8> fCache; 102 // for LRU 103 GrTextStrike* fHead; 104 GrTextStrike* fTail; 105 106 GrGpu* fGpu; 107 GrAtlasMgr* fAtlasMgr; 108 109 110 GrTextStrike* generateStrike(GrFontScaler*, const Key&); 111 inline void detachStrikeFromList(GrTextStrike*); 112 }; 113 114 #endif 115