senorblanco | d6ed19c | 2015-02-26 06:58:17 -0800 | [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 | |
Robert Phillips | 77505da | 2017-01-20 09:11:37 -0500 | [diff] [blame] | 8 | #include "Test.h" |
| 9 | |
senorblanco | 0e95b11 | 2015-04-20 15:00:06 -0700 | [diff] [blame] | 10 | #include "SkPath.h" |
| 11 | |
senorblanco | d6ed19c | 2015-02-26 06:58:17 -0800 | [diff] [blame] | 12 | #if SK_SUPPORT_GPU |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 13 | #include "GrContext.h" |
Brian Salomon | 8952743 | 2016-12-16 09:52:16 -0500 | [diff] [blame] | 14 | #include "ops/GrTessellatingPathRenderer.h" |
Stephen White | cc70083 | 2017-02-15 11:45:16 -0500 | [diff] [blame] | 15 | #include "SkGradientShader.h" |
senorblanco | d6ed19c | 2015-02-26 06:58:17 -0800 | [diff] [blame] | 16 | |
| 17 | /* |
| 18 | * These tests pass by not crashing, hanging or asserting in Debug. |
| 19 | */ |
| 20 | |
| 21 | // Tests active edges made inactive by splitting. |
| 22 | // Also tests active edge list forced into an invalid ordering by |
| 23 | // splitting (mopped up in cleanup_active_edges()). |
| 24 | static SkPath create_path_0() { |
| 25 | SkPath path; |
| 26 | path.moveTo(229.127044677734375f, 67.34100341796875f); |
| 27 | path.lineTo(187.8097381591796875f, -6.7729740142822265625f); |
| 28 | path.lineTo(171.411407470703125f, 50.94266510009765625f); |
| 29 | path.lineTo(245.5253753662109375f, 9.6253643035888671875f); |
| 30 | path.moveTo(208.4683990478515625f, 30.284009933471679688f); |
| 31 | path.lineTo(171.411407470703125f, 50.94266510009765625f); |
| 32 | path.lineTo(187.8097381591796875f, -6.7729740142822265625f); |
| 33 | return path; |
| 34 | } |
| 35 | |
| 36 | // Intersections which fall exactly on the current vertex, and require |
| 37 | // a restart of the intersection checking. |
| 38 | static SkPath create_path_1() { |
| 39 | SkPath path; |
| 40 | path.moveTo(314.483551025390625f, 486.246002197265625f); |
| 41 | path.lineTo(385.41949462890625f, 532.8087158203125f); |
| 42 | path.lineTo(373.232879638671875f, 474.05938720703125f); |
| 43 | path.lineTo(326.670166015625f, 544.995361328125f); |
| 44 | path.moveTo(349.951507568359375f, 509.52734375f); |
| 45 | path.lineTo(373.232879638671875f, 474.05938720703125f); |
| 46 | path.lineTo(385.41949462890625f, 532.8087158203125f); |
| 47 | return path; |
| 48 | } |
| 49 | |
| 50 | // Tests active edges which are removed by splitting. |
| 51 | static SkPath create_path_2() { |
| 52 | SkPath path; |
| 53 | path.moveTo(343.107391357421875f, 613.62176513671875f); |
| 54 | path.lineTo(426.632415771484375f, 628.5740966796875f); |
| 55 | path.lineTo(392.3460693359375f, 579.33544921875f); |
| 56 | path.lineTo(377.39373779296875f, 662.86041259765625f); |
| 57 | path.moveTo(384.869873046875f, 621.097900390625f); |
| 58 | path.lineTo(392.3460693359375f, 579.33544921875f); |
| 59 | path.lineTo(426.632415771484375f, 628.5740966796875f); |
| 60 | return path; |
| 61 | } |
| 62 | |
| 63 | // Collinear edges merged in set_top(). |
| 64 | // Also, an intersection between left and right enclosing edges which |
| 65 | // falls above the current vertex. |
| 66 | static SkPath create_path_3() { |
| 67 | SkPath path; |
| 68 | path.moveTo(545.95751953125f, 791.69854736328125f); |
| 69 | path.lineTo(612.05816650390625f, 738.494140625f); |
| 70 | path.lineTo(552.4056396484375f, 732.0460205078125f); |
| 71 | path.lineTo(605.61004638671875f, 798.14666748046875f); |
| 72 | path.moveTo(579.00787353515625f, 765.0963134765625f); |
| 73 | path.lineTo(552.4056396484375f, 732.0460205078125f); |
| 74 | path.lineTo(612.05816650390625f, 738.494140625f); |
| 75 | return path; |
| 76 | } |
| 77 | |
| 78 | // Tests active edges which are made inactive by set_top(). |
| 79 | static SkPath create_path_4() { |
| 80 | SkPath path; |
| 81 | path.moveTo(819.2725830078125f, 751.77447509765625f); |
| 82 | path.lineTo(820.70904541015625f, 666.933837890625f); |
| 83 | path.lineTo(777.57049560546875f, 708.63592529296875f); |
| 84 | path.lineTo(862.4111328125f, 710.0723876953125f); |
| 85 | path.moveTo(819.99078369140625f, 709.3541259765625f); |
| 86 | path.lineTo(777.57049560546875f, 708.63592529296875f); |
| 87 | path.lineTo(820.70904541015625f, 666.933837890625f); |
| 88 | return path; |
| 89 | } |
| 90 | |
| 91 | static SkPath create_path_5() { |
| 92 | SkPath path; |
| 93 | path.moveTo(823.33209228515625f, 749.052734375f); |
| 94 | path.lineTo(823.494873046875f, 664.20013427734375f); |
| 95 | path.lineTo(780.9871826171875f, 706.5450439453125f); |
| 96 | path.lineTo(865.8397216796875f, 706.70782470703125f); |
| 97 | path.moveTo(823.4134521484375f, 706.6263427734375f); |
| 98 | path.lineTo(780.9871826171875f, 706.5450439453125f); |
| 99 | path.lineTo(823.494873046875f, 664.20013427734375f); |
| 100 | return path; |
| 101 | } |
| 102 | |
| 103 | static SkPath create_path_6() { |
| 104 | SkPath path; |
| 105 | path.moveTo(954.862548828125f, 562.8349609375f); |
| 106 | path.lineTo(899.32818603515625f, 498.679443359375f); |
| 107 | path.lineTo(895.017578125f, 558.52435302734375f); |
| 108 | path.lineTo(959.17315673828125f, 502.990081787109375f); |
| 109 | path.moveTo(927.0953369140625f, 530.7572021484375f); |
| 110 | path.lineTo(895.017578125f, 558.52435302734375f); |
| 111 | path.lineTo(899.32818603515625f, 498.679443359375f); |
| 112 | return path; |
| 113 | } |
| 114 | |
| 115 | static SkPath create_path_7() { |
| 116 | SkPath path; |
| 117 | path.moveTo(958.5330810546875f, 547.35516357421875f); |
| 118 | path.lineTo(899.93109130859375f, 485.989013671875f); |
| 119 | path.lineTo(898.54901123046875f, 545.97308349609375f); |
| 120 | path.lineTo(959.9151611328125f, 487.37109375f); |
| 121 | path.moveTo(929.2320556640625f, 516.67205810546875f); |
| 122 | path.lineTo(898.54901123046875f, 545.97308349609375f); |
| 123 | path.lineTo(899.93109130859375f, 485.989013671875f); |
| 124 | return path; |
| 125 | } |
| 126 | |
| 127 | static SkPath create_path_8() { |
| 128 | SkPath path; |
| 129 | path.moveTo(389.8609619140625f, 369.326873779296875f); |
| 130 | path.lineTo(470.6290283203125f, 395.33697509765625f); |
| 131 | path.lineTo(443.250030517578125f, 341.9478759765625f); |
| 132 | path.lineTo(417.239959716796875f, 422.7159423828125f); |
| 133 | path.moveTo(430.244964599609375f, 382.3319091796875f); |
| 134 | path.lineTo(443.250030517578125f, 341.9478759765625f); |
| 135 | path.lineTo(470.6290283203125f, 395.33697509765625f); |
| 136 | return path; |
| 137 | } |
| 138 | |
| 139 | static SkPath create_path_9() { |
| 140 | SkPath path; |
| 141 | path.moveTo(20, 20); |
| 142 | path.lineTo(50, 80); |
| 143 | path.lineTo(20, 80); |
| 144 | path.moveTo(80, 50); |
| 145 | path.lineTo(50, 50); |
| 146 | path.lineTo(20, 50); |
| 147 | return path; |
| 148 | } |
| 149 | |
| 150 | static SkPath create_path_10() { |
| 151 | SkPath path; |
| 152 | path.moveTo(257.19439697265625f, 320.876617431640625f); |
| 153 | path.lineTo(190.113037109375f, 320.58978271484375f); |
| 154 | path.lineTo(203.64404296875f, 293.8145751953125f); |
| 155 | path.moveTo(203.357177734375f, 360.896026611328125f); |
| 156 | path.lineTo(216.88824462890625f, 334.120819091796875f); |
| 157 | path.lineTo(230.41925048828125f, 307.345611572265625f); |
| 158 | return path; |
| 159 | } |
| 160 | |
| 161 | // A degenerate segments case, where both upper and lower segments of |
| 162 | // a split edge must remain active. |
| 163 | static SkPath create_path_11() { |
| 164 | SkPath path; |
| 165 | path.moveTo(231.9331207275390625f, 306.2012939453125f); |
| 166 | path.lineTo(191.4859161376953125f, 306.04547119140625f); |
| 167 | path.lineTo(231.0659332275390625f, 300.2642822265625f); |
| 168 | path.moveTo(189.946807861328125f, 302.072265625f); |
| 169 | path.lineTo(179.79705810546875f, 294.859771728515625f); |
| 170 | path.lineTo(191.0016021728515625f, 296.165679931640625f); |
| 171 | path.moveTo(150.8942108154296875f, 304.900146484375f); |
| 172 | path.lineTo(179.708892822265625f, 297.849029541015625f); |
| 173 | path.lineTo(190.4742279052734375f, 299.11895751953125f); |
| 174 | return path; |
| 175 | } |
| 176 | |
| 177 | // Handle the case where edge.dist(edge.fTop) != 0.0. |
| 178 | static SkPath create_path_12() { |
| 179 | SkPath path; |
| 180 | path.moveTo( 0.0f, 400.0f); |
| 181 | path.lineTo( 138.0f, 202.0f); |
| 182 | path.lineTo( 0.0f, 202.0f); |
| 183 | path.moveTo( 12.62693023681640625f, 250.57464599609375f); |
| 184 | path.lineTo( 8.13896942138671875f, 254.556884765625f); |
| 185 | path.lineTo(-18.15641021728515625f, 220.40203857421875f); |
| 186 | path.lineTo(-15.986493110656738281f, 219.6513519287109375f); |
| 187 | path.moveTo( 36.931194305419921875f, 282.485504150390625f); |
| 188 | path.lineTo( 15.617521286010742188f, 261.2901611328125f); |
| 189 | path.lineTo( 10.3829498291015625f, 252.565765380859375f); |
| 190 | path.lineTo(-16.165292739868164062f, 222.646026611328125f); |
| 191 | return path; |
| 192 | } |
| 193 | |
| 194 | // A degenerate segments case which exercises inactive edges being |
| 195 | // made active by splitting. |
| 196 | static SkPath create_path_13() { |
| 197 | SkPath path; |
| 198 | path.moveTo(690.62127685546875f, 509.25555419921875f); |
| 199 | path.lineTo(99.336181640625f, 511.71405029296875f); |
| 200 | path.lineTo(708.362548828125f, 512.4349365234375f); |
| 201 | path.lineTo(729.9940185546875f, 516.3114013671875f); |
| 202 | path.lineTo(738.708984375f, 518.76995849609375f); |
| 203 | path.lineTo(678.3463134765625f, 510.0819091796875f); |
| 204 | path.lineTo(681.21795654296875f, 504.81378173828125f); |
| 205 | path.moveTo(758.52764892578125f, 521.55963134765625f); |
| 206 | path.lineTo(719.1549072265625f, 514.50372314453125f); |
| 207 | path.lineTo(689.59063720703125f, 512.0628662109375f); |
| 208 | path.lineTo(679.78216552734375f, 507.447845458984375f); |
| 209 | return path; |
| 210 | } |
| 211 | |
| 212 | // Tests vertices which become "orphaned" (ie., no connected edges) |
| 213 | // after simplification. |
| 214 | static SkPath create_path_14() { |
| 215 | SkPath path; |
| 216 | path.moveTo(217.326019287109375f, 166.4752960205078125f); |
| 217 | path.lineTo(226.279266357421875f, 170.929473876953125f); |
| 218 | path.lineTo(234.3973388671875f, 177.0623626708984375f); |
| 219 | path.lineTo(262.0921630859375f, 188.746124267578125f); |
| 220 | path.moveTo(196.23638916015625f, 174.0722198486328125f); |
| 221 | path.lineTo(416.15277099609375f, 180.138214111328125f); |
| 222 | path.lineTo(192.651947021484375f, 304.0228271484375f); |
| 223 | return path; |
| 224 | } |
| 225 | |
senorblanco | a2b6d28 | 2015-03-02 09:34:13 -0800 | [diff] [blame] | 226 | static SkPath create_path_15() { |
| 227 | SkPath path; |
| 228 | path.moveTo( 0.0f, 0.0f); |
| 229 | path.lineTo(10000.0f, 0.0f); |
| 230 | path.lineTo( 0.0f, -1.0f); |
| 231 | path.lineTo(10000.0f, 0.000001f); |
| 232 | path.lineTo( 0.0f, -30.0f); |
| 233 | return path; |
| 234 | } |
| 235 | |
senorblanco | 70f5251 | 2016-08-17 14:56:22 -0700 | [diff] [blame] | 236 | // Reduction of Nebraska-StateSeal.svg. Floating point error causes the |
| 237 | // same edge to be added to more than one poly on the same side. |
| 238 | static SkPath create_path_16() { |
| 239 | SkPath path; |
| 240 | path.moveTo(170.8199920654296875, 491.86700439453125); |
| 241 | path.lineTo(173.7649993896484375, 489.7340087890625); |
| 242 | path.lineTo(174.1450958251953125, 498.545989990234375); |
| 243 | path.lineTo( 171.998992919921875, 500.88201904296875); |
| 244 | path.moveTo(168.2922515869140625, 498.66265869140625); |
| 245 | path.lineTo(169.8589935302734375, 497.94500732421875); |
| 246 | path.lineTo( 172, 500.88299560546875); |
| 247 | path.moveTo( 169.555267333984375, 490.70111083984375); |
| 248 | path.lineTo(173.7649993896484375, 489.7340087890625); |
| 249 | path.lineTo( 170.82000732421875, 491.86700439453125); |
| 250 | return path; |
| 251 | } |
| 252 | |
Stephen White | cc70083 | 2017-02-15 11:45:16 -0500 | [diff] [blame] | 253 | // A simple concave path. Test this with a non-invertible matrix. |
| 254 | static SkPath create_path_17() { |
| 255 | SkPath path; |
| 256 | path.moveTo(20, 20); |
| 257 | path.lineTo(80, 20); |
| 258 | path.lineTo(30, 30); |
| 259 | path.lineTo(20, 80); |
| 260 | return path; |
| 261 | } |
| 262 | |
| 263 | static sk_sp<GrFragmentProcessor> create_linear_gradient_processor(GrContext* ctx) { |
| 264 | SkPoint pts[2] = { {0, 0}, {1, 1} }; |
| 265 | SkColor colors[2] = { SK_ColorGREEN, SK_ColorBLUE }; |
| 266 | sk_sp<SkShader> shader = SkGradientShader::MakeLinear( |
| 267 | pts, colors, nullptr, SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode); |
| 268 | SkShader::AsFPArgs args( |
| 269 | ctx, &SkMatrix::I(), &SkMatrix::I(), SkFilterQuality::kLow_SkFilterQuality, nullptr); |
| 270 | return shader->asFragmentProcessor(args); |
| 271 | } |
| 272 | |
Robert Phillips | 256c37b | 2017-03-01 14:32:46 -0500 | [diff] [blame^] | 273 | static void test_path(GrContext* ctx, |
Stephen White | cc70083 | 2017-02-15 11:45:16 -0500 | [diff] [blame] | 274 | GrRenderTargetContext* renderTargetContext, |
| 275 | const SkPath& path, |
| 276 | const SkMatrix& matrix = SkMatrix::I(), |
| 277 | GrAAType aaType = GrAAType::kNone, |
| 278 | sk_sp<GrFragmentProcessor> fp = nullptr) { |
senorblanco | d6ed19c | 2015-02-26 06:58:17 -0800 | [diff] [blame] | 279 | GrTessellatingPathRenderer tess; |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 280 | |
| 281 | GrPaint paint; |
Brian Salomon | a163392 | 2017-01-09 11:46:10 -0500 | [diff] [blame] | 282 | paint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc)); |
Stephen White | cc70083 | 2017-02-15 11:45:16 -0500 | [diff] [blame] | 283 | if (fp) { |
| 284 | paint.addColorFragmentProcessor(fp); |
| 285 | } |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 286 | |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 287 | GrNoClip noClip; |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 288 | GrStyle style(SkStrokeRec::kFill_InitStyle); |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 289 | GrShape shape(path, style); |
Robert Phillips | 256c37b | 2017-03-01 14:32:46 -0500 | [diff] [blame^] | 290 | GrPathRenderer::DrawPathArgs args{ctx, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 291 | std::move(paint), |
| 292 | &GrUserStencilSettings::kUnused, |
| 293 | renderTargetContext, |
| 294 | &noClip, |
Stephen White | cc70083 | 2017-02-15 11:45:16 -0500 | [diff] [blame] | 295 | &matrix, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 296 | &shape, |
Stephen White | cc70083 | 2017-02-15 11:45:16 -0500 | [diff] [blame] | 297 | aaType, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 298 | false}; |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 299 | tess.drawPath(args); |
senorblanco | d6ed19c | 2015-02-26 06:58:17 -0800 | [diff] [blame] | 300 | } |
| 301 | |
bsalomon | fda8807 | 2016-04-11 14:40:50 -0700 | [diff] [blame] | 302 | DEF_GPUTEST_FOR_ALL_CONTEXTS(TessellatingPathRendererTests, reporter, ctxInfo) { |
Robert Phillips | 77505da | 2017-01-20 09:11:37 -0500 | [diff] [blame] | 303 | GrContext* ctx = ctxInfo.grContext(); |
Robert Phillips | 256c37b | 2017-03-01 14:32:46 -0500 | [diff] [blame^] | 304 | |
Robert Phillips | 77505da | 2017-01-20 09:11:37 -0500 | [diff] [blame] | 305 | sk_sp<GrRenderTargetContext> rtc(ctx->makeRenderTargetContext(SkBackingFit::kApprox, |
| 306 | 800, 800, |
| 307 | kRGBA_8888_GrPixelConfig, |
| 308 | nullptr, |
| 309 | 0, |
| 310 | kTopLeft_GrSurfaceOrigin)); |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 311 | if (!rtc) { |
robertphillips | 87f15c8 | 2016-05-20 11:14:33 -0700 | [diff] [blame] | 312 | return; |
| 313 | } |
| 314 | |
Robert Phillips | 77505da | 2017-01-20 09:11:37 -0500 | [diff] [blame] | 315 | ctx->flush(); |
Robert Phillips | 256c37b | 2017-03-01 14:32:46 -0500 | [diff] [blame^] | 316 | test_path(ctx, rtc.get(), create_path_0()); |
| 317 | test_path(ctx, rtc.get(), create_path_1()); |
| 318 | test_path(ctx, rtc.get(), create_path_2()); |
| 319 | test_path(ctx, rtc.get(), create_path_3()); |
| 320 | test_path(ctx, rtc.get(), create_path_4()); |
| 321 | test_path(ctx, rtc.get(), create_path_5()); |
| 322 | test_path(ctx, rtc.get(), create_path_6()); |
| 323 | test_path(ctx, rtc.get(), create_path_7()); |
| 324 | test_path(ctx, rtc.get(), create_path_8()); |
| 325 | test_path(ctx, rtc.get(), create_path_9()); |
| 326 | test_path(ctx, rtc.get(), create_path_10()); |
| 327 | test_path(ctx, rtc.get(), create_path_11()); |
| 328 | test_path(ctx, rtc.get(), create_path_12()); |
| 329 | test_path(ctx, rtc.get(), create_path_13()); |
| 330 | test_path(ctx, rtc.get(), create_path_14()); |
| 331 | test_path(ctx, rtc.get(), create_path_15()); |
| 332 | test_path(ctx, rtc.get(), create_path_16()); |
Stephen White | cc70083 | 2017-02-15 11:45:16 -0500 | [diff] [blame] | 333 | SkMatrix nonInvertibleMatrix = SkMatrix::MakeScale(0, 0); |
| 334 | sk_sp<GrFragmentProcessor> fp(create_linear_gradient_processor(ctx)); |
Robert Phillips | 256c37b | 2017-03-01 14:32:46 -0500 | [diff] [blame^] | 335 | test_path(ctx, rtc.get(), create_path_17(), nonInvertibleMatrix, GrAAType::kCoverage, fp); |
senorblanco | d6ed19c | 2015-02-26 06:58:17 -0800 | [diff] [blame] | 336 | } |
| 337 | #endif |