aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/text
diff options
context:
space:
mode:
authorGravatar Khushal <khushalsagar@chromium.org>2018-05-22 12:13:12 -0700
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-05-22 19:49:45 +0000
commit35e0a1a6908492c754156d1abb785da3a9ce2a6b (patch)
tree0651f6dd710aecaec047ebcfb475053d832c8970 /src/gpu/text
parent1c5489412de12ab9afdbc0085e65418ca8753b43 (diff)
fonts: Add support for distance field text to font remoting.
R=jvanverth@google.com, herb@google.com Bug: skia:7913 Change-Id: Id3f5b3e75005be9a7234df774268359b406c99a8 Reviewed-on: https://skia-review.googlesource.com/128970 Reviewed-by: Brian Salomon <bsalomon@google.com> Reviewed-by: Jim Van Verth <jvanverth@google.com> Commit-Queue: Khusal Sagar <khushalsagar@chromium.org>
Diffstat (limited to 'src/gpu/text')
-rw-r--r--src/gpu/text/GrAtlasTextContext.cpp68
-rw-r--r--src/gpu/text/GrAtlasTextContext.h24
2 files changed, 54 insertions, 38 deletions
diff --git a/src/gpu/text/GrAtlasTextContext.cpp b/src/gpu/text/GrAtlasTextContext.cpp
index 8c964ba35e..1f06cfefba 100644
--- a/src/gpu/text/GrAtlasTextContext.cpp
+++ b/src/gpu/text/GrAtlasTextContext.cpp
@@ -41,14 +41,8 @@ static const int kDefaultMaxDistanceFieldFontSize = 2 * kLargeDFFontSize;
#endif
GrAtlasTextContext::GrAtlasTextContext(const Options& options)
- : fDistanceAdjustTable(new GrDistanceFieldAdjustTable) {
- fMaxDistanceFieldFontSize = options.fMaxDistanceFieldFontSize < 0.f
- ? kDefaultMaxDistanceFieldFontSize
- : options.fMaxDistanceFieldFontSize;
- fMinDistanceFieldFontSize = options.fMinDistanceFieldFontSize < 0.f
- ? kDefaultMinDistanceFieldFontSize
- : options.fMinDistanceFieldFontSize;
- fDistanceFieldVerticesAlwaysHaveW = options.fDistanceFieldVerticesAlwaysHaveW;
+ : fDistanceAdjustTable(new GrDistanceFieldAdjustTable), fOptions(options) {
+ SanitizeOptions(&fOptions);
}
std::unique_ptr<GrAtlasTextContext> GrAtlasTextContext::Make(const Options& options) {
@@ -211,7 +205,8 @@ void GrAtlasTextContext::regenerateTextBlob(GrAtlasTextBlob* cacheBlob,
}
cacheBlob->setRunPaintFlags(run, runPaint.skPaint().getFlags());
- if (this->canDrawAsDistanceFields(runPaint, viewMatrix, props, shaderCaps)) {
+ if (CanDrawAsDistanceFields(runPaint, viewMatrix, props,
+ shaderCaps.supportsDistanceFieldText(), fOptions)) {
switch (it.positioning()) {
case SkTextBlob::kDefault_Positioning: {
this->drawDFText(cacheBlob, run, glyphCache, props, runPaint, scalerContextFlags,
@@ -274,7 +269,8 @@ GrAtlasTextContext::makeDrawTextBlob(GrTextBlobCache* blobCache,
blob->initThrowawayBlob(viewMatrix, x, y);
blob->setRunPaintFlags(0, paint.skPaint().getFlags());
- if (this->canDrawAsDistanceFields(paint, viewMatrix, props, shaderCaps)) {
+ if (CanDrawAsDistanceFields(paint, viewMatrix, props, shaderCaps.supportsDistanceFieldText(),
+ fOptions)) {
this->drawDFText(blob.get(), 0, glyphCache, props, paint, scalerContextFlags, viewMatrix,
text, byteLength, x, y);
} else {
@@ -304,7 +300,8 @@ GrAtlasTextContext::makeDrawPosTextBlob(GrTextBlobCache* blobCache,
blob->initThrowawayBlob(viewMatrix, offset.x(), offset.y());
blob->setRunPaintFlags(0, paint.skPaint().getFlags());
- if (this->canDrawAsDistanceFields(paint, viewMatrix, props, shaderCaps)) {
+ if (CanDrawAsDistanceFields(paint, viewMatrix, props, shaderCaps.supportsDistanceFieldText(),
+ fOptions)) {
this->drawDFPosText(blob.get(), 0, glyphCache, props, paint, scalerContextFlags, viewMatrix,
text, byteLength, pos, scalarsPerPosition, offset);
} else {
@@ -565,16 +562,26 @@ void GrAtlasTextContext::BmpAppendGlyph(GrAtlasTextBlob* blob, int runIndex,
textRatio, true);
}
-bool GrAtlasTextContext::canDrawAsDistanceFields(const SkPaint& skPaint, const SkMatrix& viewMatrix,
+void GrAtlasTextContext::SanitizeOptions(Options* options) {
+ if (options->fMaxDistanceFieldFontSize < 0.f) {
+ options->fMaxDistanceFieldFontSize = kDefaultMaxDistanceFieldFontSize;
+ }
+ if (options->fMinDistanceFieldFontSize < 0.f) {
+ options->fMinDistanceFieldFontSize = kDefaultMinDistanceFieldFontSize;
+ }
+}
+
+bool GrAtlasTextContext::CanDrawAsDistanceFields(const SkPaint& skPaint, const SkMatrix& viewMatrix,
const SkSurfaceProps& props,
- const GrShaderCaps& caps) const {
+ bool contextSupportsDistanceFieldText,
+ const Options& options) {
if (!viewMatrix.hasPerspective()) {
SkScalar maxScale = viewMatrix.getMaxScale();
SkScalar scaledTextSize = maxScale * skPaint.getTextSize();
// Hinted text looks far better at small resolutions
// Scaling up beyond 2x yields undesireable artifacts
- if (scaledTextSize < fMinDistanceFieldFontSize ||
- scaledTextSize > fMaxDistanceFieldFontSize) {
+ if (scaledTextSize < options.fMinDistanceFieldFontSize ||
+ scaledTextSize > options.fMaxDistanceFieldFontSize) {
return false;
}
@@ -589,7 +596,7 @@ bool GrAtlasTextContext::canDrawAsDistanceFields(const SkPaint& skPaint, const S
}
// mask filters modify alpha, which doesn't translate well to distance
- if (skPaint.getMaskFilter() || !caps.shaderDerivativeSupport()) {
+ if (skPaint.getMaskFilter() || !contextSupportsDistanceFieldText) {
return false;
}
@@ -601,10 +608,12 @@ bool GrAtlasTextContext::canDrawAsDistanceFields(const SkPaint& skPaint, const S
return true;
}
-void GrAtlasTextContext::initDistanceFieldPaint(GrAtlasTextBlob* blob,
+void GrAtlasTextContext::InitDistanceFieldPaint(GrAtlasTextBlob* blob,
SkPaint* skPaint,
+ const SkMatrix& viewMatrix,
+ const Options& options,
SkScalar* textRatio,
- const SkMatrix& viewMatrix) const {
+ SkScalerContextFlags* flags) {
SkScalar textSize = skPaint->getTextSize();
SkScalar scaledTextSize = textSize;
@@ -627,7 +636,7 @@ void GrAtlasTextContext::initDistanceFieldPaint(GrAtlasTextBlob* blob,
SkScalar dfMaskScaleFloor;
SkScalar dfMaskScaleCeil;
if (scaledTextSize <= kSmallDFFontLimit) {
- dfMaskScaleFloor = fMinDistanceFieldFontSize;
+ dfMaskScaleFloor = options.fMinDistanceFieldFontSize;
dfMaskScaleCeil = kSmallDFFontLimit;
*textRatio = textSize / kSmallDFFontSize;
skPaint->setTextSize(SkIntToScalar(kSmallDFFontSize));
@@ -638,7 +647,7 @@ void GrAtlasTextContext::initDistanceFieldPaint(GrAtlasTextBlob* blob,
skPaint->setTextSize(SkIntToScalar(kMediumDFFontSize));
} else {
dfMaskScaleFloor = kMediumDFFontLimit;
- dfMaskScaleCeil = fMaxDistanceFieldFontSize;
+ dfMaskScaleCeil = options.fMaxDistanceFieldFontSize;
*textRatio = textSize / kLargeDFFontSize;
skPaint->setTextSize(SkIntToScalar(kLargeDFFontSize));
}
@@ -651,7 +660,10 @@ void GrAtlasTextContext::initDistanceFieldPaint(GrAtlasTextBlob* blob,
// against these values to decide if we can reuse or not(ie, will a given scale change our mip
// level)
SkASSERT(dfMaskScaleFloor <= scaledTextSize && scaledTextSize <= dfMaskScaleCeil);
- blob->setMinAndMaxScale(dfMaskScaleFloor / scaledTextSize, dfMaskScaleCeil / scaledTextSize);
+ if (blob) {
+ blob->setMinAndMaxScale(dfMaskScaleFloor / scaledTextSize,
+ dfMaskScaleCeil / scaledTextSize);
+ }
skPaint->setAntiAlias(true);
skPaint->setLCDRenderText(false);
@@ -660,6 +672,10 @@ void GrAtlasTextContext::initDistanceFieldPaint(GrAtlasTextBlob* blob,
skPaint->setSubpixelText(true);
skPaint->setMaskFilter(GrSDFMaskFilter::Make());
+
+ // We apply the fake-gamma by altering the distance in the shader, so we ignore the
+ // passed-in scaler context flags. (It's only used when we fall-back to bitmap text).
+ *flags = SkScalerContextFlags::kNone;
}
void GrAtlasTextContext::drawDFText(GrAtlasTextBlob* blob, int runIndex,
@@ -745,12 +761,13 @@ void GrAtlasTextContext::drawDFPosText(GrAtlasTextBlob* blob, int runIndex,
return;
}
- bool hasWCoord = viewMatrix.hasPerspective() || fDistanceFieldVerticesAlwaysHaveW;
+ bool hasWCoord = viewMatrix.hasPerspective() || fOptions.fDistanceFieldVerticesAlwaysHaveW;
// Setup distance field paint and text ratio
SkScalar textRatio;
SkPaint dfPaint(paint);
- this->initDistanceFieldPaint(blob, &dfPaint, &textRatio, viewMatrix);
+ SkScalerContextFlags flags;
+ InitDistanceFieldPaint(blob, &dfPaint, viewMatrix, fOptions, &textRatio, &flags);
blob->setHasDistanceField();
blob->setSubRunHasDistanceFields(runIndex, paint.skPaint().isLCDRenderText(),
paint.skPaint().isAntiAlias(), hasWCoord);
@@ -760,10 +777,7 @@ void GrAtlasTextContext::drawDFPosText(GrAtlasTextBlob* blob, int runIndex,
sk_sp<GrTextStrike> currStrike;
{
- // We apply the fake-gamma by altering the distance in the shader, so we ignore the
- // passed-in scaler context flags. (It's only used when we fall-back to bitmap text).
- auto cache = blob->setupCache(runIndex, props, SkScalerContextFlags::kNone, dfPaint,
- nullptr);
+ auto cache = blob->setupCache(runIndex, props, flags, dfPaint, nullptr);
SkPaint::GlyphCacheProc glyphCacheProc =
SkPaint::GetGlyphCacheProc(dfPaint.getTextEncoding(), true);
diff --git a/src/gpu/text/GrAtlasTextContext.h b/src/gpu/text/GrAtlasTextContext.h
index 1342ee7ac8..e2531b3d59 100644
--- a/src/gpu/text/GrAtlasTextContext.h
+++ b/src/gpu/text/GrAtlasTextContext.h
@@ -60,6 +60,18 @@ public:
const SkMatrix& viewMatrix, const char* text,
int x, int y);
+ static void SanitizeOptions(Options* options);
+ static bool CanDrawAsDistanceFields(const SkPaint& skPaint, const SkMatrix& viewMatrix,
+ const SkSurfaceProps& props,
+ bool contextSupportsDistanceFieldText,
+ const Options& options);
+ static void InitDistanceFieldPaint(GrAtlasTextBlob* blob,
+ SkPaint* skPaint,
+ const SkMatrix& viewMatrix,
+ const Options& options,
+ SkScalar* textRatio,
+ SkScalerContextFlags* flags);
+
private:
GrAtlasTextContext(const Options& options);
@@ -158,9 +170,6 @@ private:
const SkPoint& offset);
// functions for appending distance field text
- bool canDrawAsDistanceFields(const SkPaint& skPaint, const SkMatrix& viewMatrix,
- const SkSurfaceProps& props, const GrShaderCaps& caps) const;
-
void drawDFText(GrAtlasTextBlob* blob, int runIndex, GrGlyphCache*, const SkSurfaceProps&,
const GrTextUtils::Paint& paint, SkScalerContextFlags scalerContextFlags,
const SkMatrix& viewMatrix, const char text[], size_t byteLength, SkScalar x,
@@ -173,11 +182,6 @@ private:
size_t byteLength, const SkScalar pos[], int scalarsPerPosition,
const SkPoint& offset) const;
- void initDistanceFieldPaint(GrAtlasTextBlob* blob,
- SkPaint* skPaint,
- SkScalar* textRatio,
- const SkMatrix& viewMatrix) const;
-
static void BmpAppendGlyph(GrAtlasTextBlob*, int runIndex, GrGlyphCache*,
sk_sp<GrTextStrike>*, const SkGlyph&, SkScalar sx, SkScalar sy,
GrColor color, SkGlyphCache*, SkScalar textRatio);
@@ -190,9 +194,7 @@ private:
sk_sp<const GrDistanceFieldAdjustTable> fDistanceAdjustTable;
- SkScalar fMinDistanceFieldFontSize;
- SkScalar fMaxDistanceFieldFontSize;
- bool fDistanceFieldVerticesAlwaysHaveW;
+ Options fOptions;
#if GR_TEST_UTILS
static const SkScalerContextFlags kTextBlobOpScalerContextFlags =