OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkMatrix44_DEFINED | 8 #ifndef SkMatrix44_DEFINED |
9 #define SkMatrix44_DEFINED | 9 #define SkMatrix44_DEFINED |
10 | 10 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 class SK_API SkMatrix44 { | 129 class SK_API SkMatrix44 { |
130 public: | 130 public: |
131 | 131 |
132 enum Uninitialized_Constructor { | 132 enum Uninitialized_Constructor { |
133 kUninitialized_Constructor | 133 kUninitialized_Constructor |
134 }; | 134 }; |
135 enum Identity_Constructor { | 135 enum Identity_Constructor { |
136 kIdentity_Constructor | 136 kIdentity_Constructor |
137 }; | 137 }; |
138 | 138 |
139 SkMatrix44(Uninitialized_Constructor) { } | 139 SkMatrix44(Uninitialized_Constructor) {} |
140 SkMatrix44(Identity_Constructor) { this->setIdentity(); } | 140 |
| 141 constexpr SkMatrix44(Identity_Constructor) |
| 142 : fMat{{ 1, 0, 0, 0, }, |
| 143 { 0, 1, 0, 0, }, |
| 144 { 0, 0, 1, 0, }, |
| 145 { 0, 0, 0, 1, }} |
| 146 , fTypeMask(kIdentity_Mask) |
| 147 {} |
141 | 148 |
142 SK_ATTR_DEPRECATED("use the constructors that take an enum") | 149 SK_ATTR_DEPRECATED("use the constructors that take an enum") |
143 SkMatrix44() { this->setIdentity(); } | 150 SkMatrix44() { this->setIdentity(); } |
144 | 151 |
145 SkMatrix44(const SkMatrix44& src) { | 152 SkMatrix44(const SkMatrix44& src) { |
146 memcpy(fMat, src.fMat, sizeof(fMat)); | 153 memcpy(fMat, src.fMat, sizeof(fMat)); |
147 fTypeMask = src.fTypeMask; | 154 fTypeMask = src.fTypeMask; |
148 } | 155 } |
149 | 156 |
150 SkMatrix44(const SkMatrix44& a, const SkMatrix44& b) { | 157 SkMatrix44(const SkMatrix44& a, const SkMatrix44& b) { |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 return SkMScalarToFloat(this->get(row, col)); | 281 return SkMScalarToFloat(this->get(row, col)); |
275 } | 282 } |
276 inline void setFloat(int row, int col, float value) { | 283 inline void setFloat(int row, int col, float value) { |
277 this->set(row, col, SkFloatToMScalar(value)); | 284 this->set(row, col, SkFloatToMScalar(value)); |
278 } | 285 } |
279 | 286 |
280 /** These methods allow one to efficiently read matrix entries into an | 287 /** These methods allow one to efficiently read matrix entries into an |
281 * array. The given array must have room for exactly 16 entries. Whenever | 288 * array. The given array must have room for exactly 16 entries. Whenever |
282 * possible, they will try to use memcpy rather than an entry-by-entry | 289 * possible, they will try to use memcpy rather than an entry-by-entry |
283 * copy. | 290 * copy. |
| 291 * |
| 292 * Col major indicates that consecutive elements of columns will be stored |
| 293 * contiguously in memory. Row major indicates that consecutive elements |
| 294 * of rows will be stored contiguously in memory. |
284 */ | 295 */ |
285 void asColMajorf(float[]) const; | 296 void asColMajorf(float[]) const; |
286 void asColMajord(double[]) const; | 297 void asColMajord(double[]) const; |
287 void asRowMajorf(float[]) const; | 298 void asRowMajorf(float[]) const; |
288 void asRowMajord(double[]) const; | 299 void asRowMajord(double[]) const; |
289 | 300 |
290 /** These methods allow one to efficiently set all matrix entries from an | 301 /** These methods allow one to efficiently set all matrix entries from an |
291 * array. The given array must have room for exactly 16 entries. Whenever | 302 * array. The given array must have room for exactly 16 entries. Whenever |
292 * possible, they will try to use memcpy rather than an entry-by-entry | 303 * possible, they will try to use memcpy rather than an entry-by-entry |
293 * copy. | 304 * copy. |
| 305 * |
| 306 * Col major indicates that input memory will be treated as if consecutive |
| 307 * elements of columns are stored contiguously in memory. Row major |
| 308 * indicates that input memory will be treated as if consecutive elements |
| 309 * of rows are stored contiguously in memory. |
294 */ | 310 */ |
295 void setColMajorf(const float[]); | 311 void setColMajorf(const float[]); |
296 void setColMajord(const double[]); | 312 void setColMajord(const double[]); |
297 void setRowMajorf(const float[]); | 313 void setRowMajorf(const float[]); |
298 void setRowMajord(const double[]); | 314 void setRowMajord(const double[]); |
299 | 315 |
300 #ifdef SK_MSCALAR_IS_FLOAT | 316 #ifdef SK_MSCALAR_IS_FLOAT |
301 void setColMajor(const SkMScalar data[]) { this->setColMajorf(data); } | 317 void setColMajor(const SkMScalar data[]) { this->setColMajorf(data); } |
302 void setRowMajor(const SkMScalar data[]) { this->setRowMajorf(data); } | 318 void setRowMajor(const SkMScalar data[]) { this->setRowMajorf(data); } |
303 #else | 319 #else |
304 void setColMajor(const SkMScalar data[]) { this->setColMajord(data); } | 320 void setColMajor(const SkMScalar data[]) { this->setColMajord(data); } |
305 void setRowMajor(const SkMScalar data[]) { this->setRowMajord(data); } | 321 void setRowMajor(const SkMScalar data[]) { this->setRowMajord(data); } |
306 #endif | 322 #endif |
307 | 323 |
308 /* This sets the top-left of the matrix and clears the translation and | 324 /* This sets the top-left of the matrix and clears the translation and |
309 * perspective components (with [3][3] set to 1). */ | 325 * perspective components (with [3][3] set to 1). mXY is interpreted |
| 326 * as the matrix entry at col = X, row = Y. */ |
310 void set3x3(SkMScalar m00, SkMScalar m01, SkMScalar m02, | 327 void set3x3(SkMScalar m00, SkMScalar m01, SkMScalar m02, |
311 SkMScalar m10, SkMScalar m11, SkMScalar m12, | 328 SkMScalar m10, SkMScalar m11, SkMScalar m12, |
312 SkMScalar m20, SkMScalar m21, SkMScalar m22); | 329 SkMScalar m20, SkMScalar m21, SkMScalar m22); |
313 void set3x3ColMajorf(const float[]); | 330 void set3x3RowMajorf(const float[]); |
314 | 331 |
315 void setTranslate(SkMScalar dx, SkMScalar dy, SkMScalar dz); | 332 void setTranslate(SkMScalar dx, SkMScalar dy, SkMScalar dz); |
316 void preTranslate(SkMScalar dx, SkMScalar dy, SkMScalar dz); | 333 void preTranslate(SkMScalar dx, SkMScalar dy, SkMScalar dz); |
317 void postTranslate(SkMScalar dx, SkMScalar dy, SkMScalar dz); | 334 void postTranslate(SkMScalar dx, SkMScalar dy, SkMScalar dz); |
318 | 335 |
319 void setScale(SkMScalar sx, SkMScalar sy, SkMScalar sz); | 336 void setScale(SkMScalar sx, SkMScalar sy, SkMScalar sz); |
320 void preScale(SkMScalar sx, SkMScalar sy, SkMScalar sz); | 337 void preScale(SkMScalar sx, SkMScalar sy, SkMScalar sz); |
321 void postScale(SkMScalar sx, SkMScalar sy, SkMScalar sz); | 338 void postScale(SkMScalar sx, SkMScalar sy, SkMScalar sz); |
322 | 339 |
323 inline void setScale(SkMScalar scale) { | 340 inline void setScale(SkMScalar scale) { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 a 90-degree rotation can still end up with 10^-17 of | 440 a 90-degree rotation can still end up with 10^-17 of |
424 "non-axis-aligned" result. | 441 "non-axis-aligned" result. |
425 */ | 442 */ |
426 bool preserves2dAxisAlignment(SkMScalar epsilon = SK_ScalarNearlyZero) const
; | 443 bool preserves2dAxisAlignment(SkMScalar epsilon = SK_ScalarNearlyZero) const
; |
427 | 444 |
428 void dump() const; | 445 void dump() const; |
429 | 446 |
430 double determinant() const; | 447 double determinant() const; |
431 | 448 |
432 private: | 449 private: |
| 450 /* This is indexed by [col][row]. */ |
433 SkMScalar fMat[4][4]; | 451 SkMScalar fMat[4][4]; |
434 mutable unsigned fTypeMask; | 452 mutable unsigned fTypeMask; |
435 | 453 |
436 enum { | 454 enum { |
437 kUnknown_Mask = 0x80, | 455 kUnknown_Mask = 0x80, |
438 | 456 |
439 kAllPublic_Masks = 0xF | 457 kAllPublic_Masks = 0xF |
440 }; | 458 }; |
441 | 459 |
442 /** Efficiently reads 12 matrix entries, ignoring the last col. | |
443 * This is typically useful when we know the last col is (0, 0, 0, 1). | |
444 */ | |
445 void as4x3ColMajorf(float[]) const; | 460 void as4x3ColMajorf(float[]) const; |
446 | |
447 /* This sets the top-left of the matrix and clears the | |
448 * perspective components (with [3][3] set to 1). */ | |
449 void set4x3ColMajorf(const float[]); | 461 void set4x3ColMajorf(const float[]); |
450 | 462 |
451 SkMScalar transX() const { return fMat[3][0]; } | 463 SkMScalar transX() const { return fMat[3][0]; } |
452 SkMScalar transY() const { return fMat[3][1]; } | 464 SkMScalar transY() const { return fMat[3][1]; } |
453 SkMScalar transZ() const { return fMat[3][2]; } | 465 SkMScalar transZ() const { return fMat[3][2]; } |
454 | 466 |
455 SkMScalar scaleX() const { return fMat[0][0]; } | 467 SkMScalar scaleX() const { return fMat[0][0]; } |
456 SkMScalar scaleY() const { return fMat[1][1]; } | 468 SkMScalar scaleY() const { return fMat[1][1]; } |
457 SkMScalar scaleZ() const { return fMat[2][2]; } | 469 SkMScalar scaleZ() const { return fMat[2][2]; } |
458 | 470 |
(...skipping 17 matching lines...) Expand all Loading... |
476 * we already know that this matrix is identity. | 488 * we already know that this matrix is identity. |
477 */ | 489 */ |
478 inline bool isTriviallyIdentity() const { | 490 inline bool isTriviallyIdentity() const { |
479 return 0 == fTypeMask; | 491 return 0 == fTypeMask; |
480 } | 492 } |
481 | 493 |
482 friend class SkColorSpace; | 494 friend class SkColorSpace; |
483 }; | 495 }; |
484 | 496 |
485 #endif | 497 #endif |
OLD | NEW |