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

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

Issue 466363009: Restore text alloc optimizations. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix crash + clean up. 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
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 "GrDistanceFieldTextContext.h" 8 #include "GrDistanceFieldTextContext.h"
9 #include "GrAtlas.h" 9 #include "GrAtlas.h"
10 #include "SkColorFilter.h" 10 #include "SkColorFilter.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 {kVec2f_GrVertexAttribType, 0, kPosition_Gr VertexAttribBinding}, 49 {kVec2f_GrVertexAttribType, 0, kPosition_Gr VertexAttribBinding},
50 {kVec4ub_GrVertexAttribType, sizeof(SkPoint), kColor_GrVer texAttribBinding}, 50 {kVec4ub_GrVertexAttribType, sizeof(SkPoint), kColor_GrVer texAttribBinding},
51 {kVec2f_GrVertexAttribType, sizeof(SkPoint) + sizeof(GrColor), kEffect_GrVe rtexAttribBinding} 51 {kVec2f_GrVertexAttribType, sizeof(SkPoint) + sizeof(GrColor), kEffect_GrVe rtexAttribBinding}
52 }; 52 };
53 53
54 }; 54 };
55 55
56 GrDistanceFieldTextContext::GrDistanceFieldTextContext(GrContext* context, 56 GrDistanceFieldTextContext::GrDistanceFieldTextContext(GrContext* context,
57 const SkDeviceProperties& properties, 57 const SkDeviceProperties& properties,
58 bool enable) 58 bool enable)
59 : GrTextContext(context, pro perties) { 59 : GrTextContext(context, pro perties)
60 , fStrike(NULL)
60 #if SK_FORCE_DISTANCEFIELD_FONTS 61 #if SK_FORCE_DISTANCEFIELD_FONTS
61 fEnableDFRendering = true; 62 , fEnableDFRendering(true)
62 #else 63 #else
63 fEnableDFRendering = enable; 64 , fEnableDFRendering(true)// enable)
64 #endif 65 #endif
65 fStrike = NULL; 66 , fEffectTextureUniqueID(SK_ InvalidUniqueID)
66 fGammaTexture = NULL; 67 , fEffectColor(GrColor_ILLEG AL)
67 68 , fEffectFlags(0)
68 fCurrTexture = NULL; 69 , fGammaTexture(NULL)
69 fCurrVertex = 0; 70 , fVertices(NULL)
70 fEffectTextureUniqueID = SK_InvalidUniqueID; 71 , fVertexCount(0)
71 fEffectColor = GrColor_ILLEGAL; 72 , fCurrVertex(0) {
72 fEffectFlags = 0;
73
74 fVertices = NULL;
75 fMaxVertices = 0;
76
77 fVertexBounds.setLargestInverted(); 73 fVertexBounds.setLargestInverted();
78 } 74 }
79 75
80 GrDistanceFieldTextContext::~GrDistanceFieldTextContext() { 76 GrDistanceFieldTextContext::~GrDistanceFieldTextContext() {
81 this->flushGlyphs(); 77 this->flushGlyphs();
82 SkSafeSetNull(fGammaTexture); 78 SkSafeSetNull(fGammaTexture);
83 } 79 }
84 80
85 bool GrDistanceFieldTextContext::canDraw(const SkPaint& paint) { 81 bool GrDistanceFieldTextContext::canDraw(const SkPaint& paint) {
86 if (!fEnableDFRendering && !paint.isDistanceFieldTextTEMP()) { 82 if (!fEnableDFRendering && !paint.isDistanceFieldTextTEMP()) {
(...skipping 28 matching lines...) Expand all
115 unsigned r = SkColorGetR(c); 111 unsigned r = SkColorGetR(c);
116 unsigned g = SkColorGetG(c); 112 unsigned g = SkColorGetG(c);
117 unsigned b = SkColorGetB(c); 113 unsigned b = SkColorGetB(c);
118 return GrColorPackRGBA(r, g, b, 0xff); 114 return GrColorPackRGBA(r, g, b, 0xff);
119 } 115 }
120 116
121 void GrDistanceFieldTextContext::setupCoverageEffect(const SkColor& filteredColo r) { 117 void GrDistanceFieldTextContext::setupCoverageEffect(const SkColor& filteredColo r) {
122 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kBilerp_ FilterMode); 118 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kBilerp_ FilterMode);
123 GrTextureParams gammaParams(SkShader::kClamp_TileMode, GrTextureParams::kNon e_FilterMode); 119 GrTextureParams gammaParams(SkShader::kClamp_TileMode, GrTextureParams::kNon e_FilterMode);
124 120
125 uint32_t textureUniqueID = fCurrTexture->getUniqueID(); 121 GrTexture* currTexture = fStrike->getTexture();
122 SkASSERT(currTexture);
123 uint32_t textureUniqueID = currTexture->getUniqueID();
126 124
127 // set up any flags 125 // set up any flags
128 uint32_t flags = 0; 126 uint32_t flags = 0;
129 flags |= fContext->getMatrix().isSimilarity() ? kSimilarity_DistanceFieldEff ectFlag : 0; 127 flags |= fContext->getMatrix().isSimilarity() ? kSimilarity_DistanceFieldEff ectFlag : 0;
130 flags |= fUseLCDText ? kUseLCD_DistanceFieldEffectFlag : 0; 128 flags |= fUseLCDText ? kUseLCD_DistanceFieldEffectFlag : 0;
131 flags |= fUseLCDText && fContext->getMatrix().rectStaysRect() ? 129 flags |= fUseLCDText && fContext->getMatrix().rectStaysRect() ?
132 kRectToRect_DistanceFieldEffectFlag : 0; 130 kRectToRect_DistanceFieldEffectFlag : 0;
133 bool useBGR = SkDeviceProperties::Geometry::kBGR_Layout == 131 bool useBGR = SkDeviceProperties::Geometry::kBGR_Layout ==
134 fDeviceProperties.fGeometry.getLayout(); 132 fDeviceProperties.fGeometry.getLayout();
135 flags |= fUseLCDText && useBGR ? kBGR_DistanceFieldEffectFlag : 0; 133 flags |= fUseLCDText && useBGR ? kBGR_DistanceFieldEffectFlag : 0;
136 134
137 // see if we need to create a new effect 135 // see if we need to create a new effect
138 if (textureUniqueID != fEffectTextureUniqueID || 136 if (textureUniqueID != fEffectTextureUniqueID ||
139 filteredColor != fEffectColor || 137 filteredColor != fEffectColor ||
140 flags != fEffectFlags) { 138 flags != fEffectFlags) {
141 if (fUseLCDText) { 139 if (fUseLCDText) {
142 GrColor colorNoPreMul = skcolor_to_grcolor_nopremultiply(filteredCol or); 140 GrColor colorNoPreMul = skcolor_to_grcolor_nopremultiply(filteredCol or);
143 fCachedEffect.reset(GrDistanceFieldLCDTextureEffect::Create(fCurrTex ture, 141 fCachedEffect.reset(GrDistanceFieldLCDTextureEffect::Create(currText ure,
144 params, 142 params,
145 fGammaTe xture, 143 fGammaTe xture,
146 gammaPar ams, 144 gammaPar ams,
147 colorNoP reMul, 145 colorNoP reMul,
148 flags)); 146 flags));
149 } else { 147 } else {
150 #ifdef SK_GAMMA_APPLY_TO_A8 148 #ifdef SK_GAMMA_APPLY_TO_A8
151 U8CPU lum = SkColorSpaceLuminance::computeLuminance(fDevicePropertie s.fGamma, 149 U8CPU lum = SkColorSpaceLuminance::computeLuminance(fDevicePropertie s.fGamma,
152 filteredColor); 150 filteredColor);
153 fCachedEffect.reset(GrDistanceFieldTextureEffect::Create(fCurrTextur e, 151 fCachedEffect.reset(GrDistanceFieldTextureEffect::Create(currTexture ,
154 params, 152 params,
155 fGammaTextu re, 153 fGammaTextu re,
156 gammaParams , 154 gammaParams ,
157 lum/255.f, 155 lum/255.f,
158 flags)); 156 flags));
159 #else 157 #else
160 fCachedEffect.reset(GrDistanceFieldTextureEffect::Create(fCurrTextur e, 158 fCachedEffect.reset(GrDistanceFieldTextureEffect::Create(fCurrTextur e,
161 params, fla gs)); 159 params, fla gs));
162 #endif 160 #endif
163 } 161 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 // set back to normal in case we took LCD path previously. 217 // set back to normal in case we took LCD path previously.
220 drawState->setBlendFunc(fPaint.getSrcBlendCoeff(), fPaint.getDstBlen dCoeff()); 218 drawState->setBlendFunc(fPaint.getSrcBlendCoeff(), fPaint.getDstBlen dCoeff());
221 // We're using per-vertex color. 219 // We're using per-vertex color.
222 SkASSERT(drawState->hasColorVertexAttribute()); 220 SkASSERT(drawState->hasColorVertexAttribute());
223 } 221 }
224 int nGlyphs = fCurrVertex / 4; 222 int nGlyphs = fCurrVertex / 4;
225 fDrawTarget->setIndexSourceToBuffer(fContext->getQuadIndexBuffer()); 223 fDrawTarget->setIndexSourceToBuffer(fContext->getQuadIndexBuffer());
226 fDrawTarget->drawIndexedInstances(kTriangles_GrPrimitiveType, 224 fDrawTarget->drawIndexedInstances(kTriangles_GrPrimitiveType,
227 nGlyphs, 225 nGlyphs,
228 4, 6, &fVertexBounds); 226 4, 6, &fVertexBounds);
229 fDrawTarget->resetVertexSource();
230 fVertices = NULL;
231 fMaxVertices = 0;
232 fCurrVertex = 0; 227 fCurrVertex = 0;
233 SkSafeSetNull(fCurrTexture);
234 fVertexBounds.setLargestInverted(); 228 fVertexBounds.setLargestInverted();
235 } 229 }
230
231 fDrawTarget->resetVertexSource();
232 fVertices = NULL;
236 } 233 }
237 234
238 void GrDistanceFieldTextContext::drawPackedGlyph(GrGlyph::PackedID packed, 235 void GrDistanceFieldTextContext::drawPackedGlyph(GrGlyph::PackedID packed,
239 SkFixed vx, SkFixed vy, 236 SkFixed vx, SkFixed vy,
240 GrFontScaler* scaler) { 237 GrFontScaler* scaler) {
241 if (NULL == fDrawTarget) {
242 return;
243 }
244
245 if (NULL == fStrike) {
246 fStrike = fContext->getFontCache()->getStrike(scaler, true);
247 }
248
249 GrGlyph* glyph = fStrike->getGlyph(packed, scaler); 238 GrGlyph* glyph = fStrike->getGlyph(packed, scaler);
250 if (NULL == glyph || glyph->fBounds.isEmpty()) { 239 if (NULL == glyph || glyph->fBounds.isEmpty()) {
251 return; 240 return;
252 } 241 }
253 242
254 SkScalar sx = SkFixedToScalar(vx); 243 SkScalar sx = SkFixedToScalar(vx);
255 SkScalar sy = SkFixedToScalar(vy); 244 SkScalar sy = SkFixedToScalar(vy);
256 /* 245 /*
257 // not valid, need to find a different solution for this 246 // not valid, need to find a different solution for this
258 vx += SkIntToFixed(glyph->fBounds.fLeft); 247 vx += SkIntToFixed(glyph->fBounds.fLeft);
(...skipping 23 matching lines...) Expand all
282 fStrike->addGlyphToAtlas(glyph, scaler)) { 271 fStrike->addGlyphToAtlas(glyph, scaler)) {
283 goto HAS_ATLAS; 272 goto HAS_ATLAS;
284 } 273 }
285 274
286 if (c_DumpFontCache) { 275 if (c_DumpFontCache) {
287 #ifdef SK_DEVELOPER 276 #ifdef SK_DEVELOPER
288 fContext->getFontCache()->dump(); 277 fContext->getFontCache()->dump();
289 #endif 278 #endif
290 } 279 }
291 280
292 // before we purge the cache, we must flush any accumulated draws 281 // flush any accumulated draws to allow us to free up a plot
282 int remainingVertexCount = fVertexCount - fCurrVertex;
293 this->flushGlyphs(); 283 this->flushGlyphs();
294 fContext->flush(); 284 fContext->flush();
295 285
286 // need to reallocate the vertex buffer for the remaining glyphs
287 fVertexCount = remainingVertexCount;
288 bool success = fDrawTarget->reserveVertexAndIndexSpace(fVertexCount,
289 0,
290 &fVertices,
291 NULL);
292 GrAlwaysAssert(success);
293
296 // we should have an unused plot now 294 // we should have an unused plot now
297 if (fContext->getFontCache()->freeUnusedPlot(fStrike) && 295 if (fContext->getFontCache()->freeUnusedPlot(fStrike) &&
298 fStrike->addGlyphToAtlas(glyph, scaler)) { 296 fStrike->addGlyphToAtlas(glyph, scaler)) {
299 goto HAS_ATLAS; 297 goto HAS_ATLAS;
300 } 298 }
301 299
302 if (NULL == glyph->fPath) { 300 if (NULL == glyph->fPath) {
303 SkPath* path = SkNEW(SkPath); 301 SkPath* path = SkNEW(SkPath);
304 if (!scaler->getGlyphPath(glyph->glyphID(), path)) { 302 if (!scaler->getGlyphPath(glyph->glyphID(), path)) {
305 // flag the glyph as being dead? 303 // flag the glyph as being dead?
(...skipping 15 matching lines...) Expand all
321 } 319 }
322 320
323 HAS_ATLAS: 321 HAS_ATLAS:
324 SkASSERT(glyph->fPlot); 322 SkASSERT(glyph->fPlot);
325 GrDrawTarget::DrawToken drawToken = fDrawTarget->getCurrentDrawToken(); 323 GrDrawTarget::DrawToken drawToken = fDrawTarget->getCurrentDrawToken();
326 glyph->fPlot->setDrawToken(drawToken); 324 glyph->fPlot->setDrawToken(drawToken);
327 325
328 GrTexture* texture = glyph->fPlot->texture(); 326 GrTexture* texture = glyph->fPlot->texture();
329 SkASSERT(texture); 327 SkASSERT(texture);
330 328
331 if (fCurrTexture != texture || fCurrVertex + 4 > fMaxVertices) {
332 this->flushGlyphs();
333 fCurrTexture = texture;
334 fCurrTexture->ref();
335 }
336
337 bool useColorVerts = !fUseLCDText;
338
339 if (NULL == fVertices) {
340 // If we need to reserve vertices allow the draw target to suggest
341 // a number of verts to reserve and whether to perform a flush.
342 fMaxVertices = kMinRequestedVerts;
343 if (useColorVerts) {
344 fDrawTarget->drawState()->setVertexAttribs<gTextVertexWithColorAttri bs>(
345 SK_ARRAY_COUNT(gTextVertexWi thColorAttribs));
346 } else {
347 fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>(
348 SK_ARRAY_COUNT(gTextVertexAt tribs));
349 }
350 bool flush = fDrawTarget->geometryHints(&fMaxVertices, NULL);
351 if (flush) {
352 this->flushGlyphs();
353 fContext->flush();
354 if (useColorVerts) {
355 fDrawTarget->drawState()->setVertexAttribs<gTextVertexWithColorA ttribs>(
356 SK_ARRAY_COUNT(gTextVertexWi thColorAttribs));
357 } else {
358 fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>(
359 SK_ARRAY_COUNT(gTextVertexAt tribs));
360 }
361 }
362 fMaxVertices = kDefaultRequestedVerts;
363 // ignore return, no point in flushing again.
364 fDrawTarget->geometryHints(&fMaxVertices, NULL);
365
366 int maxQuadVertices = 4 * fContext->getQuadIndexBuffer()->maxQuads();
367 if (fMaxVertices < kMinRequestedVerts) {
368 fMaxVertices = kDefaultRequestedVerts;
369 } else if (fMaxVertices > maxQuadVertices) {
370 // don't exceed the limit of the index buffer
371 fMaxVertices = maxQuadVertices;
372 }
373 bool success = fDrawTarget->reserveVertexAndIndexSpace(fMaxVertices,
374 0,
375 &fVertices,
376 NULL);
377 GrAlwaysAssert(success);
378 }
379
380 SkScalar dx = SkIntToScalar(glyph->fBounds.fLeft + SK_DistanceFieldInset); 329 SkScalar dx = SkIntToScalar(glyph->fBounds.fLeft + SK_DistanceFieldInset);
381 SkScalar dy = SkIntToScalar(glyph->fBounds.fTop + SK_DistanceFieldInset); 330 SkScalar dy = SkIntToScalar(glyph->fBounds.fTop + SK_DistanceFieldInset);
382 SkScalar width = SkIntToScalar(glyph->fBounds.width() - 2*SK_DistanceFieldIn set); 331 SkScalar width = SkIntToScalar(glyph->fBounds.width() - 2*SK_DistanceFieldIn set);
383 SkScalar height = SkIntToScalar(glyph->fBounds.height() - 2*SK_DistanceField Inset); 332 SkScalar height = SkIntToScalar(glyph->fBounds.height() - 2*SK_DistanceField Inset);
384 333
385 SkScalar scale = fTextRatio; 334 SkScalar scale = fTextRatio;
386 dx *= scale; 335 dx *= scale;
387 dy *= scale; 336 dy *= scale;
388 sx += dx; 337 sx += dx;
389 sy += dy; 338 sy += dy;
390 width *= scale; 339 width *= scale;
391 height *= scale; 340 height *= scale;
392 341
393 SkFixed tx = SkIntToFixed(glyph->fAtlasLocation.fX + SK_DistanceFieldInset); 342 SkFixed tx = SkIntToFixed(glyph->fAtlasLocation.fX + SK_DistanceFieldInset);
394 SkFixed ty = SkIntToFixed(glyph->fAtlasLocation.fY + SK_DistanceFieldInset); 343 SkFixed ty = SkIntToFixed(glyph->fAtlasLocation.fY + SK_DistanceFieldInset);
395 SkFixed tw = SkIntToFixed(glyph->fBounds.width() - 2*SK_DistanceFieldInset); 344 SkFixed tw = SkIntToFixed(glyph->fBounds.width() - 2*SK_DistanceFieldInset);
396 SkFixed th = SkIntToFixed(glyph->fBounds.height() - 2*SK_DistanceFieldInset) ; 345 SkFixed th = SkIntToFixed(glyph->fBounds.height() - 2*SK_DistanceFieldInset) ;
397 346
398 SkRect r; 347 SkRect r;
399 r.fLeft = sx; 348 r.fLeft = sx;
400 r.fTop = sy; 349 r.fTop = sy;
401 r.fRight = sx + width; 350 r.fRight = sx + width;
402 r.fBottom = sy + height; 351 r.fBottom = sy + height;
(...skipping 10 matching lines...) Expand all
413 positions->setRectFan(r.fLeft, r.fTop, r.fRight, r.fBottom, vertSize); 362 positions->setRectFan(r.fLeft, r.fTop, r.fRight, r.fBottom, vertSize);
414 363
415 // The texture coords are last in both the with and without color vertex lay outs. 364 // The texture coords are last in both the with and without color vertex lay outs.
416 SkPoint* textureCoords = reinterpret_cast<SkPoint*>( 365 SkPoint* textureCoords = reinterpret_cast<SkPoint*>(
417 reinterpret_cast<intptr_t>(positions) + vertSize - sizeof(SkPoint)) ; 366 reinterpret_cast<intptr_t>(positions) + vertSize - sizeof(SkPoint)) ;
418 textureCoords->setRectFan(SkFixedToFloat(texture->normalizeFixedX(tx)), 367 textureCoords->setRectFan(SkFixedToFloat(texture->normalizeFixedX(tx)),
419 SkFixedToFloat(texture->normalizeFixedY(ty)), 368 SkFixedToFloat(texture->normalizeFixedY(ty)),
420 SkFixedToFloat(texture->normalizeFixedX(tx + tw)), 369 SkFixedToFloat(texture->normalizeFixedX(tx + tw)),
421 SkFixedToFloat(texture->normalizeFixedY(ty + th)), 370 SkFixedToFloat(texture->normalizeFixedY(ty + th)),
422 vertSize); 371 vertSize);
423 if (useColorVerts) { 372 if (!fUseLCDText) {
424 if (0xFF == GrColorUnpackA(fPaint.getColor())) { 373 if (0xFF == GrColorUnpackA(fPaint.getColor())) {
425 fDrawTarget->drawState()->setHint(GrDrawState::kVertexColorsAreOpaqu e_Hint, true); 374 fDrawTarget->drawState()->setHint(GrDrawState::kVertexColorsAreOpaqu e_Hint, true);
426 } 375 }
427 // color comes after position. 376 // color comes after position.
428 GrColor* colors = reinterpret_cast<GrColor*>(positions + 1); 377 GrColor* colors = reinterpret_cast<GrColor*>(positions + 1);
429 for (int i = 0; i < 4; ++i) { 378 for (int i = 0; i < 4; ++i) {
430 *colors = fPaint.getColor(); 379 *colors = fPaint.getColor();
431 colors = reinterpret_cast<GrColor*>(reinterpret_cast<intptr_t>(color s) + vertSize); 380 colors = reinterpret_cast<GrColor*>(reinterpret_cast<intptr_t>(color s) + vertSize);
432 } 381 }
433 } 382 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 return; 452 return;
504 } 453 }
505 454
506 context->writeTexturePixels(*gammaTexture, 455 context->writeTexturePixels(*gammaTexture,
507 0, 0, width, height, 456 0, 0, width, height,
508 (*gammaTexture)->config(), data.get(), 0, 457 (*gammaTexture)->config(), data.get(), 0,
509 GrContext::kDontFlush_PixelOpsFlag); 458 GrContext::kDontFlush_PixelOpsFlag);
510 } 459 }
511 } 460 }
512 461
462 void GrDistanceFieldTextContext::allocateVertices(const char text[], size_t byte Length) {
463 SkASSERT(NULL == fVertices);
464 if (!fUseLCDText) {
465 fDrawTarget->drawState()->setVertexAttribs<gTextVertexWithColorAttribs>(
466 SK_ARRAY_COUNT(gTextVertexWi thColorAttribs));
467 } else {
468 fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>(
469 SK_ARRAY_COUNT(gTextVertexAt tribs));
470 }
471 fVertexCount = 4*fSkPaint.textToGlyphs(text, byteLength, NULL);
472 bool success = fDrawTarget->reserveVertexAndIndexSpace(fVertexCount,
473 0,
474 &fVertices,
475 NULL);
476 GrAlwaysAssert(success);
477 }
478
513 void GrDistanceFieldTextContext::drawText(const GrPaint& paint, const SkPaint& s kPaint, 479 void GrDistanceFieldTextContext::drawText(const GrPaint& paint, const SkPaint& s kPaint,
514 const char text[], size_t byteLength, 480 const char text[], size_t byteLength,
515 SkScalar x, SkScalar y) { 481 SkScalar x, SkScalar y) {
516 SkASSERT(byteLength == 0 || text != NULL); 482 SkASSERT(byteLength == 0 || text != NULL);
517 483
518 // nothing to draw or can't draw 484 // nothing to draw or can't draw
519 if (text == NULL || byteLength == 0 /* no raster clip? || fRC->isEmpty()*/ 485 if (text == NULL || byteLength == 0 /* no raster clip? || fRC->isEmpty()*/
520 || fSkPaint.getRasterizer()) { 486 || fSkPaint.getRasterizer()) {
521 return; 487 return;
522 } 488 }
523 489
524 this->init(paint, skPaint); 490 this->init(paint, skPaint);
525 491
492 if (NULL == fDrawTarget) {
493 return;
494 }
495
526 SkScalar sizeRatio = fTextRatio; 496 SkScalar sizeRatio = fTextRatio;
527 497
528 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); 498 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc();
529 499
530 SkAutoGlyphCacheNoGamma autoCache(fSkPaint, &fDeviceProperties, NULL); 500 SkAutoGlyphCacheNoGamma autoCache(fSkPaint, &fDeviceProperties, NULL);
531 SkGlyphCache* cache = autoCache.getCache(); 501 SkGlyphCache* cache = autoCache.getCache();
532 GrFontScaler* fontScaler = GetGrFontScaler(cache); 502 GrFontScaler* fontScaler = GetGrFontScaler(cache);
503 if (NULL == fStrike) {
504 fStrike = fContext->getFontCache()->getStrike(fontScaler, true);
505 }
533 506
534 setup_gamma_texture(fContext, cache, fDeviceProperties, &fGammaTexture); 507 setup_gamma_texture(fContext, cache, fDeviceProperties, &fGammaTexture);
535 508
509 allocateVertices(text, byteLength);
bsalomon 2014/08/27 14:32:01 this->
jvanverth1 2014/08/27 15:31:59 Done.
510
bsalomon 2014/08/27 14:32:01 this->
jvanverth1 2014/08/27 15:31:59 Not sure what this is referring to. setup_gamma_te
536 // need to measure first 511 // need to measure first
537 // TODO - generate positions and pre-load cache as well? 512 // TODO - generate positions and pre-load cache as well?
538 const char* stop = text + byteLength; 513 const char* stop = text + byteLength;
539 if (fSkPaint.getTextAlign() != SkPaint::kLeft_Align) { 514 if (fSkPaint.getTextAlign() != SkPaint::kLeft_Align) {
540 SkFixed stopX = 0; 515 SkFixed stopX = 0;
541 SkFixed stopY = 0; 516 SkFixed stopY = 0;
542 517
543 const char* textPtr = text; 518 const char* textPtr = text;
544 while (textPtr < stop) { 519 while (textPtr < stop) {
545 // don't need x, y here, since all subpixel variants will have the 520 // don't need x, y here, since all subpixel variants will have the
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 SkASSERT(byteLength == 0 || text != NULL); 568 SkASSERT(byteLength == 0 || text != NULL);
594 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); 569 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
595 570
596 // nothing to draw 571 // nothing to draw
597 if (text == NULL || byteLength == 0 /* no raster clip? || fRC->isEmpty()*/) { 572 if (text == NULL || byteLength == 0 /* no raster clip? || fRC->isEmpty()*/) {
598 return; 573 return;
599 } 574 }
600 575
601 this->init(paint, skPaint); 576 this->init(paint, skPaint);
602 577
578 if (NULL == fDrawTarget) {
579 return;
580 }
581
603 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); 582 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc();
604 583
605 SkAutoGlyphCacheNoGamma autoCache(fSkPaint, &fDeviceProperties, NULL); 584 SkAutoGlyphCacheNoGamma autoCache(fSkPaint, &fDeviceProperties, NULL);
606 SkGlyphCache* cache = autoCache.getCache(); 585 SkGlyphCache* cache = autoCache.getCache();
607 GrFontScaler* fontScaler = GetGrFontScaler(cache); 586 GrFontScaler* fontScaler = GetGrFontScaler(cache);
587 if (NULL == fStrike) {
588 fStrike = fContext->getFontCache()->getStrike(fontScaler, true);
589 }
608 590
609 setup_gamma_texture(fContext, cache, fDeviceProperties, &fGammaTexture); 591 setup_gamma_texture(fContext, cache, fDeviceProperties, &fGammaTexture);
610 592
593 allocateVertices(text, byteLength);
594
bsalomon 2014/08/27 14:32:01 this->
jvanverth1 2014/08/27 15:31:59 Done.
611 const char* stop = text + byteLength; 595 const char* stop = text + byteLength;
612 596
613 if (SkPaint::kLeft_Align == fSkPaint.getTextAlign()) { 597 if (SkPaint::kLeft_Align == fSkPaint.getTextAlign()) {
614 while (text < stop) { 598 while (text < stop) {
615 // the last 2 parameters are ignored 599 // the last 2 parameters are ignored
616 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); 600 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0);
617 601
618 if (glyph.fWidth) { 602 if (glyph.fWidth) {
619 SkScalar x = pos[0]; 603 SkScalar x = pos[0];
620 SkScalar y = scalarsPerPosition == 1 ? constY : pos[1]; 604 SkScalar y = scalarsPerPosition == 1 ? constY : pos[1];
(...skipping 23 matching lines...) Expand all
644 SkScalarToFixed(x) - (glyph.fAdvanceX >> a lignShift), 628 SkScalarToFixed(x) - (glyph.fAdvanceX >> a lignShift),
645 SkScalarToFixed(y) - (glyph.fAdvanceY >> a lignShift), 629 SkScalarToFixed(y) - (glyph.fAdvanceY >> a lignShift),
646 fontScaler); 630 fontScaler);
647 } 631 }
648 pos += scalarsPerPosition; 632 pos += scalarsPerPosition;
649 } 633 }
650 } 634 }
651 635
652 this->finish(); 636 this->finish();
653 } 637 }
OLDNEW
« src/gpu/GrBitmapTextContext.cpp ('K') | « src/gpu/GrDistanceFieldTextContext.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698