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

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

Issue 510103003: Revert of Restore text alloc optimizations. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 3 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/GrBitmapTextContext.h ('k') | src/gpu/GrDistanceFieldTextContext.h » ('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 2013 Google Inc. 2 * Copyright 2013 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 "GrBitmapTextContext.h" 8 #include "GrBitmapTextContext.h"
9 #include "GrAtlas.h" 9 #include "GrAtlas.h"
10 #include "GrDrawTarget.h" 10 #include "GrDrawTarget.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 extern const GrVertexAttrib gTextVertexWithColorAttribs[] = { 44 extern const GrVertexAttrib gTextVertexWithColorAttribs[] = {
45 {kVec2f_GrVertexAttribType, 0, kPosition_Gr VertexAttribBinding}, 45 {kVec2f_GrVertexAttribType, 0, kPosition_Gr VertexAttribBinding},
46 {kVec4ub_GrVertexAttribType, sizeof(SkPoint), kColor_GrVer texAttribBinding}, 46 {kVec4ub_GrVertexAttribType, sizeof(SkPoint), kColor_GrVer texAttribBinding},
47 {kVec2f_GrVertexAttribType, sizeof(SkPoint) + sizeof(GrColor), kEffect_GrVe rtexAttribBinding} 47 {kVec2f_GrVertexAttribType, sizeof(SkPoint) + sizeof(GrColor), kEffect_GrVe rtexAttribBinding}
48 }; 48 };
49 49
50 }; 50 };
51 51
52 GrBitmapTextContext::GrBitmapTextContext(GrContext* context, 52 GrBitmapTextContext::GrBitmapTextContext(GrContext* context,
53 const SkDeviceProperties& properties) 53 const SkDeviceProperties& properties)
54 : GrTextContext(context, properties) 54 : GrTextContext(context, properties) {
55 , fStrike(NULL) 55 fStrike = NULL;
56 , fEffectTextureUniqueID(SK_InvalidUnique ID) 56
57 , fVertices(NULL) 57 fCurrTexture = NULL;
58 , fVertexCount(0) 58 fCurrVertex = 0;
59 , fCurrVertex(0) { 59 fEffectTextureUniqueID = SK_InvalidUniqueID;
60
61 fVertices = NULL;
62 fMaxVertices = 0;
63
60 fVertexBounds.setLargestInverted(); 64 fVertexBounds.setLargestInverted();
61 } 65 }
62 66
63 GrBitmapTextContext::~GrBitmapTextContext() { 67 GrBitmapTextContext::~GrBitmapTextContext() {
64 this->flushGlyphs(); 68 this->flushGlyphs();
65 } 69 }
66 70
67 bool GrBitmapTextContext::canDraw(const SkPaint& paint) { 71 bool GrBitmapTextContext::canDraw(const SkPaint& paint) {
68 return !SkDraw::ShouldDrawTextAsPaths(paint, fContext->getMatrix()); 72 return !SkDraw::ShouldDrawTextAsPaths(paint, fContext->getMatrix());
69 } 73 }
(...skipping 10 matching lines...) Expand all
80 return; 84 return;
81 } 85 }
82 86
83 GrDrawState* drawState = fDrawTarget->drawState(); 87 GrDrawState* drawState = fDrawTarget->drawState();
84 GrDrawState::AutoRestoreEffects are(drawState); 88 GrDrawState::AutoRestoreEffects are(drawState);
85 drawState->setFromPaint(fPaint, SkMatrix::I(), fContext->getRenderTarget()); 89 drawState->setFromPaint(fPaint, SkMatrix::I(), fContext->getRenderTarget());
86 90
87 if (fCurrVertex > 0) { 91 if (fCurrVertex > 0) {
88 // setup our sampler state for our text texture/atlas 92 // setup our sampler state for our text texture/atlas
89 SkASSERT(SkIsAlign4(fCurrVertex)); 93 SkASSERT(SkIsAlign4(fCurrVertex));
94 SkASSERT(fCurrTexture);
90 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kNon e_FilterMode); 95 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kNon e_FilterMode);
91 96
92 GrTexture* currTexture = fStrike->getTexture(); 97 uint32_t textureUniqueID = fCurrTexture->getUniqueID();
93 SkASSERT(currTexture);
94 uint32_t textureUniqueID = currTexture->getUniqueID();
95 98
96 if (textureUniqueID != fEffectTextureUniqueID) { 99 if (textureUniqueID != fEffectTextureUniqueID) {
97 fCachedEffect.reset(GrCustomCoordsTextureEffect::Create(currTexture, params)); 100 fCachedEffect.reset(GrCustomCoordsTextureEffect::Create(fCurrTexture , params));
98 fEffectTextureUniqueID = textureUniqueID; 101 fEffectTextureUniqueID = textureUniqueID;
99 } 102 }
100 103
101 // This effect could be stored with one of the cache objects (atlas?) 104 // This effect could be stored with one of the cache objects (atlas?)
102 int coordsIdx = drawState->hasColorVertexAttribute() ? kGlyphCoordsWithC olorAttributeIndex : 105 int coordsIdx = drawState->hasColorVertexAttribute() ? kGlyphCoordsWithC olorAttributeIndex :
103 kGlyphCoordsNoCol orAttributeIndex; 106 kGlyphCoordsNoCol orAttributeIndex;
104 drawState->addCoverageEffect(fCachedEffect.get(), coordsIdx); 107 drawState->addCoverageEffect(fCachedEffect.get(), coordsIdx);
105 SkASSERT(NULL != fStrike); 108 SkASSERT(NULL != fStrike);
106 switch (fStrike->getMaskFormat()) { 109 switch (fStrike->getMaskFormat()) {
107 // Color bitmap text 110 // Color bitmap text
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 SkASSERT(drawState->hasColorVertexAttribute()); 142 SkASSERT(drawState->hasColorVertexAttribute());
140 break; 143 break;
141 default: 144 default:
142 SkFAIL("Unexepected mask format."); 145 SkFAIL("Unexepected mask format.");
143 } 146 }
144 int nGlyphs = fCurrVertex / 4; 147 int nGlyphs = fCurrVertex / 4;
145 fDrawTarget->setIndexSourceToBuffer(fContext->getQuadIndexBuffer()); 148 fDrawTarget->setIndexSourceToBuffer(fContext->getQuadIndexBuffer());
146 fDrawTarget->drawIndexedInstances(kTriangles_GrPrimitiveType, 149 fDrawTarget->drawIndexedInstances(kTriangles_GrPrimitiveType,
147 nGlyphs, 150 nGlyphs,
148 4, 6, &fVertexBounds); 151 4, 6, &fVertexBounds);
149 fVertexCount = 0; 152
153 fDrawTarget->resetVertexSource();
154 fVertices = NULL;
155 fMaxVertices = 0;
150 fCurrVertex = 0; 156 fCurrVertex = 0;
151 fVertexBounds.setLargestInverted(); 157 fVertexBounds.setLargestInverted();
158 SkSafeSetNull(fCurrTexture);
152 } 159 }
153
154 fDrawTarget->resetVertexSource();
155 fVertices = NULL;
156 } 160 }
157 161
158 inline void GrBitmapTextContext::init(const GrPaint& paint, const SkPaint& skPai nt) { 162 inline void GrBitmapTextContext::init(const GrPaint& paint, const SkPaint& skPai nt) {
159 GrTextContext::init(paint, skPaint); 163 GrTextContext::init(paint, skPaint);
160 164
161 fStrike = NULL; 165 fStrike = NULL;
162 166
167 fCurrTexture = NULL;
168 fCurrVertex = 0;
169
163 fVertices = NULL; 170 fVertices = NULL;
164 fVertexCount = 0; 171 fMaxVertices = 0;
165 fCurrVertex = 0;
166 } 172 }
167 173
168 inline void GrBitmapTextContext::finish() { 174 inline void GrBitmapTextContext::finish() {
169 this->flushGlyphs(); 175 this->flushGlyphs();
170 176
171 GrTextContext::finish(); 177 GrTextContext::finish();
172 } 178 }
173 179
174 void GrBitmapTextContext::allocateVertices(const char text[], size_t byteLength) {
175 SkASSERT(NULL == fVertices);
176 bool useColorVerts = kA8_GrMaskFormat == fStrike->getMaskFormat();
177 if (useColorVerts) {
178 fDrawTarget->drawState()->setVertexAttribs<gTextVertexWithColorAttribs>(
179 SK_ARRAY_COUNT(gTextVertexWi thColorAttribs));
180 } else {
181 fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>(
182 SK_ARRAY_COUNT(gTextVertexAt tribs));
183 }
184 fVertexCount = 4*fSkPaint.textToGlyphs(text, byteLength, NULL);
185 bool success = fDrawTarget->reserveVertexAndIndexSpace(fVertexCount,
186 0,
187 &fVertices,
188 NULL);
189 GrAlwaysAssert(success);
190 }
191
192 void GrBitmapTextContext::drawText(const GrPaint& paint, const SkPaint& skPaint, 180 void GrBitmapTextContext::drawText(const GrPaint& paint, const SkPaint& skPaint,
193 const char text[], size_t byteLength, 181 const char text[], size_t byteLength,
194 SkScalar x, SkScalar y) { 182 SkScalar x, SkScalar y) {
195 SkASSERT(byteLength == 0 || text != NULL); 183 SkASSERT(byteLength == 0 || text != NULL);
196 184
197 // nothing to draw 185 // nothing to draw
198 if (text == NULL || byteLength == 0 /*|| fRC->isEmpty()*/) { 186 if (text == NULL || byteLength == 0 /*|| fRC->isEmpty()*/) {
199 return; 187 return;
200 } 188 }
201 189
202 this->init(paint, skPaint); 190 this->init(paint, skPaint);
203
204 if (NULL == fDrawTarget) {
205 return;
206 }
207 191
208 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); 192 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc();
209 193
210 SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, &fContext->getMa trix()); 194 SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, &fContext->getMa trix());
211 SkGlyphCache* cache = autoCache.getCache(); 195 SkGlyphCache* cache = autoCache.getCache();
212 GrFontScaler* fontScaler = GetGrFontScaler(cache); 196 GrFontScaler* fontScaler = GetGrFontScaler(cache);
213 if (NULL == fStrike) { 197
214 fStrike = fContext->getFontCache()->getStrike(fontScaler, false);
215 }
216
217 // transform our starting point 198 // transform our starting point
218 { 199 {
219 SkPoint loc; 200 SkPoint loc;
220 fContext->getMatrix().mapXY(x, y, &loc); 201 fContext->getMatrix().mapXY(x, y, &loc);
221 x = loc.fX; 202 x = loc.fX;
222 y = loc.fY; 203 y = loc.fY;
223 } 204 }
224 205
225 // need to measure first 206 // need to measure first
226 if (fSkPaint.getTextAlign() != SkPaint::kLeft_Align) { 207 if (fSkPaint.getTextAlign() != SkPaint::kLeft_Align) {
227 SkVector stop; 208 SkVector stop;
228 209
229 MeasureText(cache, glyphCacheProc, text, byteLength, &stop); 210 MeasureText(cache, glyphCacheProc, text, byteLength, &stop);
230 211
231 SkScalar stopX = stop.fX; 212 SkScalar stopX = stop.fX;
232 SkScalar stopY = stop.fY; 213 SkScalar stopY = stop.fY;
233 214
234 if (fSkPaint.getTextAlign() == SkPaint::kCenter_Align) { 215 if (fSkPaint.getTextAlign() == SkPaint::kCenter_Align) {
235 stopX = SkScalarHalf(stopX); 216 stopX = SkScalarHalf(stopX);
236 stopY = SkScalarHalf(stopY); 217 stopY = SkScalarHalf(stopY);
237 } 218 }
238 x -= stopX; 219 x -= stopX;
239 y -= stopY; 220 y -= stopY;
240 } 221 }
241 222
242 const char* stop = text + byteLength; 223 const char* stop = text + byteLength;
243 224
244 this->allocateVertices(text, byteLength); 225 SkAutoKern autokern;
245 226
246 SkFixed fxMask = ~0; 227 SkFixed fxMask = ~0;
247 SkFixed fyMask = ~0; 228 SkFixed fyMask = ~0;
248 SkFixed halfSampleX, halfSampleY; 229 SkFixed halfSampleX, halfSampleY;
249 if (cache->isSubpixel()) { 230 if (cache->isSubpixel()) {
250 halfSampleX = halfSampleY = (SK_FixedHalf >> SkGlyph::kSubBits); 231 halfSampleX = halfSampleY = (SK_FixedHalf >> SkGlyph::kSubBits);
251 SkAxisAlignment baseline = SkComputeAxisAlignmentForHText(fContext->getM atrix()); 232 SkAxisAlignment baseline = SkComputeAxisAlignmentForHText(fContext->getM atrix());
252 if (kX_SkAxisAlignment == baseline) { 233 if (kX_SkAxisAlignment == baseline) {
253 fyMask = 0; 234 fyMask = 0;
254 halfSampleY = SK_FixedHalf; 235 halfSampleY = SK_FixedHalf;
255 } else if (kY_SkAxisAlignment == baseline) { 236 } else if (kY_SkAxisAlignment == baseline) {
256 fxMask = 0; 237 fxMask = 0;
257 halfSampleX = SK_FixedHalf; 238 halfSampleX = SK_FixedHalf;
258 } 239 }
259 } else { 240 } else {
260 halfSampleX = halfSampleY = SK_FixedHalf; 241 halfSampleX = halfSampleY = SK_FixedHalf;
261 } 242 }
262 243
263 SkFixed fx = SkScalarToFixed(x) + halfSampleX; 244 SkFixed fx = SkScalarToFixed(x) + halfSampleX;
264 SkFixed fy = SkScalarToFixed(y) + halfSampleY; 245 SkFixed fy = SkScalarToFixed(y) + halfSampleY;
265 246
266 GrContext::AutoMatrix autoMatrix; 247 GrContext::AutoMatrix autoMatrix;
267 autoMatrix.setIdentity(fContext, &fPaint); 248 autoMatrix.setIdentity(fContext, &fPaint);
268 249
269 SkAutoKern autokern;
270 while (text < stop) { 250 while (text < stop) {
271 const SkGlyph& glyph = glyphCacheProc(cache, &text, fx & fxMask, fy & fy Mask); 251 const SkGlyph& glyph = glyphCacheProc(cache, &text, fx & fxMask, fy & fy Mask);
272 252
273 fx += autokern.adjust(glyph); 253 fx += autokern.adjust(glyph);
274 254
275 if (glyph.fWidth) { 255 if (glyph.fWidth) {
276 this->drawPackedGlyph(GrGlyph::Pack(glyph.getGlyphID(), 256 this->drawPackedGlyph(GrGlyph::Pack(glyph.getGlyphID(),
277 glyph.getSubXFixed(), 257 glyph.getSubXFixed(),
278 glyph.getSubYFixed()), 258 glyph.getSubYFixed()),
279 SkFixedFloorToFixed(fx), 259 SkFixedFloorToFixed(fx),
(...skipping 15 matching lines...) Expand all
295 SkASSERT(byteLength == 0 || text != NULL); 275 SkASSERT(byteLength == 0 || text != NULL);
296 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); 276 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
297 277
298 // nothing to draw 278 // nothing to draw
299 if (text == NULL || byteLength == 0/* || fRC->isEmpty()*/) { 279 if (text == NULL || byteLength == 0/* || fRC->isEmpty()*/) {
300 return; 280 return;
301 } 281 }
302 282
303 this->init(paint, skPaint); 283 this->init(paint, skPaint);
304 284
305 if (NULL == fDrawTarget) {
306 return;
307 }
308
309 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); 285 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc();
310 286
311 SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, &fContext->getMa trix()); 287 SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, &fContext->getMa trix());
312 SkGlyphCache* cache = autoCache.getCache(); 288 SkGlyphCache* cache = autoCache.getCache();
313 GrFontScaler* fontScaler = GetGrFontScaler(cache); 289 GrFontScaler* fontScaler = GetGrFontScaler(cache);
314 if (NULL == fStrike) {
315 fStrike = fContext->getFontCache()->getStrike(fontScaler, false);
316 }
317 290
318 // store original matrix before we reset, so we can use it to transform posi tions 291 // store original matrix before we reset, so we can use it to transform posi tions
319 SkMatrix ctm = fContext->getMatrix(); 292 SkMatrix ctm = fContext->getMatrix();
320 GrContext::AutoMatrix autoMatrix; 293 GrContext::AutoMatrix autoMatrix;
321 autoMatrix.setIdentity(fContext, &fPaint); 294 autoMatrix.setIdentity(fContext, &fPaint);
322 295
323 this->allocateVertices(text, byteLength);
324
325 const char* stop = text + byteLength; 296 const char* stop = text + byteLength;
326 SkTextAlignProc alignProc(fSkPaint.getTextAlign()); 297 SkTextAlignProc alignProc(fSkPaint.getTextAlign());
327 SkTextMapStateProc tmsProc(ctm, constY, scalarsPerPosition); 298 SkTextMapStateProc tmsProc(ctm, constY, scalarsPerPosition);
328 SkFixed halfSampleX = 0, halfSampleY = 0; 299 SkFixed halfSampleX = 0, halfSampleY = 0;
329 300
330 if (cache->isSubpixel()) { 301 if (cache->isSubpixel()) {
331 // maybe we should skip the rounding if linearText is set 302 // maybe we should skip the rounding if linearText is set
332 SkAxisAlignment baseline = SkComputeAxisAlignmentForHText(ctm); 303 SkAxisAlignment baseline = SkComputeAxisAlignmentForHText(ctm);
333 304
334 SkFixed fxMask = ~0; 305 SkFixed fxMask = ~0;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 } 417 }
447 } 418 }
448 } 419 }
449 420
450 this->finish(); 421 this->finish();
451 } 422 }
452 423
453 void GrBitmapTextContext::drawPackedGlyph(GrGlyph::PackedID packed, 424 void GrBitmapTextContext::drawPackedGlyph(GrGlyph::PackedID packed,
454 SkFixed vx, SkFixed vy, 425 SkFixed vx, SkFixed vy,
455 GrFontScaler* scaler) { 426 GrFontScaler* scaler) {
427 if (NULL == fDrawTarget) {
428 return;
429 }
430
431 if (NULL == fStrike) {
432 fStrike = fContext->getFontCache()->getStrike(scaler, false);
433 }
434
456 GrGlyph* glyph = fStrike->getGlyph(packed, scaler); 435 GrGlyph* glyph = fStrike->getGlyph(packed, scaler);
457 if (NULL == glyph || glyph->fBounds.isEmpty()) { 436 if (NULL == glyph || glyph->fBounds.isEmpty()) {
458 return; 437 return;
459 } 438 }
460 439
461 vx += SkIntToFixed(glyph->fBounds.fLeft); 440 vx += SkIntToFixed(glyph->fBounds.fLeft);
462 vy += SkIntToFixed(glyph->fBounds.fTop); 441 vy += SkIntToFixed(glyph->fBounds.fTop);
463 442
464 // keep them as ints until we've done the clip-test 443 // keep them as ints until we've done the clip-test
465 SkFixed width = glyph->fBounds.width(); 444 SkFixed width = glyph->fBounds.width();
(...skipping 20 matching lines...) Expand all
486 goto HAS_ATLAS; 465 goto HAS_ATLAS;
487 } 466 }
488 467
489 if (c_DumpFontCache) { 468 if (c_DumpFontCache) {
490 #ifdef SK_DEVELOPER 469 #ifdef SK_DEVELOPER
491 fContext->getFontCache()->dump(); 470 fContext->getFontCache()->dump();
492 #endif 471 #endif
493 } 472 }
494 473
495 // flush any accumulated draws to allow us to free up a plot 474 // flush any accumulated draws to allow us to free up a plot
496 int remainingVertexCount = fVertexCount - fCurrVertex;
497 this->flushGlyphs(); 475 this->flushGlyphs();
498 fContext->flush(); 476 fContext->flush();
499 477
500 // need to reallocate the vertex buffer for the remaining glyphs
501 fVertexCount = remainingVertexCount;
502 bool success = fDrawTarget->reserveVertexAndIndexSpace(fVertexCount,
503 0,
504 &fVertices,
505 NULL);
506 GrAlwaysAssert(success);
507
508 // we should have an unused plot now 478 // we should have an unused plot now
509 if (fContext->getFontCache()->freeUnusedPlot(fStrike) && 479 if (fContext->getFontCache()->freeUnusedPlot(fStrike) &&
510 fStrike->addGlyphToAtlas(glyph, scaler)) { 480 fStrike->addGlyphToAtlas(glyph, scaler)) {
511 goto HAS_ATLAS; 481 goto HAS_ATLAS;
512 } 482 }
513 483
514 if (NULL == glyph->fPath) { 484 if (NULL == glyph->fPath) {
515 SkPath* path = SkNEW(SkPath); 485 SkPath* path = SkNEW(SkPath);
516 if (!scaler->getGlyphPath(glyph->glyphID(), path)) { 486 if (!scaler->getGlyphPath(glyph->glyphID(), path)) {
517 // flag the glyph as being dead? 487 // flag the glyph as being dead?
(...skipping 19 matching lines...) Expand all
537 GrDrawTarget::DrawToken drawToken = fDrawTarget->getCurrentDrawToken(); 507 GrDrawTarget::DrawToken drawToken = fDrawTarget->getCurrentDrawToken();
538 glyph->fPlot->setDrawToken(drawToken); 508 glyph->fPlot->setDrawToken(drawToken);
539 509
540 // now promote them to fixed (TODO: Rethink using fixed pt). 510 // now promote them to fixed (TODO: Rethink using fixed pt).
541 width = SkIntToFixed(width); 511 width = SkIntToFixed(width);
542 height = SkIntToFixed(height); 512 height = SkIntToFixed(height);
543 513
544 GrTexture* texture = glyph->fPlot->texture(); 514 GrTexture* texture = glyph->fPlot->texture();
545 SkASSERT(texture); 515 SkASSERT(texture);
546 516
517 if (fCurrTexture != texture || fCurrVertex + 4 > fMaxVertices) {
518 this->flushGlyphs();
519 fCurrTexture = texture;
520 fCurrTexture->ref();
521 }
522
523 bool useColorVerts = kA8_GrMaskFormat == fStrike->getMaskFormat();
524
525 if (NULL == fVertices) {
526 // If we need to reserve vertices allow the draw target to suggest
527 // a number of verts to reserve and whether to perform a flush.
528 fMaxVertices = kMinRequestedVerts;
529 if (useColorVerts) {
530 fDrawTarget->drawState()->setVertexAttribs<gTextVertexWithColorAttri bs>(
531 SK_ARRAY_COUNT(gTextVertexWithColorAttribs));
532 } else {
533 fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>(
534 SK_ARRAY_COUNT(gTextVertexAttribs));
535 }
536 bool flush = fDrawTarget->geometryHints(&fMaxVertices, NULL);
537 if (flush) {
538 this->flushGlyphs();
539 fContext->flush();
540 if (useColorVerts) {
541 fDrawTarget->drawState()->setVertexAttribs<gTextVertexWithColorA ttribs>(
542 SK_ARRAY_COUNT(gTextVertexWithColorAttribs));
543 } else {
544 fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>(
545 SK_ARRAY_COUNT(gTextVertexAttribs));
546 }
547 }
548 fMaxVertices = kDefaultRequestedVerts;
549 // ignore return, no point in flushing again.
550 fDrawTarget->geometryHints(&fMaxVertices, NULL);
551
552 int maxQuadVertices = 4 * fContext->getQuadIndexBuffer()->maxQuads();
553 if (fMaxVertices < kMinRequestedVerts) {
554 fMaxVertices = kDefaultRequestedVerts;
555 } else if (fMaxVertices > maxQuadVertices) {
556 // don't exceed the limit of the index buffer
557 fMaxVertices = maxQuadVertices;
558 }
559 bool success = fDrawTarget->reserveVertexAndIndexSpace(fMaxVertices,
560 0,
561 &fVertices,
562 NULL);
563 GrAlwaysAssert(success);
564 }
565
547 SkFixed tx = SkIntToFixed(glyph->fAtlasLocation.fX); 566 SkFixed tx = SkIntToFixed(glyph->fAtlasLocation.fX);
548 SkFixed ty = SkIntToFixed(glyph->fAtlasLocation.fY); 567 SkFixed ty = SkIntToFixed(glyph->fAtlasLocation.fY);
549 568
550 SkRect r; 569 SkRect r;
551 r.fLeft = SkFixedToFloat(vx); 570 r.fLeft = SkFixedToFloat(vx);
552 r.fTop = SkFixedToFloat(vy); 571 r.fTop = SkFixedToFloat(vy);
553 r.fRight = SkFixedToFloat(vx + width); 572 r.fRight = SkFixedToFloat(vx + width);
554 r.fBottom = SkFixedToFloat(vy + height); 573 r.fBottom = SkFixedToFloat(vy + height);
555 574
556 fVertexBounds.growToInclude(r); 575 fVertexBounds.growToInclude(r);
557 576
558 bool useColorVerts = kA8_GrMaskFormat == fStrike->getMaskFormat();
559 size_t vertSize = useColorVerts ? (2 * sizeof(SkPoint) + sizeof(GrColor)) : 577 size_t vertSize = useColorVerts ? (2 * sizeof(SkPoint) + sizeof(GrColor)) :
560 (2 * sizeof(SkPoint)); 578 (2 * sizeof(SkPoint));
561 579
562 SkASSERT(vertSize == fDrawTarget->getDrawState().getVertexSize()); 580 SkASSERT(vertSize == fDrawTarget->getDrawState().getVertexSize());
563 581
564 SkPoint* positions = reinterpret_cast<SkPoint*>( 582 SkPoint* positions = reinterpret_cast<SkPoint*>(
565 reinterpret_cast<intptr_t>(fVertices) + vertSize * fCurrVertex); 583 reinterpret_cast<intptr_t>(fVertices) + vertSize * fCurrVertex);
566 positions->setRectFan(r.fLeft, r.fTop, r.fRight, r.fBottom, vertSize); 584 positions->setRectFan(r.fLeft, r.fTop, r.fRight, r.fBottom, vertSize);
567 585
568 // The texture coords are last in both the with and without color vertex lay outs. 586 // The texture coords are last in both the with and without color vertex lay outs.
(...skipping 10 matching lines...) Expand all
579 } 597 }
580 // color comes after position. 598 // color comes after position.
581 GrColor* colors = reinterpret_cast<GrColor*>(positions + 1); 599 GrColor* colors = reinterpret_cast<GrColor*>(positions + 1);
582 for (int i = 0; i < 4; ++i) { 600 for (int i = 0; i < 4; ++i) {
583 *colors = fPaint.getColor(); 601 *colors = fPaint.getColor();
584 colors = reinterpret_cast<GrColor*>(reinterpret_cast<intptr_t>(colors ) + vertSize); 602 colors = reinterpret_cast<GrColor*>(reinterpret_cast<intptr_t>(colors ) + vertSize);
585 } 603 }
586 } 604 }
587 fCurrVertex += 4; 605 fCurrVertex += 4;
588 } 606 }
OLDNEW
« no previous file with comments | « src/gpu/GrBitmapTextContext.h ('k') | src/gpu/GrDistanceFieldTextContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698