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

Side by Side Diff: src/gpu/GrTextStrike.cpp

Issue 24981004: GrAtlas cleanup: Split out GrPlot and GrAtlas (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Tweaked comment Created 7 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « src/gpu/GrTextStrike.h ('k') | no next file » | 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 2010 Google Inc. 2 * Copyright 2010 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 #include "GrAtlas.h" 8 #include "GrAtlas.h"
9 #include "GrGpu.h" 9 #include "GrGpu.h"
10 #include "GrRectanizer.h" 10 #include "GrRectanizer.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 GrMaskFormat maskFormat = preserveStrike->fMaskFormat; 96 GrMaskFormat maskFormat = preserveStrike->fMaskFormat;
97 while (strike) { 97 while (strike) {
98 if (strike == preserveStrike || maskFormat != strike->fMaskFormat) { 98 if (strike == preserveStrike || maskFormat != strike->fMaskFormat) {
99 strike = strike->fPrev; 99 strike = strike->fPrev;
100 continue; 100 continue;
101 } 101 }
102 GrTextStrike* strikeToPurge = strike; 102 GrTextStrike* strikeToPurge = strike;
103 strike = strikeToPurge->fPrev; 103 strike = strikeToPurge->fPrev;
104 if (purge) { 104 if (purge) {
105 // keep purging if we won't free up any atlases with this strike. 105 // keep purging if we won't free up any atlases with this strike.
106 purge = (NULL == strikeToPurge->fAtlas); 106 purge = strikeToPurge->fAtlas.isEmpty();
107 int index = fCache.slowFindIndex(strikeToPurge); 107 int index = fCache.slowFindIndex(strikeToPurge);
108 SkASSERT(index >= 0); 108 SkASSERT(index >= 0);
109 fCache.removeAt(index, strikeToPurge->fFontScalerKey->getHash()); 109 fCache.removeAt(index, strikeToPurge->fFontScalerKey->getHash());
110 this->detachStrikeFromList(strikeToPurge); 110 this->detachStrikeFromList(strikeToPurge);
111 delete strikeToPurge; 111 delete strikeToPurge;
112 } 112 }
113 } 113 }
114 #if FONT_CACHE_STATS 114 #if FONT_CACHE_STATS
115 ++g_PurgeCount; 115 ++g_PurgeCount;
116 #endif 116 #endif
117 } 117 }
118 118
119 void GrFontCache::freeAtlasExceptFor(GrTextStrike* preserveStrike) { 119 void GrFontCache::freePlotExceptFor(GrTextStrike* preserveStrike) {
120 SkASSERT(NULL != preserveStrike); 120 SkASSERT(NULL != preserveStrike);
121 GrTextStrike* strike = fTail; 121 GrTextStrike* strike = fTail;
122 GrMaskFormat maskFormat = preserveStrike->fMaskFormat; 122 GrMaskFormat maskFormat = preserveStrike->fMaskFormat;
123 while (strike) { 123 while (strike) {
124 if (strike == preserveStrike || maskFormat != strike->fMaskFormat) { 124 if (strike == preserveStrike || maskFormat != strike->fMaskFormat) {
125 strike = strike->fPrev; 125 strike = strike->fPrev;
126 continue; 126 continue;
127 } 127 }
128 GrTextStrike* strikeToPurge = strike; 128 GrTextStrike* strikeToPurge = strike;
129 strike = strikeToPurge->fPrev; 129 strike = strikeToPurge->fPrev;
130 if (strikeToPurge->removeUnusedAtlases()) { 130 if (strikeToPurge->removeUnusedPlots()) {
131 if (NULL == strikeToPurge->fAtlas) { 131 if (strikeToPurge->fAtlas.isEmpty()) {
132 int index = fCache.slowFindIndex(strikeToPurge); 132 int index = fCache.slowFindIndex(strikeToPurge);
133 SkASSERT(index >= 0); 133 SkASSERT(index >= 0);
134 fCache.removeAt(index, strikeToPurge->fFontScalerKey->getHash()) ; 134 fCache.removeAt(index, strikeToPurge->fFontScalerKey->getHash()) ;
135 this->detachStrikeFromList(strikeToPurge); 135 this->detachStrikeFromList(strikeToPurge);
136 delete strikeToPurge; 136 delete strikeToPurge;
137 } 137 }
138 break; 138 break;
139 } 139 }
140 } 140 }
141 } 141 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 /* 179 /*
180 The text strike is specific to a given font/style/matrix setup, which is 180 The text strike is specific to a given font/style/matrix setup, which is
181 represented by the GrHostFontScaler object we are given in getGlyph(). 181 represented by the GrHostFontScaler object we are given in getGlyph().
182 182
183 We map a 32bit glyphID to a GrGlyph record, which in turn points to a 183 We map a 32bit glyphID to a GrGlyph record, which in turn points to a
184 atlas and a position within that texture. 184 atlas and a position within that texture.
185 */ 185 */
186 186
187 GrTextStrike::GrTextStrike(GrFontCache* cache, const GrKey* key, 187 GrTextStrike::GrTextStrike(GrFontCache* cache, const GrKey* key,
188 GrMaskFormat format, 188 GrMaskFormat format,
189 GrAtlasMgr* atlasMgr) : fPool(64) { 189 GrAtlasMgr* atlasMgr) : fPool(64), fAtlas(atlasMgr) {
190 fFontScalerKey = key; 190 fFontScalerKey = key;
191 fFontScalerKey->ref(); 191 fFontScalerKey->ref();
192 192
193 fFontCache = cache; // no need to ref, it won't go away before we do 193 fFontCache = cache; // no need to ref, it won't go away before we do
194 fAtlasMgr = atlasMgr; // no need to ref, it won't go away before we do 194 fAtlasMgr = atlasMgr; // no need to ref, it won't go away before we do
195 fAtlas = NULL;
196 195
197 fMaskFormat = format; 196 fMaskFormat = format;
198 197
199 #ifdef SK_DEBUG 198 #ifdef SK_DEBUG
200 // GrPrintf(" GrTextStrike %p %d\n", this, gCounter); 199 // GrPrintf(" GrTextStrike %p %d\n", this, gCounter);
201 gCounter += 1; 200 gCounter += 1;
202 #endif 201 #endif
203 } 202 }
204 203
205 // these signatures are needed because they're used with 204 // these signatures are needed because they're used with
206 // SkTDArray::visitAll() (see destructor & removeUnusedAtlases()) 205 // SkTDArray::visitAll() (see destructor & removeUnusedAtlases())
207 static void free_glyph(GrGlyph*& glyph) { glyph->free(); } 206 static void free_glyph(GrGlyph*& glyph) { glyph->free(); }
208 207
209 static void invalidate_glyph(GrGlyph*& glyph) { 208 static void invalidate_glyph(GrGlyph*& glyph) {
210 if (glyph->fAtlas && glyph->fAtlas->drawToken().isIssued()) { 209 if (glyph->fPlot && glyph->fPlot->drawToken().isIssued()) {
211 glyph->fAtlas = NULL; 210 glyph->fPlot = NULL;
212 } 211 }
213 } 212 }
214 213
215 GrTextStrike::~GrTextStrike() { 214 GrTextStrike::~GrTextStrike() {
216 GrAtlas::FreeLList(fAtlas);
217 fFontScalerKey->unref(); 215 fFontScalerKey->unref();
218 fCache.getArray().visitAll(free_glyph); 216 fCache.getArray().visitAll(free_glyph);
219 217
220 #ifdef SK_DEBUG 218 #ifdef SK_DEBUG
221 gCounter -= 1; 219 gCounter -= 1;
222 // GrPrintf("~GrTextStrike %p %d\n", this, gCounter); 220 // GrPrintf("~GrTextStrike %p %d\n", this, gCounter);
223 #endif 221 #endif
224 } 222 }
225 223
226 GrGlyph* GrTextStrike::generateGlyph(GrGlyph::PackedID packed, 224 GrGlyph* GrTextStrike::generateGlyph(GrGlyph::PackedID packed,
227 GrFontScaler* scaler) { 225 GrFontScaler* scaler) {
228 SkIRect bounds; 226 SkIRect bounds;
229 if (!scaler->getPackedGlyphBounds(packed, &bounds)) { 227 if (!scaler->getPackedGlyphBounds(packed, &bounds)) {
230 return NULL; 228 return NULL;
231 } 229 }
232 230
233 GrGlyph* glyph = fPool.alloc(); 231 GrGlyph* glyph = fPool.alloc();
234 glyph->init(packed, bounds); 232 glyph->init(packed, bounds);
235 fCache.insert(packed, glyph); 233 fCache.insert(packed, glyph);
236 return glyph; 234 return glyph;
237 } 235 }
238 236
239 bool GrTextStrike::removeUnusedAtlases() { 237 bool GrTextStrike::removeUnusedPlots() {
240 fCache.getArray().visitAll(invalidate_glyph); 238 fCache.getArray().visitAll(invalidate_glyph);
241 return GrAtlas::RemoveUnusedAtlases(fAtlasMgr, &fAtlas); 239 return fAtlasMgr->removeUnusedPlots(&fAtlas);
242 } 240 }
243 241
244 bool GrTextStrike::getGlyphAtlas(GrGlyph* glyph, GrFontScaler* scaler, 242 bool GrTextStrike::getGlyphAtlas(GrGlyph* glyph, GrFontScaler* scaler,
245 GrDrawTarget::DrawToken currentDrawToken) { 243 GrDrawTarget::DrawToken currentDrawToken) {
246 #if 0 // testing hack to force us to flush our cache often 244 #if 0 // testing hack to force us to flush our cache often
247 static int gCounter; 245 static int gCounter;
248 if ((++gCounter % 10) == 0) return false; 246 if ((++gCounter % 10) == 0) return false;
249 #endif 247 #endif
250 248
251 SkASSERT(glyph); 249 SkASSERT(glyph);
252 SkASSERT(scaler); 250 SkASSERT(scaler);
253 SkASSERT(fCache.contains(glyph)); 251 SkASSERT(fCache.contains(glyph));
254 if (glyph->fAtlas) { 252 if (glyph->fPlot) {
255 glyph->fAtlas->setDrawToken(currentDrawToken); 253 glyph->fPlot->setDrawToken(currentDrawToken);
256 return true; 254 return true;
257 } 255 }
258 256
259 SkAutoRef ar(scaler); 257 SkAutoRef ar(scaler);
260 258
261 int bytesPerPixel = GrMaskFormatBytesPerPixel(fMaskFormat); 259 int bytesPerPixel = GrMaskFormatBytesPerPixel(fMaskFormat);
262 size_t size = glyph->fBounds.area() * bytesPerPixel; 260 size_t size = glyph->fBounds.area() * bytesPerPixel;
263 SkAutoSMalloc<1024> storage(size); 261 SkAutoSMalloc<1024> storage(size);
264 if (!scaler->getPackedGlyphImage(glyph->fPackedID, glyph->width(), 262 if (!scaler->getPackedGlyphImage(glyph->fPackedID, glyph->width(),
265 glyph->height(), 263 glyph->height(),
266 glyph->width() * bytesPerPixel, 264 glyph->width() * bytesPerPixel,
267 storage.get())) { 265 storage.get())) {
268 return false; 266 return false;
269 } 267 }
270 268
271 GrAtlas* atlas = fAtlasMgr->addToAtlas(&fAtlas, glyph->width(), 269 GrPlot* plot = fAtlasMgr->addToAtlas(&fAtlas, glyph->width(),
272 glyph->height(), storage.get(), 270 glyph->height(), storage.get(),
273 &glyph->fAtlasLocation); 271 &glyph->fAtlasLocation);
274 if (NULL == atlas) { 272 if (NULL == plot) {
275 return false; 273 return false;
276 } 274 }
277 275
278 glyph->fAtlas = atlas; 276 glyph->fPlot = plot;
279 atlas->setDrawToken(currentDrawToken); 277 plot->setDrawToken(currentDrawToken);
280 return true; 278 return true;
281 } 279 }
OLDNEW
« no previous file with comments | « src/gpu/GrTextStrike.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698