Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Side by Side Diff: src/gpu/text/GrBatchFontCache.h

Issue 1988833003: Remove GrFontDescKey. (Closed) Base URL: https://chromium.googlesource.com/skia.git@fontscaler
Patch Set: spelling fix Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/gpu/text/GrBatchFontCache.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 #include "GrBatchAtlas.h" 11 #include "GrBatchAtlas.h"
12 #include "GrFontScaler.h" 12 #include "GrFontScaler.h"
13 #include "GrGlyph.h" 13 #include "GrGlyph.h"
14 #include "SkGlyph.h" 14 #include "SkGlyph.h"
15 #include "SkTDynamicHash.h" 15 #include "SkTDynamicHash.h"
16 #include "SkVarAlloc.h" 16 #include "SkVarAlloc.h"
17 17
18 class GrBatchFontCache; 18 class GrBatchFontCache;
19 class GrGpu; 19 class GrGpu;
20 20
21 /** 21 /**
22 * The GrBatchTextStrike manages a pool of CPU backing memory for GrGlyphs. Th is backing memory 22 * The GrBatchTextStrike manages a pool of CPU backing memory for GrGlyphs. Th is backing memory
23 * is indexed by a PackedID and GrFontScaler. The GrFontScaler is what actuall y creates the mask. 23 * is indexed by a PackedID and GrFontScaler. The GrFontScaler is what actually creates the mask.
24 * The GrBatchTextStrike may outlive the generating GrFontScaler. However, it r etains a copy
25 * of it's SkDescriptor as a key to access (or regenerate) the GrFontScaler. Gr BatchTextStrikes are
26 * created by and owned by a GrBatchFontCache.
24 */ 27 */
25 class GrBatchTextStrike : public SkNVRefCnt<GrBatchTextStrike> { 28 class GrBatchTextStrike : public SkNVRefCnt<GrBatchTextStrike> {
26 public: 29 public:
27 GrBatchTextStrike(GrBatchFontCache*, const GrFontDescKey* fontScalerKey); 30 /** Owner is the cache that owns this strike. */
31 GrBatchTextStrike(GrBatchFontCache* owner, const SkDescriptor& fontScalerKey );
28 ~GrBatchTextStrike(); 32 ~GrBatchTextStrike();
29 33
30 const GrFontDescKey* getFontScalerKey() const { return fFontScalerKey; }
31 GrBatchFontCache* getBatchFontCache() const { return fBatchFontCache; }
32
33 inline GrGlyph* getGlyph(const SkGlyph& skGlyph, GrGlyph::PackedID packed, 34 inline GrGlyph* getGlyph(const SkGlyph& skGlyph, GrGlyph::PackedID packed,
34 GrFontScaler* scaler) { 35 GrFontScaler* scaler) {
35 GrGlyph* glyph = fCache.find(packed); 36 GrGlyph* glyph = fCache.find(packed);
36 if (nullptr == glyph) { 37 if (nullptr == glyph) {
37 glyph = this->generateGlyph(skGlyph, packed, scaler); 38 glyph = this->generateGlyph(skGlyph, packed, scaler);
38 } 39 }
39 return glyph; 40 return glyph;
40 } 41 }
41 42
42 // This variant of the above function is called by TextBatch. At this point , it is possible 43 // This variant of the above function is called by TextBatch. At this point , it is possible
(...skipping 25 matching lines...) Expand all
68 69
69 // testing 70 // testing
70 int countGlyphs() const { return fCache.count(); } 71 int countGlyphs() const { return fCache.count(); }
71 72
72 // remove any references to this plot 73 // remove any references to this plot
73 void removeID(GrBatchAtlas::AtlasID); 74 void removeID(GrBatchAtlas::AtlasID);
74 75
75 // If a TextStrike is abandoned by the cache, then the caller must get a new strike 76 // If a TextStrike is abandoned by the cache, then the caller must get a new strike
76 bool isAbandoned() const { return fIsAbandoned; } 77 bool isAbandoned() const { return fIsAbandoned; }
77 78
78 static const GrFontDescKey& GetKey(const GrBatchTextStrike& ts) { 79 static const SkDescriptor& GetKey(const GrBatchTextStrike& ts) {
79 return *(ts.fFontScalerKey); 80 return *ts.fFontScalerKey.getDesc();
80 } 81 }
81 static uint32_t Hash(const GrFontDescKey& key) { 82
82 return key.getHash(); 83 static uint32_t Hash(const SkDescriptor& desc) { return desc.getChecksum(); }
83 }
84 84
85 private: 85 private:
86 SkTDynamicHash<GrGlyph, GrGlyph::PackedID> fCache; 86 SkTDynamicHash<GrGlyph, GrGlyph::PackedID> fCache;
87 SkAutoTUnref<const GrFontDescKey> fFontScalerKey; 87 SkAutoDescriptor fFontScalerKey;
88 SkVarAlloc fPool; 88 SkVarAlloc fPool;
89 89
90 GrBatchFontCache* fBatchFontCache; 90 GrBatchFontCache* fBatchFontCache;
91 int fAtlasedGlyphs; 91 int fAtlasedGlyphs;
92 bool fIsAbandoned; 92 bool fIsAbandoned;
93 93
94 GrGlyph* generateGlyph(const SkGlyph&, GrGlyph::PackedID, GrFontScaler*); 94 GrGlyph* generateGlyph(const SkGlyph&, GrGlyph::PackedID, GrFontScaler*);
95 95
96 friend class GrBatchFontCache; 96 friend class GrBatchFontCache;
97 }; 97 };
98 98
99 /* 99 /*
100 * GrBatchFontCache manages strikes which are indexed by a GrFontScaler. These strikes can then be 100 * GrBatchFontCache manages strikes which are indexed by a GrFontScaler. These strikes can then be
101 * used to individual Glyph Masks. The GrBatchFontCache also manages GrBatchAtl ases, though this is 101 * used to individual Glyph Masks. The GrBatchFontCache also manages GrBatchAtl ases, though this is
102 * more or less transparent to the client(aside from atlasGeneration, described below). 102 * more or less transparent to the client(aside from atlasGeneration, described below).
103 * Note - we used to initialize the backing atlas for the GrBatchFontCache at in itialization time. 103 * Note - we used to initialize the backing atlas for the GrBatchFontCache at in itialization time.
104 * However, this caused a regression, even when the GrBatchFontCache was unused. We now initialize 104 * However, this caused a regression, even when the GrBatchFontCache was unused. We now initialize
105 * the backing atlases lazily. Its not immediately clear why this improves the situation. 105 * the backing atlases lazily. Its not immediately clear why this improves the situation.
106 */ 106 */
107 class GrBatchFontCache { 107 class GrBatchFontCache {
108 public: 108 public:
109 GrBatchFontCache(GrContext*); 109 GrBatchFontCache(GrContext*);
110 ~GrBatchFontCache(); 110 ~GrBatchFontCache();
111 // The user of the cache may hold a long-lived ref to the returned strike. H owever, actions by 111 // The user of the cache may hold a long-lived ref to the returned strike. H owever, actions by
112 // another client of the cache may cause the strike to be purged while it is still reffed. 112 // another client of the cache may cause the strike to be purged while it is still reffed.
113 // Therefore, the caller must check GrBatchTextStrike::isAbandoned() if ther e are other 113 // Therefore, the caller must check GrBatchTextStrike::isAbandoned() if ther e are other
114 // interactions with the cache since the strike was received. 114 // interactions with the cache since the strike was received.
115 inline GrBatchTextStrike* getStrike(GrFontScaler* scaler) { 115 inline GrBatchTextStrike* getStrike(GrFontScaler* scaler) {
116 GrBatchTextStrike* strike = fCache.find(*(scaler->getKey())); 116 GrBatchTextStrike* strike = fCache.find(scaler->getKey());
117 if (nullptr == strike) { 117 if (nullptr == strike) {
118 strike = this->generateStrike(scaler); 118 strike = this->generateStrike(scaler);
119 } 119 }
120 return strike; 120 return strike;
121 } 121 }
122 122
123 void freeAll(); 123 void freeAll();
124 124
125 // if getTexture returns nullptr, the client must not try to use other funct ions on the 125 // if getTexture returns nullptr, the client must not try to use other funct ions on the
126 // GrBatchFontCache which use the atlas. This function *must* be called fir st, before other 126 // GrBatchFontCache which use the atlas. This function *must* be called fir st, before other
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 } 214 }
215 215
216 GrBatchAtlas* getAtlas(GrMaskFormat format) const { 216 GrBatchAtlas* getAtlas(GrMaskFormat format) const {
217 int atlasIndex = MaskFormatToAtlasIndex(format); 217 int atlasIndex = MaskFormatToAtlasIndex(format);
218 SkASSERT(fAtlases[atlasIndex]); 218 SkASSERT(fAtlases[atlasIndex]);
219 return fAtlases[atlasIndex]; 219 return fAtlases[atlasIndex];
220 } 220 }
221 221
222 static void HandleEviction(GrBatchAtlas::AtlasID, void*); 222 static void HandleEviction(GrBatchAtlas::AtlasID, void*);
223 223
224 using StrikeHash = SkTDynamicHash<GrBatchTextStrike, SkDescriptor>;
224 GrContext* fContext; 225 GrContext* fContext;
225 SkTDynamicHash<GrBatchTextStrike, GrFontDescKey> fCache; 226 StrikeHash fCache;
226 GrBatchAtlas* fAtlases[kMaskFormatCount]; 227 GrBatchAtlas* fAtlases[kMaskFormatCount];
227 GrBatchTextStrike* fPreserveStrike; 228 GrBatchTextStrike* fPreserveStrike;
228 GrBatchAtlasConfig fAtlasConfigs[kMaskFormatCount]; 229 GrBatchAtlasConfig fAtlasConfigs[kMaskFormatCount];
229 }; 230 };
230 231
231 #endif 232 #endif
OLDNEW
« no previous file with comments | « no previous file | src/gpu/text/GrBatchFontCache.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698