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

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: update 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') | src/gpu/text/GrBatchFontCache.cpp » ('J')
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 actuall y creates the mask.
24 */ 24 */
25 class GrBatchTextStrike : public SkNVRefCnt<GrBatchTextStrike> { 25 class GrBatchTextStrike : public SkNVRefCnt<GrBatchTextStrike> {
26 public: 26 public:
27 GrBatchTextStrike(GrBatchFontCache*, const GrFontDescKey* fontScalerKey); 27 GrBatchTextStrike(GrBatchFontCache*, const SkDescriptor& fontScalerKey);
28 ~GrBatchTextStrike(); 28 ~GrBatchTextStrike();
29 29
30 const GrFontDescKey* getFontScalerKey() const { return fFontScalerKey; }
31 GrBatchFontCache* getBatchFontCache() const { return fBatchFontCache; }
32
33 inline GrGlyph* getGlyph(const SkGlyph& skGlyph, GrGlyph::PackedID packed, 30 inline GrGlyph* getGlyph(const SkGlyph& skGlyph, GrGlyph::PackedID packed,
34 GrFontScaler* scaler) { 31 GrFontScaler* scaler) {
35 GrGlyph* glyph = fCache.find(packed); 32 GrGlyph* glyph = fCache.find(packed);
36 if (nullptr == glyph) { 33 if (nullptr == glyph) {
37 glyph = this->generateGlyph(skGlyph, packed, scaler); 34 glyph = this->generateGlyph(skGlyph, packed, scaler);
38 } 35 }
39 return glyph; 36 return glyph;
40 } 37 }
41 38
42 // This variant of the above function is called by TextBatch. At this point , it is possible 39 // This variant of the above function is called by TextBatch. At this point , it is possible
(...skipping 25 matching lines...) Expand all
68 65
69 // testing 66 // testing
70 int countGlyphs() const { return fCache.count(); } 67 int countGlyphs() const { return fCache.count(); }
71 68
72 // remove any references to this plot 69 // remove any references to this plot
73 void removeID(GrBatchAtlas::AtlasID); 70 void removeID(GrBatchAtlas::AtlasID);
74 71
75 // If a TextStrike is abandoned by the cache, then the caller must get a new strike 72 // If a TextStrike is abandoned by the cache, then the caller must get a new strike
76 bool isAbandoned() const { return fIsAbandoned; } 73 bool isAbandoned() const { return fIsAbandoned; }
77 74
78 static const GrFontDescKey& GetKey(const GrBatchTextStrike& ts) { 75 static const SkDescriptor& GetKey(const GrBatchTextStrike& ts) {
79 return *(ts.fFontScalerKey); 76 return *ts.fFontScalerKey.getDesc();
80 } 77 }
81 static uint32_t Hash(const GrFontDescKey& key) { 78
82 return key.getHash(); 79 static uint32_t Hash(const SkDescriptor& desc) { return desc.getChecksum(); }
83 }
84 80
85 private: 81 private:
86 SkTDynamicHash<GrGlyph, GrGlyph::PackedID> fCache; 82 SkTDynamicHash<GrGlyph, GrGlyph::PackedID> fCache;
87 SkAutoTUnref<const GrFontDescKey> fFontScalerKey; 83 SkAutoDescriptor fFontScalerKey;
88 SkVarAlloc fPool; 84 SkVarAlloc fPool;
89 85
90 GrBatchFontCache* fBatchFontCache; 86 GrBatchFontCache* fBatchFontCache;
91 int fAtlasedGlyphs; 87 int fAtlasedGlyphs;
92 bool fIsAbandoned; 88 bool fIsAbandoned;
93 89
94 GrGlyph* generateGlyph(const SkGlyph&, GrGlyph::PackedID, GrFontScaler*); 90 GrGlyph* generateGlyph(const SkGlyph&, GrGlyph::PackedID, GrFontScaler*);
95 91
96 friend class GrBatchFontCache; 92 friend class GrBatchFontCache;
97 }; 93 };
98 94
99 /* 95 /*
100 * GrBatchFontCache manages strikes which are indexed by a GrFontScaler. These strikes can then be 96 * 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 97 * 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). 98 * 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. 99 * 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 100 * 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. 101 * the backing atlases lazily. Its not immediately clear why this improves the situation.
106 */ 102 */
107 class GrBatchFontCache { 103 class GrBatchFontCache {
108 public: 104 public:
109 GrBatchFontCache(GrContext*); 105 GrBatchFontCache(GrContext*);
110 ~GrBatchFontCache(); 106 ~GrBatchFontCache();
111 // The user of the cache may hold a long-lived ref to the returned strike. H owever, actions by 107 // 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. 108 // 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 109 // Therefore, the caller must check GrBatchTextStrike::isAbandoned() if ther e are other
114 // interactions with the cache since the strike was received. 110 // interactions with the cache since the strike was received.
115 inline GrBatchTextStrike* getStrike(GrFontScaler* scaler) { 111 inline GrBatchTextStrike* getStrike(GrFontScaler* scaler) {
116 GrBatchTextStrike* strike = fCache.find(*(scaler->getKey())); 112 GrBatchTextStrike* strike = fCache.find(scaler->getKey());
117 if (nullptr == strike) { 113 if (nullptr == strike) {
118 strike = this->generateStrike(scaler); 114 strike = this->generateStrike(scaler);
119 } 115 }
120 return strike; 116 return strike;
121 } 117 }
122 118
123 void freeAll(); 119 void freeAll();
124 120
125 // if getTexture returns nullptr, the client must not try to use other funct ions on the 121 // 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 122 // 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 } 210 }
215 211
216 GrBatchAtlas* getAtlas(GrMaskFormat format) const { 212 GrBatchAtlas* getAtlas(GrMaskFormat format) const {
217 int atlasIndex = MaskFormatToAtlasIndex(format); 213 int atlasIndex = MaskFormatToAtlasIndex(format);
218 SkASSERT(fAtlases[atlasIndex]); 214 SkASSERT(fAtlases[atlasIndex]);
219 return fAtlases[atlasIndex]; 215 return fAtlases[atlasIndex];
220 } 216 }
221 217
222 static void HandleEviction(GrBatchAtlas::AtlasID, void*); 218 static void HandleEviction(GrBatchAtlas::AtlasID, void*);
223 219
220 using StrikeHash = SkTDynamicHash<GrBatchTextStrike, SkDescriptor>;
224 GrContext* fContext; 221 GrContext* fContext;
225 SkTDynamicHash<GrBatchTextStrike, GrFontDescKey> fCache; 222 StrikeHash fCache;
226 GrBatchAtlas* fAtlases[kMaskFormatCount]; 223 GrBatchAtlas* fAtlases[kMaskFormatCount];
227 GrBatchTextStrike* fPreserveStrike; 224 GrBatchTextStrike* fPreserveStrike;
228 GrBatchAtlasConfig fAtlasConfigs[kMaskFormatCount]; 225 GrBatchAtlasConfig fAtlasConfigs[kMaskFormatCount];
229 }; 226 };
230 227
231 #endif 228 #endif
OLDNEW
« no previous file with comments | « no previous file | src/gpu/text/GrBatchFontCache.cpp » ('j') | src/gpu/text/GrBatchFontCache.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698