| 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 954 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 965 gradientTValue); | 965 gradientTValue); |
| 966 // Note that we could skip this step if both colors are known to be opaq
ue. Two | 966 // Note that we could skip this step if both colors are known to be opaq
ue. Two |
| 967 // considerations: | 967 // considerations: |
| 968 // The gradient SkShader reporting opaque is more restrictive than neces
sary in the two pt | 968 // The gradient SkShader reporting opaque is more restrictive than neces
sary in the two pt |
| 969 // case. Make sure the key reflects this optimization (and note that it
can use the same | 969 // case. Make sure the key reflects this optimization (and note that it
can use the same |
| 970 // shader as thekBeforeIterp case). This same optimization applies to th
e 3 color case below. | 970 // shader as thekBeforeIterp case). This same optimization applies to th
e 3 color case below. |
| 971 if (GrGradientEffect::kAfterInterp_PremulType == PremulTypeFromKey(key))
{ | 971 if (GrGradientEffect::kAfterInterp_PremulType == PremulTypeFromKey(key))
{ |
| 972 builder->fsCodeAppend("\tcolorTemp.rgb *= colorTemp.a;\n"); | 972 builder->fsCodeAppend("\tcolorTemp.rgb *= colorTemp.a;\n"); |
| 973 } | 973 } |
| 974 | 974 |
| 975 SkString output; | 975 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, |
| 976 builder->fsCodeAppendf("\t%s = ", outputColor); | 976 (GrGLSLExpr<4>(inputColor) * GrGLSLExpr<4>("color
Temp")).c_str()); |
| 977 GrGLSLModulatef<4>(&output, inputColor, "colorTemp"); | |
| 978 builder->fsCodeAppend(output.c_str()); | |
| 979 builder->fsCodeAppend(";\n"); | |
| 980 } else if (GrGradientEffect::kThree_ColorType == ColorTypeFromKey(key)){ | 977 } else if (GrGradientEffect::kThree_ColorType == ColorTypeFromKey(key)){ |
| 981 builder->fsCodeAppendf("\tfloat oneMinus2t = 1.0 - (2.0 * (%s));\n", | 978 builder->fsCodeAppendf("\tfloat oneMinus2t = 1.0 - (2.0 * (%s));\n", |
| 982 gradientTValue); | 979 gradientTValue); |
| 983 builder->fsCodeAppendf("\tvec4 colorTemp = clamp(oneMinus2t, 0.0, 1.0) *
%s;\n", | 980 builder->fsCodeAppendf("\tvec4 colorTemp = clamp(oneMinus2t, 0.0, 1.0) *
%s;\n", |
| 984 builder->getUniformVariable(fColorStartUni).c_str
()); | 981 builder->getUniformVariable(fColorStartUni).c_str
()); |
| 985 if (kTegra3_GrGLRenderer == builder->ctxInfo().renderer()) { | 982 if (kTegra3_GrGLRenderer == builder->ctxInfo().renderer()) { |
| 986 // The Tegra3 compiler will sometimes never return if we have | 983 // The Tegra3 compiler will sometimes never return if we have |
| 987 // min(abs(oneMinus2t), 1.0), or do the abs first in a separate expr
ession. | 984 // min(abs(oneMinus2t), 1.0), or do the abs first in a separate expr
ession. |
| 988 builder->fsCodeAppend("\tfloat minAbs = abs(oneMinus2t);\n"); | 985 builder->fsCodeAppend("\tfloat minAbs = abs(oneMinus2t);\n"); |
| 989 builder->fsCodeAppend("\tminAbs = minAbs > 1.0 ? 1.0 : minAbs;\n"); | 986 builder->fsCodeAppend("\tminAbs = minAbs > 1.0 ? 1.0 : minAbs;\n"); |
| 990 builder->fsCodeAppendf("\tcolorTemp += (1.0 - minAbs) * %s;\n", | 987 builder->fsCodeAppendf("\tcolorTemp += (1.0 - minAbs) * %s;\n", |
| 991 builder->getUniformVariable(fColorMidUni).c_s
tr()); | 988 builder->getUniformVariable(fColorMidUni).c_s
tr()); |
| 992 } else { | 989 } else { |
| 993 builder->fsCodeAppendf("\tcolorTemp += (1.0 - min(abs(oneMinus2t), 1
.0)) * %s;\n", | 990 builder->fsCodeAppendf("\tcolorTemp += (1.0 - min(abs(oneMinus2t), 1
.0)) * %s;\n", |
| 994 builder->getUniformVariable(fColorMidUni).c_s
tr()); | 991 builder->getUniformVariable(fColorMidUni).c_s
tr()); |
| 995 } | 992 } |
| 996 builder->fsCodeAppendf("\tcolorTemp += clamp(-oneMinus2t, 0.0, 1.0) * %s
;\n", | 993 builder->fsCodeAppendf("\tcolorTemp += clamp(-oneMinus2t, 0.0, 1.0) * %s
;\n", |
| 997 builder->getUniformVariable(fColorEndUni).c_str()
); | 994 builder->getUniformVariable(fColorEndUni).c_str()
); |
| 998 if (GrGradientEffect::kAfterInterp_PremulType == PremulTypeFromKey(key))
{ | 995 if (GrGradientEffect::kAfterInterp_PremulType == PremulTypeFromKey(key))
{ |
| 999 builder->fsCodeAppend("\tcolorTemp.rgb *= colorTemp.a;\n"); | 996 builder->fsCodeAppend("\tcolorTemp.rgb *= colorTemp.a;\n"); |
| 1000 } | 997 } |
| 1001 | 998 |
| 1002 SkString output; | 999 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, |
| 1003 builder->fsCodeAppendf("\t%s = ", outputColor); | 1000 (GrGLSLExpr<4>(inputColor) * GrGLSLExpr<4>("color
Temp")).c_str()); |
| 1004 GrGLSLModulatef<4>(&output, inputColor, "colorTemp"); | |
| 1005 builder->fsCodeAppend(output.c_str()); | |
| 1006 builder->fsCodeAppend(";\n"); | |
| 1007 } else { | 1001 } else { |
| 1008 builder->fsCodeAppendf("\tvec2 coord = vec2(%s, %s);\n", | 1002 builder->fsCodeAppendf("\tvec2 coord = vec2(%s, %s);\n", |
| 1009 gradientTValue, | 1003 gradientTValue, |
| 1010 builder->getUniformVariable(fFSYUni).c_str()); | 1004 builder->getUniformVariable(fFSYUni).c_str()); |
| 1011 builder->fsCodeAppendf("\t%s = ", outputColor); | 1005 builder->fsCodeAppendf("\t%s = ", outputColor); |
| 1012 builder->fsAppendTextureLookupAndModulate(inputColor, | 1006 builder->fsAppendTextureLookupAndModulate(inputColor, |
| 1013 samplers[0], | 1007 samplers[0], |
| 1014 "coord"); | 1008 "coord"); |
| 1015 builder->fsCodeAppend(";\n"); | 1009 builder->fsCodeAppend(";\n"); |
| 1016 } | 1010 } |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1156 (*stops)[i] = stop; | 1150 (*stops)[i] = stop; |
| 1157 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st
op) : 1.f; | 1151 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st
op) : 1.f; |
| 1158 } | 1152 } |
| 1159 } | 1153 } |
| 1160 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM
odeCount)); | 1154 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM
odeCount)); |
| 1161 | 1155 |
| 1162 return outColors; | 1156 return outColors; |
| 1163 } | 1157 } |
| 1164 | 1158 |
| 1165 #endif | 1159 #endif |
| OLD | NEW |