aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu
diff options
context:
space:
mode:
authorGravatar jvanverth <jvanverth@google.com>2014-09-16 05:45:19 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-09-16 05:45:19 -0700
commit9564ce60a657acce89fb956deb8645b324eaad1e (patch)
tree0fbe408f717124b40ef6c0822828c6d5371fcf0e /src/gpu
parent49005bf8929dd8ca86431e13414d683b509cd538 (diff)
Fix scaling issue with distance field text.
Picks the correct distance field size based on both the text size and the max matrix scale. Adjusts the matrix scale if non-unity. Also adds GM for verifying proper distance field scaling. BUG=skia:2928 R=bsalomon@google.com, joshualitt@google.com Author: jvanverth@google.com Review URL: https://codereview.chromium.org/568843002
Diffstat (limited to 'src/gpu')
-rwxr-xr-xsrc/gpu/GrDistanceFieldTextContext.cpp31
-rw-r--r--src/gpu/GrDistanceFieldTextContext.h1
-rwxr-xr-xsrc/gpu/effects/GrDistanceFieldTextureEffect.cpp9
3 files changed, 31 insertions, 10 deletions
diff --git a/src/gpu/GrDistanceFieldTextContext.cpp b/src/gpu/GrDistanceFieldTextContext.cpp
index d32dcb9c21..18058be17f 100755
--- a/src/gpu/GrDistanceFieldTextContext.cpp
+++ b/src/gpu/GrDistanceFieldTextContext.cpp
@@ -127,9 +127,9 @@ void GrDistanceFieldTextContext::setupCoverageEffect(const SkColor& filteredColo
// set up any flags
uint32_t flags = 0;
- flags |= fContext->getMatrix().isSimilarity() ? kSimilarity_DistanceFieldEffectFlag : 0;
+ flags |= fTextMatrix.isSimilarity() ? kSimilarity_DistanceFieldEffectFlag : 0;
flags |= fUseLCDText ? kUseLCD_DistanceFieldEffectFlag : 0;
- flags |= fUseLCDText && fContext->getMatrix().rectStaysRect() ?
+ flags |= fUseLCDText && fTextMatrix.rectStaysRect() ?
kRectToRect_DistanceFieldEffectFlag : 0;
bool useBGR = SkDeviceProperties::Geometry::kBGR_Layout ==
fDeviceProperties.fGeometry.getLayout();
@@ -176,7 +176,8 @@ void GrDistanceFieldTextContext::flushGlyphs() {
GrDrawState* drawState = fDrawTarget->drawState();
GrDrawState::AutoRestoreEffects are(drawState);
- drawState->setFromPaint(fPaint, fContext->getMatrix(), fContext->getRenderTarget());
+
+ drawState->setFromPaint(fPaint, fTextMatrix, fContext->getRenderTarget());
if (fCurrVertex > 0) {
// setup our sampler state for our text texture/atlas
@@ -443,18 +444,32 @@ inline void GrDistanceFieldTextContext::init(const GrPaint& paint, const SkPaint
fStrike = NULL;
+ fTextMatrix = fContext->getMatrix();
+
+ // getMaxScale doesn't support perspective, so neither do we at the moment
+ SkASSERT(!fTextMatrix.hasPerspective());
+ SkScalar maxScale = fTextMatrix.getMaxScale();
+ SkScalar textSize = fSkPaint.getTextSize();
+ // if we have non-unity scale, we need to adjust our text size accordingly
+ // to avoid aliasing, and prescale the matrix by the inverse to end up with the same size
+ // TODO: do we need to do this if we're scaling down (i.e. maxScale < 1)?
+ if (maxScale > 0 && !SkScalarNearlyEqual(maxScale, SK_Scalar1)) {
+ textSize *= maxScale;
+ fTextMatrix.preScale(SK_Scalar1 / maxScale, SK_Scalar1 / maxScale);
+ }
+
fCurrVertex = 0;
fVertices = NULL;
- if (fSkPaint.getTextSize() <= kSmallDFFontLimit) {
- fTextRatio = fSkPaint.getTextSize()/kSmallDFFontSize;
+ if (textSize <= kSmallDFFontLimit) {
+ fTextRatio = textSize / kSmallDFFontSize;
fSkPaint.setTextSize(SkIntToScalar(kSmallDFFontSize));
- } else if (fSkPaint.getTextSize() <= kMediumDFFontLimit) {
- fTextRatio = fSkPaint.getTextSize()/kMediumDFFontSize;
+ } else if (textSize <= kMediumDFFontLimit) {
+ fTextRatio = textSize / kMediumDFFontSize;
fSkPaint.setTextSize(SkIntToScalar(kMediumDFFontSize));
} else {
- fTextRatio = fSkPaint.getTextSize()/kLargeDFFontSize;
+ fTextRatio = textSize / kLargeDFFontSize;
fSkPaint.setTextSize(SkIntToScalar(kLargeDFFontSize));
}
diff --git a/src/gpu/GrDistanceFieldTextContext.h b/src/gpu/GrDistanceFieldTextContext.h
index 75a13b385b..15ff6d9d78 100644
--- a/src/gpu/GrDistanceFieldTextContext.h
+++ b/src/gpu/GrDistanceFieldTextContext.h
@@ -31,6 +31,7 @@ public:
private:
GrTextStrike* fStrike;
+ SkMatrix fTextMatrix;
SkScalar fTextRatio;
bool fUseLCDText;
bool fEnableDFRendering;
diff --git a/src/gpu/effects/GrDistanceFieldTextureEffect.cpp b/src/gpu/effects/GrDistanceFieldTextureEffect.cpp
index ee7dd61387..b689c8f6a1 100755
--- a/src/gpu/effects/GrDistanceFieldTextureEffect.cpp
+++ b/src/gpu/effects/GrDistanceFieldTextureEffect.cpp
@@ -34,7 +34,11 @@ public:
GrGLDistanceFieldTextureEffect(const GrBackendEffectFactory& factory,
const GrDrawEffect& drawEffect)
: INHERITED (factory)
- , fTextureSize(SkISize::Make(-1,-1)) {}
+ , fTextureSize(SkISize::Make(-1,-1))
+#ifdef SK_GAMMA_APPLY_TO_A8
+ , fLuminance(-1.0f)
+#endif
+ {}
virtual void emitCode(GrGLFullProgramBuilder* builder,
const GrDrawEffect& drawEffect,
@@ -262,7 +266,8 @@ public:
GrGLDistanceFieldLCDTextureEffect(const GrBackendEffectFactory& factory,
const GrDrawEffect& drawEffect)
: INHERITED (factory)
- , fTextureSize(SkISize::Make(-1,-1)) {}
+ , fTextureSize(SkISize::Make(-1,-1))
+ , fTextColor(GrColor_ILLEGAL) {}
virtual void emitCode(GrGLFullProgramBuilder* builder,
const GrDrawEffect& drawEffect,