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 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 /////////////////////////////////////////////////////////////////////////////// | 673 /////////////////////////////////////////////////////////////////////////////// |
674 | 674 |
675 bool SkXfermode::asCoeff(Coeff* src, Coeff* dst) const { | 675 bool SkXfermode::asCoeff(Coeff* src, Coeff* dst) const { |
676 return false; | 676 return false; |
677 } | 677 } |
678 | 678 |
679 bool SkXfermode::asMode(Mode* mode) const { | 679 bool SkXfermode::asMode(Mode* mode) const { |
680 return false; | 680 return false; |
681 } | 681 } |
682 | 682 |
683 bool SkXfermode::asNewEffect(GrContext*, GrEffectRef**, Coeff*, Coeff*) const { | 683 bool SkXfermode::asNewEffectOrCoeff(GrContext*, GrEffectRef**, Coeff* src, Coeff
* dst) const { |
684 return false; | 684 return this->asCoeff(src, dst); |
685 } | 685 } |
686 | 686 |
687 bool SkXfermode::AsNewEffect(SkXfermode* xfermode, | 687 bool SkXfermode::AsNewEffectOrCoeff(SkXfermode* xfermode, |
688 GrContext* context, | 688 GrContext* context, |
689 GrEffectRef** effect, | 689 GrEffectRef** effect, |
690 Coeff* src, | 690 Coeff* src, |
691 Coeff* dst) { | 691 Coeff* dst) { |
692 if (NULL == xfermode) { | 692 if (NULL == xfermode) { |
693 return ModeAsCoeff(kSrcOver_Mode, src, dst); | 693 return ModeAsCoeff(kSrcOver_Mode, src, dst); |
694 } else { | 694 } else { |
695 return xfermode->asNewEffect(context, effect, src, dst); | 695 return xfermode->asNewEffectOrCoeff(context, effect, src, dst); |
696 } | 696 } |
697 } | 697 } |
698 | 698 |
699 SkPMColor SkXfermode::xferColor(SkPMColor src, SkPMColor dst) const{ | 699 SkPMColor SkXfermode::xferColor(SkPMColor src, SkPMColor dst) const{ |
700 // no-op. subclasses should override this | 700 // no-op. subclasses should override this |
701 return dst; | 701 return dst; |
702 } | 702 } |
703 | 703 |
704 void SkXfermode::xfer32(SkPMColor* SK_RESTRICT dst, | 704 void SkXfermode::xfer32(SkPMColor* SK_RESTRICT dst, |
705 const SkPMColor* SK_RESTRICT src, int count, | 705 const SkPMColor* SK_RESTRICT src, int count, |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
933 buffer.writeFunctionPtr((void*)fProc); | 933 buffer.writeFunctionPtr((void*)fProc); |
934 } | 934 } |
935 } | 935 } |
936 | 936 |
937 #ifdef SK_DEVELOPER | 937 #ifdef SK_DEVELOPER |
938 void SkProcXfermode::toString(SkString* str) const { | 938 void SkProcXfermode::toString(SkString* str) const { |
939 str->appendf("SkProcXfermode: %p", fProc); | 939 str->appendf("SkProcXfermode: %p", fProc); |
940 } | 940 } |
941 #endif | 941 #endif |
942 | 942 |
| 943 ////////////////////////////////////////////////////////////////////////////// |
| 944 |
| 945 #if SK_SUPPORT_GPU |
| 946 |
| 947 #include "GrEffect.h" |
| 948 #include "GrEffectUnitTest.h" |
| 949 #include "GrTBackendEffectFactory.h" |
| 950 #include "gl/GrGLEffect.h" |
| 951 |
| 952 /** |
| 953 * GrEffect that implements the kDarken_Mode Xfermode. It requires access to the
dst pixel color |
| 954 * in the shader. TODO: Make this work for all non-Coeff SkXfermode::Mode values
. |
| 955 */ |
| 956 class DarkenEffect : public GrEffect { |
| 957 public: |
| 958 static GrEffectRef* Create() { |
| 959 static AutoEffectUnref gEffect(SkNEW(DarkenEffect)); |
| 960 return CreateEffectRef(gEffect); |
| 961 } |
| 962 |
| 963 virtual void getConstantColorComponents(GrColor* color, |
| 964 uint32_t* validFlags) const SK_OVERR
IDE { |
| 965 *validFlags = 0; |
| 966 } |
| 967 |
| 968 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE { |
| 969 return GrTBackendEffectFactory<DarkenEffect>::getInstance(); |
| 970 } |
| 971 |
| 972 static const char* Name() { return "XfermodeDarken"; } |
| 973 |
| 974 class GLEffect : public GrGLEffect { |
| 975 public: |
| 976 GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) |
| 977 : GrGLEffect(factory ) { |
| 978 } |
| 979 virtual void emitCode(GrGLShaderBuilder* builder, |
| 980 const GrDrawEffect& drawEffect, |
| 981 EffectKey key, |
| 982 const char* outputColor, |
| 983 const char* inputColor, |
| 984 const TextureSamplerArray& samplers) SK_OVERRIDE { |
| 985 const char* dstColorName = builder->dstColor(); |
| 986 GrAssert(NULL != dstColorName); |
| 987 builder->fsCodeAppendf("\t\t%s.a = 1.0 - (1.0 - %s.a) * (1.0 - %s.a)
;\n", |
| 988 outputColor, dstColorName, inputColor); |
| 989 builder->fsCodeAppendf("\t\t%s.rgb = min((1.0 - %s.a) * %s.rgb + %s.
rgb," |
| 990 " (1.0 - %s.a) * %s.rgb + %s.
rgb);\n", |
| 991 outputColor, |
| 992 inputColor, dstColorName, inputColor, |
| 993 dstColorName, inputColor, dstColorName); |
| 994 } |
| 995 |
| 996 static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&) { r
eturn 0; } |
| 997 |
| 998 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_
OVERRIDE {} |
| 999 |
| 1000 private: |
| 1001 typedef GrGLEffect INHERITED; |
| 1002 }; |
| 1003 |
| 1004 GR_DECLARE_EFFECT_TEST; |
| 1005 |
| 1006 private: |
| 1007 DarkenEffect() { this->setWillReadDst(); } |
| 1008 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE { return tru
e; } |
| 1009 |
| 1010 typedef GrEffect INHERITED; |
| 1011 }; |
| 1012 |
| 1013 GR_DEFINE_EFFECT_TEST(DarkenEffect); |
| 1014 GrEffectRef* DarkenEffect::TestCreate(SkMWCRandom*, |
| 1015 GrContext*, |
| 1016 const GrDrawTargetCaps&, |
| 1017 GrTexture*[]) { |
| 1018 static AutoEffectUnref gEffect(SkNEW(DarkenEffect)); |
| 1019 return CreateEffectRef(gEffect); |
| 1020 } |
| 1021 |
| 1022 #endif |
| 1023 |
943 /////////////////////////////////////////////////////////////////////////////// | 1024 /////////////////////////////////////////////////////////////////////////////// |
944 /////////////////////////////////////////////////////////////////////////////// | 1025 /////////////////////////////////////////////////////////////////////////////// |
945 | 1026 |
946 class SkProcCoeffXfermode : public SkProcXfermode { | 1027 class SkProcCoeffXfermode : public SkProcXfermode { |
947 public: | 1028 public: |
948 SkProcCoeffXfermode(const ProcCoeff& rec, Mode mode) | 1029 SkProcCoeffXfermode(const ProcCoeff& rec, Mode mode) |
949 : INHERITED(rec.fProc) { | 1030 : INHERITED(rec.fProc) { |
950 fMode = mode; | 1031 fMode = mode; |
951 // these may be valid, or may be CANNOT_USE_COEFF | 1032 // these may be valid, or may be CANNOT_USE_COEFF |
952 fSrcCoeff = rec.fSC; | 1033 fSrcCoeff = rec.fSC; |
(...skipping 14 matching lines...) Expand all Loading... |
967 | 1048 |
968 if (sc) { | 1049 if (sc) { |
969 *sc = fSrcCoeff; | 1050 *sc = fSrcCoeff; |
970 } | 1051 } |
971 if (dc) { | 1052 if (dc) { |
972 *dc = fDstCoeff; | 1053 *dc = fDstCoeff; |
973 } | 1054 } |
974 return true; | 1055 return true; |
975 } | 1056 } |
976 | 1057 |
977 virtual bool asNewEffect(GrContext*, GrEffectRef**, Coeff* src, Coeff* dst)
const SK_OVERRIDE { | 1058 #if SK_SUPPORT_GPU |
978 return this->asCoeff(src, dst); | 1059 virtual bool asNewEffectOrCoeff(GrContext*, |
| 1060 GrEffectRef** effect, |
| 1061 Coeff* src, |
| 1062 Coeff* dst) const SK_OVERRIDE { |
| 1063 if (this->asCoeff(src, dst)) { |
| 1064 return true; |
| 1065 } |
| 1066 if (kDarken_Mode == fMode) { |
| 1067 if (NULL != effect) { |
| 1068 *effect = DarkenEffect::Create(); |
| 1069 } |
| 1070 return true; |
| 1071 } |
| 1072 return false; |
979 } | 1073 } |
| 1074 #endif |
980 | 1075 |
981 SK_DEVELOPER_TO_STRING() | 1076 SK_DEVELOPER_TO_STRING() |
982 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkProcCoeffXfermode) | 1077 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkProcCoeffXfermode) |
983 | 1078 |
984 protected: | 1079 protected: |
985 SkProcCoeffXfermode(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) { | 1080 SkProcCoeffXfermode(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) { |
986 fMode = (SkXfermode::Mode)buffer.read32(); | 1081 fMode = (SkXfermode::Mode)buffer.read32(); |
987 | 1082 |
988 const ProcCoeff& rec = gProcCoeffs[fMode]; | 1083 const ProcCoeff& rec = gProcCoeffs[fMode]; |
989 // these may be valid, or may be CANNOT_USE_COEFF | 1084 // these may be valid, or may be CANNOT_USE_COEFF |
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1510 return proc16; | 1605 return proc16; |
1511 } | 1606 } |
1512 | 1607 |
1513 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkXfermode) | 1608 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkXfermode) |
1514 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkProcCoeffXfermode) | 1609 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkProcCoeffXfermode) |
1515 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkClearXfermode) | 1610 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkClearXfermode) |
1516 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSrcXfermode) | 1611 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSrcXfermode) |
1517 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDstInXfermode) | 1612 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDstInXfermode) |
1518 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDstOutXfermode) | 1613 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDstOutXfermode) |
1519 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 1614 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |