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

Unified Diff: src/core/SkXfermode.cpp

Issue 306943003: SkLazyPtr, mk. 2 (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: drop static Created 6 years, 7 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/SkThreadPriv.h ('k') | no next file » | 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 182d3b7197ce20b168275fdd10f73bb25b53f830..b5f95dad51bc9fca81073e6e4908c0a3243f97d2 100644
--- a/src/core/SkXfermode.cpp
+++ b/src/core/SkXfermode.cpp
@@ -11,8 +11,8 @@
#include "SkXfermode_opts_SSE2.h"
#include "SkXfermode_proccoeff.h"
#include "SkColorPriv.h"
+#include "SkLazyPtr.h"
#include "SkMathPriv.h"
-#include "SkOnce.h"
#include "SkReadBuffer.h"
#include "SkString.h"
#include "SkUtilsArm.h"
@@ -1651,26 +1651,13 @@ void SkDstOutXfermode::toString(SkString* str) const {
///////////////////////////////////////////////////////////////////////////////
-SK_DECLARE_STATIC_MUTEX(gCachedXfermodesMutex);
-static SkXfermode* gCachedXfermodes[SkXfermode::kLastMode + 1]; // All NULL to start.
-static bool gXfermodeCached[SK_ARRAY_COUNT(gCachedXfermodes)]; // All false to start.
-
-void SkXfermode::Term() {
- SkAutoMutexAcquire ac(gCachedXfermodesMutex);
-
- for (size_t i = 0; i < SK_ARRAY_COUNT(gCachedXfermodes); ++i) {
- SkSafeUnref(gCachedXfermodes[i]);
- gCachedXfermodes[i] = NULL;
- }
-}
-
-extern SkProcCoeffXfermode* SkPlatformXfermodeFactory(const ProcCoeff& rec,
- SkXfermode::Mode mode);
+extern SkProcCoeffXfermode* SkPlatformXfermodeFactory(const ProcCoeff& rec, SkXfermode::Mode mode);
extern SkXfermodeProc SkPlatformXfermodeProcFactory(SkXfermode::Mode mode);
-
-static void create_mode(SkXfermode::Mode mode) {
- SkASSERT(NULL == gCachedXfermodes[mode]);
+// 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];
SkXfermodeProc pp = SkPlatformXfermodeProcFactory(mode);
@@ -1709,28 +1696,27 @@ static void create_mode(SkXfermode::Mode mode) {
break;
}
}
- gCachedXfermodes[mode] = xfer;
+ return xfer;
}
+} // namespace
+
SkXfermode* SkXfermode::Create(Mode mode) {
SkASSERT(SK_ARRAY_COUNT(gProcCoeffs) == kModeCount);
- SkASSERT(SK_ARRAY_COUNT(gCachedXfermodes) == kModeCount);
if ((unsigned)mode >= kModeCount) {
// report error
return NULL;
}
- // Skia's "defaut" mode is srcover. NULL in SkPaint is interpreted as srcover
+ // Skia's "default" mode is srcover. NULL in SkPaint is interpreted as srcover
// so we can just return NULL from the factory.
if (kSrcOver_Mode == mode) {
return NULL;
}
- SkOnce(&gXfermodeCached[mode], &gCachedXfermodesMutex, create_mode, mode);
- SkXfermode* xfer = gCachedXfermodes[mode];
- SkASSERT(xfer != NULL);
- return SkSafeRef(xfer);
+ SK_DECLARE_STATIC_LAZY_PTR_ARRAY(SkXfermode, cached, kModeCount, create_mode);
+ return SkSafeRef(cached[mode]);
}
SkXfermodeProc SkXfermode::GetProc(Mode mode) {
« no previous file with comments | « src/core/SkThreadPriv.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698