Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: tests/SkpSkGrTest.cpp

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

Powered by Google App Engine
This is Rietveld 408576698