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 12 matching lines...) Expand all Loading... |
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 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 builder->fsCodeAppendf("\t\t%s = ", outputColor); | 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); |
| 35 SkString tmpDecl; |
| 36 tmpVar.appendDecl(builder->ctxInfo(), &tmpDecl); |
| 37 builder->fsCodeAppendf("%s;", tmpDecl.c_str()); |
| 38 |
| 39 builder->fsCodeAppendf("%s = ", tmpVar.c_str()); |
34 builder->fsAppendTextureLookup(samplers[0], coords[0].c_str(), coords[0]
.type()); | 40 builder->fsAppendTextureLookup(samplers[0], coords[0].c_str(), coords[0]
.type()); |
35 builder->fsCodeAppend(";\n"); | 41 builder->fsCodeAppend(";"); |
| 42 |
36 if (GrConfigConversionEffect::kNone_PMConversion == fPMConversion) { | 43 if (GrConfigConversionEffect::kNone_PMConversion == fPMConversion) { |
37 SkASSERT(fSwapRedAndBlue); | 44 SkASSERT(fSwapRedAndBlue); |
38 builder->fsCodeAppendf("\t%s = %s.bgra;\n", outputColor, outputColor
); | 45 builder->fsCodeAppendf("%s = %s.bgra;", outputColor, tmpVar.c_str())
; |
39 } else { | 46 } else { |
40 const char* swiz = fSwapRedAndBlue ? "bgr" : "rgb"; | 47 const char* swiz = fSwapRedAndBlue ? "bgr" : "rgb"; |
41 switch (fPMConversion) { | 48 switch (fPMConversion) { |
42 case GrConfigConversionEffect::kMulByAlpha_RoundUp_PMConversion: | 49 case GrConfigConversionEffect::kMulByAlpha_RoundUp_PMConversion: |
43 builder->fsCodeAppendf( | 50 builder->fsCodeAppendf( |
44 "\t\t%s = vec4(ceil(%s.%s * %s.a * 255.0) / 255.0, %s.a)
;\n", | 51 "%s = vec4(ceil(%s.%s * %s.a * 255.0) / 255.0, %s.a);", |
45 outputColor, outputColor, swiz, outputColor, outputColor
); | 52 tmpVar.c_str(), tmpVar.c_str(), swiz, tmpVar.c_str(), tm
pVar.c_str()); |
46 break; | 53 break; |
47 case GrConfigConversionEffect::kMulByAlpha_RoundDown_PMConversio
n: | 54 case GrConfigConversionEffect::kMulByAlpha_RoundDown_PMConversio
n: |
48 // Add a compensation(0.001) here to avoid the side effect o
f the floor operation. | 55 // Add a compensation(0.001) here to avoid the side effect o
f the floor operation. |
49 // In Intel GPUs, the integer value converted from floor(%s.
r * 255.0) / 255.0 | 56 // In Intel GPUs, the integer value converted from floor(%s.
r * 255.0) / 255.0 |
50 // is less than the integer value converted from %s.r by 1
when the %s.r is | 57 // is less than the integer value converted from %s.r by 1
when the %s.r is |
51 // converted from the integer value 2^n, such as 1, 2, 4, 8,
etc. | 58 // converted from the integer value 2^n, such as 1, 2, 4, 8,
etc. |
52 builder->fsCodeAppendf( | 59 builder->fsCodeAppendf( |
53 "\t\t%s = vec4(floor(%s.%s * %s.a * 255.0 + 0.001) / 255
.0, %s.a);\n", | 60 "%s = vec4(floor(%s.%s * %s.a * 255.0 + 0.001) / 255.0,
%s.a);", |
54 outputColor, outputColor, swiz, outputColor, outputColor
); | 61 tmpVar.c_str(), tmpVar.c_str(), swiz, tmpVar.c_str(), tm
pVar.c_str()); |
55 break; | 62 break; |
56 case GrConfigConversionEffect::kDivByAlpha_RoundUp_PMConversion: | 63 case GrConfigConversionEffect::kDivByAlpha_RoundUp_PMConversion: |
57 builder->fsCodeAppendf("\t\t%s = %s.a <= 0.0 ? vec4(0,0,0,0)
: vec4(ceil(%s.%s / %s.a * 255.0) / 255.0, %s.a);\n", | 64 builder->fsCodeAppendf( |
58 outputColor, outputColor, outputColor, swiz, outputColor
, outputColor); | 65 "%s = %s.a <= 0.0 ? vec4(0,0,0,0) : vec4(ceil(%s.%s / %s
.a * 255.0) / 255.0, %s.a);", |
| 66 tmpVar.c_str(), tmpVar.c_str(), tmpVar.c_str(), swiz, tm
pVar.c_str(), tmpVar.c_str()); |
59 break; | 67 break; |
60 case GrConfigConversionEffect::kDivByAlpha_RoundDown_PMConversio
n: | 68 case GrConfigConversionEffect::kDivByAlpha_RoundDown_PMConversio
n: |
61 builder->fsCodeAppendf("\t\t%s = %s.a <= 0.0 ? vec4(0,0,0,0)
: vec4(floor(%s.%s / %s.a * 255.0) / 255.0, %s.a);\n", | 69 builder->fsCodeAppendf( |
62 outputColor, outputColor, outputColor, swiz, outputColor
, outputColor); | 70 "%s = %s.a <= 0.0 ? vec4(0,0,0,0) : vec4(floor(%s.%s / %
s.a * 255.0) / 255.0, %s.a);", |
| 71 tmpVar.c_str(), tmpVar.c_str(), tmpVar.c_str(), swiz, tm
pVar.c_str(), tmpVar.c_str()); |
63 break; | 72 break; |
64 default: | 73 default: |
65 SkFAIL("Unknown conversion op."); | 74 SkFAIL("Unknown conversion op."); |
66 break; | 75 break; |
67 } | 76 } |
| 77 builder->fsCodeAppendf("%s = %s;", outputColor, tmpVar.c_str()); |
68 } | 78 } |
69 SkString modulate; | 79 SkString modulate; |
70 GrGLSLMulVarBy4f(&modulate, 2, outputColor, inputColor); | 80 GrGLSLMulVarBy4f(&modulate, 2, outputColor, inputColor); |
71 builder->fsCodeAppend(modulate.c_str()); | 81 builder->fsCodeAppend(modulate.c_str()); |
72 } | 82 } |
73 | 83 |
74 static inline void GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&, | 84 static inline void GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&, |
75 GrEffectKeyBuilder* b) { | 85 GrEffectKeyBuilder* b) { |
76 const GrConfigConversionEffect& conv = drawEffect.castEffect<GrConfigCon
versionEffect>(); | 86 const GrConfigConversionEffect& conv = drawEffect.castEffect<GrConfigCon
versionEffect>(); |
77 uint32_t key = (conv.swapsRedAndBlue() ? 0 : 1) | (conv.pmConversion() <
< 1); | 87 uint32_t key = (conv.swapsRedAndBlue() ? 0 : 1) | (conv.pmConversion() <
< 1); |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 kNone_PMConversion != pmConversion) { | 275 kNone_PMConversion != pmConversion) { |
266 // The PM conversions assume colors are 0..255 | 276 // The PM conversions assume colors are 0..255 |
267 return NULL; | 277 return NULL; |
268 } | 278 } |
269 return SkNEW_ARGS(GrConfigConversionEffect, (texture, | 279 return SkNEW_ARGS(GrConfigConversionEffect, (texture, |
270 swapRedAndBlue, | 280 swapRedAndBlue, |
271 pmConversion, | 281 pmConversion, |
272 matrix)); | 282 matrix)); |
273 } | 283 } |
274 } | 284 } |
OLD | NEW |