joshualitt | 4eaf9ce | 2015-04-28 13:31:18 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "GrTestUtils.h" |
Brian Osman | 9f532a3 | 2016-10-19 11:12:09 -0400 | [diff] [blame] | 9 | #include "GrProcessorUnitTest.h" |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 10 | #include "GrStyle.h" |
Matt Sarett | 77a7a1b | 2017-02-07 13:56:11 -0500 | [diff] [blame] | 11 | #include "SkColorSpace_Base.h" |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 12 | #include "SkDashPathPriv.h" |
joshualitt | 4eaf9ce | 2015-04-28 13:31:18 -0700 | [diff] [blame] | 13 | #include "SkMatrix.h" |
joshualitt | 40ded32 | 2015-05-02 07:07:17 -0700 | [diff] [blame] | 14 | #include "SkPath.h" |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 15 | #include "SkRRect.h" |
joshualitt | 4eaf9ce | 2015-04-28 13:31:18 -0700 | [diff] [blame] | 16 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 17 | #if GR_TEST_UTILS |
joshualitt | 3f655f3 | 2015-04-29 10:01:22 -0700 | [diff] [blame] | 18 | |
robertphillips | 01a1950 | 2016-07-06 09:58:57 -0700 | [diff] [blame] | 19 | static const SkMatrix& test_matrix(SkRandom* random, |
| 20 | bool includeNonPerspective, |
| 21 | bool includePerspective) { |
joshualitt | 4eaf9ce | 2015-04-28 13:31:18 -0700 | [diff] [blame] | 22 | static SkMatrix gMatrices[5]; |
joshualitt | 2fbd406 | 2015-05-07 13:06:41 -0700 | [diff] [blame] | 23 | static const int kPerspectiveCount = 1; |
joshualitt | 4eaf9ce | 2015-04-28 13:31:18 -0700 | [diff] [blame] | 24 | static bool gOnce; |
| 25 | if (!gOnce) { |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 26 | gOnce = true; |
joshualitt | 4eaf9ce | 2015-04-28 13:31:18 -0700 | [diff] [blame] | 27 | gMatrices[0].reset(); |
| 28 | gMatrices[1].setTranslate(SkIntToScalar(-100), SkIntToScalar(100)); |
| 29 | gMatrices[2].setRotate(SkIntToScalar(17)); |
| 30 | gMatrices[3].setRotate(SkIntToScalar(185)); |
| 31 | gMatrices[3].postTranslate(SkIntToScalar(66), SkIntToScalar(-33)); |
| 32 | gMatrices[3].postScale(SkIntToScalar(2), SK_ScalarHalf); |
joshualitt | 2fbd406 | 2015-05-07 13:06:41 -0700 | [diff] [blame] | 33 | |
| 34 | // Perspective matrices |
joshualitt | 4eaf9ce | 2015-04-28 13:31:18 -0700 | [diff] [blame] | 35 | gMatrices[4].setRotate(SkIntToScalar(215)); |
| 36 | gMatrices[4].set(SkMatrix::kMPersp0, 0.00013f); |
| 37 | gMatrices[4].set(SkMatrix::kMPersp1, -0.000039f); |
joshualitt | 4eaf9ce | 2015-04-28 13:31:18 -0700 | [diff] [blame] | 38 | } |
joshualitt | 2fbd406 | 2015-05-07 13:06:41 -0700 | [diff] [blame] | 39 | |
| 40 | uint32_t count = static_cast<uint32_t>(SK_ARRAY_COUNT(gMatrices)); |
robertphillips | 01a1950 | 2016-07-06 09:58:57 -0700 | [diff] [blame] | 41 | if (includeNonPerspective && includePerspective) { |
joshualitt | 2fbd406 | 2015-05-07 13:06:41 -0700 | [diff] [blame] | 42 | return gMatrices[random->nextULessThan(count)]; |
robertphillips | 01a1950 | 2016-07-06 09:58:57 -0700 | [diff] [blame] | 43 | } else if (!includeNonPerspective) { |
| 44 | return gMatrices[count - 1 - random->nextULessThan(kPerspectiveCount)]; |
joshualitt | 2fbd406 | 2015-05-07 13:06:41 -0700 | [diff] [blame] | 45 | } else { |
robertphillips | 01a1950 | 2016-07-06 09:58:57 -0700 | [diff] [blame] | 46 | SkASSERT(includeNonPerspective && !includePerspective); |
joshualitt | 2fbd406 | 2015-05-07 13:06:41 -0700 | [diff] [blame] | 47 | return gMatrices[random->nextULessThan(count - kPerspectiveCount)]; |
| 48 | } |
joshualitt | 4eaf9ce | 2015-04-28 13:31:18 -0700 | [diff] [blame] | 49 | } |
joshualitt | 3f655f3 | 2015-04-29 10:01:22 -0700 | [diff] [blame] | 50 | |
joshualitt | 2fbd406 | 2015-05-07 13:06:41 -0700 | [diff] [blame] | 51 | namespace GrTest { |
robertphillips | 01a1950 | 2016-07-06 09:58:57 -0700 | [diff] [blame] | 52 | const SkMatrix& TestMatrix(SkRandom* random) { return test_matrix(random, true, true); } |
joshualitt | 2fbd406 | 2015-05-07 13:06:41 -0700 | [diff] [blame] | 53 | |
joshualitt | fa2008f | 2015-04-29 11:32:05 -0700 | [diff] [blame] | 54 | const SkMatrix& TestMatrixPreservesRightAngles(SkRandom* random) { |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 55 | static SkMatrix gMatrices[5]; |
joshualitt | fa2008f | 2015-04-29 11:32:05 -0700 | [diff] [blame] | 56 | static bool gOnce; |
| 57 | if (!gOnce) { |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 58 | gOnce = true; |
joshualitt | fa2008f | 2015-04-29 11:32:05 -0700 | [diff] [blame] | 59 | // identity |
| 60 | gMatrices[0].reset(); |
| 61 | // translation |
| 62 | gMatrices[1].setTranslate(SkIntToScalar(-100), SkIntToScalar(100)); |
| 63 | // scale |
| 64 | gMatrices[2].setScale(SkIntToScalar(17), SkIntToScalar(17)); |
| 65 | // scale + translation |
| 66 | gMatrices[3].setScale(SkIntToScalar(-17), SkIntToScalar(-17)); |
| 67 | gMatrices[3].postTranslate(SkIntToScalar(66), SkIntToScalar(-33)); |
| 68 | // orthogonal basis vectors |
| 69 | gMatrices[4].reset(); |
| 70 | gMatrices[4].setScale(SkIntToScalar(-1), SkIntToScalar(-1)); |
| 71 | gMatrices[4].setRotate(47); |
joshualitt | fa2008f | 2015-04-29 11:32:05 -0700 | [diff] [blame] | 72 | |
| 73 | for (size_t i = 0; i < SK_ARRAY_COUNT(gMatrices); i++) { |
| 74 | SkASSERT(gMatrices[i].preservesRightAngles()); |
| 75 | } |
| 76 | } |
| 77 | return gMatrices[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gMatrices)))]; |
| 78 | } |
| 79 | |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 80 | const SkMatrix& TestMatrixRectStaysRect(SkRandom* random) { |
| 81 | static SkMatrix gMatrices[6]; |
joshualitt | 3f655f3 | 2015-04-29 10:01:22 -0700 | [diff] [blame] | 82 | static bool gOnce; |
| 83 | if (!gOnce) { |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 84 | gOnce = true; |
| 85 | // identity |
| 86 | gMatrices[0].reset(); |
| 87 | // translation |
| 88 | gMatrices[1].setTranslate(SkIntToScalar(-100), SkIntToScalar(100)); |
| 89 | // scale |
| 90 | gMatrices[2].setScale(SkIntToScalar(17), SkIntToScalar(17)); |
| 91 | // scale + translation |
| 92 | gMatrices[3].setScale(SkIntToScalar(-17), SkIntToScalar(-17)); |
| 93 | gMatrices[3].postTranslate(SkIntToScalar(66), SkIntToScalar(-33)); |
| 94 | // reflection |
| 95 | gMatrices[4].setScale(SkIntToScalar(-1), SkIntToScalar(-1)); |
| 96 | // 90 degress rotation |
| 97 | gMatrices[5].setRotate(90); |
| 98 | |
| 99 | for (size_t i = 0; i < SK_ARRAY_COUNT(gMatrices); i++) { |
| 100 | SkASSERT(gMatrices[i].rectStaysRect()); |
| 101 | } |
| 102 | } |
| 103 | return gMatrices[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gMatrices)))]; |
| 104 | } |
| 105 | |
robertphillips | 01a1950 | 2016-07-06 09:58:57 -0700 | [diff] [blame] | 106 | const SkMatrix& TestMatrixInvertible(SkRandom* random) { return test_matrix(random, true, false); } |
| 107 | const SkMatrix& TestMatrixPerspective(SkRandom* random) { return test_matrix(random, false, true); } |
joshualitt | 2fbd406 | 2015-05-07 13:06:41 -0700 | [diff] [blame] | 108 | |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame^] | 109 | void TestWrapModes(SkRandom* random, GrSamplerState::WrapMode wrapModes[2]) { |
| 110 | static const GrSamplerState::WrapMode kWrapModes[] = { |
| 111 | GrSamplerState::WrapMode::kClamp, |
| 112 | GrSamplerState::WrapMode::kRepeat, |
| 113 | GrSamplerState::WrapMode::kMirrorRepeat, |
| 114 | }; |
| 115 | wrapModes[0] = kWrapModes[random->nextULessThan(SK_ARRAY_COUNT(kWrapModes))]; |
| 116 | wrapModes[1] = kWrapModes[random->nextULessThan(SK_ARRAY_COUNT(kWrapModes))]; |
| 117 | } |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 118 | const SkRect& TestRect(SkRandom* random) { |
| 119 | static SkRect gRects[7]; |
| 120 | static bool gOnce; |
| 121 | if (!gOnce) { |
| 122 | gOnce = true; |
joshualitt | 3f655f3 | 2015-04-29 10:01:22 -0700 | [diff] [blame] | 123 | gRects[0] = SkRect::MakeWH(1.f, 1.f); |
| 124 | gRects[1] = SkRect::MakeWH(1.0f, 256.0f); |
| 125 | gRects[2] = SkRect::MakeWH(256.0f, 1.0f); |
joshualitt | 11edad9 | 2015-09-22 10:32:28 -0700 | [diff] [blame] | 126 | gRects[3] = SkRect::MakeLargest(); |
| 127 | gRects[4] = SkRect::MakeLTRB(-65535.0f, -65535.0f, 65535.0f, 65535.0f); |
| 128 | gRects[5] = SkRect::MakeLTRB(-10.0f, -10.0f, 10.0f, 10.0f); |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 129 | } |
| 130 | return gRects[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gRects)))]; |
| 131 | } |
| 132 | |
| 133 | // Just some simple rects for code which expects its input very sanitized |
| 134 | const SkRect& TestSquare(SkRandom* random) { |
| 135 | static SkRect gRects[2]; |
| 136 | static bool gOnce; |
| 137 | if (!gOnce) { |
| 138 | gOnce = true; |
| 139 | gRects[0] = SkRect::MakeWH(128.f, 128.f); |
| 140 | gRects[1] = SkRect::MakeWH(256.0f, 256.0f); |
joshualitt | 3f655f3 | 2015-04-29 10:01:22 -0700 | [diff] [blame] | 141 | } |
| 142 | return gRects[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gRects)))]; |
| 143 | } |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 144 | |
| 145 | const SkRRect& TestRRectSimple(SkRandom* random) { |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 146 | static SkRRect gRRect[2]; |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 147 | static bool gOnce; |
| 148 | if (!gOnce) { |
| 149 | gOnce = true; |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 150 | SkRect rectangle = SkRect::MakeWH(10.f, 20.f); |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 151 | // true round rect with circular corners |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 152 | gRRect[0].setRectXY(rectangle, 1.f, 1.f); |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 153 | // true round rect with elliptical corners |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 154 | gRRect[1].setRectXY(rectangle, 2.0f, 1.0f); |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 155 | |
| 156 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRRect); i++) { |
| 157 | SkASSERT(gRRect[i].isSimple()); |
| 158 | } |
| 159 | } |
| 160 | return gRRect[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gRRect)))]; |
| 161 | } |
| 162 | |
joshualitt | 40ded32 | 2015-05-02 07:07:17 -0700 | [diff] [blame] | 163 | const SkPath& TestPath(SkRandom* random) { |
| 164 | static SkPath gPath[7]; |
| 165 | static bool gOnce; |
| 166 | if (!gOnce) { |
| 167 | gOnce = true; |
| 168 | // line |
| 169 | gPath[0].moveTo(0.f, 0.f); |
| 170 | gPath[0].lineTo(10.f, 10.f); |
| 171 | // quad |
| 172 | gPath[1].moveTo(0.f, 0.f); |
| 173 | gPath[1].quadTo(10.f, 10.f, 20.f, 20.f); |
| 174 | // conic |
| 175 | gPath[2].moveTo(0.f, 0.f); |
| 176 | gPath[2].conicTo(10.f, 10.f, 20.f, 20.f, 1.f); |
| 177 | // cubic |
| 178 | gPath[3].moveTo(0.f, 0.f); |
| 179 | gPath[3].cubicTo(10.f, 10.f, 20.f, 20.f, 30.f, 30.f); |
| 180 | // all three |
| 181 | gPath[4].moveTo(0.f, 0.f); |
| 182 | gPath[4].lineTo(10.f, 10.f); |
| 183 | gPath[4].quadTo(10.f, 10.f, 20.f, 20.f); |
| 184 | gPath[4].conicTo(10.f, 10.f, 20.f, 20.f, 1.f); |
| 185 | gPath[4].cubicTo(10.f, 10.f, 20.f, 20.f, 30.f, 30.f); |
| 186 | // convex |
| 187 | gPath[5].moveTo(0.0f, 0.0f); |
| 188 | gPath[5].lineTo(10.0f, 0.0f); |
| 189 | gPath[5].lineTo(10.0f, 10.0f); |
| 190 | gPath[5].lineTo(0.0f, 10.0f); |
| 191 | gPath[5].close(); |
| 192 | // concave |
| 193 | gPath[6].moveTo(0.0f, 0.0f); |
| 194 | gPath[6].lineTo(5.0f, 5.0f); |
| 195 | gPath[6].lineTo(10.0f, 0.0f); |
| 196 | gPath[6].lineTo(10.0f, 10.0f); |
| 197 | gPath[6].lineTo(0.0f, 10.0f); |
| 198 | gPath[6].close(); |
| 199 | } |
| 200 | |
| 201 | return gPath[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gPath)))]; |
| 202 | } |
| 203 | |
joshualitt | 8e5c177 | 2015-05-11 08:58:52 -0700 | [diff] [blame] | 204 | const SkPath& TestPathConvex(SkRandom* random) { |
| 205 | static SkPath gPath[3]; |
| 206 | static bool gOnce; |
| 207 | if (!gOnce) { |
| 208 | gOnce = true; |
| 209 | // narrow rect |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 210 | gPath[0].moveTo(-1.5f, -50.0f); |
joshualitt | 8e5c177 | 2015-05-11 08:58:52 -0700 | [diff] [blame] | 211 | gPath[0].lineTo(-1.5f, -50.0f); |
| 212 | gPath[0].lineTo( 1.5f, -50.0f); |
| 213 | gPath[0].lineTo( 1.5f, 50.0f); |
| 214 | gPath[0].lineTo(-1.5f, 50.0f); |
| 215 | // degenerate |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 216 | gPath[1].moveTo(-0.025f, -0.025f); |
joshualitt | 8e5c177 | 2015-05-11 08:58:52 -0700 | [diff] [blame] | 217 | gPath[1].lineTo(-0.025f, -0.025f); |
| 218 | gPath[1].lineTo( 0.025f, -0.025f); |
| 219 | gPath[1].lineTo( 0.025f, 0.025f); |
| 220 | gPath[1].lineTo(-0.025f, 0.025f); |
| 221 | // clipped triangle |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 222 | gPath[2].moveTo(-10.0f, -50.0f); |
joshualitt | 8e5c177 | 2015-05-11 08:58:52 -0700 | [diff] [blame] | 223 | gPath[2].lineTo(-10.0f, -50.0f); |
| 224 | gPath[2].lineTo( 10.0f, -50.0f); |
| 225 | gPath[2].lineTo( 50.0f, 31.0f); |
| 226 | gPath[2].lineTo( 40.0f, 50.0f); |
| 227 | gPath[2].lineTo(-40.0f, 50.0f); |
| 228 | gPath[2].lineTo(-50.0f, 31.0f); |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 229 | |
| 230 | for (size_t i = 0; i < SK_ARRAY_COUNT(gPath); i++) { |
| 231 | SkASSERT(SkPath::kConvex_Convexity == gPath[i].getConvexity()); |
| 232 | } |
joshualitt | 8e5c177 | 2015-05-11 08:58:52 -0700 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | return gPath[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gPath)))]; |
| 236 | } |
| 237 | |
senorblanco | b4f9d0e | 2015-08-06 10:28:55 -0700 | [diff] [blame] | 238 | static void randomize_stroke_rec(SkStrokeRec* rec, SkRandom* random) { |
senorblanco | 59cd367 | 2015-08-05 13:37:49 -0700 | [diff] [blame] | 239 | bool strokeAndFill = random->nextBool(); |
| 240 | SkScalar strokeWidth = random->nextBool() ? 0.f : 1.f; |
senorblanco | b4f9d0e | 2015-08-06 10:28:55 -0700 | [diff] [blame] | 241 | rec->setStrokeStyle(strokeWidth, strokeAndFill); |
joshualitt | 21279c7 | 2015-05-11 07:21:37 -0700 | [diff] [blame] | 242 | |
senorblanco | 59cd367 | 2015-08-05 13:37:49 -0700 | [diff] [blame] | 243 | SkPaint::Cap cap = SkPaint::Cap(random->nextULessThan(SkPaint::kCapCount)); |
| 244 | SkPaint::Join join = SkPaint::Join(random->nextULessThan(SkPaint::kJoinCount)); |
| 245 | SkScalar miterLimit = random->nextRangeScalar(1.f, 5.f); |
senorblanco | b4f9d0e | 2015-08-06 10:28:55 -0700 | [diff] [blame] | 246 | rec->setStrokeParams(cap, join, miterLimit); |
| 247 | } |
| 248 | |
| 249 | SkStrokeRec TestStrokeRec(SkRandom* random) { |
| 250 | SkStrokeRec::InitStyle style = |
| 251 | SkStrokeRec::InitStyle(random->nextULessThan(SkStrokeRec::kFill_InitStyle + 1)); |
| 252 | SkStrokeRec rec(style); |
| 253 | randomize_stroke_rec(&rec, random); |
senorblanco | 59cd367 | 2015-08-05 13:37:49 -0700 | [diff] [blame] | 254 | return rec; |
senorblanco | 29e0d3f | 2015-08-05 13:18:03 -0700 | [diff] [blame] | 255 | } |
| 256 | |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 257 | void TestStyle(SkRandom* random, GrStyle* style) { |
| 258 | SkStrokeRec::InitStyle initStyle = |
senorblanco | b4f9d0e | 2015-08-06 10:28:55 -0700 | [diff] [blame] | 259 | SkStrokeRec::InitStyle(random->nextULessThan(SkStrokeRec::kFill_InitStyle + 1)); |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 260 | SkStrokeRec stroke(initStyle); |
| 261 | randomize_stroke_rec(&stroke, random); |
| 262 | sk_sp<SkPathEffect> pe; |
| 263 | if (random->nextBool()) { |
| 264 | int cnt = random->nextRangeU(1, 50) * 2; |
Ben Wagner | 7ecc596 | 2016-11-02 17:07:33 -0400 | [diff] [blame] | 265 | std::unique_ptr<SkScalar[]> intervals(new SkScalar[cnt]); |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 266 | SkScalar sum = 0; |
| 267 | for (int i = 0; i < cnt; i++) { |
| 268 | intervals[i] = random->nextRangeScalar(SkDoubleToScalar(0.01), |
| 269 | SkDoubleToScalar(10.0)); |
| 270 | sum += intervals[i]; |
| 271 | } |
| 272 | SkScalar phase = random->nextRangeScalar(0, sum); |
| 273 | pe = TestDashPathEffect::Make(intervals.get(), cnt, phase); |
senorblanco | b4f9d0e | 2015-08-06 10:28:55 -0700 | [diff] [blame] | 274 | } |
Robert Phillips | f809c1e | 2017-01-13 11:02:42 -0500 | [diff] [blame] | 275 | *style = GrStyle(stroke, std::move(pe)); |
senorblanco | b4f9d0e | 2015-08-06 10:28:55 -0700 | [diff] [blame] | 276 | } |
| 277 | |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 278 | TestDashPathEffect::TestDashPathEffect(const SkScalar* intervals, int count, SkScalar phase) { |
| 279 | fCount = count; |
| 280 | fIntervals.reset(count); |
| 281 | memcpy(fIntervals.get(), intervals, count * sizeof(SkScalar)); |
| 282 | SkDashPath::CalcDashParameters(phase, intervals, count, &fInitialDashLength, |
| 283 | &fInitialDashIndex, &fIntervalLength, &fPhase); |
| 284 | } |
| 285 | |
| 286 | bool TestDashPathEffect::filterPath(SkPath* dst, const SkPath& src, SkStrokeRec* rec, |
| 287 | const SkRect* cullRect) const { |
| 288 | return SkDashPath::InternalFilter(dst, src, rec, cullRect, fIntervals.get(), fCount, |
| 289 | fInitialDashLength, fInitialDashIndex, fIntervalLength); |
| 290 | } |
| 291 | |
| 292 | SkPathEffect::DashType TestDashPathEffect::asADash(DashInfo* info) const { |
| 293 | if (info) { |
| 294 | if (info->fCount >= fCount && info->fIntervals) { |
| 295 | memcpy(info->fIntervals, fIntervals.get(), fCount * sizeof(SkScalar)); |
| 296 | } |
| 297 | info->fCount = fCount; |
| 298 | info->fPhase = fPhase; |
| 299 | } |
| 300 | return kDash_DashType; |
| 301 | } |
| 302 | |
Brian Osman | 0d9dfe9 | 2016-10-03 15:24:44 -0400 | [diff] [blame] | 303 | sk_sp<SkColorSpace> TestColorSpace(SkRandom* random) { |
| 304 | static sk_sp<SkColorSpace> gColorSpaces[3]; |
| 305 | static bool gOnce; |
| 306 | if (!gOnce) { |
| 307 | gOnce = true; |
| 308 | // No color space (legacy mode) |
| 309 | gColorSpaces[0] = nullptr; |
| 310 | // sRGB or Adobe |
Matt Sarett | 77a7a1b | 2017-02-07 13:56:11 -0500 | [diff] [blame] | 311 | gColorSpaces[1] = SkColorSpace::MakeSRGB(); |
| 312 | gColorSpaces[2] = SkColorSpace_Base::MakeNamed(SkColorSpace_Base::kAdobeRGB_Named); |
Brian Osman | 0d9dfe9 | 2016-10-03 15:24:44 -0400 | [diff] [blame] | 313 | } |
| 314 | return gColorSpaces[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gColorSpaces)))]; |
| 315 | } |
| 316 | |
Brian Osman | e2f732f | 2016-10-03 14:23:50 -0400 | [diff] [blame] | 317 | sk_sp<GrColorSpaceXform> TestColorXform(SkRandom* random) { |
| 318 | static sk_sp<GrColorSpaceXform> gXforms[3]; |
| 319 | static bool gOnce; |
| 320 | if (!gOnce) { |
| 321 | gOnce = true; |
Matt Sarett | 77a7a1b | 2017-02-07 13:56:11 -0500 | [diff] [blame] | 322 | sk_sp<SkColorSpace> srgb = SkColorSpace::MakeSRGB(); |
| 323 | sk_sp<SkColorSpace> adobe = SkColorSpace_Base::MakeNamed(SkColorSpace_Base::kAdobeRGB_Named); |
Brian Osman | e2f732f | 2016-10-03 14:23:50 -0400 | [diff] [blame] | 324 | // No gamut change |
| 325 | gXforms[0] = nullptr; |
| 326 | // To larger gamut |
| 327 | gXforms[1] = GrColorSpaceXform::Make(srgb.get(), adobe.get()); |
| 328 | // To smaller gamut |
| 329 | gXforms[2] = GrColorSpaceXform::Make(adobe.get(), srgb.get()); |
| 330 | } |
| 331 | return gXforms[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gXforms)))]; |
| 332 | } |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 333 | |
Brian Osman | 9f532a3 | 2016-10-19 11:12:09 -0400 | [diff] [blame] | 334 | TestAsFPArgs::TestAsFPArgs(GrProcessorTestData* d) { |
| 335 | fViewMatrixStorage = TestMatrix(d->fRandom); |
| 336 | fColorSpaceStorage = TestColorSpace(d->fRandom); |
| 337 | |
Robert Phillips | dbc8eeb | 2017-02-21 10:04:31 -0500 | [diff] [blame] | 338 | fArgs.fContext = d->context(); |
Brian Osman | 9f532a3 | 2016-10-19 11:12:09 -0400 | [diff] [blame] | 339 | fArgs.fViewMatrix = &fViewMatrixStorage; |
| 340 | fArgs.fLocalMatrix = nullptr; |
| 341 | fArgs.fFilterQuality = kNone_SkFilterQuality; |
| 342 | fArgs.fDstColorSpace = fColorSpaceStorage.get(); |
Brian Osman | 9f532a3 | 2016-10-19 11:12:09 -0400 | [diff] [blame] | 343 | } |
| 344 | |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 345 | } // namespace GrTest |
joshualitt | 3f655f3 | 2015-04-29 10:01:22 -0700 | [diff] [blame] | 346 | |
| 347 | #endif |