| 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/GrGLEffectMatrix.h" | 13 #include "gl/GrGLEffectMatrix.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 GrEffectRef& s) : INHERITED (factory) { | 19 const GrDrawEffect& drawEffect) |
| 20 const GrConfigConversionEffect& effect = CastEffect<GrConfigConversionEf
fect>(s); | 20 : INHERITED (factory) |
| 21 , fEffectMatrix(drawEffect.castEffect<GrConfigConversionEffect>().coordsType
()) { |
| 22 const GrConfigConversionEffect& effect = drawEffect.castEffect<GrConfigC
onversionEffect>(); |
| 21 fSwapRedAndBlue = effect.swapsRedAndBlue(); | 23 fSwapRedAndBlue = effect.swapsRedAndBlue(); |
| 22 fPMConversion = effect.pmConversion(); | 24 fPMConversion = effect.pmConversion(); |
| 23 } | 25 } |
| 24 | 26 |
| 25 virtual void emitCode(GrGLShaderBuilder* builder, | 27 virtual void emitCode(GrGLShaderBuilder* builder, |
| 26 const GrEffectStage&, | 28 const GrDrawEffect&, |
| 27 EffectKey key, | 29 EffectKey key, |
| 28 const char* vertexCoords, | |
| 29 const char* outputColor, | 30 const char* outputColor, |
| 30 const char* inputColor, | 31 const char* inputColor, |
| 31 const TextureSamplerArray& samplers) SK_OVERRIDE { | 32 const TextureSamplerArray& samplers) SK_OVERRIDE { |
| 32 const char* coords; | 33 const char* coords; |
| 33 GrSLType coordsType = fEffectMatrix.emitCode(builder, key, vertexCoords,
&coords); | 34 GrSLType coordsType = fEffectMatrix.emitCode(builder, key, &coords); |
| 34 builder->fsCodeAppendf("\t\t%s = ", outputColor); | 35 builder->fsCodeAppendf("\t\t%s = ", outputColor); |
| 35 builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType, | 36 builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType, |
| 36 samplers[0], | 37 samplers[0], |
| 37 coords, | 38 coords, |
| 38 coordsType); | 39 coordsType); |
| 39 builder->fsCodeAppend(";\n"); | 40 builder->fsCodeAppend(";\n"); |
| 40 if (GrConfigConversionEffect::kNone_PMConversion == fPMConversion) { | 41 if (GrConfigConversionEffect::kNone_PMConversion == fPMConversion) { |
| 41 GrAssert(fSwapRedAndBlue); | 42 GrAssert(fSwapRedAndBlue); |
| 42 builder->fsCodeAppendf("\t%s = %s.bgra;\n", outputColor, outputColor
); | 43 builder->fsCodeAppendf("\t%s = %s.bgra;\n", outputColor, outputColor
); |
| 43 } else { | 44 } else { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 64 default: | 65 default: |
| 65 GrCrash("Unknown conversion op."); | 66 GrCrash("Unknown conversion op."); |
| 66 break; | 67 break; |
| 67 } | 68 } |
| 68 } | 69 } |
| 69 SkString modulate; | 70 SkString modulate; |
| 70 GrGLSLMulVarBy4f(&modulate, 2, outputColor, inputColor); | 71 GrGLSLMulVarBy4f(&modulate, 2, outputColor, inputColor); |
| 71 builder->fsCodeAppend(modulate.c_str()); | 72 builder->fsCodeAppend(modulate.c_str()); |
| 72 } | 73 } |
| 73 | 74 |
| 74 void setData(const GrGLUniformManager& uman, const GrEffectStage& stage) { | 75 void setData(const GrGLUniformManager& uman, const GrDrawEffect& drawEffect)
{ |
| 75 const GrConfigConversionEffect& effect = | 76 const GrConfigConversionEffect& conv = drawEffect.castEffect<GrConfigCon
versionEffect>(); |
| 76 GetEffectFromStage<GrConfigConversionEffect>(stage); | 77 fEffectMatrix.setData(uman, conv.getMatrix(), drawEffect, conv.texture(0
)); |
| 77 fEffectMatrix.setData(uman, | |
| 78 effect.getMatrix(), | |
| 79 stage.getCoordChangeMatrix(), | |
| 80 effect.texture(0)); | |
| 81 } | 78 } |
| 82 | 79 |
| 83 static inline EffectKey GenKey(const GrEffectStage& s, const GrGLCaps&) { | 80 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrGLCap
s&) { |
| 84 const GrConfigConversionEffect& effect = GetEffectFromStage<GrConfigConv
ersionEffect>(s); | 81 const GrConfigConversionEffect& conv = drawEffect.castEffect<GrConfigCon
versionEffect>(); |
| 85 EffectKey key = static_cast<EffectKey>(effect.swapsRedAndBlue()) | | 82 EffectKey key = static_cast<EffectKey>(conv.swapsRedAndBlue()) | (conv.p
mConversion() << 1); |
| 86 (effect.pmConversion() << 1); | |
| 87 key <<= GrGLEffectMatrix::kKeyBits; | 83 key <<= GrGLEffectMatrix::kKeyBits; |
| 88 EffectKey matrixKey = GrGLEffectMatrix::GenKey(effect.getMatrix(), | 84 EffectKey matrixKey = GrGLEffectMatrix::GenKey(conv.getMatrix(), |
| 89 s.getCoordChangeMatrix()
, | 85 drawEffect, |
| 90 effect.texture(0)); | 86 conv.coordsType(), |
| 87 conv.texture(0)); |
| 91 GrAssert(!(matrixKey & key)); | 88 GrAssert(!(matrixKey & key)); |
| 92 return matrixKey | key; | 89 return matrixKey | key; |
| 93 } | 90 } |
| 94 | 91 |
| 95 private: | 92 private: |
| 96 bool fSwapRedAndBlue; | 93 bool fSwapRedAndBlue; |
| 97 GrConfigConversionEffect::PMConversion fPMConversion; | 94 GrConfigConversionEffect::PMConversion fPMConversion; |
| 98 GrGLEffectMatrix fEffectMatrix; | 95 GrGLEffectMatrix fEffectMatrix; |
| 99 | 96 |
| 100 typedef GrGLEffect INHERITED; | 97 typedef GrGLEffect INHERITED; |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 // The PM conversions assume colors are 0..255 | 279 // The PM conversions assume colors are 0..255 |
| 283 return NULL; | 280 return NULL; |
| 284 } | 281 } |
| 285 AutoEffectUnref effect(SkNEW_ARGS(GrConfigConversionEffect, (texture, | 282 AutoEffectUnref effect(SkNEW_ARGS(GrConfigConversionEffect, (texture, |
| 286 swapRedAndB
lue, | 283 swapRedAndB
lue, |
| 287 pmConversio
n, | 284 pmConversio
n, |
| 288 matrix))); | 285 matrix))); |
| 289 return CreateEffectRef(effect); | 286 return CreateEffectRef(effect); |
| 290 } | 287 } |
| 291 } | 288 } |
| OLD | NEW |