| 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 877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 888 void SkProcXfermode::toString(SkString* str) const { | 888 void SkProcXfermode::toString(SkString* str) const { |
| 889 str->appendf("SkProcXfermode: %p", fProc); | 889 str->appendf("SkProcXfermode: %p", fProc); |
| 890 } | 890 } |
| 891 #endif | 891 #endif |
| 892 | 892 |
| 893 ////////////////////////////////////////////////////////////////////////////// | 893 ////////////////////////////////////////////////////////////////////////////// |
| 894 | 894 |
| 895 #if SK_SUPPORT_GPU | 895 #if SK_SUPPORT_GPU |
| 896 | 896 |
| 897 #include "GrEffect.h" | 897 #include "GrEffect.h" |
| 898 #include "GrCoordTransform.h" |
| 898 #include "GrEffectUnitTest.h" | 899 #include "GrEffectUnitTest.h" |
| 899 #include "GrTBackendEffectFactory.h" | 900 #include "GrTBackendEffectFactory.h" |
| 900 #include "gl/GrGLEffect.h" | 901 #include "gl/GrGLEffect.h" |
| 901 #include "gl/GrGLEffectMatrix.h" | |
| 902 | 902 |
| 903 /** | 903 /** |
| 904 * GrEffect that implements the all the separable xfer modes that cannot be expr
essed as Coeffs. | 904 * GrEffect that implements the all the separable xfer modes that cannot be expr
essed as Coeffs. |
| 905 */ | 905 */ |
| 906 class XferEffect : public GrEffect { | 906 class XferEffect : public GrEffect { |
| 907 public: | 907 public: |
| 908 static bool IsSupportedMode(SkXfermode::Mode mode) { | 908 static bool IsSupportedMode(SkXfermode::Mode mode) { |
| 909 return mode > SkXfermode::kLastCoeffMode && mode <= SkXfermode::kLastMod
e; | 909 return mode > SkXfermode::kLastCoeffMode && mode <= SkXfermode::kLastMod
e; |
| 910 } | 910 } |
| 911 | 911 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 928 } | 928 } |
| 929 | 929 |
| 930 static const char* Name() { return "XferEffect"; } | 930 static const char* Name() { return "XferEffect"; } |
| 931 | 931 |
| 932 SkXfermode::Mode mode() const { return fMode; } | 932 SkXfermode::Mode mode() const { return fMode; } |
| 933 const GrTextureAccess& backgroundAccess() const { return fBackgroundAccess;
} | 933 const GrTextureAccess& backgroundAccess() const { return fBackgroundAccess;
} |
| 934 | 934 |
| 935 class GLEffect : public GrGLEffect { | 935 class GLEffect : public GrGLEffect { |
| 936 public: | 936 public: |
| 937 GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) | 937 GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) |
| 938 : GrGLEffect(factory ) | 938 : GrGLEffect(factory) { |
| 939 , fBackgroundEffectMatrix(kCoordsType) { | |
| 940 } | 939 } |
| 941 virtual void emitCode(GrGLShaderBuilder* builder, | 940 virtual void emitCode(GrGLShaderBuilder* builder, |
| 942 const GrDrawEffect& drawEffect, | 941 const GrDrawEffect& drawEffect, |
| 943 EffectKey key, | 942 EffectKey key, |
| 944 const char* outputColor, | 943 const char* outputColor, |
| 945 const char* inputColor, | 944 const char* inputColor, |
| 945 const TransformedCoordsArray& coords, |
| 946 const TextureSamplerArray& samplers) SK_OVERRIDE { | 946 const TextureSamplerArray& samplers) SK_OVERRIDE { |
| 947 SkXfermode::Mode mode = drawEffect.castEffect<XferEffect>().mode(); | 947 SkXfermode::Mode mode = drawEffect.castEffect<XferEffect>().mode(); |
| 948 const GrTexture* backgroundTex = drawEffect.castEffect<XferEffect>()
.backgroundAccess().getTexture(); | 948 const GrTexture* backgroundTex = drawEffect.castEffect<XferEffect>()
.backgroundAccess().getTexture(); |
| 949 const char* dstColor; | 949 const char* dstColor; |
| 950 if (backgroundTex) { | 950 if (backgroundTex) { |
| 951 SkString bgCoords; | |
| 952 GrSLType bgCoordsType = fBackgroundEffectMatrix.emitCode(builder
, key, &bgCoords, NULL, "BG"); | |
| 953 dstColor = "bgColor"; | 951 dstColor = "bgColor"; |
| 954 builder->fsCodeAppendf("\t\tvec4 %s = ", dstColor); | 952 builder->fsCodeAppendf("\t\tvec4 %s = ", dstColor); |
| 955 builder->fsAppendTextureLookup(samplers[0], bgCoords.c_str(), bg
CoordsType); | 953 builder->fsAppendTextureLookup(samplers[0], coords[0].c_str(), c
oords[0].type()); |
| 956 builder->fsCodeAppendf(";\n"); | 954 builder->fsCodeAppendf(";\n"); |
| 957 } else { | 955 } else { |
| 958 dstColor = builder->dstColor(); | 956 dstColor = builder->dstColor(); |
| 959 } | 957 } |
| 960 SkASSERT(NULL != dstColor); | 958 SkASSERT(NULL != dstColor); |
| 961 | 959 |
| 962 // We don't try to optimize for this case at all | 960 // We don't try to optimize for this case at all |
| 963 if (NULL == inputColor) { | 961 if (NULL == inputColor) { |
| 964 builder->fsCodeAppendf("\t\tconst vec4 ones = %s;\n", GrGLSLOnes
Vecf(4)); | 962 builder->fsCodeAppendf("\t\tconst vec4 ones = %s;\n", GrGLSLOnes
Vecf(4)); |
| 965 inputColor = "ones"; | 963 inputColor = "ones"; |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1081 outputColor, inputColor, dstColor, ds
tColor, inputColor); | 1079 outputColor, inputColor, dstColor, ds
tColor, inputColor); |
| 1082 break; | 1080 break; |
| 1083 } | 1081 } |
| 1084 default: | 1082 default: |
| 1085 GrCrash("Unknown XferEffect mode."); | 1083 GrCrash("Unknown XferEffect mode."); |
| 1086 break; | 1084 break; |
| 1087 } | 1085 } |
| 1088 } | 1086 } |
| 1089 | 1087 |
| 1090 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrG
LCaps&) { | 1088 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrG
LCaps&) { |
| 1091 const XferEffect& xfer = drawEffect.castEffect<XferEffect>(); | 1089 return drawEffect.castEffect<XferEffect>().mode(); |
| 1092 GrTexture* bgTex = xfer.backgroundAccess().getTexture(); | |
| 1093 EffectKey bgKey = 0; | |
| 1094 if (bgTex) { | |
| 1095 bgKey = GrGLEffectMatrix::GenKey(GrEffect::MakeDivByTextureWHMat
rix(bgTex), | |
| 1096 drawEffect, | |
| 1097 GLEffect::kCoordsType, | |
| 1098 bgTex); | |
| 1099 } | |
| 1100 EffectKey modeKey = xfer.mode() << GrGLEffectMatrix::kKeyBits; | |
| 1101 return modeKey | bgKey; | |
| 1102 } | |
| 1103 | |
| 1104 virtual void setData(const GrGLUniformManager& uman, const GrDrawEffect&
drawEffect) SK_OVERRIDE { | |
| 1105 const XferEffect& xfer = drawEffect.castEffect<XferEffect>(); | |
| 1106 GrTexture* bgTex = xfer.backgroundAccess().getTexture(); | |
| 1107 if (bgTex) { | |
| 1108 fBackgroundEffectMatrix.setData(uman, | |
| 1109 GrEffect::MakeDivByTextureWHMatr
ix(bgTex), | |
| 1110 drawEffect, | |
| 1111 bgTex); | |
| 1112 } | |
| 1113 } | 1090 } |
| 1114 | 1091 |
| 1115 private: | 1092 private: |
| 1116 static void HardLight(GrGLShaderBuilder* builder, | 1093 static void HardLight(GrGLShaderBuilder* builder, |
| 1117 const char* final, | 1094 const char* final, |
| 1118 const char* src, | 1095 const char* src, |
| 1119 const char* dst) { | 1096 const char* dst) { |
| 1120 static const char kComponents[] = {'r', 'g', 'b'}; | 1097 static const char kComponents[] = {'r', 'g', 'b'}; |
| 1121 for (size_t i = 0; i < SK_ARRAY_COUNT(kComponents); ++i) { | 1098 for (size_t i = 0; i < SK_ARRAY_COUNT(kComponents); ++i) { |
| 1122 char component = kComponents[i]; | 1099 char component = kComponents[i]; |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1322 getFunction.c_str(), helpFunc, helpFunc, helpFunc
, helpFunc, | 1299 getFunction.c_str(), helpFunc, helpFunc, helpFunc
, helpFunc, |
| 1323 helpFunc, helpFunc); | 1300 helpFunc, helpFunc); |
| 1324 builder->fsEmitFunction(kVec3f_GrSLType, | 1301 builder->fsEmitFunction(kVec3f_GrSLType, |
| 1325 "set_saturation", | 1302 "set_saturation", |
| 1326 SK_ARRAY_COUNT(setSatArgs), setSatArgs, | 1303 SK_ARRAY_COUNT(setSatArgs), setSatArgs, |
| 1327 setSatBody.c_str(), | 1304 setSatBody.c_str(), |
| 1328 setSatFunction); | 1305 setSatFunction); |
| 1329 | 1306 |
| 1330 } | 1307 } |
| 1331 | 1308 |
| 1332 static const GrEffect::CoordsType kCoordsType = GrEffect::kLocal_CoordsT
ype; | |
| 1333 GrGLEffectMatrix fBackgroundEffectMatrix; | |
| 1334 typedef GrGLEffect INHERITED; | 1309 typedef GrGLEffect INHERITED; |
| 1335 }; | 1310 }; |
| 1336 | 1311 |
| 1337 GR_DECLARE_EFFECT_TEST; | 1312 GR_DECLARE_EFFECT_TEST; |
| 1338 | 1313 |
| 1339 private: | 1314 private: |
| 1340 XferEffect(SkXfermode::Mode mode, GrTexture* background) | 1315 XferEffect(SkXfermode::Mode mode, GrTexture* background) |
| 1341 : fMode(mode) { | 1316 : fMode(mode) { |
| 1342 if (background) { | 1317 if (background) { |
| 1318 fBackgroundTransform.reset(kLocal_GrCoordSet, background); |
| 1319 this->addCoordTransform(&fBackgroundTransform); |
| 1343 fBackgroundAccess.reset(background); | 1320 fBackgroundAccess.reset(background); |
| 1344 this->addTextureAccess(&fBackgroundAccess); | 1321 this->addTextureAccess(&fBackgroundAccess); |
| 1345 } else { | 1322 } else { |
| 1346 this->setWillReadDstColor(); | 1323 this->setWillReadDstColor(); |
| 1347 } | 1324 } |
| 1348 } | 1325 } |
| 1349 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE { | 1326 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE { |
| 1350 const XferEffect& s = CastEffect<XferEffect>(other); | 1327 const XferEffect& s = CastEffect<XferEffect>(other); |
| 1351 return fMode == s.fMode && | 1328 return fMode == s.fMode && |
| 1352 fBackgroundAccess.getTexture() == s.fBackgroundAccess.getTexture(
); | 1329 fBackgroundAccess.getTexture() == s.fBackgroundAccess.getTexture(
); |
| 1353 } | 1330 } |
| 1354 | 1331 |
| 1355 SkXfermode::Mode fMode; | 1332 SkXfermode::Mode fMode; |
| 1333 GrCoordTransform fBackgroundTransform; |
| 1356 GrTextureAccess fBackgroundAccess; | 1334 GrTextureAccess fBackgroundAccess; |
| 1357 | 1335 |
| 1358 typedef GrEffect INHERITED; | 1336 typedef GrEffect INHERITED; |
| 1359 }; | 1337 }; |
| 1360 | 1338 |
| 1361 GR_DEFINE_EFFECT_TEST(XferEffect); | 1339 GR_DEFINE_EFFECT_TEST(XferEffect); |
| 1362 GrEffectRef* XferEffect::TestCreate(SkRandom* rand, | 1340 GrEffectRef* XferEffect::TestCreate(SkRandom* rand, |
| 1363 GrContext*, | 1341 GrContext*, |
| 1364 const GrDrawTargetCaps&, | 1342 const GrDrawTargetCaps&, |
| 1365 GrTexture*[]) { | 1343 GrTexture*[]) { |
| (...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1963 return proc16; | 1941 return proc16; |
| 1964 } | 1942 } |
| 1965 | 1943 |
| 1966 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkXfermode) | 1944 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkXfermode) |
| 1967 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkProcCoeffXfermode) | 1945 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkProcCoeffXfermode) |
| 1968 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkClearXfermode) | 1946 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkClearXfermode) |
| 1969 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSrcXfermode) | 1947 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSrcXfermode) |
| 1970 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDstInXfermode) | 1948 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDstInXfermode) |
| 1971 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDstOutXfermode) | 1949 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDstOutXfermode) |
| 1972 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 1950 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
| OLD | NEW |