blob: 7302ebc270e1aa6bc77ee3059bc0bef2f47d40a5 [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;
msarettbb25b532016-01-13 09:31:39 -0800235 case CodecSrc::kCodecZeroInit_Mode:
236 folder.append("codec_zero_init");
237 break;
msarett9e707a02015-09-01 14:57:57 -0700238 case CodecSrc::kScanline_Mode:
239 folder.append("scanline");
240 break;
msarett9e707a02015-09-01 14:57:57 -0700241 case CodecSrc::kStripe_Mode:
242 folder.append("stripe");
243 break;
244 case CodecSrc::kSubset_Mode:
msarett36c37962015-09-02 13:20:52 -0700245 folder.append("codec_subset");
msarett9e707a02015-09-01 14:57:57 -0700246 break;
247 }
248
249 switch (dstColorType) {
250 case CodecSrc::kGrayscale_Always_DstColorType:
251 folder.append("_kGray8");
252 break;
253 case CodecSrc::kIndex8_Always_DstColorType:
254 folder.append("_kIndex8");
255 break;
256 default:
257 break;
258 }
259
260 if (1.0f != scale) {
261 folder.appendf("_%.3f", scale);
262 }
263
264 CodecSrc* src = new CodecSrc(path, mode, dstColorType, scale);
265 push_src("image", folder, src);
266}
267
msarett3d9d7a72015-10-21 10:27:10 -0700268static void push_android_codec_src(Path path, AndroidCodecSrc::Mode mode,
269 CodecSrc::DstColorType dstColorType, int sampleSize) {
270 SkString folder;
271 switch (mode) {
272 case AndroidCodecSrc::kFullImage_Mode:
273 folder.append("scaled_codec");
274 break;
275 case AndroidCodecSrc::kDivisor_Mode:
276 folder.append("scaled_codec_divisor");
277 break;
278 }
279
280 switch (dstColorType) {
281 case CodecSrc::kGrayscale_Always_DstColorType:
282 folder.append("_kGray8");
283 break;
284 case CodecSrc::kIndex8_Always_DstColorType:
285 folder.append("_kIndex8");
286 break;
287 default:
288 break;
289 }
290
291 if (1 != sampleSize) {
msarett4b0778e2015-11-13 09:59:11 -0800292 folder.appendf("_%.3f", 1.0f / (float) sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700293 }
294
295 AndroidCodecSrc* src = new AndroidCodecSrc(path, mode, dstColorType, sampleSize);
296 push_src("image", folder, src);
297}
298
msarett438b2ad2015-04-09 12:43:10 -0700299static void push_codec_srcs(Path path) {
300 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str()));
301 if (!encoded) {
302 SkDebugf("Couldn't read %s.", path.c_str());
303 return;
304 }
305 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
halcanary96fcdcc2015-08-27 07:41:13 -0700306 if (nullptr == codec.get()) {
msarett438b2ad2015-04-09 12:43:10 -0700307 SkDebugf("Couldn't create codec for %s.", path.c_str());
308 return;
309 }
310
msarett36c37962015-09-02 13:20:52 -0700311 // Native Scales
msarett0a242972015-06-11 14:27:27 -0700312 // TODO (msarett): Implement scaling tests for SkImageDecoder in order to compare with these
313 // tests. SkImageDecoder supports downscales by integer factors.
emmaleer8f4ba762015-08-14 07:44:46 -0700314 // 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 -0700315 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 -0700316
msarettbb25b532016-01-13 09:31:39 -0800317 const CodecSrc::Mode nativeModes[] = { CodecSrc::kCodec_Mode, CodecSrc::kCodecZeroInit_Mode,
318 CodecSrc::kScanline_Mode, CodecSrc::kStripe_Mode, CodecSrc::kSubset_Mode };
msarett9e707a02015-09-01 14:57:57 -0700319
msarett36c37962015-09-02 13:20:52 -0700320 CodecSrc::DstColorType colorTypes[3];
321 uint32_t numColorTypes;
322 switch (codec->getInfo().colorType()) {
323 case kGray_8_SkColorType:
324 // FIXME: Is this a long term solution for testing wbmps decodes to kIndex8?
halcanary6950de62015-11-07 05:29:00 -0800325 // Further discussion on this topic is at https://bug.skia.org/3683 .
msarett3d9d7a72015-10-21 10:27:10 -0700326 // This causes us to try to convert grayscale jpegs to kIndex8. We currently
327 // fail non-fatally in this case.
msarett36c37962015-09-02 13:20:52 -0700328 colorTypes[0] = CodecSrc::kGetFromCanvas_DstColorType;
329 colorTypes[1] = CodecSrc::kGrayscale_Always_DstColorType;
330 colorTypes[2] = CodecSrc::kIndex8_Always_DstColorType;
331 numColorTypes = 3;
332 break;
333 case kIndex_8_SkColorType:
334 colorTypes[0] = CodecSrc::kGetFromCanvas_DstColorType;
335 colorTypes[1] = CodecSrc::kIndex8_Always_DstColorType;
336 numColorTypes = 2;
337 break;
338 default:
339 colorTypes[0] = CodecSrc::kGetFromCanvas_DstColorType;
340 numColorTypes = 1;
341 break;
342 }
msarett9e707a02015-09-01 14:57:57 -0700343
msarett36c37962015-09-02 13:20:52 -0700344 for (float scale : nativeScales) {
msarett36c37962015-09-02 13:20:52 -0700345 for (CodecSrc::Mode mode : nativeModes) {
346 for (uint32_t i = 0; i < numColorTypes; i++) {
347 push_codec_src(path, mode, colorTypes[i], scale);
msarett9e707a02015-09-01 14:57:57 -0700348 }
349 }
msarett0a242972015-06-11 14:27:27 -0700350 }
msarett36c37962015-09-02 13:20:52 -0700351
halcanary6950de62015-11-07 05:29:00 -0800352 // https://bug.skia.org/4428
msarett33c76232015-11-16 13:43:40 -0800353 bool subset = false;
354 // The following image types are supported by BitmapRegionDecoder,
355 // so we will test full image decodes and subset decodes.
msarettbe8216a2015-12-04 08:00:50 -0800356 static const char* const exts[] = {
msarett3d9d7a72015-10-21 10:27:10 -0700357 "jpg", "jpeg", "png", "webp",
358 "JPG", "JPEG", "PNG", "WEBP",
359 };
msarettbe8216a2015-12-04 08:00:50 -0800360 for (const char* ext : exts) {
msarett3d9d7a72015-10-21 10:27:10 -0700361 if (path.endsWith(ext)) {
msarett33c76232015-11-16 13:43:40 -0800362 subset = true;
msarett3d9d7a72015-10-21 10:27:10 -0700363 break;
364 }
365 }
msarett33c76232015-11-16 13:43:40 -0800366
msarett3d9d7a72015-10-21 10:27:10 -0700367 const int sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
msarett36c37962015-09-02 13:20:52 -0700368
msarett3d9d7a72015-10-21 10:27:10 -0700369 for (int sampleSize : sampleSizes) {
msarett33c76232015-11-16 13:43:40 -0800370 for (uint32_t i = 0; i < numColorTypes; i++) {
371 push_android_codec_src(path, AndroidCodecSrc::kFullImage_Mode, colorTypes[i],
372 sampleSize);
373 if (subset) {
374 push_android_codec_src(path, AndroidCodecSrc::kDivisor_Mode, colorTypes[i],
375 sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700376 }
msarett36c37962015-09-02 13:20:52 -0700377 }
378 }
msarett438b2ad2015-04-09 12:43:10 -0700379}
380
msarett5cb48852015-11-06 08:56:32 -0800381static bool brd_color_type_supported(SkBitmapRegionDecoder::Strategy strategy,
msaretta5783ae2015-09-08 15:35:32 -0700382 CodecSrc::DstColorType dstColorType) {
383 switch (strategy) {
msarett5cb48852015-11-06 08:56:32 -0800384 case SkBitmapRegionDecoder::kCanvas_Strategy:
msaretta5783ae2015-09-08 15:35:32 -0700385 if (CodecSrc::kGetFromCanvas_DstColorType == dstColorType) {
386 return true;
387 }
388 return false;
msarett5cb48852015-11-06 08:56:32 -0800389 case SkBitmapRegionDecoder::kAndroidCodec_Strategy:
msarett26ad17b2015-10-22 07:29:19 -0700390 switch (dstColorType) {
391 case CodecSrc::kGetFromCanvas_DstColorType:
392 case CodecSrc::kIndex8_Always_DstColorType:
393 case CodecSrc::kGrayscale_Always_DstColorType:
394 return true;
395 default:
396 return false;
397 }
msaretta5783ae2015-09-08 15:35:32 -0700398 default:
399 SkASSERT(false);
400 return false;
401 }
402}
403
msarett5cb48852015-11-06 08:56:32 -0800404static void push_brd_src(Path path, SkBitmapRegionDecoder::Strategy strategy,
msaretta5783ae2015-09-08 15:35:32 -0700405 CodecSrc::DstColorType dstColorType, BRDSrc::Mode mode, uint32_t sampleSize) {
406 SkString folder;
407 switch (strategy) {
msarett5cb48852015-11-06 08:56:32 -0800408 case SkBitmapRegionDecoder::kCanvas_Strategy:
msaretta5783ae2015-09-08 15:35:32 -0700409 folder.append("brd_canvas");
410 break;
msarett5cb48852015-11-06 08:56:32 -0800411 case SkBitmapRegionDecoder::kAndroidCodec_Strategy:
msarett26ad17b2015-10-22 07:29:19 -0700412 folder.append("brd_android_codec");
413 break;
msaretta5783ae2015-09-08 15:35:32 -0700414 default:
415 SkASSERT(false);
416 return;
417 }
418
419 switch (mode) {
420 case BRDSrc::kFullImage_Mode:
421 break;
422 case BRDSrc::kDivisor_Mode:
423 folder.append("_divisor");
424 break;
425 default:
426 SkASSERT(false);
427 return;
428 }
429
430 switch (dstColorType) {
431 case CodecSrc::kGetFromCanvas_DstColorType:
432 break;
433 case CodecSrc::kIndex8_Always_DstColorType:
434 folder.append("_kIndex");
435 break;
436 case CodecSrc::kGrayscale_Always_DstColorType:
437 folder.append("_kGray");
438 break;
439 default:
440 SkASSERT(false);
441 return;
442 }
443
444 if (1 != sampleSize) {
msarett4b0778e2015-11-13 09:59:11 -0800445 folder.appendf("_%.3f", 1.0f / (float) sampleSize);
msaretta5783ae2015-09-08 15:35:32 -0700446 }
447
448 BRDSrc* src = new BRDSrc(path, strategy, mode, dstColorType, sampleSize);
449 push_src("image", folder, src);
450}
451
452static void push_brd_srcs(Path path) {
453
msarett5cb48852015-11-06 08:56:32 -0800454 const SkBitmapRegionDecoder::Strategy strategies[] = {
455 SkBitmapRegionDecoder::kCanvas_Strategy,
msarett5cb48852015-11-06 08:56:32 -0800456 SkBitmapRegionDecoder::kAndroidCodec_Strategy,
msaretta5783ae2015-09-08 15:35:32 -0700457 };
458
scroggo501b7342015-11-03 07:55:11 -0800459 // Test on a variety of sampleSizes, making sure to include:
460 // - 2, 4, and 8, which are natively supported by jpeg
461 // - multiples of 2 which are not divisible by 4 (analogous for 4)
462 // - larger powers of two, since BRD clients generally use powers of 2
463 // We will only produce output for the larger sizes on large images.
464 const uint32_t sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 24, 32, 64 };
msarett6efbe052015-09-11 09:01:16 -0700465
msaretta5783ae2015-09-08 15:35:32 -0700466 // We will only test to one backend (8888), but we will test all of the
467 // color types that we need to decode to on this backend.
468 const CodecSrc::DstColorType dstColorTypes[] = {
msarett26ad17b2015-10-22 07:29:19 -0700469 CodecSrc::kGetFromCanvas_DstColorType,
470 CodecSrc::kIndex8_Always_DstColorType,
471 CodecSrc::kGrayscale_Always_DstColorType,
msaretta5783ae2015-09-08 15:35:32 -0700472 };
473
474 const BRDSrc::Mode modes[] = {
msarett26ad17b2015-10-22 07:29:19 -0700475 BRDSrc::kFullImage_Mode,
476 BRDSrc::kDivisor_Mode,
msaretta5783ae2015-09-08 15:35:32 -0700477 };
478
msarett5cb48852015-11-06 08:56:32 -0800479 for (SkBitmapRegionDecoder::Strategy strategy : strategies) {
msarett6efbe052015-09-11 09:01:16 -0700480 for (uint32_t sampleSize : sampleSizes) {
msarett6efbe052015-09-11 09:01:16 -0700481 for (CodecSrc::DstColorType dstColorType : dstColorTypes) {
482 if (brd_color_type_supported(strategy, dstColorType)) {
483 for (BRDSrc::Mode mode : modes) {
msaretta5783ae2015-09-08 15:35:32 -0700484 push_brd_src(path, strategy, dstColorType, mode, sampleSize);
485 }
486 }
487 }
488 }
489 }
490}
491
492static bool brd_supported(const char* ext) {
msarett8c8f22a2015-04-01 06:58:48 -0700493 static const char* const exts[] = {
msaretta5783ae2015-09-08 15:35:32 -0700494 "jpg", "jpeg", "png", "webp",
495 "JPG", "JPEG", "PNG", "WEBP",
msarett8c8f22a2015-04-01 06:58:48 -0700496 };
497
498 for (uint32_t i = 0; i < SK_ARRAY_COUNT(exts); i++) {
499 if (0 == strcmp(exts[i], ext)) {
500 return true;
501 }
502 }
503 return false;
scroggo9b77ddd2015-03-19 06:03:39 -0700504}
505
mtklein748ca3b2015-01-15 10:56:12 -0800506static void gather_srcs() {
507 for (const skiagm::GMRegistry* r = skiagm::GMRegistry::Head(); r; r = r->next()) {
djsollen54416de2015-04-03 07:24:48 -0700508 push_src("gm", "", new GMSrc(r->factory()));
mtklein748ca3b2015-01-15 10:56:12 -0800509 }
halcanaryfc37ad12015-01-30 07:31:19 -0800510 for (int i = 0; i < FLAGS_skps.count(); i++) {
511 const char* path = FLAGS_skps[i];
512 if (sk_isdir(path)) {
513 SkOSFile::Iter it(path, "skp");
514 for (SkString file; it.next(&file); ) {
djsollen54416de2015-04-03 07:24:48 -0700515 push_src("skp", "", new SKPSrc(SkOSPath::Join(path, file.c_str())));
halcanaryfc37ad12015-01-30 07:31:19 -0800516 }
517 } else {
djsollen54416de2015-04-03 07:24:48 -0700518 push_src("skp", "", new SKPSrc(path));
mtklein114c3cd2015-01-15 10:15:02 -0800519 }
520 }
halcanary23b03c32015-01-30 09:58:58 -0800521 static const char* const exts[] = {
522 "bmp", "gif", "jpg", "jpeg", "png", "webp", "ktx", "astc", "wbmp", "ico",
523 "BMP", "GIF", "JPG", "JPEG", "PNG", "WEBP", "KTX", "ASTC", "WBMP", "ICO",
524 };
525 for (int i = 0; i < FLAGS_images.count(); i++) {
526 const char* flag = FLAGS_images[i];
527 if (sk_isdir(flag)) {
528 for (size_t j = 0; j < SK_ARRAY_COUNT(exts); j++) {
529 SkOSFile::Iter it(flag, exts[j]);
530 for (SkString file; it.next(&file); ) {
531 SkString path = SkOSPath::Join(flag, file.c_str());
djsollen54416de2015-04-03 07:24:48 -0700532 push_src("image", "decode", new ImageSrc(path)); // Decode entire image
msaretta5783ae2015-09-08 15:35:32 -0700533 push_codec_srcs(path);
534 if (brd_supported(exts[j])) {
535 push_brd_srcs(path);
scroggo9b77ddd2015-03-19 06:03:39 -0700536 }
halcanary23b03c32015-01-30 09:58:58 -0800537 }
mtklein114c3cd2015-01-15 10:15:02 -0800538 }
halcanary23b03c32015-01-30 09:58:58 -0800539 } else if (sk_exists(flag)) {
540 // assume that FLAGS_images[i] is a valid image if it is a file.
djsollen54416de2015-04-03 07:24:48 -0700541 push_src("image", "decode", new ImageSrc(flag)); // Decode entire image.
msarett438b2ad2015-04-09 12:43:10 -0700542 push_codec_srcs(flag);
msaretta5783ae2015-09-08 15:35:32 -0700543 push_brd_srcs(flag);
mtklein709d2c32015-01-15 08:30:25 -0800544 }
mtklein709d2c32015-01-15 08:30:25 -0800545 }
546}
547
kkinnunen3e980c32015-12-23 01:33:00 -0800548static void push_sink(const SkCommandLineConfig& config, Sink* s) {
rmistry0f515bd2015-12-22 10:22:26 -0800549 SkAutoTDelete<Sink> sink(s);
kkinnunen3e980c32015-12-23 01:33:00 -0800550
mtkleine0effd62015-07-29 06:37:28 -0700551 // Try a simple Src as a canary. If it fails, skip this sink.
mtklein748ca3b2015-01-15 10:56:12 -0800552 struct : public Src {
mtkleine0effd62015-07-29 06:37:28 -0700553 Error draw(SkCanvas* c) const override {
554 c->drawRect(SkRect::MakeWH(1,1), SkPaint());
555 return "";
556 }
mtklein36352bf2015-03-25 18:17:31 -0700557 SkISize size() const override { return SkISize::Make(16, 16); }
mtkleine0effd62015-07-29 06:37:28 -0700558 Name name() const override { return "justOneRect"; }
559 } justOneRect;
mtklein114c3cd2015-01-15 10:15:02 -0800560
mtklein748ca3b2015-01-15 10:56:12 -0800561 SkBitmap bitmap;
562 SkDynamicMemoryWStream stream;
mtkleinb9eb4ac2015-02-02 18:26:03 -0800563 SkString log;
mtkleine0effd62015-07-29 06:37:28 -0700564 Error err = sink->draw(justOneRect, &bitmap, &stream, &log);
mtklein4089ef72015-03-05 08:40:28 -0800565 if (err.isFatal()) {
kkinnunen3e980c32015-12-23 01:33:00 -0800566 SkDebugf("Could not run %s: %s\n", config.getTag().c_str(), err.c_str());
mtklein05641a52015-04-21 10:49:13 -0700567 exit(1);
mtklein114c3cd2015-01-15 10:15:02 -0800568 }
569
mtkleine0effd62015-07-29 06:37:28 -0700570 TaggedSink& ts = gSinks.push_back();
mtklein748ca3b2015-01-15 10:56:12 -0800571 ts.reset(sink.detach());
kkinnunen3e980c32015-12-23 01:33:00 -0800572 ts.tag = config.getTag();
mtklein748ca3b2015-01-15 10:56:12 -0800573}
574
575static bool gpu_supported() {
576#if SK_SUPPORT_GPU
577 return FLAGS_gpu;
578#else
579 return false;
580#endif
581}
kkinnunen9ebc3f02015-12-21 23:48:13 -0800582
kkinnunen3e980c32015-12-23 01:33:00 -0800583static Sink* create_sink(const SkCommandLineConfig* config) {
584#if SK_SUPPORT_GPU
585 if (gpu_supported()) {
586 if (const SkCommandLineConfigGpu* gpuConfig = config->asConfigGpu()) {
587 GrContextFactory::GLContextType contextType = gpuConfig->getContextType();
588 GrContextFactory::GLContextOptions contextOptions =
589 GrContextFactory::kNone_GLContextOptions;
590 if (gpuConfig->getUseNVPR()) {
591 contextOptions = static_cast<GrContextFactory::GLContextOptions>(
592 contextOptions | GrContextFactory::kEnableNVPR_GLContextOptions);
593 }
594 GrContextFactory testFactory;
595 if (!testFactory.get(contextType, contextOptions)) {
596 SkDebugf("WARNING: can not create GPU context for config '%s'. "
597 "GM tests will be skipped.\n", gpuConfig->getTag().c_str());
598 return nullptr;
599 }
600 return new GPUSink(contextType, contextOptions, gpuConfig->getSamples(),
601 gpuConfig->getUseDIText(), FLAGS_gpu_threading);
602 }
603 }
604#endif
605
606#define SINK(t, sink, ...) if (config->getBackend().equals(t)) { return new sink(__VA_ARGS__); }
607
tomhudsoneebc39a2015-02-23 12:18:05 -0800608#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
609 SINK("hwui", HWUISink);
610#endif
611
mtklein748ca3b2015-01-15 10:56:12 -0800612 if (FLAGS_cpu) {
613 SINK("565", RasterSink, kRGB_565_SkColorType);
614 SINK("8888", RasterSink, kN32_SkColorType);
halcanaryc11c62f2015-09-28 11:51:54 -0700615 SINK("pdf", PDFSink, "Pdfium");
616 SINK("pdf_poppler", PDFSink, "Poppler");
mtklein9c3f17d2015-01-28 11:35:18 -0800617 SINK("skp", SKPSink);
mtklein8a4527e2015-01-31 20:00:58 -0800618 SINK("svg", SVGSink);
619 SINK("null", NullSink);
halcanary47ef4d52015-03-03 09:13:09 -0800620 SINK("xps", XPSSink);
mtklein748ca3b2015-01-15 10:56:12 -0800621 }
622#undef SINK
halcanary96fcdcc2015-08-27 07:41:13 -0700623 return nullptr;
mtklein114c3cd2015-01-15 10:15:02 -0800624}
625
kkinnunen3e980c32015-12-23 01:33:00 -0800626static Sink* create_via(const SkString& tag, Sink* wrapped) {
627#define VIA(t, via, ...) if (tag.equals(t)) { return new via(__VA_ARGS__); }
halcanary96fcdcc2015-08-27 07:41:13 -0700628 VIA("twice", ViaTwice, wrapped);
halcanary96fcdcc2015-08-27 07:41:13 -0700629 VIA("serialize", ViaSerialization, wrapped);
mtklein4a34ecb2016-01-08 10:19:35 -0800630 VIA("pic", ViaPicture, wrapped);
halcanary96fcdcc2015-08-27 07:41:13 -0700631 VIA("2ndpic", ViaSecondPicture, wrapped);
mtkleind31c13d2015-05-05 12:59:56 -0700632 VIA("sp", ViaSingletonPictures, wrapped);
halcanary96fcdcc2015-08-27 07:41:13 -0700633 VIA("tiles", ViaTiles, 256, 256, nullptr, wrapped);
mtklein7edca212015-01-21 13:18:51 -0800634 VIA("tiles_rt", ViaTiles, 256, 256, new SkRTreeFactory, wrapped);
mtklein2e2ea382015-10-16 10:29:41 -0700635 VIA("remote", ViaRemote, false, wrapped);
636 VIA("remote_cache", ViaRemote, true, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800637
mtkleind603b222015-02-17 11:13:33 -0800638 if (FLAGS_matrix.count() == 4) {
mtklein748ca3b2015-01-15 10:56:12 -0800639 SkMatrix m;
mtkleind603b222015-02-17 11:13:33 -0800640 m.reset();
641 m.setScaleX((SkScalar)atof(FLAGS_matrix[0]));
642 m.setSkewX ((SkScalar)atof(FLAGS_matrix[1]));
643 m.setSkewY ((SkScalar)atof(FLAGS_matrix[2]));
644 m.setScaleY((SkScalar)atof(FLAGS_matrix[3]));
645 VIA("matrix", ViaMatrix, m, wrapped);
646 VIA("upright", ViaUpright, m, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800647 }
tomhudson64de1e12015-03-05 08:01:07 -0800648
649#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
650 VIA("androidsdk", ViaAndroidSDK, wrapped);
651#endif
652
mtklein748ca3b2015-01-15 10:56:12 -0800653#undef VIA
halcanary96fcdcc2015-08-27 07:41:13 -0700654 return nullptr;
mtklein114c3cd2015-01-15 10:15:02 -0800655}
656
mtklein748ca3b2015-01-15 10:56:12 -0800657static void gather_sinks() {
kkinnunen3e980c32015-12-23 01:33:00 -0800658 SkCommandLineConfigArray configs;
659 ParseConfigs(FLAGS_config, &configs);
660 for (int i = 0; i < configs.count(); i++) {
661 const SkCommandLineConfig& config = *configs[i];
662 Sink* sink = create_sink(&config);
663 if (sink == nullptr) {
664 SkDebugf("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(),
665 config.getTag().c_str());
666 continue;
667 }
mtklein748ca3b2015-01-15 10:56:12 -0800668
kkinnunen3e980c32015-12-23 01:33:00 -0800669 const SkTArray<SkString>& parts = config.getViaParts();
670 for (int j = parts.count(); j-- > 0;) {
671 const SkString& part = parts[j];
672 Sink* next = create_via(part, sink);
halcanary96fcdcc2015-08-27 07:41:13 -0700673 if (next == nullptr) {
kkinnunen3e980c32015-12-23 01:33:00 -0800674 SkDebugf("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(),
675 part.c_str());
mtklein748ca3b2015-01-15 10:56:12 -0800676 delete sink;
halcanary96fcdcc2015-08-27 07:41:13 -0700677 sink = nullptr;
mtklein748ca3b2015-01-15 10:56:12 -0800678 break;
679 }
680 sink = next;
681 }
682 if (sink) {
683 push_sink(config, sink);
mtklein114c3cd2015-01-15 10:15:02 -0800684 }
685 }
686}
mtklein709d2c32015-01-15 08:30:25 -0800687
mtkleina5114d72015-08-24 13:27:01 -0700688static bool dump_png(SkBitmap bitmap, const char* path, const char* md5) {
689 const int w = bitmap.width(),
690 h = bitmap.height();
691
692 // First get the bitmap into N32 color format. The next step will work only there.
693 if (bitmap.colorType() != kN32_SkColorType) {
694 SkBitmap n32;
695 if (!bitmap.copyTo(&n32, kN32_SkColorType)) {
696 return false;
697 }
698 bitmap = n32;
699 }
700
701 // Convert our N32 bitmap into unpremul RGBA for libpng.
702 SkAutoTMalloc<uint32_t> rgba(w*h);
703 if (!bitmap.readPixels(SkImageInfo::Make(w,h, kRGBA_8888_SkColorType, kUnpremul_SkAlphaType),
704 rgba, 4*w, 0,0)) {
705 return false;
706 }
707
708 // We don't need bitmap anymore. Might as well drop our ref.
mtkleinfccb77d2015-08-24 14:13:29 -0700709 bitmap.reset();
mtkleina5114d72015-08-24 13:27:01 -0700710
mtkleinc64137c2015-08-25 10:56:08 -0700711 FILE* f = fopen(path, "wb");
mtkleina5114d72015-08-24 13:27:01 -0700712 if (!f) { return false; }
713
714 png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
715 if (!png) {
716 fclose(f);
717 return false;
718 }
719
720 png_infop info = png_create_info_struct(png);
721 if (!info) {
722 png_destroy_write_struct(&png, &info);
723 fclose(f);
724 return false;
725 }
726
mtkleind69ece62015-09-10 10:37:44 -0700727 SkString description;
728 description.append("Key: ");
729 for (int i = 0; i < FLAGS_key.count(); i++) {
730 description.appendf("%s ", FLAGS_key[i]);
731 }
732 description.append("Properties: ");
733 for (int i = 0; i < FLAGS_properties.count(); i++) {
734 description.appendf("%s ", FLAGS_properties[i]);
735 }
736 description.appendf("MD5: %s", md5);
737
mtkleina5114d72015-08-24 13:27:01 -0700738 png_text text[2];
739 text[0].key = (png_charp)"Author";
740 text[0].text = (png_charp)"DM dump_png()";
741 text[0].compression = PNG_TEXT_COMPRESSION_NONE;
742 text[1].key = (png_charp)"Description";
mtkleind69ece62015-09-10 10:37:44 -0700743 text[1].text = (png_charp)description.c_str();
mtkleina5114d72015-08-24 13:27:01 -0700744 text[1].compression = PNG_TEXT_COMPRESSION_NONE;
745 png_set_text(png, info, text, 2);
746
747 png_init_io(png, f);
748 png_set_IHDR(png, info, (png_uint_32)w, (png_uint_32)h, 8,
749 PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE,
750 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
751 png_write_info(png, info);
752 for (int j = 0; j < h; j++) {
753 png_bytep row = (png_bytep)(rgba.get() + w*j);
754 png_write_rows(png, &row, 1);
755 }
756 png_write_end(png, info);
757
758 png_destroy_write_struct(&png, &info);
759 fclose(f);
760 return true;
761}
762
mtkleina2ef6422015-01-15 13:44:22 -0800763static bool match(const char* needle, const char* haystack) {
halcanary96fcdcc2015-08-27 07:41:13 -0700764 return 0 == strcmp("_", needle) || nullptr != strstr(haystack, needle);
mtkleina2ef6422015-01-15 13:44:22 -0800765}
766
djsollen54416de2015-04-03 07:24:48 -0700767static ImplicitString is_blacklisted(const char* sink, const char* src,
768 const char* srcOptions, const char* name) {
mtklein0d243ff2015-04-03 07:51:00 -0700769 for (int i = 0; i < FLAGS_blacklist.count() - 3; i += 4) {
mtkleina2ef6422015-01-15 13:44:22 -0800770 if (match(FLAGS_blacklist[i+0], sink) &&
djsollen54416de2015-04-03 07:24:48 -0700771 match(FLAGS_blacklist[i+1], src) &&
772 match(FLAGS_blacklist[i+2], srcOptions) &&
773 match(FLAGS_blacklist[i+3], name)) {
774 return SkStringPrintf("%s %s %s %s",
775 FLAGS_blacklist[i+0], FLAGS_blacklist[i+1],
776 FLAGS_blacklist[i+2], FLAGS_blacklist[i+3]);
mtkleina2ef6422015-01-15 13:44:22 -0800777 }
778 }
779 return "";
780}
781
mtkleincd50bca2016-01-05 06:20:20 -0800782// Even when a Task Sink reports to be non-threadsafe (e.g. GPU), we know things like
783// .png encoding are definitely thread safe. This lets us offload that work to CPU threads.
784static SkTaskGroup gDefinitelyThreadSafeWork;
785
mtklein748ca3b2015-01-15 10:56:12 -0800786// The finest-grained unit of work we can run: draw a single Src into a single Sink,
787// report any errors, and perhaps write out the output: a .png of the bitmap, or a raw stream.
788struct Task {
mtkleine0effd62015-07-29 06:37:28 -0700789 Task(const TaggedSrc& src, const TaggedSink& sink) : src(src), sink(sink) {}
790 const TaggedSrc& src;
791 const TaggedSink& sink;
mtklein748ca3b2015-01-15 10:56:12 -0800792
793 static void Run(Task* task) {
mtkleina2ef6422015-01-15 13:44:22 -0800794 SkString name = task->src->name();
mtkleine0effd62015-07-29 06:37:28 -0700795
796 // We'll skip drawing this Src/Sink pair if:
797 // - the Src vetoes the Sink;
798 // - this Src / Sink combination is on the blacklist;
799 // - it's a dry run.
mtklein99cab4e2015-07-31 06:43:04 -0700800 SkString note(task->src->veto(task->sink->flags()) ? " (veto)" : "");
kkinnunen3e980c32015-12-23 01:33:00 -0800801 SkString whyBlacklisted = is_blacklisted(task->sink.tag.c_str(), task->src.tag.c_str(),
msarett9e707a02015-09-01 14:57:57 -0700802 task->src.options.c_str(), name.c_str());
mtkleinb37cb412015-03-18 05:27:14 -0700803 if (!whyBlacklisted.isEmpty()) {
804 note.appendf(" (--blacklist %s)", whyBlacklisted.c_str());
805 }
mtkleine0effd62015-07-29 06:37:28 -0700806
mtkleinb9eb4ac2015-02-02 18:26:03 -0800807 SkString log;
mtkleinf27f08b2015-11-03 06:54:24 -0800808 auto timerStart = now_ms();
mtkleine0effd62015-07-29 06:37:28 -0700809 if (!FLAGS_dryRun && note.isEmpty()) {
mtklein748ca3b2015-01-15 10:56:12 -0800810 SkBitmap bitmap;
811 SkDynamicMemoryWStream stream;
bsalomon821e10e2015-06-04 14:15:33 -0700812 if (FLAGS_pre_log) {
kkinnunen3e980c32015-12-23 01:33:00 -0800813 SkDebugf("\nRunning %s->%s", name.c_str(), task->sink.tag.c_str());
bsalomon821e10e2015-06-04 14:15:33 -0700814 }
kkinnunen3e980c32015-12-23 01:33:00 -0800815 start(task->sink.tag.c_str(), task->src.tag, task->src.options, name.c_str());
mtkleinb9eb4ac2015-02-02 18:26:03 -0800816 Error err = task->sink->draw(*task->src, &bitmap, &stream, &log);
mtklein748ca3b2015-01-15 10:56:12 -0800817 if (!err.isEmpty()) {
mtkleinf27f08b2015-11-03 06:54:24 -0800818 auto elapsed = now_ms() - timerStart;
mtklein4089ef72015-03-05 08:40:28 -0800819 if (err.isFatal()) {
djsollen54416de2015-04-03 07:24:48 -0700820 fail(SkStringPrintf("%s %s %s %s: %s",
kkinnunen3e980c32015-12-23 01:33:00 -0800821 task->sink.tag.c_str(),
msarett9e707a02015-09-01 14:57:57 -0700822 task->src.tag.c_str(),
823 task->src.options.c_str(),
mtklein4089ef72015-03-05 08:40:28 -0800824 name.c_str(),
825 err.c_str()));
mtkleinb37cb412015-03-18 05:27:14 -0700826 } else {
827 note.appendf(" (skipped: %s)", err.c_str());
mtklein4089ef72015-03-05 08:40:28 -0800828 }
kkinnunen3e980c32015-12-23 01:33:00 -0800829 done(elapsed, task->sink.tag.c_str(), task->src.tag, task->src.options,
djsollen54416de2015-04-03 07:24:48 -0700830 name, note, log);
mtklein4089ef72015-03-05 08:40:28 -0800831 return;
mtklein748ca3b2015-01-15 10:56:12 -0800832 }
mtklein62bd1a62015-01-27 14:46:26 -0800833
mtkleincd50bca2016-01-05 06:20:20 -0800834 // We're likely switching threads here, so we must capture by value, [=] or [foo,bar].
835 SkStreamAsset* data = stream.detachAsStream();
836 gDefinitelyThreadSafeWork.add([task,name,bitmap,data]{
837 SkAutoTDelete<SkStreamAsset> ownedData(data);
838
839 // Why doesn't the copy constructor do this when we have pre-locked pixels?
840 bitmap.lockPixels();
841
842 SkString md5;
843 if (!FLAGS_writePath.isEmpty() || !FLAGS_readPath.isEmpty()) {
844 SkMD5 hash;
845 if (data->getLength()) {
846 hash.writeStream(data, data->getLength());
847 data->rewind();
mtklein38408462015-07-08 07:25:27 -0700848 } else {
mtkleincd50bca2016-01-05 06:20:20 -0800849 // If we're BGRA (Linux, Windows), swizzle over to RGBA (Mac, Android).
850 // This helps eliminate multiple 0-pixel-diff hashes on gold.skia.org.
851 // (Android's general slow speed breaks the tie arbitrarily in RGBA's favor.)
852 // We might consider promoting 565 to RGBA too.
853 if (bitmap.colorType() == kBGRA_8888_SkColorType) {
854 SkBitmap swizzle;
855 SkAssertResult(bitmap.copyTo(&swizzle, kRGBA_8888_SkColorType));
856 hash.write(swizzle.getPixels(), swizzle.getSize());
857 } else {
858 hash.write(bitmap.getPixels(), bitmap.getSize());
859 }
860 }
861 SkMD5::Digest digest;
862 hash.finish(digest);
863 for (int i = 0; i < 16; i++) {
864 md5.appendf("%02x", digest.data[i]);
mtklein38408462015-07-08 07:25:27 -0700865 }
mtklein62bd1a62015-01-27 14:46:26 -0800866 }
mtklein62bd1a62015-01-27 14:46:26 -0800867
mtkleincd50bca2016-01-05 06:20:20 -0800868 if (!FLAGS_readPath.isEmpty() &&
869 !gGold.contains(Gold(task->sink.tag.c_str(), task->src.tag.c_str(),
870 task->src.options.c_str(), name, md5))) {
871 fail(SkStringPrintf("%s not found for %s %s %s %s in %s",
872 md5.c_str(),
873 task->sink.tag.c_str(),
874 task->src.tag.c_str(),
875 task->src.options.c_str(),
876 name.c_str(),
877 FLAGS_readPath[0]));
mtklein748ca3b2015-01-15 10:56:12 -0800878 }
mtkleincd50bca2016-01-05 06:20:20 -0800879
880 if (!FLAGS_writePath.isEmpty()) {
881 const char* ext = task->sink->fileExtension();
882 if (data->getLength()) {
883 WriteToDisk(*task, md5, ext, data, data->getLength(), nullptr);
884 SkASSERT(bitmap.drawsNothing());
885 } else if (!bitmap.drawsNothing()) {
886 WriteToDisk(*task, md5, ext, nullptr, 0, &bitmap);
887 }
888 }
889 });
mtklein748ca3b2015-01-15 10:56:12 -0800890 }
kkinnunen3e980c32015-12-23 01:33:00 -0800891 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 -0800892 name, note, log);
mtklein748ca3b2015-01-15 10:56:12 -0800893 }
894
895 static void WriteToDisk(const Task& task,
mtklein62bd1a62015-01-27 14:46:26 -0800896 SkString md5,
897 const char* ext,
mtklein748ca3b2015-01-15 10:56:12 -0800898 SkStream* data, size_t len,
mtklein62bd1a62015-01-27 14:46:26 -0800899 const SkBitmap* bitmap) {
mtklein748ca3b2015-01-15 10:56:12 -0800900 JsonWriter::BitmapResult result;
djsollen54416de2015-04-03 07:24:48 -0700901 result.name = task.src->name();
kkinnunen3e980c32015-12-23 01:33:00 -0800902 result.config = task.sink.tag.c_str();
djsollen54416de2015-04-03 07:24:48 -0700903 result.sourceType = task.src.tag;
904 result.sourceOptions = task.src.options;
905 result.ext = ext;
906 result.md5 = md5;
mtklein748ca3b2015-01-15 10:56:12 -0800907 JsonWriter::AddBitmapResult(result);
908
mtkleinb0531a72015-04-07 13:38:48 -0700909 // If an MD5 is uninteresting, we want it noted in the JSON file,
910 // but don't want to dump it out as a .png (or whatever ext is).
911 if (gUninterestingHashes.contains(md5)) {
912 return;
913 }
914
mtklein748ca3b2015-01-15 10:56:12 -0800915 const char* dir = FLAGS_writePath[0];
916 if (0 == strcmp(dir, "@")) { // Needed for iOS.
917 dir = FLAGS_resourcePath[0];
918 }
919 sk_mkdir(dir);
920
921 SkString path;
922 if (FLAGS_nameByHash) {
923 path = SkOSPath::Join(dir, result.md5.c_str());
924 path.append(".");
925 path.append(ext);
926 if (sk_exists(path.c_str())) {
927 return; // Content-addressed. If it exists already, we're done.
928 }
929 } else {
kkinnunen3e980c32015-12-23 01:33:00 -0800930 path = SkOSPath::Join(dir, task.sink.tag.c_str());
mtklein748ca3b2015-01-15 10:56:12 -0800931 sk_mkdir(path.c_str());
msarett9e707a02015-09-01 14:57:57 -0700932 path = SkOSPath::Join(path.c_str(), task.src.tag.c_str());
mtklein748ca3b2015-01-15 10:56:12 -0800933 sk_mkdir(path.c_str());
msarett9e707a02015-09-01 14:57:57 -0700934 if (strcmp(task.src.options.c_str(), "") != 0) {
935 path = SkOSPath::Join(path.c_str(), task.src.options.c_str());
djsollen54416de2015-04-03 07:24:48 -0700936 sk_mkdir(path.c_str());
937 }
mtklein748ca3b2015-01-15 10:56:12 -0800938 path = SkOSPath::Join(path.c_str(), task.src->name().c_str());
939 path.append(".");
940 path.append(ext);
941 }
942
mtklein748ca3b2015-01-15 10:56:12 -0800943 if (bitmap) {
mtkleina5114d72015-08-24 13:27:01 -0700944 if (!dump_png(*bitmap, path.c_str(), result.md5.c_str())) {
mtklein748ca3b2015-01-15 10:56:12 -0800945 fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str()));
946 return;
947 }
948 } else {
mtkleina5114d72015-08-24 13:27:01 -0700949 SkFILEWStream file(path.c_str());
950 if (!file.isValid()) {
951 fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str()));
952 return;
953 }
mtklein748ca3b2015-01-15 10:56:12 -0800954 if (!file.writeStream(data, len)) {
955 fail(SkStringPrintf("Can't write to %s.\n", path.c_str()));
956 return;
957 }
958 }
959 }
960};
961
962// Run all tasks in the same enclave serially on the same thread.
963// They can't possibly run concurrently with each other.
964static void run_enclave(SkTArray<Task>* tasks) {
965 for (int i = 0; i < tasks->count(); i++) {
966 Task::Run(tasks->begin() + i);
967 }
968}
969
970/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
971
972// Unit tests don't fit so well into the Src/Sink model, so we give them special treatment.
973
mtklein55e88b22015-01-21 15:50:13 -0800974static SkTDArray<skiatest::Test> gThreadedTests, gGPUTests;
mtklein748ca3b2015-01-15 10:56:12 -0800975
976static void gather_tests() {
mtklein6c5fed22015-01-20 13:47:23 -0800977 if (!FLAGS_src.contains("tests")) {
mtklein748ca3b2015-01-15 10:56:12 -0800978 return;
979 }
mtklein6393c062015-04-27 08:45:01 -0700980 for (const skiatest::TestRegistry* r = skiatest::TestRegistry::Head(); r; r = r->next()) {
981 if (!in_shard()) {
982 continue;
983 }
halcanary87f3ba42015-01-20 09:30:20 -0800984 // Despite its name, factory() is returning a reference to
985 // link-time static const POD data.
986 const skiatest::Test& test = r->factory();
987 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, test.name)) {
mtklein748ca3b2015-01-15 10:56:12 -0800988 continue;
989 }
halcanary87f3ba42015-01-20 09:30:20 -0800990 if (test.needsGpu && gpu_supported()) {
mtklein55e88b22015-01-21 15:50:13 -0800991 (FLAGS_gpu_threading ? gThreadedTests : gGPUTests).push(test);
halcanary87f3ba42015-01-20 09:30:20 -0800992 } else if (!test.needsGpu && FLAGS_cpu) {
mtklein55e88b22015-01-21 15:50:13 -0800993 gThreadedTests.push(test);
mtklein82d28432015-01-15 12:46:02 -0800994 }
mtklein748ca3b2015-01-15 10:56:12 -0800995 }
996}
997
halcanary87f3ba42015-01-20 09:30:20 -0800998static void run_test(skiatest::Test* test) {
999 struct : public skiatest::Reporter {
mtklein36352bf2015-03-25 18:17:31 -07001000 void reportFailed(const skiatest::Failure& failure) override {
halcanary87f3ba42015-01-20 09:30:20 -08001001 fail(failure.toString());
1002 JsonWriter::AddTestFailure(failure);
1003 }
mtklein36352bf2015-03-25 18:17:31 -07001004 bool allowExtendedTest() const override {
halcanary87f3ba42015-01-20 09:30:20 -08001005 return FLAGS_pathOpsExtended;
1006 }
mtklein36352bf2015-03-25 18:17:31 -07001007 bool verbose() const override { return FLAGS_veryVerbose; }
halcanary87f3ba42015-01-20 09:30:20 -08001008 } reporter;
djsollen824996a2015-06-12 12:06:22 -07001009
1010 SkString note;
1011 SkString whyBlacklisted = is_blacklisted("_", "tests", "_", test->name);
1012 if (!whyBlacklisted.isEmpty()) {
1013 note.appendf(" (--blacklist %s)", whyBlacklisted.c_str());
1014 }
1015
mtkleinf27f08b2015-11-03 06:54:24 -08001016 auto timerStart = now_ms();
djsollen824996a2015-06-12 12:06:22 -07001017 if (!FLAGS_dryRun && whyBlacklisted.isEmpty()) {
djsollen54416de2015-04-03 07:24:48 -07001018 start("unit", "test", "", test->name);
mtklein55e88b22015-01-21 15:50:13 -08001019 GrContextFactory factory;
bsalomon821e10e2015-06-04 14:15:33 -07001020 if (FLAGS_pre_log) {
1021 SkDebugf("\nRunning test %s", test->name);
1022 }
mtklein55e88b22015-01-21 15:50:13 -08001023 test->proc(&reporter, &factory);
mtklein748ca3b2015-01-15 10:56:12 -08001024 }
mtkleinf27f08b2015-11-03 06:54:24 -08001025 done(now_ms()-timerStart, "unit", "test", "", test->name, note, "");
mtklein748ca3b2015-01-15 10:56:12 -08001026}
1027
1028/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1029
mtklein55e88b22015-01-21 15:50:13 -08001030// If we're isolating all GPU-bound work to one thread (the default), this function runs all that.
1031static void run_enclave_and_gpu_tests(SkTArray<Task>* tasks) {
1032 run_enclave(tasks);
1033 for (int i = 0; i < gGPUTests.count(); i++) {
1034 run_test(&gGPUTests[i]);
1035 }
1036}
1037
mtkleinde6fc2b2015-03-12 06:28:54 -07001038// Some runs (mostly, Valgrind) are so slow that the bot framework thinks we've hung.
1039// This prints something every once in a while so that it knows we're still working.
mtklein2e1c47e2015-03-12 07:16:56 -07001040static void start_keepalive() {
1041 struct Loop {
1042 static void forever(void*) {
1043 for (;;) {
1044 static const int kSec = 300;
1045 #if defined(SK_BUILD_FOR_WIN)
1046 Sleep(kSec * 1000);
1047 #else
1048 sleep(kSec);
1049 #endif
mtkleinb37cb412015-03-18 05:27:14 -07001050 SkString running;
1051 {
mtkleinbc4e0032015-12-09 08:37:35 -08001052 SkAutoMutexAcquire lock(gRunningAndTallyMutex);
mtkleinb37cb412015-03-18 05:27:14 -07001053 for (int i = 0; i < gRunning.count(); i++) {
1054 running.appendf("\n\t%s", gRunning[i].c_str());
1055 }
1056 }
1057 SkDebugf("\nCurrently running:%s\n", running.c_str());
mtklein2e1c47e2015-03-12 07:16:56 -07001058 }
1059 }
1060 };
1061 static SkThread* intentionallyLeaked = new SkThread(Loop::forever);
1062 intentionallyLeaked->start();
mtkleinde6fc2b2015-03-12 06:28:54 -07001063}
1064
caryclark83ca6282015-06-10 09:31:09 -07001065#define PORTABLE_FONT_PREFIX "Toy Liberation "
1066
1067static SkTypeface* create_from_name(const char familyName[], SkTypeface::Style style) {
1068 if (familyName && strlen(familyName) > sizeof(PORTABLE_FONT_PREFIX)
1069 && !strncmp(familyName, PORTABLE_FONT_PREFIX, sizeof(PORTABLE_FONT_PREFIX) - 1)) {
caryclark1818acb2015-07-24 12:09:25 -07001070 return sk_tool_utils::create_portable_typeface(familyName, style);
caryclark83ca6282015-06-10 09:31:09 -07001071 }
halcanary96fcdcc2015-08-27 07:41:13 -07001072 return nullptr;
caryclark83ca6282015-06-10 09:31:09 -07001073}
1074
1075#undef PORTABLE_FONT_PREFIX
1076
1077extern SkTypeface* (*gCreateTypefaceDelegate)(const char [], SkTypeface::Style );
1078
jcgregorio3b27ade2014-11-13 08:06:40 -08001079int dm_main();
caryclark17f0b6d2014-07-22 10:15:34 -07001080int dm_main() {
jcgregorio3b27ade2014-11-13 08:06:40 -08001081 SetupCrashHandler();
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +00001082 SkAutoGraphics ag;
mtklein406654b2014-09-03 15:34:37 -07001083 SkTaskGroup::Enabler enabled(FLAGS_threads);
caryclark83ca6282015-06-10 09:31:09 -07001084 gCreateTypefaceDelegate = &create_from_name;
commit-bot@chromium.orga65e2fd2014-05-30 17:23:31 +00001085
mtklein2e1c47e2015-03-12 07:16:56 -07001086 start_keepalive();
mtkleinde6fc2b2015-03-12 06:28:54 -07001087
mtklein62bd1a62015-01-27 14:46:26 -08001088 gather_gold();
borenet09ed4802015-04-03 14:15:33 -07001089 gather_uninteresting_hashes();
mtklein62bd1a62015-01-27 14:46:26 -08001090
mtklein748ca3b2015-01-15 10:56:12 -08001091 gather_srcs();
1092 gather_sinks();
1093 gather_tests();
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +00001094
mtklein55e88b22015-01-21 15:50:13 -08001095 gPending = gSrcs.count() * gSinks.count() + gThreadedTests.count() + gGPUTests.count();
mtklein748ca3b2015-01-15 10:56:12 -08001096 SkDebugf("%d srcs * %d sinks + %d tests == %d tasks\n",
mtklein55e88b22015-01-21 15:50:13 -08001097 gSrcs.count(), gSinks.count(), gThreadedTests.count() + gGPUTests.count(), gPending);
mtklein748ca3b2015-01-15 10:56:12 -08001098
1099 // We try to exploit as much parallelism as is safe. Most Src/Sink pairs run on any thread,
1100 // but Sinks that identify as part of a particular enclave run serially on a single thread.
mtklein82d28432015-01-15 12:46:02 -08001101 // CPU tests run on any thread. GPU tests depend on --gpu_threading.
mtklein748ca3b2015-01-15 10:56:12 -08001102 SkTArray<Task> enclaves[kNumEnclaves];
1103 for (int j = 0; j < gSinks.count(); j++) {
1104 SkTArray<Task>& tasks = enclaves[gSinks[j]->enclave()];
1105 for (int i = 0; i < gSrcs.count(); i++) {
1106 tasks.push_back(Task(gSrcs[i], gSinks[j]));
1107 }
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001108 }
1109
mtklein748ca3b2015-01-15 10:56:12 -08001110 SkTaskGroup tg;
mtklein279c7862016-01-04 19:13:19 -08001111 tg.batch(gThreadedTests.count(), [](int i){ run_test(&gThreadedTests[i]); });
mtklein55e88b22015-01-21 15:50:13 -08001112 for (int i = 0; i < kNumEnclaves; i++) {
herb30da5f72015-12-10 14:12:33 -08001113 SkTArray<Task>* currentEnclave = &enclaves[i];
mtklein55e88b22015-01-21 15:50:13 -08001114 switch(i) {
1115 case kAnyThread_Enclave:
mtklein279c7862016-01-04 19:13:19 -08001116 tg.batch(currentEnclave->count(),
1117 [currentEnclave](int j) { Task::Run(&(*currentEnclave)[j]); });
mtklein55e88b22015-01-21 15:50:13 -08001118 break;
1119 case kGPU_Enclave:
herb30da5f72015-12-10 14:12:33 -08001120 tg.add([currentEnclave](){ run_enclave_and_gpu_tests(currentEnclave); });
mtklein55e88b22015-01-21 15:50:13 -08001121 break;
1122 default:
herb30da5f72015-12-10 14:12:33 -08001123 tg.add([currentEnclave](){ run_enclave(currentEnclave); });
mtklein55e88b22015-01-21 15:50:13 -08001124 break;
mtklein82d28432015-01-15 12:46:02 -08001125 }
mtklein55e88b22015-01-21 15:50:13 -08001126 }
mtklein748ca3b2015-01-15 10:56:12 -08001127 tg.wait();
mtkleincd50bca2016-01-05 06:20:20 -08001128 gDefinitelyThreadSafeWork.wait();
1129
mtklein748ca3b2015-01-15 10:56:12 -08001130 // At this point we're back in single-threaded land.
caryclarkf53ce802015-06-15 06:48:30 -07001131 sk_tool_utils::release_portable_typefaces();
mtklein@google.comd36522d2013-10-16 13:02:15 +00001132
mtkleinbc4e0032015-12-09 08:37:35 -08001133 if (FLAGS_verbose && gNoteTally.count() > 0) {
1134 SkDebugf("\nNote tally:\n");
1135 gNoteTally.foreach([](const SkString& note, int* tally) {
1136 SkDebugf("%dx\t%s\n", *tally, note.c_str());
1137 });
1138 }
1139
mtklein2f64eec2015-01-15 14:20:41 -08001140 SkDebugf("\n");
mtklein748ca3b2015-01-15 10:56:12 -08001141 if (gFailures.count() > 0) {
1142 SkDebugf("Failures:\n");
1143 for (int i = 0; i < gFailures.count(); i++) {
mtklein9dc09102015-01-15 15:47:33 -08001144 SkDebugf("\t%s\n", gFailures[i].c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001145 }
1146 SkDebugf("%d failures\n", gFailures.count());
1147 return 1;
mtklein114c3cd2015-01-15 10:15:02 -08001148 }
mtklein748ca3b2015-01-15 10:56:12 -08001149 if (gPending > 0) {
1150 SkDebugf("Hrm, we didn't seem to run everything we intended to! Please file a bug.\n");
1151 return 1;
mtklein114c3cd2015-01-15 10:15:02 -08001152 }
halcanary7a14b312015-10-01 07:28:13 -07001153 #ifdef SK_PDF_IMAGE_STATS
1154 SkPDFImageDumpStats();
1155 #endif // SK_PDF_IMAGE_STATS
mtklein748ca3b2015-01-15 10:56:12 -08001156 return 0;
mtklein@google.comd36522d2013-10-16 13:02:15 +00001157}
jcgregorio3b27ade2014-11-13 08:06:40 -08001158
kkinnunen179a8f52015-11-20 13:32:24 -08001159// TODO: currently many GPU tests are declared outside SK_SUPPORT_GPU guards.
1160// Thus we export the empty RunWithGPUTestContexts when SK_SUPPORT_GPU=0.
1161namespace skiatest {
1162namespace {
1163typedef void(*TestWithGrContext)(skiatest::Reporter*, GrContext*);
1164typedef void(*TestWithGrContextAndGLContext)(skiatest::Reporter*, GrContext*, SkGLContext*);
1165#if SK_SUPPORT_GPU
1166template<typename T>
kkinnunen34058002016-01-06 23:49:30 -08001167void call_test(T test, skiatest::Reporter* reporter, const GrContextFactory::ContextInfo& context);
kkinnunen179a8f52015-11-20 13:32:24 -08001168template<>
1169void call_test(TestWithGrContext test, skiatest::Reporter* reporter,
kkinnunen34058002016-01-06 23:49:30 -08001170 const GrContextFactory::ContextInfo& context) {
1171 test(reporter, context.fGrContext);
kkinnunen179a8f52015-11-20 13:32:24 -08001172}
1173template<>
1174void call_test(TestWithGrContextAndGLContext test, skiatest::Reporter* reporter,
kkinnunen34058002016-01-06 23:49:30 -08001175 const GrContextFactory::ContextInfo& context) {
1176 test(reporter, context.fGrContext, context.fGLContext);
kkinnunen179a8f52015-11-20 13:32:24 -08001177}
1178#endif
1179} // namespace
1180
kkinnunen179a8f52015-11-20 13:32:24 -08001181template<typename T>
1182void RunWithGPUTestContexts(T test, GPUTestContexts testContexts, Reporter* reporter,
1183 GrContextFactory* factory) {
1184#if SK_SUPPORT_GPU
kkinnunen3e980c32015-12-23 01:33:00 -08001185 // Iterate over context types, except use "native" instead of explicitly trying OpenGL and
1186 // OpenGL ES. Do not use GLES on desktop, since tests do not account for not fixing
1187 // http://skbug.com/2809
1188 GrContextFactory::GLContextType contextTypes[] = {
1189 GrContextFactory::kNative_GLContextType,
1190#if SK_ANGLE
1191#ifdef SK_BUILD_FOR_WIN
1192 GrContextFactory::kANGLE_GLContextType,
1193#endif
1194 GrContextFactory::kANGLE_GL_GLContextType,
1195#endif
1196#if SK_COMMAND_BUFFER
1197 GrContextFactory::kCommandBuffer_GLContextType,
1198#endif
1199#if SK_MESA
1200 GrContextFactory::kMESA_GLContextType,
1201#endif
1202 GrContextFactory::kNull_GLContextType,
1203 GrContextFactory::kDebug_GLContextType,
1204 };
1205 static_assert(SK_ARRAY_COUNT(contextTypes) == GrContextFactory::kGLContextTypeCnt - 2,
1206 "Skipping unexpected GLContextType for GPU tests");
1207
1208 for (auto& contextType : contextTypes) {
kkinnunen179a8f52015-11-20 13:32:24 -08001209 int contextSelector = kNone_GPUTestContexts;
kkinnunen3e980c32015-12-23 01:33:00 -08001210 if (GrContextFactory::IsRenderingGLContext(contextType)) {
kkinnunen179a8f52015-11-20 13:32:24 -08001211 contextSelector |= kAllRendering_GPUTestContexts;
kkinnunen3e980c32015-12-23 01:33:00 -08001212 } else if (contextType == GrContextFactory::kNative_GLContextType) {
kkinnunen179a8f52015-11-20 13:32:24 -08001213 contextSelector |= kNative_GPUTestContexts;
kkinnunen3e980c32015-12-23 01:33:00 -08001214 } else if (contextType == GrContextFactory::kNull_GLContextType) {
kkinnunen179a8f52015-11-20 13:32:24 -08001215 contextSelector |= kNull_GPUTestContexts;
kkinnunen3e980c32015-12-23 01:33:00 -08001216 } else if (contextType == GrContextFactory::kDebug_GLContextType) {
kkinnunen55eeae92015-12-10 23:19:29 -08001217 contextSelector |= kDebug_GPUTestContexts;
kkinnunen179a8f52015-11-20 13:32:24 -08001218 }
1219 if ((testContexts & contextSelector) == 0) {
1220 continue;
1221 }
kkinnunen34058002016-01-06 23:49:30 -08001222 GrContextFactory::ContextInfo context = factory->getContextInfo(contextType);
1223 if (context.fGrContext) {
kkinnunen5219fd92015-12-10 06:28:13 -08001224 call_test(test, reporter, context);
1225 }
kkinnunen34058002016-01-06 23:49:30 -08001226 context = factory->getContextInfo(contextType,
1227 GrContextFactory::kEnableNVPR_GLContextOptions);
1228 if (context.fGrContext) {
kkinnunen179a8f52015-11-20 13:32:24 -08001229 call_test(test, reporter, context);
1230 }
1231 }
1232#endif
1233}
1234
1235template
1236void RunWithGPUTestContexts<TestWithGrContext>(TestWithGrContext test,
1237 GPUTestContexts testContexts,
1238 Reporter* reporter,
1239 GrContextFactory* factory);
1240template
1241void RunWithGPUTestContexts<TestWithGrContextAndGLContext>(TestWithGrContextAndGLContext test,
1242 GPUTestContexts testContexts,
1243 Reporter* reporter,
1244 GrContextFactory* factory);
1245} // namespace skiatest
1246
borenet48087572015-04-02 12:16:36 -07001247#if !defined(SK_BUILD_FOR_IOS)
jcgregorio3b27ade2014-11-13 08:06:40 -08001248int main(int argc, char** argv) {
1249 SkCommandLineFlags::Parse(argc, argv);
1250 return dm_main();
1251}
1252#endif