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

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

Issue 25023003: Implement color filter as GrGLEffect (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: address review comments Created 7 years, 2 months 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 | Annotate | Revision Log
« no previous file with comments | « src/effects/SkPerlinNoiseShader.cpp ('k') | src/gpu/GrAAConvexPathRenderer.cpp » ('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 933 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 (GrGLSLExpr<4>(inputColor) * GrGLSLExpr<4>("color Temp")).c_str()); 954 (GrGLSLExpr4(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 (GrGLSLExpr<4>(inputColor) * GrGLSLExpr<4>("color Temp")).c_str()); 978 (GrGLSLExpr4(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
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
OLDNEW
« no previous file with comments | « src/effects/SkPerlinNoiseShader.cpp ('k') | src/gpu/GrAAConvexPathRenderer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698