Break up InitDistanceFieldPaint

Break InitDistanceFieldPaint along code that is common and,
code that is specific to GPU.

Change-Id: Ic831491829fe402a46f4e612c2598d987ae19c8c
Reviewed-on: https://skia-review.googlesource.com/c/193371
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Herb Derby <herb@google.com>
This commit is contained in:
Herb Derby 2019-02-19 11:43:12 -05:00 committed by Skia Commit-Bot
parent 8d23b1adf2
commit 881c962762
3 changed files with 75 additions and 55 deletions

View File

@ -759,18 +759,18 @@ void GrTextBlob::generateFromGlyphRunList(GrStrikeCache* glyphCache,
|| options.fDistanceFieldVerticesAlwaysHaveW;
// Setup distance field runPaint and text ratio
SkPaint dfPaint = GrTextContext::InitDistanceFieldPaint(runPaint);
SkScalar textScale;
SkPaint distanceFieldPaint{runPaint};
SkFont distanceFieldFont{runFont};
SkScalerContextFlags flags;
GrTextContext::InitDistanceFieldPaint(runFont.getSize(),
viewMatrix,
options,
this,
&distanceFieldPaint,
&distanceFieldFont,
&textScale,
&flags);
SkFont dfFont = GrTextContext::InitDistanceFieldFont(
runFont, viewMatrix, options, &textScale);
SkScalerContextFlags flags = GrTextContext::InitDistanceFieldFlags();
SkScalar minScale, maxScale;
std::tie(minScale, maxScale) = GrTextContext::InitDistanceFieldMinMaxScale(
runFont.getSize(), viewMatrix, options);
this->setMinAndMaxScale(minScale, maxScale);
this->setHasDistanceField();
run->setSubRunHasDistanceFields(
runFont.getEdging() == SkFont::Edging::kSubpixelAntiAlias,
@ -779,7 +779,7 @@ void GrTextBlob::generateFromGlyphRunList(GrStrikeCache* glyphCache,
{
SkExclusiveStrikePtr cache = SkStrikeCache::FindOrCreateStrikeExclusive(
distanceFieldFont, distanceFieldPaint, props, flags, SkMatrix::I());
dfFont, dfPaint, props, flags, SkMatrix::I());
sk_sp<GrTextStrike> currStrike = glyphCache->getStrike(cache->getDescriptor());
run->setupFont(cache->strikeSpec());
@ -1050,18 +1050,11 @@ bool SkTextBlobCacheDiffCanvas::TrackLayerDevice::maybeProcessGlyphRunForDFT(
return false;
}
SkPaint dfPaint = GrTextContext::InitDistanceFieldPaint(runPaint);
SkScalar textRatio;
SkPaint dfPaint{runPaint};
SkFont dfFont{runFont};
SkScalerContextFlags flags;
GrTextContext::InitDistanceFieldPaint(runFont.getSize(),
runMatrix,
options,
nullptr,
&dfPaint,
&dfFont,
&textRatio,
&flags);
SkFont dfFont = GrTextContext::InitDistanceFieldFont(runFont, runMatrix, options, &textRatio);
SkScalerContextFlags flags = GrTextContext::InitDistanceFieldFlags();
SkScalerContextEffects effects;
auto* sdfCache = fStrikeServer->getOrCreateCache(dfPaint, dfFont, this->surfaceProps(),
SkMatrix::I(), flags, &effects);

View File

@ -129,14 +129,7 @@ bool GrTextContext::CanDrawAsDistanceFields(const SkPaint& paint, const SkFont&
return true;
}
void GrTextContext::InitDistanceFieldPaint(const SkScalar textSize,
const SkMatrix& viewMatrix,
const Options& options,
GrTextBlob* blob,
SkPaint* skPaint,
SkFont* skFont,
SkScalar* textRatio,
SkScalerContextFlags* flags) {
SkScalar scaled_text_size(const SkScalar textSize, const SkMatrix& viewMatrix) {
SkScalar scaledTextSize = textSize;
if (viewMatrix.hasPerspective()) {
@ -153,6 +146,43 @@ void GrTextContext::InitDistanceFieldPaint(const SkScalar textSize,
}
}
return scaledTextSize;
}
SkFont GrTextContext::InitDistanceFieldFont(const SkFont& font,
const SkMatrix& viewMatrix,
const Options& options,
SkScalar* textRatio) {
SkScalar textSize = font.getSize();
SkScalar scaledTextSize = scaled_text_size(textSize, viewMatrix);
SkFont dfFont{font};
if (scaledTextSize <= kSmallDFFontLimit) {
*textRatio = textSize / kSmallDFFontSize;
dfFont.setSize(SkIntToScalar(kSmallDFFontSize));
} else if (scaledTextSize <= kMediumDFFontLimit) {
*textRatio = textSize / kMediumDFFontSize;
dfFont.setSize(SkIntToScalar(kMediumDFFontSize));
} else {
*textRatio = textSize / kLargeDFFontSize;
dfFont.setSize(SkIntToScalar(kLargeDFFontSize));
}
dfFont.setEdging(SkFont::Edging::kAntiAlias);
dfFont.setForceAutoHinting(false);
dfFont.setHinting(kNormal_SkFontHinting);
dfFont.setSubpixel(true);
return dfFont;
}
std::pair<SkScalar, SkScalar> GrTextContext::InitDistanceFieldMinMaxScale(
SkScalar textSize,
const SkMatrix& viewMatrix,
const GrTextContext::Options& options) {
SkScalar scaledTextSize = scaled_text_size(textSize, viewMatrix);
// We have three sizes of distance field text, and within each size 'bucket' there is a floor
// and ceiling. A scale outside of this range would require regenerating the distance fields
SkScalar dfMaskScaleFloor;
@ -160,18 +190,12 @@ void GrTextContext::InitDistanceFieldPaint(const SkScalar textSize,
if (scaledTextSize <= kSmallDFFontLimit) {
dfMaskScaleFloor = options.fMinDistanceFieldFontSize;
dfMaskScaleCeil = kSmallDFFontLimit;
*textRatio = textSize / kSmallDFFontSize;
skFont->setSize(SkIntToScalar(kSmallDFFontSize));
} else if (scaledTextSize <= kMediumDFFontLimit) {
dfMaskScaleFloor = kSmallDFFontLimit;
dfMaskScaleCeil = kMediumDFFontLimit;
*textRatio = textSize / kMediumDFFontSize;
skFont->setSize(SkIntToScalar(kMediumDFFontSize));
} else {
dfMaskScaleFloor = kMediumDFFontLimit;
dfMaskScaleCeil = options.fMaxDistanceFieldFontSize;
*textRatio = textSize / kLargeDFFontSize;
skFont->setSize(SkIntToScalar(kLargeDFFontSize));
}
// Because there can be multiple runs in the blob, we want the overall maxMinScale, and
@ -182,21 +206,20 @@ void GrTextContext::InitDistanceFieldPaint(const SkScalar textSize,
// 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);
if (blob) {
blob->setMinAndMaxScale(dfMaskScaleFloor / scaledTextSize,
dfMaskScaleCeil / scaledTextSize);
}
skFont->setEdging(SkFont::Edging::kAntiAlias);
skFont->setForceAutoHinting(false);
skFont->setHinting(kNormal_SkFontHinting);
skFont->setSubpixel(true);
return std::make_pair(dfMaskScaleFloor / scaledTextSize, dfMaskScaleCeil / scaledTextSize);
}
skPaint->setMaskFilter(GrSDFMaskFilter::Make());
SkPaint GrTextContext::InitDistanceFieldPaint(const SkPaint& paint) {
SkPaint dfPaint{paint};
dfPaint.setMaskFilter(GrSDFMaskFilter::Make());
return dfPaint;
}
SkScalerContextFlags GrTextContext::InitDistanceFieldFlags() {
// 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;
return SkScalerContextFlags::kNone;
}
///////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -62,14 +62,18 @@ public:
const SkSurfaceProps& props,
bool contextSupportsDistanceFieldText,
const Options& options);
static void InitDistanceFieldPaint(SkScalar textSize,
const SkMatrix& viewMatrix,
const Options& options,
GrTextBlob* blob,
SkPaint* skPaint,
SkFont* skFont,
SkScalar* textRatio,
SkScalerContextFlags* flags);
static SkFont InitDistanceFieldFont(const SkFont& font,
const SkMatrix& viewMatrix,
const Options& options,
SkScalar* textRatio);
static SkPaint InitDistanceFieldPaint(const SkPaint& paint);
static SkScalerContextFlags InitDistanceFieldFlags();
static std::pair<SkScalar, SkScalar> InitDistanceFieldMinMaxScale(SkScalar textSize,
const SkMatrix& viewMatrix,
const Options& options);
private:
GrTextContext(const Options& options);