| 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 "gl/builders/GrGLFullProgramBuilder.h" | 9 #include "gl/builders/GrGLProgramBuilder.h" |
| 10 #include "gl/GrGLProcessor.h" | 10 #include "gl/GrGLProcessor.h" |
| 11 #include "gl/GrGLSL.h" | 11 #include "gl/GrGLSL.h" |
| 12 #include "gl/GrGLTexture.h" | 12 #include "gl/GrGLTexture.h" |
| 13 #include "gl/GrGLGeometryProcessor.h" | 13 #include "gl/GrGLGeometryProcessor.h" |
| 14 #include "GrTBackendProcessorFactory.h" | 14 #include "GrTBackendProcessorFactory.h" |
| 15 #include "GrTexture.h" | 15 #include "GrTexture.h" |
| 16 | 16 |
| 17 #include "SkDistanceFieldGen.h" | 17 #include "SkDistanceFieldGen.h" |
| 18 | 18 |
| 19 // To get optical sizes people don't complain about when we blit correctly, | 19 // To get optical sizes people don't complain about when we blit correctly, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 33 public: | 33 public: |
| 34 GrGLDistanceFieldTextureEffect(const GrBackendProcessorFactory& factory, | 34 GrGLDistanceFieldTextureEffect(const GrBackendProcessorFactory& factory, |
| 35 const GrProcessor&) | 35 const GrProcessor&) |
| 36 : INHERITED (factory) | 36 : INHERITED (factory) |
| 37 , fTextureSize(SkISize::Make(-1,-1)) | 37 , fTextureSize(SkISize::Make(-1,-1)) |
| 38 #ifdef SK_GAMMA_APPLY_TO_A8 | 38 #ifdef SK_GAMMA_APPLY_TO_A8 |
| 39 , fLuminance(-1.0f) | 39 , fLuminance(-1.0f) |
| 40 #endif | 40 #endif |
| 41 {} | 41 {} |
| 42 | 42 |
| 43 virtual void emitCode(GrGLFullProgramBuilder* builder, | 43 virtual void emitCode(GrGLGPBuilder* builder, |
| 44 const GrGeometryProcessor& geometryProcessor, | 44 const GrGeometryProcessor& geometryProcessor, |
| 45 const GrProcessorKey& key, | 45 const GrProcessorKey& key, |
| 46 const char* outputColor, | 46 const char* outputColor, |
| 47 const char* inputColor, | 47 const char* inputColor, |
| 48 const TransformedCoordsArray&, | 48 const TransformedCoordsArray&, |
| 49 const TextureSamplerArray& samplers) SK_OVERRIDE { | 49 const TextureSamplerArray& samplers) SK_OVERRIDE { |
| 50 const GrDistanceFieldTextureEffect& dfTexEffect = | 50 const GrDistanceFieldTextureEffect& dfTexEffect = |
| 51 geometryProcessor.cast<GrDistanceFieldTextureEffect>(); | 51 geometryProcessor.cast<GrDistanceFieldTextureEffect>(); |
| 52 SkASSERT(1 == dfTexEffect.getVertexAttribs().count()); | 52 SkASSERT(1 == dfTexEffect.getVertexAttribs().count()); |
| 53 | 53 |
| 54 GrGLProcessorFragmentShaderBuilder* fsBuilder = builder->getFragmentShad
erBuilder(); | 54 GrGLGPFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuild
er(); |
| 55 SkAssertResult(fsBuilder->enableFeature( | 55 SkAssertResult(fsBuilder->enableFeature( |
| 56 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); | 56 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); |
| 57 | 57 |
| 58 SkString fsCoordName; | 58 SkString fsCoordName; |
| 59 const char* vsCoordName; | 59 const char* vsCoordName; |
| 60 const char* fsCoordNamePtr; | 60 const char* fsCoordNamePtr; |
| 61 builder->addVarying(kVec2f_GrSLType, "textureCoords", &vsCoordName, &fsC
oordNamePtr); | 61 builder->addVarying(kVec2f_GrSLType, "textureCoords", &vsCoordName, &fsC
oordNamePtr); |
| 62 fsCoordName = fsCoordNamePtr; | 62 fsCoordName = fsCoordNamePtr; |
| 63 | 63 |
| 64 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder(); | 64 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder(); |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 /////////////////////////////////////////////////////////////////////////////// | 262 /////////////////////////////////////////////////////////////////////////////// |
| 263 | 263 |
| 264 class GrGLDistanceFieldLCDTextureEffect : public GrGLGeometryProcessor { | 264 class GrGLDistanceFieldLCDTextureEffect : public GrGLGeometryProcessor { |
| 265 public: | 265 public: |
| 266 GrGLDistanceFieldLCDTextureEffect(const GrBackendProcessorFactory& factory, | 266 GrGLDistanceFieldLCDTextureEffect(const GrBackendProcessorFactory& factory, |
| 267 const GrProcessor&) | 267 const GrProcessor&) |
| 268 : INHERITED (factory) | 268 : INHERITED (factory) |
| 269 , fTextureSize(SkISize::Make(-1,-1)) | 269 , fTextureSize(SkISize::Make(-1,-1)) |
| 270 , fTextColor(GrColor_ILLEGAL) {} | 270 , fTextColor(GrColor_ILLEGAL) {} |
| 271 | 271 |
| 272 virtual void emitCode(GrGLFullProgramBuilder* builder, | 272 virtual void emitCode(GrGLGPBuilder* builder, |
| 273 const GrGeometryProcessor& geometryProcessor, | 273 const GrGeometryProcessor& geometryProcessor, |
| 274 const GrProcessorKey& key, | 274 const GrProcessorKey& key, |
| 275 const char* outputColor, | 275 const char* outputColor, |
| 276 const char* inputColor, | 276 const char* inputColor, |
| 277 const TransformedCoordsArray&, | 277 const TransformedCoordsArray&, |
| 278 const TextureSamplerArray& samplers) SK_OVERRIDE { | 278 const TextureSamplerArray& samplers) SK_OVERRIDE { |
| 279 const GrDistanceFieldLCDTextureEffect& dfTexEffect = | 279 const GrDistanceFieldLCDTextureEffect& dfTexEffect = |
| 280 geometryProcessor.cast<GrDistanceFieldLCDTextureEffect>(); | 280 geometryProcessor.cast<GrDistanceFieldLCDTextureEffect>(); |
| 281 SkASSERT(1 == dfTexEffect.getVertexAttribs().count()); | 281 SkASSERT(1 == dfTexEffect.getVertexAttribs().count()); |
| 282 | 282 |
| 283 SkString fsCoordName; | 283 SkString fsCoordName; |
| 284 const char* vsCoordName; | 284 const char* vsCoordName; |
| 285 const char* fsCoordNamePtr; | 285 const char* fsCoordNamePtr; |
| 286 builder->addVarying(kVec2f_GrSLType, "textureCoords", &vsCoordName, &fsC
oordNamePtr); | 286 builder->addVarying(kVec2f_GrSLType, "textureCoords", &vsCoordName, &fsC
oordNamePtr); |
| 287 fsCoordName = fsCoordNamePtr; | 287 fsCoordName = fsCoordNamePtr; |
| 288 | 288 |
| 289 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder(); | 289 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder(); |
| 290 vsBuilder->codeAppendf("\t%s = %s;\n", vsCoordName, dfTexEffect.inTextur
eCoords().c_str()); | 290 vsBuilder->codeAppendf("\t%s = %s;\n", vsCoordName, dfTexEffect.inTextur
eCoords().c_str()); |
| 291 | 291 |
| 292 const char* textureSizeUniName = NULL; | 292 const char* textureSizeUniName = NULL; |
| 293 // width, height, 1/(3*width) | 293 // width, height, 1/(3*width) |
| 294 fTextureSizeUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visi
bility, | 294 fTextureSizeUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visi
bility, |
| 295 kVec3f_GrSLType, "TextureSize", | 295 kVec3f_GrSLType, "TextureSize", |
| 296 &textureSizeUniName); | 296 &textureSizeUniName); |
| 297 | 297 |
| 298 GrGLProcessorFragmentShaderBuilder* fsBuilder = builder->getFragmentShad
erBuilder(); | 298 GrGLGPFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuild
er(); |
| 299 | 299 |
| 300 SkAssertResult(fsBuilder->enableFeature( | 300 SkAssertResult(fsBuilder->enableFeature( |
| 301 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); | 301 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); |
| 302 | 302 |
| 303 // create LCD offset adjusted by inverse of transform | 303 // create LCD offset adjusted by inverse of transform |
| 304 fsBuilder->codeAppendf("\tvec2 uv = %s;\n", fsCoordName.c_str()); | 304 fsBuilder->codeAppendf("\tvec2 uv = %s;\n", fsCoordName.c_str()); |
| 305 fsBuilder->codeAppendf("\tvec2 st = uv*%s.xy;\n", textureSizeUniName); | 305 fsBuilder->codeAppendf("\tvec2 st = uv*%s.xy;\n", textureSizeUniName); |
| 306 bool isUniformScale = !!(dfTexEffect.getFlags() & kUniformScale_Distance
FieldEffectMask); | 306 bool isUniformScale = !!(dfTexEffect.getFlags() & kUniformScale_Distance
FieldEffectMask); |
| 307 if (isUniformScale) { | 307 if (isUniformScale) { |
| 308 fsBuilder->codeAppend("\tfloat dx = dFdx(st.x);\n"); | 308 fsBuilder->codeAppend("\tfloat dx = dFdx(st.x);\n"); |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 random->nextULessThan(256), | 520 random->nextULessThan(256), |
| 521 random->nextULessThan(256)); | 521 random->nextULessThan(256)); |
| 522 uint32_t flags = kUseLCD_DistanceFieldEffectFlag; | 522 uint32_t flags = kUseLCD_DistanceFieldEffectFlag; |
| 523 flags |= random->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; | 523 flags |= random->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; |
| 524 flags |= random->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; | 524 flags |= random->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; |
| 525 return GrDistanceFieldLCDTextureEffect::Create(textures[texIdx], params, | 525 return GrDistanceFieldLCDTextureEffect::Create(textures[texIdx], params, |
| 526 textures[texIdx2], params2, | 526 textures[texIdx2], params2, |
| 527 textColor, | 527 textColor, |
| 528 flags); | 528 flags); |
| 529 } | 529 } |
| OLD | NEW |