Chromium Code Reviews| 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 "GrDrawContext.h" | 10 #include "GrDrawContext.h" |
| 11 #include "GrInvariantOutput.h" | 11 #include "GrInvariantOutput.h" |
| 12 #include "GrSimpleTextureEffect.h" | 12 #include "GrSimpleTextureEffect.h" |
| 13 #include "SkMatrix.h" | 13 #include "SkMatrix.h" |
| 14 #include "gl/GrGLFragmentProcessor.h" | 14 #include "gl/GrGLFragmentProcessor.h" |
| 15 #include "gl/builders/GrGLProgramBuilder.h" | 15 #include "gl/builders/GrGLProgramBuilder.h" |
| 16 | 16 |
| 17 class GrGLConfigConversionEffect : public GrGLFragmentProcessor { | 17 class GrGLConfigConversionEffect : public GrGLFragmentProcessor { |
| 18 public: | 18 public: |
| 19 GrGLConfigConversionEffect(const GrProcessor& processor) { | 19 GrGLConfigConversionEffect(const GrProcessor& processor) { |
| 20 const GrConfigConversionEffect& configConversionEffect = | 20 const GrConfigConversionEffect& configConversionEffect = |
| 21 processor.cast<GrConfigConversionEffect>(); | 21 processor.cast<GrConfigConversionEffect>(); |
| 22 fSwapRedAndBlue = configConversionEffect.swapsRedAndBlue(); | 22 fSwapRedAndBlue = configConversionEffect.swapsRedAndBlue(); |
| 23 fPMConversion = configConversionEffect.pmConversion(); | 23 fPMConversion = configConversionEffect.pmConversion(); |
| 24 } | 24 } |
| 25 | 25 |
| 26 virtual void emitCode(GrGLFPBuilder* builder, | 26 virtual void emitCode(EmitArgs& args) override { |
| 27 const GrFragmentProcessor&, | |
| 28 const char* outputColor, | |
| 29 const char* inputColor, | |
| 30 const TransformedCoordsArray& coords, | |
| 31 const TextureSamplerArray& samplers) override { | |
| 32 // Using highp for GLES here in order to avoid some precision issues on specific GPUs. | 27 // Using highp for GLES here in order to avoid some precision issues on specific GPUs. |
| 33 GrGLShaderVar tmpVar("tmpColor", kVec4f_GrSLType, 0, kHigh_GrSLPrecision ); | 28 GrGLShaderVar tmpVar("tmpColor", kVec4f_GrSLType, 0, kHigh_GrSLPrecision ); |
| 34 SkString tmpDecl; | 29 SkString tmpDecl; |
| 35 tmpVar.appendDecl(builder->ctxInfo(), &tmpDecl); | 30 tmpVar.appendDecl(args.fBuilder->ctxInfo(), &tmpDecl); |
| 36 | 31 |
| 37 GrGLFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); | 32 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder (); |
| 38 | 33 |
| 39 fsBuilder->codeAppendf("%s;", tmpDecl.c_str()); | 34 fsBuilder->codeAppendf("%s;", tmpDecl.c_str()); |
| 40 | 35 |
| 41 fsBuilder->codeAppendf("%s = ", tmpVar.c_str()); | 36 fsBuilder->codeAppendf("%s = ", tmpVar.c_str()); |
| 42 fsBuilder->appendTextureLookup(samplers[0], coords[0].c_str(), coords[0] .getType()); | 37 fsBuilder->appendTextureLookup(args.fSamplers[0], args.fCoords[0].c_str( ), args.fCoords[0].getType()); |
|
joshualitt
2015/07/22 19:34:05
line wrap @100
| |
| 43 fsBuilder->codeAppend(";"); | 38 fsBuilder->codeAppend(";"); |
| 44 | 39 |
| 45 if (GrConfigConversionEffect::kNone_PMConversion == fPMConversion) { | 40 if (GrConfigConversionEffect::kNone_PMConversion == fPMConversion) { |
| 46 SkASSERT(fSwapRedAndBlue); | 41 SkASSERT(fSwapRedAndBlue); |
| 47 fsBuilder->codeAppendf("%s = %s.bgra;", outputColor, tmpVar.c_str()) ; | 42 fsBuilder->codeAppendf("%s = %s.bgra;", args.fOutputColor, tmpVar.c_ str()); |
| 48 } else { | 43 } else { |
| 49 const char* swiz = fSwapRedAndBlue ? "bgr" : "rgb"; | 44 const char* swiz = fSwapRedAndBlue ? "bgr" : "rgb"; |
| 50 switch (fPMConversion) { | 45 switch (fPMConversion) { |
| 51 case GrConfigConversionEffect::kMulByAlpha_RoundUp_PMConversion: | 46 case GrConfigConversionEffect::kMulByAlpha_RoundUp_PMConversion: |
| 52 fsBuilder->codeAppendf( | 47 fsBuilder->codeAppendf( |
| 53 "%s = vec4(ceil(%s.%s * %s.a * 255.0) / 255.0, %s.a);", | 48 "%s = vec4(ceil(%s.%s * %s.a * 255.0) / 255.0, %s.a);", |
| 54 tmpVar.c_str(), tmpVar.c_str(), swiz, tmpVar.c_str(), tm pVar.c_str()); | 49 tmpVar.c_str(), tmpVar.c_str(), swiz, tmpVar.c_str(), tm pVar.c_str()); |
| 55 break; | 50 break; |
| 56 case GrConfigConversionEffect::kMulByAlpha_RoundDown_PMConversio n: | 51 case GrConfigConversionEffect::kMulByAlpha_RoundDown_PMConversio n: |
| 57 // Add a compensation(0.001) here to avoid the side effect o f the floor operation. | 52 // Add a compensation(0.001) here to avoid the side effect o f the floor operation. |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 69 break; | 64 break; |
| 70 case GrConfigConversionEffect::kDivByAlpha_RoundDown_PMConversio n: | 65 case GrConfigConversionEffect::kDivByAlpha_RoundDown_PMConversio n: |
| 71 fsBuilder->codeAppendf( | 66 fsBuilder->codeAppendf( |
| 72 "%s = %s.a <= 0.0 ? vec4(0,0,0,0) : vec4(floor(%s.%s / % s.a * 255.0) / 255.0, %s.a);", | 67 "%s = %s.a <= 0.0 ? vec4(0,0,0,0) : vec4(floor(%s.%s / % s.a * 255.0) / 255.0, %s.a);", |
| 73 tmpVar.c_str(), tmpVar.c_str(), tmpVar.c_str(), swiz, tm pVar.c_str(), tmpVar.c_str()); | 68 tmpVar.c_str(), tmpVar.c_str(), tmpVar.c_str(), swiz, tm pVar.c_str(), tmpVar.c_str()); |
| 74 break; | 69 break; |
| 75 default: | 70 default: |
| 76 SkFAIL("Unknown conversion op."); | 71 SkFAIL("Unknown conversion op."); |
| 77 break; | 72 break; |
| 78 } | 73 } |
| 79 fsBuilder->codeAppendf("%s = %s;", outputColor, tmpVar.c_str()); | 74 fsBuilder->codeAppendf("%s = %s;", args.fOutputColor, tmpVar.c_str() ); |
| 80 } | 75 } |
| 81 SkString modulate; | 76 SkString modulate; |
| 82 GrGLSLMulVarBy4f(&modulate, outputColor, inputColor); | 77 GrGLSLMulVarBy4f(&modulate, args.fOutputColor, args.fInputColor); |
| 83 fsBuilder->codeAppend(modulate.c_str()); | 78 fsBuilder->codeAppend(modulate.c_str()); |
| 84 } | 79 } |
| 85 | 80 |
| 86 static inline void GenKey(const GrProcessor& processor, const GrGLSLCaps&, | 81 static inline void GenKey(const GrProcessor& processor, const GrGLSLCaps&, |
| 87 GrProcessorKeyBuilder* b) { | 82 GrProcessorKeyBuilder* b) { |
| 88 const GrConfigConversionEffect& conv = processor.cast<GrConfigConversion Effect>(); | 83 const GrConfigConversionEffect& conv = processor.cast<GrConfigConversion Effect>(); |
| 89 uint32_t key = (conv.swapsRedAndBlue() ? 0 : 1) | (conv.pmConversion() < < 1); | 84 uint32_t key = (conv.swapsRedAndBlue() ? 0 : 1) | (conv.pmConversion() < < 1); |
| 90 b->add32(key); | 85 b->add32(key); |
| 91 } | 86 } |
| 92 | 87 |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 299 // The PM conversions assume colors are 0..255 | 294 // The PM conversions assume colors are 0..255 |
| 300 return NULL; | 295 return NULL; |
| 301 } | 296 } |
| 302 return SkNEW_ARGS(GrConfigConversionEffect, (procDataManager, | 297 return SkNEW_ARGS(GrConfigConversionEffect, (procDataManager, |
| 303 texture, | 298 texture, |
| 304 swapRedAndBlue, | 299 swapRedAndBlue, |
| 305 pmConversion, | 300 pmConversion, |
| 306 matrix)); | 301 matrix)); |
| 307 } | 302 } |
| 308 } | 303 } |
| OLD | NEW |