Index: src/core/SkXfermode.cpp |
diff --git a/src/core/SkXfermode.cpp b/src/core/SkXfermode.cpp |
index b6d23888a741d7611eb4c7a72c7937680b045d96..1cfe8647511088cea117a28b9438691e6abd4eb3 100644 |
--- a/src/core/SkXfermode.cpp |
+++ b/src/core/SkXfermode.cpp |
@@ -9,7 +9,7 @@ |
#include "SkXfermode_proccoeff.h" |
#include "SkColorPriv.h" |
#include "SkMathPriv.h" |
-#include "SkOnce.h" |
+#include "SkOncePtr.h" |
#include "SkOpts.h" |
#include "SkReadBuffer.h" |
#include "SkString.h" |
@@ -1303,7 +1303,11 @@ |
#endif |
+SK_DECLARE_STATIC_ONCE_PTR(SkXfermode, cached[SkXfermode::kLastMode + 1]); |
+ |
sk_sp<SkXfermode> SkXfermode::Make(Mode mode) { |
+ SkASSERT(SK_ARRAY_COUNT(gProcCoeffs) == kModeCount); |
+ |
if ((unsigned)mode >= kModeCount) { |
// report error |
return nullptr; |
@@ -1315,20 +1319,13 @@ |
return nullptr; |
} |
- SkASSERT(SK_ARRAY_COUNT(gProcCoeffs) == kModeCount); |
- |
- static SkOnce once[SkXfermode::kLastMode+1]; |
- static SkXfermode* cached[SkXfermode::kLastMode+1]; |
- |
- once[mode]([mode] { |
+ return sk_ref_sp(cached[mode].get([=]{ |
ProcCoeff rec = gProcCoeffs[mode]; |
if (auto xfermode = SkOpts::create_xfermode(rec, mode)) { |
- cached[mode] = xfermode; |
- } else { |
- cached[mode] = new SkProcCoeffXfermode(rec, mode); |
+ return xfermode; |
} |
- }); |
- return sk_ref_sp(cached[mode]); |
+ return (SkXfermode*) new SkProcCoeffXfermode(rec, mode); |
+ })); |
} |
SkXfermodeProc SkXfermode::GetProc(Mode mode) { |