Index: src/core/SkMatrix.cpp |
diff --git a/src/core/SkMatrix.cpp b/src/core/SkMatrix.cpp |
index 8778f78f4105f833a7cb10f5cb48b137f625a1b2..95662fc4cd42bca1edfb286e94089494b6e5a206 100644 |
--- a/src/core/SkMatrix.cpp |
+++ b/src/core/SkMatrix.cpp |
@@ -7,9 +7,10 @@ |
#include "SkMatrix.h" |
#include "SkFloatBits.h" |
-#include "SkLazyPtr.h" |
#include "SkString.h" |
+#include <stddef.h> |
reed1
2014/06/02 18:39:50
is this not already included (directly/indirectly)
mtklein
2014/06/02 18:40:31
Nope. offsetof wasn't defined until I included th
|
+ |
// In a few places, we performed the following |
// a * b + c * d + e |
// as |
@@ -1560,31 +1561,38 @@ 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); } |
bungeman-skia
2014/06/02 17:46:32
This cast is implementation defined. Of course, we
|
+}; |
+SK_COMPILE_ASSERT(sizeof(PODMatrix) == sizeof(SkMatrix), PODMatrixSizeMismatch); |
} // namespace |
const SkMatrix& SkMatrix::I() { |
- SK_DECLARE_STATIC_LAZY_PTR(SkMatrix, identity, create_identity); |
- return *identity.get(); |
+ SK_COMPILE_ASSERT(offsetof(SkMatrix, fMat) == offsetof(PODMatrix, matrix), BadfMat); |
+ SK_COMPILE_ASSERT(offsetof(SkMatrix, fTypeMask) == offsetof(PODMatrix, typemask), BadfTypeMask); |
+ |
+ 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(); |
+ SK_COMPILE_ASSERT(offsetof(SkMatrix, fMat) == offsetof(PODMatrix, matrix), BadfMat); |
+ SK_COMPILE_ASSERT(offsetof(SkMatrix, fTypeMask) == offsetof(PODMatrix, typemask), BadfTypeMask); |
+ |
+ 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(); |
} |
/////////////////////////////////////////////////////////////////////////////// |