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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 builder->fsCodeAppend("\tvec4 gammaColor = "); | 118 builder->fsCodeAppend("\tvec4 gammaColor = "); |
119 builder->fsAppendTextureLookup(samplers[1], "uv", kVec2f_GrSLType); | 119 builder->fsAppendTextureLookup(samplers[1], "uv", kVec2f_GrSLType); |
120 builder->fsCodeAppend(";\n"); | 120 builder->fsCodeAppend(";\n"); |
121 builder->fsCodeAppend("\tval = gammaColor.r;\n"); | 121 builder->fsCodeAppend("\tval = gammaColor.r;\n"); |
122 #endif | 122 #endif |
123 | 123 |
124 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, | 124 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, |
125 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("val")
).c_str()); | 125 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("val")
).c_str()); |
126 } | 126 } |
127 | 127 |
128 virtual void setData(const GrGLUniformManager& uman, | 128 virtual void setData(const GrGLProgramDataManager& pdman, |
129 const GrDrawEffect& drawEffect) SK_OVERRIDE { | 129 const GrDrawEffect& drawEffect) SK_OVERRIDE { |
130 SkASSERT(fTextureSizeUni.isValid()); | 130 SkASSERT(fTextureSizeUni.isValid()); |
131 | 131 |
132 GrTexture* texture = drawEffect.effect()->texture(0); | 132 GrTexture* texture = drawEffect.effect()->texture(0); |
133 if (texture->width() != fTextureSize.width() || | 133 if (texture->width() != fTextureSize.width() || |
134 texture->height() != fTextureSize.height()) { | 134 texture->height() != fTextureSize.height()) { |
135 fTextureSize = SkISize::Make(texture->width(), texture->height()); | 135 fTextureSize = SkISize::Make(texture->width(), texture->height()); |
136 uman.set2f(fTextureSizeUni, | 136 pdman.set2f(fTextureSizeUni, |
137 SkIntToScalar(fTextureSize.width()), | 137 SkIntToScalar(fTextureSize.width()), |
138 SkIntToScalar(fTextureSize.height())); | 138 SkIntToScalar(fTextureSize.height())); |
139 } | 139 } |
140 #ifdef SK_GAMMA_APPLY_TO_A8 | 140 #ifdef SK_GAMMA_APPLY_TO_A8 |
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 pdman.set1f(fLuminanceUni, luminance); |
146 fLuminance = luminance; | 146 fLuminance = luminance; |
147 } | 147 } |
148 #endif | 148 #endif |
149 } | 149 } |
150 | 150 |
151 static inline void GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&, | 151 static inline void GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&, |
152 GrEffectKeyBuilder* b) { | 152 GrEffectKeyBuilder* b) { |
153 const GrDistanceFieldTextureEffect& dfTexEffect = | 153 const GrDistanceFieldTextureEffect& dfTexEffect = |
154 drawEffect.castEffect<GrDistanceFi
eldTextureEffect>(); | 154 drawEffect.castEffect<GrDistanceFi
eldTextureEffect>(); |
155 | 155 |
156 b->add32(dfTexEffect.isSimilarity()); | 156 b->add32(dfTexEffect.isSimilarity()); |
157 } | 157 } |
158 | 158 |
159 private: | 159 private: |
160 GrGLUniformManager::UniformHandle fTextureSizeUni; | 160 GrGLProgramDataManager::UniformHandle fTextureSizeUni; |
161 SkISize fTextureSize; | 161 SkISize fTextureSize; |
162 GrGLUniformManager::UniformHandle fLuminanceUni; | 162 GrGLProgramDataManager::UniformHandle fLuminanceUni; |
163 float fLuminance; | 163 float fLuminance; |
164 | 164 |
165 typedef GrGLVertexEffect INHERITED; | 165 typedef GrGLVertexEffect INHERITED; |
166 }; | 166 }; |
167 | 167 |
168 /////////////////////////////////////////////////////////////////////////////// | 168 /////////////////////////////////////////////////////////////////////////////// |
169 | 169 |
170 GrDistanceFieldTextureEffect::GrDistanceFieldTextureEffect(GrTexture* texture, | 170 GrDistanceFieldTextureEffect::GrDistanceFieldTextureEffect(GrTexture* texture, |
171 const GrTextureParams
& params, | 171 const GrTextureParams
& params, |
172 #ifdef SK_GAMMA_APPLY_TO_A8 | 172 #ifdef SK_GAMMA_APPLY_TO_A8 |
173 GrTexture* gamma, | 173 GrTexture* gamma, |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 builder->fsCodeAppendf("\tuv = vec2(val.z, %s.z);\n", textColorUniName); | 374 builder->fsCodeAppendf("\tuv = vec2(val.z, %s.z);\n", textColorUniName); |
375 builder->fsCodeAppend("\tgammaColor = "); | 375 builder->fsCodeAppend("\tgammaColor = "); |
376 builder->fsAppendTextureLookup(samplers[1], "uv", kVec2f_GrSLType); | 376 builder->fsAppendTextureLookup(samplers[1], "uv", kVec2f_GrSLType); |
377 builder->fsCodeAppend(";\n"); | 377 builder->fsCodeAppend(";\n"); |
378 builder->fsCodeAppend("\tval.z = gammaColor.r;\n"); | 378 builder->fsCodeAppend("\tval.z = gammaColor.r;\n"); |
379 | 379 |
380 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, | 380 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, |
381 (GrGLSLExpr4(inputColor) * GrGLSLExpr4("val")).c_
str()); | 381 (GrGLSLExpr4(inputColor) * GrGLSLExpr4("val")).c_
str()); |
382 } | 382 } |
383 | 383 |
384 virtual void setData(const GrGLUniformManager& uman, | 384 virtual void setData(const GrGLProgramDataManager& pdman, |
385 const GrDrawEffect& drawEffect) SK_OVERRIDE { | 385 const GrDrawEffect& drawEffect) SK_OVERRIDE { |
386 SkASSERT(fTextureSizeUni.isValid()); | 386 SkASSERT(fTextureSizeUni.isValid()); |
387 SkASSERT(fTextColorUni.isValid()); | 387 SkASSERT(fTextColorUni.isValid()); |
388 | 388 |
389 const GrDistanceFieldLCDTextureEffect& dfTexEffect = | 389 const GrDistanceFieldLCDTextureEffect& dfTexEffect = |
390 drawEffect.castEffect<GrDistanceFieldLCDText
ureEffect>(); | 390 drawEffect.castEffect<GrDistanceFieldLCDText
ureEffect>(); |
391 GrTexture* texture = drawEffect.effect()->texture(0); | 391 GrTexture* texture = drawEffect.effect()->texture(0); |
392 if (texture->width() != fTextureSize.width() || | 392 if (texture->width() != fTextureSize.width() || |
393 texture->height() != fTextureSize.height()) { | 393 texture->height() != fTextureSize.height()) { |
394 fTextureSize = SkISize::Make(texture->width(), texture->height()); | 394 fTextureSize = SkISize::Make(texture->width(), texture->height()); |
395 float delta = 1.0f/(3.0f*texture->width()); | 395 float delta = 1.0f/(3.0f*texture->width()); |
396 if (dfTexEffect.useBGR()) { | 396 if (dfTexEffect.useBGR()) { |
397 delta = -delta; | 397 delta = -delta; |
398 } | 398 } |
399 uman.set3f(fTextureSizeUni, | 399 pdman.set3f(fTextureSizeUni, |
400 SkIntToScalar(fTextureSize.width()), | 400 SkIntToScalar(fTextureSize.width()), |
401 SkIntToScalar(fTextureSize.height()), | 401 SkIntToScalar(fTextureSize.height()), |
402 delta); | 402 delta); |
403 } | 403 } |
404 | 404 |
405 GrColor textColor = dfTexEffect.getTextColor(); | 405 GrColor textColor = dfTexEffect.getTextColor(); |
406 if (textColor != fTextColor) { | 406 if (textColor != fTextColor) { |
407 static const float ONE_OVER_255 = 1.f / 255.f; | 407 static const float ONE_OVER_255 = 1.f / 255.f; |
408 uman.set3f(fTextColorUni, | 408 pdman.set3f(fTextColorUni, |
409 GrColorUnpackR(textColor) * ONE_OVER_255, | 409 GrColorUnpackR(textColor) * ONE_OVER_255, |
410 GrColorUnpackG(textColor) * ONE_OVER_255, | 410 GrColorUnpackG(textColor) * ONE_OVER_255, |
411 GrColorUnpackB(textColor) * ONE_OVER_255); | 411 GrColorUnpackB(textColor) * ONE_OVER_255); |
412 fTextColor = textColor; | 412 fTextColor = textColor; |
413 } | 413 } |
414 } | 414 } |
415 | 415 |
416 static inline void GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&, | 416 static inline void GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&, |
417 GrEffectKeyBuilder* b) { | 417 GrEffectKeyBuilder* b) { |
418 const GrDistanceFieldLCDTextureEffect& dfTexEffect = | 418 const GrDistanceFieldLCDTextureEffect& dfTexEffect = |
419 drawEffect.castEffect<GrDistanceField
LCDTextureEffect>(); | 419 drawEffect.castEffect<GrDistanceField
LCDTextureEffect>(); |
420 | 420 |
421 b->add32(dfTexEffect.isUniformScale()); | 421 b->add32(dfTexEffect.isUniformScale()); |
422 } | 422 } |
423 | 423 |
424 private: | 424 private: |
425 GrGLUniformManager::UniformHandle fTextureSizeUni; | 425 GrGLProgramDataManager::UniformHandle fTextureSizeUni; |
426 SkISize fTextureSize; | 426 SkISize fTextureSize; |
427 GrGLUniformManager::UniformHandle fTextColorUni; | 427 GrGLProgramDataManager::UniformHandle fTextColorUni; |
428 SkColor fTextColor; | 428 SkColor fTextColor; |
429 | 429 |
430 typedef GrGLVertexEffect INHERITED; | 430 typedef GrGLVertexEffect INHERITED; |
431 }; | 431 }; |
432 | 432 |
433 /////////////////////////////////////////////////////////////////////////////// | 433 /////////////////////////////////////////////////////////////////////////////// |
434 | 434 |
435 GrDistanceFieldLCDTextureEffect::GrDistanceFieldLCDTextureEffect( | 435 GrDistanceFieldLCDTextureEffect::GrDistanceFieldLCDTextureEffect( |
436 GrTexture* texture, const GrTe
xtureParams& params, | 436 GrTexture* texture, const GrTe
xtureParams& params, |
437 GrTexture* gamma, const GrText
ureParams& gParams, | 437 GrTexture* gamma, const GrText
ureParams& gParams, |
438 SkColor textColor, | 438 SkColor textColor, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 GrTextureParams::kNone_FilterMode); | 494 GrTextureParams::kNone_FilterMode); |
495 GrColor textColor = GrColorPackRGBA(random->nextULessThan(256), | 495 GrColor textColor = GrColorPackRGBA(random->nextULessThan(256), |
496 random->nextULessThan(256), | 496 random->nextULessThan(256), |
497 random->nextULessThan(256), | 497 random->nextULessThan(256), |
498 random->nextULessThan(256)); | 498 random->nextULessThan(256)); |
499 return GrDistanceFieldLCDTextureEffect::Create(textures[texIdx], params, | 499 return GrDistanceFieldLCDTextureEffect::Create(textures[texIdx], params, |
500 textures[texIdx2], params2, | 500 textures[texIdx2], params2, |
501 textColor, | 501 textColor, |
502 random->nextBool(), random->n
extBool()); | 502 random->nextBool(), random->n
extBool()); |
503 } | 503 } |
OLD | NEW |