PathOpsSkpClipTest.cpp revision 7eaa53d8f7e48fd17d02b5e3bd91f90e9c1899ef
1#include "PathOpsExtendedTest.h" 2#include "PathOpsThreadedCommon.h" 3#include "SkBitmap.h" 4#include "SkColor.h" 5#include "SkDevice.h" 6#include "SkCanvas.h" 7#include "SkImageDecoder.h" 8#include "SkImageEncoder.h" 9#include "SkStream.h" 10#include "SkOSFile.h" 11#include "SkPicture.h" 12#include "SkString.h" 13 14#ifdef SK_BUILD_FOR_WIN 15 #define PATH_SLASH "\\" 16 #define IN_DIR "D:" PATH_SLASH "skp" 17 #define OUT_DIR "D:" PATH_SLASH 18#else 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 27#endif 28 29static const char pictDir[] = IN_DIR ; 30static const char outSkpClipDir[] = OUT_DIR "skpClip"; 31static const char outOldClipDir[] = OUT_DIR "oldClip"; 32 33static SkString make_filepath(const char* dir, const SkString& name) { 34 SkString path(dir); 35 size_t len = strlen(dir); 36 if (len > 0 && dir[len - 1] != PATH_SLASH[0]) { 37 path.append(PATH_SLASH); 38 } 39 path.append(name); 40 return path; 41} 42 43static 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; 48} 49 50static void testOne(const SkString& filename) { 51 if (filename == SkString("http___migracioncolombia_gov_co.skp") 52 || filename == SkString("http___miuki_info.skp") 53 ) { 54 return; 55 } 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 74 SkString path = make_filepath(pictDir, filename); 75 SkFILEStream stream(path.c_str()); 76 if (!stream.isValid()) { 77 return; 78 } 79 SkPicture* pic = SkPicture::CreateFromStream(&stream, &SkImageDecoder::DecodeMemory); 80 if (!pic) { 81 SkDebugf("unable to decode %s\n", filename.c_str()); 82 return; 83 } 84 int width = pic->width(); 85 int height = pic->height(); 86 87 SkBitmap bitmap; 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); 102 return; 103 } 104 SkCanvas canvas(bitmap); 105 canvas.scale(1.0f / scale, 1.0f / scale); 106 SkString pngName = make_png_name(filename); 107 for (int i = 0; i < 2; ++i) { 108 bool useOp = i ? true : false; 109 canvas.setAllowSimplifyClip(useOp); 110 pic->draw(&canvas); 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 } 117 } 118 SkDELETE(pic); 119} 120 121const char* tryFixed[] = { 122 0 123}; 124 125size_t tryFixedCount = sizeof(tryFixed) / sizeof(tryFixed[0]); 126 127const 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 184size_t skipOverCount = sizeof(skipOver) / sizeof(skipOver[0]); 185 186static void PathOpsSkpClipTest(skiatest::Reporter* reporter) { 187 SkOSFile::Iter iter(pictDir, "skp"); 188 SkString filename; 189 int testCount = 0; 190 while (iter.next(&filename)) { 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(); 196 continue; 197 } 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 } 204 testOne(filename); 205 if (reporter->verbose()) { 206 SkDebugf("."); 207 if (++testCount % 100 == 0) { 208 SkDebugf("%d\n", testCount); 209 } 210 } 211skipOver: 212 reporter->bumpTestCount(); 213 } 214} 215 216static void bumpCount(skiatest::Reporter* reporter, bool skipping) { 217 if (reporter->verbose()) { 218 static int threadTestCount; 219 if (!skipping) { 220 SkDebugf("."); 221 } 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 232static void testSkpClipMain(PathOpsThreadState* data) { 233 SkString str(data->fSerialNo); 234 testOne(str); 235 bumpCount(data->fReporter, false); 236 data->fReporter->bumpTestCount(); 237} 238 239static 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)) { 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); 250 continue; 251 } 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 } 258 *testRunner.fRunnables.append() = SkNEW_ARGS(PathOpsThreadedRunnable, 259 (&testSkpClipMain, filename.c_str(), &testRunner)); 260skipOver: 261 ; 262 } 263 testRunner.render(); 264} 265 266static 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 281static void PathOpsSkpClipOneOffTest(skiatest::Reporter* reporter) { 282 SkString filename("http___78_cn_.skp"); 283 testOne(filename); 284} 285 286#include "TestClassDef.h" 287DEFINE_TESTCLASS_SHORT(PathOpsSkpClipTest) 288 289DEFINE_TESTCLASS_SHORT(PathOpsSkpClipFixedTest) 290 291DEFINE_TESTCLASS_SHORT(PathOpsSkpClipOneOffTest) 292 293DEFINE_TESTCLASS_SHORT(PathOpsSkpClipThreadedTest) 294