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" |
mtklein@google.com | 4c2af74 | 2013-10-21 21:04:06 +0000 | [diff] [blame] | 16 | #include "GrTHashTable.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 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" |
commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 20 | #include "GrAtlas.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 21 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 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: |
commit-bot@chromium.org | b2e9fa5 | 2013-10-27 20:50:23 +0000 | [diff] [blame] | 32 | GrTextStrike(GrFontCache*, const GrKey* fontScalerKey, GrMaskFormat, GrAtlasMgr*); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 33 | ~GrTextStrike(); |
| 34 | |
| 35 | const GrKey* getFontScalerKey() const { return fFontScalerKey; } |
| 36 | GrFontCache* getFontCache() const { return fFontCache; } |
reed@google.com | 98539c6 | 2011-03-15 15:40:16 +0000 | [diff] [blame] | 37 | GrMaskFormat getMaskFormat() const { return fMaskFormat; } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 38 | |
| 39 | inline GrGlyph* getGlyph(GrGlyph::PackedID, GrFontScaler*); |
commit-bot@chromium.org | 49e8083 | 2013-10-07 18:20:27 +0000 | [diff] [blame] | 40 | bool getGlyphAtlas(GrGlyph*, GrFontScaler*); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 41 | |
| 42 | // testing |
| 43 | int countGlyphs() const { return fCache.getArray().count(); } |
| 44 | const GrGlyph* glyphAt(int index) const { |
| 45 | return fCache.getArray()[index]; |
| 46 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 47 | |
commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 48 | // returns true if a plot was removed |
| 49 | bool removeUnusedPlots(); |
commit-bot@chromium.org | 67ed64e | 2013-08-05 19:42:56 +0000 | [diff] [blame] | 50 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 51 | public: |
| 52 | // for LRU |
| 53 | GrTextStrike* fPrev; |
| 54 | GrTextStrike* fNext; |
| 55 | |
| 56 | private: |
| 57 | class Key; |
| 58 | GrTHashTable<GrGlyph, Key, 7> fCache; |
| 59 | const GrKey* fFontScalerKey; |
| 60 | GrTAllocPool<GrGlyph> fPool; |
| 61 | |
| 62 | GrFontCache* fFontCache; |
| 63 | GrAtlasMgr* fAtlasMgr; |
commit-bot@chromium.org | 9529441 | 2013-09-26 15:28:40 +0000 | [diff] [blame] | 64 | GrMaskFormat fMaskFormat; |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 65 | #if SK_DISTANCEFIELD_FONTS |
| 66 | bool fUseDistanceField; |
| 67 | #endif |
| 68 | |
| 69 | GrAtlas fAtlas; |
reed@google.com | 98539c6 | 2011-03-15 15:40:16 +0000 | [diff] [blame] | 70 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 71 | GrGlyph* generateGlyph(GrGlyph::PackedID packed, GrFontScaler* scaler); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 72 | |
| 73 | friend class GrFontCache; |
| 74 | }; |
| 75 | |
| 76 | class GrFontCache { |
| 77 | public: |
| 78 | GrFontCache(GrGpu*); |
| 79 | ~GrFontCache(); |
| 80 | |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 81 | #if SK_DISTANCEFIELD_FONTS |
| 82 | inline GrTextStrike* getStrike(GrFontScaler*, bool useDistanceField); |
| 83 | #else |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 84 | inline GrTextStrike* getStrike(GrFontScaler*); |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 85 | #endif |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 86 | |
| 87 | void freeAll(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 88 | |
| 89 | void purgeExceptFor(GrTextStrike*); |
| 90 | |
commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 91 | // remove an unused plot and its strike (if necessary) |
| 92 | void freePlotExceptFor(GrTextStrike*); |
commit-bot@chromium.org | 67ed64e | 2013-08-05 19:42:56 +0000 | [diff] [blame] | 93 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 94 | // testing |
| 95 | int countStrikes() const { return fCache.getArray().count(); } |
| 96 | const GrTextStrike* strikeAt(int index) const { |
| 97 | return fCache.getArray()[index]; |
| 98 | } |
| 99 | GrTextStrike* getHeadStrike() const { return fHead; } |
| 100 | |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 101 | #ifdef SK_DEBUG |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 102 | void validate() const; |
| 103 | #else |
| 104 | void validate() const {} |
| 105 | #endif |
| 106 | |
commit-bot@chromium.org | 03e3e89 | 2013-10-02 18:19:17 +0000 | [diff] [blame] | 107 | #ifdef SK_DEVELOPER |
| 108 | void dump() const; |
| 109 | #endif |
| 110 | |
commit-bot@chromium.org | f8cb184 | 2013-12-03 19:45:22 +0000 | [diff] [blame] | 111 | enum AtlasType { |
| 112 | kA8_AtlasType, //!< 1-byte per pixel |
| 113 | k565_AtlasType, //!< 2-bytes per pixel |
| 114 | k8888_AtlasType, //!< 4-bytes per pixel |
| 115 | |
| 116 | kLast_AtlasType = k8888_AtlasType |
| 117 | }; |
| 118 | static const int kAtlasCount = kLast_AtlasType + 1; |
| 119 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 120 | private: |
| 121 | friend class GrFontPurgeListener; |
| 122 | |
| 123 | class Key; |
| 124 | GrTHashTable<GrTextStrike, Key, 8> fCache; |
| 125 | // for LRU |
| 126 | GrTextStrike* fHead; |
| 127 | GrTextStrike* fTail; |
| 128 | |
| 129 | GrGpu* fGpu; |
commit-bot@chromium.org | f8cb184 | 2013-12-03 19:45:22 +0000 | [diff] [blame] | 130 | GrAtlasMgr* fAtlasMgr[kAtlasCount]; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 131 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 132 | GrTextStrike* generateStrike(GrFontScaler*, const Key&); |
| 133 | inline void detachStrikeFromList(GrTextStrike*); |
commit-bot@chromium.org | b2e9fa5 | 2013-10-27 20:50:23 +0000 | [diff] [blame] | 134 | void purgeStrike(GrTextStrike* strike); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 135 | }; |
| 136 | |
| 137 | #endif |