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 916 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
927 key |= kPremulBeforeInterpKey; | 927 key |= kPremulBeforeInterpKey; |
928 } | 928 } |
929 | 929 |
930 return key; | 930 return key; |
931 } | 931 } |
932 | 932 |
933 void GrGLGradientEffect::emitColor(GrGLShaderBuilder* builder, | 933 void GrGLGradientEffect::emitColor(GrGLShaderBuilder* builder, |
934 const char* gradientTValue, | 934 const char* gradientTValue, |
935 EffectKey key, | 935 EffectKey key, |
936 const char* outputColor, | 936 const char* outputColor, |
937 const char* inputColor, | 937 const GrGLSLExpr4& inputColor, |
938 const TextureSamplerArray& samplers) { | 938 const TextureSamplerArray& samplers) { |
939 if (GrGradientEffect::kTwo_ColorType == ColorTypeFromKey(key)){ | 939 if (GrGradientEffect::kTwo_ColorType == ColorTypeFromKey(key)){ |
940 builder->fsCodeAppendf("\tvec4 colorTemp = mix(%s, %s, clamp(%s, 0.0, 1.
0));\n", | 940 builder->fsCodeAppendf("\tvec4 colorTemp = mix(%s, %s, clamp(%s, 0.0, 1.
0));\n", |
941 builder->getUniformVariable(fColorStartUni).c_str
(), | 941 builder->getUniformVariable(fColorStartUni).c_str
(), |
942 builder->getUniformVariable(fColorEndUni).c_str()
, | 942 builder->getUniformVariable(fColorEndUni).c_str()
, |
943 gradientTValue); | 943 gradientTValue); |
944 // Note that we could skip this step if both colors are known to be opaq
ue. Two | 944 // Note that we could skip this step if both colors are known to be opaq
ue. Two |
945 // considerations: | 945 // considerations: |
946 // The gradient SkShader reporting opaque is more restrictive than neces
sary in the two pt | 946 // The gradient SkShader reporting opaque is more restrictive than neces
sary in the two pt |
947 // case. Make sure the key reflects this optimization (and note that it
can use the same | 947 // case. Make sure the key reflects this optimization (and note that it
can use the same |
948 // shader as thekBeforeIterp case). This same optimization applies to th
e 3 color case below. | 948 // shader as thekBeforeIterp case). This same optimization applies to th
e 3 color case below. |
949 if (GrGradientEffect::kAfterInterp_PremulType == PremulTypeFromKey(key))
{ | 949 if (GrGradientEffect::kAfterInterp_PremulType == PremulTypeFromKey(key))
{ |
950 builder->fsCodeAppend("\tcolorTemp.rgb *= colorTemp.a;\n"); | 950 builder->fsCodeAppend("\tcolorTemp.rgb *= colorTemp.a;\n"); |
951 } | 951 } |
952 | 952 |
953 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, | 953 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, |
954 (GrGLSLExpr4(inputColor) * GrGLSLExpr4("colorTemp
")).c_str()); | 954 (inputColor * GrGLSLExpr4("colorTemp")).c_str()); |
955 } else if (GrGradientEffect::kThree_ColorType == ColorTypeFromKey(key)){ | 955 } else if (GrGradientEffect::kThree_ColorType == ColorTypeFromKey(key)){ |
956 builder->fsCodeAppendf("\tfloat oneMinus2t = 1.0 - (2.0 * (%s));\n", | 956 builder->fsCodeAppendf("\tfloat oneMinus2t = 1.0 - (2.0 * (%s));\n", |
957 gradientTValue); | 957 gradientTValue); |
958 builder->fsCodeAppendf("\tvec4 colorTemp = clamp(oneMinus2t, 0.0, 1.0) *
%s;\n", | 958 builder->fsCodeAppendf("\tvec4 colorTemp = clamp(oneMinus2t, 0.0, 1.0) *
%s;\n", |
959 builder->getUniformVariable(fColorStartUni).c_str
()); | 959 builder->getUniformVariable(fColorStartUni).c_str
()); |
960 if (kTegra3_GrGLRenderer == builder->ctxInfo().renderer()) { | 960 if (kTegra3_GrGLRenderer == builder->ctxInfo().renderer()) { |
961 // The Tegra3 compiler will sometimes never return if we have | 961 // The Tegra3 compiler will sometimes never return if we have |
962 // min(abs(oneMinus2t), 1.0), or do the abs first in a separate expr
ession. | 962 // min(abs(oneMinus2t), 1.0), or do the abs first in a separate expr
ession. |
963 builder->fsCodeAppend("\tfloat minAbs = abs(oneMinus2t);\n"); | 963 builder->fsCodeAppend("\tfloat minAbs = abs(oneMinus2t);\n"); |
964 builder->fsCodeAppend("\tminAbs = minAbs > 1.0 ? 1.0 : minAbs;\n"); | 964 builder->fsCodeAppend("\tminAbs = minAbs > 1.0 ? 1.0 : minAbs;\n"); |
965 builder->fsCodeAppendf("\tcolorTemp += (1.0 - minAbs) * %s;\n", | 965 builder->fsCodeAppendf("\tcolorTemp += (1.0 - minAbs) * %s;\n", |
966 builder->getUniformVariable(fColorMidUni).c_s
tr()); | 966 builder->getUniformVariable(fColorMidUni).c_s
tr()); |
967 } else { | 967 } else { |
968 builder->fsCodeAppendf("\tcolorTemp += (1.0 - min(abs(oneMinus2t), 1
.0)) * %s;\n", | 968 builder->fsCodeAppendf("\tcolorTemp += (1.0 - min(abs(oneMinus2t), 1
.0)) * %s;\n", |
969 builder->getUniformVariable(fColorMidUni).c_s
tr()); | 969 builder->getUniformVariable(fColorMidUni).c_s
tr()); |
970 } | 970 } |
971 builder->fsCodeAppendf("\tcolorTemp += clamp(-oneMinus2t, 0.0, 1.0) * %s
;\n", | 971 builder->fsCodeAppendf("\tcolorTemp += clamp(-oneMinus2t, 0.0, 1.0) * %s
;\n", |
972 builder->getUniformVariable(fColorEndUni).c_str()
); | 972 builder->getUniformVariable(fColorEndUni).c_str()
); |
973 if (GrGradientEffect::kAfterInterp_PremulType == PremulTypeFromKey(key))
{ | 973 if (GrGradientEffect::kAfterInterp_PremulType == PremulTypeFromKey(key))
{ |
974 builder->fsCodeAppend("\tcolorTemp.rgb *= colorTemp.a;\n"); | 974 builder->fsCodeAppend("\tcolorTemp.rgb *= colorTemp.a;\n"); |
975 } | 975 } |
976 | 976 |
977 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, | 977 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, |
978 (GrGLSLExpr4(inputColor) * GrGLSLExpr4("colorTemp
")).c_str()); | 978 (inputColor * GrGLSLExpr4("colorTemp")).c_str()); |
979 } else { | 979 } else { |
980 builder->fsCodeAppendf("\tvec2 coord = vec2(%s, %s);\n", | 980 builder->fsCodeAppendf("\tvec2 coord = vec2(%s, %s);\n", |
981 gradientTValue, | 981 gradientTValue, |
982 builder->getUniformVariable(fFSYUni).c_str()); | 982 builder->getUniformVariable(fFSYUni).c_str()); |
983 builder->fsCodeAppendf("\t%s = ", outputColor); | 983 builder->fsCodeAppendf("\t%s = ", outputColor); |
984 builder->fsAppendTextureLookupAndModulate(inputColor, | 984 builder->fsAppendTextureLookupAndModulate(inputColor, |
985 samplers[0], | 985 samplers[0], |
986 "coord"); | 986 "coord"); |
987 builder->fsCodeAppend(";\n"); | 987 builder->fsCodeAppend(";\n"); |
988 } | 988 } |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1133 (*stops)[i] = stop; | 1133 (*stops)[i] = stop; |
1134 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st
op) : 1.f; | 1134 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st
op) : 1.f; |
1135 } | 1135 } |
1136 } | 1136 } |
1137 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM
odeCount)); | 1137 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM
odeCount)); |
1138 | 1138 |
1139 return outColors; | 1139 return outColors; |
1140 } | 1140 } |
1141 | 1141 |
1142 #endif | 1142 #endif |
OLD | NEW |