| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "GrConfigConversionEffect.h" | 8 #include "GrConfigConversionEffect.h" |
| 9 #include "GrContext.h" | 9 #include "GrContext.h" |
| 10 #include "GrTBackendEffectFactory.h" | 10 #include "GrTBackendEffectFactory.h" |
| 11 #include "GrSimpleTextureEffect.h" | 11 #include "GrSimpleTextureEffect.h" |
| 12 #include "gl/GrGLEffect.h" | 12 #include "gl/GrGLEffect.h" |
| 13 #include "gl/builders/GrGLProgramBuilder.h" | 13 #include "gl/builders/GrGLProgramBuilder.h" |
| 14 #include "SkMatrix.h" | 14 #include "SkMatrix.h" |
| 15 | 15 |
| 16 class GrGLConfigConversionEffect : public GrGLEffect { | 16 class GrGLConfigConversionEffect : public GrGLEffect { |
| 17 public: | 17 public: |
| 18 GrGLConfigConversionEffect(const GrBackendEffectFactory& factory, | 18 GrGLConfigConversionEffect(const GrBackendEffectFactory& factory, |
| 19 const GrDrawEffect& drawEffect) | 19 const GrEffect& effect) |
| 20 : INHERITED (factory) { | 20 : INHERITED (factory) { |
| 21 const GrConfigConversionEffect& effect = drawEffect.castEffect<GrConfigC
onversionEffect>(); | 21 const GrConfigConversionEffect& configConversionEffect = effect.cast<GrC
onfigConversionEffect>(); |
| 22 fSwapRedAndBlue = effect.swapsRedAndBlue(); | 22 fSwapRedAndBlue = configConversionEffect.swapsRedAndBlue(); |
| 23 fPMConversion = effect.pmConversion(); | 23 fPMConversion = configConversionEffect.pmConversion(); |
| 24 } | 24 } |
| 25 | 25 |
| 26 virtual void emitCode(GrGLProgramBuilder* builder, | 26 virtual void emitCode(GrGLProgramBuilder* builder, |
| 27 const GrDrawEffect&, | 27 const GrEffect&, |
| 28 const GrEffectKey& key, | 28 const GrEffectKey& key, |
| 29 const char* outputColor, | 29 const char* outputColor, |
| 30 const char* inputColor, | 30 const char* inputColor, |
| 31 const TransformedCoordsArray& coords, | 31 const TransformedCoordsArray& coords, |
| 32 const TextureSamplerArray& samplers) SK_OVERRIDE { | 32 const TextureSamplerArray& samplers) SK_OVERRIDE { |
| 33 // Using highp for GLES here in order to avoid some precision issues on
specific GPUs. | 33 // Using highp for GLES here in order to avoid some precision issues on
specific GPUs. |
| 34 GrGLShaderVar tmpVar("tmpColor", kVec4f_GrSLType, 0, GrGLShaderVar::kHig
h_Precision); | 34 GrGLShaderVar tmpVar("tmpColor", kVec4f_GrSLType, 0, GrGLShaderVar::kHig
h_Precision); |
| 35 SkString tmpDecl; | 35 SkString tmpDecl; |
| 36 tmpVar.appendDecl(builder->ctxInfo(), &tmpDecl); | 36 tmpVar.appendDecl(builder->ctxInfo(), &tmpDecl); |
| 37 | 37 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 SkFAIL("Unknown conversion op."); | 77 SkFAIL("Unknown conversion op."); |
| 78 break; | 78 break; |
| 79 } | 79 } |
| 80 fsBuilder->codeAppendf("%s = %s;", outputColor, tmpVar.c_str()); | 80 fsBuilder->codeAppendf("%s = %s;", outputColor, tmpVar.c_str()); |
| 81 } | 81 } |
| 82 SkString modulate; | 82 SkString modulate; |
| 83 GrGLSLMulVarBy4f(&modulate, 2, outputColor, inputColor); | 83 GrGLSLMulVarBy4f(&modulate, 2, outputColor, inputColor); |
| 84 fsBuilder->codeAppend(modulate.c_str()); | 84 fsBuilder->codeAppend(modulate.c_str()); |
| 85 } | 85 } |
| 86 | 86 |
| 87 static inline void GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&, | 87 static inline void GenKey(const GrEffect& effect, const GrGLCaps&, |
| 88 GrEffectKeyBuilder* b) { | 88 GrEffectKeyBuilder* b) { |
| 89 const GrConfigConversionEffect& conv = drawEffect.castEffect<GrConfigCon
versionEffect>(); | 89 const GrConfigConversionEffect& conv = effect.cast<GrConfigConversionEff
ect>(); |
| 90 uint32_t key = (conv.swapsRedAndBlue() ? 0 : 1) | (conv.pmConversion() <
< 1); | 90 uint32_t key = (conv.swapsRedAndBlue() ? 0 : 1) | (conv.pmConversion() <
< 1); |
| 91 b->add32(key); | 91 b->add32(key); |
| 92 } | 92 } |
| 93 | 93 |
| 94 private: | 94 private: |
| 95 bool fSwapRedAndBlue; | 95 bool fSwapRedAndBlue; |
| 96 GrConfigConversionEffect::PMConversion fPMConversion; | 96 GrConfigConversionEffect::PMConversion fPMConversion; |
| 97 | 97 |
| 98 typedef GrGLEffect INHERITED; | 98 typedef GrGLEffect INHERITED; |
| 99 | 99 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 112 kBGRA_8888_GrPixelConfig == texture->config()); | 112 kBGRA_8888_GrPixelConfig == texture->config()); |
| 113 // Why did we pollute our texture cache instead of using a GrSingleTextureEf
fect? | 113 // Why did we pollute our texture cache instead of using a GrSingleTextureEf
fect? |
| 114 SkASSERT(swapRedAndBlue || kNone_PMConversion != pmConversion); | 114 SkASSERT(swapRedAndBlue || kNone_PMConversion != pmConversion); |
| 115 } | 115 } |
| 116 | 116 |
| 117 const GrBackendEffectFactory& GrConfigConversionEffect::getFactory() const { | 117 const GrBackendEffectFactory& GrConfigConversionEffect::getFactory() const { |
| 118 return GrTBackendEffectFactory<GrConfigConversionEffect>::getInstance(); | 118 return GrTBackendEffectFactory<GrConfigConversionEffect>::getInstance(); |
| 119 } | 119 } |
| 120 | 120 |
| 121 bool GrConfigConversionEffect::onIsEqual(const GrEffect& s) const { | 121 bool GrConfigConversionEffect::onIsEqual(const GrEffect& s) const { |
| 122 const GrConfigConversionEffect& other = CastEffect<GrConfigConversionEffect>
(s); | 122 const GrConfigConversionEffect& other = s.cast<GrConfigConversionEffect>(); |
| 123 return this->texture(0) == s.texture(0) && | 123 return this->texture(0) == s.texture(0) && |
| 124 other.fSwapRedAndBlue == fSwapRedAndBlue && | 124 other.fSwapRedAndBlue == fSwapRedAndBlue && |
| 125 other.fPMConversion == fPMConversion; | 125 other.fPMConversion == fPMConversion; |
| 126 } | 126 } |
| 127 | 127 |
| 128 void GrConfigConversionEffect::getConstantColorComponents(GrColor* color, | 128 void GrConfigConversionEffect::getConstantColorComponents(GrColor* color, |
| 129 uint32_t* validFlags)
const { | 129 uint32_t* validFlags)
const { |
| 130 this->updateConstantColorComponentsForModulation(color, validFlags); | 130 this->updateConstantColorComponentsForModulation(color, validFlags); |
| 131 } | 131 } |
| 132 | 132 |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 kNone_PMConversion != pmConversion) { | 278 kNone_PMConversion != pmConversion) { |
| 279 // The PM conversions assume colors are 0..255 | 279 // The PM conversions assume colors are 0..255 |
| 280 return NULL; | 280 return NULL; |
| 281 } | 281 } |
| 282 return SkNEW_ARGS(GrConfigConversionEffect, (texture, | 282 return SkNEW_ARGS(GrConfigConversionEffect, (texture, |
| 283 swapRedAndBlue, | 283 swapRedAndBlue, |
| 284 pmConversion, | 284 pmConversion, |
| 285 matrix)); | 285 matrix)); |
| 286 } | 286 } |
| 287 } | 287 } |
| OLD | NEW |