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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkTypeface.cpp ('k') | src/fonts/SkRemotableFontMgr.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) {
« 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