blob: 20d454d60ac16daf45faa993fe4c9c29d8c182f2 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "dm/DMJsonWriter.h"
9#include "dm/DMSrcSink.h"
10#include "include/codec/SkCodec.h"
11#include "include/core/SkBBHFactory.h"
12#include "include/core/SkColorPriv.h"
13#include "include/core/SkColorSpace.h"
14#include "include/core/SkData.h"
15#include "include/core/SkDocument.h"
16#include "include/core/SkFontMgr.h"
17#include "include/core/SkGraphics.h"
18#include "include/ports/SkTypeface_win.h"
19#include "include/private/SkChecksum.h"
20#include "include/private/SkHalf.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050021#include "include/private/SkMutex.h"
22#include "include/private/SkSpinlock.h"
23#include "include/private/SkTHash.h"
24#include "src/core/SkColorSpacePriv.h"
Ben Wagnerab6eefe2019-05-20 11:02:49 -040025#include "src/core/SkLeanWindows.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050026#include "src/core/SkMD5.h"
27#include "src/core/SkOSFile.h"
28#include "src/core/SkTaskGroup.h"
29#include "src/utils/SkOSPath.h"
30#include "tests/Test.h"
31#include "tools/HashAndEncode.h"
32#include "tools/ProcStats.h"
33#include "tools/Resources.h"
34#include "tools/ToolUtils.h"
35#include "tools/flags/CommonFlags.h"
36#include "tools/flags/CommonFlagsConfig.h"
37#include "tools/ios_utils.h"
38#include "tools/trace/ChromeTracingTracer.h"
39#include "tools/trace/EventTracingPriv.h"
40#include "tools/trace/SkDebugfTracer.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000041
scroggo19b91532016-10-24 09:03:26 -070042#include <vector>
43
bungeman60e0fee2015-08-26 05:15:46 -070044#include <stdlib.h>
45
Mike Klein8f11d4d2018-01-24 12:42:55 -050046#ifndef SK_BUILD_FOR_WIN
scroggo27a58342015-10-28 08:56:41 -070047 #include <unistd.h>
48#endif
49
Dongwon Kang0c7861f2018-02-16 10:55:21 -080050#if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && defined(SK_HAS_HEIF_LIBRARY)
51#include <binder/IPCThreadState.h>
52#endif
53
Mike Reed7c26ca72017-07-05 15:45:52 -040054extern bool gSkForceRasterPipelineBlitter;
55
Mike Klein84836b72019-03-21 11:31:36 -050056static DEFINE_string(src, "tests gm skp image", "Source types to test.");
57static DEFINE_bool(nameByHash, false,
58 "If true, write to FLAGS_writePath[0]/<hash>.png instead of "
59 "to FLAGS_writePath[0]/<config>/<sourceType>/<sourceOptions>/<name>.png");
60static DEFINE_bool2(pathOpsExtended, x, false, "Run extended pathOps tests.");
61static DEFINE_string(matrix, "1 0 0 1",
62 "2x2 scale+skew matrix to apply or upright when using "
63 "'matrix' or 'upright' in config.");
64static DEFINE_bool(gpu_threading, false, "Allow GPU work to run on multiple threads?");
mtklein@google.comd36522d2013-10-16 13:02:15 +000065
Mike Klein84836b72019-03-21 11:31:36 -050066static DEFINE_string(blacklist, "",
Chris Daltonecf78ac2017-08-15 15:43:08 -060067 "Space-separated config/src/srcOptions/name quadruples to blacklist. "
68 "'_' matches anything. '~' negates the match. E.g. \n"
djsollen54416de2015-04-03 07:24:48 -070069 "'--blacklist gpu skp _ _' will blacklist all SKPs drawn into the gpu config.\n"
Chris Daltonecf78ac2017-08-15 15:43:08 -060070 "'--blacklist gpu skp _ _ 8888 gm _ aarects' will also blacklist the aarects GM on 8888.\n"
71 "'--blacklist ~8888 svg _ svgparse_' blocks non-8888 SVGs that contain \"svgparse_\" in "
72 "the name.");
mtkleina2ef6422015-01-15 13:44:22 -080073
Mike Klein84836b72019-03-21 11:31:36 -050074static DEFINE_string2(readPath, r, "",
75 "If set check for equality with golden results in this directory.");
Mike Kleinc6142d82019-03-25 10:54:59 -050076DEFINE_string2(writePath, w, "", "If set, write bitmaps here as .pngs.");
77
Brian Osman57796b32019-01-25 18:02:59 +000078
Mike Klein84836b72019-03-21 11:31:36 -050079static DEFINE_string(uninterestingHashesFile, "",
borenet09ed4802015-04-03 14:15:33 -070080 "File containing a list of uninteresting hashes. If a result hashes to something in "
81 "this list, no image is written for that result.");
82
Mike Klein5b3f3432019-03-21 11:42:21 -050083static DEFINE_int(shards, 1, "We're splitting source data into this many shards.");
84static DEFINE_int(shard, 0, "Which shard do I run?");
mtklein6393c062015-04-27 08:45:01 -070085
Mike Klein84836b72019-03-21 11:31:36 -050086static DEFINE_string(mskps, "", "Directory to read mskps from, or a single mskp file.");
87static DEFINE_bool(forceRasterPipeline, false, "sets gSkForceRasterPipelineBlitter");
halcanary45420a92016-06-02 12:41:14 -070088
Mike Klein84836b72019-03-21 11:31:36 -050089static DEFINE_string(bisect, "",
Chris Dalton184c37e2018-09-28 11:27:39 -060090 "Pair of: SKP file to bisect, followed by an l/r bisect trail string (e.g., 'lrll'). The "
91 "l/r trail specifies which half to keep at each step of a binary search through the SKP's "
92 "paths. An empty string performs no bisect. Only the SkPaths are bisected; all other draws "
93 "are thrown out. This is useful for finding a reduced repo case for path drawing bugs.");
94
Mike Klein84836b72019-03-21 11:31:36 -050095static DEFINE_bool(ignoreSigInt, false, "ignore SIGINT signals during test execution");
Derek Sollenbergeredfe3df2017-07-19 15:25:24 -040096
Mike Klein84836b72019-03-21 11:31:36 -050097static DEFINE_string(dont_write, "", "File extensions to skip writing to --writePath."); // See skia:6821
Mike Klein97d6a7a2017-07-24 10:37:19 -040098
Mike Klein84836b72019-03-21 11:31:36 -050099static DEFINE_bool(checkF16, false, "Ensure that F16Norm pixels are clamped.");
Brian Osman582f6862019-03-11 11:20:55 -0400100
Mike Klein19fb3972019-03-21 13:08:08 -0500101static DEFINE_string(colorImages, "",
102 "List of images and/or directories to decode with color correction. "
103 "A directory with no images is treated as a fatal error.");
104
Mike Kleind0f321b2019-03-22 13:15:11 -0500105static DEFINE_bool2(veryVerbose, V, false, "tell individual tests to be verbose.");
106
Mike Klein629f5fc2019-03-22 14:55:19 -0500107static DEFINE_bool(cpu, true, "master switch for running CPU-bound work.");
108static DEFINE_bool(gpu, true, "master switch for running GPU-bound work.");
109
110static DEFINE_bool(dryRun, false,
111 "just print the tests that would be run, without actually running them.");
112
113static DEFINE_string(images, "",
114 "List of images and/or directories to decode. A directory with no images"
115 " is treated as a fatal error.");
116
117static DEFINE_bool(simpleCodec, false,
118 "Runs of a subset of the codec tests, "
119 "with no scaling or subsetting, always using the canvas color type.");
Mike Klein19fb3972019-03-21 13:08:08 -0500120
Mike Kleinc6142d82019-03-25 10:54:59 -0500121static DEFINE_string2(match, m, nullptr,
122 "[~][^]substring[$] [...] of name to run.\n"
123 "Multiple matches may be separated by spaces.\n"
124 "~ causes a matching name to always be skipped\n"
125 "^ requires the start of the name to match\n"
126 "$ requires the end of the name to match\n"
127 "^ and $ requires an exact match\n"
128 "If a name does not match any list entry,\n"
129 "it is skipped unless some list entry starts with ~");
130
131static DEFINE_bool2(quiet, q, false, "if true, don't print status updates.");
132static DEFINE_bool2(verbose, v, false, "enable verbose output from the test driver.");
133
134static DEFINE_string(skps, "skps", "Directory to read skps from.");
135static DEFINE_string(lotties, "lotties", "Directory to read (Bodymovin) jsons from.");
136static DEFINE_string(svgs, "", "Directory to read SVGs from, or a single SVG file.");
137
138static DEFINE_int_2(threads, j, -1,
139 "Run threadsafe tests on a threadpool with this many extra threads, "
140 "defaulting to one extra thread per core.");
141
142static DEFINE_string(key, "",
143 "Space-separated key/value pairs to add to JSON identifying this builder.");
144static DEFINE_string(properties, "",
145 "Space-separated key/value pairs to add to JSON identifying this run.");
146
147
mtklein748ca3b2015-01-15 10:56:12 -0800148using namespace DM;
bsalomon3724e572016-03-30 18:56:19 -0700149using sk_gpu_test::GrContextFactory;
bsalomon273c0f52016-03-31 10:59:06 -0700150using sk_gpu_test::GLTestContext;
bsalomonf2f1c172016-04-05 12:59:06 -0700151using sk_gpu_test::ContextInfo;
mtklein@google.comd36522d2013-10-16 13:02:15 +0000152
mtklein748ca3b2015-01-15 10:56:12 -0800153/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
154
Mike Kleine1271702019-03-07 11:46:59 -0600155static sk_sp<SkColorSpace> rec2020() {
Hal Canarybe67a172019-05-24 10:13:36 -0400156 return SkColorSpace::MakeRGB(SkNamedTransferFn::kRec2020, SkNamedGamut::kRec2020);
Mike Kleine1271702019-03-07 11:46:59 -0600157}
158
159/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
160
mtkleinc41fd922016-03-08 09:01:39 -0800161static FILE* gVLog;
162
163template <typename... Args>
164static void vlog(const char* fmt, Args&&... args) {
165 if (gVLog) {
mtkleinc41fd922016-03-08 09:01:39 -0800166 fprintf(gVLog, fmt, args...);
167 fflush(gVLog);
168 }
169}
170
171template <typename... Args>
172static void info(const char* fmt, Args&&... args) {
173 vlog(fmt, args...);
174 if (!FLAGS_quiet) {
175 printf(fmt, args...);
176 }
177}
178static void info(const char* fmt) {
179 if (!FLAGS_quiet) {
180 printf("%s", fmt); // Clang warns printf(fmt) is insecure.
181 }
182}
183
reed086eea92016-05-04 17:12:46 -0700184SK_DECLARE_STATIC_MUTEX(gFailuresMutex);
mtklein748ca3b2015-01-15 10:56:12 -0800185static SkTArray<SkString> gFailures;
186
mtklein3eed7dd2016-02-24 19:07:07 -0800187static void fail(const SkString& err) {
mtklein748ca3b2015-01-15 10:56:12 -0800188 SkAutoMutexAcquire lock(gFailuresMutex);
189 SkDebugf("\n\nFAILURE: %s\n\n", err.c_str());
190 gFailures.push_back(err);
halcanary9e398f72015-01-10 11:18:04 -0800191}
192
mtklein0f7748a2016-07-25 15:27:29 -0700193struct Running {
194 SkString id;
195 SkThreadID thread;
196
197 void dump() const {
198 info("\t%s\n", id.c_str());
199 }
200};
mtkleinb37cb412015-03-18 05:27:14 -0700201
Mike Kleinc6142d82019-03-25 10:54:59 -0500202static void dump_json() {
203 if (!FLAGS_writePath.isEmpty()) {
204 JsonWriter::DumpJson(FLAGS_writePath[0], FLAGS_key, FLAGS_properties);
205 }
206}
207
mtklein246ba3a2016-02-23 10:39:36 -0800208// We use a spinlock to make locking this in a signal handler _somewhat_ safe.
Mike Klein03a95ad2017-06-23 12:36:32 -0400209static SkSpinlock gMutex;
210static int gPending;
mtklein0f7748a2016-07-25 15:27:29 -0700211static SkTArray<Running> gRunning;
mtklein748ca3b2015-01-15 10:56:12 -0800212
mtklein3eed7dd2016-02-24 19:07:07 -0800213static void done(const char* config, const char* src, const char* srcOptions, const char* name) {
214 SkString id = SkStringPrintf("%s %s %s %s", config, src, srcOptions, name);
mtkleinc41fd922016-03-08 09:01:39 -0800215 vlog("done %s\n", id.c_str());
mtkleinafae30a2016-02-24 12:28:32 -0800216 int pending;
mtkleinb37cb412015-03-18 05:27:14 -0700217 {
Herb Derbya1b7be62019-05-09 16:59:18 -0400218 SkAutoSpinlock lock(gMutex);
mtkleinb37cb412015-03-18 05:27:14 -0700219 for (int i = 0; i < gRunning.count(); i++) {
mtklein0f7748a2016-07-25 15:27:29 -0700220 if (gRunning[i].id == id) {
mtkleinb37cb412015-03-18 05:27:14 -0700221 gRunning.removeShuffle(i);
222 break;
223 }
224 }
mtkleinafae30a2016-02-24 12:28:32 -0800225 pending = --gPending;
reed50bc0512015-05-19 14:13:31 -0700226 }
Mike Klein03a95ad2017-06-23 12:36:32 -0400227
228 // We write out dm.json file and print out a progress update every once in a while.
229 // Notice this also handles the final dm.json and progress update when pending == 0.
mtkleina17241b2015-01-23 05:48:00 -0800230 if (pending % 500 == 0) {
Mike Kleinc6142d82019-03-25 10:54:59 -0500231 dump_json();
Mike Klein03a95ad2017-06-23 12:36:32 -0400232
233 int curr = sk_tools::getCurrResidentSetSizeMB(),
234 peak = sk_tools::getMaxResidentSetSizeMB();
Mike Klein03a95ad2017-06-23 12:36:32 -0400235
Herb Derbya1b7be62019-05-09 16:59:18 -0400236 SkAutoSpinlock lock(gMutex);
Mike Klein21ba7722018-10-02 13:57:44 +0000237 info("\n%dMB RAM, %dMB peak, %d queued, %d active:\n",
238 curr, peak, gPending - gRunning.count(), gRunning.count());
Mike Klein03a95ad2017-06-23 12:36:32 -0400239 for (auto& task : gRunning) {
240 task.dump();
241 }
mtkleina17241b2015-01-23 05:48:00 -0800242 }
mtklein@google.comd36522d2013-10-16 13:02:15 +0000243}
244
mtklein3eed7dd2016-02-24 19:07:07 -0800245static void start(const char* config, const char* src, const char* srcOptions, const char* name) {
246 SkString id = SkStringPrintf("%s %s %s %s", config, src, srcOptions, name);
mtkleinc41fd922016-03-08 09:01:39 -0800247 vlog("start %s\n", id.c_str());
Herb Derbya1b7be62019-05-09 16:59:18 -0400248 SkAutoSpinlock lock(gMutex);
mtklein0f7748a2016-07-25 15:27:29 -0700249 gRunning.push_back({id,SkGetThreadID()});
mtkleinb37cb412015-03-18 05:27:14 -0700250}
251
Mike Klein3cc2d202016-10-24 11:39:43 -0400252static void find_culprit() {
253 // Assumes gMutex is locked.
254 SkThreadID thisThread = SkGetThreadID();
255 for (auto& task : gRunning) {
256 if (task.thread == thisThread) {
257 info("Likely culprit:\n");
258 task.dump();
mtklein0f7748a2016-07-25 15:27:29 -0700259 }
260 }
Mike Klein3cc2d202016-10-24 11:39:43 -0400261}
mtklein0f7748a2016-07-25 15:27:29 -0700262
Mike Klein8f11d4d2018-01-24 12:42:55 -0500263#if defined(SK_BUILD_FOR_WIN)
mtklein5b64dab2016-06-09 08:59:48 -0700264 static LONG WINAPI crash_handler(EXCEPTION_POINTERS* e) {
mtkleinf8557292016-02-29 06:35:28 -0800265 static const struct {
266 const char* name;
robertphillips75467862016-03-01 14:10:23 -0800267 DWORD code;
mtkleinf8557292016-02-29 06:35:28 -0800268 } kExceptions[] = {
269 #define _(E) {#E, E}
270 _(EXCEPTION_ACCESS_VIOLATION),
271 _(EXCEPTION_BREAKPOINT),
272 _(EXCEPTION_INT_DIVIDE_BY_ZERO),
273 _(EXCEPTION_STACK_OVERFLOW),
274 // TODO: more?
275 #undef _
276 };
277
Herb Derbya1b7be62019-05-09 16:59:18 -0400278 SkAutoSpinlock lock(gMutex);
mtklein5b64dab2016-06-09 08:59:48 -0700279
280 const DWORD code = e->ExceptionRecord->ExceptionCode;
281 info("\nCaught exception %u", code);
282 for (const auto& exception : kExceptions) {
283 if (exception.code == code) {
284 info(" %s", exception.name);
mtkleinf8557292016-02-29 06:35:28 -0800285 }
mtkleinf8557292016-02-29 06:35:28 -0800286 }
mtklein5b64dab2016-06-09 08:59:48 -0700287 info(", was running:\n");
288 for (auto& task : gRunning) {
mtklein0f7748a2016-07-25 15:27:29 -0700289 task.dump();
mtklein5b64dab2016-06-09 08:59:48 -0700290 }
mtklein0f7748a2016-07-25 15:27:29 -0700291 find_culprit();
mtklein5b64dab2016-06-09 08:59:48 -0700292 fflush(stdout);
293
mtkleinf8557292016-02-29 06:35:28 -0800294 // Execute default exception handler... hopefully, exit.
295 return EXCEPTION_EXECUTE_HANDLER;
mtklein246ba3a2016-02-23 10:39:36 -0800296 }
297
Mike Klein3cc2d202016-10-24 11:39:43 -0400298 static void setup_crash_handler() {
299 SetUnhandledExceptionFilter(crash_handler);
300 }
301#else
mtklein246ba3a2016-02-23 10:39:36 -0800302 #include <signal.h>
Mike Klein3cc2d202016-10-24 11:39:43 -0400303 #if !defined(SK_BUILD_FOR_ANDROID)
304 #include <execinfo.h>
Brian Salomondcbb9d92017-07-19 10:53:20 -0400305
306#endif
Mike Klein3cc2d202016-10-24 11:39:43 -0400307
308 static constexpr int max_of() { return 0; }
309 template <typename... Rest>
310 static constexpr int max_of(int x, Rest... rest) {
311 return x > max_of(rest...) ? x : max_of(rest...);
312 }
313
Mike Kleinc7278ad2018-02-15 09:26:54 -0500314 static void (*previous_handler[max_of(SIGABRT,SIGBUS,SIGFPE,SIGILL,SIGSEGV,SIGTERM)+1])(int);
mtkleinf8557292016-02-29 06:35:28 -0800315
mtklein5b64dab2016-06-09 08:59:48 -0700316 static void crash_handler(int sig) {
Herb Derbya1b7be62019-05-09 16:59:18 -0400317 SkAutoSpinlock lock(gMutex);
mtklein5b64dab2016-06-09 08:59:48 -0700318
Mike Klein701a3582018-06-28 14:08:19 +0000319 info("\nCaught signal %d [%s] (%dMB RAM, peak %dMB), was running:\n",
320 sig, strsignal(sig),
321 sk_tools::getCurrResidentSetSizeMB(), sk_tools::getMaxResidentSetSizeMB());
322
mtklein5b64dab2016-06-09 08:59:48 -0700323 for (auto& task : gRunning) {
mtklein0f7748a2016-07-25 15:27:29 -0700324 task.dump();
mtklein5b64dab2016-06-09 08:59:48 -0700325 }
mtklein0f7748a2016-07-25 15:27:29 -0700326 find_culprit();
mtklein5b64dab2016-06-09 08:59:48 -0700327
Mike Klein3cc2d202016-10-24 11:39:43 -0400328 #if !defined(SK_BUILD_FOR_ANDROID)
mtklein5b64dab2016-06-09 08:59:48 -0700329 void* stack[64];
330 int count = backtrace(stack, SK_ARRAY_COUNT(stack));
331 char** symbols = backtrace_symbols(stack, count);
332 info("\nStack trace:\n");
333 for (int i = 0; i < count; i++) {
334 info(" %s\n", symbols[i]);
335 }
Mike Klein3cc2d202016-10-24 11:39:43 -0400336 #endif
mtklein5b64dab2016-06-09 08:59:48 -0700337 fflush(stdout);
338
Mike Kleinca8087f2019-03-18 09:01:39 -0500339 if (sig == SIGINT && FLAGS_ignoreSigInt) {
340 info("Ignoring signal %d because of --ignoreSigInt.\n"
341 "This is probably a sign the bot is overloaded with work.\n", sig);
342 } else {
343 signal(sig, previous_handler[sig]);
344 raise(sig);
345 }
mtklein5b64dab2016-06-09 08:59:48 -0700346 }
347
mtklein246ba3a2016-02-23 10:39:36 -0800348 static void setup_crash_handler() {
Mike Klein701a3582018-06-28 14:08:19 +0000349 const int kSignals[] = { SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGINT, SIGSEGV, SIGTERM };
mtklein246ba3a2016-02-23 10:39:36 -0800350 for (int sig : kSignals) {
Mike Klein3cc2d202016-10-24 11:39:43 -0400351 previous_handler[sig] = signal(sig, crash_handler);
mtklein246ba3a2016-02-23 10:39:36 -0800352 }
353 }
354#endif
355
mtklein748ca3b2015-01-15 10:56:12 -0800356/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
mtklein114c3cd2015-01-15 10:15:02 -0800357
Brian Osman57796b32019-01-25 18:02:59 +0000358struct Gold : public SkString {
359 Gold() : SkString("") {}
360 Gold(const SkString& sink, const SkString& src,
361 const SkString& srcOptions, const SkString& name,
362 const SkString& md5)
363 : SkString("") {
364 this->append(sink);
365 this->append(src);
366 this->append(srcOptions);
367 this->append(name);
368 this->append(md5);
369 }
370 struct Hash {
371 uint32_t operator()(const Gold& g) const {
372 return SkGoodHash()((const SkString&)g);
373 }
374 };
375};
376static SkTHashSet<Gold, Gold::Hash> gGold;
377
378static void add_gold(JsonWriter::BitmapResult r) {
379 gGold.add(Gold(r.config, r.sourceType, r.sourceOptions, r.name, r.md5));
380}
381
382static void gather_gold() {
383 if (!FLAGS_readPath.isEmpty()) {
384 SkString path(FLAGS_readPath[0]);
385 path.append("/dm.json");
386 if (!JsonWriter::ReadJson(path.c_str(), add_gold)) {
387 fail(SkStringPrintf("Couldn't read %s for golden results.", path.c_str()));
388 }
389 }
390}
391
392/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
393
Mike Klein8f11d4d2018-01-24 12:42:55 -0500394#if defined(SK_BUILD_FOR_WIN)
mtklein935f1b12016-03-16 08:37:19 -0700395 static const char* kNewline = "\r\n";
396#else
397 static const char* kNewline = "\n";
398#endif
399
borenet09ed4802015-04-03 14:15:33 -0700400static SkTHashSet<SkString> gUninterestingHashes;
401
402static void gather_uninteresting_hashes() {
403 if (!FLAGS_uninterestingHashesFile.isEmpty()) {
bungeman38d909e2016-08-02 14:40:46 -0700404 sk_sp<SkData> data(SkData::MakeFromFileName(FLAGS_uninterestingHashesFile[0]));
mtkleincc334b32015-09-22 11:43:53 -0700405 if (!data) {
mtkleinc41fd922016-03-08 09:01:39 -0800406 info("WARNING: unable to read uninteresting hashes from %s\n",
407 FLAGS_uninterestingHashesFile[0]);
mtkleincc334b32015-09-22 11:43:53 -0700408 return;
409 }
Mike Klein45dcc0c2017-04-05 18:04:31 -0400410
411 // Copy to a string to make sure SkStrSplit has a terminating \0 to find.
412 SkString contents((const char*)data->data(), data->size());
413
borenet09ed4802015-04-03 14:15:33 -0700414 SkTArray<SkString> hashes;
Mike Klein45dcc0c2017-04-05 18:04:31 -0400415 SkStrSplit(contents.c_str(), kNewline, &hashes);
borenet09ed4802015-04-03 14:15:33 -0700416 for (const SkString& hash : hashes) {
417 gUninterestingHashes.add(hash);
418 }
mtkleinc41fd922016-03-08 09:01:39 -0800419 info("FYI: loaded %d distinct uninteresting hashes from %d lines\n",
420 gUninterestingHashes.count(), hashes.count());
borenet09ed4802015-04-03 14:15:33 -0700421 }
422}
423
424/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
425
Ben Wagner145dbcd2016-11-03 14:40:50 -0400426struct TaggedSrc : public std::unique_ptr<Src> {
mtklein3eed7dd2016-02-24 19:07:07 -0800427 SkString tag;
428 SkString options;
mtkleine0effd62015-07-29 06:37:28 -0700429};
430
Ben Wagner145dbcd2016-11-03 14:40:50 -0400431struct TaggedSink : public std::unique_ptr<Sink> {
kkinnunen3e980c32015-12-23 01:33:00 -0800432 SkString tag;
djsollen54416de2015-04-03 07:24:48 -0700433};
mtklein748ca3b2015-01-15 10:56:12 -0800434
435static const bool kMemcpyOK = true;
436
mtkleine0effd62015-07-29 06:37:28 -0700437static SkTArray<TaggedSrc, kMemcpyOK> gSrcs;
438static SkTArray<TaggedSink, kMemcpyOK> gSinks;
mtklein748ca3b2015-01-15 10:56:12 -0800439
mtklein6393c062015-04-27 08:45:01 -0700440static bool in_shard() {
441 static int N = 0;
442 return N++ % FLAGS_shards == FLAGS_shard;
443}
444
mtklein3eed7dd2016-02-24 19:07:07 -0800445static void push_src(const char* tag, ImplicitString options, Src* s) {
Ben Wagner145dbcd2016-11-03 14:40:50 -0400446 std::unique_ptr<Src> src(s);
Mike Klein88544fb2019-03-20 10:50:33 -0500447 if (in_shard() && FLAGS_src.contains(tag) &&
448 !CommandLineFlags::ShouldSkip(FLAGS_match, src->name().c_str())) {
mtkleine0effd62015-07-29 06:37:28 -0700449 TaggedSrc& s = gSrcs.push_back();
mtklein18300a32016-03-16 13:53:35 -0700450 s.reset(src.release());
mtklein748ca3b2015-01-15 10:56:12 -0800451 s.tag = tag;
djsollen54416de2015-04-03 07:24:48 -0700452 s.options = options;
mtklein114c3cd2015-01-15 10:15:02 -0800453 }
mtklein748ca3b2015-01-15 10:56:12 -0800454}
mtklein114c3cd2015-01-15 10:15:02 -0800455
msarett9e707a02015-09-01 14:57:57 -0700456static void push_codec_src(Path path, CodecSrc::Mode mode, CodecSrc::DstColorType dstColorType,
scroggoc5560be2016-02-03 09:42:42 -0800457 SkAlphaType dstAlphaType, float scale) {
scroggoe4499842016-02-25 11:03:47 -0800458 if (FLAGS_simpleCodec) {
scroggo19b91532016-10-24 09:03:26 -0700459 const bool simple = CodecSrc::kCodec_Mode == mode || CodecSrc::kAnimated_Mode == mode;
460 if (!simple || dstColorType != CodecSrc::kGetFromCanvas_DstColorType || scale != 1.0f) {
scroggoe4499842016-02-25 11:03:47 -0800461 // Only decode in the simple case.
462 return;
scroggo19b91532016-10-24 09:03:26 -0700463 }
scroggoe4499842016-02-25 11:03:47 -0800464 }
msarett9e707a02015-09-01 14:57:57 -0700465 SkString folder;
466 switch (mode) {
467 case CodecSrc::kCodec_Mode:
468 folder.append("codec");
469 break;
msarettbb25b532016-01-13 09:31:39 -0800470 case CodecSrc::kCodecZeroInit_Mode:
471 folder.append("codec_zero_init");
472 break;
msarett9e707a02015-09-01 14:57:57 -0700473 case CodecSrc::kScanline_Mode:
474 folder.append("scanline");
475 break;
msarett9e707a02015-09-01 14:57:57 -0700476 case CodecSrc::kStripe_Mode:
477 folder.append("stripe");
478 break;
msarett91c22b22016-02-22 12:27:46 -0800479 case CodecSrc::kCroppedScanline_Mode:
480 folder.append("crop");
481 break;
msarett9e707a02015-09-01 14:57:57 -0700482 case CodecSrc::kSubset_Mode:
msarett36c37962015-09-02 13:20:52 -0700483 folder.append("codec_subset");
msarett9e707a02015-09-01 14:57:57 -0700484 break;
scroggo19b91532016-10-24 09:03:26 -0700485 case CodecSrc::kAnimated_Mode:
486 folder.append("codec_animated");
487 break;
msarett9e707a02015-09-01 14:57:57 -0700488 }
489
490 switch (dstColorType) {
491 case CodecSrc::kGrayscale_Always_DstColorType:
492 folder.append("_kGray8");
493 break;
msarett34e0ec42016-04-22 16:27:24 -0700494 case CodecSrc::kNonNative8888_Always_DstColorType:
495 folder.append("_kNonNative");
496 break;
msarett9e707a02015-09-01 14:57:57 -0700497 default:
498 break;
499 }
500
scroggoc5560be2016-02-03 09:42:42 -0800501 switch (dstAlphaType) {
scroggoc5560be2016-02-03 09:42:42 -0800502 case kPremul_SkAlphaType:
503 folder.append("_premul");
504 break;
505 case kUnpremul_SkAlphaType:
506 folder.append("_unpremul");
507 break;
508 default:
509 break;
510 }
511
msarett9e707a02015-09-01 14:57:57 -0700512 if (1.0f != scale) {
513 folder.appendf("_%.3f", scale);
514 }
515
scroggoc5560be2016-02-03 09:42:42 -0800516 CodecSrc* src = new CodecSrc(path, mode, dstColorType, dstAlphaType, scale);
msarett9e707a02015-09-01 14:57:57 -0700517 push_src("image", folder, src);
518}
519
scroggof8dc9df2016-05-16 09:04:13 -0700520static void push_android_codec_src(Path path, CodecSrc::DstColorType dstColorType,
521 SkAlphaType dstAlphaType, int sampleSize) {
msarett3d9d7a72015-10-21 10:27:10 -0700522 SkString folder;
scroggof8dc9df2016-05-16 09:04:13 -0700523 folder.append("scaled_codec");
msarett3d9d7a72015-10-21 10:27:10 -0700524
525 switch (dstColorType) {
526 case CodecSrc::kGrayscale_Always_DstColorType:
527 folder.append("_kGray8");
528 break;
msarett34e0ec42016-04-22 16:27:24 -0700529 case CodecSrc::kNonNative8888_Always_DstColorType:
530 folder.append("_kNonNative");
531 break;
msarett3d9d7a72015-10-21 10:27:10 -0700532 default:
533 break;
534 }
535
scroggoc5560be2016-02-03 09:42:42 -0800536 switch (dstAlphaType) {
scroggoc5560be2016-02-03 09:42:42 -0800537 case kPremul_SkAlphaType:
538 folder.append("_premul");
539 break;
msarett9e9444c2016-02-03 12:39:10 -0800540 case kUnpremul_SkAlphaType:
541 folder.append("_unpremul");
542 break;
scroggoc5560be2016-02-03 09:42:42 -0800543 default:
544 break;
545 }
546
msarett3d9d7a72015-10-21 10:27:10 -0700547 if (1 != sampleSize) {
msarett4b0778e2015-11-13 09:59:11 -0800548 folder.appendf("_%.3f", 1.0f / (float) sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700549 }
550
scroggof8dc9df2016-05-16 09:04:13 -0700551 AndroidCodecSrc* src = new AndroidCodecSrc(path, dstColorType, dstAlphaType, sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700552 push_src("image", folder, src);
553}
554
msarett18976312016-03-09 14:20:58 -0800555static void push_image_gen_src(Path path, ImageGenSrc::Mode mode, SkAlphaType alphaType, bool isGpu)
556{
557 SkString folder;
558 switch (mode) {
559 case ImageGenSrc::kCodec_Mode:
560 folder.append("gen_codec");
561 break;
562 case ImageGenSrc::kPlatform_Mode:
563 folder.append("gen_platform");
564 break;
565 }
566
567 if (isGpu) {
568 folder.append("_gpu");
569 } else {
570 switch (alphaType) {
571 case kOpaque_SkAlphaType:
572 folder.append("_opaque");
573 break;
574 case kPremul_SkAlphaType:
575 folder.append("_premul");
576 break;
577 case kUnpremul_SkAlphaType:
578 folder.append("_unpremul");
579 break;
580 default:
581 break;
582 }
583 }
584
585 ImageGenSrc* src = new ImageGenSrc(path, mode, alphaType, isGpu);
586 push_src("image", folder, src);
587}
588
Leon Scroggins III07418182017-08-15 12:24:02 -0400589static void push_brd_src(Path path, CodecSrc::DstColorType dstColorType, BRDSrc::Mode mode,
590 uint32_t sampleSize) {
591 SkString folder("brd_android_codec");
592 switch (mode) {
593 case BRDSrc::kFullImage_Mode:
594 break;
595 case BRDSrc::kDivisor_Mode:
596 folder.append("_divisor");
597 break;
598 default:
599 SkASSERT(false);
600 return;
601 }
602
603 switch (dstColorType) {
604 case CodecSrc::kGetFromCanvas_DstColorType:
605 break;
606 case CodecSrc::kGrayscale_Always_DstColorType:
607 folder.append("_kGray");
608 break;
609 default:
610 SkASSERT(false);
611 return;
612 }
613
614 if (1 != sampleSize) {
615 folder.appendf("_%.3f", 1.0f / (float) sampleSize);
616 }
617
618 BRDSrc* src = new BRDSrc(path, mode, dstColorType, sampleSize);
619 push_src("image", folder, src);
620}
621
622static void push_brd_srcs(Path path, bool gray) {
623 if (gray) {
624 // Only run grayscale to one sampleSize and Mode. Though interesting
625 // to test grayscale, it should not reveal anything across various
626 // sampleSizes and Modes
627 // Arbitrarily choose Mode and sampleSize.
628 push_brd_src(path, CodecSrc::kGrayscale_Always_DstColorType,
629 BRDSrc::kFullImage_Mode, 2);
630 }
631
632 // Test on a variety of sampleSizes, making sure to include:
633 // - 2, 4, and 8, which are natively supported by jpeg
634 // - multiples of 2 which are not divisible by 4 (analogous for 4)
635 // - larger powers of two, since BRD clients generally use powers of 2
636 // We will only produce output for the larger sizes on large images.
637 const uint32_t sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 24, 32, 64 };
638
639 const BRDSrc::Mode modes[] = { BRDSrc::kFullImage_Mode, BRDSrc::kDivisor_Mode, };
640
641 for (uint32_t sampleSize : sampleSizes) {
642 for (BRDSrc::Mode mode : modes) {
643 push_brd_src(path, CodecSrc::kGetFromCanvas_DstColorType, mode, sampleSize);
644 }
645 }
646}
647
msarett438b2ad2015-04-09 12:43:10 -0700648static void push_codec_srcs(Path path) {
bungeman38d909e2016-08-02 14:40:46 -0700649 sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str()));
msarett438b2ad2015-04-09 12:43:10 -0700650 if (!encoded) {
mtkleinc41fd922016-03-08 09:01:39 -0800651 info("Couldn't read %s.", path.c_str());
msarett438b2ad2015-04-09 12:43:10 -0700652 return;
653 }
Mike Reedede7bac2017-07-23 15:30:02 -0400654 std::unique_ptr<SkCodec> codec = SkCodec::MakeFromData(encoded);
halcanary96fcdcc2015-08-27 07:41:13 -0700655 if (nullptr == codec.get()) {
mtkleinc41fd922016-03-08 09:01:39 -0800656 info("Couldn't create codec for %s.", path.c_str());
msarett438b2ad2015-04-09 12:43:10 -0700657 return;
658 }
659
scroggo9366aff2016-05-20 08:38:54 -0700660 // native scaling is only supported by WEBP and JPEG
661 bool supportsNativeScaling = false;
msarett438b2ad2015-04-09 12:43:10 -0700662
msarett91c22b22016-02-22 12:27:46 -0800663 SkTArray<CodecSrc::Mode> nativeModes;
664 nativeModes.push_back(CodecSrc::kCodec_Mode);
665 nativeModes.push_back(CodecSrc::kCodecZeroInit_Mode);
msarett91c22b22016-02-22 12:27:46 -0800666 switch (codec->getEncodedFormat()) {
Hal Canarydb683012016-11-23 08:55:18 -0700667 case SkEncodedImageFormat::kJPEG:
msarett91c22b22016-02-22 12:27:46 -0800668 nativeModes.push_back(CodecSrc::kScanline_Mode);
669 nativeModes.push_back(CodecSrc::kStripe_Mode);
670 nativeModes.push_back(CodecSrc::kCroppedScanline_Mode);
scroggo9366aff2016-05-20 08:38:54 -0700671 supportsNativeScaling = true;
msarett91c22b22016-02-22 12:27:46 -0800672 break;
Hal Canarydb683012016-11-23 08:55:18 -0700673 case SkEncodedImageFormat::kWEBP:
msarett91c22b22016-02-22 12:27:46 -0800674 nativeModes.push_back(CodecSrc::kSubset_Mode);
scroggo9366aff2016-05-20 08:38:54 -0700675 supportsNativeScaling = true;
msarett91c22b22016-02-22 12:27:46 -0800676 break;
Hal Canarydb683012016-11-23 08:55:18 -0700677 case SkEncodedImageFormat::kDNG:
msarettb65e6042016-02-23 05:37:25 -0800678 break;
msarett91c22b22016-02-22 12:27:46 -0800679 default:
680 nativeModes.push_back(CodecSrc::kScanline_Mode);
msarett91c22b22016-02-22 12:27:46 -0800681 break;
682 }
msarett9e707a02015-09-01 14:57:57 -0700683
msarett91c22b22016-02-22 12:27:46 -0800684 SkTArray<CodecSrc::DstColorType> colorTypes;
685 colorTypes.push_back(CodecSrc::kGetFromCanvas_DstColorType);
msarett34e0ec42016-04-22 16:27:24 -0700686 colorTypes.push_back(CodecSrc::kNonNative8888_Always_DstColorType);
msarett36c37962015-09-02 13:20:52 -0700687 switch (codec->getInfo().colorType()) {
688 case kGray_8_SkColorType:
msarett91c22b22016-02-22 12:27:46 -0800689 colorTypes.push_back(CodecSrc::kGrayscale_Always_DstColorType);
msarett36c37962015-09-02 13:20:52 -0700690 break;
691 default:
msarett36c37962015-09-02 13:20:52 -0700692 break;
693 }
msarett9e707a02015-09-01 14:57:57 -0700694
scroggoc5560be2016-02-03 09:42:42 -0800695 SkTArray<SkAlphaType> alphaModes;
696 alphaModes.push_back(kPremul_SkAlphaType);
scroggof2c96a22016-05-20 11:08:27 -0700697 if (codec->getInfo().alphaType() != kOpaque_SkAlphaType) {
698 alphaModes.push_back(kUnpremul_SkAlphaType);
scroggoc5560be2016-02-03 09:42:42 -0800699 }
msarettb714fb02016-01-22 14:46:42 -0800700
701 for (CodecSrc::Mode mode : nativeModes) {
scroggo9366aff2016-05-20 08:38:54 -0700702 for (CodecSrc::DstColorType colorType : colorTypes) {
703 for (SkAlphaType alphaType : alphaModes) {
scroggof2c96a22016-05-20 11:08:27 -0700704 // Only test kCroppedScanline_Mode when the alpha type is premul. The test is
scroggo9366aff2016-05-20 08:38:54 -0700705 // slow and won't be interestingly different with different alpha types.
706 if (CodecSrc::kCroppedScanline_Mode == mode &&
scroggof2c96a22016-05-20 11:08:27 -0700707 kPremul_SkAlphaType != alphaType) {
scroggo9366aff2016-05-20 08:38:54 -0700708 continue;
709 }
msarett91c22b22016-02-22 12:27:46 -0800710
scroggo9366aff2016-05-20 08:38:54 -0700711 push_codec_src(path, mode, colorType, alphaType, 1.0f);
msarettf3dc1882016-04-26 13:06:38 -0700712
scroggo9366aff2016-05-20 08:38:54 -0700713 // Skip kNonNative on different native scales. It won't be interestingly
714 // different.
715 if (supportsNativeScaling &&
716 CodecSrc::kNonNative8888_Always_DstColorType == colorType) {
717 // Native Scales
718 // SkJpegCodec natively supports scaling to the following:
719 for (auto scale : { 0.125f, 0.25f, 0.375f, 0.5f, 0.625f, 0.750f, 0.875f }) {
720 push_codec_src(path, mode, colorType, alphaType, scale);
721 }
scroggoc5560be2016-02-03 09:42:42 -0800722 }
msarett9e707a02015-09-01 14:57:57 -0700723 }
724 }
msarett0a242972015-06-11 14:27:27 -0700725 }
msarett36c37962015-09-02 13:20:52 -0700726
scroggo19b91532016-10-24 09:03:26 -0700727 {
728 std::vector<SkCodec::FrameInfo> frameInfos = codec->getFrameInfo();
729 if (frameInfos.size() > 1) {
Leon Scroggins III557fbbe2017-05-23 09:37:21 -0400730 for (auto dstCT : { CodecSrc::kNonNative8888_Always_DstColorType,
731 CodecSrc::kGetFromCanvas_DstColorType }) {
732 for (auto at : { kUnpremul_SkAlphaType, kPremul_SkAlphaType }) {
733 push_codec_src(path, CodecSrc::kAnimated_Mode, dstCT, at, 1.0f);
734 }
735 }
scroggo19b91532016-10-24 09:03:26 -0700736 }
737
738 }
739
scroggoe4499842016-02-25 11:03:47 -0800740 if (FLAGS_simpleCodec) {
741 return;
742 }
743
msarett3d9d7a72015-10-21 10:27:10 -0700744 const int sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
msarett36c37962015-09-02 13:20:52 -0700745
msarett3d9d7a72015-10-21 10:27:10 -0700746 for (int sampleSize : sampleSizes) {
msarett91c22b22016-02-22 12:27:46 -0800747 for (CodecSrc::DstColorType colorType : colorTypes) {
scroggoc5560be2016-02-03 09:42:42 -0800748 for (SkAlphaType alphaType : alphaModes) {
msarettf3dc1882016-04-26 13:06:38 -0700749 // We can exercise all of the kNonNative support code in the swizzler with just a
750 // few sample sizes. Skip the rest.
751 if (CodecSrc::kNonNative8888_Always_DstColorType == colorType && sampleSize > 3) {
752 continue;
753 }
754
scroggof8dc9df2016-05-16 09:04:13 -0700755 push_android_codec_src(path, colorType, alphaType, sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700756 }
msarett36c37962015-09-02 13:20:52 -0700757 }
758 }
msarett18976312016-03-09 14:20:58 -0800759
Leon Scroggins III07418182017-08-15 12:24:02 -0400760 const char* ext = strrchr(path.c_str(), '.');
761 if (ext) {
762 ext++;
msarett18976312016-03-09 14:20:58 -0800763
Leon Scroggins III07418182017-08-15 12:24:02 -0400764 static const char* const rawExts[] = {
765 "arw", "cr2", "dng", "nef", "nrw", "orf", "raf", "rw2", "pef", "srw",
766 "ARW", "CR2", "DNG", "NEF", "NRW", "ORF", "RAF", "RW2", "PEF", "SRW",
767 };
768 for (const char* rawExt : rawExts) {
769 if (0 == strcmp(rawExt, ext)) {
770 // RAW is not supported by image generator (skbug.com/5079) or BRD.
771 return;
772 }
773 }
774
775 static const char* const brdExts[] = {
776 "jpg", "jpeg", "png", "webp",
777 "JPG", "JPEG", "PNG", "WEBP",
778 };
779 for (const char* brdExt : brdExts) {
780 if (0 == strcmp(brdExt, ext)) {
Leon Scroggins IIIc8037dc2017-12-05 13:55:24 -0500781 bool gray = codec->getInfo().colorType() == kGray_8_SkColorType;
Leon Scroggins III07418182017-08-15 12:24:02 -0400782 push_brd_srcs(path, gray);
783 break;
784 }
msarett18976312016-03-09 14:20:58 -0800785 }
786 }
787
788 // Push image generator GPU test.
brianosmanc9ced392016-03-24 07:27:43 -0700789 push_image_gen_src(path, ImageGenSrc::kCodec_Mode, codec->getInfo().alphaType(), true);
msarett18976312016-03-09 14:20:58 -0800790
791 // Push image generator CPU tests.
792 for (SkAlphaType alphaType : alphaModes) {
793 push_image_gen_src(path, ImageGenSrc::kCodec_Mode, alphaType, false);
794
795#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
Hal Canarydb683012016-11-23 08:55:18 -0700796 if (SkEncodedImageFormat::kWEBP != codec->getEncodedFormat() &&
797 SkEncodedImageFormat::kWBMP != codec->getEncodedFormat() &&
msarett18976312016-03-09 14:20:58 -0800798 kUnpremul_SkAlphaType != alphaType)
799 {
800 push_image_gen_src(path, ImageGenSrc::kPlatform_Mode, alphaType, false);
801 }
msarettfc0b6d12016-03-17 13:50:17 -0700802#elif defined(SK_BUILD_FOR_WIN)
Hal Canarydb683012016-11-23 08:55:18 -0700803 if (SkEncodedImageFormat::kWEBP != codec->getEncodedFormat() &&
804 SkEncodedImageFormat::kWBMP != codec->getEncodedFormat())
msarettfc0b6d12016-03-17 13:50:17 -0700805 {
806 push_image_gen_src(path, ImageGenSrc::kPlatform_Mode, alphaType, false);
807 }
msarett18976312016-03-09 14:20:58 -0800808#endif
809 }
msarett438b2ad2015-04-09 12:43:10 -0700810}
811
fmalitaa2b9fdf2016-08-03 19:53:36 -0700812template <typename T>
Mike Klein88544fb2019-03-20 10:50:33 -0500813void gather_file_srcs(const CommandLineFlags::StringArray& flags,
814 const char* ext,
815 const char* src_name = nullptr) {
Florin Malitaf1ba3ae2018-07-19 15:09:11 -0400816 if (!src_name) {
817 // With the exception of Lottie files, the source name is the extension.
818 src_name = ext;
819 }
820
fmalitaa2b9fdf2016-08-03 19:53:36 -0700821 for (int i = 0; i < flags.count(); i++) {
822 const char* path = flags[i];
823 if (sk_isdir(path)) {
824 SkOSFile::Iter it(path, ext);
825 for (SkString file; it.next(&file); ) {
Florin Malitaf1ba3ae2018-07-19 15:09:11 -0400826 push_src(src_name, "", new T(SkOSPath::Join(path, file.c_str())));
fmalitaa2b9fdf2016-08-03 19:53:36 -0700827 }
828 } else {
Florin Malitaf1ba3ae2018-07-19 15:09:11 -0400829 push_src(src_name, "", new T(path));
fmalitaa2b9fdf2016-08-03 19:53:36 -0700830 }
831 }
832}
833
scroggo86737142016-02-03 12:19:11 -0800834static bool gather_srcs() {
Hal Canary972eba32018-07-30 17:07:07 -0400835 for (skiagm::GMFactory f : skiagm::GMRegistry::Range()) {
836 push_src("gm", "", new GMSrc(f));
mtklein748ca3b2015-01-15 10:56:12 -0800837 }
scroggo86737142016-02-03 12:19:11 -0800838
Robert Phillipse47f0a02018-03-27 17:01:16 -0400839 gather_file_srcs<SKPSrc>(FLAGS_skps, "skp");
fmalitaa2b9fdf2016-08-03 19:53:36 -0700840 gather_file_srcs<MSKPSrc>(FLAGS_mskps, "mskp");
Florin Malita87ccf332018-05-04 12:23:24 -0400841#if defined(SK_ENABLE_SKOTTIE)
Florin Malitaf1ba3ae2018-07-19 15:09:11 -0400842 gather_file_srcs<SkottieSrc>(FLAGS_lotties, "json", "lottie");
Florin Malita124d5af2017-12-31 17:02:26 -0500843#endif
fmalitaa2b9fdf2016-08-03 19:53:36 -0700844#if defined(SK_XML)
845 gather_file_srcs<SVGSrc>(FLAGS_svgs, "svg");
846#endif
Chris Dalton184c37e2018-09-28 11:27:39 -0600847 if (!FLAGS_bisect.isEmpty()) {
848 // An empty l/r trail string will draw all the paths.
849 push_src("bisect", "",
850 new BisectSrc(FLAGS_bisect[0], FLAGS_bisect.count() > 1 ? FLAGS_bisect[1] : ""));
851 }
halcanary45420a92016-06-02 12:41:14 -0700852
scroggo86737142016-02-03 12:19:11 -0800853 SkTArray<SkString> images;
msarett69deca82016-04-29 09:38:40 -0700854 if (!CollectImages(FLAGS_images, &images)) {
scroggo86737142016-02-03 12:19:11 -0800855 return false;
856 }
857
858 for (auto image : images) {
859 push_codec_srcs(image);
mtklein709d2c32015-01-15 08:30:25 -0800860 }
scroggo86737142016-02-03 12:19:11 -0800861
msarett69deca82016-04-29 09:38:40 -0700862 SkTArray<SkString> colorImages;
863 if (!CollectImages(FLAGS_colorImages, &colorImages)) {
864 return false;
865 }
866
867 for (auto colorImage : colorImages) {
Mike Klein0d5d1422019-03-06 10:56:04 -0600868 push_src("colorImage", "decode_native", new ColorCodecSrc(colorImage, false));
869 push_src("colorImage", "decode_to_dst", new ColorCodecSrc(colorImage, true));
msarett69deca82016-04-29 09:38:40 -0700870 }
871
scroggo86737142016-02-03 12:19:11 -0800872 return true;
mtklein709d2c32015-01-15 08:30:25 -0800873}
874
kkinnunen3e980c32015-12-23 01:33:00 -0800875static void push_sink(const SkCommandLineConfig& config, Sink* s) {
Ben Wagner145dbcd2016-11-03 14:40:50 -0400876 std::unique_ptr<Sink> sink(s);
kkinnunen3e980c32015-12-23 01:33:00 -0800877
mtkleine0effd62015-07-29 06:37:28 -0700878 // Try a simple Src as a canary. If it fails, skip this sink.
mtklein748ca3b2015-01-15 10:56:12 -0800879 struct : public Src {
mtkleine0effd62015-07-29 06:37:28 -0700880 Error draw(SkCanvas* c) const override {
881 c->drawRect(SkRect::MakeWH(1,1), SkPaint());
882 return "";
883 }
mtklein36352bf2015-03-25 18:17:31 -0700884 SkISize size() const override { return SkISize::Make(16, 16); }
mtkleine0effd62015-07-29 06:37:28 -0700885 Name name() const override { return "justOneRect"; }
886 } justOneRect;
mtklein114c3cd2015-01-15 10:15:02 -0800887
mtklein748ca3b2015-01-15 10:56:12 -0800888 SkBitmap bitmap;
889 SkDynamicMemoryWStream stream;
mtkleinb9eb4ac2015-02-02 18:26:03 -0800890 SkString log;
mtkleine0effd62015-07-29 06:37:28 -0700891 Error err = sink->draw(justOneRect, &bitmap, &stream, &log);
mtklein4089ef72015-03-05 08:40:28 -0800892 if (err.isFatal()) {
mtkleinc41fd922016-03-08 09:01:39 -0800893 info("Could not run %s: %s\n", config.getTag().c_str(), err.c_str());
mtklein05641a52015-04-21 10:49:13 -0700894 exit(1);
mtklein114c3cd2015-01-15 10:15:02 -0800895 }
896
mtkleine0effd62015-07-29 06:37:28 -0700897 TaggedSink& ts = gSinks.push_back();
mtklein18300a32016-03-16 13:53:35 -0700898 ts.reset(sink.release());
kkinnunen3e980c32015-12-23 01:33:00 -0800899 ts.tag = config.getTag();
mtklein748ca3b2015-01-15 10:56:12 -0800900}
901
Mike Kleinc7a09162019-02-19 06:14:39 -0500902static sk_sp<SkColorSpace> rgb_to_gbr() {
903 return SkColorSpace::MakeSRGB()->makeColorSpin();
904}
905
csmartdalton008b9d82017-02-22 12:00:42 -0700906static Sink* create_sink(const GrContextOptions& grCtxOptions, const SkCommandLineConfig* config) {
Brian Osmanc7ad40f2018-05-31 14:27:17 -0400907 if (FLAGS_gpu) {
kkinnunen3e980c32015-12-23 01:33:00 -0800908 if (const SkCommandLineConfigGpu* gpuConfig = config->asConfigGpu()) {
bsalomon85b4b532016-04-05 11:06:27 -0700909 GrContextFactory::ContextType contextType = gpuConfig->getContextType();
csmartdaltone812d492017-02-21 12:36:05 -0700910 GrContextFactory::ContextOverrides contextOverrides = gpuConfig->getContextOverrides();
csmartdalton008b9d82017-02-22 12:00:42 -0700911 GrContextFactory testFactory(grCtxOptions);
csmartdaltone812d492017-02-21 12:36:05 -0700912 if (!testFactory.get(contextType, contextOverrides)) {
mtkleinc41fd922016-03-08 09:01:39 -0800913 info("WARNING: can not create GPU context for config '%s'. "
914 "GM tests will be skipped.\n", gpuConfig->getTag().c_str());
kkinnunen3e980c32015-12-23 01:33:00 -0800915 return nullptr;
916 }
Brian Osmanf9810662017-08-30 10:02:10 -0400917 if (gpuConfig->getTestThreading()) {
Brian Salomon00a5eb82018-07-11 15:32:05 -0400918 SkASSERT(!gpuConfig->getTestPersistentCache());
Brian Salomonf865b052018-03-09 09:01:53 -0500919 return new GPUThreadTestingSink(
920 contextType, contextOverrides, gpuConfig->getSurfType(),
921 gpuConfig->getSamples(), gpuConfig->getUseDIText(),
922 gpuConfig->getColorType(), gpuConfig->getAlphaType(),
923 sk_ref_sp(gpuConfig->getColorSpace()), FLAGS_gpu_threading, grCtxOptions);
Brian Salomon00a5eb82018-07-11 15:32:05 -0400924 } else if (gpuConfig->getTestPersistentCache()) {
925 return new GPUPersistentCacheTestingSink(
926 contextType, contextOverrides, gpuConfig->getSurfType(),
927 gpuConfig->getSamples(), gpuConfig->getUseDIText(),
928 gpuConfig->getColorType(), gpuConfig->getAlphaType(),
Brian Osmanf71b0702019-04-03 13:04:16 -0400929 sk_ref_sp(gpuConfig->getColorSpace()), FLAGS_gpu_threading, grCtxOptions,
930 gpuConfig->getTestPersistentCache());
Brian Osmanf9810662017-08-30 10:02:10 -0400931 } else {
Brian Salomonf865b052018-03-09 09:01:53 -0500932 return new GPUSink(contextType, contextOverrides, gpuConfig->getSurfType(),
933 gpuConfig->getSamples(), gpuConfig->getUseDIText(),
934 gpuConfig->getColorType(), gpuConfig->getAlphaType(),
935 sk_ref_sp(gpuConfig->getColorSpace()), FLAGS_gpu_threading,
936 grCtxOptions);
Brian Osmanf9810662017-08-30 10:02:10 -0400937 }
kkinnunen3e980c32015-12-23 01:33:00 -0800938 }
939 }
Bryce Thomas95a7b762018-03-02 13:54:21 -0800940 if (const SkCommandLineConfigSvg* svgConfig = config->asConfigSvg()) {
941 int pageIndex = svgConfig->getPageIndex();
942 return new SVGSink(pageIndex);
943 }
kkinnunen3e980c32015-12-23 01:33:00 -0800944
Brian Salomon23356442018-11-30 15:33:19 -0500945#define SINK(t, sink, ...) if (config->getBackend().equals(t)) return new sink(__VA_ARGS__)
kkinnunen3e980c32015-12-23 01:33:00 -0800946
mtklein748ca3b2015-01-15 10:56:12 -0800947 if (FLAGS_cpu) {
Mike Klein515bda62018-01-09 11:21:58 -0500948 SINK("g8", RasterSink, kGray_8_SkColorType);
Matt Sarettd2228302017-03-02 08:53:46 -0500949 SINK("565", RasterSink, kRGB_565_SkColorType);
Mike Klein5340b3f2018-01-24 13:42:05 -0500950 SINK("4444", RasterSink, kARGB_4444_SkColorType);
Matt Sarettd2228302017-03-02 08:53:46 -0500951 SINK("8888", RasterSink, kN32_SkColorType);
Mike Kleinac568a92018-01-25 09:09:32 -0500952 SINK("rgba", RasterSink, kRGBA_8888_SkColorType);
953 SINK("bgra", RasterSink, kBGRA_8888_SkColorType);
954 SINK("rgbx", RasterSink, kRGB_888x_SkColorType);
955 SINK("1010102", RasterSink, kRGBA_1010102_SkColorType);
956 SINK("101010x", RasterSink, kRGB_101010x_SkColorType);
Hal Canaryc7d295e2017-07-20 15:36:00 -0400957 SINK("pdf", PDFSink, false, SK_ScalarDefaultRasterDPI);
Matt Sarettd2228302017-03-02 08:53:46 -0500958 SINK("skp", SKPSink);
Matt Sarettd2228302017-03-02 08:53:46 -0500959 SINK("svg", SVGSink);
960 SINK("null", NullSink);
961 SINK("xps", XPSSink);
Hal Canaryc7d295e2017-07-20 15:36:00 -0400962 SINK("pdfa", PDFSink, true, SK_ScalarDefaultRasterDPI);
963 SINK("pdf300", PDFSink, false, 300);
Hal Canary85c7fe82016-10-25 10:33:27 -0400964 SINK("jsdebug", DebugSink);
Mike Klein0e4041f2018-06-19 16:00:40 -0400965
966 // Configs relevant to color management testing (and 8888 for reference).
967
968 // 'narrow' has a gamut narrower than sRGB, and different transfer function.
Brian Osman82ebe042019-01-04 17:03:00 -0500969 auto narrow = SkColorSpace::MakeRGB(SkNamedTransferFn::k2Dot2, gNarrow_toXYZD50),
Mike Klein0e4041f2018-06-19 16:00:40 -0400970 srgb = SkColorSpace::MakeSRGB(),
Mike Klein4de05072018-08-16 09:09:14 -0400971 srgbLinear = SkColorSpace::MakeSRGBLinear(),
Brian Osman82ebe042019-01-04 17:03:00 -0500972 p3 = SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, SkNamedGamut::kDCIP3);
Mike Klein0e4041f2018-06-19 16:00:40 -0400973
Mike Kleinff6a73c2018-08-17 16:19:24 -0400974 SINK( "f16", RasterSink, kRGBA_F16_SkColorType, srgbLinear);
975 SINK( "srgb", RasterSink, kRGBA_8888_SkColorType, srgb );
976 SINK( "esrgb", RasterSink, kRGBA_F16_SkColorType, srgb );
Mike Kleinc7a09162019-02-19 06:14:39 -0500977 SINK( "esgbr", RasterSink, kRGBA_F16_SkColorType, rgb_to_gbr());
Mike Kleinff6a73c2018-08-17 16:19:24 -0400978 SINK( "narrow", RasterSink, kRGBA_8888_SkColorType, narrow );
979 SINK( "enarrow", RasterSink, kRGBA_F16_SkColorType, narrow );
980 SINK( "p3", RasterSink, kRGBA_8888_SkColorType, p3 );
981 SINK( "ep3", RasterSink, kRGBA_F16_SkColorType, p3 );
Mike Kleinae4b1f42018-09-13 11:13:15 -0400982 SINK( "rec2020", RasterSink, kRGBA_8888_SkColorType, rec2020() );
983 SINK("erec2020", RasterSink, kRGBA_F16_SkColorType, rec2020() );
Mike Klein37854712018-06-26 11:43:06 -0400984
Mike Kleinb70990e2019-02-28 10:03:27 -0600985 SINK("f16norm", RasterSink, kRGBA_F16Norm_SkColorType, srgb);
986
Mike Klein37854712018-06-26 11:43:06 -0400987 SINK( "f32", RasterSink, kRGBA_F32_SkColorType, srgbLinear);
mtklein748ca3b2015-01-15 10:56:12 -0800988 }
989#undef SINK
halcanary96fcdcc2015-08-27 07:41:13 -0700990 return nullptr;
mtklein114c3cd2015-01-15 10:15:02 -0800991}
992
kkinnunen3e980c32015-12-23 01:33:00 -0800993static Sink* create_via(const SkString& tag, Sink* wrapped) {
Brian Salomon23356442018-11-30 15:33:19 -0500994#define VIA(t, via, ...) if (tag.equals(t)) return new via(__VA_ARGS__)
Mike Reedbae888e2017-02-18 16:50:45 -0500995#ifdef TEST_VIA_SVG
Mike Reedf67c4592017-02-17 17:06:11 -0500996 VIA("svg", ViaSVG, wrapped);
Mike Reedbae888e2017-02-18 16:50:45 -0500997#endif
halcanary96fcdcc2015-08-27 07:41:13 -0700998 VIA("serialize", ViaSerialization, wrapped);
mtklein4a34ecb2016-01-08 10:19:35 -0800999 VIA("pic", ViaPicture, wrapped);
halcanary96fcdcc2015-08-27 07:41:13 -07001000 VIA("tiles", ViaTiles, 256, 256, nullptr, wrapped);
mtklein7edca212015-01-21 13:18:51 -08001001 VIA("tiles_rt", ViaTiles, 256, 256, new SkRTreeFactory, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -08001002
Brian Salomon57904202018-12-17 14:45:00 -05001003 VIA("ddl", ViaDDL, 1, 3, wrapped);
1004 VIA("ddl2", ViaDDL, 2, 3, wrapped);
Robert Phillips33f02ed2018-03-27 08:06:57 -04001005
mtkleind603b222015-02-17 11:13:33 -08001006 if (FLAGS_matrix.count() == 4) {
mtklein748ca3b2015-01-15 10:56:12 -08001007 SkMatrix m;
mtkleind603b222015-02-17 11:13:33 -08001008 m.reset();
1009 m.setScaleX((SkScalar)atof(FLAGS_matrix[0]));
1010 m.setSkewX ((SkScalar)atof(FLAGS_matrix[1]));
1011 m.setSkewY ((SkScalar)atof(FLAGS_matrix[2]));
1012 m.setScaleY((SkScalar)atof(FLAGS_matrix[3]));
1013 VIA("matrix", ViaMatrix, m, wrapped);
1014 VIA("upright", ViaUpright, m, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -08001015 }
tomhudson64de1e12015-03-05 08:01:07 -08001016
mtklein748ca3b2015-01-15 10:56:12 -08001017#undef VIA
halcanary96fcdcc2015-08-27 07:41:13 -07001018 return nullptr;
mtklein114c3cd2015-01-15 10:15:02 -08001019}
1020
Ben Wagnerf28d4722017-08-11 17:33:22 -04001021static bool gather_sinks(const GrContextOptions& grCtxOptions, bool defaultConfigs) {
kkinnunen3e980c32015-12-23 01:33:00 -08001022 SkCommandLineConfigArray configs;
1023 ParseConfigs(FLAGS_config, &configs);
1024 for (int i = 0; i < configs.count(); i++) {
1025 const SkCommandLineConfig& config = *configs[i];
csmartdalton008b9d82017-02-22 12:00:42 -07001026 Sink* sink = create_sink(grCtxOptions, &config);
kkinnunen3e980c32015-12-23 01:33:00 -08001027 if (sink == nullptr) {
mtkleinc41fd922016-03-08 09:01:39 -08001028 info("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(),
1029 config.getTag().c_str());
kkinnunen3e980c32015-12-23 01:33:00 -08001030 continue;
1031 }
mtklein748ca3b2015-01-15 10:56:12 -08001032
kkinnunen3e980c32015-12-23 01:33:00 -08001033 const SkTArray<SkString>& parts = config.getViaParts();
1034 for (int j = parts.count(); j-- > 0;) {
1035 const SkString& part = parts[j];
1036 Sink* next = create_via(part, sink);
halcanary96fcdcc2015-08-27 07:41:13 -07001037 if (next == nullptr) {
mtkleinc41fd922016-03-08 09:01:39 -08001038 info("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(),
1039 part.c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001040 delete sink;
halcanary96fcdcc2015-08-27 07:41:13 -07001041 sink = nullptr;
mtklein748ca3b2015-01-15 10:56:12 -08001042 break;
1043 }
1044 sink = next;
1045 }
1046 if (sink) {
1047 push_sink(config, sink);
mtklein114c3cd2015-01-15 10:15:02 -08001048 }
1049 }
brianosman05c987c2016-05-09 13:42:16 -07001050
1051 // If no configs were requested (just running tests, perhaps?), then we're okay.
Ben Wagnerf28d4722017-08-11 17:33:22 -04001052 if (configs.count() == 0 ||
1053 // If we're using the default configs, we're okay.
1054 defaultConfigs ||
Ben Wagner32fa5102017-08-10 21:25:55 -04001055 // Otherwise, make sure that all specified configs have become sinks.
1056 configs.count() == gSinks.count()) {
1057 return true;
1058 }
Ben Wagner32fa5102017-08-10 21:25:55 -04001059 return false;
mtklein114c3cd2015-01-15 10:15:02 -08001060}
mtklein709d2c32015-01-15 08:30:25 -08001061
mtkleina2ef6422015-01-15 13:44:22 -08001062static bool match(const char* needle, const char* haystack) {
Chris Daltonecf78ac2017-08-15 15:43:08 -06001063 if ('~' == needle[0]) {
1064 return !match(needle + 1, haystack);
1065 }
1066 if (0 == strcmp("_", needle)) {
1067 return true;
1068 }
1069 return nullptr != strstr(haystack, needle);
mtkleina2ef6422015-01-15 13:44:22 -08001070}
1071
mtklein3eed7dd2016-02-24 19:07:07 -08001072static bool is_blacklisted(const char* sink, const char* src,
1073 const char* srcOptions, const char* name) {
mtklein0d243ff2015-04-03 07:51:00 -07001074 for (int i = 0; i < FLAGS_blacklist.count() - 3; i += 4) {
mtkleina2ef6422015-01-15 13:44:22 -08001075 if (match(FLAGS_blacklist[i+0], sink) &&
djsollen54416de2015-04-03 07:24:48 -07001076 match(FLAGS_blacklist[i+1], src) &&
1077 match(FLAGS_blacklist[i+2], srcOptions) &&
1078 match(FLAGS_blacklist[i+3], name)) {
mtklein3eed7dd2016-02-24 19:07:07 -08001079 return true;
mtkleina2ef6422015-01-15 13:44:22 -08001080 }
1081 }
mtklein3eed7dd2016-02-24 19:07:07 -08001082 return false;
mtkleina2ef6422015-01-15 13:44:22 -08001083}
1084
mtkleincd50bca2016-01-05 06:20:20 -08001085// Even when a Task Sink reports to be non-threadsafe (e.g. GPU), we know things like
1086// .png encoding are definitely thread safe. This lets us offload that work to CPU threads.
1087static SkTaskGroup gDefinitelyThreadSafeWork;
1088
mtklein748ca3b2015-01-15 10:56:12 -08001089// The finest-grained unit of work we can run: draw a single Src into a single Sink,
1090// report any errors, and perhaps write out the output: a .png of the bitmap, or a raw stream.
1091struct Task {
mtkleine0effd62015-07-29 06:37:28 -07001092 Task(const TaggedSrc& src, const TaggedSink& sink) : src(src), sink(sink) {}
1093 const TaggedSrc& src;
1094 const TaggedSink& sink;
mtklein748ca3b2015-01-15 10:56:12 -08001095
mtklein21eaf3b2016-02-08 12:39:59 -08001096 static void Run(const Task& task) {
1097 SkString name = task.src->name();
mtkleine0effd62015-07-29 06:37:28 -07001098
mtkleinb9eb4ac2015-02-02 18:26:03 -08001099 SkString log;
mtklein3eed7dd2016-02-24 19:07:07 -08001100 if (!FLAGS_dryRun) {
mtklein748ca3b2015-01-15 10:56:12 -08001101 SkBitmap bitmap;
1102 SkDynamicMemoryWStream stream;
mtklein3eed7dd2016-02-24 19:07:07 -08001103 start(task.sink.tag.c_str(), task.src.tag.c_str(),
1104 task.src.options.c_str(), name.c_str());
mtklein21eaf3b2016-02-08 12:39:59 -08001105 Error err = task.sink->draw(*task.src, &bitmap, &stream, &log);
mtkleinb3b13b72016-03-07 13:20:52 -08001106 if (!log.isEmpty()) {
mtkleinc41fd922016-03-08 09:01:39 -08001107 info("%s %s %s %s:\n%s\n", task.sink.tag.c_str()
1108 , task.src.tag.c_str()
1109 , task.src.options.c_str()
1110 , name.c_str()
1111 , log.c_str());
mtkleinb3b13b72016-03-07 13:20:52 -08001112 }
mtklein748ca3b2015-01-15 10:56:12 -08001113 if (!err.isEmpty()) {
mtklein4089ef72015-03-05 08:40:28 -08001114 if (err.isFatal()) {
djsollen54416de2015-04-03 07:24:48 -07001115 fail(SkStringPrintf("%s %s %s %s: %s",
mtklein21eaf3b2016-02-08 12:39:59 -08001116 task.sink.tag.c_str(),
1117 task.src.tag.c_str(),
1118 task.src.options.c_str(),
mtklein4089ef72015-03-05 08:40:28 -08001119 name.c_str(),
1120 err.c_str()));
mtkleinb37cb412015-03-18 05:27:14 -07001121 } else {
mtklein3eed7dd2016-02-24 19:07:07 -08001122 done(task.sink.tag.c_str(), task.src.tag.c_str(),
1123 task.src.options.c_str(), name.c_str());
mtkleinba6ada72016-01-21 09:39:35 -08001124 return;
mtklein4089ef72015-03-05 08:40:28 -08001125 }
mtklein748ca3b2015-01-15 10:56:12 -08001126 }
mtklein62bd1a62015-01-27 14:46:26 -08001127
mtkleincd50bca2016-01-05 06:20:20 -08001128 // We're likely switching threads here, so we must capture by value, [=] or [foo,bar].
Hal Canary0b833192017-03-14 14:35:02 -04001129 SkStreamAsset* data = stream.detachAsStream().release();
mtkleincd50bca2016-01-05 06:20:20 -08001130 gDefinitelyThreadSafeWork.add([task,name,bitmap,data]{
Ben Wagner145dbcd2016-11-03 14:40:50 -04001131 std::unique_ptr<SkStreamAsset> ownedData(data);
mtkleincd50bca2016-01-05 06:20:20 -08001132
Mike Kleine1271702019-03-07 11:46:59 -06001133 std::unique_ptr<HashAndEncode> hashAndEncode;
1134
mtkleincd50bca2016-01-05 06:20:20 -08001135 SkString md5;
Brian Osman57796b32019-01-25 18:02:59 +00001136 if (!FLAGS_writePath.isEmpty() || !FLAGS_readPath.isEmpty()) {
mtkleincd50bca2016-01-05 06:20:20 -08001137 SkMD5 hash;
1138 if (data->getLength()) {
1139 hash.writeStream(data, data->getLength());
1140 data->rewind();
mtklein38408462015-07-08 07:25:27 -07001141 } else {
Mike Kleine1271702019-03-07 11:46:59 -06001142 hashAndEncode.reset(new HashAndEncode(bitmap));
1143 hashAndEncode->write(&hash);
mtkleincd50bca2016-01-05 06:20:20 -08001144 }
Hal Canary0f2f5222019-04-03 10:13:45 -04001145 SkMD5::Digest digest = hash.finish();
mtkleincd50bca2016-01-05 06:20:20 -08001146 for (int i = 0; i < 16; i++) {
1147 md5.appendf("%02x", digest.data[i]);
mtklein38408462015-07-08 07:25:27 -07001148 }
mtklein62bd1a62015-01-27 14:46:26 -08001149 }
mtklein62bd1a62015-01-27 14:46:26 -08001150
Brian Osman57796b32019-01-25 18:02:59 +00001151 if (!FLAGS_readPath.isEmpty() &&
1152 !gGold.contains(Gold(task.sink.tag, task.src.tag,
1153 task.src.options, name, md5))) {
1154 fail(SkStringPrintf("%s not found for %s %s %s %s in %s",
1155 md5.c_str(),
1156 task.sink.tag.c_str(),
1157 task.src.tag.c_str(),
1158 task.src.options.c_str(),
1159 name.c_str(),
1160 FLAGS_readPath[0]));
1161 }
1162
mtkleincd50bca2016-01-05 06:20:20 -08001163 if (!FLAGS_writePath.isEmpty()) {
mtklein21eaf3b2016-02-08 12:39:59 -08001164 const char* ext = task.sink->fileExtension();
Brian Osmanf1942de2017-08-30 14:50:22 -04001165 if (ext && !FLAGS_dont_write.contains(ext)) {
Mike Klein97d6a7a2017-07-24 10:37:19 -04001166 if (data->getLength()) {
Mike Kleine1271702019-03-07 11:46:59 -06001167 WriteToDisk(task, md5, ext, data, data->getLength(), nullptr, nullptr);
Mike Klein97d6a7a2017-07-24 10:37:19 -04001168 SkASSERT(bitmap.drawsNothing());
1169 } else if (!bitmap.drawsNothing()) {
Mike Kleine1271702019-03-07 11:46:59 -06001170 WriteToDisk(task, md5, ext, nullptr, 0, &bitmap, hashAndEncode.get());
Mike Klein97d6a7a2017-07-24 10:37:19 -04001171 }
mtkleincd50bca2016-01-05 06:20:20 -08001172 }
1173 }
Brian Osman582f6862019-03-11 11:20:55 -04001174
1175 SkPixmap pm;
1176 if (FLAGS_checkF16 && bitmap.colorType() == kRGBA_F16Norm_SkColorType &&
1177 bitmap.peekPixels(&pm)) {
1178 bool unclamped = false;
1179 for (int y = 0; y < pm.height() && !unclamped; ++y)
1180 for (int x = 0; x < pm.width() && !unclamped; ++x) {
1181 Sk4f rgba = SkHalfToFloat_finite_ftz(*pm.addr64(x, y));
1182 float a = rgba[3];
1183 if (a > 1.0f || (rgba < 0.0f).anyTrue() || (rgba > a).anyTrue()) {
Brian Osmanb73e6072019-03-15 10:02:16 -04001184 SkDebugf("[%s] F16Norm pixel [%d, %d] unclamped: (%g, %g, %g, %g)\n",
1185 name.c_str(), x, y, rgba[0], rgba[1], rgba[2], rgba[3]);
Brian Osman582f6862019-03-11 11:20:55 -04001186 unclamped = true;
1187 }
1188 }
1189 }
mtkleincd50bca2016-01-05 06:20:20 -08001190 });
mtklein748ca3b2015-01-15 10:56:12 -08001191 }
mtklein3eed7dd2016-02-24 19:07:07 -08001192 done(task.sink.tag.c_str(), task.src.tag.c_str(), task.src.options.c_str(), name.c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001193 }
1194
Mike Klein66f09a72019-02-12 13:03:54 -05001195 static SkString identify_gamut(SkColorSpace* cs) {
1196 if (!cs) {
1197 return SkString("untagged");
1198 }
1199
1200 skcms_Matrix3x3 gamut;
1201 if (cs->toXYZD50(&gamut)) {
1202 auto eq = [](skcms_Matrix3x3 x, skcms_Matrix3x3 y) {
1203 for (int i = 0; i < 3; i++)
1204 for (int j = 0; j < 3; j++) {
1205 if (x.vals[i][j] != y.vals[i][j]) { return false; }
1206 }
1207 return true;
1208 };
1209
1210 if (eq(gamut, SkNamedGamut::kSRGB )) { return SkString("sRGB"); }
1211 if (eq(gamut, SkNamedGamut::kAdobeRGB)) { return SkString("Adobe"); }
1212 if (eq(gamut, SkNamedGamut::kDCIP3 )) { return SkString("P3"); }
1213 if (eq(gamut, SkNamedGamut::kRec2020 )) { return SkString("2020"); }
1214 if (eq(gamut, SkNamedGamut::kXYZ )) { return SkString("XYZ"); }
1215 if (eq(gamut, gNarrow_toXYZD50 )) { return SkString("narrow"); }
1216 return SkString("other");
1217 }
1218 return SkString("non-XYZ");
1219 }
1220
1221 static SkString identify_transfer_fn(SkColorSpace* cs) {
1222 if (!cs) {
1223 return SkString("untagged");
1224 }
1225
1226 skcms_TransferFunction tf;
1227 if (cs->isNumericalTransferFn(&tf)) {
1228 auto eq = [](skcms_TransferFunction x, skcms_TransferFunction y) {
1229 return x.g == y.g
1230 && x.a == y.a
1231 && x.b == y.b
1232 && x.c == y.c
1233 && x.d == y.d
1234 && x.e == y.e
1235 && x.f == y.f;
1236 };
1237
1238 if (tf.a == 1 && tf.b == 0 && tf.c == 0 && tf.d == 0 && tf.e == 0 && tf.f == 0) {
1239 return SkStringPrintf("gamma %.3g", tf.g);
1240 }
Hal Canarybe67a172019-05-24 10:13:36 -04001241 if (eq(tf, SkNamedTransferFn::kSRGB )) { return SkString("sRGB"); }
1242 if (eq(tf, SkNamedTransferFn::kRec2020)) { return SkString("2020"); }
Mike Klein66f09a72019-02-12 13:03:54 -05001243 return SkStringPrintf("%.3g %.3g %.3g %.3g %.3g %.3g %.3g",
1244 tf.g, tf.a, tf.b, tf.c, tf.d, tf.e, tf.f);
1245 }
1246 return SkString("non-numeric");
1247 }
1248
mtklein748ca3b2015-01-15 10:56:12 -08001249 static void WriteToDisk(const Task& task,
mtklein62bd1a62015-01-27 14:46:26 -08001250 SkString md5,
1251 const char* ext,
mtklein748ca3b2015-01-15 10:56:12 -08001252 SkStream* data, size_t len,
Mike Kleine1271702019-03-07 11:46:59 -06001253 const SkBitmap* bitmap,
1254 const HashAndEncode* hashAndEncode) {
mtklein409d4702016-02-29 07:38:01 -08001255
mtklein748ca3b2015-01-15 10:56:12 -08001256 JsonWriter::BitmapResult result;
djsollen54416de2015-04-03 07:24:48 -07001257 result.name = task.src->name();
mtklein3eed7dd2016-02-24 19:07:07 -08001258 result.config = task.sink.tag;
djsollen54416de2015-04-03 07:24:48 -07001259 result.sourceType = task.src.tag;
1260 result.sourceOptions = task.src.options;
1261 result.ext = ext;
1262 result.md5 = md5;
Mike Klein0abbaca2019-03-06 09:57:49 -06001263 if (bitmap) {
Mike Klein98168782019-04-09 13:45:02 -05001264 result.gamut = identify_gamut (bitmap->colorSpace());
1265 result.transferFn = identify_transfer_fn (bitmap->colorSpace());
1266 result.colorType = ToolUtils::colortype_name (bitmap->colorType());
1267 result.alphaType = ToolUtils::alphatype_name (bitmap->alphaType());
1268 result.colorDepth = ToolUtils::colortype_depth(bitmap->colorType());
Mike Klein0abbaca2019-03-06 09:57:49 -06001269 }
mtklein748ca3b2015-01-15 10:56:12 -08001270 JsonWriter::AddBitmapResult(result);
1271
mtkleinb0531a72015-04-07 13:38:48 -07001272 // If an MD5 is uninteresting, we want it noted in the JSON file,
1273 // but don't want to dump it out as a .png (or whatever ext is).
1274 if (gUninterestingHashes.contains(md5)) {
1275 return;
1276 }
1277
mtklein748ca3b2015-01-15 10:56:12 -08001278 const char* dir = FLAGS_writePath[0];
Mike Kleinc6142d82019-03-25 10:54:59 -05001279 SkString resources = GetResourcePath();
mtklein748ca3b2015-01-15 10:56:12 -08001280 if (0 == strcmp(dir, "@")) { // Needed for iOS.
Mike Kleinc6142d82019-03-25 10:54:59 -05001281 dir = resources.c_str();
mtklein748ca3b2015-01-15 10:56:12 -08001282 }
1283 sk_mkdir(dir);
1284
1285 SkString path;
1286 if (FLAGS_nameByHash) {
1287 path = SkOSPath::Join(dir, result.md5.c_str());
1288 path.append(".");
1289 path.append(ext);
1290 if (sk_exists(path.c_str())) {
1291 return; // Content-addressed. If it exists already, we're done.
1292 }
1293 } else {
kkinnunen3e980c32015-12-23 01:33:00 -08001294 path = SkOSPath::Join(dir, task.sink.tag.c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001295 sk_mkdir(path.c_str());
msarett9e707a02015-09-01 14:57:57 -07001296 path = SkOSPath::Join(path.c_str(), task.src.tag.c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001297 sk_mkdir(path.c_str());
msarett9e707a02015-09-01 14:57:57 -07001298 if (strcmp(task.src.options.c_str(), "") != 0) {
1299 path = SkOSPath::Join(path.c_str(), task.src.options.c_str());
djsollen54416de2015-04-03 07:24:48 -07001300 sk_mkdir(path.c_str());
1301 }
mtklein748ca3b2015-01-15 10:56:12 -08001302 path = SkOSPath::Join(path.c_str(), task.src->name().c_str());
1303 path.append(".");
1304 path.append(ext);
1305 }
1306
mtklein748ca3b2015-01-15 10:56:12 -08001307 if (bitmap) {
Mike Kleine1271702019-03-07 11:46:59 -06001308 SkASSERT(hashAndEncode);
Mike Klein735c7ba2019-03-25 12:57:58 -05001309 if (!hashAndEncode->writePngTo(path.c_str(),
1310 result.md5.c_str(),
1311 FLAGS_key,
1312 FLAGS_properties)) {
mtklein748ca3b2015-01-15 10:56:12 -08001313 fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str()));
1314 return;
1315 }
1316 } else {
mtkleina5114d72015-08-24 13:27:01 -07001317 SkFILEWStream file(path.c_str());
1318 if (!file.isValid()) {
1319 fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str()));
1320 return;
1321 }
mtklein748ca3b2015-01-15 10:56:12 -08001322 if (!file.writeStream(data, len)) {
1323 fail(SkStringPrintf("Can't write to %s.\n", path.c_str()));
1324 return;
1325 }
1326 }
1327 }
1328};
1329
mtklein748ca3b2015-01-15 10:56:12 -08001330/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1331
1332// Unit tests don't fit so well into the Src/Sink model, so we give them special treatment.
1333
mtklein21eaf3b2016-02-08 12:39:59 -08001334static SkTDArray<skiatest::Test> gParallelTests, gSerialTests;
mtklein748ca3b2015-01-15 10:56:12 -08001335
1336static void gather_tests() {
mtklein6c5fed22015-01-20 13:47:23 -08001337 if (!FLAGS_src.contains("tests")) {
mtklein748ca3b2015-01-15 10:56:12 -08001338 return;
1339 }
Hal Canary972eba32018-07-30 17:07:07 -04001340 for (const skiatest::Test& test : skiatest::TestRegistry::Range()) {
mtklein6393c062015-04-27 08:45:01 -07001341 if (!in_shard()) {
1342 continue;
1343 }
Mike Klein88544fb2019-03-20 10:50:33 -05001344 if (CommandLineFlags::ShouldSkip(FLAGS_match, test.name)) {
mtklein748ca3b2015-01-15 10:56:12 -08001345 continue;
1346 }
Brian Osmanc7ad40f2018-05-31 14:27:17 -04001347 if (test.needsGpu && FLAGS_gpu) {
Mike Reed5edcd312018-08-08 11:23:41 -04001348 (FLAGS_gpu_threading ? gParallelTests : gSerialTests).push_back(test);
halcanary87f3ba42015-01-20 09:30:20 -08001349 } else if (!test.needsGpu && FLAGS_cpu) {
Mike Reed5edcd312018-08-08 11:23:41 -04001350 gParallelTests.push_back(test);
mtklein82d28432015-01-15 12:46:02 -08001351 }
mtklein748ca3b2015-01-15 10:56:12 -08001352 }
1353}
1354
csmartdalton008b9d82017-02-22 12:00:42 -07001355static void run_test(skiatest::Test test, const GrContextOptions& grCtxOptions) {
halcanary87f3ba42015-01-20 09:30:20 -08001356 struct : public skiatest::Reporter {
mtklein36352bf2015-03-25 18:17:31 -07001357 void reportFailed(const skiatest::Failure& failure) override {
halcanary87f3ba42015-01-20 09:30:20 -08001358 fail(failure.toString());
halcanary87f3ba42015-01-20 09:30:20 -08001359 }
mtklein36352bf2015-03-25 18:17:31 -07001360 bool allowExtendedTest() const override {
halcanary87f3ba42015-01-20 09:30:20 -08001361 return FLAGS_pathOpsExtended;
1362 }
mtklein36352bf2015-03-25 18:17:31 -07001363 bool verbose() const override { return FLAGS_veryVerbose; }
halcanary87f3ba42015-01-20 09:30:20 -08001364 } reporter;
djsollen824996a2015-06-12 12:06:22 -07001365
mtklein3eed7dd2016-02-24 19:07:07 -08001366 if (!FLAGS_dryRun && !is_blacklisted("_", "tests", "_", test.name)) {
Robert Phillipsec325342017-10-30 18:02:48 +00001367 GrContextOptions options = grCtxOptions;
1368 test.modifyGrContextOptions(&options);
1369
Brian Osmancdf31742019-03-13 10:13:46 -04001370 skiatest::ReporterContext ctx(&reporter, SkString(test.name));
mtklein21eaf3b2016-02-08 12:39:59 -08001371 start("unit", "test", "", test.name);
Brian Salomondcfca432017-11-15 15:48:03 -05001372 test.run(&reporter, options);
mtklein748ca3b2015-01-15 10:56:12 -08001373 }
mtklein3eed7dd2016-02-24 19:07:07 -08001374 done("unit", "test", "", test.name);
mtklein748ca3b2015-01-15 10:56:12 -08001375}
1376
1377/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1378
Mike Kleinbe28ee22017-02-06 12:46:20 -05001379int main(int argc, char** argv) {
Dongwon Kang0c7861f2018-02-16 10:55:21 -08001380#if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && defined(SK_HAS_HEIF_LIBRARY)
1381 android::ProcessState::self()->startThreadPool();
1382#endif
Mike Klein88544fb2019-03-20 10:50:33 -05001383 CommandLineFlags::Parse(argc, argv);
Brian Osman53136aa2017-07-20 15:43:35 -04001384
Brian Osmanbc8150f2017-07-24 11:38:01 -04001385 initializeEventTracingForTools();
Brian Osman53136aa2017-07-20 15:43:35 -04001386
Mike Klein6613cc52017-12-19 09:09:33 -05001387#if !defined(SK_BUILD_FOR_GOOGLE3) && defined(SK_BUILD_FOR_IOS)
Mike Kleinadacaef2017-02-06 09:26:14 -05001388 cd_Documents();
1389#endif
bsalomon71de3532016-04-26 14:27:21 -07001390 setbuf(stdout, nullptr);
mtklein246ba3a2016-02-23 10:39:36 -08001391 setup_crash_handler();
mtkleinafae30a2016-02-24 12:28:32 -08001392
Mike Klein19cc0f62019-03-22 15:30:07 -05001393 ToolUtils::SetDefaultFontMgr();
Mike Klein03fa5d42019-03-22 11:39:09 -05001394 SetAnalyticAAFromCommonFlags();
liyuqian38911a72016-10-04 11:23:22 -07001395
Mike Reed7c26ca72017-07-05 15:45:52 -04001396 if (FLAGS_forceRasterPipeline) {
1397 gSkForceRasterPipelineBlitter = true;
1398 }
Yuqian Li550148b2017-01-13 10:13:13 -05001399
Mike Kleine9f187b2017-06-26 13:23:12 -04001400 // The bots like having a verbose.log to upload, so always touch the file even if --verbose.
1401 if (!FLAGS_writePath.isEmpty()) {
mtklein51c8cfc2016-03-11 12:59:09 -08001402 sk_mkdir(FLAGS_writePath[0]);
mtkleina1ce2162016-07-22 12:23:46 -07001403 gVLog = fopen(SkOSPath::Join(FLAGS_writePath[0], "verbose.log").c_str(), "w");
mtkleinc41fd922016-03-08 09:01:39 -08001404 }
Mike Kleine9f187b2017-06-26 13:23:12 -04001405 if (FLAGS_verbose) {
1406 gVLog = stderr;
1407 }
mtkleinc41fd922016-03-08 09:01:39 -08001408
csmartdalton008b9d82017-02-22 12:00:42 -07001409 GrContextOptions grCtxOptions;
Chris Dalton040238b2017-12-18 14:22:34 -07001410 SetCtxOptionsFromCommonFlags(&grCtxOptions);
csmartdalton008b9d82017-02-22 12:00:42 -07001411
Mike Kleinc6142d82019-03-25 10:54:59 -05001412 dump_json(); // It's handy for the bots to assume this is ~never missing.
1413
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +00001414 SkAutoGraphics ag;
mtklein406654b2014-09-03 15:34:37 -07001415 SkTaskGroup::Enabler enabled(FLAGS_threads);
commit-bot@chromium.orga65e2fd2014-05-30 17:23:31 +00001416
Mike Reed0933bc92017-12-09 01:27:41 +00001417 if (nullptr == GetResourceAsData("images/color_wheel.png")) {
1418 info("Some resources are missing. Do you need to set --resourcePath?\n");
halcanary7d571242016-02-24 17:59:16 -08001419 }
Brian Osman57796b32019-01-25 18:02:59 +00001420 gather_gold();
borenet09ed4802015-04-03 14:15:33 -07001421 gather_uninteresting_hashes();
mtklein62bd1a62015-01-27 14:46:26 -08001422
scroggo86737142016-02-03 12:19:11 -08001423 if (!gather_srcs()) {
1424 return 1;
1425 }
Ben Wagnerf28d4722017-08-11 17:33:22 -04001426 // TODO(dogben): This is a bit ugly. Find a cleaner way to do this.
1427 bool defaultConfigs = true;
1428 for (int i = 0; i < argc; i++) {
1429 static const char* kConfigArg = "--config";
1430 if (strcmp(argv[i], kConfigArg) == 0) {
1431 defaultConfigs = false;
1432 break;
1433 }
1434 }
1435 if (!gather_sinks(grCtxOptions, defaultConfigs)) {
brianosman05c987c2016-05-09 13:42:16 -07001436 return 1;
1437 }
mtklein748ca3b2015-01-15 10:56:12 -08001438 gather_tests();
mtklein21eaf3b2016-02-08 12:39:59 -08001439 gPending = gSrcs.count() * gSinks.count() + gParallelTests.count() + gSerialTests.count();
Brian Osmand0677bc2017-08-03 12:13:47 -04001440 info("%d srcs * %d sinks + %d tests == %d tasks\n",
mtkleinc41fd922016-03-08 09:01:39 -08001441 gSrcs.count(), gSinks.count(), gParallelTests.count() + gSerialTests.count(), gPending);
mtklein748ca3b2015-01-15 10:56:12 -08001442
mtklein21eaf3b2016-02-08 12:39:59 -08001443 // Kick off as much parallel work as we can, making note of any serial work we'll need to do.
1444 SkTaskGroup parallel;
1445 SkTArray<Task> serial;
1446
1447 for (auto& sink : gSinks)
1448 for (auto& src : gSrcs) {
mtklein3eed7dd2016-02-24 19:07:07 -08001449 if (src->veto(sink->flags()) ||
1450 is_blacklisted(sink.tag.c_str(), src.tag.c_str(),
1451 src.options.c_str(), src->name().c_str())) {
Herb Derbya1b7be62019-05-09 16:59:18 -04001452 SkAutoSpinlock lock(gMutex);
mtklein3eed7dd2016-02-24 19:07:07 -08001453 gPending--;
1454 continue;
1455 }
1456
mtklein21eaf3b2016-02-08 12:39:59 -08001457 Task task(src, sink);
1458 if (src->serial() || sink->serial()) {
1459 serial.push_back(task);
1460 } else {
1461 parallel.add([task] { Task::Run(task); });
mtklein748ca3b2015-01-15 10:56:12 -08001462 }
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001463 }
mtklein21eaf3b2016-02-08 12:39:59 -08001464 for (auto test : gParallelTests) {
csmartdalton008b9d82017-02-22 12:00:42 -07001465 parallel.add([test, grCtxOptions] { run_test(test, grCtxOptions); });
mtklein55e88b22015-01-21 15:50:13 -08001466 }
mtklein21eaf3b2016-02-08 12:39:59 -08001467
1468 // With the parallel work running, run serial tasks and tests here on main thread.
1469 for (auto task : serial) { Task::Run(task); }
csmartdalton008b9d82017-02-22 12:00:42 -07001470 for (auto test : gSerialTests) { run_test(test, grCtxOptions); }
mtklein21eaf3b2016-02-08 12:39:59 -08001471
1472 // Wait for any remaining parallel work to complete (including any spun off of serial tasks).
1473 parallel.wait();
mtkleincd50bca2016-01-05 06:20:20 -08001474 gDefinitelyThreadSafeWork.wait();
1475
Ben Wagner83c6b962018-07-10 19:40:15 -04001476 // At this point we're back in single-threaded land.
1477
mtkleinda884c42016-02-24 18:00:23 -08001478 // We'd better have run everything.
1479 SkASSERT(gPending == 0);
mtkleine027f172016-02-26 15:53:06 -08001480 // Make sure we've flushed all our results to disk.
Mike Kleinc6142d82019-03-25 10:54:59 -05001481 dump_json();
mtkleinda884c42016-02-24 18:00:23 -08001482
mtklein748ca3b2015-01-15 10:56:12 -08001483 if (gFailures.count() > 0) {
mtkleinc41fd922016-03-08 09:01:39 -08001484 info("Failures:\n");
mtklein748ca3b2015-01-15 10:56:12 -08001485 for (int i = 0; i < gFailures.count(); i++) {
mtkleinc41fd922016-03-08 09:01:39 -08001486 info("\t%s\n", gFailures[i].c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001487 }
mtkleinc41fd922016-03-08 09:01:39 -08001488 info("%d failures\n", gFailures.count());
Kevin Lubick805c4e82019-03-20 09:46:09 -04001489 // A non-zero return code does not make it to Swarming
1490 // An abort does.
1491#ifdef SK_BUILD_FOR_IOS
Kevin Lubickc4fec062019-05-31 12:31:09 +00001492 SK_ABORT("There were failures!");
Kevin Lubick805c4e82019-03-20 09:46:09 -04001493#endif
mtklein748ca3b2015-01-15 10:56:12 -08001494 return 1;
mtklein114c3cd2015-01-15 10:15:02 -08001495 }
mtkleinafae30a2016-02-24 12:28:32 -08001496
Herb Derby5a523fe2017-01-26 16:48:28 -05001497 SkGraphics::PurgeAllCaches();
mtkleinc41fd922016-03-08 09:01:39 -08001498 info("Finished!\n");
Brian Osman53136aa2017-07-20 15:43:35 -04001499
mtklein748ca3b2015-01-15 10:56:12 -08001500 return 0;
mtklein@google.comd36522d2013-10-16 13:02:15 +00001501}