| OLD | NEW |
| 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 #include "GrAtlasTextContext.h" | 7 #include "GrAtlasTextContext.h" |
| 8 | 8 |
| 9 #include "GrDrawContext.h" | 9 #include "GrDrawContext.h" |
| 10 #include "GrDrawTarget.h" | 10 #include "GrDrawTarget.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 bool GrAtlasTextContext::HasLCD(const SkTextBlob* blob) { | 98 bool GrAtlasTextContext::HasLCD(const SkTextBlob* blob) { |
| 99 SkTextBlobRunIterator it(blob); | 99 SkTextBlobRunIterator it(blob); |
| 100 for (; !it.done(); it.next()) { | 100 for (; !it.done(); it.next()) { |
| 101 if (it.isLCD()) { | 101 if (it.isLCD()) { |
| 102 return true; | 102 return true; |
| 103 } | 103 } |
| 104 } | 104 } |
| 105 return false; | 105 return false; |
| 106 } | 106 } |
| 107 | 107 |
| 108 inline SkGlyphCache* GrAtlasTextContext::setupCache(GrAtlasTextBlob::Run* run, |
| 109 const SkPaint& skPaint, |
| 110 const SkMatrix* viewMatrix, |
| 111 bool noGamma) { |
| 112 skPaint.getScalerContextDescriptor(&run->fDescriptor, fSurfaceProps, viewMat
rix, noGamma); |
| 113 run->fTypeface.reset(SkSafeRef(skPaint.getTypeface())); |
| 114 return SkGlyphCache::DetachCache(run->fTypeface, run->fDescriptor.getDesc())
; |
| 115 } |
| 116 |
| 108 void GrAtlasTextContext::drawTextBlob(GrDrawContext* dc, | 117 void GrAtlasTextContext::drawTextBlob(GrDrawContext* dc, |
| 109 const GrClip& clip, const SkPaint& skPaint
, | 118 const GrClip& clip, const SkPaint& skPaint
, |
| 110 const SkMatrix& viewMatrix, const SkTextBl
ob* blob, | 119 const SkMatrix& viewMatrix, const SkTextBl
ob* blob, |
| 111 SkScalar x, SkScalar y, | 120 SkScalar x, SkScalar y, |
| 112 SkDrawFilter* drawFilter, const SkIRect& c
lipBounds) { | 121 SkDrawFilter* drawFilter, const SkIRect& c
lipBounds) { |
| 113 // If we have been abandoned, then don't draw | 122 // If we have been abandoned, then don't draw |
| 114 if (fContext->abandoned()) { | 123 if (fContext->abandoned()) { |
| 115 return; | 124 return; |
| 116 } | 125 } |
| 117 | 126 |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 | 284 |
| 276 if (this->canDrawAsDistanceFields(runPaint, viewMatrix)) { | 285 if (this->canDrawAsDistanceFields(runPaint, viewMatrix)) { |
| 277 cacheBlob->setHasDistanceField(); | 286 cacheBlob->setHasDistanceField(); |
| 278 SkPaint dfPaint = runPaint; | 287 SkPaint dfPaint = runPaint; |
| 279 SkScalar textRatio; | 288 SkScalar textRatio; |
| 280 this->initDistanceFieldPaint(cacheBlob, &dfPaint, &textRatio, viewMa
trix); | 289 this->initDistanceFieldPaint(cacheBlob, &dfPaint, &textRatio, viewMa
trix); |
| 281 Run& runIdx = cacheBlob->fRuns[run]; | 290 Run& runIdx = cacheBlob->fRuns[run]; |
| 282 PerSubRunInfo& subRun = runIdx.fSubRunInfo.back(); | 291 PerSubRunInfo& subRun = runIdx.fSubRunInfo.back(); |
| 283 subRun.setUseLCDText(runPaint.isLCDRenderText()); | 292 subRun.setUseLCDText(runPaint.isLCDRenderText()); |
| 284 subRun.setDrawAsDistanceFields(); | 293 subRun.setDrawAsDistanceFields(); |
| 294 SkGlyphCache* cache = this->setupCache(&cacheBlob->fRuns[run], dfPai
nt, nullptr, true); |
| 285 | 295 |
| 286 switch (it.positioning()) { | 296 switch (it.positioning()) { |
| 287 case SkTextBlob::kDefault_Positioning: { | 297 case SkTextBlob::kDefault_Positioning: { |
| 288 this->internalDrawDFText(cacheBlob, run, dfPaint, color, vie
wMatrix, | 298 this->internalDrawDFText(cacheBlob, run, cache, dfPaint, col
or, viewMatrix, |
| 289 (const char *)it.glyphs(), textLen, | 299 (const char *)it.glyphs(), textLen, |
| 290 x + offset.x(), y + offset.y(), tex
tRatio, runPaint); | 300 x + offset.x(), y + offset.y(), tex
tRatio, runPaint); |
| 291 break; | 301 break; |
| 292 } | 302 } |
| 293 case SkTextBlob::kHorizontal_Positioning: { | 303 case SkTextBlob::kHorizontal_Positioning: { |
| 294 SkPoint dfOffset = SkPoint::Make(x, y + offset.y()); | 304 SkPoint dfOffset = SkPoint::Make(x, y + offset.y()); |
| 295 this->internalDrawDFPosText(cacheBlob, run, dfPaint, color,
viewMatrix, | 305 this->internalDrawDFPosText(cacheBlob, run, cache, dfPaint,
color, viewMatrix, |
| 296 (const char*)it.glyphs(), textLe
n, it.pos(), | 306 (const char*)it.glyphs(), textLe
n, it.pos(), |
| 297 1, dfOffset, textRatio, | 307 1, dfOffset, textRatio, |
| 298 runPaint); | 308 runPaint); |
| 299 break; | 309 break; |
| 300 } | 310 } |
| 301 case SkTextBlob::kFull_Positioning: { | 311 case SkTextBlob::kFull_Positioning: { |
| 302 SkPoint dfOffset = SkPoint::Make(x, y); | 312 SkPoint dfOffset = SkPoint::Make(x, y); |
| 303 this->internalDrawDFPosText(cacheBlob, run, dfPaint, color,
viewMatrix, | 313 this->internalDrawDFPosText(cacheBlob, run, cache, dfPaint,
color, viewMatrix, |
| 304 (const char*)it.glyphs(), textLe
n, it.pos(), | 314 (const char*)it.glyphs(), textLe
n, it.pos(), |
| 305 2, dfOffset, textRatio, runPaint
); | 315 2, dfOffset, textRatio, runPaint
); |
| 306 break; | 316 break; |
| 307 } | 317 } |
| 308 } | 318 } |
| 319 SkGlyphCache::AttachCache(cache); |
| 309 } else if (SkDraw::ShouldDrawTextAsPaths(runPaint, viewMatrix)) { | 320 } else if (SkDraw::ShouldDrawTextAsPaths(runPaint, viewMatrix)) { |
| 310 cacheBlob->fRuns[run].fDrawAsPaths = true; | 321 cacheBlob->fRuns[run].fDrawAsPaths = true; |
| 311 } else { | 322 } else { |
| 312 cacheBlob->setHasBitmap(); | 323 cacheBlob->setHasBitmap(); |
| 324 SkGlyphCache* cache = this->setupCache(&cacheBlob->fRuns[run], runPa
int, &viewMatrix, |
| 325 false); |
| 313 switch (it.positioning()) { | 326 switch (it.positioning()) { |
| 314 case SkTextBlob::kDefault_Positioning: | 327 case SkTextBlob::kDefault_Positioning: |
| 315 GrTextUtils::DrawBmpText(cacheBlob, run, fContext->getBatchF
ontCache(), | 328 GrTextUtils::DrawBmpText(cacheBlob, run, fContext->getBatchF
ontCache(), |
| 316 fSurfaceProps, runPaint, color, vie
wMatrix, | 329 cache, runPaint, color, viewMatrix, |
| 317 (const char *)it.glyphs(), textLen, | 330 (const char *)it.glyphs(), textLen, |
| 318 x + offset.x(), y + offset.y()); | 331 x + offset.x(), y + offset.y()); |
| 319 break; | 332 break; |
| 320 case SkTextBlob::kHorizontal_Positioning: | 333 case SkTextBlob::kHorizontal_Positioning: |
| 321 GrTextUtils::DrawBmpPosText(cacheBlob, run, fContext->getBat
chFontCache(), | 334 GrTextUtils::DrawBmpPosText(cacheBlob, run, fContext->getBat
chFontCache(), |
| 322 fSurfaceProps, runPaint, color,
viewMatrix, | 335 cache, runPaint, color, viewMatr
ix, |
| 323 (const char*)it.glyphs(), textLe
n, it.pos(), 1, | 336 (const char*)it.glyphs(), textLe
n, it.pos(), 1, |
| 324 SkPoint::Make(x, y + offset.y())
); | 337 SkPoint::Make(x, y + offset.y())
); |
| 325 break; | 338 break; |
| 326 case SkTextBlob::kFull_Positioning: | 339 case SkTextBlob::kFull_Positioning: |
| 327 GrTextUtils::DrawBmpPosText(cacheBlob, run, fContext->getBat
chFontCache(), | 340 GrTextUtils::DrawBmpPosText(cacheBlob, run, fContext->getBat
chFontCache(), |
| 328 fSurfaceProps, runPaint, color,
viewMatrix, | 341 cache, runPaint, color, viewMatr
ix, |
| 329 (const char*)it.glyphs(), textLe
n, it.pos(), 2, | 342 (const char*)it.glyphs(), textLe
n, it.pos(), 2, |
| 330 SkPoint::Make(x, y)); | 343 SkPoint::Make(x, y)); |
| 331 break; | 344 break; |
| 332 } | 345 } |
| 346 SkGlyphCache::AttachCache(cache); |
| 333 } | 347 } |
| 334 | 348 |
| 335 if (drawFilter) { | 349 if (drawFilter) { |
| 336 // A draw filter may change the paint arbitrarily, so we must re-see
d in this case. | 350 // A draw filter may change the paint arbitrarily, so we must re-see
d in this case. |
| 337 runPaint = skPaint; | 351 runPaint = skPaint; |
| 338 } | 352 } |
| 339 } | 353 } |
| 340 } | 354 } |
| 341 | 355 |
| 342 inline void GrAtlasTextContext::initDistanceFieldPaint(GrAtlasTextBlob* blob, | 356 inline void GrAtlasTextContext::initDistanceFieldPaint(GrAtlasTextBlob* blob, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 const SkTDArray<char>& fallb
ackTxt, | 415 const SkTDArray<char>& fallb
ackTxt, |
| 402 const SkTDArray<SkScalar>& f
allbackPos, | 416 const SkTDArray<SkScalar>& f
allbackPos, |
| 403 int scalarsPerPosition, | 417 int scalarsPerPosition, |
| 404 const SkPoint& offset) { | 418 const SkPoint& offset) { |
| 405 SkASSERT(fallbackTxt.count()); | 419 SkASSERT(fallbackTxt.count()); |
| 406 blob->setHasBitmap(); | 420 blob->setHasBitmap(); |
| 407 Run& run = blob->fRuns[runIndex]; | 421 Run& run = blob->fRuns[runIndex]; |
| 408 // Push back a new subrun to fill and set the override descriptor | 422 // Push back a new subrun to fill and set the override descriptor |
| 409 run.push_back(); | 423 run.push_back(); |
| 410 run.fOverrideDescriptor.reset(new SkAutoDescriptor); | 424 run.fOverrideDescriptor.reset(new SkAutoDescriptor); |
| 411 GrTextUtils::DrawBmpPosText(blob, runIndex, fContext->getBatchFontCache(), f
SurfaceProps, | 425 skPaint.getScalerContextDescriptor(run.fOverrideDescriptor, |
| 412 skPaint, color, viewMatrix, fallbackTxt.begin(),
fallbackTxt.count(), | 426 fSurfaceProps, &viewMatrix, false); |
| 427 SkGlyphCache* cache = SkGlyphCache::DetachCache(run.fTypeface, |
| 428 run.fOverrideDescriptor->get
Desc()); |
| 429 GrTextUtils::DrawBmpPosText(blob, runIndex, fContext->getBatchFontCache(), c
ache, skPaint, |
| 430 color, viewMatrix, fallbackTxt.begin(), fallback
Txt.count(), |
| 413 fallbackPos.begin(), scalarsPerPosition, offset)
; | 431 fallbackPos.begin(), scalarsPerPosition, offset)
; |
| 432 SkGlyphCache::AttachCache(cache); |
| 414 } | 433 } |
| 415 | 434 |
| 416 inline GrAtlasTextBlob* | 435 inline GrAtlasTextBlob* |
| 417 GrAtlasTextContext::setupDFBlob(int glyphCount, const SkPaint& origPaint, | 436 GrAtlasTextContext::setupDFBlob(int glyphCount, const SkPaint& origPaint, |
| 418 const SkMatrix& viewMatrix, SkPaint* dfPaint, | 437 const SkMatrix& viewMatrix, SkPaint* dfPaint, |
| 419 SkScalar* textRatio) { | 438 SkScalar* textRatio) { |
| 420 GrAtlasTextBlob* blob = fCache->createBlob(glyphCount, 1, GrAtlasTextBlob::k
GrayTextVASize); | 439 GrAtlasTextBlob* blob = fCache->createBlob(glyphCount, 1, GrAtlasTextBlob::k
GrayTextVASize); |
| 421 | 440 |
| 422 *dfPaint = origPaint; | 441 *dfPaint = origPaint; |
| 423 this->initDistanceFieldPaint(blob, dfPaint, textRatio, viewMatrix); | 442 this->initDistanceFieldPaint(blob, dfPaint, textRatio, viewMatrix); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 435 const SkMatrix& viewMatrix, | 454 const SkMatrix& viewMatrix, |
| 436 const char text[], size_t byteLength, | 455 const char text[], size_t byteLength, |
| 437 SkScalar x, SkScalar y) { | 456 SkScalar x, SkScalar y) { |
| 438 int glyphCount = skPaint.countText(text, byteLength); | 457 int glyphCount = skPaint.countText(text, byteLength); |
| 439 | 458 |
| 440 GrAtlasTextBlob* blob; | 459 GrAtlasTextBlob* blob; |
| 441 if (this->canDrawAsDistanceFields(skPaint, viewMatrix)) { | 460 if (this->canDrawAsDistanceFields(skPaint, viewMatrix)) { |
| 442 SkPaint dfPaint; | 461 SkPaint dfPaint; |
| 443 SkScalar textRatio; | 462 SkScalar textRatio; |
| 444 blob = this->setupDFBlob(glyphCount, skPaint, viewMatrix, &dfPaint, &tex
tRatio); | 463 blob = this->setupDFBlob(glyphCount, skPaint, viewMatrix, &dfPaint, &tex
tRatio); |
| 464 SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], dfPaint, nullptr
, true); |
| 445 | 465 |
| 446 this->internalDrawDFText(blob, 0, dfPaint, paint.getColor(), viewMatrix,
text, | 466 this->internalDrawDFText(blob, 0, cache, dfPaint, paint.getColor(), view
Matrix, text, |
| 447 byteLength, x, y, textRatio, skPaint); | 467 byteLength, x, y, textRatio, skPaint); |
| 468 SkGlyphCache::AttachCache(cache); |
| 448 } else { | 469 } else { |
| 449 blob = fCache->createBlob(glyphCount, 1, GrAtlasTextBlob::kGrayTextVASiz
e); | 470 blob = fCache->createBlob(glyphCount, 1, GrAtlasTextBlob::kGrayTextVASiz
e); |
| 450 blob->fViewMatrix = viewMatrix; | 471 blob->fViewMatrix = viewMatrix; |
| 451 | 472 |
| 452 GrTextUtils::DrawBmpText(blob, 0, fContext->getBatchFontCache(), fSurfac
eProps, skPaint, | 473 SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], skPaint, &viewMa
trix, false); |
| 474 GrTextUtils::DrawBmpText(blob, 0, fContext->getBatchFontCache(), cache,
skPaint, |
| 453 paint.getColor(), viewMatrix, text, byteLength,
x, y); | 475 paint.getColor(), viewMatrix, text, byteLength,
x, y); |
| 476 SkGlyphCache::AttachCache(cache); |
| 454 } | 477 } |
| 455 return blob; | 478 return blob; |
| 456 } | 479 } |
| 457 | 480 |
| 458 inline GrAtlasTextBlob* | 481 inline GrAtlasTextBlob* |
| 459 GrAtlasTextContext::createDrawPosTextBlob(const GrPaint& paint, const SkPaint& s
kPaint, | 482 GrAtlasTextContext::createDrawPosTextBlob(const GrPaint& paint, const SkPaint& s
kPaint, |
| 460 const SkMatrix& viewMatrix, | 483 const SkMatrix& viewMatrix, |
| 461 const char text[], size_t byteLength, | 484 const char text[], size_t byteLength, |
| 462 const SkScalar pos[], int scalarsPerPo
sition, | 485 const SkScalar pos[], int scalarsPerPo
sition, |
| 463 const SkPoint& offset) { | 486 const SkPoint& offset) { |
| 464 int glyphCount = skPaint.countText(text, byteLength); | 487 int glyphCount = skPaint.countText(text, byteLength); |
| 465 | 488 |
| 466 GrAtlasTextBlob* blob; | 489 GrAtlasTextBlob* blob; |
| 467 if (this->canDrawAsDistanceFields(skPaint, viewMatrix)) { | 490 if (this->canDrawAsDistanceFields(skPaint, viewMatrix)) { |
| 468 SkPaint dfPaint; | 491 SkPaint dfPaint; |
| 469 SkScalar textRatio; | 492 SkScalar textRatio; |
| 470 blob = this->setupDFBlob(glyphCount, skPaint, viewMatrix, &dfPaint, &tex
tRatio); | 493 blob = this->setupDFBlob(glyphCount, skPaint, viewMatrix, &dfPaint, &tex
tRatio); |
| 494 SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], dfPaint, nullptr
, true); |
| 471 | 495 |
| 472 this->internalDrawDFPosText(blob, 0, dfPaint, paint.getColor(), viewMatr
ix, text, | 496 this->internalDrawDFPosText(blob, 0, cache, dfPaint, paint.getColor(), v
iewMatrix, text, |
| 473 byteLength, pos, scalarsPerPosition, offset,
textRatio, | 497 byteLength, pos, scalarsPerPosition, offset,
textRatio, |
| 474 skPaint); | 498 skPaint); |
| 499 SkGlyphCache::AttachCache(cache); |
| 475 } else { | 500 } else { |
| 476 blob = fCache->createBlob(glyphCount, 1, GrAtlasTextBlob::kGrayTextVASiz
e); | 501 blob = fCache->createBlob(glyphCount, 1, GrAtlasTextBlob::kGrayTextVASiz
e); |
| 477 blob->fViewMatrix = viewMatrix; | 502 blob->fViewMatrix = viewMatrix; |
| 478 GrTextUtils::DrawBmpPosText(blob, 0, fContext->getBatchFontCache(), fSur
faceProps, skPaint, | 503 SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], skPaint, &viewMa
trix, false); |
| 504 GrTextUtils::DrawBmpPosText(blob, 0, fContext->getBatchFontCache(), cach
e, skPaint, |
| 479 paint.getColor(), viewMatrix, text, | 505 paint.getColor(), viewMatrix, text, |
| 480 byteLength, pos, scalarsPerPosition, offset)
; | 506 byteLength, pos, scalarsPerPosition, offset)
; |
| 507 SkGlyphCache::AttachCache(cache); |
| 481 } | 508 } |
| 482 return blob; | 509 return blob; |
| 483 } | 510 } |
| 484 | 511 |
| 485 void GrAtlasTextContext::onDrawText(GrDrawContext* dc, | 512 void GrAtlasTextContext::onDrawText(GrDrawContext* dc, |
| 486 const GrClip& clip, | 513 const GrClip& clip, |
| 487 const GrPaint& paint, const SkPaint& skPaint
, | 514 const GrPaint& paint, const SkPaint& skPaint
, |
| 488 const SkMatrix& viewMatrix, | 515 const SkMatrix& viewMatrix, |
| 489 const char text[], size_t byteLength, | 516 const char text[], size_t byteLength, |
| 490 SkScalar x, SkScalar y, const SkIRect& regio
nClipBounds) { | 517 SkScalar x, SkScalar y, const SkIRect& regio
nClipBounds) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 505 this->createDrawPosTextBlob(paint, skPaint, viewMatrix, | 532 this->createDrawPosTextBlob(paint, skPaint, viewMatrix, |
| 506 text, byteLength, | 533 text, byteLength, |
| 507 pos, scalarsPerPosition, | 534 pos, scalarsPerPosition, |
| 508 offset)); | 535 offset)); |
| 509 | 536 |
| 510 blob->flushThrowaway(fContext, dc, fSurfaceProps, fDistanceAdjustTable, skPa
int, paint, clip, | 537 blob->flushThrowaway(fContext, dc, fSurfaceProps, fDistanceAdjustTable, skPa
int, paint, clip, |
| 511 regionClipBounds); | 538 regionClipBounds); |
| 512 } | 539 } |
| 513 | 540 |
| 514 void GrAtlasTextContext::internalDrawDFText(GrAtlasTextBlob* blob, int runIndex, | 541 void GrAtlasTextContext::internalDrawDFText(GrAtlasTextBlob* blob, int runIndex, |
| 542 SkGlyphCache* cache, |
| 515 const SkPaint& skPaint, GrColor colo
r, | 543 const SkPaint& skPaint, GrColor colo
r, |
| 516 const SkMatrix& viewMatrix, | 544 const SkMatrix& viewMatrix, |
| 517 const char text[], size_t byteLength
, | 545 const char text[], size_t byteLength
, |
| 518 SkScalar x, SkScalar y, | 546 SkScalar x, SkScalar y, |
| 519 SkScalar textRatio, | 547 SkScalar textRatio, |
| 520 const SkPaint& origPaint) { | 548 const SkPaint& origPaint) { |
| 521 SkASSERT(byteLength == 0 || text != nullptr); | 549 SkASSERT(byteLength == 0 || text != nullptr); |
| 522 | 550 |
| 523 // nothing to draw | 551 // nothing to draw |
| 524 if (text == nullptr || byteLength == 0) { | 552 if (text == nullptr || byteLength == 0) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 alignX = SkScalarHalf(alignX); | 598 alignX = SkScalarHalf(alignX); |
| 571 alignY = SkScalarHalf(alignY); | 599 alignY = SkScalarHalf(alignY); |
| 572 } else if (origPaint.getTextAlign() == SkPaint::kLeft_Align) { | 600 } else if (origPaint.getTextAlign() == SkPaint::kLeft_Align) { |
| 573 alignX = 0; | 601 alignX = 0; |
| 574 alignY = 0; | 602 alignY = 0; |
| 575 } | 603 } |
| 576 x -= alignX; | 604 x -= alignX; |
| 577 y -= alignY; | 605 y -= alignY; |
| 578 SkPoint offset = SkPoint::Make(x, y); | 606 SkPoint offset = SkPoint::Make(x, y); |
| 579 | 607 |
| 580 this->internalDrawDFPosText(blob, runIndex, skPaint, color, viewMatrix, text
, byteLength, | 608 this->internalDrawDFPosText(blob, runIndex, cache, skPaint, color, viewMatri
x, text, byteLength, |
| 581 positions.begin(), 2, offset, textRatio, origPai
nt); | 609 positions.begin(), 2, offset, textRatio, origPai
nt); |
| 582 } | 610 } |
| 583 | 611 |
| 584 void GrAtlasTextContext::internalDrawDFPosText(GrAtlasTextBlob* blob, int runInd
ex, | 612 void GrAtlasTextContext::internalDrawDFPosText(GrAtlasTextBlob* blob, int runInd
ex, |
| 613 SkGlyphCache* cache, |
| 585 const SkPaint& skPaint, | 614 const SkPaint& skPaint, |
| 586 GrColor color, | 615 GrColor color, |
| 587 const SkMatrix& viewMatrix, | 616 const SkMatrix& viewMatrix, |
| 588 const char text[], size_t byteLen
gth, | 617 const char text[], size_t byteLen
gth, |
| 589 const SkScalar pos[], int scalars
PerPosition, | 618 const SkScalar pos[], int scalars
PerPosition, |
| 590 const SkPoint& offset, | 619 const SkPoint& offset, |
| 591 SkScalar textRatio, | 620 SkScalar textRatio, |
| 592 const SkPaint& origPaint) { | 621 const SkPaint& origPaint) { |
| 593 | 622 |
| 594 SkASSERT(byteLength == 0 || text != nullptr); | 623 SkASSERT(byteLength == 0 || text != nullptr); |
| 595 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); | 624 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); |
| 596 | 625 |
| 597 // nothing to draw | 626 // nothing to draw |
| 598 if (text == nullptr || byteLength == 0) { | 627 if (text == nullptr || byteLength == 0) { |
| 599 return; | 628 return; |
| 600 } | 629 } |
| 601 | 630 |
| 602 SkTDArray<char> fallbackTxt; | 631 SkTDArray<char> fallbackTxt; |
| 603 SkTDArray<SkScalar> fallbackPos; | 632 SkTDArray<SkScalar> fallbackPos; |
| 604 | 633 |
| 605 fCurrStrike = nullptr; | 634 fCurrStrike = nullptr; |
| 606 | 635 |
| 607 SkGlyphCache* cache = blob->setupCache(runIndex, fSurfaceProps, skPaint, nul
lptr, true); | |
| 608 SkDrawCacheProc glyphCacheProc = skPaint.getDrawCacheProc(); | 636 SkDrawCacheProc glyphCacheProc = skPaint.getDrawCacheProc(); |
| 609 GrFontScaler* fontScaler = GetGrFontScaler(cache); | 637 GrFontScaler* fontScaler = GetGrFontScaler(cache); |
| 610 | 638 |
| 611 const char* stop = text + byteLength; | 639 const char* stop = text + byteLength; |
| 612 | 640 |
| 613 if (SkPaint::kLeft_Align == skPaint.getTextAlign()) { | 641 if (SkPaint::kLeft_Align == skPaint.getTextAlign()) { |
| 614 while (text < stop) { | 642 while (text < stop) { |
| 615 const char* lastText = text; | 643 const char* lastText = text; |
| 616 // the last 2 parameters are ignored | 644 // the last 2 parameters are ignored |
| 617 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); | 645 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 *fallbackPos.append() = pos[0]; | 690 *fallbackPos.append() = pos[0]; |
| 663 if (2 == scalarsPerPosition) { | 691 if (2 == scalarsPerPosition) { |
| 664 *fallbackPos.append() = pos[1]; | 692 *fallbackPos.append() = pos[1]; |
| 665 } | 693 } |
| 666 } | 694 } |
| 667 } | 695 } |
| 668 pos += scalarsPerPosition; | 696 pos += scalarsPerPosition; |
| 669 } | 697 } |
| 670 } | 698 } |
| 671 | 699 |
| 672 SkGlyphCache::AttachCache(cache); | |
| 673 if (fallbackTxt.count()) { | 700 if (fallbackTxt.count()) { |
| 674 this->fallbackDrawPosText(blob, runIndex, origPaint.getColor(), origPain
t, viewMatrix, | 701 this->fallbackDrawPosText(blob, runIndex, origPaint.getColor(), origPain
t, viewMatrix, |
| 675 fallbackTxt, fallbackPos, scalarsPerPosition,
offset); | 702 fallbackTxt, fallbackPos, scalarsPerPosition,
offset); |
| 676 } | 703 } |
| 677 } | 704 } |
| 678 | 705 |
| 679 bool GrAtlasTextContext::dfAppendGlyph(GrAtlasTextBlob* blob, int runIndex, | 706 bool GrAtlasTextContext::dfAppendGlyph(GrAtlasTextBlob* blob, int runIndex, |
| 680 const SkGlyph& skGlyph, | 707 const SkGlyph& skGlyph, |
| 681 SkScalar sx, SkScalar sy, GrColor color, | 708 SkScalar sx, SkScalar sy, GrColor color, |
| 682 GrFontScaler* scaler, | 709 GrFontScaler* scaler, |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 765 | 792 |
| 766 SkScalar transX = static_cast<SkScalar>(random->nextU()); | 793 SkScalar transX = static_cast<SkScalar>(random->nextU()); |
| 767 SkScalar transY = static_cast<SkScalar>(random->nextU()); | 794 SkScalar transY = static_cast<SkScalar>(random->nextU()); |
| 768 const GrAtlasTextBlob::Run::SubRunInfo& info = blob->fRuns[0].fSubRunInfo[0]
; | 795 const GrAtlasTextBlob::Run::SubRunInfo& info = blob->fRuns[0].fSubRunInfo[0]
; |
| 769 return blob->createBatch(info, textLen, 0, 0, color, transX, transY, skPaint
, | 796 return blob->createBatch(info, textLen, 0, 0, color, transX, transY, skPaint
, |
| 770 gSurfaceProps, gTextContext->dfAdjustTable(), | 797 gSurfaceProps, gTextContext->dfAdjustTable(), |
| 771 context->getBatchFontCache()); | 798 context->getBatchFontCache()); |
| 772 } | 799 } |
| 773 | 800 |
| 774 #endif | 801 #endif |
| OLD | NEW |