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