blob: d2fa988c6c32a61b1e00b656e9c012a4bcd3d9b9 [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"
caryclark@google.com7eaa53d2013-10-02 14:49:34 +00004#include "SkColor.h"
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +00005#include "SkDevice.h"
6#include "SkCanvas.h"
caryclark@google.comcffbcc32013-06-04 17:59:42 +00007#include "SkImageDecoder.h"
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +00008#include "SkImageEncoder.h"
9#include "SkStream.h"
10#include "SkOSFile.h"
11#include "SkPicture.h"
12#include "SkString.h"
caryclark@google.com07e97fc2013-07-08 17:17:02 +000013
14#ifdef SK_BUILD_FOR_WIN
caryclark@google.com7eaa53d2013-10-02 14:49:34 +000015 #define PATH_SLASH "\\"
16 #define IN_DIR "D:" PATH_SLASH "skp"
17 #define OUT_DIR "D:" PATH_SLASH
caryclark@google.com07e97fc2013-07-08 17:17:02 +000018#else
caryclark@google.com7eaa53d2013-10-02 14:49:34 +000019 #define PATH_SLASH "/"
20 #if 1
21 #define IN_DIR "/usr/local/google/home/caryclark/new10k" PATH_SLASH
22 #define OUT_DIR "/usr/local/google/home/caryclark/out10k" PATH_SLASH
23 #else
24 #define IN_DIR "/usr/local/google/home/caryclark/6-18-13" PATH_SLASH
25 #define OUT_DIR "/usr/local/google/home/caryclark" PATH_SLASH
26 #endif
caryclark@google.com07e97fc2013-07-08 17:17:02 +000027#endif
28
29static const char pictDir[] = IN_DIR ;
30static const char outSkpClipDir[] = OUT_DIR "skpClip";
31static const char outOldClipDir[] = OUT_DIR "oldClip";
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +000032
caryclark@google.com7eaa53d2013-10-02 14:49:34 +000033static SkString make_filepath(const char* dir, const SkString& name) {
34 SkString path(dir);
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +000035 size_t len = strlen(dir);
caryclark@google.com07e97fc2013-07-08 17:17:02 +000036 if (len > 0 && dir[len - 1] != PATH_SLASH[0]) {
caryclark@google.com7eaa53d2013-10-02 14:49:34 +000037 path.append(PATH_SLASH);
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +000038 }
caryclark@google.com7eaa53d2013-10-02 14:49:34 +000039 path.append(name);
40 return path;
41}
42
43static SkString make_png_name(const SkString& filename) {
44 SkString pngName = SkString(filename);
45 pngName.remove(pngName.size() - 3, 3);
46 pngName.append("png");
47 return pngName;
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +000048}
49
caryclark@google.com07e97fc2013-07-08 17:17:02 +000050static void testOne(const SkString& filename) {
caryclark@google.com7eaa53d2013-10-02 14:49:34 +000051 if (filename == SkString("http___migracioncolombia_gov_co.skp")
52 || filename == SkString("http___miuki_info.skp")
53 ) {
54 return;
55 }
caryclark@google.com07e97fc2013-07-08 17:17:02 +000056#if DEBUG_SHOW_TEST_NAME
57 SkString testName(filename);
58 const char http[] = "http";
59 if (testName.startsWith(http)) {
60 testName.remove(0, sizeof(http) - 1);
61 }
62 while (testName.startsWith("_")) {
63 testName.remove(0, 1);
64 }
65 const char dotSkp[] = ".skp";
66 if (testName.endsWith(dotSkp)) {
67 size_t len = testName.size();
68 testName.remove(len - (sizeof(dotSkp) - 1), sizeof(dotSkp) - 1);
69 }
70 testName.prepend("skp");
71 testName.append("1");
72 strncpy(DEBUG_FILENAME_STRING, testName.c_str(), DEBUG_FILENAME_STRING_LENGTH);
73#endif
caryclark@google.com7eaa53d2013-10-02 14:49:34 +000074 SkString path = make_filepath(pictDir, filename);
caryclark@google.com07e97fc2013-07-08 17:17:02 +000075 SkFILEStream stream(path.c_str());
76 if (!stream.isValid()) {
77 return;
78 }
caryclark@google.com4fdbb222013-07-23 15:27:41 +000079 SkPicture* pic = SkPicture::CreateFromStream(&stream, &SkImageDecoder::DecodeMemory);
80 if (!pic) {
caryclark@google.com07e97fc2013-07-08 17:17:02 +000081 SkDebugf("unable to decode %s\n", filename.c_str());
82 return;
83 }
84 int width = pic->width();
85 int height = pic->height();
caryclark@google.com7eaa53d2013-10-02 14:49:34 +000086
caryclark@google.com07e97fc2013-07-08 17:17:02 +000087 SkBitmap bitmap;
caryclark@google.com7eaa53d2013-10-02 14:49:34 +000088 int scale = 1;
89 do {
90 bitmap.setConfig(SkBitmap::kARGB_8888_Config, (width + scale - 1) / scale,
91 (height + scale - 1) / scale);
92 bool success = bitmap.allocPixels();
93 bitmap.eraseColor(SK_ColorWHITE);
94 if (success) {
95 break;
96 }
97 SkDebugf("-%d-", scale);
98 } while ((scale *= 2) < 32);
99 if (scale >= 32) {
100 SkDebugf("unable to allocate bitmap for %s (w=%d h=%d)\n", filename.c_str(),
101 width, height);
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000102 return;
103 }
104 SkCanvas canvas(bitmap);
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000105 canvas.scale(1.0f / scale, 1.0f / scale);
106 SkString pngName = make_png_name(filename);
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000107 for (int i = 0; i < 2; ++i) {
108 bool useOp = i ? true : false;
109 canvas.setAllowSimplifyClip(useOp);
110 pic->draw(&canvas);
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000111 SkString outFile = make_filepath(useOp ? outSkpClipDir : outOldClipDir, pngName);
112 if (!SkImageEncoder::EncodeFile(outFile.c_str(), bitmap, SkImageEncoder::kPNG_Type,
113 100)) {
114 SkDebugf("unable to encode %s (width=%d height=%d)\n", pngName.c_str(),
115 bitmap.width(), bitmap.height());
116 }
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000117 }
118 SkDELETE(pic);
119}
120
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000121const char* tryFixed[] = {
122 0
123};
124
125size_t tryFixedCount = sizeof(tryFixed) / sizeof(tryFixed[0]);
126
127const char* skipOver[] = {
128 "http___carpetplanet_ru.skp", // cubic/cubic intersect
129 "http___carrot_is.skp", // bridgeOp() SkASSERT(unsortable || !current->done());
130
131/*!*/"http___dotsrc_org.skp", // asserts in png decode
132 "http___frauen_magazin_com.skp", // bridgeOp() SkASSERT(unsortable || !current->done());
133 "http___i_gino_com.skp", // unexpected cubic/quad coincidence
134 // {61, 857, 61, 789.06897, 116.068977, 734, 184, 734}
135 // {184, 734, 133.051727, 734, 97.0258636, 770.025879}
136 "http___ilkoora_com.skp", // assert wind sum != min32 from markDoneBinary / findNextOp #28k
137/*!*/"http___migracioncolombia_gov_co.skp", // crashes on picture decode
138 "http___mm4everfriends_com.skp", // bumpSpan/addTCoincident (from calcPartialCoincidentWinding)
139 "http___mtrk_uz.skp", // checkEnds() assert #36.3k
140 "http___pchappy_com_au.skp", // bridgeOp() assert unsortable || ! empty #37.2k
141 "http___sciality_com.skp", // bridgeOp() SkASSERT(unsortable || !current->done()); #32.4k
142/*!*/"http___sozialticker_com.skp", // asserts in png decode
143 "http___sudoestenegocios_com.skp", // assert fT < 1 in addTCoincident
144 "http___thesuburbanite_com.skp", // bridgeOp() SkASSERT(unsortable || !current->done());
145
146 "http___fluentin3months_com.skp", // calcCommonCoincidentWinding from calcPartialCoincidentWinding #38.3k
147 "http___teachersbadi_blogspot_in.skp", // calcCommonCoincidentWinding from calcPartialCoincidentWinding #53.4k
148 "http___wsms_ru.skp", // assert wind sum != min32 from markDoneBinary / findNextOp #49.5k
149 "http___voycer_de.skp", // calcCommonCoincidentWinding from calcPartialCoincidentWinding #47k
150 "http___77hz_jp.skp", // addTCancel from calcCoincidentWinding #47.1k
151
152 "http___hostloco_com.skp", // t < 0 AddIntersectsT
153/*!*/"http___oggicronaca_it.skp", // asserts in png decode
154 "http___sergeychunkevich_com.skp", // t < 0 AddIntersectsT
155 "http___tracksflow_com.skp", // assert otherEnd >= 0 from nextChase
156 "http___autobutler_dk.skp", // t < 0 AddIntersectsT
157 "http___onlinecollege_org.skp", // bridgeOp() assert unsortable || ! empty #100.1k
158 "http___national_com_au.skp", // bridgeOp() assert unsortable || ! empty #110.2k
159/*!*/"http___anitadongre_com.skp", // exceptionally large width and height
160 "http___rentacheat_com.skp", // bridgeOp() assert unsortable || ! empty #110.8k
161/*!*/"http___gruesse_de.skp", // asserts in png decode
162/*!*/"http___crn_in.png", // width=1250047
163 "http___breakmystyle_com.skp", // assert qPt == lPt in quad intersection
164 "http___naoxrane_ru.skp", // assert t4+...t0 == 0 in quartic roots #128.3k
165 "http___tcmevents_org.skp", // assert in addTCoincident (from calcPartialCoincidentWinding) #143.3k
166/*!*/"http___listbuildingcashsecrets_com.skp", // asserts in png decode #152.7k
167/*!*/"http___skyscraperpage_com.skp", // asserts in png decode #155.5k
168 "http___mlk_com.skp", // bridgeOp() assert unsortable || ! empty #158.7k
169 "http___sd_graphic_net.skp", // bridgeOp() assert unsortable || ! empty #163.3k
170 "http___kopepasah_com.skp", // checkEnds() assert #188.2k
171/*!*/"http___darkreloaded_com.skp", // asserts in png decode #188.4k
172 "http___redbullskatearcade_es.skp", // bridgeOp() assert unsortable || ! empty #192.5k
173 "http___partainasdemo250_org.skp", // bridgeOp() assert unsortable || ! empty #200.2k
174
175// these failures are from the new 10k set
176 "http___www_freerepublic_com_.skp", // assert in opangle <
177 "http___www_lavoixdunord_fr_.skp", // bridgeOp() assert unsortable || ! empty
178 "http___www_booking_com_.skp", // bridgeOp() assert unsortable || ! empty
179 "http___www_fj_p_com_.skp", // markWinding assert from findChaseOp
180 "http___www_leadpages_net_.skp", // assert in opangle <
181 "http___www_despegar_com_mx_.skp", // bridgeOp() assert unsortable || ! empty
182};
183
184size_t skipOverCount = sizeof(skipOver) / sizeof(skipOver[0]);
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000185
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +0000186static void PathOpsSkpClipTest(skiatest::Reporter* reporter) {
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +0000187 SkOSFile::Iter iter(pictDir, "skp");
188 SkString filename;
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000189 int testCount = 0;
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +0000190 while (iter.next(&filename)) {
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000191 SkString pngName = make_png_name(filename);
192 SkString oldPng = make_filepath(outOldClipDir, pngName);
193 SkString newPng = make_filepath(outSkpClipDir, pngName);
194 if (sk_exists(oldPng.c_str()) && sk_exists(newPng.c_str())) {
195 reporter->bumpTestCount();
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +0000196 continue;
197 }
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000198 for (size_t index = 0; index < skipOverCount; ++index) {
199 if (skipOver[index] && strcmp(filename.c_str(), skipOver[index]) == 0) {
200 reporter->bumpTestCount();
201 goto skipOver;
202 }
203 }
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000204 testOne(filename);
205 if (reporter->verbose()) {
206 SkDebugf(".");
207 if (++testCount % 100 == 0) {
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000208 SkDebugf("%d\n", testCount);
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000209 }
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +0000210 }
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000211skipOver:
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +0000212 reporter->bumpTestCount();
213 }
214}
215
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000216static void bumpCount(skiatest::Reporter* reporter, bool skipping) {
217 if (reporter->verbose()) {
218 static int threadTestCount;
219 if (!skipping) {
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000220 SkDebugf(".");
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000221 }
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000222 sk_atomic_inc(&threadTestCount);
223 if (!skipping && threadTestCount % 100 == 0) {
224 SkDebugf("%d\n", threadTestCount);
225 }
226 if (skipping && threadTestCount % 10000 == 0) {
227 SkDebugf("%d\n", threadTestCount);
228 }
229 }
230}
231
232static void testSkpClipMain(PathOpsThreadState* data) {
233 SkString str(data->fSerialNo);
234 testOne(str);
235 bumpCount(data->fReporter, false);
236 data->fReporter->bumpTestCount();
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000237}
238
239static void PathOpsSkpClipThreadedTest(skiatest::Reporter* reporter) {
240 int threadCount = initializeTests(reporter, "skpClipThreadedTest");
241 PathOpsThreadedTestRunner testRunner(reporter, threadCount);
242 SkOSFile::Iter iter(pictDir, "skp");
243 SkString filename;
244 while (iter.next(&filename)) {
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000245 SkString pngName = make_png_name(filename);
246 SkString oldPng = make_filepath(outOldClipDir, pngName);
247 SkString newPng = make_filepath(outSkpClipDir, pngName);
248 if (sk_exists(oldPng.c_str()) && sk_exists(newPng.c_str())) {
249 bumpCount(reporter, true);
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000250 continue;
251 }
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000252 for (size_t index = 0; index < skipOverCount; ++index) {
253 if (skipOver[index] && strcmp(filename.c_str(), skipOver[index]) == 0) {
254 bumpCount(reporter, true);
255 goto skipOver;
256 }
257 }
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000258 *testRunner.fRunnables.append() = SkNEW_ARGS(PathOpsThreadedRunnable,
259 (&testSkpClipMain, filename.c_str(), &testRunner));
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000260skipOver:
261 ;
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000262 }
263 testRunner.render();
264}
265
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000266static void PathOpsSkpClipFixedTest(skiatest::Reporter* reporter) {
267 for (size_t index = 0; index < tryFixedCount; ) {
268 SkString filename(tryFixed[index]);
269 testOne(filename);
270 ++index;
271 if (reporter->verbose()) {
272 SkDebugf(".");
273 if (index % 100 == 0) {
274 SkDebugf("\n");
275 }
276 }
277 reporter->bumpTestCount();
278 }
279}
280
caryclark@google.comfa2aeee2013-07-15 13:29:13 +0000281static void PathOpsSkpClipOneOffTest(skiatest::Reporter* reporter) {
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000282 SkString filename("http___78_cn_.skp");
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000283 testOne(filename);
284}
285
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +0000286#include "TestClassDef.h"
287DEFINE_TESTCLASS_SHORT(PathOpsSkpClipTest)
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000288
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000289DEFINE_TESTCLASS_SHORT(PathOpsSkpClipFixedTest)
290
caryclark@google.comfa2aeee2013-07-15 13:29:13 +0000291DEFINE_TESTCLASS_SHORT(PathOpsSkpClipOneOffTest)
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000292
293DEFINE_TESTCLASS_SHORT(PathOpsSkpClipThreadedTest)