| OLD | NEW |
| (Empty) | |
| 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 "SkBitmap.h" |
| 9 #include "SkBitmapDevice.h" |
| 10 #include "SkCanvas.h" |
| 11 #include "Test.h" |
| 12 |
| 13 #if SK_SUPPORT_GPU |
| 14 #include "GrContextFactory.h" |
| 15 #include "SkGpuDevice.h" |
| 16 #endif |
| 17 |
| 18 /* |
| 19 * These tests pass by not crashing, hanging or asserting in Debug. |
| 20 */ |
| 21 |
| 22 // Tests active edges made inactive by splitting. |
| 23 // Also tests active edge list forced into an invalid ordering by |
| 24 // splitting (mopped up in cleanup_active_edges()). |
| 25 static void draw_path_0(SkCanvas* canvas, const SkPaint& paint) { |
| 26 SkPath path; |
| 27 path.moveTo( 229.127044677734375, 67.34100341796875); |
| 28 path.lineTo(187.8097381591796875, -6.7729740142822265625); |
| 29 path.lineTo( 171.411407470703125, 50.94266510009765625); |
| 30 path.lineTo(245.5253753662109375, 9.6253643035888671875); |
| 31 path.moveTo(208.4683990478515625, 30.284009933471679688); |
| 32 path.lineTo( 171.411407470703125, 50.94266510009765625); |
| 33 path.lineTo(187.8097381591796875, -6.7729740142822265625); |
| 34 canvas->drawPath(path, paint); |
| 35 } |
| 36 |
| 37 // Intersections which fall exactly on the current vertex, and require |
| 38 // a restart of the intersection checking. |
| 39 static void draw_path_1(SkCanvas* canvas, const SkPaint& paint) { |
| 40 SkPath path; |
| 41 path.moveTo( 314.483551025390625, 486.246002197265625); |
| 42 path.lineTo( 385.41949462890625, 532.8087158203125); |
| 43 path.lineTo( 373.232879638671875, 474.05938720703125); |
| 44 path.lineTo( 326.670166015625, 544.995361328125); |
| 45 path.moveTo( 349.951507568359375, 509.52734375); |
| 46 path.lineTo( 373.232879638671875, 474.05938720703125); |
| 47 path.lineTo( 385.41949462890625, 532.8087158203125); |
| 48 canvas->drawPath(path, paint); |
| 49 } |
| 50 |
| 51 // Tests active edges which are removed by splitting. |
| 52 static void draw_path_2(SkCanvas* canvas, const SkPaint& paint) { |
| 53 SkPath path; |
| 54 path.moveTo( 343.107391357421875, 613.62176513671875); |
| 55 path.lineTo( 426.632415771484375, 628.5740966796875); |
| 56 path.lineTo( 392.3460693359375, 579.33544921875); |
| 57 path.lineTo( 377.39373779296875, 662.86041259765625); |
| 58 path.moveTo( 384.869873046875, 621.097900390625); |
| 59 path.lineTo( 392.3460693359375, 579.33544921875); |
| 60 path.lineTo( 426.632415771484375, 628.5740966796875); |
| 61 canvas->drawPath(path, paint); |
| 62 } |
| 63 |
| 64 // Collinear edges merged in set_top(). |
| 65 // Also, an intersection between left and right enclosing edges which |
| 66 // falls above the current vertex. |
| 67 static void draw_path_3(SkCanvas* canvas, const SkPaint& paint) { |
| 68 SkPath path; |
| 69 path.moveTo( 545.95751953125, 791.69854736328125); |
| 70 path.lineTo( 612.05816650390625, 738.494140625); |
| 71 path.lineTo( 552.4056396484375, 732.0460205078125); |
| 72 path.lineTo( 605.61004638671875, 798.14666748046875); |
| 73 path.moveTo( 579.00787353515625, 765.0963134765625); |
| 74 path.lineTo( 552.4056396484375, 732.0460205078125); |
| 75 path.lineTo( 612.05816650390625, 738.494140625); |
| 76 canvas->drawPath(path, paint); |
| 77 } |
| 78 |
| 79 // Tests active edges which are made inactive by set_top(). |
| 80 static void draw_path_4(SkCanvas* canvas, const SkPaint& paint) { |
| 81 SkPath path; |
| 82 path.moveTo( 819.2725830078125, 751.77447509765625); |
| 83 path.lineTo( 820.70904541015625, 666.933837890625); |
| 84 path.lineTo( 777.57049560546875, 708.63592529296875); |
| 85 path.lineTo( 862.4111328125, 710.0723876953125); |
| 86 path.moveTo( 819.99078369140625, 709.3541259765625); |
| 87 path.lineTo( 777.57049560546875, 708.63592529296875); |
| 88 path.lineTo( 820.70904541015625, 666.933837890625); |
| 89 canvas->drawPath(path, paint); |
| 90 } |
| 91 |
| 92 static void draw_path_5(SkCanvas* canvas, const SkPaint& paint) { |
| 93 SkPath path; |
| 94 path.moveTo( 823.33209228515625, 749.052734375); |
| 95 path.lineTo( 823.494873046875, 664.20013427734375); |
| 96 path.lineTo( 780.9871826171875, 706.5450439453125); |
| 97 path.lineTo( 865.8397216796875, 706.70782470703125); |
| 98 path.moveTo( 823.4134521484375, 706.6263427734375); |
| 99 path.lineTo( 780.9871826171875, 706.5450439453125); |
| 100 path.lineTo( 823.494873046875, 664.20013427734375); |
| 101 canvas->drawPath(path, paint); |
| 102 } |
| 103 |
| 104 static void draw_path_6(SkCanvas* canvas, const SkPaint& paint) { |
| 105 SkPath path; |
| 106 path.moveTo( 954.862548828125, 562.8349609375); |
| 107 path.lineTo( 899.32818603515625, 498.679443359375); |
| 108 path.lineTo( 895.017578125, 558.52435302734375); |
| 109 path.lineTo( 959.17315673828125, 502.990081787109375); |
| 110 path.moveTo( 927.0953369140625, 530.7572021484375); |
| 111 path.lineTo( 895.017578125, 558.52435302734375); |
| 112 path.lineTo( 899.32818603515625, 498.679443359375); |
| 113 canvas->drawPath(path, paint); |
| 114 } |
| 115 |
| 116 static void draw_path_7(SkCanvas* canvas, const SkPaint& paint) { |
| 117 SkPath path; |
| 118 path.moveTo( 958.5330810546875, 547.35516357421875); |
| 119 path.lineTo( 899.93109130859375, 485.989013671875); |
| 120 path.lineTo( 898.54901123046875, 545.97308349609375); |
| 121 path.lineTo( 959.9151611328125, 487.37109375); |
| 122 path.moveTo( 929.2320556640625, 516.67205810546875); |
| 123 path.lineTo( 898.54901123046875, 545.97308349609375); |
| 124 path.lineTo( 899.93109130859375, 485.989013671875); |
| 125 canvas->drawPath(path, paint); |
| 126 } |
| 127 |
| 128 static void draw_path_8(SkCanvas* canvas, const SkPaint& paint) { |
| 129 SkPath path; |
| 130 path.moveTo( 389.8609619140625, 369.326873779296875); |
| 131 path.lineTo( 470.6290283203125, 395.33697509765625); |
| 132 path.lineTo( 443.250030517578125, 341.9478759765625); |
| 133 path.lineTo( 417.239959716796875, 422.7159423828125); |
| 134 path.moveTo( 430.244964599609375, 382.3319091796875); |
| 135 path.lineTo( 443.250030517578125, 341.9478759765625); |
| 136 path.lineTo( 470.6290283203125, 395.33697509765625); |
| 137 canvas->drawPath(path, paint); |
| 138 } |
| 139 |
| 140 static void draw_path_9(SkCanvas* canvas, const SkPaint& paint) { |
| 141 SkPath path; |
| 142 path.moveTo(20, 20); |
| 143 path.lineTo(50, 80); |
| 144 path.lineTo(20, 80); |
| 145 path.moveTo(80, 50); |
| 146 path.lineTo(50, 50); |
| 147 path.lineTo(20, 50); |
| 148 canvas->drawPath(path, paint); |
| 149 } |
| 150 |
| 151 static void draw_path_10(SkCanvas* canvas, const SkPaint& paint) { |
| 152 SkPath path; |
| 153 path.moveTo(257.19439697265625, 320.876617431640625); |
| 154 path.lineTo(190.113037109375, 320.58978271484375); |
| 155 path.lineTo(203.64404296875, 293.8145751953125); |
| 156 path.moveTo(203.357177734375, 360.896026611328125); |
| 157 path.lineTo(216.88824462890625, 334.120819091796875); |
| 158 path.lineTo(230.41925048828125, 307.345611572265625); |
| 159 canvas->drawPath(path, paint); |
| 160 } |
| 161 |
| 162 // A degenerate segments case, where both upper and lower segments of |
| 163 // a split edge must remain active. |
| 164 static void draw_path_11(SkCanvas* canvas, const SkPaint& paint) { |
| 165 SkPath path; |
| 166 path.moveTo(231.9331207275390625, 306.2012939453125); |
| 167 path.lineTo(191.4859161376953125, 306.04547119140625); |
| 168 path.lineTo(231.0659332275390625, 300.2642822265625); |
| 169 path.moveTo( 189.946807861328125, 302.072265625); |
| 170 path.lineTo( 179.79705810546875, 294.859771728515625); |
| 171 path.lineTo(191.0016021728515625, 296.165679931640625); |
| 172 path.moveTo(150.8942108154296875, 304.900146484375); |
| 173 path.lineTo( 179.708892822265625, 297.849029541015625); |
| 174 path.lineTo(190.4742279052734375, 299.11895751953125); |
| 175 canvas->drawPath(path, paint); |
| 176 } |
| 177 |
| 178 // Handle the case where edge.dist(edge.fTop) != 0.0. |
| 179 static void draw_path_12(SkCanvas* canvas, const SkPaint& paint) { |
| 180 SkPath path; |
| 181 path.moveTo( 0, 400); |
| 182 path.lineTo( 138, 202); |
| 183 path.lineTo( 0, 202); |
| 184 path.moveTo(12.62693023681640625, 250.57464599609375); |
| 185 path.lineTo( 8.13896942138671875, 254.556884765625); |
| 186 path.lineTo(-18.15641021728515625, 220.40203857421875); |
| 187 path.lineTo(-15.986493110656738281, 219.6513519287109375); |
| 188 path.moveTo(36.931194305419921875, 282.485504150390625); |
| 189 path.lineTo(15.617521286010742188, 261.2901611328125); |
| 190 path.lineTo( 10.3829498291015625, 252.565765380859375); |
| 191 path.lineTo(-16.165292739868164062, 222.646026611328125); |
| 192 canvas->drawPath(path, paint); |
| 193 } |
| 194 |
| 195 // A degenerate segments case which exercises inactive edges being |
| 196 // made active by splitting. |
| 197 static void draw_path_13(SkCanvas* canvas, const SkPaint& paint) { |
| 198 SkPath path; |
| 199 path.moveTo( 690.62127685546875, 509.25555419921875); |
| 200 path.lineTo( 699.336181640625, 511.71405029296875); |
| 201 path.lineTo( 708.362548828125, 512.4349365234375); |
| 202 path.lineTo( 729.9940185546875, 516.3114013671875); |
| 203 path.lineTo( 738.708984375, 518.76995849609375); |
| 204 path.lineTo( 678.3463134765625, 510.0819091796875); |
| 205 path.lineTo( 681.21795654296875, 504.81378173828125); |
| 206 path.moveTo( 758.52764892578125, 521.55963134765625); |
| 207 path.lineTo( 719.1549072265625, 514.50372314453125); |
| 208 path.lineTo( 689.59063720703125, 512.0628662109375); |
| 209 path.lineTo( 679.78216552734375, 507.447845458984375); |
| 210 canvas->drawPath(path, paint); |
| 211 } |
| 212 |
| 213 // Tests vertices which become "orphaned" (ie., no connected edges) |
| 214 // after simplification. |
| 215 static void draw_path_14(SkCanvas* canvas, const SkPaint& paint) { |
| 216 SkPath path; |
| 217 path.moveTo( 217.326019287109375, 166.4752960205078125); |
| 218 path.lineTo( 226.279266357421875, 170.929473876953125); |
| 219 path.lineTo( 234.3973388671875, 177.0623626708984375); |
| 220 path.lineTo( 262.0921630859375, 188.746124267578125); |
| 221 path.moveTo( 196.23638916015625, 174.0722198486328125); |
| 222 path.lineTo( 416.15277099609375, 180.138214111328125); |
| 223 path.lineTo( 192.651947021484375, 304.0228271484375); |
| 224 canvas->drawPath(path, paint); |
| 225 } |
| 226 |
| 227 static void test_concave_paths(SkSurface* surface, skiatest::Reporter* reporter)
{ |
| 228 SkCanvas* canvas = surface->getCanvas(); |
| 229 canvas->clear(0); |
| 230 |
| 231 SkPaint paint; |
| 232 paint.setAntiAlias(false); |
| 233 draw_path_0(canvas, paint); |
| 234 draw_path_1(canvas, paint); |
| 235 draw_path_2(canvas, paint); |
| 236 draw_path_3(canvas, paint); |
| 237 draw_path_4(canvas, paint); |
| 238 draw_path_5(canvas, paint); |
| 239 draw_path_6(canvas, paint); |
| 240 draw_path_7(canvas, paint); |
| 241 draw_path_8(canvas, paint); |
| 242 draw_path_9(canvas, paint); |
| 243 draw_path_10(canvas, paint); |
| 244 draw_path_11(canvas, paint); |
| 245 draw_path_12(canvas, paint); |
| 246 draw_path_13(canvas, paint); |
| 247 draw_path_14(canvas, paint); |
| 248 } |
| 249 |
| 250 DEF_TEST(ConcavePathTests, reporter) { |
| 251 SkBitmap temp; |
| 252 SkImageInfo info = SkImageInfo::MakeN32Premul(800, 800); |
| 253 temp.allocN32Pixels(800, 800); |
| 254 SkBitmapDevice device(temp); |
| 255 SkAutoTUnref<SkSurface> surface( |
| 256 SkSurface::NewRasterDirect(info, temp.getPixels(), temp.rowBytes())); |
| 257 test_concave_paths(surface.get(), reporter); |
| 258 } |
| 259 |
| 260 #if SK_SUPPORT_GPU |
| 261 const SkSurfaceProps gProps = SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_Ini
tType); |
| 262 |
| 263 DEF_GPUTEST(ConcavePathTestsGPU, reporter, factory) { |
| 264 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp
e>(0)); |
| 265 GrSurfaceDesc desc; |
| 266 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 267 desc.fWidth = 800; |
| 268 desc.fHeight = 800; |
| 269 desc.fConfig = kSkia8888_GrPixelConfig; |
| 270 desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
| 271 SkAutoTUnref<GrTexture> texture( |
| 272 context->refScratchTexture(desc, GrContext::kExact_ScratchTexMatch) |
| 273 ); |
| 274 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTargetDirect(texture->as
RenderTarget())); |
| 275 test_concave_paths(surface.get(), reporter); |
| 276 } |
| 277 #endif |
| OLD | NEW |