| 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" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 const TextureSamplerArray& samplers) SK_OVERRIDE { | 32 const TextureSamplerArray& samplers) SK_OVERRIDE { |
| 33 const char* coords; | 33 const char* coords; |
| 34 GrSLType coordsType = fEffectMatrix.emitCode(builder, key, &coords); | 34 GrSLType coordsType = fEffectMatrix.emitCode(builder, key, &coords); |
| 35 builder->fsCodeAppendf("\t\t%s = ", outputColor); | 35 builder->fsCodeAppendf("\t\t%s = ", outputColor); |
| 36 builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType, | 36 builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType, |
| 37 samplers[0], | 37 samplers[0], |
| 38 coords, | 38 coords, |
| 39 coordsType); | 39 coordsType); |
| 40 builder->fsCodeAppend(";\n"); | 40 builder->fsCodeAppend(";\n"); |
| 41 if (GrConfigConversionEffect::kNone_PMConversion == fPMConversion) { | 41 if (GrConfigConversionEffect::kNone_PMConversion == fPMConversion) { |
| 42 GrAssert(fSwapRedAndBlue); | 42 SkASSERT(fSwapRedAndBlue); |
| 43 builder->fsCodeAppendf("\t%s = %s.bgra;\n", outputColor, outputColor
); | 43 builder->fsCodeAppendf("\t%s = %s.bgra;\n", outputColor, outputColor
); |
| 44 } else { | 44 } else { |
| 45 const char* swiz = fSwapRedAndBlue ? "bgr" : "rgb"; | 45 const char* swiz = fSwapRedAndBlue ? "bgr" : "rgb"; |
| 46 switch (fPMConversion) { | 46 switch (fPMConversion) { |
| 47 case GrConfigConversionEffect::kMulByAlpha_RoundUp_PMConversion: | 47 case GrConfigConversionEffect::kMulByAlpha_RoundUp_PMConversion: |
| 48 builder->fsCodeAppendf( | 48 builder->fsCodeAppendf( |
| 49 "\t\t%s = vec4(ceil(%s.%s * %s.a * 255.0) / 255.0, %s.a)
;\n", | 49 "\t\t%s = vec4(ceil(%s.%s * %s.a * 255.0) / 255.0, %s.a)
;\n", |
| 50 outputColor, outputColor, swiz, outputColor, outputColor
); | 50 outputColor, outputColor, swiz, outputColor, outputColor
); |
| 51 break; | 51 break; |
| 52 case GrConfigConversionEffect::kMulByAlpha_RoundDown_PMConversio
n: | 52 case GrConfigConversionEffect::kMulByAlpha_RoundDown_PMConversio
n: |
| (...skipping 29 matching lines...) Expand all Loading... |
| 82 } | 82 } |
| 83 | 83 |
| 84 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrGLCap
s&) { | 84 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrGLCap
s&) { |
| 85 const GrConfigConversionEffect& conv = drawEffect.castEffect<GrConfigCon
versionEffect>(); | 85 const GrConfigConversionEffect& conv = drawEffect.castEffect<GrConfigCon
versionEffect>(); |
| 86 EffectKey key = static_cast<EffectKey>(conv.swapsRedAndBlue()) | (conv.p
mConversion() << 1); | 86 EffectKey key = static_cast<EffectKey>(conv.swapsRedAndBlue()) | (conv.p
mConversion() << 1); |
| 87 key <<= GrGLEffectMatrix::kKeyBits; | 87 key <<= GrGLEffectMatrix::kKeyBits; |
| 88 EffectKey matrixKey = GrGLEffectMatrix::GenKey(conv.getMatrix(), | 88 EffectKey matrixKey = GrGLEffectMatrix::GenKey(conv.getMatrix(), |
| 89 drawEffect, | 89 drawEffect, |
| 90 conv.coordsType(), | 90 conv.coordsType(), |
| 91 conv.texture(0)); | 91 conv.texture(0)); |
| 92 GrAssert(!(matrixKey & key)); | 92 SkASSERT(!(matrixKey & key)); |
| 93 return matrixKey | key; | 93 return matrixKey | key; |
| 94 } | 94 } |
| 95 | 95 |
| 96 private: | 96 private: |
| 97 bool fSwapRedAndBlue; | 97 bool fSwapRedAndBlue; |
| 98 GrConfigConversionEffect::PMConversion fPMConversion; | 98 GrConfigConversionEffect::PMConversion fPMConversion; |
| 99 GrGLEffectMatrix fEffectMatrix; | 99 GrGLEffectMatrix fEffectMatrix; |
| 100 | 100 |
| 101 typedef GrGLEffect INHERITED; | 101 typedef GrGLEffect INHERITED; |
| 102 | 102 |
| 103 }; | 103 }; |
| 104 | 104 |
| 105 /////////////////////////////////////////////////////////////////////////////// | 105 /////////////////////////////////////////////////////////////////////////////// |
| 106 | 106 |
| 107 GrConfigConversionEffect::GrConfigConversionEffect(GrTexture* texture, | 107 GrConfigConversionEffect::GrConfigConversionEffect(GrTexture* texture, |
| 108 bool swapRedAndBlue, | 108 bool swapRedAndBlue, |
| 109 PMConversion pmConversion, | 109 PMConversion pmConversion, |
| 110 const SkMatrix& matrix) | 110 const SkMatrix& matrix) |
| 111 : GrSingleTextureEffect(texture, matrix) | 111 : GrSingleTextureEffect(texture, matrix) |
| 112 , fSwapRedAndBlue(swapRedAndBlue) | 112 , fSwapRedAndBlue(swapRedAndBlue) |
| 113 , fPMConversion(pmConversion) { | 113 , fPMConversion(pmConversion) { |
| 114 GrAssert(kRGBA_8888_GrPixelConfig == texture->config() || | 114 SkASSERT(kRGBA_8888_GrPixelConfig == texture->config() || |
| 115 kBGRA_8888_GrPixelConfig == texture->config()); | 115 kBGRA_8888_GrPixelConfig == texture->config()); |
| 116 // Why did we pollute our texture cache instead of using a GrSingleTextureEf
fect? | 116 // Why did we pollute our texture cache instead of using a GrSingleTextureEf
fect? |
| 117 GrAssert(swapRedAndBlue || kNone_PMConversion != pmConversion); | 117 SkASSERT(swapRedAndBlue || kNone_PMConversion != pmConversion); |
| 118 } | 118 } |
| 119 | 119 |
| 120 const GrBackendEffectFactory& GrConfigConversionEffect::getFactory() const { | 120 const GrBackendEffectFactory& GrConfigConversionEffect::getFactory() const { |
| 121 return GrTBackendEffectFactory<GrConfigConversionEffect>::getInstance(); | 121 return GrTBackendEffectFactory<GrConfigConversionEffect>::getInstance(); |
| 122 } | 122 } |
| 123 | 123 |
| 124 bool GrConfigConversionEffect::onIsEqual(const GrEffect& s) const { | 124 bool GrConfigConversionEffect::onIsEqual(const GrEffect& s) const { |
| 125 const GrConfigConversionEffect& other = CastEffect<GrConfigConversionEffect>
(s); | 125 const GrConfigConversionEffect& other = CastEffect<GrConfigConversionEffect>
(s); |
| 126 return this->texture(0) == s.texture(0) && | 126 return this->texture(0) == s.texture(0) && |
| 127 other.fSwapRedAndBlue == fSwapRedAndBlue && | 127 other.fSwapRedAndBlue == fSwapRedAndBlue && |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 // The PM conversions assume colors are 0..255 | 287 // The PM conversions assume colors are 0..255 |
| 288 return NULL; | 288 return NULL; |
| 289 } | 289 } |
| 290 AutoEffectUnref effect(SkNEW_ARGS(GrConfigConversionEffect, (texture, | 290 AutoEffectUnref effect(SkNEW_ARGS(GrConfigConversionEffect, (texture, |
| 291 swapRedAndB
lue, | 291 swapRedAndB
lue, |
| 292 pmConversio
n, | 292 pmConversio
n, |
| 293 matrix))); | 293 matrix))); |
| 294 return CreateEffectRef(effect); | 294 return CreateEffectRef(effect); |
| 295 } | 295 } |
| 296 } | 296 } |
| OLD | NEW |