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