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

Unified Diff: src/core/SkMatrix.cpp

Issue 306063004: Revert of Port most uses of SkOnce to SkLazyPtr. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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/SkLazyPtr.h ('k') | src/core/SkMessageBus.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkMatrix.cpp
diff --git a/src/core/SkMatrix.cpp b/src/core/SkMatrix.cpp
index 8778f78f4105f833a7cb10f5cb48b137f625a1b2..40f6e5298d9375df55a8822b2a0c2372b1b0f116 100644
--- a/src/core/SkMatrix.cpp
+++ b/src/core/SkMatrix.cpp
@@ -7,7 +7,7 @@
#include "SkMatrix.h"
#include "SkFloatBits.h"
-#include "SkLazyPtr.h"
+#include "SkOnce.h"
#include "SkString.h"
// In a few places, we performed the following
@@ -1558,33 +1558,29 @@
return get_scale_factor<kBoth_MinMaxOrBoth>(this->getType(), fMat, scaleFactors);
}
-namespace {
-
-SkMatrix* create_identity() {
- SkMatrix* m = SkNEW(SkMatrix);
- m->reset();
- return m;
-}
-
-SkMatrix* create_invalid() {
- SkMatrix* m = SkNEW(SkMatrix);
- m->setAll(SK_ScalarMax, SK_ScalarMax, SK_ScalarMax,
- SK_ScalarMax, SK_ScalarMax, SK_ScalarMax,
- SK_ScalarMax, SK_ScalarMax, SK_ScalarMax);
- m->getType(); // Force the type to be computed.
- return m;
-}
-
-} // namespace
+static void reset_identity_matrix(SkMatrix* identity) {
+ identity->reset();
+}
const SkMatrix& SkMatrix::I() {
- SK_DECLARE_STATIC_LAZY_PTR(SkMatrix, identity, create_identity);
- return *identity.get();
+ // If you can use C++11 now, you might consider replacing this with a constexpr constructor.
+ static SkMatrix gIdentity;
+ SK_DECLARE_STATIC_ONCE(once);
+ SkOnce(&once, reset_identity_matrix, &gIdentity);
+ return gIdentity;
}
const SkMatrix& SkMatrix::InvalidMatrix() {
- SK_DECLARE_STATIC_LAZY_PTR(SkMatrix, invalid, create_invalid);
- return *invalid.get();
+ static SkMatrix gInvalid;
+ static bool gOnce;
+ if (!gOnce) {
+ gInvalid.setAll(SK_ScalarMax, SK_ScalarMax, SK_ScalarMax,
+ SK_ScalarMax, SK_ScalarMax, SK_ScalarMax,
+ SK_ScalarMax, SK_ScalarMax, SK_ScalarMax);
+ gInvalid.getType(); // force the type to be computed
+ gOnce = true;
+ }
+ return gInvalid;
}
///////////////////////////////////////////////////////////////////////////////
« no previous file with comments | « src/core/SkLazyPtr.h ('k') | src/core/SkMessageBus.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698