| Index: src/gpu/GrTextUtils.cpp
|
| diff --git a/src/gpu/GrTextUtils.cpp b/src/gpu/GrTextUtils.cpp
|
| index e56b5cb29e07c6901963cf5a141fe903b1c9b904..293ea4d891edac7888625522a1563b663bb9e675 100644
|
| --- a/src/gpu/GrTextUtils.cpp
|
| +++ b/src/gpu/GrTextUtils.cpp
|
| @@ -7,16 +7,122 @@
|
|
|
| #include "GrTextUtils.h"
|
|
|
| +#include "GrAtlasTextBlob.h"
|
| +#include "GrBatchFontCache.h"
|
| #include "GrBlurUtils.h"
|
| #include "GrContext.h"
|
| #include "GrDrawContext.h"
|
| +#include "GrTextContext.h"
|
| #include "SkDrawProcs.h"
|
| +#include "SkFindAndPlaceGlyph.h"
|
| #include "SkGlyphCache.h"
|
| #include "SkPaint.h"
|
| #include "SkRect.h"
|
| #include "SkTextMapStateProc.h"
|
| #include "SkTextToPathIter.h"
|
|
|
| +void GrTextUtils::DrawBmpText(GrAtlasTextBlob* blob, int runIndex,
|
| + GrBatchFontCache* fontCache,
|
| + SkGlyphCache* cache, const SkPaint& skPaint,
|
| + GrColor color,
|
| + const SkMatrix& viewMatrix,
|
| + const char text[], size_t byteLength,
|
| + SkScalar x, SkScalar y) {
|
| + SkASSERT(byteLength == 0 || text != nullptr);
|
| +
|
| + // nothing to draw
|
| + if (text == nullptr || byteLength == 0) {
|
| + return;
|
| + }
|
| +
|
| + GrBatchTextStrike* currStrike = nullptr;
|
| +
|
| + // Get GrFontScaler from cache
|
| + GrFontScaler* fontScaler = GrTextContext::GetGrFontScaler(cache);
|
| +
|
| + SkFindAndPlaceGlyph::ProcessText(
|
| + skPaint.getTextEncoding(), text, byteLength,
|
| + {x, y}, viewMatrix, skPaint.getTextAlign(),
|
| + cache,
|
| + [&](const SkGlyph& glyph, SkPoint position, SkPoint rounding) {
|
| + position += rounding;
|
| + BmpAppendGlyph(
|
| + blob, runIndex, fontCache, &currStrike, glyph,
|
| + SkScalarFloorToInt(position.fX), SkScalarFloorToInt(position.fY),
|
| + color, fontScaler);
|
| + }
|
| + );
|
| +}
|
| +
|
| +void GrTextUtils::DrawBmpPosText(GrAtlasTextBlob* blob, int runIndex,
|
| + GrBatchFontCache* fontCache,
|
| + SkGlyphCache* cache, const SkPaint& skPaint,
|
| + GrColor color,
|
| + const SkMatrix& viewMatrix,
|
| + const char text[], size_t byteLength,
|
| + const SkScalar pos[], int scalarsPerPosition,
|
| + const SkPoint& offset) {
|
| + SkASSERT(byteLength == 0 || text != nullptr);
|
| + SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
|
| +
|
| + // nothing to draw
|
| + if (text == nullptr || byteLength == 0) {
|
| + return;
|
| + }
|
| +
|
| + GrBatchTextStrike* currStrike = nullptr;
|
| +
|
| + // Get GrFontScaler from cache
|
| + GrFontScaler* fontScaler = GrTextContext::GetGrFontScaler(cache);
|
| +
|
| + SkFindAndPlaceGlyph::ProcessPosText(
|
| + skPaint.getTextEncoding(), text, byteLength,
|
| + offset, viewMatrix, pos, scalarsPerPosition,
|
| + skPaint.getTextAlign(), cache,
|
| + [&](const SkGlyph& glyph, SkPoint position, SkPoint rounding) {
|
| + position += rounding;
|
| + BmpAppendGlyph(
|
| + blob, runIndex, fontCache, &currStrike, glyph,
|
| + SkScalarFloorToInt(position.fX), SkScalarFloorToInt(position.fY),
|
| + color, fontScaler);
|
| + }
|
| + );
|
| +}
|
| +
|
| +void GrTextUtils::BmpAppendGlyph(GrAtlasTextBlob* blob, int runIndex,
|
| + GrBatchFontCache* fontCache,
|
| + GrBatchTextStrike** strike, const SkGlyph& skGlyph,
|
| + int vx, int vy, GrColor color, GrFontScaler* scaler) {
|
| + if (!*strike) {
|
| + *strike = fontCache->getStrike(scaler);
|
| + }
|
| +
|
| + GrGlyph::PackedID id = GrGlyph::Pack(skGlyph.getGlyphID(),
|
| + skGlyph.getSubXFixed(),
|
| + skGlyph.getSubYFixed(),
|
| + GrGlyph::kCoverage_MaskStyle);
|
| + GrGlyph* glyph = (*strike)->getGlyph(skGlyph, id, scaler);
|
| + if (!glyph) {
|
| + return;
|
| + }
|
| +
|
| + int x = vx + glyph->fBounds.fLeft;
|
| + int y = vy + glyph->fBounds.fTop;
|
| +
|
| + // keep them as ints until we've done the clip-test
|
| + int width = glyph->fBounds.width();
|
| + int height = glyph->fBounds.height();
|
| +
|
| + SkRect r;
|
| + r.fLeft = SkIntToScalar(x);
|
| + r.fTop = SkIntToScalar(y);
|
| + r.fRight = r.fLeft + SkIntToScalar(width);
|
| + r.fBottom = r.fTop + SkIntToScalar(height);
|
| +
|
| + blob->appendGlyph(runIndex, r, color, *strike, glyph, scaler, skGlyph,
|
| + SkIntToScalar(vx), SkIntToScalar(vy), 1.0f, false);
|
| +}
|
| +
|
| void GrTextUtils::DrawTextAsPath(GrContext* context, GrDrawContext* dc,
|
| const GrClip& clip,
|
| const SkPaint& skPaint, const SkMatrix& viewMatrix,
|
|
|