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