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