OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
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 "SkGradientShaderPriv.h" | 8 #include "SkGradientShaderPriv.h" |
9 #include "SkLinearGradient.h" | 9 #include "SkLinearGradient.h" |
10 #include "SkRadialGradient.h" | 10 #include "SkRadialGradient.h" |
(...skipping 1010 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1021 | 1021 |
1022 if (GrGradientEffect::kBeforeInterp_PremulType == e.getPremulType()) { | 1022 if (GrGradientEffect::kBeforeInterp_PremulType == e.getPremulType()) { |
1023 key |= kPremulBeforeInterpKey; | 1023 key |= kPremulBeforeInterpKey; |
1024 } | 1024 } |
1025 | 1025 |
1026 return key; | 1026 return key; |
1027 } | 1027 } |
1028 | 1028 |
1029 void GrGLGradientEffect::emitColor(GrGLSLFPBuilder* builder, | 1029 void GrGLGradientEffect::emitColor(GrGLSLFPBuilder* builder, |
1030 GrGLSLFragmentBuilder* fragBuilder, | 1030 GrGLSLFragmentBuilder* fragBuilder, |
| 1031 const GrGLSLCaps* glslCaps, |
1031 const GrGradientEffect& ge, | 1032 const GrGradientEffect& ge, |
1032 const char* gradientTValue, | 1033 const char* gradientTValue, |
1033 const char* outputColor, | 1034 const char* outputColor, |
1034 const char* inputColor, | 1035 const char* inputColor, |
1035 const TextureSamplerArray& samplers) { | 1036 const TextureSamplerArray& samplers) { |
1036 if (SkGradientShaderBase::kTwo_GpuColorType == ge.getColorType()){ | 1037 if (SkGradientShaderBase::kTwo_GpuColorType == ge.getColorType()){ |
1037 fragBuilder->codeAppendf("\tvec4 colorTemp = mix(%s, %s, clamp(%s, 0.0,
1.0));\n", | 1038 fragBuilder->codeAppendf("\tvec4 colorTemp = mix(%s, %s, clamp(%s, 0.0,
1.0));\n", |
1038 builder->getUniformVariable(fColorStartUni).c_s
tr(), | 1039 builder->getUniformVariable(fColorStartUni).c_s
tr(), |
1039 builder->getUniformVariable(fColorEndUni).c_str
(), | 1040 builder->getUniformVariable(fColorEndUni).c_str
(), |
1040 gradientTValue); | 1041 gradientTValue); |
1041 // Note that we could skip this step if both colors are known to be opaq
ue. Two | 1042 // Note that we could skip this step if both colors are known to be opaq
ue. Two |
1042 // considerations: | 1043 // considerations: |
1043 // The gradient SkShader reporting opaque is more restrictive than neces
sary in the two pt | 1044 // The gradient SkShader reporting opaque is more restrictive than neces
sary in the two pt |
1044 // case. Make sure the key reflects this optimization (and note that it
can use the same | 1045 // case. Make sure the key reflects this optimization (and note that it
can use the same |
1045 // shader as thekBeforeIterp case). This same optimization applies to th
e 3 color case below. | 1046 // shader as thekBeforeIterp case). This same optimization applies to th
e 3 color case |
| 1047 // below. |
1046 if (GrGradientEffect::kAfterInterp_PremulType == ge.getPremulType()) { | 1048 if (GrGradientEffect::kAfterInterp_PremulType == ge.getPremulType()) { |
1047 fragBuilder->codeAppend("\tcolorTemp.rgb *= colorTemp.a;\n"); | 1049 fragBuilder->codeAppend("\tcolorTemp.rgb *= colorTemp.a;\n"); |
1048 } | 1050 } |
1049 | 1051 |
1050 fragBuilder->codeAppendf("\t%s = %s;\n", outputColor, | 1052 fragBuilder->codeAppendf("\t%s = %s;\n", outputColor, |
1051 (GrGLSLExpr4(inputColor) * GrGLSLExpr4("colorTe
mp")).c_str()); | 1053 (GrGLSLExpr4(inputColor) * GrGLSLExpr4("colorTe
mp")).c_str()); |
1052 } else if (SkGradientShaderBase::kThree_GpuColorType == ge.getColorType()) { | 1054 } else if (SkGradientShaderBase::kThree_GpuColorType == ge.getColorType()) { |
1053 fragBuilder->codeAppendf("\tfloat oneMinus2t = 1.0 - (2.0 * (%s));\n", | 1055 fragBuilder->codeAppendf("\tfloat oneMinus2t = 1.0 - (2.0 * (%s));\n", |
1054 gradientTValue); | 1056 gradientTValue); |
1055 fragBuilder->codeAppendf("\tvec4 colorTemp = clamp(oneMinus2t, 0.0, 1.0)
* %s;\n", | 1057 fragBuilder->codeAppendf("\tvec4 colorTemp = clamp(oneMinus2t, 0.0, 1.0)
* %s;\n", |
1056 builder->getUniformVariable(fColorStartUni).c_s
tr()); | 1058 builder->getUniformVariable(fColorStartUni).c_s
tr()); |
1057 if (!builder->glslCaps()->canUseMinAndAbsTogether()) { | 1059 if (!glslCaps->canUseMinAndAbsTogether()) { |
1058 // The Tegra3 compiler will sometimes never return if we have | 1060 // The Tegra3 compiler will sometimes never return if we have |
1059 // min(abs(oneMinus2t), 1.0), or do the abs first in a separate expr
ession. | 1061 // min(abs(oneMinus2t), 1.0), or do the abs first in a separate expr
ession. |
1060 fragBuilder->codeAppend("\tfloat minAbs = abs(oneMinus2t);\n"); | 1062 fragBuilder->codeAppend("\tfloat minAbs = abs(oneMinus2t);\n"); |
1061 fragBuilder->codeAppend("\tminAbs = minAbs > 1.0 ? 1.0 : minAbs;\n")
; | 1063 fragBuilder->codeAppend("\tminAbs = minAbs > 1.0 ? 1.0 : minAbs;\n")
; |
1062 fragBuilder->codeAppendf("\tcolorTemp += (1.0 - minAbs) * %s;\n", | 1064 fragBuilder->codeAppendf("\tcolorTemp += (1.0 - minAbs) * %s;\n", |
1063 builder->getUniformVariable(fColorMidUni).c
_str()); | 1065 builder->getUniformVariable(fColorMidUni).c
_str()); |
1064 } else { | 1066 } else { |
1065 fragBuilder->codeAppendf("\tcolorTemp += (1.0 - min(abs(oneMinus2t),
1.0)) * %s;\n", | 1067 fragBuilder->codeAppendf("\tcolorTemp += (1.0 - min(abs(oneMinus2t),
1.0)) * %s;\n", |
1066 builder->getUniformVariable(fColorMidUni).c
_str()); | 1068 builder->getUniformVariable(fColorMidUni).c
_str()); |
1067 } | 1069 } |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1207 (*stops)[i] = stop; | 1209 (*stops)[i] = stop; |
1208 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st
op) : 1.f; | 1210 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st
op) : 1.f; |
1209 } | 1211 } |
1210 } | 1212 } |
1211 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM
odeCount)); | 1213 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM
odeCount)); |
1212 | 1214 |
1213 return outColors; | 1215 return outColors; |
1214 } | 1216 } |
1215 | 1217 |
1216 #endif | 1218 #endif |
OLD | NEW |