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 "SkXfermode.h" | 8 #include "SkXfermode.h" |
9 #include "SkXfermode_proccoeff.h" | 9 #include "SkXfermode_proccoeff.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
(...skipping 1079 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1090 } | 1090 } |
1091 | 1091 |
1092 /////////////////////////////////////////////////////////////////////////////// | 1092 /////////////////////////////////////////////////////////////////////////////// |
1093 /////////////////////////////////////////////////////////////////////////////// | 1093 /////////////////////////////////////////////////////////////////////////////// |
1094 | 1094 |
1095 SkFlattenable* SkProcCoeffXfermode::CreateProc(SkReadBuffer& buffer) { | 1095 SkFlattenable* SkProcCoeffXfermode::CreateProc(SkReadBuffer& buffer) { |
1096 uint32_t mode32 = buffer.read32(); | 1096 uint32_t mode32 = buffer.read32(); |
1097 if (!buffer.validate(mode32 < SK_ARRAY_COUNT(gProcCoeffs))) { | 1097 if (!buffer.validate(mode32 < SK_ARRAY_COUNT(gProcCoeffs))) { |
1098 return nullptr; | 1098 return nullptr; |
1099 } | 1099 } |
1100 return SkXfermode::Create((SkXfermode::Mode)mode32); | 1100 return SkXfermode::Make((SkXfermode::Mode)mode32).release(); |
1101 } | 1101 } |
1102 | 1102 |
1103 void SkProcCoeffXfermode::flatten(SkWriteBuffer& buffer) const { | 1103 void SkProcCoeffXfermode::flatten(SkWriteBuffer& buffer) const { |
1104 buffer.write32(fMode); | 1104 buffer.write32(fMode); |
1105 } | 1105 } |
1106 | 1106 |
1107 bool SkProcCoeffXfermode::asMode(Mode* mode) const { | 1107 bool SkProcCoeffXfermode::asMode(Mode* mode) const { |
1108 if (mode) { | 1108 if (mode) { |
1109 *mode = fMode; | 1109 *mode = fMode; |
1110 } | 1110 } |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1298 str->append("can't use"); | 1298 str->append("can't use"); |
1299 } else { | 1299 } else { |
1300 str->append(gCoeffStrings[fDstCoeff]); | 1300 str->append(gCoeffStrings[fDstCoeff]); |
1301 } | 1301 } |
1302 } | 1302 } |
1303 #endif | 1303 #endif |
1304 | 1304 |
1305 | 1305 |
1306 SK_DECLARE_STATIC_ONCE_PTR(SkXfermode, cached[SkXfermode::kLastMode + 1]); | 1306 SK_DECLARE_STATIC_ONCE_PTR(SkXfermode, cached[SkXfermode::kLastMode + 1]); |
1307 | 1307 |
1308 SkXfermode* SkXfermode::Create(Mode mode) { | 1308 sk_sp<SkXfermode> SkXfermode::Make(Mode mode) { |
1309 SkASSERT(SK_ARRAY_COUNT(gProcCoeffs) == kModeCount); | 1309 SkASSERT(SK_ARRAY_COUNT(gProcCoeffs) == kModeCount); |
1310 | 1310 |
1311 if ((unsigned)mode >= kModeCount) { | 1311 if ((unsigned)mode >= kModeCount) { |
1312 // report error | 1312 // report error |
1313 return nullptr; | 1313 return nullptr; |
1314 } | 1314 } |
1315 | 1315 |
1316 // Skia's "default" mode is srcover. nullptr in SkPaint is interpreted as sr
cover | 1316 // Skia's "default" mode is srcover. nullptr in SkPaint is interpreted as sr
cover |
1317 // so we can just return nullptr from the factory. | 1317 // so we can just return nullptr from the factory. |
1318 if (kSrcOver_Mode == mode) { | 1318 if (kSrcOver_Mode == mode) { |
1319 return nullptr; | 1319 return nullptr; |
1320 } | 1320 } |
1321 | 1321 |
1322 return SkSafeRef(cached[mode].get([=]{ | 1322 return sk_ref_sp(cached[mode].get([=]{ |
1323 ProcCoeff rec = gProcCoeffs[mode]; | 1323 ProcCoeff rec = gProcCoeffs[mode]; |
1324 if (auto xfermode = SkOpts::create_xfermode(rec, mode)) { | 1324 if (auto xfermode = SkOpts::create_xfermode(rec, mode)) { |
1325 return xfermode; | 1325 return xfermode; |
1326 } | 1326 } |
1327 return (SkXfermode*) new SkProcCoeffXfermode(rec, mode); | 1327 return (SkXfermode*) new SkProcCoeffXfermode(rec, mode); |
1328 })); | 1328 })); |
1329 } | 1329 } |
1330 | 1330 |
1331 SkXfermodeProc SkXfermode::GetProc(Mode mode) { | 1331 SkXfermodeProc SkXfermode::GetProc(Mode mode) { |
1332 SkXfermodeProc proc = nullptr; | 1332 SkXfermodeProc proc = nullptr; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1410 if (!xfer) { | 1410 if (!xfer) { |
1411 return SkXfermode::kOpaque_SrcColorOpacity == opacityType; | 1411 return SkXfermode::kOpaque_SrcColorOpacity == opacityType; |
1412 } | 1412 } |
1413 | 1413 |
1414 return xfer->isOpaque(opacityType); | 1414 return xfer->isOpaque(opacityType); |
1415 } | 1415 } |
1416 | 1416 |
1417 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkXfermode) | 1417 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkXfermode) |
1418 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkProcCoeffXfermode) | 1418 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkProcCoeffXfermode) |
1419 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 1419 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |