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

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

Issue 1416423003: Make GrGLSLProgramBuilder base class for ProgramBuilder (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: nit 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 901 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 #include "gl/builders/GrGLProgramBuilder.h" 912 #include "gl/builders/GrGLProgramBuilder.h"
913 #include "glsl/GrGLSLProgramDataManager.h" 913 #include "glsl/GrGLSLProgramDataManager.h"
914 #include "SkGr.h" 914 #include "SkGr.h"
915 915
916 GrGLGradientEffect::GrGLGradientEffect() 916 GrGLGradientEffect::GrGLGradientEffect()
917 : fCachedYCoord(SK_ScalarMax) { 917 : fCachedYCoord(SK_ScalarMax) {
918 } 918 }
919 919
920 GrGLGradientEffect::~GrGLGradientEffect() { } 920 GrGLGradientEffect::~GrGLGradientEffect() { }
921 921
922 void GrGLGradientEffect::emitUniforms(GrGLFPBuilder* builder, const GrGradientEf fect& ge) { 922 void GrGLGradientEffect::emitUniforms(GrGLSLFPBuilder* builder, const GrGradient Effect& ge) {
923 923
924 if (SkGradientShaderBase::kTwo_GpuColorType == ge.getColorType()) { // 2 Col or case 924 if (SkGradientShaderBase::kTwo_GpuColorType == ge.getColorType()) { // 2 Col or case
925 fColorStartUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visib ility, 925 fColorStartUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visib ility,
926 kVec4f_GrSLType, kDefault_GrSLPreci sion, 926 kVec4f_GrSLType, kDefault_GrSLPreci sion,
927 "GradientStartColor"); 927 "GradientStartColor");
928 fColorEndUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibil ity, 928 fColorEndUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibil ity,
929 kVec4f_GrSLType, kDefault_GrSLPrecisi on, 929 kVec4f_GrSLType, kDefault_GrSLPrecisi on,
930 "GradientEndColor"); 930 "GradientEndColor");
931 931
932 } else if (SkGradientShaderBase::kThree_GpuColorType == ge.getColorType()) { // 3 Color Case 932 } else if (SkGradientShaderBase::kThree_GpuColorType == ge.getColorType()) { // 3 Color Case
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1018 key |= kThreeColorKey; 1018 key |= kThreeColorKey;
1019 } 1019 }
1020 1020
1021 if (GrGradientEffect::kBeforeInterp_PremulType == e.getPremulType()) { 1021 if (GrGradientEffect::kBeforeInterp_PremulType == e.getPremulType()) {
1022 key |= kPremulBeforeInterpKey; 1022 key |= kPremulBeforeInterpKey;
1023 } 1023 }
1024 1024
1025 return key; 1025 return key;
1026 } 1026 }
1027 1027
1028 void GrGLGradientEffect::emitColor(GrGLFPBuilder* builder, 1028 void GrGLGradientEffect::emitColor(GrGLSLFPBuilder* builder,
1029 const GrGradientEffect& ge, 1029 const GrGradientEffect& ge,
1030 const char* gradientTValue, 1030 const char* gradientTValue,
1031 const char* outputColor, 1031 const char* outputColor,
1032 const char* inputColor, 1032 const char* inputColor,
1033 const TextureSamplerArray& samplers) { 1033 const TextureSamplerArray& samplers) {
1034 GrGLFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); 1034 GrGLFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder();
1035 if (SkGradientShaderBase::kTwo_GpuColorType == ge.getColorType()){ 1035 if (SkGradientShaderBase::kTwo_GpuColorType == ge.getColorType()){
1036 fsBuilder->codeAppendf("\tvec4 colorTemp = mix(%s, %s, clamp(%s, 0.0, 1. 0));\n", 1036 fsBuilder->codeAppendf("\tvec4 colorTemp = mix(%s, %s, clamp(%s, 0.0, 1. 0));\n",
1037 builder->getUniformVariable(fColorStartUni).c_str (), 1037 builder->getUniformVariable(fColorStartUni).c_str (),
1038 builder->getUniformVariable(fColorEndUni).c_str() , 1038 builder->getUniformVariable(fColorEndUni).c_str() ,
1039 gradientTValue); 1039 gradientTValue);
1040 // Note that we could skip this step if both colors are known to be opaq ue. Two 1040 // Note that we could skip this step if both colors are known to be opaq ue. Two
1041 // considerations: 1041 // considerations:
1042 // The gradient SkShader reporting opaque is more restrictive than neces sary in the two pt 1042 // The gradient SkShader reporting opaque is more restrictive than neces sary in the two pt
1043 // case. Make sure the key reflects this optimization (and note that it can use the same 1043 // case. Make sure the key reflects this optimization (and note that it can use the same
1044 // shader as thekBeforeIterp case). This same optimization applies to th e 3 color case below. 1044 // shader as thekBeforeIterp case). This same optimization applies to th e 3 color case below.
1045 if (GrGradientEffect::kAfterInterp_PremulType == ge.getPremulType()) { 1045 if (GrGradientEffect::kAfterInterp_PremulType == ge.getPremulType()) {
1046 fsBuilder->codeAppend("\tcolorTemp.rgb *= colorTemp.a;\n"); 1046 fsBuilder->codeAppend("\tcolorTemp.rgb *= colorTemp.a;\n");
1047 } 1047 }
1048 1048
1049 fsBuilder->codeAppendf("\t%s = %s;\n", outputColor, 1049 fsBuilder->codeAppendf("\t%s = %s;\n", outputColor,
1050 (GrGLSLExpr4(inputColor) * GrGLSLExpr4("colorTemp ")).c_str()); 1050 (GrGLSLExpr4(inputColor) * GrGLSLExpr4("colorTemp ")).c_str());
1051 } else if (SkGradientShaderBase::kThree_GpuColorType == ge.getColorType()) { 1051 } else if (SkGradientShaderBase::kThree_GpuColorType == ge.getColorType()) {
1052 fsBuilder->codeAppendf("\tfloat oneMinus2t = 1.0 - (2.0 * (%s));\n", 1052 fsBuilder->codeAppendf("\tfloat oneMinus2t = 1.0 - (2.0 * (%s));\n",
1053 gradientTValue); 1053 gradientTValue);
1054 fsBuilder->codeAppendf("\tvec4 colorTemp = clamp(oneMinus2t, 0.0, 1.0) * %s;\n", 1054 fsBuilder->codeAppendf("\tvec4 colorTemp = clamp(oneMinus2t, 0.0, 1.0) * %s;\n",
1055 builder->getUniformVariable(fColorStartUni).c_str ()); 1055 builder->getUniformVariable(fColorStartUni).c_str ());
1056 if (kTegra3_GrGLRenderer == builder->ctxInfo().renderer()) { 1056 if (!builder->glslCaps()->canUseMinAndAbsTogether()) {
1057 // The Tegra3 compiler will sometimes never return if we have 1057 // The Tegra3 compiler will sometimes never return if we have
1058 // min(abs(oneMinus2t), 1.0), or do the abs first in a separate expr ession. 1058 // min(abs(oneMinus2t), 1.0), or do the abs first in a separate expr ession.
1059 fsBuilder->codeAppend("\tfloat minAbs = abs(oneMinus2t);\n"); 1059 fsBuilder->codeAppend("\tfloat minAbs = abs(oneMinus2t);\n");
1060 fsBuilder->codeAppend("\tminAbs = minAbs > 1.0 ? 1.0 : minAbs;\n"); 1060 fsBuilder->codeAppend("\tminAbs = minAbs > 1.0 ? 1.0 : minAbs;\n");
1061 fsBuilder->codeAppendf("\tcolorTemp += (1.0 - minAbs) * %s;\n", 1061 fsBuilder->codeAppendf("\tcolorTemp += (1.0 - minAbs) * %s;\n",
1062 builder->getUniformVariable(fColorMidUni).c_s tr()); 1062 builder->getUniformVariable(fColorMidUni).c_s tr());
1063 } else { 1063 } else {
1064 fsBuilder->codeAppendf("\tcolorTemp += (1.0 - min(abs(oneMinus2t), 1 .0)) * %s;\n", 1064 fsBuilder->codeAppendf("\tcolorTemp += (1.0 - min(abs(oneMinus2t), 1 .0)) * %s;\n",
1065 builder->getUniformVariable(fColorMidUni).c_s tr()); 1065 builder->getUniformVariable(fColorMidUni).c_s tr());
1066 } 1066 }
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1206 (*stops)[i] = stop; 1206 (*stops)[i] = stop;
1207 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st op) : 1.f; 1207 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st op) : 1.f;
1208 } 1208 }
1209 } 1209 }
1210 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM odeCount)); 1210 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM odeCount));
1211 1211
1212 return outColors; 1212 return outColors;
1213 } 1213 }
1214 1214
1215 #endif 1215 #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