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 "Sk4fLinearGradient.h" | 8 #include "Sk4fLinearGradient.h" |
9 #include "SkGradientShaderPriv.h" | 9 #include "SkGradientShaderPriv.h" |
10 #include "SkLinearGradient.h" | 10 #include "SkLinearGradient.h" |
(...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
904 | 904 |
905 #include "effects/GrTextureStripAtlas.h" | 905 #include "effects/GrTextureStripAtlas.h" |
906 #include "GrContext.h" | 906 #include "GrContext.h" |
907 #include "GrInvariantOutput.h" | 907 #include "GrInvariantOutput.h" |
908 #include "gl/GrGLContext.h" | 908 #include "gl/GrGLContext.h" |
909 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 909 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
910 #include "glsl/GrGLSLProgramDataManager.h" | 910 #include "glsl/GrGLSLProgramDataManager.h" |
911 #include "glsl/GrGLSLUniformHandler.h" | 911 #include "glsl/GrGLSLUniformHandler.h" |
912 #include "SkGr.h" | 912 #include "SkGr.h" |
913 | 913 |
914 GrGLGradientEffect::GrGLGradientEffect() | 914 GrGradientEffect::GLSLProcessor::GLSLProcessor() |
915 : fCachedYCoord(SK_ScalarMax) { | 915 : fCachedYCoord(SK_ScalarMax) { |
916 } | 916 } |
917 | 917 |
918 void GrGLGradientEffect::emitUniforms(GrGLSLUniformHandler* uniformHandler, | 918 void GrGradientEffect::GLSLProcessor::emitUniforms(GrGLSLUniformHandler* uniform
Handler, |
919 const GrGradientEffect& ge) { | 919 const GrGradientEffect& ge) { |
920 | 920 |
921 if (SkGradientShaderBase::kTwo_GpuColorType == ge.getColorType()) { // 2 Col
or case | 921 if (SkGradientShaderBase::kTwo_GpuColorType == ge.getColorType()) { // 2 Col
or case |
922 fColorStartUni = uniformHandler->addUniform(kFragment_GrShaderFlag, | 922 fColorStartUni = uniformHandler->addUniform(kFragment_GrShaderFlag, |
923 kVec4f_GrSLType, kDefault_Gr
SLPrecision, | 923 kVec4f_GrSLType, kDefault_Gr
SLPrecision, |
924 "GradientStartColor"); | 924 "GradientStartColor"); |
925 fColorEndUni = uniformHandler->addUniform(kFragment_GrShaderFlag, | 925 fColorEndUni = uniformHandler->addUniform(kFragment_GrShaderFlag, |
926 kVec4f_GrSLType, kDefault_GrSL
Precision, | 926 kVec4f_GrSLType, kDefault_GrSL
Precision, |
927 "GradientEndColor"); | 927 "GradientEndColor"); |
928 | 928 |
929 } else if (SkGradientShaderBase::kThree_GpuColorType == ge.getColorType()) {
// 3 Color Case | 929 } else if (SkGradientShaderBase::kThree_GpuColorType == ge.getColorType()) {
// 3 Color Case |
(...skipping 29 matching lines...) Expand all Loading... |
959 const SkColor* color){ | 959 const SkColor* color){ |
960 float a = SkColorGetA(*color) / 255.f; | 960 float a = SkColorGetA(*color) / 255.f; |
961 float aDiv255 = a / 255.f; | 961 float aDiv255 = a / 255.f; |
962 pdman.set4f(uni, | 962 pdman.set4f(uni, |
963 SkColorGetR(*color) * aDiv255, | 963 SkColorGetR(*color) * aDiv255, |
964 SkColorGetG(*color) * aDiv255, | 964 SkColorGetG(*color) * aDiv255, |
965 SkColorGetB(*color) * aDiv255, | 965 SkColorGetB(*color) * aDiv255, |
966 a); | 966 a); |
967 } | 967 } |
968 | 968 |
969 void GrGLGradientEffect::onSetData(const GrGLSLProgramDataManager& pdman, | 969 void GrGradientEffect::GLSLProcessor::onSetData(const GrGLSLProgramDataManager&
pdman, |
970 const GrProcessor& processor) { | 970 const GrProcessor& processor) { |
971 | 971 |
972 const GrGradientEffect& e = processor.cast<GrGradientEffect>(); | 972 const GrGradientEffect& e = processor.cast<GrGradientEffect>(); |
973 | 973 |
974 | 974 |
975 if (SkGradientShaderBase::kTwo_GpuColorType == e.getColorType()){ | 975 if (SkGradientShaderBase::kTwo_GpuColorType == e.getColorType()){ |
976 | 976 |
977 if (GrGradientEffect::kBeforeInterp_PremulType == e.getPremulType()) { | 977 if (GrGradientEffect::kBeforeInterp_PremulType == e.getPremulType()) { |
978 set_mul_color_uni(pdman, fColorStartUni, e.getColors(0)); | 978 set_mul_color_uni(pdman, fColorStartUni, e.getColors(0)); |
979 set_mul_color_uni(pdman, fColorEndUni, e.getColors(1)); | 979 set_mul_color_uni(pdman, fColorEndUni, e.getColors(1)); |
980 } else { | 980 } else { |
(...skipping 16 matching lines...) Expand all Loading... |
997 | 997 |
998 SkScalar yCoord = e.getYCoord(); | 998 SkScalar yCoord = e.getYCoord(); |
999 if (yCoord != fCachedYCoord) { | 999 if (yCoord != fCachedYCoord) { |
1000 pdman.set1f(fFSYUni, yCoord); | 1000 pdman.set1f(fFSYUni, yCoord); |
1001 fCachedYCoord = yCoord; | 1001 fCachedYCoord = yCoord; |
1002 } | 1002 } |
1003 } | 1003 } |
1004 } | 1004 } |
1005 | 1005 |
1006 | 1006 |
1007 uint32_t GrGLGradientEffect::GenBaseGradientKey(const GrProcessor& processor) { | 1007 uint32_t GrGradientEffect::GLSLProcessor::GenBaseGradientKey(const GrProcessor&
processor) { |
1008 const GrGradientEffect& e = processor.cast<GrGradientEffect>(); | 1008 const GrGradientEffect& e = processor.cast<GrGradientEffect>(); |
1009 | 1009 |
1010 uint32_t key = 0; | 1010 uint32_t key = 0; |
1011 | 1011 |
1012 if (SkGradientShaderBase::kTwo_GpuColorType == e.getColorType()) { | 1012 if (SkGradientShaderBase::kTwo_GpuColorType == e.getColorType()) { |
1013 key |= kTwoColorKey; | 1013 key |= kTwoColorKey; |
1014 } else if (SkGradientShaderBase::kThree_GpuColorType == e.getColorType()) { | 1014 } else if (SkGradientShaderBase::kThree_GpuColorType == e.getColorType()) { |
1015 key |= kThreeColorKey; | 1015 key |= kThreeColorKey; |
1016 } | 1016 } |
1017 | 1017 |
1018 if (GrGradientEffect::kBeforeInterp_PremulType == e.getPremulType()) { | 1018 if (GrGradientEffect::kBeforeInterp_PremulType == e.getPremulType()) { |
1019 key |= kPremulBeforeInterpKey; | 1019 key |= kPremulBeforeInterpKey; |
1020 } | 1020 } |
1021 | 1021 |
1022 return key; | 1022 return key; |
1023 } | 1023 } |
1024 | 1024 |
1025 void GrGLGradientEffect::emitColor(GrGLSLFPFragmentBuilder* fragBuilder, | 1025 void GrGradientEffect::GLSLProcessor::emitColor(GrGLSLFPFragmentBuilder* fragBui
lder, |
1026 GrGLSLUniformHandler* uniformHandler, | 1026 GrGLSLUniformHandler* uniformHan
dler, |
1027 const GrGLSLCaps* glslCaps, | 1027 const GrGLSLCaps* glslCaps, |
1028 const GrGradientEffect& ge, | 1028 const GrGradientEffect& ge, |
1029 const char* gradientTValue, | 1029 const char* gradientTValue, |
1030 const char* outputColor, | 1030 const char* outputColor, |
1031 const char* inputColor, | 1031 const char* inputColor, |
1032 const SamplerHandle* texSamplers) { | 1032 const SamplerHandle* texSamplers
) { |
1033 if (SkGradientShaderBase::kTwo_GpuColorType == ge.getColorType()){ | 1033 if (SkGradientShaderBase::kTwo_GpuColorType == ge.getColorType()){ |
1034 fragBuilder->codeAppendf("\tvec4 colorTemp = mix(%s, %s, clamp(%s, 0.0,
1.0));\n", | 1034 fragBuilder->codeAppendf("\tvec4 colorTemp = mix(%s, %s, clamp(%s, 0.0,
1.0));\n", |
1035 uniformHandler->getUniformVariable(fColorStartU
ni).c_str(), | 1035 uniformHandler->getUniformVariable(fColorStartU
ni).c_str(), |
1036 uniformHandler->getUniformVariable(fColorEndUni
).c_str(), | 1036 uniformHandler->getUniformVariable(fColorEndUni
).c_str(), |
1037 gradientTValue); | 1037 gradientTValue); |
1038 // Note that we could skip this step if both colors are known to be opaq
ue. Two | 1038 // Note that we could skip this step if both colors are known to be opaq
ue. Two |
1039 // considerations: | 1039 // considerations: |
1040 // The gradient SkShader reporting opaque is more restrictive than neces
sary in the two pt | 1040 // The gradient SkShader reporting opaque is more restrictive than neces
sary in the two pt |
1041 // case. Make sure the key reflects this optimization (and note that it
can use the same | 1041 // case. Make sure the key reflects this optimization (and note that it
can use the same |
1042 // shader as thekBeforeIterp case). This same optimization applies to th
e 3 color case | 1042 // shader as thekBeforeIterp case). This same optimization applies to th
e 3 color case |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1208 (*stops)[i] = stop; | 1208 (*stops)[i] = stop; |
1209 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st
op) : 1.f; | 1209 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st
op) : 1.f; |
1210 } | 1210 } |
1211 } | 1211 } |
1212 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM
odeCount)); | 1212 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM
odeCount)); |
1213 | 1213 |
1214 return outColors; | 1214 return outColors; |
1215 } | 1215 } |
1216 | 1216 |
1217 #endif | 1217 #endif |
OLD | NEW |