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" |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 4 | #include "SkColor.h" |
skia.committer@gmail.com | 2b34fe0 | 2013-05-08 07:01:40 +0000 | [diff] [blame] | 5 | #include "SkDevice.h" |
| 6 | #include "SkCanvas.h" |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 7 | #include "SkImageDecoder.h" |
skia.committer@gmail.com | 2b34fe0 | 2013-05-08 07:01:40 +0000 | [diff] [blame] | 8 | #include "SkImageEncoder.h" |
| 9 | #include "SkStream.h" |
| 10 | #include "SkOSFile.h" |
| 11 | #include "SkPicture.h" |
| 12 | #include "SkString.h" |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 13 | |
| 14 | #ifdef SK_BUILD_FOR_WIN |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 15 | #define PATH_SLASH "\\" |
| 16 | #define IN_DIR "D:" PATH_SLASH "skp" |
| 17 | #define OUT_DIR "D:" PATH_SLASH |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 18 | #else |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 19 | #define PATH_SLASH "/" |
| 20 | #if 1 |
| 21 | #define IN_DIR "/usr/local/google/home/caryclark/new10k" PATH_SLASH |
| 22 | #define OUT_DIR "/usr/local/google/home/caryclark/out10k" PATH_SLASH |
| 23 | #else |
| 24 | #define IN_DIR "/usr/local/google/home/caryclark/6-18-13" PATH_SLASH |
| 25 | #define OUT_DIR "/usr/local/google/home/caryclark" PATH_SLASH |
| 26 | #endif |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 27 | #endif |
| 28 | |
| 29 | static const char pictDir[] = IN_DIR ; |
| 30 | static const char outSkpClipDir[] = OUT_DIR "skpClip"; |
| 31 | static const char outOldClipDir[] = OUT_DIR "oldClip"; |
skia.committer@gmail.com | 2b34fe0 | 2013-05-08 07:01:40 +0000 | [diff] [blame] | 32 | |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 33 | static SkString make_filepath(const char* dir, const SkString& name) { |
| 34 | SkString path(dir); |
skia.committer@gmail.com | 2b34fe0 | 2013-05-08 07:01:40 +0000 | [diff] [blame] | 35 | size_t len = strlen(dir); |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 36 | if (len > 0 && dir[len - 1] != PATH_SLASH[0]) { |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 37 | path.append(PATH_SLASH); |
skia.committer@gmail.com | 2b34fe0 | 2013-05-08 07:01:40 +0000 | [diff] [blame] | 38 | } |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 39 | path.append(name); |
| 40 | return path; |
| 41 | } |
| 42 | |
| 43 | static SkString make_png_name(const SkString& filename) { |
| 44 | SkString pngName = SkString(filename); |
| 45 | pngName.remove(pngName.size() - 3, 3); |
| 46 | pngName.append("png"); |
| 47 | return pngName; |
skia.committer@gmail.com | 2b34fe0 | 2013-05-08 07:01:40 +0000 | [diff] [blame] | 48 | } |
| 49 | |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 50 | static void testOne(const SkString& filename) { |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 51 | if (filename == SkString("http___migracioncolombia_gov_co.skp") |
| 52 | || filename == SkString("http___miuki_info.skp") |
| 53 | ) { |
| 54 | return; |
| 55 | } |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 56 | #if DEBUG_SHOW_TEST_NAME |
| 57 | SkString testName(filename); |
| 58 | const char http[] = "http"; |
| 59 | if (testName.startsWith(http)) { |
| 60 | testName.remove(0, sizeof(http) - 1); |
| 61 | } |
| 62 | while (testName.startsWith("_")) { |
| 63 | testName.remove(0, 1); |
| 64 | } |
| 65 | const char dotSkp[] = ".skp"; |
| 66 | if (testName.endsWith(dotSkp)) { |
| 67 | size_t len = testName.size(); |
| 68 | testName.remove(len - (sizeof(dotSkp) - 1), sizeof(dotSkp) - 1); |
| 69 | } |
| 70 | testName.prepend("skp"); |
| 71 | testName.append("1"); |
| 72 | strncpy(DEBUG_FILENAME_STRING, testName.c_str(), DEBUG_FILENAME_STRING_LENGTH); |
| 73 | #endif |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 74 | SkString path = make_filepath(pictDir, filename); |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 75 | SkFILEStream stream(path.c_str()); |
| 76 | if (!stream.isValid()) { |
| 77 | return; |
| 78 | } |
caryclark@google.com | 4fdbb22 | 2013-07-23 15:27:41 +0000 | [diff] [blame] | 79 | SkPicture* pic = SkPicture::CreateFromStream(&stream, &SkImageDecoder::DecodeMemory); |
| 80 | if (!pic) { |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 81 | SkDebugf("unable to decode %s\n", filename.c_str()); |
| 82 | return; |
| 83 | } |
| 84 | int width = pic->width(); |
| 85 | int height = pic->height(); |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 86 | |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 87 | SkBitmap bitmap; |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 88 | int scale = 1; |
| 89 | do { |
| 90 | bitmap.setConfig(SkBitmap::kARGB_8888_Config, (width + scale - 1) / scale, |
| 91 | (height + scale - 1) / scale); |
| 92 | bool success = bitmap.allocPixels(); |
| 93 | bitmap.eraseColor(SK_ColorWHITE); |
| 94 | if (success) { |
| 95 | break; |
| 96 | } |
| 97 | SkDebugf("-%d-", scale); |
| 98 | } while ((scale *= 2) < 32); |
| 99 | if (scale >= 32) { |
| 100 | SkDebugf("unable to allocate bitmap for %s (w=%d h=%d)\n", filename.c_str(), |
| 101 | width, height); |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 102 | return; |
| 103 | } |
| 104 | SkCanvas canvas(bitmap); |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 105 | canvas.scale(1.0f / scale, 1.0f / scale); |
| 106 | SkString pngName = make_png_name(filename); |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 107 | for (int i = 0; i < 2; ++i) { |
| 108 | bool useOp = i ? true : false; |
| 109 | canvas.setAllowSimplifyClip(useOp); |
| 110 | pic->draw(&canvas); |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 111 | SkString outFile = make_filepath(useOp ? outSkpClipDir : outOldClipDir, pngName); |
| 112 | if (!SkImageEncoder::EncodeFile(outFile.c_str(), bitmap, SkImageEncoder::kPNG_Type, |
| 113 | 100)) { |
| 114 | SkDebugf("unable to encode %s (width=%d height=%d)\n", pngName.c_str(), |
| 115 | bitmap.width(), bitmap.height()); |
| 116 | } |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 117 | } |
| 118 | SkDELETE(pic); |
| 119 | } |
| 120 | |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 121 | const char* tryFixed[] = { |
| 122 | 0 |
| 123 | }; |
| 124 | |
| 125 | size_t tryFixedCount = sizeof(tryFixed) / sizeof(tryFixed[0]); |
| 126 | |
| 127 | const char* skipOver[] = { |
| 128 | "http___carpetplanet_ru.skp", // cubic/cubic intersect |
| 129 | "http___carrot_is.skp", // bridgeOp() SkASSERT(unsortable || !current->done()); |
| 130 | |
| 131 | /*!*/"http___dotsrc_org.skp", // asserts in png decode |
| 132 | "http___frauen_magazin_com.skp", // bridgeOp() SkASSERT(unsortable || !current->done()); |
| 133 | "http___i_gino_com.skp", // unexpected cubic/quad coincidence |
| 134 | // {61, 857, 61, 789.06897, 116.068977, 734, 184, 734} |
| 135 | // {184, 734, 133.051727, 734, 97.0258636, 770.025879} |
| 136 | "http___ilkoora_com.skp", // assert wind sum != min32 from markDoneBinary / findNextOp #28k |
| 137 | /*!*/"http___migracioncolombia_gov_co.skp", // crashes on picture decode |
| 138 | "http___mm4everfriends_com.skp", // bumpSpan/addTCoincident (from calcPartialCoincidentWinding) |
| 139 | "http___mtrk_uz.skp", // checkEnds() assert #36.3k |
| 140 | "http___pchappy_com_au.skp", // bridgeOp() assert unsortable || ! empty #37.2k |
| 141 | "http___sciality_com.skp", // bridgeOp() SkASSERT(unsortable || !current->done()); #32.4k |
| 142 | /*!*/"http___sozialticker_com.skp", // asserts in png decode |
| 143 | "http___sudoestenegocios_com.skp", // assert fT < 1 in addTCoincident |
| 144 | "http___thesuburbanite_com.skp", // bridgeOp() SkASSERT(unsortable || !current->done()); |
| 145 | |
| 146 | "http___fluentin3months_com.skp", // calcCommonCoincidentWinding from calcPartialCoincidentWinding #38.3k |
| 147 | "http___teachersbadi_blogspot_in.skp", // calcCommonCoincidentWinding from calcPartialCoincidentWinding #53.4k |
| 148 | "http___wsms_ru.skp", // assert wind sum != min32 from markDoneBinary / findNextOp #49.5k |
| 149 | "http___voycer_de.skp", // calcCommonCoincidentWinding from calcPartialCoincidentWinding #47k |
| 150 | "http___77hz_jp.skp", // addTCancel from calcCoincidentWinding #47.1k |
| 151 | |
| 152 | "http___hostloco_com.skp", // t < 0 AddIntersectsT |
| 153 | /*!*/"http___oggicronaca_it.skp", // asserts in png decode |
| 154 | "http___sergeychunkevich_com.skp", // t < 0 AddIntersectsT |
| 155 | "http___tracksflow_com.skp", // assert otherEnd >= 0 from nextChase |
| 156 | "http___autobutler_dk.skp", // t < 0 AddIntersectsT |
| 157 | "http___onlinecollege_org.skp", // bridgeOp() assert unsortable || ! empty #100.1k |
| 158 | "http___national_com_au.skp", // bridgeOp() assert unsortable || ! empty #110.2k |
| 159 | /*!*/"http___anitadongre_com.skp", // exceptionally large width and height |
| 160 | "http___rentacheat_com.skp", // bridgeOp() assert unsortable || ! empty #110.8k |
| 161 | /*!*/"http___gruesse_de.skp", // asserts in png decode |
| 162 | /*!*/"http___crn_in.png", // width=1250047 |
| 163 | "http___breakmystyle_com.skp", // assert qPt == lPt in quad intersection |
| 164 | "http___naoxrane_ru.skp", // assert t4+...t0 == 0 in quartic roots #128.3k |
| 165 | "http___tcmevents_org.skp", // assert in addTCoincident (from calcPartialCoincidentWinding) #143.3k |
| 166 | /*!*/"http___listbuildingcashsecrets_com.skp", // asserts in png decode #152.7k |
| 167 | /*!*/"http___skyscraperpage_com.skp", // asserts in png decode #155.5k |
| 168 | "http___mlk_com.skp", // bridgeOp() assert unsortable || ! empty #158.7k |
| 169 | "http___sd_graphic_net.skp", // bridgeOp() assert unsortable || ! empty #163.3k |
| 170 | "http___kopepasah_com.skp", // checkEnds() assert #188.2k |
| 171 | /*!*/"http___darkreloaded_com.skp", // asserts in png decode #188.4k |
| 172 | "http___redbullskatearcade_es.skp", // bridgeOp() assert unsortable || ! empty #192.5k |
| 173 | "http___partainasdemo250_org.skp", // bridgeOp() assert unsortable || ! empty #200.2k |
| 174 | |
| 175 | // these failures are from the new 10k set |
| 176 | "http___www_freerepublic_com_.skp", // assert in opangle < |
| 177 | "http___www_lavoixdunord_fr_.skp", // bridgeOp() assert unsortable || ! empty |
| 178 | "http___www_booking_com_.skp", // bridgeOp() assert unsortable || ! empty |
| 179 | "http___www_fj_p_com_.skp", // markWinding assert from findChaseOp |
| 180 | "http___www_leadpages_net_.skp", // assert in opangle < |
| 181 | "http___www_despegar_com_mx_.skp", // bridgeOp() assert unsortable || ! empty |
| 182 | }; |
| 183 | |
| 184 | size_t skipOverCount = sizeof(skipOver) / sizeof(skipOver[0]); |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 185 | |
skia.committer@gmail.com | 2b34fe0 | 2013-05-08 07:01:40 +0000 | [diff] [blame] | 186 | static void PathOpsSkpClipTest(skiatest::Reporter* reporter) { |
skia.committer@gmail.com | 2b34fe0 | 2013-05-08 07:01:40 +0000 | [diff] [blame] | 187 | SkOSFile::Iter iter(pictDir, "skp"); |
| 188 | SkString filename; |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 189 | int testCount = 0; |
skia.committer@gmail.com | 2b34fe0 | 2013-05-08 07:01:40 +0000 | [diff] [blame] | 190 | while (iter.next(&filename)) { |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 191 | SkString pngName = make_png_name(filename); |
| 192 | SkString oldPng = make_filepath(outOldClipDir, pngName); |
| 193 | SkString newPng = make_filepath(outSkpClipDir, pngName); |
| 194 | if (sk_exists(oldPng.c_str()) && sk_exists(newPng.c_str())) { |
| 195 | reporter->bumpTestCount(); |
skia.committer@gmail.com | 2b34fe0 | 2013-05-08 07:01:40 +0000 | [diff] [blame] | 196 | continue; |
| 197 | } |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 198 | for (size_t index = 0; index < skipOverCount; ++index) { |
| 199 | if (skipOver[index] && strcmp(filename.c_str(), skipOver[index]) == 0) { |
| 200 | reporter->bumpTestCount(); |
| 201 | goto skipOver; |
| 202 | } |
| 203 | } |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 204 | testOne(filename); |
| 205 | if (reporter->verbose()) { |
| 206 | SkDebugf("."); |
| 207 | if (++testCount % 100 == 0) { |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 208 | SkDebugf("%d\n", testCount); |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 209 | } |
skia.committer@gmail.com | 2b34fe0 | 2013-05-08 07:01:40 +0000 | [diff] [blame] | 210 | } |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 211 | skipOver: |
skia.committer@gmail.com | 2b34fe0 | 2013-05-08 07:01:40 +0000 | [diff] [blame] | 212 | reporter->bumpTestCount(); |
| 213 | } |
| 214 | } |
| 215 | |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 216 | static void bumpCount(skiatest::Reporter* reporter, bool skipping) { |
| 217 | if (reporter->verbose()) { |
| 218 | static int threadTestCount; |
| 219 | if (!skipping) { |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 220 | SkDebugf("."); |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 221 | } |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 222 | sk_atomic_inc(&threadTestCount); |
| 223 | if (!skipping && threadTestCount % 100 == 0) { |
| 224 | SkDebugf("%d\n", threadTestCount); |
| 225 | } |
| 226 | if (skipping && threadTestCount % 10000 == 0) { |
| 227 | SkDebugf("%d\n", threadTestCount); |
| 228 | } |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | static void testSkpClipMain(PathOpsThreadState* data) { |
| 233 | SkString str(data->fSerialNo); |
| 234 | testOne(str); |
| 235 | bumpCount(data->fReporter, false); |
| 236 | data->fReporter->bumpTestCount(); |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | static void PathOpsSkpClipThreadedTest(skiatest::Reporter* reporter) { |
| 240 | int threadCount = initializeTests(reporter, "skpClipThreadedTest"); |
| 241 | PathOpsThreadedTestRunner testRunner(reporter, threadCount); |
| 242 | SkOSFile::Iter iter(pictDir, "skp"); |
| 243 | SkString filename; |
| 244 | while (iter.next(&filename)) { |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 245 | SkString pngName = make_png_name(filename); |
| 246 | SkString oldPng = make_filepath(outOldClipDir, pngName); |
| 247 | SkString newPng = make_filepath(outSkpClipDir, pngName); |
| 248 | if (sk_exists(oldPng.c_str()) && sk_exists(newPng.c_str())) { |
| 249 | bumpCount(reporter, true); |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 250 | continue; |
| 251 | } |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 252 | for (size_t index = 0; index < skipOverCount; ++index) { |
| 253 | if (skipOver[index] && strcmp(filename.c_str(), skipOver[index]) == 0) { |
| 254 | bumpCount(reporter, true); |
| 255 | goto skipOver; |
| 256 | } |
| 257 | } |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 258 | *testRunner.fRunnables.append() = SkNEW_ARGS(PathOpsThreadedRunnable, |
| 259 | (&testSkpClipMain, filename.c_str(), &testRunner)); |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 260 | skipOver: |
| 261 | ; |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 262 | } |
| 263 | testRunner.render(); |
| 264 | } |
| 265 | |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 266 | static void PathOpsSkpClipFixedTest(skiatest::Reporter* reporter) { |
| 267 | for (size_t index = 0; index < tryFixedCount; ) { |
| 268 | SkString filename(tryFixed[index]); |
| 269 | testOne(filename); |
| 270 | ++index; |
| 271 | if (reporter->verbose()) { |
| 272 | SkDebugf("."); |
| 273 | if (index % 100 == 0) { |
| 274 | SkDebugf("\n"); |
| 275 | } |
| 276 | } |
| 277 | reporter->bumpTestCount(); |
| 278 | } |
| 279 | } |
| 280 | |
caryclark@google.com | fa2aeee | 2013-07-15 13:29:13 +0000 | [diff] [blame] | 281 | static void PathOpsSkpClipOneOffTest(skiatest::Reporter* reporter) { |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 282 | SkString filename("http___78_cn_.skp"); |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 283 | testOne(filename); |
| 284 | } |
| 285 | |
skia.committer@gmail.com | 2b34fe0 | 2013-05-08 07:01:40 +0000 | [diff] [blame] | 286 | #include "TestClassDef.h" |
| 287 | DEFINE_TESTCLASS_SHORT(PathOpsSkpClipTest) |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 288 | |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 289 | DEFINE_TESTCLASS_SHORT(PathOpsSkpClipFixedTest) |
| 290 | |
caryclark@google.com | fa2aeee | 2013-07-15 13:29:13 +0000 | [diff] [blame] | 291 | DEFINE_TESTCLASS_SHORT(PathOpsSkpClipOneOffTest) |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 292 | |
| 293 | DEFINE_TESTCLASS_SHORT(PathOpsSkpClipThreadedTest) |