diff options
author | jvanverth <jvanverth@google.com> | 2015-04-15 12:31:22 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-04-15 12:31:22 -0700 |
commit | 221360a514fb4bfff5b461e83262306b2a0f36af (patch) | |
tree | a846ea9db18d86b00c4e662ad31c3f89dc327022 /src/gpu | |
parent | ddb714b09a5f84e870dfc650b6da4197fd36d9c2 (diff) |
Real fix for the Mali bug.
The dFdy(st.y) computation seems to be better than the dFdx(st.x) computation
on the Mali, so using that. The end result should be about the same.
BUG=skia:3528
Review URL: https://codereview.chromium.org/1082913006
Diffstat (limited to 'src/gpu')
-rwxr-xr-x | src/gpu/GrDistanceFieldTextContext.cpp | 35 | ||||
-rwxr-xr-x | src/gpu/effects/GrDistanceFieldGeoProc.cpp | 61 | ||||
-rw-r--r-- | src/gpu/effects/GrDistanceFieldGeoProc.h | 12 |
3 files changed, 21 insertions, 87 deletions
diff --git a/src/gpu/GrDistanceFieldTextContext.cpp b/src/gpu/GrDistanceFieldTextContext.cpp index b1120e4637..cc592833c9 100755 --- a/src/gpu/GrDistanceFieldTextContext.cpp +++ b/src/gpu/GrDistanceFieldTextContext.cpp @@ -271,12 +271,6 @@ inline void GrDistanceFieldTextContext::init(GrRenderTarget* rt, const GrClip& c fSkPaint.setAutohinted(false); fSkPaint.setHinting(SkPaint::kNormal_Hinting); fSkPaint.setSubpixelText(true); - - // fix for skia:3528 - // if we're scaling up, include any scaling to match text size in the view matrix - if (fTextRatio > 1.0f) { - fViewMatrix.preScale(fTextRatio, fTextRatio); - } } void GrDistanceFieldTextContext::onDrawText(GrRenderTarget* rt, const GrClip& clip, @@ -490,21 +484,11 @@ void GrDistanceFieldTextContext::setupCoverageEffect(const SkColor& filteredColo bool useBGR = SkPixelGeometryIsBGR(fDeviceProperties.pixelGeometry()); flags |= fUseLCDText && useBGR ? kBGR_DistanceFieldEffectFlag : 0; - // fix for skia:3528 - // set the local matrix to correct any text size scaling for gradients et al. - SkMatrix localMatrix; - if (fTextRatio > 1.0f) { - localMatrix.setScale(fTextRatio, fTextRatio); - } else { - localMatrix.reset(); - } - // see if we need to create a new effect if (textureUniqueID != fEffectTextureUniqueID || filteredColor != fEffectColor || flags != fEffectFlags || - !fCachedGeometryProcessor->viewMatrix().cheapEqualTo(fViewMatrix) || - !fCachedGeometryProcessor->localMatrix().cheapEqualTo(localMatrix)) { + !fCachedGeometryProcessor->viewMatrix().cheapEqualTo(fViewMatrix)) { GrColor color = fPaint.getColor(); if (fUseLCDText) { @@ -522,7 +506,6 @@ void GrDistanceFieldTextContext::setupCoverageEffect(const SkColor& filteredColo blueCorrection); fCachedGeometryProcessor.reset(GrDistanceFieldLCDTextGeoProc::Create(color, fViewMatrix, - localMatrix, fCurrTexture, params, widthAdjust, @@ -536,7 +519,6 @@ void GrDistanceFieldTextContext::setupCoverageEffect(const SkColor& filteredColo float correction = fDistanceAdjustTable[lum >> kDistanceAdjustLumShift]; fCachedGeometryProcessor.reset(GrDistanceFieldA8TextGeoProc::Create(color, fViewMatrix, - localMatrix, fCurrTexture, params, correction, @@ -545,7 +527,6 @@ void GrDistanceFieldTextContext::setupCoverageEffect(const SkColor& filteredColo #else fCachedGeometryProcessor.reset(GrDistanceFieldA8TextGeoProc::Create(color, fViewMatrix, - localMatrix, fCurrTexture, params, flags, @@ -624,16 +605,10 @@ bool GrDistanceFieldTextContext::appendGlyph(GrGlyph::PackedID packed, SkScalar height = SkIntToScalar(glyph->fBounds.height() - 2*SK_DistanceFieldInset); SkScalar scale = fTextRatio; - // if we're scaling up, using fix for skia:3528 - if (scale > 1.0f) { - sx /= scale; - sy /= scale; - } else { - dx *= scale; - dy *= scale; - width *= scale; - height *= scale; - } + dx *= scale; + dy *= scale; + width *= scale; + height *= scale; sx += dx; sy += dy; SkRect glyphRect = SkRect::MakeXYWH(sx, sy, width, height); diff --git a/src/gpu/effects/GrDistanceFieldGeoProc.cpp b/src/gpu/effects/GrDistanceFieldGeoProc.cpp index 34ea27bb65..05e42c9240 100755 --- a/src/gpu/effects/GrDistanceFieldGeoProc.cpp +++ b/src/gpu/effects/GrDistanceFieldGeoProc.cpp @@ -76,19 +76,8 @@ public: GrGLVertToFrag recipScale(kFloat_GrSLType); GrGLVertToFrag st(kVec2f_GrSLType); bool isSimilarity = SkToBool(dfTexEffect.getFlags() & kSimilarity_DistanceFieldEffectFlag); - const char* viewMatrixName = this->uViewM(); - // view matrix name is NULL if identity matrix - bool useInverseScale = !localMatrix.isIdentity() && viewMatrixName; - if (isSimilarity && useInverseScale) { - args.fPB->addVarying("RecipScale", &recipScale, kHigh_GrSLPrecision); - vsBuilder->codeAppendf("vec2 tx = vec2(%s[0][0], %s[1][0]);", - viewMatrixName, viewMatrixName); - vsBuilder->codeAppend("float tx2 = dot(tx, tx);"); - vsBuilder->codeAppendf("%s = inversesqrt(tx2);", recipScale.vsOut()); - } else { - args.fPB->addVarying("IntTextureCoords", &st, kHigh_GrSLPrecision); - vsBuilder->codeAppendf("%s = %s;", st.vsOut(), dfTexEffect.inTextureCoords()->fName); - } + args.fPB->addVarying("IntTextureCoords", &st, kHigh_GrSLPrecision); + vsBuilder->codeAppendf("%s = %s;", st.vsOut(), dfTexEffect.inTextureCoords()->fName); GrGLVertToFrag uv(kVec2f_GrSLType); args.fPB->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision); @@ -117,18 +106,13 @@ public: fsBuilder->codeAppend("float afwidth;"); if (isSimilarity) { // For uniform scale, we adjust for the effect of the transformation on the distance - // either by using the inverse scale in the view matrix, or (if there is no view matrix) // by using the length of the gradient of the texture coordinates. We use st coordinates - // with the latter to ensure we're mapping 1:1 from texel space to pixel space. + // to ensure we're mapping 1:1 from texel space to pixel space. // this gives us a smooth step across approximately one fragment - if (useInverseScale) { - fsBuilder->codeAppendf("afwidth = abs(" SK_DistanceFieldAAFactor "*%s);", - recipScale.fsIn()); - } else { - fsBuilder->codeAppendf("afwidth = abs(" SK_DistanceFieldAAFactor "*dFdx(%s.x));", + // we use y to work around a Mali400 bug in the x direction + fsBuilder->codeAppendf("afwidth = abs(" SK_DistanceFieldAAFactor "*dFdy(%s.y));", st.fsIn()); - } } else { // For general transforms, to determine the amount of correction we multiply a unit // vector pointing along the SDF gradient direction by the Jacobian of the st coords @@ -189,7 +173,6 @@ public: key |= local.fInputColorType << 16; key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x1 << 24: 0x0; key |= ComputePosKey(gp.viewMatrix()) << 25; - key |= (!gp.viewMatrix().isIdentity() && !gp.localMatrix().isIdentity()) ? 0x1 << 27 : 0x0; b->add32(key); } @@ -208,14 +191,13 @@ private: GrDistanceFieldA8TextGeoProc::GrDistanceFieldA8TextGeoProc(GrColor color, const SkMatrix& viewMatrix, - const SkMatrix& localMatrix, GrTexture* texture, const GrTextureParams& params, #ifdef SK_GAMMA_APPLY_TO_A8 float distanceAdjust, #endif uint32_t flags, bool opaqueVertexColors) - : INHERITED(color, viewMatrix, localMatrix, opaqueVertexColors) + : INHERITED(color, viewMatrix, SkMatrix::I(), opaqueVertexColors) , fTextureAccess(texture, params) #ifdef SK_GAMMA_APPLY_TO_A8 , fDistanceAdjust(distanceAdjust) @@ -302,7 +284,6 @@ GrGeometryProcessor* GrDistanceFieldA8TextGeoProc::TestCreate(SkRandom* random, return GrDistanceFieldA8TextGeoProc::Create(GrRandomColor(random), GrProcessorUnitTest::TestMatrix(random), - GrProcessorUnitTest::TestMatrix(random), textures[texIdx], params, #ifdef SK_GAMMA_APPLY_TO_A8 random->nextF(), @@ -595,19 +576,8 @@ public: bool isUniformScale = SkToBool(dfTexEffect.getFlags() & kUniformScale_DistanceFieldEffectMask); GrGLVertToFrag recipScale(kFloat_GrSLType); GrGLVertToFrag st(kVec2f_GrSLType); - const char* viewMatrixName = this->uViewM(); - // view matrix name is NULL if identity matrix - bool useInverseScale = !localMatrix.isIdentity() && viewMatrixName; - if (isUniformScale && useInverseScale) { - args.fPB->addVarying("RecipScale", &recipScale, kHigh_GrSLPrecision); - vsBuilder->codeAppendf("vec2 tx = vec2(%s[0][0], %s[1][0]);", - viewMatrixName, viewMatrixName); - vsBuilder->codeAppend("float tx2 = dot(tx, tx);"); - vsBuilder->codeAppendf("%s = inversesqrt(tx2);", recipScale.vsOut()); - } else { - args.fPB->addVarying("IntTextureCoords", &st, kHigh_GrSLPrecision); - vsBuilder->codeAppendf("%s = %s;", st.vsOut(), dfTexEffect.inTextureCoords()->fName); - } + args.fPB->addVarying("IntTextureCoords", &st, kHigh_GrSLPrecision); + vsBuilder->codeAppendf("%s = %s;", st.vsOut(), dfTexEffect.inTextureCoords()->fName); GrGLVertToFrag uv(kVec2f_GrSLType); args.fPB->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision); @@ -635,12 +605,8 @@ public: fsBuilder->codeAppend("float delta = " GR_FONT_ATLAS_LCD_DELTA ";\n"); } if (isUniformScale) { - if (useInverseScale) { - fsBuilder->codeAppendf("float dx = %s;", recipScale.fsIn()); - } else { - fsBuilder->codeAppendf("float dx = dFdx(%s.x);", st.fsIn()); - } - fsBuilder->codeAppend("vec2 offset = vec2(dx*delta, 0.0);"); + fsBuilder->codeAppendf("float dy = dFdy(%s.y);", st.fsIn()); + fsBuilder->codeAppend("vec2 offset = vec2(dy*delta, 0.0);"); } else { fsBuilder->codeAppendf("vec2 st = %s;\n", st.fsIn()); @@ -689,7 +655,7 @@ public: // to ensure we're mapping 1:1 from texel space to pixel space. // this gives us a smooth step across approximately one fragment - fsBuilder->codeAppend("afwidth = abs(" SK_DistanceFieldAAFactor "*dx);"); + fsBuilder->codeAppend("afwidth = abs(" SK_DistanceFieldAAFactor "*dy);"); } else { // For general transforms, to determine the amount of correction we multiply a unit // vector pointing along the SDF gradient direction by the Jacobian of the st coords @@ -754,7 +720,6 @@ public: key |= local.fInputColorType << 16; key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x1 << 24: 0x0; key |= ComputePosKey(gp.viewMatrix()) << 25; - key |= (!gp.viewMatrix().isIdentity() && !gp.localMatrix().isIdentity()) ? 0x1 << 27 : 0x0; b->add32(key); } @@ -771,11 +736,10 @@ private: GrDistanceFieldLCDTextGeoProc::GrDistanceFieldLCDTextGeoProc( GrColor color, const SkMatrix& viewMatrix, - const SkMatrix& localMatrix, GrTexture* texture, const GrTextureParams& params, DistanceAdjust distanceAdjust, uint32_t flags) - : INHERITED(color, viewMatrix, localMatrix) + : INHERITED(color, viewMatrix, SkMatrix::I()) , fTextureAccess(texture, params) , fDistanceAdjust(distanceAdjust) , fFlags(flags & kLCD_DistanceFieldEffectMask){ @@ -855,7 +819,6 @@ GrGeometryProcessor* GrDistanceFieldLCDTextGeoProc::TestCreate(SkRandom* random, flags |= random->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; return GrDistanceFieldLCDTextGeoProc::Create(GrRandomColor(random), GrProcessorUnitTest::TestMatrix(random), - GrProcessorUnitTest::TestMatrix(random), textures[texIdx], params, wa, flags); diff --git a/src/gpu/effects/GrDistanceFieldGeoProc.h b/src/gpu/effects/GrDistanceFieldGeoProc.h index aaa1b6339c..0ae0c0f711 100644 --- a/src/gpu/effects/GrDistanceFieldGeoProc.h +++ b/src/gpu/effects/GrDistanceFieldGeoProc.h @@ -48,18 +48,16 @@ class GrDistanceFieldA8TextGeoProc : public GrGeometryProcessor { public: #ifdef SK_GAMMA_APPLY_TO_A8 static GrGeometryProcessor* Create(GrColor color, const SkMatrix& viewMatrix, - const SkMatrix& localMatrix, GrTexture* tex, const GrTextureParams& params, float lum, uint32_t flags, bool opaqueVertexColors) { - return SkNEW_ARGS(GrDistanceFieldA8TextGeoProc, (color, viewMatrix, localMatrix, tex, + return SkNEW_ARGS(GrDistanceFieldA8TextGeoProc, (color, viewMatrix, tex, params, lum, flags, opaqueVertexColors)); } #else static GrGeometryProcessor* Create(GrColor color, const SkMatrix& viewMatrix, - const SkMatrix& localMatrix, GrTexture* tex, const GrTextureParams& params, uint32_t flags, bool opaqueVertexColors) { - return SkNEW_ARGS(GrDistanceFieldA8TextGeoProc, (color, viewMatrix, localMatrix, tex, + return SkNEW_ARGS(GrDistanceFieldA8TextGeoProc, (color, viewMatrix, tex, params, flags, opaqueVertexColors)); } #endif @@ -90,7 +88,7 @@ public: const GrBatchTracker&) const override; private: - GrDistanceFieldA8TextGeoProc(GrColor, const SkMatrix& viewMatrix, const SkMatrix& localMatrix, + GrDistanceFieldA8TextGeoProc(GrColor, const SkMatrix& viewMatrix, GrTexture* texture, const GrTextureParams& params, #ifdef SK_GAMMA_APPLY_TO_A8 float distanceAdjust, @@ -197,11 +195,10 @@ public: }; static GrGeometryProcessor* Create(GrColor color, const SkMatrix& viewMatrix, - const SkMatrix& localMatrix, GrTexture* tex, const GrTextureParams& params, DistanceAdjust distanceAdjust, uint32_t flags) { return SkNEW_ARGS(GrDistanceFieldLCDTextGeoProc, - (color, viewMatrix, localMatrix, tex, params, distanceAdjust, flags)); + (color, viewMatrix, tex, params, distanceAdjust, flags)); } virtual ~GrDistanceFieldLCDTextGeoProc() {} @@ -228,7 +225,6 @@ public: private: GrDistanceFieldLCDTextGeoProc(GrColor, const SkMatrix& viewMatrix, - const SkMatrix& localMatrix, GrTexture* texture, const GrTextureParams& params, DistanceAdjust wa, uint32_t flags); |