blob: 0e36c073673a2607d8ecd62682aa059817f75adf [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);
halcanary96fcdcc2015-08-27 07:41:13 -0700626 VIA("serialize", ViaSerialization, wrapped);
mtklein4a34ecb2016-01-08 10:19:35 -0800627 VIA("pic", ViaPicture, wrapped);
halcanary96fcdcc2015-08-27 07:41:13 -0700628 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
mtkleincd50bca2016-01-05 06:20:20 -0800779// Even when a Task Sink reports to be non-threadsafe (e.g. GPU), we know things like
780// .png encoding are definitely thread safe. This lets us offload that work to CPU threads.
781static SkTaskGroup gDefinitelyThreadSafeWork;
782
mtklein748ca3b2015-01-15 10:56:12 -0800783// The finest-grained unit of work we can run: draw a single Src into a single Sink,
784// report any errors, and perhaps write out the output: a .png of the bitmap, or a raw stream.
785struct Task {
mtkleine0effd62015-07-29 06:37:28 -0700786 Task(const TaggedSrc& src, const TaggedSink& sink) : src(src), sink(sink) {}
787 const TaggedSrc& src;
788 const TaggedSink& sink;
mtklein748ca3b2015-01-15 10:56:12 -0800789
790 static void Run(Task* task) {
mtkleina2ef6422015-01-15 13:44:22 -0800791 SkString name = task->src->name();
mtkleine0effd62015-07-29 06:37:28 -0700792
793 // We'll skip drawing this Src/Sink pair if:
794 // - the Src vetoes the Sink;
795 // - this Src / Sink combination is on the blacklist;
796 // - it's a dry run.
mtklein99cab4e2015-07-31 06:43:04 -0700797 SkString note(task->src->veto(task->sink->flags()) ? " (veto)" : "");
kkinnunen3e980c32015-12-23 01:33:00 -0800798 SkString whyBlacklisted = is_blacklisted(task->sink.tag.c_str(), task->src.tag.c_str(),
msarett9e707a02015-09-01 14:57:57 -0700799 task->src.options.c_str(), name.c_str());
mtkleinb37cb412015-03-18 05:27:14 -0700800 if (!whyBlacklisted.isEmpty()) {
801 note.appendf(" (--blacklist %s)", whyBlacklisted.c_str());
802 }
mtkleine0effd62015-07-29 06:37:28 -0700803
mtkleinb9eb4ac2015-02-02 18:26:03 -0800804 SkString log;
mtkleinf27f08b2015-11-03 06:54:24 -0800805 auto timerStart = now_ms();
mtkleine0effd62015-07-29 06:37:28 -0700806 if (!FLAGS_dryRun && note.isEmpty()) {
mtklein748ca3b2015-01-15 10:56:12 -0800807 SkBitmap bitmap;
808 SkDynamicMemoryWStream stream;
bsalomon821e10e2015-06-04 14:15:33 -0700809 if (FLAGS_pre_log) {
kkinnunen3e980c32015-12-23 01:33:00 -0800810 SkDebugf("\nRunning %s->%s", name.c_str(), task->sink.tag.c_str());
bsalomon821e10e2015-06-04 14:15:33 -0700811 }
kkinnunen3e980c32015-12-23 01:33:00 -0800812 start(task->sink.tag.c_str(), task->src.tag, task->src.options, name.c_str());
mtkleinb9eb4ac2015-02-02 18:26:03 -0800813 Error err = task->sink->draw(*task->src, &bitmap, &stream, &log);
mtklein748ca3b2015-01-15 10:56:12 -0800814 if (!err.isEmpty()) {
mtkleinf27f08b2015-11-03 06:54:24 -0800815 auto elapsed = now_ms() - timerStart;
mtklein4089ef72015-03-05 08:40:28 -0800816 if (err.isFatal()) {
djsollen54416de2015-04-03 07:24:48 -0700817 fail(SkStringPrintf("%s %s %s %s: %s",
kkinnunen3e980c32015-12-23 01:33:00 -0800818 task->sink.tag.c_str(),
msarett9e707a02015-09-01 14:57:57 -0700819 task->src.tag.c_str(),
820 task->src.options.c_str(),
mtklein4089ef72015-03-05 08:40:28 -0800821 name.c_str(),
822 err.c_str()));
mtkleinb37cb412015-03-18 05:27:14 -0700823 } else {
824 note.appendf(" (skipped: %s)", err.c_str());
mtklein4089ef72015-03-05 08:40:28 -0800825 }
kkinnunen3e980c32015-12-23 01:33:00 -0800826 done(elapsed, task->sink.tag.c_str(), task->src.tag, task->src.options,
djsollen54416de2015-04-03 07:24:48 -0700827 name, note, log);
mtklein4089ef72015-03-05 08:40:28 -0800828 return;
mtklein748ca3b2015-01-15 10:56:12 -0800829 }
mtklein62bd1a62015-01-27 14:46:26 -0800830
mtkleincd50bca2016-01-05 06:20:20 -0800831 // We're likely switching threads here, so we must capture by value, [=] or [foo,bar].
832 SkStreamAsset* data = stream.detachAsStream();
833 gDefinitelyThreadSafeWork.add([task,name,bitmap,data]{
834 SkAutoTDelete<SkStreamAsset> ownedData(data);
835
836 // Why doesn't the copy constructor do this when we have pre-locked pixels?
837 bitmap.lockPixels();
838
839 SkString md5;
840 if (!FLAGS_writePath.isEmpty() || !FLAGS_readPath.isEmpty()) {
841 SkMD5 hash;
842 if (data->getLength()) {
843 hash.writeStream(data, data->getLength());
844 data->rewind();
mtklein38408462015-07-08 07:25:27 -0700845 } else {
mtkleincd50bca2016-01-05 06:20:20 -0800846 // If we're BGRA (Linux, Windows), swizzle over to RGBA (Mac, Android).
847 // This helps eliminate multiple 0-pixel-diff hashes on gold.skia.org.
848 // (Android's general slow speed breaks the tie arbitrarily in RGBA's favor.)
849 // We might consider promoting 565 to RGBA too.
850 if (bitmap.colorType() == kBGRA_8888_SkColorType) {
851 SkBitmap swizzle;
852 SkAssertResult(bitmap.copyTo(&swizzle, kRGBA_8888_SkColorType));
853 hash.write(swizzle.getPixels(), swizzle.getSize());
854 } else {
855 hash.write(bitmap.getPixels(), bitmap.getSize());
856 }
857 }
858 SkMD5::Digest digest;
859 hash.finish(digest);
860 for (int i = 0; i < 16; i++) {
861 md5.appendf("%02x", digest.data[i]);
mtklein38408462015-07-08 07:25:27 -0700862 }
mtklein62bd1a62015-01-27 14:46:26 -0800863 }
mtklein62bd1a62015-01-27 14:46:26 -0800864
mtkleincd50bca2016-01-05 06:20:20 -0800865 if (!FLAGS_readPath.isEmpty() &&
866 !gGold.contains(Gold(task->sink.tag.c_str(), task->src.tag.c_str(),
867 task->src.options.c_str(), name, md5))) {
868 fail(SkStringPrintf("%s not found for %s %s %s %s in %s",
869 md5.c_str(),
870 task->sink.tag.c_str(),
871 task->src.tag.c_str(),
872 task->src.options.c_str(),
873 name.c_str(),
874 FLAGS_readPath[0]));
mtklein748ca3b2015-01-15 10:56:12 -0800875 }
mtkleincd50bca2016-01-05 06:20:20 -0800876
877 if (!FLAGS_writePath.isEmpty()) {
878 const char* ext = task->sink->fileExtension();
879 if (data->getLength()) {
880 WriteToDisk(*task, md5, ext, data, data->getLength(), nullptr);
881 SkASSERT(bitmap.drawsNothing());
882 } else if (!bitmap.drawsNothing()) {
883 WriteToDisk(*task, md5, ext, nullptr, 0, &bitmap);
884 }
885 }
886 });
mtklein748ca3b2015-01-15 10:56:12 -0800887 }
kkinnunen3e980c32015-12-23 01:33:00 -0800888 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 -0800889 name, note, log);
mtklein748ca3b2015-01-15 10:56:12 -0800890 }
891
892 static void WriteToDisk(const Task& task,
mtklein62bd1a62015-01-27 14:46:26 -0800893 SkString md5,
894 const char* ext,
mtklein748ca3b2015-01-15 10:56:12 -0800895 SkStream* data, size_t len,
mtklein62bd1a62015-01-27 14:46:26 -0800896 const SkBitmap* bitmap) {
mtklein748ca3b2015-01-15 10:56:12 -0800897 JsonWriter::BitmapResult result;
djsollen54416de2015-04-03 07:24:48 -0700898 result.name = task.src->name();
kkinnunen3e980c32015-12-23 01:33:00 -0800899 result.config = task.sink.tag.c_str();
djsollen54416de2015-04-03 07:24:48 -0700900 result.sourceType = task.src.tag;
901 result.sourceOptions = task.src.options;
902 result.ext = ext;
903 result.md5 = md5;
mtklein748ca3b2015-01-15 10:56:12 -0800904 JsonWriter::AddBitmapResult(result);
905
mtkleinb0531a72015-04-07 13:38:48 -0700906 // If an MD5 is uninteresting, we want it noted in the JSON file,
907 // but don't want to dump it out as a .png (or whatever ext is).
908 if (gUninterestingHashes.contains(md5)) {
909 return;
910 }
911
mtklein748ca3b2015-01-15 10:56:12 -0800912 const char* dir = FLAGS_writePath[0];
913 if (0 == strcmp(dir, "@")) { // Needed for iOS.
914 dir = FLAGS_resourcePath[0];
915 }
916 sk_mkdir(dir);
917
918 SkString path;
919 if (FLAGS_nameByHash) {
920 path = SkOSPath::Join(dir, result.md5.c_str());
921 path.append(".");
922 path.append(ext);
923 if (sk_exists(path.c_str())) {
924 return; // Content-addressed. If it exists already, we're done.
925 }
926 } else {
kkinnunen3e980c32015-12-23 01:33:00 -0800927 path = SkOSPath::Join(dir, task.sink.tag.c_str());
mtklein748ca3b2015-01-15 10:56:12 -0800928 sk_mkdir(path.c_str());
msarett9e707a02015-09-01 14:57:57 -0700929 path = SkOSPath::Join(path.c_str(), task.src.tag.c_str());
mtklein748ca3b2015-01-15 10:56:12 -0800930 sk_mkdir(path.c_str());
msarett9e707a02015-09-01 14:57:57 -0700931 if (strcmp(task.src.options.c_str(), "") != 0) {
932 path = SkOSPath::Join(path.c_str(), task.src.options.c_str());
djsollen54416de2015-04-03 07:24:48 -0700933 sk_mkdir(path.c_str());
934 }
mtklein748ca3b2015-01-15 10:56:12 -0800935 path = SkOSPath::Join(path.c_str(), task.src->name().c_str());
936 path.append(".");
937 path.append(ext);
938 }
939
mtklein748ca3b2015-01-15 10:56:12 -0800940 if (bitmap) {
mtkleina5114d72015-08-24 13:27:01 -0700941 if (!dump_png(*bitmap, path.c_str(), result.md5.c_str())) {
mtklein748ca3b2015-01-15 10:56:12 -0800942 fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str()));
943 return;
944 }
945 } else {
mtkleina5114d72015-08-24 13:27:01 -0700946 SkFILEWStream file(path.c_str());
947 if (!file.isValid()) {
948 fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str()));
949 return;
950 }
mtklein748ca3b2015-01-15 10:56:12 -0800951 if (!file.writeStream(data, len)) {
952 fail(SkStringPrintf("Can't write to %s.\n", path.c_str()));
953 return;
954 }
955 }
956 }
957};
958
959// Run all tasks in the same enclave serially on the same thread.
960// They can't possibly run concurrently with each other.
961static void run_enclave(SkTArray<Task>* tasks) {
962 for (int i = 0; i < tasks->count(); i++) {
963 Task::Run(tasks->begin() + i);
964 }
965}
966
967/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
968
969// Unit tests don't fit so well into the Src/Sink model, so we give them special treatment.
970
mtklein55e88b22015-01-21 15:50:13 -0800971static SkTDArray<skiatest::Test> gThreadedTests, gGPUTests;
mtklein748ca3b2015-01-15 10:56:12 -0800972
973static void gather_tests() {
mtklein6c5fed22015-01-20 13:47:23 -0800974 if (!FLAGS_src.contains("tests")) {
mtklein748ca3b2015-01-15 10:56:12 -0800975 return;
976 }
mtklein6393c062015-04-27 08:45:01 -0700977 for (const skiatest::TestRegistry* r = skiatest::TestRegistry::Head(); r; r = r->next()) {
978 if (!in_shard()) {
979 continue;
980 }
halcanary87f3ba42015-01-20 09:30:20 -0800981 // Despite its name, factory() is returning a reference to
982 // link-time static const POD data.
983 const skiatest::Test& test = r->factory();
984 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, test.name)) {
mtklein748ca3b2015-01-15 10:56:12 -0800985 continue;
986 }
halcanary87f3ba42015-01-20 09:30:20 -0800987 if (test.needsGpu && gpu_supported()) {
mtklein55e88b22015-01-21 15:50:13 -0800988 (FLAGS_gpu_threading ? gThreadedTests : gGPUTests).push(test);
halcanary87f3ba42015-01-20 09:30:20 -0800989 } else if (!test.needsGpu && FLAGS_cpu) {
mtklein55e88b22015-01-21 15:50:13 -0800990 gThreadedTests.push(test);
mtklein82d28432015-01-15 12:46:02 -0800991 }
mtklein748ca3b2015-01-15 10:56:12 -0800992 }
993}
994
halcanary87f3ba42015-01-20 09:30:20 -0800995static void run_test(skiatest::Test* test) {
996 struct : public skiatest::Reporter {
mtklein36352bf2015-03-25 18:17:31 -0700997 void reportFailed(const skiatest::Failure& failure) override {
halcanary87f3ba42015-01-20 09:30:20 -0800998 fail(failure.toString());
999 JsonWriter::AddTestFailure(failure);
1000 }
mtklein36352bf2015-03-25 18:17:31 -07001001 bool allowExtendedTest() const override {
halcanary87f3ba42015-01-20 09:30:20 -08001002 return FLAGS_pathOpsExtended;
1003 }
mtklein36352bf2015-03-25 18:17:31 -07001004 bool verbose() const override { return FLAGS_veryVerbose; }
halcanary87f3ba42015-01-20 09:30:20 -08001005 } reporter;
djsollen824996a2015-06-12 12:06:22 -07001006
1007 SkString note;
1008 SkString whyBlacklisted = is_blacklisted("_", "tests", "_", test->name);
1009 if (!whyBlacklisted.isEmpty()) {
1010 note.appendf(" (--blacklist %s)", whyBlacklisted.c_str());
1011 }
1012
mtkleinf27f08b2015-11-03 06:54:24 -08001013 auto timerStart = now_ms();
djsollen824996a2015-06-12 12:06:22 -07001014 if (!FLAGS_dryRun && whyBlacklisted.isEmpty()) {
djsollen54416de2015-04-03 07:24:48 -07001015 start("unit", "test", "", test->name);
mtklein55e88b22015-01-21 15:50:13 -08001016 GrContextFactory factory;
bsalomon821e10e2015-06-04 14:15:33 -07001017 if (FLAGS_pre_log) {
1018 SkDebugf("\nRunning test %s", test->name);
1019 }
mtklein55e88b22015-01-21 15:50:13 -08001020 test->proc(&reporter, &factory);
mtklein748ca3b2015-01-15 10:56:12 -08001021 }
mtkleinf27f08b2015-11-03 06:54:24 -08001022 done(now_ms()-timerStart, "unit", "test", "", test->name, note, "");
mtklein748ca3b2015-01-15 10:56:12 -08001023}
1024
1025/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1026
mtklein55e88b22015-01-21 15:50:13 -08001027// If we're isolating all GPU-bound work to one thread (the default), this function runs all that.
1028static void run_enclave_and_gpu_tests(SkTArray<Task>* tasks) {
1029 run_enclave(tasks);
1030 for (int i = 0; i < gGPUTests.count(); i++) {
1031 run_test(&gGPUTests[i]);
1032 }
1033}
1034
mtkleinde6fc2b2015-03-12 06:28:54 -07001035// Some runs (mostly, Valgrind) are so slow that the bot framework thinks we've hung.
1036// This prints something every once in a while so that it knows we're still working.
mtklein2e1c47e2015-03-12 07:16:56 -07001037static void start_keepalive() {
1038 struct Loop {
1039 static void forever(void*) {
1040 for (;;) {
1041 static const int kSec = 300;
1042 #if defined(SK_BUILD_FOR_WIN)
1043 Sleep(kSec * 1000);
1044 #else
1045 sleep(kSec);
1046 #endif
mtkleinb37cb412015-03-18 05:27:14 -07001047 SkString running;
1048 {
mtkleinbc4e0032015-12-09 08:37:35 -08001049 SkAutoMutexAcquire lock(gRunningAndTallyMutex);
mtkleinb37cb412015-03-18 05:27:14 -07001050 for (int i = 0; i < gRunning.count(); i++) {
1051 running.appendf("\n\t%s", gRunning[i].c_str());
1052 }
1053 }
1054 SkDebugf("\nCurrently running:%s\n", running.c_str());
mtklein2e1c47e2015-03-12 07:16:56 -07001055 }
1056 }
1057 };
1058 static SkThread* intentionallyLeaked = new SkThread(Loop::forever);
1059 intentionallyLeaked->start();
mtkleinde6fc2b2015-03-12 06:28:54 -07001060}
1061
caryclark83ca6282015-06-10 09:31:09 -07001062#define PORTABLE_FONT_PREFIX "Toy Liberation "
1063
1064static SkTypeface* create_from_name(const char familyName[], SkTypeface::Style style) {
1065 if (familyName && strlen(familyName) > sizeof(PORTABLE_FONT_PREFIX)
1066 && !strncmp(familyName, PORTABLE_FONT_PREFIX, sizeof(PORTABLE_FONT_PREFIX) - 1)) {
caryclark1818acb2015-07-24 12:09:25 -07001067 return sk_tool_utils::create_portable_typeface(familyName, style);
caryclark83ca6282015-06-10 09:31:09 -07001068 }
halcanary96fcdcc2015-08-27 07:41:13 -07001069 return nullptr;
caryclark83ca6282015-06-10 09:31:09 -07001070}
1071
1072#undef PORTABLE_FONT_PREFIX
1073
1074extern SkTypeface* (*gCreateTypefaceDelegate)(const char [], SkTypeface::Style );
1075
jcgregorio3b27ade2014-11-13 08:06:40 -08001076int dm_main();
caryclark17f0b6d2014-07-22 10:15:34 -07001077int dm_main() {
jcgregorio3b27ade2014-11-13 08:06:40 -08001078 SetupCrashHandler();
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +00001079 SkAutoGraphics ag;
mtklein406654b2014-09-03 15:34:37 -07001080 SkTaskGroup::Enabler enabled(FLAGS_threads);
caryclark83ca6282015-06-10 09:31:09 -07001081 gCreateTypefaceDelegate = &create_from_name;
commit-bot@chromium.orga65e2fd2014-05-30 17:23:31 +00001082
mtklein2e1c47e2015-03-12 07:16:56 -07001083 start_keepalive();
mtkleinde6fc2b2015-03-12 06:28:54 -07001084
mtklein62bd1a62015-01-27 14:46:26 -08001085 gather_gold();
borenet09ed4802015-04-03 14:15:33 -07001086 gather_uninteresting_hashes();
mtklein62bd1a62015-01-27 14:46:26 -08001087
mtklein748ca3b2015-01-15 10:56:12 -08001088 gather_srcs();
1089 gather_sinks();
1090 gather_tests();
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +00001091
mtklein55e88b22015-01-21 15:50:13 -08001092 gPending = gSrcs.count() * gSinks.count() + gThreadedTests.count() + gGPUTests.count();
mtklein748ca3b2015-01-15 10:56:12 -08001093 SkDebugf("%d srcs * %d sinks + %d tests == %d tasks\n",
mtklein55e88b22015-01-21 15:50:13 -08001094 gSrcs.count(), gSinks.count(), gThreadedTests.count() + gGPUTests.count(), gPending);
mtklein748ca3b2015-01-15 10:56:12 -08001095
1096 // We try to exploit as much parallelism as is safe. Most Src/Sink pairs run on any thread,
1097 // but Sinks that identify as part of a particular enclave run serially on a single thread.
mtklein82d28432015-01-15 12:46:02 -08001098 // CPU tests run on any thread. GPU tests depend on --gpu_threading.
mtklein748ca3b2015-01-15 10:56:12 -08001099 SkTArray<Task> enclaves[kNumEnclaves];
1100 for (int j = 0; j < gSinks.count(); j++) {
1101 SkTArray<Task>& tasks = enclaves[gSinks[j]->enclave()];
1102 for (int i = 0; i < gSrcs.count(); i++) {
1103 tasks.push_back(Task(gSrcs[i], gSinks[j]));
1104 }
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001105 }
1106
mtklein748ca3b2015-01-15 10:56:12 -08001107 SkTaskGroup tg;
mtklein279c7862016-01-04 19:13:19 -08001108 tg.batch(gThreadedTests.count(), [](int i){ run_test(&gThreadedTests[i]); });
mtklein55e88b22015-01-21 15:50:13 -08001109 for (int i = 0; i < kNumEnclaves; i++) {
herb30da5f72015-12-10 14:12:33 -08001110 SkTArray<Task>* currentEnclave = &enclaves[i];
mtklein55e88b22015-01-21 15:50:13 -08001111 switch(i) {
1112 case kAnyThread_Enclave:
mtklein279c7862016-01-04 19:13:19 -08001113 tg.batch(currentEnclave->count(),
1114 [currentEnclave](int j) { Task::Run(&(*currentEnclave)[j]); });
mtklein55e88b22015-01-21 15:50:13 -08001115 break;
1116 case kGPU_Enclave:
herb30da5f72015-12-10 14:12:33 -08001117 tg.add([currentEnclave](){ run_enclave_and_gpu_tests(currentEnclave); });
mtklein55e88b22015-01-21 15:50:13 -08001118 break;
1119 default:
herb30da5f72015-12-10 14:12:33 -08001120 tg.add([currentEnclave](){ run_enclave(currentEnclave); });
mtklein55e88b22015-01-21 15:50:13 -08001121 break;
mtklein82d28432015-01-15 12:46:02 -08001122 }
mtklein55e88b22015-01-21 15:50:13 -08001123 }
mtklein748ca3b2015-01-15 10:56:12 -08001124 tg.wait();
mtkleincd50bca2016-01-05 06:20:20 -08001125 gDefinitelyThreadSafeWork.wait();
1126
mtklein748ca3b2015-01-15 10:56:12 -08001127 // At this point we're back in single-threaded land.
caryclarkf53ce802015-06-15 06:48:30 -07001128 sk_tool_utils::release_portable_typefaces();
mtklein@google.comd36522d2013-10-16 13:02:15 +00001129
mtkleinbc4e0032015-12-09 08:37:35 -08001130 if (FLAGS_verbose && gNoteTally.count() > 0) {
1131 SkDebugf("\nNote tally:\n");
1132 gNoteTally.foreach([](const SkString& note, int* tally) {
1133 SkDebugf("%dx\t%s\n", *tally, note.c_str());
1134 });
1135 }
1136
mtklein2f64eec2015-01-15 14:20:41 -08001137 SkDebugf("\n");
mtklein748ca3b2015-01-15 10:56:12 -08001138 if (gFailures.count() > 0) {
1139 SkDebugf("Failures:\n");
1140 for (int i = 0; i < gFailures.count(); i++) {
mtklein9dc09102015-01-15 15:47:33 -08001141 SkDebugf("\t%s\n", gFailures[i].c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001142 }
1143 SkDebugf("%d failures\n", gFailures.count());
1144 return 1;
mtklein114c3cd2015-01-15 10:15:02 -08001145 }
mtklein748ca3b2015-01-15 10:56:12 -08001146 if (gPending > 0) {
1147 SkDebugf("Hrm, we didn't seem to run everything we intended to! Please file a bug.\n");
1148 return 1;
mtklein114c3cd2015-01-15 10:15:02 -08001149 }
halcanary7a14b312015-10-01 07:28:13 -07001150 #ifdef SK_PDF_IMAGE_STATS
1151 SkPDFImageDumpStats();
1152 #endif // SK_PDF_IMAGE_STATS
mtklein748ca3b2015-01-15 10:56:12 -08001153 return 0;
mtklein@google.comd36522d2013-10-16 13:02:15 +00001154}
jcgregorio3b27ade2014-11-13 08:06:40 -08001155
kkinnunen179a8f52015-11-20 13:32:24 -08001156// TODO: currently many GPU tests are declared outside SK_SUPPORT_GPU guards.
1157// Thus we export the empty RunWithGPUTestContexts when SK_SUPPORT_GPU=0.
1158namespace skiatest {
1159namespace {
1160typedef void(*TestWithGrContext)(skiatest::Reporter*, GrContext*);
1161typedef void(*TestWithGrContextAndGLContext)(skiatest::Reporter*, GrContext*, SkGLContext*);
1162#if SK_SUPPORT_GPU
1163template<typename T>
kkinnunen34058002016-01-06 23:49:30 -08001164void call_test(T test, skiatest::Reporter* reporter, const GrContextFactory::ContextInfo& context);
kkinnunen179a8f52015-11-20 13:32:24 -08001165template<>
1166void call_test(TestWithGrContext test, skiatest::Reporter* reporter,
kkinnunen34058002016-01-06 23:49:30 -08001167 const GrContextFactory::ContextInfo& context) {
1168 test(reporter, context.fGrContext);
kkinnunen179a8f52015-11-20 13:32:24 -08001169}
1170template<>
1171void call_test(TestWithGrContextAndGLContext test, skiatest::Reporter* reporter,
kkinnunen34058002016-01-06 23:49:30 -08001172 const GrContextFactory::ContextInfo& context) {
1173 test(reporter, context.fGrContext, context.fGLContext);
kkinnunen179a8f52015-11-20 13:32:24 -08001174}
1175#endif
1176} // namespace
1177
kkinnunen179a8f52015-11-20 13:32:24 -08001178template<typename T>
1179void RunWithGPUTestContexts(T test, GPUTestContexts testContexts, Reporter* reporter,
1180 GrContextFactory* factory) {
1181#if SK_SUPPORT_GPU
kkinnunen3e980c32015-12-23 01:33:00 -08001182 // Iterate over context types, except use "native" instead of explicitly trying OpenGL and
1183 // OpenGL ES. Do not use GLES on desktop, since tests do not account for not fixing
1184 // http://skbug.com/2809
1185 GrContextFactory::GLContextType contextTypes[] = {
1186 GrContextFactory::kNative_GLContextType,
1187#if SK_ANGLE
1188#ifdef SK_BUILD_FOR_WIN
1189 GrContextFactory::kANGLE_GLContextType,
1190#endif
1191 GrContextFactory::kANGLE_GL_GLContextType,
1192#endif
1193#if SK_COMMAND_BUFFER
1194 GrContextFactory::kCommandBuffer_GLContextType,
1195#endif
1196#if SK_MESA
1197 GrContextFactory::kMESA_GLContextType,
1198#endif
1199 GrContextFactory::kNull_GLContextType,
1200 GrContextFactory::kDebug_GLContextType,
1201 };
1202 static_assert(SK_ARRAY_COUNT(contextTypes) == GrContextFactory::kGLContextTypeCnt - 2,
1203 "Skipping unexpected GLContextType for GPU tests");
1204
1205 for (auto& contextType : contextTypes) {
kkinnunen179a8f52015-11-20 13:32:24 -08001206 int contextSelector = kNone_GPUTestContexts;
kkinnunen3e980c32015-12-23 01:33:00 -08001207 if (GrContextFactory::IsRenderingGLContext(contextType)) {
kkinnunen179a8f52015-11-20 13:32:24 -08001208 contextSelector |= kAllRendering_GPUTestContexts;
kkinnunen3e980c32015-12-23 01:33:00 -08001209 } else if (contextType == GrContextFactory::kNative_GLContextType) {
kkinnunen179a8f52015-11-20 13:32:24 -08001210 contextSelector |= kNative_GPUTestContexts;
kkinnunen3e980c32015-12-23 01:33:00 -08001211 } else if (contextType == GrContextFactory::kNull_GLContextType) {
kkinnunen179a8f52015-11-20 13:32:24 -08001212 contextSelector |= kNull_GPUTestContexts;
kkinnunen3e980c32015-12-23 01:33:00 -08001213 } else if (contextType == GrContextFactory::kDebug_GLContextType) {
kkinnunen55eeae92015-12-10 23:19:29 -08001214 contextSelector |= kDebug_GPUTestContexts;
kkinnunen179a8f52015-11-20 13:32:24 -08001215 }
1216 if ((testContexts & contextSelector) == 0) {
1217 continue;
1218 }
kkinnunen34058002016-01-06 23:49:30 -08001219 GrContextFactory::ContextInfo context = factory->getContextInfo(contextType);
1220 if (context.fGrContext) {
kkinnunen5219fd92015-12-10 06:28:13 -08001221 call_test(test, reporter, context);
1222 }
kkinnunen34058002016-01-06 23:49:30 -08001223 context = factory->getContextInfo(contextType,
1224 GrContextFactory::kEnableNVPR_GLContextOptions);
1225 if (context.fGrContext) {
kkinnunen179a8f52015-11-20 13:32:24 -08001226 call_test(test, reporter, context);
1227 }
1228 }
1229#endif
1230}
1231
1232template
1233void RunWithGPUTestContexts<TestWithGrContext>(TestWithGrContext test,
1234 GPUTestContexts testContexts,
1235 Reporter* reporter,
1236 GrContextFactory* factory);
1237template
1238void RunWithGPUTestContexts<TestWithGrContextAndGLContext>(TestWithGrContextAndGLContext test,
1239 GPUTestContexts testContexts,
1240 Reporter* reporter,
1241 GrContextFactory* factory);
1242} // namespace skiatest
1243
borenet48087572015-04-02 12:16:36 -07001244#if !defined(SK_BUILD_FOR_IOS)
jcgregorio3b27ade2014-11-13 08:06:40 -08001245int main(int argc, char** argv) {
1246 SkCommandLineFlags::Parse(argc, argv);
1247 return dm_main();
1248}
1249#endif