diff options
author | Jim Van Verth <jvanverth@google.com> | 2017-06-27 15:07:31 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-06-27 20:17:23 +0000 |
commit | 3921ba236f1e3320b5999fe472f0acfbb6b6f75a (patch) | |
tree | 0535d645f0ea5fc1533a76c84f2947addd39bdf6 | |
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>
-rw-r--r-- | samplecode/SampleApp.cpp | 16 | ||||
-rw-r--r-- | src/gpu/text/GrTextUtils.cpp | 52 |
2 files changed, 35 insertions, 33 deletions
diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp index 16dbef24a4..dde939bc66 100644 --- a/samplecode/SampleApp.cpp +++ b/samplecode/SampleApp.cpp @@ -2026,23 +2026,19 @@ void SampleWindow::resetFPS() { } void SampleWindow::toggleDistanceFieldFonts() { - // reset backend - fDevManager->tearDownBackend(this); - fDevManager->setUpBackend(this, fBackendOptions); - SkSurfaceProps props = this->getSurfaceProps(); uint32_t flags = props.flags() ^ SkSurfaceProps::kUseDeviceIndependentFonts_Flag; this->setSurfaceProps(SkSurfaceProps(flags, props.pixelGeometry())); + // reset backend + fDevManager->tearDownBackend(this); + fDevManager->setUpBackend(this, fBackendOptions); + this->updateTitle(); this->inval(nullptr); } void SampleWindow::setPixelGeometry(int pixelGeometryIndex) { - // reset backend - fDevManager->tearDownBackend(this); - fDevManager->setUpBackend(this, fBackendOptions); - const SkSurfaceProps& oldProps = this->getSurfaceProps(); SkSurfaceProps newProps(oldProps.flags(), SkSurfaceProps::kLegacyFontHost_InitType); if (pixelGeometryIndex > 0) { @@ -2051,6 +2047,10 @@ void SampleWindow::setPixelGeometry(int pixelGeometryIndex) { } this->setSurfaceProps(newProps); + // reset backend + fDevManager->tearDownBackend(this); + fDevManager->setUpBackend(this, fBackendOptions); + this->updateTitle(); this->inval(nullptr); } 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 |