| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #include "SkXfermode.h" | 10 #include "SkXfermode.h" |
| (...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 | 776 |
| 777 ////////////////////////////////////////////////////////////////////////////// | 777 ////////////////////////////////////////////////////////////////////////////// |
| 778 | 778 |
| 779 #if SK_SUPPORT_GPU | 779 #if SK_SUPPORT_GPU |
| 780 | 780 |
| 781 #include "GrEffect.h" | 781 #include "GrEffect.h" |
| 782 #include "GrCoordTransform.h" | 782 #include "GrCoordTransform.h" |
| 783 #include "GrEffectUnitTest.h" | 783 #include "GrEffectUnitTest.h" |
| 784 #include "GrTBackendEffectFactory.h" | 784 #include "GrTBackendEffectFactory.h" |
| 785 #include "gl/GrGLEffect.h" | 785 #include "gl/GrGLEffect.h" |
| 786 #include "gl/GrGLShaderBuilder.h" | 786 #include "gl/builders/GrGLProgramBuilder.h" |
| 787 | 787 |
| 788 /** | 788 /** |
| 789 * GrEffect that implements the all the separable xfer modes that cannot be expr
essed as Coeffs. | 789 * GrEffect that implements the all the separable xfer modes that cannot be expr
essed as Coeffs. |
| 790 */ | 790 */ |
| 791 class XferEffect : public GrEffect { | 791 class XferEffect : public GrEffect { |
| 792 public: | 792 public: |
| 793 static bool IsSupportedMode(SkXfermode::Mode mode) { | 793 static bool IsSupportedMode(SkXfermode::Mode mode) { |
| 794 return mode > SkXfermode::kLastCoeffMode && mode <= SkXfermode::kLastMod
e; | 794 return mode > SkXfermode::kLastCoeffMode && mode <= SkXfermode::kLastMod
e; |
| 795 } | 795 } |
| 796 | 796 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 814 static const char* Name() { return "XferEffect"; } | 814 static const char* Name() { return "XferEffect"; } |
| 815 | 815 |
| 816 SkXfermode::Mode mode() const { return fMode; } | 816 SkXfermode::Mode mode() const { return fMode; } |
| 817 const GrTextureAccess& backgroundAccess() const { return fBackgroundAccess;
} | 817 const GrTextureAccess& backgroundAccess() const { return fBackgroundAccess;
} |
| 818 | 818 |
| 819 class GLEffect : public GrGLEffect { | 819 class GLEffect : public GrGLEffect { |
| 820 public: | 820 public: |
| 821 GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) | 821 GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) |
| 822 : GrGLEffect(factory) { | 822 : GrGLEffect(factory) { |
| 823 } | 823 } |
| 824 virtual void emitCode(GrGLShaderBuilder* builder, | 824 virtual void emitCode(GrGLProgramBuilder* builder, |
| 825 const GrDrawEffect& drawEffect, | 825 const GrDrawEffect& drawEffect, |
| 826 const GrEffectKey& key, | 826 const GrEffectKey& key, |
| 827 const char* outputColor, | 827 const char* outputColor, |
| 828 const char* inputColor, | 828 const char* inputColor, |
| 829 const TransformedCoordsArray& coords, | 829 const TransformedCoordsArray& coords, |
| 830 const TextureSamplerArray& samplers) SK_OVERRIDE { | 830 const TextureSamplerArray& samplers) SK_OVERRIDE { |
| 831 SkXfermode::Mode mode = drawEffect.castEffect<XferEffect>().mode(); | 831 SkXfermode::Mode mode = drawEffect.castEffect<XferEffect>().mode(); |
| 832 const GrTexture* backgroundTex = drawEffect.castEffect<XferEffect>()
.backgroundAccess().getTexture(); | 832 const GrTexture* backgroundTex = drawEffect.castEffect<XferEffect>()
.backgroundAccess().getTexture(); |
| 833 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBui
lder(); |
| 833 const char* dstColor; | 834 const char* dstColor; |
| 834 if (backgroundTex) { | 835 if (backgroundTex) { |
| 835 dstColor = "bgColor"; | 836 dstColor = "bgColor"; |
| 836 builder->fsCodeAppendf("\t\tvec4 %s = ", dstColor); | 837 fsBuilder->codeAppendf("\t\tvec4 %s = ", dstColor); |
| 837 builder->fsAppendTextureLookup(samplers[0], coords[0].c_str(), c
oords[0].type()); | 838 fsBuilder->appendTextureLookup(samplers[0], coords[0].c_str(), c
oords[0].type()); |
| 838 builder->fsCodeAppendf(";\n"); | 839 fsBuilder->codeAppendf(";\n"); |
| 839 } else { | 840 } else { |
| 840 dstColor = builder->dstColor(); | 841 dstColor = fsBuilder->dstColor(); |
| 841 } | 842 } |
| 842 SkASSERT(NULL != dstColor); | 843 SkASSERT(NULL != dstColor); |
| 843 | 844 |
| 844 // We don't try to optimize for this case at all | 845 // We don't try to optimize for this case at all |
| 845 if (NULL == inputColor) { | 846 if (NULL == inputColor) { |
| 846 builder->fsCodeAppendf("\t\tconst vec4 ones = vec4(1);\n"); | 847 fsBuilder->codeAppendf("\t\tconst vec4 ones = vec4(1);\n"); |
| 847 inputColor = "ones"; | 848 inputColor = "ones"; |
| 848 } | 849 } |
| 849 builder->fsCodeAppendf("\t\t// SkXfermode::Mode: %s\n", SkXfermode::
ModeName(mode)); | 850 fsBuilder->codeAppendf("\t\t// SkXfermode::Mode: %s\n", SkXfermode::
ModeName(mode)); |
| 850 | 851 |
| 851 // These all perform src-over on the alpha channel. | 852 // These all perform src-over on the alpha channel. |
| 852 builder->fsCodeAppendf("\t\t%s.a = %s.a + (1.0 - %s.a) * %s.a;\n", | 853 fsBuilder->codeAppendf("\t\t%s.a = %s.a + (1.0 - %s.a) * %s.a;\n", |
| 853 outputColor, inputColor, inputColor, dstColo
r); | 854 outputColor, inputColor, inputColor, dstColo
r); |
| 854 | 855 |
| 855 switch (mode) { | 856 switch (mode) { |
| 856 case SkXfermode::kOverlay_Mode: | 857 case SkXfermode::kOverlay_Mode: |
| 857 // Overlay is Hard-Light with the src and dst reversed | 858 // Overlay is Hard-Light with the src and dst reversed |
| 858 HardLight(builder, outputColor, dstColor, inputColor); | 859 HardLight(fsBuilder, outputColor, dstColor, inputColor); |
| 859 break; | 860 break; |
| 860 case SkXfermode::kDarken_Mode: | 861 case SkXfermode::kDarken_Mode: |
| 861 builder->fsCodeAppendf("\t\t%s.rgb = min((1.0 - %s.a) * %s.r
gb + %s.rgb, " | 862 fsBuilder->codeAppendf("\t\t%s.rgb = min((1.0 - %s.a) * %s.r
gb + %s.rgb, " |
| 862 "(1.0 - %s.a) * %s.r
gb + %s.rgb);\n", | 863 "(1.0 - %s.a) * %s.r
gb + %s.rgb);\n", |
| 863 outputColor, | 864 outputColor, |
| 864 inputColor, dstColor, inputColor, | 865 inputColor, dstColor, inputColor, |
| 865 dstColor, inputColor, dstColor); | 866 dstColor, inputColor, dstColor); |
| 866 break; | 867 break; |
| 867 case SkXfermode::kLighten_Mode: | 868 case SkXfermode::kLighten_Mode: |
| 868 builder->fsCodeAppendf("\t\t%s.rgb = max((1.0 - %s.a) * %s.r
gb + %s.rgb, " | 869 fsBuilder->codeAppendf("\t\t%s.rgb = max((1.0 - %s.a) * %s.r
gb + %s.rgb, " |
| 869 "(1.0 - %s.a) * %s.r
gb + %s.rgb);\n", | 870 "(1.0 - %s.a) * %s.r
gb + %s.rgb);\n", |
| 870 outputColor, | 871 outputColor, |
| 871 inputColor, dstColor, inputColor, | 872 inputColor, dstColor, inputColor, |
| 872 dstColor, inputColor, dstColor); | 873 dstColor, inputColor, dstColor); |
| 873 break; | 874 break; |
| 874 case SkXfermode::kColorDodge_Mode: | 875 case SkXfermode::kColorDodge_Mode: |
| 875 ColorDodgeComponent(builder, outputColor, inputColor, dstCol
or, 'r'); | 876 ColorDodgeComponent(fsBuilder, outputColor, inputColor, dstC
olor, 'r'); |
| 876 ColorDodgeComponent(builder, outputColor, inputColor, dstCol
or, 'g'); | 877 ColorDodgeComponent(fsBuilder, outputColor, inputColor, dstC
olor, 'g'); |
| 877 ColorDodgeComponent(builder, outputColor, inputColor, dstCol
or, 'b'); | 878 ColorDodgeComponent(fsBuilder, outputColor, inputColor, dstC
olor, 'b'); |
| 878 break; | 879 break; |
| 879 case SkXfermode::kColorBurn_Mode: | 880 case SkXfermode::kColorBurn_Mode: |
| 880 ColorBurnComponent(builder, outputColor, inputColor, dstColo
r, 'r'); | 881 ColorBurnComponent(fsBuilder, outputColor, inputColor, dstCo
lor, 'r'); |
| 881 ColorBurnComponent(builder, outputColor, inputColor, dstColo
r, 'g'); | 882 ColorBurnComponent(fsBuilder, outputColor, inputColor, dstCo
lor, 'g'); |
| 882 ColorBurnComponent(builder, outputColor, inputColor, dstColo
r, 'b'); | 883 ColorBurnComponent(fsBuilder, outputColor, inputColor, dstCo
lor, 'b'); |
| 883 break; | 884 break; |
| 884 case SkXfermode::kHardLight_Mode: | 885 case SkXfermode::kHardLight_Mode: |
| 885 HardLight(builder, outputColor, inputColor, dstColor); | 886 HardLight(fsBuilder, outputColor, inputColor, dstColor); |
| 886 break; | 887 break; |
| 887 case SkXfermode::kSoftLight_Mode: | 888 case SkXfermode::kSoftLight_Mode: |
| 888 builder->fsCodeAppendf("\t\tif (0.0 == %s.a) {\n", dstColor)
; | 889 fsBuilder->codeAppendf("\t\tif (0.0 == %s.a) {\n", dstColor)
; |
| 889 builder->fsCodeAppendf("\t\t\t%s.rgba = %s;\n", outputColor,
inputColor); | 890 fsBuilder->codeAppendf("\t\t\t%s.rgba = %s;\n", outputColor,
inputColor); |
| 890 builder->fsCodeAppendf("\t\t} else {\n"); | 891 fsBuilder->codeAppendf("\t\t} else {\n"); |
| 891 SoftLightComponentPosDstAlpha(builder, outputColor, inputCol
or, dstColor, 'r'); | 892 SoftLightComponentPosDstAlpha(fsBuilder, outputColor, inputC
olor, dstColor, 'r'); |
| 892 SoftLightComponentPosDstAlpha(builder, outputColor, inputCol
or, dstColor, 'g'); | 893 SoftLightComponentPosDstAlpha(fsBuilder, outputColor, inputC
olor, dstColor, 'g'); |
| 893 SoftLightComponentPosDstAlpha(builder, outputColor, inputCol
or, dstColor, 'b'); | 894 SoftLightComponentPosDstAlpha(fsBuilder, outputColor, inputC
olor, dstColor, 'b'); |
| 894 builder->fsCodeAppendf("\t\t}\n"); | 895 fsBuilder->codeAppendf("\t\t}\n"); |
| 895 break; | 896 break; |
| 896 case SkXfermode::kDifference_Mode: | 897 case SkXfermode::kDifference_Mode: |
| 897 builder->fsCodeAppendf("\t\t%s.rgb = %s.rgb + %s.rgb -" | 898 fsBuilder->codeAppendf("\t\t%s.rgb = %s.rgb + %s.rgb -" |
| 898 "2.0 * min(%s.rgb * %s.a,
%s.rgb * %s.a);\n", | 899 "2.0 * min(%s.rgb * %s.a,
%s.rgb * %s.a);\n", |
| 899 outputColor, inputColor, dstColor, in
putColor, dstColor, | 900 outputColor, inputColor, dstColor, in
putColor, dstColor, |
| 900 dstColor, inputColor); | 901 dstColor, inputColor); |
| 901 break; | 902 break; |
| 902 case SkXfermode::kExclusion_Mode: | 903 case SkXfermode::kExclusion_Mode: |
| 903 builder->fsCodeAppendf("\t\t%s.rgb = %s.rgb + %s.rgb - " | 904 fsBuilder->codeAppendf("\t\t%s.rgb = %s.rgb + %s.rgb - " |
| 904 "2.0 * %s.rgb * %s.rgb;\
n", | 905 "2.0 * %s.rgb * %s.rgb;\
n", |
| 905 outputColor, dstColor, inputColor, ds
tColor, inputColor); | 906 outputColor, dstColor, inputColor, ds
tColor, inputColor); |
| 906 break; | 907 break; |
| 907 case SkXfermode::kMultiply_Mode: | 908 case SkXfermode::kMultiply_Mode: |
| 908 builder->fsCodeAppendf("\t\t%s.rgb = (1.0 - %s.a) * %s.rgb +
" | 909 fsBuilder->codeAppendf("\t\t%s.rgb = (1.0 - %s.a) * %s.rgb +
" |
| 909 "(1.0 - %s.a) * %s.rgb +
" | 910 "(1.0 - %s.a) * %s.rgb +
" |
| 910 "%s.rgb * %s.rgb;\n", | 911 "%s.rgb * %s.rgb;\n", |
| 911 outputColor, inputColor, dstColor, ds
tColor, inputColor, | 912 outputColor, inputColor, dstColor, ds
tColor, inputColor, |
| 912 inputColor, dstColor); | 913 inputColor, dstColor); |
| 913 break; | 914 break; |
| 914 case SkXfermode::kHue_Mode: { | 915 case SkXfermode::kHue_Mode: { |
| 915 // SetLum(SetSat(S * Da, Sat(D * Sa)), Sa*Da, D*Sa) + (1 -
Sa) * D + (1 - Da) * S | 916 // SetLum(SetSat(S * Da, Sat(D * Sa)), Sa*Da, D*Sa) + (1 -
Sa) * D + (1 - Da) * S |
| 916 SkString setSat, setLum; | 917 SkString setSat, setLum; |
| 917 AddSatFunction(builder, &setSat); | 918 AddSatFunction(fsBuilder, &setSat); |
| 918 AddLumFunction(builder, &setLum); | 919 AddLumFunction(fsBuilder, &setLum); |
| 919 builder->fsCodeAppendf("\t\tvec4 dstSrcAlpha = %s * %s.a;\n"
, | 920 fsBuilder->codeAppendf("\t\tvec4 dstSrcAlpha = %s * %s.a;\n"
, |
| 920 dstColor, inputColor); | 921 dstColor, inputColor); |
| 921 builder->fsCodeAppendf("\t\t%s.rgb = %s(%s(%s.rgb * %s.a, ds
tSrcAlpha.rgb), dstSrcAlpha.a, dstSrcAlpha.rgb);\n", | 922 fsBuilder->codeAppendf("\t\t%s.rgb = %s(%s(%s.rgb * %s.a, ds
tSrcAlpha.rgb), dstSrcAlpha.a, dstSrcAlpha.rgb);\n", |
| 922 outputColor, setLum.c_str(), setSat.c
_str(), inputColor, | 923 outputColor, setLum.c_str(), setSat.c
_str(), inputColor, |
| 923 dstColor); | 924 dstColor); |
| 924 builder->fsCodeAppendf("\t\t%s.rgb += (1.0 - %s.a) * %s.rgb
+ (1.0 - %s.a) * %s.rgb;\n", | 925 fsBuilder->codeAppendf("\t\t%s.rgb += (1.0 - %s.a) * %s.rgb
+ (1.0 - %s.a) * %s.rgb;\n", |
| 925 outputColor, inputColor, dstColor, ds
tColor, inputColor); | 926 outputColor, inputColor, dstColor, ds
tColor, inputColor); |
| 926 break; | 927 break; |
| 927 } | 928 } |
| 928 case SkXfermode::kSaturation_Mode: { | 929 case SkXfermode::kSaturation_Mode: { |
| 929 // SetLum(SetSat(D * Sa, Sat(S * Da)), Sa*Da, D*Sa)) + (1 -
Sa) * D + (1 - Da) * S | 930 // SetLum(SetSat(D * Sa, Sat(S * Da)), Sa*Da, D*Sa)) + (1 -
Sa) * D + (1 - Da) * S |
| 930 SkString setSat, setLum; | 931 SkString setSat, setLum; |
| 931 AddSatFunction(builder, &setSat); | 932 AddSatFunction(fsBuilder, &setSat); |
| 932 AddLumFunction(builder, &setLum); | 933 AddLumFunction(fsBuilder, &setLum); |
| 933 builder->fsCodeAppendf("\t\tvec4 dstSrcAlpha = %s * %s.a;\n"
, | 934 fsBuilder->codeAppendf("\t\tvec4 dstSrcAlpha = %s * %s.a;\n"
, |
| 934 dstColor, inputColor); | 935 dstColor, inputColor); |
| 935 builder->fsCodeAppendf("\t\t%s.rgb = %s(%s(dstSrcAlpha.rgb,
%s.rgb * %s.a), dstSrcAlpha.a, dstSrcAlpha.rgb);\n", | 936 fsBuilder->codeAppendf("\t\t%s.rgb = %s(%s(dstSrcAlpha.rgb,
%s.rgb * %s.a), dstSrcAlpha.a, dstSrcAlpha.rgb);\n", |
| 936 outputColor, setLum.c_str(), setSat.c
_str(), inputColor, | 937 outputColor, setLum.c_str(), setSat.c
_str(), inputColor, |
| 937 dstColor); | 938 dstColor); |
| 938 builder->fsCodeAppendf("\t\t%s.rgb += (1.0 - %s.a) * %s.rgb
+ (1.0 - %s.a) * %s.rgb;\n", | 939 fsBuilder->codeAppendf("\t\t%s.rgb += (1.0 - %s.a) * %s.rgb
+ (1.0 - %s.a) * %s.rgb;\n", |
| 939 outputColor, inputColor, dstColor, ds
tColor, inputColor); | 940 outputColor, inputColor, dstColor, ds
tColor, inputColor); |
| 940 break; | 941 break; |
| 941 } | 942 } |
| 942 case SkXfermode::kColor_Mode: { | 943 case SkXfermode::kColor_Mode: { |
| 943 // SetLum(S * Da, Sa* Da, D * Sa) + (1 - Sa) * D + (1 - Da)
* S | 944 // SetLum(S * Da, Sa* Da, D * Sa) + (1 - Sa) * D + (1 - Da)
* S |
| 944 SkString setLum; | 945 SkString setLum; |
| 945 AddLumFunction(builder, &setLum); | 946 AddLumFunction(fsBuilder, &setLum); |
| 946 builder->fsCodeAppendf("\t\tvec4 srcDstAlpha = %s * %s.a;\n"
, | 947 fsBuilder->codeAppendf("\t\tvec4 srcDstAlpha = %s * %s.a;\n"
, |
| 947 inputColor, dstColor); | 948 inputColor, dstColor); |
| 948 builder->fsCodeAppendf("\t\t%s.rgb = %s(srcDstAlpha.rgb, src
DstAlpha.a, %s.rgb * %s.a);\n", | 949 fsBuilder->codeAppendf("\t\t%s.rgb = %s(srcDstAlpha.rgb, src
DstAlpha.a, %s.rgb * %s.a);\n", |
| 949 outputColor, setLum.c_str(), dstColor
, inputColor); | 950 outputColor, setLum.c_str(), dstColor
, inputColor); |
| 950 builder->fsCodeAppendf("\t\t%s.rgb += (1.0 - %s.a) * %s.rgb
+ (1.0 - %s.a) * %s.rgb;\n", | 951 fsBuilder->codeAppendf("\t\t%s.rgb += (1.0 - %s.a) * %s.rgb
+ (1.0 - %s.a) * %s.rgb;\n", |
| 951 outputColor, inputColor, dstColor, ds
tColor, inputColor); | 952 outputColor, inputColor, dstColor, ds
tColor, inputColor); |
| 952 break; | 953 break; |
| 953 } | 954 } |
| 954 case SkXfermode::kLuminosity_Mode: { | 955 case SkXfermode::kLuminosity_Mode: { |
| 955 // SetLum(D * Sa, Sa* Da, S * Da) + (1 - Sa) * D + (1 - Da)
* S | 956 // SetLum(D * Sa, Sa* Da, S * Da) + (1 - Sa) * D + (1 - Da)
* S |
| 956 SkString setLum; | 957 SkString setLum; |
| 957 AddLumFunction(builder, &setLum); | 958 AddLumFunction(fsBuilder, &setLum); |
| 958 builder->fsCodeAppendf("\t\tvec4 srcDstAlpha = %s * %s.a;\n"
, | 959 fsBuilder->codeAppendf("\t\tvec4 srcDstAlpha = %s * %s.a;\n"
, |
| 959 inputColor, dstColor); | 960 inputColor, dstColor); |
| 960 builder->fsCodeAppendf("\t\t%s.rgb = %s(%s.rgb * %s.a, srcDs
tAlpha.a, srcDstAlpha.rgb);\n", | 961 fsBuilder->codeAppendf("\t\t%s.rgb = %s(%s.rgb * %s.a, srcDs
tAlpha.a, srcDstAlpha.rgb);\n", |
| 961 outputColor, setLum.c_str(), dstColor
, inputColor); | 962 outputColor, setLum.c_str(), dstColor
, inputColor); |
| 962 builder->fsCodeAppendf("\t\t%s.rgb += (1.0 - %s.a) * %s.rgb
+ (1.0 - %s.a) * %s.rgb;\n", | 963 fsBuilder->codeAppendf("\t\t%s.rgb += (1.0 - %s.a) * %s.rgb
+ (1.0 - %s.a) * %s.rgb;\n", |
| 963 outputColor, inputColor, dstColor, ds
tColor, inputColor); | 964 outputColor, inputColor, dstColor, ds
tColor, inputColor); |
| 964 break; | 965 break; |
| 965 } | 966 } |
| 966 default: | 967 default: |
| 967 SkFAIL("Unknown XferEffect mode."); | 968 SkFAIL("Unknown XferEffect mode."); |
| 968 break; | 969 break; |
| 969 } | 970 } |
| 970 } | 971 } |
| 971 | 972 |
| 972 static inline void GenKey(const GrDrawEffect& drawEffect, const GrGLCaps
&, | 973 static inline void GenKey(const GrDrawEffect& drawEffect, const GrGLCaps
&, |
| 973 GrEffectKeyBuilder* b) { | 974 GrEffectKeyBuilder* b) { |
| 974 // The background may come from the dst or from a texture. | 975 // The background may come from the dst or from a texture. |
| 975 uint32_t key = drawEffect.effect()->numTextures(); | 976 uint32_t key = drawEffect.effect()->numTextures(); |
| 976 SkASSERT(key <= 1); | 977 SkASSERT(key <= 1); |
| 977 key |= drawEffect.castEffect<XferEffect>().mode() << 1; | 978 key |= drawEffect.castEffect<XferEffect>().mode() << 1; |
| 978 b->add32(key); | 979 b->add32(key); |
| 979 } | 980 } |
| 980 | 981 |
| 981 private: | 982 private: |
| 982 static void HardLight(GrGLShaderBuilder* builder, | 983 static void HardLight(GrGLFragmentShaderBuilder* fsBuilder, |
| 983 const char* final, | 984 const char* final, |
| 984 const char* src, | 985 const char* src, |
| 985 const char* dst) { | 986 const char* dst) { |
| 986 static const char kComponents[] = {'r', 'g', 'b'}; | 987 static const char kComponents[] = {'r', 'g', 'b'}; |
| 987 for (size_t i = 0; i < SK_ARRAY_COUNT(kComponents); ++i) { | 988 for (size_t i = 0; i < SK_ARRAY_COUNT(kComponents); ++i) { |
| 988 char component = kComponents[i]; | 989 char component = kComponents[i]; |
| 989 builder->fsCodeAppendf("\t\tif (2.0 * %s.%c <= %s.a) {\n", src,
component, src); | 990 fsBuilder->codeAppendf("\t\tif (2.0 * %s.%c <= %s.a) {\n", src,
component, src); |
| 990 builder->fsCodeAppendf("\t\t\t%s.%c = 2.0 * %s.%c * %s.%c;\n", f
inal, component, src, component, dst, component); | 991 fsBuilder->codeAppendf("\t\t\t%s.%c = 2.0 * %s.%c * %s.%c;\n", f
inal, component, src, component, dst, component); |
| 991 builder->fsCodeAppend("\t\t} else {\n"); | 992 fsBuilder->codeAppend("\t\t} else {\n"); |
| 992 builder->fsCodeAppendf("\t\t\t%s.%c = %s.a * %s.a - 2.0 * (%s.a
- %s.%c) * (%s.a - %s.%c);\n", | 993 fsBuilder->codeAppendf("\t\t\t%s.%c = %s.a * %s.a - 2.0 * (%s.a
- %s.%c) * (%s.a - %s.%c);\n", |
| 993 final, component, src, dst, dst, dst, com
ponent, src, src, component); | 994 final, component, src, dst, dst, dst, com
ponent, src, src, component); |
| 994 builder->fsCodeAppend("\t\t}\n"); | 995 fsBuilder->codeAppend("\t\t}\n"); |
| 995 } | 996 } |
| 996 builder->fsCodeAppendf("\t\t%s.rgb += %s.rgb * (1.0 - %s.a) + %s.rgb
* (1.0 - %s.a);\n", | 997 fsBuilder->codeAppendf("\t\t%s.rgb += %s.rgb * (1.0 - %s.a) + %s.rgb
* (1.0 - %s.a);\n", |
| 997 final, src, dst, dst, src); | 998 final, src, dst, dst, src); |
| 998 } | 999 } |
| 999 | 1000 |
| 1000 // Does one component of color-dodge | 1001 // Does one component of color-dodge |
| 1001 static void ColorDodgeComponent(GrGLShaderBuilder* builder, | 1002 static void ColorDodgeComponent(GrGLFragmentShaderBuilder* fsBuilder, |
| 1002 const char* final, | 1003 const char* final, |
| 1003 const char* src, | 1004 const char* src, |
| 1004 const char* dst, | 1005 const char* dst, |
| 1005 const char component) { | 1006 const char component) { |
| 1006 builder->fsCodeAppendf("\t\tif (0.0 == %s.%c) {\n", dst, component); | 1007 fsBuilder->codeAppendf("\t\tif (0.0 == %s.%c) {\n", dst, component); |
| 1007 builder->fsCodeAppendf("\t\t\t%s.%c = %s.%c * (1.0 - %s.a);\n", | 1008 fsBuilder->codeAppendf("\t\t\t%s.%c = %s.%c * (1.0 - %s.a);\n", |
| 1008 final, component, src, component, dst); | 1009 final, component, src, component, dst); |
| 1009 builder->fsCodeAppend("\t\t} else {\n"); | 1010 fsBuilder->codeAppend("\t\t} else {\n"); |
| 1010 builder->fsCodeAppendf("\t\t\tfloat d = %s.a - %s.%c;\n", src, src,
component); | 1011 fsBuilder->codeAppendf("\t\t\tfloat d = %s.a - %s.%c;\n", src, src,
component); |
| 1011 builder->fsCodeAppend("\t\t\tif (0.0 == d) {\n"); | 1012 fsBuilder->codeAppend("\t\t\tif (0.0 == d) {\n"); |
| 1012 builder->fsCodeAppendf("\t\t\t\t%s.%c = %s.a * %s.a + %s.%c * (1.0 -
%s.a) + %s.%c * (1.0 - %s.a);\n", | 1013 fsBuilder->codeAppendf("\t\t\t\t%s.%c = %s.a * %s.a + %s.%c * (1.0 -
%s.a) + %s.%c * (1.0 - %s.a);\n", |
| 1013 final, component, src, dst, src, component, d
st, dst, component, | 1014 final, component, src, dst, src, component, d
st, dst, component, |
| 1014 src); | 1015 src); |
| 1015 builder->fsCodeAppend("\t\t\t} else {\n"); | 1016 fsBuilder->codeAppend("\t\t\t} else {\n"); |
| 1016 builder->fsCodeAppendf("\t\t\t\td = min(%s.a, %s.%c * %s.a / d);\n", | 1017 fsBuilder->codeAppendf("\t\t\t\td = min(%s.a, %s.%c * %s.a / d);\n", |
| 1017 dst, dst, component, src); | 1018 dst, dst, component, src); |
| 1018 builder->fsCodeAppendf("\t\t\t\t%s.%c = d * %s.a + %s.%c * (1.0 - %s
.a) + %s.%c * (1.0 - %s.a);\n", | 1019 fsBuilder->codeAppendf("\t\t\t\t%s.%c = d * %s.a + %s.%c * (1.0 - %s
.a) + %s.%c * (1.0 - %s.a);\n", |
| 1019 final, component, src, src, component, dst, d
st, component, src); | 1020 final, component, src, src, component, dst, d
st, component, src); |
| 1020 builder->fsCodeAppend("\t\t\t}\n"); | 1021 fsBuilder->codeAppend("\t\t\t}\n"); |
| 1021 builder->fsCodeAppend("\t\t}\n"); | 1022 fsBuilder->codeAppend("\t\t}\n"); |
| 1022 } | 1023 } |
| 1023 | 1024 |
| 1024 // Does one component of color-burn | 1025 // Does one component of color-burn |
| 1025 static void ColorBurnComponent(GrGLShaderBuilder* builder, | 1026 static void ColorBurnComponent(GrGLFragmentShaderBuilder* fsBuilder, |
| 1026 const char* final, | 1027 const char* final, |
| 1027 const char* src, | 1028 const char* src, |
| 1028 const char* dst, | 1029 const char* dst, |
| 1029 const char component) { | 1030 const char component) { |
| 1030 builder->fsCodeAppendf("\t\tif (%s.a == %s.%c) {\n", dst, dst, compo
nent); | 1031 fsBuilder->codeAppendf("\t\tif (%s.a == %s.%c) {\n", dst, dst, compo
nent); |
| 1031 builder->fsCodeAppendf("\t\t\t%s.%c = %s.a * %s.a + %s.%c * (1.0 - %
s.a) + %s.%c * (1.0 - %s.a);\n", | 1032 fsBuilder->codeAppendf("\t\t\t%s.%c = %s.a * %s.a + %s.%c * (1.0 - %
s.a) + %s.%c * (1.0 - %s.a);\n", |
| 1032 final, component, src, dst, src, component, d
st, dst, component, | 1033 final, component, src, dst, src, component, d
st, dst, component, |
| 1033 src); | 1034 src); |
| 1034 builder->fsCodeAppendf("\t\t} else if (0.0 == %s.%c) {\n", src, comp
onent); | 1035 fsBuilder->codeAppendf("\t\t} else if (0.0 == %s.%c) {\n", src, comp
onent); |
| 1035 builder->fsCodeAppendf("\t\t\t%s.%c = %s.%c * (1.0 - %s.a);\n", | 1036 fsBuilder->codeAppendf("\t\t\t%s.%c = %s.%c * (1.0 - %s.a);\n", |
| 1036 final, component, dst, component, src); | 1037 final, component, dst, component, src); |
| 1037 builder->fsCodeAppend("\t\t} else {\n"); | 1038 fsBuilder->codeAppend("\t\t} else {\n"); |
| 1038 builder->fsCodeAppendf("\t\t\tfloat d = max(0.0, %s.a - (%s.a - %s.%
c) * %s.a / %s.%c);\n", | 1039 fsBuilder->codeAppendf("\t\t\tfloat d = max(0.0, %s.a - (%s.a - %s.%
c) * %s.a / %s.%c);\n", |
| 1039 dst, dst, dst, component, src, src, component
); | 1040 dst, dst, dst, component, src, src, component
); |
| 1040 builder->fsCodeAppendf("\t\t\t%s.%c = %s.a * d + %s.%c * (1.0 - %s.a
) + %s.%c * (1.0 - %s.a);\n", | 1041 fsBuilder->codeAppendf("\t\t\t%s.%c = %s.a * d + %s.%c * (1.0 - %s.a
) + %s.%c * (1.0 - %s.a);\n", |
| 1041 final, component, src, src, component, dst, d
st, component, src); | 1042 final, component, src, src, component, dst, d
st, component, src); |
| 1042 builder->fsCodeAppend("\t\t}\n"); | 1043 fsBuilder->codeAppend("\t\t}\n"); |
| 1043 } | 1044 } |
| 1044 | 1045 |
| 1045 // Does one component of soft-light. Caller should have already checked
that dst alpha > 0. | 1046 // Does one component of soft-light. Caller should have already checked
that dst alpha > 0. |
| 1046 static void SoftLightComponentPosDstAlpha(GrGLShaderBuilder* builder, | 1047 static void SoftLightComponentPosDstAlpha(GrGLFragmentShaderBuilder* fsB
uilder, |
| 1047 const char* final, | 1048 const char* final, |
| 1048 const char* src, | 1049 const char* src, |
| 1049 const char* dst, | 1050 const char* dst, |
| 1050 const char component) { | 1051 const char component) { |
| 1051 // if (2S < Sa) | 1052 // if (2S < Sa) |
| 1052 builder->fsCodeAppendf("\t\t\tif (2.0 * %s.%c <= %s.a) {\n", src, co
mponent, src); | 1053 fsBuilder->codeAppendf("\t\t\tif (2.0 * %s.%c <= %s.a) {\n", src, co
mponent, src); |
| 1053 // (D^2 (Sa-2 S))/Da+(1-Da) S+D (-Sa+2 S+1) | 1054 // (D^2 (Sa-2 S))/Da+(1-Da) S+D (-Sa+2 S+1) |
| 1054 builder->fsCodeAppendf("\t\t\t\t%s.%c = (%s.%c*%s.%c*(%s.a - 2.0*%s.
%c)) / %s.a + (1.0 - %s.a) * %s.%c + %s.%c*(-%s.a + 2.0*%s.%c + 1.0);\n", | 1055 fsBuilder->codeAppendf("\t\t\t\t%s.%c = (%s.%c*%s.%c*(%s.a - 2.0*%s.
%c)) / %s.a + (1.0 - %s.a) * %s.%c + %s.%c*(-%s.a + 2.0*%s.%c + 1.0);\n", |
| 1055 final, component, dst, component, dst, compon
ent, src, src, | 1056 final, component, dst, component, dst, compon
ent, src, src, |
| 1056 component, dst, dst, src, component, dst, com
ponent, src, src, | 1057 component, dst, dst, src, component, dst, com
ponent, src, src, |
| 1057 component); | 1058 component); |
| 1058 // else if (4D < Da) | 1059 // else if (4D < Da) |
| 1059 builder->fsCodeAppendf("\t\t\t} else if (4.0 * %s.%c <= %s.a) {\n", | 1060 fsBuilder->codeAppendf("\t\t\t} else if (4.0 * %s.%c <= %s.a) {\n", |
| 1060 dst, component, dst); | 1061 dst, component, dst); |
| 1061 builder->fsCodeAppendf("\t\t\t\tfloat DSqd = %s.%c * %s.%c;\n", | 1062 fsBuilder->codeAppendf("\t\t\t\tfloat DSqd = %s.%c * %s.%c;\n", |
| 1062 dst, component, dst, component); | 1063 dst, component, dst, component); |
| 1063 builder->fsCodeAppendf("\t\t\t\tfloat DCub = DSqd * %s.%c;\n", dst,
component); | 1064 fsBuilder->codeAppendf("\t\t\t\tfloat DCub = DSqd * %s.%c;\n", dst,
component); |
| 1064 builder->fsCodeAppendf("\t\t\t\tfloat DaSqd = %s.a * %s.a;\n", dst,
dst); | 1065 fsBuilder->codeAppendf("\t\t\t\tfloat DaSqd = %s.a * %s.a;\n", dst,
dst); |
| 1065 builder->fsCodeAppendf("\t\t\t\tfloat DaCub = DaSqd * %s.a;\n", dst)
; | 1066 fsBuilder->codeAppendf("\t\t\t\tfloat DaCub = DaSqd * %s.a;\n", dst)
; |
| 1066 // (Da^3 (-S)+Da^2 (S-D (3 Sa-6 S-1))+12 Da D^2 (Sa-2 S)-16 D^3 (Sa-
2 S))/Da^2 | 1067 // (Da^3 (-S)+Da^2 (S-D (3 Sa-6 S-1))+12 Da D^2 (Sa-2 S)-16 D^3 (Sa-
2 S))/Da^2 |
| 1067 builder->fsCodeAppendf("\t\t\t\t%s.%c = (-DaCub*%s.%c + DaSqd*(%s.%c
- %s.%c * (3.0*%s.a - 6.0*%s.%c - 1.0)) + 12.0*%s.a*DSqd*(%s.a - 2.0*%s.%c) - 1
6.0*DCub * (%s.a - 2.0*%s.%c)) / DaSqd;\n", | 1068 fsBuilder->codeAppendf("\t\t\t\t%s.%c = (-DaCub*%s.%c + DaSqd*(%s.%c
- %s.%c * (3.0*%s.a - 6.0*%s.%c - 1.0)) + 12.0*%s.a*DSqd*(%s.a - 2.0*%s.%c) - 1
6.0*DCub * (%s.a - 2.0*%s.%c)) / DaSqd;\n", |
| 1068 final, component, src, component, src, compon
ent, dst, component, | 1069 final, component, src, component, src, compon
ent, dst, component, |
| 1069 src, src, component, dst, src, src, component
, src, src, | 1070 src, src, component, dst, src, src, component
, src, src, |
| 1070 component); | 1071 component); |
| 1071 builder->fsCodeAppendf("\t\t\t} else {\n"); | 1072 fsBuilder->codeAppendf("\t\t\t} else {\n"); |
| 1072 // -sqrt(Da * D) (Sa-2 S)-Da S+D (Sa-2 S+1)+S | 1073 // -sqrt(Da * D) (Sa-2 S)-Da S+D (Sa-2 S+1)+S |
| 1073 builder->fsCodeAppendf("\t\t\t\t%s.%c = -sqrt(%s.a*%s.%c)*(%s.a - 2.
0*%s.%c) - %s.a*%s.%c + %s.%c*(%s.a - 2.0*%s.%c + 1.0) + %s.%c;\n", | 1074 fsBuilder->codeAppendf("\t\t\t\t%s.%c = -sqrt(%s.a*%s.%c)*(%s.a - 2.
0*%s.%c) - %s.a*%s.%c + %s.%c*(%s.a - 2.0*%s.%c + 1.0) + %s.%c;\n", |
| 1074 final, component, dst, dst, component, src,
src, component, dst, | 1075 final, component, dst, dst, component, src,
src, component, dst, |
| 1075 src, component, dst, component, src, src, co
mponent, src, | 1076 src, component, dst, component, src, src, co
mponent, src, |
| 1076 component); | 1077 component); |
| 1077 builder->fsCodeAppendf("\t\t\t}\n"); | 1078 fsBuilder->codeAppendf("\t\t\t}\n"); |
| 1078 } | 1079 } |
| 1079 | 1080 |
| 1080 // Adds a function that takes two colors and an alpha as input. It produ
ces a color with the | 1081 // Adds a function that takes two colors and an alpha as input. It produ
ces a color with the |
| 1081 // hue and saturation of the first color, the luminosity of the second c
olor, and the input | 1082 // hue and saturation of the first color, the luminosity of the second c
olor, and the input |
| 1082 // alpha. It has this signature: | 1083 // alpha. It has this signature: |
| 1083 // vec3 set_luminance(vec3 hueSatColor, float alpha, vec3 lumColor)
. | 1084 // vec3 set_luminance(vec3 hueSatColor, float alpha, vec3 lumColor)
. |
| 1084 static void AddLumFunction(GrGLShaderBuilder* builder, SkString* setLumF
unction) { | 1085 static void AddLumFunction(GrGLFragmentShaderBuilder* fsBuilder, SkStrin
g* setLumFunction) { |
| 1085 // Emit a helper that gets the luminance of a color. | 1086 // Emit a helper that gets the luminance of a color. |
| 1086 SkString getFunction; | 1087 SkString getFunction; |
| 1087 GrGLShaderVar getLumArgs[] = { | 1088 GrGLShaderVar getLumArgs[] = { |
| 1088 GrGLShaderVar("color", kVec3f_GrSLType), | 1089 GrGLShaderVar("color", kVec3f_GrSLType), |
| 1089 }; | 1090 }; |
| 1090 SkString getLumBody("\treturn dot(vec3(0.3, 0.59, 0.11), color);\n")
; | 1091 SkString getLumBody("\treturn dot(vec3(0.3, 0.59, 0.11), color);\n")
; |
| 1091 builder->fsEmitFunction(kFloat_GrSLType, | 1092 fsBuilder->emitFunction(kFloat_GrSLType, |
| 1092 "luminance", | 1093 "luminance", |
| 1093 SK_ARRAY_COUNT(getLumArgs), getLumArgs, | 1094 SK_ARRAY_COUNT(getLumArgs), getLumArgs, |
| 1094 getLumBody.c_str(), | 1095 getLumBody.c_str(), |
| 1095 &getFunction); | 1096 &getFunction); |
| 1096 | 1097 |
| 1097 // Emit the set luminance function. | 1098 // Emit the set luminance function. |
| 1098 GrGLShaderVar setLumArgs[] = { | 1099 GrGLShaderVar setLumArgs[] = { |
| 1099 GrGLShaderVar("hueSat", kVec3f_GrSLType), | 1100 GrGLShaderVar("hueSat", kVec3f_GrSLType), |
| 1100 GrGLShaderVar("alpha", kFloat_GrSLType), | 1101 GrGLShaderVar("alpha", kFloat_GrSLType), |
| 1101 GrGLShaderVar("lumColor", kVec3f_GrSLType), | 1102 GrGLShaderVar("lumColor", kVec3f_GrSLType), |
| 1102 }; | 1103 }; |
| 1103 SkString setLumBody; | 1104 SkString setLumBody; |
| 1104 setLumBody.printf("\tfloat diff = %s(lumColor - hueSat);\n", getFunc
tion.c_str()); | 1105 setLumBody.printf("\tfloat diff = %s(lumColor - hueSat);\n", getFunc
tion.c_str()); |
| 1105 setLumBody.append("\tvec3 outColor = hueSat + diff;\n"); | 1106 setLumBody.append("\tvec3 outColor = hueSat + diff;\n"); |
| 1106 setLumBody.appendf("\tfloat outLum = %s(outColor);\n", getFunction.c
_str()); | 1107 setLumBody.appendf("\tfloat outLum = %s(outColor);\n", getFunction.c
_str()); |
| 1107 setLumBody.append("\tfloat minComp = min(min(outColor.r, outColor.g)
, outColor.b);\n" | 1108 setLumBody.append("\tfloat minComp = min(min(outColor.r, outColor.g)
, outColor.b);\n" |
| 1108 "\tfloat maxComp = max(max(outColor.r, outColor.g)
, outColor.b);\n" | 1109 "\tfloat maxComp = max(max(outColor.r, outColor.g)
, outColor.b);\n" |
| 1109 "\tif (minComp < 0.0) {\n" | 1110 "\tif (minComp < 0.0) {\n" |
| 1110 "\t\toutColor = outLum + ((outColor - vec3(outLum,
outLum, outLum)) * outLum) / (outLum - minComp);\n" | 1111 "\t\toutColor = outLum + ((outColor - vec3(outLum,
outLum, outLum)) * outLum) / (outLum - minComp);\n" |
| 1111 "\t}\n" | 1112 "\t}\n" |
| 1112 "\tif (maxComp > alpha) {\n" | 1113 "\tif (maxComp > alpha) {\n" |
| 1113 "\t\toutColor = outLum + ((outColor - vec3(outLum,
outLum, outLum)) * (alpha - outLum)) / (maxComp - outLum);\n" | 1114 "\t\toutColor = outLum + ((outColor - vec3(outLum,
outLum, outLum)) * (alpha - outLum)) / (maxComp - outLum);\n" |
| 1114 "\t}\n" | 1115 "\t}\n" |
| 1115 "\treturn outColor;\n"); | 1116 "\treturn outColor;\n"); |
| 1116 builder->fsEmitFunction(kVec3f_GrSLType, | 1117 fsBuilder->emitFunction(kVec3f_GrSLType, |
| 1117 "set_luminance", | 1118 "set_luminance", |
| 1118 SK_ARRAY_COUNT(setLumArgs), setLumArgs, | 1119 SK_ARRAY_COUNT(setLumArgs), setLumArgs, |
| 1119 setLumBody.c_str(), | 1120 setLumBody.c_str(), |
| 1120 setLumFunction); | 1121 setLumFunction); |
| 1121 } | 1122 } |
| 1122 | 1123 |
| 1123 // Adds a function that creates a color with the hue and luminosity of o
ne input color and | 1124 // Adds a function that creates a color with the hue and luminosity of o
ne input color and |
| 1124 // the saturation of another color. It will have this signature: | 1125 // the saturation of another color. It will have this signature: |
| 1125 // float set_saturation(vec3 hueLumColor, vec3 satColor) | 1126 // float set_saturation(vec3 hueLumColor, vec3 satColor) |
| 1126 static void AddSatFunction(GrGLShaderBuilder* builder, SkString* setSatF
unction) { | 1127 static void AddSatFunction(GrGLFragmentShaderBuilder* fsBuilder, SkStrin
g* setSatFunction) { |
| 1127 // Emit a helper that gets the saturation of a color | 1128 // Emit a helper that gets the saturation of a color |
| 1128 SkString getFunction; | 1129 SkString getFunction; |
| 1129 GrGLShaderVar getSatArgs[] = { GrGLShaderVar("color", kVec3f_GrSLTyp
e) }; | 1130 GrGLShaderVar getSatArgs[] = { GrGLShaderVar("color", kVec3f_GrSLTyp
e) }; |
| 1130 SkString getSatBody; | 1131 SkString getSatBody; |
| 1131 getSatBody.printf("\treturn max(max(color.r, color.g), color.b) - " | 1132 getSatBody.printf("\treturn max(max(color.r, color.g), color.b) - " |
| 1132 "min(min(color.r, color.g), color.b);\n"); | 1133 "min(min(color.r, color.g), color.b);\n"); |
| 1133 builder->fsEmitFunction(kFloat_GrSLType, | 1134 fsBuilder->emitFunction(kFloat_GrSLType, |
| 1134 "saturation", | 1135 "saturation", |
| 1135 SK_ARRAY_COUNT(getSatArgs), getSatArgs, | 1136 SK_ARRAY_COUNT(getSatArgs), getSatArgs, |
| 1136 getSatBody.c_str(), | 1137 getSatBody.c_str(), |
| 1137 &getFunction); | 1138 &getFunction); |
| 1138 | 1139 |
| 1139 // Emit a helper that sets the saturation given sorted input channel
s. This used | 1140 // Emit a helper that sets the saturation given sorted input channel
s. This used |
| 1140 // to use inout params for min, mid, and max components but that see
ms to cause | 1141 // to use inout params for min, mid, and max components but that see
ms to cause |
| 1141 // problems on PowerVR drivers. So instead it returns a vec3 where r
, g ,b are the | 1142 // problems on PowerVR drivers. So instead it returns a vec3 where r
, g ,b are the |
| 1142 // adjusted min, mid, and max inputs, respectively. | 1143 // adjusted min, mid, and max inputs, respectively. |
| 1143 SkString helperFunction; | 1144 SkString helperFunction; |
| 1144 GrGLShaderVar helperArgs[] = { | 1145 GrGLShaderVar helperArgs[] = { |
| 1145 GrGLShaderVar("minComp", kFloat_GrSLType), | 1146 GrGLShaderVar("minComp", kFloat_GrSLType), |
| 1146 GrGLShaderVar("midComp", kFloat_GrSLType), | 1147 GrGLShaderVar("midComp", kFloat_GrSLType), |
| 1147 GrGLShaderVar("maxComp", kFloat_GrSLType), | 1148 GrGLShaderVar("maxComp", kFloat_GrSLType), |
| 1148 GrGLShaderVar("sat", kFloat_GrSLType), | 1149 GrGLShaderVar("sat", kFloat_GrSLType), |
| 1149 }; | 1150 }; |
| 1150 static const char kHelperBody[] = "\tif (minComp < maxComp) {\n" | 1151 static const char kHelperBody[] = "\tif (minComp < maxComp) {\n" |
| 1151 "\t\tvec3 result;\n" | 1152 "\t\tvec3 result;\n" |
| 1152 "\t\tresult.r = 0.0;\n" | 1153 "\t\tresult.r = 0.0;\n" |
| 1153 "\t\tresult.g = sat * (midComp - m
inComp) / (maxComp - minComp);\n" | 1154 "\t\tresult.g = sat * (midComp - m
inComp) / (maxComp - minComp);\n" |
| 1154 "\t\tresult.b = sat;\n" | 1155 "\t\tresult.b = sat;\n" |
| 1155 "\t\treturn result;\n" | 1156 "\t\treturn result;\n" |
| 1156 "\t} else {\n" | 1157 "\t} else {\n" |
| 1157 "\t\treturn vec3(0, 0, 0);\n" | 1158 "\t\treturn vec3(0, 0, 0);\n" |
| 1158 "\t}\n"; | 1159 "\t}\n"; |
| 1159 builder->fsEmitFunction(kVec3f_GrSLType, | 1160 fsBuilder->emitFunction(kVec3f_GrSLType, |
| 1160 "set_saturation_helper", | 1161 "set_saturation_helper", |
| 1161 SK_ARRAY_COUNT(helperArgs), helperArgs, | 1162 SK_ARRAY_COUNT(helperArgs), helperArgs, |
| 1162 kHelperBody, | 1163 kHelperBody, |
| 1163 &helperFunction); | 1164 &helperFunction); |
| 1164 | 1165 |
| 1165 GrGLShaderVar setSatArgs[] = { | 1166 GrGLShaderVar setSatArgs[] = { |
| 1166 GrGLShaderVar("hueLumColor", kVec3f_GrSLType), | 1167 GrGLShaderVar("hueLumColor", kVec3f_GrSLType), |
| 1167 GrGLShaderVar("satColor", kVec3f_GrSLType), | 1168 GrGLShaderVar("satColor", kVec3f_GrSLType), |
| 1168 }; | 1169 }; |
| 1169 const char* helpFunc = helperFunction.c_str(); | 1170 const char* helpFunc = helperFunction.c_str(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1180 "\t} else if (hueLumColor.r <= hueLumColor.b) {\n
" | 1181 "\t} else if (hueLumColor.r <= hueLumColor.b) {\n
" |
| 1181 "\t\thueLumColor.grb = %s(hueLumColor.g, hueLumCo
lor.r, hueLumColor.b, sat);\n" | 1182 "\t\thueLumColor.grb = %s(hueLumColor.g, hueLumCo
lor.r, hueLumColor.b, sat);\n" |
| 1182 "\t} else if (hueLumColor.g <= hueLumColor.b) {\n
" | 1183 "\t} else if (hueLumColor.g <= hueLumColor.b) {\n
" |
| 1183 "\t\thueLumColor.gbr = %s(hueLumColor.g, hueLumCo
lor.b, hueLumColor.r, sat);\n" | 1184 "\t\thueLumColor.gbr = %s(hueLumColor.g, hueLumCo
lor.b, hueLumColor.r, sat);\n" |
| 1184 "\t} else {\n" | 1185 "\t} else {\n" |
| 1185 "\t\thueLumColor.bgr = %s(hueLumColor.b, hueLumCo
lor.g, hueLumColor.r, sat);\n" | 1186 "\t\thueLumColor.bgr = %s(hueLumColor.b, hueLumCo
lor.g, hueLumColor.r, sat);\n" |
| 1186 "\t}\n" | 1187 "\t}\n" |
| 1187 "\treturn hueLumColor;\n", | 1188 "\treturn hueLumColor;\n", |
| 1188 getFunction.c_str(), helpFunc, helpFunc, helpFunc
, helpFunc, | 1189 getFunction.c_str(), helpFunc, helpFunc, helpFunc
, helpFunc, |
| 1189 helpFunc, helpFunc); | 1190 helpFunc, helpFunc); |
| 1190 builder->fsEmitFunction(kVec3f_GrSLType, | 1191 fsBuilder->emitFunction(kVec3f_GrSLType, |
| 1191 "set_saturation", | 1192 "set_saturation", |
| 1192 SK_ARRAY_COUNT(setSatArgs), setSatArgs, | 1193 SK_ARRAY_COUNT(setSatArgs), setSatArgs, |
| 1193 setSatBody.c_str(), | 1194 setSatBody.c_str(), |
| 1194 setSatFunction); | 1195 setSatFunction); |
| 1195 | 1196 |
| 1196 } | 1197 } |
| 1197 | 1198 |
| 1198 typedef GrGLEffect INHERITED; | 1199 typedef GrGLEffect INHERITED; |
| 1199 }; | 1200 }; |
| 1200 | 1201 |
| (...skipping 754 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1955 } else { | 1956 } else { |
| 1956 proc16 = rec.fProc16_General; | 1957 proc16 = rec.fProc16_General; |
| 1957 } | 1958 } |
| 1958 } | 1959 } |
| 1959 return proc16; | 1960 return proc16; |
| 1960 } | 1961 } |
| 1961 | 1962 |
| 1962 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkXfermode) | 1963 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkXfermode) |
| 1963 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkProcCoeffXfermode) | 1964 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkProcCoeffXfermode) |
| 1964 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 1965 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
| OLD | NEW |