OLD | NEW |
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 "PathOpsExtendedTest.h" | 8 #include "PathOpsExtendedTest.h" |
9 #include "PathOpsThreadedCommon.h" | 9 #include "PathOpsThreadedCommon.h" |
10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 void ShowTestArray() { | 315 void ShowTestArray() { |
316 for (int x = gTestFirst; x < gTestNo; ++x) { | 316 for (int x = gTestFirst; x < gTestNo; ++x) { |
317 SkDebugf(" TEST(xOp%d%s),\n", x, opSuffixes[gTestOp[x - gTestFirst]])
; | 317 SkDebugf(" TEST(xOp%d%s),\n", x, opSuffixes[gTestOp[x - gTestFirst]])
; |
318 } | 318 } |
319 } | 319 } |
320 | 320 |
321 SK_DECLARE_STATIC_MUTEX(compareDebugOut3); | 321 SK_DECLARE_STATIC_MUTEX(compareDebugOut3); |
322 SK_DECLARE_STATIC_MUTEX(compareDebugOut4); | 322 SK_DECLARE_STATIC_MUTEX(compareDebugOut4); |
323 static int comparePaths(skiatest::Reporter* reporter, const char* testName, cons
t SkPath& one, | 323 static int comparePaths(skiatest::Reporter* reporter, const char* testName, cons
t SkPath& one, |
324 const SkPath& scaledOne, const SkPath& two, const SkPath& scaledTwo, SkB
itmap& bitmap, | 324 const SkPath& scaledOne, const SkPath& two, const SkPath& scaledTwo, SkB
itmap& bitmap, |
325 const SkPath& a, const SkPath& b, const SkPathOp shapeOp, const SkMatrix
& scale, | 325 const SkPath& a, const SkPath& b, const SkPathOp shapeOp, const SkMatrix
& scale) { |
326 bool expectSuccess) { | |
327 int errors2x2; | 326 int errors2x2; |
328 const int MAX_ERRORS = 8; | |
329 (void) pathsDrawTheSame(bitmap, scaledOne, scaledTwo, errors2x2); | 327 (void) pathsDrawTheSame(bitmap, scaledOne, scaledTwo, errors2x2); |
330 if (!expectSuccess) { | |
331 if (errors2x2 <= MAX_ERRORS) { | |
332 REPORTER_ASSERT(reporter, 0); | |
333 } | |
334 return 0; | |
335 } | |
336 if (errors2x2 == 0) { | 328 if (errors2x2 == 0) { |
337 if (gShowPath) { | 329 if (gShowPath) { |
338 showPathOpPath(testName, one, two, a, b, scaledOne, scaledTwo, shape
Op, scale); | 330 showPathOpPath(testName, one, two, a, b, scaledOne, scaledTwo, shape
Op, scale); |
339 } | 331 } |
340 return 0; | 332 return 0; |
341 } | 333 } |
| 334 const int MAX_ERRORS = 8; |
342 if (errors2x2 > MAX_ERRORS && gComparePathsAssert) { | 335 if (errors2x2 > MAX_ERRORS && gComparePathsAssert) { |
343 SkAutoMutexAcquire autoM(compareDebugOut3); | 336 SkAutoMutexAcquire autoM(compareDebugOut3); |
344 SkDebugf("\n*** this test fails ***\n"); | 337 SkDebugf("\n*** this test fails ***\n"); |
345 showPathOpPath(testName, one, two, a, b, scaledOne, scaledTwo, shapeOp,
scale); | 338 showPathOpPath(testName, one, two, a, b, scaledOne, scaledTwo, shapeOp,
scale); |
346 REPORTER_ASSERT(reporter, 0); | 339 REPORTER_ASSERT(reporter, 0); |
347 } else if (gShowPath || errors2x2 == MAX_ERRORS || errors2x2 == MAX_ERRORS -
1) { | 340 } else if (gShowPath || errors2x2 == MAX_ERRORS || errors2x2 == MAX_ERRORS -
1) { |
348 SkAutoMutexAcquire autoM(compareDebugOut4); | 341 SkAutoMutexAcquire autoM(compareDebugOut4); |
349 showPathOpPath(testName, one, two, a, b, scaledOne, scaledTwo, shapeOp,
scale); | 342 showPathOpPath(testName, one, two, a, b, scaledOne, scaledTwo, shapeOp,
scale); |
350 } | 343 } |
351 return errors2x2 > MAX_ERRORS ? errors2x2 : 0; | 344 return errors2x2 > MAX_ERRORS ? errors2x2 : 0; |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 #if DEBUG_SHOW_TEST_NAME | 465 #if DEBUG_SHOW_TEST_NAME |
473 static void showName(const SkPath& a, const SkPath& b, const SkPathOp shapeOp) { | 466 static void showName(const SkPath& a, const SkPath& b, const SkPathOp shapeOp) { |
474 SkDebugf("\n"); | 467 SkDebugf("\n"); |
475 showPathData(a); | 468 showPathData(a); |
476 showOp(shapeOp); | 469 showOp(shapeOp); |
477 showPathData(b); | 470 showPathData(b); |
478 } | 471 } |
479 #endif | 472 #endif |
480 | 473 |
481 static bool innerPathOp(skiatest::Reporter* reporter, const SkPath& a, const SkP
ath& b, | 474 static bool innerPathOp(skiatest::Reporter* reporter, const SkPath& a, const SkP
ath& b, |
482 const SkPathOp shapeOp, const char* testName, bool threaded, bool expect
Success) { | 475 const SkPathOp shapeOp, const char* testName, bool threaded) { |
483 #if DEBUG_SHOW_TEST_NAME | 476 #if DEBUG_SHOW_TEST_NAME |
484 showName(a, b, shapeOp); | 477 showName(a, b, shapeOp); |
485 #endif | 478 #endif |
486 SkPath out; | 479 SkPath out; |
487 if (!Op(a, b, shapeOp, &out) ) { | 480 if (!Op(a, b, shapeOp, &out) ) { |
488 SkDebugf("%s did not expect failure\n", __FUNCTION__); | 481 SkDebugf("%s did not expect failure\n", __FUNCTION__); |
489 REPORTER_ASSERT(reporter, 0); | 482 REPORTER_ASSERT(reporter, 0); |
490 return false; | 483 return false; |
491 } | 484 } |
492 if (threaded && !reporter->verbose()) { | 485 if (threaded && !reporter->verbose()) { |
(...skipping 17 matching lines...) Expand all Loading... |
510 scaledB.setFillType(b.getFillType()); | 503 scaledB.setFillType(b.getFillType()); |
511 scaledRgnA.setPath(scaledA, openClip); | 504 scaledRgnA.setPath(scaledA, openClip); |
512 scaledRgnB.setPath(scaledB, openClip); | 505 scaledRgnB.setPath(scaledB, openClip); |
513 scaledRgnOut.op(scaledRgnA, scaledRgnB, (SkRegion::Op) shapeOp); | 506 scaledRgnOut.op(scaledRgnA, scaledRgnB, (SkRegion::Op) shapeOp); |
514 scaledRgnOut.getBoundaryPath(&scaledPathOut); | 507 scaledRgnOut.getBoundaryPath(&scaledPathOut); |
515 SkBitmap bitmap; | 508 SkBitmap bitmap; |
516 SkPath scaledOut; | 509 SkPath scaledOut; |
517 scaledOut.addPath(out, scale); | 510 scaledOut.addPath(out, scale); |
518 scaledOut.setFillType(out.getFillType()); | 511 scaledOut.setFillType(out.getFillType()); |
519 int result = comparePaths(reporter, testName, pathOut, scaledPathOut, out, s
caledOut, bitmap, | 512 int result = comparePaths(reporter, testName, pathOut, scaledPathOut, out, s
caledOut, bitmap, |
520 a, b, shapeOp, scale, expectSuccess); | 513 a, b, shapeOp, scale); |
521 if (result && gPathStrAssert) { | 514 if (result && gPathStrAssert) { |
522 REPORTER_ASSERT(reporter, 0); | 515 REPORTER_ASSERT(reporter, 0); |
523 } | 516 } |
524 reporter->bumpTestCount(); | 517 reporter->bumpTestCount(); |
525 return result == 0; | 518 return result == 0; |
526 } | 519 } |
527 | 520 |
528 bool testPathOp(skiatest::Reporter* reporter, const SkPath& a, const SkPath& b, | 521 bool testPathOp(skiatest::Reporter* reporter, const SkPath& a, const SkPath& b, |
529 const SkPathOp shapeOp, const char* testName) { | 522 const SkPathOp shapeOp, const char* testName) { |
530 return innerPathOp(reporter, a, b, shapeOp, testName, false, true); | 523 return innerPathOp(reporter, a, b, shapeOp, testName, false); |
531 } | |
532 | |
533 bool testPathOpCheck(skiatest::Reporter* reporter, const SkPath& a, const SkPath
& b, | |
534 const SkPathOp shapeOp, const char* testName, bool checkFail) { | |
535 return innerPathOp(reporter, a, b, shapeOp, testName, false, checkFail); | |
536 } | 524 } |
537 | 525 |
538 bool testPathFailOp(skiatest::Reporter* reporter, const SkPath& a, const SkPath&
b, | 526 bool testPathFailOp(skiatest::Reporter* reporter, const SkPath& a, const SkPath&
b, |
539 const SkPathOp shapeOp, const char* testName) { | 527 const SkPathOp shapeOp, const char* testName) { |
540 #if DEBUG_SHOW_TEST_NAME | 528 #if DEBUG_SHOW_TEST_NAME |
541 showName(a, b, shapeOp); | 529 showName(a, b, shapeOp); |
542 #endif | 530 #endif |
543 SkPath out; | 531 SkPath out; |
544 if (Op(a, b, shapeOp, &out) ) { | 532 if (Op(a, b, shapeOp, &out) ) { |
545 SkDebugf("%s test is expected to fail\n", __FUNCTION__); | 533 SkDebugf("%s test is expected to fail\n", __FUNCTION__); |
546 REPORTER_ASSERT(reporter, 0); | 534 REPORTER_ASSERT(reporter, 0); |
547 return false; | 535 return false; |
548 } | 536 } |
549 return true; | 537 return true; |
550 } | 538 } |
551 | 539 |
552 bool testThreadedPathOp(skiatest::Reporter* reporter, const SkPath& a, const SkP
ath& b, | 540 bool testThreadedPathOp(skiatest::Reporter* reporter, const SkPath& a, const SkP
ath& b, |
553 const SkPathOp shapeOp, const char* testName) { | 541 const SkPathOp shapeOp, const char* testName) { |
554 return innerPathOp(reporter, a, b, shapeOp, testName, true, true); | 542 return innerPathOp(reporter, a, b, shapeOp, testName, true); |
555 } | 543 } |
556 | 544 |
557 SK_DECLARE_STATIC_MUTEX(gMutex); | 545 SK_DECLARE_STATIC_MUTEX(gMutex); |
558 | 546 |
559 void initializeTests(skiatest::Reporter* reporter, const char* test) { | 547 void initializeTests(skiatest::Reporter* reporter, const char* test) { |
560 #if 0 // doesn't work yet | 548 #if 0 // doesn't work yet |
561 SK_CONF_SET("images.jpeg.suppressDecoderWarnings", true); | 549 SK_CONF_SET("images.jpeg.suppressDecoderWarnings", true); |
562 SK_CONF_SET("images.png.suppressDecoderWarnings", true); | 550 SK_CONF_SET("images.png.suppressDecoderWarnings", true); |
563 #endif | 551 #endif |
564 if (reporter->verbose()) { | 552 if (reporter->verbose()) { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 if (tests[index].fun == stopTest) { | 621 if (tests[index].fun == stopTest) { |
634 SkDebugf("lastTest\n"); | 622 SkDebugf("lastTest\n"); |
635 break; | 623 break; |
636 } | 624 } |
637 if (index == last) { | 625 if (index == last) { |
638 break; | 626 break; |
639 } | 627 } |
640 index += reverse ? -1 : 1; | 628 index += reverse ? -1 : 1; |
641 } while (true); | 629 } while (true); |
642 } | 630 } |
OLD | NEW |