blob: e5a6e4d196d2cc5c990f551b01f7fc6dcc742939 [file] [log] [blame]
scroggo478652e2015-03-25 07:11:02 -07001/*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
jcgregorio3b27ade2014-11-13 08:06:40 -08008#include "CrashHandler.h"
mtklein748ca3b2015-01-15 10:56:12 -08009#include "DMJsonWriter.h"
10#include "DMSrcSink.h"
tomhudsoneebc39a2015-02-23 12:18:05 -080011#include "DMSrcSinkAndroid.h"
mtklein748ca3b2015-01-15 10:56:12 -080012#include "OverwriteLine.h"
13#include "ProcStats.h"
14#include "SkBBHFactory.h"
mtklein62bd1a62015-01-27 14:46:26 -080015#include "SkChecksum.h"
scroggocc2feb12015-08-14 08:32:46 -070016#include "SkCodec.h"
caryclark17f0b6d2014-07-22 10:15:34 -070017#include "SkCommonFlags.h"
kkinnunen3e980c32015-12-23 01:33:00 -080018#include "SkCommonFlagsConfig.h"
caryclark83ca6282015-06-10 09:31:09 -070019#include "SkFontMgr.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000020#include "SkForceLinking.h"
21#include "SkGraphics.h"
mtklein748ca3b2015-01-15 10:56:12 -080022#include "SkMD5.h"
mtklein1b249332015-07-07 12:21:21 -070023#include "SkMutex.h"
mtklein1d0f1642014-09-08 08:05:18 -070024#include "SkOSFile.h"
mtkleina82f5622015-02-20 12:30:19 -080025#include "SkTHash.h"
mtklein406654b2014-09-03 15:34:37 -070026#include "SkTaskGroup.h"
mtkleinde6fc2b2015-03-12 06:28:54 -070027#include "SkThreadUtils.h"
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000028#include "Test.h"
mtklein748ca3b2015-01-15 10:56:12 -080029#include "Timer.h"
caryclark83ca6282015-06-10 09:31:09 -070030#include "sk_tool_utils.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000031
halcanary7a14b312015-10-01 07:28:13 -070032#ifdef SK_PDF_IMAGE_STATS
33extern void SkPDFImageDumpStats();
34#endif
35
mtkleina5114d72015-08-24 13:27:01 -070036#include "png.h"
37
bungeman60e0fee2015-08-26 05:15:46 -070038#include <stdlib.h>
39
scroggo27a58342015-10-28 08:56:41 -070040#ifndef SK_BUILD_FOR_WIN32
41 #include <unistd.h>
42#endif
43
djsollen54416de2015-04-03 07:24:48 -070044DEFINE_string(src, "tests gm skp image", "Source types to test.");
mtklein748ca3b2015-01-15 10:56:12 -080045DEFINE_bool(nameByHash, false,
46 "If true, write to FLAGS_writePath[0]/<hash>.png instead of "
djsollen54416de2015-04-03 07:24:48 -070047 "to FLAGS_writePath[0]/<config>/<sourceType>/<sourceOptions>/<name>.png");
mtklein748ca3b2015-01-15 10:56:12 -080048DEFINE_bool2(pathOpsExtended, x, false, "Run extended pathOps tests.");
mtkleind603b222015-02-17 11:13:33 -080049DEFINE_string(matrix, "1 0 0 1",
50 "2x2 scale+skew matrix to apply or upright when using "
51 "'matrix' or 'upright' in config.");
mtklein82d28432015-01-15 12:46:02 -080052DEFINE_bool(gpu_threading, false, "Allow GPU work to run on multiple threads?");
mtklein@google.comd36522d2013-10-16 13:02:15 +000053
mtkleina2ef6422015-01-15 13:44:22 -080054DEFINE_string(blacklist, "",
djsollen54416de2015-04-03 07:24:48 -070055 "Space-separated config/src/srcOptions/name quadruples to blacklist. '_' matches anything. E.g. \n"
56 "'--blacklist gpu skp _ _' will blacklist all SKPs drawn into the gpu config.\n"
57 "'--blacklist gpu skp _ _ 8888 gm _ aarects' will also blacklist the aarects GM on 8888.");
mtkleina2ef6422015-01-15 13:44:22 -080058
mtklein62bd1a62015-01-27 14:46:26 -080059DEFINE_string2(readPath, r, "", "If set check for equality with golden results in this directory.");
60
borenet09ed4802015-04-03 14:15:33 -070061DEFINE_string(uninterestingHashesFile, "",
62 "File containing a list of uninteresting hashes. If a result hashes to something in "
63 "this list, no image is written for that result.");
64
mtklein6393c062015-04-27 08:45:01 -070065DEFINE_int32(shards, 1, "We're splitting source data into this many shards.");
66DEFINE_int32(shard, 0, "Which shard do I run?");
67
mtklein@google.comd36522d2013-10-16 13:02:15 +000068__SK_FORCE_IMAGE_DECODER_LINKING;
mtklein748ca3b2015-01-15 10:56:12 -080069using namespace DM;
mtklein@google.comd36522d2013-10-16 13:02:15 +000070
mtklein748ca3b2015-01-15 10:56:12 -080071/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
72
mtkleinf27f08b2015-11-03 06:54:24 -080073static double now_ms() { return SkTime::GetNSecs() * 1e-6; }
74
mtklein748ca3b2015-01-15 10:56:12 -080075SK_DECLARE_STATIC_MUTEX(gFailuresMutex);
76static SkTArray<SkString> gFailures;
77
78static void fail(ImplicitString err) {
79 SkAutoMutexAcquire lock(gFailuresMutex);
80 SkDebugf("\n\nFAILURE: %s\n\n", err.c_str());
81 gFailures.push_back(err);
halcanary9e398f72015-01-10 11:18:04 -080082}
83
mtkleinb37cb412015-03-18 05:27:14 -070084static int32_t gPending = 0; // Atomic. Total number of running and queued tasks.
85
mtkleinbc4e0032015-12-09 08:37:35 -080086SK_DECLARE_STATIC_MUTEX(gRunningAndTallyMutex);
87static SkTArray<SkString> gRunning;
88static SkTHashMap<SkString, int> gNoteTally;
mtklein748ca3b2015-01-15 10:56:12 -080089
mtkleinb9eb4ac2015-02-02 18:26:03 -080090static void done(double ms,
djsollen54416de2015-04-03 07:24:48 -070091 ImplicitString config, ImplicitString src, ImplicitString srcOptions,
92 ImplicitString name, ImplicitString note, ImplicitString log) {
93 SkString id = SkStringPrintf("%s %s %s %s", config.c_str(), src.c_str(),
94 srcOptions.c_str(), name.c_str());
mtkleinb37cb412015-03-18 05:27:14 -070095 {
mtkleinbc4e0032015-12-09 08:37:35 -080096 SkAutoMutexAcquire lock(gRunningAndTallyMutex);
mtkleinb37cb412015-03-18 05:27:14 -070097 for (int i = 0; i < gRunning.count(); i++) {
98 if (gRunning[i] == id) {
99 gRunning.removeShuffle(i);
100 break;
101 }
102 }
mtkleinbc4e0032015-12-09 08:37:35 -0800103 if (!note.isEmpty()) {
104 if (int* tally = gNoteTally.find(note)) {
105 *tally += 1;
106 } else {
107 gNoteTally.set(note, 1);
108 }
109 }
mtkleinb37cb412015-03-18 05:27:14 -0700110 }
mtkleinb9eb4ac2015-02-02 18:26:03 -0800111 if (!log.isEmpty()) {
112 log.prepend("\n");
113 }
mtklein6dee2ad2015-02-05 09:53:44 -0800114 auto pending = sk_atomic_dec(&gPending)-1;
mtkleinbc4e0032015-12-09 08:37:35 -0800115 if (!FLAGS_quiet && note.isEmpty()) {
116 SkDebugf("%s(%4d/%-4dMB %6d) %s\t%s%s", FLAGS_verbose ? "\n" : kSkOverwriteLine
reed50bc0512015-05-19 14:13:31 -0700117 , sk_tools::getCurrResidentSetSizeMB()
118 , sk_tools::getMaxResidentSetSizeMB()
119 , pending
120 , HumanizeMs(ms).c_str()
121 , id.c_str()
reed50bc0512015-05-19 14:13:31 -0700122 , log.c_str());
123 }
mtkleina17241b2015-01-23 05:48:00 -0800124 // We write our dm.json file every once in a while in case we crash.
125 // Notice this also handles the final dm.json when pending == 0.
126 if (pending % 500 == 0) {
127 JsonWriter::DumpJson();
128 }
mtklein@google.comd36522d2013-10-16 13:02:15 +0000129}
130
djsollen54416de2015-04-03 07:24:48 -0700131static void start(ImplicitString config, ImplicitString src,
132 ImplicitString srcOptions, ImplicitString name) {
133 SkString id = SkStringPrintf("%s %s %s %s", config.c_str(), src.c_str(),
134 srcOptions.c_str(), name.c_str());
mtkleinbc4e0032015-12-09 08:37:35 -0800135 SkAutoMutexAcquire lock(gRunningAndTallyMutex);
mtkleinb37cb412015-03-18 05:27:14 -0700136 gRunning.push_back(id);
137}
138
mtklein748ca3b2015-01-15 10:56:12 -0800139/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
mtklein114c3cd2015-01-15 10:15:02 -0800140
mtklein62bd1a62015-01-27 14:46:26 -0800141struct Gold : public SkString {
mtkleina82f5622015-02-20 12:30:19 -0800142 Gold() : SkString("") {}
djsollen54416de2015-04-03 07:24:48 -0700143 Gold(ImplicitString sink, ImplicitString src, ImplicitString srcOptions,
144 ImplicitString name, ImplicitString md5)
mtklein62bd1a62015-01-27 14:46:26 -0800145 : SkString("") {
146 this->append(sink);
147 this->append(src);
djsollen54416de2015-04-03 07:24:48 -0700148 this->append(srcOptions);
mtklein62bd1a62015-01-27 14:46:26 -0800149 this->append(name);
150 this->append(md5);
mtklein62bd1a62015-01-27 14:46:26 -0800151 }
mtkleinc8d1dd42015-10-15 12:23:01 -0700152 struct Hash {
153 uint32_t operator()(const Gold& g) const {
154 return SkGoodHash()((const SkString&)g);
155 }
156 };
mtklein62bd1a62015-01-27 14:46:26 -0800157};
mtkleina82f5622015-02-20 12:30:19 -0800158static SkTHashSet<Gold, Gold::Hash> gGold;
mtklein62bd1a62015-01-27 14:46:26 -0800159
160static void add_gold(JsonWriter::BitmapResult r) {
djsollen54416de2015-04-03 07:24:48 -0700161 gGold.add(Gold(r.config, r.sourceType, r.sourceOptions, r.name, r.md5));
mtklein62bd1a62015-01-27 14:46:26 -0800162}
163
164static void gather_gold() {
165 if (!FLAGS_readPath.isEmpty()) {
166 SkString path(FLAGS_readPath[0]);
167 path.append("/dm.json");
168 if (!JsonWriter::ReadJson(path.c_str(), add_gold)) {
169 fail(SkStringPrintf("Couldn't read %s for golden results.", path.c_str()));
170 }
171 }
172}
173
174/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
175
borenet09ed4802015-04-03 14:15:33 -0700176static SkTHashSet<SkString> gUninterestingHashes;
177
178static void gather_uninteresting_hashes() {
179 if (!FLAGS_uninterestingHashesFile.isEmpty()) {
180 SkAutoTUnref<SkData> data(SkData::NewFromFileName(FLAGS_uninterestingHashesFile[0]));
mtkleincc334b32015-09-22 11:43:53 -0700181 if (!data) {
182 SkDebugf("WARNING: unable to read uninteresting hashes from %s\n",
183 FLAGS_uninterestingHashesFile[0]);
184 return;
185 }
borenet09ed4802015-04-03 14:15:33 -0700186 SkTArray<SkString> hashes;
187 SkStrSplit((const char*)data->data(), "\n", &hashes);
188 for (const SkString& hash : hashes) {
189 gUninterestingHashes.add(hash);
190 }
191 }
192}
193
194/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
195
mtkleine0effd62015-07-29 06:37:28 -0700196struct TaggedSrc : public SkAutoTDelete<Src> {
msarett9e707a02015-09-01 14:57:57 -0700197 ImplicitString tag;
198 ImplicitString options;
mtkleine0effd62015-07-29 06:37:28 -0700199};
200
201struct TaggedSink : public SkAutoTDelete<Sink> {
kkinnunen3e980c32015-12-23 01:33:00 -0800202 SkString tag;
djsollen54416de2015-04-03 07:24:48 -0700203};
mtklein748ca3b2015-01-15 10:56:12 -0800204
205static const bool kMemcpyOK = true;
206
mtkleine0effd62015-07-29 06:37:28 -0700207static SkTArray<TaggedSrc, kMemcpyOK> gSrcs;
208static SkTArray<TaggedSink, kMemcpyOK> gSinks;
mtklein748ca3b2015-01-15 10:56:12 -0800209
mtklein6393c062015-04-27 08:45:01 -0700210static bool in_shard() {
211 static int N = 0;
212 return N++ % FLAGS_shards == FLAGS_shard;
213}
214
msarett9e707a02015-09-01 14:57:57 -0700215static void push_src(ImplicitString tag, ImplicitString options, Src* s) {
mtklein748ca3b2015-01-15 10:56:12 -0800216 SkAutoTDelete<Src> src(s);
mtklein6393c062015-04-27 08:45:01 -0700217 if (in_shard() &&
msarett9e707a02015-09-01 14:57:57 -0700218 FLAGS_src.contains(tag.c_str()) &&
mtklein748ca3b2015-01-15 10:56:12 -0800219 !SkCommandLineFlags::ShouldSkip(FLAGS_match, src->name().c_str())) {
mtkleine0effd62015-07-29 06:37:28 -0700220 TaggedSrc& s = gSrcs.push_back();
mtklein748ca3b2015-01-15 10:56:12 -0800221 s.reset(src.detach());
222 s.tag = tag;
djsollen54416de2015-04-03 07:24:48 -0700223 s.options = options;
mtklein114c3cd2015-01-15 10:15:02 -0800224 }
mtklein748ca3b2015-01-15 10:56:12 -0800225}
mtklein114c3cd2015-01-15 10:15:02 -0800226
msarett9e707a02015-09-01 14:57:57 -0700227static void push_codec_src(Path path, CodecSrc::Mode mode, CodecSrc::DstColorType dstColorType,
scroggoc5560be2016-02-03 09:42:42 -0800228 SkAlphaType dstAlphaType, float scale) {
msarett9e707a02015-09-01 14:57:57 -0700229 SkString folder;
230 switch (mode) {
231 case CodecSrc::kCodec_Mode:
232 folder.append("codec");
233 break;
msarettbb25b532016-01-13 09:31:39 -0800234 case CodecSrc::kCodecZeroInit_Mode:
235 folder.append("codec_zero_init");
236 break;
msarett9e707a02015-09-01 14:57:57 -0700237 case CodecSrc::kScanline_Mode:
238 folder.append("scanline");
239 break;
msarett9e707a02015-09-01 14:57:57 -0700240 case CodecSrc::kStripe_Mode:
241 folder.append("stripe");
242 break;
243 case CodecSrc::kSubset_Mode:
msarett36c37962015-09-02 13:20:52 -0700244 folder.append("codec_subset");
msarett9e707a02015-09-01 14:57:57 -0700245 break;
msarettb714fb02016-01-22 14:46:42 -0800246 case CodecSrc::kGen_Mode:
247 folder.append("gen");
248 break;
msarett9e707a02015-09-01 14:57:57 -0700249 }
250
251 switch (dstColorType) {
252 case CodecSrc::kGrayscale_Always_DstColorType:
253 folder.append("_kGray8");
254 break;
255 case CodecSrc::kIndex8_Always_DstColorType:
256 folder.append("_kIndex8");
257 break;
258 default:
259 break;
260 }
261
scroggoc5560be2016-02-03 09:42:42 -0800262 switch (dstAlphaType) {
263 case kOpaque_SkAlphaType:
264 folder.append("_opaque");
265 break;
266 case kPremul_SkAlphaType:
267 folder.append("_premul");
268 break;
269 case kUnpremul_SkAlphaType:
270 folder.append("_unpremul");
271 break;
272 default:
273 break;
274 }
275
msarett9e707a02015-09-01 14:57:57 -0700276 if (1.0f != scale) {
277 folder.appendf("_%.3f", scale);
278 }
279
scroggoc5560be2016-02-03 09:42:42 -0800280 CodecSrc* src = new CodecSrc(path, mode, dstColorType, dstAlphaType, scale);
msarett9e707a02015-09-01 14:57:57 -0700281 push_src("image", folder, src);
282}
283
msarett3d9d7a72015-10-21 10:27:10 -0700284static void push_android_codec_src(Path path, AndroidCodecSrc::Mode mode,
scroggoc5560be2016-02-03 09:42:42 -0800285 CodecSrc::DstColorType dstColorType, SkAlphaType dstAlphaType, int sampleSize) {
msarett3d9d7a72015-10-21 10:27:10 -0700286 SkString folder;
287 switch (mode) {
288 case AndroidCodecSrc::kFullImage_Mode:
289 folder.append("scaled_codec");
290 break;
291 case AndroidCodecSrc::kDivisor_Mode:
292 folder.append("scaled_codec_divisor");
293 break;
294 }
295
296 switch (dstColorType) {
297 case CodecSrc::kGrayscale_Always_DstColorType:
298 folder.append("_kGray8");
299 break;
300 case CodecSrc::kIndex8_Always_DstColorType:
301 folder.append("_kIndex8");
302 break;
303 default:
304 break;
305 }
306
scroggoc5560be2016-02-03 09:42:42 -0800307 switch (dstAlphaType) {
308 case kOpaque_SkAlphaType:
309 folder.append("_opaque");
310 break;
311 case kPremul_SkAlphaType:
312 folder.append("_premul");
313 break;
314 default:
315 break;
316 }
317
msarett3d9d7a72015-10-21 10:27:10 -0700318 if (1 != sampleSize) {
msarett4b0778e2015-11-13 09:59:11 -0800319 folder.appendf("_%.3f", 1.0f / (float) sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700320 }
321
scroggoc5560be2016-02-03 09:42:42 -0800322 AndroidCodecSrc* src = new AndroidCodecSrc(path, mode, dstColorType, dstAlphaType, sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700323 push_src("image", folder, src);
324}
325
msarett438b2ad2015-04-09 12:43:10 -0700326static void push_codec_srcs(Path path) {
327 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str()));
328 if (!encoded) {
329 SkDebugf("Couldn't read %s.", path.c_str());
330 return;
331 }
332 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
halcanary96fcdcc2015-08-27 07:41:13 -0700333 if (nullptr == codec.get()) {
msarett438b2ad2015-04-09 12:43:10 -0700334 SkDebugf("Couldn't create codec for %s.", path.c_str());
335 return;
336 }
337
msarett36c37962015-09-02 13:20:52 -0700338 // Native Scales
msarett0a242972015-06-11 14:27:27 -0700339 // TODO (msarett): Implement scaling tests for SkImageDecoder in order to compare with these
340 // tests. SkImageDecoder supports downscales by integer factors.
emmaleer8f4ba762015-08-14 07:44:46 -0700341 // 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 -0700342 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 -0700343
msarettbb25b532016-01-13 09:31:39 -0800344 const CodecSrc::Mode nativeModes[] = { CodecSrc::kCodec_Mode, CodecSrc::kCodecZeroInit_Mode,
msarettb714fb02016-01-22 14:46:42 -0800345 CodecSrc::kScanline_Mode, CodecSrc::kStripe_Mode, CodecSrc::kSubset_Mode,
346 CodecSrc::kGen_Mode };
msarett9e707a02015-09-01 14:57:57 -0700347
msarett36c37962015-09-02 13:20:52 -0700348 CodecSrc::DstColorType colorTypes[3];
349 uint32_t numColorTypes;
350 switch (codec->getInfo().colorType()) {
351 case kGray_8_SkColorType:
352 // FIXME: Is this a long term solution for testing wbmps decodes to kIndex8?
halcanary6950de62015-11-07 05:29:00 -0800353 // Further discussion on this topic is at https://bug.skia.org/3683 .
msarett3d9d7a72015-10-21 10:27:10 -0700354 // This causes us to try to convert grayscale jpegs to kIndex8. We currently
355 // fail non-fatally in this case.
msarett36c37962015-09-02 13:20:52 -0700356 colorTypes[0] = CodecSrc::kGetFromCanvas_DstColorType;
357 colorTypes[1] = CodecSrc::kGrayscale_Always_DstColorType;
358 colorTypes[2] = CodecSrc::kIndex8_Always_DstColorType;
359 numColorTypes = 3;
360 break;
361 case kIndex_8_SkColorType:
362 colorTypes[0] = CodecSrc::kGetFromCanvas_DstColorType;
363 colorTypes[1] = CodecSrc::kIndex8_Always_DstColorType;
364 numColorTypes = 2;
365 break;
366 default:
367 colorTypes[0] = CodecSrc::kGetFromCanvas_DstColorType;
368 numColorTypes = 1;
369 break;
370 }
msarett9e707a02015-09-01 14:57:57 -0700371
scroggoc5560be2016-02-03 09:42:42 -0800372 SkTArray<SkAlphaType> alphaModes;
373 alphaModes.push_back(kPremul_SkAlphaType);
374 // FIXME: Currently we cannot draw unpremultiplied sources. skbug.com/3338 and skbug.com/3339
375 // alphaModes.push_back(kUnpremul_SkAlphaType);
376 if (codec->getInfo().alphaType() == kOpaque_SkAlphaType) {
377 alphaModes.push_back(kOpaque_SkAlphaType);
378 }
msarettb714fb02016-01-22 14:46:42 -0800379
380 for (CodecSrc::Mode mode : nativeModes) {
381 // SkCodecImageGenerator only runs for the default colorType
382 // recommended by SkCodec. There is no need to generate multiple
383 // tests for different colorTypes.
384 // TODO (msarett): Add scaling support to SkCodecImageGenerator.
385 if (CodecSrc::kGen_Mode == mode) {
386 // FIXME: The gpu backend does not draw kGray sources correctly. (skbug.com/4822)
387 if (kGray_8_SkColorType != codec->getInfo().colorType()) {
scroggoc5560be2016-02-03 09:42:42 -0800388 push_codec_src(path, mode, CodecSrc::kGetFromCanvas_DstColorType,
389 codec->getInfo().alphaType(), 1.0f);
msarettb714fb02016-01-22 14:46:42 -0800390 }
391 continue;
392 }
393
394 for (float scale : nativeScales) {
msarett36c37962015-09-02 13:20:52 -0700395 for (uint32_t i = 0; i < numColorTypes; i++) {
scroggoc5560be2016-02-03 09:42:42 -0800396 for (SkAlphaType alphaType : alphaModes) {
397 push_codec_src(path, mode, colorTypes[i], alphaType, scale);
398 }
msarett9e707a02015-09-01 14:57:57 -0700399 }
400 }
msarett0a242972015-06-11 14:27:27 -0700401 }
msarett36c37962015-09-02 13:20:52 -0700402
halcanary6950de62015-11-07 05:29:00 -0800403 // https://bug.skia.org/4428
msarett33c76232015-11-16 13:43:40 -0800404 bool subset = false;
405 // The following image types are supported by BitmapRegionDecoder,
406 // so we will test full image decodes and subset decodes.
msarettbe8216a2015-12-04 08:00:50 -0800407 static const char* const exts[] = {
msarett3d9d7a72015-10-21 10:27:10 -0700408 "jpg", "jpeg", "png", "webp",
409 "JPG", "JPEG", "PNG", "WEBP",
410 };
msarettbe8216a2015-12-04 08:00:50 -0800411 for (const char* ext : exts) {
msarett3d9d7a72015-10-21 10:27:10 -0700412 if (path.endsWith(ext)) {
msarett33c76232015-11-16 13:43:40 -0800413 subset = true;
msarett3d9d7a72015-10-21 10:27:10 -0700414 break;
415 }
416 }
msarett33c76232015-11-16 13:43:40 -0800417
msarett3d9d7a72015-10-21 10:27:10 -0700418 const int sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
msarett36c37962015-09-02 13:20:52 -0700419
msarett3d9d7a72015-10-21 10:27:10 -0700420 for (int sampleSize : sampleSizes) {
msarett33c76232015-11-16 13:43:40 -0800421 for (uint32_t i = 0; i < numColorTypes; i++) {
scroggoc5560be2016-02-03 09:42:42 -0800422 for (SkAlphaType alphaType : alphaModes) {
423 push_android_codec_src(path, AndroidCodecSrc::kFullImage_Mode, colorTypes[i],
424 alphaType, sampleSize);
425 if (subset) {
426 push_android_codec_src(path, AndroidCodecSrc::kDivisor_Mode, colorTypes[i],
427 alphaType, sampleSize);
428 }
msarett3d9d7a72015-10-21 10:27:10 -0700429 }
msarett36c37962015-09-02 13:20:52 -0700430 }
431 }
msarett438b2ad2015-04-09 12:43:10 -0700432}
433
msarett5cb48852015-11-06 08:56:32 -0800434static bool brd_color_type_supported(SkBitmapRegionDecoder::Strategy strategy,
msaretta5783ae2015-09-08 15:35:32 -0700435 CodecSrc::DstColorType dstColorType) {
436 switch (strategy) {
msarett5cb48852015-11-06 08:56:32 -0800437 case SkBitmapRegionDecoder::kCanvas_Strategy:
msaretta5783ae2015-09-08 15:35:32 -0700438 if (CodecSrc::kGetFromCanvas_DstColorType == dstColorType) {
439 return true;
440 }
441 return false;
msarett5cb48852015-11-06 08:56:32 -0800442 case SkBitmapRegionDecoder::kAndroidCodec_Strategy:
msarett26ad17b2015-10-22 07:29:19 -0700443 switch (dstColorType) {
444 case CodecSrc::kGetFromCanvas_DstColorType:
445 case CodecSrc::kIndex8_Always_DstColorType:
446 case CodecSrc::kGrayscale_Always_DstColorType:
447 return true;
448 default:
449 return false;
450 }
msaretta5783ae2015-09-08 15:35:32 -0700451 default:
452 SkASSERT(false);
453 return false;
454 }
455}
456
msarett5cb48852015-11-06 08:56:32 -0800457static void push_brd_src(Path path, SkBitmapRegionDecoder::Strategy strategy,
msaretta5783ae2015-09-08 15:35:32 -0700458 CodecSrc::DstColorType dstColorType, BRDSrc::Mode mode, uint32_t sampleSize) {
459 SkString folder;
460 switch (strategy) {
msarett5cb48852015-11-06 08:56:32 -0800461 case SkBitmapRegionDecoder::kCanvas_Strategy:
msaretta5783ae2015-09-08 15:35:32 -0700462 folder.append("brd_canvas");
463 break;
msarett5cb48852015-11-06 08:56:32 -0800464 case SkBitmapRegionDecoder::kAndroidCodec_Strategy:
msarett26ad17b2015-10-22 07:29:19 -0700465 folder.append("brd_android_codec");
466 break;
msaretta5783ae2015-09-08 15:35:32 -0700467 default:
468 SkASSERT(false);
469 return;
470 }
471
472 switch (mode) {
473 case BRDSrc::kFullImage_Mode:
474 break;
475 case BRDSrc::kDivisor_Mode:
476 folder.append("_divisor");
477 break;
478 default:
479 SkASSERT(false);
480 return;
481 }
482
483 switch (dstColorType) {
484 case CodecSrc::kGetFromCanvas_DstColorType:
485 break;
486 case CodecSrc::kIndex8_Always_DstColorType:
487 folder.append("_kIndex");
488 break;
489 case CodecSrc::kGrayscale_Always_DstColorType:
490 folder.append("_kGray");
491 break;
492 default:
493 SkASSERT(false);
494 return;
495 }
496
497 if (1 != sampleSize) {
msarett4b0778e2015-11-13 09:59:11 -0800498 folder.appendf("_%.3f", 1.0f / (float) sampleSize);
msaretta5783ae2015-09-08 15:35:32 -0700499 }
500
501 BRDSrc* src = new BRDSrc(path, strategy, mode, dstColorType, sampleSize);
502 push_src("image", folder, src);
503}
504
505static void push_brd_srcs(Path path) {
506
msarett5cb48852015-11-06 08:56:32 -0800507 const SkBitmapRegionDecoder::Strategy strategies[] = {
508 SkBitmapRegionDecoder::kCanvas_Strategy,
msarett5cb48852015-11-06 08:56:32 -0800509 SkBitmapRegionDecoder::kAndroidCodec_Strategy,
msaretta5783ae2015-09-08 15:35:32 -0700510 };
511
scroggo501b7342015-11-03 07:55:11 -0800512 // Test on a variety of sampleSizes, making sure to include:
513 // - 2, 4, and 8, which are natively supported by jpeg
514 // - multiples of 2 which are not divisible by 4 (analogous for 4)
515 // - larger powers of two, since BRD clients generally use powers of 2
516 // We will only produce output for the larger sizes on large images.
517 const uint32_t sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 24, 32, 64 };
msarett6efbe052015-09-11 09:01:16 -0700518
msaretta5783ae2015-09-08 15:35:32 -0700519 // We will only test to one backend (8888), but we will test all of the
520 // color types that we need to decode to on this backend.
521 const CodecSrc::DstColorType dstColorTypes[] = {
msarett26ad17b2015-10-22 07:29:19 -0700522 CodecSrc::kGetFromCanvas_DstColorType,
523 CodecSrc::kIndex8_Always_DstColorType,
524 CodecSrc::kGrayscale_Always_DstColorType,
msaretta5783ae2015-09-08 15:35:32 -0700525 };
526
527 const BRDSrc::Mode modes[] = {
msarett26ad17b2015-10-22 07:29:19 -0700528 BRDSrc::kFullImage_Mode,
529 BRDSrc::kDivisor_Mode,
msaretta5783ae2015-09-08 15:35:32 -0700530 };
531
msarett5cb48852015-11-06 08:56:32 -0800532 for (SkBitmapRegionDecoder::Strategy strategy : strategies) {
msarett6efbe052015-09-11 09:01:16 -0700533 for (uint32_t sampleSize : sampleSizes) {
msarett6efbe052015-09-11 09:01:16 -0700534 for (CodecSrc::DstColorType dstColorType : dstColorTypes) {
535 if (brd_color_type_supported(strategy, dstColorType)) {
536 for (BRDSrc::Mode mode : modes) {
msaretta5783ae2015-09-08 15:35:32 -0700537 push_brd_src(path, strategy, dstColorType, mode, sampleSize);
538 }
539 }
540 }
541 }
542 }
543}
544
545static bool brd_supported(const char* ext) {
msarett8c8f22a2015-04-01 06:58:48 -0700546 static const char* const exts[] = {
msaretta5783ae2015-09-08 15:35:32 -0700547 "jpg", "jpeg", "png", "webp",
548 "JPG", "JPEG", "PNG", "WEBP",
msarett8c8f22a2015-04-01 06:58:48 -0700549 };
550
551 for (uint32_t i = 0; i < SK_ARRAY_COUNT(exts); i++) {
552 if (0 == strcmp(exts[i], ext)) {
553 return true;
554 }
555 }
556 return false;
scroggo9b77ddd2015-03-19 06:03:39 -0700557}
558
scroggoad38ed62016-01-29 14:41:55 -0800559static void gather_srcs() {
mtklein748ca3b2015-01-15 10:56:12 -0800560 for (const skiagm::GMRegistry* r = skiagm::GMRegistry::Head(); r; r = r->next()) {
djsollen54416de2015-04-03 07:24:48 -0700561 push_src("gm", "", new GMSrc(r->factory()));
mtklein748ca3b2015-01-15 10:56:12 -0800562 }
halcanaryfc37ad12015-01-30 07:31:19 -0800563 for (int i = 0; i < FLAGS_skps.count(); i++) {
564 const char* path = FLAGS_skps[i];
565 if (sk_isdir(path)) {
566 SkOSFile::Iter it(path, "skp");
567 for (SkString file; it.next(&file); ) {
djsollen54416de2015-04-03 07:24:48 -0700568 push_src("skp", "", new SKPSrc(SkOSPath::Join(path, file.c_str())));
halcanaryfc37ad12015-01-30 07:31:19 -0800569 }
570 } else {
djsollen54416de2015-04-03 07:24:48 -0700571 push_src("skp", "", new SKPSrc(path));
mtklein114c3cd2015-01-15 10:15:02 -0800572 }
573 }
scroggoad38ed62016-01-29 14:41:55 -0800574 static const char* const exts[] = {
575 "bmp", "gif", "jpg", "jpeg", "png", "webp", "ktx", "astc", "wbmp", "ico",
576 "BMP", "GIF", "JPG", "JPEG", "PNG", "WEBP", "KTX", "ASTC", "WBMP", "ICO",
scroggo1497f9f2016-02-02 11:56:33 -0800577#ifdef SK_CODEC_DECODES_RAW
scroggoad38ed62016-01-29 14:41:55 -0800578 "arw", "cr2", "dng", "nef", "nrw", "orf", "raf", "rw2", "pef", "srw",
579 "ARW", "CR2", "DNG", "NEF", "NRW", "ORF", "RAF", "RW2", "PEF", "SRW",
scroggo1497f9f2016-02-02 11:56:33 -0800580#endif
scroggoad38ed62016-01-29 14:41:55 -0800581 };
582 for (int i = 0; i < FLAGS_images.count(); i++) {
583 const char* flag = FLAGS_images[i];
584 if (sk_isdir(flag)) {
585 for (size_t j = 0; j < SK_ARRAY_COUNT(exts); j++) {
586 SkOSFile::Iter it(flag, exts[j]);
587 for (SkString file; it.next(&file); ) {
588 SkString path = SkOSPath::Join(flag, file.c_str());
589 push_codec_srcs(path);
590 if (brd_supported(exts[j])) {
591 push_brd_srcs(path);
592 }
593 }
594 }
595 } else if (sk_exists(flag)) {
596 // assume that FLAGS_images[i] is a valid image if it is a file.
597 push_codec_srcs(flag);
598 push_brd_srcs(flag);
mtklein709d2c32015-01-15 08:30:25 -0800599 }
mtklein709d2c32015-01-15 08:30:25 -0800600 }
601}
602
kkinnunen3e980c32015-12-23 01:33:00 -0800603static void push_sink(const SkCommandLineConfig& config, Sink* s) {
rmistry0f515bd2015-12-22 10:22:26 -0800604 SkAutoTDelete<Sink> sink(s);
kkinnunen3e980c32015-12-23 01:33:00 -0800605
mtkleine0effd62015-07-29 06:37:28 -0700606 // Try a simple Src as a canary. If it fails, skip this sink.
mtklein748ca3b2015-01-15 10:56:12 -0800607 struct : public Src {
mtkleine0effd62015-07-29 06:37:28 -0700608 Error draw(SkCanvas* c) const override {
609 c->drawRect(SkRect::MakeWH(1,1), SkPaint());
610 return "";
611 }
mtklein36352bf2015-03-25 18:17:31 -0700612 SkISize size() const override { return SkISize::Make(16, 16); }
mtkleine0effd62015-07-29 06:37:28 -0700613 Name name() const override { return "justOneRect"; }
614 } justOneRect;
mtklein114c3cd2015-01-15 10:15:02 -0800615
mtklein748ca3b2015-01-15 10:56:12 -0800616 SkBitmap bitmap;
617 SkDynamicMemoryWStream stream;
mtkleinb9eb4ac2015-02-02 18:26:03 -0800618 SkString log;
mtkleine0effd62015-07-29 06:37:28 -0700619 Error err = sink->draw(justOneRect, &bitmap, &stream, &log);
mtklein4089ef72015-03-05 08:40:28 -0800620 if (err.isFatal()) {
kkinnunen3e980c32015-12-23 01:33:00 -0800621 SkDebugf("Could not run %s: %s\n", config.getTag().c_str(), err.c_str());
mtklein05641a52015-04-21 10:49:13 -0700622 exit(1);
mtklein114c3cd2015-01-15 10:15:02 -0800623 }
624
mtkleine0effd62015-07-29 06:37:28 -0700625 TaggedSink& ts = gSinks.push_back();
mtklein748ca3b2015-01-15 10:56:12 -0800626 ts.reset(sink.detach());
kkinnunen3e980c32015-12-23 01:33:00 -0800627 ts.tag = config.getTag();
mtklein748ca3b2015-01-15 10:56:12 -0800628}
629
630static bool gpu_supported() {
631#if SK_SUPPORT_GPU
632 return FLAGS_gpu;
633#else
634 return false;
635#endif
636}
kkinnunen9ebc3f02015-12-21 23:48:13 -0800637
kkinnunen3e980c32015-12-23 01:33:00 -0800638static Sink* create_sink(const SkCommandLineConfig* config) {
639#if SK_SUPPORT_GPU
640 if (gpu_supported()) {
641 if (const SkCommandLineConfigGpu* gpuConfig = config->asConfigGpu()) {
642 GrContextFactory::GLContextType contextType = gpuConfig->getContextType();
643 GrContextFactory::GLContextOptions contextOptions =
644 GrContextFactory::kNone_GLContextOptions;
645 if (gpuConfig->getUseNVPR()) {
646 contextOptions = static_cast<GrContextFactory::GLContextOptions>(
647 contextOptions | GrContextFactory::kEnableNVPR_GLContextOptions);
648 }
649 GrContextFactory testFactory;
650 if (!testFactory.get(contextType, contextOptions)) {
651 SkDebugf("WARNING: can not create GPU context for config '%s'. "
652 "GM tests will be skipped.\n", gpuConfig->getTag().c_str());
653 return nullptr;
654 }
655 return new GPUSink(contextType, contextOptions, gpuConfig->getSamples(),
656 gpuConfig->getUseDIText(), FLAGS_gpu_threading);
657 }
658 }
659#endif
660
661#define SINK(t, sink, ...) if (config->getBackend().equals(t)) { return new sink(__VA_ARGS__); }
662
tomhudsoneebc39a2015-02-23 12:18:05 -0800663#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
664 SINK("hwui", HWUISink);
665#endif
666
mtklein748ca3b2015-01-15 10:56:12 -0800667 if (FLAGS_cpu) {
668 SINK("565", RasterSink, kRGB_565_SkColorType);
669 SINK("8888", RasterSink, kN32_SkColorType);
halcanaryc11c62f2015-09-28 11:51:54 -0700670 SINK("pdf", PDFSink, "Pdfium");
671 SINK("pdf_poppler", PDFSink, "Poppler");
mtklein9c3f17d2015-01-28 11:35:18 -0800672 SINK("skp", SKPSink);
mtklein8a4527e2015-01-31 20:00:58 -0800673 SINK("svg", SVGSink);
674 SINK("null", NullSink);
halcanary47ef4d52015-03-03 09:13:09 -0800675 SINK("xps", XPSSink);
mtklein748ca3b2015-01-15 10:56:12 -0800676 }
677#undef SINK
halcanary96fcdcc2015-08-27 07:41:13 -0700678 return nullptr;
mtklein114c3cd2015-01-15 10:15:02 -0800679}
680
kkinnunen3e980c32015-12-23 01:33:00 -0800681static Sink* create_via(const SkString& tag, Sink* wrapped) {
682#define VIA(t, via, ...) if (tag.equals(t)) { return new via(__VA_ARGS__); }
halcanary96fcdcc2015-08-27 07:41:13 -0700683 VIA("twice", ViaTwice, wrapped);
halcanary96fcdcc2015-08-27 07:41:13 -0700684 VIA("serialize", ViaSerialization, wrapped);
mtklein4a34ecb2016-01-08 10:19:35 -0800685 VIA("pic", ViaPicture, wrapped);
halcanary96fcdcc2015-08-27 07:41:13 -0700686 VIA("2ndpic", ViaSecondPicture, wrapped);
mtkleind31c13d2015-05-05 12:59:56 -0700687 VIA("sp", ViaSingletonPictures, wrapped);
halcanary96fcdcc2015-08-27 07:41:13 -0700688 VIA("tiles", ViaTiles, 256, 256, nullptr, wrapped);
mtklein7edca212015-01-21 13:18:51 -0800689 VIA("tiles_rt", ViaTiles, 256, 256, new SkRTreeFactory, wrapped);
mtklein2e2ea382015-10-16 10:29:41 -0700690 VIA("remote", ViaRemote, false, wrapped);
691 VIA("remote_cache", ViaRemote, true, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800692
mtkleind603b222015-02-17 11:13:33 -0800693 if (FLAGS_matrix.count() == 4) {
mtklein748ca3b2015-01-15 10:56:12 -0800694 SkMatrix m;
mtkleind603b222015-02-17 11:13:33 -0800695 m.reset();
696 m.setScaleX((SkScalar)atof(FLAGS_matrix[0]));
697 m.setSkewX ((SkScalar)atof(FLAGS_matrix[1]));
698 m.setSkewY ((SkScalar)atof(FLAGS_matrix[2]));
699 m.setScaleY((SkScalar)atof(FLAGS_matrix[3]));
700 VIA("matrix", ViaMatrix, m, wrapped);
701 VIA("upright", ViaUpright, m, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800702 }
tomhudson64de1e12015-03-05 08:01:07 -0800703
704#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
705 VIA("androidsdk", ViaAndroidSDK, wrapped);
706#endif
707
mtklein748ca3b2015-01-15 10:56:12 -0800708#undef VIA
halcanary96fcdcc2015-08-27 07:41:13 -0700709 return nullptr;
mtklein114c3cd2015-01-15 10:15:02 -0800710}
711
mtklein748ca3b2015-01-15 10:56:12 -0800712static void gather_sinks() {
kkinnunen3e980c32015-12-23 01:33:00 -0800713 SkCommandLineConfigArray configs;
714 ParseConfigs(FLAGS_config, &configs);
715 for (int i = 0; i < configs.count(); i++) {
716 const SkCommandLineConfig& config = *configs[i];
717 Sink* sink = create_sink(&config);
718 if (sink == nullptr) {
719 SkDebugf("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(),
720 config.getTag().c_str());
721 continue;
722 }
mtklein748ca3b2015-01-15 10:56:12 -0800723
kkinnunen3e980c32015-12-23 01:33:00 -0800724 const SkTArray<SkString>& parts = config.getViaParts();
725 for (int j = parts.count(); j-- > 0;) {
726 const SkString& part = parts[j];
727 Sink* next = create_via(part, sink);
halcanary96fcdcc2015-08-27 07:41:13 -0700728 if (next == nullptr) {
kkinnunen3e980c32015-12-23 01:33:00 -0800729 SkDebugf("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(),
730 part.c_str());
mtklein748ca3b2015-01-15 10:56:12 -0800731 delete sink;
halcanary96fcdcc2015-08-27 07:41:13 -0700732 sink = nullptr;
mtklein748ca3b2015-01-15 10:56:12 -0800733 break;
734 }
735 sink = next;
736 }
737 if (sink) {
738 push_sink(config, sink);
mtklein114c3cd2015-01-15 10:15:02 -0800739 }
740 }
741}
mtklein709d2c32015-01-15 08:30:25 -0800742
mtkleina5114d72015-08-24 13:27:01 -0700743static bool dump_png(SkBitmap bitmap, const char* path, const char* md5) {
744 const int w = bitmap.width(),
745 h = bitmap.height();
746
747 // First get the bitmap into N32 color format. The next step will work only there.
748 if (bitmap.colorType() != kN32_SkColorType) {
749 SkBitmap n32;
750 if (!bitmap.copyTo(&n32, kN32_SkColorType)) {
751 return false;
752 }
753 bitmap = n32;
754 }
755
756 // Convert our N32 bitmap into unpremul RGBA for libpng.
757 SkAutoTMalloc<uint32_t> rgba(w*h);
758 if (!bitmap.readPixels(SkImageInfo::Make(w,h, kRGBA_8888_SkColorType, kUnpremul_SkAlphaType),
759 rgba, 4*w, 0,0)) {
760 return false;
761 }
762
763 // We don't need bitmap anymore. Might as well drop our ref.
mtkleinfccb77d2015-08-24 14:13:29 -0700764 bitmap.reset();
mtkleina5114d72015-08-24 13:27:01 -0700765
mtkleinc64137c2015-08-25 10:56:08 -0700766 FILE* f = fopen(path, "wb");
mtkleina5114d72015-08-24 13:27:01 -0700767 if (!f) { return false; }
768
769 png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
770 if (!png) {
771 fclose(f);
772 return false;
773 }
774
775 png_infop info = png_create_info_struct(png);
776 if (!info) {
777 png_destroy_write_struct(&png, &info);
778 fclose(f);
779 return false;
780 }
781
mtkleind69ece62015-09-10 10:37:44 -0700782 SkString description;
783 description.append("Key: ");
784 for (int i = 0; i < FLAGS_key.count(); i++) {
785 description.appendf("%s ", FLAGS_key[i]);
786 }
787 description.append("Properties: ");
788 for (int i = 0; i < FLAGS_properties.count(); i++) {
789 description.appendf("%s ", FLAGS_properties[i]);
790 }
791 description.appendf("MD5: %s", md5);
792
mtkleina5114d72015-08-24 13:27:01 -0700793 png_text text[2];
794 text[0].key = (png_charp)"Author";
795 text[0].text = (png_charp)"DM dump_png()";
796 text[0].compression = PNG_TEXT_COMPRESSION_NONE;
797 text[1].key = (png_charp)"Description";
mtkleind69ece62015-09-10 10:37:44 -0700798 text[1].text = (png_charp)description.c_str();
mtkleina5114d72015-08-24 13:27:01 -0700799 text[1].compression = PNG_TEXT_COMPRESSION_NONE;
800 png_set_text(png, info, text, 2);
801
802 png_init_io(png, f);
803 png_set_IHDR(png, info, (png_uint_32)w, (png_uint_32)h, 8,
804 PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE,
805 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
806 png_write_info(png, info);
807 for (int j = 0; j < h; j++) {
808 png_bytep row = (png_bytep)(rgba.get() + w*j);
809 png_write_rows(png, &row, 1);
810 }
811 png_write_end(png, info);
812
813 png_destroy_write_struct(&png, &info);
814 fclose(f);
815 return true;
816}
817
mtkleina2ef6422015-01-15 13:44:22 -0800818static bool match(const char* needle, const char* haystack) {
halcanary96fcdcc2015-08-27 07:41:13 -0700819 return 0 == strcmp("_", needle) || nullptr != strstr(haystack, needle);
mtkleina2ef6422015-01-15 13:44:22 -0800820}
821
djsollen54416de2015-04-03 07:24:48 -0700822static ImplicitString is_blacklisted(const char* sink, const char* src,
823 const char* srcOptions, const char* name) {
mtklein0d243ff2015-04-03 07:51:00 -0700824 for (int i = 0; i < FLAGS_blacklist.count() - 3; i += 4) {
mtkleina2ef6422015-01-15 13:44:22 -0800825 if (match(FLAGS_blacklist[i+0], sink) &&
djsollen54416de2015-04-03 07:24:48 -0700826 match(FLAGS_blacklist[i+1], src) &&
827 match(FLAGS_blacklist[i+2], srcOptions) &&
828 match(FLAGS_blacklist[i+3], name)) {
829 return SkStringPrintf("%s %s %s %s",
830 FLAGS_blacklist[i+0], FLAGS_blacklist[i+1],
831 FLAGS_blacklist[i+2], FLAGS_blacklist[i+3]);
mtkleina2ef6422015-01-15 13:44:22 -0800832 }
833 }
834 return "";
835}
836
mtkleincd50bca2016-01-05 06:20:20 -0800837// Even when a Task Sink reports to be non-threadsafe (e.g. GPU), we know things like
838// .png encoding are definitely thread safe. This lets us offload that work to CPU threads.
839static SkTaskGroup gDefinitelyThreadSafeWork;
840
mtklein748ca3b2015-01-15 10:56:12 -0800841// The finest-grained unit of work we can run: draw a single Src into a single Sink,
842// report any errors, and perhaps write out the output: a .png of the bitmap, or a raw stream.
843struct Task {
mtkleine0effd62015-07-29 06:37:28 -0700844 Task(const TaggedSrc& src, const TaggedSink& sink) : src(src), sink(sink) {}
845 const TaggedSrc& src;
846 const TaggedSink& sink;
mtklein748ca3b2015-01-15 10:56:12 -0800847
848 static void Run(Task* task) {
mtkleina2ef6422015-01-15 13:44:22 -0800849 SkString name = task->src->name();
mtkleine0effd62015-07-29 06:37:28 -0700850
851 // We'll skip drawing this Src/Sink pair if:
852 // - the Src vetoes the Sink;
853 // - this Src / Sink combination is on the blacklist;
854 // - it's a dry run.
mtklein99cab4e2015-07-31 06:43:04 -0700855 SkString note(task->src->veto(task->sink->flags()) ? " (veto)" : "");
kkinnunen3e980c32015-12-23 01:33:00 -0800856 SkString whyBlacklisted = is_blacklisted(task->sink.tag.c_str(), task->src.tag.c_str(),
msarett9e707a02015-09-01 14:57:57 -0700857 task->src.options.c_str(), name.c_str());
mtkleinb37cb412015-03-18 05:27:14 -0700858 if (!whyBlacklisted.isEmpty()) {
859 note.appendf(" (--blacklist %s)", whyBlacklisted.c_str());
860 }
mtkleine0effd62015-07-29 06:37:28 -0700861
mtkleinb9eb4ac2015-02-02 18:26:03 -0800862 SkString log;
mtkleinf27f08b2015-11-03 06:54:24 -0800863 auto timerStart = now_ms();
mtkleine0effd62015-07-29 06:37:28 -0700864 if (!FLAGS_dryRun && note.isEmpty()) {
mtklein748ca3b2015-01-15 10:56:12 -0800865 SkBitmap bitmap;
866 SkDynamicMemoryWStream stream;
bsalomon821e10e2015-06-04 14:15:33 -0700867 if (FLAGS_pre_log) {
kkinnunen3e980c32015-12-23 01:33:00 -0800868 SkDebugf("\nRunning %s->%s", name.c_str(), task->sink.tag.c_str());
bsalomon821e10e2015-06-04 14:15:33 -0700869 }
kkinnunen3e980c32015-12-23 01:33:00 -0800870 start(task->sink.tag.c_str(), task->src.tag, task->src.options, name.c_str());
mtkleinb9eb4ac2015-02-02 18:26:03 -0800871 Error err = task->sink->draw(*task->src, &bitmap, &stream, &log);
mtklein748ca3b2015-01-15 10:56:12 -0800872 if (!err.isEmpty()) {
mtklein4089ef72015-03-05 08:40:28 -0800873 if (err.isFatal()) {
djsollen54416de2015-04-03 07:24:48 -0700874 fail(SkStringPrintf("%s %s %s %s: %s",
kkinnunen3e980c32015-12-23 01:33:00 -0800875 task->sink.tag.c_str(),
msarett9e707a02015-09-01 14:57:57 -0700876 task->src.tag.c_str(),
877 task->src.options.c_str(),
mtklein4089ef72015-03-05 08:40:28 -0800878 name.c_str(),
879 err.c_str()));
mtkleinb37cb412015-03-18 05:27:14 -0700880 } else {
881 note.appendf(" (skipped: %s)", err.c_str());
mtkleinba6ada72016-01-21 09:39:35 -0800882 auto elapsed = now_ms() - timerStart;
883 done(elapsed, task->sink.tag.c_str(), task->src.tag, task->src.options,
884 name, note, log);
885 return;
mtklein4089ef72015-03-05 08:40:28 -0800886 }
mtklein748ca3b2015-01-15 10:56:12 -0800887 }
mtklein62bd1a62015-01-27 14:46:26 -0800888
mtkleincd50bca2016-01-05 06:20:20 -0800889 // We're likely switching threads here, so we must capture by value, [=] or [foo,bar].
890 SkStreamAsset* data = stream.detachAsStream();
891 gDefinitelyThreadSafeWork.add([task,name,bitmap,data]{
892 SkAutoTDelete<SkStreamAsset> ownedData(data);
893
894 // Why doesn't the copy constructor do this when we have pre-locked pixels?
895 bitmap.lockPixels();
896
897 SkString md5;
898 if (!FLAGS_writePath.isEmpty() || !FLAGS_readPath.isEmpty()) {
899 SkMD5 hash;
900 if (data->getLength()) {
901 hash.writeStream(data, data->getLength());
902 data->rewind();
mtklein38408462015-07-08 07:25:27 -0700903 } else {
mtkleincd50bca2016-01-05 06:20:20 -0800904 // If we're BGRA (Linux, Windows), swizzle over to RGBA (Mac, Android).
905 // This helps eliminate multiple 0-pixel-diff hashes on gold.skia.org.
906 // (Android's general slow speed breaks the tie arbitrarily in RGBA's favor.)
907 // We might consider promoting 565 to RGBA too.
908 if (bitmap.colorType() == kBGRA_8888_SkColorType) {
909 SkBitmap swizzle;
910 SkAssertResult(bitmap.copyTo(&swizzle, kRGBA_8888_SkColorType));
911 hash.write(swizzle.getPixels(), swizzle.getSize());
912 } else {
913 hash.write(bitmap.getPixels(), bitmap.getSize());
914 }
915 }
916 SkMD5::Digest digest;
917 hash.finish(digest);
918 for (int i = 0; i < 16; i++) {
919 md5.appendf("%02x", digest.data[i]);
mtklein38408462015-07-08 07:25:27 -0700920 }
mtklein62bd1a62015-01-27 14:46:26 -0800921 }
mtklein62bd1a62015-01-27 14:46:26 -0800922
mtkleincd50bca2016-01-05 06:20:20 -0800923 if (!FLAGS_readPath.isEmpty() &&
924 !gGold.contains(Gold(task->sink.tag.c_str(), task->src.tag.c_str(),
925 task->src.options.c_str(), name, md5))) {
926 fail(SkStringPrintf("%s not found for %s %s %s %s in %s",
927 md5.c_str(),
928 task->sink.tag.c_str(),
929 task->src.tag.c_str(),
930 task->src.options.c_str(),
931 name.c_str(),
932 FLAGS_readPath[0]));
mtklein748ca3b2015-01-15 10:56:12 -0800933 }
mtkleincd50bca2016-01-05 06:20:20 -0800934
935 if (!FLAGS_writePath.isEmpty()) {
936 const char* ext = task->sink->fileExtension();
937 if (data->getLength()) {
938 WriteToDisk(*task, md5, ext, data, data->getLength(), nullptr);
939 SkASSERT(bitmap.drawsNothing());
940 } else if (!bitmap.drawsNothing()) {
941 WriteToDisk(*task, md5, ext, nullptr, 0, &bitmap);
942 }
943 }
944 });
mtklein748ca3b2015-01-15 10:56:12 -0800945 }
mtkleinba6ada72016-01-21 09:39:35 -0800946 auto elapsed = now_ms() - timerStart;
947 done(elapsed, task->sink.tag.c_str(), task->src.tag.c_str(), task->src.options.c_str(),
mtkleinf27f08b2015-11-03 06:54:24 -0800948 name, note, log);
mtklein748ca3b2015-01-15 10:56:12 -0800949 }
950
951 static void WriteToDisk(const Task& task,
mtklein62bd1a62015-01-27 14:46:26 -0800952 SkString md5,
953 const char* ext,
mtklein748ca3b2015-01-15 10:56:12 -0800954 SkStream* data, size_t len,
mtklein62bd1a62015-01-27 14:46:26 -0800955 const SkBitmap* bitmap) {
mtklein748ca3b2015-01-15 10:56:12 -0800956 JsonWriter::BitmapResult result;
djsollen54416de2015-04-03 07:24:48 -0700957 result.name = task.src->name();
kkinnunen3e980c32015-12-23 01:33:00 -0800958 result.config = task.sink.tag.c_str();
djsollen54416de2015-04-03 07:24:48 -0700959 result.sourceType = task.src.tag;
960 result.sourceOptions = task.src.options;
961 result.ext = ext;
962 result.md5 = md5;
mtklein748ca3b2015-01-15 10:56:12 -0800963 JsonWriter::AddBitmapResult(result);
964
mtkleinb0531a72015-04-07 13:38:48 -0700965 // If an MD5 is uninteresting, we want it noted in the JSON file,
966 // but don't want to dump it out as a .png (or whatever ext is).
967 if (gUninterestingHashes.contains(md5)) {
968 return;
969 }
970
mtklein748ca3b2015-01-15 10:56:12 -0800971 const char* dir = FLAGS_writePath[0];
972 if (0 == strcmp(dir, "@")) { // Needed for iOS.
973 dir = FLAGS_resourcePath[0];
974 }
975 sk_mkdir(dir);
976
977 SkString path;
978 if (FLAGS_nameByHash) {
979 path = SkOSPath::Join(dir, result.md5.c_str());
980 path.append(".");
981 path.append(ext);
982 if (sk_exists(path.c_str())) {
983 return; // Content-addressed. If it exists already, we're done.
984 }
985 } else {
kkinnunen3e980c32015-12-23 01:33:00 -0800986 path = SkOSPath::Join(dir, task.sink.tag.c_str());
mtklein748ca3b2015-01-15 10:56:12 -0800987 sk_mkdir(path.c_str());
msarett9e707a02015-09-01 14:57:57 -0700988 path = SkOSPath::Join(path.c_str(), task.src.tag.c_str());
mtklein748ca3b2015-01-15 10:56:12 -0800989 sk_mkdir(path.c_str());
msarett9e707a02015-09-01 14:57:57 -0700990 if (strcmp(task.src.options.c_str(), "") != 0) {
991 path = SkOSPath::Join(path.c_str(), task.src.options.c_str());
djsollen54416de2015-04-03 07:24:48 -0700992 sk_mkdir(path.c_str());
993 }
mtklein748ca3b2015-01-15 10:56:12 -0800994 path = SkOSPath::Join(path.c_str(), task.src->name().c_str());
995 path.append(".");
996 path.append(ext);
997 }
998
mtklein748ca3b2015-01-15 10:56:12 -0800999 if (bitmap) {
mtkleina5114d72015-08-24 13:27:01 -07001000 if (!dump_png(*bitmap, path.c_str(), result.md5.c_str())) {
mtklein748ca3b2015-01-15 10:56:12 -08001001 fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str()));
1002 return;
1003 }
1004 } else {
mtkleina5114d72015-08-24 13:27:01 -07001005 SkFILEWStream file(path.c_str());
1006 if (!file.isValid()) {
1007 fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str()));
1008 return;
1009 }
mtklein748ca3b2015-01-15 10:56:12 -08001010 if (!file.writeStream(data, len)) {
1011 fail(SkStringPrintf("Can't write to %s.\n", path.c_str()));
1012 return;
1013 }
1014 }
1015 }
1016};
1017
1018// Run all tasks in the same enclave serially on the same thread.
1019// They can't possibly run concurrently with each other.
1020static void run_enclave(SkTArray<Task>* tasks) {
1021 for (int i = 0; i < tasks->count(); i++) {
1022 Task::Run(tasks->begin() + i);
1023 }
1024}
1025
1026/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1027
1028// Unit tests don't fit so well into the Src/Sink model, so we give them special treatment.
1029
mtklein55e88b22015-01-21 15:50:13 -08001030static SkTDArray<skiatest::Test> gThreadedTests, gGPUTests;
mtklein748ca3b2015-01-15 10:56:12 -08001031
1032static void gather_tests() {
mtklein6c5fed22015-01-20 13:47:23 -08001033 if (!FLAGS_src.contains("tests")) {
mtklein748ca3b2015-01-15 10:56:12 -08001034 return;
1035 }
mtklein6393c062015-04-27 08:45:01 -07001036 for (const skiatest::TestRegistry* r = skiatest::TestRegistry::Head(); r; r = r->next()) {
1037 if (!in_shard()) {
1038 continue;
1039 }
halcanary87f3ba42015-01-20 09:30:20 -08001040 // Despite its name, factory() is returning a reference to
1041 // link-time static const POD data.
1042 const skiatest::Test& test = r->factory();
1043 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, test.name)) {
mtklein748ca3b2015-01-15 10:56:12 -08001044 continue;
1045 }
halcanary87f3ba42015-01-20 09:30:20 -08001046 if (test.needsGpu && gpu_supported()) {
mtklein55e88b22015-01-21 15:50:13 -08001047 (FLAGS_gpu_threading ? gThreadedTests : gGPUTests).push(test);
halcanary87f3ba42015-01-20 09:30:20 -08001048 } else if (!test.needsGpu && FLAGS_cpu) {
mtklein55e88b22015-01-21 15:50:13 -08001049 gThreadedTests.push(test);
mtklein82d28432015-01-15 12:46:02 -08001050 }
mtklein748ca3b2015-01-15 10:56:12 -08001051 }
1052}
1053
halcanary87f3ba42015-01-20 09:30:20 -08001054static void run_test(skiatest::Test* test) {
1055 struct : public skiatest::Reporter {
mtklein36352bf2015-03-25 18:17:31 -07001056 void reportFailed(const skiatest::Failure& failure) override {
halcanary87f3ba42015-01-20 09:30:20 -08001057 fail(failure.toString());
1058 JsonWriter::AddTestFailure(failure);
1059 }
mtklein36352bf2015-03-25 18:17:31 -07001060 bool allowExtendedTest() const override {
halcanary87f3ba42015-01-20 09:30:20 -08001061 return FLAGS_pathOpsExtended;
1062 }
mtklein36352bf2015-03-25 18:17:31 -07001063 bool verbose() const override { return FLAGS_veryVerbose; }
halcanary87f3ba42015-01-20 09:30:20 -08001064 } reporter;
djsollen824996a2015-06-12 12:06:22 -07001065
1066 SkString note;
1067 SkString whyBlacklisted = is_blacklisted("_", "tests", "_", test->name);
1068 if (!whyBlacklisted.isEmpty()) {
1069 note.appendf(" (--blacklist %s)", whyBlacklisted.c_str());
1070 }
1071
mtkleinf27f08b2015-11-03 06:54:24 -08001072 auto timerStart = now_ms();
djsollen824996a2015-06-12 12:06:22 -07001073 if (!FLAGS_dryRun && whyBlacklisted.isEmpty()) {
djsollen54416de2015-04-03 07:24:48 -07001074 start("unit", "test", "", test->name);
mtklein55e88b22015-01-21 15:50:13 -08001075 GrContextFactory factory;
bsalomon821e10e2015-06-04 14:15:33 -07001076 if (FLAGS_pre_log) {
1077 SkDebugf("\nRunning test %s", test->name);
1078 }
mtklein55e88b22015-01-21 15:50:13 -08001079 test->proc(&reporter, &factory);
mtklein748ca3b2015-01-15 10:56:12 -08001080 }
mtkleinf27f08b2015-11-03 06:54:24 -08001081 done(now_ms()-timerStart, "unit", "test", "", test->name, note, "");
mtklein748ca3b2015-01-15 10:56:12 -08001082}
1083
1084/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1085
mtklein55e88b22015-01-21 15:50:13 -08001086// If we're isolating all GPU-bound work to one thread (the default), this function runs all that.
1087static void run_enclave_and_gpu_tests(SkTArray<Task>* tasks) {
1088 run_enclave(tasks);
1089 for (int i = 0; i < gGPUTests.count(); i++) {
1090 run_test(&gGPUTests[i]);
1091 }
1092}
1093
mtkleinde6fc2b2015-03-12 06:28:54 -07001094// Some runs (mostly, Valgrind) are so slow that the bot framework thinks we've hung.
1095// This prints something every once in a while so that it knows we're still working.
mtklein2e1c47e2015-03-12 07:16:56 -07001096static void start_keepalive() {
1097 struct Loop {
1098 static void forever(void*) {
1099 for (;;) {
1100 static const int kSec = 300;
1101 #if defined(SK_BUILD_FOR_WIN)
1102 Sleep(kSec * 1000);
1103 #else
1104 sleep(kSec);
1105 #endif
mtkleinb37cb412015-03-18 05:27:14 -07001106 SkString running;
1107 {
mtkleinbc4e0032015-12-09 08:37:35 -08001108 SkAutoMutexAcquire lock(gRunningAndTallyMutex);
mtkleinb37cb412015-03-18 05:27:14 -07001109 for (int i = 0; i < gRunning.count(); i++) {
1110 running.appendf("\n\t%s", gRunning[i].c_str());
1111 }
1112 }
1113 SkDebugf("\nCurrently running:%s\n", running.c_str());
mtklein2e1c47e2015-03-12 07:16:56 -07001114 }
1115 }
1116 };
1117 static SkThread* intentionallyLeaked = new SkThread(Loop::forever);
1118 intentionallyLeaked->start();
mtkleinde6fc2b2015-03-12 06:28:54 -07001119}
1120
caryclark83ca6282015-06-10 09:31:09 -07001121#define PORTABLE_FONT_PREFIX "Toy Liberation "
1122
1123static SkTypeface* create_from_name(const char familyName[], SkTypeface::Style style) {
1124 if (familyName && strlen(familyName) > sizeof(PORTABLE_FONT_PREFIX)
1125 && !strncmp(familyName, PORTABLE_FONT_PREFIX, sizeof(PORTABLE_FONT_PREFIX) - 1)) {
caryclark1818acb2015-07-24 12:09:25 -07001126 return sk_tool_utils::create_portable_typeface(familyName, style);
caryclark83ca6282015-06-10 09:31:09 -07001127 }
halcanary96fcdcc2015-08-27 07:41:13 -07001128 return nullptr;
caryclark83ca6282015-06-10 09:31:09 -07001129}
1130
1131#undef PORTABLE_FONT_PREFIX
1132
1133extern SkTypeface* (*gCreateTypefaceDelegate)(const char [], SkTypeface::Style );
1134
jcgregorio3b27ade2014-11-13 08:06:40 -08001135int dm_main();
caryclark17f0b6d2014-07-22 10:15:34 -07001136int dm_main() {
jcgregorio3b27ade2014-11-13 08:06:40 -08001137 SetupCrashHandler();
mtklein5286f022016-01-22 08:18:14 -08001138 JsonWriter::DumpJson(); // It's handy for the bots to assume this is ~never missing.
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +00001139 SkAutoGraphics ag;
mtklein406654b2014-09-03 15:34:37 -07001140 SkTaskGroup::Enabler enabled(FLAGS_threads);
caryclark83ca6282015-06-10 09:31:09 -07001141 gCreateTypefaceDelegate = &create_from_name;
commit-bot@chromium.orga65e2fd2014-05-30 17:23:31 +00001142
mtklein2e1c47e2015-03-12 07:16:56 -07001143 start_keepalive();
mtkleinde6fc2b2015-03-12 06:28:54 -07001144
mtklein62bd1a62015-01-27 14:46:26 -08001145 gather_gold();
borenet09ed4802015-04-03 14:15:33 -07001146 gather_uninteresting_hashes();
mtklein62bd1a62015-01-27 14:46:26 -08001147
scroggoad38ed62016-01-29 14:41:55 -08001148 gather_srcs();
mtklein748ca3b2015-01-15 10:56:12 -08001149 gather_sinks();
1150 gather_tests();
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +00001151
mtklein55e88b22015-01-21 15:50:13 -08001152 gPending = gSrcs.count() * gSinks.count() + gThreadedTests.count() + gGPUTests.count();
mtklein748ca3b2015-01-15 10:56:12 -08001153 SkDebugf("%d srcs * %d sinks + %d tests == %d tasks\n",
mtklein55e88b22015-01-21 15:50:13 -08001154 gSrcs.count(), gSinks.count(), gThreadedTests.count() + gGPUTests.count(), gPending);
mtklein748ca3b2015-01-15 10:56:12 -08001155
1156 // We try to exploit as much parallelism as is safe. Most Src/Sink pairs run on any thread,
1157 // but Sinks that identify as part of a particular enclave run serially on a single thread.
mtklein82d28432015-01-15 12:46:02 -08001158 // CPU tests run on any thread. GPU tests depend on --gpu_threading.
mtklein748ca3b2015-01-15 10:56:12 -08001159 SkTArray<Task> enclaves[kNumEnclaves];
1160 for (int j = 0; j < gSinks.count(); j++) {
1161 SkTArray<Task>& tasks = enclaves[gSinks[j]->enclave()];
1162 for (int i = 0; i < gSrcs.count(); i++) {
1163 tasks.push_back(Task(gSrcs[i], gSinks[j]));
1164 }
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001165 }
1166
mtklein748ca3b2015-01-15 10:56:12 -08001167 SkTaskGroup tg;
mtklein279c7862016-01-04 19:13:19 -08001168 tg.batch(gThreadedTests.count(), [](int i){ run_test(&gThreadedTests[i]); });
mtklein55e88b22015-01-21 15:50:13 -08001169 for (int i = 0; i < kNumEnclaves; i++) {
herb30da5f72015-12-10 14:12:33 -08001170 SkTArray<Task>* currentEnclave = &enclaves[i];
mtklein55e88b22015-01-21 15:50:13 -08001171 switch(i) {
1172 case kAnyThread_Enclave:
mtklein279c7862016-01-04 19:13:19 -08001173 tg.batch(currentEnclave->count(),
1174 [currentEnclave](int j) { Task::Run(&(*currentEnclave)[j]); });
mtklein55e88b22015-01-21 15:50:13 -08001175 break;
1176 case kGPU_Enclave:
herb30da5f72015-12-10 14:12:33 -08001177 tg.add([currentEnclave](){ run_enclave_and_gpu_tests(currentEnclave); });
mtklein55e88b22015-01-21 15:50:13 -08001178 break;
1179 default:
herb30da5f72015-12-10 14:12:33 -08001180 tg.add([currentEnclave](){ run_enclave(currentEnclave); });
mtklein55e88b22015-01-21 15:50:13 -08001181 break;
mtklein82d28432015-01-15 12:46:02 -08001182 }
mtklein55e88b22015-01-21 15:50:13 -08001183 }
mtklein748ca3b2015-01-15 10:56:12 -08001184 tg.wait();
mtkleincd50bca2016-01-05 06:20:20 -08001185 gDefinitelyThreadSafeWork.wait();
1186
mtklein748ca3b2015-01-15 10:56:12 -08001187 // At this point we're back in single-threaded land.
caryclarkf53ce802015-06-15 06:48:30 -07001188 sk_tool_utils::release_portable_typefaces();
mtklein@google.comd36522d2013-10-16 13:02:15 +00001189
mtkleinbc4e0032015-12-09 08:37:35 -08001190 if (FLAGS_verbose && gNoteTally.count() > 0) {
1191 SkDebugf("\nNote tally:\n");
1192 gNoteTally.foreach([](const SkString& note, int* tally) {
1193 SkDebugf("%dx\t%s\n", *tally, note.c_str());
1194 });
1195 }
1196
mtklein2f64eec2015-01-15 14:20:41 -08001197 SkDebugf("\n");
mtklein748ca3b2015-01-15 10:56:12 -08001198 if (gFailures.count() > 0) {
1199 SkDebugf("Failures:\n");
1200 for (int i = 0; i < gFailures.count(); i++) {
mtklein9dc09102015-01-15 15:47:33 -08001201 SkDebugf("\t%s\n", gFailures[i].c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001202 }
1203 SkDebugf("%d failures\n", gFailures.count());
1204 return 1;
mtklein114c3cd2015-01-15 10:15:02 -08001205 }
mtklein748ca3b2015-01-15 10:56:12 -08001206 if (gPending > 0) {
1207 SkDebugf("Hrm, we didn't seem to run everything we intended to! Please file a bug.\n");
1208 return 1;
mtklein114c3cd2015-01-15 10:15:02 -08001209 }
halcanary7a14b312015-10-01 07:28:13 -07001210 #ifdef SK_PDF_IMAGE_STATS
1211 SkPDFImageDumpStats();
1212 #endif // SK_PDF_IMAGE_STATS
scroggo4d9eaea2016-01-29 07:48:33 -08001213 SkDebugf("Finished!\n");
mtklein748ca3b2015-01-15 10:56:12 -08001214 return 0;
mtklein@google.comd36522d2013-10-16 13:02:15 +00001215}
jcgregorio3b27ade2014-11-13 08:06:40 -08001216
kkinnunen179a8f52015-11-20 13:32:24 -08001217// TODO: currently many GPU tests are declared outside SK_SUPPORT_GPU guards.
1218// Thus we export the empty RunWithGPUTestContexts when SK_SUPPORT_GPU=0.
1219namespace skiatest {
1220namespace {
1221typedef void(*TestWithGrContext)(skiatest::Reporter*, GrContext*);
1222typedef void(*TestWithGrContextAndGLContext)(skiatest::Reporter*, GrContext*, SkGLContext*);
1223#if SK_SUPPORT_GPU
1224template<typename T>
kkinnunen34058002016-01-06 23:49:30 -08001225void call_test(T test, skiatest::Reporter* reporter, const GrContextFactory::ContextInfo& context);
kkinnunen179a8f52015-11-20 13:32:24 -08001226template<>
1227void call_test(TestWithGrContext test, skiatest::Reporter* reporter,
kkinnunen34058002016-01-06 23:49:30 -08001228 const GrContextFactory::ContextInfo& context) {
1229 test(reporter, context.fGrContext);
kkinnunen179a8f52015-11-20 13:32:24 -08001230}
1231template<>
1232void call_test(TestWithGrContextAndGLContext test, skiatest::Reporter* reporter,
kkinnunen34058002016-01-06 23:49:30 -08001233 const GrContextFactory::ContextInfo& context) {
1234 test(reporter, context.fGrContext, context.fGLContext);
kkinnunen179a8f52015-11-20 13:32:24 -08001235}
1236#endif
1237} // namespace
1238
kkinnunen179a8f52015-11-20 13:32:24 -08001239template<typename T>
1240void RunWithGPUTestContexts(T test, GPUTestContexts testContexts, Reporter* reporter,
1241 GrContextFactory* factory) {
1242#if SK_SUPPORT_GPU
kkinnunen3e980c32015-12-23 01:33:00 -08001243 // Iterate over context types, except use "native" instead of explicitly trying OpenGL and
1244 // OpenGL ES. Do not use GLES on desktop, since tests do not account for not fixing
1245 // http://skbug.com/2809
1246 GrContextFactory::GLContextType contextTypes[] = {
1247 GrContextFactory::kNative_GLContextType,
1248#if SK_ANGLE
1249#ifdef SK_BUILD_FOR_WIN
1250 GrContextFactory::kANGLE_GLContextType,
1251#endif
1252 GrContextFactory::kANGLE_GL_GLContextType,
1253#endif
1254#if SK_COMMAND_BUFFER
1255 GrContextFactory::kCommandBuffer_GLContextType,
1256#endif
1257#if SK_MESA
1258 GrContextFactory::kMESA_GLContextType,
1259#endif
1260 GrContextFactory::kNull_GLContextType,
1261 GrContextFactory::kDebug_GLContextType,
1262 };
1263 static_assert(SK_ARRAY_COUNT(contextTypes) == GrContextFactory::kGLContextTypeCnt - 2,
1264 "Skipping unexpected GLContextType for GPU tests");
1265
1266 for (auto& contextType : contextTypes) {
kkinnunen179a8f52015-11-20 13:32:24 -08001267 int contextSelector = kNone_GPUTestContexts;
kkinnunen3e980c32015-12-23 01:33:00 -08001268 if (GrContextFactory::IsRenderingGLContext(contextType)) {
kkinnunen179a8f52015-11-20 13:32:24 -08001269 contextSelector |= kAllRendering_GPUTestContexts;
kkinnunen3e980c32015-12-23 01:33:00 -08001270 } else if (contextType == GrContextFactory::kNative_GLContextType) {
kkinnunen179a8f52015-11-20 13:32:24 -08001271 contextSelector |= kNative_GPUTestContexts;
kkinnunen3e980c32015-12-23 01:33:00 -08001272 } else if (contextType == GrContextFactory::kNull_GLContextType) {
kkinnunen179a8f52015-11-20 13:32:24 -08001273 contextSelector |= kNull_GPUTestContexts;
kkinnunen3e980c32015-12-23 01:33:00 -08001274 } else if (contextType == GrContextFactory::kDebug_GLContextType) {
kkinnunen55eeae92015-12-10 23:19:29 -08001275 contextSelector |= kDebug_GPUTestContexts;
kkinnunen179a8f52015-11-20 13:32:24 -08001276 }
1277 if ((testContexts & contextSelector) == 0) {
1278 continue;
1279 }
kkinnunen34058002016-01-06 23:49:30 -08001280 GrContextFactory::ContextInfo context = factory->getContextInfo(contextType);
1281 if (context.fGrContext) {
kkinnunen5219fd92015-12-10 06:28:13 -08001282 call_test(test, reporter, context);
1283 }
kkinnunen34058002016-01-06 23:49:30 -08001284 context = factory->getContextInfo(contextType,
1285 GrContextFactory::kEnableNVPR_GLContextOptions);
1286 if (context.fGrContext) {
kkinnunen179a8f52015-11-20 13:32:24 -08001287 call_test(test, reporter, context);
1288 }
1289 }
1290#endif
1291}
1292
1293template
1294void RunWithGPUTestContexts<TestWithGrContext>(TestWithGrContext test,
1295 GPUTestContexts testContexts,
1296 Reporter* reporter,
1297 GrContextFactory* factory);
1298template
1299void RunWithGPUTestContexts<TestWithGrContextAndGLContext>(TestWithGrContextAndGLContext test,
1300 GPUTestContexts testContexts,
1301 Reporter* reporter,
1302 GrContextFactory* factory);
1303} // namespace skiatest
1304
borenet48087572015-04-02 12:16:36 -07001305#if !defined(SK_BUILD_FOR_IOS)
jcgregorio3b27ade2014-11-13 08:06:40 -08001306int main(int argc, char** argv) {
1307 SkCommandLineFlags::Parse(argc, argv);
1308 return dm_main();
1309}
1310#endif