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 #include "SkXfermode.h" | 9 #include "SkXfermode.h" |
10 #include "SkXfermode_proccoeff.h" | 10 #include "SkXfermode_proccoeff.h" |
11 #include "SkColorPriv.h" | 11 #include "SkColorPriv.h" |
| 12 #include "SkLazyPtr.h" |
12 #include "SkMathPriv.h" | 13 #include "SkMathPriv.h" |
13 #include "SkOncePtr.h" | |
14 #include "SkOpts.h" | 14 #include "SkOpts.h" |
15 #include "SkReadBuffer.h" | 15 #include "SkReadBuffer.h" |
16 #include "SkString.h" | 16 #include "SkString.h" |
17 #include "SkWriteBuffer.h" | 17 #include "SkWriteBuffer.h" |
18 | 18 |
19 #define SkAlphaMulAlpha(a, b) SkMulDiv255Round(a, b) | 19 #define SkAlphaMulAlpha(a, b) SkMulDiv255Round(a, b) |
20 | 20 |
21 static inline unsigned saturated_add(unsigned a, unsigned b) { | 21 static inline unsigned saturated_add(unsigned a, unsigned b) { |
22 SkASSERT(a <= 255); | 22 SkASSERT(a <= 255); |
23 SkASSERT(b <= 255); | 23 SkASSERT(b <= 255); |
(...skipping 965 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
989 str->append(" dst: "); | 989 str->append(" dst: "); |
990 if (CANNOT_USE_COEFF == fDstCoeff) { | 990 if (CANNOT_USE_COEFF == fDstCoeff) { |
991 str->append("can't use"); | 991 str->append("can't use"); |
992 } else { | 992 } else { |
993 str->append(gCoeffStrings[fDstCoeff]); | 993 str->append(gCoeffStrings[fDstCoeff]); |
994 } | 994 } |
995 } | 995 } |
996 #endif | 996 #endif |
997 | 997 |
998 | 998 |
999 SK_DECLARE_STATIC_ONCE_PTR(SkXfermode, cached[SkXfermode::kLastMode + 1]); | 999 // Technically, can't be static and passed as a template parameter. So we use a
nonymous namespace. |
| 1000 namespace { |
| 1001 SkXfermode* create_mode(int iMode) { |
| 1002 SkXfermode::Mode mode = (SkXfermode::Mode)iMode; |
| 1003 |
| 1004 ProcCoeff rec = gProcCoeffs[mode]; |
| 1005 if (auto xfermode = SkOpts::create_xfermode(rec, mode)) { |
| 1006 return xfermode; |
| 1007 } |
| 1008 return new SkProcCoeffXfermode(rec, mode); |
| 1009 } |
| 1010 } // namespace |
| 1011 |
| 1012 SK_DECLARE_STATIC_LAZY_PTR_ARRAY(SkXfermode, cached, SkXfermode::kLastMode + 1,
create_mode); |
1000 | 1013 |
1001 SkXfermode* SkXfermode::Create(Mode mode) { | 1014 SkXfermode* SkXfermode::Create(Mode mode) { |
1002 SkASSERT(SK_ARRAY_COUNT(gProcCoeffs) == kModeCount); | 1015 SkASSERT(SK_ARRAY_COUNT(gProcCoeffs) == kModeCount); |
1003 | 1016 |
1004 if ((unsigned)mode >= kModeCount) { | 1017 if ((unsigned)mode >= kModeCount) { |
1005 // report error | 1018 // report error |
1006 return nullptr; | 1019 return nullptr; |
1007 } | 1020 } |
1008 | 1021 |
1009 // Skia's "default" mode is srcover. nullptr in SkPaint is interpreted as sr
cover | 1022 // Skia's "default" mode is srcover. nullptr in SkPaint is interpreted as sr
cover |
1010 // so we can just return nullptr from the factory. | 1023 // so we can just return nullptr from the factory. |
1011 if (kSrcOver_Mode == mode) { | 1024 if (kSrcOver_Mode == mode) { |
1012 return nullptr; | 1025 return nullptr; |
1013 } | 1026 } |
1014 | 1027 |
1015 return SkSafeRef(cached[mode].get([=]{ | 1028 return SkSafeRef(cached[mode]); |
1016 ProcCoeff rec = gProcCoeffs[mode]; | |
1017 if (auto xfermode = SkOpts::create_xfermode(rec, mode)) { | |
1018 return xfermode; | |
1019 } | |
1020 return (SkXfermode*) new SkProcCoeffXfermode(rec, mode); | |
1021 })); | |
1022 } | 1029 } |
1023 | 1030 |
1024 SkXfermodeProc SkXfermode::GetProc(Mode mode) { | 1031 SkXfermodeProc SkXfermode::GetProc(Mode mode) { |
1025 SkXfermodeProc proc = nullptr; | 1032 SkXfermodeProc proc = nullptr; |
1026 if ((unsigned)mode < kModeCount) { | 1033 if ((unsigned)mode < kModeCount) { |
1027 proc = gProcCoeffs[mode].fProc; | 1034 proc = gProcCoeffs[mode].fProc; |
1028 } | 1035 } |
1029 return proc; | 1036 return proc; |
1030 } | 1037 } |
1031 | 1038 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1086 if (!xfer) { | 1093 if (!xfer) { |
1087 return SkXfermode::kOpaque_SrcColorOpacity == opacityType; | 1094 return SkXfermode::kOpaque_SrcColorOpacity == opacityType; |
1088 } | 1095 } |
1089 | 1096 |
1090 return xfer->isOpaque(opacityType); | 1097 return xfer->isOpaque(opacityType); |
1091 } | 1098 } |
1092 | 1099 |
1093 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkXfermode) | 1100 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkXfermode) |
1094 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkProcCoeffXfermode) | 1101 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkProcCoeffXfermode) |
1095 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 1102 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |