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 "GrStyle.h" | 9 #include "GrStyle.h" |
10 #include "SkDashPathPriv.h" | 10 #include "SkDashPathPriv.h" |
11 #include "SkMatrix.h" | 11 #include "SkMatrix.h" |
12 #include "SkPath.h" | 12 #include "SkPath.h" |
13 #include "SkRRect.h" | 13 #include "SkRRect.h" |
14 | 14 |
15 #ifdef GR_TEST_UTILS | 15 #ifdef GR_TEST_UTILS |
16 | 16 |
17 static const SkMatrix& test_matrix(SkRandom* random, bool includePerspective) { | 17 static const SkMatrix& test_matrix(SkRandom* random, |
| 18 bool includeNonPerspective, |
| 19 bool includePerspective) { |
18 static SkMatrix gMatrices[5]; | 20 static SkMatrix gMatrices[5]; |
19 static const int kPerspectiveCount = 1; | 21 static const int kPerspectiveCount = 1; |
20 static bool gOnce; | 22 static bool gOnce; |
21 if (!gOnce) { | 23 if (!gOnce) { |
22 gOnce = true; | 24 gOnce = true; |
23 gMatrices[0].reset(); | 25 gMatrices[0].reset(); |
24 gMatrices[1].setTranslate(SkIntToScalar(-100), SkIntToScalar(100)); | 26 gMatrices[1].setTranslate(SkIntToScalar(-100), SkIntToScalar(100)); |
25 gMatrices[2].setRotate(SkIntToScalar(17)); | 27 gMatrices[2].setRotate(SkIntToScalar(17)); |
26 gMatrices[3].setRotate(SkIntToScalar(185)); | 28 gMatrices[3].setRotate(SkIntToScalar(185)); |
27 gMatrices[3].postTranslate(SkIntToScalar(66), SkIntToScalar(-33)); | 29 gMatrices[3].postTranslate(SkIntToScalar(66), SkIntToScalar(-33)); |
28 gMatrices[3].postScale(SkIntToScalar(2), SK_ScalarHalf); | 30 gMatrices[3].postScale(SkIntToScalar(2), SK_ScalarHalf); |
29 | 31 |
30 // Perspective matrices | 32 // Perspective matrices |
31 gMatrices[4].setRotate(SkIntToScalar(215)); | 33 gMatrices[4].setRotate(SkIntToScalar(215)); |
32 gMatrices[4].set(SkMatrix::kMPersp0, 0.00013f); | 34 gMatrices[4].set(SkMatrix::kMPersp0, 0.00013f); |
33 gMatrices[4].set(SkMatrix::kMPersp1, -0.000039f); | 35 gMatrices[4].set(SkMatrix::kMPersp1, -0.000039f); |
34 } | 36 } |
35 | 37 |
36 uint32_t count = static_cast<uint32_t>(SK_ARRAY_COUNT(gMatrices)); | 38 uint32_t count = static_cast<uint32_t>(SK_ARRAY_COUNT(gMatrices)); |
37 if (includePerspective) { | 39 if (includeNonPerspective && includePerspective) { |
38 return gMatrices[random->nextULessThan(count)]; | 40 return gMatrices[random->nextULessThan(count)]; |
| 41 } else if (!includeNonPerspective) { |
| 42 return gMatrices[count - 1 - random->nextULessThan(kPerspectiveCount)]; |
39 } else { | 43 } else { |
| 44 SkASSERT(includeNonPerspective && !includePerspective); |
40 return gMatrices[random->nextULessThan(count - kPerspectiveCount)]; | 45 return gMatrices[random->nextULessThan(count - kPerspectiveCount)]; |
41 } | 46 } |
42 } | 47 } |
43 | 48 |
44 namespace GrTest { | 49 namespace GrTest { |
45 const SkMatrix& TestMatrix(SkRandom* random) { return test_matrix(random, true);
} | 50 const SkMatrix& TestMatrix(SkRandom* random) { return test_matrix(random, true,
true); } |
46 | 51 |
47 const SkMatrix& TestMatrixPreservesRightAngles(SkRandom* random) { | 52 const SkMatrix& TestMatrixPreservesRightAngles(SkRandom* random) { |
48 static SkMatrix gMatrices[5]; | 53 static SkMatrix gMatrices[5]; |
49 static bool gOnce; | 54 static bool gOnce; |
50 if (!gOnce) { | 55 if (!gOnce) { |
51 gOnce = true; | 56 gOnce = true; |
52 // identity | 57 // identity |
53 gMatrices[0].reset(); | 58 gMatrices[0].reset(); |
54 // translation | 59 // translation |
55 gMatrices[1].setTranslate(SkIntToScalar(-100), SkIntToScalar(100)); | 60 gMatrices[1].setTranslate(SkIntToScalar(-100), SkIntToScalar(100)); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 // 90 degress rotation | 94 // 90 degress rotation |
90 gMatrices[5].setRotate(90); | 95 gMatrices[5].setRotate(90); |
91 | 96 |
92 for (size_t i = 0; i < SK_ARRAY_COUNT(gMatrices); i++) { | 97 for (size_t i = 0; i < SK_ARRAY_COUNT(gMatrices); i++) { |
93 SkASSERT(gMatrices[i].rectStaysRect()); | 98 SkASSERT(gMatrices[i].rectStaysRect()); |
94 } | 99 } |
95 } | 100 } |
96 return gMatrices[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(
gMatrices)))]; | 101 return gMatrices[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(
gMatrices)))]; |
97 } | 102 } |
98 | 103 |
99 const SkMatrix& TestMatrixInvertible(SkRandom* random) { return test_matrix(rand
om, false); } | 104 const SkMatrix& TestMatrixInvertible(SkRandom* random) { return test_matrix(rand
om, true, false); } |
| 105 const SkMatrix& TestMatrixPerspective(SkRandom* random) { return test_matrix(ran
dom, false, true); } |
100 | 106 |
101 const SkRect& TestRect(SkRandom* random) { | 107 const SkRect& TestRect(SkRandom* random) { |
102 static SkRect gRects[7]; | 108 static SkRect gRects[7]; |
103 static bool gOnce; | 109 static bool gOnce; |
104 if (!gOnce) { | 110 if (!gOnce) { |
105 gOnce = true; | 111 gOnce = true; |
106 gRects[0] = SkRect::MakeWH(1.f, 1.f); | 112 gRects[0] = SkRect::MakeWH(1.f, 1.f); |
107 gRects[1] = SkRect::MakeWH(1.0f, 256.0f); | 113 gRects[1] = SkRect::MakeWH(1.0f, 256.0f); |
108 gRects[2] = SkRect::MakeWH(256.0f, 1.0f); | 114 gRects[2] = SkRect::MakeWH(256.0f, 1.0f); |
109 gRects[3] = SkRect::MakeLargest(); | 115 gRects[3] = SkRect::MakeLargest(); |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 info->fCount = fCount; | 286 info->fCount = fCount; |
281 info->fPhase = fPhase; | 287 info->fPhase = fPhase; |
282 } | 288 } |
283 return kDash_DashType; | 289 return kDash_DashType; |
284 } | 290 } |
285 | 291 |
286 | 292 |
287 } // namespace GrTest | 293 } // namespace GrTest |
288 | 294 |
289 #endif | 295 #endif |
OLD | NEW |