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

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: add offsetof asserts 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..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();
}
///////////////////////////////////////////////////////////////////////////////
« 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