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

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

Issue 920333003: Revert of Use uint16s for texture coordinates when rendering text. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 10 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/GrBitmapTextGeoProc.cpp ('k') | src/gpu/gl/GrGLVertexArray.h » ('j') | 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"
10 #include "GrInvariantOutput.h" 9 #include "GrInvariantOutput.h"
11 #include "GrTexture.h" 10 #include "GrTexture.h"
12 #include "SkDistanceFieldGen.h" 11 #include "SkDistanceFieldGen.h"
13 #include "gl/GrGLProcessor.h" 12 #include "gl/GrGLProcessor.h"
14 #include "gl/GrGLSL.h" 13 #include "gl/GrGLSL.h"
15 #include "gl/GrGLTexture.h" 14 #include "gl/GrGLTexture.h"
16 #include "gl/GrGLGeometryProcessor.h" 15 #include "gl/GrGLGeometryProcessor.h"
17 #include "gl/builders/GrGLProgramBuilder.h" 16 #include "gl/builders/GrGLProgramBuilder.h"
18 17
19 // Assuming a radius of the diagonal of the fragment, hence a factor of sqrt(2)/ 2 18 // Assuming a radius of the diagonal of the fragment, hence a factor of sqrt(2)/ 2
20 #define SK_DistanceFieldAAFactor "0.7071" 19 #define SK_DistanceFieldAAFactor "0.7071"
21 20
22 struct DistanceFieldBatchTracker { 21 struct DistanceFieldBatchTracker {
23 GrGPInput fInputColorType; 22 GrGPInput fInputColorType;
24 GrColor fColor; 23 GrColor fColor;
25 bool fUsesLocalCoords; 24 bool fUsesLocalCoords;
26 }; 25 };
27 26
28 class GrGLDistanceFieldTextureEffect : public GrGLGeometryProcessor { 27 class GrGLDistanceFieldTextureEffect : public GrGLGeometryProcessor {
29 public: 28 public:
30 GrGLDistanceFieldTextureEffect(const GrGeometryProcessor&, 29 GrGLDistanceFieldTextureEffect(const GrGeometryProcessor&,
31 const GrBatchTracker&) 30 const GrBatchTracker&)
32 : fColor(GrColor_ILLEGAL) 31 : fColor(GrColor_ILLEGAL)
32 , fTextureSize(SkISize::Make(-1,-1))
33 #ifdef SK_GAMMA_APPLY_TO_A8 33 #ifdef SK_GAMMA_APPLY_TO_A8
34 , fLuminance(-1.0f) 34 , fLuminance(-1.0f)
35 #endif 35 #endif
36 {} 36 {}
37 37
38 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) SK_OVERRIDE{ 38 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) SK_OVERRIDE{
39 const GrDistanceFieldTextureEffect& dfTexEffect = 39 const GrDistanceFieldTextureEffect& dfTexEffect =
40 args.fGP.cast<GrDistanceFieldTextureEffect>(); 40 args.fGP.cast<GrDistanceFieldTextureEffect>();
41 const DistanceFieldBatchTracker& local = args.fBT.cast<DistanceFieldBatc hTracker>(); 41 const DistanceFieldBatchTracker& local = args.fBT.cast<DistanceFieldBatc hTracker>();
42 GrGLGPBuilder* pb = args.fPB; 42 GrGLGPBuilder* pb = args.fPB;
43 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); 43 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
44 SkAssertResult(fsBuilder->enableFeature( 44 SkAssertResult(fsBuilder->enableFeature(
45 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); 45 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature));
46 46
47 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); 47 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();
48 48
49 // emit attributes 49 // emit attributes
50 vsBuilder->emitAttributes(dfTexEffect); 50 vsBuilder->emitAttributes(dfTexEffect);
51 51
52 GrGLVertToFrag st(kVec2f_GrSLType); 52 GrGLVertToFrag v(kVec2f_GrSLType);
53 args.fPB->addVarying("IntTextureCoords", &st); 53 args.fPB->addVarying("TextureCoords", &v);
54 vsBuilder->codeAppendf("%s = %s;", st.vsOut(), dfTexEffect.inTextureCoor ds()->fName); 54 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), dfTexEffect.inTextureCoord s()->fName);
55
56 GrGLVertToFrag uv(kVec2f_GrSLType);
57 args.fPB->addVarying("TextureCoords", &uv);
58 // this is only used with text, so our texture bounds always match the g lyph atlas
59 vsBuilder->codeAppendf("%s = vec2(" GR_FONT_ATLAS_RECIP_WIDTH ", "
60 GR_FONT_ATLAS_RECIP_HEIGHT ")*%s;", uv.vsOut(),
61 dfTexEffect.inTextureCoords()->fName);
62 55
63 // Setup pass through color 56 // Setup pass through color
64 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor , 57 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor ,
65 dfTexEffect.inColor(), &fColorUniform); 58 dfTexEffect.inColor(), &fColorUniform);
66 59
67 // Setup position 60 // Setup position
68 this->setupPosition(pb, gpArgs, dfTexEffect.inPosition()->fName, dfTexEf fect.viewMatrix()); 61 this->setupPosition(pb, gpArgs, dfTexEffect.inPosition()->fName, dfTexEf fect.viewMatrix());
69 62
70 // emit transforms 63 // emit transforms
71 this->emitTransforms(args.fPB, gpArgs->fPositionVar, dfTexEffect.inPosit ion()->fName, 64 this->emitTransforms(args.fPB, gpArgs->fPositionVar, dfTexEffect.inPosit ion()->fName,
72 dfTexEffect.localMatrix(), args.fTransformsIn, args .fTransformsOut); 65 dfTexEffect.localMatrix(), args.fTransformsIn, args .fTransformsOut);
73 66
67 const char* textureSizeUniName = NULL;
68 fTextureSizeUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Vis ibility,
69 kVec2f_GrSLType, kDefault_GrSLPre cision,
70 "TextureSize", &textureSizeUniNam e);
71
74 // Use highp to work around aliasing issues 72 // Use highp to work around aliasing issues
75 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision , 73 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision ,
76 pb->ctxInfo().stand ard())); 74 pb->ctxInfo().stand ard()));
77 fsBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn()); 75 fsBuilder->codeAppendf("vec2 uv = %s;\n", v.fsIn());
78 76
79 fsBuilder->codeAppend("\tfloat texColor = "); 77 fsBuilder->codeAppend("\tfloat texColor = ");
80 fsBuilder->appendTextureLookup(args.fSamplers[0], 78 fsBuilder->appendTextureLookup(args.fSamplers[0],
81 "uv", 79 "uv",
82 kVec2f_GrSLType); 80 kVec2f_GrSLType);
83 fsBuilder->codeAppend(".r;\n"); 81 fsBuilder->codeAppend(".r;\n");
84 fsBuilder->codeAppend("\tfloat distance = " 82 fsBuilder->codeAppend("\tfloat distance = "
85 SK_DistanceFieldMultiplier "*(texColor - " SK_DistanceFie ldThreshold ");"); 83 SK_DistanceFieldMultiplier "*(texColor - " SK_DistanceFie ldThreshold ");");
86 84
87 // we adjust for the effect of the transformation on the distance by usi ng 85 // we adjust for the effect of the transformation on the distance by usi ng
88 // the length of the gradient of the texture coordinates. We use st coor dinates 86 // the length of the gradient of the texture coordinates. We use st coor dinates
89 // to ensure we're mapping 1:1 from texel space to pixel space. 87 // to ensure we're mapping 1:1 from texel space to pixel space.
90 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision , 88 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision ,
91 pb->ctxInfo().stand ard())); 89 pb->ctxInfo().stand ard()));
92 fsBuilder->codeAppendf("vec2 st = %s;\n", st.fsIn()); 90 fsBuilder->codeAppendf("vec2 st = uv*%s;\n", textureSizeUniName);
93 fsBuilder->codeAppend("\tfloat afwidth;\n"); 91 fsBuilder->codeAppend("\tfloat afwidth;\n");
94 if (dfTexEffect.getFlags() & kSimilarity_DistanceFieldEffectFlag) { 92 if (dfTexEffect.getFlags() & kSimilarity_DistanceFieldEffectFlag) {
95 // this gives us a smooth step across approximately one fragment 93 // this gives us a smooth step across approximately one fragment
96 fsBuilder->codeAppend("\tafwidth = abs(" SK_DistanceFieldAAFactor "* dFdx(st.x));\n"); 94 fsBuilder->codeAppend("\tafwidth = abs(" SK_DistanceFieldAAFactor "* dFdx(st.x));\n");
97 } else { 95 } else {
98 fsBuilder->codeAppend("\tvec2 Jdx = dFdx(st);\n"); 96 fsBuilder->codeAppend("\tvec2 Jdx = dFdx(st);\n");
99 fsBuilder->codeAppend("\tvec2 Jdy = dFdy(st);\n"); 97 fsBuilder->codeAppend("\tvec2 Jdy = dFdy(st);\n");
100 98
101 fsBuilder->codeAppend("\tvec2 uv_grad;\n"); 99 fsBuilder->codeAppend("\tvec2 uv_grad;\n");
102 if (args.fPB->ctxInfo().caps()->dropsTileOnZeroDivide()) { 100 if (args.fPB->ctxInfo().caps()->dropsTileOnZeroDivide()) {
(...skipping 29 matching lines...) Expand all
132 fsBuilder->codeAppend(";\n"); 130 fsBuilder->codeAppend(";\n");
133 fsBuilder->codeAppend("\tval = gammaColor.r;\n"); 131 fsBuilder->codeAppend("\tval = gammaColor.r;\n");
134 #endif 132 #endif
135 133
136 fsBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage); 134 fsBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage);
137 } 135 }
138 136
139 virtual void setData(const GrGLProgramDataManager& pdman, 137 virtual void setData(const GrGLProgramDataManager& pdman,
140 const GrPrimitiveProcessor& proc, 138 const GrPrimitiveProcessor& proc,
141 const GrBatchTracker& bt) SK_OVERRIDE { 139 const GrBatchTracker& bt) SK_OVERRIDE {
140 SkASSERT(fTextureSizeUni.isValid());
141
142 GrTexture* texture = proc.texture(0);
143 if (texture->width() != fTextureSize.width() ||
144 texture->height() != fTextureSize.height()) {
145 fTextureSize = SkISize::Make(texture->width(), texture->height());
146 pdman.set2f(fTextureSizeUni,
147 SkIntToScalar(fTextureSize.width()),
148 SkIntToScalar(fTextureSize.height()));
149 }
142 #ifdef SK_GAMMA_APPLY_TO_A8 150 #ifdef SK_GAMMA_APPLY_TO_A8
143 const GrDistanceFieldTextureEffect& dfTexEffect = 151 const GrDistanceFieldTextureEffect& dfTexEffect =
144 proc.cast<GrDistanceFieldTextureEffect>(); 152 proc.cast<GrDistanceFieldTextureEffect>();
145 float luminance = dfTexEffect.getLuminance(); 153 float luminance = dfTexEffect.getLuminance();
146 if (luminance != fLuminance) { 154 if (luminance != fLuminance) {
147 pdman.set1f(fLuminanceUni, luminance); 155 pdman.set1f(fLuminanceUni, luminance);
148 fLuminance = luminance; 156 fLuminance = luminance;
149 } 157 }
150 #endif 158 #endif
151 159
(...skipping 17 matching lines...) Expand all
169 uint32_t key = dfTexEffect.getFlags(); 177 uint32_t key = dfTexEffect.getFlags();
170 key |= local.fInputColorType << 16; 178 key |= local.fInputColorType << 16;
171 key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x1 << 24: 0x0; 179 key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x1 << 24: 0x0;
172 key |= ComputePosKey(gp.viewMatrix()) << 25; 180 key |= ComputePosKey(gp.viewMatrix()) << 25;
173 b->add32(key); 181 b->add32(key);
174 } 182 }
175 183
176 private: 184 private:
177 GrColor fColor; 185 GrColor fColor;
178 UniformHandle fColorUniform; 186 UniformHandle fColorUniform;
187 UniformHandle fTextureSizeUni;
188 SkISize fTextureSize;
179 UniformHandle fLuminanceUni; 189 UniformHandle fLuminanceUni;
180 #ifdef SK_GAMMA_APPLY_TO_A8 190 #ifdef SK_GAMMA_APPLY_TO_A8
181 float fLuminance; 191 float fLuminance;
182 #endif 192 #endif
183 193
184 typedef GrGLGeometryProcessor INHERITED; 194 typedef GrGLGeometryProcessor INHERITED;
185 }; 195 };
186 196
187 /////////////////////////////////////////////////////////////////////////////// 197 ///////////////////////////////////////////////////////////////////////////////
188 198
(...skipping 16 matching lines...) Expand all
205 , fFlags(flags & kNonLCD_DistanceFieldEffectMask) 215 , fFlags(flags & kNonLCD_DistanceFieldEffectMask)
206 , fInColor(NULL) { 216 , fInColor(NULL) {
207 SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask)); 217 SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask));
208 this->initClassID<GrDistanceFieldTextureEffect>(); 218 this->initClassID<GrDistanceFieldTextureEffect>();
209 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex AttribType)); 219 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex AttribType));
210 if (flags & kColorAttr_DistanceFieldEffectFlag) { 220 if (flags & kColorAttr_DistanceFieldEffectFlag) {
211 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexA ttribType)); 221 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexA ttribType));
212 this->setHasVertexColor(); 222 this->setHasVertexColor();
213 } 223 }
214 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", 224 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords",
215 kVec2s_GrVertexAttribT ype)); 225 kVec2f_GrVertexAttribT ype));
216 this->addTextureAccess(&fTextureAccess); 226 this->addTextureAccess(&fTextureAccess);
217 #ifdef SK_GAMMA_APPLY_TO_A8 227 #ifdef SK_GAMMA_APPLY_TO_A8
218 this->addTextureAccess(&fGammaTextureAccess); 228 this->addTextureAccess(&fGammaTextureAccess);
219 #endif 229 #endif
220 } 230 }
221 231
222 bool GrDistanceFieldTextureEffect::onIsEqual(const GrGeometryProcessor& other) c onst { 232 bool GrDistanceFieldTextureEffect::onIsEqual(const GrGeometryProcessor& other) c onst {
223 const GrDistanceFieldTextureEffect& cte = other.cast<GrDistanceFieldTextureE ffect>(); 233 const GrDistanceFieldTextureEffect& cte = other.cast<GrDistanceFieldTextureE ffect>();
224 return 234 return
225 #ifdef SK_GAMMA_APPLY_TO_A8 235 #ifdef SK_GAMMA_APPLY_TO_A8
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 struct DistanceFieldNoGammaBatchTracker { 319 struct DistanceFieldNoGammaBatchTracker {
310 GrGPInput fInputColorType; 320 GrGPInput fInputColorType;
311 GrColor fColor; 321 GrColor fColor;
312 bool fUsesLocalCoords; 322 bool fUsesLocalCoords;
313 }; 323 };
314 324
315 class GrGLDistanceFieldNoGammaTextureEffect : public GrGLGeometryProcessor { 325 class GrGLDistanceFieldNoGammaTextureEffect : public GrGLGeometryProcessor {
316 public: 326 public:
317 GrGLDistanceFieldNoGammaTextureEffect(const GrGeometryProcessor&, 327 GrGLDistanceFieldNoGammaTextureEffect(const GrGeometryProcessor&,
318 const GrBatchTracker&) 328 const GrBatchTracker&)
319 : fColor(GrColor_ILLEGAL) {} 329 : fColor(GrColor_ILLEGAL), fTextureSize(SkISize::Make(-1, -1)) {}
320 330
321 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) SK_OVERRIDE{ 331 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) SK_OVERRIDE{
322 const GrDistanceFieldNoGammaTextureEffect& dfTexEffect = 332 const GrDistanceFieldNoGammaTextureEffect& dfTexEffect =
323 args.fGP.cast<GrDistanceFieldNoGammaTextureEffect>(); 333 args.fGP.cast<GrDistanceFieldNoGammaTextureEffect>();
324 334
325 const DistanceFieldNoGammaBatchTracker& local = 335 const DistanceFieldNoGammaBatchTracker& local =
326 args.fBT.cast<DistanceFieldNoGammaBatchTracker>(); 336 args.fBT.cast<DistanceFieldNoGammaBatchTracker>();
327 GrGLGPBuilder* pb = args.fPB; 337 GrGLGPBuilder* pb = args.fPB;
328 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); 338 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
329 SkAssertResult(fsBuilder->enableFeature( 339 SkAssertResult(fsBuilder->enableFeature(
330 GrGLFragmentShaderBuilder::kStandardDerivat ives_GLSLFeature)); 340 GrGLFragmentShaderBuilder::kStandardDerivat ives_GLSLFeature));
331 341
332 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); 342 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();
333 343
334 // emit attributes 344 // emit attributes
335 vsBuilder->emitAttributes(dfTexEffect); 345 vsBuilder->emitAttributes(dfTexEffect);
336 346
337 GrGLVertToFrag st(kVec2f_GrSLType); 347 GrGLVertToFrag v(kVec2f_GrSLType);
338 args.fPB->addVarying("IntTextureCoords", &st); 348 args.fPB->addVarying("TextureCoords", &v);
339 vsBuilder->codeAppendf("%s = %s;", st.vsOut(), dfTexEffect.inTextureCoor ds()->fName);
340
341 const char* recipTextureSizeUniName = NULL;
342 fRecipTextureSizeUni = args.fPB->addUniform(GrGLProgramBuilder::kVertex_ Visibility,
343 kVec2f_GrSLType, kDefault_Gr SLPrecision,
344 "RecipTextureSize", &recipTe xtureSizeUniName);
345 GrGLVertToFrag uv(kVec2f_GrSLType);
346 args.fPB->addVarying("TextureCoords", &uv);
347 // this GP can be used with either text or paths, so texture bound param s need to
348 // be set by a uniform
349 vsBuilder->codeAppendf("%s = %s*%s;", uv.vsOut(), recipTextureSizeUniNam e,
350 dfTexEffect.inTextureCoords()->fName);
351 349
352 // setup pass through color 350 // setup pass through color
353 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor , 351 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor ,
354 dfTexEffect.inColor(), &fColorUniform); 352 dfTexEffect.inColor(), &fColorUniform);
355 353
354 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), dfTexEffect.inTextureCoord s()->fName);
355
356 // Setup position 356 // Setup position
357 this->setupPosition(pb, gpArgs, dfTexEffect.inPosition()->fName, dfTexEf fect.viewMatrix()); 357 this->setupPosition(pb, gpArgs, dfTexEffect.inPosition()->fName, dfTexEf fect.viewMatrix());
358 358
359 // emit transforms 359 // emit transforms
360 this->emitTransforms(args.fPB, gpArgs->fPositionVar, dfTexEffect.inPosit ion()->fName, 360 this->emitTransforms(args.fPB, gpArgs->fPositionVar, dfTexEffect.inPosit ion()->fName,
361 dfTexEffect.localMatrix(), args.fTransformsIn, args .fTransformsOut); 361 dfTexEffect.localMatrix(), args.fTransformsIn, args .fTransformsOut);
362 362
363 const char* textureSizeUniName = NULL;
364 fTextureSizeUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Vis ibility,
365 kVec2f_GrSLType, kDefault_GrSLPrec ision,
366 "TextureSize", &textureSizeUniName );
367
363 // Use highp to work around aliasing issues 368 // Use highp to work around aliasing issues
364 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision , 369 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision ,
365 pb->ctxInfo().stand ard())); 370 pb->ctxInfo().stand ard()));
366 fsBuilder->codeAppendf("vec2 uv = %s;", uv.fsIn()); 371 fsBuilder->codeAppendf("vec2 uv = %s;", v.fsIn());
367 372
368 fsBuilder->codeAppend("float texColor = "); 373 fsBuilder->codeAppend("float texColor = ");
369 fsBuilder->appendTextureLookup(args.fSamplers[0], 374 fsBuilder->appendTextureLookup(args.fSamplers[0],
370 "uv", 375 "uv",
371 kVec2f_GrSLType); 376 kVec2f_GrSLType);
372 fsBuilder->codeAppend(".r;"); 377 fsBuilder->codeAppend(".r;");
373 fsBuilder->codeAppend("float distance = " 378 fsBuilder->codeAppend("float distance = "
374 SK_DistanceFieldMultiplier "*(texColor - " SK_DistanceFieldThreshold ");"); 379 SK_DistanceFieldMultiplier "*(texColor - " SK_DistanceFieldThreshold ");");
375 380
376 // we adjust for the effect of the transformation on the distance by usi ng 381 // we adjust for the effect of the transformation on the distance by usi ng
377 // the length of the gradient of the texture coordinates. We use st coor dinates 382 // the length of the gradient of the texture coordinates. We use st coor dinates
378 // to ensure we're mapping 1:1 from texel space to pixel space. 383 // to ensure we're mapping 1:1 from texel space to pixel space.
379 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision , 384 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision ,
380 pb->ctxInfo().stand ard())); 385 pb->ctxInfo().stand ard()));
381 fsBuilder->codeAppendf("vec2 st = %s;", st.fsIn()); 386 fsBuilder->codeAppendf("vec2 st = uv*%s;", textureSizeUniName);
382 fsBuilder->codeAppend("float afwidth;"); 387 fsBuilder->codeAppend("float afwidth;");
383 if (dfTexEffect.getFlags() & kSimilarity_DistanceFieldEffectFlag) { 388 if (dfTexEffect.getFlags() & kSimilarity_DistanceFieldEffectFlag) {
384 // this gives us a smooth step across approximately one fragment 389 // this gives us a smooth step across approximately one fragment
385 fsBuilder->codeAppend("afwidth = abs(" SK_DistanceFieldAAFactor "*dF dx(st.x));"); 390 fsBuilder->codeAppend("afwidth = abs(" SK_DistanceFieldAAFactor "*dF dx(st.x));");
386 } else { 391 } else {
387 fsBuilder->codeAppend("vec2 Jdx = dFdx(st);"); 392 fsBuilder->codeAppend("vec2 Jdx = dFdx(st);");
388 fsBuilder->codeAppend("vec2 Jdy = dFdy(st);"); 393 fsBuilder->codeAppend("vec2 Jdy = dFdy(st);");
389 394
390 fsBuilder->codeAppend("vec2 uv_grad;"); 395 fsBuilder->codeAppend("vec2 uv_grad;");
391 if (args.fPB->ctxInfo().caps()->dropsTileOnZeroDivide()) { 396 if (args.fPB->ctxInfo().caps()->dropsTileOnZeroDivide()) {
(...skipping 14 matching lines...) Expand all
406 fsBuilder->codeAppend("afwidth = " SK_DistanceFieldAAFactor "*length (grad);"); 411 fsBuilder->codeAppend("afwidth = " SK_DistanceFieldAAFactor "*length (grad);");
407 } 412 }
408 fsBuilder->codeAppend("float val = smoothstep(-afwidth, afwidth, distanc e);"); 413 fsBuilder->codeAppend("float val = smoothstep(-afwidth, afwidth, distanc e);");
409 414
410 fsBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage); 415 fsBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage);
411 } 416 }
412 417
413 virtual void setData(const GrGLProgramDataManager& pdman, 418 virtual void setData(const GrGLProgramDataManager& pdman,
414 const GrPrimitiveProcessor& proc, 419 const GrPrimitiveProcessor& proc,
415 const GrBatchTracker& bt) SK_OVERRIDE { 420 const GrBatchTracker& bt) SK_OVERRIDE {
416 SkASSERT(fRecipTextureSizeUni.isValid()); 421 SkASSERT(fTextureSizeUni.isValid());
417 422
418 GrTexture* texture = proc.texture(0); 423 GrTexture* texture = proc.texture(0);
419 if (texture->width() != fTextureSize.width() || 424 if (texture->width() != fTextureSize.width() ||
420 texture->height() != fTextureSize.height()) { 425 texture->height() != fTextureSize.height()) {
421 fTextureSize = SkISize::Make(texture->width(), texture->height()); 426 fTextureSize = SkISize::Make(texture->width(), texture->height());
422 pdman.set2f(fRecipTextureSizeUni, 427 pdman.set2f(fTextureSizeUni,
423 1.0f/SkIntToScalar(fTextureSize.width()), 428 SkIntToScalar(fTextureSize.width()),
424 1.0f/SkIntToScalar(fTextureSize.height())); 429 SkIntToScalar(fTextureSize.height()));
425 } 430 }
426 431
427 this->setUniformViewMatrix(pdman, proc.viewMatrix()); 432 this->setUniformViewMatrix(pdman, proc.viewMatrix());
428 433
429 const DistanceFieldNoGammaBatchTracker& local = bt.cast<DistanceFieldNoG ammaBatchTracker>(); 434 const DistanceFieldNoGammaBatchTracker& local = bt.cast<DistanceFieldNoG ammaBatchTracker>();
430 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColo r) { 435 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColo r) {
431 GrGLfloat c[4]; 436 GrGLfloat c[4];
432 GrColorToRGBAFloat(local.fColor, c); 437 GrColorToRGBAFloat(local.fColor, c);
433 pdman.set4fv(fColorUniform, 1, c); 438 pdman.set4fv(fColorUniform, 1, c);
434 fColor = local.fColor; 439 fColor = local.fColor;
(...skipping 10 matching lines...) Expand all
445 const DistanceFieldNoGammaBatchTracker& local = bt.cast<DistanceFieldNoG ammaBatchTracker>(); 450 const DistanceFieldNoGammaBatchTracker& local = bt.cast<DistanceFieldNoG ammaBatchTracker>();
446 uint32_t key = dfTexEffect.getFlags(); 451 uint32_t key = dfTexEffect.getFlags();
447 key |= local.fInputColorType << 16; 452 key |= local.fInputColorType << 16;
448 key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x1 << 24: 0x0; 453 key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x1 << 24: 0x0;
449 key |= ComputePosKey(gp.viewMatrix()) << 25; 454 key |= ComputePosKey(gp.viewMatrix()) << 25;
450 b->add32(key); 455 b->add32(key);
451 } 456 }
452 457
453 private: 458 private:
454 UniformHandle fColorUniform; 459 UniformHandle fColorUniform;
455 UniformHandle fRecipTextureSizeUni; 460 UniformHandle fTextureSizeUni;
456 GrColor fColor; 461 GrColor fColor;
457 SkISize fTextureSize; 462 SkISize fTextureSize;
458 463
459 typedef GrGLGeometryProcessor INHERITED; 464 typedef GrGLGeometryProcessor INHERITED;
460 }; 465 };
461 466
462 /////////////////////////////////////////////////////////////////////////////// 467 ///////////////////////////////////////////////////////////////////////////////
463 468
464 GrDistanceFieldNoGammaTextureEffect::GrDistanceFieldNoGammaTextureEffect( 469 GrDistanceFieldNoGammaTextureEffect::GrDistanceFieldNoGammaTextureEffect(
465 GrColor color, 470 GrColor color,
466 const SkMatrix& viewMatrix, 471 const SkMatrix& viewMatrix,
467 GrTexture* texture, 472 GrTexture* texture,
468 const GrTextureParams& params, 473 const GrTextureParams& params,
469 uint32_t flags, 474 uint32_t flags,
470 bool opaqueVertexColors) 475 bool opaqueVertexColors)
471 : INHERITED(color, viewMatrix, SkMatrix::I(), opaqueVertexColors) 476 : INHERITED(color, viewMatrix, SkMatrix::I(), opaqueVertexColors)
472 , fTextureAccess(texture, params) 477 , fTextureAccess(texture, params)
473 , fFlags(flags & kNonLCD_DistanceFieldEffectMask) 478 , fFlags(flags & kNonLCD_DistanceFieldEffectMask)
474 , fInColor(NULL) { 479 , fInColor(NULL) {
475 SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask)); 480 SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask));
476 this->initClassID<GrDistanceFieldNoGammaTextureEffect>(); 481 this->initClassID<GrDistanceFieldNoGammaTextureEffect>();
477 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex AttribType)); 482 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex AttribType));
478 if (flags & kColorAttr_DistanceFieldEffectFlag) { 483 if (flags & kColorAttr_DistanceFieldEffectFlag) {
479 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexA ttribType)); 484 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexA ttribType));
480 this->setHasVertexColor(); 485 this->setHasVertexColor();
481 } 486 }
482 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", 487 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords",
483 kVec2s_GrVertexAttribT ype)); 488 kVec2f_GrVertexAttribT ype));
484 this->addTextureAccess(&fTextureAccess); 489 this->addTextureAccess(&fTextureAccess);
485 } 490 }
486 491
487 bool GrDistanceFieldNoGammaTextureEffect::onIsEqual(const GrGeometryProcessor& o ther) const { 492 bool GrDistanceFieldNoGammaTextureEffect::onIsEqual(const GrGeometryProcessor& o ther) const {
488 const GrDistanceFieldNoGammaTextureEffect& cte = 493 const GrDistanceFieldNoGammaTextureEffect& cte =
489 other.cast<GrDistanceFieldNoGam maTextureEffect>(); 494 other.cast<GrDistanceFieldNoGam maTextureEffect>();
490 return fFlags == cte.fFlags; 495 return fFlags == cte.fFlags;
491 } 496 }
492 497
493 void GrDistanceFieldNoGammaTextureEffect::onGetInvariantOutputCoverage(GrInitInv ariantOutput* out) const{ 498 void GrDistanceFieldNoGammaTextureEffect::onGetInvariantOutputCoverage(GrInitInv ariantOutput* out) const{
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 GrGPInput fInputColorType; 565 GrGPInput fInputColorType;
561 GrColor fColor; 566 GrColor fColor;
562 bool fUsesLocalCoords; 567 bool fUsesLocalCoords;
563 }; 568 };
564 569
565 class GrGLDistanceFieldLCDTextureEffect : public GrGLGeometryProcessor { 570 class GrGLDistanceFieldLCDTextureEffect : public GrGLGeometryProcessor {
566 public: 571 public:
567 GrGLDistanceFieldLCDTextureEffect(const GrGeometryProcessor&, 572 GrGLDistanceFieldLCDTextureEffect(const GrGeometryProcessor&,
568 const GrBatchTracker&) 573 const GrBatchTracker&)
569 : fColor(GrColor_ILLEGAL) 574 : fColor(GrColor_ILLEGAL)
575 , fTextureSize(SkISize::Make(-1,-1))
570 , fTextColor(GrColor_ILLEGAL) {} 576 , fTextColor(GrColor_ILLEGAL) {}
571 577
572 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) SK_OVERRIDE{ 578 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) SK_OVERRIDE{
573 const GrDistanceFieldLCDTextureEffect& dfTexEffect = 579 const GrDistanceFieldLCDTextureEffect& dfTexEffect =
574 args.fGP.cast<GrDistanceFieldLCDTextureEffect>(); 580 args.fGP.cast<GrDistanceFieldLCDTextureEffect>();
575 const DistanceFieldLCDBatchTracker& local = args.fBT.cast<DistanceFieldL CDBatchTracker>(); 581 const DistanceFieldLCDBatchTracker& local = args.fBT.cast<DistanceFieldL CDBatchTracker>();
576 GrGLGPBuilder* pb = args.fPB; 582 GrGLGPBuilder* pb = args.fPB;
577 583
578 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); 584 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();
579 585
580 // emit attributes 586 // emit attributes
581 vsBuilder->emitAttributes(dfTexEffect); 587 vsBuilder->emitAttributes(dfTexEffect);
582 588
583 GrGLVertToFrag st(kVec2f_GrSLType); 589 GrGLVertToFrag v(kVec2f_GrSLType);
584 args.fPB->addVarying("IntTextureCoords", &st); 590 args.fPB->addVarying("TextureCoords", &v);
585 vsBuilder->codeAppendf("%s = %s;", st.vsOut(), dfTexEffect.inTextureCoor ds()->fName); 591 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), dfTexEffect.inTextureCoord s()->fName);
586 592
587 GrGLVertToFrag uv(kVec2f_GrSLType);
588 args.fPB->addVarying("TextureCoords", &uv);
589 // this is only used with text, so our texture bounds always match the g lyph atlas
590 vsBuilder->codeAppendf("%s = vec2(" GR_FONT_ATLAS_RECIP_WIDTH ", "
591 GR_FONT_ATLAS_RECIP_HEIGHT ")*%s;", uv.vsOut(),
592 dfTexEffect.inTextureCoords()->fName);
593
594 // setup pass through color 593 // setup pass through color
595 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor , NULL, 594 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor , NULL,
596 &fColorUniform); 595 &fColorUniform);
597 596
598 // Setup position 597 // Setup position
599 this->setupPosition(pb, gpArgs, dfTexEffect.inPosition()->fName, dfTexEf fect.viewMatrix()); 598 this->setupPosition(pb, gpArgs, dfTexEffect.inPosition()->fName, dfTexEf fect.viewMatrix());
600 599
601 // emit transforms 600 // emit transforms
602 this->emitTransforms(args.fPB, gpArgs->fPositionVar, dfTexEffect.inPosit ion()->fName, 601 this->emitTransforms(args.fPB, gpArgs->fPositionVar, dfTexEffect.inPosit ion()->fName,
603 dfTexEffect.localMatrix(), args.fTransformsIn, args .fTransformsOut); 602 dfTexEffect.localMatrix(), args.fTransformsIn, args .fTransformsOut);
604 603
604 const char* textureSizeUniName = NULL;
605 // width, height, 1/(3*width)
606 fTextureSizeUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Vis ibility,
607 kVec3f_GrSLType, kDefault_GrSLPrec ision,
608 "TextureSize", &textureSizeUniName );
609
605 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); 610 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
606 611
607 SkAssertResult(fsBuilder->enableFeature( 612 SkAssertResult(fsBuilder->enableFeature(
608 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); 613 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature));
609 614
610 // create LCD offset adjusted by inverse of transform 615 // create LCD offset adjusted by inverse of transform
611 // Use highp to work around aliasing issues 616 // Use highp to work around aliasing issues
612 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision , 617 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision ,
613 pb->ctxInfo().stand ard())); 618 pb->ctxInfo().stand ard()));
614 fsBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn()); 619 fsBuilder->codeAppendf("vec2 uv = %s;\n", v.fsIn());
615 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision , 620 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision ,
616 pb->ctxInfo().stand ard())); 621 pb->ctxInfo().stand ard()));
617 fsBuilder->codeAppendf("vec2 st = %s;\n", st.fsIn()); 622 fsBuilder->codeAppendf("vec2 st = uv*%s.xy;\n", textureSizeUniName);
618 bool isUniformScale = !!(dfTexEffect.getFlags() & kUniformScale_Distance FieldEffectMask); 623 bool isUniformScale = !!(dfTexEffect.getFlags() & kUniformScale_Distance FieldEffectMask);
619
620 if (dfTexEffect.getFlags() & kBGR_DistanceFieldEffectFlag) {
621 fsBuilder->codeAppend("float delta = -" GR_FONT_ATLAS_LCD_DELTA ";\n ");
622 } else {
623 fsBuilder->codeAppend("float delta = " GR_FONT_ATLAS_LCD_DELTA ";\n" );
624 }
625 if (isUniformScale) { 624 if (isUniformScale) {
626 fsBuilder->codeAppend("\tfloat dx = dFdx(st.x);\n"); 625 fsBuilder->codeAppend("\tfloat dx = dFdx(st.x);\n");
627 fsBuilder->codeAppend("\tvec2 offset = vec2(dx*delta, 0.0);\n"); 626 fsBuilder->codeAppendf("\tvec2 offset = vec2(dx*%s.z, 0.0);\n", text ureSizeUniName);
628 } else { 627 } else {
629 fsBuilder->codeAppend("\tvec2 Jdx = dFdx(st);\n"); 628 fsBuilder->codeAppend("\tvec2 Jdx = dFdx(st);\n");
630 fsBuilder->codeAppend("\tvec2 Jdy = dFdy(st);\n"); 629 fsBuilder->codeAppend("\tvec2 Jdy = dFdy(st);\n");
631 fsBuilder->codeAppend("\tvec2 offset = delta*Jdx;\n"); 630 fsBuilder->codeAppendf("\tvec2 offset = %s.z*Jdx;\n", textureSizeUni Name);
632 } 631 }
633 632
634 // green is distance to uv center 633 // green is distance to uv center
635 fsBuilder->codeAppend("\tvec4 texColor = "); 634 fsBuilder->codeAppend("\tvec4 texColor = ");
636 fsBuilder->appendTextureLookup(args.fSamplers[0], "uv", kVec2f_GrSLType) ; 635 fsBuilder->appendTextureLookup(args.fSamplers[0], "uv", kVec2f_GrSLType) ;
637 fsBuilder->codeAppend(";\n"); 636 fsBuilder->codeAppend(";\n");
638 fsBuilder->codeAppend("\tvec3 distance;\n"); 637 fsBuilder->codeAppend("\tvec3 distance;\n");
639 fsBuilder->codeAppend("\tdistance.y = texColor.r;\n"); 638 fsBuilder->codeAppend("\tdistance.y = texColor.r;\n");
640 // red is distance to left offset 639 // red is distance to left offset
641 fsBuilder->codeAppend("\tvec2 uv_adjusted = uv - offset;\n"); 640 fsBuilder->codeAppend("\tvec2 uv_adjusted = uv - offset;\n");
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 fsBuilder->codeAppend("\t uv_grad.x*Jdx.y + uv_grad. y*Jdy.y);\n"); 681 fsBuilder->codeAppend("\t uv_grad.x*Jdx.y + uv_grad. y*Jdy.y);\n");
683 682
684 // this gives us a smooth step across approximately one fragment 683 // this gives us a smooth step across approximately one fragment
685 fsBuilder->codeAppend("\tafwidth = " SK_DistanceFieldAAFactor "*leng th(grad);\n"); 684 fsBuilder->codeAppend("\tafwidth = " SK_DistanceFieldAAFactor "*leng th(grad);\n");
686 } 685 }
687 686
688 fsBuilder->codeAppend("\tvec4 val = vec4(smoothstep(vec3(-afwidth), vec3 (afwidth), distance), 1.0);\n"); 687 fsBuilder->codeAppend("\tvec4 val = vec4(smoothstep(vec3(-afwidth), vec3 (afwidth), distance), 1.0);\n");
689 688
690 // adjust based on gamma 689 // adjust based on gamma
691 const char* textColorUniName = NULL; 690 const char* textColorUniName = NULL;
691 // width, height, 1/(3*width)
692 fTextColorUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Visib ility, 692 fTextColorUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Visib ility,
693 kVec3f_GrSLType, kDefault_GrSLPreci sion, 693 kVec3f_GrSLType, kDefault_GrSLPreci sion,
694 "TextColor", &textColorUniName); 694 "TextColor", &textColorUniName);
695 695
696 fsBuilder->codeAppendf("\tuv = vec2(val.x, %s.x);\n", textColorUniName); 696 fsBuilder->codeAppendf("\tuv = vec2(val.x, %s.x);\n", textColorUniName);
697 fsBuilder->codeAppend("float gammaColor = "); 697 fsBuilder->codeAppend("float gammaColor = ");
698 fsBuilder->appendTextureLookup(args.fSamplers[1], "uv", kVec2f_GrSLType) ; 698 fsBuilder->appendTextureLookup(args.fSamplers[1], "uv", kVec2f_GrSLType) ;
699 fsBuilder->codeAppend(".r;\n"); 699 fsBuilder->codeAppend(".r;\n");
700 fsBuilder->codeAppend("\tval.x = gammaColor;\n"); 700 fsBuilder->codeAppend("\tval.x = gammaColor;\n");
701 701
702 fsBuilder->codeAppendf("\tuv = vec2(val.y, %s.y);\n", textColorUniName); 702 fsBuilder->codeAppendf("\tuv = vec2(val.y, %s.y);\n", textColorUniName);
703 fsBuilder->codeAppend("\tgammaColor = "); 703 fsBuilder->codeAppend("\tgammaColor = ");
704 fsBuilder->appendTextureLookup(args.fSamplers[1], "uv", kVec2f_GrSLType) ; 704 fsBuilder->appendTextureLookup(args.fSamplers[1], "uv", kVec2f_GrSLType) ;
705 fsBuilder->codeAppend(".r;\n"); 705 fsBuilder->codeAppend(".r;\n");
706 fsBuilder->codeAppend("\tval.y = gammaColor;\n"); 706 fsBuilder->codeAppend("\tval.y = gammaColor;\n");
707 707
708 fsBuilder->codeAppendf("\tuv = vec2(val.z, %s.z);\n", textColorUniName); 708 fsBuilder->codeAppendf("\tuv = vec2(val.z, %s.z);\n", textColorUniName);
709 fsBuilder->codeAppend("\tgammaColor = "); 709 fsBuilder->codeAppend("\tgammaColor = ");
710 fsBuilder->appendTextureLookup(args.fSamplers[1], "uv", kVec2f_GrSLType) ; 710 fsBuilder->appendTextureLookup(args.fSamplers[1], "uv", kVec2f_GrSLType) ;
711 fsBuilder->codeAppend(".r;\n"); 711 fsBuilder->codeAppend(".r;\n");
712 fsBuilder->codeAppend("\tval.z = gammaColor;\n"); 712 fsBuilder->codeAppend("\tval.z = gammaColor;\n");
713 713
714 fsBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage); 714 fsBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage);
715 } 715 }
716 716
717 virtual void setData(const GrGLProgramDataManager& pdman, 717 virtual void setData(const GrGLProgramDataManager& pdman,
718 const GrPrimitiveProcessor& processor, 718 const GrPrimitiveProcessor& processor,
719 const GrBatchTracker& bt) SK_OVERRIDE { 719 const GrBatchTracker& bt) SK_OVERRIDE {
720 SkASSERT(fTextureSizeUni.isValid());
720 SkASSERT(fTextColorUni.isValid()); 721 SkASSERT(fTextColorUni.isValid());
721 722
722 const GrDistanceFieldLCDTextureEffect& dfTexEffect = 723 const GrDistanceFieldLCDTextureEffect& dfTexEffect =
723 processor.cast<GrDistanceFieldLCDTextureEffect>(); 724 processor.cast<GrDistanceFieldLCDTextureEffect>();
725 GrTexture* texture = processor.texture(0);
726 if (texture->width() != fTextureSize.width() ||
727 texture->height() != fTextureSize.height()) {
728 fTextureSize = SkISize::Make(texture->width(), texture->height());
729 float delta = 1.0f/(3.0f*texture->width());
730 if (dfTexEffect.getFlags() & kBGR_DistanceFieldEffectFlag) {
731 delta = -delta;
732 }
733 pdman.set3f(fTextureSizeUni,
734 SkIntToScalar(fTextureSize.width()),
735 SkIntToScalar(fTextureSize.height()),
736 delta);
737 }
738
724 GrColor textColor = dfTexEffect.getTextColor(); 739 GrColor textColor = dfTexEffect.getTextColor();
725 if (textColor != fTextColor) { 740 if (textColor != fTextColor) {
726 static const float ONE_OVER_255 = 1.f / 255.f; 741 static const float ONE_OVER_255 = 1.f / 255.f;
727 pdman.set3f(fTextColorUni, 742 pdman.set3f(fTextColorUni,
728 GrColorUnpackR(textColor) * ONE_OVER_255, 743 GrColorUnpackR(textColor) * ONE_OVER_255,
729 GrColorUnpackG(textColor) * ONE_OVER_255, 744 GrColorUnpackG(textColor) * ONE_OVER_255,
730 GrColorUnpackB(textColor) * ONE_OVER_255); 745 GrColorUnpackB(textColor) * ONE_OVER_255);
731 fTextColor = textColor; 746 fTextColor = textColor;
732 } 747 }
733 748
(...skipping 19 matching lines...) Expand all
753 uint32_t key = dfTexEffect.getFlags(); 768 uint32_t key = dfTexEffect.getFlags();
754 key |= local.fInputColorType << 16; 769 key |= local.fInputColorType << 16;
755 key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x1 << 24: 0x0; 770 key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x1 << 24: 0x0;
756 key |= ComputePosKey(gp.viewMatrix()) << 25; 771 key |= ComputePosKey(gp.viewMatrix()) << 25;
757 b->add32(key); 772 b->add32(key);
758 } 773 }
759 774
760 private: 775 private:
761 GrColor fColor; 776 GrColor fColor;
762 UniformHandle fColorUniform; 777 UniformHandle fColorUniform;
778 UniformHandle fTextureSizeUni;
779 SkISize fTextureSize;
763 UniformHandle fTextColorUni; 780 UniformHandle fTextColorUni;
764 SkColor fTextColor; 781 SkColor fTextColor;
765 782
766 typedef GrGLGeometryProcessor INHERITED; 783 typedef GrGLGeometryProcessor INHERITED;
767 }; 784 };
768 785
769 /////////////////////////////////////////////////////////////////////////////// 786 ///////////////////////////////////////////////////////////////////////////////
770 787
771 GrDistanceFieldLCDTextureEffect::GrDistanceFieldLCDTextureEffect( 788 GrDistanceFieldLCDTextureEffect::GrDistanceFieldLCDTextureEffect(
772 GrColor color, const SkMatrix& viewMatrix, 789 GrColor color, const SkMatrix& viewMatrix,
773 GrTexture* texture, const GrTe xtureParams& params, 790 GrTexture* texture, const GrTe xtureParams& params,
774 GrTexture* gamma, const GrText ureParams& gParams, 791 GrTexture* gamma, const GrText ureParams& gParams,
775 SkColor textColor, 792 SkColor textColor,
776 uint32_t flags) 793 uint32_t flags)
777 : INHERITED(color, viewMatrix, SkMatrix::I()) 794 : INHERITED(color, viewMatrix, SkMatrix::I())
778 , fTextureAccess(texture, params) 795 , fTextureAccess(texture, params)
779 , fGammaTextureAccess(gamma, gParams) 796 , fGammaTextureAccess(gamma, gParams)
780 , fTextColor(textColor) 797 , fTextColor(textColor)
781 , fFlags(flags & kLCD_DistanceFieldEffectMask){ 798 , fFlags(flags & kLCD_DistanceFieldEffectMask){
782 SkASSERT(!(flags & ~kLCD_DistanceFieldEffectMask) && (flags & kUseLCD_Distan ceFieldEffectFlag)); 799 SkASSERT(!(flags & ~kLCD_DistanceFieldEffectMask) && (flags & kUseLCD_Distan ceFieldEffectFlag));
783 this->initClassID<GrDistanceFieldLCDTextureEffect>(); 800 this->initClassID<GrDistanceFieldLCDTextureEffect>();
784 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex AttribType)); 801 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex AttribType));
785 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", 802 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords",
786 kVec2s_GrVertexAttribT ype)); 803 kVec2f_GrVertexAttribT ype));
787 this->addTextureAccess(&fTextureAccess); 804 this->addTextureAccess(&fTextureAccess);
788 this->addTextureAccess(&fGammaTextureAccess); 805 this->addTextureAccess(&fGammaTextureAccess);
789 } 806 }
790 807
791 bool GrDistanceFieldLCDTextureEffect::onIsEqual(const GrGeometryProcessor& other ) const { 808 bool GrDistanceFieldLCDTextureEffect::onIsEqual(const GrGeometryProcessor& other ) const {
792 const GrDistanceFieldLCDTextureEffect& cte = other.cast<GrDistanceFieldLCDTe xtureEffect>(); 809 const GrDistanceFieldLCDTextureEffect& cte = other.cast<GrDistanceFieldLCDTe xtureEffect>();
793 return (fTextColor == cte.fTextColor && 810 return (fTextColor == cte.fTextColor &&
794 fFlags == cte.fFlags); 811 fFlags == cte.fFlags);
795 } 812 }
796 813
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 uint32_t flags = kUseLCD_DistanceFieldEffectFlag; 878 uint32_t flags = kUseLCD_DistanceFieldEffectFlag;
862 flags |= random->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; 879 flags |= random->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0;
863 flags |= random->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; 880 flags |= random->nextBool() ? kBGR_DistanceFieldEffectFlag : 0;
864 return GrDistanceFieldLCDTextureEffect::Create(GrRandomColor(random), 881 return GrDistanceFieldLCDTextureEffect::Create(GrRandomColor(random),
865 GrProcessorUnitTest::TestMatr ix(random), 882 GrProcessorUnitTest::TestMatr ix(random),
866 textures[texIdx], params, 883 textures[texIdx], params,
867 textures[texIdx2], params2, 884 textures[texIdx2], params2,
868 textColor, 885 textColor,
869 flags); 886 flags);
870 } 887 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrBitmapTextGeoProc.cpp ('k') | src/gpu/gl/GrGLVertexArray.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698