blob: f46ad976d528f6d82e75c14169ce97a27df3ba29 [file] [log] [blame]
caryclark@google.com07e97fc2013-07-08 17:17:02 +00001#include "PathOpsExtendedTest.h"
2#include "PathOpsThreadedCommon.h"
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +00003#include "SkBitmap.h"
4#include "SkDevice.h"
5#include "SkCanvas.h"
caryclark@google.comcffbcc32013-06-04 17:59:42 +00006#include "SkImageDecoder.h"
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +00007#include "SkImageEncoder.h"
8#include "SkStream.h"
9#include "SkOSFile.h"
10#include "SkPicture.h"
11#include "SkString.h"
caryclark@google.com07e97fc2013-07-08 17:17:02 +000012
13#ifdef SK_BUILD_FOR_WIN
14#define PATH_SLASH "\\"
15#define IN_DIR "D:" PATH_SLASH "skp"
16#define OUT_DIR "D:" PATH_SLASH
17#else
18#define PATH_SLASH "/"
19#define IN_DIR "/Volumes/Untitled" PATH_SLASH
20#define OUT_DIR PATH_SLASH
21#endif
22
23static const char pictDir[] = IN_DIR ;
24static const char outSkpClipDir[] = OUT_DIR "skpClip";
25static const char outOldClipDir[] = OUT_DIR "oldClip";
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +000026
27static void make_filepath(SkString* path, const char* dir, const SkString& name) {
28 size_t len = strlen(dir);
29 path->set(dir);
caryclark@google.com07e97fc2013-07-08 17:17:02 +000030 if (len > 0 && dir[len - 1] != PATH_SLASH[0]) {
31 path->append(PATH_SLASH);
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +000032 }
33 path->append(name);
34}
35
caryclark@google.com07e97fc2013-07-08 17:17:02 +000036static void testOne(const SkString& filename) {
37#if DEBUG_SHOW_TEST_NAME
38 SkString testName(filename);
39 const char http[] = "http";
40 if (testName.startsWith(http)) {
41 testName.remove(0, sizeof(http) - 1);
42 }
43 while (testName.startsWith("_")) {
44 testName.remove(0, 1);
45 }
46 const char dotSkp[] = ".skp";
47 if (testName.endsWith(dotSkp)) {
48 size_t len = testName.size();
49 testName.remove(len - (sizeof(dotSkp) - 1), sizeof(dotSkp) - 1);
50 }
51 testName.prepend("skp");
52 testName.append("1");
53 strncpy(DEBUG_FILENAME_STRING, testName.c_str(), DEBUG_FILENAME_STRING_LENGTH);
54#endif
55 SkString path;
56 make_filepath(&path, pictDir, filename);
57 SkFILEStream stream(path.c_str());
58 if (!stream.isValid()) {
59 return;
60 }
61 bool success;
62 SkPicture* pic = SkNEW_ARGS(SkPicture, (&stream, &success, &SkImageDecoder::DecodeMemory));
63 if (!success) {
64 SkDebugf("unable to decode %s\n", filename.c_str());
65 return;
66 }
67 int width = pic->width();
68 int height = pic->height();
69 SkBitmap bitmap;
70 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
71 success = bitmap.allocPixels();
72 if (!success) {
73 SkDebugf("unable to allocate bitmap for %s\n", filename.c_str());
74 return;
75 }
76 SkCanvas canvas(bitmap);
77 SkString pngName(filename);
78 pngName.remove(pngName.size() - 3, 3);
79 pngName.append("png");
80 for (int i = 0; i < 2; ++i) {
81 bool useOp = i ? true : false;
82 canvas.setAllowSimplifyClip(useOp);
83 pic->draw(&canvas);
84 SkString outFile;
85 make_filepath(&outFile, useOp ? outSkpClipDir : outOldClipDir, pngName);
86 SkImageEncoder::EncodeFile(outFile.c_str(), bitmap, SkImageEncoder::kPNG_Type, 100);
87 }
88 SkDELETE(pic);
89}
90
91const char skipBefore[] = "http___health_com.skp";
92
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +000093static void PathOpsSkpClipTest(skiatest::Reporter* reporter) {
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +000094 SkOSFile::Iter iter(pictDir, "skp");
95 SkString filename;
caryclark@google.com07e97fc2013-07-08 17:17:02 +000096 int testCount = 0;
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +000097 while (iter.next(&filename)) {
caryclark@google.com07e97fc2013-07-08 17:17:02 +000098 if (strcmp(filename.c_str(), skipBefore) < 0) {
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +000099 continue;
100 }
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000101 testOne(filename);
102 if (reporter->verbose()) {
103 SkDebugf(".");
104 if (++testCount % 100 == 0) {
105 SkDebugf("\n");
106 }
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +0000107 }
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +0000108 reporter->bumpTestCount();
109 }
110}
111
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000112static void testSkpClipMain(PathOpsThreadState* data) {
113 SkString str(data->fSerialNo);
114 testOne(str);
115 if (data->fReporter->verbose()) {
116 SkDebugf(".");
117 static int threadTestCount;
118 sk_atomic_inc(&threadTestCount);
119 if (threadTestCount % 100 == 0) {
120 SkDebugf("\n");
121 }
122 }
123}
124
125static void PathOpsSkpClipThreadedTest(skiatest::Reporter* reporter) {
126 int threadCount = initializeTests(reporter, "skpClipThreadedTest");
127 PathOpsThreadedTestRunner testRunner(reporter, threadCount);
128 SkOSFile::Iter iter(pictDir, "skp");
129 SkString filename;
130 while (iter.next(&filename)) {
131 if (strcmp(filename.c_str(), skipBefore) < 0) {
132 continue;
133 }
134 *testRunner.fRunnables.append() = SkNEW_ARGS(PathOpsThreadedRunnable,
135 (&testSkpClipMain, filename.c_str(), &testRunner));
136 reporter->bumpTestCount();
137 }
138 testRunner.render();
139}
140
141static void PathOpsSkpClipTestOne(skiatest::Reporter* reporter) {
142 SkString filename(skipBefore);
143 testOne(filename);
144}
145
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +0000146#include "TestClassDef.h"
147DEFINE_TESTCLASS_SHORT(PathOpsSkpClipTest)
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000148
149DEFINE_TESTCLASS_SHORT(PathOpsSkpClipTestOne)
150
151DEFINE_TESTCLASS_SHORT(PathOpsSkpClipThreadedTest)