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 1203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1214 } | 1214 } |
1215 } | 1215 } |
1216 | 1216 |
1217 void GrAtlasTextContext::bmpAppendGlyph(GrAtlasTextBlob* blob, int runIndex, | 1217 void GrAtlasTextContext::bmpAppendGlyph(GrAtlasTextBlob* blob, int runIndex, |
1218 const SkGlyph& skGlyph, | 1218 const SkGlyph& skGlyph, |
1219 int vx, int vy, GrColor color, GrFontSca
ler* scaler, | 1219 int vx, int vy, GrColor color, GrFontSca
ler* scaler, |
1220 const SkIRect& clipRect) { | 1220 const SkIRect& clipRect) { |
1221 Run& run = blob->fRuns[runIndex]; | 1221 Run& run = blob->fRuns[runIndex]; |
1222 if (!fCurrStrike) { | 1222 if (!fCurrStrike) { |
1223 fCurrStrike = fContext->getBatchFontCache()->getStrike(scaler); | 1223 fCurrStrike = fContext->getBatchFontCache()->getStrike(scaler); |
1224 run.fStrike.reset(SkRef(fCurrStrike)); | |
1225 } | 1224 } |
1226 | 1225 |
1227 GrGlyph::PackedID id = GrGlyph::Pack(skGlyph.getGlyphID(), | 1226 GrGlyph::PackedID id = GrGlyph::Pack(skGlyph.getGlyphID(), |
1228 skGlyph.getSubXFixed(), | 1227 skGlyph.getSubXFixed(), |
1229 skGlyph.getSubYFixed(), | 1228 skGlyph.getSubYFixed(), |
1230 GrGlyph::kCoverage_MaskStyle); | 1229 GrGlyph::kCoverage_MaskStyle); |
1231 GrGlyph* glyph = fCurrStrike->getGlyph(skGlyph, id, scaler); | 1230 GrGlyph* glyph = fCurrStrike->getGlyph(skGlyph, id, scaler); |
1232 if (!glyph) { | 1231 if (!glyph) { |
1233 return; | 1232 return; |
1234 } | 1233 } |
(...skipping 21 matching lines...) Expand all Loading... |
1256 if (glyph->fTooLargeForAtlas) { | 1255 if (glyph->fTooLargeForAtlas) { |
1257 this->appendGlyphPath(blob, glyph, scaler, skGlyph, SkIntToScalar(vx), S
kIntToScalar(vy)); | 1256 this->appendGlyphPath(blob, glyph, scaler, skGlyph, SkIntToScalar(vx), S
kIntToScalar(vy)); |
1258 return; | 1257 return; |
1259 } | 1258 } |
1260 | 1259 |
1261 GrMaskFormat format = glyph->fMaskFormat; | 1260 GrMaskFormat format = glyph->fMaskFormat; |
1262 | 1261 |
1263 PerSubRunInfo* subRun = &run.fSubRunInfo.back(); | 1262 PerSubRunInfo* subRun = &run.fSubRunInfo.back(); |
1264 if (run.fInitialized && subRun->fMaskFormat != format) { | 1263 if (run.fInitialized && subRun->fMaskFormat != format) { |
1265 subRun = &run.push_back(); | 1264 subRun = &run.push_back(); |
| 1265 subRun->fStrike.reset(SkRef(fCurrStrike)); |
| 1266 } else if (!run.fInitialized) { |
| 1267 subRun->fStrike.reset(SkRef(fCurrStrike)); |
1266 } | 1268 } |
1267 | 1269 |
1268 run.fInitialized = true; | 1270 run.fInitialized = true; |
1269 | 1271 |
1270 size_t vertexStride = get_vertex_stride(format); | 1272 size_t vertexStride = get_vertex_stride(format); |
1271 | 1273 |
1272 SkRect r; | 1274 SkRect r; |
1273 r.fLeft = SkIntToScalar(x); | 1275 r.fLeft = SkIntToScalar(x); |
1274 r.fTop = SkIntToScalar(y); | 1276 r.fTop = SkIntToScalar(y); |
1275 r.fRight = r.fLeft + SkIntToScalar(width); | 1277 r.fRight = r.fLeft + SkIntToScalar(width); |
1276 r.fBottom = r.fTop + SkIntToScalar(height); | 1278 r.fBottom = r.fTop + SkIntToScalar(height); |
1277 subRun->fMaskFormat = format; | 1279 subRun->fMaskFormat = format; |
1278 this->appendGlyphCommon(blob, &run, subRun, r, color, vertexStride, kA8_GrMa
skFormat == format, | 1280 this->appendGlyphCommon(blob, &run, subRun, r, color, vertexStride, kA8_GrMa
skFormat == format, |
1279 glyph); | 1281 glyph); |
1280 } | 1282 } |
1281 | 1283 |
1282 bool GrAtlasTextContext::dfAppendGlyph(GrAtlasTextBlob* blob, int runIndex, | 1284 bool GrAtlasTextContext::dfAppendGlyph(GrAtlasTextBlob* blob, int runIndex, |
1283 const SkGlyph& skGlyph, | 1285 const SkGlyph& skGlyph, |
1284 SkScalar sx, SkScalar sy, GrColor color, | 1286 SkScalar sx, SkScalar sy, GrColor color, |
1285 GrFontScaler* scaler, | 1287 GrFontScaler* scaler, |
1286 const SkIRect& clipRect, | 1288 const SkIRect& clipRect, |
1287 SkScalar textRatio, const SkMatrix& viewM
atrix) { | 1289 SkScalar textRatio, const SkMatrix& viewM
atrix) { |
1288 Run& run = blob->fRuns[runIndex]; | 1290 Run& run = blob->fRuns[runIndex]; |
1289 if (!fCurrStrike) { | 1291 if (!fCurrStrike) { |
1290 fCurrStrike = fContext->getBatchFontCache()->getStrike(scaler); | 1292 fCurrStrike = fContext->getBatchFontCache()->getStrike(scaler); |
1291 run.fStrike.reset(SkRef(fCurrStrike)); | |
1292 } | 1293 } |
1293 | 1294 |
1294 GrGlyph::PackedID id = GrGlyph::Pack(skGlyph.getGlyphID(), | 1295 GrGlyph::PackedID id = GrGlyph::Pack(skGlyph.getGlyphID(), |
1295 skGlyph.getSubXFixed(), | 1296 skGlyph.getSubXFixed(), |
1296 skGlyph.getSubYFixed(), | 1297 skGlyph.getSubYFixed(), |
1297 GrGlyph::kDistance_MaskStyle); | 1298 GrGlyph::kDistance_MaskStyle); |
1298 GrGlyph* glyph = fCurrStrike->getGlyph(skGlyph, id, scaler); | 1299 GrGlyph* glyph = fCurrStrike->getGlyph(skGlyph, id, scaler); |
1299 if (!glyph) { | 1300 if (!glyph) { |
1300 return true; | 1301 return true; |
1301 } | 1302 } |
(...skipping 30 matching lines...) Expand all Loading... |
1332 #endif | 1333 #endif |
1333 | 1334 |
1334 // TODO combine with the above | 1335 // TODO combine with the above |
1335 // If the glyph is too large we fall back to paths | 1336 // If the glyph is too large we fall back to paths |
1336 if (glyph->fTooLargeForAtlas) { | 1337 if (glyph->fTooLargeForAtlas) { |
1337 this->appendGlyphPath(blob, glyph, scaler, skGlyph, sx - dx, sy - dy); | 1338 this->appendGlyphPath(blob, glyph, scaler, skGlyph, sx - dx, sy - dy); |
1338 return true; | 1339 return true; |
1339 } | 1340 } |
1340 | 1341 |
1341 PerSubRunInfo* subRun = &run.fSubRunInfo.back(); | 1342 PerSubRunInfo* subRun = &run.fSubRunInfo.back(); |
| 1343 if (!run.fInitialized) { |
| 1344 subRun->fStrike.reset(SkRef(fCurrStrike)); |
| 1345 } |
| 1346 run.fInitialized = true; |
1342 SkASSERT(glyph->fMaskFormat == kA8_GrMaskFormat); | 1347 SkASSERT(glyph->fMaskFormat == kA8_GrMaskFormat); |
1343 subRun->fMaskFormat = kA8_GrMaskFormat; | 1348 subRun->fMaskFormat = kA8_GrMaskFormat; |
1344 | 1349 |
1345 size_t vertexStride = get_vertex_stride_df(kA8_GrMaskFormat, subRun->fUseLCD
Text); | 1350 size_t vertexStride = get_vertex_stride_df(kA8_GrMaskFormat, subRun->fUseLCD
Text); |
1346 | 1351 |
1347 bool useColorVerts = !subRun->fUseLCDText; | 1352 bool useColorVerts = !subRun->fUseLCDText; |
1348 this->appendGlyphCommon(blob, &run, subRun, glyphRect, color, vertexStride,
useColorVerts, | 1353 this->appendGlyphCommon(blob, &run, subRun, glyphRect, color, vertexStride,
useColorVerts, |
1349 glyph); | 1354 glyph); |
1350 return true; | 1355 return true; |
1351 } | 1356 } |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1596 SkTypeface* typeface = NULL; | 1601 SkTypeface* typeface = NULL; |
1597 | 1602 |
1598 for (int i = 0; i < fGeoCount; i++) { | 1603 for (int i = 0; i < fGeoCount; i++) { |
1599 Geometry& args = fGeoData[i]; | 1604 Geometry& args = fGeoData[i]; |
1600 Blob* blob = args.fBlob; | 1605 Blob* blob = args.fBlob; |
1601 Run& run = blob->fRuns[args.fRun]; | 1606 Run& run = blob->fRuns[args.fRun]; |
1602 TextInfo& info = run.fSubRunInfo[args.fSubRun]; | 1607 TextInfo& info = run.fSubRunInfo[args.fSubRun]; |
1603 | 1608 |
1604 uint64_t currentAtlasGen = fFontCache->atlasGeneration(maskFormat); | 1609 uint64_t currentAtlasGen = fFontCache->atlasGeneration(maskFormat); |
1605 bool regenerateTextureCoords = info.fAtlasGeneration != currentAtlas
Gen || | 1610 bool regenerateTextureCoords = info.fAtlasGeneration != currentAtlas
Gen || |
1606 run.fStrike->isAbandoned(); | 1611 info.fStrike->isAbandoned(); |
1607 bool regenerateColors; | 1612 bool regenerateColors; |
1608 if (usesDistanceFields) { | 1613 if (usesDistanceFields) { |
1609 regenerateColors = !isLCD && run.fColor != args.fColor; | 1614 regenerateColors = !isLCD && run.fColor != args.fColor; |
1610 } else { | 1615 } else { |
1611 regenerateColors = kA8_GrMaskFormat == maskFormat && run.fColor
!= args.fColor; | 1616 regenerateColors = kA8_GrMaskFormat == maskFormat && run.fColor
!= args.fColor; |
1612 } | 1617 } |
1613 bool regeneratePositions = args.fTransX != 0.f || args.fTransY != 0.
f; | 1618 bool regeneratePositions = args.fTransX != 0.f || args.fTransY != 0.
f; |
1614 int glyphCount = info.fGlyphEndIndex - info.fGlyphStartIndex; | 1619 int glyphCount = info.fGlyphEndIndex - info.fGlyphStartIndex; |
1615 | 1620 |
1616 // We regenerate both texture coords and colors in the blob itself,
and update the | 1621 // We regenerate both texture coords and colors in the blob itself,
and update the |
(...skipping 27 matching lines...) Expand all Loading... |
1644 run.fOverrideDescriptor->getDe
sc() : | 1649 run.fOverrideDescriptor->getDe
sc() : |
1645 run.fDescriptor.getDesc(); | 1650 run.fDescriptor.getDesc(); |
1646 if (!cache || !SkTypeface::Equal(typeface, run.fTypeface) || | 1651 if (!cache || !SkTypeface::Equal(typeface, run.fTypeface) || |
1647 !(desc->equals(*newDesc))) { | 1652 !(desc->equals(*newDesc))) { |
1648 if (cache) { | 1653 if (cache) { |
1649 SkGlyphCache::AttachCache(cache); | 1654 SkGlyphCache::AttachCache(cache); |
1650 } | 1655 } |
1651 desc = newDesc; | 1656 desc = newDesc; |
1652 cache = SkGlyphCache::DetachCache(run.fTypeface, desc); | 1657 cache = SkGlyphCache::DetachCache(run.fTypeface, desc); |
1653 scaler = GrTextContext::GetGrFontScaler(cache); | 1658 scaler = GrTextContext::GetGrFontScaler(cache); |
1654 strike = run.fStrike; | 1659 strike = info.fStrike; |
1655 typeface = run.fTypeface; | 1660 typeface = run.fTypeface; |
1656 } | 1661 } |
1657 | 1662 |
1658 if (run.fStrike->isAbandoned()) { | 1663 if (info.fStrike->isAbandoned()) { |
1659 regenerateGlyphs = true; | 1664 regenerateGlyphs = true; |
1660 strike = fFontCache->getStrike(scaler); | 1665 strike = fFontCache->getStrike(scaler); |
1661 } else { | 1666 } else { |
1662 strike = run.fStrike; | 1667 strike = info.fStrike; |
1663 } | 1668 } |
1664 } | 1669 } |
1665 | 1670 |
1666 for (int glyphIdx = 0; glyphIdx < glyphCount; glyphIdx++) { | 1671 for (int glyphIdx = 0; glyphIdx < glyphCount; glyphIdx++) { |
1667 if (regenerateTextureCoords) { | 1672 if (regenerateTextureCoords) { |
1668 size_t glyphOffset = glyphIdx + info.fGlyphStartIndex; | 1673 size_t glyphOffset = glyphIdx + info.fGlyphStartIndex; |
1669 | 1674 |
1670 GrGlyph* glyph = blob->fGlyphs[glyphOffset]; | 1675 GrGlyph* glyph = blob->fGlyphs[glyphOffset]; |
1671 GrGlyph::PackedID id = glyph->fPackedID; | 1676 GrGlyph::PackedID id = glyph->fPackedID; |
1672 const SkGlyph& skGlyph = scaler->grToSkGlyph(id); | 1677 const SkGlyph& skGlyph = scaler->grToSkGlyph(id); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1725 SkScalar transY = args.fTransY; | 1730 SkScalar transY = args.fTransY; |
1726 this->regeneratePositions(vertex, vertexStride, transX,
transY); | 1731 this->regeneratePositions(vertex, vertexStride, transX,
transY); |
1727 } | 1732 } |
1728 flushInfo.fGlyphsToFlush++; | 1733 flushInfo.fGlyphsToFlush++; |
1729 } | 1734 } |
1730 | 1735 |
1731 // We my have changed the color so update it here | 1736 // We my have changed the color so update it here |
1732 run.fColor = args.fColor; | 1737 run.fColor = args.fColor; |
1733 if (regenerateTextureCoords) { | 1738 if (regenerateTextureCoords) { |
1734 if (regenerateGlyphs) { | 1739 if (regenerateGlyphs) { |
1735 run.fStrike.reset(SkRef(strike)); | 1740 info.fStrike.reset(SkRef(strike)); |
1736 } | 1741 } |
1737 info.fAtlasGeneration = brokenRun ? GrBatchAtlas::kInvalidAt
lasGeneration : | 1742 info.fAtlasGeneration = brokenRun ? GrBatchAtlas::kInvalidAt
lasGeneration : |
1738 fFontCache->atlasGenerat
ion(maskFormat); | 1743 fFontCache->atlasGenerat
ion(maskFormat); |
1739 } | 1744 } |
1740 } else { | 1745 } else { |
1741 flushInfo.fGlyphsToFlush += glyphCount; | 1746 flushInfo.fGlyphsToFlush += glyphCount; |
1742 | 1747 |
1743 // set use tokens for all of the glyphs in our subrun. This is
only valid if we | 1748 // set use tokens for all of the glyphs in our subrun. This is
only valid if we |
1744 // have a valid atlas generation | 1749 // have a valid atlas generation |
1745 fFontCache->setUseTokenBulk(info.fBulkUseToken, | 1750 fFontCache->setUseTokenBulk(info.fBulkUseToken, |
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2277 gTextContext->createDrawTextBlob(rt, clip, grPaint, skPaint, viewMat
rix, text, | 2282 gTextContext->createDrawTextBlob(rt, clip, grPaint, skPaint, viewMat
rix, text, |
2278 static_cast<size_t>(textLen), 0, 0,
noClip)); | 2283 static_cast<size_t>(textLen), 0, 0,
noClip)); |
2279 | 2284 |
2280 SkScalar transX = static_cast<SkScalar>(random->nextU()); | 2285 SkScalar transX = static_cast<SkScalar>(random->nextU()); |
2281 SkScalar transY = static_cast<SkScalar>(random->nextU()); | 2286 SkScalar transY = static_cast<SkScalar>(random->nextU()); |
2282 const GrAtlasTextBlob::Run::SubRunInfo& info = blob->fRuns[0].fSubRunInfo[0]
; | 2287 const GrAtlasTextBlob::Run::SubRunInfo& info = blob->fRuns[0].fSubRunInfo[0]
; |
2283 return gTextContext->createBatch(blob, info, textLen, 0, 0, color, transX, t
ransY, skPaint); | 2288 return gTextContext->createBatch(blob, info, textLen, 0, 0, color, transX, t
ransY, skPaint); |
2284 } | 2289 } |
2285 | 2290 |
2286 #endif | 2291 #endif |
OLD | NEW |