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