| 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 "GrAtlas.h" | 9 #include "GrAtlas.h" |
| 10 #include "GrBatch.h" | 10 #include "GrBatch.h" |
| (...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 *textRatio = textSize / kLargeDFFontSize; | 538 *textRatio = textSize / kLargeDFFontSize; |
| 539 skPaint->setTextSize(SkIntToScalar(kLargeDFFontSize)); | 539 skPaint->setTextSize(SkIntToScalar(kLargeDFFontSize)); |
| 540 } | 540 } |
| 541 | 541 |
| 542 skPaint->setLCDRenderText(false); | 542 skPaint->setLCDRenderText(false); |
| 543 skPaint->setAutohinted(false); | 543 skPaint->setAutohinted(false); |
| 544 skPaint->setHinting(SkPaint::kNormal_Hinting); | 544 skPaint->setHinting(SkPaint::kNormal_Hinting); |
| 545 skPaint->setSubpixelText(true); | 545 skPaint->setSubpixelText(true); |
| 546 } | 546 } |
| 547 | 547 |
| 548 inline void GrAtlasTextContext::fallbackDrawPosText(GrRenderTarget* rt, const Gr
Clip& clip, | 548 inline void GrAtlasTextContext::fallbackDrawPosText(BitmapTextBlob* blob, |
| 549 GrRenderTarget* rt, const Gr
Clip& clip, |
| 549 const GrPaint& paint, | 550 const GrPaint& paint, |
| 550 const SkPaint& skPaint, | 551 const SkPaint& skPaint, |
| 551 const SkMatrix& viewMatrix, | 552 const SkMatrix& viewMatrix, |
| 552 const SkTDArray<char>& fallb
ackTxt, | 553 const SkTDArray<char>& fallb
ackTxt, |
| 553 const SkTDArray<SkScalar>& f
allbackPos, | 554 const SkTDArray<SkScalar>& f
allbackPos, |
| 554 int scalarsPerPosition, | 555 int scalarsPerPosition, |
| 555 const SkPoint& offset, | 556 const SkPoint& offset, |
| 556 const SkIRect& clipRect) { | 557 const SkIRect& clipRect) { |
| 557 int glyphCount = fallbackTxt.count(); | 558 SkASSERT(fallbackTxt.count()); |
| 558 SkASSERT(glyphCount); | 559 Run& run = blob->fRuns[0]; |
| 559 // TODO currently we have to create a whole new blob for fallback text. Thi
s is because | 560 PerSubRunInfo& subRun = run.fSubRunInfo.push_back(); |
| 560 // they have a different descriptor and we currently only have one descripto
r per run. | 561 subRun.fOverrideDescriptor.reset(SkNEW(SkAutoDescriptor)); |
| 561 // We should fix this and allow an override descriptor on each subrun | 562 skPaint.getScalerContextDescriptor(subRun.fOverrideDescriptor, |
| 562 SkAutoTUnref<BitmapTextBlob> blob(fCache->createBlob(glyphCount, 1, kGrayTex
tVASize)); | 563 &fDeviceProperties, &viewMatrix, false); |
| 563 blob->fViewMatrix = viewMatrix; | 564 SkGlyphCache* cache = SkGlyphCache::DetachCache(run.fTypeface, |
| 564 | 565 subRun.fOverrideDescriptor->
getDesc()); |
| 565 SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], skPaint, &viewMatrix
, false); | |
| 566 this->internalDrawBMPPosText(blob, 0, cache, skPaint, paint.getColor(), view
Matrix, | 566 this->internalDrawBMPPosText(blob, 0, cache, skPaint, paint.getColor(), view
Matrix, |
| 567 fallbackTxt.begin(), fallbackTxt.count(), | 567 fallbackTxt.begin(), fallbackTxt.count(), |
| 568 fallbackPos.begin(), scalarsPerPosition, offset
, clipRect); | 568 fallbackPos.begin(), scalarsPerPosition, offset
, clipRect); |
| 569 SkGlyphCache::AttachCache(cache); | 569 SkGlyphCache::AttachCache(cache); |
| 570 this->flush(fContext->getTextTarget(), blob, rt, skPaint, paint, clip); | |
| 571 } | 570 } |
| 572 | 571 |
| 573 inline GrAtlasTextContext::BitmapTextBlob* | 572 inline GrAtlasTextContext::BitmapTextBlob* |
| 574 GrAtlasTextContext::setupDFBlob(int glyphCount, const SkPaint& origPaint, | 573 GrAtlasTextContext::setupDFBlob(int glyphCount, const SkPaint& origPaint, |
| 575 const SkMatrix& viewMatrix, SkGlyphCache** cache
, | 574 const SkMatrix& viewMatrix, SkGlyphCache** cache
, |
| 576 SkPaint* dfPaint, SkScalar* textRatio) { | 575 SkPaint* dfPaint, SkScalar* textRatio) { |
| 577 BitmapTextBlob* blob = fCache->createBlob(glyphCount, 1, kGrayTextVASize); | 576 BitmapTextBlob* blob = fCache->createBlob(glyphCount, 1, kGrayTextVASize); |
| 578 | 577 |
| 579 *dfPaint = origPaint; | 578 *dfPaint = origPaint; |
| 580 this->initDistanceFieldPaint(dfPaint, textRatio, viewMatrix); | 579 this->initDistanceFieldPaint(dfPaint, textRatio, viewMatrix); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 603 SkAutoTUnref<BitmapTextBlob> blob(this->setupDFBlob(glyphCount, skPaint,
viewMatrix, &cache, | 602 SkAutoTUnref<BitmapTextBlob> blob(this->setupDFBlob(glyphCount, skPaint,
viewMatrix, &cache, |
| 604 &dfPaint, &textRatio
)); | 603 &dfPaint, &textRatio
)); |
| 605 | 604 |
| 606 SkTDArray<char> fallbackTxt; | 605 SkTDArray<char> fallbackTxt; |
| 607 SkTDArray<SkScalar> fallbackPos; | 606 SkTDArray<SkScalar> fallbackPos; |
| 608 SkPoint offset; | 607 SkPoint offset; |
| 609 this->internalDrawDFText(blob, 0, cache, dfPaint, paint.getColor(), view
Matrix, text, | 608 this->internalDrawDFText(blob, 0, cache, dfPaint, paint.getColor(), view
Matrix, text, |
| 610 byteLength, x, y, clipRect, textRatio, &fallbac
kTxt, &fallbackPos, | 609 byteLength, x, y, clipRect, textRatio, &fallbac
kTxt, &fallbackPos, |
| 611 &offset, skPaint); | 610 &offset, skPaint); |
| 612 SkGlyphCache::AttachCache(cache); | 611 SkGlyphCache::AttachCache(cache); |
| 613 this->flush(fContext->getTextTarget(), blob, rt, dfPaint, paint, clip); | |
| 614 if (fallbackTxt.count()) { | 612 if (fallbackTxt.count()) { |
| 615 this->fallbackDrawPosText(rt, clip, paint, skPaint, viewMatrix, fall
backTxt, | 613 this->fallbackDrawPosText(blob, rt, clip, paint, skPaint, viewMatrix
, fallbackTxt, |
| 616 fallbackPos, 2, offset, clipRect); | 614 fallbackPos, 2, offset, clipRect); |
| 617 } | 615 } |
| 616 this->flush(fContext->getTextTarget(), blob, rt, skPaint, paint, clip); |
| 618 } else { | 617 } else { |
| 619 SkAutoTUnref<BitmapTextBlob> blob(fCache->createBlob(glyphCount, 1, kGra
yTextVASize)); | 618 SkAutoTUnref<BitmapTextBlob> blob(fCache->createBlob(glyphCount, 1, kGra
yTextVASize)); |
| 620 blob->fViewMatrix = viewMatrix; | 619 blob->fViewMatrix = viewMatrix; |
| 621 | 620 |
| 622 SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], skPaint, &viewMa
trix, false); | 621 SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], skPaint, &viewMa
trix, false); |
| 623 this->internalDrawBMPText(blob, 0, cache, skPaint, paint.getColor(), vie
wMatrix, text, | 622 this->internalDrawBMPText(blob, 0, cache, skPaint, paint.getColor(), vie
wMatrix, text, |
| 624 byteLength, x, y, clipRect); | 623 byteLength, x, y, clipRect); |
| 625 SkGlyphCache::AttachCache(cache); | 624 SkGlyphCache::AttachCache(cache); |
| 626 this->flush(fContext->getTextTarget(), blob, rt, skPaint, paint, clip); | 625 this->flush(fContext->getTextTarget(), blob, rt, skPaint, paint, clip); |
| 627 } | 626 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 644 SkGlyphCache* cache; | 643 SkGlyphCache* cache; |
| 645 SkAutoTUnref<BitmapTextBlob> blob(this->setupDFBlob(glyphCount, skPaint,
viewMatrix, &cache, | 644 SkAutoTUnref<BitmapTextBlob> blob(this->setupDFBlob(glyphCount, skPaint,
viewMatrix, &cache, |
| 646 &dfPaint, &textRatio
)); | 645 &dfPaint, &textRatio
)); |
| 647 | 646 |
| 648 SkTDArray<char> fallbackTxt; | 647 SkTDArray<char> fallbackTxt; |
| 649 SkTDArray<SkScalar> fallbackPos; | 648 SkTDArray<SkScalar> fallbackPos; |
| 650 this->internalDrawDFPosText(blob, 0, cache, dfPaint, paint.getColor(), v
iewMatrix, text, | 649 this->internalDrawDFPosText(blob, 0, cache, dfPaint, paint.getColor(), v
iewMatrix, text, |
| 651 byteLength, pos, scalarsPerPosition, offset,
clipRect, | 650 byteLength, pos, scalarsPerPosition, offset,
clipRect, |
| 652 textRatio, &fallbackTxt, &fallbackPos); | 651 textRatio, &fallbackTxt, &fallbackPos); |
| 653 SkGlyphCache::AttachCache(cache); | 652 SkGlyphCache::AttachCache(cache); |
| 654 this->flush(fContext->getTextTarget(), blob, rt, dfPaint, paint, clip); | |
| 655 if (fallbackTxt.count()) { | 653 if (fallbackTxt.count()) { |
| 656 this->fallbackDrawPosText(rt, clip, paint, skPaint, viewMatrix, fall
backTxt, | 654 this->fallbackDrawPosText(blob, rt, clip, paint, skPaint, viewMatrix
, fallbackTxt, |
| 657 fallbackPos, scalarsPerPosition, offset, c
lipRect); | 655 fallbackPos, scalarsPerPosition, offset, c
lipRect); |
| 658 } | 656 } |
| 657 this->flush(fContext->getTextTarget(), blob, rt, skPaint, paint, clip); |
| 659 } else { | 658 } else { |
| 660 SkAutoTUnref<BitmapTextBlob> blob(fCache->createBlob(glyphCount, 1, kGra
yTextVASize)); | 659 SkAutoTUnref<BitmapTextBlob> blob(fCache->createBlob(glyphCount, 1, kGra
yTextVASize)); |
| 661 blob->fViewMatrix = viewMatrix; | 660 blob->fViewMatrix = viewMatrix; |
| 662 SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], skPaint, &viewMa
trix, false); | 661 SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], skPaint, &viewMa
trix, false); |
| 663 this->internalDrawBMPPosText(blob, 0, cache, skPaint, paint.getColor(),
viewMatrix, text, | 662 this->internalDrawBMPPosText(blob, 0, cache, skPaint, paint.getColor(),
viewMatrix, text, |
| 664 byteLength, pos, scalarsPerPosition, offset
, clipRect); | 663 byteLength, pos, scalarsPerPosition, offset
, clipRect); |
| 665 SkGlyphCache::AttachCache(cache); | 664 SkGlyphCache::AttachCache(cache); |
| 666 this->flush(fContext->getTextTarget(), blob, rt, skPaint, paint, clip); | 665 this->flush(fContext->getTextTarget(), blob, rt, skPaint, paint, clip); |
| 667 } | 666 } |
| 668 } | 667 } |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1127 this->appendGlyphPath(blob, glyph, scaler, vx, vy); | 1126 this->appendGlyphPath(blob, glyph, scaler, vx, vy); |
| 1128 return; | 1127 return; |
| 1129 } | 1128 } |
| 1130 | 1129 |
| 1131 Run& run = blob->fRuns[runIndex]; | 1130 Run& run = blob->fRuns[runIndex]; |
| 1132 | 1131 |
| 1133 GrMaskFormat format = glyph->fMaskFormat; | 1132 GrMaskFormat format = glyph->fMaskFormat; |
| 1134 | 1133 |
| 1135 PerSubRunInfo* subRun = &run.fSubRunInfo.back(); | 1134 PerSubRunInfo* subRun = &run.fSubRunInfo.back(); |
| 1136 if (run.fInitialized && subRun->fMaskFormat != format) { | 1135 if (run.fInitialized && subRun->fMaskFormat != format) { |
| 1137 PerSubRunInfo* newSubRun = &run.fSubRunInfo.push_back(); | 1136 subRun = &run.fSubRunInfo.push_back(); |
| 1138 newSubRun->fGlyphStartIndex = subRun->fGlyphEndIndex; | |
| 1139 newSubRun->fGlyphEndIndex = subRun->fGlyphEndIndex; | |
| 1140 | |
| 1141 newSubRun->fVertexStartIndex = subRun->fVertexEndIndex; | |
| 1142 newSubRun->fVertexEndIndex = subRun->fVertexEndIndex; | |
| 1143 | |
| 1144 subRun = newSubRun; | |
| 1145 } | 1137 } |
| 1146 | 1138 |
| 1147 run.fInitialized = true; | 1139 run.fInitialized = true; |
| 1148 | 1140 |
| 1149 size_t vertexStride = get_vertex_stride(format); | 1141 size_t vertexStride = get_vertex_stride(format); |
| 1150 | 1142 |
| 1151 SkRect r; | 1143 SkRect r; |
| 1152 r.fLeft = SkIntToScalar(x); | 1144 r.fLeft = SkIntToScalar(x); |
| 1153 r.fTop = SkIntToScalar(y); | 1145 r.fTop = SkIntToScalar(y); |
| 1154 r.fRight = r.fLeft + SkIntToScalar(width); | 1146 r.fRight = r.fLeft + SkIntToScalar(width); |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1468 // should be pretty rare, so we just always regenerate in those case
s | 1460 // should be pretty rare, so we just always regenerate in those case
s |
| 1469 if (regenerateTextureCoords || regenerateColors || regeneratePositio
ns) { | 1461 if (regenerateTextureCoords || regenerateColors || regeneratePositio
ns) { |
| 1470 // first regenerate texture coordinates / colors if need be | 1462 // first regenerate texture coordinates / colors if need be |
| 1471 const SkDescriptor* desc = NULL; | 1463 const SkDescriptor* desc = NULL; |
| 1472 SkGlyphCache* cache = NULL; | 1464 SkGlyphCache* cache = NULL; |
| 1473 GrFontScaler* scaler = NULL; | 1465 GrFontScaler* scaler = NULL; |
| 1474 GrBatchTextStrike* strike = NULL; | 1466 GrBatchTextStrike* strike = NULL; |
| 1475 bool brokenRun = false; | 1467 bool brokenRun = false; |
| 1476 if (regenerateTextureCoords) { | 1468 if (regenerateTextureCoords) { |
| 1477 info.fBulkUseToken.reset(); | 1469 info.fBulkUseToken.reset(); |
| 1478 desc = run.fDescriptor.getDesc(); | 1470 desc = info.fOverrideDescriptor ? info.fOverrideDescriptor->
getDesc() : |
| 1471 run.fDescriptor.getDesc(); |
| 1479 cache = SkGlyphCache::DetachCache(run.fTypeface, desc); | 1472 cache = SkGlyphCache::DetachCache(run.fTypeface, desc); |
| 1480 scaler = GrTextContext::GetGrFontScaler(cache); | 1473 scaler = GrTextContext::GetGrFontScaler(cache); |
| 1481 strike = fFontCache->getStrike(scaler); | 1474 strike = fFontCache->getStrike(scaler); |
| 1482 } | 1475 } |
| 1483 for (int glyphIdx = 0; glyphIdx < glyphCount; glyphIdx++) { | 1476 for (int glyphIdx = 0; glyphIdx < glyphCount; glyphIdx++) { |
| 1484 GrGlyph::PackedID glyphID = blob->fGlyphIDs[glyphIdx + info.
fGlyphStartIndex]; | 1477 GrGlyph::PackedID glyphID = blob->fGlyphIDs[glyphIdx + info.
fGlyphStartIndex]; |
| 1485 | 1478 |
| 1486 if (regenerateTextureCoords) { | 1479 if (regenerateTextureCoords) { |
| 1487 // Upload the glyph only if needed | 1480 // Upload the glyph only if needed |
| 1488 GrGlyph* glyph = strike->getGlyph(glyphID, scaler); | 1481 GrGlyph* glyph = strike->getGlyph(glyphID, scaler); |
| (...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2007 pipelineBuilder.setFromPaint(grPaint, rt, clip); | 2000 pipelineBuilder.setFromPaint(grPaint, rt, clip); |
| 2008 | 2001 |
| 2009 GrColor color = grPaint.getColor(); | 2002 GrColor color = grPaint.getColor(); |
| 2010 for (int run = 0; run < cacheBlob->fRunCount; run++) { | 2003 for (int run = 0; run < cacheBlob->fRunCount; run++) { |
| 2011 this->flushRun(target, &pipelineBuilder, cacheBlob, run, color, 0, 0, sk
Paint); | 2004 this->flushRun(target, &pipelineBuilder, cacheBlob, run, color, 0, 0, sk
Paint); |
| 2012 } | 2005 } |
| 2013 | 2006 |
| 2014 // Now flush big glyphs | 2007 // Now flush big glyphs |
| 2015 this->flushBigGlyphs(cacheBlob, rt, grPaint, clip, 0, 0); | 2008 this->flushBigGlyphs(cacheBlob, rt, grPaint, clip, 0, 0); |
| 2016 } | 2009 } |
| OLD | NEW |