| 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 "GrBatchFontCache.h" | 9 #include "GrBatchFontCache.h" |
| 10 #include "GrBatchFlushState.h" | 10 #include "GrBatchFlushState.h" |
| 11 #include "GrBatchTest.h" | 11 #include "GrBatchTest.h" |
| 12 #include "GrBlurUtils.h" | 12 #include "GrBlurUtils.h" |
| 13 #include "GrDefaultGeoProcFactory.h" | 13 #include "GrDefaultGeoProcFactory.h" |
| 14 #include "GrDrawContext.h" | 14 #include "GrDrawContext.h" |
| 15 #include "GrDrawTarget.h" | 15 #include "GrDrawTarget.h" |
| 16 #include "GrFontScaler.h" | 16 #include "GrFontScaler.h" |
| 17 #include "GrResourceProvider.h" | 17 #include "GrResourceProvider.h" |
| 18 #include "GrStrokeInfo.h" | 18 #include "GrStrokeInfo.h" |
| 19 #include "GrTextBlobCache.h" | 19 #include "GrTextBlobCache.h" |
| 20 #include "GrTexturePriv.h" | 20 #include "GrTexturePriv.h" |
| 21 #include "GrVertexBuffer.h" | 21 #include "GrVertexBuffer.h" |
| 22 | 22 |
| 23 #include "SkAutoKern.h" | 23 #include "SkAutoKern.h" |
| 24 #include "SkColorPriv.h" | 24 #include "SkColorPriv.h" |
| 25 #include "SkColorFilter.h" | 25 #include "SkColorFilter.h" |
| 26 #include "SkDistanceFieldGen.h" | 26 #include "SkDistanceFieldGen.h" |
| 27 #include "SkDraw.h" | 27 #include "SkDraw.h" |
| 28 #include "SkDrawFilter.h" | 28 #include "SkDrawFilter.h" |
| 29 #include "SkDrawProcs.h" | 29 #include "SkDrawProcs.h" |
| 30 #include "SkFindAndPlaceGlyph.h" |
| 30 #include "SkGlyphCache.h" | 31 #include "SkGlyphCache.h" |
| 31 #include "SkGpuDevice.h" | 32 #include "SkGpuDevice.h" |
| 32 #include "SkGrPriv.h" | 33 #include "SkGrPriv.h" |
| 33 #include "SkPath.h" | 34 #include "SkPath.h" |
| 34 #include "SkRTConf.h" | 35 #include "SkRTConf.h" |
| 35 #include "SkStrokeRec.h" | 36 #include "SkStrokeRec.h" |
| 36 #include "SkTextBlob.h" | 37 #include "SkTextBlob.h" |
| 37 #include "SkTextMapStateProc.h" | 38 #include "SkTextMapStateProc.h" |
| 38 | 39 |
| 39 #include "batches/GrVertexBatch.h" | 40 #include "batches/GrVertexBatch.h" |
| (...skipping 868 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 908 if (text == nullptr || byteLength == 0) { | 909 if (text == nullptr || byteLength == 0) { |
| 909 return; | 910 return; |
| 910 } | 911 } |
| 911 | 912 |
| 912 fCurrStrike = nullptr; | 913 fCurrStrike = nullptr; |
| 913 SkDrawCacheProc glyphCacheProc = skPaint.getDrawCacheProc(); | 914 SkDrawCacheProc glyphCacheProc = skPaint.getDrawCacheProc(); |
| 914 | 915 |
| 915 // Get GrFontScaler from cache | 916 // Get GrFontScaler from cache |
| 916 GrFontScaler* fontScaler = GetGrFontScaler(cache); | 917 GrFontScaler* fontScaler = GetGrFontScaler(cache); |
| 917 | 918 |
| 918 const char* stop = text + byteLength; | 919 SkFindAndPlaceGlyph::ProcessPosText( |
| 919 SkTextAlignProc alignProc(skPaint.getTextAlign()); | 920 text, byteLength, offset, viewMatrix, pos, scalarsPerPosition, |
| 920 SkTextMapStateProc tmsProc(viewMatrix, offset, scalarsPerPosition); | 921 skPaint.getTextAlign(), glyphCacheProc, cache, |
| 921 | 922 [&](const SkGlyph& glyph, SkPoint position, SkPoint rounding) { |
| 922 if (cache->isSubpixel()) { | 923 position += rounding; |
| 923 // maybe we should skip the rounding if linearText is set | 924 this->bmpAppendGlyph( |
| 924 SkAxisAlignment baseline = SkComputeAxisAlignmentForHText(viewMatrix); | 925 blob, runIndex, glyph, |
| 925 | 926 SkScalarFloorToInt(position.fX), SkScalarFloorToInt(position.fY)
, |
| 926 SkFixed fxMask = ~0; | 927 color, fontScaler, clipRect); |
| 927 SkFixed fyMask = ~0; | |
| 928 SkScalar halfSampleX = SkFixedToScalar(SkGlyph::kSubpixelRound); | |
| 929 SkScalar halfSampleY = SkFixedToScalar(SkGlyph::kSubpixelRound); | |
| 930 if (kX_SkAxisAlignment == baseline) { | |
| 931 fyMask = 0; | |
| 932 halfSampleY = SK_ScalarHalf; | |
| 933 } else if (kY_SkAxisAlignment == baseline) { | |
| 934 fxMask = 0; | |
| 935 halfSampleX = SK_ScalarHalf; | |
| 936 } | 928 } |
| 937 | 929 ); |
| 938 if (SkPaint::kLeft_Align == skPaint.getTextAlign()) { | |
| 939 while (text < stop) { | |
| 940 SkPoint tmsLoc; | |
| 941 tmsProc(pos, &tmsLoc); | |
| 942 Sk48Dot16 fx = SkScalarTo48Dot16(tmsLoc.fX + halfSampleX); | |
| 943 Sk48Dot16 fy = SkScalarTo48Dot16(tmsLoc.fY + halfSampleY); | |
| 944 | |
| 945 const SkGlyph& glyph = glyphCacheProc(cache, &text, | |
| 946 fx & fxMask, fy & fyMask); | |
| 947 | |
| 948 if (glyph.fWidth) { | |
| 949 this->bmpAppendGlyph(blob, | |
| 950 runIndex, | |
| 951 glyph, | |
| 952 Sk48Dot16FloorToInt(fx), | |
| 953 Sk48Dot16FloorToInt(fy), | |
| 954 color, | |
| 955 fontScaler, | |
| 956 clipRect); | |
| 957 } | |
| 958 pos += scalarsPerPosition; | |
| 959 } | |
| 960 } else { | |
| 961 while (text < stop) { | |
| 962 const char* currentText = text; | |
| 963 const SkGlyph& metricGlyph = glyphCacheProc(cache, &text, 0, 0); | |
| 964 | |
| 965 if (metricGlyph.fWidth) { | |
| 966 SkDEBUGCODE(SkFixed prevAdvX = metricGlyph.fAdvanceX;) | |
| 967 SkDEBUGCODE(SkFixed prevAdvY = metricGlyph.fAdvanceY;) | |
| 968 SkPoint tmsLoc; | |
| 969 tmsProc(pos, &tmsLoc); | |
| 970 SkPoint alignLoc; | |
| 971 alignProc(tmsLoc, metricGlyph, &alignLoc); | |
| 972 | |
| 973 Sk48Dot16 fx = SkScalarTo48Dot16(alignLoc.fX + halfSampleX); | |
| 974 Sk48Dot16 fy = SkScalarTo48Dot16(alignLoc.fY + halfSampleY); | |
| 975 | |
| 976 // have to call again, now that we've been "aligned" | |
| 977 const SkGlyph& glyph = glyphCacheProc(cache, ¤tText, | |
| 978 fx & fxMask, fy & fyMa
sk); | |
| 979 // the assumption is that the metrics haven't changed | |
| 980 SkASSERT(prevAdvX == glyph.fAdvanceX); | |
| 981 SkASSERT(prevAdvY == glyph.fAdvanceY); | |
| 982 SkASSERT(glyph.fWidth); | |
| 983 | |
| 984 this->bmpAppendGlyph(blob, | |
| 985 runIndex, | |
| 986 glyph, | |
| 987 Sk48Dot16FloorToInt(fx), | |
| 988 Sk48Dot16FloorToInt(fy), | |
| 989 color, | |
| 990 fontScaler, | |
| 991 clipRect); | |
| 992 } | |
| 993 pos += scalarsPerPosition; | |
| 994 } | |
| 995 } | |
| 996 } else { // not subpixel | |
| 997 | |
| 998 if (SkPaint::kLeft_Align == skPaint.getTextAlign()) { | |
| 999 while (text < stop) { | |
| 1000 // the last 2 parameters are ignored | |
| 1001 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); | |
| 1002 | |
| 1003 if (glyph.fWidth) { | |
| 1004 SkPoint tmsLoc; | |
| 1005 tmsProc(pos, &tmsLoc); | |
| 1006 | |
| 1007 Sk48Dot16 fx = SkScalarTo48Dot16(tmsLoc.fX + SK_ScalarHalf);
//halfSampleX; | |
| 1008 Sk48Dot16 fy = SkScalarTo48Dot16(tmsLoc.fY + SK_ScalarHalf);
//halfSampleY; | |
| 1009 this->bmpAppendGlyph(blob, | |
| 1010 runIndex, | |
| 1011 glyph, | |
| 1012 Sk48Dot16FloorToInt(fx), | |
| 1013 Sk48Dot16FloorToInt(fy), | |
| 1014 color, | |
| 1015 fontScaler, | |
| 1016 clipRect); | |
| 1017 } | |
| 1018 pos += scalarsPerPosition; | |
| 1019 } | |
| 1020 } else { | |
| 1021 while (text < stop) { | |
| 1022 // the last 2 parameters are ignored | |
| 1023 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); | |
| 1024 | |
| 1025 if (glyph.fWidth) { | |
| 1026 SkPoint tmsLoc; | |
| 1027 tmsProc(pos, &tmsLoc); | |
| 1028 | |
| 1029 SkPoint alignLoc; | |
| 1030 alignProc(tmsLoc, glyph, &alignLoc); | |
| 1031 | |
| 1032 Sk48Dot16 fx = SkScalarTo48Dot16(alignLoc.fX + SK_ScalarHalf
); //halfSampleX; | |
| 1033 Sk48Dot16 fy = SkScalarTo48Dot16(alignLoc.fY + SK_ScalarHalf
); //halfSampleY; | |
| 1034 this->bmpAppendGlyph(blob, | |
| 1035 runIndex, | |
| 1036 glyph, | |
| 1037 Sk48Dot16FloorToInt(fx), | |
| 1038 Sk48Dot16FloorToInt(fy), | |
| 1039 color, | |
| 1040 fontScaler, | |
| 1041 clipRect); | |
| 1042 } | |
| 1043 pos += scalarsPerPosition; | |
| 1044 } | |
| 1045 } | |
| 1046 } | |
| 1047 } | 930 } |
| 1048 | 931 |
| 1049 | |
| 1050 void GrAtlasTextContext::internalDrawDFText(GrAtlasTextBlob* blob, int runIndex, | 932 void GrAtlasTextContext::internalDrawDFText(GrAtlasTextBlob* blob, int runIndex, |
| 1051 const SkPaint& skPaint, GrColor colo
r, | 933 const SkPaint& skPaint, GrColor colo
r, |
| 1052 const SkMatrix& viewMatrix, | 934 const SkMatrix& viewMatrix, |
| 1053 const char text[], size_t byteLength
, | 935 const char text[], size_t byteLength
, |
| 1054 SkScalar x, SkScalar y, const SkIRec
t& clipRect, | 936 SkScalar x, SkScalar y, const SkIRec
t& clipRect, |
| 1055 SkScalar textRatio, | 937 SkScalar textRatio, |
| 1056 SkTDArray<char>* fallbackTxt, | 938 SkTDArray<char>* fallbackTxt, |
| 1057 SkTDArray<SkScalar>* fallbackPos, | 939 SkTDArray<SkScalar>* fallbackPos, |
| 1058 SkPoint* offset, | 940 SkPoint* offset, |
| 1059 const SkPaint& origPaint) { | 941 const SkPaint& origPaint) { |
| (...skipping 1222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2282 gTextContext->createDrawTextBlob(rt, clip, grPaint, skPaint, viewMat
rix, text, | 2164 gTextContext->createDrawTextBlob(rt, clip, grPaint, skPaint, viewMat
rix, text, |
| 2283 static_cast<size_t>(textLen), 0, 0,
noClip)); | 2165 static_cast<size_t>(textLen), 0, 0,
noClip)); |
| 2284 | 2166 |
| 2285 SkScalar transX = static_cast<SkScalar>(random->nextU()); | 2167 SkScalar transX = static_cast<SkScalar>(random->nextU()); |
| 2286 SkScalar transY = static_cast<SkScalar>(random->nextU()); | 2168 SkScalar transY = static_cast<SkScalar>(random->nextU()); |
| 2287 const GrAtlasTextBlob::Run::SubRunInfo& info = blob->fRuns[0].fSubRunInfo[0]
; | 2169 const GrAtlasTextBlob::Run::SubRunInfo& info = blob->fRuns[0].fSubRunInfo[0]
; |
| 2288 return gTextContext->createBatch(blob, info, textLen, 0, 0, color, transX, t
ransY, skPaint); | 2170 return gTextContext->createBatch(blob, info, textLen, 0, 0, color, transX, t
ransY, skPaint); |
| 2289 } | 2171 } |
| 2290 | 2172 |
| 2291 #endif | 2173 #endif |
| OLD | NEW |