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

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

Issue 1076853002: fix for perf regression on ugamsolutions / msaa16 (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: nit Created 5 years, 8 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 | « src/gpu/GrAtlasTextContext.cpp ('k') | src/gpu/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
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 int fAtlasedGlyphs; 68 int fAtlasedGlyphs;
69 69
70 GrGlyph* generateGlyph(GrGlyph::PackedID packed, GrFontScaler* scaler); 70 GrGlyph* generateGlyph(GrGlyph::PackedID packed, GrFontScaler* scaler);
71 71
72 friend class GrBatchFontCache; 72 friend class GrBatchFontCache;
73 }; 73 };
74 74
75 /* 75 /*
76 * GrBatchFontCache manages strikes which are indexed by a GrFontScaler. These strikes can then be 76 * GrBatchFontCache manages strikes which are indexed by a GrFontScaler. These strikes can then be
77 * used to individual Glyph Masks. The GrBatchFontCache also manages GrBatchAtl ases, though this is 77 * used to individual Glyph Masks. The GrBatchFontCache also manages GrBatchAtl ases, though this is
78 * more or less transparent to the client(aside from atlasGeneration, described below) 78 * more or less transparent to the client(aside from atlasGeneration, described below).
79 * Note - we used to initialize the backing atlas for the GrBatchFontCache at in itialization time.
80 * However, this caused a regression, even when the GrBatchFontCache was unused. We now initialize
81 * the backing atlases lazily. Its not immediately clear why this improves the situation.
79 */ 82 */
80 class GrBatchFontCache { 83 class GrBatchFontCache {
81 public: 84 public:
82 GrBatchFontCache(); 85 GrBatchFontCache(GrContext*);
83 ~GrBatchFontCache(); 86 ~GrBatchFontCache();
84 87
85 // Initializes the GrBatchFontCache on the owning GrContext
86 void init(GrContext*);
87
88 inline GrBatchTextStrike* getStrike(GrFontScaler* scaler) { 88 inline GrBatchTextStrike* getStrike(GrFontScaler* scaler) {
89
90 GrBatchTextStrike* strike = fCache.find(*(scaler->getKey())); 89 GrBatchTextStrike* strike = fCache.find(*(scaler->getKey()));
91 if (NULL == strike) { 90 if (NULL == strike) {
92 strike = this->generateStrike(scaler); 91 strike = this->generateStrike(scaler);
93 } 92 }
94 return strike; 93 return strike;
95 } 94 }
96 95
97 bool hasGlyph(GrGlyph* glyph); 96 void freeAll();
97
98 // if getTexture returns NULL, the client must not try to use other function s on the
99 // GrBatchFontCache which use the atlas. This function *must* be called fir st, before other
100 // functions which use the atlas.
101 GrTexture* getTexture(GrMaskFormat format) {
102 if (this->initAtlas(format)) {
103 return this->getAtlas(format)->getTexture();
104 }
105 return NULL;
106 }
107
108 bool hasGlyph(GrGlyph* glyph) {
109 SkASSERT(glyph);
110 return this->getAtlas(glyph->fMaskFormat)->hasID(glyph->fID);
111 }
98 112
99 // To ensure the GrBatchAtlas does not evict the Glyph Mask from its texture backing store, 113 // To ensure the GrBatchAtlas does not evict the Glyph Mask from its texture backing store,
100 // the client must pass in the currentToken from the GrBatchTarget along wit h the GrGlyph. 114 // the client must pass in the currentToken from the GrBatchTarget along wit h the GrGlyph.
101 // A BulkUseTokenUpdater is used to manage bulk last use token updating in t he Atlas. 115 // A BulkUseTokenUpdater is used to manage bulk last use token updating in t he Atlas.
102 // For convenience, this function will also set the use token for the curren t glyph if required 116 // For convenience, this function will also set the use token for the curren t glyph if required
103 // NOTE: the bulk uploader is only valid if the subrun has a valid atlasGene ration 117 // NOTE: the bulk uploader is only valid if the subrun has a valid atlasGene ration
104 void addGlyphToBulkAndSetUseToken(GrBatchAtlas::BulkUseTokenUpdater*, GrGlyp h*, 118 void addGlyphToBulkAndSetUseToken(GrBatchAtlas::BulkUseTokenUpdater* updater ,
105 GrBatchAtlas::BatchToken); 119 GrGlyph* glyph, GrBatchAtlas::BatchToken t oken) {
120 SkASSERT(glyph);
121 updater->add(glyph->fID);
122 this->getAtlas(glyph->fMaskFormat)->setLastUseToken(glyph->fID, token);
123 }
106 124
107 void setUseTokenBulk(const GrBatchAtlas::BulkUseTokenUpdater&, GrBatchAtlas: :BatchToken, 125 void setUseTokenBulk(const GrBatchAtlas::BulkUseTokenUpdater& updater,
108 GrMaskFormat); 126 GrBatchAtlas::BatchToken token,
127 GrMaskFormat format) {
128 this->getAtlas(format)->setLastUseTokenBulk(updater, token);
129 }
109 130
110 // add to texture atlas that matches this format 131 // add to texture atlas that matches this format
111 bool addToAtlas(GrBatchTextStrike*, GrBatchAtlas::AtlasID*, GrBatchTarget*, 132 bool addToAtlas(GrBatchTextStrike* strike, GrBatchAtlas::AtlasID* id,
112 GrMaskFormat, int width, int height, const void* image, 133 GrBatchTarget* batchTarget,
113 SkIPoint16* loc); 134 GrMaskFormat format, int width, int height, const void* imag e,
135 SkIPoint16* loc) {
136 fPreserveStrike = strike;
137 return this->getAtlas(format)->addToAtlas(id, batchTarget, width, height , image, loc);
138 }
114 139
115 // Some clients may wish to verify the integrity of the texture backing stor e of the 140 // Some clients may wish to verify the integrity of the texture backing stor e of the
116 // GrBatchAtlas. The atlasGeneration returned below is a monitonically incr easing number which 141 // GrBatchAtlas. The atlasGeneration returned below is a monitonically incr easing number which
117 // changes everytime something is removed from the texture backing store. 142 // changes everytime something is removed from the texture backing store.
118 uint64_t atlasGeneration(GrMaskFormat) const; 143 uint64_t atlasGeneration(GrMaskFormat format) const {
144 return this->getAtlas(format)->atlasGeneration();
145 }
119 146
120 void freeAll();
121
122 GrTexture* getTexture(GrMaskFormat);
123 GrPixelConfig getPixelConfig(GrMaskFormat) const; 147 GrPixelConfig getPixelConfig(GrMaskFormat) const;
124 148
125 void dump() const; 149 void dump() const;
126 150
127 private: 151 private:
128 // There is a 1:1 mapping between GrMaskFormats and atlas indices 152 // There is a 1:1 mapping between GrMaskFormats and atlas indices
129 static int MaskFormatToAtlasIndex(GrMaskFormat); 153 static int MaskFormatToAtlasIndex(GrMaskFormat format) {
130 static GrMaskFormat AtlasIndexToMaskFormat(int atlasIndex); 154 static const int sAtlasIndices[] = {
155 kA8_GrMaskFormat,
156 kA565_GrMaskFormat,
157 kARGB_GrMaskFormat,
158 };
159 SK_COMPILE_ASSERT(SK_ARRAY_COUNT(sAtlasIndices) == kMaskFormatCount, arr ay_size_mismatch);
131 160
132 GrBatchTextStrike* generateStrike(GrFontScaler*); 161 SkASSERT(sAtlasIndices[format] < kMaskFormatCount);
162 return sAtlasIndices[format];
163 }
133 164
134 inline GrBatchAtlas* getAtlas(GrMaskFormat) const; 165 bool initAtlas(GrMaskFormat);
166
167 GrBatchTextStrike* generateStrike(GrFontScaler* scaler) {
168 GrBatchTextStrike* strike = SkNEW_ARGS(GrBatchTextStrike, (this, scaler- >getKey()));
169 fCache.add(strike);
170 return strike;
171 }
172
173 GrBatchAtlas* getAtlas(GrMaskFormat format) const {
174 int atlasIndex = MaskFormatToAtlasIndex(format);
175 SkASSERT(fAtlases[atlasIndex]);
176 return fAtlases[atlasIndex];
177 }
135 178
136 static void HandleEviction(GrBatchAtlas::AtlasID, void*); 179 static void HandleEviction(GrBatchAtlas::AtlasID, void*);
137 180
181 GrContext* fContext;
138 SkTDynamicHash<GrBatchTextStrike, GrFontDescKey> fCache; 182 SkTDynamicHash<GrBatchTextStrike, GrFontDescKey> fCache;
139
140 GrBatchAtlas* fAtlases[kMaskFormatCount]; 183 GrBatchAtlas* fAtlases[kMaskFormatCount];
141 GrBatchTextStrike* fPreserveStrike; 184 GrBatchTextStrike* fPreserveStrike;
142 }; 185 };
143 186
144 #endif 187 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrAtlasTextContext.cpp ('k') | src/gpu/GrBatchFontCache.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698