blob: ac37aeb09fd06a9b98a80d673ab4a5abf73b0b22 [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?");
bsalomon821e10e2015-06-04 14:15:33 -070067DEFINE_bool2(pre_log, p, false, "Log before running each test. May be incomprehensible when threading");
mtklein6393c062015-04-27 08:45:01 -070068
mtklein@google.comd36522d2013-10-16 13:02:15 +000069__SK_FORCE_IMAGE_DECODER_LINKING;
mtklein748ca3b2015-01-15 10:56:12 -080070using namespace DM;
mtklein@google.comd36522d2013-10-16 13:02:15 +000071
mtklein748ca3b2015-01-15 10:56:12 -080072/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
73
mtkleinf27f08b2015-11-03 06:54:24 -080074static double now_ms() { return SkTime::GetNSecs() * 1e-6; }
75
mtklein748ca3b2015-01-15 10:56:12 -080076SK_DECLARE_STATIC_MUTEX(gFailuresMutex);
77static SkTArray<SkString> gFailures;
78
79static void fail(ImplicitString err) {
80 SkAutoMutexAcquire lock(gFailuresMutex);
81 SkDebugf("\n\nFAILURE: %s\n\n", err.c_str());
82 gFailures.push_back(err);
halcanary9e398f72015-01-10 11:18:04 -080083}
84
mtkleinb37cb412015-03-18 05:27:14 -070085static int32_t gPending = 0; // Atomic. Total number of running and queued tasks.
86
mtkleinbc4e0032015-12-09 08:37:35 -080087SK_DECLARE_STATIC_MUTEX(gRunningAndTallyMutex);
88static SkTArray<SkString> gRunning;
89static SkTHashMap<SkString, int> gNoteTally;
mtklein748ca3b2015-01-15 10:56:12 -080090
mtkleinb9eb4ac2015-02-02 18:26:03 -080091static void done(double ms,
djsollen54416de2015-04-03 07:24:48 -070092 ImplicitString config, ImplicitString src, ImplicitString srcOptions,
93 ImplicitString name, ImplicitString note, ImplicitString log) {
94 SkString id = SkStringPrintf("%s %s %s %s", config.c_str(), src.c_str(),
95 srcOptions.c_str(), name.c_str());
mtkleinb37cb412015-03-18 05:27:14 -070096 {
mtkleinbc4e0032015-12-09 08:37:35 -080097 SkAutoMutexAcquire lock(gRunningAndTallyMutex);
mtkleinb37cb412015-03-18 05:27:14 -070098 for (int i = 0; i < gRunning.count(); i++) {
99 if (gRunning[i] == id) {
100 gRunning.removeShuffle(i);
101 break;
102 }
103 }
mtkleinbc4e0032015-12-09 08:37:35 -0800104 if (!note.isEmpty()) {
105 if (int* tally = gNoteTally.find(note)) {
106 *tally += 1;
107 } else {
108 gNoteTally.set(note, 1);
109 }
110 }
mtkleinb37cb412015-03-18 05:27:14 -0700111 }
mtkleinb9eb4ac2015-02-02 18:26:03 -0800112 if (!log.isEmpty()) {
113 log.prepend("\n");
114 }
mtklein6dee2ad2015-02-05 09:53:44 -0800115 auto pending = sk_atomic_dec(&gPending)-1;
mtkleinbc4e0032015-12-09 08:37:35 -0800116 if (!FLAGS_quiet && note.isEmpty()) {
117 SkDebugf("%s(%4d/%-4dMB %6d) %s\t%s%s", FLAGS_verbose ? "\n" : kSkOverwriteLine
reed50bc0512015-05-19 14:13:31 -0700118 , sk_tools::getCurrResidentSetSizeMB()
119 , sk_tools::getMaxResidentSetSizeMB()
120 , pending
121 , HumanizeMs(ms).c_str()
122 , id.c_str()
reed50bc0512015-05-19 14:13:31 -0700123 , log.c_str());
124 }
mtkleina17241b2015-01-23 05:48:00 -0800125 // We write our dm.json file every once in a while in case we crash.
126 // Notice this also handles the final dm.json when pending == 0.
127 if (pending % 500 == 0) {
128 JsonWriter::DumpJson();
129 }
mtklein@google.comd36522d2013-10-16 13:02:15 +0000130}
131
djsollen54416de2015-04-03 07:24:48 -0700132static void start(ImplicitString config, ImplicitString src,
133 ImplicitString srcOptions, ImplicitString name) {
134 SkString id = SkStringPrintf("%s %s %s %s", config.c_str(), src.c_str(),
135 srcOptions.c_str(), name.c_str());
mtkleinbc4e0032015-12-09 08:37:35 -0800136 SkAutoMutexAcquire lock(gRunningAndTallyMutex);
mtkleinb37cb412015-03-18 05:27:14 -0700137 gRunning.push_back(id);
138}
139
mtklein748ca3b2015-01-15 10:56:12 -0800140/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
mtklein114c3cd2015-01-15 10:15:02 -0800141
mtklein62bd1a62015-01-27 14:46:26 -0800142struct Gold : public SkString {
mtkleina82f5622015-02-20 12:30:19 -0800143 Gold() : SkString("") {}
djsollen54416de2015-04-03 07:24:48 -0700144 Gold(ImplicitString sink, ImplicitString src, ImplicitString srcOptions,
145 ImplicitString name, ImplicitString md5)
mtklein62bd1a62015-01-27 14:46:26 -0800146 : SkString("") {
147 this->append(sink);
148 this->append(src);
djsollen54416de2015-04-03 07:24:48 -0700149 this->append(srcOptions);
mtklein62bd1a62015-01-27 14:46:26 -0800150 this->append(name);
151 this->append(md5);
mtklein62bd1a62015-01-27 14:46:26 -0800152 }
mtkleinc8d1dd42015-10-15 12:23:01 -0700153 struct Hash {
154 uint32_t operator()(const Gold& g) const {
155 return SkGoodHash()((const SkString&)g);
156 }
157 };
mtklein62bd1a62015-01-27 14:46:26 -0800158};
mtkleina82f5622015-02-20 12:30:19 -0800159static SkTHashSet<Gold, Gold::Hash> gGold;
mtklein62bd1a62015-01-27 14:46:26 -0800160
161static void add_gold(JsonWriter::BitmapResult r) {
djsollen54416de2015-04-03 07:24:48 -0700162 gGold.add(Gold(r.config, r.sourceType, r.sourceOptions, r.name, r.md5));
mtklein62bd1a62015-01-27 14:46:26 -0800163}
164
165static void gather_gold() {
166 if (!FLAGS_readPath.isEmpty()) {
167 SkString path(FLAGS_readPath[0]);
168 path.append("/dm.json");
169 if (!JsonWriter::ReadJson(path.c_str(), add_gold)) {
170 fail(SkStringPrintf("Couldn't read %s for golden results.", path.c_str()));
171 }
172 }
173}
174
175/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
176
borenet09ed4802015-04-03 14:15:33 -0700177static SkTHashSet<SkString> gUninterestingHashes;
178
179static void gather_uninteresting_hashes() {
180 if (!FLAGS_uninterestingHashesFile.isEmpty()) {
181 SkAutoTUnref<SkData> data(SkData::NewFromFileName(FLAGS_uninterestingHashesFile[0]));
mtkleincc334b32015-09-22 11:43:53 -0700182 if (!data) {
183 SkDebugf("WARNING: unable to read uninteresting hashes from %s\n",
184 FLAGS_uninterestingHashesFile[0]);
185 return;
186 }
borenet09ed4802015-04-03 14:15:33 -0700187 SkTArray<SkString> hashes;
188 SkStrSplit((const char*)data->data(), "\n", &hashes);
189 for (const SkString& hash : hashes) {
190 gUninterestingHashes.add(hash);
191 }
192 }
193}
194
195/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
196
mtkleine0effd62015-07-29 06:37:28 -0700197struct TaggedSrc : public SkAutoTDelete<Src> {
msarett9e707a02015-09-01 14:57:57 -0700198 ImplicitString tag;
199 ImplicitString options;
mtkleine0effd62015-07-29 06:37:28 -0700200};
201
202struct TaggedSink : public SkAutoTDelete<Sink> {
kkinnunen3e980c32015-12-23 01:33:00 -0800203 SkString tag;
djsollen54416de2015-04-03 07:24:48 -0700204};
mtklein748ca3b2015-01-15 10:56:12 -0800205
206static const bool kMemcpyOK = true;
207
mtkleine0effd62015-07-29 06:37:28 -0700208static SkTArray<TaggedSrc, kMemcpyOK> gSrcs;
209static SkTArray<TaggedSink, kMemcpyOK> gSinks;
mtklein748ca3b2015-01-15 10:56:12 -0800210
mtklein6393c062015-04-27 08:45:01 -0700211static bool in_shard() {
212 static int N = 0;
213 return N++ % FLAGS_shards == FLAGS_shard;
214}
215
msarett9e707a02015-09-01 14:57:57 -0700216static void push_src(ImplicitString tag, ImplicitString options, Src* s) {
mtklein748ca3b2015-01-15 10:56:12 -0800217 SkAutoTDelete<Src> src(s);
mtklein6393c062015-04-27 08:45:01 -0700218 if (in_shard() &&
msarett9e707a02015-09-01 14:57:57 -0700219 FLAGS_src.contains(tag.c_str()) &&
mtklein748ca3b2015-01-15 10:56:12 -0800220 !SkCommandLineFlags::ShouldSkip(FLAGS_match, src->name().c_str())) {
mtkleine0effd62015-07-29 06:37:28 -0700221 TaggedSrc& s = gSrcs.push_back();
mtklein748ca3b2015-01-15 10:56:12 -0800222 s.reset(src.detach());
223 s.tag = tag;
djsollen54416de2015-04-03 07:24:48 -0700224 s.options = options;
mtklein114c3cd2015-01-15 10:15:02 -0800225 }
mtklein748ca3b2015-01-15 10:56:12 -0800226}
mtklein114c3cd2015-01-15 10:15:02 -0800227
msarett9e707a02015-09-01 14:57:57 -0700228static void push_codec_src(Path path, CodecSrc::Mode mode, CodecSrc::DstColorType dstColorType,
229 float scale) {
230 SkString folder;
231 switch (mode) {
232 case CodecSrc::kCodec_Mode:
233 folder.append("codec");
234 break;
msarett9e707a02015-09-01 14:57:57 -0700235 case CodecSrc::kScanline_Mode:
236 folder.append("scanline");
237 break;
msarett9e707a02015-09-01 14:57:57 -0700238 case CodecSrc::kStripe_Mode:
239 folder.append("stripe");
240 break;
241 case CodecSrc::kSubset_Mode:
msarett36c37962015-09-02 13:20:52 -0700242 folder.append("codec_subset");
msarett9e707a02015-09-01 14:57:57 -0700243 break;
244 }
245
246 switch (dstColorType) {
247 case CodecSrc::kGrayscale_Always_DstColorType:
248 folder.append("_kGray8");
249 break;
250 case CodecSrc::kIndex8_Always_DstColorType:
251 folder.append("_kIndex8");
252 break;
253 default:
254 break;
255 }
256
257 if (1.0f != scale) {
258 folder.appendf("_%.3f", scale);
259 }
260
261 CodecSrc* src = new CodecSrc(path, mode, dstColorType, scale);
262 push_src("image", folder, src);
263}
264
msarett3d9d7a72015-10-21 10:27:10 -0700265static void push_android_codec_src(Path path, AndroidCodecSrc::Mode mode,
266 CodecSrc::DstColorType dstColorType, int sampleSize) {
267 SkString folder;
268 switch (mode) {
269 case AndroidCodecSrc::kFullImage_Mode:
270 folder.append("scaled_codec");
271 break;
272 case AndroidCodecSrc::kDivisor_Mode:
273 folder.append("scaled_codec_divisor");
274 break;
275 }
276
277 switch (dstColorType) {
278 case CodecSrc::kGrayscale_Always_DstColorType:
279 folder.append("_kGray8");
280 break;
281 case CodecSrc::kIndex8_Always_DstColorType:
282 folder.append("_kIndex8");
283 break;
284 default:
285 break;
286 }
287
288 if (1 != sampleSize) {
msarett4b0778e2015-11-13 09:59:11 -0800289 folder.appendf("_%.3f", 1.0f / (float) sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700290 }
291
292 AndroidCodecSrc* src = new AndroidCodecSrc(path, mode, dstColorType, sampleSize);
293 push_src("image", folder, src);
294}
295
msarett438b2ad2015-04-09 12:43:10 -0700296static void push_codec_srcs(Path path) {
297 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str()));
298 if (!encoded) {
299 SkDebugf("Couldn't read %s.", path.c_str());
300 return;
301 }
302 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
halcanary96fcdcc2015-08-27 07:41:13 -0700303 if (nullptr == codec.get()) {
msarett438b2ad2015-04-09 12:43:10 -0700304 SkDebugf("Couldn't create codec for %s.", path.c_str());
305 return;
306 }
307
msarett36c37962015-09-02 13:20:52 -0700308 // Native Scales
msarett0a242972015-06-11 14:27:27 -0700309 // TODO (msarett): Implement scaling tests for SkImageDecoder in order to compare with these
310 // tests. SkImageDecoder supports downscales by integer factors.
emmaleer8f4ba762015-08-14 07:44:46 -0700311 // 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 -0700312 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 -0700313
msarett36c37962015-09-02 13:20:52 -0700314 const CodecSrc::Mode nativeModes[] = { CodecSrc::kCodec_Mode, CodecSrc::kScanline_Mode,
msarett5af4e0b2015-11-17 11:18:03 -0800315 CodecSrc::kStripe_Mode, CodecSrc::kSubset_Mode };
msarett9e707a02015-09-01 14:57:57 -0700316
msarett36c37962015-09-02 13:20:52 -0700317 CodecSrc::DstColorType colorTypes[3];
318 uint32_t numColorTypes;
319 switch (codec->getInfo().colorType()) {
320 case kGray_8_SkColorType:
321 // FIXME: Is this a long term solution for testing wbmps decodes to kIndex8?
halcanary6950de62015-11-07 05:29:00 -0800322 // Further discussion on this topic is at https://bug.skia.org/3683 .
msarett3d9d7a72015-10-21 10:27:10 -0700323 // This causes us to try to convert grayscale jpegs to kIndex8. We currently
324 // fail non-fatally in this case.
msarett36c37962015-09-02 13:20:52 -0700325 colorTypes[0] = CodecSrc::kGetFromCanvas_DstColorType;
326 colorTypes[1] = CodecSrc::kGrayscale_Always_DstColorType;
327 colorTypes[2] = CodecSrc::kIndex8_Always_DstColorType;
328 numColorTypes = 3;
329 break;
330 case kIndex_8_SkColorType:
331 colorTypes[0] = CodecSrc::kGetFromCanvas_DstColorType;
332 colorTypes[1] = CodecSrc::kIndex8_Always_DstColorType;
333 numColorTypes = 2;
334 break;
335 default:
336 colorTypes[0] = CodecSrc::kGetFromCanvas_DstColorType;
337 numColorTypes = 1;
338 break;
339 }
msarett9e707a02015-09-01 14:57:57 -0700340
msarett36c37962015-09-02 13:20:52 -0700341 for (float scale : nativeScales) {
msarett36c37962015-09-02 13:20:52 -0700342 for (CodecSrc::Mode mode : nativeModes) {
343 for (uint32_t i = 0; i < numColorTypes; i++) {
344 push_codec_src(path, mode, colorTypes[i], scale);
msarett9e707a02015-09-01 14:57:57 -0700345 }
346 }
msarett0a242972015-06-11 14:27:27 -0700347 }
msarett36c37962015-09-02 13:20:52 -0700348
halcanary6950de62015-11-07 05:29:00 -0800349 // https://bug.skia.org/4428
msarett33c76232015-11-16 13:43:40 -0800350 bool subset = false;
351 // The following image types are supported by BitmapRegionDecoder,
352 // so we will test full image decodes and subset decodes.
msarettbe8216a2015-12-04 08:00:50 -0800353 static const char* const exts[] = {
msarett3d9d7a72015-10-21 10:27:10 -0700354 "jpg", "jpeg", "png", "webp",
355 "JPG", "JPEG", "PNG", "WEBP",
356 };
msarettbe8216a2015-12-04 08:00:50 -0800357 for (const char* ext : exts) {
msarett3d9d7a72015-10-21 10:27:10 -0700358 if (path.endsWith(ext)) {
msarett33c76232015-11-16 13:43:40 -0800359 subset = true;
msarett3d9d7a72015-10-21 10:27:10 -0700360 break;
361 }
362 }
msarett33c76232015-11-16 13:43:40 -0800363
msarett3d9d7a72015-10-21 10:27:10 -0700364 const int sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
msarett36c37962015-09-02 13:20:52 -0700365
msarett3d9d7a72015-10-21 10:27:10 -0700366 for (int sampleSize : sampleSizes) {
msarett33c76232015-11-16 13:43:40 -0800367 for (uint32_t i = 0; i < numColorTypes; i++) {
368 push_android_codec_src(path, AndroidCodecSrc::kFullImage_Mode, colorTypes[i],
369 sampleSize);
370 if (subset) {
371 push_android_codec_src(path, AndroidCodecSrc::kDivisor_Mode, colorTypes[i],
372 sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700373 }
msarett36c37962015-09-02 13:20:52 -0700374 }
375 }
msarett438b2ad2015-04-09 12:43:10 -0700376}
377
msarett5cb48852015-11-06 08:56:32 -0800378static bool brd_color_type_supported(SkBitmapRegionDecoder::Strategy strategy,
msaretta5783ae2015-09-08 15:35:32 -0700379 CodecSrc::DstColorType dstColorType) {
380 switch (strategy) {
msarett5cb48852015-11-06 08:56:32 -0800381 case SkBitmapRegionDecoder::kCanvas_Strategy:
msaretta5783ae2015-09-08 15:35:32 -0700382 if (CodecSrc::kGetFromCanvas_DstColorType == dstColorType) {
383 return true;
384 }
385 return false;
msarett5cb48852015-11-06 08:56:32 -0800386 case SkBitmapRegionDecoder::kAndroidCodec_Strategy:
msarett26ad17b2015-10-22 07:29:19 -0700387 switch (dstColorType) {
388 case CodecSrc::kGetFromCanvas_DstColorType:
389 case CodecSrc::kIndex8_Always_DstColorType:
390 case CodecSrc::kGrayscale_Always_DstColorType:
391 return true;
392 default:
393 return false;
394 }
msaretta5783ae2015-09-08 15:35:32 -0700395 default:
396 SkASSERT(false);
397 return false;
398 }
399}
400
msarett5cb48852015-11-06 08:56:32 -0800401static void push_brd_src(Path path, SkBitmapRegionDecoder::Strategy strategy,
msaretta5783ae2015-09-08 15:35:32 -0700402 CodecSrc::DstColorType dstColorType, BRDSrc::Mode mode, uint32_t sampleSize) {
403 SkString folder;
404 switch (strategy) {
msarett5cb48852015-11-06 08:56:32 -0800405 case SkBitmapRegionDecoder::kCanvas_Strategy:
msaretta5783ae2015-09-08 15:35:32 -0700406 folder.append("brd_canvas");
407 break;
msarett5cb48852015-11-06 08:56:32 -0800408 case SkBitmapRegionDecoder::kAndroidCodec_Strategy:
msarett26ad17b2015-10-22 07:29:19 -0700409 folder.append("brd_android_codec");
410 break;
msaretta5783ae2015-09-08 15:35:32 -0700411 default:
412 SkASSERT(false);
413 return;
414 }
415
416 switch (mode) {
417 case BRDSrc::kFullImage_Mode:
418 break;
419 case BRDSrc::kDivisor_Mode:
420 folder.append("_divisor");
421 break;
422 default:
423 SkASSERT(false);
424 return;
425 }
426
427 switch (dstColorType) {
428 case CodecSrc::kGetFromCanvas_DstColorType:
429 break;
430 case CodecSrc::kIndex8_Always_DstColorType:
431 folder.append("_kIndex");
432 break;
433 case CodecSrc::kGrayscale_Always_DstColorType:
434 folder.append("_kGray");
435 break;
436 default:
437 SkASSERT(false);
438 return;
439 }
440
441 if (1 != sampleSize) {
msarett4b0778e2015-11-13 09:59:11 -0800442 folder.appendf("_%.3f", 1.0f / (float) sampleSize);
msaretta5783ae2015-09-08 15:35:32 -0700443 }
444
445 BRDSrc* src = new BRDSrc(path, strategy, mode, dstColorType, sampleSize);
446 push_src("image", folder, src);
447}
448
449static void push_brd_srcs(Path path) {
450
msarett5cb48852015-11-06 08:56:32 -0800451 const SkBitmapRegionDecoder::Strategy strategies[] = {
452 SkBitmapRegionDecoder::kCanvas_Strategy,
msarett5cb48852015-11-06 08:56:32 -0800453 SkBitmapRegionDecoder::kAndroidCodec_Strategy,
msaretta5783ae2015-09-08 15:35:32 -0700454 };
455
scroggo501b7342015-11-03 07:55:11 -0800456 // Test on a variety of sampleSizes, making sure to include:
457 // - 2, 4, and 8, which are natively supported by jpeg
458 // - multiples of 2 which are not divisible by 4 (analogous for 4)
459 // - larger powers of two, since BRD clients generally use powers of 2
460 // We will only produce output for the larger sizes on large images.
461 const uint32_t sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 24, 32, 64 };
msarett6efbe052015-09-11 09:01:16 -0700462
msaretta5783ae2015-09-08 15:35:32 -0700463 // We will only test to one backend (8888), but we will test all of the
464 // color types that we need to decode to on this backend.
465 const CodecSrc::DstColorType dstColorTypes[] = {
msarett26ad17b2015-10-22 07:29:19 -0700466 CodecSrc::kGetFromCanvas_DstColorType,
467 CodecSrc::kIndex8_Always_DstColorType,
468 CodecSrc::kGrayscale_Always_DstColorType,
msaretta5783ae2015-09-08 15:35:32 -0700469 };
470
471 const BRDSrc::Mode modes[] = {
msarett26ad17b2015-10-22 07:29:19 -0700472 BRDSrc::kFullImage_Mode,
473 BRDSrc::kDivisor_Mode,
msaretta5783ae2015-09-08 15:35:32 -0700474 };
475
msarett5cb48852015-11-06 08:56:32 -0800476 for (SkBitmapRegionDecoder::Strategy strategy : strategies) {
msarett6efbe052015-09-11 09:01:16 -0700477 for (uint32_t sampleSize : sampleSizes) {
msarett6efbe052015-09-11 09:01:16 -0700478 for (CodecSrc::DstColorType dstColorType : dstColorTypes) {
479 if (brd_color_type_supported(strategy, dstColorType)) {
480 for (BRDSrc::Mode mode : modes) {
msaretta5783ae2015-09-08 15:35:32 -0700481 push_brd_src(path, strategy, dstColorType, mode, sampleSize);
482 }
483 }
484 }
485 }
486 }
487}
488
489static bool brd_supported(const char* ext) {
msarett8c8f22a2015-04-01 06:58:48 -0700490 static const char* const exts[] = {
msaretta5783ae2015-09-08 15:35:32 -0700491 "jpg", "jpeg", "png", "webp",
492 "JPG", "JPEG", "PNG", "WEBP",
msarett8c8f22a2015-04-01 06:58:48 -0700493 };
494
495 for (uint32_t i = 0; i < SK_ARRAY_COUNT(exts); i++) {
496 if (0 == strcmp(exts[i], ext)) {
497 return true;
498 }
499 }
500 return false;
scroggo9b77ddd2015-03-19 06:03:39 -0700501}
502
mtklein748ca3b2015-01-15 10:56:12 -0800503static void gather_srcs() {
504 for (const skiagm::GMRegistry* r = skiagm::GMRegistry::Head(); r; r = r->next()) {
djsollen54416de2015-04-03 07:24:48 -0700505 push_src("gm", "", new GMSrc(r->factory()));
mtklein748ca3b2015-01-15 10:56:12 -0800506 }
halcanaryfc37ad12015-01-30 07:31:19 -0800507 for (int i = 0; i < FLAGS_skps.count(); i++) {
508 const char* path = FLAGS_skps[i];
509 if (sk_isdir(path)) {
510 SkOSFile::Iter it(path, "skp");
511 for (SkString file; it.next(&file); ) {
djsollen54416de2015-04-03 07:24:48 -0700512 push_src("skp", "", new SKPSrc(SkOSPath::Join(path, file.c_str())));
halcanaryfc37ad12015-01-30 07:31:19 -0800513 }
514 } else {
djsollen54416de2015-04-03 07:24:48 -0700515 push_src("skp", "", new SKPSrc(path));
mtklein114c3cd2015-01-15 10:15:02 -0800516 }
517 }
halcanary23b03c32015-01-30 09:58:58 -0800518 static const char* const exts[] = {
519 "bmp", "gif", "jpg", "jpeg", "png", "webp", "ktx", "astc", "wbmp", "ico",
520 "BMP", "GIF", "JPG", "JPEG", "PNG", "WEBP", "KTX", "ASTC", "WBMP", "ICO",
521 };
522 for (int i = 0; i < FLAGS_images.count(); i++) {
523 const char* flag = FLAGS_images[i];
524 if (sk_isdir(flag)) {
525 for (size_t j = 0; j < SK_ARRAY_COUNT(exts); j++) {
526 SkOSFile::Iter it(flag, exts[j]);
527 for (SkString file; it.next(&file); ) {
528 SkString path = SkOSPath::Join(flag, file.c_str());
djsollen54416de2015-04-03 07:24:48 -0700529 push_src("image", "decode", new ImageSrc(path)); // Decode entire image
msaretta5783ae2015-09-08 15:35:32 -0700530 push_codec_srcs(path);
531 if (brd_supported(exts[j])) {
532 push_brd_srcs(path);
scroggo9b77ddd2015-03-19 06:03:39 -0700533 }
halcanary23b03c32015-01-30 09:58:58 -0800534 }
mtklein114c3cd2015-01-15 10:15:02 -0800535 }
halcanary23b03c32015-01-30 09:58:58 -0800536 } else if (sk_exists(flag)) {
537 // assume that FLAGS_images[i] is a valid image if it is a file.
djsollen54416de2015-04-03 07:24:48 -0700538 push_src("image", "decode", new ImageSrc(flag)); // Decode entire image.
msarett438b2ad2015-04-09 12:43:10 -0700539 push_codec_srcs(flag);
msaretta5783ae2015-09-08 15:35:32 -0700540 push_brd_srcs(flag);
mtklein709d2c32015-01-15 08:30:25 -0800541 }
mtklein709d2c32015-01-15 08:30:25 -0800542 }
543}
544
kkinnunen3e980c32015-12-23 01:33:00 -0800545static void push_sink(const SkCommandLineConfig& config, Sink* s) {
rmistry0f515bd2015-12-22 10:22:26 -0800546 SkAutoTDelete<Sink> sink(s);
kkinnunen3e980c32015-12-23 01:33:00 -0800547
mtkleine0effd62015-07-29 06:37:28 -0700548 // Try a simple Src as a canary. If it fails, skip this sink.
mtklein748ca3b2015-01-15 10:56:12 -0800549 struct : public Src {
mtkleine0effd62015-07-29 06:37:28 -0700550 Error draw(SkCanvas* c) const override {
551 c->drawRect(SkRect::MakeWH(1,1), SkPaint());
552 return "";
553 }
mtklein36352bf2015-03-25 18:17:31 -0700554 SkISize size() const override { return SkISize::Make(16, 16); }
mtkleine0effd62015-07-29 06:37:28 -0700555 Name name() const override { return "justOneRect"; }
556 } justOneRect;
mtklein114c3cd2015-01-15 10:15:02 -0800557
mtklein748ca3b2015-01-15 10:56:12 -0800558 SkBitmap bitmap;
559 SkDynamicMemoryWStream stream;
mtkleinb9eb4ac2015-02-02 18:26:03 -0800560 SkString log;
mtkleine0effd62015-07-29 06:37:28 -0700561 Error err = sink->draw(justOneRect, &bitmap, &stream, &log);
mtklein4089ef72015-03-05 08:40:28 -0800562 if (err.isFatal()) {
kkinnunen3e980c32015-12-23 01:33:00 -0800563 SkDebugf("Could not run %s: %s\n", config.getTag().c_str(), err.c_str());
mtklein05641a52015-04-21 10:49:13 -0700564 exit(1);
mtklein114c3cd2015-01-15 10:15:02 -0800565 }
566
mtkleine0effd62015-07-29 06:37:28 -0700567 TaggedSink& ts = gSinks.push_back();
mtklein748ca3b2015-01-15 10:56:12 -0800568 ts.reset(sink.detach());
kkinnunen3e980c32015-12-23 01:33:00 -0800569 ts.tag = config.getTag();
mtklein748ca3b2015-01-15 10:56:12 -0800570}
571
572static bool gpu_supported() {
573#if SK_SUPPORT_GPU
574 return FLAGS_gpu;
575#else
576 return false;
577#endif
578}
kkinnunen9ebc3f02015-12-21 23:48:13 -0800579
kkinnunen3e980c32015-12-23 01:33:00 -0800580static Sink* create_sink(const SkCommandLineConfig* config) {
581#if SK_SUPPORT_GPU
582 if (gpu_supported()) {
583 if (const SkCommandLineConfigGpu* gpuConfig = config->asConfigGpu()) {
584 GrContextFactory::GLContextType contextType = gpuConfig->getContextType();
585 GrContextFactory::GLContextOptions contextOptions =
586 GrContextFactory::kNone_GLContextOptions;
587 if (gpuConfig->getUseNVPR()) {
588 contextOptions = static_cast<GrContextFactory::GLContextOptions>(
589 contextOptions | GrContextFactory::kEnableNVPR_GLContextOptions);
590 }
591 GrContextFactory testFactory;
592 if (!testFactory.get(contextType, contextOptions)) {
593 SkDebugf("WARNING: can not create GPU context for config '%s'. "
594 "GM tests will be skipped.\n", gpuConfig->getTag().c_str());
595 return nullptr;
596 }
597 return new GPUSink(contextType, contextOptions, gpuConfig->getSamples(),
598 gpuConfig->getUseDIText(), FLAGS_gpu_threading);
599 }
600 }
601#endif
602
603#define SINK(t, sink, ...) if (config->getBackend().equals(t)) { return new sink(__VA_ARGS__); }
604
tomhudsoneebc39a2015-02-23 12:18:05 -0800605#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
606 SINK("hwui", HWUISink);
607#endif
608
mtklein748ca3b2015-01-15 10:56:12 -0800609 if (FLAGS_cpu) {
610 SINK("565", RasterSink, kRGB_565_SkColorType);
611 SINK("8888", RasterSink, kN32_SkColorType);
halcanaryc11c62f2015-09-28 11:51:54 -0700612 SINK("pdf", PDFSink, "Pdfium");
613 SINK("pdf_poppler", PDFSink, "Poppler");
mtklein9c3f17d2015-01-28 11:35:18 -0800614 SINK("skp", SKPSink);
mtklein8a4527e2015-01-31 20:00:58 -0800615 SINK("svg", SVGSink);
616 SINK("null", NullSink);
halcanary47ef4d52015-03-03 09:13:09 -0800617 SINK("xps", XPSSink);
mtklein748ca3b2015-01-15 10:56:12 -0800618 }
619#undef SINK
halcanary96fcdcc2015-08-27 07:41:13 -0700620 return nullptr;
mtklein114c3cd2015-01-15 10:15:02 -0800621}
622
kkinnunen3e980c32015-12-23 01:33:00 -0800623static Sink* create_via(const SkString& tag, Sink* wrapped) {
624#define VIA(t, via, ...) if (tag.equals(t)) { return new via(__VA_ARGS__); }
halcanary96fcdcc2015-08-27 07:41:13 -0700625 VIA("twice", ViaTwice, wrapped);
626 VIA("pipe", ViaPipe, wrapped);
627 VIA("serialize", ViaSerialization, wrapped);
628 VIA("2ndpic", ViaSecondPicture, wrapped);
mtkleind31c13d2015-05-05 12:59:56 -0700629 VIA("sp", ViaSingletonPictures, wrapped);
halcanary96fcdcc2015-08-27 07:41:13 -0700630 VIA("tiles", ViaTiles, 256, 256, nullptr, wrapped);
mtklein7edca212015-01-21 13:18:51 -0800631 VIA("tiles_rt", ViaTiles, 256, 256, new SkRTreeFactory, wrapped);
mtklein2e2ea382015-10-16 10:29:41 -0700632 VIA("remote", ViaRemote, false, wrapped);
633 VIA("remote_cache", ViaRemote, true, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800634
mtkleind603b222015-02-17 11:13:33 -0800635 if (FLAGS_matrix.count() == 4) {
mtklein748ca3b2015-01-15 10:56:12 -0800636 SkMatrix m;
mtkleind603b222015-02-17 11:13:33 -0800637 m.reset();
638 m.setScaleX((SkScalar)atof(FLAGS_matrix[0]));
639 m.setSkewX ((SkScalar)atof(FLAGS_matrix[1]));
640 m.setSkewY ((SkScalar)atof(FLAGS_matrix[2]));
641 m.setScaleY((SkScalar)atof(FLAGS_matrix[3]));
642 VIA("matrix", ViaMatrix, m, wrapped);
643 VIA("upright", ViaUpright, m, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800644 }
tomhudson64de1e12015-03-05 08:01:07 -0800645
646#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
647 VIA("androidsdk", ViaAndroidSDK, wrapped);
648#endif
649
mtklein748ca3b2015-01-15 10:56:12 -0800650#undef VIA
halcanary96fcdcc2015-08-27 07:41:13 -0700651 return nullptr;
mtklein114c3cd2015-01-15 10:15:02 -0800652}
653
mtklein748ca3b2015-01-15 10:56:12 -0800654static void gather_sinks() {
kkinnunen3e980c32015-12-23 01:33:00 -0800655 SkCommandLineConfigArray configs;
656 ParseConfigs(FLAGS_config, &configs);
657 for (int i = 0; i < configs.count(); i++) {
658 const SkCommandLineConfig& config = *configs[i];
659 Sink* sink = create_sink(&config);
660 if (sink == nullptr) {
661 SkDebugf("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(),
662 config.getTag().c_str());
663 continue;
664 }
mtklein748ca3b2015-01-15 10:56:12 -0800665
kkinnunen3e980c32015-12-23 01:33:00 -0800666 const SkTArray<SkString>& parts = config.getViaParts();
667 for (int j = parts.count(); j-- > 0;) {
668 const SkString& part = parts[j];
669 Sink* next = create_via(part, sink);
halcanary96fcdcc2015-08-27 07:41:13 -0700670 if (next == nullptr) {
kkinnunen3e980c32015-12-23 01:33:00 -0800671 SkDebugf("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(),
672 part.c_str());
mtklein748ca3b2015-01-15 10:56:12 -0800673 delete sink;
halcanary96fcdcc2015-08-27 07:41:13 -0700674 sink = nullptr;
mtklein748ca3b2015-01-15 10:56:12 -0800675 break;
676 }
677 sink = next;
678 }
679 if (sink) {
680 push_sink(config, sink);
mtklein114c3cd2015-01-15 10:15:02 -0800681 }
682 }
683}
mtklein709d2c32015-01-15 08:30:25 -0800684
mtkleina5114d72015-08-24 13:27:01 -0700685static bool dump_png(SkBitmap bitmap, const char* path, const char* md5) {
686 const int w = bitmap.width(),
687 h = bitmap.height();
688
689 // First get the bitmap into N32 color format. The next step will work only there.
690 if (bitmap.colorType() != kN32_SkColorType) {
691 SkBitmap n32;
692 if (!bitmap.copyTo(&n32, kN32_SkColorType)) {
693 return false;
694 }
695 bitmap = n32;
696 }
697
698 // Convert our N32 bitmap into unpremul RGBA for libpng.
699 SkAutoTMalloc<uint32_t> rgba(w*h);
700 if (!bitmap.readPixels(SkImageInfo::Make(w,h, kRGBA_8888_SkColorType, kUnpremul_SkAlphaType),
701 rgba, 4*w, 0,0)) {
702 return false;
703 }
704
705 // We don't need bitmap anymore. Might as well drop our ref.
mtkleinfccb77d2015-08-24 14:13:29 -0700706 bitmap.reset();
mtkleina5114d72015-08-24 13:27:01 -0700707
mtkleinc64137c2015-08-25 10:56:08 -0700708 FILE* f = fopen(path, "wb");
mtkleina5114d72015-08-24 13:27:01 -0700709 if (!f) { return false; }
710
711 png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
712 if (!png) {
713 fclose(f);
714 return false;
715 }
716
717 png_infop info = png_create_info_struct(png);
718 if (!info) {
719 png_destroy_write_struct(&png, &info);
720 fclose(f);
721 return false;
722 }
723
mtkleind69ece62015-09-10 10:37:44 -0700724 SkString description;
725 description.append("Key: ");
726 for (int i = 0; i < FLAGS_key.count(); i++) {
727 description.appendf("%s ", FLAGS_key[i]);
728 }
729 description.append("Properties: ");
730 for (int i = 0; i < FLAGS_properties.count(); i++) {
731 description.appendf("%s ", FLAGS_properties[i]);
732 }
733 description.appendf("MD5: %s", md5);
734
mtkleina5114d72015-08-24 13:27:01 -0700735 png_text text[2];
736 text[0].key = (png_charp)"Author";
737 text[0].text = (png_charp)"DM dump_png()";
738 text[0].compression = PNG_TEXT_COMPRESSION_NONE;
739 text[1].key = (png_charp)"Description";
mtkleind69ece62015-09-10 10:37:44 -0700740 text[1].text = (png_charp)description.c_str();
mtkleina5114d72015-08-24 13:27:01 -0700741 text[1].compression = PNG_TEXT_COMPRESSION_NONE;
742 png_set_text(png, info, text, 2);
743
744 png_init_io(png, f);
745 png_set_IHDR(png, info, (png_uint_32)w, (png_uint_32)h, 8,
746 PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE,
747 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
748 png_write_info(png, info);
749 for (int j = 0; j < h; j++) {
750 png_bytep row = (png_bytep)(rgba.get() + w*j);
751 png_write_rows(png, &row, 1);
752 }
753 png_write_end(png, info);
754
755 png_destroy_write_struct(&png, &info);
756 fclose(f);
757 return true;
758}
759
mtkleina2ef6422015-01-15 13:44:22 -0800760static bool match(const char* needle, const char* haystack) {
halcanary96fcdcc2015-08-27 07:41:13 -0700761 return 0 == strcmp("_", needle) || nullptr != strstr(haystack, needle);
mtkleina2ef6422015-01-15 13:44:22 -0800762}
763
djsollen54416de2015-04-03 07:24:48 -0700764static ImplicitString is_blacklisted(const char* sink, const char* src,
765 const char* srcOptions, const char* name) {
mtklein0d243ff2015-04-03 07:51:00 -0700766 for (int i = 0; i < FLAGS_blacklist.count() - 3; i += 4) {
mtkleina2ef6422015-01-15 13:44:22 -0800767 if (match(FLAGS_blacklist[i+0], sink) &&
djsollen54416de2015-04-03 07:24:48 -0700768 match(FLAGS_blacklist[i+1], src) &&
769 match(FLAGS_blacklist[i+2], srcOptions) &&
770 match(FLAGS_blacklist[i+3], name)) {
771 return SkStringPrintf("%s %s %s %s",
772 FLAGS_blacklist[i+0], FLAGS_blacklist[i+1],
773 FLAGS_blacklist[i+2], FLAGS_blacklist[i+3]);
mtkleina2ef6422015-01-15 13:44:22 -0800774 }
775 }
776 return "";
777}
778
mtklein748ca3b2015-01-15 10:56:12 -0800779// The finest-grained unit of work we can run: draw a single Src into a single Sink,
780// report any errors, and perhaps write out the output: a .png of the bitmap, or a raw stream.
781struct Task {
mtkleine0effd62015-07-29 06:37:28 -0700782 Task(const TaggedSrc& src, const TaggedSink& sink) : src(src), sink(sink) {}
783 const TaggedSrc& src;
784 const TaggedSink& sink;
mtklein748ca3b2015-01-15 10:56:12 -0800785
786 static void Run(Task* task) {
mtkleina2ef6422015-01-15 13:44:22 -0800787 SkString name = task->src->name();
mtkleine0effd62015-07-29 06:37:28 -0700788
789 // We'll skip drawing this Src/Sink pair if:
790 // - the Src vetoes the Sink;
791 // - this Src / Sink combination is on the blacklist;
792 // - it's a dry run.
mtklein99cab4e2015-07-31 06:43:04 -0700793 SkString note(task->src->veto(task->sink->flags()) ? " (veto)" : "");
kkinnunen3e980c32015-12-23 01:33:00 -0800794 SkString whyBlacklisted = is_blacklisted(task->sink.tag.c_str(), task->src.tag.c_str(),
msarett9e707a02015-09-01 14:57:57 -0700795 task->src.options.c_str(), name.c_str());
mtkleinb37cb412015-03-18 05:27:14 -0700796 if (!whyBlacklisted.isEmpty()) {
797 note.appendf(" (--blacklist %s)", whyBlacklisted.c_str());
798 }
mtkleine0effd62015-07-29 06:37:28 -0700799
mtkleinb9eb4ac2015-02-02 18:26:03 -0800800 SkString log;
mtkleinf27f08b2015-11-03 06:54:24 -0800801 auto timerStart = now_ms();
mtkleine0effd62015-07-29 06:37:28 -0700802 if (!FLAGS_dryRun && note.isEmpty()) {
mtklein748ca3b2015-01-15 10:56:12 -0800803 SkBitmap bitmap;
804 SkDynamicMemoryWStream stream;
bsalomon821e10e2015-06-04 14:15:33 -0700805 if (FLAGS_pre_log) {
kkinnunen3e980c32015-12-23 01:33:00 -0800806 SkDebugf("\nRunning %s->%s", name.c_str(), task->sink.tag.c_str());
bsalomon821e10e2015-06-04 14:15:33 -0700807 }
kkinnunen3e980c32015-12-23 01:33:00 -0800808 start(task->sink.tag.c_str(), task->src.tag, task->src.options, name.c_str());
mtkleinb9eb4ac2015-02-02 18:26:03 -0800809 Error err = task->sink->draw(*task->src, &bitmap, &stream, &log);
mtklein748ca3b2015-01-15 10:56:12 -0800810 if (!err.isEmpty()) {
mtkleinf27f08b2015-11-03 06:54:24 -0800811 auto elapsed = now_ms() - timerStart;
mtklein4089ef72015-03-05 08:40:28 -0800812 if (err.isFatal()) {
djsollen54416de2015-04-03 07:24:48 -0700813 fail(SkStringPrintf("%s %s %s %s: %s",
kkinnunen3e980c32015-12-23 01:33:00 -0800814 task->sink.tag.c_str(),
msarett9e707a02015-09-01 14:57:57 -0700815 task->src.tag.c_str(),
816 task->src.options.c_str(),
mtklein4089ef72015-03-05 08:40:28 -0800817 name.c_str(),
818 err.c_str()));
mtkleinb37cb412015-03-18 05:27:14 -0700819 } else {
820 note.appendf(" (skipped: %s)", err.c_str());
mtklein4089ef72015-03-05 08:40:28 -0800821 }
kkinnunen3e980c32015-12-23 01:33:00 -0800822 done(elapsed, task->sink.tag.c_str(), task->src.tag, task->src.options,
djsollen54416de2015-04-03 07:24:48 -0700823 name, note, log);
mtklein4089ef72015-03-05 08:40:28 -0800824 return;
mtklein748ca3b2015-01-15 10:56:12 -0800825 }
mtklein62bd1a62015-01-27 14:46:26 -0800826 SkAutoTDelete<SkStreamAsset> data(stream.detachAsStream());
827
828 SkString md5;
829 if (!FLAGS_writePath.isEmpty() || !FLAGS_readPath.isEmpty()) {
830 SkMD5 hash;
831 if (data->getLength()) {
832 hash.writeStream(data, data->getLength());
833 data->rewind();
834 } else {
mtklein38408462015-07-08 07:25:27 -0700835 // If we're BGRA (Linux, Windows), swizzle over to RGBA (Mac, Android).
836 // This helps eliminate multiple 0-pixel-diff hashes on gold.skia.org.
837 // (Android's general slow speed breaks the tie arbitrarily in RGBA's favor.)
838 // We might consider promoting 565 to RGBA too.
839 if (bitmap.colorType() == kBGRA_8888_SkColorType) {
840 SkBitmap swizzle;
841 SkAssertResult(bitmap.copyTo(&swizzle, kRGBA_8888_SkColorType));
842 hash.write(swizzle.getPixels(), swizzle.getSize());
843 } else {
844 hash.write(bitmap.getPixels(), bitmap.getSize());
845 }
mtklein62bd1a62015-01-27 14:46:26 -0800846 }
847 SkMD5::Digest digest;
848 hash.finish(digest);
849 for (int i = 0; i < 16; i++) {
850 md5.appendf("%02x", digest.data[i]);
851 }
852 }
853
854 if (!FLAGS_readPath.isEmpty() &&
kkinnunen3e980c32015-12-23 01:33:00 -0800855 !gGold.contains(Gold(task->sink.tag.c_str(), task->src.tag.c_str(),
msarett9e707a02015-09-01 14:57:57 -0700856 task->src.options.c_str(), name, md5))) {
djsollen54416de2015-04-03 07:24:48 -0700857 fail(SkStringPrintf("%s not found for %s %s %s %s in %s",
mtklein62bd1a62015-01-27 14:46:26 -0800858 md5.c_str(),
kkinnunen3e980c32015-12-23 01:33:00 -0800859 task->sink.tag.c_str(),
msarett9e707a02015-09-01 14:57:57 -0700860 task->src.tag.c_str(),
861 task->src.options.c_str(),
mtklein62bd1a62015-01-27 14:46:26 -0800862 name.c_str(),
863 FLAGS_readPath[0]));
864 }
865
mtkleinb0531a72015-04-07 13:38:48 -0700866 if (!FLAGS_writePath.isEmpty()) {
mtklein748ca3b2015-01-15 10:56:12 -0800867 const char* ext = task->sink->fileExtension();
mtklein62bd1a62015-01-27 14:46:26 -0800868 if (data->getLength()) {
halcanary96fcdcc2015-08-27 07:41:13 -0700869 WriteToDisk(*task, md5, ext, data, data->getLength(), nullptr);
halcanary022afb82015-01-30 11:00:12 -0800870 SkASSERT(bitmap.drawsNothing());
871 } else if (!bitmap.drawsNothing()) {
halcanary96fcdcc2015-08-27 07:41:13 -0700872 WriteToDisk(*task, md5, ext, nullptr, 0, &bitmap);
mtklein748ca3b2015-01-15 10:56:12 -0800873 }
874 }
875 }
kkinnunen3e980c32015-12-23 01:33:00 -0800876 done(now_ms()-timerStart, task->sink.tag.c_str(), task->src.tag.c_str(), task->src.options.c_str(),
mtkleinf27f08b2015-11-03 06:54:24 -0800877 name, note, log);
mtklein748ca3b2015-01-15 10:56:12 -0800878 }
879
880 static void WriteToDisk(const Task& task,
mtklein62bd1a62015-01-27 14:46:26 -0800881 SkString md5,
882 const char* ext,
mtklein748ca3b2015-01-15 10:56:12 -0800883 SkStream* data, size_t len,
mtklein62bd1a62015-01-27 14:46:26 -0800884 const SkBitmap* bitmap) {
mtklein748ca3b2015-01-15 10:56:12 -0800885 JsonWriter::BitmapResult result;
djsollen54416de2015-04-03 07:24:48 -0700886 result.name = task.src->name();
kkinnunen3e980c32015-12-23 01:33:00 -0800887 result.config = task.sink.tag.c_str();
djsollen54416de2015-04-03 07:24:48 -0700888 result.sourceType = task.src.tag;
889 result.sourceOptions = task.src.options;
890 result.ext = ext;
891 result.md5 = md5;
mtklein748ca3b2015-01-15 10:56:12 -0800892 JsonWriter::AddBitmapResult(result);
893
mtkleinb0531a72015-04-07 13:38:48 -0700894 // If an MD5 is uninteresting, we want it noted in the JSON file,
895 // but don't want to dump it out as a .png (or whatever ext is).
896 if (gUninterestingHashes.contains(md5)) {
897 return;
898 }
899
mtklein748ca3b2015-01-15 10:56:12 -0800900 const char* dir = FLAGS_writePath[0];
901 if (0 == strcmp(dir, "@")) { // Needed for iOS.
902 dir = FLAGS_resourcePath[0];
903 }
904 sk_mkdir(dir);
905
906 SkString path;
907 if (FLAGS_nameByHash) {
908 path = SkOSPath::Join(dir, result.md5.c_str());
909 path.append(".");
910 path.append(ext);
911 if (sk_exists(path.c_str())) {
912 return; // Content-addressed. If it exists already, we're done.
913 }
914 } else {
kkinnunen3e980c32015-12-23 01:33:00 -0800915 path = SkOSPath::Join(dir, task.sink.tag.c_str());
mtklein748ca3b2015-01-15 10:56:12 -0800916 sk_mkdir(path.c_str());
msarett9e707a02015-09-01 14:57:57 -0700917 path = SkOSPath::Join(path.c_str(), task.src.tag.c_str());
mtklein748ca3b2015-01-15 10:56:12 -0800918 sk_mkdir(path.c_str());
msarett9e707a02015-09-01 14:57:57 -0700919 if (strcmp(task.src.options.c_str(), "") != 0) {
920 path = SkOSPath::Join(path.c_str(), task.src.options.c_str());
djsollen54416de2015-04-03 07:24:48 -0700921 sk_mkdir(path.c_str());
922 }
mtklein748ca3b2015-01-15 10:56:12 -0800923 path = SkOSPath::Join(path.c_str(), task.src->name().c_str());
924 path.append(".");
925 path.append(ext);
926 }
927
mtklein748ca3b2015-01-15 10:56:12 -0800928 if (bitmap) {
mtkleina5114d72015-08-24 13:27:01 -0700929 if (!dump_png(*bitmap, path.c_str(), result.md5.c_str())) {
mtklein748ca3b2015-01-15 10:56:12 -0800930 fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str()));
931 return;
932 }
933 } else {
mtkleina5114d72015-08-24 13:27:01 -0700934 SkFILEWStream file(path.c_str());
935 if (!file.isValid()) {
936 fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str()));
937 return;
938 }
mtklein748ca3b2015-01-15 10:56:12 -0800939 if (!file.writeStream(data, len)) {
940 fail(SkStringPrintf("Can't write to %s.\n", path.c_str()));
941 return;
942 }
943 }
944 }
945};
946
947// Run all tasks in the same enclave serially on the same thread.
948// They can't possibly run concurrently with each other.
949static void run_enclave(SkTArray<Task>* tasks) {
950 for (int i = 0; i < tasks->count(); i++) {
951 Task::Run(tasks->begin() + i);
952 }
953}
954
955/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
956
957// Unit tests don't fit so well into the Src/Sink model, so we give them special treatment.
958
mtklein55e88b22015-01-21 15:50:13 -0800959static SkTDArray<skiatest::Test> gThreadedTests, gGPUTests;
mtklein748ca3b2015-01-15 10:56:12 -0800960
961static void gather_tests() {
mtklein6c5fed22015-01-20 13:47:23 -0800962 if (!FLAGS_src.contains("tests")) {
mtklein748ca3b2015-01-15 10:56:12 -0800963 return;
964 }
mtklein6393c062015-04-27 08:45:01 -0700965 for (const skiatest::TestRegistry* r = skiatest::TestRegistry::Head(); r; r = r->next()) {
966 if (!in_shard()) {
967 continue;
968 }
halcanary87f3ba42015-01-20 09:30:20 -0800969 // Despite its name, factory() is returning a reference to
970 // link-time static const POD data.
971 const skiatest::Test& test = r->factory();
972 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, test.name)) {
mtklein748ca3b2015-01-15 10:56:12 -0800973 continue;
974 }
halcanary87f3ba42015-01-20 09:30:20 -0800975 if (test.needsGpu && gpu_supported()) {
mtklein55e88b22015-01-21 15:50:13 -0800976 (FLAGS_gpu_threading ? gThreadedTests : gGPUTests).push(test);
halcanary87f3ba42015-01-20 09:30:20 -0800977 } else if (!test.needsGpu && FLAGS_cpu) {
mtklein55e88b22015-01-21 15:50:13 -0800978 gThreadedTests.push(test);
mtklein82d28432015-01-15 12:46:02 -0800979 }
mtklein748ca3b2015-01-15 10:56:12 -0800980 }
981}
982
halcanary87f3ba42015-01-20 09:30:20 -0800983static void run_test(skiatest::Test* test) {
984 struct : public skiatest::Reporter {
mtklein36352bf2015-03-25 18:17:31 -0700985 void reportFailed(const skiatest::Failure& failure) override {
halcanary87f3ba42015-01-20 09:30:20 -0800986 fail(failure.toString());
987 JsonWriter::AddTestFailure(failure);
988 }
mtklein36352bf2015-03-25 18:17:31 -0700989 bool allowExtendedTest() const override {
halcanary87f3ba42015-01-20 09:30:20 -0800990 return FLAGS_pathOpsExtended;
991 }
mtklein36352bf2015-03-25 18:17:31 -0700992 bool verbose() const override { return FLAGS_veryVerbose; }
halcanary87f3ba42015-01-20 09:30:20 -0800993 } reporter;
djsollen824996a2015-06-12 12:06:22 -0700994
995 SkString note;
996 SkString whyBlacklisted = is_blacklisted("_", "tests", "_", test->name);
997 if (!whyBlacklisted.isEmpty()) {
998 note.appendf(" (--blacklist %s)", whyBlacklisted.c_str());
999 }
1000
mtkleinf27f08b2015-11-03 06:54:24 -08001001 auto timerStart = now_ms();
djsollen824996a2015-06-12 12:06:22 -07001002 if (!FLAGS_dryRun && whyBlacklisted.isEmpty()) {
djsollen54416de2015-04-03 07:24:48 -07001003 start("unit", "test", "", test->name);
mtklein55e88b22015-01-21 15:50:13 -08001004 GrContextFactory factory;
bsalomon821e10e2015-06-04 14:15:33 -07001005 if (FLAGS_pre_log) {
1006 SkDebugf("\nRunning test %s", test->name);
1007 }
mtklein55e88b22015-01-21 15:50:13 -08001008 test->proc(&reporter, &factory);
mtklein748ca3b2015-01-15 10:56:12 -08001009 }
mtkleinf27f08b2015-11-03 06:54:24 -08001010 done(now_ms()-timerStart, "unit", "test", "", test->name, note, "");
mtklein748ca3b2015-01-15 10:56:12 -08001011}
1012
1013/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1014
mtklein55e88b22015-01-21 15:50:13 -08001015// If we're isolating all GPU-bound work to one thread (the default), this function runs all that.
1016static void run_enclave_and_gpu_tests(SkTArray<Task>* tasks) {
1017 run_enclave(tasks);
1018 for (int i = 0; i < gGPUTests.count(); i++) {
1019 run_test(&gGPUTests[i]);
1020 }
1021}
1022
mtkleinde6fc2b2015-03-12 06:28:54 -07001023// Some runs (mostly, Valgrind) are so slow that the bot framework thinks we've hung.
1024// This prints something every once in a while so that it knows we're still working.
mtklein2e1c47e2015-03-12 07:16:56 -07001025static void start_keepalive() {
1026 struct Loop {
1027 static void forever(void*) {
1028 for (;;) {
1029 static const int kSec = 300;
1030 #if defined(SK_BUILD_FOR_WIN)
1031 Sleep(kSec * 1000);
1032 #else
1033 sleep(kSec);
1034 #endif
mtkleinb37cb412015-03-18 05:27:14 -07001035 SkString running;
1036 {
mtkleinbc4e0032015-12-09 08:37:35 -08001037 SkAutoMutexAcquire lock(gRunningAndTallyMutex);
mtkleinb37cb412015-03-18 05:27:14 -07001038 for (int i = 0; i < gRunning.count(); i++) {
1039 running.appendf("\n\t%s", gRunning[i].c_str());
1040 }
1041 }
1042 SkDebugf("\nCurrently running:%s\n", running.c_str());
mtklein2e1c47e2015-03-12 07:16:56 -07001043 }
1044 }
1045 };
1046 static SkThread* intentionallyLeaked = new SkThread(Loop::forever);
1047 intentionallyLeaked->start();
mtkleinde6fc2b2015-03-12 06:28:54 -07001048}
1049
caryclark83ca6282015-06-10 09:31:09 -07001050#define PORTABLE_FONT_PREFIX "Toy Liberation "
1051
1052static SkTypeface* create_from_name(const char familyName[], SkTypeface::Style style) {
1053 if (familyName && strlen(familyName) > sizeof(PORTABLE_FONT_PREFIX)
1054 && !strncmp(familyName, PORTABLE_FONT_PREFIX, sizeof(PORTABLE_FONT_PREFIX) - 1)) {
caryclark1818acb2015-07-24 12:09:25 -07001055 return sk_tool_utils::create_portable_typeface(familyName, style);
caryclark83ca6282015-06-10 09:31:09 -07001056 }
halcanary96fcdcc2015-08-27 07:41:13 -07001057 return nullptr;
caryclark83ca6282015-06-10 09:31:09 -07001058}
1059
1060#undef PORTABLE_FONT_PREFIX
1061
1062extern SkTypeface* (*gCreateTypefaceDelegate)(const char [], SkTypeface::Style );
1063
jcgregorio3b27ade2014-11-13 08:06:40 -08001064int dm_main();
caryclark17f0b6d2014-07-22 10:15:34 -07001065int dm_main() {
jcgregorio3b27ade2014-11-13 08:06:40 -08001066 SetupCrashHandler();
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +00001067 SkAutoGraphics ag;
mtklein406654b2014-09-03 15:34:37 -07001068 SkTaskGroup::Enabler enabled(FLAGS_threads);
caryclark83ca6282015-06-10 09:31:09 -07001069 gCreateTypefaceDelegate = &create_from_name;
commit-bot@chromium.orga65e2fd2014-05-30 17:23:31 +00001070
mtklein2e1c47e2015-03-12 07:16:56 -07001071 start_keepalive();
mtkleinde6fc2b2015-03-12 06:28:54 -07001072
mtklein62bd1a62015-01-27 14:46:26 -08001073 gather_gold();
borenet09ed4802015-04-03 14:15:33 -07001074 gather_uninteresting_hashes();
mtklein62bd1a62015-01-27 14:46:26 -08001075
mtklein748ca3b2015-01-15 10:56:12 -08001076 gather_srcs();
1077 gather_sinks();
1078 gather_tests();
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +00001079
mtklein55e88b22015-01-21 15:50:13 -08001080 gPending = gSrcs.count() * gSinks.count() + gThreadedTests.count() + gGPUTests.count();
mtklein748ca3b2015-01-15 10:56:12 -08001081 SkDebugf("%d srcs * %d sinks + %d tests == %d tasks\n",
mtklein55e88b22015-01-21 15:50:13 -08001082 gSrcs.count(), gSinks.count(), gThreadedTests.count() + gGPUTests.count(), gPending);
mtklein748ca3b2015-01-15 10:56:12 -08001083
1084 // We try to exploit as much parallelism as is safe. Most Src/Sink pairs run on any thread,
1085 // but Sinks that identify as part of a particular enclave run serially on a single thread.
mtklein82d28432015-01-15 12:46:02 -08001086 // CPU tests run on any thread. GPU tests depend on --gpu_threading.
mtklein748ca3b2015-01-15 10:56:12 -08001087 SkTArray<Task> enclaves[kNumEnclaves];
1088 for (int j = 0; j < gSinks.count(); j++) {
1089 SkTArray<Task>& tasks = enclaves[gSinks[j]->enclave()];
1090 for (int i = 0; i < gSrcs.count(); i++) {
1091 tasks.push_back(Task(gSrcs[i], gSinks[j]));
1092 }
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001093 }
1094
mtklein748ca3b2015-01-15 10:56:12 -08001095 SkTaskGroup tg;
herb30da5f72015-12-10 14:12:33 -08001096 tg.batch([](int i){ run_test(&gThreadedTests[i]); }, gThreadedTests.count());
mtklein55e88b22015-01-21 15:50:13 -08001097 for (int i = 0; i < kNumEnclaves; i++) {
herb30da5f72015-12-10 14:12:33 -08001098 SkTArray<Task>* currentEnclave = &enclaves[i];
mtklein55e88b22015-01-21 15:50:13 -08001099 switch(i) {
1100 case kAnyThread_Enclave:
herb30da5f72015-12-10 14:12:33 -08001101 tg.batch([currentEnclave](int j) { Task::Run(&(*currentEnclave)[j]); }, currentEnclave->count());
mtklein55e88b22015-01-21 15:50:13 -08001102 break;
1103 case kGPU_Enclave:
herb30da5f72015-12-10 14:12:33 -08001104 tg.add([currentEnclave](){ run_enclave_and_gpu_tests(currentEnclave); });
mtklein55e88b22015-01-21 15:50:13 -08001105 break;
1106 default:
herb30da5f72015-12-10 14:12:33 -08001107 tg.add([currentEnclave](){ run_enclave(currentEnclave); });
mtklein55e88b22015-01-21 15:50:13 -08001108 break;
mtklein82d28432015-01-15 12:46:02 -08001109 }
mtklein55e88b22015-01-21 15:50:13 -08001110 }
mtklein748ca3b2015-01-15 10:56:12 -08001111 tg.wait();
mtklein748ca3b2015-01-15 10:56:12 -08001112 // At this point we're back in single-threaded land.
caryclarkf53ce802015-06-15 06:48:30 -07001113 sk_tool_utils::release_portable_typefaces();
mtklein@google.comd36522d2013-10-16 13:02:15 +00001114
mtkleinbc4e0032015-12-09 08:37:35 -08001115 if (FLAGS_verbose && gNoteTally.count() > 0) {
1116 SkDebugf("\nNote tally:\n");
1117 gNoteTally.foreach([](const SkString& note, int* tally) {
1118 SkDebugf("%dx\t%s\n", *tally, note.c_str());
1119 });
1120 }
1121
mtklein2f64eec2015-01-15 14:20:41 -08001122 SkDebugf("\n");
mtklein748ca3b2015-01-15 10:56:12 -08001123 if (gFailures.count() > 0) {
1124 SkDebugf("Failures:\n");
1125 for (int i = 0; i < gFailures.count(); i++) {
mtklein9dc09102015-01-15 15:47:33 -08001126 SkDebugf("\t%s\n", gFailures[i].c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001127 }
1128 SkDebugf("%d failures\n", gFailures.count());
1129 return 1;
mtklein114c3cd2015-01-15 10:15:02 -08001130 }
mtklein748ca3b2015-01-15 10:56:12 -08001131 if (gPending > 0) {
1132 SkDebugf("Hrm, we didn't seem to run everything we intended to! Please file a bug.\n");
1133 return 1;
mtklein114c3cd2015-01-15 10:15:02 -08001134 }
halcanary7a14b312015-10-01 07:28:13 -07001135 #ifdef SK_PDF_IMAGE_STATS
1136 SkPDFImageDumpStats();
1137 #endif // SK_PDF_IMAGE_STATS
mtklein748ca3b2015-01-15 10:56:12 -08001138 return 0;
mtklein@google.comd36522d2013-10-16 13:02:15 +00001139}
jcgregorio3b27ade2014-11-13 08:06:40 -08001140
kkinnunen179a8f52015-11-20 13:32:24 -08001141// TODO: currently many GPU tests are declared outside SK_SUPPORT_GPU guards.
1142// Thus we export the empty RunWithGPUTestContexts when SK_SUPPORT_GPU=0.
1143namespace skiatest {
1144namespace {
1145typedef void(*TestWithGrContext)(skiatest::Reporter*, GrContext*);
1146typedef void(*TestWithGrContextAndGLContext)(skiatest::Reporter*, GrContext*, SkGLContext*);
1147#if SK_SUPPORT_GPU
1148template<typename T>
1149void call_test(T test, skiatest::Reporter* reporter, GrContextFactory::ContextInfo* context);
1150template<>
1151void call_test(TestWithGrContext test, skiatest::Reporter* reporter,
1152 GrContextFactory::ContextInfo* context) {
1153 test(reporter, context->fGrContext);
1154}
1155template<>
1156void call_test(TestWithGrContextAndGLContext test, skiatest::Reporter* reporter,
1157 GrContextFactory::ContextInfo* context) {
1158 test(reporter, context->fGrContext, context->fGLContext);
1159}
1160#endif
1161} // namespace
1162
kkinnunen179a8f52015-11-20 13:32:24 -08001163template<typename T>
1164void RunWithGPUTestContexts(T test, GPUTestContexts testContexts, Reporter* reporter,
1165 GrContextFactory* factory) {
1166#if SK_SUPPORT_GPU
kkinnunen3e980c32015-12-23 01:33:00 -08001167 // Iterate over context types, except use "native" instead of explicitly trying OpenGL and
1168 // OpenGL ES. Do not use GLES on desktop, since tests do not account for not fixing
1169 // http://skbug.com/2809
1170 GrContextFactory::GLContextType contextTypes[] = {
1171 GrContextFactory::kNative_GLContextType,
1172#if SK_ANGLE
1173#ifdef SK_BUILD_FOR_WIN
1174 GrContextFactory::kANGLE_GLContextType,
1175#endif
1176 GrContextFactory::kANGLE_GL_GLContextType,
1177#endif
1178#if SK_COMMAND_BUFFER
1179 GrContextFactory::kCommandBuffer_GLContextType,
1180#endif
1181#if SK_MESA
1182 GrContextFactory::kMESA_GLContextType,
1183#endif
1184 GrContextFactory::kNull_GLContextType,
1185 GrContextFactory::kDebug_GLContextType,
1186 };
1187 static_assert(SK_ARRAY_COUNT(contextTypes) == GrContextFactory::kGLContextTypeCnt - 2,
1188 "Skipping unexpected GLContextType for GPU tests");
1189
1190 for (auto& contextType : contextTypes) {
kkinnunen179a8f52015-11-20 13:32:24 -08001191 int contextSelector = kNone_GPUTestContexts;
kkinnunen3e980c32015-12-23 01:33:00 -08001192 if (GrContextFactory::IsRenderingGLContext(contextType)) {
kkinnunen179a8f52015-11-20 13:32:24 -08001193 contextSelector |= kAllRendering_GPUTestContexts;
kkinnunen3e980c32015-12-23 01:33:00 -08001194 } else if (contextType == GrContextFactory::kNative_GLContextType) {
kkinnunen179a8f52015-11-20 13:32:24 -08001195 contextSelector |= kNative_GPUTestContexts;
kkinnunen3e980c32015-12-23 01:33:00 -08001196 } else if (contextType == GrContextFactory::kNull_GLContextType) {
kkinnunen179a8f52015-11-20 13:32:24 -08001197 contextSelector |= kNull_GPUTestContexts;
kkinnunen3e980c32015-12-23 01:33:00 -08001198 } else if (contextType == GrContextFactory::kDebug_GLContextType) {
kkinnunen55eeae92015-12-10 23:19:29 -08001199 contextSelector |= kDebug_GPUTestContexts;
kkinnunen179a8f52015-11-20 13:32:24 -08001200 }
1201 if ((testContexts & contextSelector) == 0) {
1202 continue;
1203 }
kkinnunen3e980c32015-12-23 01:33:00 -08001204 if (GrContextFactory::ContextInfo* context = factory->getContextInfo(contextType)) {
kkinnunen5219fd92015-12-10 06:28:13 -08001205 call_test(test, reporter, context);
1206 }
1207 if (GrContextFactory::ContextInfo* context =
kkinnunen3e980c32015-12-23 01:33:00 -08001208 factory->getContextInfo(contextType, GrContextFactory::kEnableNVPR_GLContextOptions)) {
kkinnunen179a8f52015-11-20 13:32:24 -08001209 call_test(test, reporter, context);
1210 }
1211 }
1212#endif
1213}
1214
1215template
1216void RunWithGPUTestContexts<TestWithGrContext>(TestWithGrContext test,
1217 GPUTestContexts testContexts,
1218 Reporter* reporter,
1219 GrContextFactory* factory);
1220template
1221void RunWithGPUTestContexts<TestWithGrContextAndGLContext>(TestWithGrContextAndGLContext test,
1222 GPUTestContexts testContexts,
1223 Reporter* reporter,
1224 GrContextFactory* factory);
1225} // namespace skiatest
1226
borenet48087572015-04-02 12:16:36 -07001227#if !defined(SK_BUILD_FOR_IOS)
jcgregorio3b27ade2014-11-13 08:06:40 -08001228int main(int argc, char** argv) {
1229 SkCommandLineFlags::Parse(argc, argv);
1230 return dm_main();
1231}
1232#endif