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 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
284 | 284 |
285 if (this->canDrawAsDistanceFields(runPaint, viewMatrix)) { | 285 if (this->canDrawAsDistanceFields(runPaint, viewMatrix)) { |
286 cacheBlob->setHasDistanceField(); | 286 cacheBlob->setHasDistanceField(); |
287 SkPaint dfPaint = runPaint; | 287 SkPaint dfPaint = runPaint; |
288 SkScalar textRatio; | 288 SkScalar textRatio; |
289 this->initDistanceFieldPaint(cacheBlob, &dfPaint, &textRatio, viewMa trix); | 289 this->initDistanceFieldPaint(cacheBlob, &dfPaint, &textRatio, viewMa trix); |
290 Run& runIdx = cacheBlob->fRuns[run]; | 290 Run& runIdx = cacheBlob->fRuns[run]; |
291 PerSubRunInfo& subRun = runIdx.fSubRunInfo.back(); | 291 PerSubRunInfo& subRun = runIdx.fSubRunInfo.back(); |
292 subRun.setUseLCDText(runPaint.isLCDRenderText()); | 292 subRun.setUseLCDText(runPaint.isLCDRenderText()); |
293 subRun.setDrawAsDistanceFields(); | 293 subRun.setDrawAsDistanceFields(); |
294 SkGlyphCache* cache = this->setupCache(&cacheBlob->fRuns[run], dfPai nt, nullptr, true); | |
294 | 295 |
295 SkTDArray<char> fallbackTxt; | |
296 SkTDArray<SkScalar> fallbackPos; | |
297 SkPoint dfOffset; | |
298 int scalarsPerPosition = 2; | |
299 switch (it.positioning()) { | 296 switch (it.positioning()) { |
300 case SkTextBlob::kDefault_Positioning: { | 297 case SkTextBlob::kDefault_Positioning: { |
301 this->internalDrawDFText(cacheBlob, run, dfPaint, color, vie wMatrix, | 298 this->internalDrawDFText(cacheBlob, run, cache, dfPaint, col or, viewMatrix, |
302 (const char *)it.glyphs(), textLen, | 299 (const char *)it.glyphs(), textLen, |
303 x + offset.x(), y + offset.y(), tex tRatio, | 300 x + offset.x(), y + offset.y(), tex tRatio, runPaint); |
304 &fallbackTxt, &fallbackPos, &dfOffs et, runPaint); | |
305 break; | 301 break; |
306 } | 302 } |
307 case SkTextBlob::kHorizontal_Positioning: { | 303 case SkTextBlob::kHorizontal_Positioning: { |
308 scalarsPerPosition = 1; | 304 SkPoint dfOffset = SkPoint::Make(x, y + offset.y()); |
309 dfOffset = SkPoint::Make(x, y + offset.y()); | 305 this->internalDrawDFPosText(cacheBlob, run, cache, dfPaint, color, viewMatrix, |
310 this->internalDrawDFPosText(cacheBlob, run, dfPaint, color, viewMatrix, | |
311 (const char*)it.glyphs(), textLe n, it.pos(), | 306 (const char*)it.glyphs(), textLe n, it.pos(), |
312 scalarsPerPosition, dfOffset, te xtRatio, | 307 1, dfOffset, textRatio, |
313 &fallbackTxt, &fallbackPos); | 308 runPaint); |
314 break; | 309 break; |
315 } | 310 } |
316 case SkTextBlob::kFull_Positioning: { | 311 case SkTextBlob::kFull_Positioning: { |
317 dfOffset = SkPoint::Make(x, y); | 312 SkPoint dfOffset = SkPoint::Make(x, y); |
318 this->internalDrawDFPosText(cacheBlob, run, dfPaint, color, viewMatrix, | 313 this->internalDrawDFPosText(cacheBlob, run, cache, dfPaint, color, viewMatrix, |
319 (const char*)it.glyphs(), textLe n, it.pos(), | 314 (const char*)it.glyphs(), textLe n, it.pos(), |
320 scalarsPerPosition, dfOffset, te xtRatio, | 315 2, dfOffset, textRatio, runPaint ); |
321 &fallbackTxt, &fallbackPos); | |
322 break; | 316 break; |
323 } | 317 } |
324 } | 318 } |
325 if (fallbackTxt.count()) { | 319 SkGlyphCache::AttachCache(cache); |
326 this->fallbackDrawPosText(cacheBlob, run, clip, color, runPaint, viewMatrix, | |
327 fallbackTxt, fallbackPos, scalarsPerPo sition, dfOffset); | |
328 } | |
329 } else if (SkDraw::ShouldDrawTextAsPaths(runPaint, viewMatrix)) { | 320 } else if (SkDraw::ShouldDrawTextAsPaths(runPaint, viewMatrix)) { |
330 cacheBlob->fRuns[run].fDrawAsPaths = true; | 321 cacheBlob->fRuns[run].fDrawAsPaths = true; |
331 } else { | 322 } else { |
332 cacheBlob->setHasBitmap(); | 323 cacheBlob->setHasBitmap(); |
333 SkGlyphCache* cache = this->setupCache(&cacheBlob->fRuns[run], runPa int, &viewMatrix, | 324 SkGlyphCache* cache = this->setupCache(&cacheBlob->fRuns[run], runPa int, &viewMatrix, |
334 false); | 325 false); |
335 switch (it.positioning()) { | 326 switch (it.positioning()) { |
336 case SkTextBlob::kDefault_Positioning: | 327 case SkTextBlob::kDefault_Positioning: |
337 GrTextUtils::DrawBmpText(cacheBlob, run, fContext->getBatchF ontCache(), | 328 GrTextUtils::DrawBmpText(cacheBlob, run, fContext->getBatchF ontCache(), |
338 cache, runPaint, color, viewMatrix, | 329 cache, runPaint, color, viewMatrix, |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
411 blob->fMinMaxScale = SkMinScalar(dfMaskScaleCeil / scaledTextSize, blob->fMi nMaxScale); | 402 blob->fMinMaxScale = SkMinScalar(dfMaskScaleCeil / scaledTextSize, blob->fMi nMaxScale); |
412 | 403 |
413 skPaint->setLCDRenderText(false); | 404 skPaint->setLCDRenderText(false); |
414 skPaint->setAutohinted(false); | 405 skPaint->setAutohinted(false); |
415 skPaint->setHinting(SkPaint::kNormal_Hinting); | 406 skPaint->setHinting(SkPaint::kNormal_Hinting); |
416 skPaint->setSubpixelText(true); | 407 skPaint->setSubpixelText(true); |
417 } | 408 } |
418 | 409 |
419 inline void GrAtlasTextContext::fallbackDrawPosText(GrAtlasTextBlob* blob, | 410 inline void GrAtlasTextContext::fallbackDrawPosText(GrAtlasTextBlob* blob, |
420 int runIndex, | 411 int runIndex, |
421 const GrClip& clip, | |
422 GrColor color, | 412 GrColor color, |
423 const SkPaint& skPaint, | 413 const SkPaint& skPaint, |
424 const SkMatrix& viewMatrix, | 414 const SkMatrix& viewMatrix, |
425 const SkTDArray<char>& fallb ackTxt, | 415 const SkTDArray<char>& fallb ackTxt, |
426 const SkTDArray<SkScalar>& f allbackPos, | 416 const SkTDArray<SkScalar>& f allbackPos, |
427 int scalarsPerPosition, | 417 int scalarsPerPosition, |
428 const SkPoint& offset) { | 418 const SkPoint& offset) { |
429 SkASSERT(fallbackTxt.count()); | 419 SkASSERT(fallbackTxt.count()); |
430 blob->setHasBitmap(); | 420 blob->setHasBitmap(); |
431 Run& run = blob->fRuns[runIndex]; | 421 Run& run = blob->fRuns[runIndex]; |
(...skipping 21 matching lines...) Expand all Loading... | |
453 blob->fViewMatrix = viewMatrix; | 443 blob->fViewMatrix = viewMatrix; |
454 Run& run = blob->fRuns[0]; | 444 Run& run = blob->fRuns[0]; |
455 PerSubRunInfo& subRun = run.fSubRunInfo.back(); | 445 PerSubRunInfo& subRun = run.fSubRunInfo.back(); |
456 subRun.setUseLCDText(origPaint.isLCDRenderText()); | 446 subRun.setUseLCDText(origPaint.isLCDRenderText()); |
457 subRun.setDrawAsDistanceFields(); | 447 subRun.setDrawAsDistanceFields(); |
458 | 448 |
459 return blob; | 449 return blob; |
460 } | 450 } |
461 | 451 |
462 inline GrAtlasTextBlob* | 452 inline GrAtlasTextBlob* |
463 GrAtlasTextContext::createDrawTextBlob(const GrClip& clip, | 453 GrAtlasTextContext::createDrawTextBlob(const GrPaint& paint, const SkPaint& skPa int, |
464 const GrPaint& paint, const SkPaint& skPa int, | |
465 const SkMatrix& viewMatrix, | 454 const SkMatrix& viewMatrix, |
466 const char text[], size_t byteLength, | 455 const char text[], size_t byteLength, |
467 SkScalar x, SkScalar y, const SkIRect& re gionClipBounds) { | 456 SkScalar x, SkScalar y) { |
468 int glyphCount = skPaint.countText(text, byteLength); | 457 int glyphCount = skPaint.countText(text, byteLength); |
469 | 458 |
470 GrAtlasTextBlob* blob; | 459 GrAtlasTextBlob* blob; |
471 if (this->canDrawAsDistanceFields(skPaint, viewMatrix)) { | 460 if (this->canDrawAsDistanceFields(skPaint, viewMatrix)) { |
472 SkPaint dfPaint; | 461 SkPaint dfPaint; |
473 SkScalar textRatio; | 462 SkScalar textRatio; |
474 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); | |
475 | 465 |
476 SkTDArray<char> fallbackTxt; | 466 this->internalDrawDFText(blob, 0, cache, dfPaint, paint.getColor(), view Matrix, text, |
477 SkTDArray<SkScalar> fallbackPos; | 467 byteLength, x, y, textRatio, skPaint); |
478 SkPoint offset; | 468 SkGlyphCache::AttachCache(cache); |
479 this->internalDrawDFText(blob, 0, dfPaint, paint.getColor(), viewMatrix, text, | |
480 byteLength, x, y, textRatio, &fallbackTxt, &fal lbackPos, | |
481 &offset, skPaint); | |
482 if (fallbackTxt.count()) { | |
483 this->fallbackDrawPosText(blob, 0, clip, paint.getColor(), skPaint, viewMatrix, | |
484 fallbackTxt, fallbackPos, 2, offset); | |
485 } | |
486 } else { | 469 } else { |
487 blob = fCache->createBlob(glyphCount, 1, GrAtlasTextBlob::kGrayTextVASiz e); | 470 blob = fCache->createBlob(glyphCount, 1, GrAtlasTextBlob::kGrayTextVASiz e); |
488 blob->fViewMatrix = viewMatrix; | 471 blob->fViewMatrix = viewMatrix; |
489 | 472 |
490 SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], skPaint, &viewMa trix, false); | 473 SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], skPaint, &viewMa trix, false); |
491 GrTextUtils::DrawBmpText(blob, 0, fContext->getBatchFontCache(), cache, skPaint, | 474 GrTextUtils::DrawBmpText(blob, 0, fContext->getBatchFontCache(), cache, skPaint, |
492 paint.getColor(), viewMatrix, text, byteLength, x, y); | 475 paint.getColor(), viewMatrix, text, byteLength, x, y); |
493 SkGlyphCache::AttachCache(cache); | 476 SkGlyphCache::AttachCache(cache); |
494 } | 477 } |
495 return blob; | 478 return blob; |
496 } | 479 } |
497 | 480 |
498 inline GrAtlasTextBlob* | 481 inline GrAtlasTextBlob* |
499 GrAtlasTextContext::createDrawPosTextBlob(const GrClip& clip, | 482 GrAtlasTextContext::createDrawPosTextBlob(const GrPaint& paint, const SkPaint& s kPaint, |
500 const GrPaint& paint, const SkPaint& s kPaint, | |
501 const SkMatrix& viewMatrix, | 483 const SkMatrix& viewMatrix, |
502 const char text[], size_t byteLength, | 484 const char text[], size_t byteLength, |
503 const SkScalar pos[], int scalarsPerPo sition, | 485 const SkScalar pos[], int scalarsPerPo sition, |
504 const SkPoint& offset, const SkIRect& regionClipBounds) { | 486 const SkPoint& offset) { |
505 int glyphCount = skPaint.countText(text, byteLength); | 487 int glyphCount = skPaint.countText(text, byteLength); |
506 | 488 |
507 GrAtlasTextBlob* blob; | 489 GrAtlasTextBlob* blob; |
508 if (this->canDrawAsDistanceFields(skPaint, viewMatrix)) { | 490 if (this->canDrawAsDistanceFields(skPaint, viewMatrix)) { |
509 SkPaint dfPaint; | 491 SkPaint dfPaint; |
510 SkScalar textRatio; | 492 SkScalar textRatio; |
511 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); | |
512 | 495 |
513 SkTDArray<char> fallbackTxt; | 496 this->internalDrawDFPosText(blob, 0, cache, dfPaint, paint.getColor(), v iewMatrix, text, |
514 SkTDArray<SkScalar> fallbackPos; | 497 byteLength, pos, scalarsPerPosition, offset, textRatio, |
515 this->internalDrawDFPosText(blob, 0, dfPaint, paint.getColor(), viewMatr ix, text, | 498 skPaint); |
516 byteLength, pos, scalarsPerPosition, offset, | 499 SkGlyphCache::AttachCache(cache); |
517 textRatio, &fallbackTxt, &fallbackPos); | |
518 if (fallbackTxt.count()) { | |
519 this->fallbackDrawPosText(blob, 0, clip, paint.getColor(), skPaint, viewMatrix, | |
520 fallbackTxt, fallbackPos, scalarsPerPositi on, offset); | |
521 } | |
522 } else { | 500 } else { |
523 blob = fCache->createBlob(glyphCount, 1, GrAtlasTextBlob::kGrayTextVASiz e); | 501 blob = fCache->createBlob(glyphCount, 1, GrAtlasTextBlob::kGrayTextVASiz e); |
524 blob->fViewMatrix = viewMatrix; | 502 blob->fViewMatrix = viewMatrix; |
525 SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], skPaint, &viewMa trix, false); | 503 SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], skPaint, &viewMa trix, false); |
526 GrTextUtils::DrawBmpPosText(blob, 0, fContext->getBatchFontCache(), cach e, skPaint, | 504 GrTextUtils::DrawBmpPosText(blob, 0, fContext->getBatchFontCache(), cach e, skPaint, |
527 paint.getColor(), viewMatrix, text, | 505 paint.getColor(), viewMatrix, text, |
528 byteLength, pos, scalarsPerPosition, offset) ; | 506 byteLength, pos, scalarsPerPosition, offset) ; |
529 SkGlyphCache::AttachCache(cache); | 507 SkGlyphCache::AttachCache(cache); |
530 } | 508 } |
531 return blob; | 509 return blob; |
532 } | 510 } |
533 | 511 |
534 void GrAtlasTextContext::onDrawText(GrDrawContext* dc, | 512 void GrAtlasTextContext::onDrawText(GrDrawContext* dc, |
535 const GrClip& clip, | 513 const GrClip& clip, |
536 const GrPaint& paint, const SkPaint& skPaint , | 514 const GrPaint& paint, const SkPaint& skPaint , |
537 const SkMatrix& viewMatrix, | 515 const SkMatrix& viewMatrix, |
538 const char text[], size_t byteLength, | 516 const char text[], size_t byteLength, |
539 SkScalar x, SkScalar y, const SkIRect& regio nClipBounds) { | 517 SkScalar x, SkScalar y, const SkIRect& regio nClipBounds) { |
540 SkAutoTUnref<GrAtlasTextBlob> blob( | 518 SkAutoTUnref<GrAtlasTextBlob> blob( |
541 this->createDrawTextBlob(clip, paint, skPaint, viewMatrix, | 519 this->createDrawTextBlob(paint, skPaint, viewMatrix, text, byteLength, x , y)); |
542 text, byteLength, x, y, regionClipBounds)); | |
543 blob->flushThrowaway(fContext, dc, fSurfaceProps, fDistanceAdjustTable, skPa int, paint, | 520 blob->flushThrowaway(fContext, dc, fSurfaceProps, fDistanceAdjustTable, skPa int, paint, |
544 clip, regionClipBounds); | 521 clip, regionClipBounds); |
545 } | 522 } |
546 | 523 |
547 void GrAtlasTextContext::onDrawPosText(GrDrawContext* dc, | 524 void GrAtlasTextContext::onDrawPosText(GrDrawContext* dc, |
548 const GrClip& clip, | 525 const GrClip& clip, |
549 const GrPaint& paint, const SkPaint& skPa int, | 526 const GrPaint& paint, const SkPaint& skPa int, |
550 const SkMatrix& viewMatrix, | 527 const SkMatrix& viewMatrix, |
551 const char text[], size_t byteLength, | 528 const char text[], size_t byteLength, |
552 const SkScalar pos[], int scalarsPerPosit ion, | 529 const SkScalar pos[], int scalarsPerPosit ion, |
553 const SkPoint& offset, const SkIRect& reg ionClipBounds) { | 530 const SkPoint& offset, const SkIRect& reg ionClipBounds) { |
554 SkAutoTUnref<GrAtlasTextBlob> blob( | 531 SkAutoTUnref<GrAtlasTextBlob> blob( |
555 this->createDrawPosTextBlob(clip, paint, skPaint, viewMatrix, | 532 this->createDrawPosTextBlob(paint, skPaint, viewMatrix, |
556 text, byteLength, | 533 text, byteLength, |
557 pos, scalarsPerPosition, | 534 pos, scalarsPerPosition, |
558 offset, regionClipBounds)); | 535 offset)); |
559 | 536 |
560 blob->flushThrowaway(fContext, dc, fSurfaceProps, fDistanceAdjustTable, skPa int, paint, clip, | 537 blob->flushThrowaway(fContext, dc, fSurfaceProps, fDistanceAdjustTable, skPa int, paint, clip, |
561 regionClipBounds); | 538 regionClipBounds); |
562 } | 539 } |
563 | 540 |
564 void GrAtlasTextContext::internalDrawDFText(GrAtlasTextBlob* blob, int runIndex, | 541 void GrAtlasTextContext::internalDrawDFText(GrAtlasTextBlob* blob, int runIndex, |
542 SkGlyphCache* cache, | |
565 const SkPaint& skPaint, GrColor colo r, | 543 const SkPaint& skPaint, GrColor colo r, |
566 const SkMatrix& viewMatrix, | 544 const SkMatrix& viewMatrix, |
567 const char text[], size_t byteLength , | 545 const char text[], size_t byteLength , |
568 SkScalar x, SkScalar y, | 546 SkScalar x, SkScalar y, |
569 SkScalar textRatio, | 547 SkScalar textRatio, |
570 SkTDArray<char>* fallbackTxt, | |
571 SkTDArray<SkScalar>* fallbackPos, | |
572 SkPoint* offset, | |
573 const SkPaint& origPaint) { | 548 const SkPaint& origPaint) { |
574 SkASSERT(byteLength == 0 || text != nullptr); | 549 SkASSERT(byteLength == 0 || text != nullptr); |
575 | 550 |
576 // nothing to draw | 551 // nothing to draw |
577 if (text == nullptr || byteLength == 0) { | 552 if (text == nullptr || byteLength == 0) { |
578 return; | 553 return; |
579 } | 554 } |
580 | 555 |
581 SkDrawCacheProc glyphCacheProc = origPaint.getDrawCacheProc(); | 556 SkDrawCacheProc glyphCacheProc = origPaint.getDrawCacheProc(); |
582 SkAutoDescriptor desc; | 557 SkAutoDescriptor desc; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
621 SkScalar alignY = SkFixedToScalar(stopY); | 596 SkScalar alignY = SkFixedToScalar(stopY); |
622 if (origPaint.getTextAlign() == SkPaint::kCenter_Align) { | 597 if (origPaint.getTextAlign() == SkPaint::kCenter_Align) { |
623 alignX = SkScalarHalf(alignX); | 598 alignX = SkScalarHalf(alignX); |
624 alignY = SkScalarHalf(alignY); | 599 alignY = SkScalarHalf(alignY); |
625 } else if (origPaint.getTextAlign() == SkPaint::kLeft_Align) { | 600 } else if (origPaint.getTextAlign() == SkPaint::kLeft_Align) { |
626 alignX = 0; | 601 alignX = 0; |
627 alignY = 0; | 602 alignY = 0; |
628 } | 603 } |
629 x -= alignX; | 604 x -= alignX; |
630 y -= alignY; | 605 y -= alignY; |
631 *offset = SkPoint::Make(x, y); | 606 SkPoint offset = SkPoint::Make(x, y); |
632 | 607 |
633 this->internalDrawDFPosText(blob, runIndex, skPaint, color, viewMatrix, text , byteLength, | 608 this->internalDrawDFPosText(blob, runIndex, cache, skPaint, color, viewMatri x, text, byteLength, |
634 positions.begin(), 2, *offset, textRatio, fallba ckTxt, | 609 positions.begin(), 2, offset, textRatio, origPai nt); |
635 fallbackPos); | |
636 } | 610 } |
637 | 611 |
638 void GrAtlasTextContext::internalDrawDFPosText(GrAtlasTextBlob* blob, int runInd ex, | 612 void GrAtlasTextContext::internalDrawDFPosText(GrAtlasTextBlob* blob, int runInd ex, |
639 const SkPaint& skPaint, GrColor c olor, | 613 SkGlyphCache* cache, |
614 const SkPaint& skPaint, | |
615 GrColor color, | |
640 const SkMatrix& viewMatrix, | 616 const SkMatrix& viewMatrix, |
641 const char text[], size_t byteLen gth, | 617 const char text[], size_t byteLen gth, |
642 const SkScalar pos[], int scalars PerPosition, | 618 const SkScalar pos[], int scalars PerPosition, |
643 const SkPoint& offset, | 619 const SkPoint& offset, |
644 SkScalar textRatio, | 620 SkScalar textRatio, |
645 SkTDArray<char>* fallbackTxt, | 621 const SkPaint& origPaint) { |
646 SkTDArray<SkScalar>* fallbackPos) { | |
647 | 622 |
648 SkASSERT(byteLength == 0 || text != nullptr); | 623 SkASSERT(byteLength == 0 || text != nullptr); |
649 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); | 624 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); |
650 | 625 |
651 // nothing to draw | 626 // nothing to draw |
652 if (text == nullptr || byteLength == 0) { | 627 if (text == nullptr || byteLength == 0) { |
653 return; | 628 return; |
654 } | 629 } |
655 | 630 |
631 SkTDArray<char> fallbackTxt; | |
632 SkTDArray<SkScalar> fallbackPos; | |
633 | |
656 fCurrStrike = nullptr; | 634 fCurrStrike = nullptr; |
657 | 635 |
658 SkDrawCacheProc glyphCacheProc = skPaint.getDrawCacheProc(); | 636 SkDrawCacheProc glyphCacheProc = skPaint.getDrawCacheProc(); |
659 SkGlyphCache* cache = this->setupCache(&blob->fRuns[runIndex], skPaint, null ptr, true); | |
660 GrFontScaler* fontScaler = GetGrFontScaler(cache); | 637 GrFontScaler* fontScaler = GetGrFontScaler(cache); |
661 | 638 |
662 const char* stop = text + byteLength; | 639 const char* stop = text + byteLength; |
663 | 640 |
664 if (SkPaint::kLeft_Align == skPaint.getTextAlign()) { | 641 if (SkPaint::kLeft_Align == skPaint.getTextAlign()) { |
665 while (text < stop) { | 642 while (text < stop) { |
666 const char* lastText = text; | 643 const char* lastText = text; |
667 // the last 2 parameters are ignored | 644 // the last 2 parameters are ignored |
668 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); | 645 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); |
669 | 646 |
670 if (glyph.fWidth) { | 647 if (glyph.fWidth) { |
671 SkScalar x = offset.x() + pos[0]; | 648 SkScalar x = offset.x() + pos[0]; |
672 SkScalar y = offset.y() + (2 == scalarsPerPosition ? pos[1] : 0) ; | 649 SkScalar y = offset.y() + (2 == scalarsPerPosition ? pos[1] : 0) ; |
673 | 650 |
674 if (!this->dfAppendGlyph(blob, | 651 if (!this->dfAppendGlyph(blob, |
675 runIndex, | 652 runIndex, |
676 glyph, | 653 glyph, |
677 x, y, color, fontScaler, | 654 x, y, color, fontScaler, |
678 textRatio, viewMatrix)) { | 655 textRatio, viewMatrix)) { |
679 // couldn't append, send to fallback | 656 // couldn't append, send to fallback |
680 fallbackTxt->append(SkToInt(text-lastText), lastText); | 657 fallbackTxt.append(SkToInt(text-lastText), lastText); |
681 *fallbackPos->append() = pos[0]; | 658 *fallbackPos.append() = pos[0]; |
682 if (2 == scalarsPerPosition) { | 659 if (2 == scalarsPerPosition) { |
683 *fallbackPos->append() = pos[1]; | 660 *fallbackPos.append() = pos[1]; |
684 } | 661 } |
685 } | 662 } |
686 } | 663 } |
687 pos += scalarsPerPosition; | 664 pos += scalarsPerPosition; |
688 } | 665 } |
689 } else { | 666 } else { |
690 SkScalar alignMul = SkPaint::kCenter_Align == skPaint.getTextAlign() ? S K_ScalarHalf | 667 SkScalar alignMul = SkPaint::kCenter_Align == skPaint.getTextAlign() ? S K_ScalarHalf |
691 : S K_Scalar1; | 668 : S K_Scalar1; |
692 while (text < stop) { | 669 while (text < stop) { |
693 const char* lastText = text; | 670 const char* lastText = text; |
694 // the last 2 parameters are ignored | 671 // the last 2 parameters are ignored |
695 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); | 672 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); |
696 | 673 |
697 if (glyph.fWidth) { | 674 if (glyph.fWidth) { |
698 SkScalar x = offset.x() + pos[0]; | 675 SkScalar x = offset.x() + pos[0]; |
699 SkScalar y = offset.y() + (2 == scalarsPerPosition ? pos[1] : 0) ; | 676 SkScalar y = offset.y() + (2 == scalarsPerPosition ? pos[1] : 0) ; |
700 | 677 |
701 SkScalar advanceX = SkFixedToScalar(glyph.fAdvanceX) * alignMul * textRatio; | 678 SkScalar advanceX = SkFixedToScalar(glyph.fAdvanceX) * alignMul * textRatio; |
702 SkScalar advanceY = SkFixedToScalar(glyph.fAdvanceY) * alignMul * textRatio; | 679 SkScalar advanceY = SkFixedToScalar(glyph.fAdvanceY) * alignMul * textRatio; |
703 | 680 |
704 if (!this->dfAppendGlyph(blob, | 681 if (!this->dfAppendGlyph(blob, |
705 runIndex, | 682 runIndex, |
706 glyph, | 683 glyph, |
707 x - advanceX, y - advanceY, color, | 684 x - advanceX, y - advanceY, color, |
708 fontScaler, | 685 fontScaler, |
709 textRatio, | 686 textRatio, |
710 viewMatrix)) { | 687 viewMatrix)) { |
711 // couldn't append, send to fallback | 688 // couldn't append, send to fallback |
712 fallbackTxt->append(SkToInt(text-lastText), lastText); | 689 fallbackTxt.append(SkToInt(text-lastText), lastText); |
713 *fallbackPos->append() = pos[0]; | 690 *fallbackPos.append() = pos[0]; |
714 if (2 == scalarsPerPosition) { | 691 if (2 == scalarsPerPosition) { |
715 *fallbackPos->append() = pos[1]; | 692 *fallbackPos.append() = pos[1]; |
716 } | 693 } |
717 } | 694 } |
718 } | 695 } |
719 pos += scalarsPerPosition; | 696 pos += scalarsPerPosition; |
720 } | 697 } |
721 } | 698 } |
722 | 699 |
723 SkGlyphCache::AttachCache(cache); | 700 if (fallbackTxt.count()) { |
jvanverth1
2015/12/11 18:12:57
+1. This makes a lot more sense than passing it ou
| |
701 this->fallbackDrawPosText(blob, runIndex, origPaint.getColor(), origPain t, viewMatrix, | |
702 fallbackTxt, fallbackPos, scalarsPerPosition, offset); | |
703 } | |
724 } | 704 } |
725 | 705 |
726 bool GrAtlasTextContext::dfAppendGlyph(GrAtlasTextBlob* blob, int runIndex, | 706 bool GrAtlasTextContext::dfAppendGlyph(GrAtlasTextBlob* blob, int runIndex, |
727 const SkGlyph& skGlyph, | 707 const SkGlyph& skGlyph, |
728 SkScalar sx, SkScalar sy, GrColor color, | 708 SkScalar sx, SkScalar sy, GrColor color, |
729 GrFontScaler* scaler, | 709 GrFontScaler* scaler, |
730 SkScalar textRatio, const SkMatrix& viewM atrix) { | 710 SkScalar textRatio, const SkMatrix& viewM atrix) { |
731 if (!fCurrStrike) { | 711 if (!fCurrStrike) { |
732 fCurrStrike = fContext->getBatchFontCache()->getStrike(scaler); | 712 fCurrStrike = fContext->getBatchFontCache()->getStrike(scaler); |
733 } | 713 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
796 GrPaint grPaint; | 776 GrPaint grPaint; |
797 if (!SkPaintToGrPaint(context, skPaint, viewMatrix, &grPaint)) { | 777 if (!SkPaintToGrPaint(context, skPaint, viewMatrix, &grPaint)) { |
798 SkFAIL("couldn't convert paint\n"); | 778 SkFAIL("couldn't convert paint\n"); |
799 } | 779 } |
800 | 780 |
801 const char* text = "The quick brown fox jumps over the lazy dog."; | 781 const char* text = "The quick brown fox jumps over the lazy dog."; |
802 int textLen = (int)strlen(text); | 782 int textLen = (int)strlen(text); |
803 | 783 |
804 // Setup clip | 784 // Setup clip |
805 GrClip clip; | 785 GrClip clip; |
806 SkIRect noClip = SkIRect::MakeLargest(); | |
807 | 786 |
808 // right now we don't handle textblobs, nor do we handle drawPosText. Since we only | 787 // right now we don't handle textblobs, nor do we handle drawPosText. Since we only |
809 // intend to test the batch with this unit test, that is okay. | 788 // intend to test the batch with this unit test, that is okay. |
810 SkAutoTUnref<GrAtlasTextBlob> blob( | 789 SkAutoTUnref<GrAtlasTextBlob> blob( |
811 gTextContext->createDrawTextBlob(clip, grPaint, skPaint, viewMatrix, text, | 790 gTextContext->createDrawTextBlob(grPaint, skPaint, viewMatrix, text, |
812 static_cast<size_t>(textLen), 0, 0, noClip)); | 791 static_cast<size_t>(textLen), 0, 0) ); |
813 | 792 |
814 SkScalar transX = static_cast<SkScalar>(random->nextU()); | 793 SkScalar transX = static_cast<SkScalar>(random->nextU()); |
815 SkScalar transY = static_cast<SkScalar>(random->nextU()); | 794 SkScalar transY = static_cast<SkScalar>(random->nextU()); |
816 const GrAtlasTextBlob::Run::SubRunInfo& info = blob->fRuns[0].fSubRunInfo[0] ; | 795 const GrAtlasTextBlob::Run::SubRunInfo& info = blob->fRuns[0].fSubRunInfo[0] ; |
817 return blob->createBatch(info, textLen, 0, 0, color, transX, transY, skPaint , | 796 return blob->createBatch(info, textLen, 0, 0, color, transX, transY, skPaint , |
818 gSurfaceProps, gTextContext->dfAdjustTable(), | 797 gSurfaceProps, gTextContext->dfAdjustTable(), |
819 context->getBatchFontCache()); | 798 context->getBatchFontCache()); |
820 } | 799 } |
821 | 800 |
822 #endif | 801 #endif |
OLD | NEW |