| 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 "GrBlurUtils.h" | 9 #include "GrBlurUtils.h" |
| 10 #include "GrDrawContext.h" | 10 #include "GrDrawContext.h" |
| (...skipping 1192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1203 | 1203 |
| 1204 // V3 | 1204 // V3 |
| 1205 position = reinterpret_cast<SkPoint*>(vertex); | 1205 position = reinterpret_cast<SkPoint*>(vertex); |
| 1206 position->set(positions.fRight, positions.fTop); | 1206 position->set(positions.fRight, positions.fTop); |
| 1207 } | 1207 } |
| 1208 | 1208 |
| 1209 subRun->fGlyphEndIndex++; | 1209 subRun->fGlyphEndIndex++; |
| 1210 subRun->fVertexEndIndex += vertexStride * GrAtlasTextBatch::kVerticesPerGlyp
h; | 1210 subRun->fVertexEndIndex += vertexStride * GrAtlasTextBatch::kVerticesPerGlyp
h; |
| 1211 } | 1211 } |
| 1212 | 1212 |
| 1213 void GrAtlasTextContext::flushRunAsPaths(GrDrawContext* dc, GrRenderTarget* rt, | 1213 void GrAtlasTextContext::flushRunAsPaths(GrDrawContext* dc, |
| 1214 const SkTextBlobRunIterator& it, | 1214 const SkTextBlobRunIterator& it, |
| 1215 const GrClip& clip, const SkPaint& skPa
int, | 1215 const GrClip& clip, const SkPaint& skPa
int, |
| 1216 SkDrawFilter* drawFilter, const SkMatri
x& viewMatrix, | 1216 SkDrawFilter* drawFilter, const SkMatri
x& viewMatrix, |
| 1217 const SkIRect& clipBounds, SkScalar x,
SkScalar y) { | 1217 const SkIRect& clipBounds, SkScalar x,
SkScalar y) { |
| 1218 SkPaint runPaint = skPaint; | 1218 SkPaint runPaint = skPaint; |
| 1219 | 1219 |
| 1220 size_t textLen = it.glyphCount() * sizeof(uint16_t); | 1220 size_t textLen = it.glyphCount() * sizeof(uint16_t); |
| 1221 const SkPoint& offset = it.offset(); | 1221 const SkPoint& offset = it.offset(); |
| 1222 | 1222 |
| 1223 it.applyFontToPaint(&runPaint); | 1223 it.applyFontToPaint(&runPaint); |
| 1224 | 1224 |
| 1225 if (drawFilter && !drawFilter->filter(&runPaint, SkDrawFilter::kText_Type))
{ | 1225 if (drawFilter && !drawFilter->filter(&runPaint, SkDrawFilter::kText_Type))
{ |
| 1226 return; | 1226 return; |
| 1227 } | 1227 } |
| 1228 | 1228 |
| 1229 runPaint.setFlags(FilterTextFlags(fSurfaceProps, runPaint)); | 1229 runPaint.setFlags(FilterTextFlags(fSurfaceProps, runPaint)); |
| 1230 | 1230 |
| 1231 switch (it.positioning()) { | 1231 switch (it.positioning()) { |
| 1232 case SkTextBlob::kDefault_Positioning: | 1232 case SkTextBlob::kDefault_Positioning: |
| 1233 this->drawTextAsPath(dc, rt, clip, runPaint, viewMatrix, | 1233 this->drawTextAsPath(dc, clip, runPaint, viewMatrix, |
| 1234 (const char *)it.glyphs(), | 1234 (const char *)it.glyphs(), |
| 1235 textLen, x + offset.x(), y + offset.y(), clipBo
unds); | 1235 textLen, x + offset.x(), y + offset.y(), clipBo
unds); |
| 1236 break; | 1236 break; |
| 1237 case SkTextBlob::kHorizontal_Positioning: | 1237 case SkTextBlob::kHorizontal_Positioning: |
| 1238 this->drawPosTextAsPath(dc, rt, clip, runPaint, viewMatrix, | 1238 this->drawPosTextAsPath(dc, clip, runPaint, viewMatrix, |
| 1239 (const char*)it.glyphs(), | 1239 (const char*)it.glyphs(), |
| 1240 textLen, it.pos(), 1, SkPoint::Make(x, y + o
ffset.y()), | 1240 textLen, it.pos(), 1, SkPoint::Make(x, y + o
ffset.y()), |
| 1241 clipBounds); | 1241 clipBounds); |
| 1242 break; | 1242 break; |
| 1243 case SkTextBlob::kFull_Positioning: | 1243 case SkTextBlob::kFull_Positioning: |
| 1244 this->drawPosTextAsPath(dc, rt, clip, runPaint, viewMatrix, | 1244 this->drawPosTextAsPath(dc, clip, runPaint, viewMatrix, |
| 1245 (const char*)it.glyphs(), | 1245 (const char*)it.glyphs(), |
| 1246 textLen, it.pos(), 2, SkPoint::Make(x, y), c
lipBounds); | 1246 textLen, it.pos(), 2, SkPoint::Make(x, y), c
lipBounds); |
| 1247 break; | 1247 break; |
| 1248 } | 1248 } |
| 1249 } | 1249 } |
| 1250 | 1250 |
| 1251 inline GrDrawBatch* | 1251 inline GrDrawBatch* |
| 1252 GrAtlasTextContext::createBatch(GrAtlasTextBlob* cacheBlob, const PerSubRunInfo&
info, | 1252 GrAtlasTextContext::createBatch(GrAtlasTextBlob* cacheBlob, const PerSubRunInfo&
info, |
| 1253 int glyphCount, int run, int subRun, | 1253 int glyphCount, int run, int subRun, |
| 1254 GrColor color, SkScalar transX, SkScalar transY, | 1254 GrColor color, SkScalar transX, SkScalar transY, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1302 } | 1302 } |
| 1303 | 1303 |
| 1304 SkAutoTUnref<GrDrawBatch> batch(this->createBatch(cacheBlob, info, glyph
Count, run, | 1304 SkAutoTUnref<GrDrawBatch> batch(this->createBatch(cacheBlob, info, glyph
Count, run, |
| 1305 subRun, color, transX,
transY, | 1305 subRun, color, transX,
transY, |
| 1306 skPaint)); | 1306 skPaint)); |
| 1307 dc->drawBatch(pipelineBuilder, batch); | 1307 dc->drawBatch(pipelineBuilder, batch); |
| 1308 } | 1308 } |
| 1309 } | 1309 } |
| 1310 | 1310 |
| 1311 inline void GrAtlasTextContext::flushBigGlyphs(GrAtlasTextBlob* cacheBlob, | 1311 inline void GrAtlasTextContext::flushBigGlyphs(GrAtlasTextBlob* cacheBlob, |
| 1312 GrDrawContext* dc, GrRenderTarget
* rt, | 1312 GrDrawContext* dc, |
| 1313 const GrClip& clip, const SkPaint
& skPaint, | 1313 const GrClip& clip, const SkPaint
& skPaint, |
| 1314 SkScalar transX, SkScalar transY, | 1314 SkScalar transX, SkScalar transY, |
| 1315 const SkIRect& clipBounds) { | 1315 const SkIRect& clipBounds) { |
| 1316 if (!cacheBlob->fBigGlyphs.count()) { | 1316 if (!cacheBlob->fBigGlyphs.count()) { |
| 1317 return; | 1317 return; |
| 1318 } | 1318 } |
| 1319 | 1319 |
| 1320 for (int i = 0; i < cacheBlob->fBigGlyphs.count(); i++) { | 1320 for (int i = 0; i < cacheBlob->fBigGlyphs.count(); i++) { |
| 1321 GrAtlasTextBlob::BigGlyph& bigGlyph = cacheBlob->fBigGlyphs[i]; | 1321 GrAtlasTextBlob::BigGlyph& bigGlyph = cacheBlob->fBigGlyphs[i]; |
| 1322 bigGlyph.fVx += transX; | 1322 bigGlyph.fVx += transX; |
| 1323 bigGlyph.fVy += transY; | 1323 bigGlyph.fVy += transY; |
| 1324 SkMatrix ctm; | 1324 SkMatrix ctm; |
| 1325 ctm.setScale(bigGlyph.fScale, bigGlyph.fScale); | 1325 ctm.setScale(bigGlyph.fScale, bigGlyph.fScale); |
| 1326 ctm.postTranslate(bigGlyph.fVx, bigGlyph.fVy); | 1326 ctm.postTranslate(bigGlyph.fVx, bigGlyph.fVy); |
| 1327 if (bigGlyph.fApplyVM) { | 1327 if (bigGlyph.fApplyVM) { |
| 1328 ctm.postConcat(cacheBlob->fViewMatrix); | 1328 ctm.postConcat(cacheBlob->fViewMatrix); |
| 1329 } | 1329 } |
| 1330 | 1330 |
| 1331 GrBlurUtils::drawPathWithMaskFilter(fContext, dc, rt, clip, bigGlyph.fPa
th, | 1331 GrBlurUtils::drawPathWithMaskFilter(fContext, dc, clip, bigGlyph.fPath, |
| 1332 skPaint, ctm, nullptr, clipBounds, f
alse); | 1332 skPaint, ctm, nullptr, clipBounds, f
alse); |
| 1333 } | 1333 } |
| 1334 } | 1334 } |
| 1335 | 1335 |
| 1336 void GrAtlasTextContext::flush(const SkTextBlob* blob, | 1336 void GrAtlasTextContext::flush(const SkTextBlob* blob, |
| 1337 GrAtlasTextBlob* cacheBlob, | 1337 GrAtlasTextBlob* cacheBlob, |
| 1338 GrDrawContext* dc, | 1338 GrDrawContext* dc, |
| 1339 GrRenderTarget* rt, | 1339 GrRenderTarget* rt, |
| 1340 const SkPaint& skPaint, | 1340 const SkPaint& skPaint, |
| 1341 const GrPaint& grPaint, | 1341 const GrPaint& grPaint, |
| 1342 SkDrawFilter* drawFilter, | 1342 SkDrawFilter* drawFilter, |
| 1343 const GrClip& clip, | 1343 const GrClip& clip, |
| 1344 const SkMatrix& viewMatrix, | 1344 const SkMatrix& viewMatrix, |
| 1345 const SkIRect& clipBounds, | 1345 const SkIRect& clipBounds, |
| 1346 SkScalar x, SkScalar y, | 1346 SkScalar x, SkScalar y, |
| 1347 SkScalar transX, SkScalar transY) { | 1347 SkScalar transX, SkScalar transY) { |
| 1348 // We loop through the runs of the blob, flushing each. If any run is too l
arge, then we flush | 1348 // We loop through the runs of the blob, flushing each. If any run is too l
arge, then we flush |
| 1349 // it as paths | 1349 // it as paths |
| 1350 GrPipelineBuilder pipelineBuilder(grPaint, rt, clip); | 1350 GrPipelineBuilder pipelineBuilder(grPaint, rt, clip); |
| 1351 | 1351 |
| 1352 GrColor color = grPaint.getColor(); | 1352 GrColor color = grPaint.getColor(); |
| 1353 | 1353 |
| 1354 SkTextBlobRunIterator it(blob); | 1354 SkTextBlobRunIterator it(blob); |
| 1355 for (int run = 0; !it.done(); it.next(), run++) { | 1355 for (int run = 0; !it.done(); it.next(), run++) { |
| 1356 if (cacheBlob->fRuns[run].fDrawAsPaths) { | 1356 if (cacheBlob->fRuns[run].fDrawAsPaths) { |
| 1357 this->flushRunAsPaths(dc, rt, it, clip, skPaint, | 1357 this->flushRunAsPaths(dc, it, clip, skPaint, |
| 1358 drawFilter, viewMatrix, clipBounds, x, y); | 1358 drawFilter, viewMatrix, clipBounds, x, y); |
| 1359 continue; | 1359 continue; |
| 1360 } | 1360 } |
| 1361 cacheBlob->fRuns[run].fVertexBounds.offset(transX, transY); | 1361 cacheBlob->fRuns[run].fVertexBounds.offset(transX, transY); |
| 1362 this->flushRun(dc, &pipelineBuilder, cacheBlob, run, color, | 1362 this->flushRun(dc, &pipelineBuilder, cacheBlob, run, color, |
| 1363 transX, transY, skPaint); | 1363 transX, transY, skPaint); |
| 1364 } | 1364 } |
| 1365 | 1365 |
| 1366 // Now flush big glyphs | 1366 // Now flush big glyphs |
| 1367 this->flushBigGlyphs(cacheBlob, dc, rt, clip, skPaint, transX, transY, clipB
ounds); | 1367 this->flushBigGlyphs(cacheBlob, dc, clip, skPaint, transX, transY, clipBound
s); |
| 1368 } | 1368 } |
| 1369 | 1369 |
| 1370 void GrAtlasTextContext::flush(GrAtlasTextBlob* cacheBlob, | 1370 void GrAtlasTextContext::flush(GrAtlasTextBlob* cacheBlob, |
| 1371 GrDrawContext* dc, | 1371 GrDrawContext* dc, |
| 1372 GrRenderTarget* rt, | 1372 GrRenderTarget* rt, |
| 1373 const SkPaint& skPaint, | 1373 const SkPaint& skPaint, |
| 1374 const GrPaint& grPaint, | 1374 const GrPaint& grPaint, |
| 1375 const GrClip& clip, | 1375 const GrClip& clip, |
| 1376 const SkIRect& clipBounds) { | 1376 const SkIRect& clipBounds) { |
| 1377 GrPipelineBuilder pipelineBuilder(grPaint, rt, clip); | 1377 GrPipelineBuilder pipelineBuilder(grPaint, rt, clip); |
| 1378 | 1378 |
| 1379 GrColor color = grPaint.getColor(); | 1379 GrColor color = grPaint.getColor(); |
| 1380 for (int run = 0; run < cacheBlob->fRunCount; run++) { | 1380 for (int run = 0; run < cacheBlob->fRunCount; run++) { |
| 1381 this->flushRun(dc, &pipelineBuilder, cacheBlob, run, color, 0, 0, skPain
t); | 1381 this->flushRun(dc, &pipelineBuilder, cacheBlob, run, color, 0, 0, skPain
t); |
| 1382 } | 1382 } |
| 1383 | 1383 |
| 1384 // Now flush big glyphs | 1384 // Now flush big glyphs |
| 1385 this->flushBigGlyphs(cacheBlob, dc, rt, clip, skPaint, 0, 0, clipBounds); | 1385 this->flushBigGlyphs(cacheBlob, dc, clip, skPaint, 0, 0, clipBounds); |
| 1386 } | 1386 } |
| 1387 | 1387 |
| 1388 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 1388 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 1389 | 1389 |
| 1390 #ifdef GR_TEST_UTILS | 1390 #ifdef GR_TEST_UTILS |
| 1391 | 1391 |
| 1392 DRAW_BATCH_TEST_DEFINE(TextBlobBatch) { | 1392 DRAW_BATCH_TEST_DEFINE(TextBlobBatch) { |
| 1393 static uint32_t gContextID = SK_InvalidGenID; | 1393 static uint32_t gContextID = SK_InvalidGenID; |
| 1394 static GrAtlasTextContext* gTextContext = nullptr; | 1394 static GrAtlasTextContext* gTextContext = nullptr; |
| 1395 static SkSurfaceProps gSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType
); | 1395 static SkSurfaceProps gSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType
); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1443 gTextContext->createDrawTextBlob(rt, clip, grPaint, skPaint, viewMat
rix, text, | 1443 gTextContext->createDrawTextBlob(rt, clip, grPaint, skPaint, viewMat
rix, text, |
| 1444 static_cast<size_t>(textLen), 0, 0,
noClip)); | 1444 static_cast<size_t>(textLen), 0, 0,
noClip)); |
| 1445 | 1445 |
| 1446 SkScalar transX = static_cast<SkScalar>(random->nextU()); | 1446 SkScalar transX = static_cast<SkScalar>(random->nextU()); |
| 1447 SkScalar transY = static_cast<SkScalar>(random->nextU()); | 1447 SkScalar transY = static_cast<SkScalar>(random->nextU()); |
| 1448 const GrAtlasTextBlob::Run::SubRunInfo& info = blob->fRuns[0].fSubRunInfo[0]
; | 1448 const GrAtlasTextBlob::Run::SubRunInfo& info = blob->fRuns[0].fSubRunInfo[0]
; |
| 1449 return gTextContext->createBatch(blob, info, textLen, 0, 0, color, transX, t
ransY, skPaint); | 1449 return gTextContext->createBatch(blob, info, textLen, 0, 0, color, transX, t
ransY, skPaint); |
| 1450 } | 1450 } |
| 1451 | 1451 |
| 1452 #endif | 1452 #endif |
| OLD | NEW |