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

Unified Diff: src/core/SkMatrix.cpp

Issue 303263011: Compile-time initialize special SkMatrices. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: nit 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 | « no previous file | no next file » | 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..01f1814f5a2c279feb7e9a09ce102fe129c646ce 100644
--- a/src/core/SkMatrix.cpp
+++ b/src/core/SkMatrix.cpp
@@ -7,7 +7,6 @@
#include "SkMatrix.h"
#include "SkFloatBits.h"
-#include "SkLazyPtr.h"
#include "SkString.h"
// In a few places, we performed the following
@@ -1560,31 +1559,32 @@ bool SkMatrix::getMinMaxScales(SkScalar scaleFactors[2]) const {
namespace {
-SkMatrix* create_identity() {
- SkMatrix* m = SkNEW(SkMatrix);
- m->reset();
- return m;
-}
+struct PODMatrix {
+ SkScalar matrix[9];
+ uint32_t typemask;
-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;
-}
+ const SkMatrix& asSkMatrix() const { return *reinterpret_cast<const SkMatrix*>(this); }
+};
+SK_COMPILE_ASSERT(sizeof(PODMatrix) == sizeof(SkMatrix), PODMatrixSizeMismatch);
bungeman-skia 2014/06/02 16:35:15 In addition to this, it would be nice for SkMatrix
} // namespace
const SkMatrix& SkMatrix::I() {
- SK_DECLARE_STATIC_LAZY_PTR(SkMatrix, identity, create_identity);
- return *identity.get();
+ static const PODMatrix identity = { {SK_Scalar1, 0, 0,
+ 0, SK_Scalar1, 0,
+ 0, 0, SK_Scalar1 },
+ kIdentity_Mask | kRectStaysRect_Mask};
+ SkASSERT(identity.asSkMatrix().isIdentity());
+ return identity.asSkMatrix();
}
const SkMatrix& SkMatrix::InvalidMatrix() {
- SK_DECLARE_STATIC_LAZY_PTR(SkMatrix, invalid, create_invalid);
- return *invalid.get();
+ static const PODMatrix invalid =
+ { {SK_ScalarMax, SK_ScalarMax, SK_ScalarMax,
+ SK_ScalarMax, SK_ScalarMax, SK_ScalarMax,
+ SK_ScalarMax, SK_ScalarMax, SK_ScalarMax },
+ kTranslate_Mask | kScale_Mask | kAffine_Mask | kPerspective_Mask };
+ return invalid.asSkMatrix();
}
///////////////////////////////////////////////////////////////////////////////
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698