Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(227)

Side by Side Diff: tests/DrawPathTest.cpp

Issue 1817383002: switch surface to sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tests/DrawFilterTest.cpp ('k') | tests/GpuDrawPathTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkDashPathEffect.h" 10 #include "SkDashPathEffect.h"
11 #include "SkStrokeRec.h" 11 #include "SkStrokeRec.h"
12 #include "SkSurface.h" 12 #include "SkSurface.h"
13 #include "Test.h" 13 #include "Test.h"
14 14
15 // test that we can draw an aa-rect at coordinates > 32K (bigger than fixedpoint ) 15 // test that we can draw an aa-rect at coordinates > 32K (bigger than fixedpoint )
16 static void test_big_aa_rect(skiatest::Reporter* reporter) { 16 static void test_big_aa_rect(skiatest::Reporter* reporter) {
17 SkBitmap output; 17 SkBitmap output;
18 SkPMColor pixel[1]; 18 SkPMColor pixel[1];
19 output.installPixels(SkImageInfo::MakeN32Premul(1, 1), pixel, 4); 19 output.installPixels(SkImageInfo::MakeN32Premul(1, 1), pixel, 4);
20 20
21 SkSurface* surf = SkSurface::NewRasterN32Premul(300, 33300); 21 auto surf = SkSurface::MakeRasterN32Premul(300, 33300);
22 SkCanvas* canvas = surf->getCanvas(); 22 SkCanvas* canvas = surf->getCanvas();
23 23
24 SkRect r = { 0, 33000, 300, 33300 }; 24 SkRect r = { 0, 33000, 300, 33300 };
25 int x = SkScalarRoundToInt(r.left()); 25 int x = SkScalarRoundToInt(r.left());
26 int y = SkScalarRoundToInt(r.top()); 26 int y = SkScalarRoundToInt(r.top());
27 27
28 // check that the pixel in question starts as transparent (by the surface) 28 // check that the pixel in question starts as transparent (by the surface)
29 if (canvas->readPixels(&output, x, y)) { 29 if (canvas->readPixels(&output, x, y)) {
30 REPORTER_ASSERT(reporter, 0 == pixel[0]); 30 REPORTER_ASSERT(reporter, 0 == pixel[0]);
31 } else { 31 } else {
32 REPORTER_ASSERT_MESSAGE(reporter, false, "readPixels failed"); 32 REPORTER_ASSERT_MESSAGE(reporter, false, "readPixels failed");
33 } 33 }
34 34
35 SkPaint paint; 35 SkPaint paint;
36 paint.setAntiAlias(true); 36 paint.setAntiAlias(true);
37 paint.setColor(SK_ColorWHITE); 37 paint.setColor(SK_ColorWHITE);
38 38
39 canvas->drawRect(r, paint); 39 canvas->drawRect(r, paint);
40 40
41 // Now check that it is BLACK 41 // Now check that it is BLACK
42 if (canvas->readPixels(&output, x, y)) { 42 if (canvas->readPixels(&output, x, y)) {
43 // don't know what swizzling PMColor did, but white should always 43 // don't know what swizzling PMColor did, but white should always
44 // appear the same. 44 // appear the same.
45 REPORTER_ASSERT(reporter, 0xFFFFFFFF == pixel[0]); 45 REPORTER_ASSERT(reporter, 0xFFFFFFFF == pixel[0]);
46 } else { 46 } else {
47 REPORTER_ASSERT_MESSAGE(reporter, false, "readPixels failed"); 47 REPORTER_ASSERT_MESSAGE(reporter, false, "readPixels failed");
48 } 48 }
49 surf->unref();
50 } 49 }
51 50
52 /////////////////////////////////////////////////////////////////////////////// 51 ///////////////////////////////////////////////////////////////////////////////
53 52
54 static void moveToH(SkPath* path, const uint32_t raw[]) { 53 static void moveToH(SkPath* path, const uint32_t raw[]) {
55 const float* fptr = (const float*)raw; 54 const float* fptr = (const float*)raw;
56 path->moveTo(fptr[0], fptr[1]); 55 path->moveTo(fptr[0], fptr[1]);
57 } 56 }
58 57
59 static void cubicToH(SkPath* path, const uint32_t raw[]) { 58 static void cubicToH(SkPath* path, const uint32_t raw[]) {
(...skipping 28 matching lines...) Expand all
88 */ 87 */
89 uint32_t data[] = { 88 uint32_t data[] = {
90 0x419727af, 0x43011f0c, 0x41972663, 0x43011f27, 89 0x419727af, 0x43011f0c, 0x41972663, 0x43011f27,
91 0x419728fc, 0x43011ed4, 0x4194064b, 0x43012197 90 0x419728fc, 0x43011ed4, 0x4194064b, 0x43012197
92 }; 91 };
93 92
94 SkPath path; 93 SkPath path;
95 moveToH(&path, &data[0]); 94 moveToH(&path, &data[0]);
96 cubicToH(&path, &data[2]); 95 cubicToH(&path, &data[2]);
97 96
98 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(640, 480)); 97 auto surface(SkSurface::MakeRasterN32Premul(640, 480));
99 98
100 SkPaint paint; 99 SkPaint paint;
101 paint.setAntiAlias(true); 100 paint.setAntiAlias(true);
102 surface->getCanvas()->drawPath(path, paint); 101 surface->getCanvas()->drawPath(path, paint);
103 } 102 }
104 103
105 // This used to assert in debug builds (and crash writing bad memory in release) 104 // This used to assert in debug builds (and crash writing bad memory in release)
106 // because we overflowed an intermediate value (B coefficient) setting up our 105 // because we overflowed an intermediate value (B coefficient) setting up our
107 // stepper for the quadratic. Now we bias that value by 1/2 so we don't overflow 106 // stepper for the quadratic. Now we bias that value by 1/2 so we don't overflow
108 static void test_crbug_140803() { 107 static void test_crbug_140803() {
(...skipping 16 matching lines...) Expand all
125 // 124 //
126 static void test_inversepathwithclip() { 125 static void test_inversepathwithclip() {
127 SkPath path; 126 SkPath path;
128 127
129 path.moveTo(0, 20); 128 path.moveTo(0, 20);
130 path.quadTo(10, 10, 20, 20); 129 path.quadTo(10, 10, 20, 20);
131 path.toggleInverseFillType(); 130 path.toggleInverseFillType();
132 131
133 SkPaint paint; 132 SkPaint paint;
134 133
135 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(640, 480)); 134 auto surface(SkSurface::MakeRasterN32Premul(640, 480));
136 SkCanvas* canvas = surface->getCanvas(); 135 SkCanvas* canvas = surface->getCanvas();
137 canvas->save(); 136 canvas->save();
138 canvas->clipRect(SkRect::MakeWH(19, 11)); 137 canvas->clipRect(SkRect::MakeWH(19, 11));
139 138
140 paint.setAntiAlias(false); 139 paint.setAntiAlias(false);
141 canvas->drawPath(path, paint); 140 canvas->drawPath(path, paint);
142 paint.setAntiAlias(true); 141 paint.setAntiAlias(true);
143 canvas->drawPath(path, paint); 142 canvas->drawPath(path, paint);
144 143
145 canvas->restore(); 144 canvas->restore();
(...skipping 18 matching lines...) Expand all
164 This particular test/bug only applies to the float case, where the 163 This particular test/bug only applies to the float case, where the
165 coordinates are very large. 164 coordinates are very large.
166 */ 165 */
167 SkPath path; 166 SkPath path;
168 path.moveTo(64, 3); 167 path.moveTo(64, 3);
169 path.quadTo(-329936, -100000000, 1153, 330003); 168 path.quadTo(-329936, -100000000, 1153, 330003);
170 169
171 SkPaint paint; 170 SkPaint paint;
172 paint.setAntiAlias(true); 171 paint.setAntiAlias(true);
173 172
174 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(640, 480)); 173 auto surface(SkSurface::MakeRasterN32Premul(640, 480));
175 surface->getCanvas()->drawPath(path, paint); 174 surface->getCanvas()->drawPath(path, paint);
176 } 175 }
177 176
178 static void test_crbug_140642() { 177 static void test_crbug_140642() {
179 /* 178 /*
180 * We used to see this construct, and due to rounding as we accumulated 179 * We used to see this construct, and due to rounding as we accumulated
181 * our length, the loop where we apply the phase would run off the end of 180 * our length, the loop where we apply the phase would run off the end of
182 * the array, since it relied on just -= each interval value, which did not 181 * the array, since it relied on just -= each interval value, which did not
183 * behave as "expected". Now the code explicitly checks for walking off the 182 * behave as "expected". Now the code explicitly checks for walking off the
184 * end of that array. 183 * end of that array.
(...skipping 21 matching lines...) Expand all
206 } 205 }
207 206
208 static void test_bigcubic() { 207 static void test_bigcubic() {
209 SkPath path; 208 SkPath path;
210 path.moveTo(64, 3); 209 path.moveTo(64, 3);
211 path.cubicTo(-329936, -100000000, -329936, 100000000, 1153, 330003); 210 path.cubicTo(-329936, -100000000, -329936, 100000000, 1153, 330003);
212 211
213 SkPaint paint; 212 SkPaint paint;
214 paint.setAntiAlias(true); 213 paint.setAntiAlias(true);
215 214
216 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(640, 480)); 215 auto surface(SkSurface::MakeRasterN32Premul(640, 480));
217 surface->getCanvas()->drawPath(path, paint); 216 surface->getCanvas()->drawPath(path, paint);
218 } 217 }
219 218
220 // asserts if halfway case is not handled 219 // asserts if halfway case is not handled
221 static void test_halfway() { 220 static void test_halfway() {
222 SkPaint paint; 221 SkPaint paint;
223 SkPath path; 222 SkPath path;
224 path.moveTo(16365.5f, 1394); 223 path.moveTo(16365.5f, 1394);
225 path.lineTo(16365.5f, 1387.5f); 224 path.lineTo(16365.5f, 1387.5f);
226 path.quadTo(16365.5f, 1385.43f, 16367, 1383.96f); 225 path.quadTo(16365.5f, 1385.43f, 16367, 1383.96f);
227 path.quadTo(16368.4f, 1382.5f, 16370.5f, 1382.5f); 226 path.quadTo(16368.4f, 1382.5f, 16370.5f, 1382.5f);
228 path.lineTo(16465.5f, 1382.5f); 227 path.lineTo(16465.5f, 1382.5f);
229 path.quadTo(16467.6f, 1382.5f, 16469, 1383.96f); 228 path.quadTo(16467.6f, 1382.5f, 16469, 1383.96f);
230 path.quadTo(16470.5f, 1385.43f, 16470.5f, 1387.5f); 229 path.quadTo(16470.5f, 1385.43f, 16470.5f, 1387.5f);
231 path.lineTo(16470.5f, 1394); 230 path.lineTo(16470.5f, 1394);
232 path.quadTo(16470.5f, 1396.07f, 16469, 1397.54f); 231 path.quadTo(16470.5f, 1396.07f, 16469, 1397.54f);
233 path.quadTo(16467.6f, 1399, 16465.5f, 1399); 232 path.quadTo(16467.6f, 1399, 16465.5f, 1399);
234 path.lineTo(16370.5f, 1399); 233 path.lineTo(16370.5f, 1399);
235 path.quadTo(16368.4f, 1399, 16367, 1397.54f); 234 path.quadTo(16368.4f, 1399, 16367, 1397.54f);
236 path.quadTo(16365.5f, 1396.07f, 16365.5f, 1394); 235 path.quadTo(16365.5f, 1396.07f, 16365.5f, 1394);
237 path.close(); 236 path.close();
238 SkPath p2; 237 SkPath p2;
239 SkMatrix m; 238 SkMatrix m;
240 m.reset(); 239 m.reset();
241 m.postTranslate(0.001f, 0.001f); 240 m.postTranslate(0.001f, 0.001f);
242 path.transform(m, &p2); 241 path.transform(m, &p2);
243 242
244 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(640, 480)); 243 auto surface(SkSurface::MakeRasterN32Premul(640, 480));
245 SkCanvas* canvas = surface->getCanvas(); 244 SkCanvas* canvas = surface->getCanvas();
246 canvas->translate(-16366, -1383); 245 canvas->translate(-16366, -1383);
247 canvas->drawPath(p2, paint); 246 canvas->drawPath(p2, paint);
248 247
249 m.reset(); 248 m.reset();
250 m.postTranslate(-0.001f, -0.001f); 249 m.postTranslate(-0.001f, -0.001f);
251 path.transform(m, &p2); 250 path.transform(m, &p2);
252 canvas->drawPath(p2, paint); 251 canvas->drawPath(p2, paint);
253 252
254 m.reset(); 253 m.reset();
255 path.transform(m, &p2); 254 path.transform(m, &p2);
256 canvas->drawPath(p2, paint); 255 canvas->drawPath(p2, paint);
257 } 256 }
258 257
259 // we used to assert if the bounds of the device (clip) was larger than 32K 258 // we used to assert if the bounds of the device (clip) was larger than 32K
260 // even when the path itself was smaller. We just draw and hope in the debug 259 // even when the path itself was smaller. We just draw and hope in the debug
261 // version to not assert. 260 // version to not assert.
262 static void test_giantaa() { 261 static void test_giantaa() {
263 const int W = 400; 262 const int W = 400;
264 const int H = 400; 263 const int H = 400;
265 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(33000, 10)); 264 auto surface(SkSurface::MakeRasterN32Premul(33000, 10));
266 265
267 SkPaint paint; 266 SkPaint paint;
268 paint.setAntiAlias(true); 267 paint.setAntiAlias(true);
269 SkPath path; 268 SkPath path;
270 path.addOval(SkRect::MakeXYWH(-10, -10, 20 + W, 20 + H)); 269 path.addOval(SkRect::MakeXYWH(-10, -10, 20 + W, 20 + H));
271 surface->getCanvas()->drawPath(path, paint); 270 surface->getCanvas()->drawPath(path, paint);
272 } 271 }
273 272
274 // Extremely large path_length/dash_length ratios may cause infinite looping 273 // Extremely large path_length/dash_length ratios may cause infinite looping
275 // in SkDashPathEffect::filterPath() due to single precision rounding. 274 // in SkDashPathEffect::filterPath() due to single precision rounding.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 308
310 SkPath filteredPath; 309 SkPath filteredPath;
311 SkStrokeRec rec(paint); 310 SkStrokeRec rec(paint);
312 REPORTER_ASSERT(reporter, !dash->filterPath(&filteredPath, path, &rec, nullp tr)); 311 REPORTER_ASSERT(reporter, !dash->filterPath(&filteredPath, path, &rec, nullp tr));
313 REPORTER_ASSERT(reporter, filteredPath.isEmpty()); 312 REPORTER_ASSERT(reporter, filteredPath.isEmpty());
314 } 313 }
315 314
316 // http://crbug.com/472147 315 // http://crbug.com/472147
317 // This is a simplified version from the bug. RRect radii not properly scaled. 316 // This is a simplified version from the bug. RRect radii not properly scaled.
318 static void test_crbug_472147_simple(skiatest::Reporter* reporter) { 317 static void test_crbug_472147_simple(skiatest::Reporter* reporter) {
319 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(1000, 1000)); 318 auto surface(SkSurface::MakeRasterN32Premul(1000, 1000));
320 SkCanvas* canvas = surface->getCanvas(); 319 SkCanvas* canvas = surface->getCanvas();
321 SkPaint p; 320 SkPaint p;
322 SkRect r = SkRect::MakeLTRB(-246.0f, 33.0f, 848.0f, 33554464.0f); 321 SkRect r = SkRect::MakeLTRB(-246.0f, 33.0f, 848.0f, 33554464.0f);
323 SkVector radii[4] = { 322 SkVector radii[4] = {
324 { 13.0f, 8.0f }, { 170.0f, 2.0 }, { 256.0f, 33554430.0f }, { 120.0f, 5.0 f } 323 { 13.0f, 8.0f }, { 170.0f, 2.0 }, { 256.0f, 33554430.0f }, { 120.0f, 5.0 f }
325 }; 324 };
326 SkRRect rr; 325 SkRRect rr;
327 rr.setRectRadii(r, radii); 326 rr.setRectRadii(r, radii);
328 canvas->drawRRect(rr, p); 327 canvas->drawRRect(rr, p);
329 } 328 }
330 329
331 // http://crbug.com/472147 330 // http://crbug.com/472147
332 // RRect radii not properly scaled. 331 // RRect radii not properly scaled.
333 static void test_crbug_472147_actual(skiatest::Reporter* reporter) { 332 static void test_crbug_472147_actual(skiatest::Reporter* reporter) {
334 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(1000, 1000)); 333 auto surface(SkSurface::MakeRasterN32Premul(1000, 1000));
335 SkCanvas* canvas = surface->getCanvas(); 334 SkCanvas* canvas = surface->getCanvas();
336 SkPaint p; 335 SkPaint p;
337 SkRect r = SkRect::MakeLTRB(-246.0f, 33.0f, 848.0f, 33554464.0f); 336 SkRect r = SkRect::MakeLTRB(-246.0f, 33.0f, 848.0f, 33554464.0f);
338 SkVector radii[4] = { 337 SkVector radii[4] = {
339 { 13.0f, 8.0f }, { 170.0f, 2.0 }, { 256.0f, 33554430.0f }, { 120.0f, 5.0 f } 338 { 13.0f, 8.0f }, { 170.0f, 2.0 }, { 256.0f, 33554430.0f }, { 120.0f, 5.0 f }
340 }; 339 };
341 SkRRect rr; 340 SkRRect rr;
342 rr.setRectRadii(r, radii); 341 rr.setRectRadii(r, radii);
343 canvas->clipRRect(rr, SkRegion::kIntersect_Op, false); 342 canvas->clipRRect(rr, SkRegion::kIntersect_Op, false);
344 343
(...skipping 11 matching lines...) Expand all
356 test_inversepathwithclip(); 355 test_inversepathwithclip();
357 // why? 356 // why?
358 if (false) test_crbug131181(); 357 if (false) test_crbug131181();
359 test_infinite_dash(reporter); 358 test_infinite_dash(reporter);
360 test_crbug_165432(reporter); 359 test_crbug_165432(reporter);
361 test_crbug_472147_simple(reporter); 360 test_crbug_472147_simple(reporter);
362 test_crbug_472147_actual(reporter); 361 test_crbug_472147_actual(reporter);
363 test_big_aa_rect(reporter); 362 test_big_aa_rect(reporter);
364 test_halfway(); 363 test_halfway();
365 } 364 }
OLDNEW
« no previous file with comments | « tests/DrawFilterTest.cpp ('k') | tests/GpuDrawPathTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698