Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: src/core/SkXfermode.cpp

Issue 1322933005: Port uses of SkLazyPtr to SkOncePtr. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: name Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkTypeface.cpp ('k') | src/fonts/SkRemotableFontMgr.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
13 #include "SkMathPriv.h" 12 #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
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 // Technically, can't be static and passed as a template parameter. So we use a nonymous namespace. 999 SK_DECLARE_STATIC_ONCE_PTR(SkXfermode, cached[SkXfermode::kLastMode + 1]);
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);
1013 1000
1014 SkXfermode* SkXfermode::Create(Mode mode) { 1001 SkXfermode* SkXfermode::Create(Mode mode) {
1015 SkASSERT(SK_ARRAY_COUNT(gProcCoeffs) == kModeCount); 1002 SkASSERT(SK_ARRAY_COUNT(gProcCoeffs) == kModeCount);
1016 1003
1017 if ((unsigned)mode >= kModeCount) { 1004 if ((unsigned)mode >= kModeCount) {
1018 // report error 1005 // report error
1019 return nullptr; 1006 return nullptr;
1020 } 1007 }
1021 1008
1022 // Skia's "default" mode is srcover. nullptr in SkPaint is interpreted as sr cover 1009 // Skia's "default" mode is srcover. nullptr in SkPaint is interpreted as sr cover
1023 // so we can just return nullptr from the factory. 1010 // so we can just return nullptr from the factory.
1024 if (kSrcOver_Mode == mode) { 1011 if (kSrcOver_Mode == mode) {
1025 return nullptr; 1012 return nullptr;
1026 } 1013 }
1027 1014
1028 return SkSafeRef(cached[mode]); 1015 return SkSafeRef(cached[mode].get([=]{
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 }));
1029 } 1022 }
1030 1023
1031 SkXfermodeProc SkXfermode::GetProc(Mode mode) { 1024 SkXfermodeProc SkXfermode::GetProc(Mode mode) {
1032 SkXfermodeProc proc = nullptr; 1025 SkXfermodeProc proc = nullptr;
1033 if ((unsigned)mode < kModeCount) { 1026 if ((unsigned)mode < kModeCount) {
1034 proc = gProcCoeffs[mode].fProc; 1027 proc = gProcCoeffs[mode].fProc;
1035 } 1028 }
1036 return proc; 1029 return proc;
1037 } 1030 }
1038 1031
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 if (!xfer) { 1086 if (!xfer) {
1094 return SkXfermode::kOpaque_SrcColorOpacity == opacityType; 1087 return SkXfermode::kOpaque_SrcColorOpacity == opacityType;
1095 } 1088 }
1096 1089
1097 return xfer->isOpaque(opacityType); 1090 return xfer->isOpaque(opacityType);
1098 } 1091 }
1099 1092
1100 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkXfermode) 1093 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkXfermode)
1101 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkProcCoeffXfermode) 1094 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkProcCoeffXfermode)
1102 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 1095 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
OLDNEW
« no previous file with comments | « src/core/SkTypeface.cpp ('k') | src/fonts/SkRemotableFontMgr.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698