Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(284)

Unified Diff: src/gpu/effects/GrDistanceFieldTextureEffect.cpp

Issue 1066613003: Revert of Calculate inverse scale for distance fields in vertex shader (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/effects/GrDistanceFieldTextureEffect.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/effects/GrDistanceFieldTextureEffect.cpp
diff --git a/src/gpu/effects/GrDistanceFieldTextureEffect.cpp b/src/gpu/effects/GrDistanceFieldTextureEffect.cpp
index 13ca05271c8603e41a72be1302a483e451d277cd..d44c193260dac3f674c62a52db885206b2486a13 100755
--- a/src/gpu/effects/GrDistanceFieldTextureEffect.cpp
+++ b/src/gpu/effects/GrDistanceFieldTextureEffect.cpp
@@ -51,6 +51,16 @@
// emit attributes
vsBuilder->emitAttributes(dfTexEffect);
+ GrGLVertToFrag st(kVec2f_GrSLType);
+ 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);
+ // this is only used with text, so our texture bounds always match the glyph atlas
+ vsBuilder->codeAppendf("%s = vec2(" GR_FONT_ATLAS_A8_RECIP_WIDTH ", "
+ GR_FONT_ATLAS_RECIP_HEIGHT ")*%s;", uv.vsOut(),
+ dfTexEffect.inTextureCoords()->fName);
#ifdef SK_GAMMA_APPLY_TO_A8
// adjust based on gamma
const char* distanceAdjustUniName = NULL;
@@ -68,36 +78,9 @@
this->setupPosition(pb, gpArgs, dfTexEffect.inPosition()->fName, dfTexEffect.viewMatrix());
// emit transforms
- const SkMatrix& localMatrix = dfTexEffect.localMatrix();
this->emitTransforms(args.fPB, gpArgs->fPositionVar, dfTexEffect.inPosition()->fName,
- localMatrix, args.fTransformsIn, args.fTransformsOut);
-
- // add varyings
- 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);
- }
-
- GrGLVertToFrag uv(kVec2f_GrSLType);
- args.fPB->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision);
- // this is only used with text, so our texture bounds always match the glyph atlas
- vsBuilder->codeAppendf("%s = vec2(" GR_FONT_ATLAS_A8_RECIP_WIDTH ", "
- GR_FONT_ATLAS_RECIP_HEIGHT ")*%s;", uv.vsOut(),
- dfTexEffect.inTextureCoords()->fName);
-
-
+ dfTexEffect.localMatrix(), args.fTransformsIn, args.fTransformsOut);
+
// Use highp to work around aliasing issues
fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision,
pb->ctxInfo().standard()));
@@ -117,23 +100,16 @@
fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision,
pb->ctxInfo().standard()));
+ fsBuilder->codeAppendf("vec2 st = %s;", st.fsIn());
fsBuilder->codeAppend("float afwidth;");
- if (isSimilarity) {
+ if (dfTexEffect.getFlags() & kSimilarity_DistanceFieldEffectFlag) {
// 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));",
- st.fsIn());
- }
+ fsBuilder->codeAppend("afwidth = abs(" SK_DistanceFieldAAFactor "*dFdx(st.x));");
} else {
- fsBuilder->codeAppendf("vec2 st = %s;", st.fsIn());
// 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
// (which is the inverse transform for this fragment) and take the length of the result.
@@ -194,7 +170,6 @@
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);
}
@@ -213,14 +188,13 @@
GrDistanceFieldTextureEffect::GrDistanceFieldTextureEffect(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)
@@ -307,7 +281,6 @@
return GrDistanceFieldTextureEffect::Create(GrRandomColor(random),
GrProcessorUnitTest::TestMatrix(random),
- GrProcessorUnitTest::TestMatrix(random),
textures[texIdx], params,
#ifdef SK_GAMMA_APPLY_TO_A8
random->nextF(),
@@ -591,44 +564,28 @@
// emit attributes
vsBuilder->emitAttributes(dfTexEffect);
- // setup pass through color
- this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor, NULL,
- &fColorUniform);
-
- // Setup position
- this->setupPosition(pb, gpArgs, dfTexEffect.inPosition()->fName, dfTexEffect.viewMatrix());
-
- // emit transforms
- const SkMatrix& localMatrix = dfTexEffect.localMatrix();
- this->emitTransforms(args.fPB, gpArgs->fPositionVar, dfTexEffect.inPosition()->fName,
- localMatrix, args.fTransformsIn, args.fTransformsOut);
-
- // set up varyings
- 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);
// this is only used with text, so our texture bounds always match the glyph atlas
vsBuilder->codeAppendf("%s = vec2(" GR_FONT_ATLAS_A8_RECIP_WIDTH ", "
GR_FONT_ATLAS_RECIP_HEIGHT ")*%s;", uv.vsOut(),
dfTexEffect.inTextureCoords()->fName);
-
- // add frag shader code
+
+ // setup pass through color
+ this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor, NULL,
+ &fColorUniform);
+
+ // Setup position
+ this->setupPosition(pb, gpArgs, dfTexEffect.inPosition()->fName, dfTexEffect.viewMatrix());
+
+ // emit transforms
+ this->emitTransforms(args.fPB, gpArgs->fPositionVar, dfTexEffect.inPosition()->fName,
+ dfTexEffect.localMatrix(), args.fTransformsIn, args.fTransformsOut);
+
GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
SkAssertResult(fsBuilder->enableFeature(
@@ -641,24 +598,21 @@
fsBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn());
fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision,
pb->ctxInfo().standard()));
+ fsBuilder->codeAppendf("vec2 st = %s;\n", st.fsIn());
+ bool isUniformScale = !!(dfTexEffect.getFlags() & kUniformScale_DistanceFieldEffectMask);
+
if (dfTexEffect.getFlags() & kBGR_DistanceFieldEffectFlag) {
fsBuilder->codeAppend("float delta = -" GR_FONT_ATLAS_LCD_DELTA ";\n");
} else {
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->codeAppend("\tfloat dx = dFdx(st.x);\n");
+ fsBuilder->codeAppend("\tvec2 offset = vec2(dx*delta, 0.0);\n");
} else {
- fsBuilder->codeAppendf("vec2 st = %s;\n", st.fsIn());
-
- fsBuilder->codeAppend("vec2 Jdx = dFdx(st);");
- fsBuilder->codeAppend("vec2 Jdy = dFdy(st);");
- fsBuilder->codeAppend("vec2 offset = delta*Jdx;");
+ fsBuilder->codeAppend("\tvec2 Jdx = dFdx(st);\n");
+ fsBuilder->codeAppend("\tvec2 Jdy = dFdy(st);\n");
+ fsBuilder->codeAppend("\tvec2 offset = delta*Jdx;\n");
}
// green is distance to uv center
@@ -767,7 +721,6 @@
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);
}
@@ -784,11 +737,10 @@
GrDistanceFieldLCDTextureEffect::GrDistanceFieldLCDTextureEffect(
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){
@@ -869,7 +821,6 @@
flags |= random->nextBool() ? kBGR_DistanceFieldEffectFlag : 0;
return GrDistanceFieldLCDTextureEffect::Create(GrRandomColor(random),
GrProcessorUnitTest::TestMatrix(random),
- GrProcessorUnitTest::TestMatrix(random),
textures[texIdx], params,
wa,
flags);
« no previous file with comments | « src/gpu/effects/GrDistanceFieldTextureEffect.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698