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