| Index: src/gpu/effects/GrDistanceFieldTextureEffect.cpp
|
| diff --git a/src/gpu/effects/GrDistanceFieldTextureEffect.cpp b/src/gpu/effects/GrDistanceFieldTextureEffect.cpp
|
| index cd80e067450bf7f1793462badfbb177e893ce208..9159a701e32a966bbb0ba1a3d465b35cd3abc6d2 100755
|
| --- a/src/gpu/effects/GrDistanceFieldTextureEffect.cpp
|
| +++ b/src/gpu/effects/GrDistanceFieldTextureEffect.cpp
|
| @@ -35,8 +35,6 @@
|
| SkASSERT(1 == drawEffect.castEffect<GrDistanceFieldTextureEffect>().numVertexAttribs());
|
|
|
| SkAssertResult(builder->enableFeature(GrGLShaderBuilder::kStandardDerivatives_GLSLFeature));
|
| - const GrDistanceFieldTextureEffect& dfTexEffect =
|
| - drawEffect.castEffect<GrDistanceFieldTextureEffect>();
|
|
|
| SkString fsCoordName;
|
| const char* vsCoordName;
|
| @@ -63,37 +61,16 @@
|
| // we adjust for the effect of the transformation on the distance by using
|
| // the length of the gradient of the texture coordinates. We use st coordinates
|
| // to ensure we're mapping 1:1 from texel space to pixel space.
|
| - builder->fsCodeAppendf("\tvec2 uv = %s;\n", fsCoordName.c_str());
|
| - builder->fsCodeAppendf("\tvec2 st = uv*%s;\n", textureSizeUniName);
|
| - builder->fsCodeAppend("\tfloat afwidth;\n");
|
| - if (dfTexEffect.isUniformScale()) {
|
| - // this gives us a smooth step across approximately one fragment
|
| - // (assuming a radius of the diagonal of the fragment, hence a factor of sqrt(2)/2)
|
| - builder->fsCodeAppend("\tafwidth = 0.7071*dFdx(st.x);\n");
|
| - } else {
|
| - builder->fsCodeAppend("\tvec2 Jdx = dFdx(st);\n");
|
| - builder->fsCodeAppend("\tvec2 Jdy = dFdy(st);\n");
|
| + builder->fsCodeAppendf("\tvec2 st = %s*%s;\n", fsCoordName.c_str(), textureSizeUniName);
|
| + builder->fsCodeAppend("\tvec2 Jdx = dFdx(st);\n");
|
| + builder->fsCodeAppend("\tvec2 Jdy = dFdy(st);\n");
|
| + builder->fsCodeAppend("\tvec2 st_grad = normalize(st);\n");
|
| + builder->fsCodeAppend("\tvec2 grad = vec2(st_grad.x*Jdx.x + st_grad.y*Jdy.x,\n");
|
| + builder->fsCodeAppend("\t st_grad.x*Jdx.y + st_grad.y*Jdy.y);\n");
|
|
|
| - builder->fsCodeAppend("\tvec2 uv_grad;\n");
|
| - if (builder->ctxInfo().caps()->dropsTileOnZeroDivide()) {
|
| - // this is to compensate for the Adreno, which likes to drop tiles on division by 0
|
| - builder->fsCodeAppend("\tfloat uv_len2 = dot(uv, uv);\n");
|
| - builder->fsCodeAppend("\tif (uv_len2 < 0.0001) {\n");
|
| - builder->fsCodeAppend("\t\tuv_grad = vec2(0.7071, 0.7071);\n");
|
| - builder->fsCodeAppend("\t} else {\n");
|
| - builder->fsCodeAppend("\t\tuv_grad = uv*inversesqrt(uv_len2);\n");
|
| - builder->fsCodeAppend("\t}\n");
|
| - } else {
|
| - builder->fsCodeAppend("\tuv_grad = normalize(uv);\n");
|
| - }
|
| - builder->fsCodeAppend("\tvec2 grad = vec2(uv_grad.x*Jdx.x + uv_grad.y*Jdy.x,\n");
|
| - builder->fsCodeAppend("\t uv_grad.x*Jdx.y + uv_grad.y*Jdy.y);\n");
|
| -
|
| - // this gives us a smooth step across approximately one fragment
|
| - // (assuming a radius of the diagonal of the fragment, hence a factor of sqrt(2)/2)
|
| - builder->fsCodeAppend("\tafwidth = 0.7071*length(grad);\n");
|
| - }
|
| -
|
| + // this gives us a smooth step across approximately one fragment
|
| + // (assuming a radius of the diagonal of the fragment, hence a factor of sqrt(2)/2)
|
| + builder->fsCodeAppend("\tfloat afwidth = 0.7071*length(grad);\n");
|
| builder->fsCodeAppend("\tfloat val = smoothstep(-afwidth, afwidth, distance);\n");
|
|
|
| builder->fsCodeAppendf("\t%s = %s;\n", outputColor,
|
| @@ -103,22 +80,15 @@
|
| virtual void setData(const GrGLUniformManager& uman,
|
| const GrDrawEffect& drawEffect) SK_OVERRIDE {
|
| SkASSERT(fTextureSizeUni.isValid());
|
| -
|
| - GrTexture* texture = drawEffect.effect()->get()->texture(0);
|
| - if (texture->width() != fTextureSize.width() ||
|
| - texture->height() != fTextureSize.height()) {
|
| - fTextureSize = SkSize::Make(texture->width(), texture->height());
|
| + const GrDistanceFieldTextureEffect& distanceFieldEffect =
|
| + drawEffect.castEffect<GrDistanceFieldTextureEffect>();
|
| + if (distanceFieldEffect.getSize().width() != fTextureSize.width() ||
|
| + distanceFieldEffect.getSize().height() != fTextureSize.height()) {
|
| + fTextureSize = distanceFieldEffect.getSize();
|
| uman.set2f(fTextureSizeUni,
|
| - fTextureSize.width(),
|
| - fTextureSize.height());
|
| + distanceFieldEffect.getSize().width(),
|
| + distanceFieldEffect.getSize().height());
|
| }
|
| - }
|
| -
|
| - static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&) {
|
| - const GrDistanceFieldTextureEffect& dfTexEffect =
|
| - drawEffect.castEffect<GrDistanceFieldTextureEffect>();
|
| -
|
| - return dfTexEffect.isUniformScale() ? 0x1 : 0x0;
|
| }
|
|
|
| private:
|
| @@ -132,9 +102,9 @@
|
|
|
| GrDistanceFieldTextureEffect::GrDistanceFieldTextureEffect(GrTexture* texture,
|
| const GrTextureParams& params,
|
| - bool uniformScale)
|
| + const SkISize& size)
|
| : fTextureAccess(texture, params)
|
| - , fUniformScale(uniformScale) {
|
| + , fSize(SkSize::Make(SkIntToScalar(size.width()), SkIntToScalar(size.height()))) {
|
| this->addTextureAccess(&fTextureAccess);
|
| this->addVertexAttrib(kVec2f_GrSLType);
|
| }
|
| @@ -179,6 +149,7 @@
|
| };
|
| GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBilerp_FilterMode :
|
| GrTextureParams::kNone_FilterMode);
|
| + SkISize size = SkISize::Make(1024, 2048);
|
|
|
| - return GrDistanceFieldTextureEffect::Create(textures[texIdx], params, random->nextBool());
|
| + return GrDistanceFieldTextureEffect::Create(textures[texIdx], params, size);
|
| }
|
|
|