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