diff options
Diffstat (limited to 'experimental')
-rw-r--r-- | experimental/SkMatrix44.cpp | 38 | ||||
-rw-r--r-- | experimental/SkMatrix44.h | 12 |
2 files changed, 49 insertions, 1 deletions
diff --git a/experimental/SkMatrix44.cpp b/experimental/SkMatrix44.cpp index b2b8c30465..841eec27d1 100644 --- a/experimental/SkMatrix44.cpp +++ b/experimental/SkMatrix44.cpp @@ -269,4 +269,42 @@ void SkMatrix44::dump() const { #endif } +/////////////////////////////////////////////////////////////////////////////// + +static void initFromMatrix(SkMScalar dst[4][4], const SkMatrix& src) { + sk_bzero(dst, 16 * sizeof(SkMScalar)); + dst[0][0] = src[SkMatrix::kMScaleX]; + dst[1][0] = src[SkMatrix::kMSkewX]; + dst[3][0] = src[SkMatrix::kMTransX]; + dst[0][1] = src[SkMatrix::kMSkewY]; + dst[1][1] = src[SkMatrix::kMScaleY]; + dst[3][1] = src[SkMatrix::kMTransY]; + dst[2][2] = dst[3][3] = 1; +} + +SkMatrix44::SkMatrix44(const SkMatrix& src) { + initFromMatrix(fMat, src); +} + +SkMatrix44& SkMatrix44::operator=(const SkMatrix& src) { + initFromMatrix(fMat, src); + return *this; +} + +SkMatrix44::operator SkMatrix() const { + SkMatrix dst; + dst.reset(); // setup our perspective correctly for identity + + dst[SkMatrix::kMScaleX] = SkMScalarToFloat(fMat[0][0]); + dst[SkMatrix::kMSkewX] = SkMScalarToFloat(fMat[1][0]); + dst[SkMatrix::kMTransX] = SkMScalarToFloat(fMat[3][0]); + + dst[SkMatrix::kMSkewY] = SkMScalarToFloat(fMat[0][1]); + dst[SkMatrix::kMScaleY] = SkMScalarToFloat(fMat[1][1]); + dst[SkMatrix::kMTransY] = SkMScalarToFloat(fMat[3][1]); + + return dst; +} + + diff --git a/experimental/SkMatrix44.h b/experimental/SkMatrix44.h index f86559056a..b0e7148c41 100644 --- a/experimental/SkMatrix44.h +++ b/experimental/SkMatrix44.h @@ -1,6 +1,7 @@ #ifndef SkMatrix44_DEFINED #define SkMatrix44_DEFINED +#include "SkMatrix.h" #include "SkScalar.h" // uncomment this to use doubles for matrix44 @@ -89,13 +90,22 @@ public: SkMatrix44(const SkMatrix44&); SkMatrix44(const SkMatrix44& a, const SkMatrix44& b); + SkMatrix44& operator=(const SkMatrix44& src) { + memcpy(this, &src, sizeof(*this)); + return *this; + } + bool operator==(const SkMatrix44& other) const { return !memcmp(this, &other, sizeof(*this)); } bool operator!=(const SkMatrix44& other) const { return !!memcmp(this, &other, sizeof(*this)); } - + + SkMatrix44(const SkMatrix&); + SkMatrix44& operator=(const SkMatrix& src); + operator SkMatrix() const; + bool isIdentity() const; void setIdentity(); void reset() { this->setIdentity(); } |