epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 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. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 10 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 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" |
commit-bot@chromium.org | a8916ff | 2013-08-16 15:53:46 +0000 | [diff] [blame] | 19 | #include "GrDrawTarget.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 20 | |
| 21 | class GrAtlasMgr; |
| 22 | class GrFontCache; |
| 23 | class GrGpu; |
| 24 | class GrFontPurgeListener; |
| 25 | |
| 26 | /** |
| 27 | * The textcache maps a hostfontscaler instance to a dictionary of |
| 28 | * glyphid->strike |
| 29 | */ |
| 30 | class GrTextStrike { |
| 31 | public: |
reed@google.com | 98539c6 | 2011-03-15 15:40:16 +0000 | [diff] [blame] | 32 | GrTextStrike(GrFontCache*, const GrKey* fontScalerKey, GrMaskFormat, |
| 33 | GrAtlasMgr*); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 34 | ~GrTextStrike(); |
| 35 | |
| 36 | const GrKey* getFontScalerKey() const { return fFontScalerKey; } |
| 37 | GrFontCache* getFontCache() const { return fFontCache; } |
reed@google.com | 98539c6 | 2011-03-15 15:40:16 +0000 | [diff] [blame] | 38 | GrMaskFormat getMaskFormat() const { return fMaskFormat; } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 39 | |
| 40 | inline GrGlyph* getGlyph(GrGlyph::PackedID, GrFontScaler*); |
commit-bot@chromium.org | a8916ff | 2013-08-16 15:53:46 +0000 | [diff] [blame] | 41 | bool getGlyphAtlas(GrGlyph*, GrFontScaler*, GrDrawTarget::DrawToken currentDrawToken); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 42 | |
| 43 | // testing |
| 44 | int countGlyphs() const { return fCache.getArray().count(); } |
| 45 | const GrGlyph* glyphAt(int index) const { |
| 46 | return fCache.getArray()[index]; |
| 47 | } |
| 48 | GrAtlas* getAtlas() const { return fAtlas; } |
| 49 | |
commit-bot@chromium.org | 67ed64e | 2013-08-05 19:42:56 +0000 | [diff] [blame] | 50 | // returns true if an atlas was removed |
| 51 | bool removeUnusedAtlases(); |
| 52 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 53 | public: |
| 54 | // for LRU |
| 55 | GrTextStrike* fPrev; |
| 56 | GrTextStrike* fNext; |
| 57 | |
| 58 | private: |
| 59 | class Key; |
| 60 | GrTHashTable<GrGlyph, Key, 7> fCache; |
| 61 | const GrKey* fFontScalerKey; |
| 62 | GrTAllocPool<GrGlyph> fPool; |
| 63 | |
| 64 | GrFontCache* fFontCache; |
| 65 | GrAtlasMgr* fAtlasMgr; |
| 66 | GrAtlas* fAtlas; // linklist |
| 67 | |
reed@google.com | 98539c6 | 2011-03-15 15:40:16 +0000 | [diff] [blame] | 68 | GrMaskFormat fMaskFormat; |
| 69 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 70 | GrGlyph* generateGlyph(GrGlyph::PackedID packed, GrFontScaler* scaler); |
| 71 | // returns true if after the purge, the strike is empty |
| 72 | bool purgeAtlasAtY(GrAtlas* atlas, int yCoord); |
| 73 | |
| 74 | friend class GrFontCache; |
| 75 | }; |
| 76 | |
| 77 | class GrFontCache { |
| 78 | public: |
| 79 | GrFontCache(GrGpu*); |
| 80 | ~GrFontCache(); |
| 81 | |
| 82 | inline GrTextStrike* getStrike(GrFontScaler*); |
| 83 | |
| 84 | void freeAll(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 85 | |
| 86 | void purgeExceptFor(GrTextStrike*); |
| 87 | |
commit-bot@chromium.org | 67ed64e | 2013-08-05 19:42:56 +0000 | [diff] [blame] | 88 | // remove an unused atlas and its strike (if necessary) |
| 89 | void freeAtlasExceptFor(GrTextStrike*); |
| 90 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 91 | // testing |
| 92 | int countStrikes() const { return fCache.getArray().count(); } |
| 93 | const GrTextStrike* strikeAt(int index) const { |
| 94 | return fCache.getArray()[index]; |
| 95 | } |
| 96 | GrTextStrike* getHeadStrike() const { return fHead; } |
| 97 | |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 98 | #ifdef SK_DEBUG |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 99 | void validate() const; |
| 100 | #else |
| 101 | void validate() const {} |
| 102 | #endif |
| 103 | |
| 104 | private: |
| 105 | friend class GrFontPurgeListener; |
| 106 | |
| 107 | class Key; |
| 108 | GrTHashTable<GrTextStrike, Key, 8> fCache; |
| 109 | // for LRU |
| 110 | GrTextStrike* fHead; |
| 111 | GrTextStrike* fTail; |
| 112 | |
| 113 | GrGpu* fGpu; |
commit-bot@chromium.org | 3fddf0e | 2013-09-26 12:57:19 +0000 | [diff] [blame^] | 114 | GrAtlasMgr* fAtlasMgr[kMaskFormatCount]; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 115 | |
reed@google.com | 98539c6 | 2011-03-15 15:40:16 +0000 | [diff] [blame] | 116 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 117 | GrTextStrike* generateStrike(GrFontScaler*, const Key&); |
| 118 | inline void detachStrikeFromList(GrTextStrike*); |
| 119 | }; |
| 120 | |
| 121 | #endif |