Fix matrix type in setRectToRect

Review URL: https://codereview.appspot.com/6655055

git-svn-id: http://skia.googlecode.com/svn/trunk@5913 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@google.com 2012-10-12 14:35:48 +00:00
parent e9c2f9ba9e
commit 97cd69ca23
2 changed files with 36 additions and 1 deletions

View File

@ -544,7 +544,14 @@ bool SkMatrix::setRectToRect(const SkRect& src, const SkRect& dst,
fMat[kMSkewX] = fMat[kMSkewY] =
fMat[kMPersp0] = fMat[kMPersp1] = 0;
this->setTypeMask(kScale_Mask | kTranslate_Mask | kRectStaysRect_Mask);
unsigned mask = kRectStaysRect_Mask;
if (sx != SK_Scalar1 || sy != SK_Scalar1) {
mask |= kScale_Mask;
}
if (tx || ty) {
mask |= kTranslate_Mask;
}
this->setTypeMask(mask);
}
// shared cleanup
fMat[kMPersp2] = kMatrix22Elem;

View File

@ -81,6 +81,33 @@ static bool is_identity(const SkMatrix& m) {
return nearly_equal(m, identity);
}
static void test_matrix_recttorect(skiatest::Reporter* reporter) {
SkRect src, dst;
SkMatrix matrix;
src.set(0, 0, SK_Scalar1*10, SK_Scalar1*10);
dst = src;
matrix.setRectToRect(src, dst, SkMatrix::kFill_ScaleToFit);
REPORTER_ASSERT(reporter, SkMatrix::kIdentity_Mask == matrix.getType());
REPORTER_ASSERT(reporter, matrix.rectStaysRect());
dst.offset(SK_Scalar1, SK_Scalar1);
matrix.setRectToRect(src, dst, SkMatrix::kFill_ScaleToFit);
REPORTER_ASSERT(reporter, SkMatrix::kTranslate_Mask == matrix.getType());
REPORTER_ASSERT(reporter, matrix.rectStaysRect());
dst.fRight += SK_Scalar1;
matrix.setRectToRect(src, dst, SkMatrix::kFill_ScaleToFit);
REPORTER_ASSERT(reporter, SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask == matrix.getType());
REPORTER_ASSERT(reporter, matrix.rectStaysRect());
dst = src;
dst.fRight = src.fRight * 2;
matrix.setRectToRect(src, dst, SkMatrix::kFill_ScaleToFit);
REPORTER_ASSERT(reporter, SkMatrix::kScale_Mask == matrix.getType());
REPORTER_ASSERT(reporter, matrix.rectStaysRect());
}
static void test_flatten(skiatest::Reporter* reporter, const SkMatrix& m) {
// add 100 in case we have a bug, I don't want to kill my stack in the test
char buffer[SkMatrix::kMaxFlattenSize + 100];
@ -459,6 +486,7 @@ static void TestMatrix(skiatest::Reporter* reporter) {
test_matrix_max_stretch(reporter);
test_matrix_is_similarity_transform(reporter);
test_matrix_recttorect(reporter);
}
#include "TestClassDef.h"