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 "GrBatch.h" | 9 #include "GrBatch.h" |
10 #include "GrBatchFontCache.h" | 10 #include "GrBatchFontCache.h" |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 SkTextBlob::RunIterator it(blob); | 237 SkTextBlob::RunIterator it(blob); |
238 for (; !it.done(); it.next()) { | 238 for (; !it.done(); it.next()) { |
239 if (it.isLCD()) { | 239 if (it.isLCD()) { |
240 return true; | 240 return true; |
241 } | 241 } |
242 } | 242 } |
243 return false; | 243 return false; |
244 } | 244 } |
245 | 245 |
246 bool GrAtlasTextContext::MustRegenerateBlob(SkScalar* outTransX, SkScalar* outTr
ansY, | 246 bool GrAtlasTextContext::MustRegenerateBlob(SkScalar* outTransX, SkScalar* outTr
ansY, |
247 const BitmapTextBlob& blob, const Sk
Paint& paint, | 247 const GrAtlasTextBlob& blob, const S
kPaint& paint, |
248 const SkMaskFilter::BlurRec& blurRec
, | 248 const SkMaskFilter::BlurRec& blurRec
, |
249 const SkMatrix& viewMatrix, SkScalar
x, SkScalar y) { | 249 const SkMatrix& viewMatrix, SkScalar
x, SkScalar y) { |
250 // If we have LCD text then our canonical color will be set to transparent,
in this case we have | 250 // If we have LCD text then our canonical color will be set to transparent,
in this case we have |
251 // to regenerate the blob on any color change | 251 // to regenerate the blob on any color change |
252 if (blob.fKey.fCanonicalColor == SK_ColorTRANSPARENT && blob.fPaintColor !=
paint.getColor()) { | 252 if (blob.fKey.fCanonicalColor == SK_ColorTRANSPARENT && blob.fPaintColor !=
paint.getColor()) { |
253 return true; | 253 return true; |
254 } | 254 } |
255 | 255 |
256 if (blob.fViewMatrix.hasPerspective() != viewMatrix.hasPerspective()) { | 256 if (blob.fViewMatrix.hasPerspective() != viewMatrix.hasPerspective()) { |
257 return true; | 257 return true; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 SkScalar newMaxScale = viewMatrix.getMaxScale(); | 319 SkScalar newMaxScale = viewMatrix.getMaxScale(); |
320 SkScalar oldMaxScale = blob.fViewMatrix.getMaxScale(); | 320 SkScalar oldMaxScale = blob.fViewMatrix.getMaxScale(); |
321 SkScalar scaleAdjust = newMaxScale / oldMaxScale; | 321 SkScalar scaleAdjust = newMaxScale / oldMaxScale; |
322 if (scaleAdjust < blob.fMaxMinScale || scaleAdjust > blob.fMinMaxScale)
{ | 322 if (scaleAdjust < blob.fMaxMinScale || scaleAdjust > blob.fMinMaxScale)
{ |
323 return true; | 323 return true; |
324 } | 324 } |
325 | 325 |
326 (*outTransX) = x - blob.fX; | 326 (*outTransX) = x - blob.fX; |
327 (*outTransY) = y - blob.fY; | 327 (*outTransY) = y - blob.fY; |
328 } | 328 } |
| 329 |
329 // It is possible that a blob has neither distanceField nor bitmaptext. Thi
s is in the case | 330 // It is possible that a blob has neither distanceField nor bitmaptext. Thi
s is in the case |
330 // when all of the runs inside the blob are drawn as paths. In this case, w
e always regenerate | 331 // when all of the runs inside the blob are drawn as paths. In this case, w
e always regenerate |
331 // the blob anyways at flush time, so no need to regenerate explicitly | 332 // the blob anyways at flush time, so no need to regenerate explicitly |
332 | |
333 return false; | 333 return false; |
334 } | 334 } |
335 | 335 |
336 | 336 |
337 inline SkGlyphCache* GrAtlasTextContext::setupCache(BitmapTextBlob::Run* run, | 337 inline SkGlyphCache* GrAtlasTextContext::setupCache(GrAtlasTextBlob::Run* run, |
338 const SkPaint& skPaint, | 338 const SkPaint& skPaint, |
339 const SkMatrix* viewMatrix, | 339 const SkMatrix* viewMatrix, |
340 bool noGamma) { | 340 bool noGamma) { |
341 skPaint.getScalerContextDescriptor(&run->fDescriptor, fSurfaceProps, viewMat
rix, noGamma); | 341 skPaint.getScalerContextDescriptor(&run->fDescriptor, fSurfaceProps, viewMat
rix, noGamma); |
342 run->fTypeface.reset(SkSafeRef(skPaint.getTypeface())); | 342 run->fTypeface.reset(SkSafeRef(skPaint.getTypeface())); |
343 return SkGlyphCache::DetachCache(run->fTypeface, run->fDescriptor.getDesc())
; | 343 return SkGlyphCache::DetachCache(run->fTypeface, run->fDescriptor.getDesc())
; |
344 } | 344 } |
345 | 345 |
346 void GrAtlasTextContext::drawTextBlob(GrRenderTarget* rt, | 346 void GrAtlasTextContext::drawTextBlob(GrRenderTarget* rt, |
347 const GrClip& clip, const SkPaint& skPaint
, | 347 const GrClip& clip, const SkPaint& skPaint
, |
348 const SkMatrix& viewMatrix, const SkTextBl
ob* blob, | 348 const SkMatrix& viewMatrix, const SkTextBl
ob* blob, |
349 SkScalar x, SkScalar y, | 349 SkScalar x, SkScalar y, |
350 SkDrawFilter* drawFilter, const SkIRect& c
lipBounds) { | 350 SkDrawFilter* drawFilter, const SkIRect& c
lipBounds) { |
351 // If we have been abandoned, then don't draw | 351 // If we have been abandoned, then don't draw |
352 if (fContext->abandoned()) { | 352 if (fContext->abandoned()) { |
353 return; | 353 return; |
354 } | 354 } |
355 | 355 |
356 SkAutoTUnref<BitmapTextBlob> cacheBlob; | 356 SkAutoTUnref<GrAtlasTextBlob> cacheBlob; |
357 SkMaskFilter::BlurRec blurRec; | 357 SkMaskFilter::BlurRec blurRec; |
358 BitmapTextBlob::Key key; | 358 GrAtlasTextBlob::Key key; |
359 // It might be worth caching these things, but its not clear at this time | 359 // It might be worth caching these things, but its not clear at this time |
360 // TODO for animated mask filters, this will fill up our cache. We need a s
afeguard here | 360 // TODO for animated mask filters, this will fill up our cache. We need a s
afeguard here |
361 const SkMaskFilter* mf = skPaint.getMaskFilter(); | 361 const SkMaskFilter* mf = skPaint.getMaskFilter(); |
362 bool canCache = !(skPaint.getPathEffect() || | 362 bool canCache = !(skPaint.getPathEffect() || |
363 (mf && !mf->asABlur(&blurRec)) || | 363 (mf && !mf->asABlur(&blurRec)) || |
364 drawFilter); | 364 drawFilter); |
365 | 365 |
366 if (canCache) { | 366 if (canCache) { |
367 bool hasLCD = HasLCD(blob); | 367 bool hasLCD = HasLCD(blob); |
368 | 368 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 } | 463 } |
464 | 464 |
465 // TODO: add some stroking support | 465 // TODO: add some stroking support |
466 if (skPaint.getStyle() != SkPaint::kFill_Style) { | 466 if (skPaint.getStyle() != SkPaint::kFill_Style) { |
467 return false; | 467 return false; |
468 } | 468 } |
469 | 469 |
470 return true; | 470 return true; |
471 } | 471 } |
472 | 472 |
473 void GrAtlasTextContext::regenerateTextBlob(BitmapTextBlob* cacheBlob, | 473 void GrAtlasTextContext::regenerateTextBlob(GrAtlasTextBlob* cacheBlob, |
474 const SkPaint& skPaint, GrColor colo
r, | 474 const SkPaint& skPaint, GrColor colo
r, |
475 const SkMatrix& viewMatrix, | 475 const SkMatrix& viewMatrix, |
476 const SkTextBlob* blob, SkScalar x,
SkScalar y, | 476 const SkTextBlob* blob, SkScalar x,
SkScalar y, |
477 SkDrawFilter* drawFilter, const SkIR
ect& clipRect, | 477 SkDrawFilter* drawFilter, const SkIR
ect& clipRect, |
478 GrRenderTarget* rt, const GrClip& cl
ip, | 478 GrRenderTarget* rt, const GrClip& cl
ip, |
479 const GrPaint& paint) { | 479 const GrPaint& paint) { |
480 cacheBlob->fViewMatrix = viewMatrix; | 480 cacheBlob->fViewMatrix = viewMatrix; |
481 cacheBlob->fX = x; | 481 cacheBlob->fX = x; |
482 cacheBlob->fY = y; | 482 cacheBlob->fY = y; |
483 | 483 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 SkGlyphCache::AttachCache(cache); | 587 SkGlyphCache::AttachCache(cache); |
588 } | 588 } |
589 | 589 |
590 if (drawFilter) { | 590 if (drawFilter) { |
591 // A draw filter may change the paint arbitrarily, so we must re-see
d in this case. | 591 // A draw filter may change the paint arbitrarily, so we must re-see
d in this case. |
592 runPaint = skPaint; | 592 runPaint = skPaint; |
593 } | 593 } |
594 } | 594 } |
595 } | 595 } |
596 | 596 |
597 inline void GrAtlasTextContext::initDistanceFieldPaint(BitmapTextBlob* blob, | 597 inline void GrAtlasTextContext::initDistanceFieldPaint(GrAtlasTextBlob* blob, |
598 SkPaint* skPaint, | 598 SkPaint* skPaint, |
599 SkScalar* textRatio, | 599 SkScalar* textRatio, |
600 const SkMatrix& viewMatri
x) { | 600 const SkMatrix& viewMatri
x) { |
601 // getMaxScale doesn't support perspective, so neither do we at the moment | 601 // getMaxScale doesn't support perspective, so neither do we at the moment |
602 SkASSERT(!viewMatrix.hasPerspective()); | 602 SkASSERT(!viewMatrix.hasPerspective()); |
603 SkScalar maxScale = viewMatrix.getMaxScale(); | 603 SkScalar maxScale = viewMatrix.getMaxScale(); |
604 SkScalar textSize = skPaint->getTextSize(); | 604 SkScalar textSize = skPaint->getTextSize(); |
605 SkScalar scaledTextSize = textSize; | 605 SkScalar scaledTextSize = textSize; |
606 // if we have non-unity scale, we need to choose our base text size | 606 // if we have non-unity scale, we need to choose our base text size |
607 // based on the SkPaint's text size multiplied by the max scale factor | 607 // based on the SkPaint's text size multiplied by the max scale factor |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 SkASSERT(dfMaskScaleFloor <= scaledTextSize && scaledTextSize <= dfMaskScale
Ceil); | 641 SkASSERT(dfMaskScaleFloor <= scaledTextSize && scaledTextSize <= dfMaskScale
Ceil); |
642 blob->fMaxMinScale = SkMaxScalar(dfMaskScaleFloor / scaledTextSize, blob->fM
axMinScale); | 642 blob->fMaxMinScale = SkMaxScalar(dfMaskScaleFloor / scaledTextSize, blob->fM
axMinScale); |
643 blob->fMinMaxScale = SkMinScalar(dfMaskScaleCeil / scaledTextSize, blob->fMi
nMaxScale); | 643 blob->fMinMaxScale = SkMinScalar(dfMaskScaleCeil / scaledTextSize, blob->fMi
nMaxScale); |
644 | 644 |
645 skPaint->setLCDRenderText(false); | 645 skPaint->setLCDRenderText(false); |
646 skPaint->setAutohinted(false); | 646 skPaint->setAutohinted(false); |
647 skPaint->setHinting(SkPaint::kNormal_Hinting); | 647 skPaint->setHinting(SkPaint::kNormal_Hinting); |
648 skPaint->setSubpixelText(true); | 648 skPaint->setSubpixelText(true); |
649 } | 649 } |
650 | 650 |
651 inline void GrAtlasTextContext::fallbackDrawPosText(BitmapTextBlob* blob, | 651 inline void GrAtlasTextContext::fallbackDrawPosText(GrAtlasTextBlob* blob, |
652 int runIndex, | 652 int runIndex, |
653 GrRenderTarget* rt, const Gr
Clip& clip, | 653 GrRenderTarget* rt, const Gr
Clip& clip, |
654 const GrPaint& paint, | 654 const GrPaint& paint, |
655 const SkPaint& skPaint, | 655 const SkPaint& skPaint, |
656 const SkMatrix& viewMatrix, | 656 const SkMatrix& viewMatrix, |
657 const SkTDArray<char>& fallb
ackTxt, | 657 const SkTDArray<char>& fallb
ackTxt, |
658 const SkTDArray<SkScalar>& f
allbackPos, | 658 const SkTDArray<SkScalar>& f
allbackPos, |
659 int scalarsPerPosition, | 659 int scalarsPerPosition, |
660 const SkPoint& offset, | 660 const SkPoint& offset, |
661 const SkIRect& clipRect) { | 661 const SkIRect& clipRect) { |
662 SkASSERT(fallbackTxt.count()); | 662 SkASSERT(fallbackTxt.count()); |
663 blob->setHasBitmap(); | 663 blob->setHasBitmap(); |
664 Run& run = blob->fRuns[runIndex]; | 664 Run& run = blob->fRuns[runIndex]; |
665 // Push back a new subrun to fill and set the override descriptor | 665 // Push back a new subrun to fill and set the override descriptor |
666 run.push_back(); | 666 run.push_back(); |
667 run.fOverrideDescriptor.reset(SkNEW(SkAutoDescriptor)); | 667 run.fOverrideDescriptor.reset(SkNEW(SkAutoDescriptor)); |
668 skPaint.getScalerContextDescriptor(run.fOverrideDescriptor, | 668 skPaint.getScalerContextDescriptor(run.fOverrideDescriptor, |
669 fSurfaceProps, &viewMatrix, false); | 669 fSurfaceProps, &viewMatrix, false); |
670 SkGlyphCache* cache = SkGlyphCache::DetachCache(run.fTypeface, | 670 SkGlyphCache* cache = SkGlyphCache::DetachCache(run.fTypeface, |
671 run.fOverrideDescriptor->get
Desc()); | 671 run.fOverrideDescriptor->get
Desc()); |
672 this->internalDrawBMPPosText(blob, runIndex, cache, skPaint, paint.getColor(
), viewMatrix, | 672 this->internalDrawBMPPosText(blob, runIndex, cache, skPaint, paint.getColor(
), viewMatrix, |
673 fallbackTxt.begin(), fallbackTxt.count(), | 673 fallbackTxt.begin(), fallbackTxt.count(), |
674 fallbackPos.begin(), scalarsPerPosition, offset
, clipRect); | 674 fallbackPos.begin(), scalarsPerPosition, offset
, clipRect); |
675 SkGlyphCache::AttachCache(cache); | 675 SkGlyphCache::AttachCache(cache); |
676 } | 676 } |
677 | 677 |
678 inline GrAtlasTextContext::BitmapTextBlob* | 678 inline GrAtlasTextBlob* |
679 GrAtlasTextContext::setupDFBlob(int glyphCount, const SkPaint& origPaint, | 679 GrAtlasTextContext::setupDFBlob(int glyphCount, const SkPaint& origPaint, |
680 const SkMatrix& viewMatrix, SkGlyphCache** cache
, | 680 const SkMatrix& viewMatrix, SkGlyphCache** cache
, |
681 SkPaint* dfPaint, SkScalar* textRatio) { | 681 SkPaint* dfPaint, SkScalar* textRatio) { |
682 BitmapTextBlob* blob = fCache->createBlob(glyphCount, 1, kGrayTextVASize); | 682 GrAtlasTextBlob* blob = fCache->createBlob(glyphCount, 1, kGrayTextVASize); |
683 | 683 |
684 *dfPaint = origPaint; | 684 *dfPaint = origPaint; |
685 this->initDistanceFieldPaint(blob, dfPaint, textRatio, viewMatrix); | 685 this->initDistanceFieldPaint(blob, dfPaint, textRatio, viewMatrix); |
686 blob->fViewMatrix = viewMatrix; | 686 blob->fViewMatrix = viewMatrix; |
687 Run& run = blob->fRuns[0]; | 687 Run& run = blob->fRuns[0]; |
688 PerSubRunInfo& subRun = run.fSubRunInfo.back(); | 688 PerSubRunInfo& subRun = run.fSubRunInfo.back(); |
689 subRun.fUseLCDText = origPaint.isLCDRenderText(); | 689 subRun.fUseLCDText = origPaint.isLCDRenderText(); |
690 subRun.fDrawAsDistanceFields = true; | 690 subRun.fDrawAsDistanceFields = true; |
691 | 691 |
692 *cache = this->setupCache(&blob->fRuns[0], *dfPaint, NULL, true); | 692 *cache = this->setupCache(&blob->fRuns[0], *dfPaint, NULL, true); |
693 return blob; | 693 return blob; |
694 } | 694 } |
695 | 695 |
696 inline GrAtlasTextContext::BitmapTextBlob* | 696 inline GrAtlasTextBlob* |
697 GrAtlasTextContext::createDrawTextBlob(GrRenderTarget* rt, const GrClip& clip, | 697 GrAtlasTextContext::createDrawTextBlob(GrRenderTarget* rt, const GrClip& clip, |
698 const GrPaint& paint, const SkPaint& skPa
int, | 698 const GrPaint& paint, const SkPaint& skPa
int, |
699 const SkMatrix& viewMatrix, | 699 const SkMatrix& viewMatrix, |
700 const char text[], size_t byteLength, | 700 const char text[], size_t byteLength, |
701 SkScalar x, SkScalar y, const SkIRect& re
gionClipBounds) { | 701 SkScalar x, SkScalar y, const SkIRect& re
gionClipBounds) { |
702 int glyphCount = skPaint.countText(text, byteLength); | 702 int glyphCount = skPaint.countText(text, byteLength); |
703 SkIRect clipRect; | 703 SkIRect clipRect; |
704 clip.getConservativeBounds(rt->width(), rt->height(), &clipRect); | 704 clip.getConservativeBounds(rt->width(), rt->height(), &clipRect); |
705 | 705 |
706 BitmapTextBlob* blob; | 706 GrAtlasTextBlob* blob; |
707 if (this->canDrawAsDistanceFields(skPaint, viewMatrix)) { | 707 if (this->canDrawAsDistanceFields(skPaint, viewMatrix)) { |
708 SkPaint dfPaint; | 708 SkPaint dfPaint; |
709 SkScalar textRatio; | 709 SkScalar textRatio; |
710 SkGlyphCache* cache; | 710 SkGlyphCache* cache; |
711 blob = this->setupDFBlob(glyphCount, skPaint, viewMatrix, &cache, &dfPai
nt, &textRatio); | 711 blob = this->setupDFBlob(glyphCount, skPaint, viewMatrix, &cache, &dfPai
nt, &textRatio); |
712 | 712 |
713 SkTDArray<char> fallbackTxt; | 713 SkTDArray<char> fallbackTxt; |
714 SkTDArray<SkScalar> fallbackPos; | 714 SkTDArray<SkScalar> fallbackPos; |
715 SkPoint offset; | 715 SkPoint offset; |
716 this->internalDrawDFText(blob, 0, cache, dfPaint, paint.getColor(), view
Matrix, text, | 716 this->internalDrawDFText(blob, 0, cache, dfPaint, paint.getColor(), view
Matrix, text, |
717 byteLength, x, y, clipRect, textRatio, &fallbac
kTxt, &fallbackPos, | 717 byteLength, x, y, clipRect, textRatio, &fallbac
kTxt, &fallbackPos, |
718 &offset, skPaint); | 718 &offset, skPaint); |
719 SkGlyphCache::AttachCache(cache); | 719 SkGlyphCache::AttachCache(cache); |
720 if (fallbackTxt.count()) { | 720 if (fallbackTxt.count()) { |
721 this->fallbackDrawPosText(blob, 0, rt, clip, paint, skPaint, viewMat
rix, fallbackTxt, | 721 this->fallbackDrawPosText(blob, 0, rt, clip, paint, skPaint, viewMat
rix, fallbackTxt, |
722 fallbackPos, 2, offset, clipRect); | 722 fallbackPos, 2, offset, clipRect); |
723 } | 723 } |
724 } else { | 724 } else { |
725 blob = fCache->createBlob(glyphCount, 1, kGrayTextVASize); | 725 blob = fCache->createBlob(glyphCount, 1, kGrayTextVASize); |
726 blob->fViewMatrix = viewMatrix; | 726 blob->fViewMatrix = viewMatrix; |
727 | 727 |
728 SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], skPaint, &viewMa
trix, false); | 728 SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], skPaint, &viewMa
trix, false); |
729 this->internalDrawBMPText(blob, 0, cache, skPaint, paint.getColor(), vie
wMatrix, text, | 729 this->internalDrawBMPText(blob, 0, cache, skPaint, paint.getColor(), vie
wMatrix, text, |
730 byteLength, x, y, clipRect); | 730 byteLength, x, y, clipRect); |
731 SkGlyphCache::AttachCache(cache); | 731 SkGlyphCache::AttachCache(cache); |
732 } | 732 } |
733 return blob; | 733 return blob; |
734 } | 734 } |
735 | 735 |
736 inline GrAtlasTextContext::BitmapTextBlob* | 736 inline GrAtlasTextBlob* |
737 GrAtlasTextContext::createDrawPosTextBlob(GrRenderTarget* rt, const GrClip& clip
, | 737 GrAtlasTextContext::createDrawPosTextBlob(GrRenderTarget* rt, const GrClip& clip
, |
738 const GrPaint& paint, const SkPaint& s
kPaint, | 738 const GrPaint& paint, const SkPaint& s
kPaint, |
739 const SkMatrix& viewMatrix, | 739 const SkMatrix& viewMatrix, |
740 const char text[], size_t byteLength, | 740 const char text[], size_t byteLength, |
741 const SkScalar pos[], int scalarsPerPo
sition, | 741 const SkScalar pos[], int scalarsPerPo
sition, |
742 const SkPoint& offset, const SkIRect&
regionClipBounds) { | 742 const SkPoint& offset, const SkIRect&
regionClipBounds) { |
743 int glyphCount = skPaint.countText(text, byteLength); | 743 int glyphCount = skPaint.countText(text, byteLength); |
744 | 744 |
745 SkIRect clipRect; | 745 SkIRect clipRect; |
746 clip.getConservativeBounds(rt->width(), rt->height(), &clipRect); | 746 clip.getConservativeBounds(rt->width(), rt->height(), &clipRect); |
747 | 747 |
748 BitmapTextBlob* blob; | 748 GrAtlasTextBlob* blob; |
749 if (this->canDrawAsDistanceFields(skPaint, viewMatrix)) { | 749 if (this->canDrawAsDistanceFields(skPaint, viewMatrix)) { |
750 SkPaint dfPaint; | 750 SkPaint dfPaint; |
751 SkScalar textRatio; | 751 SkScalar textRatio; |
752 SkGlyphCache* cache; | 752 SkGlyphCache* cache; |
753 blob = this->setupDFBlob(glyphCount, skPaint, viewMatrix, &cache, &dfPai
nt, &textRatio); | 753 blob = this->setupDFBlob(glyphCount, skPaint, viewMatrix, &cache, &dfPai
nt, &textRatio); |
754 | 754 |
755 SkTDArray<char> fallbackTxt; | 755 SkTDArray<char> fallbackTxt; |
756 SkTDArray<SkScalar> fallbackPos; | 756 SkTDArray<SkScalar> fallbackPos; |
757 this->internalDrawDFPosText(blob, 0, cache, dfPaint, paint.getColor(), v
iewMatrix, text, | 757 this->internalDrawDFPosText(blob, 0, cache, dfPaint, paint.getColor(), v
iewMatrix, text, |
758 byteLength, pos, scalarsPerPosition, offset,
clipRect, | 758 byteLength, pos, scalarsPerPosition, offset,
clipRect, |
(...skipping 13 matching lines...) Expand all Loading... |
772 } | 772 } |
773 return blob; | 773 return blob; |
774 } | 774 } |
775 | 775 |
776 void GrAtlasTextContext::onDrawText(GrRenderTarget* rt, | 776 void GrAtlasTextContext::onDrawText(GrRenderTarget* rt, |
777 const GrClip& clip, | 777 const GrClip& clip, |
778 const GrPaint& paint, const SkPaint& skPaint
, | 778 const GrPaint& paint, const SkPaint& skPaint
, |
779 const SkMatrix& viewMatrix, | 779 const SkMatrix& viewMatrix, |
780 const char text[], size_t byteLength, | 780 const char text[], size_t byteLength, |
781 SkScalar x, SkScalar y, const SkIRect& regio
nClipBounds) { | 781 SkScalar x, SkScalar y, const SkIRect& regio
nClipBounds) { |
782 SkAutoTUnref<BitmapTextBlob> blob( | 782 SkAutoTUnref<GrAtlasTextBlob> blob( |
783 this->createDrawTextBlob(rt, clip, paint, skPaint, viewMatrix, | 783 this->createDrawTextBlob(rt, clip, paint, skPaint, viewMatrix, |
784 text, byteLength, x, y, regionClipBounds)); | 784 text, byteLength, x, y, regionClipBounds)); |
785 this->flush(blob, rt, skPaint, paint, clip, regionClipBounds); | 785 this->flush(blob, rt, skPaint, paint, clip, regionClipBounds); |
786 } | 786 } |
787 | 787 |
788 void GrAtlasTextContext::onDrawPosText(GrRenderTarget* rt, | 788 void GrAtlasTextContext::onDrawPosText(GrRenderTarget* rt, |
789 const GrClip& clip, | 789 const GrClip& clip, |
790 const GrPaint& paint, const SkPaint& skPa
int, | 790 const GrPaint& paint, const SkPaint& skPa
int, |
791 const SkMatrix& viewMatrix, | 791 const SkMatrix& viewMatrix, |
792 const char text[], size_t byteLength, | 792 const char text[], size_t byteLength, |
793 const SkScalar pos[], int scalarsPerPosit
ion, | 793 const SkScalar pos[], int scalarsPerPosit
ion, |
794 const SkPoint& offset, const SkIRect& reg
ionClipBounds) { | 794 const SkPoint& offset, const SkIRect& reg
ionClipBounds) { |
795 SkAutoTUnref<BitmapTextBlob> blob( | 795 SkAutoTUnref<GrAtlasTextBlob> blob( |
796 this->createDrawPosTextBlob(rt, clip, paint, skPaint, viewMatrix, | 796 this->createDrawPosTextBlob(rt, clip, paint, skPaint, viewMatrix, |
797 text, byteLength, | 797 text, byteLength, |
798 pos, scalarsPerPosition, | 798 pos, scalarsPerPosition, |
799 offset, regionClipBounds)); | 799 offset, regionClipBounds)); |
800 | 800 |
801 this->flush(blob, rt, skPaint, paint, clip, regionClipBounds); | 801 this->flush(blob, rt, skPaint, paint, clip, regionClipBounds); |
802 } | 802 } |
803 | 803 |
804 void GrAtlasTextContext::internalDrawBMPText(BitmapTextBlob* blob, int runIndex, | 804 void GrAtlasTextContext::internalDrawBMPText(GrAtlasTextBlob* blob, int runIndex
, |
805 SkGlyphCache* cache, const SkPaint&
skPaint, | 805 SkGlyphCache* cache, const SkPaint&
skPaint, |
806 GrColor color, | 806 GrColor color, |
807 const SkMatrix& viewMatrix, | 807 const SkMatrix& viewMatrix, |
808 const char text[], size_t byteLengt
h, | 808 const char text[], size_t byteLengt
h, |
809 SkScalar x, SkScalar y, const SkIRe
ct& clipRect) { | 809 SkScalar x, SkScalar y, const SkIRe
ct& clipRect) { |
810 SkASSERT(byteLength == 0 || text != NULL); | 810 SkASSERT(byteLength == 0 || text != NULL); |
811 | 811 |
812 // nothing to draw | 812 // nothing to draw |
813 if (text == NULL || byteLength == 0) { | 813 if (text == NULL || byteLength == 0) { |
814 return; | 814 return; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
885 color, | 885 color, |
886 fontScaler, | 886 fontScaler, |
887 clipRect); | 887 clipRect); |
888 } | 888 } |
889 | 889 |
890 fx += glyph.fAdvanceX; | 890 fx += glyph.fAdvanceX; |
891 fy += glyph.fAdvanceY; | 891 fy += glyph.fAdvanceY; |
892 } | 892 } |
893 } | 893 } |
894 | 894 |
895 void GrAtlasTextContext::internalDrawBMPPosText(BitmapTextBlob* blob, int runInd
ex, | 895 void GrAtlasTextContext::internalDrawBMPPosText(GrAtlasTextBlob* blob, int runIn
dex, |
896 SkGlyphCache* cache, const SkPai
nt& skPaint, | 896 SkGlyphCache* cache, const SkPai
nt& skPaint, |
897 GrColor color, | 897 GrColor color, |
898 const SkMatrix& viewMatrix, | 898 const SkMatrix& viewMatrix, |
899 const char text[], size_t byteLe
ngth, | 899 const char text[], size_t byteLe
ngth, |
900 const SkScalar pos[], int scalar
sPerPosition, | 900 const SkScalar pos[], int scalar
sPerPosition, |
901 const SkPoint& offset, const SkI
Rect& clipRect) { | 901 const SkPoint& offset, const SkI
Rect& clipRect) { |
902 SkASSERT(byteLength == 0 || text != NULL); | 902 SkASSERT(byteLength == 0 || text != NULL); |
903 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); | 903 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); |
904 | 904 |
905 // nothing to draw | 905 // nothing to draw |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1050 fontScaler, | 1050 fontScaler, |
1051 clipRect); | 1051 clipRect); |
1052 } | 1052 } |
1053 pos += scalarsPerPosition; | 1053 pos += scalarsPerPosition; |
1054 } | 1054 } |
1055 } | 1055 } |
1056 } | 1056 } |
1057 } | 1057 } |
1058 | 1058 |
1059 | 1059 |
1060 void GrAtlasTextContext::internalDrawDFText(BitmapTextBlob* blob, int runIndex, | 1060 void GrAtlasTextContext::internalDrawDFText(GrAtlasTextBlob* blob, int runIndex, |
1061 SkGlyphCache* cache, const SkPaint&
skPaint, | 1061 SkGlyphCache* cache, const SkPaint&
skPaint, |
1062 GrColor color, | 1062 GrColor color, |
1063 const SkMatrix& viewMatrix, | 1063 const SkMatrix& viewMatrix, |
1064 const char text[], size_t byteLength
, | 1064 const char text[], size_t byteLength
, |
1065 SkScalar x, SkScalar y, const SkIRec
t& clipRect, | 1065 SkScalar x, SkScalar y, const SkIRec
t& clipRect, |
1066 SkScalar textRatio, | 1066 SkScalar textRatio, |
1067 SkTDArray<char>* fallbackTxt, | 1067 SkTDArray<char>* fallbackTxt, |
1068 SkTDArray<SkScalar>* fallbackPos, | 1068 SkTDArray<SkScalar>* fallbackPos, |
1069 SkPoint* offset, | 1069 SkPoint* offset, |
1070 const SkPaint& origPaint) { | 1070 const SkPaint& origPaint) { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1124 x -= alignX; | 1124 x -= alignX; |
1125 y -= alignY; | 1125 y -= alignY; |
1126 *offset = SkPoint::Make(x, y); | 1126 *offset = SkPoint::Make(x, y); |
1127 | 1127 |
1128 this->internalDrawDFPosText(blob, runIndex, cache, skPaint, color, viewMatri
x, text, byteLength, | 1128 this->internalDrawDFPosText(blob, runIndex, cache, skPaint, color, viewMatri
x, text, byteLength, |
1129 positions.begin(), 2, *offset, clipRect, textRat
io, fallbackTxt, | 1129 positions.begin(), 2, *offset, clipRect, textRat
io, fallbackTxt, |
1130 fallbackPos); | 1130 fallbackPos); |
1131 SkGlyphCache::AttachCache(origPaintCache); | 1131 SkGlyphCache::AttachCache(origPaintCache); |
1132 } | 1132 } |
1133 | 1133 |
1134 void GrAtlasTextContext::internalDrawDFPosText(BitmapTextBlob* blob, int runInde
x, | 1134 void GrAtlasTextContext::internalDrawDFPosText(GrAtlasTextBlob* blob, int runInd
ex, |
1135 SkGlyphCache* cache, const SkPain
t& skPaint, | 1135 SkGlyphCache* cache, const SkPain
t& skPaint, |
1136 GrColor color, | 1136 GrColor color, |
1137 const SkMatrix& viewMatrix, | 1137 const SkMatrix& viewMatrix, |
1138 const char text[], size_t byteLen
gth, | 1138 const char text[], size_t byteLen
gth, |
1139 const SkScalar pos[], int scalars
PerPosition, | 1139 const SkScalar pos[], int scalars
PerPosition, |
1140 const SkPoint& offset, const SkIR
ect& clipRect, | 1140 const SkPoint& offset, const SkIR
ect& clipRect, |
1141 SkScalar textRatio, | 1141 SkScalar textRatio, |
1142 SkTDArray<char>* fallbackTxt, | 1142 SkTDArray<char>* fallbackTxt, |
1143 SkTDArray<SkScalar>* fallbackPos)
{ | 1143 SkTDArray<SkScalar>* fallbackPos)
{ |
1144 | 1144 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1217 if (2 == scalarsPerPosition) { | 1217 if (2 == scalarsPerPosition) { |
1218 *fallbackPos->append() = pos[1]; | 1218 *fallbackPos->append() = pos[1]; |
1219 } | 1219 } |
1220 } | 1220 } |
1221 } | 1221 } |
1222 pos += scalarsPerPosition; | 1222 pos += scalarsPerPosition; |
1223 } | 1223 } |
1224 } | 1224 } |
1225 } | 1225 } |
1226 | 1226 |
1227 void GrAtlasTextContext::bmpAppendGlyph(BitmapTextBlob* blob, int runIndex, | 1227 void GrAtlasTextContext::bmpAppendGlyph(GrAtlasTextBlob* blob, int runIndex, |
1228 GrGlyph::PackedID packed, | 1228 GrGlyph::PackedID packed, |
1229 int vx, int vy, GrColor color, GrFontSca
ler* scaler, | 1229 int vx, int vy, GrColor color, GrFontSca
ler* scaler, |
1230 const SkIRect& clipRect) { | 1230 const SkIRect& clipRect) { |
1231 Run& run = blob->fRuns[runIndex]; | 1231 Run& run = blob->fRuns[runIndex]; |
1232 if (!fCurrStrike) { | 1232 if (!fCurrStrike) { |
1233 fCurrStrike = fContext->getBatchFontCache()->getStrike(scaler); | 1233 fCurrStrike = fContext->getBatchFontCache()->getStrike(scaler); |
1234 run.fStrike.reset(SkRef(fCurrStrike)); | 1234 run.fStrike.reset(SkRef(fCurrStrike)); |
1235 } | 1235 } |
1236 | 1236 |
1237 GrGlyph* glyph = fCurrStrike->getGlyph(packed, scaler); | 1237 GrGlyph* glyph = fCurrStrike->getGlyph(packed, scaler); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1278 SkRect r; | 1278 SkRect r; |
1279 r.fLeft = SkIntToScalar(x); | 1279 r.fLeft = SkIntToScalar(x); |
1280 r.fTop = SkIntToScalar(y); | 1280 r.fTop = SkIntToScalar(y); |
1281 r.fRight = r.fLeft + SkIntToScalar(width); | 1281 r.fRight = r.fLeft + SkIntToScalar(width); |
1282 r.fBottom = r.fTop + SkIntToScalar(height); | 1282 r.fBottom = r.fTop + SkIntToScalar(height); |
1283 subRun->fMaskFormat = format; | 1283 subRun->fMaskFormat = format; |
1284 this->appendGlyphCommon(blob, &run, subRun, r, color, vertexStride, kA8_GrMa
skFormat == format, | 1284 this->appendGlyphCommon(blob, &run, subRun, r, color, vertexStride, kA8_GrMa
skFormat == format, |
1285 glyph); | 1285 glyph); |
1286 } | 1286 } |
1287 | 1287 |
1288 bool GrAtlasTextContext::dfAppendGlyph(BitmapTextBlob* blob, int runIndex, | 1288 bool GrAtlasTextContext::dfAppendGlyph(GrAtlasTextBlob* blob, int runIndex, |
1289 GrGlyph::PackedID packed, | 1289 GrGlyph::PackedID packed, |
1290 SkScalar sx, SkScalar sy, GrColor color, | 1290 SkScalar sx, SkScalar sy, GrColor color, |
1291 GrFontScaler* scaler, | 1291 GrFontScaler* scaler, |
1292 const SkIRect& clipRect, | 1292 const SkIRect& clipRect, |
1293 SkScalar textRatio, const SkMatrix& viewM
atrix) { | 1293 SkScalar textRatio, const SkMatrix& viewM
atrix) { |
1294 Run& run = blob->fRuns[runIndex]; | 1294 Run& run = blob->fRuns[runIndex]; |
1295 if (!fCurrStrike) { | 1295 if (!fCurrStrike) { |
1296 fCurrStrike = fContext->getBatchFontCache()->getStrike(scaler); | 1296 fCurrStrike = fContext->getBatchFontCache()->getStrike(scaler); |
1297 run.fStrike.reset(SkRef(fCurrStrike)); | 1297 run.fStrike.reset(SkRef(fCurrStrike)); |
1298 } | 1298 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1345 subRun->fMaskFormat = kA8_GrMaskFormat; | 1345 subRun->fMaskFormat = kA8_GrMaskFormat; |
1346 | 1346 |
1347 size_t vertexStride = get_vertex_stride_df(kA8_GrMaskFormat, subRun->fUseLCD
Text); | 1347 size_t vertexStride = get_vertex_stride_df(kA8_GrMaskFormat, subRun->fUseLCD
Text); |
1348 | 1348 |
1349 bool useColorVerts = !subRun->fUseLCDText; | 1349 bool useColorVerts = !subRun->fUseLCDText; |
1350 this->appendGlyphCommon(blob, &run, subRun, glyphRect, color, vertexStride,
useColorVerts, | 1350 this->appendGlyphCommon(blob, &run, subRun, glyphRect, color, vertexStride,
useColorVerts, |
1351 glyph); | 1351 glyph); |
1352 return true; | 1352 return true; |
1353 } | 1353 } |
1354 | 1354 |
1355 inline void GrAtlasTextContext::appendGlyphPath(BitmapTextBlob* blob, GrGlyph* g
lyph, | 1355 inline void GrAtlasTextContext::appendGlyphPath(GrAtlasTextBlob* blob, GrGlyph*
glyph, |
1356 GrFontScaler* scaler, SkScalar x
, SkScalar y) { | 1356 GrFontScaler* scaler, SkScalar x
, SkScalar y) { |
1357 if (NULL == glyph->fPath) { | 1357 if (NULL == glyph->fPath) { |
1358 SkPath* path = SkNEW(SkPath); | 1358 SkPath* path = SkNEW(SkPath); |
1359 if (!scaler->getGlyphPath(glyph->glyphID(), path)) { | 1359 if (!scaler->getGlyphPath(glyph->glyphID(), path)) { |
1360 // flag the glyph as being dead? | 1360 // flag the glyph as being dead? |
1361 SkDELETE(path); | 1361 SkDELETE(path); |
1362 return; | 1362 return; |
1363 } | 1363 } |
1364 glyph->fPath = path; | 1364 glyph->fPath = path; |
1365 } | 1365 } |
1366 SkASSERT(glyph->fPath); | 1366 SkASSERT(glyph->fPath); |
1367 blob->fBigGlyphs.push_back(BitmapTextBlob::BigGlyph(*glyph->fPath, x, y)); | 1367 blob->fBigGlyphs.push_back(GrAtlasTextBlob::BigGlyph(*glyph->fPath, x, y)); |
1368 } | 1368 } |
1369 | 1369 |
1370 inline void GrAtlasTextContext::appendGlyphCommon(BitmapTextBlob* blob, Run* run
, | 1370 inline void GrAtlasTextContext::appendGlyphCommon(GrAtlasTextBlob* blob, Run* ru
n, |
1371 Run::SubRunInfo* subRun, | 1371 Run::SubRunInfo* subRun, |
1372 const SkRect& positions, GrCol
or color, | 1372 const SkRect& positions, GrCol
or color, |
1373 size_t vertexStride, bool useV
ertexColor, | 1373 size_t vertexStride, bool useV
ertexColor, |
1374 GrGlyph* glyph) { | 1374 GrGlyph* glyph) { |
1375 blob->fGlyphs[subRun->fGlyphEndIndex] = glyph; | 1375 blob->fGlyphs[subRun->fGlyphEndIndex] = glyph; |
1376 run->fVertexBounds.joinNonEmptyArg(positions); | 1376 run->fVertexBounds.joinNonEmptyArg(positions); |
1377 run->fColor = color; | 1377 run->fColor = color; |
1378 | 1378 |
1379 intptr_t vertex = reinterpret_cast<intptr_t>(blob->fVertices + subRun->fVert
exEndIndex); | 1379 intptr_t vertex = reinterpret_cast<intptr_t>(blob->fVertices + subRun->fVert
exEndIndex); |
1380 | 1380 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1426 position->set(positions.fRight, positions.fTop); | 1426 position->set(positions.fRight, positions.fTop); |
1427 } | 1427 } |
1428 | 1428 |
1429 subRun->fGlyphEndIndex++; | 1429 subRun->fGlyphEndIndex++; |
1430 subRun->fVertexEndIndex += vertexStride * kVerticesPerGlyph; | 1430 subRun->fVertexEndIndex += vertexStride * kVerticesPerGlyph; |
1431 } | 1431 } |
1432 | 1432 |
1433 class BitmapTextBatch : public GrBatch { | 1433 class BitmapTextBatch : public GrBatch { |
1434 public: | 1434 public: |
1435 typedef GrAtlasTextContext::DistanceAdjustTable DistanceAdjustTable; | 1435 typedef GrAtlasTextContext::DistanceAdjustTable DistanceAdjustTable; |
1436 typedef GrAtlasTextContext::BitmapTextBlob Blob; | 1436 typedef GrAtlasTextBlob Blob; |
1437 typedef Blob::Run Run; | 1437 typedef Blob::Run Run; |
1438 typedef Run::SubRunInfo TextInfo; | 1438 typedef Run::SubRunInfo TextInfo; |
1439 struct Geometry { | 1439 struct Geometry { |
1440 Blob* fBlob; | 1440 Blob* fBlob; |
1441 int fRun; | 1441 int fRun; |
1442 int fSubRun; | 1442 int fSubRun; |
1443 GrColor fColor; | 1443 GrColor fColor; |
1444 SkScalar fTransX; | 1444 SkScalar fTransX; |
1445 SkScalar fTransY; | 1445 SkScalar fTransY; |
1446 }; | 1446 }; |
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2067 case SkTextBlob::kFull_Positioning: | 2067 case SkTextBlob::kFull_Positioning: |
2068 this->drawPosTextAsPath(rt, clip, runPaint, viewMatrix, | 2068 this->drawPosTextAsPath(rt, clip, runPaint, viewMatrix, |
2069 (const char*)it.glyphs(), | 2069 (const char*)it.glyphs(), |
2070 textLen, it.pos(), 2, SkPoint::Make(x, y), c
lipBounds); | 2070 textLen, it.pos(), 2, SkPoint::Make(x, y), c
lipBounds); |
2071 break; | 2071 break; |
2072 } | 2072 } |
2073 } | 2073 } |
2074 | 2074 |
2075 | 2075 |
2076 inline BitmapTextBatch* | 2076 inline BitmapTextBatch* |
2077 GrAtlasTextContext::createBatch(BitmapTextBlob* cacheBlob, const PerSubRunInfo&
info, | 2077 GrAtlasTextContext::createBatch(GrAtlasTextBlob* cacheBlob, const PerSubRunInfo&
info, |
2078 int glyphCount, int run, int subRun, | 2078 int glyphCount, int run, int subRun, |
2079 GrColor color, SkScalar transX, SkScalar transY, | 2079 GrColor color, SkScalar transX, SkScalar transY, |
2080 const SkPaint& skPaint) { | 2080 const SkPaint& skPaint) { |
2081 GrMaskFormat format = info.fMaskFormat; | 2081 GrMaskFormat format = info.fMaskFormat; |
2082 GrColor subRunColor; | 2082 GrColor subRunColor; |
2083 if (kARGB_GrMaskFormat == format) { | 2083 if (kARGB_GrMaskFormat == format) { |
2084 uint8_t paintAlpha = skPaint.getAlpha(); | 2084 uint8_t paintAlpha = skPaint.getAlpha(); |
2085 subRunColor = SkColorSetARGB(paintAlpha, paintAlpha, paintAlpha, paintAl
pha); | 2085 subRunColor = SkColorSetARGB(paintAlpha, paintAlpha, paintAlpha, paintAl
pha); |
2086 } else { | 2086 } else { |
2087 subRunColor = color; | 2087 subRunColor = color; |
(...skipping 21 matching lines...) Expand all Loading... |
2109 geometry.fSubRun = subRun; | 2109 geometry.fSubRun = subRun; |
2110 geometry.fColor = subRunColor; | 2110 geometry.fColor = subRunColor; |
2111 geometry.fTransX = transX; | 2111 geometry.fTransX = transX; |
2112 geometry.fTransY = transY; | 2112 geometry.fTransY = transY; |
2113 batch->init(); | 2113 batch->init(); |
2114 | 2114 |
2115 return batch; | 2115 return batch; |
2116 } | 2116 } |
2117 | 2117 |
2118 inline void GrAtlasTextContext::flushRun(GrPipelineBuilder* pipelineBuilder, | 2118 inline void GrAtlasTextContext::flushRun(GrPipelineBuilder* pipelineBuilder, |
2119 BitmapTextBlob* cacheBlob, int run, GrC
olor color, | 2119 GrAtlasTextBlob* cacheBlob, int run, Gr
Color color, |
2120 SkScalar transX, SkScalar transY, | 2120 SkScalar transX, SkScalar transY, |
2121 const SkPaint& skPaint) { | 2121 const SkPaint& skPaint) { |
2122 for (int subRun = 0; subRun < cacheBlob->fRuns[run].fSubRunInfo.count(); sub
Run++) { | 2122 for (int subRun = 0; subRun < cacheBlob->fRuns[run].fSubRunInfo.count(); sub
Run++) { |
2123 const PerSubRunInfo& info = cacheBlob->fRuns[run].fSubRunInfo[subRun]; | 2123 const PerSubRunInfo& info = cacheBlob->fRuns[run].fSubRunInfo[subRun]; |
2124 int glyphCount = info.fGlyphEndIndex - info.fGlyphStartIndex; | 2124 int glyphCount = info.fGlyphEndIndex - info.fGlyphStartIndex; |
2125 if (0 == glyphCount) { | 2125 if (0 == glyphCount) { |
2126 continue; | 2126 continue; |
2127 } | 2127 } |
2128 | 2128 |
2129 SkAutoTUnref<BitmapTextBatch> batch(this->createBatch(cacheBlob, info, g
lyphCount, run, | 2129 SkAutoTUnref<BitmapTextBatch> batch(this->createBatch(cacheBlob, info, g
lyphCount, run, |
2130 subRun, color, tra
nsX, transY, | 2130 subRun, color, tra
nsX, transY, |
2131 skPaint)); | 2131 skPaint)); |
2132 fDrawContext->drawBatch(pipelineBuilder, batch); | 2132 fDrawContext->drawBatch(pipelineBuilder, batch); |
2133 } | 2133 } |
2134 } | 2134 } |
2135 | 2135 |
2136 inline void GrAtlasTextContext::flushBigGlyphs(BitmapTextBlob* cacheBlob, GrRend
erTarget* rt, | 2136 inline void GrAtlasTextContext::flushBigGlyphs(GrAtlasTextBlob* cacheBlob, GrRen
derTarget* rt, |
2137 const GrClip& clip, const SkPaint
& skPaint, | 2137 const GrClip& clip, const SkPaint
& skPaint, |
2138 SkScalar transX, SkScalar transY, | 2138 SkScalar transX, SkScalar transY, |
2139 const SkIRect& clipBounds) { | 2139 const SkIRect& clipBounds) { |
2140 if (!cacheBlob->fBigGlyphs.count()) { | 2140 if (!cacheBlob->fBigGlyphs.count()) { |
2141 return; | 2141 return; |
2142 } | 2142 } |
2143 | 2143 |
2144 SkMatrix pathMatrix; | 2144 SkMatrix pathMatrix; |
2145 if (!cacheBlob->fViewMatrix.invert(&pathMatrix)) { | 2145 if (!cacheBlob->fViewMatrix.invert(&pathMatrix)) { |
2146 SkDebugf("could not invert viewmatrix\n"); | 2146 SkDebugf("could not invert viewmatrix\n"); |
2147 return; | 2147 return; |
2148 } | 2148 } |
2149 | 2149 |
2150 for (int i = 0; i < cacheBlob->fBigGlyphs.count(); i++) { | 2150 for (int i = 0; i < cacheBlob->fBigGlyphs.count(); i++) { |
2151 BitmapTextBlob::BigGlyph& bigGlyph = cacheBlob->fBigGlyphs[i]; | 2151 GrAtlasTextBlob::BigGlyph& bigGlyph = cacheBlob->fBigGlyphs[i]; |
2152 bigGlyph.fVx += transX; | 2152 bigGlyph.fVx += transX; |
2153 bigGlyph.fVy += transY; | 2153 bigGlyph.fVy += transY; |
2154 SkMatrix translate = cacheBlob->fViewMatrix; | 2154 SkMatrix translate = cacheBlob->fViewMatrix; |
2155 translate.postTranslate(bigGlyph.fVx, bigGlyph.fVy); | 2155 translate.postTranslate(bigGlyph.fVx, bigGlyph.fVy); |
2156 | 2156 |
2157 GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext, rt, clip, bi
gGlyph.fPath, | 2157 GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext, rt, clip, bi
gGlyph.fPath, |
2158 skPaint, translate, &pathMatrix, cli
pBounds, false); | 2158 skPaint, translate, &pathMatrix, cli
pBounds, false); |
2159 } | 2159 } |
2160 } | 2160 } |
2161 | 2161 |
2162 void GrAtlasTextContext::flush(const SkTextBlob* blob, | 2162 void GrAtlasTextContext::flush(const SkTextBlob* blob, |
2163 BitmapTextBlob* cacheBlob, | 2163 GrAtlasTextBlob* cacheBlob, |
2164 GrRenderTarget* rt, | 2164 GrRenderTarget* rt, |
2165 const SkPaint& skPaint, | 2165 const SkPaint& skPaint, |
2166 const GrPaint& grPaint, | 2166 const GrPaint& grPaint, |
2167 SkDrawFilter* drawFilter, | 2167 SkDrawFilter* drawFilter, |
2168 const GrClip& clip, | 2168 const GrClip& clip, |
2169 const SkMatrix& viewMatrix, | 2169 const SkMatrix& viewMatrix, |
2170 const SkIRect& clipBounds, | 2170 const SkIRect& clipBounds, |
2171 SkScalar x, SkScalar y, | 2171 SkScalar x, SkScalar y, |
2172 SkScalar transX, SkScalar transY) { | 2172 SkScalar transX, SkScalar transY) { |
2173 // We loop through the runs of the blob, flushing each. If any run is too l
arge, then we flush | 2173 // We loop through the runs of the blob, flushing each. If any run is too l
arge, then we flush |
(...skipping 11 matching lines...) Expand all Loading... |
2185 } | 2185 } |
2186 cacheBlob->fRuns[run].fVertexBounds.offset(transX, transY); | 2186 cacheBlob->fRuns[run].fVertexBounds.offset(transX, transY); |
2187 this->flushRun(&pipelineBuilder, cacheBlob, run, color, | 2187 this->flushRun(&pipelineBuilder, cacheBlob, run, color, |
2188 transX, transY, skPaint); | 2188 transX, transY, skPaint); |
2189 } | 2189 } |
2190 | 2190 |
2191 // Now flush big glyphs | 2191 // Now flush big glyphs |
2192 this->flushBigGlyphs(cacheBlob, rt, clip, skPaint, transX, transY, clipBound
s); | 2192 this->flushBigGlyphs(cacheBlob, rt, clip, skPaint, transX, transY, clipBound
s); |
2193 } | 2193 } |
2194 | 2194 |
2195 void GrAtlasTextContext::flush(BitmapTextBlob* cacheBlob, | 2195 void GrAtlasTextContext::flush(GrAtlasTextBlob* cacheBlob, |
2196 GrRenderTarget* rt, | 2196 GrRenderTarget* rt, |
2197 const SkPaint& skPaint, | 2197 const SkPaint& skPaint, |
2198 const GrPaint& grPaint, | 2198 const GrPaint& grPaint, |
2199 const GrClip& clip, | 2199 const GrClip& clip, |
2200 const SkIRect& clipBounds) { | 2200 const SkIRect& clipBounds) { |
2201 GrPipelineBuilder pipelineBuilder(grPaint, rt, clip); | 2201 GrPipelineBuilder pipelineBuilder(grPaint, rt, clip); |
2202 | 2202 |
2203 GrColor color = grPaint.getColor(); | 2203 GrColor color = grPaint.getColor(); |
2204 for (int run = 0; run < cacheBlob->fRunCount; run++) { | 2204 for (int run = 0; run < cacheBlob->fRunCount; run++) { |
2205 this->flushRun(&pipelineBuilder, cacheBlob, run, color, 0, 0, skPaint); | 2205 this->flushRun(&pipelineBuilder, cacheBlob, run, color, 0, 0, skPaint); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2258 | 2258 |
2259 const char* text = "The quick brown fox jumps over the lazy dog."; | 2259 const char* text = "The quick brown fox jumps over the lazy dog."; |
2260 int textLen = (int)strlen(text); | 2260 int textLen = (int)strlen(text); |
2261 | 2261 |
2262 // Setup clip | 2262 // Setup clip |
2263 GrClip clip; | 2263 GrClip clip; |
2264 SkIRect noClip = SkIRect::MakeLargest(); | 2264 SkIRect noClip = SkIRect::MakeLargest(); |
2265 | 2265 |
2266 // right now we don't handle textblobs, nor do we handle drawPosText. Since
we only | 2266 // right now we don't handle textblobs, nor do we handle drawPosText. Since
we only |
2267 // intend to test the batch with this unit test, that is okay. | 2267 // intend to test the batch with this unit test, that is okay. |
2268 SkAutoTUnref<GrAtlasTextContext::BitmapTextBlob> blob( | 2268 SkAutoTUnref<GrAtlasTextBlob> blob( |
2269 gTextContext->createDrawTextBlob(rt, clip, grPaint, skPaint, viewMat
rix, text, | 2269 gTextContext->createDrawTextBlob(rt, clip, grPaint, skPaint, viewMat
rix, text, |
2270 static_cast<size_t>(textLen), 0, 0,
noClip)); | 2270 static_cast<size_t>(textLen), 0, 0,
noClip)); |
2271 | 2271 |
2272 SkScalar transX = static_cast<SkScalar>(random->nextU()); | 2272 SkScalar transX = static_cast<SkScalar>(random->nextU()); |
2273 SkScalar transY = static_cast<SkScalar>(random->nextU()); | 2273 SkScalar transY = static_cast<SkScalar>(random->nextU()); |
2274 const GrAtlasTextContext::BitmapTextBlob::Run::SubRunInfo& info = blob->fRun
s[0].fSubRunInfo[0]; | 2274 const GrAtlasTextBlob::Run::SubRunInfo& info = blob->fRuns[0].fSubRunInfo[0]
; |
2275 return gTextContext->createBatch(blob, info, textLen, 0, 0, color, transX, t
ransY, skPaint); | 2275 return gTextContext->createBatch(blob, info, textLen, 0, 0, color, transX, t
ransY, skPaint); |
2276 } | 2276 } |
2277 | 2277 |
2278 #endif | 2278 #endif |
OLD | NEW |