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

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

Issue 385713005: Allow GrGLEffects to produce variable length keys. (Closed) Base URL: https://skia.googlesource.com/skia.git@key
Patch Set: rebase Created 6 years, 5 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
« 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 844 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 #include "gl/GrGLShaderBuilder.h" 855 #include "gl/GrGLShaderBuilder.h"
856 #include "SkGr.h" 856 #include "SkGr.h"
857 857
858 GrGLGradientEffect::GrGLGradientEffect(const GrBackendEffectFactory& factory) 858 GrGLGradientEffect::GrGLGradientEffect(const GrBackendEffectFactory& factory)
859 : INHERITED(factory) 859 : INHERITED(factory)
860 , fCachedYCoord(SK_ScalarMax) { 860 , fCachedYCoord(SK_ScalarMax) {
861 } 861 }
862 862
863 GrGLGradientEffect::~GrGLGradientEffect() { } 863 GrGLGradientEffect::~GrGLGradientEffect() { }
864 864
865 void GrGLGradientEffect::emitUniforms(GrGLShaderBuilder* builder, EffectKey key) { 865 void GrGLGradientEffect::emitUniforms(GrGLShaderBuilder* builder, uint32_t baseK ey) {
866 866
867 if (SkGradientShaderBase::kTwo_GpuColorType == ColorTypeFromKey(key)) { // 2 Color case 867 if (SkGradientShaderBase::kTwo_GpuColorType == ColorTypeFromKey(baseKey)) { // 2 Color case
868 fColorStartUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibi lity, 868 fColorStartUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibi lity,
869 kVec4f_GrSLType, "GradientStartColo r"); 869 kVec4f_GrSLType, "GradientStartColo r");
870 fColorEndUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibili ty, 870 fColorEndUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibili ty,
871 kVec4f_GrSLType, "GradientEndColor"); 871 kVec4f_GrSLType, "GradientEndColor");
872 872
873 } else if (SkGradientShaderBase::kThree_GpuColorType == ColorTypeFromKey(key )){ // 3 Color Case 873 } else if (SkGradientShaderBase::kThree_GpuColorType == ColorTypeFromKey(bas eKey)){ // 3 Color Case
874 fColorStartUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibi lity, 874 fColorStartUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibi lity,
875 kVec4f_GrSLType, "GradientStartColo r"); 875 kVec4f_GrSLType, "GradientStartColo r");
876 fColorMidUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibili ty, 876 fColorMidUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibili ty,
877 kVec4f_GrSLType, "GradientMidColor"); 877 kVec4f_GrSLType, "GradientMidColor");
878 fColorEndUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibili ty, 878 fColorEndUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibili ty,
879 kVec4f_GrSLType, "GradientEndColor" ); 879 kVec4f_GrSLType, "GradientEndColor" );
880 880
881 } else { // if not a fast case 881 } else { // if not a fast case
882 fFSYUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, 882 fFSYUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
883 kFloat_GrSLType, "GradientYCoordFS"); 883 kFloat_GrSLType, "GradientYCoordFS");
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
937 937
938 SkScalar yCoord = e.getYCoord(); 938 SkScalar yCoord = e.getYCoord();
939 if (yCoord != fCachedYCoord) { 939 if (yCoord != fCachedYCoord) {
940 uman.set1f(fFSYUni, yCoord); 940 uman.set1f(fFSYUni, yCoord);
941 fCachedYCoord = yCoord; 941 fCachedYCoord = yCoord;
942 } 942 }
943 } 943 }
944 } 944 }
945 945
946 946
947 GrGLEffect::EffectKey GrGLGradientEffect::GenBaseGradientKey(const GrDrawEffect& drawEffect) { 947 uint32_t GrGLGradientEffect::GenBaseGradientKey(const GrDrawEffect& drawEffect) {
948 const GrGradientEffect& e = drawEffect.castEffect<GrGradientEffect>(); 948 const GrGradientEffect& e = drawEffect.castEffect<GrGradientEffect>();
949 949
950 EffectKey key = 0; 950 uint32_t key = 0;
951 951
952 if (SkGradientShaderBase::kTwo_GpuColorType == e.getColorType()) { 952 if (SkGradientShaderBase::kTwo_GpuColorType == e.getColorType()) {
953 key |= kTwoColorKey; 953 key |= kTwoColorKey;
954 } else if (SkGradientShaderBase::kThree_GpuColorType == e.getColorType()){ 954 } else if (SkGradientShaderBase::kThree_GpuColorType == e.getColorType()){
955 key |= kThreeColorKey; 955 key |= kThreeColorKey;
956 } 956 }
957 957
958 if (GrGradientEffect::kBeforeInterp_PremulType == e.getPremulType()) { 958 if (GrGradientEffect::kBeforeInterp_PremulType == e.getPremulType()) {
959 key |= kPremulBeforeInterpKey; 959 key |= kPremulBeforeInterpKey;
960 } 960 }
961 961
962 return key; 962 return key;
963 } 963 }
964 964
965 void GrGLGradientEffect::emitColor(GrGLShaderBuilder* builder, 965 void GrGLGradientEffect::emitColor(GrGLShaderBuilder* builder,
966 const char* gradientTValue, 966 const char* gradientTValue,
967 EffectKey key, 967 uint32_t baseKey,
968 const char* outputColor, 968 const char* outputColor,
969 const char* inputColor, 969 const char* inputColor,
970 const TextureSamplerArray& samplers) { 970 const TextureSamplerArray& samplers) {
971 if (SkGradientShaderBase::kTwo_GpuColorType == ColorTypeFromKey(key)){ 971 if (SkGradientShaderBase::kTwo_GpuColorType == ColorTypeFromKey(baseKey)){
972 builder->fsCodeAppendf("\tvec4 colorTemp = mix(%s, %s, clamp(%s, 0.0, 1. 0));\n", 972 builder->fsCodeAppendf("\tvec4 colorTemp = mix(%s, %s, clamp(%s, 0.0, 1. 0));\n",
973 builder->getUniformVariable(fColorStartUni).c_str (), 973 builder->getUniformVariable(fColorStartUni).c_str (),
974 builder->getUniformVariable(fColorEndUni).c_str() , 974 builder->getUniformVariable(fColorEndUni).c_str() ,
975 gradientTValue); 975 gradientTValue);
976 // Note that we could skip this step if both colors are known to be opaq ue. Two 976 // Note that we could skip this step if both colors are known to be opaq ue. Two
977 // considerations: 977 // considerations:
978 // The gradient SkShader reporting opaque is more restrictive than neces sary in the two pt 978 // The gradient SkShader reporting opaque is more restrictive than neces sary in the two pt
979 // case. Make sure the key reflects this optimization (and note that it can use the same 979 // case. Make sure the key reflects this optimization (and note that it can use the same
980 // shader as thekBeforeIterp case). This same optimization applies to th e 3 color case below. 980 // shader as thekBeforeIterp case). This same optimization applies to th e 3 color case below.
981 if (GrGradientEffect::kAfterInterp_PremulType == PremulTypeFromKey(key)) { 981 if (GrGradientEffect::kAfterInterp_PremulType == PremulTypeFromKey(baseK ey)) {
982 builder->fsCodeAppend("\tcolorTemp.rgb *= colorTemp.a;\n"); 982 builder->fsCodeAppend("\tcolorTemp.rgb *= colorTemp.a;\n");
983 } 983 }
984 984
985 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, 985 builder->fsCodeAppendf("\t%s = %s;\n", outputColor,
986 (GrGLSLExpr4(inputColor) * GrGLSLExpr4("colorTemp ")).c_str()); 986 (GrGLSLExpr4(inputColor) * GrGLSLExpr4("colorTemp ")).c_str());
987 } else if (SkGradientShaderBase::kThree_GpuColorType == ColorTypeFromKey(key )){ 987 } else if (SkGradientShaderBase::kThree_GpuColorType == ColorTypeFromKey(bas eKey)){
988 builder->fsCodeAppendf("\tfloat oneMinus2t = 1.0 - (2.0 * (%s));\n", 988 builder->fsCodeAppendf("\tfloat oneMinus2t = 1.0 - (2.0 * (%s));\n",
989 gradientTValue); 989 gradientTValue);
990 builder->fsCodeAppendf("\tvec4 colorTemp = clamp(oneMinus2t, 0.0, 1.0) * %s;\n", 990 builder->fsCodeAppendf("\tvec4 colorTemp = clamp(oneMinus2t, 0.0, 1.0) * %s;\n",
991 builder->getUniformVariable(fColorStartUni).c_str ()); 991 builder->getUniformVariable(fColorStartUni).c_str ());
992 if (kTegra3_GrGLRenderer == builder->ctxInfo().renderer()) { 992 if (kTegra3_GrGLRenderer == builder->ctxInfo().renderer()) {
993 // The Tegra3 compiler will sometimes never return if we have 993 // The Tegra3 compiler will sometimes never return if we have
994 // min(abs(oneMinus2t), 1.0), or do the abs first in a separate expr ession. 994 // min(abs(oneMinus2t), 1.0), or do the abs first in a separate expr ession.
995 builder->fsCodeAppend("\tfloat minAbs = abs(oneMinus2t);\n"); 995 builder->fsCodeAppend("\tfloat minAbs = abs(oneMinus2t);\n");
996 builder->fsCodeAppend("\tminAbs = minAbs > 1.0 ? 1.0 : minAbs;\n"); 996 builder->fsCodeAppend("\tminAbs = minAbs > 1.0 ? 1.0 : minAbs;\n");
997 builder->fsCodeAppendf("\tcolorTemp += (1.0 - minAbs) * %s;\n", 997 builder->fsCodeAppendf("\tcolorTemp += (1.0 - minAbs) * %s;\n",
998 builder->getUniformVariable(fColorMidUni).c_s tr()); 998 builder->getUniformVariable(fColorMidUni).c_s tr());
999 } else { 999 } else {
1000 builder->fsCodeAppendf("\tcolorTemp += (1.0 - min(abs(oneMinus2t), 1 .0)) * %s;\n", 1000 builder->fsCodeAppendf("\tcolorTemp += (1.0 - min(abs(oneMinus2t), 1 .0)) * %s;\n",
1001 builder->getUniformVariable(fColorMidUni).c_s tr()); 1001 builder->getUniformVariable(fColorMidUni).c_s tr());
1002 } 1002 }
1003 builder->fsCodeAppendf("\tcolorTemp += clamp(-oneMinus2t, 0.0, 1.0) * %s ;\n", 1003 builder->fsCodeAppendf("\tcolorTemp += clamp(-oneMinus2t, 0.0, 1.0) * %s ;\n",
1004 builder->getUniformVariable(fColorEndUni).c_str() ); 1004 builder->getUniformVariable(fColorEndUni).c_str() );
1005 if (GrGradientEffect::kAfterInterp_PremulType == PremulTypeFromKey(key)) { 1005 if (GrGradientEffect::kAfterInterp_PremulType == PremulTypeFromKey(baseK ey)) {
1006 builder->fsCodeAppend("\tcolorTemp.rgb *= colorTemp.a;\n"); 1006 builder->fsCodeAppend("\tcolorTemp.rgb *= colorTemp.a;\n");
1007 } 1007 }
1008 1008
1009 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, 1009 builder->fsCodeAppendf("\t%s = %s;\n", outputColor,
1010 (GrGLSLExpr4(inputColor) * GrGLSLExpr4("colorTemp ")).c_str()); 1010 (GrGLSLExpr4(inputColor) * GrGLSLExpr4("colorTemp ")).c_str());
1011 } else { 1011 } else {
1012 builder->fsCodeAppendf("\tvec2 coord = vec2(%s, %s);\n", 1012 builder->fsCodeAppendf("\tvec2 coord = vec2(%s, %s);\n",
1013 gradientTValue, 1013 gradientTValue,
1014 builder->getUniformVariable(fFSYUni).c_str()); 1014 builder->getUniformVariable(fFSYUni).c_str());
1015 builder->fsCodeAppendf("\t%s = ", outputColor); 1015 builder->fsCodeAppendf("\t%s = ", outputColor);
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1148 (*stops)[i] = stop; 1148 (*stops)[i] = stop;
1149 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st op) : 1.f; 1149 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st op) : 1.f;
1150 } 1150 }
1151 } 1151 }
1152 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM odeCount)); 1152 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM odeCount));
1153 1153
1154 return outColors; 1154 return outColors;
1155 } 1155 }
1156 1156
1157 #endif 1157 #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