diff options
author | 2017-06-27 15:07:31 -0400 | |
---|---|---|
committer | 2017-06-27 20:17:23 +0000 | |
commit | 3921ba236f1e3320b5999fe472f0acfbb6b6f75a (patch) | |
tree | 0535d645f0ea5fc1533a76c84f2947addd39bdf6 /src/gpu/text/GrTextUtils.cpp | |
parent | d08109f3448c4a725a233e759508e9242e6bba42 (diff) |
Enable SDF text when using a perspective matrix.
Also fixes some state issues in SampleApp.
Change-Id: I854754e8b547f7e62aa90914520aaaa20095f965
Reviewed-on: https://skia-review.googlesource.com/20975
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Jim Van Verth <jvanverth@google.com>
Diffstat (limited to 'src/gpu/text/GrTextUtils.cpp')
-rw-r--r-- | src/gpu/text/GrTextUtils.cpp | 52 |
1 files changed, 27 insertions, 25 deletions
diff --git a/src/gpu/text/GrTextUtils.cpp b/src/gpu/text/GrTextUtils.cpp index 20001a4f8a..20d5aaf338 100644 --- a/src/gpu/text/GrTextUtils.cpp +++ b/src/gpu/text/GrTextUtils.cpp @@ -197,27 +197,24 @@ void GrTextUtils::BmpAppendGlyph(GrAtlasTextBlob* blob, int runIndex, bool GrTextUtils::CanDrawAsDistanceFields(const SkPaint& skPaint, const SkMatrix& viewMatrix, const SkSurfaceProps& props, const GrShaderCaps& caps) { - // TODO: support perspective (need getMaxScale replacement) - if (viewMatrix.hasPerspective()) { - return false; - } - - 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 < kMinDFFontSize || - scaledTextSize > kLargeDFFontLimit) { - return false; - } + 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 < kMinDFFontSize || + scaledTextSize > kLargeDFFontLimit) { + return false; + } - bool useDFT = props.isUseDeviceIndependentFonts(); + bool useDFT = props.isUseDeviceIndependentFonts(); #if SK_FORCE_DISTANCE_FIELD_TEXT - useDFT = true; + useDFT = true; #endif - if (!useDFT && scaledTextSize < kLargeDFFontSize) { - return false; + if (!useDFT && scaledTextSize < kLargeDFFontSize) { + return false; + } } // rasterizers and mask filters modify alpha, which doesn't @@ -238,16 +235,21 @@ void GrTextUtils::InitDistanceFieldPaint(GrAtlasTextBlob* blob, SkPaint* skPaint, SkScalar* textRatio, const SkMatrix& viewMatrix) { - // getMaxScale doesn't support perspective, so neither do we at the moment - SkASSERT(!viewMatrix.hasPerspective()); - SkScalar maxScale = viewMatrix.getMaxScale(); SkScalar textSize = skPaint->getTextSize(); SkScalar scaledTextSize = textSize; - // if we have non-unity scale, we need to choose our base text size - // based on the SkPaint's text size multiplied by the max scale factor - // TODO: do we need to do this if we're scaling down (i.e. maxScale < 1)? - if (maxScale > 0 && !SkScalarNearlyEqual(maxScale, SK_Scalar1)) { - scaledTextSize *= maxScale; + + if (viewMatrix.hasPerspective()) { + // for perspective, we simply force to the medium size + // TODO: compute a size based on approximate screen area + scaledTextSize = kMediumDFFontLimit; + } else { + SkScalar maxScale = viewMatrix.getMaxScale(); + // if we have non-unity scale, we need to choose our base text size + // based on the SkPaint's text size multiplied by the max scale factor + // TODO: do we need to do this if we're scaling down (i.e. maxScale < 1)? + if (maxScale > 0 && !SkScalarNearlyEqual(maxScale, SK_Scalar1)) { + scaledTextSize *= maxScale; + } } // We have three sizes of distance field text, and within each size 'bucket' there is a floor |