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

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

Issue 1310513008: Detach cache in DF routines rather than passing it in. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/GrAtlasTextContext.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 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 "GrBatchFontCache.h" 9 #include "GrBatchFontCache.h"
10 #include "GrBatchFlushState.h" 10 #include "GrBatchFlushState.h"
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 if (this->canDrawAsDistanceFields(runPaint, viewMatrix)) { 528 if (this->canDrawAsDistanceFields(runPaint, viewMatrix)) {
529 cacheBlob->setHasDistanceField(); 529 cacheBlob->setHasDistanceField();
530 SkPaint dfPaint = runPaint; 530 SkPaint dfPaint = runPaint;
531 SkScalar textRatio; 531 SkScalar textRatio;
532 this->initDistanceFieldPaint(cacheBlob, &dfPaint, &textRatio, viewMa trix); 532 this->initDistanceFieldPaint(cacheBlob, &dfPaint, &textRatio, viewMa trix);
533 Run& runIdx = cacheBlob->fRuns[run]; 533 Run& runIdx = cacheBlob->fRuns[run];
534 PerSubRunInfo& subRun = runIdx.fSubRunInfo.back(); 534 PerSubRunInfo& subRun = runIdx.fSubRunInfo.back();
535 subRun.fUseLCDText = runPaint.isLCDRenderText(); 535 subRun.fUseLCDText = runPaint.isLCDRenderText();
536 subRun.fDrawAsDistanceFields = true; 536 subRun.fDrawAsDistanceFields = true;
537 537
538 SkGlyphCache* cache = this->setupCache(&cacheBlob->fRuns[run], dfPai nt, nullptr, true);
539
540 SkTDArray<char> fallbackTxt; 538 SkTDArray<char> fallbackTxt;
541 SkTDArray<SkScalar> fallbackPos; 539 SkTDArray<SkScalar> fallbackPos;
542 SkPoint dfOffset; 540 SkPoint dfOffset;
543 int scalarsPerPosition = 2; 541 int scalarsPerPosition = 2;
544 switch (it.positioning()) { 542 switch (it.positioning()) {
545 case SkTextBlob::kDefault_Positioning: { 543 case SkTextBlob::kDefault_Positioning: {
546 this->internalDrawDFText(cacheBlob, run, cache, dfPaint, col or, viewMatrix, 544 this->internalDrawDFText(cacheBlob, run, dfPaint, color, vie wMatrix,
547 (const char *)it.glyphs(), textLen, 545 (const char *)it.glyphs(), textLen,
548 x + offset.x(), y + offset.y(), cli pRect, textRatio, 546 x + offset.x(), y + offset.y(), cli pRect, textRatio,
549 &fallbackTxt, &fallbackPos, &dfOffs et, runPaint); 547 &fallbackTxt, &fallbackPos, &dfOffs et, runPaint);
550 break; 548 break;
551 } 549 }
552 case SkTextBlob::kHorizontal_Positioning: { 550 case SkTextBlob::kHorizontal_Positioning: {
553 scalarsPerPosition = 1; 551 scalarsPerPosition = 1;
554 dfOffset = SkPoint::Make(x, y + offset.y()); 552 dfOffset = SkPoint::Make(x, y + offset.y());
555 this->internalDrawDFPosText(cacheBlob, run, cache, dfPaint, color, viewMatrix, 553 this->internalDrawDFPosText(cacheBlob, run, dfPaint, color, viewMatrix,
556 (const char*)it.glyphs(), textLe n, it.pos(), 554 (const char*)it.glyphs(), textLe n, it.pos(),
557 scalarsPerPosition, dfOffset, cl ipRect, textRatio, 555 scalarsPerPosition, dfOffset, cl ipRect, textRatio,
558 &fallbackTxt, &fallbackPos); 556 &fallbackTxt, &fallbackPos);
559 break; 557 break;
560 } 558 }
561 case SkTextBlob::kFull_Positioning: { 559 case SkTextBlob::kFull_Positioning: {
562 dfOffset = SkPoint::Make(x, y); 560 dfOffset = SkPoint::Make(x, y);
563 this->internalDrawDFPosText(cacheBlob, run, cache, dfPaint, color, viewMatrix, 561 this->internalDrawDFPosText(cacheBlob, run, dfPaint, color, viewMatrix,
564 (const char*)it.glyphs(), textLe n, it.pos(), 562 (const char*)it.glyphs(), textLe n, it.pos(),
565 scalarsPerPosition, dfOffset, cl ipRect, textRatio, 563 scalarsPerPosition, dfOffset, cl ipRect, textRatio,
566 &fallbackTxt, &fallbackPos); 564 &fallbackTxt, &fallbackPos);
567 break; 565 break;
568 } 566 }
569 } 567 }
570 if (fallbackTxt.count()) { 568 if (fallbackTxt.count()) {
571 this->fallbackDrawPosText(cacheBlob, run, rt, clip, color, runPa int, viewMatrix, 569 this->fallbackDrawPosText(cacheBlob, run, rt, clip, color, runPa int, viewMatrix,
572 fallbackTxt, fallbackPos, scalarsPerPo sition, dfOffset, 570 fallbackTxt, fallbackPos, scalarsPerPo sition, dfOffset,
573 clipRect); 571 clipRect);
574 } 572 }
575
576 SkGlyphCache::AttachCache(cache);
577 } else if (SkDraw::ShouldDrawTextAsPaths(runPaint, viewMatrix)) { 573 } else if (SkDraw::ShouldDrawTextAsPaths(runPaint, viewMatrix)) {
578 cacheBlob->fRuns[run].fDrawAsPaths = true; 574 cacheBlob->fRuns[run].fDrawAsPaths = true;
579 } else { 575 } else {
580 cacheBlob->setHasBitmap(); 576 cacheBlob->setHasBitmap();
581 SkGlyphCache* cache = this->setupCache(&cacheBlob->fRuns[run], runPa int, &viewMatrix, 577 SkGlyphCache* cache = this->setupCache(&cacheBlob->fRuns[run], runPa int, &viewMatrix,
582 false); 578 false);
583 switch (it.positioning()) { 579 switch (it.positioning()) {
584 case SkTextBlob::kDefault_Positioning: 580 case SkTextBlob::kDefault_Positioning:
585 this->internalDrawBMPText(cacheBlob, run, cache, runPaint, c olor, viewMatrix, 581 this->internalDrawBMPText(cacheBlob, run, cache, runPaint, c olor, viewMatrix,
586 (const char *)it.glyphs(), textLen , 582 (const char *)it.glyphs(), textLen ,
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 fSurfaceProps, &viewMatrix, false); 678 fSurfaceProps, &viewMatrix, false);
683 SkGlyphCache* cache = SkGlyphCache::DetachCache(run.fTypeface, 679 SkGlyphCache* cache = SkGlyphCache::DetachCache(run.fTypeface,
684 run.fOverrideDescriptor->get Desc()); 680 run.fOverrideDescriptor->get Desc());
685 this->internalDrawBMPPosText(blob, runIndex, cache, skPaint, color, viewMatr ix, 681 this->internalDrawBMPPosText(blob, runIndex, cache, skPaint, color, viewMatr ix,
686 fallbackTxt.begin(), fallbackTxt.count(), 682 fallbackTxt.begin(), fallbackTxt.count(),
687 fallbackPos.begin(), scalarsPerPosition, offset , clipRect); 683 fallbackPos.begin(), scalarsPerPosition, offset , clipRect);
688 SkGlyphCache::AttachCache(cache); 684 SkGlyphCache::AttachCache(cache);
689 } 685 }
690 686
691 inline GrAtlasTextBlob* 687 inline GrAtlasTextBlob*
692 GrAtlasTextContext::setupDFBlob(int glyphCount, const SkPaint& origPaint, 688 GrAtlasTextContext::setupDFBlob(int glyphCount, const SkPaint& origPaint,
693 const SkMatrix& viewMatrix, SkGlyphCache** cache , 689 const SkMatrix& viewMatrix, SkPaint* dfPaint,
694 SkPaint* dfPaint, SkScalar* textRatio) { 690 SkScalar* textRatio) {
695 GrAtlasTextBlob* blob = fCache->createBlob(glyphCount, 1, kGrayTextVASize); 691 GrAtlasTextBlob* blob = fCache->createBlob(glyphCount, 1, kGrayTextVASize);
696 692
697 *dfPaint = origPaint; 693 *dfPaint = origPaint;
698 this->initDistanceFieldPaint(blob, dfPaint, textRatio, viewMatrix); 694 this->initDistanceFieldPaint(blob, dfPaint, textRatio, viewMatrix);
699 blob->fViewMatrix = viewMatrix; 695 blob->fViewMatrix = viewMatrix;
700 Run& run = blob->fRuns[0]; 696 Run& run = blob->fRuns[0];
701 PerSubRunInfo& subRun = run.fSubRunInfo.back(); 697 PerSubRunInfo& subRun = run.fSubRunInfo.back();
702 subRun.fUseLCDText = origPaint.isLCDRenderText(); 698 subRun.fUseLCDText = origPaint.isLCDRenderText();
703 subRun.fDrawAsDistanceFields = true; 699 subRun.fDrawAsDistanceFields = true;
704 700
705 *cache = this->setupCache(&blob->fRuns[0], *dfPaint, nullptr, true);
706 return blob; 701 return blob;
707 } 702 }
708 703
709 inline GrAtlasTextBlob* 704 inline GrAtlasTextBlob*
710 GrAtlasTextContext::createDrawTextBlob(GrRenderTarget* rt, const GrClip& clip, 705 GrAtlasTextContext::createDrawTextBlob(GrRenderTarget* rt, const GrClip& clip,
711 const GrPaint& paint, const SkPaint& skPa int, 706 const GrPaint& paint, const SkPaint& skPa int,
712 const SkMatrix& viewMatrix, 707 const SkMatrix& viewMatrix,
713 const char text[], size_t byteLength, 708 const char text[], size_t byteLength,
714 SkScalar x, SkScalar y, const SkIRect& re gionClipBounds) { 709 SkScalar x, SkScalar y, const SkIRect& re gionClipBounds) {
715 int glyphCount = skPaint.countText(text, byteLength); 710 int glyphCount = skPaint.countText(text, byteLength);
716 SkIRect clipRect; 711 SkIRect clipRect;
717 clip.getConservativeBounds(rt->width(), rt->height(), &clipRect); 712 clip.getConservativeBounds(rt->width(), rt->height(), &clipRect);
718 713
719 GrAtlasTextBlob* blob; 714 GrAtlasTextBlob* blob;
720 if (this->canDrawAsDistanceFields(skPaint, viewMatrix)) { 715 if (this->canDrawAsDistanceFields(skPaint, viewMatrix)) {
721 SkPaint dfPaint; 716 SkPaint dfPaint;
722 SkScalar textRatio; 717 SkScalar textRatio;
723 SkGlyphCache* cache; 718 blob = this->setupDFBlob(glyphCount, skPaint, viewMatrix, &dfPaint, &tex tRatio);
724 blob = this->setupDFBlob(glyphCount, skPaint, viewMatrix, &cache, &dfPai nt, &textRatio);
725 719
726 SkTDArray<char> fallbackTxt; 720 SkTDArray<char> fallbackTxt;
727 SkTDArray<SkScalar> fallbackPos; 721 SkTDArray<SkScalar> fallbackPos;
728 SkPoint offset; 722 SkPoint offset;
729 this->internalDrawDFText(blob, 0, cache, dfPaint, paint.getColor(), view Matrix, text, 723 this->internalDrawDFText(blob, 0, dfPaint, paint.getColor(), viewMatrix, text,
730 byteLength, x, y, clipRect, textRatio, &fallbac kTxt, &fallbackPos, 724 byteLength, x, y, clipRect, textRatio, &fallbac kTxt, &fallbackPos,
731 &offset, skPaint); 725 &offset, skPaint);
732 SkGlyphCache::AttachCache(cache);
733 if (fallbackTxt.count()) { 726 if (fallbackTxt.count()) {
734 this->fallbackDrawPosText(blob, 0, rt, clip, paint.getColor(), skPai nt, viewMatrix, 727 this->fallbackDrawPosText(blob, 0, rt, clip, paint.getColor(), skPai nt, viewMatrix,
735 fallbackTxt, fallbackPos, 2, offset, clipR ect); 728 fallbackTxt, fallbackPos, 2, offset, clipR ect);
736 } 729 }
737 } else { 730 } else {
738 blob = fCache->createBlob(glyphCount, 1, kGrayTextVASize); 731 blob = fCache->createBlob(glyphCount, 1, kGrayTextVASize);
739 blob->fViewMatrix = viewMatrix; 732 blob->fViewMatrix = viewMatrix;
740 733
741 SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], skPaint, &viewMa trix, false); 734 SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], skPaint, &viewMa trix, false);
742 this->internalDrawBMPText(blob, 0, cache, skPaint, paint.getColor(), vie wMatrix, text, 735 this->internalDrawBMPText(blob, 0, cache, skPaint, paint.getColor(), vie wMatrix, text,
(...skipping 12 matching lines...) Expand all
755 const SkPoint& offset, const SkIRect& regionClipBounds) { 748 const SkPoint& offset, const SkIRect& regionClipBounds) {
756 int glyphCount = skPaint.countText(text, byteLength); 749 int glyphCount = skPaint.countText(text, byteLength);
757 750
758 SkIRect clipRect; 751 SkIRect clipRect;
759 clip.getConservativeBounds(rt->width(), rt->height(), &clipRect); 752 clip.getConservativeBounds(rt->width(), rt->height(), &clipRect);
760 753
761 GrAtlasTextBlob* blob; 754 GrAtlasTextBlob* blob;
762 if (this->canDrawAsDistanceFields(skPaint, viewMatrix)) { 755 if (this->canDrawAsDistanceFields(skPaint, viewMatrix)) {
763 SkPaint dfPaint; 756 SkPaint dfPaint;
764 SkScalar textRatio; 757 SkScalar textRatio;
765 SkGlyphCache* cache; 758 blob = this->setupDFBlob(glyphCount, skPaint, viewMatrix, &dfPaint, &tex tRatio);
766 blob = this->setupDFBlob(glyphCount, skPaint, viewMatrix, &cache, &dfPai nt, &textRatio);
767 759
768 SkTDArray<char> fallbackTxt; 760 SkTDArray<char> fallbackTxt;
769 SkTDArray<SkScalar> fallbackPos; 761 SkTDArray<SkScalar> fallbackPos;
770 this->internalDrawDFPosText(blob, 0, cache, dfPaint, paint.getColor(), v iewMatrix, text, 762 this->internalDrawDFPosText(blob, 0, dfPaint, paint.getColor(), viewMatr ix, text,
771 byteLength, pos, scalarsPerPosition, offset, clipRect, 763 byteLength, pos, scalarsPerPosition, offset, clipRect,
772 textRatio, &fallbackTxt, &fallbackPos); 764 textRatio, &fallbackTxt, &fallbackPos);
773 SkGlyphCache::AttachCache(cache);
774 if (fallbackTxt.count()) { 765 if (fallbackTxt.count()) {
775 this->fallbackDrawPosText(blob, 0, rt, clip, paint.getColor(), skPai nt, viewMatrix, 766 this->fallbackDrawPosText(blob, 0, rt, clip, paint.getColor(), skPai nt, viewMatrix,
776 fallbackTxt, fallbackPos, scalarsPerPositi on, offset, 767 fallbackTxt, fallbackPos, scalarsPerPositi on, offset,
777 clipRect); 768 clipRect);
778 } 769 }
779 } else { 770 } else {
780 blob = fCache->createBlob(glyphCount, 1, kGrayTextVASize); 771 blob = fCache->createBlob(glyphCount, 1, kGrayTextVASize);
781 blob->fViewMatrix = viewMatrix; 772 blob->fViewMatrix = viewMatrix;
782 SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], skPaint, &viewMa trix, false); 773 SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], skPaint, &viewMa trix, false);
783 this->internalDrawBMPPosText(blob, 0, cache, skPaint, paint.getColor(), viewMatrix, text, 774 this->internalDrawBMPPosText(blob, 0, cache, skPaint, paint.getColor(), viewMatrix, text,
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 clipRect); 1041 clipRect);
1051 } 1042 }
1052 pos += scalarsPerPosition; 1043 pos += scalarsPerPosition;
1053 } 1044 }
1054 } 1045 }
1055 } 1046 }
1056 } 1047 }
1057 1048
1058 1049
1059 void GrAtlasTextContext::internalDrawDFText(GrAtlasTextBlob* blob, int runIndex, 1050 void GrAtlasTextContext::internalDrawDFText(GrAtlasTextBlob* blob, int runIndex,
1060 SkGlyphCache* cache, const SkPaint& skPaint, 1051 const SkPaint& skPaint, GrColor colo r,
1061 GrColor color,
1062 const SkMatrix& viewMatrix, 1052 const SkMatrix& viewMatrix,
1063 const char text[], size_t byteLength , 1053 const char text[], size_t byteLength ,
1064 SkScalar x, SkScalar y, const SkIRec t& clipRect, 1054 SkScalar x, SkScalar y, const SkIRec t& clipRect,
1065 SkScalar textRatio, 1055 SkScalar textRatio,
1066 SkTDArray<char>* fallbackTxt, 1056 SkTDArray<char>* fallbackTxt,
1067 SkTDArray<SkScalar>* fallbackPos, 1057 SkTDArray<SkScalar>* fallbackPos,
1068 SkPoint* offset, 1058 SkPoint* offset,
1069 const SkPaint& origPaint) { 1059 const SkPaint& origPaint) {
1070 SkASSERT(byteLength == 0 || text != nullptr); 1060 SkASSERT(byteLength == 0 || text != nullptr);
1071 1061
1072 // nothing to draw 1062 // nothing to draw
1073 if (text == nullptr || byteLength == 0) { 1063 if (text == nullptr || byteLength == 0) {
1074 return; 1064 return;
1075 } 1065 }
1076 1066
1077 SkDrawCacheProc glyphCacheProc = origPaint.getDrawCacheProc(); 1067 SkDrawCacheProc glyphCacheProc = origPaint.getDrawCacheProc();
1078 SkAutoDescriptor desc; 1068 SkAutoDescriptor desc;
1079 origPaint.getScalerContextDescriptor(&desc, fSurfaceProps, nullptr, true); 1069 origPaint.getScalerContextDescriptor(&desc, fSurfaceProps, nullptr, true);
1080 SkGlyphCache* origPaintCache = SkGlyphCache::DetachCache(origPaint.getTypefa ce(), 1070 SkGlyphCache* origPaintCache = SkGlyphCache::DetachCache(origPaint.getTypefa ce(),
1081 desc.getDesc()); 1071 desc.getDesc());
1082 1072
1083 SkTArray<SkScalar> positions; 1073 SkTArray<SkScalar> positions;
1084 1074
1085 const char* textPtr = text; 1075 const char* textPtr = text;
1086 SkFixed stopX = 0; 1076 SkFixed stopX = 0;
1087 SkFixed stopY = 0; 1077 SkFixed stopY = 0;
1088 SkFixed origin = 0; 1078 SkFixed origin = 0;
1089 switch (origPaint.getTextAlign()) { 1079 switch (origPaint.getTextAlign()) {
1090 case SkPaint::kRight_Align: origin = SK_Fixed1; break; 1080 case SkPaint::kRight_Align: origin = SK_Fixed1; break;
(...skipping 12 matching lines...) Expand all
1103 positions.push_back(SkFixedToScalar(stopX + SkFixedMul(origin, width))); 1093 positions.push_back(SkFixedToScalar(stopX + SkFixedMul(origin, width)));
1104 1094
1105 SkFixed height = glyph.fAdvanceY; 1095 SkFixed height = glyph.fAdvanceY;
1106 positions.push_back(SkFixedToScalar(stopY + SkFixedMul(origin, height))) ; 1096 positions.push_back(SkFixedToScalar(stopY + SkFixedMul(origin, height))) ;
1107 1097
1108 stopX += width; 1098 stopX += width;
1109 stopY += height; 1099 stopY += height;
1110 } 1100 }
1111 SkASSERT(textPtr == stop); 1101 SkASSERT(textPtr == stop);
1112 1102
1103 SkGlyphCache::AttachCache(origPaintCache);
1104
1113 // now adjust starting point depending on alignment 1105 // now adjust starting point depending on alignment
1114 SkScalar alignX = SkFixedToScalar(stopX); 1106 SkScalar alignX = SkFixedToScalar(stopX);
1115 SkScalar alignY = SkFixedToScalar(stopY); 1107 SkScalar alignY = SkFixedToScalar(stopY);
1116 if (origPaint.getTextAlign() == SkPaint::kCenter_Align) { 1108 if (origPaint.getTextAlign() == SkPaint::kCenter_Align) {
1117 alignX = SkScalarHalf(alignX); 1109 alignX = SkScalarHalf(alignX);
1118 alignY = SkScalarHalf(alignY); 1110 alignY = SkScalarHalf(alignY);
1119 } else if (origPaint.getTextAlign() == SkPaint::kLeft_Align) { 1111 } else if (origPaint.getTextAlign() == SkPaint::kLeft_Align) {
1120 alignX = 0; 1112 alignX = 0;
1121 alignY = 0; 1113 alignY = 0;
1122 } 1114 }
1123 x -= alignX; 1115 x -= alignX;
1124 y -= alignY; 1116 y -= alignY;
1125 *offset = SkPoint::Make(x, y); 1117 *offset = SkPoint::Make(x, y);
1126 1118
1127 this->internalDrawDFPosText(blob, runIndex, cache, skPaint, color, viewMatri x, text, byteLength, 1119 this->internalDrawDFPosText(blob, runIndex, skPaint, color, viewMatrix, text , byteLength,
1128 positions.begin(), 2, *offset, clipRect, textRat io, fallbackTxt, 1120 positions.begin(), 2, *offset, clipRect, textRat io, fallbackTxt,
1129 fallbackPos); 1121 fallbackPos);
1130 SkGlyphCache::AttachCache(origPaintCache);
1131 } 1122 }
1132 1123
1133 void GrAtlasTextContext::internalDrawDFPosText(GrAtlasTextBlob* blob, int runInd ex, 1124 void GrAtlasTextContext::internalDrawDFPosText(GrAtlasTextBlob* blob, int runInd ex,
1134 SkGlyphCache* cache, const SkPain t& skPaint, 1125 const SkPaint& skPaint, GrColor c olor,
1135 GrColor color,
1136 const SkMatrix& viewMatrix, 1126 const SkMatrix& viewMatrix,
1137 const char text[], size_t byteLen gth, 1127 const char text[], size_t byteLen gth,
1138 const SkScalar pos[], int scalars PerPosition, 1128 const SkScalar pos[], int scalars PerPosition,
1139 const SkPoint& offset, const SkIR ect& clipRect, 1129 const SkPoint& offset, const SkIR ect& clipRect,
1140 SkScalar textRatio, 1130 SkScalar textRatio,
1141 SkTDArray<char>* fallbackTxt, 1131 SkTDArray<char>* fallbackTxt,
1142 SkTDArray<SkScalar>* fallbackPos) { 1132 SkTDArray<SkScalar>* fallbackPos) {
1143 1133
1144 SkASSERT(byteLength == 0 || text != nullptr); 1134 SkASSERT(byteLength == 0 || text != nullptr);
1145 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); 1135 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
1146 1136
1147 // nothing to draw 1137 // nothing to draw
1148 if (text == nullptr || byteLength == 0) { 1138 if (text == nullptr || byteLength == 0) {
1149 return; 1139 return;
1150 } 1140 }
1151 1141
1152 fCurrStrike = nullptr; 1142 fCurrStrike = nullptr;
1153 1143
1154 SkDrawCacheProc glyphCacheProc = skPaint.getDrawCacheProc(); 1144 SkDrawCacheProc glyphCacheProc = skPaint.getDrawCacheProc();
1145 SkGlyphCache* cache = this->setupCache(&blob->fRuns[runIndex], skPaint, null ptr, true);
1155 GrFontScaler* fontScaler = GetGrFontScaler(cache); 1146 GrFontScaler* fontScaler = GetGrFontScaler(cache);
1156 1147
1157 const char* stop = text + byteLength; 1148 const char* stop = text + byteLength;
1158 1149
1159 if (SkPaint::kLeft_Align == skPaint.getTextAlign()) { 1150 if (SkPaint::kLeft_Align == skPaint.getTextAlign()) {
1160 while (text < stop) { 1151 while (text < stop) {
1161 const char* lastText = text; 1152 const char* lastText = text;
1162 // the last 2 parameters are ignored 1153 // the last 2 parameters are ignored
1163 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); 1154 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0);
1164 1155
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1208 fallbackTxt->append(SkToInt(text-lastText), lastText); 1199 fallbackTxt->append(SkToInt(text-lastText), lastText);
1209 *fallbackPos->append() = pos[0]; 1200 *fallbackPos->append() = pos[0];
1210 if (2 == scalarsPerPosition) { 1201 if (2 == scalarsPerPosition) {
1211 *fallbackPos->append() = pos[1]; 1202 *fallbackPos->append() = pos[1];
1212 } 1203 }
1213 } 1204 }
1214 } 1205 }
1215 pos += scalarsPerPosition; 1206 pos += scalarsPerPosition;
1216 } 1207 }
1217 } 1208 }
1209
1210 SkGlyphCache::AttachCache(cache);
1218 } 1211 }
1219 1212
1220 void GrAtlasTextContext::bmpAppendGlyph(GrAtlasTextBlob* blob, int runIndex, 1213 void GrAtlasTextContext::bmpAppendGlyph(GrAtlasTextBlob* blob, int runIndex,
1221 const SkGlyph& skGlyph, 1214 const SkGlyph& skGlyph,
1222 int vx, int vy, GrColor color, GrFontSca ler* scaler, 1215 int vx, int vy, GrColor color, GrFontSca ler* scaler,
1223 const SkIRect& clipRect) { 1216 const SkIRect& clipRect) {
1224 Run& run = blob->fRuns[runIndex]; 1217 Run& run = blob->fRuns[runIndex];
1225 if (!fCurrStrike) { 1218 if (!fCurrStrike) {
1226 fCurrStrike = fContext->getBatchFontCache()->getStrike(scaler); 1219 fCurrStrike = fContext->getBatchFontCache()->getStrike(scaler);
1227 } 1220 }
(...skipping 1058 matching lines...) Expand 10 before | Expand all | Expand 10 after
2286 gTextContext->createDrawTextBlob(rt, clip, grPaint, skPaint, viewMat rix, text, 2279 gTextContext->createDrawTextBlob(rt, clip, grPaint, skPaint, viewMat rix, text,
2287 static_cast<size_t>(textLen), 0, 0, noClip)); 2280 static_cast<size_t>(textLen), 0, 0, noClip));
2288 2281
2289 SkScalar transX = static_cast<SkScalar>(random->nextU()); 2282 SkScalar transX = static_cast<SkScalar>(random->nextU());
2290 SkScalar transY = static_cast<SkScalar>(random->nextU()); 2283 SkScalar transY = static_cast<SkScalar>(random->nextU());
2291 const GrAtlasTextBlob::Run::SubRunInfo& info = blob->fRuns[0].fSubRunInfo[0] ; 2284 const GrAtlasTextBlob::Run::SubRunInfo& info = blob->fRuns[0].fSubRunInfo[0] ;
2292 return gTextContext->createBatch(blob, info, textLen, 0, 0, color, transX, t ransY, skPaint); 2285 return gTextContext->createBatch(blob, info, textLen, 0, 0, color, transX, t ransY, skPaint);
2293 } 2286 }
2294 2287
2295 #endif 2288 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrAtlasTextContext.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698