blob: 456c6abf6f0cee33744ee72ddd536bee60815fd3 [file] [log] [blame]
scroggo478652e2015-03-25 07:11:02 -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 */
7
jcgregorio3b27ade2014-11-13 08:06:40 -08008#include "CrashHandler.h"
mtklein748ca3b2015-01-15 10:56:12 -08009#include "DMJsonWriter.h"
10#include "DMSrcSink.h"
tomhudsoneebc39a2015-02-23 12:18:05 -080011#include "DMSrcSinkAndroid.h"
mtklein748ca3b2015-01-15 10:56:12 -080012#include "OverwriteLine.h"
13#include "ProcStats.h"
14#include "SkBBHFactory.h"
mtklein62bd1a62015-01-27 14:46:26 -080015#include "SkChecksum.h"
scroggocc2feb12015-08-14 08:32:46 -070016#include "SkCodec.h"
caryclark17f0b6d2014-07-22 10:15:34 -070017#include "SkCommonFlags.h"
kkinnunen3e980c32015-12-23 01:33:00 -080018#include "SkCommonFlagsConfig.h"
caryclark83ca6282015-06-10 09:31:09 -070019#include "SkFontMgr.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000020#include "SkForceLinking.h"
21#include "SkGraphics.h"
mtklein748ca3b2015-01-15 10:56:12 -080022#include "SkMD5.h"
mtklein1b249332015-07-07 12:21:21 -070023#include "SkMutex.h"
mtklein1d0f1642014-09-08 08:05:18 -070024#include "SkOSFile.h"
mtkleina82f5622015-02-20 12:30:19 -080025#include "SkTHash.h"
mtklein406654b2014-09-03 15:34:37 -070026#include "SkTaskGroup.h"
mtkleinde6fc2b2015-03-12 06:28:54 -070027#include "SkThreadUtils.h"
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000028#include "Test.h"
mtklein748ca3b2015-01-15 10:56:12 -080029#include "Timer.h"
caryclark83ca6282015-06-10 09:31:09 -070030#include "sk_tool_utils.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000031
halcanary7a14b312015-10-01 07:28:13 -070032#ifdef SK_PDF_IMAGE_STATS
33extern void SkPDFImageDumpStats();
34#endif
35
mtkleina5114d72015-08-24 13:27:01 -070036#include "png.h"
37
bungeman60e0fee2015-08-26 05:15:46 -070038#include <stdlib.h>
39
scroggo27a58342015-10-28 08:56:41 -070040#ifndef SK_BUILD_FOR_WIN32
41 #include <unistd.h>
42#endif
43
djsollen54416de2015-04-03 07:24:48 -070044DEFINE_string(src, "tests gm skp image", "Source types to test.");
mtklein748ca3b2015-01-15 10:56:12 -080045DEFINE_bool(nameByHash, false,
46 "If true, write to FLAGS_writePath[0]/<hash>.png instead of "
djsollen54416de2015-04-03 07:24:48 -070047 "to FLAGS_writePath[0]/<config>/<sourceType>/<sourceOptions>/<name>.png");
mtklein748ca3b2015-01-15 10:56:12 -080048DEFINE_bool2(pathOpsExtended, x, false, "Run extended pathOps tests.");
mtkleind603b222015-02-17 11:13:33 -080049DEFINE_string(matrix, "1 0 0 1",
50 "2x2 scale+skew matrix to apply or upright when using "
51 "'matrix' or 'upright' in config.");
mtklein82d28432015-01-15 12:46:02 -080052DEFINE_bool(gpu_threading, false, "Allow GPU work to run on multiple threads?");
mtklein@google.comd36522d2013-10-16 13:02:15 +000053
mtkleina2ef6422015-01-15 13:44:22 -080054DEFINE_string(blacklist, "",
djsollen54416de2015-04-03 07:24:48 -070055 "Space-separated config/src/srcOptions/name quadruples to blacklist. '_' matches anything. E.g. \n"
56 "'--blacklist gpu skp _ _' will blacklist all SKPs drawn into the gpu config.\n"
57 "'--blacklist gpu skp _ _ 8888 gm _ aarects' will also blacklist the aarects GM on 8888.");
mtkleina2ef6422015-01-15 13:44:22 -080058
mtklein62bd1a62015-01-27 14:46:26 -080059DEFINE_string2(readPath, r, "", "If set check for equality with golden results in this directory.");
60
borenet09ed4802015-04-03 14:15:33 -070061DEFINE_string(uninterestingHashesFile, "",
62 "File containing a list of uninteresting hashes. If a result hashes to something in "
63 "this list, no image is written for that result.");
64
mtklein6393c062015-04-27 08:45:01 -070065DEFINE_int32(shards, 1, "We're splitting source data into this many shards.");
66DEFINE_int32(shard, 0, "Which shard do I run?");
67
mtklein@google.comd36522d2013-10-16 13:02:15 +000068__SK_FORCE_IMAGE_DECODER_LINKING;
mtklein748ca3b2015-01-15 10:56:12 -080069using namespace DM;
mtklein@google.comd36522d2013-10-16 13:02:15 +000070
mtklein748ca3b2015-01-15 10:56:12 -080071/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
72
mtkleinf27f08b2015-11-03 06:54:24 -080073static double now_ms() { return SkTime::GetNSecs() * 1e-6; }
74
mtklein748ca3b2015-01-15 10:56:12 -080075SK_DECLARE_STATIC_MUTEX(gFailuresMutex);
76static SkTArray<SkString> gFailures;
77
78static void fail(ImplicitString err) {
79 SkAutoMutexAcquire lock(gFailuresMutex);
80 SkDebugf("\n\nFAILURE: %s\n\n", err.c_str());
81 gFailures.push_back(err);
halcanary9e398f72015-01-10 11:18:04 -080082}
83
mtkleinb37cb412015-03-18 05:27:14 -070084static int32_t gPending = 0; // Atomic. Total number of running and queued tasks.
85
mtkleinbc4e0032015-12-09 08:37:35 -080086SK_DECLARE_STATIC_MUTEX(gRunningAndTallyMutex);
87static SkTArray<SkString> gRunning;
88static SkTHashMap<SkString, int> gNoteTally;
mtklein748ca3b2015-01-15 10:56:12 -080089
mtkleinb9eb4ac2015-02-02 18:26:03 -080090static void done(double ms,
djsollen54416de2015-04-03 07:24:48 -070091 ImplicitString config, ImplicitString src, ImplicitString srcOptions,
92 ImplicitString name, ImplicitString note, ImplicitString log) {
93 SkString id = SkStringPrintf("%s %s %s %s", config.c_str(), src.c_str(),
94 srcOptions.c_str(), name.c_str());
mtkleinb37cb412015-03-18 05:27:14 -070095 {
mtkleinbc4e0032015-12-09 08:37:35 -080096 SkAutoMutexAcquire lock(gRunningAndTallyMutex);
mtkleinb37cb412015-03-18 05:27:14 -070097 for (int i = 0; i < gRunning.count(); i++) {
98 if (gRunning[i] == id) {
99 gRunning.removeShuffle(i);
100 break;
101 }
102 }
mtkleinbc4e0032015-12-09 08:37:35 -0800103 if (!note.isEmpty()) {
104 if (int* tally = gNoteTally.find(note)) {
105 *tally += 1;
106 } else {
107 gNoteTally.set(note, 1);
108 }
109 }
mtkleinb37cb412015-03-18 05:27:14 -0700110 }
mtkleinb9eb4ac2015-02-02 18:26:03 -0800111 if (!log.isEmpty()) {
112 log.prepend("\n");
113 }
mtklein6dee2ad2015-02-05 09:53:44 -0800114 auto pending = sk_atomic_dec(&gPending)-1;
mtkleinbc4e0032015-12-09 08:37:35 -0800115 if (!FLAGS_quiet && note.isEmpty()) {
116 SkDebugf("%s(%4d/%-4dMB %6d) %s\t%s%s", FLAGS_verbose ? "\n" : kSkOverwriteLine
reed50bc0512015-05-19 14:13:31 -0700117 , sk_tools::getCurrResidentSetSizeMB()
118 , sk_tools::getMaxResidentSetSizeMB()
119 , pending
120 , HumanizeMs(ms).c_str()
121 , id.c_str()
reed50bc0512015-05-19 14:13:31 -0700122 , log.c_str());
123 }
mtkleina17241b2015-01-23 05:48:00 -0800124 // We write our dm.json file every once in a while in case we crash.
125 // Notice this also handles the final dm.json when pending == 0.
126 if (pending % 500 == 0) {
127 JsonWriter::DumpJson();
128 }
mtklein@google.comd36522d2013-10-16 13:02:15 +0000129}
130
djsollen54416de2015-04-03 07:24:48 -0700131static void start(ImplicitString config, ImplicitString src,
132 ImplicitString srcOptions, ImplicitString name) {
133 SkString id = SkStringPrintf("%s %s %s %s", config.c_str(), src.c_str(),
134 srcOptions.c_str(), name.c_str());
mtkleinbc4e0032015-12-09 08:37:35 -0800135 SkAutoMutexAcquire lock(gRunningAndTallyMutex);
mtkleinb37cb412015-03-18 05:27:14 -0700136 gRunning.push_back(id);
137}
138
mtklein748ca3b2015-01-15 10:56:12 -0800139/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
mtklein114c3cd2015-01-15 10:15:02 -0800140
mtklein62bd1a62015-01-27 14:46:26 -0800141struct Gold : public SkString {
mtkleina82f5622015-02-20 12:30:19 -0800142 Gold() : SkString("") {}
djsollen54416de2015-04-03 07:24:48 -0700143 Gold(ImplicitString sink, ImplicitString src, ImplicitString srcOptions,
144 ImplicitString name, ImplicitString md5)
mtklein62bd1a62015-01-27 14:46:26 -0800145 : SkString("") {
146 this->append(sink);
147 this->append(src);
djsollen54416de2015-04-03 07:24:48 -0700148 this->append(srcOptions);
mtklein62bd1a62015-01-27 14:46:26 -0800149 this->append(name);
150 this->append(md5);
mtklein62bd1a62015-01-27 14:46:26 -0800151 }
mtkleinc8d1dd42015-10-15 12:23:01 -0700152 struct Hash {
153 uint32_t operator()(const Gold& g) const {
154 return SkGoodHash()((const SkString&)g);
155 }
156 };
mtklein62bd1a62015-01-27 14:46:26 -0800157};
mtkleina82f5622015-02-20 12:30:19 -0800158static SkTHashSet<Gold, Gold::Hash> gGold;
mtklein62bd1a62015-01-27 14:46:26 -0800159
160static void add_gold(JsonWriter::BitmapResult r) {
djsollen54416de2015-04-03 07:24:48 -0700161 gGold.add(Gold(r.config, r.sourceType, r.sourceOptions, r.name, r.md5));
mtklein62bd1a62015-01-27 14:46:26 -0800162}
163
164static void gather_gold() {
165 if (!FLAGS_readPath.isEmpty()) {
166 SkString path(FLAGS_readPath[0]);
167 path.append("/dm.json");
168 if (!JsonWriter::ReadJson(path.c_str(), add_gold)) {
169 fail(SkStringPrintf("Couldn't read %s for golden results.", path.c_str()));
170 }
171 }
172}
173
174/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
175
borenet09ed4802015-04-03 14:15:33 -0700176static SkTHashSet<SkString> gUninterestingHashes;
177
178static void gather_uninteresting_hashes() {
179 if (!FLAGS_uninterestingHashesFile.isEmpty()) {
180 SkAutoTUnref<SkData> data(SkData::NewFromFileName(FLAGS_uninterestingHashesFile[0]));
mtkleincc334b32015-09-22 11:43:53 -0700181 if (!data) {
182 SkDebugf("WARNING: unable to read uninteresting hashes from %s\n",
183 FLAGS_uninterestingHashesFile[0]);
184 return;
185 }
borenet09ed4802015-04-03 14:15:33 -0700186 SkTArray<SkString> hashes;
187 SkStrSplit((const char*)data->data(), "\n", &hashes);
188 for (const SkString& hash : hashes) {
189 gUninterestingHashes.add(hash);
190 }
mtklein136baaa2016-02-03 11:21:45 -0800191 SkDebugf("FYI: loaded %d distinct uninteresting hashes from %d lines\n",
192 gUninterestingHashes.count(), hashes.count());
borenet09ed4802015-04-03 14:15:33 -0700193 }
194}
195
196/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
197
mtkleine0effd62015-07-29 06:37:28 -0700198struct TaggedSrc : public SkAutoTDelete<Src> {
msarett9e707a02015-09-01 14:57:57 -0700199 ImplicitString tag;
200 ImplicitString options;
mtkleine0effd62015-07-29 06:37:28 -0700201};
202
203struct TaggedSink : public SkAutoTDelete<Sink> {
kkinnunen3e980c32015-12-23 01:33:00 -0800204 SkString tag;
djsollen54416de2015-04-03 07:24:48 -0700205};
mtklein748ca3b2015-01-15 10:56:12 -0800206
207static const bool kMemcpyOK = true;
208
mtkleine0effd62015-07-29 06:37:28 -0700209static SkTArray<TaggedSrc, kMemcpyOK> gSrcs;
210static SkTArray<TaggedSink, kMemcpyOK> gSinks;
mtklein748ca3b2015-01-15 10:56:12 -0800211
mtklein6393c062015-04-27 08:45:01 -0700212static bool in_shard() {
213 static int N = 0;
214 return N++ % FLAGS_shards == FLAGS_shard;
215}
216
msarett9e707a02015-09-01 14:57:57 -0700217static void push_src(ImplicitString tag, ImplicitString options, Src* s) {
mtklein748ca3b2015-01-15 10:56:12 -0800218 SkAutoTDelete<Src> src(s);
mtklein6393c062015-04-27 08:45:01 -0700219 if (in_shard() &&
msarett9e707a02015-09-01 14:57:57 -0700220 FLAGS_src.contains(tag.c_str()) &&
mtklein748ca3b2015-01-15 10:56:12 -0800221 !SkCommandLineFlags::ShouldSkip(FLAGS_match, src->name().c_str())) {
mtkleine0effd62015-07-29 06:37:28 -0700222 TaggedSrc& s = gSrcs.push_back();
mtklein748ca3b2015-01-15 10:56:12 -0800223 s.reset(src.detach());
224 s.tag = tag;
djsollen54416de2015-04-03 07:24:48 -0700225 s.options = options;
mtklein114c3cd2015-01-15 10:15:02 -0800226 }
mtklein748ca3b2015-01-15 10:56:12 -0800227}
mtklein114c3cd2015-01-15 10:15:02 -0800228
msarett9e707a02015-09-01 14:57:57 -0700229static void push_codec_src(Path path, CodecSrc::Mode mode, CodecSrc::DstColorType dstColorType,
scroggoc5560be2016-02-03 09:42:42 -0800230 SkAlphaType dstAlphaType, float scale) {
msarett9e707a02015-09-01 14:57:57 -0700231 SkString folder;
232 switch (mode) {
233 case CodecSrc::kCodec_Mode:
234 folder.append("codec");
235 break;
msarettbb25b532016-01-13 09:31:39 -0800236 case CodecSrc::kCodecZeroInit_Mode:
237 folder.append("codec_zero_init");
238 break;
msarett9e707a02015-09-01 14:57:57 -0700239 case CodecSrc::kScanline_Mode:
240 folder.append("scanline");
241 break;
msarett9e707a02015-09-01 14:57:57 -0700242 case CodecSrc::kStripe_Mode:
243 folder.append("stripe");
244 break;
245 case CodecSrc::kSubset_Mode:
msarett36c37962015-09-02 13:20:52 -0700246 folder.append("codec_subset");
msarett9e707a02015-09-01 14:57:57 -0700247 break;
msarettb714fb02016-01-22 14:46:42 -0800248 case CodecSrc::kGen_Mode:
249 folder.append("gen");
250 break;
msarett9e707a02015-09-01 14:57:57 -0700251 }
252
253 switch (dstColorType) {
254 case CodecSrc::kGrayscale_Always_DstColorType:
255 folder.append("_kGray8");
256 break;
257 case CodecSrc::kIndex8_Always_DstColorType:
258 folder.append("_kIndex8");
259 break;
260 default:
261 break;
262 }
263
scroggoc5560be2016-02-03 09:42:42 -0800264 switch (dstAlphaType) {
265 case kOpaque_SkAlphaType:
266 folder.append("_opaque");
267 break;
268 case kPremul_SkAlphaType:
269 folder.append("_premul");
270 break;
271 case kUnpremul_SkAlphaType:
272 folder.append("_unpremul");
273 break;
274 default:
275 break;
276 }
277
msarett9e707a02015-09-01 14:57:57 -0700278 if (1.0f != scale) {
279 folder.appendf("_%.3f", scale);
280 }
281
scroggoc5560be2016-02-03 09:42:42 -0800282 CodecSrc* src = new CodecSrc(path, mode, dstColorType, dstAlphaType, scale);
msarett9e707a02015-09-01 14:57:57 -0700283 push_src("image", folder, src);
284}
285
msarett3d9d7a72015-10-21 10:27:10 -0700286static void push_android_codec_src(Path path, AndroidCodecSrc::Mode mode,
scroggoc5560be2016-02-03 09:42:42 -0800287 CodecSrc::DstColorType dstColorType, SkAlphaType dstAlphaType, int sampleSize) {
msarett3d9d7a72015-10-21 10:27:10 -0700288 SkString folder;
289 switch (mode) {
290 case AndroidCodecSrc::kFullImage_Mode:
291 folder.append("scaled_codec");
292 break;
293 case AndroidCodecSrc::kDivisor_Mode:
294 folder.append("scaled_codec_divisor");
295 break;
296 }
297
298 switch (dstColorType) {
299 case CodecSrc::kGrayscale_Always_DstColorType:
300 folder.append("_kGray8");
301 break;
302 case CodecSrc::kIndex8_Always_DstColorType:
303 folder.append("_kIndex8");
304 break;
305 default:
306 break;
307 }
308
scroggoc5560be2016-02-03 09:42:42 -0800309 switch (dstAlphaType) {
310 case kOpaque_SkAlphaType:
311 folder.append("_opaque");
312 break;
313 case kPremul_SkAlphaType:
314 folder.append("_premul");
315 break;
msarett9e9444c2016-02-03 12:39:10 -0800316 case kUnpremul_SkAlphaType:
317 folder.append("_unpremul");
318 break;
scroggoc5560be2016-02-03 09:42:42 -0800319 default:
320 break;
321 }
322
msarett3d9d7a72015-10-21 10:27:10 -0700323 if (1 != sampleSize) {
msarett4b0778e2015-11-13 09:59:11 -0800324 folder.appendf("_%.3f", 1.0f / (float) sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700325 }
326
scroggoc5560be2016-02-03 09:42:42 -0800327 AndroidCodecSrc* src = new AndroidCodecSrc(path, mode, dstColorType, dstAlphaType, sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700328 push_src("image", folder, src);
329}
330
msarett438b2ad2015-04-09 12:43:10 -0700331static void push_codec_srcs(Path path) {
332 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str()));
333 if (!encoded) {
334 SkDebugf("Couldn't read %s.", path.c_str());
335 return;
336 }
337 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
halcanary96fcdcc2015-08-27 07:41:13 -0700338 if (nullptr == codec.get()) {
msarett438b2ad2015-04-09 12:43:10 -0700339 SkDebugf("Couldn't create codec for %s.", path.c_str());
340 return;
341 }
342
msarett36c37962015-09-02 13:20:52 -0700343 // Native Scales
msarett0a242972015-06-11 14:27:27 -0700344 // TODO (msarett): Implement scaling tests for SkImageDecoder in order to compare with these
345 // tests. SkImageDecoder supports downscales by integer factors.
emmaleer8f4ba762015-08-14 07:44:46 -0700346 // SkJpegCodec natively supports scaling to: 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875
msarett36c37962015-09-02 13:20:52 -0700347 const float nativeScales[] = { 0.125f, 0.25f, 0.375f, 0.5f, 0.625f, 0.750f, 0.875f, 1.0f };
msarett438b2ad2015-04-09 12:43:10 -0700348
msarettbb25b532016-01-13 09:31:39 -0800349 const CodecSrc::Mode nativeModes[] = { CodecSrc::kCodec_Mode, CodecSrc::kCodecZeroInit_Mode,
msarettb714fb02016-01-22 14:46:42 -0800350 CodecSrc::kScanline_Mode, CodecSrc::kStripe_Mode, CodecSrc::kSubset_Mode,
351 CodecSrc::kGen_Mode };
msarett9e707a02015-09-01 14:57:57 -0700352
msarett36c37962015-09-02 13:20:52 -0700353 CodecSrc::DstColorType colorTypes[3];
354 uint32_t numColorTypes;
355 switch (codec->getInfo().colorType()) {
356 case kGray_8_SkColorType:
357 // FIXME: Is this a long term solution for testing wbmps decodes to kIndex8?
halcanary6950de62015-11-07 05:29:00 -0800358 // Further discussion on this topic is at https://bug.skia.org/3683 .
msarett3d9d7a72015-10-21 10:27:10 -0700359 // This causes us to try to convert grayscale jpegs to kIndex8. We currently
360 // fail non-fatally in this case.
msarett36c37962015-09-02 13:20:52 -0700361 colorTypes[0] = CodecSrc::kGetFromCanvas_DstColorType;
362 colorTypes[1] = CodecSrc::kGrayscale_Always_DstColorType;
363 colorTypes[2] = CodecSrc::kIndex8_Always_DstColorType;
364 numColorTypes = 3;
365 break;
366 case kIndex_8_SkColorType:
367 colorTypes[0] = CodecSrc::kGetFromCanvas_DstColorType;
368 colorTypes[1] = CodecSrc::kIndex8_Always_DstColorType;
369 numColorTypes = 2;
370 break;
371 default:
372 colorTypes[0] = CodecSrc::kGetFromCanvas_DstColorType;
373 numColorTypes = 1;
374 break;
375 }
msarett9e707a02015-09-01 14:57:57 -0700376
scroggoc5560be2016-02-03 09:42:42 -0800377 SkTArray<SkAlphaType> alphaModes;
378 alphaModes.push_back(kPremul_SkAlphaType);
msarett9e9444c2016-02-03 12:39:10 -0800379 alphaModes.push_back(kUnpremul_SkAlphaType);
scroggoc5560be2016-02-03 09:42:42 -0800380 if (codec->getInfo().alphaType() == kOpaque_SkAlphaType) {
381 alphaModes.push_back(kOpaque_SkAlphaType);
382 }
msarettb714fb02016-01-22 14:46:42 -0800383
384 for (CodecSrc::Mode mode : nativeModes) {
385 // SkCodecImageGenerator only runs for the default colorType
386 // recommended by SkCodec. There is no need to generate multiple
387 // tests for different colorTypes.
388 // TODO (msarett): Add scaling support to SkCodecImageGenerator.
389 if (CodecSrc::kGen_Mode == mode) {
390 // FIXME: The gpu backend does not draw kGray sources correctly. (skbug.com/4822)
391 if (kGray_8_SkColorType != codec->getInfo().colorType()) {
scroggoc5560be2016-02-03 09:42:42 -0800392 push_codec_src(path, mode, CodecSrc::kGetFromCanvas_DstColorType,
393 codec->getInfo().alphaType(), 1.0f);
msarettb714fb02016-01-22 14:46:42 -0800394 }
395 continue;
396 }
397
398 for (float scale : nativeScales) {
msarett36c37962015-09-02 13:20:52 -0700399 for (uint32_t i = 0; i < numColorTypes; i++) {
scroggoc5560be2016-02-03 09:42:42 -0800400 for (SkAlphaType alphaType : alphaModes) {
401 push_codec_src(path, mode, colorTypes[i], alphaType, scale);
402 }
msarett9e707a02015-09-01 14:57:57 -0700403 }
404 }
msarett0a242972015-06-11 14:27:27 -0700405 }
msarett36c37962015-09-02 13:20:52 -0700406
halcanary6950de62015-11-07 05:29:00 -0800407 // https://bug.skia.org/4428
msarett33c76232015-11-16 13:43:40 -0800408 bool subset = false;
409 // The following image types are supported by BitmapRegionDecoder,
410 // so we will test full image decodes and subset decodes.
msarettbe8216a2015-12-04 08:00:50 -0800411 static const char* const exts[] = {
msarett3d9d7a72015-10-21 10:27:10 -0700412 "jpg", "jpeg", "png", "webp",
413 "JPG", "JPEG", "PNG", "WEBP",
414 };
msarettbe8216a2015-12-04 08:00:50 -0800415 for (const char* ext : exts) {
msarett3d9d7a72015-10-21 10:27:10 -0700416 if (path.endsWith(ext)) {
msarett33c76232015-11-16 13:43:40 -0800417 subset = true;
msarett3d9d7a72015-10-21 10:27:10 -0700418 break;
419 }
420 }
msarett33c76232015-11-16 13:43:40 -0800421
msarett3d9d7a72015-10-21 10:27:10 -0700422 const int sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
msarett36c37962015-09-02 13:20:52 -0700423
msarett3d9d7a72015-10-21 10:27:10 -0700424 for (int sampleSize : sampleSizes) {
msarett33c76232015-11-16 13:43:40 -0800425 for (uint32_t i = 0; i < numColorTypes; i++) {
scroggoc5560be2016-02-03 09:42:42 -0800426 for (SkAlphaType alphaType : alphaModes) {
427 push_android_codec_src(path, AndroidCodecSrc::kFullImage_Mode, colorTypes[i],
428 alphaType, sampleSize);
429 if (subset) {
430 push_android_codec_src(path, AndroidCodecSrc::kDivisor_Mode, colorTypes[i],
431 alphaType, sampleSize);
432 }
msarett3d9d7a72015-10-21 10:27:10 -0700433 }
msarett36c37962015-09-02 13:20:52 -0700434 }
435 }
msarett438b2ad2015-04-09 12:43:10 -0700436}
437
msarett5cb48852015-11-06 08:56:32 -0800438static bool brd_color_type_supported(SkBitmapRegionDecoder::Strategy strategy,
msaretta5783ae2015-09-08 15:35:32 -0700439 CodecSrc::DstColorType dstColorType) {
440 switch (strategy) {
msarett5cb48852015-11-06 08:56:32 -0800441 case SkBitmapRegionDecoder::kCanvas_Strategy:
msaretta5783ae2015-09-08 15:35:32 -0700442 if (CodecSrc::kGetFromCanvas_DstColorType == dstColorType) {
443 return true;
444 }
445 return false;
msarett5cb48852015-11-06 08:56:32 -0800446 case SkBitmapRegionDecoder::kAndroidCodec_Strategy:
msarett26ad17b2015-10-22 07:29:19 -0700447 switch (dstColorType) {
448 case CodecSrc::kGetFromCanvas_DstColorType:
449 case CodecSrc::kIndex8_Always_DstColorType:
450 case CodecSrc::kGrayscale_Always_DstColorType:
451 return true;
452 default:
453 return false;
454 }
msaretta5783ae2015-09-08 15:35:32 -0700455 default:
456 SkASSERT(false);
457 return false;
458 }
459}
460
msarett5cb48852015-11-06 08:56:32 -0800461static void push_brd_src(Path path, SkBitmapRegionDecoder::Strategy strategy,
msaretta5783ae2015-09-08 15:35:32 -0700462 CodecSrc::DstColorType dstColorType, BRDSrc::Mode mode, uint32_t sampleSize) {
463 SkString folder;
464 switch (strategy) {
msarett5cb48852015-11-06 08:56:32 -0800465 case SkBitmapRegionDecoder::kCanvas_Strategy:
msaretta5783ae2015-09-08 15:35:32 -0700466 folder.append("brd_canvas");
467 break;
msarett5cb48852015-11-06 08:56:32 -0800468 case SkBitmapRegionDecoder::kAndroidCodec_Strategy:
msarett26ad17b2015-10-22 07:29:19 -0700469 folder.append("brd_android_codec");
470 break;
msaretta5783ae2015-09-08 15:35:32 -0700471 default:
472 SkASSERT(false);
473 return;
474 }
475
476 switch (mode) {
477 case BRDSrc::kFullImage_Mode:
478 break;
479 case BRDSrc::kDivisor_Mode:
480 folder.append("_divisor");
481 break;
482 default:
483 SkASSERT(false);
484 return;
485 }
486
487 switch (dstColorType) {
488 case CodecSrc::kGetFromCanvas_DstColorType:
489 break;
490 case CodecSrc::kIndex8_Always_DstColorType:
491 folder.append("_kIndex");
492 break;
493 case CodecSrc::kGrayscale_Always_DstColorType:
494 folder.append("_kGray");
495 break;
496 default:
497 SkASSERT(false);
498 return;
499 }
500
501 if (1 != sampleSize) {
msarett4b0778e2015-11-13 09:59:11 -0800502 folder.appendf("_%.3f", 1.0f / (float) sampleSize);
msaretta5783ae2015-09-08 15:35:32 -0700503 }
504
505 BRDSrc* src = new BRDSrc(path, strategy, mode, dstColorType, sampleSize);
506 push_src("image", folder, src);
507}
508
509static void push_brd_srcs(Path path) {
510
msarett5cb48852015-11-06 08:56:32 -0800511 const SkBitmapRegionDecoder::Strategy strategies[] = {
512 SkBitmapRegionDecoder::kCanvas_Strategy,
msarett5cb48852015-11-06 08:56:32 -0800513 SkBitmapRegionDecoder::kAndroidCodec_Strategy,
msaretta5783ae2015-09-08 15:35:32 -0700514 };
515
scroggo501b7342015-11-03 07:55:11 -0800516 // Test on a variety of sampleSizes, making sure to include:
517 // - 2, 4, and 8, which are natively supported by jpeg
518 // - multiples of 2 which are not divisible by 4 (analogous for 4)
519 // - larger powers of two, since BRD clients generally use powers of 2
520 // We will only produce output for the larger sizes on large images.
521 const uint32_t sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 24, 32, 64 };
msarett6efbe052015-09-11 09:01:16 -0700522
msaretta5783ae2015-09-08 15:35:32 -0700523 // We will only test to one backend (8888), but we will test all of the
524 // color types that we need to decode to on this backend.
525 const CodecSrc::DstColorType dstColorTypes[] = {
msarett26ad17b2015-10-22 07:29:19 -0700526 CodecSrc::kGetFromCanvas_DstColorType,
527 CodecSrc::kIndex8_Always_DstColorType,
528 CodecSrc::kGrayscale_Always_DstColorType,
msaretta5783ae2015-09-08 15:35:32 -0700529 };
530
531 const BRDSrc::Mode modes[] = {
msarett26ad17b2015-10-22 07:29:19 -0700532 BRDSrc::kFullImage_Mode,
533 BRDSrc::kDivisor_Mode,
msaretta5783ae2015-09-08 15:35:32 -0700534 };
535
msarett5cb48852015-11-06 08:56:32 -0800536 for (SkBitmapRegionDecoder::Strategy strategy : strategies) {
msarett6efbe052015-09-11 09:01:16 -0700537 for (uint32_t sampleSize : sampleSizes) {
msarett6efbe052015-09-11 09:01:16 -0700538 for (CodecSrc::DstColorType dstColorType : dstColorTypes) {
539 if (brd_color_type_supported(strategy, dstColorType)) {
540 for (BRDSrc::Mode mode : modes) {
msaretta5783ae2015-09-08 15:35:32 -0700541 push_brd_src(path, strategy, dstColorType, mode, sampleSize);
542 }
543 }
544 }
545 }
546 }
547}
548
549static bool brd_supported(const char* ext) {
msarett8c8f22a2015-04-01 06:58:48 -0700550 static const char* const exts[] = {
msaretta5783ae2015-09-08 15:35:32 -0700551 "jpg", "jpeg", "png", "webp",
552 "JPG", "JPEG", "PNG", "WEBP",
msarett8c8f22a2015-04-01 06:58:48 -0700553 };
554
555 for (uint32_t i = 0; i < SK_ARRAY_COUNT(exts); i++) {
556 if (0 == strcmp(exts[i], ext)) {
557 return true;
558 }
559 }
560 return false;
scroggo9b77ddd2015-03-19 06:03:39 -0700561}
562
scroggo86737142016-02-03 12:19:11 -0800563static bool gather_srcs() {
mtklein748ca3b2015-01-15 10:56:12 -0800564 for (const skiagm::GMRegistry* r = skiagm::GMRegistry::Head(); r; r = r->next()) {
djsollen54416de2015-04-03 07:24:48 -0700565 push_src("gm", "", new GMSrc(r->factory()));
mtklein748ca3b2015-01-15 10:56:12 -0800566 }
halcanaryfc37ad12015-01-30 07:31:19 -0800567 for (int i = 0; i < FLAGS_skps.count(); i++) {
568 const char* path = FLAGS_skps[i];
569 if (sk_isdir(path)) {
570 SkOSFile::Iter it(path, "skp");
571 for (SkString file; it.next(&file); ) {
djsollen54416de2015-04-03 07:24:48 -0700572 push_src("skp", "", new SKPSrc(SkOSPath::Join(path, file.c_str())));
halcanaryfc37ad12015-01-30 07:31:19 -0800573 }
574 } else {
djsollen54416de2015-04-03 07:24:48 -0700575 push_src("skp", "", new SKPSrc(path));
mtklein114c3cd2015-01-15 10:15:02 -0800576 }
577 }
scroggo86737142016-02-03 12:19:11 -0800578
579 SkTArray<SkString> images;
580 if (!CollectImages(&images)) {
581 return false;
582 }
583
584 for (auto image : images) {
585 push_codec_srcs(image);
586 const char* ext = "";
587 int index = image.findLastOf('.');
588 if (index >= 0 && (size_t) ++index < image.size()) {
589 ext = &image.c_str()[index];
590 }
591 if (brd_supported(ext)) {
592 push_brd_srcs(image);
mtklein709d2c32015-01-15 08:30:25 -0800593 }
mtklein709d2c32015-01-15 08:30:25 -0800594 }
scroggo86737142016-02-03 12:19:11 -0800595
596 return true;
mtklein709d2c32015-01-15 08:30:25 -0800597}
598
kkinnunen3e980c32015-12-23 01:33:00 -0800599static void push_sink(const SkCommandLineConfig& config, Sink* s) {
rmistry0f515bd2015-12-22 10:22:26 -0800600 SkAutoTDelete<Sink> sink(s);
kkinnunen3e980c32015-12-23 01:33:00 -0800601
mtkleine0effd62015-07-29 06:37:28 -0700602 // Try a simple Src as a canary. If it fails, skip this sink.
mtklein748ca3b2015-01-15 10:56:12 -0800603 struct : public Src {
mtkleine0effd62015-07-29 06:37:28 -0700604 Error draw(SkCanvas* c) const override {
605 c->drawRect(SkRect::MakeWH(1,1), SkPaint());
606 return "";
607 }
mtklein36352bf2015-03-25 18:17:31 -0700608 SkISize size() const override { return SkISize::Make(16, 16); }
mtkleine0effd62015-07-29 06:37:28 -0700609 Name name() const override { return "justOneRect"; }
610 } justOneRect;
mtklein114c3cd2015-01-15 10:15:02 -0800611
mtklein748ca3b2015-01-15 10:56:12 -0800612 SkBitmap bitmap;
613 SkDynamicMemoryWStream stream;
mtkleinb9eb4ac2015-02-02 18:26:03 -0800614 SkString log;
mtkleine0effd62015-07-29 06:37:28 -0700615 Error err = sink->draw(justOneRect, &bitmap, &stream, &log);
mtklein4089ef72015-03-05 08:40:28 -0800616 if (err.isFatal()) {
kkinnunen3e980c32015-12-23 01:33:00 -0800617 SkDebugf("Could not run %s: %s\n", config.getTag().c_str(), err.c_str());
mtklein05641a52015-04-21 10:49:13 -0700618 exit(1);
mtklein114c3cd2015-01-15 10:15:02 -0800619 }
620
mtkleine0effd62015-07-29 06:37:28 -0700621 TaggedSink& ts = gSinks.push_back();
mtklein748ca3b2015-01-15 10:56:12 -0800622 ts.reset(sink.detach());
kkinnunen3e980c32015-12-23 01:33:00 -0800623 ts.tag = config.getTag();
mtklein748ca3b2015-01-15 10:56:12 -0800624}
625
626static bool gpu_supported() {
627#if SK_SUPPORT_GPU
628 return FLAGS_gpu;
629#else
630 return false;
631#endif
632}
kkinnunen9ebc3f02015-12-21 23:48:13 -0800633
kkinnunen3e980c32015-12-23 01:33:00 -0800634static Sink* create_sink(const SkCommandLineConfig* config) {
635#if SK_SUPPORT_GPU
636 if (gpu_supported()) {
637 if (const SkCommandLineConfigGpu* gpuConfig = config->asConfigGpu()) {
638 GrContextFactory::GLContextType contextType = gpuConfig->getContextType();
639 GrContextFactory::GLContextOptions contextOptions =
640 GrContextFactory::kNone_GLContextOptions;
641 if (gpuConfig->getUseNVPR()) {
642 contextOptions = static_cast<GrContextFactory::GLContextOptions>(
643 contextOptions | GrContextFactory::kEnableNVPR_GLContextOptions);
644 }
645 GrContextFactory testFactory;
646 if (!testFactory.get(contextType, contextOptions)) {
647 SkDebugf("WARNING: can not create GPU context for config '%s'. "
648 "GM tests will be skipped.\n", gpuConfig->getTag().c_str());
649 return nullptr;
650 }
651 return new GPUSink(contextType, contextOptions, gpuConfig->getSamples(),
652 gpuConfig->getUseDIText(), FLAGS_gpu_threading);
653 }
654 }
655#endif
656
657#define SINK(t, sink, ...) if (config->getBackend().equals(t)) { return new sink(__VA_ARGS__); }
658
tomhudsoneebc39a2015-02-23 12:18:05 -0800659#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
660 SINK("hwui", HWUISink);
661#endif
662
mtklein748ca3b2015-01-15 10:56:12 -0800663 if (FLAGS_cpu) {
664 SINK("565", RasterSink, kRGB_565_SkColorType);
665 SINK("8888", RasterSink, kN32_SkColorType);
halcanaryc11c62f2015-09-28 11:51:54 -0700666 SINK("pdf", PDFSink, "Pdfium");
667 SINK("pdf_poppler", PDFSink, "Poppler");
mtklein9c3f17d2015-01-28 11:35:18 -0800668 SINK("skp", SKPSink);
mtklein8a4527e2015-01-31 20:00:58 -0800669 SINK("svg", SVGSink);
670 SINK("null", NullSink);
halcanary47ef4d52015-03-03 09:13:09 -0800671 SINK("xps", XPSSink);
mtklein748ca3b2015-01-15 10:56:12 -0800672 }
673#undef SINK
halcanary96fcdcc2015-08-27 07:41:13 -0700674 return nullptr;
mtklein114c3cd2015-01-15 10:15:02 -0800675}
676
kkinnunen3e980c32015-12-23 01:33:00 -0800677static Sink* create_via(const SkString& tag, Sink* wrapped) {
678#define VIA(t, via, ...) if (tag.equals(t)) { return new via(__VA_ARGS__); }
halcanary96fcdcc2015-08-27 07:41:13 -0700679 VIA("twice", ViaTwice, wrapped);
halcanary96fcdcc2015-08-27 07:41:13 -0700680 VIA("serialize", ViaSerialization, wrapped);
mtklein4a34ecb2016-01-08 10:19:35 -0800681 VIA("pic", ViaPicture, wrapped);
halcanary96fcdcc2015-08-27 07:41:13 -0700682 VIA("2ndpic", ViaSecondPicture, wrapped);
mtkleind31c13d2015-05-05 12:59:56 -0700683 VIA("sp", ViaSingletonPictures, wrapped);
halcanary96fcdcc2015-08-27 07:41:13 -0700684 VIA("tiles", ViaTiles, 256, 256, nullptr, wrapped);
mtklein7edca212015-01-21 13:18:51 -0800685 VIA("tiles_rt", ViaTiles, 256, 256, new SkRTreeFactory, wrapped);
mtklein2e2ea382015-10-16 10:29:41 -0700686 VIA("remote", ViaRemote, false, wrapped);
687 VIA("remote_cache", ViaRemote, true, wrapped);
halcanary7a76f9c2016-02-03 11:53:18 -0800688 VIA("mojo", ViaMojo, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800689
mtkleind603b222015-02-17 11:13:33 -0800690 if (FLAGS_matrix.count() == 4) {
mtklein748ca3b2015-01-15 10:56:12 -0800691 SkMatrix m;
mtkleind603b222015-02-17 11:13:33 -0800692 m.reset();
693 m.setScaleX((SkScalar)atof(FLAGS_matrix[0]));
694 m.setSkewX ((SkScalar)atof(FLAGS_matrix[1]));
695 m.setSkewY ((SkScalar)atof(FLAGS_matrix[2]));
696 m.setScaleY((SkScalar)atof(FLAGS_matrix[3]));
697 VIA("matrix", ViaMatrix, m, wrapped);
698 VIA("upright", ViaUpright, m, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800699 }
tomhudson64de1e12015-03-05 08:01:07 -0800700
701#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
702 VIA("androidsdk", ViaAndroidSDK, wrapped);
703#endif
704
mtklein748ca3b2015-01-15 10:56:12 -0800705#undef VIA
halcanary96fcdcc2015-08-27 07:41:13 -0700706 return nullptr;
mtklein114c3cd2015-01-15 10:15:02 -0800707}
708
mtklein748ca3b2015-01-15 10:56:12 -0800709static void gather_sinks() {
kkinnunen3e980c32015-12-23 01:33:00 -0800710 SkCommandLineConfigArray configs;
711 ParseConfigs(FLAGS_config, &configs);
712 for (int i = 0; i < configs.count(); i++) {
713 const SkCommandLineConfig& config = *configs[i];
714 Sink* sink = create_sink(&config);
715 if (sink == nullptr) {
716 SkDebugf("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(),
717 config.getTag().c_str());
718 continue;
719 }
mtklein748ca3b2015-01-15 10:56:12 -0800720
kkinnunen3e980c32015-12-23 01:33:00 -0800721 const SkTArray<SkString>& parts = config.getViaParts();
722 for (int j = parts.count(); j-- > 0;) {
723 const SkString& part = parts[j];
724 Sink* next = create_via(part, sink);
halcanary96fcdcc2015-08-27 07:41:13 -0700725 if (next == nullptr) {
kkinnunen3e980c32015-12-23 01:33:00 -0800726 SkDebugf("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(),
727 part.c_str());
mtklein748ca3b2015-01-15 10:56:12 -0800728 delete sink;
halcanary96fcdcc2015-08-27 07:41:13 -0700729 sink = nullptr;
mtklein748ca3b2015-01-15 10:56:12 -0800730 break;
731 }
732 sink = next;
733 }
734 if (sink) {
735 push_sink(config, sink);
mtklein114c3cd2015-01-15 10:15:02 -0800736 }
737 }
738}
mtklein709d2c32015-01-15 08:30:25 -0800739
mtkleina5114d72015-08-24 13:27:01 -0700740static bool dump_png(SkBitmap bitmap, const char* path, const char* md5) {
741 const int w = bitmap.width(),
742 h = bitmap.height();
743
744 // First get the bitmap into N32 color format. The next step will work only there.
745 if (bitmap.colorType() != kN32_SkColorType) {
746 SkBitmap n32;
747 if (!bitmap.copyTo(&n32, kN32_SkColorType)) {
748 return false;
749 }
750 bitmap = n32;
751 }
752
753 // Convert our N32 bitmap into unpremul RGBA for libpng.
754 SkAutoTMalloc<uint32_t> rgba(w*h);
755 if (!bitmap.readPixels(SkImageInfo::Make(w,h, kRGBA_8888_SkColorType, kUnpremul_SkAlphaType),
756 rgba, 4*w, 0,0)) {
757 return false;
758 }
759
760 // We don't need bitmap anymore. Might as well drop our ref.
mtkleinfccb77d2015-08-24 14:13:29 -0700761 bitmap.reset();
mtkleina5114d72015-08-24 13:27:01 -0700762
mtkleinc64137c2015-08-25 10:56:08 -0700763 FILE* f = fopen(path, "wb");
mtkleina5114d72015-08-24 13:27:01 -0700764 if (!f) { return false; }
765
766 png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
767 if (!png) {
768 fclose(f);
769 return false;
770 }
771
772 png_infop info = png_create_info_struct(png);
773 if (!info) {
774 png_destroy_write_struct(&png, &info);
775 fclose(f);
776 return false;
777 }
778
mtkleind69ece62015-09-10 10:37:44 -0700779 SkString description;
780 description.append("Key: ");
781 for (int i = 0; i < FLAGS_key.count(); i++) {
782 description.appendf("%s ", FLAGS_key[i]);
783 }
784 description.append("Properties: ");
785 for (int i = 0; i < FLAGS_properties.count(); i++) {
786 description.appendf("%s ", FLAGS_properties[i]);
787 }
788 description.appendf("MD5: %s", md5);
789
mtkleina5114d72015-08-24 13:27:01 -0700790 png_text text[2];
791 text[0].key = (png_charp)"Author";
792 text[0].text = (png_charp)"DM dump_png()";
793 text[0].compression = PNG_TEXT_COMPRESSION_NONE;
794 text[1].key = (png_charp)"Description";
mtkleind69ece62015-09-10 10:37:44 -0700795 text[1].text = (png_charp)description.c_str();
mtkleina5114d72015-08-24 13:27:01 -0700796 text[1].compression = PNG_TEXT_COMPRESSION_NONE;
797 png_set_text(png, info, text, 2);
798
799 png_init_io(png, f);
800 png_set_IHDR(png, info, (png_uint_32)w, (png_uint_32)h, 8,
801 PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE,
802 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
803 png_write_info(png, info);
804 for (int j = 0; j < h; j++) {
805 png_bytep row = (png_bytep)(rgba.get() + w*j);
806 png_write_rows(png, &row, 1);
807 }
808 png_write_end(png, info);
809
810 png_destroy_write_struct(&png, &info);
811 fclose(f);
812 return true;
813}
814
mtkleina2ef6422015-01-15 13:44:22 -0800815static bool match(const char* needle, const char* haystack) {
halcanary96fcdcc2015-08-27 07:41:13 -0700816 return 0 == strcmp("_", needle) || nullptr != strstr(haystack, needle);
mtkleina2ef6422015-01-15 13:44:22 -0800817}
818
djsollen54416de2015-04-03 07:24:48 -0700819static ImplicitString is_blacklisted(const char* sink, const char* src,
820 const char* srcOptions, const char* name) {
mtklein0d243ff2015-04-03 07:51:00 -0700821 for (int i = 0; i < FLAGS_blacklist.count() - 3; i += 4) {
mtkleina2ef6422015-01-15 13:44:22 -0800822 if (match(FLAGS_blacklist[i+0], sink) &&
djsollen54416de2015-04-03 07:24:48 -0700823 match(FLAGS_blacklist[i+1], src) &&
824 match(FLAGS_blacklist[i+2], srcOptions) &&
825 match(FLAGS_blacklist[i+3], name)) {
826 return SkStringPrintf("%s %s %s %s",
827 FLAGS_blacklist[i+0], FLAGS_blacklist[i+1],
828 FLAGS_blacklist[i+2], FLAGS_blacklist[i+3]);
mtkleina2ef6422015-01-15 13:44:22 -0800829 }
830 }
831 return "";
832}
833
mtkleincd50bca2016-01-05 06:20:20 -0800834// Even when a Task Sink reports to be non-threadsafe (e.g. GPU), we know things like
835// .png encoding are definitely thread safe. This lets us offload that work to CPU threads.
836static SkTaskGroup gDefinitelyThreadSafeWork;
837
mtklein748ca3b2015-01-15 10:56:12 -0800838// The finest-grained unit of work we can run: draw a single Src into a single Sink,
839// report any errors, and perhaps write out the output: a .png of the bitmap, or a raw stream.
840struct Task {
mtkleine0effd62015-07-29 06:37:28 -0700841 Task(const TaggedSrc& src, const TaggedSink& sink) : src(src), sink(sink) {}
842 const TaggedSrc& src;
843 const TaggedSink& sink;
mtklein748ca3b2015-01-15 10:56:12 -0800844
845 static void Run(Task* task) {
mtkleina2ef6422015-01-15 13:44:22 -0800846 SkString name = task->src->name();
mtkleine0effd62015-07-29 06:37:28 -0700847
848 // We'll skip drawing this Src/Sink pair if:
849 // - the Src vetoes the Sink;
850 // - this Src / Sink combination is on the blacklist;
851 // - it's a dry run.
mtklein99cab4e2015-07-31 06:43:04 -0700852 SkString note(task->src->veto(task->sink->flags()) ? " (veto)" : "");
kkinnunen3e980c32015-12-23 01:33:00 -0800853 SkString whyBlacklisted = is_blacklisted(task->sink.tag.c_str(), task->src.tag.c_str(),
msarett9e707a02015-09-01 14:57:57 -0700854 task->src.options.c_str(), name.c_str());
mtkleinb37cb412015-03-18 05:27:14 -0700855 if (!whyBlacklisted.isEmpty()) {
856 note.appendf(" (--blacklist %s)", whyBlacklisted.c_str());
857 }
mtkleine0effd62015-07-29 06:37:28 -0700858
mtkleinb9eb4ac2015-02-02 18:26:03 -0800859 SkString log;
mtkleinf27f08b2015-11-03 06:54:24 -0800860 auto timerStart = now_ms();
mtkleine0effd62015-07-29 06:37:28 -0700861 if (!FLAGS_dryRun && note.isEmpty()) {
mtklein748ca3b2015-01-15 10:56:12 -0800862 SkBitmap bitmap;
863 SkDynamicMemoryWStream stream;
bsalomon821e10e2015-06-04 14:15:33 -0700864 if (FLAGS_pre_log) {
kkinnunen3e980c32015-12-23 01:33:00 -0800865 SkDebugf("\nRunning %s->%s", name.c_str(), task->sink.tag.c_str());
bsalomon821e10e2015-06-04 14:15:33 -0700866 }
kkinnunen3e980c32015-12-23 01:33:00 -0800867 start(task->sink.tag.c_str(), task->src.tag, task->src.options, name.c_str());
mtkleinb9eb4ac2015-02-02 18:26:03 -0800868 Error err = task->sink->draw(*task->src, &bitmap, &stream, &log);
mtklein748ca3b2015-01-15 10:56:12 -0800869 if (!err.isEmpty()) {
mtklein4089ef72015-03-05 08:40:28 -0800870 if (err.isFatal()) {
djsollen54416de2015-04-03 07:24:48 -0700871 fail(SkStringPrintf("%s %s %s %s: %s",
kkinnunen3e980c32015-12-23 01:33:00 -0800872 task->sink.tag.c_str(),
msarett9e707a02015-09-01 14:57:57 -0700873 task->src.tag.c_str(),
874 task->src.options.c_str(),
mtklein4089ef72015-03-05 08:40:28 -0800875 name.c_str(),
876 err.c_str()));
mtkleinb37cb412015-03-18 05:27:14 -0700877 } else {
878 note.appendf(" (skipped: %s)", err.c_str());
mtkleinba6ada72016-01-21 09:39:35 -0800879 auto elapsed = now_ms() - timerStart;
880 done(elapsed, task->sink.tag.c_str(), task->src.tag, task->src.options,
881 name, note, log);
882 return;
mtklein4089ef72015-03-05 08:40:28 -0800883 }
mtklein748ca3b2015-01-15 10:56:12 -0800884 }
mtklein62bd1a62015-01-27 14:46:26 -0800885
mtkleincd50bca2016-01-05 06:20:20 -0800886 // We're likely switching threads here, so we must capture by value, [=] or [foo,bar].
887 SkStreamAsset* data = stream.detachAsStream();
888 gDefinitelyThreadSafeWork.add([task,name,bitmap,data]{
889 SkAutoTDelete<SkStreamAsset> ownedData(data);
890
891 // Why doesn't the copy constructor do this when we have pre-locked pixels?
892 bitmap.lockPixels();
893
894 SkString md5;
895 if (!FLAGS_writePath.isEmpty() || !FLAGS_readPath.isEmpty()) {
896 SkMD5 hash;
897 if (data->getLength()) {
898 hash.writeStream(data, data->getLength());
899 data->rewind();
mtklein38408462015-07-08 07:25:27 -0700900 } else {
mtkleincd50bca2016-01-05 06:20:20 -0800901 // If we're BGRA (Linux, Windows), swizzle over to RGBA (Mac, Android).
902 // This helps eliminate multiple 0-pixel-diff hashes on gold.skia.org.
903 // (Android's general slow speed breaks the tie arbitrarily in RGBA's favor.)
904 // We might consider promoting 565 to RGBA too.
905 if (bitmap.colorType() == kBGRA_8888_SkColorType) {
906 SkBitmap swizzle;
907 SkAssertResult(bitmap.copyTo(&swizzle, kRGBA_8888_SkColorType));
908 hash.write(swizzle.getPixels(), swizzle.getSize());
909 } else {
910 hash.write(bitmap.getPixels(), bitmap.getSize());
911 }
912 }
913 SkMD5::Digest digest;
914 hash.finish(digest);
915 for (int i = 0; i < 16; i++) {
916 md5.appendf("%02x", digest.data[i]);
mtklein38408462015-07-08 07:25:27 -0700917 }
mtklein62bd1a62015-01-27 14:46:26 -0800918 }
mtklein62bd1a62015-01-27 14:46:26 -0800919
mtkleincd50bca2016-01-05 06:20:20 -0800920 if (!FLAGS_readPath.isEmpty() &&
921 !gGold.contains(Gold(task->sink.tag.c_str(), task->src.tag.c_str(),
922 task->src.options.c_str(), name, md5))) {
923 fail(SkStringPrintf("%s not found for %s %s %s %s in %s",
924 md5.c_str(),
925 task->sink.tag.c_str(),
926 task->src.tag.c_str(),
927 task->src.options.c_str(),
928 name.c_str(),
929 FLAGS_readPath[0]));
mtklein748ca3b2015-01-15 10:56:12 -0800930 }
mtkleincd50bca2016-01-05 06:20:20 -0800931
932 if (!FLAGS_writePath.isEmpty()) {
933 const char* ext = task->sink->fileExtension();
934 if (data->getLength()) {
935 WriteToDisk(*task, md5, ext, data, data->getLength(), nullptr);
936 SkASSERT(bitmap.drawsNothing());
937 } else if (!bitmap.drawsNothing()) {
938 WriteToDisk(*task, md5, ext, nullptr, 0, &bitmap);
939 }
940 }
941 });
mtklein748ca3b2015-01-15 10:56:12 -0800942 }
mtkleinba6ada72016-01-21 09:39:35 -0800943 auto elapsed = now_ms() - timerStart;
944 done(elapsed, task->sink.tag.c_str(), task->src.tag.c_str(), task->src.options.c_str(),
mtkleinf27f08b2015-11-03 06:54:24 -0800945 name, note, log);
mtklein748ca3b2015-01-15 10:56:12 -0800946 }
947
948 static void WriteToDisk(const Task& task,
mtklein62bd1a62015-01-27 14:46:26 -0800949 SkString md5,
950 const char* ext,
mtklein748ca3b2015-01-15 10:56:12 -0800951 SkStream* data, size_t len,
mtklein62bd1a62015-01-27 14:46:26 -0800952 const SkBitmap* bitmap) {
mtklein748ca3b2015-01-15 10:56:12 -0800953 JsonWriter::BitmapResult result;
djsollen54416de2015-04-03 07:24:48 -0700954 result.name = task.src->name();
kkinnunen3e980c32015-12-23 01:33:00 -0800955 result.config = task.sink.tag.c_str();
djsollen54416de2015-04-03 07:24:48 -0700956 result.sourceType = task.src.tag;
957 result.sourceOptions = task.src.options;
958 result.ext = ext;
959 result.md5 = md5;
mtklein748ca3b2015-01-15 10:56:12 -0800960 JsonWriter::AddBitmapResult(result);
961
mtkleinb0531a72015-04-07 13:38:48 -0700962 // If an MD5 is uninteresting, we want it noted in the JSON file,
963 // but don't want to dump it out as a .png (or whatever ext is).
964 if (gUninterestingHashes.contains(md5)) {
965 return;
966 }
967
mtklein748ca3b2015-01-15 10:56:12 -0800968 const char* dir = FLAGS_writePath[0];
969 if (0 == strcmp(dir, "@")) { // Needed for iOS.
970 dir = FLAGS_resourcePath[0];
971 }
972 sk_mkdir(dir);
973
974 SkString path;
975 if (FLAGS_nameByHash) {
976 path = SkOSPath::Join(dir, result.md5.c_str());
977 path.append(".");
978 path.append(ext);
979 if (sk_exists(path.c_str())) {
980 return; // Content-addressed. If it exists already, we're done.
981 }
982 } else {
kkinnunen3e980c32015-12-23 01:33:00 -0800983 path = SkOSPath::Join(dir, task.sink.tag.c_str());
mtklein748ca3b2015-01-15 10:56:12 -0800984 sk_mkdir(path.c_str());
msarett9e707a02015-09-01 14:57:57 -0700985 path = SkOSPath::Join(path.c_str(), task.src.tag.c_str());
mtklein748ca3b2015-01-15 10:56:12 -0800986 sk_mkdir(path.c_str());
msarett9e707a02015-09-01 14:57:57 -0700987 if (strcmp(task.src.options.c_str(), "") != 0) {
988 path = SkOSPath::Join(path.c_str(), task.src.options.c_str());
djsollen54416de2015-04-03 07:24:48 -0700989 sk_mkdir(path.c_str());
990 }
mtklein748ca3b2015-01-15 10:56:12 -0800991 path = SkOSPath::Join(path.c_str(), task.src->name().c_str());
992 path.append(".");
993 path.append(ext);
994 }
995
mtklein748ca3b2015-01-15 10:56:12 -0800996 if (bitmap) {
mtkleina5114d72015-08-24 13:27:01 -0700997 if (!dump_png(*bitmap, path.c_str(), result.md5.c_str())) {
mtklein748ca3b2015-01-15 10:56:12 -0800998 fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str()));
999 return;
1000 }
1001 } else {
mtkleina5114d72015-08-24 13:27:01 -07001002 SkFILEWStream file(path.c_str());
1003 if (!file.isValid()) {
1004 fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str()));
1005 return;
1006 }
mtklein748ca3b2015-01-15 10:56:12 -08001007 if (!file.writeStream(data, len)) {
1008 fail(SkStringPrintf("Can't write to %s.\n", path.c_str()));
1009 return;
1010 }
1011 }
1012 }
1013};
1014
1015// Run all tasks in the same enclave serially on the same thread.
1016// They can't possibly run concurrently with each other.
1017static void run_enclave(SkTArray<Task>* tasks) {
1018 for (int i = 0; i < tasks->count(); i++) {
1019 Task::Run(tasks->begin() + i);
1020 }
1021}
1022
1023/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1024
1025// Unit tests don't fit so well into the Src/Sink model, so we give them special treatment.
1026
mtklein55e88b22015-01-21 15:50:13 -08001027static SkTDArray<skiatest::Test> gThreadedTests, gGPUTests;
mtklein748ca3b2015-01-15 10:56:12 -08001028
1029static void gather_tests() {
mtklein6c5fed22015-01-20 13:47:23 -08001030 if (!FLAGS_src.contains("tests")) {
mtklein748ca3b2015-01-15 10:56:12 -08001031 return;
1032 }
mtklein6393c062015-04-27 08:45:01 -07001033 for (const skiatest::TestRegistry* r = skiatest::TestRegistry::Head(); r; r = r->next()) {
1034 if (!in_shard()) {
1035 continue;
1036 }
halcanary87f3ba42015-01-20 09:30:20 -08001037 // Despite its name, factory() is returning a reference to
1038 // link-time static const POD data.
1039 const skiatest::Test& test = r->factory();
1040 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, test.name)) {
mtklein748ca3b2015-01-15 10:56:12 -08001041 continue;
1042 }
halcanary87f3ba42015-01-20 09:30:20 -08001043 if (test.needsGpu && gpu_supported()) {
mtklein55e88b22015-01-21 15:50:13 -08001044 (FLAGS_gpu_threading ? gThreadedTests : gGPUTests).push(test);
halcanary87f3ba42015-01-20 09:30:20 -08001045 } else if (!test.needsGpu && FLAGS_cpu) {
mtklein55e88b22015-01-21 15:50:13 -08001046 gThreadedTests.push(test);
mtklein82d28432015-01-15 12:46:02 -08001047 }
mtklein748ca3b2015-01-15 10:56:12 -08001048 }
1049}
1050
halcanary87f3ba42015-01-20 09:30:20 -08001051static void run_test(skiatest::Test* test) {
1052 struct : public skiatest::Reporter {
mtklein36352bf2015-03-25 18:17:31 -07001053 void reportFailed(const skiatest::Failure& failure) override {
halcanary87f3ba42015-01-20 09:30:20 -08001054 fail(failure.toString());
1055 JsonWriter::AddTestFailure(failure);
1056 }
mtklein36352bf2015-03-25 18:17:31 -07001057 bool allowExtendedTest() const override {
halcanary87f3ba42015-01-20 09:30:20 -08001058 return FLAGS_pathOpsExtended;
1059 }
mtklein36352bf2015-03-25 18:17:31 -07001060 bool verbose() const override { return FLAGS_veryVerbose; }
halcanary87f3ba42015-01-20 09:30:20 -08001061 } reporter;
djsollen824996a2015-06-12 12:06:22 -07001062
1063 SkString note;
1064 SkString whyBlacklisted = is_blacklisted("_", "tests", "_", test->name);
1065 if (!whyBlacklisted.isEmpty()) {
1066 note.appendf(" (--blacklist %s)", whyBlacklisted.c_str());
1067 }
1068
mtkleinf27f08b2015-11-03 06:54:24 -08001069 auto timerStart = now_ms();
djsollen824996a2015-06-12 12:06:22 -07001070 if (!FLAGS_dryRun && whyBlacklisted.isEmpty()) {
djsollen54416de2015-04-03 07:24:48 -07001071 start("unit", "test", "", test->name);
mtklein55e88b22015-01-21 15:50:13 -08001072 GrContextFactory factory;
bsalomon821e10e2015-06-04 14:15:33 -07001073 if (FLAGS_pre_log) {
1074 SkDebugf("\nRunning test %s", test->name);
1075 }
mtklein55e88b22015-01-21 15:50:13 -08001076 test->proc(&reporter, &factory);
mtklein748ca3b2015-01-15 10:56:12 -08001077 }
mtkleinf27f08b2015-11-03 06:54:24 -08001078 done(now_ms()-timerStart, "unit", "test", "", test->name, note, "");
mtklein748ca3b2015-01-15 10:56:12 -08001079}
1080
1081/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1082
mtklein55e88b22015-01-21 15:50:13 -08001083// If we're isolating all GPU-bound work to one thread (the default), this function runs all that.
1084static void run_enclave_and_gpu_tests(SkTArray<Task>* tasks) {
1085 run_enclave(tasks);
1086 for (int i = 0; i < gGPUTests.count(); i++) {
1087 run_test(&gGPUTests[i]);
1088 }
1089}
1090
mtkleinde6fc2b2015-03-12 06:28:54 -07001091// Some runs (mostly, Valgrind) are so slow that the bot framework thinks we've hung.
1092// This prints something every once in a while so that it knows we're still working.
mtklein2e1c47e2015-03-12 07:16:56 -07001093static void start_keepalive() {
1094 struct Loop {
1095 static void forever(void*) {
1096 for (;;) {
1097 static const int kSec = 300;
1098 #if defined(SK_BUILD_FOR_WIN)
1099 Sleep(kSec * 1000);
1100 #else
1101 sleep(kSec);
1102 #endif
mtkleinb37cb412015-03-18 05:27:14 -07001103 SkString running;
1104 {
mtkleinbc4e0032015-12-09 08:37:35 -08001105 SkAutoMutexAcquire lock(gRunningAndTallyMutex);
mtkleinb37cb412015-03-18 05:27:14 -07001106 for (int i = 0; i < gRunning.count(); i++) {
1107 running.appendf("\n\t%s", gRunning[i].c_str());
1108 }
1109 }
1110 SkDebugf("\nCurrently running:%s\n", running.c_str());
mtklein2e1c47e2015-03-12 07:16:56 -07001111 }
1112 }
1113 };
1114 static SkThread* intentionallyLeaked = new SkThread(Loop::forever);
1115 intentionallyLeaked->start();
mtkleinde6fc2b2015-03-12 06:28:54 -07001116}
1117
caryclark83ca6282015-06-10 09:31:09 -07001118#define PORTABLE_FONT_PREFIX "Toy Liberation "
1119
1120static SkTypeface* create_from_name(const char familyName[], SkTypeface::Style style) {
1121 if (familyName && strlen(familyName) > sizeof(PORTABLE_FONT_PREFIX)
1122 && !strncmp(familyName, PORTABLE_FONT_PREFIX, sizeof(PORTABLE_FONT_PREFIX) - 1)) {
caryclark1818acb2015-07-24 12:09:25 -07001123 return sk_tool_utils::create_portable_typeface(familyName, style);
caryclark83ca6282015-06-10 09:31:09 -07001124 }
halcanary96fcdcc2015-08-27 07:41:13 -07001125 return nullptr;
caryclark83ca6282015-06-10 09:31:09 -07001126}
1127
1128#undef PORTABLE_FONT_PREFIX
1129
1130extern SkTypeface* (*gCreateTypefaceDelegate)(const char [], SkTypeface::Style );
1131
jcgregorio3b27ade2014-11-13 08:06:40 -08001132int dm_main();
caryclark17f0b6d2014-07-22 10:15:34 -07001133int dm_main() {
jcgregorio3b27ade2014-11-13 08:06:40 -08001134 SetupCrashHandler();
mtklein5286f022016-01-22 08:18:14 -08001135 JsonWriter::DumpJson(); // It's handy for the bots to assume this is ~never missing.
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +00001136 SkAutoGraphics ag;
mtklein406654b2014-09-03 15:34:37 -07001137 SkTaskGroup::Enabler enabled(FLAGS_threads);
caryclark83ca6282015-06-10 09:31:09 -07001138 gCreateTypefaceDelegate = &create_from_name;
commit-bot@chromium.orga65e2fd2014-05-30 17:23:31 +00001139
mtklein2e1c47e2015-03-12 07:16:56 -07001140 start_keepalive();
mtkleinde6fc2b2015-03-12 06:28:54 -07001141
mtklein62bd1a62015-01-27 14:46:26 -08001142 gather_gold();
borenet09ed4802015-04-03 14:15:33 -07001143 gather_uninteresting_hashes();
mtklein62bd1a62015-01-27 14:46:26 -08001144
scroggo86737142016-02-03 12:19:11 -08001145 if (!gather_srcs()) {
1146 return 1;
1147 }
mtklein748ca3b2015-01-15 10:56:12 -08001148 gather_sinks();
1149 gather_tests();
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +00001150
mtklein55e88b22015-01-21 15:50:13 -08001151 gPending = gSrcs.count() * gSinks.count() + gThreadedTests.count() + gGPUTests.count();
mtklein748ca3b2015-01-15 10:56:12 -08001152 SkDebugf("%d srcs * %d sinks + %d tests == %d tasks\n",
mtklein55e88b22015-01-21 15:50:13 -08001153 gSrcs.count(), gSinks.count(), gThreadedTests.count() + gGPUTests.count(), gPending);
mtklein748ca3b2015-01-15 10:56:12 -08001154
1155 // We try to exploit as much parallelism as is safe. Most Src/Sink pairs run on any thread,
1156 // but Sinks that identify as part of a particular enclave run serially on a single thread.
mtklein82d28432015-01-15 12:46:02 -08001157 // CPU tests run on any thread. GPU tests depend on --gpu_threading.
mtklein748ca3b2015-01-15 10:56:12 -08001158 SkTArray<Task> enclaves[kNumEnclaves];
1159 for (int j = 0; j < gSinks.count(); j++) {
1160 SkTArray<Task>& tasks = enclaves[gSinks[j]->enclave()];
1161 for (int i = 0; i < gSrcs.count(); i++) {
1162 tasks.push_back(Task(gSrcs[i], gSinks[j]));
1163 }
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001164 }
1165
mtklein748ca3b2015-01-15 10:56:12 -08001166 SkTaskGroup tg;
mtklein279c7862016-01-04 19:13:19 -08001167 tg.batch(gThreadedTests.count(), [](int i){ run_test(&gThreadedTests[i]); });
mtklein55e88b22015-01-21 15:50:13 -08001168 for (int i = 0; i < kNumEnclaves; i++) {
herb30da5f72015-12-10 14:12:33 -08001169 SkTArray<Task>* currentEnclave = &enclaves[i];
mtklein55e88b22015-01-21 15:50:13 -08001170 switch(i) {
1171 case kAnyThread_Enclave:
mtklein279c7862016-01-04 19:13:19 -08001172 tg.batch(currentEnclave->count(),
1173 [currentEnclave](int j) { Task::Run(&(*currentEnclave)[j]); });
mtklein55e88b22015-01-21 15:50:13 -08001174 break;
1175 case kGPU_Enclave:
herb30da5f72015-12-10 14:12:33 -08001176 tg.add([currentEnclave](){ run_enclave_and_gpu_tests(currentEnclave); });
mtklein55e88b22015-01-21 15:50:13 -08001177 break;
1178 default:
herb30da5f72015-12-10 14:12:33 -08001179 tg.add([currentEnclave](){ run_enclave(currentEnclave); });
mtklein55e88b22015-01-21 15:50:13 -08001180 break;
mtklein82d28432015-01-15 12:46:02 -08001181 }
mtklein55e88b22015-01-21 15:50:13 -08001182 }
mtklein748ca3b2015-01-15 10:56:12 -08001183 tg.wait();
mtkleincd50bca2016-01-05 06:20:20 -08001184 gDefinitelyThreadSafeWork.wait();
1185
mtklein748ca3b2015-01-15 10:56:12 -08001186 // At this point we're back in single-threaded land.
caryclarkf53ce802015-06-15 06:48:30 -07001187 sk_tool_utils::release_portable_typefaces();
mtklein@google.comd36522d2013-10-16 13:02:15 +00001188
mtkleinbc4e0032015-12-09 08:37:35 -08001189 if (FLAGS_verbose && gNoteTally.count() > 0) {
1190 SkDebugf("\nNote tally:\n");
1191 gNoteTally.foreach([](const SkString& note, int* tally) {
1192 SkDebugf("%dx\t%s\n", *tally, note.c_str());
1193 });
1194 }
1195
mtklein2f64eec2015-01-15 14:20:41 -08001196 SkDebugf("\n");
mtklein748ca3b2015-01-15 10:56:12 -08001197 if (gFailures.count() > 0) {
1198 SkDebugf("Failures:\n");
1199 for (int i = 0; i < gFailures.count(); i++) {
mtklein9dc09102015-01-15 15:47:33 -08001200 SkDebugf("\t%s\n", gFailures[i].c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001201 }
1202 SkDebugf("%d failures\n", gFailures.count());
1203 return 1;
mtklein114c3cd2015-01-15 10:15:02 -08001204 }
mtklein748ca3b2015-01-15 10:56:12 -08001205 if (gPending > 0) {
1206 SkDebugf("Hrm, we didn't seem to run everything we intended to! Please file a bug.\n");
1207 return 1;
mtklein114c3cd2015-01-15 10:15:02 -08001208 }
halcanary7a14b312015-10-01 07:28:13 -07001209 #ifdef SK_PDF_IMAGE_STATS
1210 SkPDFImageDumpStats();
1211 #endif // SK_PDF_IMAGE_STATS
scroggo4d9eaea2016-01-29 07:48:33 -08001212 SkDebugf("Finished!\n");
mtklein748ca3b2015-01-15 10:56:12 -08001213 return 0;
mtklein@google.comd36522d2013-10-16 13:02:15 +00001214}
jcgregorio3b27ade2014-11-13 08:06:40 -08001215
kkinnunen179a8f52015-11-20 13:32:24 -08001216// TODO: currently many GPU tests are declared outside SK_SUPPORT_GPU guards.
1217// Thus we export the empty RunWithGPUTestContexts when SK_SUPPORT_GPU=0.
1218namespace skiatest {
1219namespace {
1220typedef void(*TestWithGrContext)(skiatest::Reporter*, GrContext*);
1221typedef void(*TestWithGrContextAndGLContext)(skiatest::Reporter*, GrContext*, SkGLContext*);
1222#if SK_SUPPORT_GPU
1223template<typename T>
kkinnunen34058002016-01-06 23:49:30 -08001224void call_test(T test, skiatest::Reporter* reporter, const GrContextFactory::ContextInfo& context);
kkinnunen179a8f52015-11-20 13:32:24 -08001225template<>
1226void call_test(TestWithGrContext test, skiatest::Reporter* reporter,
kkinnunen34058002016-01-06 23:49:30 -08001227 const GrContextFactory::ContextInfo& context) {
1228 test(reporter, context.fGrContext);
kkinnunen179a8f52015-11-20 13:32:24 -08001229}
1230template<>
1231void call_test(TestWithGrContextAndGLContext test, skiatest::Reporter* reporter,
kkinnunen34058002016-01-06 23:49:30 -08001232 const GrContextFactory::ContextInfo& context) {
1233 test(reporter, context.fGrContext, context.fGLContext);
kkinnunen179a8f52015-11-20 13:32:24 -08001234}
1235#endif
1236} // namespace
1237
kkinnunen179a8f52015-11-20 13:32:24 -08001238template<typename T>
1239void RunWithGPUTestContexts(T test, GPUTestContexts testContexts, Reporter* reporter,
1240 GrContextFactory* factory) {
1241#if SK_SUPPORT_GPU
kkinnunen3e980c32015-12-23 01:33:00 -08001242 // Iterate over context types, except use "native" instead of explicitly trying OpenGL and
1243 // OpenGL ES. Do not use GLES on desktop, since tests do not account for not fixing
1244 // http://skbug.com/2809
1245 GrContextFactory::GLContextType contextTypes[] = {
1246 GrContextFactory::kNative_GLContextType,
1247#if SK_ANGLE
1248#ifdef SK_BUILD_FOR_WIN
1249 GrContextFactory::kANGLE_GLContextType,
1250#endif
1251 GrContextFactory::kANGLE_GL_GLContextType,
1252#endif
1253#if SK_COMMAND_BUFFER
1254 GrContextFactory::kCommandBuffer_GLContextType,
1255#endif
1256#if SK_MESA
1257 GrContextFactory::kMESA_GLContextType,
1258#endif
1259 GrContextFactory::kNull_GLContextType,
1260 GrContextFactory::kDebug_GLContextType,
1261 };
1262 static_assert(SK_ARRAY_COUNT(contextTypes) == GrContextFactory::kGLContextTypeCnt - 2,
1263 "Skipping unexpected GLContextType for GPU tests");
1264
1265 for (auto& contextType : contextTypes) {
kkinnunen179a8f52015-11-20 13:32:24 -08001266 int contextSelector = kNone_GPUTestContexts;
kkinnunen3e980c32015-12-23 01:33:00 -08001267 if (GrContextFactory::IsRenderingGLContext(contextType)) {
kkinnunen179a8f52015-11-20 13:32:24 -08001268 contextSelector |= kAllRendering_GPUTestContexts;
kkinnunen3e980c32015-12-23 01:33:00 -08001269 } else if (contextType == GrContextFactory::kNative_GLContextType) {
kkinnunen179a8f52015-11-20 13:32:24 -08001270 contextSelector |= kNative_GPUTestContexts;
kkinnunen3e980c32015-12-23 01:33:00 -08001271 } else if (contextType == GrContextFactory::kNull_GLContextType) {
kkinnunen179a8f52015-11-20 13:32:24 -08001272 contextSelector |= kNull_GPUTestContexts;
kkinnunen3e980c32015-12-23 01:33:00 -08001273 } else if (contextType == GrContextFactory::kDebug_GLContextType) {
kkinnunen55eeae92015-12-10 23:19:29 -08001274 contextSelector |= kDebug_GPUTestContexts;
kkinnunen179a8f52015-11-20 13:32:24 -08001275 }
1276 if ((testContexts & contextSelector) == 0) {
1277 continue;
1278 }
kkinnunen34058002016-01-06 23:49:30 -08001279 GrContextFactory::ContextInfo context = factory->getContextInfo(contextType);
1280 if (context.fGrContext) {
kkinnunen5219fd92015-12-10 06:28:13 -08001281 call_test(test, reporter, context);
1282 }
kkinnunen34058002016-01-06 23:49:30 -08001283 context = factory->getContextInfo(contextType,
1284 GrContextFactory::kEnableNVPR_GLContextOptions);
1285 if (context.fGrContext) {
kkinnunen179a8f52015-11-20 13:32:24 -08001286 call_test(test, reporter, context);
1287 }
1288 }
1289#endif
1290}
1291
1292template
1293void RunWithGPUTestContexts<TestWithGrContext>(TestWithGrContext test,
1294 GPUTestContexts testContexts,
1295 Reporter* reporter,
1296 GrContextFactory* factory);
1297template
1298void RunWithGPUTestContexts<TestWithGrContextAndGLContext>(TestWithGrContextAndGLContext test,
1299 GPUTestContexts testContexts,
1300 Reporter* reporter,
1301 GrContextFactory* factory);
1302} // namespace skiatest
1303
borenet48087572015-04-02 12:16:36 -07001304#if !defined(SK_BUILD_FOR_IOS)
jcgregorio3b27ade2014-11-13 08:06:40 -08001305int main(int argc, char** argv) {
1306 SkCommandLineFlags::Parse(argc, argv);
1307 return dm_main();
1308}
1309#endif