caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 1 | #include "PathOpsExtendedTest.h" |
| 2 | #include "PathOpsThreadedCommon.h" |
skia.committer@gmail.com | 2b34fe0 | 2013-05-08 07:01:40 +0000 | [diff] [blame] | 3 | #include "SkBitmap.h" |
| 4 | #include "SkDevice.h" |
| 5 | #include "SkCanvas.h" |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 6 | #include "SkImageDecoder.h" |
skia.committer@gmail.com | 2b34fe0 | 2013-05-08 07:01:40 +0000 | [diff] [blame] | 7 | #include "SkImageEncoder.h" |
| 8 | #include "SkStream.h" |
| 9 | #include "SkOSFile.h" |
| 10 | #include "SkPicture.h" |
| 11 | #include "SkString.h" |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 12 | |
| 13 | #ifdef SK_BUILD_FOR_WIN |
| 14 | #define PATH_SLASH "\\" |
| 15 | #define IN_DIR "D:" PATH_SLASH "skp" |
| 16 | #define OUT_DIR "D:" PATH_SLASH |
| 17 | #else |
| 18 | #define PATH_SLASH "/" |
| 19 | #define IN_DIR "/Volumes/Untitled" PATH_SLASH |
| 20 | #define OUT_DIR PATH_SLASH |
| 21 | #endif |
| 22 | |
| 23 | static const char pictDir[] = IN_DIR ; |
| 24 | static const char outSkpClipDir[] = OUT_DIR "skpClip"; |
| 25 | static const char outOldClipDir[] = OUT_DIR "oldClip"; |
skia.committer@gmail.com | 2b34fe0 | 2013-05-08 07:01:40 +0000 | [diff] [blame] | 26 | |
| 27 | static void make_filepath(SkString* path, const char* dir, const SkString& name) { |
| 28 | size_t len = strlen(dir); |
| 29 | path->set(dir); |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 30 | if (len > 0 && dir[len - 1] != PATH_SLASH[0]) { |
| 31 | path->append(PATH_SLASH); |
skia.committer@gmail.com | 2b34fe0 | 2013-05-08 07:01:40 +0000 | [diff] [blame] | 32 | } |
| 33 | path->append(name); |
| 34 | } |
| 35 | |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 36 | static void testOne(const SkString& filename) { |
| 37 | #if DEBUG_SHOW_TEST_NAME |
| 38 | SkString testName(filename); |
| 39 | const char http[] = "http"; |
| 40 | if (testName.startsWith(http)) { |
| 41 | testName.remove(0, sizeof(http) - 1); |
| 42 | } |
| 43 | while (testName.startsWith("_")) { |
| 44 | testName.remove(0, 1); |
| 45 | } |
| 46 | const char dotSkp[] = ".skp"; |
| 47 | if (testName.endsWith(dotSkp)) { |
| 48 | size_t len = testName.size(); |
| 49 | testName.remove(len - (sizeof(dotSkp) - 1), sizeof(dotSkp) - 1); |
| 50 | } |
| 51 | testName.prepend("skp"); |
| 52 | testName.append("1"); |
| 53 | strncpy(DEBUG_FILENAME_STRING, testName.c_str(), DEBUG_FILENAME_STRING_LENGTH); |
| 54 | #endif |
| 55 | SkString path; |
| 56 | make_filepath(&path, pictDir, filename); |
| 57 | SkFILEStream stream(path.c_str()); |
| 58 | if (!stream.isValid()) { |
| 59 | return; |
| 60 | } |
| 61 | bool success; |
| 62 | SkPicture* pic = SkNEW_ARGS(SkPicture, (&stream, &success, &SkImageDecoder::DecodeMemory)); |
| 63 | if (!success) { |
| 64 | SkDebugf("unable to decode %s\n", filename.c_str()); |
| 65 | return; |
| 66 | } |
| 67 | int width = pic->width(); |
| 68 | int height = pic->height(); |
| 69 | SkBitmap bitmap; |
| 70 | bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); |
| 71 | success = bitmap.allocPixels(); |
| 72 | if (!success) { |
| 73 | SkDebugf("unable to allocate bitmap for %s\n", filename.c_str()); |
| 74 | return; |
| 75 | } |
| 76 | SkCanvas canvas(bitmap); |
| 77 | SkString pngName(filename); |
| 78 | pngName.remove(pngName.size() - 3, 3); |
| 79 | pngName.append("png"); |
| 80 | for (int i = 0; i < 2; ++i) { |
| 81 | bool useOp = i ? true : false; |
| 82 | canvas.setAllowSimplifyClip(useOp); |
| 83 | pic->draw(&canvas); |
| 84 | SkString outFile; |
| 85 | make_filepath(&outFile, useOp ? outSkpClipDir : outOldClipDir, pngName); |
| 86 | SkImageEncoder::EncodeFile(outFile.c_str(), bitmap, SkImageEncoder::kPNG_Type, 100); |
| 87 | } |
| 88 | SkDELETE(pic); |
| 89 | } |
| 90 | |
| 91 | const char skipBefore[] = "http___health_com.skp"; |
| 92 | |
skia.committer@gmail.com | 2b34fe0 | 2013-05-08 07:01:40 +0000 | [diff] [blame] | 93 | static void PathOpsSkpClipTest(skiatest::Reporter* reporter) { |
skia.committer@gmail.com | 2b34fe0 | 2013-05-08 07:01:40 +0000 | [diff] [blame] | 94 | SkOSFile::Iter iter(pictDir, "skp"); |
| 95 | SkString filename; |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 96 | int testCount = 0; |
skia.committer@gmail.com | 2b34fe0 | 2013-05-08 07:01:40 +0000 | [diff] [blame] | 97 | while (iter.next(&filename)) { |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 98 | if (strcmp(filename.c_str(), skipBefore) < 0) { |
skia.committer@gmail.com | 2b34fe0 | 2013-05-08 07:01:40 +0000 | [diff] [blame] | 99 | continue; |
| 100 | } |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 101 | testOne(filename); |
| 102 | if (reporter->verbose()) { |
| 103 | SkDebugf("."); |
| 104 | if (++testCount % 100 == 0) { |
| 105 | SkDebugf("\n"); |
| 106 | } |
skia.committer@gmail.com | 2b34fe0 | 2013-05-08 07:01:40 +0000 | [diff] [blame] | 107 | } |
skia.committer@gmail.com | 2b34fe0 | 2013-05-08 07:01:40 +0000 | [diff] [blame] | 108 | reporter->bumpTestCount(); |
| 109 | } |
| 110 | } |
| 111 | |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 112 | static void testSkpClipMain(PathOpsThreadState* data) { |
| 113 | SkString str(data->fSerialNo); |
| 114 | testOne(str); |
| 115 | if (data->fReporter->verbose()) { |
| 116 | SkDebugf("."); |
| 117 | static int threadTestCount; |
| 118 | sk_atomic_inc(&threadTestCount); |
| 119 | if (threadTestCount % 100 == 0) { |
| 120 | SkDebugf("\n"); |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | static void PathOpsSkpClipThreadedTest(skiatest::Reporter* reporter) { |
| 126 | int threadCount = initializeTests(reporter, "skpClipThreadedTest"); |
| 127 | PathOpsThreadedTestRunner testRunner(reporter, threadCount); |
| 128 | SkOSFile::Iter iter(pictDir, "skp"); |
| 129 | SkString filename; |
| 130 | while (iter.next(&filename)) { |
| 131 | if (strcmp(filename.c_str(), skipBefore) < 0) { |
| 132 | continue; |
| 133 | } |
| 134 | *testRunner.fRunnables.append() = SkNEW_ARGS(PathOpsThreadedRunnable, |
| 135 | (&testSkpClipMain, filename.c_str(), &testRunner)); |
| 136 | reporter->bumpTestCount(); |
| 137 | } |
| 138 | testRunner.render(); |
| 139 | } |
| 140 | |
| 141 | static void PathOpsSkpClipTestOne(skiatest::Reporter* reporter) { |
| 142 | SkString filename(skipBefore); |
| 143 | testOne(filename); |
| 144 | } |
| 145 | |
skia.committer@gmail.com | 2b34fe0 | 2013-05-08 07:01:40 +0000 | [diff] [blame] | 146 | #include "TestClassDef.h" |
| 147 | DEFINE_TESTCLASS_SHORT(PathOpsSkpClipTest) |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 148 | |
| 149 | DEFINE_TESTCLASS_SHORT(PathOpsSkpClipTestOne) |
| 150 | |
| 151 | DEFINE_TESTCLASS_SHORT(PathOpsSkpClipThreadedTest) |