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

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

Issue 1257603005: Minimize retrieving SkGlyph in GrTextContext (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: cleanup Created 5 years, 4 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') | src/gpu/GrBatchFontCache.h » ('j') | 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 "GrBatch.h" 9 #include "GrBatch.h"
10 #include "GrBatchFontCache.h" 10 #include "GrBatchFontCache.h"
(...skipping 872 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 Sk48Dot16 fy = SkScalarTo48Dot16(y + halfSampleY); 883 Sk48Dot16 fy = SkScalarTo48Dot16(y + halfSampleY);
884 884
885 while (text < stop) { 885 while (text < stop) {
886 const SkGlyph& glyph = glyphCacheProc(cache, &text, fx & fxMask, fy & fy Mask); 886 const SkGlyph& glyph = glyphCacheProc(cache, &text, fx & fxMask, fy & fy Mask);
887 887
888 fx += autokern.adjust(glyph); 888 fx += autokern.adjust(glyph);
889 889
890 if (glyph.fWidth) { 890 if (glyph.fWidth) {
891 this->bmpAppendGlyph(blob, 891 this->bmpAppendGlyph(blob,
892 runIndex, 892 runIndex,
893 GrGlyph::Pack(glyph.getGlyphID(), 893 glyph,
894 glyph.getSubXFixed(),
895 glyph.getSubYFixed(),
896 GrGlyph::kCoverage_MaskStyle),
897 Sk48Dot16FloorToInt(fx), 894 Sk48Dot16FloorToInt(fx),
898 Sk48Dot16FloorToInt(fy), 895 Sk48Dot16FloorToInt(fy),
899 color, 896 color,
900 fontScaler, 897 fontScaler,
901 clipRect); 898 clipRect);
902 } 899 }
903 900
904 fx += glyph.fAdvanceX; 901 fx += glyph.fAdvanceX;
905 fy += glyph.fAdvanceY; 902 fy += glyph.fAdvanceY;
906 } 903 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
953 tmsProc(pos, &tmsLoc); 950 tmsProc(pos, &tmsLoc);
954 Sk48Dot16 fx = SkScalarTo48Dot16(tmsLoc.fX + halfSampleX); 951 Sk48Dot16 fx = SkScalarTo48Dot16(tmsLoc.fX + halfSampleX);
955 Sk48Dot16 fy = SkScalarTo48Dot16(tmsLoc.fY + halfSampleY); 952 Sk48Dot16 fy = SkScalarTo48Dot16(tmsLoc.fY + halfSampleY);
956 953
957 const SkGlyph& glyph = glyphCacheProc(cache, &text, 954 const SkGlyph& glyph = glyphCacheProc(cache, &text,
958 fx & fxMask, fy & fyMask); 955 fx & fxMask, fy & fyMask);
959 956
960 if (glyph.fWidth) { 957 if (glyph.fWidth) {
961 this->bmpAppendGlyph(blob, 958 this->bmpAppendGlyph(blob,
962 runIndex, 959 runIndex,
963 GrGlyph::Pack(glyph.getGlyphID(), 960 glyph,
964 glyph.getSubXFixed(),
965 glyph.getSubYFixed(),
966 GrGlyph::kCoverage_MaskSt yle),
967 Sk48Dot16FloorToInt(fx), 961 Sk48Dot16FloorToInt(fx),
968 Sk48Dot16FloorToInt(fy), 962 Sk48Dot16FloorToInt(fy),
969 color, 963 color,
970 fontScaler, 964 fontScaler,
971 clipRect); 965 clipRect);
972 } 966 }
973 pos += scalarsPerPosition; 967 pos += scalarsPerPosition;
974 } 968 }
975 } else { 969 } else {
976 while (text < stop) { 970 while (text < stop) {
(...skipping 14 matching lines...) Expand all
991 // have to call again, now that we've been "aligned" 985 // have to call again, now that we've been "aligned"
992 const SkGlyph& glyph = glyphCacheProc(cache, &currentText, 986 const SkGlyph& glyph = glyphCacheProc(cache, &currentText,
993 fx & fxMask, fy & fyMa sk); 987 fx & fxMask, fy & fyMa sk);
994 // the assumption is that the metrics haven't changed 988 // the assumption is that the metrics haven't changed
995 SkASSERT(prevAdvX == glyph.fAdvanceX); 989 SkASSERT(prevAdvX == glyph.fAdvanceX);
996 SkASSERT(prevAdvY == glyph.fAdvanceY); 990 SkASSERT(prevAdvY == glyph.fAdvanceY);
997 SkASSERT(glyph.fWidth); 991 SkASSERT(glyph.fWidth);
998 992
999 this->bmpAppendGlyph(blob, 993 this->bmpAppendGlyph(blob,
1000 runIndex, 994 runIndex,
1001 GrGlyph::Pack(glyph.getGlyphID(), 995 glyph,
1002 glyph.getSubXFixed(),
1003 glyph.getSubYFixed(),
1004 GrGlyph::kCoverage_MaskSt yle),
1005 Sk48Dot16FloorToInt(fx), 996 Sk48Dot16FloorToInt(fx),
1006 Sk48Dot16FloorToInt(fy), 997 Sk48Dot16FloorToInt(fy),
1007 color, 998 color,
1008 fontScaler, 999 fontScaler,
1009 clipRect); 1000 clipRect);
1010 } 1001 }
1011 pos += scalarsPerPosition; 1002 pos += scalarsPerPosition;
1012 } 1003 }
1013 } 1004 }
1014 } else { // not subpixel 1005 } else { // not subpixel
1015 1006
1016 if (SkPaint::kLeft_Align == skPaint.getTextAlign()) { 1007 if (SkPaint::kLeft_Align == skPaint.getTextAlign()) {
1017 while (text < stop) { 1008 while (text < stop) {
1018 // the last 2 parameters are ignored 1009 // the last 2 parameters are ignored
1019 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); 1010 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0);
1020 1011
1021 if (glyph.fWidth) { 1012 if (glyph.fWidth) {
1022 SkPoint tmsLoc; 1013 SkPoint tmsLoc;
1023 tmsProc(pos, &tmsLoc); 1014 tmsProc(pos, &tmsLoc);
1024 1015
1025 Sk48Dot16 fx = SkScalarTo48Dot16(tmsLoc.fX + SK_ScalarHalf); //halfSampleX; 1016 Sk48Dot16 fx = SkScalarTo48Dot16(tmsLoc.fX + SK_ScalarHalf); //halfSampleX;
1026 Sk48Dot16 fy = SkScalarTo48Dot16(tmsLoc.fY + SK_ScalarHalf); //halfSampleY; 1017 Sk48Dot16 fy = SkScalarTo48Dot16(tmsLoc.fY + SK_ScalarHalf); //halfSampleY;
1027 this->bmpAppendGlyph(blob, 1018 this->bmpAppendGlyph(blob,
1028 runIndex, 1019 runIndex,
1029 GrGlyph::Pack(glyph.getGlyphID(), 1020 glyph,
1030 glyph.getSubXFixed(),
1031 glyph.getSubYFixed(),
1032 GrGlyph::kCoverage_MaskSt yle),
1033 Sk48Dot16FloorToInt(fx), 1021 Sk48Dot16FloorToInt(fx),
1034 Sk48Dot16FloorToInt(fy), 1022 Sk48Dot16FloorToInt(fy),
1035 color, 1023 color,
1036 fontScaler, 1024 fontScaler,
1037 clipRect); 1025 clipRect);
1038 } 1026 }
1039 pos += scalarsPerPosition; 1027 pos += scalarsPerPosition;
1040 } 1028 }
1041 } else { 1029 } else {
1042 while (text < stop) { 1030 while (text < stop) {
1043 // the last 2 parameters are ignored 1031 // the last 2 parameters are ignored
1044 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); 1032 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0);
1045 1033
1046 if (glyph.fWidth) { 1034 if (glyph.fWidth) {
1047 SkPoint tmsLoc; 1035 SkPoint tmsLoc;
1048 tmsProc(pos, &tmsLoc); 1036 tmsProc(pos, &tmsLoc);
1049 1037
1050 SkPoint alignLoc; 1038 SkPoint alignLoc;
1051 alignProc(tmsLoc, glyph, &alignLoc); 1039 alignProc(tmsLoc, glyph, &alignLoc);
1052 1040
1053 Sk48Dot16 fx = SkScalarTo48Dot16(alignLoc.fX + SK_ScalarHalf ); //halfSampleX; 1041 Sk48Dot16 fx = SkScalarTo48Dot16(alignLoc.fX + SK_ScalarHalf ); //halfSampleX;
1054 Sk48Dot16 fy = SkScalarTo48Dot16(alignLoc.fY + SK_ScalarHalf ); //halfSampleY; 1042 Sk48Dot16 fy = SkScalarTo48Dot16(alignLoc.fY + SK_ScalarHalf ); //halfSampleY;
1055 this->bmpAppendGlyph(blob, 1043 this->bmpAppendGlyph(blob,
1056 runIndex, 1044 runIndex,
1057 GrGlyph::Pack(glyph.getGlyphID(), 1045 glyph,
1058 glyph.getSubXFixed(),
1059 glyph.getSubYFixed(),
1060 GrGlyph::kCoverage_MaskSt yle),
1061 Sk48Dot16FloorToInt(fx), 1046 Sk48Dot16FloorToInt(fx),
1062 Sk48Dot16FloorToInt(fy), 1047 Sk48Dot16FloorToInt(fy),
1063 color, 1048 color,
1064 fontScaler, 1049 fontScaler,
1065 clipRect); 1050 clipRect);
1066 } 1051 }
1067 pos += scalarsPerPosition; 1052 pos += scalarsPerPosition;
1068 } 1053 }
1069 } 1054 }
1070 } 1055 }
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1176 const char* lastText = text; 1161 const char* lastText = text;
1177 // the last 2 parameters are ignored 1162 // the last 2 parameters are ignored
1178 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); 1163 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0);
1179 1164
1180 if (glyph.fWidth) { 1165 if (glyph.fWidth) {
1181 SkScalar x = offset.x() + pos[0]; 1166 SkScalar x = offset.x() + pos[0];
1182 SkScalar y = offset.y() + (2 == scalarsPerPosition ? pos[1] : 0) ; 1167 SkScalar y = offset.y() + (2 == scalarsPerPosition ? pos[1] : 0) ;
1183 1168
1184 if (!this->dfAppendGlyph(blob, 1169 if (!this->dfAppendGlyph(blob,
1185 runIndex, 1170 runIndex,
1186 GrGlyph::Pack(glyph.getGlyphID(), 1171 glyph,
1187 glyph.getSubXFixed(),
1188 glyph.getSubYFixed(),
1189 GrGlyph::kDistance_MaskSt yle),
1190 x, y, color, fontScaler, clipRect, 1172 x, y, color, fontScaler, clipRect,
1191 textRatio, viewMatrix)) { 1173 textRatio, viewMatrix)) {
1192 // couldn't append, send to fallback 1174 // couldn't append, send to fallback
1193 fallbackTxt->append(SkToInt(text-lastText), lastText); 1175 fallbackTxt->append(SkToInt(text-lastText), lastText);
1194 *fallbackPos->append() = pos[0]; 1176 *fallbackPos->append() = pos[0];
1195 if (2 == scalarsPerPosition) { 1177 if (2 == scalarsPerPosition) {
1196 *fallbackPos->append() = pos[1]; 1178 *fallbackPos->append() = pos[1];
1197 } 1179 }
1198 } 1180 }
1199 } 1181 }
1200 pos += scalarsPerPosition; 1182 pos += scalarsPerPosition;
1201 } 1183 }
1202 } else { 1184 } else {
1203 SkScalar alignMul = SkPaint::kCenter_Align == skPaint.getTextAlign() ? S K_ScalarHalf 1185 SkScalar alignMul = SkPaint::kCenter_Align == skPaint.getTextAlign() ? S K_ScalarHalf
1204 : S K_Scalar1; 1186 : S K_Scalar1;
1205 while (text < stop) { 1187 while (text < stop) {
1206 const char* lastText = text; 1188 const char* lastText = text;
1207 // the last 2 parameters are ignored 1189 // the last 2 parameters are ignored
1208 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); 1190 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0);
1209 1191
1210 if (glyph.fWidth) { 1192 if (glyph.fWidth) {
1211 SkScalar x = offset.x() + pos[0]; 1193 SkScalar x = offset.x() + pos[0];
1212 SkScalar y = offset.y() + (2 == scalarsPerPosition ? pos[1] : 0) ; 1194 SkScalar y = offset.y() + (2 == scalarsPerPosition ? pos[1] : 0) ;
1213 1195
1214 SkScalar advanceX = SkFixedToScalar(glyph.fAdvanceX) * alignMul * textRatio; 1196 SkScalar advanceX = SkFixedToScalar(glyph.fAdvanceX) * alignMul * textRatio;
1215 SkScalar advanceY = SkFixedToScalar(glyph.fAdvanceY) * alignMul * textRatio; 1197 SkScalar advanceY = SkFixedToScalar(glyph.fAdvanceY) * alignMul * textRatio;
1216 1198
1217 if (!this->dfAppendGlyph(blob, 1199 if (!this->dfAppendGlyph(blob,
1218 runIndex, 1200 runIndex,
1219 GrGlyph::Pack(glyph.getGlyphID(), 1201 glyph,
1220 glyph.getSubXFixed(),
1221 glyph.getSubYFixed(),
1222 GrGlyph::kDistance_MaskSt yle),
1223 x - advanceX, y - advanceY, color, 1202 x - advanceX, y - advanceY, color,
1224 fontScaler, 1203 fontScaler,
1225 clipRect, 1204 clipRect,
1226 textRatio, 1205 textRatio,
1227 viewMatrix)) { 1206 viewMatrix)) {
1228 // couldn't append, send to fallback 1207 // couldn't append, send to fallback
1229 fallbackTxt->append(SkToInt(text-lastText), lastText); 1208 fallbackTxt->append(SkToInt(text-lastText), lastText);
1230 *fallbackPos->append() = pos[0]; 1209 *fallbackPos->append() = pos[0];
1231 if (2 == scalarsPerPosition) { 1210 if (2 == scalarsPerPosition) {
1232 *fallbackPos->append() = pos[1]; 1211 *fallbackPos->append() = pos[1];
1233 } 1212 }
1234 } 1213 }
1235 } 1214 }
1236 pos += scalarsPerPosition; 1215 pos += scalarsPerPosition;
1237 } 1216 }
1238 } 1217 }
1239 } 1218 }
1240 1219
1241 void GrAtlasTextContext::bmpAppendGlyph(GrAtlasTextBlob* blob, int runIndex, 1220 void GrAtlasTextContext::bmpAppendGlyph(GrAtlasTextBlob* blob, int runIndex,
1242 GrGlyph::PackedID packed, 1221 const SkGlyph& skGlyph,
1243 int vx, int vy, GrColor color, GrFontSca ler* scaler, 1222 int vx, int vy, GrColor color, GrFontSca ler* scaler,
1244 const SkIRect& clipRect) { 1223 const SkIRect& clipRect) {
1245 Run& run = blob->fRuns[runIndex]; 1224 Run& run = blob->fRuns[runIndex];
1246 if (!fCurrStrike) { 1225 if (!fCurrStrike) {
1247 fCurrStrike = fContext->getBatchFontCache()->getStrike(scaler); 1226 fCurrStrike = fContext->getBatchFontCache()->getStrike(scaler);
1248 run.fStrike.reset(SkRef(fCurrStrike)); 1227 run.fStrike.reset(SkRef(fCurrStrike));
1249 } 1228 }
1250 1229
1251 GrGlyph* glyph = fCurrStrike->getGlyph(packed, scaler); 1230 GrGlyph::PackedID id = GrGlyph::Pack(skGlyph.getGlyphID(),
1231 skGlyph.getSubXFixed(),
1232 skGlyph.getSubYFixed(),
1233 GrGlyph::kCoverage_MaskStyle);
1234 GrGlyph* glyph = fCurrStrike->getGlyph(skGlyph, id, scaler);
1252 if (!glyph) { 1235 if (!glyph) {
1253 return; 1236 return;
1254 } 1237 }
1255 1238
1256 int x = vx + glyph->fBounds.fLeft; 1239 int x = vx + glyph->fBounds.fLeft;
1257 int y = vy + glyph->fBounds.fTop; 1240 int y = vy + glyph->fBounds.fTop;
1258 1241
1259 // keep them as ints until we've done the clip-test 1242 // keep them as ints until we've done the clip-test
1260 int width = glyph->fBounds.width(); 1243 int width = glyph->fBounds.width();
1261 int height = glyph->fBounds.height(); 1244 int height = glyph->fBounds.height();
1262 1245
1263 #if 0 1246 #if 0
1264 // Not checking the clip bounds might introduce a performance regression. H owever, its not 1247 // Not checking the clip bounds might introduce a performance regression. H owever, its not
1265 // clear if this is still true today with the larger tiles we use in Chrome. For repositionable 1248 // clear if this is still true today with the larger tiles we use in Chrome. For repositionable
1266 // blobs, we want to make sure we have all of the glyphs, so clipping them o ut is not ideal. 1249 // blobs, we want to make sure we have all of the glyphs, so clipping them o ut is not ideal.
1267 // We could store the cliprect in the key, but then we'd lose the ability to do integer scrolls 1250 // We could store the cliprect in the key, but then we'd lose the ability to do integer scrolls
1268 // TODO verify this 1251 // TODO verify this
1269 // check if we clipped out 1252 // check if we clipped out
1270 if (clipRect.quickReject(x, y, x + width, y + height)) { 1253 if (clipRect.quickReject(x, y, x + width, y + height)) {
1271 return; 1254 return;
1272 } 1255 }
1273 #endif 1256 #endif
1274 1257
1275 // If the glyph is too large we fall back to paths 1258 // If the glyph is too large we fall back to paths
1276 if (glyph->fTooLargeForAtlas) { 1259 if (glyph->fTooLargeForAtlas) {
1277 this->appendGlyphPath(blob, glyph, scaler, SkIntToScalar(vx), SkIntToSca lar(vy)); 1260 this->appendGlyphPath(blob, glyph, scaler, skGlyph, SkIntToScalar(vx), S kIntToScalar(vy));
1278 return; 1261 return;
1279 } 1262 }
1280 1263
1281 GrMaskFormat format = glyph->fMaskFormat; 1264 GrMaskFormat format = glyph->fMaskFormat;
1282 1265
1283 PerSubRunInfo* subRun = &run.fSubRunInfo.back(); 1266 PerSubRunInfo* subRun = &run.fSubRunInfo.back();
1284 if (run.fInitialized && subRun->fMaskFormat != format) { 1267 if (run.fInitialized && subRun->fMaskFormat != format) {
1285 subRun = &run.fSubRunInfo.push_back(); 1268 subRun = &run.fSubRunInfo.push_back();
1286 } 1269 }
1287 1270
1288 run.fInitialized = true; 1271 run.fInitialized = true;
1289 1272
1290 size_t vertexStride = get_vertex_stride(format); 1273 size_t vertexStride = get_vertex_stride(format);
1291 1274
1292 SkRect r; 1275 SkRect r;
1293 r.fLeft = SkIntToScalar(x); 1276 r.fLeft = SkIntToScalar(x);
1294 r.fTop = SkIntToScalar(y); 1277 r.fTop = SkIntToScalar(y);
1295 r.fRight = r.fLeft + SkIntToScalar(width); 1278 r.fRight = r.fLeft + SkIntToScalar(width);
1296 r.fBottom = r.fTop + SkIntToScalar(height); 1279 r.fBottom = r.fTop + SkIntToScalar(height);
1297 subRun->fMaskFormat = format; 1280 subRun->fMaskFormat = format;
1298 this->appendGlyphCommon(blob, &run, subRun, r, color, vertexStride, kA8_GrMa skFormat == format, 1281 this->appendGlyphCommon(blob, &run, subRun, r, color, vertexStride, kA8_GrMa skFormat == format,
1299 glyph); 1282 glyph);
1300 } 1283 }
1301 1284
1302 bool GrAtlasTextContext::dfAppendGlyph(GrAtlasTextBlob* blob, int runIndex, 1285 bool GrAtlasTextContext::dfAppendGlyph(GrAtlasTextBlob* blob, int runIndex,
1303 GrGlyph::PackedID packed, 1286 const SkGlyph& skGlyph,
1304 SkScalar sx, SkScalar sy, GrColor color, 1287 SkScalar sx, SkScalar sy, GrColor color,
1305 GrFontScaler* scaler, 1288 GrFontScaler* scaler,
1306 const SkIRect& clipRect, 1289 const SkIRect& clipRect,
1307 SkScalar textRatio, const SkMatrix& viewM atrix) { 1290 SkScalar textRatio, const SkMatrix& viewM atrix) {
1308 Run& run = blob->fRuns[runIndex]; 1291 Run& run = blob->fRuns[runIndex];
1309 if (!fCurrStrike) { 1292 if (!fCurrStrike) {
1310 fCurrStrike = fContext->getBatchFontCache()->getStrike(scaler); 1293 fCurrStrike = fContext->getBatchFontCache()->getStrike(scaler);
1311 run.fStrike.reset(SkRef(fCurrStrike)); 1294 run.fStrike.reset(SkRef(fCurrStrike));
1312 } 1295 }
1313 1296
1314 GrGlyph* glyph = fCurrStrike->getGlyph(packed, scaler); 1297 GrGlyph::PackedID id = GrGlyph::Pack(skGlyph.getGlyphID(),
1298 skGlyph.getSubXFixed(),
1299 skGlyph.getSubYFixed(),
1300 GrGlyph::kDistance_MaskStyle);
1301 GrGlyph* glyph = fCurrStrike->getGlyph(skGlyph, id, scaler);
1315 if (!glyph) { 1302 if (!glyph) {
1316 return true; 1303 return true;
1317 } 1304 }
1318 1305
1319 // fallback to color glyph support 1306 // fallback to color glyph support
1320 if (kA8_GrMaskFormat != glyph->fMaskFormat) { 1307 if (kA8_GrMaskFormat != glyph->fMaskFormat) {
1321 return false; 1308 return false;
1322 } 1309 }
1323 1310
1324 SkScalar dx = SkIntToScalar(glyph->fBounds.fLeft + SK_DistanceFieldInset); 1311 SkScalar dx = SkIntToScalar(glyph->fBounds.fLeft + SK_DistanceFieldInset);
(...skipping 18 matching lines...) Expand all
1343 SkScalarTruncToInt(dstRect.top()), 1330 SkScalarTruncToInt(dstRect.top()),
1344 SkScalarTruncToInt(dstRect.right()), 1331 SkScalarTruncToInt(dstRect.right()),
1345 SkScalarTruncToInt(dstRect.bottom()))) { 1332 SkScalarTruncToInt(dstRect.bottom()))) {
1346 return true; 1333 return true;
1347 } 1334 }
1348 #endif 1335 #endif
1349 1336
1350 // TODO combine with the above 1337 // TODO combine with the above
1351 // If the glyph is too large we fall back to paths 1338 // If the glyph is too large we fall back to paths
1352 if (glyph->fTooLargeForAtlas) { 1339 if (glyph->fTooLargeForAtlas) {
1353 this->appendGlyphPath(blob, glyph, scaler, sx - dx, sy - dy); 1340 this->appendGlyphPath(blob, glyph, scaler, skGlyph, sx - dx, sy - dy);
1354 return true; 1341 return true;
1355 } 1342 }
1356 1343
1357 PerSubRunInfo* subRun = &run.fSubRunInfo.back(); 1344 PerSubRunInfo* subRun = &run.fSubRunInfo.back();
1358 SkASSERT(glyph->fMaskFormat == kA8_GrMaskFormat); 1345 SkASSERT(glyph->fMaskFormat == kA8_GrMaskFormat);
1359 subRun->fMaskFormat = kA8_GrMaskFormat; 1346 subRun->fMaskFormat = kA8_GrMaskFormat;
1360 1347
1361 size_t vertexStride = get_vertex_stride_df(kA8_GrMaskFormat, subRun->fUseLCD Text); 1348 size_t vertexStride = get_vertex_stride_df(kA8_GrMaskFormat, subRun->fUseLCD Text);
1362 1349
1363 bool useColorVerts = !subRun->fUseLCDText; 1350 bool useColorVerts = !subRun->fUseLCDText;
1364 this->appendGlyphCommon(blob, &run, subRun, glyphRect, color, vertexStride, useColorVerts, 1351 this->appendGlyphCommon(blob, &run, subRun, glyphRect, color, vertexStride, useColorVerts,
1365 glyph); 1352 glyph);
1366 return true; 1353 return true;
1367 } 1354 }
1368 1355
1369 inline void GrAtlasTextContext::appendGlyphPath(GrAtlasTextBlob* blob, GrGlyph* glyph, 1356 inline void GrAtlasTextContext::appendGlyphPath(GrAtlasTextBlob* blob, GrGlyph* glyph,
1370 GrFontScaler* scaler, SkScalar x , SkScalar y) { 1357 GrFontScaler* scaler, const SkGl yph& skGlyph,
1358 SkScalar x, SkScalar y) {
1371 if (NULL == glyph->fPath) { 1359 if (NULL == glyph->fPath) {
1372 SkPath* path = SkNEW(SkPath); 1360 const SkPath* glyphPath = scaler->getGlyphPath(skGlyph);
1373 if (!scaler->getGlyphPath(glyph->glyphID(), path)) { 1361 if (!glyphPath) {
1374 // flag the glyph as being dead?
1375 SkDELETE(path);
1376 return; 1362 return;
1377 } 1363 }
1378 glyph->fPath = path; 1364
1365 glyph->fPath = SkNEW_ARGS(SkPath, (*glyphPath));
1379 } 1366 }
1380 SkASSERT(glyph->fPath);
1381 blob->fBigGlyphs.push_back(GrAtlasTextBlob::BigGlyph(*glyph->fPath, x, y)); 1367 blob->fBigGlyphs.push_back(GrAtlasTextBlob::BigGlyph(*glyph->fPath, x, y));
1382 } 1368 }
1383 1369
1384 inline void GrAtlasTextContext::appendGlyphCommon(GrAtlasTextBlob* blob, Run* ru n, 1370 inline void GrAtlasTextContext::appendGlyphCommon(GrAtlasTextBlob* blob, Run* ru n,
1385 Run::SubRunInfo* subRun, 1371 Run::SubRunInfo* subRun,
1386 const SkRect& positions, GrCol or color, 1372 const SkRect& positions, GrCol or color,
1387 size_t vertexStride, bool useV ertexColor, 1373 size_t vertexStride, bool useV ertexColor,
1388 GrGlyph* glyph) { 1374 GrGlyph* glyph) {
1389 blob->fGlyphs[subRun->fGlyphEndIndex] = glyph; 1375 blob->fGlyphs[subRun->fGlyphEndIndex] = glyph;
1390 run->fVertexBounds.joinNonEmptyArg(positions); 1376 run->fVertexBounds.joinNonEmptyArg(positions);
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
1679 regenerateGlyphs = true; 1665 regenerateGlyphs = true;
1680 strike = fFontCache->getStrike(scaler); 1666 strike = fFontCache->getStrike(scaler);
1681 } else { 1667 } else {
1682 strike = run.fStrike; 1668 strike = run.fStrike;
1683 } 1669 }
1684 } 1670 }
1685 1671
1686 for (int glyphIdx = 0; glyphIdx < glyphCount; glyphIdx++) { 1672 for (int glyphIdx = 0; glyphIdx < glyphCount; glyphIdx++) {
1687 if (regenerateTextureCoords) { 1673 if (regenerateTextureCoords) {
1688 size_t glyphOffset = glyphIdx + info.fGlyphStartIndex; 1674 size_t glyphOffset = glyphIdx + info.fGlyphStartIndex;
1689 GrGlyph* glyph; 1675
1676 GrGlyph* glyph = blob->fGlyphs[glyphOffset];
1677 GrGlyph::PackedID id = glyph->fPackedID;
1678 const SkGlyph& skGlyph = scaler->grToSkGlyph(id);
1690 if (regenerateGlyphs) { 1679 if (regenerateGlyphs) {
1691 // Get the id from the old glyph, and use the new st rike to lookup 1680 // Get the id from the old glyph, and use the new st rike to lookup
1692 // the glyph. 1681 // the glyph.
1693 glyph = blob->fGlyphs[glyphOffset]; 1682 blob->fGlyphs[glyphOffset] = strike->getGlyph(skGlyp h, id, scaler);
1694 blob->fGlyphs[glyphOffset] = strike->getGlyph(glyph- >fPackedID,
1695 scaler );
1696 } 1683 }
1697 glyph = blob->fGlyphs[glyphOffset]; 1684 glyph = blob->fGlyphs[glyphOffset];
1698 SkASSERT(glyph); 1685 SkASSERT(glyph);
1699 SkASSERT(glyph->fMaskFormat == this->maskFormat()); 1686 SkASSERT(id == glyph->fPackedID &&
1687 glyph->fMaskFormat == this->maskFormat());
1700 1688
1701 if (!fFontCache->hasGlyph(glyph) && 1689 if (!fFontCache->hasGlyph(glyph) &&
1702 !strike->addGlyphToAtlas(batchTarget, glyph, scaler) ) { 1690 !strike->addGlyphToAtlas(batchTarget, glyph, scaler, skGlyph)) {
1703 this->flush(batchTarget, &flushInfo); 1691 this->flush(batchTarget, &flushInfo);
1704 batchTarget->initDraw(gp, pipeline); 1692 batchTarget->initDraw(gp, pipeline);
1705 brokenRun = glyphIdx > 0; 1693 brokenRun = glyphIdx > 0;
1706 1694
1707 SkDEBUGCODE(bool success =) strike->addGlyphToAtlas( batchTarget, 1695 SkDEBUGCODE(bool success =) strike->addGlyphToAtlas( batchTarget,
1708 glyph, 1696 glyph,
1709 scaler); 1697 scaler,
1698 skGlyph);
1710 SkASSERT(success); 1699 SkASSERT(success);
1711 } 1700 }
1712 fFontCache->addGlyphToBulkAndSetUseToken(&info.fBulkUseT oken, glyph, 1701 fFontCache->addGlyphToBulkAndSetUseToken(&info.fBulkUseT oken, glyph,
1713 batchTarget->cu rrentToken()); 1702 batchTarget->cu rrentToken());
1714 1703
1715 // Texture coords are the last vertex attribute so we ge t a pointer to the 1704 // Texture coords are the last vertex attribute so we ge t a pointer to the
1716 // first one and then map with stride in regenerateTextu reCoords 1705 // first one and then map with stride in regenerateTextu reCoords
1717 intptr_t vertex = reinterpret_cast<intptr_t>(blob->fVert ices); 1706 intptr_t vertex = reinterpret_cast<intptr_t>(blob->fVert ices);
1718 vertex += info.fVertexStartIndex; 1707 vertex += info.fVertexStartIndex;
1719 vertex += vertexStride * glyphIdx * kVerticesPerGlyph; 1708 vertex += vertexStride * glyphIdx * kVerticesPerGlyph;
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
2291 gTextContext->createDrawTextBlob(rt, clip, grPaint, skPaint, viewMat rix, text, 2280 gTextContext->createDrawTextBlob(rt, clip, grPaint, skPaint, viewMat rix, text,
2292 static_cast<size_t>(textLen), 0, 0, noClip)); 2281 static_cast<size_t>(textLen), 0, 0, noClip));
2293 2282
2294 SkScalar transX = static_cast<SkScalar>(random->nextU()); 2283 SkScalar transX = static_cast<SkScalar>(random->nextU());
2295 SkScalar transY = static_cast<SkScalar>(random->nextU()); 2284 SkScalar transY = static_cast<SkScalar>(random->nextU());
2296 const GrAtlasTextBlob::Run::SubRunInfo& info = blob->fRuns[0].fSubRunInfo[0] ; 2285 const GrAtlasTextBlob::Run::SubRunInfo& info = blob->fRuns[0].fSubRunInfo[0] ;
2297 return gTextContext->createBatch(blob, info, textLen, 0, 0, color, transX, t ransY, skPaint); 2286 return gTextContext->createBatch(blob, info, textLen, 0, 0, color, transX, t ransY, skPaint);
2298 } 2287 }
2299 2288
2300 #endif 2289 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrAtlasTextContext.h ('k') | src/gpu/GrBatchFontCache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698