OLD | NEW |
1 #include "PathOpsExtendedTest.h" | 1 |
2 #include "PathOpsThreadedCommon.h" | |
3 #include "SkBitmap.h" | 2 #include "SkBitmap.h" |
| 3 #include "SkCanvas.h" |
4 #include "SkColor.h" | 4 #include "SkColor.h" |
| 5 #include "SkColorPriv.h" |
5 #include "SkDevice.h" | 6 #include "SkDevice.h" |
6 #include "SkCanvas.h" | 7 #include "SkGraphics.h" |
7 #include "SkImageDecoder.h" | 8 #include "SkImageDecoder.h" |
8 #include "SkImageEncoder.h" | 9 #include "SkImageEncoder.h" |
| 10 #include "SkOSFile.h" |
| 11 #include "SkPathOpsDebug.h" |
| 12 #include "SkPicture.h" |
| 13 #include "SkRTConf.h" |
9 #include "SkStream.h" | 14 #include "SkStream.h" |
10 #include "SkOSFile.h" | |
11 #include "SkPicture.h" | |
12 #include "SkString.h" | 15 #include "SkString.h" |
| 16 #include "SkTArray.h" |
| 17 #include "SkTDArray.h" |
| 18 #include "SkThreadPool.h" |
| 19 #include "SkTime.h" |
| 20 #include "Test.h" |
13 | 21 |
14 #ifdef SK_BUILD_FOR_WIN | 22 #ifdef SK_BUILD_FOR_WIN |
15 #define PATH_SLASH "\\" | 23 #define PATH_SLASH "\\" |
16 #define IN_DIR "D:" PATH_SLASH "skp" | 24 #define IN_DIR "D:" PATH_SLASH "skp" |
17 #define OUT_DIR "D:" PATH_SLASH | 25 #define OUT_DIR "D:" PATH_SLASH |
18 #else | 26 #else |
19 #define PATH_SLASH "/" | 27 #define PATH_SLASH "/" |
20 #if 1 | 28 #ifdef SK_BUILD_FOR_MAC |
21 #define IN_DIR "/usr/local/google/home/caryclark/new10k" PATH_SLASH | 29 #define IN_DIR "/Volumes/tera/9-30-13/skp" |
22 #define OUT_DIR "/usr/local/google/home/caryclark/out10k" PATH_SLASH | 30 #define OUT_DIR "/Volumes/tera/out/9-30-13/1/" |
23 #else | 31 #else |
24 #define IN_DIR "/usr/local/google/home/caryclark/6-18-13" PATH_SLASH | 32 #define IN_DIR "/usr/local/google/home/caryclark/skps/9-30-13/skp" |
25 #define OUT_DIR "/usr/local/google/home/caryclark" PATH_SLASH | 33 #define OUT_DIR "/mnt/skia/opSkpClip/1/" |
26 #endif | 34 #endif |
27 #endif | 35 #endif |
28 | 36 |
29 static const char pictDir[] = IN_DIR ; | 37 const struct { |
30 static const char outSkpClipDir[] = OUT_DIR "skpClip"; | 38 int directory; |
31 static const char outOldClipDir[] = OUT_DIR "oldClip"; | 39 const char* filename; |
| 40 } skipOverSept[] = { |
| 41 {9, "http___www_symptome_ch_.skp"}, // triangle clip with corner at x.999 |
| 42 {11, "http___www_menly_fr_.skp"}, |
| 43 }; |
32 | 44 |
33 static SkString make_filepath(const char* dir, const SkString& name) { | 45 size_t skipOverSeptCount = sizeof(skipOverSept) / sizeof(skipOverSept[0]); |
| 46 |
| 47 enum TestStep { |
| 48 kCompareBits, |
| 49 kEncodeFiles, |
| 50 }; |
| 51 |
| 52 enum { |
| 53 kMaxLength = 128, |
| 54 kMaxFiles = 128, |
| 55 kSmallLimit = 1000, |
| 56 }; |
| 57 |
| 58 struct TestResult { |
| 59 void init(int dirNo) { |
| 60 fDirNo = dirNo; |
| 61 sk_bzero(fFilename, sizeof(fFilename)); |
| 62 fTestStep = kCompareBits; |
| 63 fScaleOversized = true; |
| 64 } |
| 65 |
| 66 SkString status() { |
| 67 SkString outStr; |
| 68 outStr.printf("%s %d %d\n", fFilename, fPixelError, fTime); |
| 69 return outStr; |
| 70 } |
| 71 |
| 72 static void Test(int dirNo, const char* filename, TestStep testStep) { |
| 73 TestResult test; |
| 74 test.init(dirNo); |
| 75 test.fTestStep = testStep; |
| 76 strcpy(test.fFilename, filename); |
| 77 test.testOne(); |
| 78 } |
| 79 |
| 80 void test(int dirNo, const SkString& filename) { |
| 81 init(dirNo); |
| 82 strcpy(fFilename, filename.c_str()); |
| 83 testOne(); |
| 84 } |
| 85 |
| 86 void testOne(); |
| 87 |
| 88 char fFilename[kMaxLength]; |
| 89 TestStep fTestStep; |
| 90 int fDirNo; |
| 91 int fPixelError; |
| 92 int fTime; |
| 93 bool fScaleOversized; |
| 94 }; |
| 95 |
| 96 struct TestState { |
| 97 void init(int dirNo, skiatest::Reporter* reporter) { |
| 98 fReporter = reporter; |
| 99 fResult.init(dirNo); |
| 100 fFoundCount = 0; |
| 101 TestState::fSmallCount = 0; |
| 102 fSmallestError = 0; |
| 103 sk_bzero(fFilesFound, sizeof(fFilesFound)); |
| 104 sk_bzero(fDirsFound, sizeof(fDirsFound)); |
| 105 sk_bzero(fError, sizeof(fError)); |
| 106 } |
| 107 |
| 108 static bool bumpSmallCount() { |
| 109 sk_atomic_inc(&fSmallCount); |
| 110 return fSmallCount > kSmallLimit; |
| 111 } |
| 112 |
| 113 static void clearSmallCount() { |
| 114 if (fSmallCount < kSmallLimit) { |
| 115 fSmallCount = 0; |
| 116 } |
| 117 } |
| 118 |
| 119 char fFilesFound[kMaxFiles][kMaxLength]; |
| 120 int fDirsFound[kMaxFiles]; |
| 121 int fError[kMaxFiles]; |
| 122 int fFoundCount; |
| 123 static int fSmallCount; |
| 124 int fSmallestError; |
| 125 skiatest::Reporter* fReporter; |
| 126 TestResult fResult; |
| 127 }; |
| 128 |
| 129 int TestState::fSmallCount; |
| 130 |
| 131 struct TestRunner { |
| 132 TestRunner(skiatest::Reporter* reporter, int threadCount) |
| 133 : fNumThreads(threadCount) |
| 134 , fReporter(reporter) { |
| 135 } |
| 136 |
| 137 ~TestRunner(); |
| 138 void render(); |
| 139 int fNumThreads; |
| 140 SkTDArray<class TestRunnable*> fRunnables; |
| 141 skiatest::Reporter* fReporter; |
| 142 }; |
| 143 |
| 144 class TestRunnable : public SkRunnable { |
| 145 public: |
| 146 TestRunnable(void (*testFun)(TestState*), int dirNo, TestRunner* runner) { |
| 147 fState.init(dirNo, runner->fReporter); |
| 148 fTestFun = testFun; |
| 149 } |
| 150 |
| 151 virtual void run() SK_OVERRIDE { |
| 152 SkGraphics::SetTLSFontCacheLimit(1 * 1024 * 1024); |
| 153 (*fTestFun)(&fState); |
| 154 } |
| 155 |
| 156 TestState fState; |
| 157 void (*fTestFun)(TestState*); |
| 158 }; |
| 159 |
| 160 TestRunner::~TestRunner() { |
| 161 for (int index = 0; index < fRunnables.count(); index++) { |
| 162 SkDELETE(fRunnables[index]); |
| 163 } |
| 164 } |
| 165 |
| 166 void TestRunner::render() { |
| 167 SkThreadPool pool(fNumThreads); |
| 168 for (int index = 0; index < fRunnables.count(); ++ index) { |
| 169 pool.add(fRunnables[index]); |
| 170 } |
| 171 } |
| 172 |
| 173 //////////////////////////////////////////////// |
| 174 |
| 175 static const char outOpDir[] = OUT_DIR "opClip"; |
| 176 static const char outOldDir[] = OUT_DIR "oldClip"; |
| 177 static const char outSkpDir[] = OUT_DIR "skpTest"; |
| 178 static const char outDiffDir[] = OUT_DIR "outTest"; |
| 179 static const char outStatusDir[] = OUT_DIR "statusTest"; |
| 180 |
| 181 static SkString make_filepath(int dirNo, const char* dir, const char* name) { |
34 SkString path(dir); | 182 SkString path(dir); |
| 183 if (dirNo) { |
| 184 path.appendf("%d", dirNo); |
| 185 } |
35 size_t len = strlen(dir); | 186 size_t len = strlen(dir); |
36 if (len > 0 && dir[len - 1] != PATH_SLASH[0]) { | 187 if (len > 0 && dir[len - 1] != PATH_SLASH[0]) { |
37 path.append(PATH_SLASH); | 188 path.append(PATH_SLASH); |
38 } | 189 } |
39 path.append(name); | 190 path.append(name); |
40 return path; | 191 return path; |
41 } | 192 } |
42 | 193 |
43 static SkString make_png_name(const SkString& filename) { | 194 static SkString make_in_dir_name(int dirNo) { |
| 195 SkString dirName(IN_DIR); |
| 196 dirName.appendf("%d", dirNo); |
| 197 if (!sk_exists(dirName.c_str())) { |
| 198 SkDebugf("could not read dir %s\n", dirName.c_str()); |
| 199 return SkString(); |
| 200 } |
| 201 return dirName; |
| 202 } |
| 203 |
| 204 static bool make_one_out_dir(const char* outDirStr) { |
| 205 SkString outDir = make_filepath(0, outDirStr, ""); |
| 206 if (!sk_exists(outDir.c_str())) { |
| 207 if (!sk_mkdir(outDir.c_str())) { |
| 208 SkDebugf("could not create dir %s\n", outDir.c_str()); |
| 209 return false; |
| 210 } |
| 211 } |
| 212 return true; |
| 213 } |
| 214 |
| 215 static bool make_out_dirs() { |
| 216 SkString outDir = make_filepath(0, OUT_DIR, ""); |
| 217 if (!sk_exists(outDir.c_str())) { |
| 218 if (!sk_mkdir(outDir.c_str())) { |
| 219 SkDebugf("could not create dir %s\n", outDir.c_str()); |
| 220 return false; |
| 221 } |
| 222 } |
| 223 return make_one_out_dir(outOldDir) |
| 224 && make_one_out_dir(outOpDir) |
| 225 && make_one_out_dir(outSkpDir) |
| 226 && make_one_out_dir(outDiffDir) |
| 227 && make_one_out_dir(outStatusDir); |
| 228 } |
| 229 |
| 230 static SkString make_png_name(const char* filename) { |
44 SkString pngName = SkString(filename); | 231 SkString pngName = SkString(filename); |
45 pngName.remove(pngName.size() - 3, 3); | 232 pngName.remove(pngName.size() - 3, 3); |
46 pngName.append("png"); | 233 pngName.append("png"); |
47 return pngName; | 234 return pngName; |
48 } | 235 } |
49 | 236 |
50 static void testOne(const SkString& filename) { | 237 static int similarBits(const SkBitmap& gr, const SkBitmap& sk) { |
51 if (filename == SkString("http___migracioncolombia_gov_co.skp") | 238 const int kRowCount = 3; |
52 || filename == SkString("http___miuki_info.skp") | 239 const int kThreshold = 3; |
53 ) { | 240 int width = SkTMin(gr.width(), sk.width()); |
54 return; | 241 if (width < kRowCount) { |
55 } | 242 return true; |
56 #if DEBUG_SHOW_TEST_NAME | 243 } |
57 SkString testName(filename); | 244 int height = SkTMin(gr.height(), sk.height()); |
58 const char http[] = "http"; | 245 if (height < kRowCount) { |
59 if (testName.startsWith(http)) { | 246 return true; |
60 testName.remove(0, sizeof(http) - 1); | 247 } |
61 } | 248 int errorTotal = 0; |
62 while (testName.startsWith("_")) { | 249 SkTArray<int, true> errorRows; |
63 testName.remove(0, 1); | 250 errorRows.push_back_n(width * kRowCount); |
64 } | 251 SkAutoLockPixels autoGr(gr); |
65 const char dotSkp[] = ".skp"; | 252 SkAutoLockPixels autoSk(sk); |
66 if (testName.endsWith(dotSkp)) { | 253 for (int y = 0; y < height; ++y) { |
67 size_t len = testName.size(); | 254 SkPMColor* grRow = gr.getAddr32(0, y); |
68 testName.remove(len - (sizeof(dotSkp) - 1), sizeof(dotSkp) - 1); | 255 SkPMColor* skRow = sk.getAddr32(0, y); |
69 } | 256 int* base = &errorRows[0]; |
70 testName.prepend("skp"); | 257 int* cOut = &errorRows[y % kRowCount]; |
71 testName.append("1"); | 258 for (int x = 0; x < width; ++x) { |
72 strncpy(DEBUG_FILENAME_STRING, testName.c_str(), DEBUG_FILENAME_STRING_LENGT
H); | 259 SkPMColor grColor = grRow[x]; |
73 #endif | 260 SkPMColor skColor = skRow[x]; |
74 SkString path = make_filepath(pictDir, filename); | 261 int dr = SkGetPackedR32(grColor) - SkGetPackedR32(skColor); |
75 SkFILEStream stream(path.c_str()); | 262 int dg = SkGetPackedG32(grColor) - SkGetPackedG32(skColor); |
76 if (!stream.isValid()) { | 263 int db = SkGetPackedB32(grColor) - SkGetPackedB32(skColor); |
77 return; | 264 int error = cOut[x] = SkTMax(SkAbs32(dr), SkTMax(SkAbs32(dg), SkAbs3
2(db))); |
78 } | 265 if (error < kThreshold || x < 2) { |
79 SkPicture* pic = SkPicture::CreateFromStream(&stream, &SkImageDecoder::Decod
eMemory); | 266 continue; |
80 if (!pic) { | 267 } |
81 SkDebugf("unable to decode %s\n", filename.c_str()); | 268 if (base[x - 2] < kThreshold |
82 return; | 269 || base[width + x - 2] < kThreshold |
83 } | 270 || base[width * 2 + x - 2] < kThreshold |
84 int width = pic->width(); | 271 || base[x - 1] < kThreshold |
85 int height = pic->height(); | 272 || base[width + x - 1] < kThreshold |
86 | 273 || base[width * 2 + x - 1] < kThreshold |
87 SkBitmap bitmap; | 274 || base[x] < kThreshold |
88 int scale = 1; | 275 || base[width + x] < kThreshold |
89 do { | 276 || base[width * 2 + x] < kThreshold) { |
90 bitmap.setConfig(SkBitmap::kARGB_8888_Config, (width + scale - 1) / scal
e, | 277 continue; |
91 (height + scale - 1) / scale); | 278 } |
92 bool success = bitmap.allocPixels(); | 279 errorTotal += error; |
93 bitmap.eraseColor(SK_ColorWHITE); | 280 } |
94 if (success) { | 281 } |
95 break; | 282 return errorTotal; |
96 } | 283 } |
97 SkDebugf("-%d-", scale); | 284 |
98 } while ((scale *= 2) < 32); | 285 static bool addError(TestState* data, const TestResult& testResult) { |
99 if (scale >= 32) { | 286 bool foundSmaller = false; |
100 SkDebugf("unable to allocate bitmap for %s (w=%d h=%d)\n", filename.c_st
r(), | 287 int dCount = data->fFoundCount; |
101 width, height); | 288 int pixelError = testResult.fPixelError; |
102 return; | 289 if (data->fFoundCount < kMaxFiles) { |
103 } | 290 data->fError[dCount] = pixelError; |
104 SkCanvas canvas(bitmap); | 291 strcpy(data->fFilesFound[dCount], testResult.fFilename); |
105 canvas.scale(1.0f / scale, 1.0f / scale); | 292 data->fDirsFound[dCount] = testResult.fDirNo; |
106 SkString pngName = make_png_name(filename); | 293 ++data->fFoundCount; |
107 for (int i = 0; i < 2; ++i) { | 294 } else if (pixelError > data->fSmallestError) { |
108 bool useOp = i ? true : false; | 295 int smallest = SK_MaxS32; |
109 canvas.setAllowSimplifyClip(useOp); | 296 int smallestIndex = 0; |
110 pic->draw(&canvas); | 297 for (int index = 0; index < kMaxFiles; ++index) { |
111 SkString outFile = make_filepath(useOp ? outSkpClipDir : outOldClipDir,
pngName); | 298 if (smallest > data->fError[index]) { |
112 if (!SkImageEncoder::EncodeFile(outFile.c_str(), bitmap, SkImageEncoder:
:kPNG_Type, | 299 smallest = data->fError[index]; |
113 100)) { | 300 smallestIndex = index; |
114 SkDebugf("unable to encode %s (width=%d height=%d)\n", pngName.c_str
(), | 301 } |
115 bitmap.width(), bitmap.height()); | 302 } |
116 } | 303 data->fError[smallestIndex] = pixelError; |
117 } | 304 strcpy(data->fFilesFound[smallestIndex], testResult.fFilename); |
| 305 data->fDirsFound[smallestIndex] = testResult.fDirNo; |
| 306 data->fSmallestError = SK_MaxS32; |
| 307 for (int index = 0; index < kMaxFiles; ++index) { |
| 308 if (data->fSmallestError > data->fError[index]) { |
| 309 data->fSmallestError = data->fError[index]; |
| 310 } |
| 311 } |
| 312 SkDebugf("*%d*", data->fSmallestError); |
| 313 foundSmaller = true; |
| 314 } |
| 315 return foundSmaller; |
| 316 } |
| 317 |
| 318 |
| 319 |
| 320 static SkMSec timePict(SkPicture* pic, SkCanvas* canvas) { |
| 321 canvas->save(); |
| 322 int pWidth = pic->width(); |
| 323 int pHeight = pic->height(); |
| 324 const int maxDimension = 1000; |
| 325 const int slices = 3; |
| 326 int xInterval = SkTMax(pWidth - maxDimension, 0) / (slices - 1); |
| 327 int yInterval = SkTMax(pHeight - maxDimension, 0) / (slices - 1); |
| 328 SkRect rect = {0, 0, SkTMin(maxDimension, pWidth), SkTMin(maxDimension, pHei
ght)}; |
| 329 canvas->clipRect(rect); |
| 330 SkMSec start = SkTime::GetMSecs(); |
| 331 for (int x = 0; x < slices; ++x) { |
| 332 for (int y = 0; y < slices; ++y) { |
| 333 pic->draw(canvas); |
| 334 canvas->translate(0, yInterval); |
| 335 } |
| 336 canvas->translate(xInterval, -yInterval * slices); |
| 337 } |
| 338 SkMSec end = SkTime::GetMSecs(); |
| 339 canvas->restore(); |
| 340 return end - start; |
| 341 } |
| 342 |
| 343 static void drawPict(SkPicture* pic, SkCanvas* canvas, int scale) { |
| 344 canvas->clear(SK_ColorWHITE); |
| 345 if (scale != 1) { |
| 346 canvas->save(); |
| 347 canvas->scale(1.0f / scale, 1.0f / scale); |
| 348 } |
| 349 pic->draw(canvas); |
| 350 if (scale != 1) { |
| 351 canvas->restore(); |
| 352 } |
| 353 } |
| 354 |
| 355 static void writePict(const SkBitmap& bitmap, const char* outDir, const char* pn
gName) { |
| 356 SkString outFile = make_filepath(0, outDir, pngName); |
| 357 if (!SkImageEncoder::EncodeFile(outFile.c_str(), bitmap, |
| 358 SkImageEncoder::kPNG_Type, 100)) { |
| 359 SkDebugf("unable to encode gr %s (width=%d height=%d)\n", pngName, |
| 360 bitmap.width(), bitmap.height()); |
| 361 } |
| 362 } |
| 363 |
| 364 void TestResult::testOne() { |
| 365 SkPicture* pic = NULL; |
| 366 { |
| 367 #if DEBUG_SHOW_TEST_NAME |
| 368 if (fTestStep == kCompareBits) { |
| 369 SkString testName(fFilename); |
| 370 const char http[] = "http"; |
| 371 if (testName.startsWith(http)) { |
| 372 testName.remove(0, sizeof(http) - 1); |
| 373 } |
| 374 while (testName.startsWith("_")) { |
| 375 testName.remove(0, 1); |
| 376 } |
| 377 const char dotSkp[] = ".skp"; |
| 378 if (testName.endsWith(dotSkp)) { |
| 379 size_t len = testName.size(); |
| 380 testName.remove(len - (sizeof(dotSkp) - 1), sizeof(dotSkp) - 1); |
| 381 } |
| 382 testName.prepend("skp"); |
| 383 testName.append("1"); |
| 384 strncpy(DEBUG_FILENAME_STRING, testName.c_str(), DEBUG_FILENAME_STRI
NG_LENGTH); |
| 385 } else if (fTestStep == kEncodeFiles) { |
| 386 strncpy(DEBUG_FILENAME_STRING, "", DEBUG_FILENAME_STRING_LENGTH); |
| 387 } |
| 388 #endif |
| 389 SkString path = make_filepath(fDirNo, IN_DIR, fFilename); |
| 390 SkFILEStream stream(path.c_str()); |
| 391 if (!stream.isValid()) { |
| 392 SkDebugf("invalid stream %s\n", path.c_str()); |
| 393 goto finish; |
| 394 } |
| 395 SkPicture* pic = SkPicture::CreateFromStream(&stream, &SkImageDecoder::D
ecodeMemory); |
| 396 if (!pic) { |
| 397 SkDebugf("unable to decode %s\n", fFilename); |
| 398 goto finish; |
| 399 } |
| 400 int width = pic->width(); |
| 401 int height = pic->height(); |
| 402 SkBitmap oldBitmap, opBitmap; |
| 403 int scale = 1; |
| 404 do { |
| 405 int dimX = (width + scale - 1) / scale; |
| 406 int dimY = (height + scale - 1) / scale; |
| 407 oldBitmap.setConfig(SkBitmap::kARGB_8888_Config, dimX, dimY); |
| 408 opBitmap.setConfig(SkBitmap::kARGB_8888_Config, dimX, dimY); |
| 409 bool success = oldBitmap.allocPixels() && opBitmap.allocPixels(); |
| 410 if (success) { |
| 411 break; |
| 412 } |
| 413 SkDebugf("-%d-", scale); |
| 414 } while ((scale *= 2) < 256); |
| 415 if (scale >= 256) { |
| 416 SkDebugf("unable to allocate bitmap for %s (w=%d h=%d)\n", fFilename
, |
| 417 width, height); |
| 418 return; |
| 419 } |
| 420 oldBitmap.eraseColor(SK_ColorWHITE); |
| 421 SkCanvas oldCanvas(oldBitmap); |
| 422 oldCanvas.setAllowSimplifyClip(false); |
| 423 opBitmap.eraseColor(SK_ColorWHITE); |
| 424 SkCanvas opCanvas(opBitmap); |
| 425 opCanvas.setAllowSimplifyClip(true); |
| 426 drawPict(pic, &oldCanvas, fScaleOversized ? scale : 1); |
| 427 drawPict(pic, &opCanvas, fScaleOversized ? scale : 1); |
| 428 if (fTestStep == kCompareBits) { |
| 429 fPixelError = similarBits(oldBitmap, opBitmap); |
| 430 int oldTime = timePict(pic, &oldCanvas); |
| 431 int opTime = timePict(pic, &opCanvas); |
| 432 fTime = oldTime - opTime; |
| 433 } else if (fTestStep == kEncodeFiles) { |
| 434 SkString pngStr = make_png_name(fFilename); |
| 435 const char* pngName = pngStr.c_str(); |
| 436 writePict(oldBitmap, outOldDir, pngName); |
| 437 writePict(opBitmap, outOpDir, pngName); |
| 438 } |
| 439 } |
| 440 finish: |
118 SkDELETE(pic); | 441 SkDELETE(pic); |
119 } | 442 } |
120 | 443 |
121 const char* tryFixed[] = { | 444 static SkString makeStatusString(int dirNo) { |
122 0 | 445 SkString statName; |
| 446 statName.printf("stats%d.txt", dirNo); |
| 447 SkString statusFile = make_filepath(0, outStatusDir, statName.c_str()); |
| 448 return statusFile; |
| 449 } |
| 450 |
| 451 class PreParser { |
| 452 public: |
| 453 PreParser(int dirNo) |
| 454 : fDirNo(dirNo) |
| 455 , fIndex(0) { |
| 456 SkString statusPath = makeStatusString(dirNo); |
| 457 if (!sk_exists(statusPath.c_str())) { |
| 458 return; |
| 459 } |
| 460 SkFILEStream reader; |
| 461 reader.setPath(statusPath.c_str()); |
| 462 while (fetch(reader, &fResults.push_back())) |
| 463 ; |
| 464 fResults.pop_back(); |
| 465 } |
| 466 |
| 467 bool fetch(SkFILEStream& reader, TestResult* result) { |
| 468 char c; |
| 469 int i = 0; |
| 470 result->init(fDirNo); |
| 471 result->fPixelError = 0; |
| 472 result->fTime = 0; |
| 473 do { |
| 474 bool readOne = reader.read(&c, 1); |
| 475 if (!readOne) { |
| 476 SkASSERT(i == 0); |
| 477 return false; |
| 478 } |
| 479 if (c == ' ') { |
| 480 result->fFilename[i++] = '\0'; |
| 481 break; |
| 482 } |
| 483 result->fFilename[i++] = c; |
| 484 SkASSERT(i < kMaxLength); |
| 485 } while (true); |
| 486 do { |
| 487 SkAssertResult(reader.read(&c, 1)); |
| 488 if (c == ' ') { |
| 489 break; |
| 490 } |
| 491 SkASSERT(c >= '0' && c <= '9'); |
| 492 result->fPixelError = result->fPixelError * 10 + (c - '0'); |
| 493 } while (true); |
| 494 bool minus = false; |
| 495 do { |
| 496 SkAssertResult(reader.read(&c, 1)); |
| 497 if (c == '\n') { |
| 498 break; |
| 499 } |
| 500 if (c == '-') { |
| 501 minus = true; |
| 502 continue; |
| 503 } |
| 504 SkASSERT(c >= '0' && c <= '9'); |
| 505 result->fTime = result->fTime * 10 + (c - '0'); |
| 506 } while (true); |
| 507 if (minus) { |
| 508 result->fTime = -result->fTime; |
| 509 } |
| 510 return true; |
| 511 } |
| 512 |
| 513 bool match(const SkString& filename, SkFILEWStream* stream, TestResult* resu
lt) { |
| 514 if (fIndex < fResults.count()) { |
| 515 *result = fResults[fIndex++]; |
| 516 SkASSERT(filename.equals(result->fFilename)); |
| 517 SkString outStr(result->status()); |
| 518 stream->write(outStr.c_str(), outStr.size()); |
| 519 return true; |
| 520 } |
| 521 return false; |
| 522 } |
| 523 |
| 524 private: |
| 525 int fDirNo; |
| 526 int fIndex; |
| 527 SkTArray<TestResult, true> fResults; |
123 }; | 528 }; |
124 | 529 |
125 size_t tryFixedCount = sizeof(tryFixed) / sizeof(tryFixed[0]); | 530 static bool doOneDir(TestState* state) { |
126 | 531 int dirNo = state->fResult.fDirNo; |
127 const char* skipOver[] = { | 532 skiatest::Reporter* reporter = state->fReporter; |
128 "http___carpetplanet_ru.skp", // cubic/cubic intersect | 533 SkString dirName = make_in_dir_name(dirNo); |
129 "http___carrot_is.skp", // bridgeOp() SkASSERT(unsortable || !current->don
e()); | 534 SkASSERT(dirName.size()); |
130 | 535 SkOSFile::Iter iter(dirName.c_str(), "skp"); |
131 /*!*/"http___dotsrc_org.skp", // asserts in png decode | |
132 "http___frauen_magazin_com.skp", // bridgeOp() SkASSERT(unsortable || !cur
rent->done()); | |
133 "http___i_gino_com.skp", // unexpected cubic/quad coincidence | |
134 // {61, 857, 61, 789.06897, 116.068977, 734, 184, 73
4} | |
135 // {184, 734, 133.051727, 734, 97.0258636, 770.02587
9} | |
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 calcParti
alCoincidentWinding) | |
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 || !cur
rent->done()); | |
145 | |
146 "http___fluentin3months_com.skp", // calcCommonCoincidentWinding from calcPa
rtialCoincidentWinding #38.3k | |
147 "http___teachersbadi_blogspot_in.skp", // calcCommonCoincidentWinding from
calcPartialCoincidentWinding #53.4k | |
148 "http___wsms_ru.skp", // assert wind sum != min32 from markDoneBinary / fin
dNextOp #49.5k | |
149 "http___voycer_de.skp", // calcCommonCoincidentWinding from calcPartialCoin
cidentWinding #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 #1
10.2k | |
159 /*!*/"http___anitadongre_com.skp", // exceptionally large width and height | |
160 "http___rentacheat_com.skp", // bridgeOp() assert unsortable || ! empty #11
0.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 calcPartialCo
incidentWinding) #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 #16
3.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 || ! em
pty #192.5k | |
173 "http___partainasdemo250_org.skp", // bridgeOp() assert unsortable || ! em
pty #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 || ! emp
ty | |
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 || ! emp
ty | |
182 }; | |
183 | |
184 size_t skipOverCount = sizeof(skipOver) / sizeof(skipOver[0]); | |
185 | |
186 static void PathOpsSkpClipTest(skiatest::Reporter* reporter) { | |
187 SkOSFile::Iter iter(pictDir, "skp"); | |
188 SkString filename; | 536 SkString filename; |
189 int testCount = 0; | 537 int testCount = 0; |
| 538 PreParser preParser(dirNo); |
| 539 SkFILEWStream statusStream(makeStatusString(dirNo).c_str()); |
190 while (iter.next(&filename)) { | 540 while (iter.next(&filename)) { |
191 SkString pngName = make_png_name(filename); | 541 for (size_t index = 0; index < skipOverSeptCount; ++index) { |
192 SkString oldPng = make_filepath(outOldClipDir, pngName); | 542 if (skipOverSept[index].directory == dirNo |
193 SkString newPng = make_filepath(outSkpClipDir, pngName); | 543 && strcmp(filename.c_str(), skipOverSept[index].filename) ==
0) { |
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; | 544 goto skipOver; |
202 } | 545 } |
203 } | 546 } |
204 testOne(filename); | 547 if (preParser.match(filename, &statusStream, &state->fResult)) { |
| 548 addError(state, state->fResult); |
| 549 ++testCount; |
| 550 goto checkEarlyExit; |
| 551 } |
| 552 if (state->fSmallestError > 5000000) { |
| 553 return false; |
| 554 } |
| 555 { |
| 556 TestResult& result = state->fResult; |
| 557 result.test(dirNo, filename); |
| 558 SkString outStr(result.status()); |
| 559 statusStream.write(outStr.c_str(), outStr.size()); |
| 560 statusStream.flush(); |
| 561 if (1) { |
| 562 SkDebugf("%s", outStr.c_str()); |
| 563 } |
| 564 bool noMatch = addError(state, state->fResult); |
| 565 if (noMatch) { |
| 566 state->clearSmallCount(); |
| 567 } else if (state->bumpSmallCount()) { |
| 568 return false; |
| 569 } |
| 570 } |
| 571 ++testCount; |
205 if (reporter->verbose()) { | 572 if (reporter->verbose()) { |
206 SkDebugf("."); | 573 SkDebugf("."); |
207 if (++testCount % 100 == 0) { | 574 if (++testCount % 100 == 0) { |
208 SkDebugf("%d\n", testCount); | 575 SkDebugf("%d\n", testCount); |
209 } | 576 } |
210 } | 577 } |
211 skipOver: | 578 skipOver: |
212 reporter->bumpTestCount(); | 579 if (reporter->verbose()) { |
| 580 static int threadTestCount; |
| 581 SkDebugf("."); |
| 582 sk_atomic_inc(&threadTestCount); |
| 583 if (threadTestCount % 100 == 0) { |
| 584 SkDebugf("%d\n", threadTestCount); |
| 585 } |
| 586 } |
| 587 checkEarlyExit: |
| 588 if (1 && testCount == 20) { |
| 589 return true; |
| 590 } |
| 591 } |
| 592 return true; |
| 593 } |
| 594 |
| 595 static bool initTest() { |
| 596 SK_CONF_SET("images.jpeg.suppressDecoderWarnings", true); |
| 597 SK_CONF_SET("images.png.suppressDecoderWarnings", true); |
| 598 return make_out_dirs(); |
| 599 } |
| 600 |
| 601 static void encodeFound(skiatest::Reporter* reporter, TestState& state) { |
| 602 if (reporter->verbose()) { |
| 603 for (int index = 0; index < state.fFoundCount; ++index) { |
| 604 SkDebugf("%d %s %d\n", state.fDirsFound[index], state.fFilesFound[in
dex], |
| 605 state.fError[index]); |
| 606 } |
| 607 } |
| 608 for (int index = 0; index < state.fFoundCount; ++index) { |
| 609 TestResult::Test(state.fDirsFound[index], state.fFilesFound[index], kEnc
odeFiles); |
| 610 if (state.fReporter->verbose()) SkDebugf("+"); |
213 } | 611 } |
214 } | 612 } |
215 | 613 |
216 static void bumpCount(skiatest::Reporter* reporter, bool skipping) { | 614 static void PathOpsSkpClipTest(skiatest::Reporter* reporter) { |
217 if (reporter->verbose()) { | 615 if (!initTest()) { |
218 static int threadTestCount; | 616 return; |
219 if (!skipping) { | 617 } |
220 SkDebugf("."); | 618 SkTArray<TestResult, true> errors; |
| 619 TestState state; |
| 620 state.init(0, reporter); |
| 621 for (int dirNo = 1; dirNo <= 100; ++dirNo) { |
| 622 if (reporter->verbose()) { |
| 623 SkDebugf("dirNo=%d\n", dirNo); |
221 } | 624 } |
222 sk_atomic_inc(&threadTestCount); | 625 state.fResult.fDirNo = dirNo; |
223 if (!skipping && threadTestCount % 100 == 0) { | 626 if (!doOneDir(&state)) { |
224 SkDebugf("%d\n", threadTestCount); | 627 break; |
225 } | |
226 if (skipping && threadTestCount % 10000 == 0) { | |
227 SkDebugf("%d\n", threadTestCount); | |
228 } | 628 } |
229 } | 629 } |
| 630 encodeFound(reporter, state); |
230 } | 631 } |
231 | 632 |
232 static void testSkpClipMain(PathOpsThreadState* data) { | 633 static void testSkpClipMain(TestState* data) { |
233 SkString str(data->fSerialNo); | 634 (void) doOneDir(data); |
234 testOne(str); | |
235 bumpCount(data->fReporter, false); | |
236 data->fReporter->bumpTestCount(); | |
237 } | 635 } |
238 | 636 |
239 static void PathOpsSkpClipThreadedTest(skiatest::Reporter* reporter) { | 637 static void PathOpsSkpClipThreadedTest(skiatest::Reporter* reporter) { |
240 int threadCount = initializeTests(reporter, "skpClipThreadedTest"); | 638 if (!initTest()) { |
241 PathOpsThreadedTestRunner testRunner(reporter, threadCount); | 639 return; |
242 SkOSFile::Iter iter(pictDir, "skp"); | 640 } |
243 SkString filename; | 641 int threadCount = reporter->allowThreaded() ? SkThreadPool::kThreadPerCore :
1; |
244 while (iter.next(&filename)) { | 642 TestRunner testRunner(reporter, threadCount); |
245 SkString pngName = make_png_name(filename); | 643 for (int dirNo = 1; dirNo <= 100; ++dirNo) { |
246 SkString oldPng = make_filepath(outOldClipDir, pngName); | 644 *testRunner.fRunnables.append() = SkNEW_ARGS(TestRunnable, |
247 SkString newPng = make_filepath(outSkpClipDir, pngName); | 645 (&testSkpClipMain, dirNo, &testRunner)); |
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)); | |
260 skipOver: | |
261 ; | |
262 } | 646 } |
263 testRunner.render(); | 647 testRunner.render(); |
264 } | 648 TestState state; |
265 | 649 state.init(0, reporter); |
266 static void PathOpsSkpClipFixedTest(skiatest::Reporter* reporter) { | 650 for (int dirNo = 1; dirNo <= 100; ++dirNo) { |
267 for (size_t index = 0; index < tryFixedCount; ) { | 651 TestState& testState = testRunner.fRunnables[dirNo - 1]->fState; |
268 SkString filename(tryFixed[index]); | 652 for (int inner = 0; inner < testState.fFoundCount; ++inner) { |
269 testOne(filename); | 653 TestResult& testResult = testState.fResult; |
270 ++index; | 654 SkASSERT(testResult.fDirNo == dirNo); |
271 if (reporter->verbose()) { | 655 testResult.fPixelError = testState.fError[inner]; |
272 SkDebugf("."); | 656 strcpy(testResult.fFilename, testState.fFilesFound[inner]); |
273 if (index % 100 == 0) { | 657 addError(&state, testResult); |
274 SkDebugf("\n"); | |
275 } | |
276 } | 658 } |
277 reporter->bumpTestCount(); | |
278 } | 659 } |
| 660 encodeFound(reporter, state); |
279 } | 661 } |
280 | 662 |
281 static void PathOpsSkpClipOneOffTest(skiatest::Reporter* reporter) { | 663 static void PathOpsSkpClipOneOffTest(skiatest::Reporter* reporter) { |
282 SkString filename("http___78_cn_.skp"); | 664 if (!initTest()) { |
283 testOne(filename); | 665 return; |
| 666 } |
| 667 const int testIndex = 42 - 41; |
| 668 int dirNo = skipOverSept[testIndex].directory; |
| 669 SkAssertResult(make_in_dir_name(dirNo).size()); |
| 670 SkString filename(skipOverSept[testIndex].filename); |
| 671 TestResult state; |
| 672 state.test(dirNo, filename); |
| 673 if (reporter->verbose()) { |
| 674 SkDebugf("%s", state.status().c_str()); |
| 675 } |
| 676 state.fTestStep = kEncodeFiles; |
| 677 state.testOne(); |
284 } | 678 } |
285 | 679 |
286 #include "TestClassDef.h" | 680 #include "TestClassDef.h" |
287 DEFINE_TESTCLASS_SHORT(PathOpsSkpClipTest) | 681 DEFINE_TESTCLASS_SHORT(PathOpsSkpClipTest) |
288 | 682 |
289 DEFINE_TESTCLASS_SHORT(PathOpsSkpClipFixedTest) | |
290 | |
291 DEFINE_TESTCLASS_SHORT(PathOpsSkpClipOneOffTest) | 683 DEFINE_TESTCLASS_SHORT(PathOpsSkpClipOneOffTest) |
292 | 684 |
293 DEFINE_TESTCLASS_SHORT(PathOpsSkpClipThreadedTest) | 685 DEFINE_TESTCLASS_SHORT(PathOpsSkpClipThreadedTest) |
OLD | NEW |