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

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

Issue 79333002: Fix SkMatrix44::invert(...) for identity matrices and a NULL parameter (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 1 month 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 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 // Calculate the determinant 445 // Calculate the determinant
446 return b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06 ; 446 return b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06 ;
447 } 447 }
448 448
449 /////////////////////////////////////////////////////////////////////////////// 449 ///////////////////////////////////////////////////////////////////////////////
450 450
451 bool SkMatrix44::invert(SkMatrix44* inverse) const { 451 bool SkMatrix44::invert(SkMatrix44* inverse) const {
452 if (this->isIdentity()) { 452 if (this->isIdentity()) {
453 if (inverse) { 453 if (inverse) {
454 inverse->setIdentity(); 454 inverse->setIdentity();
455 return true;
456 } 455 }
456 return true;
457 } 457 }
458
458 if (this->isTranslate()) { 459 if (this->isTranslate()) {
459 if (inverse) { 460 if (inverse) {
460 inverse->setTranslate(-fMat[3][0], -fMat[3][1], -fMat[3][2]); 461 inverse->setTranslate(-fMat[3][0], -fMat[3][1], -fMat[3][2]);
461 } 462 }
462 return true; 463 return true;
463 } 464 }
465
464 if (this->isScaleTranslate()) { 466 if (this->isScaleTranslate()) {
465 if (0 == fMat[0][0] * fMat[1][1] * fMat[2][2]) { 467 if (0 == fMat[0][0] * fMat[1][1] * fMat[2][2]) {
466 return false; 468 return false;
467 } 469 }
468 470
469 if (inverse) { 471 if (inverse) {
470 double invXScale = 1 / fMat[0][0]; 472 double invXScale = 1 / fMat[0][0];
471 double invYScale = 1 / fMat[1][1]; 473 double invYScale = 1 / fMat[1][1];
472 double invZScale = 1 / fMat[2][2]; 474 double invZScale = 1 / fMat[2][2];
473 475
474 inverse->fMat[0][0] = invXScale; 476 inverse->fMat[0][0] = invXScale;
475 inverse->fMat[0][1] = 0; 477 inverse->fMat[0][1] = 0;
476 inverse->fMat[0][2] = 0; 478 inverse->fMat[0][2] = 0;
477 inverse->fMat[0][3] = 0; 479 inverse->fMat[0][3] = 0;
478 480
479 inverse->fMat[1][0] = 0; 481 inverse->fMat[1][0] = 0;
480 inverse->fMat[1][1] = invYScale; 482 inverse->fMat[1][1] = invYScale;
481 inverse->fMat[1][2] = 0; 483 inverse->fMat[1][2] = 0;
482 inverse->fMat[1][3] = 0; 484 inverse->fMat[1][3] = 0;
483 485
484 inverse->fMat[2][0] = 0; 486 inverse->fMat[2][0] = 0;
485 inverse->fMat[2][1] = 0; 487 inverse->fMat[2][1] = 0;
486 inverse->fMat[2][2] = invZScale; 488 inverse->fMat[2][2] = invZScale;
487 inverse->fMat[2][3] = 0; 489 inverse->fMat[2][3] = 0;
488 490
489 inverse->fMat[3][0] = -fMat[3][0] * invXScale; 491 inverse->fMat[3][0] = -fMat[3][0] * invXScale;
490 inverse->fMat[3][1] = -fMat[3][1] * invYScale; 492 inverse->fMat[3][1] = -fMat[3][1] * invYScale;
491 inverse->fMat[3][2] = -fMat[3][2] * invZScale; 493 inverse->fMat[3][2] = -fMat[3][2] * invZScale;
492 inverse->fMat[3][3] = 1; 494 inverse->fMat[3][3] = 1;
493 495
494 inverse->setTypeMask(this->getType()); 496 inverse->setTypeMask(this->getType());
495 } 497 }
496 498
497 return true; 499 return true;
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 dst[SkMatrix::kMSkewY] = SkMScalarToScalar(fMat[0][1]); 923 dst[SkMatrix::kMSkewY] = SkMScalarToScalar(fMat[0][1]);
922 dst[SkMatrix::kMScaleY] = SkMScalarToScalar(fMat[1][1]); 924 dst[SkMatrix::kMScaleY] = SkMScalarToScalar(fMat[1][1]);
923 dst[SkMatrix::kMTransY] = SkMScalarToScalar(fMat[3][1]); 925 dst[SkMatrix::kMTransY] = SkMScalarToScalar(fMat[3][1]);
924 926
925 dst[SkMatrix::kMPersp0] = SkMScalarToScalar(fMat[0][3]); 927 dst[SkMatrix::kMPersp0] = SkMScalarToScalar(fMat[0][3]);
926 dst[SkMatrix::kMPersp1] = SkMScalarToScalar(fMat[1][3]); 928 dst[SkMatrix::kMPersp1] = SkMScalarToScalar(fMat[1][3]);
927 dst[SkMatrix::kMPersp2] = SkMScalarToScalar(fMat[3][3]); 929 dst[SkMatrix::kMPersp2] = SkMScalarToScalar(fMat[3][3]);
928 930
929 return dst; 931 return dst;
930 } 932 }
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