| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1 | /* |
| 2 | Copyright 2010 Google Inc. |
| 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | you may not use this file except in compliance with the License. |
| 6 | You may obtain a copy of the License at |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | |
| 18 | #ifndef GrTextStrike_DEFINED |
| 19 | #define GrTextStrike_DEFINED |
| 20 | |
| 21 | #include "GrAllocPool.h" |
| 22 | #include "GrFontScaler.h" |
| 23 | #include "GrTHashCache.h" |
| 24 | #include "GrPoint.h" |
| 25 | #include "GrGlyph.h" |
| 26 | |
| 27 | class GrAtlasMgr; |
| 28 | class GrFontCache; |
| 29 | class GrGpu; |
| 30 | class GrFontPurgeListener; |
| 31 | |
| 32 | /** |
| 33 | * The textcache maps a hostfontscaler instance to a dictionary of |
| 34 | * glyphid->strike |
| 35 | */ |
| 36 | class GrTextStrike { |
| 37 | public: |
| reed@google.com | 98539c6 | 2011-03-15 15:40:16 +0000 | [diff] [blame] | 38 | GrTextStrike(GrFontCache*, const GrKey* fontScalerKey, GrMaskFormat, |
| 39 | GrAtlasMgr*); |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 40 | ~GrTextStrike(); |
| 41 | |
| 42 | const GrKey* getFontScalerKey() const { return fFontScalerKey; } |
| 43 | GrFontCache* getFontCache() const { return fFontCache; } |
| reed@google.com | 98539c6 | 2011-03-15 15:40:16 +0000 | [diff] [blame] | 44 | GrMaskFormat getMaskFormat() const { return fMaskFormat; } |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 45 | |
| 46 | inline GrGlyph* getGlyph(GrGlyph::PackedID, GrFontScaler*); |
| 47 | bool getGlyphAtlas(GrGlyph*, GrFontScaler*); |
| 48 | |
| 49 | // testing |
| 50 | int countGlyphs() const { return fCache.getArray().count(); } |
| 51 | const GrGlyph* glyphAt(int index) const { |
| 52 | return fCache.getArray()[index]; |
| 53 | } |
| 54 | GrAtlas* getAtlas() const { return fAtlas; } |
| 55 | |
| 56 | public: |
| 57 | // for LRU |
| 58 | GrTextStrike* fPrev; |
| 59 | GrTextStrike* fNext; |
| 60 | |
| 61 | private: |
| 62 | class Key; |
| 63 | GrTHashTable<GrGlyph, Key, 7> fCache; |
| 64 | const GrKey* fFontScalerKey; |
| 65 | GrTAllocPool<GrGlyph> fPool; |
| 66 | |
| 67 | GrFontCache* fFontCache; |
| 68 | GrAtlasMgr* fAtlasMgr; |
| 69 | GrAtlas* fAtlas; // linklist |
| 70 | |
| reed@google.com | 98539c6 | 2011-03-15 15:40:16 +0000 | [diff] [blame] | 71 | GrMaskFormat fMaskFormat; |
| 72 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 73 | GrGlyph* generateGlyph(GrGlyph::PackedID packed, GrFontScaler* scaler); |
| 74 | // returns true if after the purge, the strike is empty |
| 75 | bool purgeAtlasAtY(GrAtlas* atlas, int yCoord); |
| 76 | |
| 77 | friend class GrFontCache; |
| 78 | }; |
| 79 | |
| 80 | class GrFontCache { |
| 81 | public: |
| 82 | GrFontCache(GrGpu*); |
| 83 | ~GrFontCache(); |
| 84 | |
| 85 | inline GrTextStrike* getStrike(GrFontScaler*); |
| 86 | |
| 87 | void freeAll(); |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 88 | |
| 89 | void purgeExceptFor(GrTextStrike*); |
| 90 | |
| 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 | |
| 98 | #if GR_DEBUG |
| 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; |
| 114 | GrAtlasMgr* fAtlasMgr; |
| 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 |
| 122 | |