TessellatingPathRendererTests.cpp 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796
  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. #include "tests/Test.h"
  8. #include "include/core/SkPath.h"
  9. #include "include/effects/SkGradientShader.h"
  10. #include "include/gpu/GrContext.h"
  11. #include "src/gpu/GrClip.h"
  12. #include "src/gpu/GrContextPriv.h"
  13. #include "src/gpu/GrStyle.h"
  14. #include "src/gpu/effects/GrPorterDuffXferProcessor.h"
  15. #include "src/gpu/geometry/GrShape.h"
  16. #include "src/gpu/ops/GrTessellatingPathRenderer.h"
  17. #include "src/shaders/SkShaderBase.h"
  18. /*
  19. * These tests pass by not crashing, hanging or asserting in Debug.
  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. // Intersections which fall exactly on the current vertex, and require
  36. // a restart of the intersection checking.
  37. static SkPath create_path_1() {
  38. SkPath path;
  39. path.moveTo(314.483551025390625f, 486.246002197265625f);
  40. path.lineTo(385.41949462890625f, 532.8087158203125f);
  41. path.lineTo(373.232879638671875f, 474.05938720703125f);
  42. path.lineTo(326.670166015625f, 544.995361328125f);
  43. path.moveTo(349.951507568359375f, 509.52734375f);
  44. path.lineTo(373.232879638671875f, 474.05938720703125f);
  45. path.lineTo(385.41949462890625f, 532.8087158203125f);
  46. return path;
  47. }
  48. // Tests active edges which are removed by splitting.
  49. static SkPath create_path_2() {
  50. SkPath path;
  51. path.moveTo(343.107391357421875f, 613.62176513671875f);
  52. path.lineTo(426.632415771484375f, 628.5740966796875f);
  53. path.lineTo(392.3460693359375f, 579.33544921875f);
  54. path.lineTo(377.39373779296875f, 662.86041259765625f);
  55. path.moveTo(384.869873046875f, 621.097900390625f);
  56. path.lineTo(392.3460693359375f, 579.33544921875f);
  57. path.lineTo(426.632415771484375f, 628.5740966796875f);
  58. return path;
  59. }
  60. // Collinear edges merged in set_top().
  61. // Also, an intersection between left and right enclosing edges which
  62. // falls above the current vertex.
  63. static SkPath create_path_3() {
  64. SkPath path;
  65. path.moveTo(545.95751953125f, 791.69854736328125f);
  66. path.lineTo(612.05816650390625f, 738.494140625f);
  67. path.lineTo(552.4056396484375f, 732.0460205078125f);
  68. path.lineTo(605.61004638671875f, 798.14666748046875f);
  69. path.moveTo(579.00787353515625f, 765.0963134765625f);
  70. path.lineTo(552.4056396484375f, 732.0460205078125f);
  71. path.lineTo(612.05816650390625f, 738.494140625f);
  72. return path;
  73. }
  74. // Tests active edges which are made inactive by set_top().
  75. static SkPath create_path_4() {
  76. SkPath path;
  77. path.moveTo(819.2725830078125f, 751.77447509765625f);
  78. path.lineTo(820.70904541015625f, 666.933837890625f);
  79. path.lineTo(777.57049560546875f, 708.63592529296875f);
  80. path.lineTo(862.4111328125f, 710.0723876953125f);
  81. path.moveTo(819.99078369140625f, 709.3541259765625f);
  82. path.lineTo(777.57049560546875f, 708.63592529296875f);
  83. path.lineTo(820.70904541015625f, 666.933837890625f);
  84. return path;
  85. }
  86. static SkPath create_path_5() {
  87. SkPath path;
  88. path.moveTo(823.33209228515625f, 749.052734375f);
  89. path.lineTo(823.494873046875f, 664.20013427734375f);
  90. path.lineTo(780.9871826171875f, 706.5450439453125f);
  91. path.lineTo(865.8397216796875f, 706.70782470703125f);
  92. path.moveTo(823.4134521484375f, 706.6263427734375f);
  93. path.lineTo(780.9871826171875f, 706.5450439453125f);
  94. path.lineTo(823.494873046875f, 664.20013427734375f);
  95. return path;
  96. }
  97. static SkPath create_path_6() {
  98. SkPath path;
  99. path.moveTo(954.862548828125f, 562.8349609375f);
  100. path.lineTo(899.32818603515625f, 498.679443359375f);
  101. path.lineTo(895.017578125f, 558.52435302734375f);
  102. path.lineTo(959.17315673828125f, 502.990081787109375f);
  103. path.moveTo(927.0953369140625f, 530.7572021484375f);
  104. path.lineTo(895.017578125f, 558.52435302734375f);
  105. path.lineTo(899.32818603515625f, 498.679443359375f);
  106. return path;
  107. }
  108. static SkPath create_path_7() {
  109. SkPath path;
  110. path.moveTo(958.5330810546875f, 547.35516357421875f);
  111. path.lineTo(899.93109130859375f, 485.989013671875f);
  112. path.lineTo(898.54901123046875f, 545.97308349609375f);
  113. path.lineTo(959.9151611328125f, 487.37109375f);
  114. path.moveTo(929.2320556640625f, 516.67205810546875f);
  115. path.lineTo(898.54901123046875f, 545.97308349609375f);
  116. path.lineTo(899.93109130859375f, 485.989013671875f);
  117. return path;
  118. }
  119. static SkPath create_path_8() {
  120. SkPath path;
  121. path.moveTo(389.8609619140625f, 369.326873779296875f);
  122. path.lineTo(470.6290283203125f, 395.33697509765625f);
  123. path.lineTo(443.250030517578125f, 341.9478759765625f);
  124. path.lineTo(417.239959716796875f, 422.7159423828125f);
  125. path.moveTo(430.244964599609375f, 382.3319091796875f);
  126. path.lineTo(443.250030517578125f, 341.9478759765625f);
  127. path.lineTo(470.6290283203125f, 395.33697509765625f);
  128. return path;
  129. }
  130. static SkPath create_path_9() {
  131. SkPath path;
  132. path.moveTo(20, 20);
  133. path.lineTo(50, 80);
  134. path.lineTo(20, 80);
  135. path.moveTo(80, 50);
  136. path.lineTo(50, 50);
  137. path.lineTo(20, 50);
  138. return path;
  139. }
  140. static SkPath create_path_10() {
  141. SkPath path;
  142. path.moveTo(257.19439697265625f, 320.876617431640625f);
  143. path.lineTo(190.113037109375f, 320.58978271484375f);
  144. path.lineTo(203.64404296875f, 293.8145751953125f);
  145. path.moveTo(203.357177734375f, 360.896026611328125f);
  146. path.lineTo(216.88824462890625f, 334.120819091796875f);
  147. path.lineTo(230.41925048828125f, 307.345611572265625f);
  148. return path;
  149. }
  150. // A degenerate segments case, where both upper and lower segments of
  151. // a split edge must remain active.
  152. static SkPath create_path_11() {
  153. SkPath path;
  154. path.moveTo(231.9331207275390625f, 306.2012939453125f);
  155. path.lineTo(191.4859161376953125f, 306.04547119140625f);
  156. path.lineTo(231.0659332275390625f, 300.2642822265625f);
  157. path.moveTo(189.946807861328125f, 302.072265625f);
  158. path.lineTo(179.79705810546875f, 294.859771728515625f);
  159. path.lineTo(191.0016021728515625f, 296.165679931640625f);
  160. path.moveTo(150.8942108154296875f, 304.900146484375f);
  161. path.lineTo(179.708892822265625f, 297.849029541015625f);
  162. path.lineTo(190.4742279052734375f, 299.11895751953125f);
  163. return path;
  164. }
  165. // Handle the case where edge.dist(edge.fTop) != 0.0.
  166. static SkPath create_path_12() {
  167. SkPath path;
  168. path.moveTo( 0.0f, 400.0f);
  169. path.lineTo( 138.0f, 202.0f);
  170. path.lineTo( 0.0f, 202.0f);
  171. path.moveTo( 12.62693023681640625f, 250.57464599609375f);
  172. path.lineTo( 8.13896942138671875f, 254.556884765625f);
  173. path.lineTo(-18.15641021728515625f, 220.40203857421875f);
  174. path.lineTo(-15.986493110656738281f, 219.6513519287109375f);
  175. path.moveTo( 36.931194305419921875f, 282.485504150390625f);
  176. path.lineTo( 15.617521286010742188f, 261.2901611328125f);
  177. path.lineTo( 10.3829498291015625f, 252.565765380859375f);
  178. path.lineTo(-16.165292739868164062f, 222.646026611328125f);
  179. return path;
  180. }
  181. // A degenerate segments case which exercises inactive edges being
  182. // made active by splitting.
  183. static SkPath create_path_13() {
  184. SkPath path;
  185. path.moveTo(690.62127685546875f, 509.25555419921875f);
  186. path.lineTo(99.336181640625f, 511.71405029296875f);
  187. path.lineTo(708.362548828125f, 512.4349365234375f);
  188. path.lineTo(729.9940185546875f, 516.3114013671875f);
  189. path.lineTo(738.708984375f, 518.76995849609375f);
  190. path.lineTo(678.3463134765625f, 510.0819091796875f);
  191. path.lineTo(681.21795654296875f, 504.81378173828125f);
  192. path.moveTo(758.52764892578125f, 521.55963134765625f);
  193. path.lineTo(719.1549072265625f, 514.50372314453125f);
  194. path.lineTo(689.59063720703125f, 512.0628662109375f);
  195. path.lineTo(679.78216552734375f, 507.447845458984375f);
  196. return path;
  197. }
  198. // Tests vertices which become "orphaned" (ie., no connected edges)
  199. // after simplification.
  200. static SkPath create_path_14() {
  201. SkPath path;
  202. path.moveTo(217.326019287109375f, 166.4752960205078125f);
  203. path.lineTo(226.279266357421875f, 170.929473876953125f);
  204. path.lineTo(234.3973388671875f, 177.0623626708984375f);
  205. path.lineTo(262.0921630859375f, 188.746124267578125f);
  206. path.moveTo(196.23638916015625f, 174.0722198486328125f);
  207. path.lineTo(416.15277099609375f, 180.138214111328125f);
  208. path.lineTo(192.651947021484375f, 304.0228271484375f);
  209. return path;
  210. }
  211. static SkPath create_path_15() {
  212. SkPath path;
  213. path.moveTo( 0.0f, 0.0f);
  214. path.lineTo(10000.0f, 0.0f);
  215. path.lineTo( 0.0f, -1.0f);
  216. path.lineTo(10000.0f, 0.000001f);
  217. path.lineTo( 0.0f, -30.0f);
  218. return path;
  219. }
  220. // Reduction of Nebraska-StateSeal.svg. Floating point error causes the
  221. // same edge to be added to more than one poly on the same side.
  222. static SkPath create_path_16() {
  223. SkPath path;
  224. path.moveTo(170.8199920654296875, 491.86700439453125);
  225. path.lineTo(173.7649993896484375, 489.7340087890625);
  226. path.lineTo(174.1450958251953125, 498.545989990234375);
  227. path.lineTo( 171.998992919921875, 500.88201904296875);
  228. path.moveTo(168.2922515869140625, 498.66265869140625);
  229. path.lineTo(169.8589935302734375, 497.94500732421875);
  230. path.lineTo( 172, 500.88299560546875);
  231. path.moveTo( 169.555267333984375, 490.70111083984375);
  232. path.lineTo(173.7649993896484375, 489.7340087890625);
  233. path.lineTo( 170.82000732421875, 491.86700439453125);
  234. return path;
  235. }
  236. // A simple concave path. Test this with a non-invertible matrix.
  237. static SkPath create_path_17() {
  238. SkPath path;
  239. path.moveTo(20, 20);
  240. path.lineTo(80, 20);
  241. path.lineTo(30, 30);
  242. path.lineTo(20, 80);
  243. return path;
  244. }
  245. // A shape with a vertex collinear to the right hand edge.
  246. // This messes up find_enclosing_edges.
  247. static SkPath create_path_18() {
  248. SkPath path;
  249. path.moveTo(80, 20);
  250. path.lineTo(80, 60);
  251. path.lineTo(20, 60);
  252. path.moveTo(80, 50);
  253. path.lineTo(80, 80);
  254. path.lineTo(20, 80);
  255. return path;
  256. }
  257. // Exercises the case where an edge becomes collinear with *two* of its
  258. // adjacent neighbour edges after splitting.
  259. // This is a reduction from
  260. // http://mooooo.ooo/chebyshev-sine-approximation/horner_ulp.svg
  261. static SkPath create_path_19() {
  262. SkPath path;
  263. path.moveTo( 351.99298095703125, 348.23046875);
  264. path.lineTo( 351.91876220703125, 347.33984375);
  265. path.lineTo( 351.91876220703125, 346.1953125);
  266. path.lineTo( 351.90313720703125, 347.734375);
  267. path.lineTo( 351.90313720703125, 346.1328125);
  268. path.lineTo( 351.87579345703125, 347.93359375);
  269. path.lineTo( 351.87579345703125, 345.484375);
  270. path.lineTo( 351.86407470703125, 347.7890625);
  271. path.lineTo( 351.86407470703125, 346.2109375);
  272. path.lineTo( 351.84844970703125, 347.63763427734375);
  273. path.lineTo( 351.84454345703125, 344.19232177734375);
  274. path.lineTo( 351.78204345703125, 346.9483642578125);
  275. path.lineTo( 351.758636474609375, 347.18310546875);
  276. path.lineTo( 351.75469970703125, 346.75);
  277. path.lineTo( 351.75469970703125, 345.46875);
  278. path.lineTo( 352.5546875, 345.46875);
  279. path.lineTo( 352.55078125, 347.01953125);
  280. path.lineTo( 351.75079345703125, 347.02313232421875);
  281. path.lineTo( 351.74688720703125, 346.15203857421875);
  282. path.lineTo( 351.74688720703125, 347.646148681640625);
  283. path.lineTo( 352.5390625, 346.94140625);
  284. path.lineTo( 351.73907470703125, 346.94268798828125);
  285. path.lineTo( 351.73516845703125, 344.48565673828125);
  286. path.lineTo( 352.484375, 346.73828125);
  287. path.lineTo( 351.68438720703125, 346.7401123046875);
  288. path.lineTo( 352.4765625, 346.546875);
  289. path.lineTo( 351.67657470703125, 346.54937744140625);
  290. path.lineTo( 352.47265625, 346.75390625);
  291. path.lineTo( 351.67266845703125, 346.756622314453125);
  292. path.lineTo( 351.66876220703125, 345.612091064453125);
  293. return path;
  294. }
  295. // An intersection above the first vertex in the mesh.
  296. // Reduction from http://crbug.com/730687
  297. static SkPath create_path_20() {
  298. SkPath path;
  299. path.moveTo( 2822128.5, 235.026336669921875);
  300. path.lineTo( 2819349.25, 235.3623504638671875);
  301. path.lineTo( -340558688, 23.83478546142578125);
  302. path.lineTo( -340558752, 25.510419845581054688);
  303. path.lineTo( -340558720, 27.18605804443359375);
  304. return path;
  305. }
  306. // An intersection whose result is NaN (due to rounded-to-inf endpoint).
  307. static SkPath create_path_21() {
  308. SkPath path;
  309. path.moveTo(1.7889142061167663539e+38, 39338463358011572224.0);
  310. path.lineTo( 1647.4193115234375, -522.603515625);
  311. path.lineTo( 1677.74560546875, -529.0028076171875);
  312. path.lineTo( 1678.29541015625, -528.7847900390625);
  313. path.lineTo( 1637.5167236328125, -519.79266357421875);
  314. path.lineTo( 1647.4193115234375, -522.603515625);
  315. return path;
  316. }
  317. // A path which contains out-of-range colinear intersections.
  318. static SkPath create_path_23() {
  319. SkPath path;
  320. path.moveTo( 0, 63.39080047607421875);
  321. path.lineTo(-0.70804601907730102539, 63.14350128173828125);
  322. path.lineTo(-7.8608899287380243391e-17, 64.14080047607421875);
  323. path.moveTo( 0, 64.14080047607421875);
  324. path.lineTo(44.285900115966796875, 64.14080047607421875);
  325. path.lineTo( 0, 62.64080047607421875);
  326. path.moveTo(21.434900283813476562, -0.24732701480388641357);
  327. path.lineTo(-0.70804601907730102539, 63.14350128173828125);
  328. path.lineTo(0.70804601907730102539, 63.6381988525390625);
  329. return path;
  330. }
  331. // A path which results in infs and nans when conics are converted to quads.
  332. static SkPath create_path_24() {
  333. SkPath path;
  334. path.moveTo(-2.20883e+37f, -1.02892e+37f);
  335. path.conicTo(-2.00958e+38f, -9.36107e+37f, -1.7887e+38f, -8.33215e+37f, 0.707107f);
  336. path.conicTo(-1.56782e+38f, -7.30323e+37f, 2.20883e+37f, 1.02892e+37f, 0.707107f);
  337. path.conicTo(2.00958e+38f, 9.36107e+37f, 1.7887e+38f, 8.33215e+37f, 0.707107f);
  338. path.conicTo(1.56782e+38f, 7.30323e+37f, -2.20883e+37f, -1.02892e+37f, 0.707107f);
  339. return path;
  340. }
  341. // An edge collapse event which also collapses a neighbour, requiring
  342. // its event to be removed.
  343. static SkPath create_path_25() {
  344. SkPath path;
  345. path.moveTo( 43.44110107421875, 148.15106201171875);
  346. path.lineTo( 44.64471435546875, 148.16748046875);
  347. path.lineTo( 46.35009765625, 147.403076171875);
  348. path.lineTo( 46.45404052734375, 148.34906005859375);
  349. path.lineTo( 45.0400390625, 148.54205322265625);
  350. path.lineTo( 44.624053955078125, 148.9810791015625);
  351. path.lineTo( 44.59405517578125, 149.16107177734375);
  352. path.lineTo( 44.877044677734375, 149.62005615234375);
  353. path.lineTo(144.373016357421875, 68.8070068359375);
  354. return path;
  355. }
  356. // An edge collapse event causes an edge to become collinear, requiring
  357. // its event to be removed.
  358. static SkPath create_path_26() {
  359. SkPath path;
  360. path.moveTo( 43.44110107421875, 148.15106201171875);
  361. path.lineTo( 44.64471435546875, 148.16748046875);
  362. path.lineTo( 46.35009765625, 147.403076171875);
  363. path.lineTo( 46.45404052734375, 148.34906005859375);
  364. path.lineTo( 45.0400390625, 148.54205322265625);
  365. path.lineTo( 44.624053955078125, 148.9810791015625);
  366. path.lineTo( 44.59405517578125, 149.16107177734375);
  367. path.lineTo( 44.877044677734375, 149.62005615234375);
  368. path.lineTo(144.373016357421875, 68.8070068359375);
  369. return path;
  370. }
  371. // A path which results in non-finite points when stroked and bevelled for AA.
  372. static SkPath create_path_27() {
  373. SkPath path;
  374. path.moveTo(8.5027233009104409507e+37, 1.7503381025241130639e+37);
  375. path.lineTo(7.0923661737711584874e+37, 1.4600074517285415699e+37);
  376. path.lineTo(7.0848733446033294691e+37, 1.4584649744781838604e+37);
  377. path.lineTo(-2.0473916115129349496e+37, -4.2146796450364162012e+36);
  378. path.lineTo(2.0473912312177548811e+37, 4.2146815465123165435e+36);
  379. return path;
  380. }
  381. // AA stroking this path produces intersection failures on bevelling.
  382. // This should skip the point, but not assert.
  383. static SkPath create_path_28() {
  384. SkPath path;
  385. path.moveTo(-7.5952312625177475154e+21, -2.6819185100266674911e+24);
  386. path.lineTo( 1260.3787841796875, 1727.7947998046875);
  387. path.lineTo( 1260.5567626953125, 1728.0386962890625);
  388. path.lineTo(1.1482511310557754163e+21, 4.054538502765980051e+23);
  389. path.lineTo(-7.5952312625177475154e+21, -2.6819185100266674911e+24);
  390. return path;
  391. }
  392. // A quad which generates a huge number of points (>2B) when uniformly
  393. // linearized. This should not hang or OOM.
  394. static SkPath create_path_29() {
  395. SkPath path;
  396. path.moveTo(10, 0);
  397. path.lineTo(0, 0);
  398. path.quadTo(10, 0, 0, 8315084722602508288);
  399. return path;
  400. }
  401. // A path which hangs during simplification. It produces an edge which is
  402. // to the left of its own endpoints, which causes an infinte loop in the
  403. // right-enclosing-edge splitting.
  404. static SkPath create_path_30() {
  405. SkPath path;
  406. path.moveTo(0.75001740455627441406, 23.051967620849609375);
  407. path.lineTo(5.8471612930297851562, 22.731662750244140625);
  408. path.lineTo(10.749670028686523438, 22.253145217895507812);
  409. path.lineTo(13.115868568420410156, 22.180681228637695312);
  410. path.lineTo(15.418928146362304688, 22.340015411376953125);
  411. path.lineTo( 17.654022216796875, 22.82159423828125);
  412. path.lineTo(19.81632232666015625, 23.715869903564453125);
  413. path.lineTo(40, 0);
  414. path.lineTo(5.5635203441547955577e-15, 0);
  415. path.lineTo(5.5635203441547955577e-15, 47);
  416. path.lineTo(-1.4210854715202003717e-14, 21.713298797607421875);
  417. path.lineTo(0.75001740455627441406, 21.694292068481445312);
  418. path.lineTo(0.75001740455627441406, 23.051967620849609375);
  419. return path;
  420. }
  421. // A path with vertices which become infinite on AA stroking. Should not crash or assert.
  422. static SkPath create_path_31() {
  423. SkPath path;
  424. path.moveTo(2.0257809259190991347e+36, -1244080640);
  425. path.conicTo(2.0257809259190991347e+36, -1244080640,
  426. 2.0257809259190991347e+36, 0.10976474732160568237, 0.70710676908493041992);
  427. path.lineTo(-10036566016, -1954718402215936);
  428. path.conicTo(-1.1375507718551896064e+20, -1954721086570496,
  429. 10036566016, -1954721086570496, 0.70710676908493041992);
  430. return path;
  431. }
  432. // Reduction from skbug.com/7911 that causes a crash due to splitting a
  433. // zombie edge.
  434. static SkPath create_path_32() {
  435. SkPath path;
  436. path.moveTo( 0, 1.0927740941146660348e+24);
  437. path.lineTo(2.9333931225865729333e+32, 16476101);
  438. path.lineTo(1.0927731573659435417e+24, 1.0927740941146660348e+24);
  439. path.lineTo(1.0927740941146660348e+24, 3.7616281094287041715e-37);
  440. path.lineTo(1.0927740941146660348e+24, 1.0927740941146660348e+24);
  441. path.lineTo(1.3061803026169399536e-33, 1.0927740941146660348e+24);
  442. path.lineTo(4.7195362919941370727e-16, -8.4247545146051822591e+32);
  443. return path;
  444. }
  445. // From crbug.com/844873. Crashes trying to merge a zombie edge.
  446. static SkPath create_path_33() {
  447. SkPath path;
  448. path.moveTo( 316.000579833984375, -4338355948977389568);
  449. path.lineTo(1.5069369808623501312e+20, 75180972320904708096.0);
  450. path.lineTo(1.5069369808623501312e+20, 75180972320904708096.0);
  451. path.lineTo( 771.21014404296875, -4338355948977389568.0);
  452. path.lineTo( 316.000579833984375, -4338355948977389568.0);
  453. path.moveTo( 354.208984375, -4338355948977389568.0);
  454. path.lineTo( 773.00177001953125, -4338355948977389568.0);
  455. path.lineTo(1.5069369808623501312e+20, 75180972320904708096.0);
  456. path.lineTo(1.5069369808623501312e+20, 75180972320904708096.0);
  457. path.lineTo( 354.208984375, -4338355948977389568.0);
  458. return path;
  459. }
  460. // From crbug.com/844873. Hangs repeatedly splitting alternate vertices.
  461. static SkPath create_path_34() {
  462. SkPath path;
  463. path.moveTo(10, -1e+20f);
  464. path.lineTo(11, 25000);
  465. path.lineTo(10, 25000);
  466. path.lineTo(11, 25010);
  467. return path;
  468. }
  469. // Reduction from circular_arcs_stroke_and_fill_round GM which
  470. // repeatedly splits on the opposite edge from case 34 above.
  471. static SkPath create_path_35() {
  472. SkPath path;
  473. path.moveTo( 16.25, 26.495191574096679688);
  474. path.lineTo(32.420825958251953125, 37.377376556396484375);
  475. path.lineTo(25.176382064819335938, 39.31851959228515625);
  476. path.moveTo( 20, 20);
  477. path.lineTo(28.847436904907226562, 37.940830230712890625);
  478. path.lineTo(25.17638397216796875, 39.31851959228515625);
  479. return path;
  480. }
  481. // Reduction from crbug.com/843135 where an intersection is found
  482. // below the bottom of both intersected edges.
  483. static SkPath create_path_36() {
  484. SkPath path;
  485. path.moveTo(-2791476679359332352, 2608107002026524672);
  486. path.lineTo( 0, 11.95427703857421875);
  487. path.lineTo(-2781824066779086848, 2599088532777598976);
  488. path.lineTo( -7772.6875, 7274);
  489. return path;
  490. }
  491. // Reduction from crbug.com/843135. Exercises a case where an intersection is missed.
  492. // This causes bad ordering in the active edge list.
  493. static SkPath create_path_37() {
  494. SkPath path;
  495. path.moveTo(-1.0662557646016024569e+23, 9.9621425197286319718e+22);
  496. path.lineTo( -121806400, 113805032);
  497. path.lineTo( -120098872, 112209680);
  498. path.lineTo( 6.2832999862817380468e-36, 2.9885697364807128906);
  499. return path;
  500. }
  501. // Reduction from crbug.com/851914.
  502. static SkPath create_path_38() {
  503. SkPath path;
  504. path.moveTo(14.400531768798828125, 17.711114883422851562);
  505. path.lineTo(14.621990203857421875, 171563104293879808);
  506. path.lineTo(14.027951240539550781, 872585759381520384);
  507. path.lineTo( 14.0216827392578125, 872665817571917824);
  508. path.lineTo(7.699314117431640625, -3417320793833472);
  509. path.moveTo(11.606547355651855469, 17.40966796875);
  510. path.lineTo( 7642114886926860288, 21.08358001708984375);
  511. path.lineTo(11.606547355651855469, 21.08358001708984375);
  512. return path;
  513. }
  514. // Reduction from crbug.com/851409. Exercises collinear last vertex.
  515. static SkPath create_path_39() {
  516. SkPath path;
  517. path.moveTo(2072553216, 0);
  518. path.lineTo(2072553216, 1);
  519. path.lineTo(2072553472, -13.5);
  520. path.lineTo(2072553216, 0);
  521. path.lineTo(2072553472, -6.5);
  522. return path;
  523. }
  524. // Another reduction from crbug.com/851409. Exercises two sequential collinear edges.
  525. static SkPath create_path_40() {
  526. SkPath path;
  527. path.moveTo(2072553216, 0);
  528. path.lineTo(2072553216, 1);
  529. path.lineTo(2072553472, -13);
  530. path.lineTo(2072553216, 0);
  531. path.lineTo(2072553472, -6);
  532. path.lineTo(2072553472, -13);
  533. return path;
  534. }
  535. // Reduction from crbug.com/860453. Tests a case where a "missing" intersection
  536. // requires the active edge list to go out-of-order.
  537. static SkPath create_path_41() {
  538. SkPath path;
  539. path.moveTo(72154931603311689728.0, 330.95965576171875);
  540. path.lineTo(24053266013925408768.0, 78.11376953125);
  541. path.lineTo(1.2031099003292404941e+20, 387.168731689453125);
  542. path.lineTo(68859835992355373056.0, 346.55047607421875);
  543. path.lineTo(76451708695451009024.0, 337.780029296875);
  544. path.moveTo(-20815817797613387776.0, 18065700622522384384.0);
  545. path.lineTo(-72144121204987396096.0, 142.855804443359375);
  546. path.lineTo(72144121204987396096.0, 325.184783935546875);
  547. path.lineTo(1.2347242901040791552e+20, 18065700622522384384.0);
  548. return path;
  549. }
  550. // Reduction from crbug.com/860655. Cause is three collinear edges discovered during
  551. // sanitize_contours pass, before the vertices have been found coincident.
  552. static SkPath create_path_42() {
  553. SkPath path;
  554. path.moveTo( 32572426382475264, -3053391034974208);
  555. path.lineTo( 521289856, -48865776);
  556. path.lineTo( 130322464, -12215873);
  557. path.moveTo( 32572426382475264, -3053391034974208);
  558. path.lineTo( 521289856, -48865776);
  559. path.lineTo( 130322464, -12215873);
  560. path.moveTo( 32572426382475264, -3053391034974208);
  561. path.lineTo( 32114477642022912, -3010462031544320);
  562. path.lineTo( 32111784697528320, -3010209702215680);
  563. return path;
  564. }
  565. // Reduction from crbug.com/866319. Cause is edges that are collinear when tested from
  566. // one side, but non-collinear when tested from the other.
  567. static SkPath create_path_43() {
  568. SkPath path;
  569. path.moveTo( 307316821852160, -28808363114496);
  570. path.lineTo( 307165222928384, -28794154909696);
  571. path.lineTo( 307013691113472, -28779948802048);
  572. path.lineTo( 306862159298560, -28765744791552);
  573. path.lineTo( 306870313025536, -28766508154880);
  574. path.lineTo( 307049695019008, -28783327313920);
  575. path.lineTo( 307408660332544, -28816974020608);
  576. return path;
  577. }
  578. // Reduction from crbug.com/966696
  579. static SkPath create_path_44() {
  580. SkPath path;
  581. path.moveTo(114.4606170654296875, 186.443878173828125);
  582. path.lineTo( 91.5394744873046875, 185.4189453125);
  583. path.lineTo(306.45538330078125, 3203.986083984375);
  584. path.moveTo(16276206965409972224.0, 815.59393310546875);
  585. path.lineTo(-3.541605062372533207e+20, 487.7236328125);
  586. path.lineTo(-3.541605062372533207e+20, 168.204071044921875);
  587. path.lineTo(16276206965409972224.0, 496.07427978515625);
  588. path.moveTo(-3.541605062372533207e+20, 167.00958251953125);
  589. path.lineTo(-3.541605062372533207e+20, 488.32086181640625);
  590. path.lineTo(16276206965409972224.0, 816.78839111328125);
  591. path.lineTo(16276206965409972224.0, 495.47705078125);
  592. return path;
  593. }
  594. // Reduction from crbug.com/966274.
  595. static SkPath create_path_45() {
  596. SkPath path;
  597. path.moveTo( 706471854080, 379003666432);
  598. path.lineTo( 706503180288, 379020443648);
  599. path.lineTo( 706595717120, 379070087168);
  600. path.lineTo( 706626060288, 379086372864);
  601. path.lineTo( 706656141312, 379102527488);
  602. path.lineTo( 706774171648, 379165835264);
  603. path.lineTo( 706803073024, 379181334528);
  604. path.lineTo( 706831712256, 379196702720);
  605. path.lineTo( 706860154880, 379211939840);
  606. path.lineTo( 706888335360, 379227078656);
  607. path.lineTo( 706916253696, 379242053632);
  608. path.lineTo( 706956820480, 379263811584);
  609. path.lineTo( 706929098752, 379248934912);
  610. path.lineTo( 706901114880, 379233927168);
  611. path.lineTo( 706872934400, 379218821120);
  612. path.lineTo( 706844491776, 379203551232);
  613. path.lineTo( 706815787008, 379188183040);
  614. path.lineTo( 706786885632, 379172651008);
  615. path.lineTo( 706757722112, 379156987904);
  616. path.lineTo( 706728296448, 379141226496);
  617. path.lineTo( 706698608640, 379125301248);
  618. path.lineTo( 706668724224, 379109244928);
  619. path.lineTo( 706638577664, 379093090304);
  620. path.lineTo( 706608168960, 379076771840);
  621. path.lineTo( 706484174848, 379010252800);
  622. return path;
  623. }
  624. // Reduction from crbug.com/969359. Inf generated by intersections
  625. // causes NaN in subsequent intersections, leading to assert or hang.
  626. static SkPath create_path_46() {
  627. SkPath path;
  628. path.moveTo(1.0321827899075254821e+37, -5.1199920965387697886e+37);
  629. path.lineTo(-1.0321827899075254821e+37, 5.1199920965387697886e+37);
  630. path.lineTo(-1.0425214946728668754e+37, 4.5731834042267216669e+37);
  631. path.moveTo(-9.5077331762291841872e+36, 8.1304868292377430302e+37);
  632. path.lineTo(9.5077331762291841872e+36, -8.1304868292377430302e+37);
  633. path.lineTo(1.0795449417808426232e+37, 1.2246856113744539311e+37);
  634. path.moveTo(-165.8018341064453125, -44.859375);
  635. path.lineTo(-9.558702871563160835e+36, -7.9814405281448285475e+37);
  636. path.lineTo(-9.4147814283168490381e+36, -8.3935116522790983488e+37);
  637. return path;
  638. }
  639. static std::unique_ptr<GrFragmentProcessor> create_linear_gradient_processor(GrContext* ctx) {
  640. SkPoint pts[2] = { {0, 0}, {1, 1} };
  641. SkColor colors[2] = { SK_ColorGREEN, SK_ColorBLUE };
  642. sk_sp<SkShader> shader = SkGradientShader::MakeLinear(
  643. pts, colors, nullptr, SK_ARRAY_COUNT(colors), SkTileMode::kClamp);
  644. GrColorSpaceInfo colorSpaceInfo(GrColorType::kRGBA_8888, kPremul_SkAlphaType, nullptr);
  645. GrFPArgs args(ctx, &SkMatrix::I(), SkFilterQuality::kLow_SkFilterQuality, &colorSpaceInfo);
  646. return as_SB(shader)->asFragmentProcessor(args);
  647. }
  648. static void test_path(GrContext* ctx,
  649. GrRenderTargetContext* renderTargetContext,
  650. const SkPath& path,
  651. const SkMatrix& matrix = SkMatrix::I(),
  652. GrAAType aaType = GrAAType::kNone,
  653. std::unique_ptr<GrFragmentProcessor> fp = nullptr) {
  654. GrTessellatingPathRenderer tess;
  655. tess.setMaxVerbCount(100);
  656. GrPaint paint;
  657. paint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc));
  658. if (fp) {
  659. paint.addColorFragmentProcessor(std::move(fp));
  660. }
  661. GrNoClip noClip;
  662. SkIRect clipConservativeBounds = SkIRect::MakeWH(renderTargetContext->width(),
  663. renderTargetContext->height());
  664. GrStyle style(SkStrokeRec::kFill_InitStyle);
  665. GrShape shape(path, style);
  666. GrPathRenderer::DrawPathArgs args{ctx,
  667. std::move(paint),
  668. &GrUserStencilSettings::kUnused,
  669. renderTargetContext,
  670. &noClip,
  671. &clipConservativeBounds,
  672. &matrix,
  673. &shape,
  674. aaType,
  675. false};
  676. tess.drawPath(args);
  677. }
  678. DEF_GPUTEST_FOR_ALL_CONTEXTS(TessellatingPathRendererTests, reporter, ctxInfo) {
  679. GrContext* ctx = ctxInfo.grContext();
  680. sk_sp<GrRenderTargetContext> rtc(ctx->priv().makeDeferredRenderTargetContext(
  681. SkBackingFit::kApprox, 800, 800, GrColorType::kRGBA_8888, nullptr, 1, GrMipMapped::kNo,
  682. kTopLeft_GrSurfaceOrigin));
  683. if (!rtc) {
  684. return;
  685. }
  686. ctx->flush();
  687. // Adding discard to appease vulkan validation warning about loading uninitialized data on draw
  688. rtc->discard();
  689. test_path(ctx, rtc.get(), create_path_0());
  690. test_path(ctx, rtc.get(), create_path_1());
  691. test_path(ctx, rtc.get(), create_path_2());
  692. test_path(ctx, rtc.get(), create_path_3());
  693. test_path(ctx, rtc.get(), create_path_4());
  694. test_path(ctx, rtc.get(), create_path_5());
  695. test_path(ctx, rtc.get(), create_path_6());
  696. test_path(ctx, rtc.get(), create_path_7());
  697. test_path(ctx, rtc.get(), create_path_8());
  698. test_path(ctx, rtc.get(), create_path_9());
  699. test_path(ctx, rtc.get(), create_path_10());
  700. test_path(ctx, rtc.get(), create_path_11());
  701. test_path(ctx, rtc.get(), create_path_12());
  702. test_path(ctx, rtc.get(), create_path_13());
  703. test_path(ctx, rtc.get(), create_path_14());
  704. test_path(ctx, rtc.get(), create_path_15());
  705. test_path(ctx, rtc.get(), create_path_16());
  706. SkMatrix nonInvertibleMatrix = SkMatrix::MakeScale(0, 0);
  707. std::unique_ptr<GrFragmentProcessor> fp(create_linear_gradient_processor(ctx));
  708. test_path(ctx, rtc.get(), create_path_17(), nonInvertibleMatrix, GrAAType::kCoverage,
  709. std::move(fp));
  710. test_path(ctx, rtc.get(), create_path_18());
  711. test_path(ctx, rtc.get(), create_path_19());
  712. test_path(ctx, rtc.get(), create_path_20(), SkMatrix(), GrAAType::kCoverage);
  713. test_path(ctx, rtc.get(), create_path_21(), SkMatrix(), GrAAType::kCoverage);
  714. test_path(ctx, rtc.get(), create_path_23());
  715. test_path(ctx, rtc.get(), create_path_24());
  716. test_path(ctx, rtc.get(), create_path_25(), SkMatrix(), GrAAType::kCoverage);
  717. test_path(ctx, rtc.get(), create_path_26(), SkMatrix(), GrAAType::kCoverage);
  718. test_path(ctx, rtc.get(), create_path_27(), SkMatrix(), GrAAType::kCoverage);
  719. test_path(ctx, rtc.get(), create_path_28(), SkMatrix(), GrAAType::kCoverage);
  720. test_path(ctx, rtc.get(), create_path_29());
  721. test_path(ctx, rtc.get(), create_path_30());
  722. test_path(ctx, rtc.get(), create_path_31(), SkMatrix(), GrAAType::kCoverage);
  723. test_path(ctx, rtc.get(), create_path_32());
  724. test_path(ctx, rtc.get(), create_path_33());
  725. test_path(ctx, rtc.get(), create_path_34());
  726. test_path(ctx, rtc.get(), create_path_35());
  727. test_path(ctx, rtc.get(), create_path_36());
  728. test_path(ctx, rtc.get(), create_path_37());
  729. test_path(ctx, rtc.get(), create_path_38(), SkMatrix(), GrAAType::kCoverage);
  730. test_path(ctx, rtc.get(), create_path_39());
  731. test_path(ctx, rtc.get(), create_path_40());
  732. test_path(ctx, rtc.get(), create_path_41(), SkMatrix(), GrAAType::kCoverage);
  733. test_path(ctx, rtc.get(), create_path_42());
  734. test_path(ctx, rtc.get(), create_path_43(), SkMatrix(), GrAAType::kCoverage);
  735. test_path(ctx, rtc.get(), create_path_44(), SkMatrix(), GrAAType::kCoverage);
  736. test_path(ctx, rtc.get(), create_path_45(), SkMatrix(), GrAAType::kCoverage);
  737. test_path(ctx, rtc.get(), create_path_46(), SkMatrix(), GrAAType::kCoverage);
  738. }