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" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 const SkRect& TestRect(SkRandom* random) { | 99 const SkRect& TestRect(SkRandom* random) { |
100 static SkRect gRects[7]; | 100 static SkRect gRects[7]; |
101 static bool gOnce; | 101 static bool gOnce; |
102 if (!gOnce) { | 102 if (!gOnce) { |
103 gOnce = true; | 103 gOnce = true; |
104 gRects[0] = SkRect::MakeWH(1.f, 1.f); | 104 gRects[0] = SkRect::MakeWH(1.f, 1.f); |
105 gRects[1] = SkRect::MakeWH(1.0f, 256.0f); | 105 gRects[1] = SkRect::MakeWH(1.0f, 256.0f); |
106 gRects[2] = SkRect::MakeWH(256.0f, 1.0f); | 106 gRects[2] = SkRect::MakeWH(256.0f, 1.0f); |
107 gRects[4] = SkRect::MakeLargest(); | 107 gRects[4] = SkRect::MakeLargest(); |
108 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); |
109 gRects[6] = SkRect::MakeLTRB(10.0f, 10.0f, -10.0f, -10.0f); | 109 gRects[6] = SkRect::MakeLTRB(-10.0f, -10.0f, 10.0f, 10.0f); |
| 110 } |
| 111 return gRects[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gRe
cts)))]; |
| 112 } |
| 113 |
| 114 // Just some simple rects for code which expects its input very sanitized |
| 115 const SkRect& TestSquare(SkRandom* random) { |
| 116 static SkRect gRects[2]; |
| 117 static bool gOnce; |
| 118 if (!gOnce) { |
| 119 gOnce = true; |
| 120 gRects[0] = SkRect::MakeWH(128.f, 128.f); |
| 121 gRects[1] = SkRect::MakeWH(256.0f, 256.0f); |
110 } | 122 } |
111 return gRects[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gRe
cts)))]; | 123 return gRects[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gRe
cts)))]; |
112 } | 124 } |
113 | 125 |
114 const SkRRect& TestRRectSimple(SkRandom* random) { | 126 const SkRRect& TestRRectSimple(SkRandom* random) { |
115 static SkRRect gRRect[4]; | 127 static SkRRect gRRect[2]; |
116 static bool gOnce; | 128 static bool gOnce; |
117 if (!gOnce) { | 129 if (!gOnce) { |
118 gOnce = true; | 130 gOnce = true; |
119 SkRect square = SkRect::MakeWH(10.f, 10.f); | |
120 SkRect rectangle = SkRect::MakeWH(10.f, 20.f); | 131 SkRect rectangle = SkRect::MakeWH(10.f, 20.f); |
121 // rect | |
122 gRRect[0].setRect(square); | |
123 // oval | |
124 gRRect[1].setOval(rectangle); | |
125 // true round rect with circular corners | 132 // true round rect with circular corners |
126 gRRect[2].setRectXY(rectangle, 1.f, 1.f); | 133 gRRect[0].setRectXY(rectangle, 1.f, 1.f); |
127 // true round rect with elliptical corners | 134 // true round rect with elliptical corners |
128 gRRect[3].setRectXY(rectangle, 2.0f, 1.0f); | 135 gRRect[1].setRectXY(rectangle, 2.0f, 1.0f); |
129 | 136 |
130 for (size_t i = 0; i < SK_ARRAY_COUNT(gRRect); i++) { | 137 for (size_t i = 0; i < SK_ARRAY_COUNT(gRRect); i++) { |
131 SkASSERT(gRRect[i].isSimple()); | 138 SkASSERT(gRRect[i].isSimple()); |
132 } | 139 } |
133 } | 140 } |
134 return gRRect[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gRR
ect)))]; | 141 return gRRect[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gRR
ect)))]; |
135 } | 142 } |
136 | 143 |
137 const SkPath& TestPath(SkRandom* random) { | 144 const SkPath& TestPath(SkRandom* random) { |
138 static SkPath gPath[7]; | 145 static SkPath gPath[7]; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 | 181 |
175 return gPath[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gPat
h)))]; | 182 return gPath[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gPat
h)))]; |
176 } | 183 } |
177 | 184 |
178 const SkPath& TestPathConvex(SkRandom* random) { | 185 const SkPath& TestPathConvex(SkRandom* random) { |
179 static SkPath gPath[3]; | 186 static SkPath gPath[3]; |
180 static bool gOnce; | 187 static bool gOnce; |
181 if (!gOnce) { | 188 if (!gOnce) { |
182 gOnce = true; | 189 gOnce = true; |
183 // narrow rect | 190 // narrow rect |
184 gPath[0].moveTo(0.f, 0.f); | 191 gPath[0].moveTo(-1.5f, -50.0f); |
185 gPath[0].lineTo(-1.5f, -50.0f); | 192 gPath[0].lineTo(-1.5f, -50.0f); |
186 gPath[0].lineTo( 1.5f, -50.0f); | 193 gPath[0].lineTo( 1.5f, -50.0f); |
187 gPath[0].lineTo( 1.5f, 50.0f); | 194 gPath[0].lineTo( 1.5f, 50.0f); |
188 gPath[0].lineTo(-1.5f, 50.0f); | 195 gPath[0].lineTo(-1.5f, 50.0f); |
189 // degenerate | 196 // degenerate |
190 gPath[1].moveTo(0.f, 0.f); | 197 gPath[1].moveTo(-0.025f, -0.025f); |
191 gPath[1].lineTo(-0.025f, -0.025f); | 198 gPath[1].lineTo(-0.025f, -0.025f); |
192 gPath[1].lineTo( 0.025f, -0.025f); | 199 gPath[1].lineTo( 0.025f, -0.025f); |
193 gPath[1].lineTo( 0.025f, 0.025f); | 200 gPath[1].lineTo( 0.025f, 0.025f); |
194 gPath[1].lineTo(-0.025f, 0.025f); | 201 gPath[1].lineTo(-0.025f, 0.025f); |
195 // clipped triangle | 202 // clipped triangle |
196 gPath[2].moveTo(0.f, 0.f); | 203 gPath[2].moveTo(-10.0f, -50.0f); |
197 gPath[2].lineTo(-10.0f, -50.0f); | 204 gPath[2].lineTo(-10.0f, -50.0f); |
198 gPath[2].lineTo( 10.0f, -50.0f); | 205 gPath[2].lineTo( 10.0f, -50.0f); |
199 gPath[2].lineTo( 50.0f, 31.0f); | 206 gPath[2].lineTo( 50.0f, 31.0f); |
200 gPath[2].lineTo( 40.0f, 50.0f); | 207 gPath[2].lineTo( 40.0f, 50.0f); |
201 gPath[2].lineTo(-40.0f, 50.0f); | 208 gPath[2].lineTo(-40.0f, 50.0f); |
202 gPath[2].lineTo(-50.0f, 31.0f); | 209 gPath[2].lineTo(-50.0f, 31.0f); |
| 210 |
| 211 for (size_t i = 0; i < SK_ARRAY_COUNT(gPath); i++) { |
| 212 SkASSERT(SkPath::kConvex_Convexity == gPath[i].getConvexity()); |
| 213 } |
203 } | 214 } |
204 | 215 |
205 return gPath[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gPat
h)))]; | 216 return gPath[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gPat
h)))]; |
206 } | 217 } |
207 | 218 |
208 SkStrokeRec TestStrokeRec(SkRandom* random) { | 219 SkStrokeRec TestStrokeRec(SkRandom* random) { |
209 SkStrokeRec::InitStyle style = | 220 SkStrokeRec::InitStyle style = |
210 SkStrokeRec::InitStyle(random->nextULessThan(SkStrokeRec::kFill_Init
Style + 1)); | 221 SkStrokeRec::InitStyle(random->nextULessThan(SkStrokeRec::kFill_Init
Style + 1)); |
211 SkStrokeRec rec(style); | 222 SkStrokeRec rec(style); |
212 bool strokeAndFill = random->nextBool(); | 223 bool strokeAndFill = random->nextBool(); |
213 SkScalar strokeWidth = random->nextBool() ? 0.f : 1.f; | 224 SkScalar strokeWidth = random->nextBool() ? 0.f : 1.f; |
214 rec.setStrokeStyle(strokeWidth, strokeAndFill); | 225 rec.setStrokeStyle(strokeWidth, strokeAndFill); |
215 | 226 |
216 SkPaint::Cap cap = SkPaint::Cap(random->nextULessThan(SkPaint::kCapCount)); | 227 SkPaint::Cap cap = SkPaint::Cap(random->nextULessThan(SkPaint::kCapCount)); |
217 SkPaint::Join join = SkPaint::Join(random->nextULessThan(SkPaint::kJoinCount
)); | 228 SkPaint::Join join = SkPaint::Join(random->nextULessThan(SkPaint::kJoinCount
)); |
218 SkScalar miterLimit = random->nextRangeScalar(1.f, 5.f); | 229 SkScalar miterLimit = random->nextRangeScalar(1.f, 5.f); |
219 rec.setStrokeParams(cap, join, miterLimit); | 230 rec.setStrokeParams(cap, join, miterLimit); |
220 return rec; | 231 return rec; |
221 } | 232 } |
222 | 233 |
223 }; | 234 }; |
224 | 235 |
225 #endif | 236 #endif |
OLD | NEW |