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: |
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 | 49e8083 | 2013-10-07 18:20:27 +0000 | [diff] [blame] | 41 | bool getGlyphAtlas(GrGlyph*, GrFontScaler*); |
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 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 48 | |
commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 49 | // returns true if a plot was removed |
| 50 | bool removeUnusedPlots(); |
commit-bot@chromium.org | 67ed64e | 2013-08-05 19:42:56 +0000 | [diff] [blame] | 51 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 52 | public: |
| 53 | // for LRU |
| 54 | GrTextStrike* fPrev; |
| 55 | GrTextStrike* fNext; |
| 56 | |
| 57 | private: |
| 58 | class Key; |
| 59 | GrTHashTable<GrGlyph, Key, 7> fCache; |
| 60 | const GrKey* fFontScalerKey; |
| 61 | GrTAllocPool<GrGlyph> fPool; |
| 62 | |
| 63 | GrFontCache* fFontCache; |
| 64 | GrAtlasMgr* fAtlasMgr; |
skia.committer@gmail.com | 50df4d0 | 2013-09-28 07:01:33 +0000 | [diff] [blame] | 65 | GrAtlas fAtlas; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 66 | |
commit-bot@chromium.org | 9529441 | 2013-09-26 15:28:40 +0000 | [diff] [blame] | 67 | GrMaskFormat fMaskFormat; |
reed@google.com | 98539c6 | 2011-03-15 15:40:16 +0000 | [diff] [blame] | 68 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 69 | GrGlyph* generateGlyph(GrGlyph::PackedID packed, GrFontScaler* scaler); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 70 | |
| 71 | friend class GrFontCache; |
| 72 | }; |
| 73 | |
| 74 | class GrFontCache { |
| 75 | public: |
| 76 | GrFontCache(GrGpu*); |
| 77 | ~GrFontCache(); |
| 78 | |
| 79 | inline GrTextStrike* getStrike(GrFontScaler*); |
| 80 | |
| 81 | void freeAll(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 82 | |
| 83 | void purgeExceptFor(GrTextStrike*); |
| 84 | |
commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 85 | // remove an unused plot and its strike (if necessary) |
| 86 | void freePlotExceptFor(GrTextStrike*); |
commit-bot@chromium.org | 67ed64e | 2013-08-05 19:42:56 +0000 | [diff] [blame] | 87 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 88 | // testing |
| 89 | int countStrikes() const { return fCache.getArray().count(); } |
| 90 | const GrTextStrike* strikeAt(int index) const { |
| 91 | return fCache.getArray()[index]; |
| 92 | } |
| 93 | GrTextStrike* getHeadStrike() const { return fHead; } |
| 94 | |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 95 | #ifdef SK_DEBUG |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 96 | void validate() const; |
| 97 | #else |
| 98 | void validate() const {} |
| 99 | #endif |
| 100 | |
commit-bot@chromium.org | 03e3e89 | 2013-10-02 18:19:17 +0000 | [diff] [blame] | 101 | #ifdef SK_DEVELOPER |
| 102 | void dump() const; |
| 103 | #endif |
| 104 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 105 | private: |
| 106 | friend class GrFontPurgeListener; |
| 107 | |
| 108 | class Key; |
| 109 | GrTHashTable<GrTextStrike, Key, 8> fCache; |
| 110 | // for LRU |
| 111 | GrTextStrike* fHead; |
| 112 | GrTextStrike* fTail; |
| 113 | |
| 114 | GrGpu* fGpu; |
commit-bot@chromium.org | 3fddf0e | 2013-09-26 12:57:19 +0000 | [diff] [blame] | 115 | GrAtlasMgr* fAtlasMgr[kMaskFormatCount]; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +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 |