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

Side by Side Diff: src/utils/SkMatrix44.cpp

Issue 23477020: Revert determinant-based ScaleTranslate inverse. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "SkMatrix44.h" 8 #include "SkMatrix44.h"
9 9
10 static inline bool eq4(const SkMScalar* SK_RESTRICT a, 10 static inline bool eq4(const SkMScalar* SK_RESTRICT a,
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 if (inverse) { 484 if (inverse) {
485 inverse->setTranslate(-fMat[3][0], -fMat[3][1], -fMat[3][2]); 485 inverse->setTranslate(-fMat[3][0], -fMat[3][1], -fMat[3][2]);
486 } 486 }
487 return true; 487 return true;
488 } 488 }
489 if (this->isScaleTranslate()) { 489 if (this->isScaleTranslate()) {
490 if (0 == fMat[0][0] * fMat[1][1] * fMat[2][2]) { 490 if (0 == fMat[0][0] * fMat[1][1] * fMat[2][2]) {
491 return false; 491 return false;
492 } 492 }
493 493
494 double a00 = fMat[0][0]; 494 » if (inverse) {
495 double a11 = fMat[1][1]; 495 » double invXScale = 1 / fMat[0][0];
496 double a22 = fMat[2][2]; 496 » double invYScale = 1 / fMat[1][1];
497 double a30 = fMat[3][0]; 497 » double invZScale = 1 / fMat[2][2];
498 double a31 = fMat[3][1]; 498 »
499 double a32 = fMat[3][2]; 499 inverse->fMat[0][0] = invXScale;
500 » inverse->fMat[0][1] = 0;
501 » inverse->fMat[0][2] = 0;
502 » inverse->fMat[0][3] = 0;
500 503
501 double b00 = a00 * a11; 504 » inverse->fMat[1][0] = 0;
502 double b07 = -a22 * a30; 505 » inverse->fMat[1][1] = invYScale;
503 double b09 = -a22 * a31; 506 » inverse->fMat[1][2] = 0;
504 double b11 = a22; 507 » inverse->fMat[1][3] = 0;
508 »
509 » inverse->fMat[2][0] = 0;
510 inverse->fMat[2][1] = 0;
511 » inverse->fMat[2][2] = invZScale;
512 » inverse->fMat[2][3] = 0;
513 »
514 inverse->fMat[3][0] = -fMat[3][0] * invXScale;
515 inverse->fMat[3][1] = -fMat[3][1] * invYScale;
516 inverse->fMat[3][2] = -fMat[3][2] * invZScale;
517 inverse->fMat[3][3] = 1;
505 518
506 // Calculate the determinant 519 inverse->setTypeMask(this->getType());
507 double det = b00 * b11;
508
509 double invdet = 1.0 / det;
510 // If det is zero, we want to return false. However, we also want to ret urn false
511 // if 1/det overflows to infinity (i.e. det is denormalized). Both of th ese are
512 // handled by checking that 1/det is finite.
513 if (!sk_float_isfinite(invdet)) {
514 return false;
515 }
516 if (NULL == inverse) {
517 return true;
518 } 520 }
519 521
520 b00 *= invdet;
521 b07 *= invdet;
522 b09 *= invdet;
523 b11 *= invdet;
524
525 inverse->fMat[0][0] = SkDoubleToMScalar(a11 * b11);
526 inverse->fMat[0][1] = 0;
527 inverse->fMat[0][2] = 0;
528 inverse->fMat[0][3] = 0;
529 inverse->fMat[1][0] = 0;
530 inverse->fMat[1][1] = SkDoubleToMScalar(a00 * b11);
531 inverse->fMat[1][2] = 0;
532 inverse->fMat[1][3] = 0;
533 inverse->fMat[2][0] = 0;
534 inverse->fMat[2][1] = 0;
535 inverse->fMat[2][2] = SkDoubleToMScalar(b00);
536 inverse->fMat[2][3] = 0;
537 inverse->fMat[3][0] = SkDoubleToMScalar(a11 * b07);
538 inverse->fMat[3][1] = SkDoubleToMScalar(a00 * b09);
539 inverse->fMat[3][2] = SkDoubleToMScalar(-a32 * b00);
540 inverse->fMat[3][3] = 1;
541
542 inverse->setTypeMask(this->getType());
543 return true; 522 return true;
544 } 523 }
545 524
546 double a00 = fMat[0][0]; 525 double a00 = fMat[0][0];
547 double a01 = fMat[0][1]; 526 double a01 = fMat[0][1];
548 double a02 = fMat[0][2]; 527 double a02 = fMat[0][2];
549 double a03 = fMat[0][3]; 528 double a03 = fMat[0][3];
550 double a10 = fMat[1][0]; 529 double a10 = fMat[1][0];
551 double a11 = fMat[1][1]; 530 double a11 = fMat[1][1];
552 double a12 = fMat[1][2]; 531 double a12 = fMat[1][2];
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 dst[SkMatrix::kMScaleX] = SkMScalarToScalar(fMat[0][0]); 947 dst[SkMatrix::kMScaleX] = SkMScalarToScalar(fMat[0][0]);
969 dst[SkMatrix::kMSkewX] = SkMScalarToScalar(fMat[1][0]); 948 dst[SkMatrix::kMSkewX] = SkMScalarToScalar(fMat[1][0]);
970 dst[SkMatrix::kMTransX] = SkMScalarToScalar(fMat[3][0]); 949 dst[SkMatrix::kMTransX] = SkMScalarToScalar(fMat[3][0]);
971 950
972 dst[SkMatrix::kMSkewY] = SkMScalarToScalar(fMat[0][1]); 951 dst[SkMatrix::kMSkewY] = SkMScalarToScalar(fMat[0][1]);
973 dst[SkMatrix::kMScaleY] = SkMScalarToScalar(fMat[1][1]); 952 dst[SkMatrix::kMScaleY] = SkMScalarToScalar(fMat[1][1]);
974 dst[SkMatrix::kMTransY] = SkMScalarToScalar(fMat[3][1]); 953 dst[SkMatrix::kMTransY] = SkMScalarToScalar(fMat[3][1]);
975 954
976 return dst; 955 return dst;
977 } 956 }
OLDNEW
« 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