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