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(const char* testName) { | 315 void ShowTestArray(const char* testName) { |
316 if (!testName) { | 316 if (!testName) { |
317 testName = "xOp"; | 317 testName = "xOp"; |
318 } | 318 } |
319 for (int x = gTestFirst; x < gTestNo; ++x) { | 319 for (int x = gTestFirst; x < gTestNo; ++x) { |
320 SkDebugf(" TEST(%s%d%s),\n", testName, x, opSuffixes[gTestOp[x - gTes
tFirst]]); | 320 SkDebugf(" TEST(%s%d%s),\n", testName, x, opSuffixes[gTestOp[x - gTes
tFirst]]); |
321 } | 321 } |
322 } | 322 } |
323 | 323 |
324 SK_DECLARE_STATIC_MUTEX(compareDebugOut3); | 324 SK_DECLARE_STATIC_MUTEX(compareDebugOut3); |
325 SK_DECLARE_STATIC_MUTEX(compareDebugOut4); | 325 |
326 static int comparePaths(skiatest::Reporter* reporter, const char* testName, cons
t SkPath& one, | 326 static int comparePaths(skiatest::Reporter* reporter, const char* testName, cons
t SkPath& one, |
327 const SkPath& scaledOne, const SkPath& two, const SkPath& scaledTwo, SkB
itmap& bitmap, | 327 const SkPath& scaledOne, const SkPath& two, const SkPath& scaledTwo, SkB
itmap& bitmap, |
328 const SkPath& a, const SkPath& b, const SkPathOp shapeOp, const SkMatrix
& scale, | 328 const SkPath& a, const SkPath& b, const SkPathOp shapeOp, const SkMatrix
& scale, |
329 bool expectSuccess, bool flaky) { | 329 bool expectSuccess) { |
330 int errors2x2; | 330 int errors2x2; |
331 const int MAX_ERRORS = 8; | 331 const int MAX_ERRORS = 8; |
332 (void) pathsDrawTheSame(bitmap, scaledOne, scaledTwo, errors2x2); | 332 (void) pathsDrawTheSame(bitmap, scaledOne, scaledTwo, errors2x2); |
333 if (!expectSuccess) { | 333 if (!expectSuccess) { |
334 if (errors2x2 <= MAX_ERRORS && !flaky) { | 334 if (errors2x2 < MAX_ERRORS) { |
335 REPORTER_ASSERT(reporter, 0); | 335 REPORTER_ASSERT(reporter, 0); |
336 } | 336 } |
337 return 0; | 337 return 0; |
338 } | 338 } |
339 if (errors2x2 == 0) { | 339 if (errors2x2 == 0) { |
340 return 0; | 340 return 0; |
341 } | 341 } |
342 if (flaky) { | 342 if (errors2x2 >= MAX_ERRORS) { |
343 return 0; | |
344 } | |
345 if (errors2x2 > MAX_ERRORS) { | |
346 SkAutoMutexAcquire autoM(compareDebugOut3); | 343 SkAutoMutexAcquire autoM(compareDebugOut3); |
347 showPathOpPath(testName, one, two, a, b, scaledOne, scaledTwo, shapeOp,
scale); | 344 showPathOpPath(testName, one, two, a, b, scaledOne, scaledTwo, shapeOp,
scale); |
348 SkDebugf("\n/*"); | 345 SkDebugf("\n/*"); |
349 REPORTER_ASSERT(reporter, 0); | 346 REPORTER_ASSERT(reporter, 0); |
350 SkDebugf(" */\n"); | 347 SkDebugf(" */\n"); |
351 } else if (errors2x2 == MAX_ERRORS || errors2x2 == MAX_ERRORS - 1) { | |
352 SkAutoMutexAcquire autoM(compareDebugOut4); | |
353 showPathOpPath(testName, one, two, a, b, scaledOne, scaledTwo, shapeOp,
scale); | |
354 } | 348 } |
355 return errors2x2 > MAX_ERRORS ? errors2x2 : 0; | 349 return errors2x2 >= MAX_ERRORS ? errors2x2 : 0; |
356 } | 350 } |
357 | 351 |
358 // Default values for when reporter->verbose() is false. | 352 // Default values for when reporter->verbose() is false. |
359 static int testNumber = 55; | 353 static int testNumber = 55; |
360 static const char* testName = "pathOpTest"; | 354 static const char* testName = "pathOpTest"; |
361 | 355 |
362 static void writeTestName(const char* nameSuffix, SkMemoryWStream& outFile) { | 356 static void writeTestName(const char* nameSuffix, SkMemoryWStream& outFile) { |
363 outFile.writeText(testName); | 357 outFile.writeText(testName); |
364 outFile.writeDecAsText(testNumber); | 358 outFile.writeDecAsText(testNumber); |
365 ++testNumber; | 359 ++testNumber; |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 SkDebugf("\n"); | 485 SkDebugf("\n"); |
492 showPathData(a); | 486 showPathData(a); |
493 showOp(shapeOp); | 487 showOp(shapeOp); |
494 showPathData(b); | 488 showPathData(b); |
495 } | 489 } |
496 #endif | 490 #endif |
497 | 491 |
498 bool OpDebug(const SkPath& one, const SkPath& two, SkPathOp op, SkPath* result,
bool expectSuccess); | 492 bool OpDebug(const SkPath& one, const SkPath& two, SkPathOp op, SkPath* result,
bool expectSuccess); |
499 | 493 |
500 static bool innerPathOp(skiatest::Reporter* reporter, const SkPath& a, const SkP
ath& b, | 494 static bool innerPathOp(skiatest::Reporter* reporter, const SkPath& a, const SkP
ath& b, |
501 const SkPathOp shapeOp, const char* testName, bool threaded, bool expect
Success, | 495 const SkPathOp shapeOp, const char* testName, bool expectSuccess) { |
502 bool flaky) { | |
503 #if 0 && DEBUG_SHOW_TEST_NAME | 496 #if 0 && DEBUG_SHOW_TEST_NAME |
504 showName(a, b, shapeOp); | 497 showName(a, b, shapeOp); |
505 #endif | 498 #endif |
506 SkPath out; | 499 SkPath out; |
507 if (!OpDebug(a, b, shapeOp, &out, expectSuccess)) { | 500 if (!OpDebug(a, b, shapeOp, &out, expectSuccess)) { |
508 SkDebugf("%s did not expect failure\n", __FUNCTION__); | 501 SkDebugf("%s did not expect failure\n", __FUNCTION__); |
509 REPORTER_ASSERT(reporter, 0); | 502 REPORTER_ASSERT(reporter, 0); |
510 return false; | 503 return false; |
511 } | 504 } |
512 if (!reporter->verbose()) { | 505 if (!reporter->verbose()) { |
(...skipping 17 matching lines...) Expand all Loading... |
530 scaledB.setFillType(b.getFillType()); | 523 scaledB.setFillType(b.getFillType()); |
531 scaledRgnA.setPath(scaledA, openClip); | 524 scaledRgnA.setPath(scaledA, openClip); |
532 scaledRgnB.setPath(scaledB, openClip); | 525 scaledRgnB.setPath(scaledB, openClip); |
533 scaledRgnOut.op(scaledRgnA, scaledRgnB, (SkRegion::Op) shapeOp); | 526 scaledRgnOut.op(scaledRgnA, scaledRgnB, (SkRegion::Op) shapeOp); |
534 scaledRgnOut.getBoundaryPath(&scaledPathOut); | 527 scaledRgnOut.getBoundaryPath(&scaledPathOut); |
535 SkBitmap bitmap; | 528 SkBitmap bitmap; |
536 SkPath scaledOut; | 529 SkPath scaledOut; |
537 scaledOut.addPath(out, scale); | 530 scaledOut.addPath(out, scale); |
538 scaledOut.setFillType(out.getFillType()); | 531 scaledOut.setFillType(out.getFillType()); |
539 int result = comparePaths(reporter, testName, pathOut, scaledPathOut, out, s
caledOut, bitmap, | 532 int result = comparePaths(reporter, testName, pathOut, scaledPathOut, out, s
caledOut, bitmap, |
540 a, b, shapeOp, scale, expectSuccess, flaky); | 533 a, b, shapeOp, scale, expectSuccess); |
541 reporter->bumpTestCount(); | 534 reporter->bumpTestCount(); |
542 return result == 0; | 535 return result == 0; |
543 } | 536 } |
544 | 537 |
545 bool testPathOp(skiatest::Reporter* reporter, const SkPath& a, const SkPath& b, | 538 bool testPathOp(skiatest::Reporter* reporter, const SkPath& a, const SkPath& b, |
546 const SkPathOp shapeOp, const char* testName) { | 539 const SkPathOp shapeOp, const char* testName) { |
547 return innerPathOp(reporter, a, b, shapeOp, testName, false, true, false); | 540 return innerPathOp(reporter, a, b, shapeOp, testName, true); |
548 } | |
549 | |
550 bool testPathOpFlaky(skiatest::Reporter* reporter, const SkPath& a, const SkPath
& b, | |
551 const SkPathOp shapeOp, const char* testName) { | |
552 return innerPathOp(reporter, a, b, shapeOp, testName, false, true, true); | |
553 } | 541 } |
554 | 542 |
555 bool testPathOpCheck(skiatest::Reporter* reporter, const SkPath& a, const SkPath
& b, | 543 bool testPathOpCheck(skiatest::Reporter* reporter, const SkPath& a, const SkPath
& b, |
556 const SkPathOp shapeOp, const char* testName, bool checkFail) { | 544 const SkPathOp shapeOp, const char* testName, bool checkFail) { |
557 return innerPathOp(reporter, a, b, shapeOp, testName, false, checkFail, fals
e); | 545 return innerPathOp(reporter, a, b, shapeOp, testName, checkFail); |
558 } | 546 } |
559 | 547 |
560 bool testPathOpFailCheck(skiatest::Reporter* reporter, const SkPath& a, const Sk
Path& b, | 548 bool testPathOpFailCheck(skiatest::Reporter* reporter, const SkPath& a, const Sk
Path& b, |
561 const SkPathOp shapeOp, const char* testName) { | 549 const SkPathOp shapeOp, const char* testName) { |
562 return innerPathOp(reporter, a, b, shapeOp, testName, false, false, true); | 550 return innerPathOp(reporter, a, b, shapeOp, testName, false); |
563 } | 551 } |
564 | 552 |
565 bool testPathFailOp(skiatest::Reporter* reporter, const SkPath& a, const SkPath&
b, | 553 bool testPathFailOp(skiatest::Reporter* reporter, const SkPath& a, const SkPath&
b, |
566 const SkPathOp shapeOp, const char* testName) { | 554 const SkPathOp shapeOp, const char* testName) { |
567 #if DEBUG_SHOW_TEST_NAME | 555 #if DEBUG_SHOW_TEST_NAME |
568 showName(a, b, shapeOp); | 556 showName(a, b, shapeOp); |
569 #endif | 557 #endif |
570 SkPath orig; | 558 SkPath orig; |
571 orig.lineTo(54, 43); | 559 orig.lineTo(54, 43); |
572 SkPath out = orig; | 560 SkPath out = orig; |
573 if (Op(a, b, shapeOp, &out) ) { | 561 if (Op(a, b, shapeOp, &out) ) { |
574 SkDebugf("%s test is expected to fail\n", __FUNCTION__); | 562 SkDebugf("%s test is expected to fail\n", __FUNCTION__); |
575 REPORTER_ASSERT(reporter, 0); | 563 REPORTER_ASSERT(reporter, 0); |
576 return false; | 564 return false; |
577 } | 565 } |
578 SkASSERT(out == orig); | 566 SkASSERT(out == orig); |
579 return true; | 567 return true; |
580 } | 568 } |
581 | 569 |
582 bool testThreadedPathOp(skiatest::Reporter* reporter, const SkPath& a, const SkP
ath& b, | |
583 const SkPathOp shapeOp, const char* testName) { | |
584 return innerPathOp(reporter, a, b, shapeOp, testName, true, true, false); | |
585 } | |
586 | |
587 SK_DECLARE_STATIC_MUTEX(gMutex); | 570 SK_DECLARE_STATIC_MUTEX(gMutex); |
588 | 571 |
589 void initializeTests(skiatest::Reporter* reporter, const char* test) { | 572 void initializeTests(skiatest::Reporter* reporter, const char* test) { |
590 #if 0 // doesn't work yet | 573 #if 0 // doesn't work yet |
591 SK_CONF_SET("images.jpeg.suppressDecoderWarnings", true); | 574 SK_CONF_SET("images.jpeg.suppressDecoderWarnings", true); |
592 SK_CONF_SET("images.png.suppressDecoderWarnings", true); | 575 SK_CONF_SET("images.png.suppressDecoderWarnings", true); |
593 #endif | 576 #endif |
594 if (reporter->verbose()) { | 577 if (reporter->verbose()) { |
595 SkAutoMutexAcquire lock(gMutex); | 578 SkAutoMutexAcquire lock(gMutex); |
596 testName = test; | 579 testName = test; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
687 if (foundSkip && tests[index].fun != firstTest) { | 670 if (foundSkip && tests[index].fun != firstTest) { |
688 SkDebugf(" %s,\n", tests[index].str); | 671 SkDebugf(" %s,\n", tests[index].str); |
689 } | 672 } |
690 if (tests[index].fun == stopTest || index == last) { | 673 if (tests[index].fun == stopTest || index == last) { |
691 break; | 674 break; |
692 } | 675 } |
693 index += reverse ? -1 : 1; | 676 index += reverse ? -1 : 1; |
694 } while (true); | 677 } while (true); |
695 #endif | 678 #endif |
696 } | 679 } |
OLD | NEW |