Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/effects/gradients/SkGradientShader.cpp

Issue 1457543003: Add ShaderBuilders to EmitArgs and remove gettings from ProgBuilder. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/effects/SkTableColorFilter.cpp ('k') | src/effects/gradients/SkGradientShaderPriv.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1009 matching lines...) Expand 10 before | Expand all | Expand 10 after
1020 } 1020 }
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 const GrGradientEffect& ge, 1031 const GrGradientEffect& ge,
1031 const char* gradientTValue, 1032 const char* gradientTValue,
1032 const char* outputColor, 1033 const char* outputColor,
1033 const char* inputColor, 1034 const char* inputColor,
1034 const TextureSamplerArray& samplers) { 1035 const TextureSamplerArray& samplers) {
1035 GrGLSLFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder();
1036 if (SkGradientShaderBase::kTwo_GpuColorType == ge.getColorType()){ 1036 if (SkGradientShaderBase::kTwo_GpuColorType == ge.getColorType()){
1037 fsBuilder->codeAppendf("\tvec4 colorTemp = mix(%s, %s, clamp(%s, 0.0, 1. 0));\n", 1037 fragBuilder->codeAppendf("\tvec4 colorTemp = mix(%s, %s, clamp(%s, 0.0, 1.0));\n",
1038 builder->getUniformVariable(fColorStartUni).c_str (), 1038 builder->getUniformVariable(fColorStartUni).c_s tr(),
1039 builder->getUniformVariable(fColorEndUni).c_str() , 1039 builder->getUniformVariable(fColorEndUni).c_str (),
1040 gradientTValue); 1040 gradientTValue);
1041 // Note that we could skip this step if both colors are known to be opaq ue. Two 1041 // Note that we could skip this step if both colors are known to be opaq ue. Two
1042 // considerations: 1042 // considerations:
1043 // The gradient SkShader reporting opaque is more restrictive than neces sary in the two pt 1043 // 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 1044 // 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. 1045 // shader as thekBeforeIterp case). This same optimization applies to th e 3 color case below.
1046 if (GrGradientEffect::kAfterInterp_PremulType == ge.getPremulType()) { 1046 if (GrGradientEffect::kAfterInterp_PremulType == ge.getPremulType()) {
1047 fsBuilder->codeAppend("\tcolorTemp.rgb *= colorTemp.a;\n"); 1047 fragBuilder->codeAppend("\tcolorTemp.rgb *= colorTemp.a;\n");
1048 } 1048 }
1049 1049
1050 fsBuilder->codeAppendf("\t%s = %s;\n", outputColor, 1050 fragBuilder->codeAppendf("\t%s = %s;\n", outputColor,
1051 (GrGLSLExpr4(inputColor) * GrGLSLExpr4("colorTemp ")).c_str()); 1051 (GrGLSLExpr4(inputColor) * GrGLSLExpr4("colorTe mp")).c_str());
1052 } else if (SkGradientShaderBase::kThree_GpuColorType == ge.getColorType()) { 1052 } else if (SkGradientShaderBase::kThree_GpuColorType == ge.getColorType()) {
1053 fsBuilder->codeAppendf("\tfloat oneMinus2t = 1.0 - (2.0 * (%s));\n", 1053 fragBuilder->codeAppendf("\tfloat oneMinus2t = 1.0 - (2.0 * (%s));\n",
1054 gradientTValue); 1054 gradientTValue);
1055 fsBuilder->codeAppendf("\tvec4 colorTemp = clamp(oneMinus2t, 0.0, 1.0) * %s;\n", 1055 fragBuilder->codeAppendf("\tvec4 colorTemp = clamp(oneMinus2t, 0.0, 1.0) * %s;\n",
1056 builder->getUniformVariable(fColorStartUni).c_str ()); 1056 builder->getUniformVariable(fColorStartUni).c_s tr());
1057 if (!builder->glslCaps()->canUseMinAndAbsTogether()) { 1057 if (!builder->glslCaps()->canUseMinAndAbsTogether()) {
1058 // The Tegra3 compiler will sometimes never return if we have 1058 // 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. 1059 // min(abs(oneMinus2t), 1.0), or do the abs first in a separate expr ession.
1060 fsBuilder->codeAppend("\tfloat minAbs = abs(oneMinus2t);\n"); 1060 fragBuilder->codeAppend("\tfloat minAbs = abs(oneMinus2t);\n");
1061 fsBuilder->codeAppend("\tminAbs = minAbs > 1.0 ? 1.0 : minAbs;\n"); 1061 fragBuilder->codeAppend("\tminAbs = minAbs > 1.0 ? 1.0 : minAbs;\n") ;
1062 fsBuilder->codeAppendf("\tcolorTemp += (1.0 - minAbs) * %s;\n", 1062 fragBuilder->codeAppendf("\tcolorTemp += (1.0 - minAbs) * %s;\n",
1063 builder->getUniformVariable(fColorMidUni).c_s tr()); 1063 builder->getUniformVariable(fColorMidUni).c _str());
1064 } else { 1064 } else {
1065 fsBuilder->codeAppendf("\tcolorTemp += (1.0 - min(abs(oneMinus2t), 1 .0)) * %s;\n", 1065 fragBuilder->codeAppendf("\tcolorTemp += (1.0 - min(abs(oneMinus2t), 1.0)) * %s;\n",
1066 builder->getUniformVariable(fColorMidUni).c_s tr()); 1066 builder->getUniformVariable(fColorMidUni).c _str());
1067 } 1067 }
1068 fsBuilder->codeAppendf("\tcolorTemp += clamp(-oneMinus2t, 0.0, 1.0) * %s ;\n", 1068 fragBuilder->codeAppendf("\tcolorTemp += clamp(-oneMinus2t, 0.0, 1.0) * %s;\n",
1069 builder->getUniformVariable(fColorEndUni).c_str() ); 1069 builder->getUniformVariable(fColorEndUni).c_str ());
1070 if (GrGradientEffect::kAfterInterp_PremulType == ge.getPremulType()) { 1070 if (GrGradientEffect::kAfterInterp_PremulType == ge.getPremulType()) {
1071 fsBuilder->codeAppend("\tcolorTemp.rgb *= colorTemp.a;\n"); 1071 fragBuilder->codeAppend("\tcolorTemp.rgb *= colorTemp.a;\n");
1072 } 1072 }
1073 1073
1074 fsBuilder->codeAppendf("\t%s = %s;\n", outputColor, 1074 fragBuilder->codeAppendf("\t%s = %s;\n", outputColor,
1075 (GrGLSLExpr4(inputColor) * GrGLSLExpr4("colorTemp ")).c_str()); 1075 (GrGLSLExpr4(inputColor) * GrGLSLExpr4("colorTe mp")).c_str());
1076 } else { 1076 } else {
1077 fsBuilder->codeAppendf("\tvec2 coord = vec2(%s, %s);\n", 1077 fragBuilder->codeAppendf("\tvec2 coord = vec2(%s, %s);\n",
1078 gradientTValue, 1078 gradientTValue,
1079 builder->getUniformVariable(fFSYUni).c_str()); 1079 builder->getUniformVariable(fFSYUni).c_str());
1080 fsBuilder->codeAppendf("\t%s = ", outputColor); 1080 fragBuilder->codeAppendf("\t%s = ", outputColor);
1081 fsBuilder->appendTextureLookupAndModulate(inputColor, 1081 fragBuilder->appendTextureLookupAndModulate(inputColor,
1082 samplers[0], 1082 samplers[0],
1083 "coord"); 1083 "coord");
1084 fsBuilder->codeAppend(";\n"); 1084 fragBuilder->codeAppend(";\n");
1085 } 1085 }
1086 } 1086 }
1087 1087
1088 ///////////////////////////////////////////////////////////////////// 1088 /////////////////////////////////////////////////////////////////////
1089 1089
1090 GrGradientEffect::GrGradientEffect(GrContext* ctx, 1090 GrGradientEffect::GrGradientEffect(GrContext* ctx,
1091 const SkGradientShaderBase& shader, 1091 const SkGradientShaderBase& shader,
1092 const SkMatrix& matrix, 1092 const SkMatrix& matrix,
1093 SkShader::TileMode tileMode) { 1093 SkShader::TileMode tileMode) {
1094 1094
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1207 (*stops)[i] = stop; 1207 (*stops)[i] = stop;
1208 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st op) : 1.f; 1208 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st op) : 1.f;
1209 } 1209 }
1210 } 1210 }
1211 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM odeCount)); 1211 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM odeCount));
1212 1212
1213 return outColors; 1213 return outColors;
1214 } 1214 }
1215 1215
1216 #endif 1216 #endif
OLDNEW
« no previous file with comments | « src/effects/SkTableColorFilter.cpp ('k') | src/effects/gradients/SkGradientShaderPriv.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698