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

Side by Side Diff: src/gpu/effects/GrDistanceFieldTextureEffect.cpp

Issue 1029423003: Calculate inverse scale for distance fields in vertex shader (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix gradients and textalign issues 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 unified diff | Download patch
« no previous file with comments | « src/gpu/effects/GrDistanceFieldTextureEffect.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "GrDistanceFieldTextureEffect.h" 8 #include "GrDistanceFieldTextureEffect.h"
9 #include "GrFontAtlasSizes.h" 9 #include "GrFontAtlasSizes.h"
10 #include "GrInvariantOutput.h" 10 #include "GrInvariantOutput.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 GrGLGPBuilder* pb = args.fPB; 44 GrGLGPBuilder* pb = args.fPB;
45 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); 45 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
46 SkAssertResult(fsBuilder->enableFeature( 46 SkAssertResult(fsBuilder->enableFeature(
47 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); 47 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature));
48 48
49 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); 49 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();
50 50
51 // emit attributes 51 // emit attributes
52 vsBuilder->emitAttributes(dfTexEffect); 52 vsBuilder->emitAttributes(dfTexEffect);
53 53
54 GrGLVertToFrag st(kVec2f_GrSLType);
55 args.fPB->addVarying("IntTextureCoords", &st, kHigh_GrSLPrecision);
56 vsBuilder->codeAppendf("%s = %s;", st.vsOut(), dfTexEffect.inTextureCoor ds()->fName);
57
58 GrGLVertToFrag uv(kVec2f_GrSLType);
59 args.fPB->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision);
60 // this is only used with text, so our texture bounds always match the g lyph atlas
61 vsBuilder->codeAppendf("%s = vec2(" GR_FONT_ATLAS_A8_RECIP_WIDTH ", "
62 GR_FONT_ATLAS_RECIP_HEIGHT ")*%s;", uv.vsOut(),
63 dfTexEffect.inTextureCoords()->fName);
64 #ifdef SK_GAMMA_APPLY_TO_A8 54 #ifdef SK_GAMMA_APPLY_TO_A8
65 // adjust based on gamma 55 // adjust based on gamma
66 const char* distanceAdjustUniName = NULL; 56 const char* distanceAdjustUniName = NULL;
67 // width, height, 1/(3*width) 57 // width, height, 1/(3*width)
68 fDistanceAdjustUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_ Visibility, 58 fDistanceAdjustUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_ Visibility,
69 kFloat_GrSLType, kDefault_GrSLPrecision, 59 kFloat_GrSLType, kDefault_GrSLPrecision,
70 "DistanceAdjust", &distanceAdjustUniName); 60 "DistanceAdjust", &distanceAdjustUniName);
71 #endif 61 #endif
72 62
73 // Setup pass through color 63 // Setup pass through color
74 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor , 64 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor ,
75 dfTexEffect.inColor(), &fColorUniform); 65 dfTexEffect.inColor(), &fColorUniform);
76 66
77 // Setup position 67 // Setup position
78 this->setupPosition(pb, gpArgs, dfTexEffect.inPosition()->fName, dfTexEf fect.viewMatrix()); 68 this->setupPosition(pb, gpArgs, dfTexEffect.inPosition()->fName, dfTexEf fect.viewMatrix());
79 69
80 // emit transforms 70 // emit transforms
81 this->emitTransforms(args.fPB, gpArgs->fPositionVar, dfTexEffect.inPosit ion()->fName, 71 this->emitTransforms(args.fPB, gpArgs->fPositionVar, dfTexEffect.inPosit ion()->fName,
82 dfTexEffect.localMatrix(), args.fTransformsIn, args .fTransformsOut); 72 dfTexEffect.localMatrix(), args.fTransformsIn, args .fTransformsOut);
83 73
74 // add varyings
75 GrGLVertToFrag recipScale(kFloat_GrSLType);
76 GrGLVertToFrag st(kVec2f_GrSLType);
77 bool isSimilarity = !!(dfTexEffect.getFlags() & kSimilarity_DistanceFiel dEffectFlag);
bsalomon 2015/04/03 21:16:30 SkToBool?
jvanverth1 2015/04/06 14:14:47 Done.
78 const char* viewMatrixName = this->uViewM();
79 if (isSimilarity && viewMatrixName) {
80 args.fPB->addVarying("RecipScale", &recipScale, kHigh_GrSLPrecision) ;
81 vsBuilder->codeAppendf("vec2 tx = vec2(%s[0][0], %s[1][0]);",
82 viewMatrixName, viewMatrixName);
83 vsBuilder->codeAppend("float tx2 = dot(tx, tx);");
84 vsBuilder->codeAppendf("%s = inversesqrt(tx2);", recipScale.vsOut()) ;
85 } else {
86 args.fPB->addVarying("IntTextureCoords", &st, kHigh_GrSLPrecision);
87 vsBuilder->codeAppendf("%s = %s;", st.vsOut(), dfTexEffect.inTexture Coords()->fName);
88 }
89
90 GrGLVertToFrag uv(kVec2f_GrSLType);
91 args.fPB->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision);
92 // this is only used with text, so our texture bounds always match the g lyph atlas
93 vsBuilder->codeAppendf("%s = vec2(" GR_FONT_ATLAS_A8_RECIP_WIDTH ", "
94 GR_FONT_ATLAS_RECIP_HEIGHT ")*%s;", uv.vsOut(),
95 dfTexEffect.inTextureCoords()->fName);
96
97
84 // Use highp to work around aliasing issues 98 // Use highp to work around aliasing issues
85 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision , 99 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision ,
86 pb->ctxInfo().stand ard())); 100 pb->ctxInfo().stand ard()));
87 fsBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn()); 101 fsBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn());
88 102
89 fsBuilder->codeAppend("\tfloat texColor = "); 103 fsBuilder->codeAppend("\tfloat texColor = ");
90 fsBuilder->appendTextureLookup(args.fSamplers[0], 104 fsBuilder->appendTextureLookup(args.fSamplers[0],
91 "uv", 105 "uv",
92 kVec2f_GrSLType); 106 kVec2f_GrSLType);
93 fsBuilder->codeAppend(".r;\n"); 107 fsBuilder->codeAppend(".r;\n");
94 fsBuilder->codeAppend("\tfloat distance = " 108 fsBuilder->codeAppend("\tfloat distance = "
95 SK_DistanceFieldMultiplier "*(texColor - " SK_DistanceFie ldThreshold ");"); 109 SK_DistanceFieldMultiplier "*(texColor - " SK_DistanceFie ldThreshold ");");
96 #ifdef SK_GAMMA_APPLY_TO_A8 110 #ifdef SK_GAMMA_APPLY_TO_A8
97 // adjust width based on gamma 111 // adjust width based on gamma
98 fsBuilder->codeAppendf("distance -= %s;", distanceAdjustUniName); 112 fsBuilder->codeAppendf("distance -= %s;", distanceAdjustUniName);
99 #endif 113 #endif
100 114
101 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision , 115 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision ,
102 pb->ctxInfo().stand ard())); 116 pb->ctxInfo().stand ard()));
103 fsBuilder->codeAppendf("vec2 st = %s;", st.fsIn());
104 fsBuilder->codeAppend("float afwidth;"); 117 fsBuilder->codeAppend("float afwidth;");
105 if (dfTexEffect.getFlags() & kSimilarity_DistanceFieldEffectFlag) { 118 if (isSimilarity) {
106 // For uniform scale, we adjust for the effect of the transformation on the distance 119 // For uniform scale, we adjust for the effect of the transformation on the distance
120 // either by using the inverse scale in the view matrix, or (if ther e is no view matrix)
107 // by using the length of the gradient of the texture coordinates. W e use st coordinates 121 // by using the length of the gradient of the texture coordinates. W e use st coordinates
108 // to ensure we're mapping 1:1 from texel space to pixel space. 122 // with the latter to ensure we're mapping 1:1 from texel space to p ixel space.
109 123
110 // this gives us a smooth step across approximately one fragment 124 // this gives us a smooth step across approximately one fragment
111 fsBuilder->codeAppend("afwidth = abs(" SK_DistanceFieldAAFactor "*dF dx(st.x));"); 125 if (viewMatrixName) {
126 fsBuilder->codeAppendf("afwidth = abs(" SK_DistanceFieldAAFactor "*%s);",
127 recipScale.fsIn());
128 } else {
129 fsBuilder->codeAppendf("afwidth = abs(" SK_DistanceFieldAAFactor "*dFdx(%s.x));",
130 st.fsIn());
131 }
112 } else { 132 } else {
133 fsBuilder->codeAppendf("vec2 st = %s;", st.fsIn());
113 // For general transforms, to determine the amount of correction we multiply a unit 134 // For general transforms, to determine the amount of correction we multiply a unit
114 // vector pointing along the SDF gradient direction by the Jacobian of the st coords 135 // vector pointing along the SDF gradient direction by the Jacobian of the st coords
115 // (which is the inverse transform for this fragment) and take the l ength of the result. 136 // (which is the inverse transform for this fragment) and take the l ength of the result.
116 fsBuilder->codeAppend("vec2 dist_grad = vec2(dFdx(distance), dFdy(di stance));"); 137 fsBuilder->codeAppend("vec2 dist_grad = vec2(dFdx(distance), dFdy(di stance));");
117 // the length of the gradient may be 0, so we need to check for this 138 // the length of the gradient may be 0, so we need to check for this
118 // this also compensates for the Adreno, which likes to drop tiles o n division by 0 139 // this also compensates for the Adreno, which likes to drop tiles o n division by 0
119 fsBuilder->codeAppend("float dg_len2 = dot(dist_grad, dist_grad);"); 140 fsBuilder->codeAppend("float dg_len2 = dot(dist_grad, dist_grad);");
120 fsBuilder->codeAppend("if (dg_len2 < 0.0001) {"); 141 fsBuilder->codeAppend("if (dg_len2 < 0.0001) {");
121 fsBuilder->codeAppend("dist_grad = vec2(0.7071, 0.7071);"); 142 fsBuilder->codeAppend("dist_grad = vec2(0.7071, 0.7071);");
122 fsBuilder->codeAppend("} else {"); 143 fsBuilder->codeAppend("} else {");
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 UniformHandle fDistanceAdjustUni; 202 UniformHandle fDistanceAdjustUni;
182 #endif 203 #endif
183 204
184 typedef GrGLGeometryProcessor INHERITED; 205 typedef GrGLGeometryProcessor INHERITED;
185 }; 206 };
186 207
187 /////////////////////////////////////////////////////////////////////////////// 208 ///////////////////////////////////////////////////////////////////////////////
188 209
189 GrDistanceFieldTextureEffect::GrDistanceFieldTextureEffect(GrColor color, 210 GrDistanceFieldTextureEffect::GrDistanceFieldTextureEffect(GrColor color,
190 const SkMatrix& viewM atrix, 211 const SkMatrix& viewM atrix,
212 const SkMatrix& local Matrix,
191 GrTexture* texture, 213 GrTexture* texture,
192 const GrTextureParams & params, 214 const GrTextureParams & params,
193 #ifdef SK_GAMMA_APPLY_TO_A8 215 #ifdef SK_GAMMA_APPLY_TO_A8
194 float distanceAdjust, 216 float distanceAdjust,
195 #endif 217 #endif
196 uint32_t flags, bool opaqueVertexColors) 218 uint32_t flags, bool opaqueVertexColors)
197 : INHERITED(color, viewMatrix, SkMatrix::I(), opaqueVertexColors) 219 : INHERITED(color, viewMatrix, localMatrix, opaqueVertexColors)
198 , fTextureAccess(texture, params) 220 , fTextureAccess(texture, params)
199 #ifdef SK_GAMMA_APPLY_TO_A8 221 #ifdef SK_GAMMA_APPLY_TO_A8
200 , fDistanceAdjust(distanceAdjust) 222 , fDistanceAdjust(distanceAdjust)
201 #endif 223 #endif
202 , fFlags(flags & kNonLCD_DistanceFieldEffectMask) 224 , fFlags(flags & kNonLCD_DistanceFieldEffectMask)
203 , fInColor(NULL) { 225 , fInColor(NULL) {
204 SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask)); 226 SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask));
205 this->initClassID<GrDistanceFieldTextureEffect>(); 227 this->initClassID<GrDistanceFieldTextureEffect>();
206 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex AttribType)); 228 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex AttribType));
207 if (flags & kColorAttr_DistanceFieldEffectFlag) { 229 if (flags & kColorAttr_DistanceFieldEffectFlag) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 }; 296 };
275 SkShader::TileMode tileModes[] = { 297 SkShader::TileMode tileModes[] = {
276 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], 298 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
277 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], 299 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
278 }; 300 };
279 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil erp_FilterMode : 301 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil erp_FilterMode :
280 GrTextureParams::kNon e_FilterMode); 302 GrTextureParams::kNon e_FilterMode);
281 303
282 return GrDistanceFieldTextureEffect::Create(GrRandomColor(random), 304 return GrDistanceFieldTextureEffect::Create(GrRandomColor(random),
283 GrProcessorUnitTest::TestMatrix( random), 305 GrProcessorUnitTest::TestMatrix( random),
306 GrProcessorUnitTest::TestMatrix( random),
284 textures[texIdx], params, 307 textures[texIdx], params,
285 #ifdef SK_GAMMA_APPLY_TO_A8 308 #ifdef SK_GAMMA_APPLY_TO_A8
286 random->nextF(), 309 random->nextF(),
287 #endif 310 #endif
288 random->nextBool() ? 311 random->nextBool() ?
289 kSimilarity_DistanceFieldEff ectFlag : 0, 312 kSimilarity_DistanceFieldEff ectFlag : 0,
290 random->nextBool()); 313 random->nextBool());
291 } 314 }
292 315
293 /////////////////////////////////////////////////////////////////////////////// 316 ///////////////////////////////////////////////////////////////////////////////
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 const GrDistanceFieldLCDTextureEffect& dfTexEffect = 580 const GrDistanceFieldLCDTextureEffect& dfTexEffect =
558 args.fGP.cast<GrDistanceFieldLCDTextureEffect>(); 581 args.fGP.cast<GrDistanceFieldLCDTextureEffect>();
559 const DistanceFieldLCDBatchTracker& local = args.fBT.cast<DistanceFieldL CDBatchTracker>(); 582 const DistanceFieldLCDBatchTracker& local = args.fBT.cast<DistanceFieldL CDBatchTracker>();
560 GrGLGPBuilder* pb = args.fPB; 583 GrGLGPBuilder* pb = args.fPB;
561 584
562 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); 585 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();
563 586
564 // emit attributes 587 // emit attributes
565 vsBuilder->emitAttributes(dfTexEffect); 588 vsBuilder->emitAttributes(dfTexEffect);
566 589
567 GrGLVertToFrag st(kVec2f_GrSLType);
568 args.fPB->addVarying("IntTextureCoords", &st, kHigh_GrSLPrecision);
569 vsBuilder->codeAppendf("%s = %s;", st.vsOut(), dfTexEffect.inTextureCoor ds()->fName);
570
571 GrGLVertToFrag uv(kVec2f_GrSLType);
572 args.fPB->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision);
573 // this is only used with text, so our texture bounds always match the g lyph atlas
574 vsBuilder->codeAppendf("%s = vec2(" GR_FONT_ATLAS_A8_RECIP_WIDTH ", "
575 GR_FONT_ATLAS_RECIP_HEIGHT ")*%s;", uv.vsOut(),
576 dfTexEffect.inTextureCoords()->fName);
577
578 // setup pass through color 590 // setup pass through color
579 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor , NULL, 591 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor , NULL,
580 &fColorUniform); 592 &fColorUniform);
581 593
582 // Setup position 594 // Setup position
583 this->setupPosition(pb, gpArgs, dfTexEffect.inPosition()->fName, dfTexEf fect.viewMatrix()); 595 this->setupPosition(pb, gpArgs, dfTexEffect.inPosition()->fName, dfTexEf fect.viewMatrix());
584 596
585 // emit transforms 597 // emit transforms
586 this->emitTransforms(args.fPB, gpArgs->fPositionVar, dfTexEffect.inPosit ion()->fName, 598 this->emitTransforms(args.fPB, gpArgs->fPositionVar, dfTexEffect.inPosit ion()->fName,
587 dfTexEffect.localMatrix(), args.fTransformsIn, args .fTransformsOut); 599 dfTexEffect.localMatrix(), args.fTransformsIn, args .fTransformsOut);
588 600
601 // set up varyings
602 bool isUniformScale = !!(dfTexEffect.getFlags() & kUniformScale_Distance FieldEffectMask);
bsalomon 2015/04/03 21:16:30 SkToBool?
jvanverth1 2015/04/06 14:14:47 Done.
603 GrGLVertToFrag recipScale(kFloat_GrSLType);
604 GrGLVertToFrag st(kVec2f_GrSLType);
605 const char* viewMatrixName = this->uViewM();
606 if (isUniformScale && viewMatrixName) {
607 args.fPB->addVarying("RecipScale", &recipScale, kHigh_GrSLPrecision) ;
608 vsBuilder->codeAppendf("vec2 tx = vec2(%s[0][0], %s[1][0]);",
609 viewMatrixName, viewMatrixName);
610 vsBuilder->codeAppend("float tx2 = dot(tx, tx);");
611 vsBuilder->codeAppendf("%s = inversesqrt(tx2);", recipScale.vsOut()) ;
612 } else {
613 args.fPB->addVarying("IntTextureCoords", &st, kHigh_GrSLPrecision);
614 vsBuilder->codeAppendf("%s = %s;", st.vsOut(), dfTexEffect.inTexture Coords()->fName);
615 }
616
617 GrGLVertToFrag uv(kVec2f_GrSLType);
618 args.fPB->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision);
619 // this is only used with text, so our texture bounds always match the g lyph atlas
620 vsBuilder->codeAppendf("%s = vec2(" GR_FONT_ATLAS_A8_RECIP_WIDTH ", "
621 GR_FONT_ATLAS_RECIP_HEIGHT ")*%s;", uv.vsOut(),
622 dfTexEffect.inTextureCoords()->fName);
623
624 // add frag shader code
589 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); 625 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
590 626
591 SkAssertResult(fsBuilder->enableFeature( 627 SkAssertResult(fsBuilder->enableFeature(
592 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); 628 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature));
593 629
594 // create LCD offset adjusted by inverse of transform 630 // create LCD offset adjusted by inverse of transform
595 // Use highp to work around aliasing issues 631 // Use highp to work around aliasing issues
596 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision , 632 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision ,
597 pb->ctxInfo().stand ard())); 633 pb->ctxInfo().stand ard()));
598 fsBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn()); 634 fsBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn());
599 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision , 635 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision ,
600 pb->ctxInfo().stand ard())); 636 pb->ctxInfo().stand ard()));
601 fsBuilder->codeAppendf("vec2 st = %s;\n", st.fsIn());
602 bool isUniformScale = !!(dfTexEffect.getFlags() & kUniformScale_Distance FieldEffectMask);
603
604 if (dfTexEffect.getFlags() & kBGR_DistanceFieldEffectFlag) { 637 if (dfTexEffect.getFlags() & kBGR_DistanceFieldEffectFlag) {
605 fsBuilder->codeAppend("float delta = -" GR_FONT_ATLAS_LCD_DELTA ";\n "); 638 fsBuilder->codeAppend("float delta = -" GR_FONT_ATLAS_LCD_DELTA ";\n ");
606 } else { 639 } else {
607 fsBuilder->codeAppend("float delta = " GR_FONT_ATLAS_LCD_DELTA ";\n" ); 640 fsBuilder->codeAppend("float delta = " GR_FONT_ATLAS_LCD_DELTA ";\n" );
608 } 641 }
609 if (isUniformScale) { 642 if (isUniformScale) {
610 fsBuilder->codeAppend("\tfloat dx = dFdx(st.x);\n"); 643 if (viewMatrixName) {
611 fsBuilder->codeAppend("\tvec2 offset = vec2(dx*delta, 0.0);\n"); 644 fsBuilder->codeAppendf("float dx = %s;", recipScale.fsIn());
645 } else {
646 fsBuilder->codeAppendf("float dx = dFdx(%s.x);", st.fsIn());
647 }
648 fsBuilder->codeAppend("vec2 offset = vec2(dx*delta, 0.0);");
612 } else { 649 } else {
613 fsBuilder->codeAppend("\tvec2 Jdx = dFdx(st);\n"); 650 fsBuilder->codeAppendf("vec2 st = %s;\n", st.fsIn());
614 fsBuilder->codeAppend("\tvec2 Jdy = dFdy(st);\n"); 651
615 fsBuilder->codeAppend("\tvec2 offset = delta*Jdx;\n"); 652 fsBuilder->codeAppend("vec2 Jdx = dFdx(st);");
653 fsBuilder->codeAppend("vec2 Jdy = dFdy(st);");
654 fsBuilder->codeAppend("vec2 offset = delta*Jdx;");
616 } 655 }
617 656
618 // green is distance to uv center 657 // green is distance to uv center
619 fsBuilder->codeAppend("\tvec4 texColor = "); 658 fsBuilder->codeAppend("\tvec4 texColor = ");
620 fsBuilder->appendTextureLookup(args.fSamplers[0], "uv", kVec2f_GrSLType) ; 659 fsBuilder->appendTextureLookup(args.fSamplers[0], "uv", kVec2f_GrSLType) ;
621 fsBuilder->codeAppend(";\n"); 660 fsBuilder->codeAppend(";\n");
622 fsBuilder->codeAppend("\tvec3 distance;\n"); 661 fsBuilder->codeAppend("\tvec3 distance;\n");
623 fsBuilder->codeAppend("\tdistance.y = texColor.r;\n"); 662 fsBuilder->codeAppend("\tdistance.y = texColor.r;\n");
624 // red is distance to left offset 663 // red is distance to left offset
625 fsBuilder->codeAppend("\tvec2 uv_adjusted = uv - offset;\n"); 664 fsBuilder->codeAppend("\tvec2 uv_adjusted = uv - offset;\n");
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 GrDistanceFieldLCDTextureEffect::DistanceAdjust fDistanceAdjust; 769 GrDistanceFieldLCDTextureEffect::DistanceAdjust fDistanceAdjust;
731 UniformHandle fDistanceAdjustUni; 770 UniformHandle fDistanceAdjustUni;
732 771
733 typedef GrGLGeometryProcessor INHERITED; 772 typedef GrGLGeometryProcessor INHERITED;
734 }; 773 };
735 774
736 /////////////////////////////////////////////////////////////////////////////// 775 ///////////////////////////////////////////////////////////////////////////////
737 776
738 GrDistanceFieldLCDTextureEffect::GrDistanceFieldLCDTextureEffect( 777 GrDistanceFieldLCDTextureEffect::GrDistanceFieldLCDTextureEffect(
739 GrColor color, const SkMatrix& viewMatrix, 778 GrColor color, const SkMatrix& viewMatrix,
779 const SkMatrix& localMatrix,
740 GrTexture* texture, const GrTe xtureParams& params, 780 GrTexture* texture, const GrTe xtureParams& params,
741 DistanceAdjust distanceAdjust, 781 DistanceAdjust distanceAdjust,
742 uint32_t flags) 782 uint32_t flags)
743 : INHERITED(color, viewMatrix, SkMatrix::I()) 783 : INHERITED(color, viewMatrix, localMatrix)
744 , fTextureAccess(texture, params) 784 , fTextureAccess(texture, params)
745 , fDistanceAdjust(distanceAdjust) 785 , fDistanceAdjust(distanceAdjust)
746 , fFlags(flags & kLCD_DistanceFieldEffectMask){ 786 , fFlags(flags & kLCD_DistanceFieldEffectMask){
747 SkASSERT(!(flags & ~kLCD_DistanceFieldEffectMask) && (flags & kUseLCD_Distan ceFieldEffectFlag)); 787 SkASSERT(!(flags & ~kLCD_DistanceFieldEffectMask) && (flags & kUseLCD_Distan ceFieldEffectFlag));
748 this->initClassID<GrDistanceFieldLCDTextureEffect>(); 788 this->initClassID<GrDistanceFieldLCDTextureEffect>();
749 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex AttribType)); 789 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex AttribType));
750 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", 790 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords",
751 kVec2s_GrVertexAttribT ype)); 791 kVec2s_GrVertexAttribT ype));
752 this->addTextureAccess(&fTextureAccess); 792 this->addTextureAccess(&fTextureAccess);
753 } 793 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], 854 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
815 }; 855 };
816 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil erp_FilterMode : 856 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil erp_FilterMode :
817 GrTextureParams::kNone_FilterMode); 857 GrTextureParams::kNone_FilterMode);
818 DistanceAdjust wa = { 0.0f, 0.1f, -0.1f }; 858 DistanceAdjust wa = { 0.0f, 0.1f, -0.1f };
819 uint32_t flags = kUseLCD_DistanceFieldEffectFlag; 859 uint32_t flags = kUseLCD_DistanceFieldEffectFlag;
820 flags |= random->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; 860 flags |= random->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0;
821 flags |= random->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; 861 flags |= random->nextBool() ? kBGR_DistanceFieldEffectFlag : 0;
822 return GrDistanceFieldLCDTextureEffect::Create(GrRandomColor(random), 862 return GrDistanceFieldLCDTextureEffect::Create(GrRandomColor(random),
823 GrProcessorUnitTest::TestMatr ix(random), 863 GrProcessorUnitTest::TestMatr ix(random),
864 GrProcessorUnitTest::TestMatr ix(random),
824 textures[texIdx], params, 865 textures[texIdx], params,
825 wa, 866 wa,
826 flags); 867 flags);
827 } 868 }
OLDNEW
« 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