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 932 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 SkString output; | 953 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, |
954 builder->fsCodeAppendf("\t%s = ", outputColor); | 954 (GrGLSLExpr<4>(inputColor) * GrGLSLExpr<4>("color
Temp")).c_str()); |
955 GrGLSLModulatef<4>(&output, inputColor, "colorTemp"); | |
956 builder->fsCodeAppend(output.c_str()); | |
957 builder->fsCodeAppend(";\n"); | |
958 } else if (GrGradientEffect::kThree_ColorType == ColorTypeFromKey(key)){ | 955 } else if (GrGradientEffect::kThree_ColorType == ColorTypeFromKey(key)){ |
959 builder->fsCodeAppendf("\tfloat oneMinus2t = 1.0 - (2.0 * (%s));\n", | 956 builder->fsCodeAppendf("\tfloat oneMinus2t = 1.0 - (2.0 * (%s));\n", |
960 gradientTValue); | 957 gradientTValue); |
961 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", |
962 builder->getUniformVariable(fColorStartUni).c_str
()); | 959 builder->getUniformVariable(fColorStartUni).c_str
()); |
963 if (kTegra3_GrGLRenderer == builder->ctxInfo().renderer()) { | 960 if (kTegra3_GrGLRenderer == builder->ctxInfo().renderer()) { |
964 // The Tegra3 compiler will sometimes never return if we have | 961 // The Tegra3 compiler will sometimes never return if we have |
965 // 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. |
966 builder->fsCodeAppend("\tfloat minAbs = abs(oneMinus2t);\n"); | 963 builder->fsCodeAppend("\tfloat minAbs = abs(oneMinus2t);\n"); |
967 builder->fsCodeAppend("\tminAbs = minAbs > 1.0 ? 1.0 : minAbs;\n"); | 964 builder->fsCodeAppend("\tminAbs = minAbs > 1.0 ? 1.0 : minAbs;\n"); |
968 builder->fsCodeAppendf("\tcolorTemp += (1.0 - minAbs) * %s;\n", | 965 builder->fsCodeAppendf("\tcolorTemp += (1.0 - minAbs) * %s;\n", |
969 builder->getUniformVariable(fColorMidUni).c_s
tr()); | 966 builder->getUniformVariable(fColorMidUni).c_s
tr()); |
970 } else { | 967 } else { |
971 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", |
972 builder->getUniformVariable(fColorMidUni).c_s
tr()); | 969 builder->getUniformVariable(fColorMidUni).c_s
tr()); |
973 } | 970 } |
974 builder->fsCodeAppendf("\tcolorTemp += clamp(-oneMinus2t, 0.0, 1.0) * %s
;\n", | 971 builder->fsCodeAppendf("\tcolorTemp += clamp(-oneMinus2t, 0.0, 1.0) * %s
;\n", |
975 builder->getUniformVariable(fColorEndUni).c_str()
); | 972 builder->getUniformVariable(fColorEndUni).c_str()
); |
976 if (GrGradientEffect::kAfterInterp_PremulType == PremulTypeFromKey(key))
{ | 973 if (GrGradientEffect::kAfterInterp_PremulType == PremulTypeFromKey(key))
{ |
977 builder->fsCodeAppend("\tcolorTemp.rgb *= colorTemp.a;\n"); | 974 builder->fsCodeAppend("\tcolorTemp.rgb *= colorTemp.a;\n"); |
978 } | 975 } |
979 | 976 |
980 SkString output; | 977 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, |
981 builder->fsCodeAppendf("\t%s = ", outputColor); | 978 (GrGLSLExpr<4>(inputColor) * GrGLSLExpr<4>("color
Temp")).c_str()); |
982 GrGLSLModulatef<4>(&output, inputColor, "colorTemp"); | |
983 builder->fsCodeAppend(output.c_str()); | |
984 builder->fsCodeAppend(";\n"); | |
985 } else { | 979 } else { |
986 builder->fsCodeAppendf("\tvec2 coord = vec2(%s, %s);\n", | 980 builder->fsCodeAppendf("\tvec2 coord = vec2(%s, %s);\n", |
987 gradientTValue, | 981 gradientTValue, |
988 builder->getUniformVariable(fFSYUni).c_str()); | 982 builder->getUniformVariable(fFSYUni).c_str()); |
989 builder->fsCodeAppendf("\t%s = ", outputColor); | 983 builder->fsCodeAppendf("\t%s = ", outputColor); |
990 builder->fsAppendTextureLookupAndModulate(inputColor, | 984 builder->fsAppendTextureLookupAndModulate(inputColor, |
991 samplers[0], | 985 samplers[0], |
992 "coord"); | 986 "coord"); |
993 builder->fsCodeAppend(";\n"); | 987 builder->fsCodeAppend(";\n"); |
994 } | 988 } |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1139 (*stops)[i] = stop; | 1133 (*stops)[i] = stop; |
1140 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; |
1141 } | 1135 } |
1142 } | 1136 } |
1143 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM
odeCount)); | 1137 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM
odeCount)); |
1144 | 1138 |
1145 return outColors; | 1139 return outColors; |
1146 } | 1140 } |
1147 | 1141 |
1148 #endif | 1142 #endif |
OLD | NEW |