| 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/GrGLEffect.h" | 9 #include "gl/GrGLEffect.h" |
| 10 #include "gl/GrGLShaderBuilder.h" | 10 #include "gl/GrGLShaderBuilder.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 class GrGLDistanceFieldTextureEffect : public GrGLVertexEffect { | 32 class GrGLDistanceFieldTextureEffect : public GrGLVertexEffect { |
| 33 public: | 33 public: |
| 34 GrGLDistanceFieldTextureEffect(const GrBackendEffectFactory& factory, | 34 GrGLDistanceFieldTextureEffect(const GrBackendEffectFactory& factory, |
| 35 const GrDrawEffect& drawEffect) | 35 const GrDrawEffect& drawEffect) |
| 36 : INHERITED (factory) | 36 : INHERITED (factory) |
| 37 , fTextureSize(SkISize::Make(-1,-1)) {} | 37 , fTextureSize(SkISize::Make(-1,-1)) {} |
| 38 | 38 |
| 39 virtual void emitCode(GrGLFullShaderBuilder* builder, | 39 virtual void emitCode(GrGLFullShaderBuilder* builder, |
| 40 const GrDrawEffect& drawEffect, | 40 const GrDrawEffect& drawEffect, |
| 41 EffectKey key, | 41 const GrEffectKey& key, |
| 42 const char* outputColor, | 42 const char* outputColor, |
| 43 const char* inputColor, | 43 const char* inputColor, |
| 44 const TransformedCoordsArray&, | 44 const TransformedCoordsArray&, |
| 45 const TextureSamplerArray& samplers) SK_OVERRIDE { | 45 const TextureSamplerArray& samplers) SK_OVERRIDE { |
| 46 SkASSERT(1 == drawEffect.castEffect<GrDistanceFieldTextureEffect>().numV
ertexAttribs()); | 46 SkASSERT(1 == drawEffect.castEffect<GrDistanceFieldTextureEffect>().numV
ertexAttribs()); |
| 47 | 47 |
| 48 SkAssertResult(builder->enableFeature(GrGLShaderBuilder::kStandardDeriva
tives_GLSLFeature)); | 48 SkAssertResult(builder->enableFeature(GrGLShaderBuilder::kStandardDeriva
tives_GLSLFeature)); |
| 49 const GrDistanceFieldTextureEffect& dfTexEffect = | 49 const GrDistanceFieldTextureEffect& dfTexEffect = |
| 50 drawEffect.castEffect<GrDistanceFi
eldTextureEffect>(); | 50 drawEffect.castEffect<GrDistanceFi
eldTextureEffect>(); |
| 51 | 51 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 const GrDistanceFieldTextureEffect& dfTexEffect = | 141 const GrDistanceFieldTextureEffect& dfTexEffect = |
| 142 drawEffect.castEffect<GrDistanceFi
eldTextureEffect>(); | 142 drawEffect.castEffect<GrDistanceFi
eldTextureEffect>(); |
| 143 float luminance = dfTexEffect.getLuminance(); | 143 float luminance = dfTexEffect.getLuminance(); |
| 144 if (luminance != fLuminance) { | 144 if (luminance != fLuminance) { |
| 145 uman.set1f(fLuminanceUni, luminance); | 145 uman.set1f(fLuminanceUni, luminance); |
| 146 fLuminance = luminance; | 146 fLuminance = luminance; |
| 147 } | 147 } |
| 148 #endif | 148 #endif |
| 149 } | 149 } |
| 150 | 150 |
| 151 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrGLCap
s&) { | 151 static inline void GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&, |
| 152 GrEffectKeyBuilder* b) { |
| 152 const GrDistanceFieldTextureEffect& dfTexEffect = | 153 const GrDistanceFieldTextureEffect& dfTexEffect = |
| 153 drawEffect.castEffect<GrDistanceFi
eldTextureEffect>(); | 154 drawEffect.castEffect<GrDistanceFi
eldTextureEffect>(); |
| 154 | 155 |
| 155 return dfTexEffect.isSimilarity() ? 0x1 : 0x0; | 156 b->add32(dfTexEffect.isSimilarity()); |
| 156 } | 157 } |
| 157 | 158 |
| 158 private: | 159 private: |
| 159 GrGLUniformManager::UniformHandle fTextureSizeUni; | 160 GrGLUniformManager::UniformHandle fTextureSizeUni; |
| 160 SkISize fTextureSize; | 161 SkISize fTextureSize; |
| 161 GrGLUniformManager::UniformHandle fLuminanceUni; | 162 GrGLUniformManager::UniformHandle fLuminanceUni; |
| 162 float fLuminance; | 163 float fLuminance; |
| 163 | 164 |
| 164 typedef GrGLVertexEffect INHERITED; | 165 typedef GrGLVertexEffect INHERITED; |
| 165 }; | 166 }; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 | 249 |
| 249 class GrGLDistanceFieldLCDTextureEffect : public GrGLVertexEffect { | 250 class GrGLDistanceFieldLCDTextureEffect : public GrGLVertexEffect { |
| 250 public: | 251 public: |
| 251 GrGLDistanceFieldLCDTextureEffect(const GrBackendEffectFactory& factory, | 252 GrGLDistanceFieldLCDTextureEffect(const GrBackendEffectFactory& factory, |
| 252 const GrDrawEffect& drawEffect) | 253 const GrDrawEffect& drawEffect) |
| 253 : INHERITED (factory) | 254 : INHERITED (factory) |
| 254 , fTextureSize(SkISize::Make(-1,-1)) {} | 255 , fTextureSize(SkISize::Make(-1,-1)) {} |
| 255 | 256 |
| 256 virtual void emitCode(GrGLFullShaderBuilder* builder, | 257 virtual void emitCode(GrGLFullShaderBuilder* builder, |
| 257 const GrDrawEffect& drawEffect, | 258 const GrDrawEffect& drawEffect, |
| 258 EffectKey key, | 259 const GrEffectKey& key, |
| 259 const char* outputColor, | 260 const char* outputColor, |
| 260 const char* inputColor, | 261 const char* inputColor, |
| 261 const TransformedCoordsArray&, | 262 const TransformedCoordsArray&, |
| 262 const TextureSamplerArray& samplers) SK_OVERRIDE { | 263 const TextureSamplerArray& samplers) SK_OVERRIDE { |
| 263 SkASSERT(1 == drawEffect.castEffect<GrDistanceFieldLCDTextureEffect>().n
umVertexAttribs()); | 264 SkASSERT(1 == drawEffect.castEffect<GrDistanceFieldLCDTextureEffect>().n
umVertexAttribs()); |
| 264 | 265 |
| 265 SkAssertResult(builder->enableFeature(GrGLShaderBuilder::kStandardDeriva
tives_GLSLFeature)); | 266 SkAssertResult(builder->enableFeature(GrGLShaderBuilder::kStandardDeriva
tives_GLSLFeature)); |
| 266 const GrDistanceFieldLCDTextureEffect& dfTexEffect = | 267 const GrDistanceFieldLCDTextureEffect& dfTexEffect = |
| 267 drawEffect.castEffect<GrDistanceField
LCDTextureEffect>(); | 268 drawEffect.castEffect<GrDistanceField
LCDTextureEffect>(); |
| 268 | 269 |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 if (textColor != fTextColor) { | 406 if (textColor != fTextColor) { |
| 406 static const float ONE_OVER_255 = 1.f / 255.f; | 407 static const float ONE_OVER_255 = 1.f / 255.f; |
| 407 uman.set3f(fTextColorUni, | 408 uman.set3f(fTextColorUni, |
| 408 GrColorUnpackR(textColor) * ONE_OVER_255, | 409 GrColorUnpackR(textColor) * ONE_OVER_255, |
| 409 GrColorUnpackG(textColor) * ONE_OVER_255, | 410 GrColorUnpackG(textColor) * ONE_OVER_255, |
| 410 GrColorUnpackB(textColor) * ONE_OVER_255); | 411 GrColorUnpackB(textColor) * ONE_OVER_255); |
| 411 fTextColor = textColor; | 412 fTextColor = textColor; |
| 412 } | 413 } |
| 413 } | 414 } |
| 414 | 415 |
| 415 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrGLCap
s&) { | 416 static inline void GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&, |
| 417 GrEffectKeyBuilder* b) { |
| 416 const GrDistanceFieldLCDTextureEffect& dfTexEffect = | 418 const GrDistanceFieldLCDTextureEffect& dfTexEffect = |
| 417 drawEffect.castEffect<GrDistanceField
LCDTextureEffect>(); | 419 drawEffect.castEffect<GrDistanceField
LCDTextureEffect>(); |
| 418 | 420 |
| 419 return dfTexEffect.isUniformScale() ? 0x01 : 0x00;; | 421 b->add32(dfTexEffect.isUniformScale()); |
| 420 } | 422 } |
| 421 | 423 |
| 422 private: | 424 private: |
| 423 GrGLUniformManager::UniformHandle fTextureSizeUni; | 425 GrGLUniformManager::UniformHandle fTextureSizeUni; |
| 424 SkISize fTextureSize; | 426 SkISize fTextureSize; |
| 425 GrGLUniformManager::UniformHandle fTextColorUni; | 427 GrGLUniformManager::UniformHandle fTextColorUni; |
| 426 SkColor fTextColor; | 428 SkColor fTextColor; |
| 427 | 429 |
| 428 typedef GrGLVertexEffect INHERITED; | 430 typedef GrGLVertexEffect INHERITED; |
| 429 }; | 431 }; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 GrTextureParams::kNone_FilterMode); | 494 GrTextureParams::kNone_FilterMode); |
| 493 GrColor textColor = GrColorPackRGBA(random->nextULessThan(256), | 495 GrColor textColor = GrColorPackRGBA(random->nextULessThan(256), |
| 494 random->nextULessThan(256), | 496 random->nextULessThan(256), |
| 495 random->nextULessThan(256), | 497 random->nextULessThan(256), |
| 496 random->nextULessThan(256)); | 498 random->nextULessThan(256)); |
| 497 return GrDistanceFieldLCDTextureEffect::Create(textures[texIdx], params, | 499 return GrDistanceFieldLCDTextureEffect::Create(textures[texIdx], params, |
| 498 textures[texIdx2], params2, | 500 textures[texIdx2], params2, |
| 499 textColor, | 501 textColor, |
| 500 random->nextBool(), random->n
extBool()); | 502 random->nextBool(), random->n
extBool()); |
| 501 } | 503 } |
| OLD | NEW |