reed@google.com | 8260a89 | 2011-06-13 14:02:52 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
reed@google.com | 8260a89 | 2011-06-13 14:02:52 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
reed@google.com | 8260a89 | 2011-06-13 14:02:52 +0000 | [diff] [blame] | 8 | #ifndef SkMatrix44_DEFINED |
| 9 | #define SkMatrix44_DEFINED |
| 10 | |
| 11 | #include "SkMatrix.h" |
| 12 | #include "SkScalar.h" |
| 13 | |
reed@google.com | 8260a89 | 2011-06-13 14:02:52 +0000 | [diff] [blame] | 14 | #ifdef SK_MSCALAR_IS_DOUBLE |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 15 | #ifdef SK_MSCALAR_IS_FLOAT |
| 16 | #error "can't define MSCALAR both as DOUBLE and FLOAT" |
| 17 | #endif |
reed@google.com | 8260a89 | 2011-06-13 14:02:52 +0000 | [diff] [blame] | 18 | typedef double SkMScalar; |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 19 | typedef int64_t SkMIntScalar; |
| 20 | |
reed@google.com | 8260a89 | 2011-06-13 14:02:52 +0000 | [diff] [blame] | 21 | static inline double SkFloatToMScalar(float x) { |
| 22 | return static_cast<double>(x); |
| 23 | } |
| 24 | static inline float SkMScalarToFloat(double x) { |
| 25 | return static_cast<float>(x); |
| 26 | } |
| 27 | static inline double SkDoubleToMScalar(double x) { |
| 28 | return x; |
| 29 | } |
| 30 | static inline double SkMScalarToDouble(double x) { |
| 31 | return x; |
| 32 | } |
| 33 | static const SkMScalar SK_MScalarPI = 3.141592653589793; |
vollick@chromium.org | 5596a69 | 2012-11-13 20:12:00 +0000 | [diff] [blame] | 34 | #elif defined SK_MSCALAR_IS_FLOAT |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 35 | #ifdef SK_MSCALAR_IS_DOUBLE |
| 36 | #error "can't define MSCALAR both as DOUBLE and FLOAT" |
| 37 | #endif |
reed@google.com | 8260a89 | 2011-06-13 14:02:52 +0000 | [diff] [blame] | 38 | typedef float SkMScalar; |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 39 | typedef int32_t SkMIntScalar; |
skia.committer@gmail.com | 0264fb4 | 2012-12-06 02:01:25 +0000 | [diff] [blame] | 40 | |
reed@google.com | 8260a89 | 2011-06-13 14:02:52 +0000 | [diff] [blame] | 41 | static inline float SkFloatToMScalar(float x) { |
| 42 | return x; |
| 43 | } |
| 44 | static inline float SkMScalarToFloat(float x) { |
| 45 | return x; |
| 46 | } |
| 47 | static inline float SkDoubleToMScalar(double x) { |
| 48 | return static_cast<float>(x); |
| 49 | } |
| 50 | static inline double SkMScalarToDouble(float x) { |
| 51 | return static_cast<double>(x); |
| 52 | } |
| 53 | static const SkMScalar SK_MScalarPI = 3.14159265f; |
| 54 | #endif |
| 55 | |
reed@google.com | 20d4467 | 2012-11-09 21:28:55 +0000 | [diff] [blame] | 56 | #define SkMScalarToScalar SkMScalarToFloat |
| 57 | #define SkScalarToMScalar SkFloatToMScalar |
bsalomon@google.com | 72e49b8 | 2011-10-27 21:47:03 +0000 | [diff] [blame] | 58 | |
reed@google.com | 8260a89 | 2011-06-13 14:02:52 +0000 | [diff] [blame] | 59 | static const SkMScalar SK_MScalar1 = 1; |
| 60 | |
| 61 | /////////////////////////////////////////////////////////////////////////////// |
| 62 | |
| 63 | struct SkVector4 { |
| 64 | SkScalar fData[4]; |
| 65 | |
| 66 | SkVector4() { |
| 67 | this->set(0, 0, 0, 1); |
| 68 | } |
| 69 | SkVector4(const SkVector4& src) { |
| 70 | memcpy(fData, src.fData, sizeof(fData)); |
| 71 | } |
| 72 | SkVector4(SkScalar x, SkScalar y, SkScalar z, SkScalar w = SK_Scalar1) { |
| 73 | fData[0] = x; |
| 74 | fData[1] = y; |
| 75 | fData[2] = z; |
| 76 | fData[3] = w; |
| 77 | } |
| 78 | |
| 79 | SkVector4& operator=(const SkVector4& src) { |
| 80 | memcpy(fData, src.fData, sizeof(fData)); |
| 81 | return *this; |
| 82 | } |
| 83 | |
| 84 | bool operator==(const SkVector4& v) { |
| 85 | return fData[0] == v.fData[0] && fData[1] == v.fData[1] && |
| 86 | fData[2] == v.fData[2] && fData[3] == v.fData[3]; |
| 87 | } |
| 88 | bool operator!=(const SkVector4& v) { |
| 89 | return !(*this == v); |
| 90 | } |
| 91 | bool equals(SkScalar x, SkScalar y, SkScalar z, SkScalar w = SK_Scalar1) { |
| 92 | return fData[0] == x && fData[1] == y && |
| 93 | fData[2] == z && fData[3] == w; |
| 94 | } |
| 95 | |
| 96 | void set(SkScalar x, SkScalar y, SkScalar z, SkScalar w = SK_Scalar1) { |
| 97 | fData[0] = x; |
| 98 | fData[1] = y; |
| 99 | fData[2] = z; |
| 100 | fData[3] = w; |
| 101 | } |
| 102 | }; |
| 103 | |
reed@google.com | 65d8bb0 | 2011-07-05 19:12:59 +0000 | [diff] [blame] | 104 | class SK_API SkMatrix44 { |
reed@google.com | 8260a89 | 2011-06-13 14:02:52 +0000 | [diff] [blame] | 105 | public: |
vollick@chromium.org | 57a54e3 | 2012-12-10 20:16:10 +0000 | [diff] [blame^] | 106 | |
| 107 | enum Uninitialized_Constructor { |
| 108 | kUninitialized_Constructor |
| 109 | }; |
| 110 | enum Identity_Constructor { |
| 111 | kIdentity_Constructor |
| 112 | }; |
| 113 | |
| 114 | SkMatrix44(Uninitialized_Constructor) { } |
| 115 | SkMatrix44(Identity_Constructor) { this->setIdentity(); } |
| 116 | |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 117 | SkMatrix44() { this->setIdentity(); } |
reed@google.com | 8260a89 | 2011-06-13 14:02:52 +0000 | [diff] [blame] | 118 | SkMatrix44(const SkMatrix44&); |
| 119 | SkMatrix44(const SkMatrix44& a, const SkMatrix44& b); |
| 120 | |
| 121 | SkMatrix44& operator=(const SkMatrix44& src) { |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 122 | SkASSERT(sizeof(src) == sizeof(fMat) + sizeof(SkMIntScalar)); |
reed@google.com | 8260a89 | 2011-06-13 14:02:52 +0000 | [diff] [blame] | 123 | memcpy(this, &src, sizeof(*this)); |
| 124 | return *this; |
| 125 | } |
| 126 | |
reed@google.com | 631940c | 2012-11-27 13:13:22 +0000 | [diff] [blame] | 127 | bool operator==(const SkMatrix44& other) const; |
reed@google.com | 8260a89 | 2011-06-13 14:02:52 +0000 | [diff] [blame] | 128 | bool operator!=(const SkMatrix44& other) const { |
reed@google.com | 631940c | 2012-11-27 13:13:22 +0000 | [diff] [blame] | 129 | return !(other == *this); |
reed@google.com | 8260a89 | 2011-06-13 14:02:52 +0000 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | SkMatrix44(const SkMatrix&); |
| 133 | SkMatrix44& operator=(const SkMatrix& src); |
| 134 | operator SkMatrix() const; |
| 135 | |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 136 | /** |
| 137 | * Return a reference to a const identity matrix |
| 138 | */ |
| 139 | static const SkMatrix44& I(); |
| 140 | |
| 141 | enum TypeMask { |
| 142 | kIdentity_Mask = 0, |
| 143 | kTranslate_Mask = 0x01, //!< set if the matrix has translation |
| 144 | kScale_Mask = 0x02, //!< set if the matrix has any scale != 1 |
| 145 | kAffine_Mask = 0x04, //!< set if the matrix skews or rotates |
| 146 | kPerspective_Mask = 0x08 //!< set if the matrix is in perspective |
| 147 | }; |
skia.committer@gmail.com | 0264fb4 | 2012-12-06 02:01:25 +0000 | [diff] [blame] | 148 | |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 149 | /** |
| 150 | * Returns a bitfield describing the transformations the matrix may |
| 151 | * perform. The bitfield is computed conservatively, so it may include |
| 152 | * false positives. For example, when kPerspective_Mask is true, all |
| 153 | * other bits may be set to true even in the case of a pure perspective |
| 154 | * transform. |
| 155 | */ |
| 156 | inline TypeMask getType() const { |
| 157 | if (fTypeMask & kUnknown_Mask) { |
| 158 | fTypeMask = this->computeTypeMask(); |
| 159 | } |
| 160 | SkASSERT(!(fTypeMask & kUnknown_Mask)); |
| 161 | return (TypeMask)fTypeMask; |
| 162 | } |
| 163 | |
mike@reedtribe.org | f8b1ebc | 2012-12-10 03:27:47 +0000 | [diff] [blame] | 164 | /** |
| 165 | * Return true if the matrix is identity. |
| 166 | */ |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 167 | inline bool isIdentity() const { |
mike@reedtribe.org | f8b1ebc | 2012-12-10 03:27:47 +0000 | [diff] [blame] | 168 | return kIdentity_Mask == this->getType(); |
| 169 | } |
| 170 | |
| 171 | /** |
| 172 | * Return true if the matrix contains translate or is identity. |
| 173 | */ |
| 174 | inline bool isTranslate() const { |
| 175 | return !(this->getType() & ~kTranslate_Mask); |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * Return true if the matrix only contains scale or translate or is identity. |
| 180 | */ |
| 181 | inline bool isScaleTranslate() const { |
| 182 | return !(this->getType() & ~(kScale_Mask | kTranslate_Mask)); |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 183 | } |
skia.committer@gmail.com | 0264fb4 | 2012-12-06 02:01:25 +0000 | [diff] [blame] | 184 | |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 185 | void setIdentity(); |
| 186 | inline void reset() { this->setIdentity();} |
| 187 | |
| 188 | /** |
| 189 | * get a value from the matrix. The row,col parameters work as follows: |
| 190 | * (0, 0) scale-x |
| 191 | * (0, 3) translate-x |
| 192 | * (3, 0) perspective-x |
| 193 | */ |
| 194 | inline SkMScalar get(int row, int col) const { |
reed@google.com | 631940c | 2012-11-27 13:13:22 +0000 | [diff] [blame] | 195 | SkASSERT((unsigned)row <= 3); |
| 196 | SkASSERT((unsigned)col <= 3); |
| 197 | return fMat[col][row]; |
| 198 | } |
reed@google.com | 8260a89 | 2011-06-13 14:02:52 +0000 | [diff] [blame] | 199 | |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 200 | /** |
| 201 | * set a value in the matrix. The row,col parameters work as follows: |
| 202 | * (0, 0) scale-x |
| 203 | * (0, 3) translate-x |
| 204 | * (3, 0) perspective-x |
| 205 | */ |
| 206 | inline void set(int row, int col, SkMScalar value) { |
reed@google.com | 631940c | 2012-11-27 13:13:22 +0000 | [diff] [blame] | 207 | SkASSERT((unsigned)row <= 3); |
| 208 | SkASSERT((unsigned)col <= 3); |
| 209 | fMat[col][row] = value; |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 210 | this->dirtyTypeMask(); |
reed@google.com | 631940c | 2012-11-27 13:13:22 +0000 | [diff] [blame] | 211 | } |
skia.committer@gmail.com | ab38f7a | 2012-11-28 02:02:11 +0000 | [diff] [blame] | 212 | |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 213 | inline double getDouble(int row, int col) const { |
vollick@chromium.org | 9b21c25 | 2012-11-14 21:33:55 +0000 | [diff] [blame] | 214 | return SkMScalarToDouble(this->get(row, col)); |
| 215 | } |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 216 | inline void setDouble(int row, int col, double value) { |
vollick@chromium.org | 9b21c25 | 2012-11-14 21:33:55 +0000 | [diff] [blame] | 217 | this->set(row, col, SkDoubleToMScalar(value)); |
| 218 | } |
| 219 | |
vollick@chromium.org | f11cf9f | 2012-11-19 21:02:06 +0000 | [diff] [blame] | 220 | /** These methods allow one to efficiently read matrix entries into an |
| 221 | * array. The given array must have room for exactly 16 entries. Whenever |
| 222 | * possible, they will try to use memcpy rather than an entry-by-entry |
| 223 | * copy. |
| 224 | */ |
reed@google.com | da9fac0 | 2011-06-13 14:46:52 +0000 | [diff] [blame] | 225 | void asColMajorf(float[]) const; |
| 226 | void asColMajord(double[]) const; |
| 227 | void asRowMajorf(float[]) const; |
| 228 | void asRowMajord(double[]) const; |
| 229 | |
vollick@chromium.org | f11cf9f | 2012-11-19 21:02:06 +0000 | [diff] [blame] | 230 | /** These methods allow one to efficiently set all matrix entries from an |
| 231 | * array. The given array must have room for exactly 16 entries. Whenever |
| 232 | * possible, they will try to use memcpy rather than an entry-by-entry |
| 233 | * copy. |
| 234 | */ |
| 235 | void setColMajorf(const float[]); |
| 236 | void setColMajord(const double[]); |
| 237 | void setRowMajorf(const float[]); |
| 238 | void setRowMajord(const double[]); |
| 239 | |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 240 | #ifdef SK_MSCALAR_IS_FLOAT |
| 241 | void setColMajor(const SkMScalar data[]) { this->setColMajorf(data); } |
| 242 | void setRowMajor(const SkMScalar data[]) { this->setRowMajorf(data); } |
| 243 | #else |
| 244 | void setColMajor(const SkMScalar data[]) { this->setColMajord(data); } |
| 245 | void setRowMajor(const SkMScalar data[]) { this->setRowMajord(data); } |
| 246 | #endif |
reed@google.com | 8260a89 | 2011-06-13 14:02:52 +0000 | [diff] [blame] | 247 | |
| 248 | void set3x3(SkMScalar m00, SkMScalar m01, SkMScalar m02, |
| 249 | SkMScalar m10, SkMScalar m11, SkMScalar m12, |
| 250 | SkMScalar m20, SkMScalar m21, SkMScalar m22); |
| 251 | |
| 252 | void setTranslate(SkMScalar dx, SkMScalar dy, SkMScalar dz); |
| 253 | void preTranslate(SkMScalar dx, SkMScalar dy, SkMScalar dz); |
| 254 | void postTranslate(SkMScalar dx, SkMScalar dy, SkMScalar dz); |
| 255 | |
| 256 | void setScale(SkMScalar sx, SkMScalar sy, SkMScalar sz); |
| 257 | void preScale(SkMScalar sx, SkMScalar sy, SkMScalar sz); |
| 258 | void postScale(SkMScalar sx, SkMScalar sy, SkMScalar sz); |
| 259 | |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 260 | inline void setScale(SkMScalar scale) { |
reed@google.com | 8260a89 | 2011-06-13 14:02:52 +0000 | [diff] [blame] | 261 | this->setScale(scale, scale, scale); |
| 262 | } |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 263 | inline void preScale(SkMScalar scale) { |
reed@google.com | 8260a89 | 2011-06-13 14:02:52 +0000 | [diff] [blame] | 264 | this->preScale(scale, scale, scale); |
| 265 | } |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 266 | inline void postScale(SkMScalar scale) { |
reed@google.com | 8260a89 | 2011-06-13 14:02:52 +0000 | [diff] [blame] | 267 | this->postScale(scale, scale, scale); |
| 268 | } |
| 269 | |
| 270 | void setRotateDegreesAbout(SkMScalar x, SkMScalar y, SkMScalar z, |
| 271 | SkMScalar degrees) { |
| 272 | this->setRotateAbout(x, y, z, degrees * SK_MScalarPI / 180); |
| 273 | } |
| 274 | |
| 275 | /** Rotate about the vector [x,y,z]. If that vector is not unit-length, |
| 276 | it will be automatically resized. |
| 277 | */ |
| 278 | void setRotateAbout(SkMScalar x, SkMScalar y, SkMScalar z, |
| 279 | SkMScalar radians); |
| 280 | /** Rotate about the vector [x,y,z]. Does not check the length of the |
| 281 | vector, assuming it is unit-length. |
| 282 | */ |
| 283 | void setRotateAboutUnit(SkMScalar x, SkMScalar y, SkMScalar z, |
| 284 | SkMScalar radians); |
| 285 | |
| 286 | void setConcat(const SkMatrix44& a, const SkMatrix44& b); |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 287 | inline void preConcat(const SkMatrix44& m) { |
reed@google.com | 8260a89 | 2011-06-13 14:02:52 +0000 | [diff] [blame] | 288 | this->setConcat(*this, m); |
| 289 | } |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 290 | inline void postConcat(const SkMatrix44& m) { |
reed@google.com | 8260a89 | 2011-06-13 14:02:52 +0000 | [diff] [blame] | 291 | this->setConcat(m, *this); |
| 292 | } |
| 293 | |
| 294 | friend SkMatrix44 operator*(const SkMatrix44& a, const SkMatrix44& b) { |
| 295 | return SkMatrix44(a, b); |
| 296 | } |
| 297 | |
| 298 | /** If this is invertible, return that in inverse and return true. If it is |
| 299 | not invertible, return false and ignore the inverse parameter. |
| 300 | */ |
| 301 | bool invert(SkMatrix44* inverse) const; |
| 302 | |
vollick@chromium.org | 9b21c25 | 2012-11-14 21:33:55 +0000 | [diff] [blame] | 303 | /** Transpose this matrix in place. */ |
| 304 | void transpose(); |
| 305 | |
reed@google.com | 8260a89 | 2011-06-13 14:02:52 +0000 | [diff] [blame] | 306 | /** Apply the matrix to the src vector, returning the new vector in dst. |
| 307 | It is legal for src and dst to point to the same memory. |
| 308 | */ |
reed@google.com | 1ea95be | 2012-11-09 21:39:48 +0000 | [diff] [blame] | 309 | void mapScalars(const SkScalar src[4], SkScalar dst[4]) const; |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 310 | inline void mapScalars(SkScalar vec[4]) const { |
reed@google.com | 1ea95be | 2012-11-09 21:39:48 +0000 | [diff] [blame] | 311 | this->mapScalars(vec, vec); |
| 312 | } |
| 313 | |
| 314 | // DEPRECATED: call mapScalars() |
| 315 | void map(const SkScalar src[4], SkScalar dst[4]) const { |
| 316 | this->mapScalars(src, dst); |
| 317 | } |
| 318 | // DEPRECATED: call mapScalars() |
reed@google.com | 8260a89 | 2011-06-13 14:02:52 +0000 | [diff] [blame] | 319 | void map(SkScalar vec[4]) const { |
reed@google.com | 1ea95be | 2012-11-09 21:39:48 +0000 | [diff] [blame] | 320 | this->mapScalars(vec, vec); |
| 321 | } |
| 322 | |
| 323 | #ifdef SK_MSCALAR_IS_DOUBLE |
reed@google.com | dd31131 | 2012-11-12 20:43:59 +0000 | [diff] [blame] | 324 | void mapMScalars(const SkMScalar src[4], SkMScalar dst[4]) const; |
vollick@chromium.org | 5596a69 | 2012-11-13 20:12:00 +0000 | [diff] [blame] | 325 | #elif defined SK_MSCALAR_IS_FLOAT |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 326 | inline void mapMScalars(const SkMScalar src[4], SkMScalar dst[4]) const { |
reed@google.com | 1ea95be | 2012-11-09 21:39:48 +0000 | [diff] [blame] | 327 | this->mapScalars(src, dst); |
| 328 | } |
| 329 | #endif |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 330 | inline void mapMScalars(SkMScalar vec[4]) const { |
reed@google.com | 1ea95be | 2012-11-09 21:39:48 +0000 | [diff] [blame] | 331 | this->mapMScalars(vec, vec); |
reed@google.com | 8260a89 | 2011-06-13 14:02:52 +0000 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | friend SkVector4 operator*(const SkMatrix44& m, const SkVector4& src) { |
| 335 | SkVector4 dst; |
| 336 | m.map(src.fData, dst.fData); |
| 337 | return dst; |
| 338 | } |
| 339 | |
reed@google.com | 99b5c7f | 2012-12-05 22:13:59 +0000 | [diff] [blame] | 340 | /** |
| 341 | * map an array of [x, y, 0, 1] through the matrix, returning an array |
| 342 | * of [x', y', z', w']. |
| 343 | * |
| 344 | * @param src2 array of [x, y] pairs, with implied z=0 and w=1 |
| 345 | * @param count number of [x, y] pairs in src2 |
| 346 | * @param dst4 array of [x', y', z', w'] quads as the output. |
| 347 | */ |
| 348 | void map2(const float src2[], int count, float dst4[]) const; |
| 349 | void map2(const double src2[], int count, double dst4[]) const; |
| 350 | |
reed@google.com | 8260a89 | 2011-06-13 14:02:52 +0000 | [diff] [blame] | 351 | void dump() const; |
| 352 | |
vollick@chromium.org | 3959a76 | 2012-11-13 15:08:22 +0000 | [diff] [blame] | 353 | double determinant() const; |
| 354 | |
reed@google.com | 8260a89 | 2011-06-13 14:02:52 +0000 | [diff] [blame] | 355 | private: |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 356 | SkMScalar fMat[4][4]; |
| 357 | // we use SkMIntScalar instead of just int, as we want to ensure that |
| 358 | // we are always packed with no extra bits, allowing us to call memcpy |
| 359 | // without fear of copying uninitialized bits. |
| 360 | mutable SkMIntScalar fTypeMask; |
skia.committer@gmail.com | 0264fb4 | 2012-12-06 02:01:25 +0000 | [diff] [blame] | 361 | |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 362 | enum { |
| 363 | kUnknown_Mask = 0x80, |
jamesr@chromium.org | deb4c16 | 2012-11-29 21:17:16 +0000 | [diff] [blame] | 364 | |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 365 | kAllPublic_Masks = 0xF |
| 366 | }; |
| 367 | |
| 368 | SkMScalar transX() const { return fMat[3][0]; } |
| 369 | SkMScalar transY() const { return fMat[3][1]; } |
| 370 | SkMScalar transZ() const { return fMat[3][2]; } |
| 371 | |
| 372 | SkMScalar scaleX() const { return fMat[0][0]; } |
| 373 | SkMScalar scaleY() const { return fMat[1][1]; } |
| 374 | SkMScalar scaleZ() const { return fMat[2][2]; } |
skia.committer@gmail.com | 0264fb4 | 2012-12-06 02:01:25 +0000 | [diff] [blame] | 375 | |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 376 | SkMScalar perspX() const { return fMat[0][3]; } |
| 377 | SkMScalar perspY() const { return fMat[1][3]; } |
| 378 | SkMScalar perspZ() const { return fMat[2][3]; } |
| 379 | |
| 380 | int computeTypeMask() const; |
| 381 | |
| 382 | inline void dirtyTypeMask() { |
| 383 | fTypeMask = kUnknown_Mask; |
| 384 | } |
| 385 | |
| 386 | inline void setTypeMask(int mask) { |
| 387 | SkASSERT(0 == (~(kAllPublic_Masks | kUnknown_Mask) & mask)); |
| 388 | fTypeMask = mask; |
| 389 | } |
| 390 | |
| 391 | /** |
| 392 | * Does not take the time to 'compute' the typemask. Only returns true if |
| 393 | * we already know that this matrix is identity. |
| 394 | */ |
| 395 | inline bool isTriviallyIdentity() const { |
| 396 | return 0 == fTypeMask; |
| 397 | } |
reed@google.com | 8260a89 | 2011-06-13 14:02:52 +0000 | [diff] [blame] | 398 | }; |
| 399 | |
| 400 | #endif |