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 below. |
joshualitt
2015/11/18 17:42:50
/n
| |
1046 if (GrGradientEffect::kAfterInterp_PremulType == ge.getPremulType()) { | 1047 if (GrGradientEffect::kAfterInterp_PremulType == ge.getPremulType()) { |
1047 fragBuilder->codeAppend("\tcolorTemp.rgb *= colorTemp.a;\n"); | 1048 fragBuilder->codeAppend("\tcolorTemp.rgb *= colorTemp.a;\n"); |
1048 } | 1049 } |
1049 | 1050 |
1050 fragBuilder->codeAppendf("\t%s = %s;\n", outputColor, | 1051 fragBuilder->codeAppendf("\t%s = %s;\n", outputColor, |
1051 (GrGLSLExpr4(inputColor) * GrGLSLExpr4("colorTe mp")).c_str()); | 1052 (GrGLSLExpr4(inputColor) * GrGLSLExpr4("colorTe mp")).c_str()); |
1052 } else if (SkGradientShaderBase::kThree_GpuColorType == ge.getColorType()) { | 1053 } else if (SkGradientShaderBase::kThree_GpuColorType == ge.getColorType()) { |
1053 fragBuilder->codeAppendf("\tfloat oneMinus2t = 1.0 - (2.0 * (%s));\n", | 1054 fragBuilder->codeAppendf("\tfloat oneMinus2t = 1.0 - (2.0 * (%s));\n", |
1054 gradientTValue); | 1055 gradientTValue); |
1055 fragBuilder->codeAppendf("\tvec4 colorTemp = clamp(oneMinus2t, 0.0, 1.0) * %s;\n", | 1056 fragBuilder->codeAppendf("\tvec4 colorTemp = clamp(oneMinus2t, 0.0, 1.0) * %s;\n", |
1056 builder->getUniformVariable(fColorStartUni).c_s tr()); | 1057 builder->getUniformVariable(fColorStartUni).c_s tr()); |
1057 if (!builder->glslCaps()->canUseMinAndAbsTogether()) { | 1058 if (!glslCaps->canUseMinAndAbsTogether()) { |
1058 // The Tegra3 compiler will sometimes never return if we have | 1059 // 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. | 1060 // min(abs(oneMinus2t), 1.0), or do the abs first in a separate expr ession. |
1060 fragBuilder->codeAppend("\tfloat minAbs = abs(oneMinus2t);\n"); | 1061 fragBuilder->codeAppend("\tfloat minAbs = abs(oneMinus2t);\n"); |
1061 fragBuilder->codeAppend("\tminAbs = minAbs > 1.0 ? 1.0 : minAbs;\n") ; | 1062 fragBuilder->codeAppend("\tminAbs = minAbs > 1.0 ? 1.0 : minAbs;\n") ; |
1062 fragBuilder->codeAppendf("\tcolorTemp += (1.0 - minAbs) * %s;\n", | 1063 fragBuilder->codeAppendf("\tcolorTemp += (1.0 - minAbs) * %s;\n", |
1063 builder->getUniformVariable(fColorMidUni).c _str()); | 1064 builder->getUniformVariable(fColorMidUni).c _str()); |
1064 } else { | 1065 } else { |
1065 fragBuilder->codeAppendf("\tcolorTemp += (1.0 - min(abs(oneMinus2t), 1.0)) * %s;\n", | 1066 fragBuilder->codeAppendf("\tcolorTemp += (1.0 - min(abs(oneMinus2t), 1.0)) * %s;\n", |
1066 builder->getUniformVariable(fColorMidUni).c _str()); | 1067 builder->getUniformVariable(fColorMidUni).c _str()); |
1067 } | 1068 } |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1207 (*stops)[i] = stop; | 1208 (*stops)[i] = stop; |
1208 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st op) : 1.f; | 1209 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st op) : 1.f; |
1209 } | 1210 } |
1210 } | 1211 } |
1211 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM odeCount)); | 1212 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM odeCount)); |
1212 | 1213 |
1213 return outColors; | 1214 return outColors; |
1214 } | 1215 } |
1215 | 1216 |
1216 #endif | 1217 #endif |
OLD | NEW |