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) { |
robertphillips
2015/05/07 19:10:44
Shouldn't this still be 5 ?
| |
16 const SkMatrix& TestMatrix(SkRandom* random) { | 16 static SkMatrix gMatrices[4]; |
17 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 } | |
40 } | |
41 | |
42 namespace GrTest { | |
robertphillips
2015/05/07 19:10:44
one line ?
| |
43 const SkMatrix& TestMatrix(SkRandom* random) { | |
44 return test_matrix(random, true); | |
32 } | 45 } |
33 | 46 |
34 const SkMatrix& TestMatrixPreservesRightAngles(SkRandom* random) { | 47 const SkMatrix& TestMatrixPreservesRightAngles(SkRandom* random) { |
35 static SkMatrix gMatrices[5]; | 48 static SkMatrix gMatrices[5]; |
36 static bool gOnce; | 49 static bool gOnce; |
37 if (!gOnce) { | 50 if (!gOnce) { |
38 gOnce = true; | 51 gOnce = true; |
39 // identity | 52 // identity |
40 gMatrices[0].reset(); | 53 gMatrices[0].reset(); |
41 // translation | 54 // translation |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
76 // 90 degress rotation | 89 // 90 degress rotation |
77 gMatrices[5].setRotate(90); | 90 gMatrices[5].setRotate(90); |
78 | 91 |
79 for (size_t i = 0; i < SK_ARRAY_COUNT(gMatrices); i++) { | 92 for (size_t i = 0; i < SK_ARRAY_COUNT(gMatrices); i++) { |
80 SkASSERT(gMatrices[i].rectStaysRect()); | 93 SkASSERT(gMatrices[i].rectStaysRect()); |
81 } | 94 } |
82 } | 95 } |
83 return gMatrices[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT( gMatrices)))]; | 96 return gMatrices[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT( gMatrices)))]; |
84 } | 97 } |
85 | 98 |
99 const SkMatrix& TestMatrixInvertible(SkRandom* random) { | |
100 return test_matrix(random, false); | |
101 } | |
102 | |
86 const SkRect& TestRect(SkRandom* random) { | 103 const SkRect& TestRect(SkRandom* random) { |
87 static SkRect gRects[7]; | 104 static SkRect gRects[7]; |
88 static bool gOnce; | 105 static bool gOnce; |
89 if (!gOnce) { | 106 if (!gOnce) { |
90 gOnce = true; | 107 gOnce = true; |
91 gRects[0] = SkRect::MakeWH(1.f, 1.f); | 108 gRects[0] = SkRect::MakeWH(1.f, 1.f); |
92 gRects[1] = SkRect::MakeWH(1.0f, 256.0f); | 109 gRects[1] = SkRect::MakeWH(1.0f, 256.0f); |
93 gRects[2] = SkRect::MakeWH(256.0f, 1.0f); | 110 gRects[2] = SkRect::MakeWH(256.0f, 1.0f); |
94 gRects[4] = SkRect::MakeLargest(); | 111 gRects[4] = SkRect::MakeLargest(); |
95 gRects[5] = SkRect::MakeLTRB(-65535.0f, -65535.0f, 65535.0f, 65535.0f); | 112 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); | 175 gPath[6].lineTo(0.0f, 10.0f); |
159 gPath[6].close(); | 176 gPath[6].close(); |
160 } | 177 } |
161 | 178 |
162 return gPath[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gPat h)))]; | 179 return gPath[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gPat h)))]; |
163 } | 180 } |
164 | 181 |
165 }; | 182 }; |
166 | 183 |
167 #endif | 184 #endif |
OLD | NEW |