blob: 02aabbe2af0258aa41d885f9ad45d5e84aeb2de6 [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"
tfarina@chromium.org8f6884a2014-01-24 20:56:26 +000012#include "SkCanvas.h"
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +000013#include "SkColor.h"
14#include "SkDevice.h"
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +000015#include "SkGraphics.h"
16#include "SkImageDecoder.h"
17#include "SkImageEncoder.h"
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +000018#include "SkOSFile.h"
19#include "SkPicture.h"
20#include "SkRTConf.h"
21#include "SkRunnable.h"
tfarina@chromium.org8f6884a2014-01-24 20:56:26 +000022#include "SkStream.h"
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +000023#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
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +000039 #define LINE_FEED "\n"
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +000040#endif
41
42#define PATH_STR_SIZE 512
43
44static const struct {
45 int directory;
46 const char* filename;
47} skipOverSkGr[] = {
48 {1, "http___accuweather_com_.skp"}, // Couldn't convert bitmap to texture.http___absoku072_com_
49};
50
51static const size_t skipOverSkGrCount = 0; // SK_ARRAY_COUNT(skipOverSkGr);
52
53/////////////////////////////////////////
54
55class SkpSkGrThreadedRunnable;
56
57enum TestStep {
58 kCompareBits,
59 kEncodeFiles,
60};
61
62enum {
63 kMaxLength = 128,
64 kMaxFiles = 128,
65};
66
67struct 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 verbose) {
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();
skia.committer@gmail.comf54ad6f2013-11-02 07:02:02 +000099
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000100 char fFilename[kMaxLength];
101 TestStep fTestStep;
102 int fDirNo;
103 int fPixelError;
104 int fTime;
105 bool fScaleOversized;
106};
107
108struct 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 }
skia.committer@gmail.comf54ad6f2013-11-02 07:02:02 +0000117
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000118 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
127struct 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
140class SkpSkGrThreadedRunnable : public SkRunnable {
141public:
142 SkpSkGrThreadedRunnable(void (*testFun)(SkpSkGrThreadState*), int dirNo, const 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
160SkpSkGrThreadedTestRunner::~SkpSkGrThreadedTestRunner() {
161 for (int index = 0; index < fRunnables.count(); index++) {
162 SkDELETE(fRunnables[index]);
163 }
164}
165
166void 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
175static const char outGrDir[] = OUT_DIR "grTest";
176static const char outSkDir[] = OUT_DIR "skTest";
177static const char outSkpDir[] = OUT_DIR "skpTest";
178static const char outDiffDir[] = OUT_DIR "outTest";
179static const char outStatusDir[] = OUT_DIR "statusTest";
180
181static 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
191static 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
201static 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
247static 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
254typedef GrContextFactory::GLContextType GLContextType;
255#ifdef SK_BUILD_FOR_WIN
256static const GLContextType kAngle = GrContextFactory::kANGLE_GLContextType;
257#else
258static const GLContextType kNative = GrContextFactory::kNative_GLContextType;
259#endif
260
261static 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
300static 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
333static 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);
skia.committer@gmail.comf54ad6f2013-11-02 07:02:02 +0000341 SkRect rect = {0, 0, SkIntToScalar(SkTMin(maxDimension, pWidth)),
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000342 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 * slices));
351 }
352 SkMSec end = SkTime::GetMSecs();
353 canvas->restore();
354 return end - start;
355}
356
357static 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
369static void writePict(const SkBitmap& bitmap, const char* outDir, const char* pngName) {
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
378void 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;
mike@reedtribe.orgdeee4962014-02-13 14:41:43 +0000428 bool success = bitmap.allocN32Pixels(, dim.fX, dim.fY);
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000429 if (success) {
430 break;
431 }
432 SkDebugf("-%d-", scale);
433 } while ((scale *= 2) < 256);
434 if (scale >= 256) {
435 SkDebugf("unable to allocate bitmap for %s (w=%d h=%d) (sw=%d sh=%d)\n",
436 fFilename, pWidth, pHeight, dim.fX, dim.fY);
437 goto finish;
438 }
439 SkCanvas skCanvas(bitmap);
440 drawPict(pic, &skCanvas, fScaleOversized ? scale : 1);
441 GrTextureDesc desc;
442 desc.fConfig = kSkia8888_GrPixelConfig;
443 desc.fFlags = kRenderTarget_GrTextureFlagBit;
444 desc.fWidth = dim.fX;
445 desc.fHeight = dim.fY;
446 desc.fSampleCnt = 0;
447 SkAutoTUnref<GrTexture> texture(context->createUncachedTexture(desc, NULL, 0));
448 if (!texture) {
449 SkDebugf("unable to allocate texture for %s (w=%d h=%d)\n", fFilename,
450 dim.fX, dim.fY);
451 goto finish;
452 }
453 SkGpuDevice grDevice(context, texture.get());
454 SkCanvas grCanvas(&grDevice);
455 drawPict(pic, &grCanvas, fScaleOversized ? scale : 1);
commit-bot@chromium.orgbda591c2014-02-13 15:29:03 +0000456 const SkBitmap& grBitmap = grDevice.accessBitmap(false);
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000457 if (fTestStep == kCompareBits) {
458 fPixelError = similarBits(grBitmap, bitmap);
459 int skTime = timePict(pic, &skCanvas);
460 int grTime = timePict(pic, &grCanvas);
461 fTime = skTime - grTime;
462 } else if (fTestStep == kEncodeFiles) {
463 SkString pngStr = make_png_name(fFilename);
464 const char* pngName = pngStr.c_str();
465 writePict(grBitmap, outGrDir, pngName);
466 writePict(bitmap, outSkDir, pngName);
467 }
468 }
469finish:
470 SkDELETE(pic);
471}
472
473static SkString makeStatusString(int dirNo) {
474 SkString statName;
475 statName.printf("stats%d.txt", dirNo);
476 SkString statusFile = make_filepath(0, outStatusDir, statName.c_str());
477 return statusFile;
478}
479
480class PreParser {
481public:
482 PreParser(int dirNo)
483 : fDirNo(dirNo)
484 , fIndex(0)
485 , fStatusPath(makeStatusString(dirNo)) {
486 if (!sk_exists(fStatusPath.c_str())) {
487 return;
488 }
489 SkFILEStream reader;
490 reader.setPath(fStatusPath.c_str());
491 while (fetch(reader, &fResults.push_back()))
492 ;
493 fResults.pop_back();
494 }
495
496 bool fetch(SkFILEStream& reader, TestResult* result) {
497 char c;
498 int i = 0;
499 result->init(fDirNo);
500 result->fPixelError = 0;
501 result->fTime = 0;
502 do {
503 bool readOne = reader.read(&c, 1) != 0;
504 if (!readOne) {
505 SkASSERT(i == 0);
506 return false;
507 }
508 if (c == ' ') {
509 result->fFilename[i++] = '\0';
510 break;
511 }
512 result->fFilename[i++] = c;
513 SkASSERT(i < kMaxLength);
514 } while (true);
515 do {
516 SkAssertResult(reader.read(&c, 1) != 0);
517 if (c == ' ') {
518 break;
519 }
520 SkASSERT(c >= '0' && c <= '9');
521 result->fPixelError = result->fPixelError * 10 + (c - '0');
522 } while (true);
523 bool minus = false;
524 do {
525 if (reader.read(&c, 1) == 0) {
526 break;
527 }
528 if (c == '\r' && reader.read(&c, 1) == 0) {
529 break;
530 }
531 if (c == '\n') {
532 break;
533 }
534 if (c == '-') {
535 minus = true;
536 continue;
537 }
538 SkASSERT(c >= '0' && c <= '9');
539 result->fTime = result->fTime * 10 + (c - '0');
540 } while (true);
541 if (minus) {
542 result->fTime = -result->fTime;
543 }
544 return true;
545 }
546
547 bool match(const SkString& filename, SkFILEWStream* stream, TestResult* result) {
548 if (fIndex < fResults.count()) {
549 *result = fResults[fIndex++];
550 SkASSERT(filename.equals(result->fFilename));
551 SkString outStr(result->status());
552 stream->write(outStr.c_str(), outStr.size());
553 stream->flush();
554 return true;
555 }
556 return false;
557 }
558
559private:
560 int fDirNo;
561 int fIndex;
562 SkTArray<TestResult, true> fResults;
563 SkString fStatusPath;
564};
565
566static bool initTest() {
567#if !defined SK_BUILD_FOR_WIN && !defined SK_BUILD_FOR_MAC
568 SK_CONF_SET("images.jpeg.suppressDecoderWarnings", true);
569 SK_CONF_SET("images.png.suppressDecoderWarnings", true);
570#endif
571 return make_out_dirs();
572}
573
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +0000574DEF_TEST(SkpSkGr, reporter) {
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000575 SkTArray<TestResult, true> errors;
576 if (!initTest()) {
577 return;
578 }
579 SkpSkGrThreadState state;
580 state.init(0);
581 int smallCount = 0;
582 for (int dirNo = 1; dirNo <= 100; ++dirNo) {
583 SkString pictDir = make_in_dir_name(dirNo);
584 SkASSERT(pictDir.size());
585 if (reporter->verbose()) {
586 SkDebugf("dirNo=%d\n", dirNo);
587 }
588 SkOSFile::Iter iter(pictDir.c_str(), "skp");
589 SkString filename;
590 int testCount = 0;
591 PreParser preParser(dirNo);
592 SkFILEWStream statusStream(makeStatusString(dirNo).c_str());
593 while (iter.next(&filename)) {
594 for (size_t index = 0; index < skipOverSkGrCount; ++index) {
595 if (skipOverSkGr[index].directory == dirNo
596 && strcmp(filename.c_str(), skipOverSkGr[index].filename) == 0) {
597 goto skipOver;
598 }
599 }
600 if (preParser.match(filename, &statusStream, &state.fResult)) {
601 addError(&state);
602 ++testCount;
603 goto checkEarlyExit;
604 }
605 if (state.fSmallestError > 5000000) {
606 goto breakOut;
607 }
608 {
609 TestResult& result = state.fResult;
610 result.test(dirNo, filename);
611 SkString outStr(result.status());
612 statusStream.write(outStr.c_str(), outStr.size());
613 statusStream.flush();
614 if (1) {
615 SkDebugf("%s", outStr.c_str());
616 }
617 bool noMatch = addError(&state);
618 if (noMatch) {
619 smallCount = 0;
620 } else if (++smallCount > 10000) {
621 goto breakOut;
622 }
623 }
624 ++testCount;
625 if (reporter->verbose()) {
626 if (testCount % 100 == 0) {
627 SkDebugf("#%d\n", testCount);
628 }
629 }
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +0000630 skipOver:
631 reporter->bumpTestCount();
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000632 checkEarlyExit:
633 if (1 && testCount == 20) {
634 break;
635 }
636 }
637 }
638breakOut:
639 if (reporter->verbose()) {
640 for (int index = 0; index < state.fFoundCount; ++index) {
641 SkDebugf("%d %s %d\n", state.fDirsFound[index], state.fFilesFound[index],
642 state.fError[index]);
643 }
644 }
645 for (int index = 0; index < state.fFoundCount; ++index) {
646 TestResult::Test(state.fDirsFound[index], state.fFilesFound[index], kEncodeFiles,
647 reporter->verbose());
648 if (reporter->verbose()) SkDebugf("+");
649 }
650}
651
652static void bumpCount(skiatest::Reporter* reporter, bool skipping) {
653 if (reporter->verbose()) {
654 static int threadTestCount;
655 sk_atomic_inc(&threadTestCount);
656 if (!skipping && threadTestCount % 100 == 0) {
657 SkDebugf("#%d\n", threadTestCount);
658 }
659 if (skipping && threadTestCount % 10000 == 0) {
660 SkDebugf("#%d\n", threadTestCount);
661 }
662 }
663}
664
665static void testSkGrMain(SkpSkGrThreadState* data) {
666 data->fResult.testOne();
667 bumpCount(data->fReporter, false);
668 data->fReporter->bumpTestCount();
669}
670
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +0000671DEF_TEST(SkpSkGrThreaded, reporter) {
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000672 if (!initTest()) {
673 return;
674 }
675 int threadCount = reporter->allowThreaded() ? 3 : 1;
676 SkpSkGrThreadedTestRunner testRunner(reporter, threadCount);
677 for (int dirIndex = 1; dirIndex <= 100; ++dirIndex) {
678 SkString pictDir = make_in_dir_name(dirIndex);
679 if (pictDir.size() == 0) {
680 continue;
681 }
682 SkOSFile::Iter iter(pictDir.c_str(), "skp");
683 SkString filename;
684 while (iter.next(&filename)) {
685 SkString pngName = make_png_name(filename.c_str());
686 SkString oldPng = make_filepath(dirIndex, outSkDir, pngName.c_str());
687 SkString newPng = make_filepath(dirIndex, outGrDir, pngName.c_str());
688 if (sk_exists(oldPng.c_str()) && sk_exists(newPng.c_str())) {
689 bumpCount(reporter, true);
690 continue;
691 }
692 for (size_t index = 0; index < skipOverSkGrCount; ++index) {
693 if (skipOverSkGr[index].directory == dirIndex
694 && strcmp(filename.c_str(), skipOverSkGr[index].filename) == 0) {
695 bumpCount(reporter, true);
696 goto skipOver;
697 }
698 }
699 *testRunner.fRunnables.append() = SkNEW_ARGS(SkpSkGrThreadedRunnable,
700 (&testSkGrMain, dirIndex, filename.c_str(), &testRunner));
701 skipOver:
702 ;
703 }
704 }
705 testRunner.render();
706 SkpSkGrThreadState& max = testRunner.fRunnables[0]->fState;
707 for (int dirIndex = 2; dirIndex <= 100; ++dirIndex) {
708 SkpSkGrThreadState& state = testRunner.fRunnables[dirIndex - 1]->fState;
709 for (int index = 0; index < state.fFoundCount; ++index) {
710 int maxIdx = max.fFoundCount;
711 if (maxIdx < kMaxFiles) {
712 max.fError[maxIdx] = state.fError[index];
713 strcpy(max.fFilesFound[maxIdx], state.fFilesFound[index]);
714 max.fDirsFound[maxIdx] = state.fDirsFound[index];
715 ++max.fFoundCount;
716 continue;
717 }
718 for (maxIdx = 0; maxIdx < max.fFoundCount; ++maxIdx) {
719 if (max.fError[maxIdx] < state.fError[index]) {
720 max.fError[maxIdx] = state.fError[index];
721 strcpy(max.fFilesFound[maxIdx], state.fFilesFound[index]);
722 max.fDirsFound[maxIdx] = state.fDirsFound[index];
723 break;
724 }
725 }
726 }
727 }
728 TestResult encoder;
729 encoder.fTestStep = kEncodeFiles;
730 for (int index = 0; index < max.fFoundCount; ++index) {
731 encoder.fDirNo = max.fDirsFound[index];
732 strcpy(encoder.fFilename, max.fFilesFound[index]);
733 encoder.testOne();
734 SkDebugf("+");
735 }
736}
737
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +0000738DEF_TEST(SkpSkGrOneOff, reporter) {
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000739 if (!initTest()) {
740 return;
741 }
742 int testIndex = 166;
743 int dirIndex = skipOverSkGr[testIndex - 166].directory;
744 SkString pictDir = make_in_dir_name(dirIndex);
745 if (pictDir.size() == 0) {
746 return;
747 }
748 SkString filename(skipOverSkGr[testIndex - 166].filename);
749 TestResult::Test(dirIndex, filename.c_str(), kCompareBits, reporter->verbose());
750 TestResult::Test(dirIndex, filename.c_str(), kEncodeFiles, reporter->verbose());
751}