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 "SkRRect.h" | |
10 | 11 |
11 #ifdef GR_TEST_UTILS | 12 #ifdef GR_TEST_UTILS |
12 | 13 |
13 namespace GrTest { | 14 namespace GrTest { |
14 const SkMatrix& TestMatrix(SkRandom* random) { | 15 const SkMatrix& TestMatrix(SkRandom* random) { |
15 static SkMatrix gMatrices[5]; | 16 static SkMatrix gMatrices[5]; |
16 static bool gOnce; | 17 static bool gOnce; |
17 if (!gOnce) { | 18 if (!gOnce) { |
18 gMatrices[0].reset(); | 19 gMatrices[0].reset(); |
19 gMatrices[1].setTranslate(SkIntToScalar(-100), SkIntToScalar(100)); | 20 gMatrices[1].setTranslate(SkIntToScalar(-100), SkIntToScalar(100)); |
20 gMatrices[2].setRotate(SkIntToScalar(17)); | 21 gMatrices[2].setRotate(SkIntToScalar(17)); |
21 gMatrices[3].setRotate(SkIntToScalar(185)); | 22 gMatrices[3].setRotate(SkIntToScalar(185)); |
22 gMatrices[3].postTranslate(SkIntToScalar(66), SkIntToScalar(-33)); | 23 gMatrices[3].postTranslate(SkIntToScalar(66), SkIntToScalar(-33)); |
23 gMatrices[3].postScale(SkIntToScalar(2), SK_ScalarHalf); | 24 gMatrices[3].postScale(SkIntToScalar(2), SK_ScalarHalf); |
24 gMatrices[4].setRotate(SkIntToScalar(215)); | 25 gMatrices[4].setRotate(SkIntToScalar(215)); |
25 gMatrices[4].set(SkMatrix::kMPersp0, 0.00013f); | 26 gMatrices[4].set(SkMatrix::kMPersp0, 0.00013f); |
26 gMatrices[4].set(SkMatrix::kMPersp1, -0.000039f); | 27 gMatrices[4].set(SkMatrix::kMPersp1, -0.000039f); |
27 gOnce = true; | 28 gOnce = true; |
28 } | 29 } |
29 return gMatrices[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT( gMatrices)))]; | 30 return gMatrices[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT( gMatrices)))]; |
30 } | 31 } |
31 | 32 |
32 const SkMatrix& TestMatrixPreservesRightAngles(SkRandom* random) { | 33 const SkMatrix& TestMatrixPreservesRightAngles(SkRandom* random) { |
33 static SkMatrix gMatrices[4]; | 34 static SkMatrix gMatrices[5]; |
34 static bool gOnce; | 35 static bool gOnce; |
35 if (!gOnce) { | 36 if (!gOnce) { |
36 // identity | 37 // identity |
37 gMatrices[0].reset(); | 38 gMatrices[0].reset(); |
38 // translation | 39 // translation |
39 gMatrices[1].setTranslate(SkIntToScalar(-100), SkIntToScalar(100)); | 40 gMatrices[1].setTranslate(SkIntToScalar(-100), SkIntToScalar(100)); |
40 // scale | 41 // scale |
41 gMatrices[2].setScale(SkIntToScalar(17), SkIntToScalar(17)); | 42 gMatrices[2].setScale(SkIntToScalar(17), SkIntToScalar(17)); |
42 // scale + translation | 43 // scale + translation |
43 gMatrices[3].setScale(SkIntToScalar(-17), SkIntToScalar(-17)); | 44 gMatrices[3].setScale(SkIntToScalar(-17), SkIntToScalar(-17)); |
44 gMatrices[3].postTranslate(SkIntToScalar(66), SkIntToScalar(-33)); | 45 gMatrices[3].postTranslate(SkIntToScalar(66), SkIntToScalar(-33)); |
45 // orthogonal basis vectors | 46 // orthogonal basis vectors |
46 gMatrices[4].reset(); | 47 gMatrices[4].reset(); |
47 gMatrices[4].setScale(SkIntToScalar(-1), SkIntToScalar(-1)); | 48 gMatrices[4].setScale(SkIntToScalar(-1), SkIntToScalar(-1)); |
48 gMatrices[4].setRotate(47); | 49 gMatrices[4].setRotate(47); |
49 gOnce = true; | 50 gOnce = true; |
50 | 51 |
51 for (size_t i = 0; i < SK_ARRAY_COUNT(gMatrices); i++) { | 52 for (size_t i = 0; i < SK_ARRAY_COUNT(gMatrices); i++) { |
52 SkASSERT(gMatrices[i].preservesRightAngles()); | 53 SkASSERT(gMatrices[i].preservesRightAngles()); |
53 } | 54 } |
54 } | 55 } |
55 return gMatrices[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT( gMatrices)))]; | 56 return gMatrices[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT( gMatrices)))]; |
56 } | 57 } |
57 | 58 |
59 const SkMatrix& TestMatrixRectStaysRect(SkRandom* random) { | |
60 static SkMatrix gMatrices[6]; | |
61 static bool gOnce; | |
62 if (!gOnce) { | |
63 // identity | |
64 gMatrices[0].reset(); | |
65 // translation | |
66 gMatrices[1].setTranslate(SkIntToScalar(-100), SkIntToScalar(100)); | |
67 // scale | |
68 gMatrices[2].setScale(SkIntToScalar(17), SkIntToScalar(17)); | |
69 // scale + translation | |
70 gMatrices[3].setScale(SkIntToScalar(-17), SkIntToScalar(-17)); | |
71 gMatrices[3].postTranslate(SkIntToScalar(66), SkIntToScalar(-33)); | |
72 // reflection | |
73 gMatrices[4].setScale(SkIntToScalar(-1), SkIntToScalar(-1)); | |
74 // 90 degress rotation | |
75 gMatrices[5].setRotate(90); | |
robertphillips
2015/04/30 14:07:32
Move this up to first line in the if-block?
| |
76 gOnce = true; | |
77 | |
78 for (size_t i = 0; i < SK_ARRAY_COUNT(gMatrices); i++) { | |
79 SkASSERT(gMatrices[i].rectStaysRect()); | |
80 } | |
81 } | |
82 return gMatrices[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT( gMatrices)))]; | |
83 } | |
84 | |
58 const SkRect& TestRect(SkRandom* random) { | 85 const SkRect& TestRect(SkRandom* random) { |
59 static SkRect gRects[1]; | 86 static SkRect gRects[7]; |
60 static bool gOnce; | 87 static bool gOnce; |
61 if (!gOnce) { | 88 if (!gOnce) { |
62 gRects[0] = SkRect::MakeWH(1.f, 1.f); | 89 gRects[0] = SkRect::MakeWH(1.f, 1.f); |
63 gRects[1] = SkRect::MakeWH(1.0f, 256.0f); | 90 gRects[1] = SkRect::MakeWH(1.0f, 256.0f); |
64 gRects[2] = SkRect::MakeWH(256.0f, 1.0f); | 91 gRects[2] = SkRect::MakeWH(256.0f, 1.0f); |
65 gRects[4] = SkRect::MakeLargest(); | 92 gRects[4] = SkRect::MakeLargest(); |
66 gRects[5] = SkRect::MakeLTRB(-65535.0f, -65535.0f, 65535.0f, 65535.0f); | 93 gRects[5] = SkRect::MakeLTRB(-65535.0f, -65535.0f, 65535.0f, 65535.0f); |
67 gRects[6] = SkRect::MakeLTRB(10.0f, 10.0f, -10.0f, -10.0f); | 94 gRects[6] = SkRect::MakeLTRB(10.0f, 10.0f, -10.0f, -10.0f); |
68 gOnce = true; | 95 gOnce = true; |
69 } | 96 } |
70 return gRects[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gRe cts)))]; | 97 return gRects[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gRe cts)))]; |
71 } | 98 } |
99 | |
100 const SkRRect& TestRRectSimple(SkRandom* random) { | |
101 static SkRRect gRRect[3]; | |
102 static bool gOnce; | |
103 if (!gOnce) { | |
104 SkRect square = SkRect::MakeWH(10.f, 10.f); | |
105 SkRect rectangle = SkRect::MakeWH(10.f, 20.f); | |
106 // rect | |
107 gRRect[0].setRect(square); | |
108 // oval | |
109 gRRect[1].setOval(rectangle); | |
110 // true round rect | |
robertphillips
2015/04/30 14:07:32
// true round rect with circular corners
| |
111 gRRect[2].setRectXY(rectangle, 1.f, 1.f); | |
robertphillips
2015/04/30 14:07:32
// true round rect with elliptical corners
gRRect[
robertphillips
2015/04/30 14:07:32
same here ?
| |
112 gOnce = true; | |
113 | |
114 for (size_t i = 0; i < SK_ARRAY_COUNT(gRRect); i++) { | |
115 SkASSERT(gRRect[i].isSimple()); | |
116 } | |
117 } | |
118 return gRRect[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gRR ect)))]; | |
119 } | |
120 | |
72 }; | 121 }; |
73 | 122 |
74 #endif | 123 #endif |
OLD | NEW |