Index: src/core/SkXfermode.cpp |
diff --git a/src/core/SkXfermode.cpp b/src/core/SkXfermode.cpp |
index 18ab9b6a0a6347a45771673fddd32121a19ca0c6..8548fe8aaca251fcac622864270496a92516039d 100644 |
--- a/src/core/SkXfermode.cpp |
+++ b/src/core/SkXfermode.cpp |
@@ -9,8 +9,8 @@ |
#include "SkXfermode.h" |
#include "SkXfermode_proccoeff.h" |
#include "SkColorPriv.h" |
-#include "SkLazyPtr.h" |
#include "SkMathPriv.h" |
+#include "SkOncePtr.h" |
#include "SkOpts.h" |
#include "SkReadBuffer.h" |
#include "SkString.h" |
@@ -996,20 +996,7 @@ void SkProcCoeffXfermode::toString(SkString* str) const { |
#endif |
-// Technically, can't be static and passed as a template parameter. So we use anonymous namespace. |
-namespace { |
-SkXfermode* create_mode(int iMode) { |
- SkXfermode::Mode mode = (SkXfermode::Mode)iMode; |
- |
- ProcCoeff rec = gProcCoeffs[mode]; |
- if (auto xfermode = SkOpts::create_xfermode(rec, mode)) { |
- return xfermode; |
- } |
- return new SkProcCoeffXfermode(rec, mode); |
-} |
-} // namespace |
- |
-SK_DECLARE_STATIC_LAZY_PTR_ARRAY(SkXfermode, cached, SkXfermode::kLastMode + 1, create_mode); |
+SK_DECLARE_STATIC_ONCE_PTR(SkXfermode, cached[SkXfermode::kLastMode + 1]); |
SkXfermode* SkXfermode::Create(Mode mode) { |
SkASSERT(SK_ARRAY_COUNT(gProcCoeffs) == kModeCount); |
@@ -1025,7 +1012,13 @@ SkXfermode* SkXfermode::Create(Mode mode) { |
return nullptr; |
} |
- return SkSafeRef(cached[mode]); |
+ return SkSafeRef(cached[mode].get([=]{ |
+ ProcCoeff rec = gProcCoeffs[mode]; |
+ if (auto xfermode = SkOpts::create_xfermode(rec, mode)) { |
+ return xfermode; |
+ } |
+ return (SkXfermode*) new SkProcCoeffXfermode(rec, mode); |
+ })); |
} |
SkXfermodeProc SkXfermode::GetProc(Mode mode) { |