| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "GrTestUtils.h" | 8 #include "GrTestUtils.h" |
| 9 #include "SkMatrix.h" | 9 #include "SkMatrix.h" |
| 10 #include "SkPath.h" | 10 #include "SkPath.h" |
| 11 #include "SkRRect.h" | 11 #include "SkRRect.h" |
| 12 | 12 |
| 13 #ifdef GR_TEST_UTILS | 13 #ifdef GR_TEST_UTILS |
| 14 | 14 |
| 15 namespace GrTest { | 15 static const SkMatrix& test_matrix(SkRandom* random, bool includePerspective) { |
| 16 const SkMatrix& TestMatrix(SkRandom* random) { | |
| 17 static SkMatrix gMatrices[5]; | 16 static SkMatrix gMatrices[5]; |
| 17 static const int kPerspectiveCount = 1; |
| 18 static bool gOnce; | 18 static bool gOnce; |
| 19 if (!gOnce) { | 19 if (!gOnce) { |
| 20 gOnce = true; | 20 gOnce = true; |
| 21 gMatrices[0].reset(); | 21 gMatrices[0].reset(); |
| 22 gMatrices[1].setTranslate(SkIntToScalar(-100), SkIntToScalar(100)); | 22 gMatrices[1].setTranslate(SkIntToScalar(-100), SkIntToScalar(100)); |
| 23 gMatrices[2].setRotate(SkIntToScalar(17)); | 23 gMatrices[2].setRotate(SkIntToScalar(17)); |
| 24 gMatrices[3].setRotate(SkIntToScalar(185)); | 24 gMatrices[3].setRotate(SkIntToScalar(185)); |
| 25 gMatrices[3].postTranslate(SkIntToScalar(66), SkIntToScalar(-33)); | 25 gMatrices[3].postTranslate(SkIntToScalar(66), SkIntToScalar(-33)); |
| 26 gMatrices[3].postScale(SkIntToScalar(2), SK_ScalarHalf); | 26 gMatrices[3].postScale(SkIntToScalar(2), SK_ScalarHalf); |
| 27 |
| 28 // Perspective matrices |
| 27 gMatrices[4].setRotate(SkIntToScalar(215)); | 29 gMatrices[4].setRotate(SkIntToScalar(215)); |
| 28 gMatrices[4].set(SkMatrix::kMPersp0, 0.00013f); | 30 gMatrices[4].set(SkMatrix::kMPersp0, 0.00013f); |
| 29 gMatrices[4].set(SkMatrix::kMPersp1, -0.000039f); | 31 gMatrices[4].set(SkMatrix::kMPersp1, -0.000039f); |
| 30 } | 32 } |
| 31 return gMatrices[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(
gMatrices)))]; | 33 |
| 34 uint32_t count = static_cast<uint32_t>(SK_ARRAY_COUNT(gMatrices)); |
| 35 if (includePerspective) { |
| 36 return gMatrices[random->nextULessThan(count)]; |
| 37 } else { |
| 38 return gMatrices[random->nextULessThan(count - kPerspectiveCount)]; |
| 39 } |
| 32 } | 40 } |
| 33 | 41 |
| 42 namespace GrTest { |
| 43 const SkMatrix& TestMatrix(SkRandom* random) { return test_matrix(random, true);
} |
| 44 |
| 34 const SkMatrix& TestMatrixPreservesRightAngles(SkRandom* random) { | 45 const SkMatrix& TestMatrixPreservesRightAngles(SkRandom* random) { |
| 35 static SkMatrix gMatrices[5]; | 46 static SkMatrix gMatrices[5]; |
| 36 static bool gOnce; | 47 static bool gOnce; |
| 37 if (!gOnce) { | 48 if (!gOnce) { |
| 38 gOnce = true; | 49 gOnce = true; |
| 39 // identity | 50 // identity |
| 40 gMatrices[0].reset(); | 51 gMatrices[0].reset(); |
| 41 // translation | 52 // translation |
| 42 gMatrices[1].setTranslate(SkIntToScalar(-100), SkIntToScalar(100)); | 53 gMatrices[1].setTranslate(SkIntToScalar(-100), SkIntToScalar(100)); |
| 43 // scale | 54 // scale |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 // 90 degress rotation | 87 // 90 degress rotation |
| 77 gMatrices[5].setRotate(90); | 88 gMatrices[5].setRotate(90); |
| 78 | 89 |
| 79 for (size_t i = 0; i < SK_ARRAY_COUNT(gMatrices); i++) { | 90 for (size_t i = 0; i < SK_ARRAY_COUNT(gMatrices); i++) { |
| 80 SkASSERT(gMatrices[i].rectStaysRect()); | 91 SkASSERT(gMatrices[i].rectStaysRect()); |
| 81 } | 92 } |
| 82 } | 93 } |
| 83 return gMatrices[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(
gMatrices)))]; | 94 return gMatrices[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(
gMatrices)))]; |
| 84 } | 95 } |
| 85 | 96 |
| 97 const SkMatrix& TestMatrixInvertible(SkRandom* random) { return test_matrix(rand
om, false); } |
| 98 |
| 86 const SkRect& TestRect(SkRandom* random) { | 99 const SkRect& TestRect(SkRandom* random) { |
| 87 static SkRect gRects[7]; | 100 static SkRect gRects[7]; |
| 88 static bool gOnce; | 101 static bool gOnce; |
| 89 if (!gOnce) { | 102 if (!gOnce) { |
| 90 gOnce = true; | 103 gOnce = true; |
| 91 gRects[0] = SkRect::MakeWH(1.f, 1.f); | 104 gRects[0] = SkRect::MakeWH(1.f, 1.f); |
| 92 gRects[1] = SkRect::MakeWH(1.0f, 256.0f); | 105 gRects[1] = SkRect::MakeWH(1.0f, 256.0f); |
| 93 gRects[2] = SkRect::MakeWH(256.0f, 1.0f); | 106 gRects[2] = SkRect::MakeWH(256.0f, 1.0f); |
| 94 gRects[4] = SkRect::MakeLargest(); | 107 gRects[4] = SkRect::MakeLargest(); |
| 95 gRects[5] = SkRect::MakeLTRB(-65535.0f, -65535.0f, 65535.0f, 65535.0f); | 108 gRects[5] = SkRect::MakeLTRB(-65535.0f, -65535.0f, 65535.0f, 65535.0f); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 gPath[6].lineTo(0.0f, 10.0f); | 171 gPath[6].lineTo(0.0f, 10.0f); |
| 159 gPath[6].close(); | 172 gPath[6].close(); |
| 160 } | 173 } |
| 161 | 174 |
| 162 return gPath[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gPat
h)))]; | 175 return gPath[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gPat
h)))]; |
| 163 } | 176 } |
| 164 | 177 |
| 165 }; | 178 }; |
| 166 | 179 |
| 167 #endif | 180 #endif |
| OLD | NEW |