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