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/GrGLShaderBuilder.h" | 13 #include "gl/GrGLShaderBuilder.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 GrDrawEffect& drawEffect) |
20 : INHERITED (factory) { | 20 : INHERITED (factory) { |
21 const GrConfigConversionEffect& effect = drawEffect.castEffect<GrConfigC
onversionEffect>(); | 21 const GrConfigConversionEffect& effect = drawEffect.castEffect<GrConfigC
onversionEffect>(); |
22 fSwapRedAndBlue = effect.swapsRedAndBlue(); | 22 fSwapRedAndBlue = effect.swapsRedAndBlue(); |
23 fPMConversion = effect.pmConversion(); | 23 fPMConversion = effect.pmConversion(); |
24 } | 24 } |
25 | 25 |
26 virtual void emitCode(GrGLShaderBuilder* builder, | 26 virtual void emitCode(GrGLShaderBuilder* builder, |
27 const GrDrawEffect&, | 27 const GrDrawEffect&, |
28 EffectKey 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 builder->fsCodeAppendf("\t\t%s = ", outputColor); | 33 builder->fsCodeAppendf("\t\t%s = ", outputColor); |
34 builder->fsAppendTextureLookup(samplers[0], coords[0].c_str(), coords[0]
.type()); | 34 builder->fsAppendTextureLookup(samplers[0], coords[0].c_str(), coords[0]
.type()); |
35 builder->fsCodeAppend(";\n"); | 35 builder->fsCodeAppend(";\n"); |
36 if (GrConfigConversionEffect::kNone_PMConversion == fPMConversion) { | 36 if (GrConfigConversionEffect::kNone_PMConversion == fPMConversion) { |
37 SkASSERT(fSwapRedAndBlue); | 37 SkASSERT(fSwapRedAndBlue); |
38 builder->fsCodeAppendf("\t%s = %s.bgra;\n", outputColor, outputColor
); | 38 builder->fsCodeAppendf("\t%s = %s.bgra;\n", outputColor, outputColor
); |
(...skipping 25 matching lines...) Expand all Loading... |
64 default: | 64 default: |
65 SkFAIL("Unknown conversion op."); | 65 SkFAIL("Unknown conversion op."); |
66 break; | 66 break; |
67 } | 67 } |
68 } | 68 } |
69 SkString modulate; | 69 SkString modulate; |
70 GrGLSLMulVarBy4f(&modulate, 2, outputColor, inputColor); | 70 GrGLSLMulVarBy4f(&modulate, 2, outputColor, inputColor); |
71 builder->fsCodeAppend(modulate.c_str()); | 71 builder->fsCodeAppend(modulate.c_str()); |
72 } | 72 } |
73 | 73 |
74 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrGLCap
s&) { | 74 static inline void GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&, |
| 75 GrEffectKeyBuilder* b) { |
75 const GrConfigConversionEffect& conv = drawEffect.castEffect<GrConfigCon
versionEffect>(); | 76 const GrConfigConversionEffect& conv = drawEffect.castEffect<GrConfigCon
versionEffect>(); |
76 return static_cast<EffectKey>(conv.swapsRedAndBlue()) | (conv.pmConversi
on() << 1); | 77 uint32_t key = (conv.swapsRedAndBlue() ? 0 : 1) | (conv.pmConversion() <
< 1); |
| 78 b->add32(key); |
77 } | 79 } |
78 | 80 |
79 private: | 81 private: |
80 bool fSwapRedAndBlue; | 82 bool fSwapRedAndBlue; |
81 GrConfigConversionEffect::PMConversion fPMConversion; | 83 GrConfigConversionEffect::PMConversion fPMConversion; |
82 | 84 |
83 typedef GrGLEffect INHERITED; | 85 typedef GrGLEffect INHERITED; |
84 | 86 |
85 }; | 87 }; |
86 | 88 |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 kNone_PMConversion != pmConversion) { | 265 kNone_PMConversion != pmConversion) { |
264 // The PM conversions assume colors are 0..255 | 266 // The PM conversions assume colors are 0..255 |
265 return NULL; | 267 return NULL; |
266 } | 268 } |
267 return SkNEW_ARGS(GrConfigConversionEffect, (texture, | 269 return SkNEW_ARGS(GrConfigConversionEffect, (texture, |
268 swapRedAndBlue, | 270 swapRedAndBlue, |
269 pmConversion, | 271 pmConversion, |
270 matrix)); | 272 matrix)); |
271 } | 273 } |
272 } | 274 } |
OLD | NEW |