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