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 808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 | 819 |
820 #if SK_SUPPORT_GPU | 820 #if SK_SUPPORT_GPU |
821 | 821 |
822 #include "effects/GrTextureStripAtlas.h" | 822 #include "effects/GrTextureStripAtlas.h" |
823 #include "GrTBackendEffectFactory.h" | 823 #include "GrTBackendEffectFactory.h" |
824 #include "SkGr.h" | 824 #include "SkGr.h" |
825 | 825 |
826 GrGLGradientEffect::GrGLGradientEffect(const GrBackendEffectFactory& factory) | 826 GrGLGradientEffect::GrGLGradientEffect(const GrBackendEffectFactory& factory) |
827 : INHERITED(factory) | 827 : INHERITED(factory) |
828 , fCachedYCoord(SK_ScalarMax) | 828 , fCachedYCoord(SK_ScalarMax) |
829 , fFSYUni(GrGLUniformManager::kInvalidUniformHandle) | 829 , fFSYUni(NULL) |
830 , fEffectMatrix(kCoordsType) { | 830 , fEffectMatrix(kCoordsType) { |
831 } | 831 } |
832 | 832 |
833 GrGLGradientEffect::~GrGLGradientEffect() { } | 833 GrGLGradientEffect::~GrGLGradientEffect() { } |
834 | 834 |
835 void GrGLGradientEffect::emitYCoordUniform(GrGLShaderBuilder* builder) { | 835 GrGLShaderBuilder::Uniform* GrGLGradientEffect::emitYCoordUniform(GrGLShaderBuil
der* builder) { |
836 fFSYUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, | 836 GrGLShaderBuilder::Uniform* fsYUni = |
837 kFloat_GrSLType, "GradientYCoordFS"); | 837 builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, |
| 838 kFloat_GrSLType, "GradientYCoordFS"); |
| 839 fFSYUni = fsYUni->glUniform(); |
| 840 return fsYUni; |
838 } | 841 } |
839 | 842 |
840 void GrGLGradientEffect::setData(const GrGLUniformManager& uman, | 843 void GrGLGradientEffect::setData(const GrGLContext& context, |
841 const GrDrawEffect& drawEffect) { | 844 const GrDrawEffect& drawEffect) { |
842 const GrGradientEffect& e = drawEffect.castEffect<GrGradientEffect>(); | 845 const GrGradientEffect& e = drawEffect.castEffect<GrGradientEffect>(); |
843 const GrTexture* texture = e.texture(0); | 846 const GrTexture* texture = e.texture(0); |
844 fEffectMatrix.setData(uman, e.getMatrix(), drawEffect, texture); | 847 fEffectMatrix.setData(context, e.getMatrix(), drawEffect, texture); |
845 | 848 |
846 SkScalar yCoord = e.getYCoord(); | 849 SkScalar yCoord = e.getYCoord(); |
847 if (yCoord != fCachedYCoord) { | 850 if (yCoord != fCachedYCoord) { |
848 uman.set1f(fFSYUni, yCoord); | 851 fFSYUni->set1f(context, yCoord); |
849 fCachedYCoord = yCoord; | 852 fCachedYCoord = yCoord; |
850 } | 853 } |
851 } | 854 } |
852 | 855 |
853 GrGLEffect::EffectKey GrGLGradientEffect::GenMatrixKey(const GrDrawEffect& drawE
ffect) { | 856 GrGLEffect::EffectKey GrGLGradientEffect::GenMatrixKey(const GrDrawEffect& drawE
ffect) { |
854 const GrGradientEffect& e = drawEffect.castEffect<GrGradientEffect>(); | 857 const GrGradientEffect& e = drawEffect.castEffect<GrGradientEffect>(); |
855 const GrTexture* texture = e.texture(0); | 858 const GrTexture* texture = e.texture(0); |
856 return GrGLEffectMatrix::GenKey(e.getMatrix(), drawEffect, kCoordsType, text
ure); | 859 return GrGLEffectMatrix::GenKey(e.getMatrix(), drawEffect, kCoordsType, text
ure); |
857 } | 860 } |
858 | 861 |
859 void GrGLGradientEffect::setupMatrix(GrGLShaderBuilder* builder, | 862 void GrGLGradientEffect::setupMatrix(GrGLShaderBuilder* builder, |
860 EffectKey key, | 863 EffectKey key, |
861 const char** fsCoordName, | 864 const char** fsCoordName, |
862 const char** vsVaryingName, | 865 const char** vsVaryingName, |
863 GrSLType* vsVaryingType) { | 866 GrSLType* vsVaryingType) { |
864 fEffectMatrix.emitCodeMakeFSCoords2D(builder, | 867 fEffectMatrix.emitCodeMakeFSCoords2D(builder, |
865 key & kMatrixKeyMask, | 868 key & kMatrixKeyMask, |
866 fsCoordName, | 869 fsCoordName, |
867 vsVaryingName, | 870 vsVaryingName, |
868 vsVaryingType); | 871 vsVaryingType); |
869 } | 872 } |
870 | 873 |
871 void GrGLGradientEffect::emitColorLookup(GrGLShaderBuilder* builder, | 874 void GrGLGradientEffect::emitColorLookup(GrGLShaderBuilder* builder, |
| 875 GrGLShaderBuilder::Uniform* fsYUni, |
872 const char* gradientTValue, | 876 const char* gradientTValue, |
873 const char* outputColor, | 877 const char* outputColor, |
874 const char* inputColor, | 878 const char* inputColor, |
875 const GrGLShaderBuilder::TextureSampler
& sampler) { | 879 const GrGLShaderBuilder::TextureSampler
& sampler) { |
876 | 880 |
877 builder->fsCodeAppendf("\tvec2 coord = vec2(%s, %s);\n", | 881 builder->fsCodeAppendf("\tvec2 coord = vec2(%s, %s);\n", |
878 gradientTValue, | 882 gradientTValue, |
879 builder->getUniformVariable(fFSYUni).c_str()); | 883 fsYUni->c_str()); |
880 builder->fsCodeAppendf("\t%s = ", outputColor); | 884 builder->fsCodeAppendf("\t%s = ", outputColor); |
881 builder->appendTextureLookupAndModulate(GrGLShaderBuilder::kFragment_ShaderT
ype, | 885 builder->appendTextureLookupAndModulate(GrGLShaderBuilder::kFragment_ShaderT
ype, |
882 inputColor, | 886 inputColor, |
883 sampler, | 887 sampler, |
884 "coord"); | 888 "coord"); |
885 builder->fsCodeAppend(";\n"); | 889 builder->fsCodeAppend(";\n"); |
886 } | 890 } |
887 | 891 |
888 ///////////////////////////////////////////////////////////////////// | 892 ///////////////////////////////////////////////////////////////////// |
889 | 893 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
977 (*stops)[i] = stop; | 981 (*stops)[i] = stop; |
978 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st
op) : 1.f; | 982 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st
op) : 1.f; |
979 } | 983 } |
980 } | 984 } |
981 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM
odeCount)); | 985 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM
odeCount)); |
982 | 986 |
983 return outColors; | 987 return outColors; |
984 } | 988 } |
985 | 989 |
986 #endif | 990 #endif |
OLD | NEW |