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 938 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
949 #include "gl/builders/GrGLProgramBuilder.h" | 949 #include "gl/builders/GrGLProgramBuilder.h" |
950 #include "SkGr.h" | 950 #include "SkGr.h" |
951 | 951 |
952 GrGLGradientEffect::GrGLGradientEffect(const GrBackendProcessorFactory& factory) | 952 GrGLGradientEffect::GrGLGradientEffect(const GrBackendProcessorFactory& factory) |
953 : INHERITED(factory) | 953 : INHERITED(factory) |
954 , fCachedYCoord(SK_ScalarMax) { | 954 , fCachedYCoord(SK_ScalarMax) { |
955 } | 955 } |
956 | 956 |
957 GrGLGradientEffect::~GrGLGradientEffect() { } | 957 GrGLGradientEffect::~GrGLGradientEffect() { } |
958 | 958 |
959 void GrGLGradientEffect::emitUniforms(GrGLProgramBuilder* builder, uint32_t base
Key) { | 959 void GrGLGradientEffect::emitUniforms(GrGLFPBuilder* builder, uint32_t baseKey)
{ |
960 | 960 |
961 if (SkGradientShaderBase::kTwo_GpuColorType == ColorTypeFromKey(baseKey)) {
// 2 Color case | 961 if (SkGradientShaderBase::kTwo_GpuColorType == ColorTypeFromKey(baseKey)) {
// 2 Color case |
962 fColorStartUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visib
ility, | 962 fColorStartUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visib
ility, |
963 kVec4f_GrSLType, "GradientStartColo
r"); | 963 kVec4f_GrSLType, "GradientStartColo
r"); |
964 fColorEndUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibil
ity, | 964 fColorEndUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibil
ity, |
965 kVec4f_GrSLType, "GradientEndColor"); | 965 kVec4f_GrSLType, "GradientEndColor"); |
966 | 966 |
967 } else if (SkGradientShaderBase::kThree_GpuColorType == ColorTypeFromKey(bas
eKey)){ // 3 Color Case | 967 } else if (SkGradientShaderBase::kThree_GpuColorType == ColorTypeFromKey(bas
eKey)){ // 3 Color Case |
968 fColorStartUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visib
ility, | 968 fColorStartUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visib
ility, |
969 kVec4f_GrSLType, "GradientStartColo
r"); | 969 kVec4f_GrSLType, "GradientStartColo
r"); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1049 key |= kThreeColorKey; | 1049 key |= kThreeColorKey; |
1050 } | 1050 } |
1051 | 1051 |
1052 if (GrGradientEffect::kBeforeInterp_PremulType == e.getPremulType()) { | 1052 if (GrGradientEffect::kBeforeInterp_PremulType == e.getPremulType()) { |
1053 key |= kPremulBeforeInterpKey; | 1053 key |= kPremulBeforeInterpKey; |
1054 } | 1054 } |
1055 | 1055 |
1056 return key; | 1056 return key; |
1057 } | 1057 } |
1058 | 1058 |
1059 void GrGLGradientEffect::emitColor(GrGLProgramBuilder* builder, | 1059 void GrGLGradientEffect::emitColor(GrGLFPBuilder* builder, |
1060 const char* gradientTValue, | 1060 const char* gradientTValue, |
1061 uint32_t baseKey, | 1061 uint32_t baseKey, |
1062 const char* outputColor, | 1062 const char* outputColor, |
1063 const char* inputColor, | 1063 const char* inputColor, |
1064 const TextureSamplerArray& samplers) { | 1064 const TextureSamplerArray& samplers) { |
1065 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); | 1065 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
1066 if (SkGradientShaderBase::kTwo_GpuColorType == ColorTypeFromKey(baseKey)){ | 1066 if (SkGradientShaderBase::kTwo_GpuColorType == ColorTypeFromKey(baseKey)){ |
1067 fsBuilder->codeAppendf("\tvec4 colorTemp = mix(%s, %s, clamp(%s, 0.0, 1.
0));\n", | 1067 fsBuilder->codeAppendf("\tvec4 colorTemp = mix(%s, %s, clamp(%s, 0.0, 1.
0));\n", |
1068 builder->getUniformVariable(fColorStartUni).c_str
(), | 1068 builder->getUniformVariable(fColorStartUni).c_str
(), |
1069 builder->getUniformVariable(fColorEndUni).c_str()
, | 1069 builder->getUniformVariable(fColorEndUni).c_str()
, |
1070 gradientTValue); | 1070 gradientTValue); |
1071 // Note that we could skip this step if both colors are known to be opaq
ue. Two | 1071 // Note that we could skip this step if both colors are known to be opaq
ue. Two |
1072 // considerations: | 1072 // considerations: |
1073 // The gradient SkShader reporting opaque is more restrictive than neces
sary in the two pt | 1073 // The gradient SkShader reporting opaque is more restrictive than neces
sary in the two pt |
1074 // case. Make sure the key reflects this optimization (and note that it
can use the same | 1074 // case. Make sure the key reflects this optimization (and note that it
can use the same |
1075 // shader as thekBeforeIterp case). This same optimization applies to th
e 3 color case below. | 1075 // shader as thekBeforeIterp case). This same optimization applies to th
e 3 color case below. |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1239 (*stops)[i] = stop; | 1239 (*stops)[i] = stop; |
1240 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st
op) : 1.f; | 1240 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st
op) : 1.f; |
1241 } | 1241 } |
1242 } | 1242 } |
1243 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM
odeCount)); | 1243 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM
odeCount)); |
1244 | 1244 |
1245 return outColors; | 1245 return outColors; |
1246 } | 1246 } |
1247 | 1247 |
1248 #endif | 1248 #endif |
OLD | NEW |