| 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/GrGLFullProgramBuilder.h" |
| 10 #include "gl/GrGLEffect.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 "GrTBackendEffectFactory.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, |
| 20 // we need to slightly bold each glyph. On the Mac, we need a larger bold value. | 20 // we need to slightly bold each glyph. On the Mac, we need a larger bold value. |
| 21 #if defined(SK_BUILD_FOR_MAC) | 21 #if defined(SK_BUILD_FOR_MAC) |
| 22 #define SK_DistanceFieldLCDFactor "0.33" | 22 #define SK_DistanceFieldLCDFactor "0.33" |
| 23 #define SK_DistanceFieldNonLCDFactor "0.25" | 23 #define SK_DistanceFieldNonLCDFactor "0.25" |
| 24 #else | 24 #else |
| 25 #define SK_DistanceFieldLCDFactor "0.05" | 25 #define SK_DistanceFieldLCDFactor "0.05" |
| 26 #define SK_DistanceFieldNonLCDFactor "0.05" | 26 #define SK_DistanceFieldNonLCDFactor "0.05" |
| 27 #endif | 27 #endif |
| 28 | 28 |
| 29 // Assuming a radius of the diagonal of the fragment, hence a factor of sqrt(2)/
2 | 29 // Assuming a radius of the diagonal of the fragment, hence a factor of sqrt(2)/
2 |
| 30 #define SK_DistanceFieldAAFactor "0.7071" | 30 #define SK_DistanceFieldAAFactor "0.7071" |
| 31 | 31 |
| 32 class GrGLDistanceFieldTextureEffect : public GrGLGeometryProcessor { | 32 class GrGLDistanceFieldTextureEffect : public GrGLGeometryProcessor { |
| 33 public: | 33 public: |
| 34 GrGLDistanceFieldTextureEffect(const GrBackendEffectFactory& factory, | 34 GrGLDistanceFieldTextureEffect(const GrBackendProcessorFactory& factory, |
| 35 const GrEffect& effect) | 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(GrGLFullProgramBuilder* builder, |
| 44 const GrEffect& effect, | 44 const GrGeometryProcessor& geometryProcessor, |
| 45 const GrEffectKey& 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 effect.cast<GrDistanceFieldTextureEffect>(); | 51 geometryProcessor.cast<GrDistanceFieldTextureEffect>(); |
| 52 SkASSERT(1 == dfTexEffect.getVertexAttribs().count()); | 52 SkASSERT(1 == dfTexEffect.getVertexAttribs().count()); |
| 53 | 53 |
| 54 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder
(); | 54 GrGLProcessorFragmentShaderBuilder* fsBuilder = builder->getFragmentShad
erBuilder(); |
| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 fsBuilder->appendTextureLookup(samplers[1], "uv", kVec2f_GrSLType); | 124 fsBuilder->appendTextureLookup(samplers[1], "uv", kVec2f_GrSLType); |
| 125 fsBuilder->codeAppend(";\n"); | 125 fsBuilder->codeAppend(";\n"); |
| 126 fsBuilder->codeAppend("\tval = gammaColor.r;\n"); | 126 fsBuilder->codeAppend("\tval = gammaColor.r;\n"); |
| 127 #endif | 127 #endif |
| 128 | 128 |
| 129 fsBuilder->codeAppendf("\t%s = %s;\n", outputColor, | 129 fsBuilder->codeAppendf("\t%s = %s;\n", outputColor, |
| 130 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("val")
).c_str()); | 130 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("val")
).c_str()); |
| 131 } | 131 } |
| 132 | 132 |
| 133 virtual void setData(const GrGLProgramDataManager& pdman, | 133 virtual void setData(const GrGLProgramDataManager& pdman, |
| 134 const GrEffect& effect) SK_OVERRIDE { | 134 const GrProcessor& effect) SK_OVERRIDE { |
| 135 SkASSERT(fTextureSizeUni.isValid()); | 135 SkASSERT(fTextureSizeUni.isValid()); |
| 136 | 136 |
| 137 GrTexture* texture = effect.texture(0); | 137 GrTexture* texture = effect.texture(0); |
| 138 if (texture->width() != fTextureSize.width() || | 138 if (texture->width() != fTextureSize.width() || |
| 139 texture->height() != fTextureSize.height()) { | 139 texture->height() != fTextureSize.height()) { |
| 140 fTextureSize = SkISize::Make(texture->width(), texture->height()); | 140 fTextureSize = SkISize::Make(texture->width(), texture->height()); |
| 141 pdman.set2f(fTextureSizeUni, | 141 pdman.set2f(fTextureSizeUni, |
| 142 SkIntToScalar(fTextureSize.width()), | 142 SkIntToScalar(fTextureSize.width()), |
| 143 SkIntToScalar(fTextureSize.height())); | 143 SkIntToScalar(fTextureSize.height())); |
| 144 } | 144 } |
| 145 #ifdef SK_GAMMA_APPLY_TO_A8 | 145 #ifdef SK_GAMMA_APPLY_TO_A8 |
| 146 const GrDistanceFieldTextureEffect& dfTexEffect = | 146 const GrDistanceFieldTextureEffect& dfTexEffect = |
| 147 effect.cast<GrDistanceFieldTexture
Effect>(); | 147 effect.cast<GrDistanceFieldTextureEffect>(); |
| 148 float luminance = dfTexEffect.getLuminance(); | 148 float luminance = dfTexEffect.getLuminance(); |
| 149 if (luminance != fLuminance) { | 149 if (luminance != fLuminance) { |
| 150 pdman.set1f(fLuminanceUni, luminance); | 150 pdman.set1f(fLuminanceUni, luminance); |
| 151 fLuminance = luminance; | 151 fLuminance = luminance; |
| 152 } | 152 } |
| 153 #endif | 153 #endif |
| 154 } | 154 } |
| 155 | 155 |
| 156 static inline void GenKey(const GrEffect& effect, const GrGLCaps&, | 156 static inline void GenKey(const GrProcessor& processor, const GrGLCaps&, |
| 157 GrEffectKeyBuilder* b) { | 157 GrProcessorKeyBuilder* b) { |
| 158 const GrDistanceFieldTextureEffect& dfTexEffect = | 158 const GrDistanceFieldTextureEffect& dfTexEffect = |
| 159 effect.cast<GrDistanceFieldTextureEffect>(); | 159 processor.cast<GrDistanceFieldTextureEffect>(); |
| 160 | 160 |
| 161 b->add32(dfTexEffect.getFlags()); | 161 b->add32(dfTexEffect.getFlags()); |
| 162 } | 162 } |
| 163 | 163 |
| 164 private: | 164 private: |
| 165 GrGLProgramDataManager::UniformHandle fTextureSizeUni; | 165 GrGLProgramDataManager::UniformHandle fTextureSizeUni; |
| 166 SkISize fTextureSize; | 166 SkISize fTextureSize; |
| 167 GrGLProgramDataManager::UniformHandle fLuminanceUni; | 167 GrGLProgramDataManager::UniformHandle fLuminanceUni; |
| 168 float fLuminance; | 168 float fLuminance; |
| 169 | 169 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 189 , fInTextureCoords(this->addVertexAttrib(GrShaderVar("inTextureCoords", | 189 , fInTextureCoords(this->addVertexAttrib(GrShaderVar("inTextureCoords", |
| 190 kVec2f_GrSLType, | 190 kVec2f_GrSLType, |
| 191 GrShaderVar::kAttribute
_TypeModifier))) { | 191 GrShaderVar::kAttribute
_TypeModifier))) { |
| 192 SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask)); | 192 SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask)); |
| 193 this->addTextureAccess(&fTextureAccess); | 193 this->addTextureAccess(&fTextureAccess); |
| 194 #ifdef SK_GAMMA_APPLY_TO_A8 | 194 #ifdef SK_GAMMA_APPLY_TO_A8 |
| 195 this->addTextureAccess(&fGammaTextureAccess); | 195 this->addTextureAccess(&fGammaTextureAccess); |
| 196 #endif | 196 #endif |
| 197 } | 197 } |
| 198 | 198 |
| 199 bool GrDistanceFieldTextureEffect::onIsEqual(const GrEffect& other) const { | 199 bool GrDistanceFieldTextureEffect::onIsEqual(const GrProcessor& other) const { |
| 200 const GrDistanceFieldTextureEffect& cte = other.cast<GrDistanceFieldTextureE
ffect>(); | 200 const GrDistanceFieldTextureEffect& cte = other.cast<GrDistanceFieldTextureE
ffect>(); |
| 201 return fTextureAccess == cte.fTextureAccess && | 201 return fTextureAccess == cte.fTextureAccess && |
| 202 #ifdef SK_GAMMA_APPLY_TO_A8 | 202 #ifdef SK_GAMMA_APPLY_TO_A8 |
| 203 fGammaTextureAccess == cte.fGammaTextureAccess && | 203 fGammaTextureAccess == cte.fGammaTextureAccess && |
| 204 fLuminance == cte.fLuminance && | 204 fLuminance == cte.fLuminance && |
| 205 #endif | 205 #endif |
| 206 fFlags == cte.fFlags; | 206 fFlags == cte.fFlags; |
| 207 } | 207 } |
| 208 | 208 |
| 209 void GrDistanceFieldTextureEffect::getConstantColorComponents(GrColor* color, | 209 void GrDistanceFieldTextureEffect::getConstantColorComponents(GrColor* color, |
| 210 uint32_t* validFlag
s) const { | 210 uint32_t* validFlag
s) const { |
| 211 if ((*validFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUnpackA(*color
) && | 211 if ((*validFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUnpackA(*color
) && |
| 212 GrPixelConfigIsOpaque(this->texture(0)->config())) { | 212 GrPixelConfigIsOpaque(this->texture(0)->config())) { |
| 213 *validFlags = kA_GrColorComponentFlag; | 213 *validFlags = kA_GrColorComponentFlag; |
| 214 } else { | 214 } else { |
| 215 *validFlags = 0; | 215 *validFlags = 0; |
| 216 } | 216 } |
| 217 } | 217 } |
| 218 | 218 |
| 219 const GrBackendEffectFactory& GrDistanceFieldTextureEffect::getFactory() const { | 219 const GrBackendGeometryProcessorFactory& GrDistanceFieldTextureEffect::getFactor
y() const { |
| 220 return GrTBackendEffectFactory<GrDistanceFieldTextureEffect>::getInstance(); | 220 return GrTBackendGeometryProcessorFactory<GrDistanceFieldTextureEffect>::get
Instance(); |
| 221 } | 221 } |
| 222 | 222 |
| 223 /////////////////////////////////////////////////////////////////////////////// | 223 /////////////////////////////////////////////////////////////////////////////// |
| 224 | 224 |
| 225 GR_DEFINE_EFFECT_TEST(GrDistanceFieldTextureEffect); | 225 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldTextureEffect); |
| 226 | 226 |
| 227 GrEffect* GrDistanceFieldTextureEffect::TestCreate(SkRandom* random, | 227 GrGeometryProcessor* GrDistanceFieldTextureEffect::TestCreate(SkRandom* random, |
| 228 GrContext*, | 228 GrContext*, |
| 229 const GrDrawTargetCaps&, | 229 const GrDrawTarget
Caps&, |
| 230 GrTexture* textures[]) { | 230 GrTexture* texture
s[]) { |
| 231 int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx : | 231 int texIdx = random->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : |
| 232 GrEffectUnitTest::kAlphaTextureIdx; | 232 GrProcessorUnitTest::kAlphaTextureIdx; |
| 233 #ifdef SK_GAMMA_APPLY_TO_A8 | 233 #ifdef SK_GAMMA_APPLY_TO_A8 |
| 234 int texIdx2 = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx : | 234 int texIdx2 = random->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : |
| 235 GrEffectUnitTest::kAlphaTextureIdx; | 235 GrProcessorUnitTest::kAlphaTextureIdx; |
| 236 #endif | 236 #endif |
| 237 static const SkShader::TileMode kTileModes[] = { | 237 static const SkShader::TileMode kTileModes[] = { |
| 238 SkShader::kClamp_TileMode, | 238 SkShader::kClamp_TileMode, |
| 239 SkShader::kRepeat_TileMode, | 239 SkShader::kRepeat_TileMode, |
| 240 SkShader::kMirror_TileMode, | 240 SkShader::kMirror_TileMode, |
| 241 }; | 241 }; |
| 242 SkShader::TileMode tileModes[] = { | 242 SkShader::TileMode tileModes[] = { |
| 243 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 243 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
| 244 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 244 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
| 245 }; | 245 }; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 256 random->nextF(), | 256 random->nextF(), |
| 257 #endif | 257 #endif |
| 258 random->nextBool() ? | 258 random->nextBool() ? |
| 259 kSimilarity_DistanceFieldEff
ectFlag : 0); | 259 kSimilarity_DistanceFieldEff
ectFlag : 0); |
| 260 } | 260 } |
| 261 | 261 |
| 262 /////////////////////////////////////////////////////////////////////////////// | 262 /////////////////////////////////////////////////////////////////////////////// |
| 263 | 263 |
| 264 class GrGLDistanceFieldLCDTextureEffect : public GrGLGeometryProcessor { | 264 class GrGLDistanceFieldLCDTextureEffect : public GrGLGeometryProcessor { |
| 265 public: | 265 public: |
| 266 GrGLDistanceFieldLCDTextureEffect(const GrBackendEffectFactory& factory, | 266 GrGLDistanceFieldLCDTextureEffect(const GrBackendProcessorFactory& factory, |
| 267 const GrEffect& effect) | 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(GrGLFullProgramBuilder* builder, |
| 273 const GrEffect& effect, | 273 const GrGeometryProcessor& geometryProcessor, |
| 274 const GrEffectKey& 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 effect.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 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder
(); | 298 GrGLProcessorFragmentShaderBuilder* fsBuilder = builder->getFragmentShad
erBuilder(); |
| 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 fsBuilder->codeAppend("\tgammaColor = "); | 393 fsBuilder->codeAppend("\tgammaColor = "); |
| 394 fsBuilder->appendTextureLookup(samplers[1], "uv", kVec2f_GrSLType); | 394 fsBuilder->appendTextureLookup(samplers[1], "uv", kVec2f_GrSLType); |
| 395 fsBuilder->codeAppend(";\n"); | 395 fsBuilder->codeAppend(";\n"); |
| 396 fsBuilder->codeAppend("\tval.z = gammaColor.r;\n"); | 396 fsBuilder->codeAppend("\tval.z = gammaColor.r;\n"); |
| 397 | 397 |
| 398 fsBuilder->codeAppendf("\t%s = %s;\n", outputColor, | 398 fsBuilder->codeAppendf("\t%s = %s;\n", outputColor, |
| 399 (GrGLSLExpr4(inputColor) * GrGLSLExpr4("val")).c_
str()); | 399 (GrGLSLExpr4(inputColor) * GrGLSLExpr4("val")).c_
str()); |
| 400 } | 400 } |
| 401 | 401 |
| 402 virtual void setData(const GrGLProgramDataManager& pdman, | 402 virtual void setData(const GrGLProgramDataManager& pdman, |
| 403 const GrEffect& effect) SK_OVERRIDE { | 403 const GrProcessor& processor) SK_OVERRIDE { |
| 404 SkASSERT(fTextureSizeUni.isValid()); | 404 SkASSERT(fTextureSizeUni.isValid()); |
| 405 SkASSERT(fTextColorUni.isValid()); | 405 SkASSERT(fTextColorUni.isValid()); |
| 406 | 406 |
| 407 const GrDistanceFieldLCDTextureEffect& dfTexEffect = | 407 const GrDistanceFieldLCDTextureEffect& dfTexEffect = |
| 408 effect.cast<GrDistanceFieldLCDTextureEffect>(); | 408 processor.cast<GrDistanceFieldLCDTextureEffect>(); |
| 409 GrTexture* texture = effect.texture(0); | 409 GrTexture* texture = processor.texture(0); |
| 410 if (texture->width() != fTextureSize.width() || | 410 if (texture->width() != fTextureSize.width() || |
| 411 texture->height() != fTextureSize.height()) { | 411 texture->height() != fTextureSize.height()) { |
| 412 fTextureSize = SkISize::Make(texture->width(), texture->height()); | 412 fTextureSize = SkISize::Make(texture->width(), texture->height()); |
| 413 float delta = 1.0f/(3.0f*texture->width()); | 413 float delta = 1.0f/(3.0f*texture->width()); |
| 414 if (dfTexEffect.getFlags() & kBGR_DistanceFieldEffectFlag) { | 414 if (dfTexEffect.getFlags() & kBGR_DistanceFieldEffectFlag) { |
| 415 delta = -delta; | 415 delta = -delta; |
| 416 } | 416 } |
| 417 pdman.set3f(fTextureSizeUni, | 417 pdman.set3f(fTextureSizeUni, |
| 418 SkIntToScalar(fTextureSize.width()), | 418 SkIntToScalar(fTextureSize.width()), |
| 419 SkIntToScalar(fTextureSize.height()), | 419 SkIntToScalar(fTextureSize.height()), |
| 420 delta); | 420 delta); |
| 421 } | 421 } |
| 422 | 422 |
| 423 GrColor textColor = dfTexEffect.getTextColor(); | 423 GrColor textColor = dfTexEffect.getTextColor(); |
| 424 if (textColor != fTextColor) { | 424 if (textColor != fTextColor) { |
| 425 static const float ONE_OVER_255 = 1.f / 255.f; | 425 static const float ONE_OVER_255 = 1.f / 255.f; |
| 426 pdman.set3f(fTextColorUni, | 426 pdman.set3f(fTextColorUni, |
| 427 GrColorUnpackR(textColor) * ONE_OVER_255, | 427 GrColorUnpackR(textColor) * ONE_OVER_255, |
| 428 GrColorUnpackG(textColor) * ONE_OVER_255, | 428 GrColorUnpackG(textColor) * ONE_OVER_255, |
| 429 GrColorUnpackB(textColor) * ONE_OVER_255); | 429 GrColorUnpackB(textColor) * ONE_OVER_255); |
| 430 fTextColor = textColor; | 430 fTextColor = textColor; |
| 431 } | 431 } |
| 432 } | 432 } |
| 433 | 433 |
| 434 static inline void GenKey(const GrEffect& effect, const GrGLCaps&, | 434 static inline void GenKey(const GrProcessor& processor, const GrGLCaps&, |
| 435 GrEffectKeyBuilder* b) { | 435 GrProcessorKeyBuilder* b) { |
| 436 const GrDistanceFieldLCDTextureEffect& dfTexEffect = | 436 const GrDistanceFieldLCDTextureEffect& dfTexEffect = |
| 437 effect.cast<GrDistanceFieldLCDTextureEffect>(); | 437 processor.cast<GrDistanceFieldLCDTextureEffect>(); |
| 438 | 438 |
| 439 b->add32(dfTexEffect.getFlags()); | 439 b->add32(dfTexEffect.getFlags()); |
| 440 } | 440 } |
| 441 | 441 |
| 442 private: | 442 private: |
| 443 GrGLProgramDataManager::UniformHandle fTextureSizeUni; | 443 GrGLProgramDataManager::UniformHandle fTextureSizeUni; |
| 444 SkISize fTextureSize; | 444 SkISize fTextureSize; |
| 445 GrGLProgramDataManager::UniformHandle fTextColorUni; | 445 GrGLProgramDataManager::UniformHandle fTextColorUni; |
| 446 SkColor fTextColor; | 446 SkColor fTextColor; |
| 447 | 447 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 461 , fFlags(flags & kLCD_DistanceFieldEffectMask) | 461 , fFlags(flags & kLCD_DistanceFieldEffectMask) |
| 462 , fInTextureCoords(this->addVertexAttrib(GrShaderVar("inTextureCoords", | 462 , fInTextureCoords(this->addVertexAttrib(GrShaderVar("inTextureCoords", |
| 463 kVec2f_GrSLType, | 463 kVec2f_GrSLType, |
| 464 GrShaderVar::kAttribute
_TypeModifier))) { | 464 GrShaderVar::kAttribute
_TypeModifier))) { |
| 465 SkASSERT(!(flags & ~kLCD_DistanceFieldEffectMask) && (flags & kUseLCD_Distan
ceFieldEffectFlag)); | 465 SkASSERT(!(flags & ~kLCD_DistanceFieldEffectMask) && (flags & kUseLCD_Distan
ceFieldEffectFlag)); |
| 466 | 466 |
| 467 this->addTextureAccess(&fTextureAccess); | 467 this->addTextureAccess(&fTextureAccess); |
| 468 this->addTextureAccess(&fGammaTextureAccess); | 468 this->addTextureAccess(&fGammaTextureAccess); |
| 469 } | 469 } |
| 470 | 470 |
| 471 bool GrDistanceFieldLCDTextureEffect::onIsEqual(const GrEffect& other) const { | 471 bool GrDistanceFieldLCDTextureEffect::onIsEqual(const GrProcessor& other) const
{ |
| 472 const GrDistanceFieldLCDTextureEffect& cte = other.cast<GrDistanceFieldLCDTe
xtureEffect>(); | 472 const GrDistanceFieldLCDTextureEffect& cte = other.cast<GrDistanceFieldLCDTe
xtureEffect>(); |
| 473 return (fTextureAccess == cte.fTextureAccess && | 473 return (fTextureAccess == cte.fTextureAccess && |
| 474 fGammaTextureAccess == cte.fGammaTextureAccess && | 474 fGammaTextureAccess == cte.fGammaTextureAccess && |
| 475 fTextColor == cte.fTextColor && | 475 fTextColor == cte.fTextColor && |
| 476 fFlags == cte.fFlags); | 476 fFlags == cte.fFlags); |
| 477 } | 477 } |
| 478 | 478 |
| 479 void GrDistanceFieldLCDTextureEffect::getConstantColorComponents(GrColor* color, | 479 void GrDistanceFieldLCDTextureEffect::getConstantColorComponents(GrColor* color, |
| 480 uint32_t* valid
Flags) const { | 480 uint32_t* valid
Flags) const { |
| 481 if ((*validFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUnpackA(*color
) && | 481 if ((*validFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUnpackA(*color
) && |
| 482 GrPixelConfigIsOpaque(this->texture(0)->config())) { | 482 GrPixelConfigIsOpaque(this->texture(0)->config())) { |
| 483 *validFlags = kA_GrColorComponentFlag; | 483 *validFlags = kA_GrColorComponentFlag; |
| 484 } else { | 484 } else { |
| 485 *validFlags = 0; | 485 *validFlags = 0; |
| 486 } | 486 } |
| 487 } | 487 } |
| 488 | 488 |
| 489 const GrBackendEffectFactory& GrDistanceFieldLCDTextureEffect::getFactory() cons
t { | 489 const GrBackendGeometryProcessorFactory& GrDistanceFieldLCDTextureEffect::getFac
tory() const { |
| 490 return GrTBackendEffectFactory<GrDistanceFieldLCDTextureEffect>::getInstance
(); | 490 return GrTBackendGeometryProcessorFactory<GrDistanceFieldLCDTextureEffect>::
getInstance(); |
| 491 } | 491 } |
| 492 | 492 |
| 493 /////////////////////////////////////////////////////////////////////////////// | 493 /////////////////////////////////////////////////////////////////////////////// |
| 494 | 494 |
| 495 GR_DEFINE_EFFECT_TEST(GrDistanceFieldLCDTextureEffect); | 495 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldLCDTextureEffect); |
| 496 | 496 |
| 497 GrEffect* GrDistanceFieldLCDTextureEffect::TestCreate(SkRandom* random, | 497 GrGeometryProcessor* GrDistanceFieldLCDTextureEffect::TestCreate(SkRandom* rando
m, |
| 498 GrContext*, | 498 GrContext*, |
| 499 const GrDrawTargetCaps&, | 499 const GrDrawTar
getCaps&, |
| 500 GrTexture* textures[]) { | 500 GrTexture* text
ures[]) { |
| 501 int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx : | 501 int texIdx = random->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : |
| 502 GrEffectUnitTest::kAlphaTextureIdx; | 502 GrProcessorUnitTest::kAlphaTextureIdx; |
| 503 int texIdx2 = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx : | 503 int texIdx2 = random->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : |
| 504 GrEffectUnitTest::kAlphaTextureIdx; | 504 GrProcessorUnitTest::kAlphaTextureIdx; |
| 505 static const SkShader::TileMode kTileModes[] = { | 505 static const SkShader::TileMode kTileModes[] = { |
| 506 SkShader::kClamp_TileMode, | 506 SkShader::kClamp_TileMode, |
| 507 SkShader::kRepeat_TileMode, | 507 SkShader::kRepeat_TileMode, |
| 508 SkShader::kMirror_TileMode, | 508 SkShader::kMirror_TileMode, |
| 509 }; | 509 }; |
| 510 SkShader::TileMode tileModes[] = { | 510 SkShader::TileMode tileModes[] = { |
| 511 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 511 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
| 512 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 512 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
| 513 }; | 513 }; |
| 514 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil
erp_FilterMode : | 514 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil
erp_FilterMode : |
| 515 GrTextureParams::kNone_FilterMode); | 515 GrTextureParams::kNone_FilterMode); |
| 516 GrTextureParams params2(tileModes, random->nextBool() ? GrTextureParams::kBi
lerp_FilterMode : | 516 GrTextureParams params2(tileModes, random->nextBool() ? GrTextureParams::kBi
lerp_FilterMode : |
| 517 GrTextureParams::kNone_FilterMode); | 517 GrTextureParams::kNone_FilterMode); |
| 518 GrColor textColor = GrColorPackRGBA(random->nextULessThan(256), | 518 GrColor textColor = GrColorPackRGBA(random->nextULessThan(256), |
| 519 random->nextULessThan(256), | 519 random->nextULessThan(256), |
| 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 |