aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkMatrix.cpp
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-05-30 20:42:00 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-05-30 20:42:00 +0000
commit5a70945ddd036b8079987954123ff8f382c285af (patch)
tree3bb2d0ee55d6732edc13c04d4f63050deea157e3 /src/core/SkMatrix.cpp
parent2a5cd60bfff32c92cf44a8cfc3e8c017b9aee456 (diff)
Port most uses of SkOnce to SkLazyPtr.
BUG=skia: R=reed@google.com, mtklein@google.com Author: mtklein@chromium.org Review URL: https://codereview.chromium.org/304383005 git-svn-id: http://skia.googlecode.com/svn/trunk@15006 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/core/SkMatrix.cpp')
-rw-r--r--src/core/SkMatrix.cpp40
1 files changed, 22 insertions, 18 deletions
diff --git a/src/core/SkMatrix.cpp b/src/core/SkMatrix.cpp
index 40f6e5298d..8778f78f41 100644
--- a/src/core/SkMatrix.cpp
+++ b/src/core/SkMatrix.cpp
@@ -7,7 +7,7 @@
#include "SkMatrix.h"
#include "SkFloatBits.h"
-#include "SkOnce.h"
+#include "SkLazyPtr.h"
#include "SkString.h"
// In a few places, we performed the following
@@ -1558,29 +1558,33 @@ bool SkMatrix::getMinMaxScales(SkScalar scaleFactors[2]) const {
return get_scale_factor<kBoth_MinMaxOrBoth>(this->getType(), fMat, scaleFactors);
}
-static void reset_identity_matrix(SkMatrix* identity) {
- identity->reset();
+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
+
const SkMatrix& SkMatrix::I() {
- // 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;
+ SK_DECLARE_STATIC_LAZY_PTR(SkMatrix, identity, create_identity);
+ return *identity.get();
}
const SkMatrix& SkMatrix::InvalidMatrix() {
- 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;
+ SK_DECLARE_STATIC_LAZY_PTR(SkMatrix, invalid, create_invalid);
+ return *invalid.get();
}
///////////////////////////////////////////////////////////////////////////////