OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrBatchFontCache_DEFINED | 8 #ifndef GrBatchFontCache_DEFINED |
9 #define GrBatchFontCache_DEFINED | 9 #define GrBatchFontCache_DEFINED |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... |
26 public: | 26 public: |
27 GrBatchTextStrike(GrBatchFontCache*, const GrFontDescKey* fontScalerKey); | 27 GrBatchTextStrike(GrBatchFontCache*, const GrFontDescKey* fontScalerKey); |
28 ~GrBatchTextStrike(); | 28 ~GrBatchTextStrike(); |
29 | 29 |
30 const GrFontDescKey* getFontScalerKey() const { return fFontScalerKey; } | 30 const GrFontDescKey* getFontScalerKey() const { return fFontScalerKey; } |
31 GrBatchFontCache* getBatchFontCache() const { return fBatchFontCache; } | 31 GrBatchFontCache* getBatchFontCache() const { return fBatchFontCache; } |
32 | 32 |
33 inline GrGlyph* getGlyph(const SkGlyph& skGlyph, GrGlyph::PackedID packed, | 33 inline GrGlyph* getGlyph(const SkGlyph& skGlyph, GrGlyph::PackedID packed, |
34 GrFontScaler* scaler) { | 34 GrFontScaler* scaler) { |
35 GrGlyph* glyph = fCache.find(packed); | 35 GrGlyph* glyph = fCache.find(packed); |
36 if (NULL == glyph) { | 36 if (nullptr == glyph) { |
37 glyph = this->generateGlyph(skGlyph, packed, scaler); | 37 glyph = this->generateGlyph(skGlyph, packed, scaler); |
38 } | 38 } |
39 return glyph; | 39 return glyph; |
40 } | 40 } |
41 | 41 |
42 // This variant of the above function is called by TextBatch. At this point
, it is possible | 42 // This variant of the above function is called by TextBatch. At this point
, it is possible |
43 // that the maskformat of the glyph differs from what we expect. In these c
ases we will just | 43 // that the maskformat of the glyph differs from what we expect. In these c
ases we will just |
44 // draw a clear square. | 44 // draw a clear square. |
45 // skbug:4143 crbug:510931 | 45 // skbug:4143 crbug:510931 |
46 inline GrGlyph* getGlyph(const SkGlyph& skGlyph, GrGlyph::PackedID packed, | 46 inline GrGlyph* getGlyph(const SkGlyph& skGlyph, GrGlyph::PackedID packed, |
47 GrMaskFormat expectedMaskFormat, GrFontScaler* scal
er) { | 47 GrMaskFormat expectedMaskFormat, GrFontScaler* scal
er) { |
48 GrGlyph* glyph = fCache.find(packed); | 48 GrGlyph* glyph = fCache.find(packed); |
49 if (NULL == glyph) { | 49 if (nullptr == glyph) { |
50 glyph = this->generateGlyph(skGlyph, packed, scaler); | 50 glyph = this->generateGlyph(skGlyph, packed, scaler); |
51 glyph->fMaskFormat = expectedMaskFormat; | 51 glyph->fMaskFormat = expectedMaskFormat; |
52 } | 52 } |
53 return glyph; | 53 return glyph; |
54 } | 54 } |
55 | 55 |
56 // returns true if glyph successfully added to texture atlas, false otherwis
e. If the glyph's | 56 // returns true if glyph successfully added to texture atlas, false otherwis
e. If the glyph's |
57 // mask format has changed, then addGlyphToAtlas will draw a clear box. Thi
s will almost never | 57 // mask format has changed, then addGlyphToAtlas will draw a clear box. Thi
s will almost never |
58 // happen. | 58 // happen. |
59 // TODO we can handle some of these cases if we really want to, but the long
term solution is to | 59 // TODO we can handle some of these cases if we really want to, but the long
term solution is to |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 class GrBatchFontCache { | 102 class GrBatchFontCache { |
103 public: | 103 public: |
104 GrBatchFontCache(GrContext*); | 104 GrBatchFontCache(GrContext*); |
105 ~GrBatchFontCache(); | 105 ~GrBatchFontCache(); |
106 // The user of the cache may hold a long-lived ref to the returned strike. H
owever, actions by | 106 // The user of the cache may hold a long-lived ref to the returned strike. H
owever, actions by |
107 // another client of the cache may cause the strike to be purged while it is
still reffed. | 107 // another client of the cache may cause the strike to be purged while it is
still reffed. |
108 // Therefore, the caller must check GrBatchTextStrike::isAbandoned() if ther
e are other | 108 // Therefore, the caller must check GrBatchTextStrike::isAbandoned() if ther
e are other |
109 // interactions with the cache since the strike was received. | 109 // interactions with the cache since the strike was received. |
110 inline GrBatchTextStrike* getStrike(GrFontScaler* scaler) { | 110 inline GrBatchTextStrike* getStrike(GrFontScaler* scaler) { |
111 GrBatchTextStrike* strike = fCache.find(*(scaler->getKey())); | 111 GrBatchTextStrike* strike = fCache.find(*(scaler->getKey())); |
112 if (NULL == strike) { | 112 if (nullptr == strike) { |
113 strike = this->generateStrike(scaler); | 113 strike = this->generateStrike(scaler); |
114 } | 114 } |
115 return strike; | 115 return strike; |
116 } | 116 } |
117 | 117 |
118 void freeAll(); | 118 void freeAll(); |
119 | 119 |
120 // if getTexture returns NULL, the client must not try to use other function
s on the | 120 // if getTexture returns nullptr, the client must not try to use other funct
ions on the |
121 // GrBatchFontCache which use the atlas. This function *must* be called fir
st, before other | 121 // GrBatchFontCache which use the atlas. This function *must* be called fir
st, before other |
122 // functions which use the atlas. | 122 // functions which use the atlas. |
123 GrTexture* getTexture(GrMaskFormat format) { | 123 GrTexture* getTexture(GrMaskFormat format) { |
124 if (this->initAtlas(format)) { | 124 if (this->initAtlas(format)) { |
125 return this->getAtlas(format)->getTexture(); | 125 return this->getAtlas(format)->getTexture(); |
126 } | 126 } |
127 return NULL; | 127 return nullptr; |
128 } | 128 } |
129 | 129 |
130 bool hasGlyph(GrGlyph* glyph) { | 130 bool hasGlyph(GrGlyph* glyph) { |
131 SkASSERT(glyph); | 131 SkASSERT(glyph); |
132 return this->getAtlas(glyph->fMaskFormat)->hasID(glyph->fID); | 132 return this->getAtlas(glyph->fMaskFormat)->hasID(glyph->fID); |
133 } | 133 } |
134 | 134 |
135 // To ensure the GrBatchAtlas does not evict the Glyph Mask from its texture
backing store, | 135 // To ensure the GrBatchAtlas does not evict the Glyph Mask from its texture
backing store, |
136 // the client must pass in the current batch token along with the GrGlyph. | 136 // the client must pass in the current batch token along with the GrGlyph. |
137 // A BulkUseTokenUpdater is used to manage bulk last use token updating in t
he Atlas. | 137 // A BulkUseTokenUpdater is used to manage bulk last use token updating in t
he Atlas. |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 static void HandleEviction(GrBatchAtlas::AtlasID, void*); | 214 static void HandleEviction(GrBatchAtlas::AtlasID, void*); |
215 | 215 |
216 GrContext* fContext; | 216 GrContext* fContext; |
217 SkTDynamicHash<GrBatchTextStrike, GrFontDescKey> fCache; | 217 SkTDynamicHash<GrBatchTextStrike, GrFontDescKey> fCache; |
218 GrBatchAtlas* fAtlases[kMaskFormatCount]; | 218 GrBatchAtlas* fAtlases[kMaskFormatCount]; |
219 GrBatchTextStrike* fPreserveStrike; | 219 GrBatchTextStrike* fPreserveStrike; |
220 GrBatchAtlasConfig fAtlasConfigs[kMaskFormatCount]; | 220 GrBatchAtlasConfig fAtlasConfigs[kMaskFormatCount]; |
221 }; | 221 }; |
222 | 222 |
223 #endif | 223 #endif |
OLD | NEW |