OLD | NEW |
(Empty) | |
| 1 #if !SK_SUPPORT_GPU |
| 2 #error "GPU support required" |
| 3 #endif |
| 4 |
| 5 #include "GrContext.h" |
| 6 #include "GrContextFactory.h" |
| 7 #include "GrRenderTarget.h" |
| 8 #include "SkGpuDevice.h" |
| 9 #include "gl/GrGLDefines.h" |
| 10 |
| 11 #include "SkBitmap.h" |
| 12 #include "SkColor.h" |
| 13 #include "SkDevice.h" |
| 14 #include "SkCanvas.h" |
| 15 #include "SkGraphics.h" |
| 16 #include "SkImageDecoder.h" |
| 17 #include "SkImageEncoder.h" |
| 18 #include "SkStream.h" |
| 19 #include "SkOSFile.h" |
| 20 #include "SkPicture.h" |
| 21 #include "SkRTConf.h" |
| 22 #include "SkRunnable.h" |
| 23 #include "SkString.h" |
| 24 #include "SkTArray.h" |
| 25 #include "SkTDArray.h" |
| 26 #include "SkThreadPool.h" |
| 27 #include "SkTime.h" |
| 28 #include "Test.h" |
| 29 |
| 30 #ifdef SK_BUILD_FOR_WIN |
| 31 #define PATH_SLASH "\\" |
| 32 #define IN_DIR "D:\\9-30-13\\" |
| 33 #define OUT_DIR "D:\\skpSkGr\\11\\" |
| 34 #define LINE_FEED "\r\n" |
| 35 #else |
| 36 #define PATH_SLASH "/" |
| 37 #define IN_DIR "/usr/local/google/home/caryclark" PATH_SLASH "9-30-13-skp" |
| 38 #define OUT_DIR "/media/01CD75512A7F9EE0/4" PATH_SLASH |
| 39 #define LINE_FEED \n" |
| 40 #endif |
| 41 |
| 42 #define PATH_STR_SIZE 512 |
| 43 |
| 44 static const struct { |
| 45 int directory; |
| 46 const char* filename; |
| 47 } skipOverSkGr[] = { |
| 48 {1, "http___accuweather_com_.skp"}, // Couldn't convert bitmap to texture.h
ttp___absoku072_com_ |
| 49 }; |
| 50 |
| 51 static const size_t skipOverSkGrCount = 0; // SK_ARRAY_COUNT(skipOverSkGr); |
| 52 |
| 53 ///////////////////////////////////////// |
| 54 |
| 55 class SkpSkGrThreadedRunnable; |
| 56 |
| 57 enum TestStep { |
| 58 kCompareBits, |
| 59 kEncodeFiles, |
| 60 }; |
| 61 |
| 62 enum { |
| 63 kMaxLength = 128, |
| 64 kMaxFiles = 128, |
| 65 }; |
| 66 |
| 67 struct TestResult { |
| 68 void init(int dirNo) { |
| 69 fDirNo = dirNo; |
| 70 sk_bzero(fFilename, sizeof(fFilename)); |
| 71 fTestStep = kCompareBits; |
| 72 fScaleOversized = true; |
| 73 } |
| 74 |
| 75 SkString status() { |
| 76 SkString outStr; |
| 77 outStr.printf("%s %d %d%s", fFilename, fPixelError, fTime, LINE_FEED); |
| 78 return outStr; |
| 79 } |
| 80 |
| 81 static void Test(int dirNo, const char* filename, TestStep testStep, bool ve
rbose) { |
| 82 TestResult test; |
| 83 test.init(dirNo); |
| 84 test.fTestStep = testStep; |
| 85 strcpy(test.fFilename, filename); |
| 86 test.testOne(); |
| 87 if (verbose) { |
| 88 SkDebugf("%s", test.status().c_str()); |
| 89 } |
| 90 } |
| 91 |
| 92 void test(int dirNo, const SkString& filename) { |
| 93 init(dirNo); |
| 94 strcpy(fFilename, filename.c_str()); |
| 95 testOne(); |
| 96 } |
| 97 |
| 98 void testOne(); |
| 99 |
| 100 char fFilename[kMaxLength]; |
| 101 TestStep fTestStep; |
| 102 int fDirNo; |
| 103 int fPixelError; |
| 104 int fTime; |
| 105 bool fScaleOversized; |
| 106 }; |
| 107 |
| 108 struct SkpSkGrThreadState { |
| 109 void init(int dirNo) { |
| 110 fResult.init(dirNo); |
| 111 fFoundCount = 0; |
| 112 fSmallestError = 0; |
| 113 sk_bzero(fFilesFound, sizeof(fFilesFound)); |
| 114 sk_bzero(fDirsFound, sizeof(fDirsFound)); |
| 115 sk_bzero(fError, sizeof(fError)); |
| 116 } |
| 117 |
| 118 char fFilesFound[kMaxFiles][kMaxLength]; |
| 119 int fDirsFound[kMaxFiles]; |
| 120 int fError[kMaxFiles]; |
| 121 int fFoundCount; |
| 122 int fSmallestError; |
| 123 skiatest::Reporter* fReporter; |
| 124 TestResult fResult; |
| 125 }; |
| 126 |
| 127 struct SkpSkGrThreadedTestRunner { |
| 128 SkpSkGrThreadedTestRunner(skiatest::Reporter* reporter, int threadCount) |
| 129 : fNumThreads(threadCount) |
| 130 , fReporter(reporter) { |
| 131 } |
| 132 |
| 133 ~SkpSkGrThreadedTestRunner(); |
| 134 void render(); |
| 135 int fNumThreads; |
| 136 SkTDArray<SkpSkGrThreadedRunnable*> fRunnables; |
| 137 skiatest::Reporter* fReporter; |
| 138 }; |
| 139 |
| 140 class SkpSkGrThreadedRunnable : public SkRunnable { |
| 141 public: |
| 142 SkpSkGrThreadedRunnable(void (*testFun)(SkpSkGrThreadState*), int dirNo, con
st char* str, |
| 143 SkpSkGrThreadedTestRunner* runner) { |
| 144 SkASSERT(strlen(str) < sizeof(fState.fResult.fFilename) - 1); |
| 145 fState.init(dirNo); |
| 146 strcpy(fState.fResult.fFilename, str); |
| 147 fState.fReporter = 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 SkpSkGrThreadState fState; |
| 157 void (*fTestFun)(SkpSkGrThreadState*); |
| 158 }; |
| 159 |
| 160 SkpSkGrThreadedTestRunner::~SkpSkGrThreadedTestRunner() { |
| 161 for (int index = 0; index < fRunnables.count(); index++) { |
| 162 SkDELETE(fRunnables[index]); |
| 163 } |
| 164 } |
| 165 |
| 166 void SkpSkGrThreadedTestRunner::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 outGrDir[] = OUT_DIR "grTest"; |
| 176 static const char outSkDir[] = OUT_DIR "skTest"; |
| 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 dirIndex, const char* dir, const char* name) { |
| 182 SkString path(dir); |
| 183 if (dirIndex) { |
| 184 path.appendf("%d", dirIndex); |
| 185 } |
| 186 path.append(PATH_SLASH); |
| 187 path.append(name); |
| 188 return path; |
| 189 } |
| 190 |
| 191 static SkString make_in_dir_name(int dirIndex) { |
| 192 SkString dirName(IN_DIR); |
| 193 dirName.appendf("%d", dirIndex); |
| 194 if (!sk_exists(dirName.c_str())) { |
| 195 SkDebugf("could not read dir %s\n", dirName.c_str()); |
| 196 return SkString(); |
| 197 } |
| 198 return dirName; |
| 199 } |
| 200 |
| 201 static bool make_out_dirs() { |
| 202 SkString outDir = make_filepath(0, OUT_DIR, ""); |
| 203 if (!sk_exists(outDir.c_str())) { |
| 204 if (!sk_mkdir(outDir.c_str())) { |
| 205 SkDebugf("could not create dir %s\n", outDir.c_str()); |
| 206 return false; |
| 207 } |
| 208 } |
| 209 SkString grDir = make_filepath(0, outGrDir, ""); |
| 210 if (!sk_exists(grDir.c_str())) { |
| 211 if (!sk_mkdir(grDir.c_str())) { |
| 212 SkDebugf("could not create dir %s\n", grDir.c_str()); |
| 213 return false; |
| 214 } |
| 215 } |
| 216 SkString skDir = make_filepath(0, outSkDir, ""); |
| 217 if (!sk_exists(skDir.c_str())) { |
| 218 if (!sk_mkdir(skDir.c_str())) { |
| 219 SkDebugf("could not create dir %s\n", skDir.c_str()); |
| 220 return false; |
| 221 } |
| 222 } |
| 223 SkString skpDir = make_filepath(0, outSkpDir, ""); |
| 224 if (!sk_exists(skpDir.c_str())) { |
| 225 if (!sk_mkdir(skpDir.c_str())) { |
| 226 SkDebugf("could not create dir %s\n", skpDir.c_str()); |
| 227 return false; |
| 228 } |
| 229 } |
| 230 SkString diffDir = make_filepath(0, outDiffDir, ""); |
| 231 if (!sk_exists(diffDir.c_str())) { |
| 232 if (!sk_mkdir(diffDir.c_str())) { |
| 233 SkDebugf("could not create dir %s\n", diffDir.c_str()); |
| 234 return false; |
| 235 } |
| 236 } |
| 237 SkString statusDir = make_filepath(0, outStatusDir, ""); |
| 238 if (!sk_exists(statusDir.c_str())) { |
| 239 if (!sk_mkdir(statusDir.c_str())) { |
| 240 SkDebugf("could not create dir %s\n", statusDir.c_str()); |
| 241 return false; |
| 242 } |
| 243 } |
| 244 return true; |
| 245 } |
| 246 |
| 247 static SkString make_png_name(const char* filename) { |
| 248 SkString pngName = SkString(filename); |
| 249 pngName.remove(pngName.size() - 3, 3); |
| 250 pngName.append("png"); |
| 251 return pngName; |
| 252 } |
| 253 |
| 254 typedef GrContextFactory::GLContextType GLContextType; |
| 255 #ifdef SK_BUILD_FOR_WIN |
| 256 static const GLContextType kAngle = GrContextFactory::kANGLE_GLContextType; |
| 257 #else |
| 258 static const GLContextType kNative = GrContextFactory::kNative_GLContextType; |
| 259 #endif |
| 260 |
| 261 static int similarBits(const SkBitmap& gr, const SkBitmap& sk) { |
| 262 const int kRowCount = 3; |
| 263 const int kThreshold = 3; |
| 264 int width = SkTMin(gr.width(), sk.width()); |
| 265 if (width < kRowCount) { |
| 266 return true; |
| 267 } |
| 268 int height = SkTMin(gr.height(), sk.height()); |
| 269 if (height < kRowCount) { |
| 270 return true; |
| 271 } |
| 272 int errorTotal = 0; |
| 273 SkTArray<char, true> errorRows; |
| 274 errorRows.push_back_n(width * kRowCount); |
| 275 SkAutoLockPixels autoGr(gr); |
| 276 SkAutoLockPixels autoSk(sk); |
| 277 char* base = &errorRows[0]; |
| 278 for (int y = 0; y < height; ++y) { |
| 279 SkPMColor* grRow = gr.getAddr32(0, y); |
| 280 SkPMColor* skRow = sk.getAddr32(0, y); |
| 281 char* cOut = &errorRows[(y % kRowCount) * width]; |
| 282 for (int x = 0; x < width; ++x) { |
| 283 SkPMColor grColor = grRow[x]; |
| 284 SkPMColor skColor = skRow[x]; |
| 285 int dr = SkGetPackedR32(grColor) - SkGetPackedR32(skColor); |
| 286 int dg = SkGetPackedG32(grColor) - SkGetPackedG32(skColor); |
| 287 int db = SkGetPackedB32(grColor) - SkGetPackedB32(skColor); |
| 288 int error = SkTMax(SkAbs32(dr), SkTMax(SkAbs32(dg), SkAbs32(db))); |
| 289 if ((cOut[x] = error >= kThreshold) && x >= 2 |
| 290 && base[x - 2] && base[width + x - 2] && base[width * 2 + x
- 2] |
| 291 && base[x - 1] && base[width + x - 1] && base[width * 2 + x
- 1] |
| 292 && base[x - 0] && base[width + x - 0] && base[width * 2 + x
- 0]) { |
| 293 errorTotal += error; |
| 294 } |
| 295 } |
| 296 } |
| 297 return errorTotal; |
| 298 } |
| 299 |
| 300 static bool addError(SkpSkGrThreadState* data) { |
| 301 bool foundSmaller = false; |
| 302 int dCount = data->fFoundCount; |
| 303 int pixelError = data->fResult.fPixelError; |
| 304 if (data->fFoundCount < kMaxFiles) { |
| 305 data->fError[dCount] = pixelError; |
| 306 strcpy(data->fFilesFound[dCount], data->fResult.fFilename); |
| 307 data->fDirsFound[dCount] = data->fResult.fDirNo; |
| 308 ++data->fFoundCount; |
| 309 } else if (pixelError > data->fSmallestError) { |
| 310 int smallest = SK_MaxS32; |
| 311 int smallestIndex = 0; |
| 312 for (int index = 0; index < kMaxFiles; ++index) { |
| 313 if (smallest > data->fError[index]) { |
| 314 smallest = data->fError[index]; |
| 315 smallestIndex = index; |
| 316 } |
| 317 } |
| 318 data->fError[smallestIndex] = pixelError; |
| 319 strcpy(data->fFilesFound[smallestIndex], data->fResult.fFilename); |
| 320 data->fDirsFound[smallestIndex] = data->fResult.fDirNo; |
| 321 data->fSmallestError = SK_MaxS32; |
| 322 for (int index = 0; index < kMaxFiles; ++index) { |
| 323 if (data->fSmallestError > data->fError[index]) { |
| 324 data->fSmallestError = data->fError[index]; |
| 325 } |
| 326 } |
| 327 SkDebugf("*%d*", data->fSmallestError); |
| 328 foundSmaller = true; |
| 329 } |
| 330 return foundSmaller; |
| 331 } |
| 332 |
| 333 static SkMSec timePict(SkPicture* pic, SkCanvas* canvas) { |
| 334 canvas->save(); |
| 335 int pWidth = pic->width(); |
| 336 int pHeight = pic->height(); |
| 337 const int maxDimension = 1000; |
| 338 const int slices = 3; |
| 339 int xInterval = SkTMax(pWidth - maxDimension, 0) / (slices - 1); |
| 340 int yInterval = SkTMax(pHeight - maxDimension, 0) / (slices - 1); |
| 341 SkRect rect = {0, 0, SkIntToScalar(SkTMin(maxDimension, pWidth)), |
| 342 SkIntToScalar(SkTMin(maxDimension, pHeight))}; |
| 343 canvas->clipRect(rect); |
| 344 SkMSec start = SkTime::GetMSecs(); |
| 345 for (int x = 0; x < slices; ++x) { |
| 346 for (int y = 0; y < slices; ++y) { |
| 347 pic->draw(canvas); |
| 348 canvas->translate(0, SkIntToScalar(yInterval)); |
| 349 } |
| 350 canvas->translate(SkIntToScalar(xInterval), SkIntToScalar(-yInterval * s
lices)); |
| 351 } |
| 352 SkMSec end = SkTime::GetMSecs(); |
| 353 canvas->restore(); |
| 354 return end - start; |
| 355 } |
| 356 |
| 357 static void drawPict(SkPicture* pic, SkCanvas* canvas, int scale) { |
| 358 canvas->clear(SK_ColorWHITE); |
| 359 if (scale != 1) { |
| 360 canvas->save(); |
| 361 canvas->scale(1.0f / scale, 1.0f / scale); |
| 362 } |
| 363 pic->draw(canvas); |
| 364 if (scale != 1) { |
| 365 canvas->restore(); |
| 366 } |
| 367 } |
| 368 |
| 369 static void writePict(const SkBitmap& bitmap, const char* outDir, const char* pn
gName) { |
| 370 SkString outFile = make_filepath(0, outDir, pngName); |
| 371 if (!SkImageEncoder::EncodeFile(outFile.c_str(), bitmap, |
| 372 SkImageEncoder::kPNG_Type, 100)) { |
| 373 SkDebugf("unable to encode gr %s (width=%d height=%d)br \n", pngName, |
| 374 bitmap.width(), bitmap.height()); |
| 375 } |
| 376 } |
| 377 |
| 378 void TestResult::testOne() { |
| 379 SkPicture* pic = NULL; |
| 380 { |
| 381 SkString d; |
| 382 d.printf(" {%d, \"%s\"},", fDirNo, fFilename); |
| 383 SkString path = make_filepath(fDirNo, IN_DIR, fFilename); |
| 384 SkFILEStream stream(path.c_str()); |
| 385 if (!stream.isValid()) { |
| 386 SkDebugf("invalid stream %s\n", path.c_str()); |
| 387 goto finish; |
| 388 } |
| 389 if (fTestStep == kEncodeFiles) { |
| 390 size_t length = stream.getLength(); |
| 391 SkTArray<char, true> bytes; |
| 392 bytes.push_back_n(length); |
| 393 stream.read(&bytes[0], length); |
| 394 stream.rewind(); |
| 395 SkString wPath = make_filepath(0, outSkpDir, fFilename); |
| 396 SkFILEWStream wStream(wPath.c_str()); |
| 397 wStream.write(&bytes[0], length); |
| 398 wStream.flush(); |
| 399 } |
| 400 pic = SkPicture::CreateFromStream(&stream, &SkImageDecoder::DecodeMemory
); |
| 401 if (!pic) { |
| 402 SkDebugf("unable to decode %s\n", fFilename); |
| 403 goto finish; |
| 404 } |
| 405 int pWidth = pic->width(); |
| 406 int pHeight = pic->height(); |
| 407 int pLargerWH = SkTMax(pWidth, pHeight); |
| 408 GrContextFactory contextFactory; |
| 409 #ifdef SK_BUILD_FOR_WIN |
| 410 GrContext* context = contextFactory.get(kAngle); |
| 411 #else |
| 412 GrContext* context = contextFactory.get(kNative); |
| 413 #endif |
| 414 if (NULL == context) { |
| 415 SkDebugf("unable to allocate context for %s\n", fFilename); |
| 416 goto finish; |
| 417 } |
| 418 int maxWH = context->getMaxRenderTargetSize(); |
| 419 int scale = 1; |
| 420 while (pLargerWH / scale > maxWH) { |
| 421 scale *= 2; |
| 422 } |
| 423 SkBitmap bitmap; |
| 424 SkIPoint dim; |
| 425 do { |
| 426 dim.fX = (pWidth + scale - 1) / scale; |
| 427 dim.fY = (pHeight + scale - 1) / scale; |
| 428 bitmap.setConfig(SkBitmap::kARGB_8888_Config, dim.fX, dim.fY); |
| 429 bool success = bitmap.allocPixels(); |
| 430 if (success) { |
| 431 break; |
| 432 } |
| 433 SkDebugf("-%d-", scale); |
| 434 } while ((scale *= 2) < 256); |
| 435 if (scale >= 256) { |
| 436 SkDebugf("unable to allocate bitmap for %s (w=%d h=%d) (sw=%d sh=%d)
\n", |
| 437 fFilename, pWidth, pHeight, dim.fX, dim.fY); |
| 438 goto finish; |
| 439 } |
| 440 SkCanvas skCanvas(bitmap); |
| 441 drawPict(pic, &skCanvas, fScaleOversized ? scale : 1); |
| 442 GrTextureDesc desc; |
| 443 desc.fConfig = kSkia8888_GrPixelConfig; |
| 444 desc.fFlags = kRenderTarget_GrTextureFlagBit; |
| 445 desc.fWidth = dim.fX; |
| 446 desc.fHeight = dim.fY; |
| 447 desc.fSampleCnt = 0; |
| 448 SkAutoTUnref<GrTexture> texture(context->createUncachedTexture(desc, NUL
L, 0)); |
| 449 if (!texture) { |
| 450 SkDebugf("unable to allocate texture for %s (w=%d h=%d)\n", fFilenam
e, |
| 451 dim.fX, dim.fY); |
| 452 goto finish; |
| 453 } |
| 454 SkGpuDevice grDevice(context, texture.get()); |
| 455 SkCanvas grCanvas(&grDevice); |
| 456 drawPict(pic, &grCanvas, fScaleOversized ? scale : 1); |
| 457 const SkBitmap& grBitmap = grDevice.accessBitmap(false); |
| 458 if (fTestStep == kCompareBits) { |
| 459 fPixelError = similarBits(grBitmap, bitmap); |
| 460 int skTime = timePict(pic, &skCanvas); |
| 461 int grTime = timePict(pic, &grCanvas); |
| 462 fTime = skTime - grTime; |
| 463 } else if (fTestStep == kEncodeFiles) { |
| 464 SkString pngStr = make_png_name(fFilename); |
| 465 const char* pngName = pngStr.c_str(); |
| 466 writePict(grBitmap, outGrDir, pngName); |
| 467 writePict(bitmap, outSkDir, pngName); |
| 468 } |
| 469 } |
| 470 finish: |
| 471 SkDELETE(pic); |
| 472 } |
| 473 |
| 474 static SkString makeStatusString(int dirNo) { |
| 475 SkString statName; |
| 476 statName.printf("stats%d.txt", dirNo); |
| 477 SkString statusFile = make_filepath(0, outStatusDir, statName.c_str()); |
| 478 return statusFile; |
| 479 } |
| 480 |
| 481 class PreParser { |
| 482 public: |
| 483 PreParser(int dirNo) |
| 484 : fDirNo(dirNo) |
| 485 , fIndex(0) |
| 486 , fStatusPath(makeStatusString(dirNo)) { |
| 487 if (!sk_exists(fStatusPath.c_str())) { |
| 488 return; |
| 489 } |
| 490 SkFILEStream reader; |
| 491 reader.setPath(fStatusPath.c_str()); |
| 492 while (fetch(reader, &fResults.push_back())) |
| 493 ; |
| 494 fResults.pop_back(); |
| 495 } |
| 496 |
| 497 bool fetch(SkFILEStream& reader, TestResult* result) { |
| 498 char c; |
| 499 int i = 0; |
| 500 result->init(fDirNo); |
| 501 result->fPixelError = 0; |
| 502 result->fTime = 0; |
| 503 do { |
| 504 bool readOne = reader.read(&c, 1) != 0; |
| 505 if (!readOne) { |
| 506 SkASSERT(i == 0); |
| 507 return false; |
| 508 } |
| 509 if (c == ' ') { |
| 510 result->fFilename[i++] = '\0'; |
| 511 break; |
| 512 } |
| 513 result->fFilename[i++] = c; |
| 514 SkASSERT(i < kMaxLength); |
| 515 } while (true); |
| 516 do { |
| 517 SkAssertResult(reader.read(&c, 1) != 0); |
| 518 if (c == ' ') { |
| 519 break; |
| 520 } |
| 521 SkASSERT(c >= '0' && c <= '9'); |
| 522 result->fPixelError = result->fPixelError * 10 + (c - '0'); |
| 523 } while (true); |
| 524 bool minus = false; |
| 525 do { |
| 526 if (reader.read(&c, 1) == 0) { |
| 527 break; |
| 528 } |
| 529 if (c == '\r' && reader.read(&c, 1) == 0) { |
| 530 break; |
| 531 } |
| 532 if (c == '\n') { |
| 533 break; |
| 534 } |
| 535 if (c == '-') { |
| 536 minus = true; |
| 537 continue; |
| 538 } |
| 539 SkASSERT(c >= '0' && c <= '9'); |
| 540 result->fTime = result->fTime * 10 + (c - '0'); |
| 541 } while (true); |
| 542 if (minus) { |
| 543 result->fTime = -result->fTime; |
| 544 } |
| 545 return true; |
| 546 } |
| 547 |
| 548 bool match(const SkString& filename, SkFILEWStream* stream, TestResult* resu
lt) { |
| 549 if (fIndex < fResults.count()) { |
| 550 *result = fResults[fIndex++]; |
| 551 SkASSERT(filename.equals(result->fFilename)); |
| 552 SkString outStr(result->status()); |
| 553 stream->write(outStr.c_str(), outStr.size()); |
| 554 stream->flush(); |
| 555 return true; |
| 556 } |
| 557 return false; |
| 558 } |
| 559 |
| 560 private: |
| 561 int fDirNo; |
| 562 int fIndex; |
| 563 SkTArray<TestResult, true> fResults; |
| 564 SkString fStatusPath; |
| 565 }; |
| 566 |
| 567 static bool initTest() { |
| 568 #if !defined SK_BUILD_FOR_WIN && !defined SK_BUILD_FOR_MAC |
| 569 SK_CONF_SET("images.jpeg.suppressDecoderWarnings", true); |
| 570 SK_CONF_SET("images.png.suppressDecoderWarnings", true); |
| 571 #endif |
| 572 return make_out_dirs(); |
| 573 } |
| 574 |
| 575 static void SkpSkGrTest(skiatest::Reporter* reporter) { |
| 576 SkTArray<TestResult, true> errors; |
| 577 if (!initTest()) { |
| 578 return; |
| 579 } |
| 580 SkpSkGrThreadState state; |
| 581 state.init(0); |
| 582 int smallCount = 0; |
| 583 for (int dirNo = 1; dirNo <= 100; ++dirNo) { |
| 584 SkString pictDir = make_in_dir_name(dirNo); |
| 585 SkASSERT(pictDir.size()); |
| 586 if (reporter->verbose()) { |
| 587 SkDebugf("dirNo=%d\n", dirNo); |
| 588 } |
| 589 SkOSFile::Iter iter(pictDir.c_str(), "skp"); |
| 590 SkString filename; |
| 591 int testCount = 0; |
| 592 PreParser preParser(dirNo); |
| 593 SkFILEWStream statusStream(makeStatusString(dirNo).c_str()); |
| 594 while (iter.next(&filename)) { |
| 595 for (size_t index = 0; index < skipOverSkGrCount; ++index) { |
| 596 if (skipOverSkGr[index].directory == dirNo |
| 597 && strcmp(filename.c_str(), skipOverSkGr[index].filename
) == 0) { |
| 598 goto skipOver; |
| 599 } |
| 600 } |
| 601 if (preParser.match(filename, &statusStream, &state.fResult)) { |
| 602 addError(&state); |
| 603 ++testCount; |
| 604 goto checkEarlyExit; |
| 605 } |
| 606 if (state.fSmallestError > 5000000) { |
| 607 goto breakOut; |
| 608 } |
| 609 { |
| 610 TestResult& result = state.fResult; |
| 611 result.test(dirNo, filename); |
| 612 SkString outStr(result.status()); |
| 613 statusStream.write(outStr.c_str(), outStr.size()); |
| 614 statusStream.flush(); |
| 615 if (1) { |
| 616 SkDebugf("%s", outStr.c_str()); |
| 617 } |
| 618 bool noMatch = addError(&state); |
| 619 if (noMatch) { |
| 620 smallCount = 0; |
| 621 } else if (++smallCount > 10000) { |
| 622 goto breakOut; |
| 623 } |
| 624 } |
| 625 ++testCount; |
| 626 if (reporter->verbose()) { |
| 627 if (testCount % 100 == 0) { |
| 628 SkDebugf("#%d\n", testCount); |
| 629 } |
| 630 } |
| 631 skipOver: |
| 632 reporter->bumpTestCount(); |
| 633 checkEarlyExit: |
| 634 if (1 && testCount == 20) { |
| 635 break; |
| 636 } |
| 637 } |
| 638 } |
| 639 breakOut: |
| 640 if (reporter->verbose()) { |
| 641 for (int index = 0; index < state.fFoundCount; ++index) { |
| 642 SkDebugf("%d %s %d\n", state.fDirsFound[index], state.fFilesFound[in
dex], |
| 643 state.fError[index]); |
| 644 } |
| 645 } |
| 646 for (int index = 0; index < state.fFoundCount; ++index) { |
| 647 TestResult::Test(state.fDirsFound[index], state.fFilesFound[index], kEnc
odeFiles, |
| 648 reporter->verbose()); |
| 649 if (reporter->verbose()) SkDebugf("+"); |
| 650 } |
| 651 } |
| 652 |
| 653 static void bumpCount(skiatest::Reporter* reporter, bool skipping) { |
| 654 if (reporter->verbose()) { |
| 655 static int threadTestCount; |
| 656 sk_atomic_inc(&threadTestCount); |
| 657 if (!skipping && threadTestCount % 100 == 0) { |
| 658 SkDebugf("#%d\n", threadTestCount); |
| 659 } |
| 660 if (skipping && threadTestCount % 10000 == 0) { |
| 661 SkDebugf("#%d\n", threadTestCount); |
| 662 } |
| 663 } |
| 664 } |
| 665 |
| 666 static void testSkGrMain(SkpSkGrThreadState* data) { |
| 667 data->fResult.testOne(); |
| 668 bumpCount(data->fReporter, false); |
| 669 data->fReporter->bumpTestCount(); |
| 670 } |
| 671 |
| 672 static void SkpSkGrThreadedTest(skiatest::Reporter* reporter) { |
| 673 if (!initTest()) { |
| 674 return; |
| 675 } |
| 676 int threadCount = reporter->allowThreaded() ? 3 : 1; |
| 677 SkpSkGrThreadedTestRunner testRunner(reporter, threadCount); |
| 678 for (int dirIndex = 1; dirIndex <= 100; ++dirIndex) { |
| 679 SkString pictDir = make_in_dir_name(dirIndex); |
| 680 if (pictDir.size() == 0) { |
| 681 continue; |
| 682 } |
| 683 SkOSFile::Iter iter(pictDir.c_str(), "skp"); |
| 684 SkString filename; |
| 685 while (iter.next(&filename)) { |
| 686 SkString pngName = make_png_name(filename.c_str()); |
| 687 SkString oldPng = make_filepath(dirIndex, outSkDir, pngName.c_str())
; |
| 688 SkString newPng = make_filepath(dirIndex, outGrDir, pngName.c_str())
; |
| 689 if (sk_exists(oldPng.c_str()) && sk_exists(newPng.c_str())) { |
| 690 bumpCount(reporter, true); |
| 691 continue; |
| 692 } |
| 693 for (size_t index = 0; index < skipOverSkGrCount; ++index) { |
| 694 if (skipOverSkGr[index].directory == dirIndex |
| 695 && strcmp(filename.c_str(), skipOverSkGr[index].filename
) == 0) { |
| 696 bumpCount(reporter, true); |
| 697 goto skipOver; |
| 698 } |
| 699 } |
| 700 *testRunner.fRunnables.append() = SkNEW_ARGS(SkpSkGrThreadedRunnable
, |
| 701 (&testSkGrMain, dirIndex, filename.c_str(), &testRunner)); |
| 702 skipOver: |
| 703 ; |
| 704 } |
| 705 } |
| 706 testRunner.render(); |
| 707 SkpSkGrThreadState& max = testRunner.fRunnables[0]->fState; |
| 708 for (int dirIndex = 2; dirIndex <= 100; ++dirIndex) { |
| 709 SkpSkGrThreadState& state = testRunner.fRunnables[dirIndex - 1]->fState; |
| 710 for (int index = 0; index < state.fFoundCount; ++index) { |
| 711 int maxIdx = max.fFoundCount; |
| 712 if (maxIdx < kMaxFiles) { |
| 713 max.fError[maxIdx] = state.fError[index]; |
| 714 strcpy(max.fFilesFound[maxIdx], state.fFilesFound[index]); |
| 715 max.fDirsFound[maxIdx] = state.fDirsFound[index]; |
| 716 ++max.fFoundCount; |
| 717 continue; |
| 718 } |
| 719 for (maxIdx = 0; maxIdx < max.fFoundCount; ++maxIdx) { |
| 720 if (max.fError[maxIdx] < state.fError[index]) { |
| 721 max.fError[maxIdx] = state.fError[index]; |
| 722 strcpy(max.fFilesFound[maxIdx], state.fFilesFound[index]); |
| 723 max.fDirsFound[maxIdx] = state.fDirsFound[index]; |
| 724 break; |
| 725 } |
| 726 } |
| 727 } |
| 728 } |
| 729 TestResult encoder; |
| 730 encoder.fTestStep = kEncodeFiles; |
| 731 for (int index = 0; index < max.fFoundCount; ++index) { |
| 732 encoder.fDirNo = max.fDirsFound[index]; |
| 733 strcpy(encoder.fFilename, max.fFilesFound[index]); |
| 734 encoder.testOne(); |
| 735 SkDebugf("+"); |
| 736 } |
| 737 } |
| 738 |
| 739 static void SkpSkGrOneOffTest(skiatest::Reporter* reporter) { |
| 740 if (!initTest()) { |
| 741 return; |
| 742 } |
| 743 int testIndex = 166; |
| 744 int dirIndex = skipOverSkGr[testIndex - 166].directory; |
| 745 SkString pictDir = make_in_dir_name(dirIndex); |
| 746 if (pictDir.size() == 0) { |
| 747 return; |
| 748 } |
| 749 SkString filename(skipOverSkGr[testIndex - 166].filename); |
| 750 TestResult::Test(dirIndex, filename.c_str(), kCompareBits, reporter->verbose
()); |
| 751 TestResult::Test(dirIndex, filename.c_str(), kEncodeFiles, reporter->verbose
()); |
| 752 } |
| 753 |
| 754 #include "TestClassDef.h" |
| 755 DEFINE_TESTCLASS_SHORT(SkpSkGrTest) |
| 756 |
| 757 DEFINE_TESTCLASS_SHORT(SkpSkGrOneOffTest) |
| 758 |
| 759 DEFINE_TESTCLASS_SHORT(SkpSkGrThreadedTest) |
OLD | NEW |