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

Side by Side Diff: tests/PathTest.cpp

Issue 12334131: Change random number generator for tests to SkMWCRandom (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Rebase to latest Created 7 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 | Annotate | Revision Log
« no previous file with comments | « tests/PackBitsTest.cpp ('k') | tests/PictureTest.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 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "Test.h" 8 #include "Test.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkPaint.h" 10 #include "SkPaint.h"
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 add_corner_arc(path, r, xCorner, yCorner, 90); 283 add_corner_arc(path, r, xCorner, yCorner, 90);
284 add_corner_arc(path, r, xCorner, yCorner, 180); 284 add_corner_arc(path, r, xCorner, yCorner, 180);
285 path->close(); 285 path->close();
286 } 286 }
287 287
288 // Chrome creates its own round rects with each corner possibly being different. 288 // Chrome creates its own round rects with each corner possibly being different.
289 // Performance will suffer if they are not convex. 289 // Performance will suffer if they are not convex.
290 // Note: PathBench::ArbRoundRectBench performs almost exactly 290 // Note: PathBench::ArbRoundRectBench performs almost exactly
291 // the same test (but with drawing) 291 // the same test (but with drawing)
292 static void test_arb_round_rect_is_convex(skiatest::Reporter* reporter) { 292 static void test_arb_round_rect_is_convex(skiatest::Reporter* reporter) {
293 SkRandom rand; 293 SkMWCRandom rand;
294 SkRect r; 294 SkRect r;
295 295
296 for (int i = 0; i < 5000; ++i) { 296 for (int i = 0; i < 5000; ++i) {
297 297
298 SkScalar size = rand.nextUScalar1() * 30; 298 SkScalar size = rand.nextUScalar1() * 30;
299 if (size < SK_Scalar1) { 299 if (size < SK_Scalar1) {
300 continue; 300 continue;
301 } 301 }
302 r.fLeft = rand.nextUScalar1() * 300; 302 r.fLeft = rand.nextUScalar1() * 300;
303 r.fTop = rand.nextUScalar1() * 300; 303 r.fTop = rand.nextUScalar1() * 300;
304 r.fRight = r.fLeft + 2 * size; 304 r.fRight = r.fLeft + 2 * size;
305 r.fBottom = r.fTop + 2 * size; 305 r.fBottom = r.fTop + 2 * size;
306 306
307 SkPath temp; 307 SkPath temp;
308 308
309 make_arb_round_rect(&temp, r, r.width() / 10, r.height() / 15); 309 make_arb_round_rect(&temp, r, r.width() / 10, r.height() / 15);
310 310
311 REPORTER_ASSERT(reporter, temp.isConvex()); 311 REPORTER_ASSERT(reporter, temp.isConvex());
312 } 312 }
313 } 313 }
314 314
315 // Chrome will sometimes create a 0 radius round rect. The degenerate 315 // Chrome will sometimes create a 0 radius round rect. The degenerate
316 // quads prevent the path from being converted to a rect 316 // quads prevent the path from being converted to a rect
317 // Note: PathBench::ArbRoundRectBench performs almost exactly 317 // Note: PathBench::ArbRoundRectBench performs almost exactly
318 // the same test (but with drawing) 318 // the same test (but with drawing)
319 static void test_arb_zero_rad_round_rect_is_rect(skiatest::Reporter* reporter) { 319 static void test_arb_zero_rad_round_rect_is_rect(skiatest::Reporter* reporter) {
320 SkRandom rand; 320 SkMWCRandom rand;
321 SkRect r; 321 SkRect r;
322 322
323 for (int i = 0; i < 5000; ++i) { 323 for (int i = 0; i < 5000; ++i) {
324 324
325 SkScalar size = rand.nextUScalar1() * 30; 325 SkScalar size = rand.nextUScalar1() * 30;
326 if (size < SK_Scalar1) { 326 if (size < SK_Scalar1) {
327 continue; 327 continue;
328 } 328 }
329 r.fLeft = rand.nextUScalar1() * 300; 329 r.fLeft = rand.nextUScalar1() * 300;
330 r.fTop = rand.nextUScalar1() * 300; 330 r.fTop = rand.nextUScalar1() * 300;
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 case SkPath::kDone_Verb: 445 case SkPath::kDone_Verb:
446 goto DONE; 446 goto DONE;
447 } 447 }
448 } 448 }
449 DONE: 449 DONE:
450 REPORTER_ASSERT(reporter, foundClose == expectClose); 450 REPORTER_ASSERT(reporter, foundClose == expectClose);
451 } 451 }
452 452
453 static void test_addPoly(skiatest::Reporter* reporter) { 453 static void test_addPoly(skiatest::Reporter* reporter) {
454 SkPoint pts[32]; 454 SkPoint pts[32];
455 SkRandom rand; 455 SkMWCRandom rand;
456 456
457 for (size_t i = 0; i < SK_ARRAY_COUNT(pts); ++i) { 457 for (size_t i = 0; i < SK_ARRAY_COUNT(pts); ++i) {
458 pts[i].fX = rand.nextSScalar1(); 458 pts[i].fX = rand.nextSScalar1();
459 pts[i].fY = rand.nextSScalar1(); 459 pts[i].fY = rand.nextSScalar1();
460 } 460 }
461 461
462 for (int doClose = 0; doClose <= 1; ++doClose) { 462 for (int doClose = 0; doClose <= 1; ++doClose) {
463 for (size_t count = 1; count <= SK_ARRAY_COUNT(pts); ++count) { 463 for (size_t count = 1; count <= SK_ARRAY_COUNT(pts); ++count) {
464 SkPath path; 464 SkPath path;
465 path.addPoly(pts, count, SkToBool(doClose)); 465 path.addPoly(pts, count, SkToBool(doClose));
(...skipping 1389 matching lines...) Expand 10 before | Expand all | Expand 10 after
1855 1855
1856 // Generate random paths and verify 1856 // Generate random paths and verify
1857 SkPoint randomPts[25]; 1857 SkPoint randomPts[25];
1858 for (int i = 0; i < 5; ++i) { 1858 for (int i = 0; i < 5; ++i) {
1859 for (int j = 0; j < 5; ++j) { 1859 for (int j = 0; j < 5; ++j) {
1860 randomPts[i*5+j].set(SK_Scalar1*i, SK_Scalar1*j); 1860 randomPts[i*5+j].set(SK_Scalar1*i, SK_Scalar1*j);
1861 } 1861 }
1862 } 1862 }
1863 1863
1864 // Max of 10 segments, max 3 points per segment 1864 // Max of 10 segments, max 3 points per segment
1865 SkRandom rand(9876543); 1865 SkMWCRandom rand(9876543);
1866 SkPoint expectedPts[31]; // May have leading moveTo 1866 SkPoint expectedPts[31]; // May have leading moveTo
1867 SkPath::Verb expectedVerbs[22]; // May have leading moveTo 1867 SkPath::Verb expectedVerbs[22]; // May have leading moveTo
1868 SkPath::Verb nextVerb; 1868 SkPath::Verb nextVerb;
1869 1869
1870 for (int i = 0; i < 500; ++i) { 1870 for (int i = 0; i < 500; ++i) {
1871 p.reset(); 1871 p.reset();
1872 bool lastWasClose = true; 1872 bool lastWasClose = true;
1873 bool haveMoveTo = false; 1873 bool haveMoveTo = false;
1874 SkPoint lastMoveToPt = { 0, 0 }; 1874 SkPoint lastMoveToPt = { 0, 0 };
1875 int numPoints = 0; 1875 int numPoints = 0;
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
2350 test_arb_round_rect_is_convex(reporter); 2350 test_arb_round_rect_is_convex(reporter);
2351 test_arb_zero_rad_round_rect_is_rect(reporter); 2351 test_arb_zero_rad_round_rect_is_rect(reporter);
2352 test_addrect_isfinite(reporter); 2352 test_addrect_isfinite(reporter);
2353 test_tricky_cubic(); 2353 test_tricky_cubic();
2354 test_clipped_cubic(); 2354 test_clipped_cubic();
2355 test_crbug_170666(); 2355 test_crbug_170666();
2356 } 2356 }
2357 2357
2358 #include "TestClassDef.h" 2358 #include "TestClassDef.h"
2359 DEFINE_TESTCLASS("Path", PathTestClass, TestPath) 2359 DEFINE_TESTCLASS("Path", PathTestClass, TestPath)
OLDNEW
« no previous file with comments | « tests/PackBitsTest.cpp ('k') | tests/PictureTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698