blob: 6244a4141f0822faa18a49af5e386240c411a6e9 [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"
Tyler Denniston45f94f82020-02-04 16:09:08 -050010#include "gm/verifiers/gmverifier.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/codec/SkCodec.h"
12#include "include/core/SkBBHFactory.h"
13#include "include/core/SkColorPriv.h"
14#include "include/core/SkColorSpace.h"
15#include "include/core/SkData.h"
16#include "include/core/SkDocument.h"
17#include "include/core/SkFontMgr.h"
18#include "include/core/SkGraphics.h"
19#include "include/ports/SkTypeface_win.h"
20#include "include/private/SkChecksum.h"
21#include "include/private/SkHalf.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050022#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"
Jim Van Verth8a9a3712019-05-31 10:49:12 -040031#include "tools/AutoreleasePool.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050032#include "tools/HashAndEncode.h"
33#include "tools/ProcStats.h"
34#include "tools/Resources.h"
35#include "tools/ToolUtils.h"
36#include "tools/flags/CommonFlags.h"
37#include "tools/flags/CommonFlagsConfig.h"
38#include "tools/ios_utils.h"
39#include "tools/trace/ChromeTracingTracer.h"
40#include "tools/trace/EventTracingPriv.h"
41#include "tools/trace/SkDebugfTracer.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000042
scroggo19b91532016-10-24 09:03:26 -070043#include <vector>
44
bungeman60e0fee2015-08-26 05:15:46 -070045#include <stdlib.h>
46
Mike Klein8f11d4d2018-01-24 12:42:55 -050047#ifndef SK_BUILD_FOR_WIN
scroggo27a58342015-10-28 08:56:41 -070048 #include <unistd.h>
49#endif
50
Dongwon Kang0c7861f2018-02-16 10:55:21 -080051#if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && defined(SK_HAS_HEIF_LIBRARY)
Mike Klein055f5352020-01-30 11:11:12 -060052 #include <binder/IPCThreadState.h>
53#endif
54
55#if defined(SK_BUILD_FOR_MAC)
56 #include "include/utils/mac/SkCGUtils.h"
57 #include "src/utils/mac/SkUniqueCFRef.h"
Dongwon Kang0c7861f2018-02-16 10:55:21 -080058#endif
59
Mike Reed7c26ca72017-07-05 15:45:52 -040060extern bool gSkForceRasterPipelineBlitter;
Mike Klein9ae06632020-01-28 12:41:02 -060061extern bool gUseSkVMBlitter;
Mike Reed7c26ca72017-07-05 15:45:52 -040062
Mike Klein84836b72019-03-21 11:31:36 -050063static DEFINE_string(src, "tests gm skp image", "Source types to test.");
64static DEFINE_bool(nameByHash, false,
65 "If true, write to FLAGS_writePath[0]/<hash>.png instead of "
66 "to FLAGS_writePath[0]/<config>/<sourceType>/<sourceOptions>/<name>.png");
67static DEFINE_bool2(pathOpsExtended, x, false, "Run extended pathOps tests.");
68static DEFINE_string(matrix, "1 0 0 1",
69 "2x2 scale+skew matrix to apply or upright when using "
70 "'matrix' or 'upright' in config.");
mtklein@google.comd36522d2013-10-16 13:02:15 +000071
Mike Klein84836b72019-03-21 11:31:36 -050072static DEFINE_string(blacklist, "",
Chris Daltonecf78ac2017-08-15 15:43:08 -060073 "Space-separated config/src/srcOptions/name quadruples to blacklist. "
74 "'_' matches anything. '~' negates the match. E.g. \n"
djsollen54416de2015-04-03 07:24:48 -070075 "'--blacklist gpu skp _ _' will blacklist all SKPs drawn into the gpu config.\n"
Chris Daltonecf78ac2017-08-15 15:43:08 -060076 "'--blacklist gpu skp _ _ 8888 gm _ aarects' will also blacklist the aarects GM on 8888.\n"
77 "'--blacklist ~8888 svg _ svgparse_' blocks non-8888 SVGs that contain \"svgparse_\" in "
78 "the name.");
mtkleina2ef6422015-01-15 13:44:22 -080079
Mike Klein84836b72019-03-21 11:31:36 -050080static DEFINE_string2(readPath, r, "",
81 "If set check for equality with golden results in this directory.");
Mike Kleinc6142d82019-03-25 10:54:59 -050082DEFINE_string2(writePath, w, "", "If set, write bitmaps here as .pngs.");
83
Brian Osman57796b32019-01-25 18:02:59 +000084
Mike Klein84836b72019-03-21 11:31:36 -050085static DEFINE_string(uninterestingHashesFile, "",
borenet09ed4802015-04-03 14:15:33 -070086 "File containing a list of uninteresting hashes. If a result hashes to something in "
87 "this list, no image is written for that result.");
88
Mike Klein5b3f3432019-03-21 11:42:21 -050089static DEFINE_int(shards, 1, "We're splitting source data into this many shards.");
90static DEFINE_int(shard, 0, "Which shard do I run?");
mtklein6393c062015-04-27 08:45:01 -070091
Mike Klein84836b72019-03-21 11:31:36 -050092static DEFINE_string(mskps, "", "Directory to read mskps from, or a single mskp file.");
93static DEFINE_bool(forceRasterPipeline, false, "sets gSkForceRasterPipelineBlitter");
Mike Klein9ae06632020-01-28 12:41:02 -060094static DEFINE_bool(skvm, false, "sets gUseSkVMBlitter");
halcanary45420a92016-06-02 12:41:14 -070095
Mike Klein84836b72019-03-21 11:31:36 -050096static DEFINE_string(bisect, "",
Chris Dalton184c37e2018-09-28 11:27:39 -060097 "Pair of: SKP file to bisect, followed by an l/r bisect trail string (e.g., 'lrll'). The "
98 "l/r trail specifies which half to keep at each step of a binary search through the SKP's "
99 "paths. An empty string performs no bisect. Only the SkPaths are bisected; all other draws "
100 "are thrown out. This is useful for finding a reduced repo case for path drawing bugs.");
101
Mike Klein84836b72019-03-21 11:31:36 -0500102static DEFINE_bool(ignoreSigInt, false, "ignore SIGINT signals during test execution");
Derek Sollenbergeredfe3df2017-07-19 15:25:24 -0400103
Mike Klein84836b72019-03-21 11:31:36 -0500104static DEFINE_bool(checkF16, false, "Ensure that F16Norm pixels are clamped.");
Brian Osman582f6862019-03-11 11:20:55 -0400105
Mike Klein19fb3972019-03-21 13:08:08 -0500106static DEFINE_string(colorImages, "",
107 "List of images and/or directories to decode with color correction. "
108 "A directory with no images is treated as a fatal error.");
109
Mike Kleind0f321b2019-03-22 13:15:11 -0500110static DEFINE_bool2(veryVerbose, V, false, "tell individual tests to be verbose.");
111
Mike Klein629f5fc2019-03-22 14:55:19 -0500112static DEFINE_bool(cpu, true, "master switch for running CPU-bound work.");
113static DEFINE_bool(gpu, true, "master switch for running GPU-bound work.");
114
115static DEFINE_bool(dryRun, false,
116 "just print the tests that would be run, without actually running them.");
117
118static DEFINE_string(images, "",
119 "List of images and/or directories to decode. A directory with no images"
120 " is treated as a fatal error.");
121
122static DEFINE_bool(simpleCodec, false,
123 "Runs of a subset of the codec tests, "
124 "with no scaling or subsetting, always using the canvas color type.");
Mike Klein19fb3972019-03-21 13:08:08 -0500125
Mike Kleinc6142d82019-03-25 10:54:59 -0500126static DEFINE_string2(match, m, nullptr,
127 "[~][^]substring[$] [...] of name to run.\n"
128 "Multiple matches may be separated by spaces.\n"
129 "~ causes a matching name to always be skipped\n"
130 "^ requires the start of the name to match\n"
131 "$ requires the end of the name to match\n"
132 "^ and $ requires an exact match\n"
133 "If a name does not match any list entry,\n"
134 "it is skipped unless some list entry starts with ~");
135
136static DEFINE_bool2(quiet, q, false, "if true, don't print status updates.");
137static DEFINE_bool2(verbose, v, false, "enable verbose output from the test driver.");
138
139static DEFINE_string(skps, "skps", "Directory to read skps from.");
140static DEFINE_string(lotties, "lotties", "Directory to read (Bodymovin) jsons from.");
141static DEFINE_string(svgs, "", "Directory to read SVGs from, or a single SVG file.");
142
143static DEFINE_int_2(threads, j, -1,
144 "Run threadsafe tests on a threadpool with this many extra threads, "
145 "defaulting to one extra thread per core.");
146
147static DEFINE_string(key, "",
148 "Space-separated key/value pairs to add to JSON identifying this builder.");
149static DEFINE_string(properties, "",
150 "Space-separated key/value pairs to add to JSON identifying this run.");
151
Mike Klein055f5352020-01-30 11:11:12 -0600152static DEFINE_bool(rasterize_pdf, false, "Rasterize PDFs when possible.");
153
Tyler Denniston45f94f82020-02-04 16:09:08 -0500154static DEFINE_bool(runVerifiers, false,
155 "if true, run SkQP-style verification of GM-produced images.");
156
Mike Kleinc6142d82019-03-25 10:54:59 -0500157
Brian Osman1c1208e2019-06-24 13:36:05 -0400158#if defined(__MSVC_RUNTIME_CHECKS)
159#include <rtcapi.h>
160int RuntimeCheckErrorFunc(int errorType, const char* filename, int linenumber,
161 const char* moduleName, const char* fmt, ...) {
162 va_list args;
163 va_start(args, fmt);
164 vfprintf(stderr, fmt, args);
165 va_end(args);
166
167 SkDebugf("Line #%d\nFile: %s\nModule: %s\n",
168 linenumber, filename ? filename : "Unknown", moduleName ? moduleName : "Unknwon");
169 return 1;
170}
171#endif
172
mtklein748ca3b2015-01-15 10:56:12 -0800173using namespace DM;
bsalomon3724e572016-03-30 18:56:19 -0700174using sk_gpu_test::GrContextFactory;
bsalomon273c0f52016-03-31 10:59:06 -0700175using sk_gpu_test::GLTestContext;
bsalomonf2f1c172016-04-05 12:59:06 -0700176using sk_gpu_test::ContextInfo;
mtklein@google.comd36522d2013-10-16 13:02:15 +0000177
mtklein748ca3b2015-01-15 10:56:12 -0800178/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
179
Mike Kleine1271702019-03-07 11:46:59 -0600180static sk_sp<SkColorSpace> rec2020() {
Hal Canarybe67a172019-05-24 10:13:36 -0400181 return SkColorSpace::MakeRGB(SkNamedTransferFn::kRec2020, SkNamedGamut::kRec2020);
Mike Kleine1271702019-03-07 11:46:59 -0600182}
183
184/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
185
mtkleinc41fd922016-03-08 09:01:39 -0800186static FILE* gVLog;
187
188template <typename... Args>
189static void vlog(const char* fmt, Args&&... args) {
190 if (gVLog) {
mtkleinc41fd922016-03-08 09:01:39 -0800191 fprintf(gVLog, fmt, args...);
192 fflush(gVLog);
193 }
194}
195
196template <typename... Args>
197static void info(const char* fmt, Args&&... args) {
198 vlog(fmt, args...);
199 if (!FLAGS_quiet) {
200 printf(fmt, args...);
201 }
202}
203static void info(const char* fmt) {
204 if (!FLAGS_quiet) {
205 printf("%s", fmt); // Clang warns printf(fmt) is insecure.
206 }
207}
208
mtklein748ca3b2015-01-15 10:56:12 -0800209static SkTArray<SkString> gFailures;
210
mtklein3eed7dd2016-02-24 19:07:07 -0800211static void fail(const SkString& err) {
Herb Derby9c71e7b2019-06-17 14:40:42 -0400212 static SkSpinlock mutex;
213 SkAutoSpinlock lock(mutex);
mtklein748ca3b2015-01-15 10:56:12 -0800214 SkDebugf("\n\nFAILURE: %s\n\n", err.c_str());
215 gFailures.push_back(err);
halcanary9e398f72015-01-10 11:18:04 -0800216}
217
mtklein0f7748a2016-07-25 15:27:29 -0700218struct Running {
219 SkString id;
220 SkThreadID thread;
221
222 void dump() const {
223 info("\t%s\n", id.c_str());
224 }
225};
mtkleinb37cb412015-03-18 05:27:14 -0700226
Mike Kleinc6142d82019-03-25 10:54:59 -0500227static void dump_json() {
228 if (!FLAGS_writePath.isEmpty()) {
229 JsonWriter::DumpJson(FLAGS_writePath[0], FLAGS_key, FLAGS_properties);
230 }
231}
232
mtklein246ba3a2016-02-23 10:39:36 -0800233// We use a spinlock to make locking this in a signal handler _somewhat_ safe.
Mike Klein03a95ad2017-06-23 12:36:32 -0400234static SkSpinlock gMutex;
235static int gPending;
mtklein0f7748a2016-07-25 15:27:29 -0700236static SkTArray<Running> gRunning;
mtklein748ca3b2015-01-15 10:56:12 -0800237
mtklein3eed7dd2016-02-24 19:07:07 -0800238static void done(const char* config, const char* src, const char* srcOptions, const char* name) {
239 SkString id = SkStringPrintf("%s %s %s %s", config, src, srcOptions, name);
mtkleinc41fd922016-03-08 09:01:39 -0800240 vlog("done %s\n", id.c_str());
mtkleinafae30a2016-02-24 12:28:32 -0800241 int pending;
mtkleinb37cb412015-03-18 05:27:14 -0700242 {
Herb Derbya1b7be62019-05-09 16:59:18 -0400243 SkAutoSpinlock lock(gMutex);
mtkleinb37cb412015-03-18 05:27:14 -0700244 for (int i = 0; i < gRunning.count(); i++) {
mtklein0f7748a2016-07-25 15:27:29 -0700245 if (gRunning[i].id == id) {
mtkleinb37cb412015-03-18 05:27:14 -0700246 gRunning.removeShuffle(i);
247 break;
248 }
249 }
mtkleinafae30a2016-02-24 12:28:32 -0800250 pending = --gPending;
reed50bc0512015-05-19 14:13:31 -0700251 }
Mike Klein03a95ad2017-06-23 12:36:32 -0400252
253 // We write out dm.json file and print out a progress update every once in a while.
254 // Notice this also handles the final dm.json and progress update when pending == 0.
mtkleina17241b2015-01-23 05:48:00 -0800255 if (pending % 500 == 0) {
Mike Kleinc6142d82019-03-25 10:54:59 -0500256 dump_json();
Mike Klein03a95ad2017-06-23 12:36:32 -0400257
258 int curr = sk_tools::getCurrResidentSetSizeMB(),
259 peak = sk_tools::getMaxResidentSetSizeMB();
Mike Klein03a95ad2017-06-23 12:36:32 -0400260
Herb Derbya1b7be62019-05-09 16:59:18 -0400261 SkAutoSpinlock lock(gMutex);
Mike Klein21ba7722018-10-02 13:57:44 +0000262 info("\n%dMB RAM, %dMB peak, %d queued, %d active:\n",
263 curr, peak, gPending - gRunning.count(), gRunning.count());
Mike Klein03a95ad2017-06-23 12:36:32 -0400264 for (auto& task : gRunning) {
265 task.dump();
266 }
mtkleina17241b2015-01-23 05:48:00 -0800267 }
mtklein@google.comd36522d2013-10-16 13:02:15 +0000268}
269
mtklein3eed7dd2016-02-24 19:07:07 -0800270static void start(const char* config, const char* src, const char* srcOptions, const char* name) {
271 SkString id = SkStringPrintf("%s %s %s %s", config, src, srcOptions, name);
mtkleinc41fd922016-03-08 09:01:39 -0800272 vlog("start %s\n", id.c_str());
Herb Derbya1b7be62019-05-09 16:59:18 -0400273 SkAutoSpinlock lock(gMutex);
mtklein0f7748a2016-07-25 15:27:29 -0700274 gRunning.push_back({id,SkGetThreadID()});
mtkleinb37cb412015-03-18 05:27:14 -0700275}
276
Mike Klein3cc2d202016-10-24 11:39:43 -0400277static void find_culprit() {
278 // Assumes gMutex is locked.
279 SkThreadID thisThread = SkGetThreadID();
280 for (auto& task : gRunning) {
281 if (task.thread == thisThread) {
282 info("Likely culprit:\n");
283 task.dump();
mtklein0f7748a2016-07-25 15:27:29 -0700284 }
285 }
Mike Klein3cc2d202016-10-24 11:39:43 -0400286}
mtklein0f7748a2016-07-25 15:27:29 -0700287
Mike Klein8f11d4d2018-01-24 12:42:55 -0500288#if defined(SK_BUILD_FOR_WIN)
mtklein5b64dab2016-06-09 08:59:48 -0700289 static LONG WINAPI crash_handler(EXCEPTION_POINTERS* e) {
mtkleinf8557292016-02-29 06:35:28 -0800290 static const struct {
291 const char* name;
robertphillips75467862016-03-01 14:10:23 -0800292 DWORD code;
mtkleinf8557292016-02-29 06:35:28 -0800293 } kExceptions[] = {
294 #define _(E) {#E, E}
295 _(EXCEPTION_ACCESS_VIOLATION),
296 _(EXCEPTION_BREAKPOINT),
297 _(EXCEPTION_INT_DIVIDE_BY_ZERO),
298 _(EXCEPTION_STACK_OVERFLOW),
299 // TODO: more?
300 #undef _
301 };
302
Herb Derbya1b7be62019-05-09 16:59:18 -0400303 SkAutoSpinlock lock(gMutex);
mtklein5b64dab2016-06-09 08:59:48 -0700304
305 const DWORD code = e->ExceptionRecord->ExceptionCode;
306 info("\nCaught exception %u", code);
307 for (const auto& exception : kExceptions) {
308 if (exception.code == code) {
309 info(" %s", exception.name);
mtkleinf8557292016-02-29 06:35:28 -0800310 }
mtkleinf8557292016-02-29 06:35:28 -0800311 }
mtklein5b64dab2016-06-09 08:59:48 -0700312 info(", was running:\n");
313 for (auto& task : gRunning) {
mtklein0f7748a2016-07-25 15:27:29 -0700314 task.dump();
mtklein5b64dab2016-06-09 08:59:48 -0700315 }
mtklein0f7748a2016-07-25 15:27:29 -0700316 find_culprit();
mtklein5b64dab2016-06-09 08:59:48 -0700317 fflush(stdout);
318
mtkleinf8557292016-02-29 06:35:28 -0800319 // Execute default exception handler... hopefully, exit.
320 return EXCEPTION_EXECUTE_HANDLER;
mtklein246ba3a2016-02-23 10:39:36 -0800321 }
322
Mike Klein3cc2d202016-10-24 11:39:43 -0400323 static void setup_crash_handler() {
324 SetUnhandledExceptionFilter(crash_handler);
325 }
326#else
mtklein246ba3a2016-02-23 10:39:36 -0800327 #include <signal.h>
Mike Klein3cc2d202016-10-24 11:39:43 -0400328 #if !defined(SK_BUILD_FOR_ANDROID)
329 #include <execinfo.h>
Brian Salomondcbb9d92017-07-19 10:53:20 -0400330
331#endif
Mike Klein3cc2d202016-10-24 11:39:43 -0400332
333 static constexpr int max_of() { return 0; }
334 template <typename... Rest>
335 static constexpr int max_of(int x, Rest... rest) {
336 return x > max_of(rest...) ? x : max_of(rest...);
337 }
338
Mike Kleinc7278ad2018-02-15 09:26:54 -0500339 static void (*previous_handler[max_of(SIGABRT,SIGBUS,SIGFPE,SIGILL,SIGSEGV,SIGTERM)+1])(int);
mtkleinf8557292016-02-29 06:35:28 -0800340
mtklein5b64dab2016-06-09 08:59:48 -0700341 static void crash_handler(int sig) {
Herb Derbya1b7be62019-05-09 16:59:18 -0400342 SkAutoSpinlock lock(gMutex);
mtklein5b64dab2016-06-09 08:59:48 -0700343
Mike Klein701a3582018-06-28 14:08:19 +0000344 info("\nCaught signal %d [%s] (%dMB RAM, peak %dMB), was running:\n",
345 sig, strsignal(sig),
346 sk_tools::getCurrResidentSetSizeMB(), sk_tools::getMaxResidentSetSizeMB());
347
mtklein5b64dab2016-06-09 08:59:48 -0700348 for (auto& task : gRunning) {
mtklein0f7748a2016-07-25 15:27:29 -0700349 task.dump();
mtklein5b64dab2016-06-09 08:59:48 -0700350 }
mtklein0f7748a2016-07-25 15:27:29 -0700351 find_culprit();
mtklein5b64dab2016-06-09 08:59:48 -0700352
Mike Klein3cc2d202016-10-24 11:39:43 -0400353 #if !defined(SK_BUILD_FOR_ANDROID)
mtklein5b64dab2016-06-09 08:59:48 -0700354 void* stack[64];
355 int count = backtrace(stack, SK_ARRAY_COUNT(stack));
356 char** symbols = backtrace_symbols(stack, count);
357 info("\nStack trace:\n");
358 for (int i = 0; i < count; i++) {
359 info(" %s\n", symbols[i]);
360 }
Mike Klein3cc2d202016-10-24 11:39:43 -0400361 #endif
mtklein5b64dab2016-06-09 08:59:48 -0700362 fflush(stdout);
363
Mike Kleinca8087f2019-03-18 09:01:39 -0500364 if (sig == SIGINT && FLAGS_ignoreSigInt) {
365 info("Ignoring signal %d because of --ignoreSigInt.\n"
366 "This is probably a sign the bot is overloaded with work.\n", sig);
367 } else {
368 signal(sig, previous_handler[sig]);
369 raise(sig);
370 }
mtklein5b64dab2016-06-09 08:59:48 -0700371 }
372
mtklein246ba3a2016-02-23 10:39:36 -0800373 static void setup_crash_handler() {
Mike Klein701a3582018-06-28 14:08:19 +0000374 const int kSignals[] = { SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGINT, SIGSEGV, SIGTERM };
mtklein246ba3a2016-02-23 10:39:36 -0800375 for (int sig : kSignals) {
Mike Klein3cc2d202016-10-24 11:39:43 -0400376 previous_handler[sig] = signal(sig, crash_handler);
mtklein246ba3a2016-02-23 10:39:36 -0800377 }
378 }
379#endif
380
mtklein748ca3b2015-01-15 10:56:12 -0800381/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
mtklein114c3cd2015-01-15 10:15:02 -0800382
Brian Osman57796b32019-01-25 18:02:59 +0000383struct Gold : public SkString {
384 Gold() : SkString("") {}
385 Gold(const SkString& sink, const SkString& src,
386 const SkString& srcOptions, const SkString& name,
387 const SkString& md5)
388 : SkString("") {
389 this->append(sink);
390 this->append(src);
391 this->append(srcOptions);
392 this->append(name);
393 this->append(md5);
394 }
395 struct Hash {
396 uint32_t operator()(const Gold& g) const {
397 return SkGoodHash()((const SkString&)g);
398 }
399 };
400};
401static SkTHashSet<Gold, Gold::Hash> gGold;
402
403static void add_gold(JsonWriter::BitmapResult r) {
404 gGold.add(Gold(r.config, r.sourceType, r.sourceOptions, r.name, r.md5));
405}
406
407static void gather_gold() {
408 if (!FLAGS_readPath.isEmpty()) {
409 SkString path(FLAGS_readPath[0]);
410 path.append("/dm.json");
411 if (!JsonWriter::ReadJson(path.c_str(), add_gold)) {
412 fail(SkStringPrintf("Couldn't read %s for golden results.", path.c_str()));
413 }
414 }
415}
416
417/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
418
Mike Klein8f11d4d2018-01-24 12:42:55 -0500419#if defined(SK_BUILD_FOR_WIN)
mtklein935f1b12016-03-16 08:37:19 -0700420 static const char* kNewline = "\r\n";
421#else
422 static const char* kNewline = "\n";
423#endif
424
borenet09ed4802015-04-03 14:15:33 -0700425static SkTHashSet<SkString> gUninterestingHashes;
426
427static void gather_uninteresting_hashes() {
428 if (!FLAGS_uninterestingHashesFile.isEmpty()) {
bungeman38d909e2016-08-02 14:40:46 -0700429 sk_sp<SkData> data(SkData::MakeFromFileName(FLAGS_uninterestingHashesFile[0]));
mtkleincc334b32015-09-22 11:43:53 -0700430 if (!data) {
mtkleinc41fd922016-03-08 09:01:39 -0800431 info("WARNING: unable to read uninteresting hashes from %s\n",
432 FLAGS_uninterestingHashesFile[0]);
mtkleincc334b32015-09-22 11:43:53 -0700433 return;
434 }
Mike Klein45dcc0c2017-04-05 18:04:31 -0400435
436 // Copy to a string to make sure SkStrSplit has a terminating \0 to find.
437 SkString contents((const char*)data->data(), data->size());
438
borenet09ed4802015-04-03 14:15:33 -0700439 SkTArray<SkString> hashes;
Mike Klein45dcc0c2017-04-05 18:04:31 -0400440 SkStrSplit(contents.c_str(), kNewline, &hashes);
borenet09ed4802015-04-03 14:15:33 -0700441 for (const SkString& hash : hashes) {
442 gUninterestingHashes.add(hash);
443 }
mtkleinc41fd922016-03-08 09:01:39 -0800444 info("FYI: loaded %d distinct uninteresting hashes from %d lines\n",
445 gUninterestingHashes.count(), hashes.count());
borenet09ed4802015-04-03 14:15:33 -0700446 }
447}
448
449/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
450
Ben Wagner145dbcd2016-11-03 14:40:50 -0400451struct TaggedSrc : public std::unique_ptr<Src> {
mtklein3eed7dd2016-02-24 19:07:07 -0800452 SkString tag;
453 SkString options;
mtkleine0effd62015-07-29 06:37:28 -0700454};
455
Ben Wagner145dbcd2016-11-03 14:40:50 -0400456struct TaggedSink : public std::unique_ptr<Sink> {
kkinnunen3e980c32015-12-23 01:33:00 -0800457 SkString tag;
djsollen54416de2015-04-03 07:24:48 -0700458};
mtklein748ca3b2015-01-15 10:56:12 -0800459
460static const bool kMemcpyOK = true;
461
mtkleine0effd62015-07-29 06:37:28 -0700462static SkTArray<TaggedSrc, kMemcpyOK> gSrcs;
463static SkTArray<TaggedSink, kMemcpyOK> gSinks;
mtklein748ca3b2015-01-15 10:56:12 -0800464
mtklein6393c062015-04-27 08:45:01 -0700465static bool in_shard() {
466 static int N = 0;
467 return N++ % FLAGS_shards == FLAGS_shard;
468}
469
mtklein3eed7dd2016-02-24 19:07:07 -0800470static void push_src(const char* tag, ImplicitString options, Src* s) {
Ben Wagner145dbcd2016-11-03 14:40:50 -0400471 std::unique_ptr<Src> src(s);
Mike Klein88544fb2019-03-20 10:50:33 -0500472 if (in_shard() && FLAGS_src.contains(tag) &&
473 !CommandLineFlags::ShouldSkip(FLAGS_match, src->name().c_str())) {
mtkleine0effd62015-07-29 06:37:28 -0700474 TaggedSrc& s = gSrcs.push_back();
mtklein18300a32016-03-16 13:53:35 -0700475 s.reset(src.release());
mtklein748ca3b2015-01-15 10:56:12 -0800476 s.tag = tag;
djsollen54416de2015-04-03 07:24:48 -0700477 s.options = options;
mtklein114c3cd2015-01-15 10:15:02 -0800478 }
mtklein748ca3b2015-01-15 10:56:12 -0800479}
mtklein114c3cd2015-01-15 10:15:02 -0800480
msarett9e707a02015-09-01 14:57:57 -0700481static void push_codec_src(Path path, CodecSrc::Mode mode, CodecSrc::DstColorType dstColorType,
scroggoc5560be2016-02-03 09:42:42 -0800482 SkAlphaType dstAlphaType, float scale) {
scroggoe4499842016-02-25 11:03:47 -0800483 if (FLAGS_simpleCodec) {
scroggo19b91532016-10-24 09:03:26 -0700484 const bool simple = CodecSrc::kCodec_Mode == mode || CodecSrc::kAnimated_Mode == mode;
485 if (!simple || dstColorType != CodecSrc::kGetFromCanvas_DstColorType || scale != 1.0f) {
scroggoe4499842016-02-25 11:03:47 -0800486 // Only decode in the simple case.
487 return;
scroggo19b91532016-10-24 09:03:26 -0700488 }
scroggoe4499842016-02-25 11:03:47 -0800489 }
msarett9e707a02015-09-01 14:57:57 -0700490 SkString folder;
491 switch (mode) {
492 case CodecSrc::kCodec_Mode:
493 folder.append("codec");
494 break;
msarettbb25b532016-01-13 09:31:39 -0800495 case CodecSrc::kCodecZeroInit_Mode:
496 folder.append("codec_zero_init");
497 break;
msarett9e707a02015-09-01 14:57:57 -0700498 case CodecSrc::kScanline_Mode:
499 folder.append("scanline");
500 break;
msarett9e707a02015-09-01 14:57:57 -0700501 case CodecSrc::kStripe_Mode:
502 folder.append("stripe");
503 break;
msarett91c22b22016-02-22 12:27:46 -0800504 case CodecSrc::kCroppedScanline_Mode:
505 folder.append("crop");
506 break;
msarett9e707a02015-09-01 14:57:57 -0700507 case CodecSrc::kSubset_Mode:
msarett36c37962015-09-02 13:20:52 -0700508 folder.append("codec_subset");
msarett9e707a02015-09-01 14:57:57 -0700509 break;
scroggo19b91532016-10-24 09:03:26 -0700510 case CodecSrc::kAnimated_Mode:
511 folder.append("codec_animated");
512 break;
msarett9e707a02015-09-01 14:57:57 -0700513 }
514
515 switch (dstColorType) {
516 case CodecSrc::kGrayscale_Always_DstColorType:
517 folder.append("_kGray8");
518 break;
msarett34e0ec42016-04-22 16:27:24 -0700519 case CodecSrc::kNonNative8888_Always_DstColorType:
520 folder.append("_kNonNative");
521 break;
msarett9e707a02015-09-01 14:57:57 -0700522 default:
523 break;
524 }
525
scroggoc5560be2016-02-03 09:42:42 -0800526 switch (dstAlphaType) {
scroggoc5560be2016-02-03 09:42:42 -0800527 case kPremul_SkAlphaType:
528 folder.append("_premul");
529 break;
530 case kUnpremul_SkAlphaType:
531 folder.append("_unpremul");
532 break;
533 default:
534 break;
535 }
536
msarett9e707a02015-09-01 14:57:57 -0700537 if (1.0f != scale) {
538 folder.appendf("_%.3f", scale);
539 }
540
scroggoc5560be2016-02-03 09:42:42 -0800541 CodecSrc* src = new CodecSrc(path, mode, dstColorType, dstAlphaType, scale);
msarett9e707a02015-09-01 14:57:57 -0700542 push_src("image", folder, src);
543}
544
scroggof8dc9df2016-05-16 09:04:13 -0700545static void push_android_codec_src(Path path, CodecSrc::DstColorType dstColorType,
546 SkAlphaType dstAlphaType, int sampleSize) {
msarett3d9d7a72015-10-21 10:27:10 -0700547 SkString folder;
scroggof8dc9df2016-05-16 09:04:13 -0700548 folder.append("scaled_codec");
msarett3d9d7a72015-10-21 10:27:10 -0700549
550 switch (dstColorType) {
551 case CodecSrc::kGrayscale_Always_DstColorType:
552 folder.append("_kGray8");
553 break;
msarett34e0ec42016-04-22 16:27:24 -0700554 case CodecSrc::kNonNative8888_Always_DstColorType:
555 folder.append("_kNonNative");
556 break;
msarett3d9d7a72015-10-21 10:27:10 -0700557 default:
558 break;
559 }
560
scroggoc5560be2016-02-03 09:42:42 -0800561 switch (dstAlphaType) {
scroggoc5560be2016-02-03 09:42:42 -0800562 case kPremul_SkAlphaType:
563 folder.append("_premul");
564 break;
msarett9e9444c2016-02-03 12:39:10 -0800565 case kUnpremul_SkAlphaType:
566 folder.append("_unpremul");
567 break;
scroggoc5560be2016-02-03 09:42:42 -0800568 default:
569 break;
570 }
571
msarett3d9d7a72015-10-21 10:27:10 -0700572 if (1 != sampleSize) {
msarett4b0778e2015-11-13 09:59:11 -0800573 folder.appendf("_%.3f", 1.0f / (float) sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700574 }
575
scroggof8dc9df2016-05-16 09:04:13 -0700576 AndroidCodecSrc* src = new AndroidCodecSrc(path, dstColorType, dstAlphaType, sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700577 push_src("image", folder, src);
578}
579
msarett18976312016-03-09 14:20:58 -0800580static void push_image_gen_src(Path path, ImageGenSrc::Mode mode, SkAlphaType alphaType, bool isGpu)
581{
582 SkString folder;
583 switch (mode) {
584 case ImageGenSrc::kCodec_Mode:
585 folder.append("gen_codec");
586 break;
587 case ImageGenSrc::kPlatform_Mode:
588 folder.append("gen_platform");
589 break;
590 }
591
592 if (isGpu) {
593 folder.append("_gpu");
594 } else {
595 switch (alphaType) {
596 case kOpaque_SkAlphaType:
597 folder.append("_opaque");
598 break;
599 case kPremul_SkAlphaType:
600 folder.append("_premul");
601 break;
602 case kUnpremul_SkAlphaType:
603 folder.append("_unpremul");
604 break;
605 default:
606 break;
607 }
608 }
609
610 ImageGenSrc* src = new ImageGenSrc(path, mode, alphaType, isGpu);
611 push_src("image", folder, src);
612}
613
Leon Scroggins III07418182017-08-15 12:24:02 -0400614static void push_brd_src(Path path, CodecSrc::DstColorType dstColorType, BRDSrc::Mode mode,
615 uint32_t sampleSize) {
616 SkString folder("brd_android_codec");
617 switch (mode) {
618 case BRDSrc::kFullImage_Mode:
619 break;
620 case BRDSrc::kDivisor_Mode:
621 folder.append("_divisor");
622 break;
623 default:
624 SkASSERT(false);
625 return;
626 }
627
628 switch (dstColorType) {
629 case CodecSrc::kGetFromCanvas_DstColorType:
630 break;
631 case CodecSrc::kGrayscale_Always_DstColorType:
632 folder.append("_kGray");
633 break;
634 default:
635 SkASSERT(false);
636 return;
637 }
638
639 if (1 != sampleSize) {
640 folder.appendf("_%.3f", 1.0f / (float) sampleSize);
641 }
642
643 BRDSrc* src = new BRDSrc(path, mode, dstColorType, sampleSize);
644 push_src("image", folder, src);
645}
646
647static void push_brd_srcs(Path path, bool gray) {
648 if (gray) {
649 // Only run grayscale to one sampleSize and Mode. Though interesting
650 // to test grayscale, it should not reveal anything across various
651 // sampleSizes and Modes
652 // Arbitrarily choose Mode and sampleSize.
653 push_brd_src(path, CodecSrc::kGrayscale_Always_DstColorType,
654 BRDSrc::kFullImage_Mode, 2);
655 }
656
657 // Test on a variety of sampleSizes, making sure to include:
658 // - 2, 4, and 8, which are natively supported by jpeg
659 // - multiples of 2 which are not divisible by 4 (analogous for 4)
660 // - larger powers of two, since BRD clients generally use powers of 2
661 // We will only produce output for the larger sizes on large images.
662 const uint32_t sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 24, 32, 64 };
663
664 const BRDSrc::Mode modes[] = { BRDSrc::kFullImage_Mode, BRDSrc::kDivisor_Mode, };
665
666 for (uint32_t sampleSize : sampleSizes) {
667 for (BRDSrc::Mode mode : modes) {
668 push_brd_src(path, CodecSrc::kGetFromCanvas_DstColorType, mode, sampleSize);
669 }
670 }
671}
672
msarett438b2ad2015-04-09 12:43:10 -0700673static void push_codec_srcs(Path path) {
bungeman38d909e2016-08-02 14:40:46 -0700674 sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str()));
msarett438b2ad2015-04-09 12:43:10 -0700675 if (!encoded) {
mtkleinc41fd922016-03-08 09:01:39 -0800676 info("Couldn't read %s.", path.c_str());
msarett438b2ad2015-04-09 12:43:10 -0700677 return;
678 }
Mike Reedede7bac2017-07-23 15:30:02 -0400679 std::unique_ptr<SkCodec> codec = SkCodec::MakeFromData(encoded);
halcanary96fcdcc2015-08-27 07:41:13 -0700680 if (nullptr == codec.get()) {
mtkleinc41fd922016-03-08 09:01:39 -0800681 info("Couldn't create codec for %s.", path.c_str());
msarett438b2ad2015-04-09 12:43:10 -0700682 return;
683 }
684
scroggo9366aff2016-05-20 08:38:54 -0700685 // native scaling is only supported by WEBP and JPEG
686 bool supportsNativeScaling = false;
msarett438b2ad2015-04-09 12:43:10 -0700687
msarett91c22b22016-02-22 12:27:46 -0800688 SkTArray<CodecSrc::Mode> nativeModes;
689 nativeModes.push_back(CodecSrc::kCodec_Mode);
690 nativeModes.push_back(CodecSrc::kCodecZeroInit_Mode);
msarett91c22b22016-02-22 12:27:46 -0800691 switch (codec->getEncodedFormat()) {
Hal Canarydb683012016-11-23 08:55:18 -0700692 case SkEncodedImageFormat::kJPEG:
msarett91c22b22016-02-22 12:27:46 -0800693 nativeModes.push_back(CodecSrc::kScanline_Mode);
694 nativeModes.push_back(CodecSrc::kStripe_Mode);
695 nativeModes.push_back(CodecSrc::kCroppedScanline_Mode);
scroggo9366aff2016-05-20 08:38:54 -0700696 supportsNativeScaling = true;
msarett91c22b22016-02-22 12:27:46 -0800697 break;
Hal Canarydb683012016-11-23 08:55:18 -0700698 case SkEncodedImageFormat::kWEBP:
msarett91c22b22016-02-22 12:27:46 -0800699 nativeModes.push_back(CodecSrc::kSubset_Mode);
scroggo9366aff2016-05-20 08:38:54 -0700700 supportsNativeScaling = true;
msarett91c22b22016-02-22 12:27:46 -0800701 break;
Hal Canarydb683012016-11-23 08:55:18 -0700702 case SkEncodedImageFormat::kDNG:
msarettb65e6042016-02-23 05:37:25 -0800703 break;
msarett91c22b22016-02-22 12:27:46 -0800704 default:
705 nativeModes.push_back(CodecSrc::kScanline_Mode);
msarett91c22b22016-02-22 12:27:46 -0800706 break;
707 }
msarett9e707a02015-09-01 14:57:57 -0700708
msarett91c22b22016-02-22 12:27:46 -0800709 SkTArray<CodecSrc::DstColorType> colorTypes;
710 colorTypes.push_back(CodecSrc::kGetFromCanvas_DstColorType);
msarett34e0ec42016-04-22 16:27:24 -0700711 colorTypes.push_back(CodecSrc::kNonNative8888_Always_DstColorType);
msarett36c37962015-09-02 13:20:52 -0700712 switch (codec->getInfo().colorType()) {
713 case kGray_8_SkColorType:
msarett91c22b22016-02-22 12:27:46 -0800714 colorTypes.push_back(CodecSrc::kGrayscale_Always_DstColorType);
msarett36c37962015-09-02 13:20:52 -0700715 break;
716 default:
msarett36c37962015-09-02 13:20:52 -0700717 break;
718 }
msarett9e707a02015-09-01 14:57:57 -0700719
scroggoc5560be2016-02-03 09:42:42 -0800720 SkTArray<SkAlphaType> alphaModes;
721 alphaModes.push_back(kPremul_SkAlphaType);
scroggof2c96a22016-05-20 11:08:27 -0700722 if (codec->getInfo().alphaType() != kOpaque_SkAlphaType) {
723 alphaModes.push_back(kUnpremul_SkAlphaType);
scroggoc5560be2016-02-03 09:42:42 -0800724 }
msarettb714fb02016-01-22 14:46:42 -0800725
726 for (CodecSrc::Mode mode : nativeModes) {
scroggo9366aff2016-05-20 08:38:54 -0700727 for (CodecSrc::DstColorType colorType : colorTypes) {
728 for (SkAlphaType alphaType : alphaModes) {
scroggof2c96a22016-05-20 11:08:27 -0700729 // Only test kCroppedScanline_Mode when the alpha type is premul. The test is
scroggo9366aff2016-05-20 08:38:54 -0700730 // slow and won't be interestingly different with different alpha types.
731 if (CodecSrc::kCroppedScanline_Mode == mode &&
scroggof2c96a22016-05-20 11:08:27 -0700732 kPremul_SkAlphaType != alphaType) {
scroggo9366aff2016-05-20 08:38:54 -0700733 continue;
734 }
msarett91c22b22016-02-22 12:27:46 -0800735
scroggo9366aff2016-05-20 08:38:54 -0700736 push_codec_src(path, mode, colorType, alphaType, 1.0f);
msarettf3dc1882016-04-26 13:06:38 -0700737
scroggo9366aff2016-05-20 08:38:54 -0700738 // Skip kNonNative on different native scales. It won't be interestingly
739 // different.
740 if (supportsNativeScaling &&
741 CodecSrc::kNonNative8888_Always_DstColorType == colorType) {
742 // Native Scales
743 // SkJpegCodec natively supports scaling to the following:
744 for (auto scale : { 0.125f, 0.25f, 0.375f, 0.5f, 0.625f, 0.750f, 0.875f }) {
745 push_codec_src(path, mode, colorType, alphaType, scale);
746 }
scroggoc5560be2016-02-03 09:42:42 -0800747 }
msarett9e707a02015-09-01 14:57:57 -0700748 }
749 }
msarett0a242972015-06-11 14:27:27 -0700750 }
msarett36c37962015-09-02 13:20:52 -0700751
scroggo19b91532016-10-24 09:03:26 -0700752 {
753 std::vector<SkCodec::FrameInfo> frameInfos = codec->getFrameInfo();
754 if (frameInfos.size() > 1) {
Leon Scroggins III557fbbe2017-05-23 09:37:21 -0400755 for (auto dstCT : { CodecSrc::kNonNative8888_Always_DstColorType,
756 CodecSrc::kGetFromCanvas_DstColorType }) {
757 for (auto at : { kUnpremul_SkAlphaType, kPremul_SkAlphaType }) {
758 push_codec_src(path, CodecSrc::kAnimated_Mode, dstCT, at, 1.0f);
759 }
760 }
scroggo19b91532016-10-24 09:03:26 -0700761 }
762
763 }
764
scroggoe4499842016-02-25 11:03:47 -0800765 if (FLAGS_simpleCodec) {
766 return;
767 }
768
msarett3d9d7a72015-10-21 10:27:10 -0700769 const int sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
msarett36c37962015-09-02 13:20:52 -0700770
msarett3d9d7a72015-10-21 10:27:10 -0700771 for (int sampleSize : sampleSizes) {
msarett91c22b22016-02-22 12:27:46 -0800772 for (CodecSrc::DstColorType colorType : colorTypes) {
scroggoc5560be2016-02-03 09:42:42 -0800773 for (SkAlphaType alphaType : alphaModes) {
msarettf3dc1882016-04-26 13:06:38 -0700774 // We can exercise all of the kNonNative support code in the swizzler with just a
775 // few sample sizes. Skip the rest.
776 if (CodecSrc::kNonNative8888_Always_DstColorType == colorType && sampleSize > 3) {
777 continue;
778 }
779
scroggof8dc9df2016-05-16 09:04:13 -0700780 push_android_codec_src(path, colorType, alphaType, sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700781 }
msarett36c37962015-09-02 13:20:52 -0700782 }
783 }
msarett18976312016-03-09 14:20:58 -0800784
Leon Scroggins III07418182017-08-15 12:24:02 -0400785 const char* ext = strrchr(path.c_str(), '.');
786 if (ext) {
787 ext++;
msarett18976312016-03-09 14:20:58 -0800788
Leon Scroggins III07418182017-08-15 12:24:02 -0400789 static const char* const rawExts[] = {
790 "arw", "cr2", "dng", "nef", "nrw", "orf", "raf", "rw2", "pef", "srw",
791 "ARW", "CR2", "DNG", "NEF", "NRW", "ORF", "RAF", "RW2", "PEF", "SRW",
792 };
793 for (const char* rawExt : rawExts) {
794 if (0 == strcmp(rawExt, ext)) {
795 // RAW is not supported by image generator (skbug.com/5079) or BRD.
796 return;
797 }
798 }
799
800 static const char* const brdExts[] = {
801 "jpg", "jpeg", "png", "webp",
802 "JPG", "JPEG", "PNG", "WEBP",
803 };
804 for (const char* brdExt : brdExts) {
805 if (0 == strcmp(brdExt, ext)) {
Leon Scroggins IIIc8037dc2017-12-05 13:55:24 -0500806 bool gray = codec->getInfo().colorType() == kGray_8_SkColorType;
Leon Scroggins III07418182017-08-15 12:24:02 -0400807 push_brd_srcs(path, gray);
808 break;
809 }
msarett18976312016-03-09 14:20:58 -0800810 }
811 }
812
813 // Push image generator GPU test.
brianosmanc9ced392016-03-24 07:27:43 -0700814 push_image_gen_src(path, ImageGenSrc::kCodec_Mode, codec->getInfo().alphaType(), true);
msarett18976312016-03-09 14:20:58 -0800815
816 // Push image generator CPU tests.
817 for (SkAlphaType alphaType : alphaModes) {
818 push_image_gen_src(path, ImageGenSrc::kCodec_Mode, alphaType, false);
819
820#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
Hal Canarydb683012016-11-23 08:55:18 -0700821 if (SkEncodedImageFormat::kWEBP != codec->getEncodedFormat() &&
822 SkEncodedImageFormat::kWBMP != codec->getEncodedFormat() &&
msarett18976312016-03-09 14:20:58 -0800823 kUnpremul_SkAlphaType != alphaType)
824 {
825 push_image_gen_src(path, ImageGenSrc::kPlatform_Mode, alphaType, false);
826 }
msarettfc0b6d12016-03-17 13:50:17 -0700827#elif defined(SK_BUILD_FOR_WIN)
Hal Canarydb683012016-11-23 08:55:18 -0700828 if (SkEncodedImageFormat::kWEBP != codec->getEncodedFormat() &&
829 SkEncodedImageFormat::kWBMP != codec->getEncodedFormat())
msarettfc0b6d12016-03-17 13:50:17 -0700830 {
831 push_image_gen_src(path, ImageGenSrc::kPlatform_Mode, alphaType, false);
832 }
msarett18976312016-03-09 14:20:58 -0800833#endif
834 }
msarett438b2ad2015-04-09 12:43:10 -0700835}
836
fmalitaa2b9fdf2016-08-03 19:53:36 -0700837template <typename T>
Mike Klein88544fb2019-03-20 10:50:33 -0500838void gather_file_srcs(const CommandLineFlags::StringArray& flags,
839 const char* ext,
840 const char* src_name = nullptr) {
Florin Malitaf1ba3ae2018-07-19 15:09:11 -0400841 if (!src_name) {
842 // With the exception of Lottie files, the source name is the extension.
843 src_name = ext;
844 }
845
fmalitaa2b9fdf2016-08-03 19:53:36 -0700846 for (int i = 0; i < flags.count(); i++) {
847 const char* path = flags[i];
848 if (sk_isdir(path)) {
849 SkOSFile::Iter it(path, ext);
850 for (SkString file; it.next(&file); ) {
Florin Malitaf1ba3ae2018-07-19 15:09:11 -0400851 push_src(src_name, "", new T(SkOSPath::Join(path, file.c_str())));
fmalitaa2b9fdf2016-08-03 19:53:36 -0700852 }
853 } else {
Florin Malitaf1ba3ae2018-07-19 15:09:11 -0400854 push_src(src_name, "", new T(path));
fmalitaa2b9fdf2016-08-03 19:53:36 -0700855 }
856 }
857}
858
scroggo86737142016-02-03 12:19:11 -0800859static bool gather_srcs() {
Hal Canary972eba32018-07-30 17:07:07 -0400860 for (skiagm::GMFactory f : skiagm::GMRegistry::Range()) {
861 push_src("gm", "", new GMSrc(f));
mtklein748ca3b2015-01-15 10:56:12 -0800862 }
scroggo86737142016-02-03 12:19:11 -0800863
Robert Phillipse47f0a02018-03-27 17:01:16 -0400864 gather_file_srcs<SKPSrc>(FLAGS_skps, "skp");
fmalitaa2b9fdf2016-08-03 19:53:36 -0700865 gather_file_srcs<MSKPSrc>(FLAGS_mskps, "mskp");
Florin Malita87ccf332018-05-04 12:23:24 -0400866#if defined(SK_ENABLE_SKOTTIE)
Florin Malitaf1ba3ae2018-07-19 15:09:11 -0400867 gather_file_srcs<SkottieSrc>(FLAGS_lotties, "json", "lottie");
Florin Malita124d5af2017-12-31 17:02:26 -0500868#endif
fmalitaa2b9fdf2016-08-03 19:53:36 -0700869#if defined(SK_XML)
870 gather_file_srcs<SVGSrc>(FLAGS_svgs, "svg");
871#endif
Chris Dalton184c37e2018-09-28 11:27:39 -0600872 if (!FLAGS_bisect.isEmpty()) {
873 // An empty l/r trail string will draw all the paths.
874 push_src("bisect", "",
875 new BisectSrc(FLAGS_bisect[0], FLAGS_bisect.count() > 1 ? FLAGS_bisect[1] : ""));
876 }
halcanary45420a92016-06-02 12:41:14 -0700877
scroggo86737142016-02-03 12:19:11 -0800878 SkTArray<SkString> images;
msarett69deca82016-04-29 09:38:40 -0700879 if (!CollectImages(FLAGS_images, &images)) {
scroggo86737142016-02-03 12:19:11 -0800880 return false;
881 }
882
883 for (auto image : images) {
884 push_codec_srcs(image);
mtklein709d2c32015-01-15 08:30:25 -0800885 }
scroggo86737142016-02-03 12:19:11 -0800886
msarett69deca82016-04-29 09:38:40 -0700887 SkTArray<SkString> colorImages;
888 if (!CollectImages(FLAGS_colorImages, &colorImages)) {
889 return false;
890 }
891
892 for (auto colorImage : colorImages) {
Mike Klein0d5d1422019-03-06 10:56:04 -0600893 push_src("colorImage", "decode_native", new ColorCodecSrc(colorImage, false));
894 push_src("colorImage", "decode_to_dst", new ColorCodecSrc(colorImage, true));
msarett69deca82016-04-29 09:38:40 -0700895 }
896
scroggo86737142016-02-03 12:19:11 -0800897 return true;
mtklein709d2c32015-01-15 08:30:25 -0800898}
899
kkinnunen3e980c32015-12-23 01:33:00 -0800900static void push_sink(const SkCommandLineConfig& config, Sink* s) {
Ben Wagner145dbcd2016-11-03 14:40:50 -0400901 std::unique_ptr<Sink> sink(s);
kkinnunen3e980c32015-12-23 01:33:00 -0800902
mtkleine0effd62015-07-29 06:37:28 -0700903 // Try a simple Src as a canary. If it fails, skip this sink.
mtklein748ca3b2015-01-15 10:56:12 -0800904 struct : public Src {
Ben Wagnerea25fcf2020-02-12 11:18:46 -0500905 Result draw(SkCanvas* c) const override {
mtkleine0effd62015-07-29 06:37:28 -0700906 c->drawRect(SkRect::MakeWH(1,1), SkPaint());
Ben Wagnerea25fcf2020-02-12 11:18:46 -0500907 return Result::Ok();
mtkleine0effd62015-07-29 06:37:28 -0700908 }
mtklein36352bf2015-03-25 18:17:31 -0700909 SkISize size() const override { return SkISize::Make(16, 16); }
mtkleine0effd62015-07-29 06:37:28 -0700910 Name name() const override { return "justOneRect"; }
911 } justOneRect;
mtklein114c3cd2015-01-15 10:15:02 -0800912
mtklein748ca3b2015-01-15 10:56:12 -0800913 SkBitmap bitmap;
914 SkDynamicMemoryWStream stream;
mtkleinb9eb4ac2015-02-02 18:26:03 -0800915 SkString log;
Ben Wagnerea25fcf2020-02-12 11:18:46 -0500916 Result result = sink->draw(justOneRect, &bitmap, &stream, &log);
917 if (result.isFatal()) {
Robert Phillips45f37c32020-02-13 20:26:58 +0000918 info("Could not run %s: %s\n", config.getTag().c_str(), result.c_str());
mtklein05641a52015-04-21 10:49:13 -0700919 exit(1);
mtklein114c3cd2015-01-15 10:15:02 -0800920 }
921
mtkleine0effd62015-07-29 06:37:28 -0700922 TaggedSink& ts = gSinks.push_back();
mtklein18300a32016-03-16 13:53:35 -0700923 ts.reset(sink.release());
kkinnunen3e980c32015-12-23 01:33:00 -0800924 ts.tag = config.getTag();
mtklein748ca3b2015-01-15 10:56:12 -0800925}
926
Mike Kleinc7a09162019-02-19 06:14:39 -0500927static sk_sp<SkColorSpace> rgb_to_gbr() {
928 return SkColorSpace::MakeSRGB()->makeColorSpin();
929}
930
csmartdalton008b9d82017-02-22 12:00:42 -0700931static Sink* create_sink(const GrContextOptions& grCtxOptions, const SkCommandLineConfig* config) {
Brian Osmanc7ad40f2018-05-31 14:27:17 -0400932 if (FLAGS_gpu) {
kkinnunen3e980c32015-12-23 01:33:00 -0800933 if (const SkCommandLineConfigGpu* gpuConfig = config->asConfigGpu()) {
csmartdalton008b9d82017-02-22 12:00:42 -0700934 GrContextFactory testFactory(grCtxOptions);
Brian Osman3fdfe282019-09-09 13:46:52 -0400935 if (!testFactory.get(gpuConfig->getContextType(), gpuConfig->getContextOverrides())) {
mtkleinc41fd922016-03-08 09:01:39 -0800936 info("WARNING: can not create GPU context for config '%s'. "
937 "GM tests will be skipped.\n", gpuConfig->getTag().c_str());
kkinnunen3e980c32015-12-23 01:33:00 -0800938 return nullptr;
939 }
Brian Osmanf9810662017-08-30 10:02:10 -0400940 if (gpuConfig->getTestThreading()) {
Brian Salomon00a5eb82018-07-11 15:32:05 -0400941 SkASSERT(!gpuConfig->getTestPersistentCache());
Brian Osman3fdfe282019-09-09 13:46:52 -0400942 return new GPUThreadTestingSink(gpuConfig, grCtxOptions);
Brian Salomon00a5eb82018-07-11 15:32:05 -0400943 } else if (gpuConfig->getTestPersistentCache()) {
Brian Osman3fdfe282019-09-09 13:46:52 -0400944 return new GPUPersistentCacheTestingSink(gpuConfig, grCtxOptions);
Brian Osmaned58e002019-09-06 14:42:43 -0400945 } else if (gpuConfig->getTestPrecompile()) {
Brian Osman3fdfe282019-09-09 13:46:52 -0400946 return new GPUPrecompileTestingSink(gpuConfig, grCtxOptions);
Robert Phillips291f3402020-02-19 14:14:47 -0500947 } else if (gpuConfig->getUseDDLSink()) {
948 return new GPUDDLSink(gpuConfig, grCtxOptions);
Brian Osmanf9810662017-08-30 10:02:10 -0400949 } else {
Brian Osman3fdfe282019-09-09 13:46:52 -0400950 return new GPUSink(gpuConfig, grCtxOptions);
Brian Osmanf9810662017-08-30 10:02:10 -0400951 }
kkinnunen3e980c32015-12-23 01:33:00 -0800952 }
953 }
Bryce Thomas95a7b762018-03-02 13:54:21 -0800954 if (const SkCommandLineConfigSvg* svgConfig = config->asConfigSvg()) {
955 int pageIndex = svgConfig->getPageIndex();
956 return new SVGSink(pageIndex);
957 }
kkinnunen3e980c32015-12-23 01:33:00 -0800958
Brian Salomon23356442018-11-30 15:33:19 -0500959#define SINK(t, sink, ...) if (config->getBackend().equals(t)) return new sink(__VA_ARGS__)
kkinnunen3e980c32015-12-23 01:33:00 -0800960
mtklein748ca3b2015-01-15 10:56:12 -0800961 if (FLAGS_cpu) {
Mike Kleinf7eb0542020-02-11 12:19:08 -0600962 SINK("g8", RasterSink, kGray_8_SkColorType);
963 SINK("565", RasterSink, kRGB_565_SkColorType);
964 SINK("4444", RasterSink, kARGB_4444_SkColorType);
965 SINK("8888", RasterSink, kN32_SkColorType);
966 SINK("rgba", RasterSink, kRGBA_8888_SkColorType);
967 SINK("bgra", RasterSink, kBGRA_8888_SkColorType);
968 SINK("rgbx", RasterSink, kRGB_888x_SkColorType);
969 SINK("1010102", RasterSink, kRGBA_1010102_SkColorType);
970 SINK("101010x", RasterSink, kRGB_101010x_SkColorType);
971 SINK("bgra1010102", RasterSink, kBGRA_1010102_SkColorType);
972 SINK("bgr101010x", RasterSink, kBGR_101010x_SkColorType);
973 SINK("pdf", PDFSink, false, SK_ScalarDefaultRasterDPI);
974 SINK("skp", SKPSink);
975 SINK("svg", SVGSink);
976 SINK("null", NullSink);
977 SINK("xps", XPSSink);
978 SINK("pdfa", PDFSink, true, SK_ScalarDefaultRasterDPI);
979 SINK("pdf300", PDFSink, false, 300);
980 SINK("jsdebug", DebugSink);
Mike Klein0e4041f2018-06-19 16:00:40 -0400981
982 // Configs relevant to color management testing (and 8888 for reference).
983
984 // 'narrow' has a gamut narrower than sRGB, and different transfer function.
Brian Osman82ebe042019-01-04 17:03:00 -0500985 auto narrow = SkColorSpace::MakeRGB(SkNamedTransferFn::k2Dot2, gNarrow_toXYZD50),
Mike Klein0e4041f2018-06-19 16:00:40 -0400986 srgb = SkColorSpace::MakeSRGB(),
Mike Klein4de05072018-08-16 09:09:14 -0400987 srgbLinear = SkColorSpace::MakeSRGBLinear(),
Mike Kleinb147ace2020-01-16 11:11:06 -0600988 p3 = SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, SkNamedGamut::kDisplayP3);
Mike Klein0e4041f2018-06-19 16:00:40 -0400989
Mike Kleinff6a73c2018-08-17 16:19:24 -0400990 SINK( "f16", RasterSink, kRGBA_F16_SkColorType, srgbLinear);
991 SINK( "srgb", RasterSink, kRGBA_8888_SkColorType, srgb );
992 SINK( "esrgb", RasterSink, kRGBA_F16_SkColorType, srgb );
Mike Kleinc7a09162019-02-19 06:14:39 -0500993 SINK( "esgbr", RasterSink, kRGBA_F16_SkColorType, rgb_to_gbr());
Mike Kleinff6a73c2018-08-17 16:19:24 -0400994 SINK( "narrow", RasterSink, kRGBA_8888_SkColorType, narrow );
995 SINK( "enarrow", RasterSink, kRGBA_F16_SkColorType, narrow );
996 SINK( "p3", RasterSink, kRGBA_8888_SkColorType, p3 );
997 SINK( "ep3", RasterSink, kRGBA_F16_SkColorType, p3 );
Mike Kleinae4b1f42018-09-13 11:13:15 -0400998 SINK( "rec2020", RasterSink, kRGBA_8888_SkColorType, rec2020() );
999 SINK("erec2020", RasterSink, kRGBA_F16_SkColorType, rec2020() );
Mike Klein37854712018-06-26 11:43:06 -04001000
Mike Kleinb70990e2019-02-28 10:03:27 -06001001 SINK("f16norm", RasterSink, kRGBA_F16Norm_SkColorType, srgb);
1002
Mike Klein37854712018-06-26 11:43:06 -04001003 SINK( "f32", RasterSink, kRGBA_F32_SkColorType, srgbLinear);
mtklein748ca3b2015-01-15 10:56:12 -08001004 }
1005#undef SINK
halcanary96fcdcc2015-08-27 07:41:13 -07001006 return nullptr;
mtklein114c3cd2015-01-15 10:15:02 -08001007}
1008
kkinnunen3e980c32015-12-23 01:33:00 -08001009static Sink* create_via(const SkString& tag, Sink* wrapped) {
Brian Salomon23356442018-11-30 15:33:19 -05001010#define VIA(t, via, ...) if (tag.equals(t)) return new via(__VA_ARGS__)
Mike Reedbae888e2017-02-18 16:50:45 -05001011#ifdef TEST_VIA_SVG
Mike Reedf67c4592017-02-17 17:06:11 -05001012 VIA("svg", ViaSVG, wrapped);
Mike Reedbae888e2017-02-18 16:50:45 -05001013#endif
halcanary96fcdcc2015-08-27 07:41:13 -07001014 VIA("serialize", ViaSerialization, wrapped);
mtklein4a34ecb2016-01-08 10:19:35 -08001015 VIA("pic", ViaPicture, wrapped);
Brian Salomon57904202018-12-17 14:45:00 -05001016 VIA("ddl", ViaDDL, 1, 3, wrapped);
1017 VIA("ddl2", ViaDDL, 2, 3, wrapped);
Robert Phillips33f02ed2018-03-27 08:06:57 -04001018
mtkleind603b222015-02-17 11:13:33 -08001019 if (FLAGS_matrix.count() == 4) {
mtklein748ca3b2015-01-15 10:56:12 -08001020 SkMatrix m;
mtkleind603b222015-02-17 11:13:33 -08001021 m.reset();
1022 m.setScaleX((SkScalar)atof(FLAGS_matrix[0]));
1023 m.setSkewX ((SkScalar)atof(FLAGS_matrix[1]));
1024 m.setSkewY ((SkScalar)atof(FLAGS_matrix[2]));
1025 m.setScaleY((SkScalar)atof(FLAGS_matrix[3]));
1026 VIA("matrix", ViaMatrix, m, wrapped);
1027 VIA("upright", ViaUpright, m, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -08001028 }
tomhudson64de1e12015-03-05 08:01:07 -08001029
mtklein748ca3b2015-01-15 10:56:12 -08001030#undef VIA
halcanary96fcdcc2015-08-27 07:41:13 -07001031 return nullptr;
mtklein114c3cd2015-01-15 10:15:02 -08001032}
1033
Ben Wagnerf28d4722017-08-11 17:33:22 -04001034static bool gather_sinks(const GrContextOptions& grCtxOptions, bool defaultConfigs) {
kkinnunen3e980c32015-12-23 01:33:00 -08001035 SkCommandLineConfigArray configs;
1036 ParseConfigs(FLAGS_config, &configs);
Jim Van Verth8a9a3712019-05-31 10:49:12 -04001037 AutoreleasePool pool;
kkinnunen3e980c32015-12-23 01:33:00 -08001038 for (int i = 0; i < configs.count(); i++) {
1039 const SkCommandLineConfig& config = *configs[i];
csmartdalton008b9d82017-02-22 12:00:42 -07001040 Sink* sink = create_sink(grCtxOptions, &config);
kkinnunen3e980c32015-12-23 01:33:00 -08001041 if (sink == nullptr) {
mtkleinc41fd922016-03-08 09:01:39 -08001042 info("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(),
1043 config.getTag().c_str());
kkinnunen3e980c32015-12-23 01:33:00 -08001044 continue;
1045 }
mtklein748ca3b2015-01-15 10:56:12 -08001046
kkinnunen3e980c32015-12-23 01:33:00 -08001047 const SkTArray<SkString>& parts = config.getViaParts();
1048 for (int j = parts.count(); j-- > 0;) {
1049 const SkString& part = parts[j];
1050 Sink* next = create_via(part, sink);
halcanary96fcdcc2015-08-27 07:41:13 -07001051 if (next == nullptr) {
mtkleinc41fd922016-03-08 09:01:39 -08001052 info("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(),
1053 part.c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001054 delete sink;
halcanary96fcdcc2015-08-27 07:41:13 -07001055 sink = nullptr;
mtklein748ca3b2015-01-15 10:56:12 -08001056 break;
1057 }
1058 sink = next;
1059 }
1060 if (sink) {
1061 push_sink(config, sink);
mtklein114c3cd2015-01-15 10:15:02 -08001062 }
1063 }
brianosman05c987c2016-05-09 13:42:16 -07001064
1065 // If no configs were requested (just running tests, perhaps?), then we're okay.
Ben Wagnerf28d4722017-08-11 17:33:22 -04001066 if (configs.count() == 0 ||
1067 // If we're using the default configs, we're okay.
1068 defaultConfigs ||
Ben Wagner32fa5102017-08-10 21:25:55 -04001069 // Otherwise, make sure that all specified configs have become sinks.
1070 configs.count() == gSinks.count()) {
1071 return true;
1072 }
Ben Wagner32fa5102017-08-10 21:25:55 -04001073 return false;
mtklein114c3cd2015-01-15 10:15:02 -08001074}
mtklein709d2c32015-01-15 08:30:25 -08001075
mtkleina2ef6422015-01-15 13:44:22 -08001076static bool match(const char* needle, const char* haystack) {
Chris Daltonecf78ac2017-08-15 15:43:08 -06001077 if ('~' == needle[0]) {
1078 return !match(needle + 1, haystack);
1079 }
1080 if (0 == strcmp("_", needle)) {
1081 return true;
1082 }
1083 return nullptr != strstr(haystack, needle);
mtkleina2ef6422015-01-15 13:44:22 -08001084}
1085
mtklein3eed7dd2016-02-24 19:07:07 -08001086static bool is_blacklisted(const char* sink, const char* src,
1087 const char* srcOptions, const char* name) {
mtklein0d243ff2015-04-03 07:51:00 -07001088 for (int i = 0; i < FLAGS_blacklist.count() - 3; i += 4) {
mtkleina2ef6422015-01-15 13:44:22 -08001089 if (match(FLAGS_blacklist[i+0], sink) &&
djsollen54416de2015-04-03 07:24:48 -07001090 match(FLAGS_blacklist[i+1], src) &&
1091 match(FLAGS_blacklist[i+2], srcOptions) &&
1092 match(FLAGS_blacklist[i+3], name)) {
mtklein3eed7dd2016-02-24 19:07:07 -08001093 return true;
mtkleina2ef6422015-01-15 13:44:22 -08001094 }
1095 }
mtklein3eed7dd2016-02-24 19:07:07 -08001096 return false;
mtkleina2ef6422015-01-15 13:44:22 -08001097}
1098
mtkleincd50bca2016-01-05 06:20:20 -08001099// Even when a Task Sink reports to be non-threadsafe (e.g. GPU), we know things like
1100// .png encoding are definitely thread safe. This lets us offload that work to CPU threads.
1101static SkTaskGroup gDefinitelyThreadSafeWork;
1102
mtklein748ca3b2015-01-15 10:56:12 -08001103// The finest-grained unit of work we can run: draw a single Src into a single Sink,
1104// report any errors, and perhaps write out the output: a .png of the bitmap, or a raw stream.
1105struct Task {
mtkleine0effd62015-07-29 06:37:28 -07001106 Task(const TaggedSrc& src, const TaggedSink& sink) : src(src), sink(sink) {}
1107 const TaggedSrc& src;
1108 const TaggedSink& sink;
mtklein748ca3b2015-01-15 10:56:12 -08001109
mtklein21eaf3b2016-02-08 12:39:59 -08001110 static void Run(const Task& task) {
Jim Van Verth8a9a3712019-05-31 10:49:12 -04001111 AutoreleasePool pool;
mtklein21eaf3b2016-02-08 12:39:59 -08001112 SkString name = task.src->name();
mtkleine0effd62015-07-29 06:37:28 -07001113
mtkleinb9eb4ac2015-02-02 18:26:03 -08001114 SkString log;
mtklein3eed7dd2016-02-24 19:07:07 -08001115 if (!FLAGS_dryRun) {
mtklein748ca3b2015-01-15 10:56:12 -08001116 SkBitmap bitmap;
1117 SkDynamicMemoryWStream stream;
mtklein3eed7dd2016-02-24 19:07:07 -08001118 start(task.sink.tag.c_str(), task.src.tag.c_str(),
1119 task.src.options.c_str(), name.c_str());
Ben Wagnerea25fcf2020-02-12 11:18:46 -05001120 Result result = task.sink->draw(*task.src, &bitmap, &stream, &log);
mtkleinb3b13b72016-03-07 13:20:52 -08001121 if (!log.isEmpty()) {
mtkleinc41fd922016-03-08 09:01:39 -08001122 info("%s %s %s %s:\n%s\n", task.sink.tag.c_str()
1123 , task.src.tag.c_str()
1124 , task.src.options.c_str()
1125 , name.c_str()
1126 , log.c_str());
mtkleinb3b13b72016-03-07 13:20:52 -08001127 }
Ben Wagnerea25fcf2020-02-12 11:18:46 -05001128 if (result.isSkip()) {
1129 done(task.sink.tag.c_str(), task.src.tag.c_str(),
1130 task.src.options.c_str(), name.c_str());
1131 return;
1132 }
1133 if (result.isFatal()) {
1134 fail(SkStringPrintf("%s %s %s %s: %s",
1135 task.sink.tag.c_str(),
1136 task.src.tag.c_str(),
1137 task.src.options.c_str(),
1138 name.c_str(),
1139 result.c_str()));
mtklein748ca3b2015-01-15 10:56:12 -08001140 }
mtklein62bd1a62015-01-27 14:46:26 -08001141
Tyler Denniston45f94f82020-02-04 16:09:08 -05001142 // Run verifiers if specified
1143 if (FLAGS_runVerifiers) {
1144 RunGMVerifiers(task, bitmap);
1145 }
1146
mtkleincd50bca2016-01-05 06:20:20 -08001147 // We're likely switching threads here, so we must capture by value, [=] or [foo,bar].
Hal Canary0b833192017-03-14 14:35:02 -04001148 SkStreamAsset* data = stream.detachAsStream().release();
mtkleincd50bca2016-01-05 06:20:20 -08001149 gDefinitelyThreadSafeWork.add([task,name,bitmap,data]{
Ben Wagner145dbcd2016-11-03 14:40:50 -04001150 std::unique_ptr<SkStreamAsset> ownedData(data);
mtkleincd50bca2016-01-05 06:20:20 -08001151
Mike Kleine1271702019-03-07 11:46:59 -06001152 std::unique_ptr<HashAndEncode> hashAndEncode;
1153
mtkleincd50bca2016-01-05 06:20:20 -08001154 SkString md5;
Brian Osman57796b32019-01-25 18:02:59 +00001155 if (!FLAGS_writePath.isEmpty() || !FLAGS_readPath.isEmpty()) {
mtkleincd50bca2016-01-05 06:20:20 -08001156 SkMD5 hash;
1157 if (data->getLength()) {
1158 hash.writeStream(data, data->getLength());
1159 data->rewind();
mtklein38408462015-07-08 07:25:27 -07001160 } else {
Mike Kleine1271702019-03-07 11:46:59 -06001161 hashAndEncode.reset(new HashAndEncode(bitmap));
1162 hashAndEncode->write(&hash);
mtkleincd50bca2016-01-05 06:20:20 -08001163 }
Hal Canary0f2f5222019-04-03 10:13:45 -04001164 SkMD5::Digest digest = hash.finish();
mtkleincd50bca2016-01-05 06:20:20 -08001165 for (int i = 0; i < 16; i++) {
1166 md5.appendf("%02x", digest.data[i]);
mtklein38408462015-07-08 07:25:27 -07001167 }
mtklein62bd1a62015-01-27 14:46:26 -08001168 }
mtklein62bd1a62015-01-27 14:46:26 -08001169
Brian Osman57796b32019-01-25 18:02:59 +00001170 if (!FLAGS_readPath.isEmpty() &&
1171 !gGold.contains(Gold(task.sink.tag, task.src.tag,
1172 task.src.options, name, md5))) {
1173 fail(SkStringPrintf("%s not found for %s %s %s %s in %s",
1174 md5.c_str(),
1175 task.sink.tag.c_str(),
1176 task.src.tag.c_str(),
1177 task.src.options.c_str(),
1178 name.c_str(),
1179 FLAGS_readPath[0]));
1180 }
1181
Mike Klein055f5352020-01-30 11:11:12 -06001182 // Tests sometimes use a nullptr ext to indicate no image should be uploaded.
1183 const char* ext = task.sink->fileExtension();
1184 if (ext && !FLAGS_writePath.isEmpty()) {
1185 #if defined(SK_BUILD_FOR_MAC)
1186 if (FLAGS_rasterize_pdf && SkString("pdf").equals(ext)) {
1187 SkASSERT(data->getLength() > 0);
1188
1189 sk_sp<SkData> blob = SkData::MakeFromStream(data, data->getLength());
1190
1191 SkUniqueCFRef<CGDataProviderRef> provider{
1192 CGDataProviderCreateWithData(nullptr,
1193 blob->data(),
1194 blob->size(),
1195 nullptr)};
1196
1197 SkUniqueCFRef<CGPDFDocumentRef> pdf{
1198 CGPDFDocumentCreateWithProvider(provider.get())};
1199
1200 CGPDFPageRef page = CGPDFDocumentGetPage(pdf.get(), 1);
1201
1202 CGRect bounds = CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
1203 const int w = (int)CGRectGetWidth (bounds),
1204 h = (int)CGRectGetHeight(bounds);
1205
1206 SkBitmap rasterized;
1207 rasterized.allocPixels(
1208 SkImageInfo::Make(w,h, kRGBA_8888_SkColorType, kPremul_SkAlphaType));
1209 rasterized.eraseColor(SK_ColorWHITE);
1210
1211 SkUniqueCFRef<CGColorSpaceRef> cs{
1212 CGColorSpaceCreateDeviceRGB()};
1213 CGBitmapInfo info = kCGBitmapByteOrder32Big
1214 | kCGImageAlphaPremultipliedLast;
1215
1216 SkUniqueCFRef<CGContextRef> ctx{
1217 CGBitmapContextCreate(rasterized.getPixels(),
1218 w,h,8,rasterized.rowBytes(), cs.get(),info)};
1219 CGContextDrawPDFPage(ctx.get(), page);
1220
1221
1222 // Skip calling hashAndEncode->write(SkMD5*)... we want the .pdf's hash.
1223 hashAndEncode.reset(new HashAndEncode(rasterized));
1224 WriteToDisk(task, md5, "png", nullptr,0, &rasterized, hashAndEncode.get());
1225 } else
1226 #endif
1227 if (data->getLength()) {
1228 WriteToDisk(task, md5, ext, data, data->getLength(), nullptr, nullptr);
1229 SkASSERT(bitmap.drawsNothing());
1230 } else if (!bitmap.drawsNothing()) {
1231 WriteToDisk(task, md5, ext, nullptr, 0, &bitmap, hashAndEncode.get());
mtkleincd50bca2016-01-05 06:20:20 -08001232 }
1233 }
Brian Osman582f6862019-03-11 11:20:55 -04001234
1235 SkPixmap pm;
1236 if (FLAGS_checkF16 && bitmap.colorType() == kRGBA_F16Norm_SkColorType &&
1237 bitmap.peekPixels(&pm)) {
1238 bool unclamped = false;
1239 for (int y = 0; y < pm.height() && !unclamped; ++y)
1240 for (int x = 0; x < pm.width() && !unclamped; ++x) {
1241 Sk4f rgba = SkHalfToFloat_finite_ftz(*pm.addr64(x, y));
1242 float a = rgba[3];
1243 if (a > 1.0f || (rgba < 0.0f).anyTrue() || (rgba > a).anyTrue()) {
Brian Osmanb73e6072019-03-15 10:02:16 -04001244 SkDebugf("[%s] F16Norm pixel [%d, %d] unclamped: (%g, %g, %g, %g)\n",
1245 name.c_str(), x, y, rgba[0], rgba[1], rgba[2], rgba[3]);
Brian Osman582f6862019-03-11 11:20:55 -04001246 unclamped = true;
1247 }
1248 }
1249 }
mtkleincd50bca2016-01-05 06:20:20 -08001250 });
mtklein748ca3b2015-01-15 10:56:12 -08001251 }
mtklein3eed7dd2016-02-24 19:07:07 -08001252 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 -08001253 }
1254
Mike Klein66f09a72019-02-12 13:03:54 -05001255 static SkString identify_gamut(SkColorSpace* cs) {
1256 if (!cs) {
1257 return SkString("untagged");
1258 }
1259
1260 skcms_Matrix3x3 gamut;
1261 if (cs->toXYZD50(&gamut)) {
1262 auto eq = [](skcms_Matrix3x3 x, skcms_Matrix3x3 y) {
1263 for (int i = 0; i < 3; i++)
1264 for (int j = 0; j < 3; j++) {
1265 if (x.vals[i][j] != y.vals[i][j]) { return false; }
1266 }
1267 return true;
1268 };
1269
Mike Kleinb147ace2020-01-16 11:11:06 -06001270 if (eq(gamut, SkNamedGamut::kSRGB )) { return SkString("sRGB"); }
1271 if (eq(gamut, SkNamedGamut::kAdobeRGB )) { return SkString("Adobe"); }
1272 if (eq(gamut, SkNamedGamut::kDisplayP3)) { return SkString("P3"); }
1273 if (eq(gamut, SkNamedGamut::kRec2020 )) { return SkString("2020"); }
1274 if (eq(gamut, SkNamedGamut::kXYZ )) { return SkString("XYZ"); }
1275 if (eq(gamut, gNarrow_toXYZD50 )) { return SkString("narrow"); }
Mike Klein66f09a72019-02-12 13:03:54 -05001276 return SkString("other");
1277 }
1278 return SkString("non-XYZ");
1279 }
1280
1281 static SkString identify_transfer_fn(SkColorSpace* cs) {
1282 if (!cs) {
1283 return SkString("untagged");
1284 }
1285
Brian Osman11e6aa82019-10-16 13:58:42 -04001286 auto eq = [](skcms_TransferFunction x, skcms_TransferFunction y) {
1287 return x.g == y.g
1288 && x.a == y.a
1289 && x.b == y.b
1290 && x.c == y.c
1291 && x.d == y.d
1292 && x.e == y.e
1293 && x.f == y.f;
1294 };
Mike Klein66f09a72019-02-12 13:03:54 -05001295
Brian Osman11e6aa82019-10-16 13:58:42 -04001296 skcms_TransferFunction tf;
Brian Osman09ee1122019-11-05 11:41:16 -05001297 cs->transferFn(&tf);
Brian Osman11e6aa82019-10-16 13:58:42 -04001298 switch (classify_transfer_fn(tf)) {
1299 case sRGBish_TF:
1300 if (tf.a == 1 && tf.b == 0 && tf.c == 0 && tf.d == 0 && tf.e == 0 && tf.f == 0) {
1301 return SkStringPrintf("gamma %.3g", tf.g);
1302 }
1303 if (eq(tf, SkNamedTransferFn::kSRGB)) { return SkString("sRGB"); }
1304 if (eq(tf, SkNamedTransferFn::kRec2020)) { return SkString("2020"); }
1305 return SkStringPrintf("%.3g %.3g %.3g %.3g %.3g %.3g %.3g",
1306 tf.g, tf.a, tf.b, tf.c, tf.d, tf.e, tf.f);
1307
1308 case PQish_TF:
1309 if (eq(tf, SkNamedTransferFn::kPQ)) { return SkString("PQ"); }
1310 return SkStringPrintf("PQish %.3g %.3g %.3g %.3g %.3g %.3g",
1311 tf.a, tf.b, tf.c, tf.d, tf.e, tf.f);
1312
1313 case HLGish_TF:
1314 if (eq(tf, SkNamedTransferFn::kHLG)) { return SkString("HLG"); }
1315 return SkStringPrintf("HLGish %.3g %.3g %.3g %.3g %.3g",
1316 tf.a, tf.b, tf.c, tf.d, tf.e);
1317
1318 case HLGinvish_TF: break;
1319 case Bad_TF: break;
Mike Klein66f09a72019-02-12 13:03:54 -05001320 }
1321 return SkString("non-numeric");
1322 }
1323
mtklein748ca3b2015-01-15 10:56:12 -08001324 static void WriteToDisk(const Task& task,
mtklein62bd1a62015-01-27 14:46:26 -08001325 SkString md5,
1326 const char* ext,
mtklein748ca3b2015-01-15 10:56:12 -08001327 SkStream* data, size_t len,
Mike Kleine1271702019-03-07 11:46:59 -06001328 const SkBitmap* bitmap,
1329 const HashAndEncode* hashAndEncode) {
mtklein409d4702016-02-29 07:38:01 -08001330
mtklein748ca3b2015-01-15 10:56:12 -08001331 JsonWriter::BitmapResult result;
djsollen54416de2015-04-03 07:24:48 -07001332 result.name = task.src->name();
mtklein3eed7dd2016-02-24 19:07:07 -08001333 result.config = task.sink.tag;
djsollen54416de2015-04-03 07:24:48 -07001334 result.sourceType = task.src.tag;
1335 result.sourceOptions = task.src.options;
1336 result.ext = ext;
1337 result.md5 = md5;
Mike Klein0abbaca2019-03-06 09:57:49 -06001338 if (bitmap) {
Mike Klein98168782019-04-09 13:45:02 -05001339 result.gamut = identify_gamut (bitmap->colorSpace());
1340 result.transferFn = identify_transfer_fn (bitmap->colorSpace());
1341 result.colorType = ToolUtils::colortype_name (bitmap->colorType());
1342 result.alphaType = ToolUtils::alphatype_name (bitmap->alphaType());
1343 result.colorDepth = ToolUtils::colortype_depth(bitmap->colorType());
Mike Klein0abbaca2019-03-06 09:57:49 -06001344 }
mtklein748ca3b2015-01-15 10:56:12 -08001345 JsonWriter::AddBitmapResult(result);
1346
mtkleinb0531a72015-04-07 13:38:48 -07001347 // If an MD5 is uninteresting, we want it noted in the JSON file,
1348 // but don't want to dump it out as a .png (or whatever ext is).
1349 if (gUninterestingHashes.contains(md5)) {
1350 return;
1351 }
1352
mtklein748ca3b2015-01-15 10:56:12 -08001353 const char* dir = FLAGS_writePath[0];
Mike Kleinc6142d82019-03-25 10:54:59 -05001354 SkString resources = GetResourcePath();
mtklein748ca3b2015-01-15 10:56:12 -08001355 if (0 == strcmp(dir, "@")) { // Needed for iOS.
Mike Kleinc6142d82019-03-25 10:54:59 -05001356 dir = resources.c_str();
mtklein748ca3b2015-01-15 10:56:12 -08001357 }
1358 sk_mkdir(dir);
1359
1360 SkString path;
1361 if (FLAGS_nameByHash) {
1362 path = SkOSPath::Join(dir, result.md5.c_str());
1363 path.append(".");
1364 path.append(ext);
1365 if (sk_exists(path.c_str())) {
1366 return; // Content-addressed. If it exists already, we're done.
1367 }
1368 } else {
kkinnunen3e980c32015-12-23 01:33:00 -08001369 path = SkOSPath::Join(dir, task.sink.tag.c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001370 sk_mkdir(path.c_str());
msarett9e707a02015-09-01 14:57:57 -07001371 path = SkOSPath::Join(path.c_str(), task.src.tag.c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001372 sk_mkdir(path.c_str());
msarett9e707a02015-09-01 14:57:57 -07001373 if (strcmp(task.src.options.c_str(), "") != 0) {
1374 path = SkOSPath::Join(path.c_str(), task.src.options.c_str());
djsollen54416de2015-04-03 07:24:48 -07001375 sk_mkdir(path.c_str());
1376 }
mtklein748ca3b2015-01-15 10:56:12 -08001377 path = SkOSPath::Join(path.c_str(), task.src->name().c_str());
1378 path.append(".");
1379 path.append(ext);
1380 }
1381
mtklein748ca3b2015-01-15 10:56:12 -08001382 if (bitmap) {
Mike Kleine1271702019-03-07 11:46:59 -06001383 SkASSERT(hashAndEncode);
Mike Klein735c7ba2019-03-25 12:57:58 -05001384 if (!hashAndEncode->writePngTo(path.c_str(),
1385 result.md5.c_str(),
1386 FLAGS_key,
1387 FLAGS_properties)) {
mtklein748ca3b2015-01-15 10:56:12 -08001388 fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str()));
1389 return;
1390 }
1391 } else {
mtkleina5114d72015-08-24 13:27:01 -07001392 SkFILEWStream file(path.c_str());
1393 if (!file.isValid()) {
1394 fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str()));
1395 return;
1396 }
mtklein748ca3b2015-01-15 10:56:12 -08001397 if (!file.writeStream(data, len)) {
1398 fail(SkStringPrintf("Can't write to %s.\n", path.c_str()));
1399 return;
1400 }
1401 }
1402 }
Tyler Denniston45f94f82020-02-04 16:09:08 -05001403
1404 static void RunGMVerifiers(const Task& task, const SkBitmap& actualBitmap) {
1405 const SkString name = task.src->name();
1406 auto verifierList = task.src->getVerifiers();
1407 if (verifierList == nullptr) {
1408 return;
1409 }
1410
1411 skiagm::verifiers::VerifierResult
1412 res = verifierList->verifyAll(task.sink->colorInfo(), actualBitmap);
1413 if (!res.ok()) {
1414 fail(
1415 SkStringPrintf(
1416 "%s %s %s %s: verifier failed: %s", task.sink.tag.c_str(), task.src.tag.c_str(),
1417 task.src.options.c_str(), name.c_str(), res.message().c_str()));
1418 }
1419 }
mtklein748ca3b2015-01-15 10:56:12 -08001420};
1421
mtklein748ca3b2015-01-15 10:56:12 -08001422/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1423
1424// Unit tests don't fit so well into the Src/Sink model, so we give them special treatment.
1425
mtklein21eaf3b2016-02-08 12:39:59 -08001426static SkTDArray<skiatest::Test> gParallelTests, gSerialTests;
mtklein748ca3b2015-01-15 10:56:12 -08001427
1428static void gather_tests() {
mtklein6c5fed22015-01-20 13:47:23 -08001429 if (!FLAGS_src.contains("tests")) {
mtklein748ca3b2015-01-15 10:56:12 -08001430 return;
1431 }
Hal Canary972eba32018-07-30 17:07:07 -04001432 for (const skiatest::Test& test : skiatest::TestRegistry::Range()) {
mtklein6393c062015-04-27 08:45:01 -07001433 if (!in_shard()) {
1434 continue;
1435 }
Mike Klein88544fb2019-03-20 10:50:33 -05001436 if (CommandLineFlags::ShouldSkip(FLAGS_match, test.name)) {
mtklein748ca3b2015-01-15 10:56:12 -08001437 continue;
1438 }
Brian Osmanc7ad40f2018-05-31 14:27:17 -04001439 if (test.needsGpu && FLAGS_gpu) {
Brian Osman3fdfe282019-09-09 13:46:52 -04001440 gSerialTests.push_back(test);
halcanary87f3ba42015-01-20 09:30:20 -08001441 } else if (!test.needsGpu && FLAGS_cpu) {
Mike Reed5edcd312018-08-08 11:23:41 -04001442 gParallelTests.push_back(test);
mtklein82d28432015-01-15 12:46:02 -08001443 }
mtklein748ca3b2015-01-15 10:56:12 -08001444 }
1445}
1446
csmartdalton008b9d82017-02-22 12:00:42 -07001447static void run_test(skiatest::Test test, const GrContextOptions& grCtxOptions) {
halcanary87f3ba42015-01-20 09:30:20 -08001448 struct : public skiatest::Reporter {
mtklein36352bf2015-03-25 18:17:31 -07001449 void reportFailed(const skiatest::Failure& failure) override {
halcanary87f3ba42015-01-20 09:30:20 -08001450 fail(failure.toString());
halcanary87f3ba42015-01-20 09:30:20 -08001451 }
mtklein36352bf2015-03-25 18:17:31 -07001452 bool allowExtendedTest() const override {
halcanary87f3ba42015-01-20 09:30:20 -08001453 return FLAGS_pathOpsExtended;
1454 }
mtklein36352bf2015-03-25 18:17:31 -07001455 bool verbose() const override { return FLAGS_veryVerbose; }
halcanary87f3ba42015-01-20 09:30:20 -08001456 } reporter;
djsollen824996a2015-06-12 12:06:22 -07001457
mtklein3eed7dd2016-02-24 19:07:07 -08001458 if (!FLAGS_dryRun && !is_blacklisted("_", "tests", "_", test.name)) {
Jim Van Verth8a9a3712019-05-31 10:49:12 -04001459 AutoreleasePool pool;
Robert Phillipsec325342017-10-30 18:02:48 +00001460 GrContextOptions options = grCtxOptions;
1461 test.modifyGrContextOptions(&options);
1462
Brian Osmancdf31742019-03-13 10:13:46 -04001463 skiatest::ReporterContext ctx(&reporter, SkString(test.name));
mtklein21eaf3b2016-02-08 12:39:59 -08001464 start("unit", "test", "", test.name);
Brian Salomondcfca432017-11-15 15:48:03 -05001465 test.run(&reporter, options);
mtklein748ca3b2015-01-15 10:56:12 -08001466 }
mtklein3eed7dd2016-02-24 19:07:07 -08001467 done("unit", "test", "", test.name);
mtklein748ca3b2015-01-15 10:56:12 -08001468}
1469
1470/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1471
Mike Kleinbe28ee22017-02-06 12:46:20 -05001472int main(int argc, char** argv) {
Brian Osman1c1208e2019-06-24 13:36:05 -04001473#if defined(__MSVC_RUNTIME_CHECKS)
1474 _RTC_SetErrorFunc(RuntimeCheckErrorFunc);
1475#endif
Dongwon Kang0c7861f2018-02-16 10:55:21 -08001476#if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && defined(SK_HAS_HEIF_LIBRARY)
1477 android::ProcessState::self()->startThreadPool();
1478#endif
Mike Klein88544fb2019-03-20 10:50:33 -05001479 CommandLineFlags::Parse(argc, argv);
Brian Osman53136aa2017-07-20 15:43:35 -04001480
Brian Osmanbc8150f2017-07-24 11:38:01 -04001481 initializeEventTracingForTools();
Brian Osman53136aa2017-07-20 15:43:35 -04001482
Mike Klein6613cc52017-12-19 09:09:33 -05001483#if !defined(SK_BUILD_FOR_GOOGLE3) && defined(SK_BUILD_FOR_IOS)
Mike Kleinadacaef2017-02-06 09:26:14 -05001484 cd_Documents();
1485#endif
bsalomon71de3532016-04-26 14:27:21 -07001486 setbuf(stdout, nullptr);
mtklein246ba3a2016-02-23 10:39:36 -08001487 setup_crash_handler();
mtkleinafae30a2016-02-24 12:28:32 -08001488
Mike Klein19cc0f62019-03-22 15:30:07 -05001489 ToolUtils::SetDefaultFontMgr();
Mike Klein03fa5d42019-03-22 11:39:09 -05001490 SetAnalyticAAFromCommonFlags();
liyuqian38911a72016-10-04 11:23:22 -07001491
Mike Klein9ae06632020-01-28 12:41:02 -06001492 gSkForceRasterPipelineBlitter = FLAGS_forceRasterPipeline;
1493 gUseSkVMBlitter = FLAGS_skvm;
Yuqian Li550148b2017-01-13 10:13:13 -05001494
Mike Kleine9f187b2017-06-26 13:23:12 -04001495 // The bots like having a verbose.log to upload, so always touch the file even if --verbose.
1496 if (!FLAGS_writePath.isEmpty()) {
mtklein51c8cfc2016-03-11 12:59:09 -08001497 sk_mkdir(FLAGS_writePath[0]);
mtkleina1ce2162016-07-22 12:23:46 -07001498 gVLog = fopen(SkOSPath::Join(FLAGS_writePath[0], "verbose.log").c_str(), "w");
mtkleinc41fd922016-03-08 09:01:39 -08001499 }
Mike Kleine9f187b2017-06-26 13:23:12 -04001500 if (FLAGS_verbose) {
1501 gVLog = stderr;
1502 }
mtkleinc41fd922016-03-08 09:01:39 -08001503
csmartdalton008b9d82017-02-22 12:00:42 -07001504 GrContextOptions grCtxOptions;
Chris Dalton040238b2017-12-18 14:22:34 -07001505 SetCtxOptionsFromCommonFlags(&grCtxOptions);
csmartdalton008b9d82017-02-22 12:00:42 -07001506
Mike Kleinc6142d82019-03-25 10:54:59 -05001507 dump_json(); // It's handy for the bots to assume this is ~never missing.
1508
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +00001509 SkAutoGraphics ag;
mtklein406654b2014-09-03 15:34:37 -07001510 SkTaskGroup::Enabler enabled(FLAGS_threads);
commit-bot@chromium.orga65e2fd2014-05-30 17:23:31 +00001511
Mike Reed0933bc92017-12-09 01:27:41 +00001512 if (nullptr == GetResourceAsData("images/color_wheel.png")) {
1513 info("Some resources are missing. Do you need to set --resourcePath?\n");
halcanary7d571242016-02-24 17:59:16 -08001514 }
Brian Osman57796b32019-01-25 18:02:59 +00001515 gather_gold();
borenet09ed4802015-04-03 14:15:33 -07001516 gather_uninteresting_hashes();
mtklein62bd1a62015-01-27 14:46:26 -08001517
scroggo86737142016-02-03 12:19:11 -08001518 if (!gather_srcs()) {
1519 return 1;
1520 }
Ben Wagnerf28d4722017-08-11 17:33:22 -04001521 // TODO(dogben): This is a bit ugly. Find a cleaner way to do this.
1522 bool defaultConfigs = true;
1523 for (int i = 0; i < argc; i++) {
1524 static const char* kConfigArg = "--config";
1525 if (strcmp(argv[i], kConfigArg) == 0) {
1526 defaultConfigs = false;
1527 break;
1528 }
1529 }
1530 if (!gather_sinks(grCtxOptions, defaultConfigs)) {
brianosman05c987c2016-05-09 13:42:16 -07001531 return 1;
1532 }
mtklein748ca3b2015-01-15 10:56:12 -08001533 gather_tests();
mtklein21eaf3b2016-02-08 12:39:59 -08001534 gPending = gSrcs.count() * gSinks.count() + gParallelTests.count() + gSerialTests.count();
Brian Osmand0677bc2017-08-03 12:13:47 -04001535 info("%d srcs * %d sinks + %d tests == %d tasks\n",
mtkleinc41fd922016-03-08 09:01:39 -08001536 gSrcs.count(), gSinks.count(), gParallelTests.count() + gSerialTests.count(), gPending);
mtklein748ca3b2015-01-15 10:56:12 -08001537
mtklein21eaf3b2016-02-08 12:39:59 -08001538 // Kick off as much parallel work as we can, making note of any serial work we'll need to do.
1539 SkTaskGroup parallel;
1540 SkTArray<Task> serial;
1541
1542 for (auto& sink : gSinks)
1543 for (auto& src : gSrcs) {
mtklein3eed7dd2016-02-24 19:07:07 -08001544 if (src->veto(sink->flags()) ||
1545 is_blacklisted(sink.tag.c_str(), src.tag.c_str(),
1546 src.options.c_str(), src->name().c_str())) {
Herb Derbya1b7be62019-05-09 16:59:18 -04001547 SkAutoSpinlock lock(gMutex);
mtklein3eed7dd2016-02-24 19:07:07 -08001548 gPending--;
1549 continue;
1550 }
1551
mtklein21eaf3b2016-02-08 12:39:59 -08001552 Task task(src, sink);
1553 if (src->serial() || sink->serial()) {
1554 serial.push_back(task);
1555 } else {
1556 parallel.add([task] { Task::Run(task); });
mtklein748ca3b2015-01-15 10:56:12 -08001557 }
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001558 }
mtklein21eaf3b2016-02-08 12:39:59 -08001559 for (auto test : gParallelTests) {
csmartdalton008b9d82017-02-22 12:00:42 -07001560 parallel.add([test, grCtxOptions] { run_test(test, grCtxOptions); });
mtklein55e88b22015-01-21 15:50:13 -08001561 }
mtklein21eaf3b2016-02-08 12:39:59 -08001562
1563 // With the parallel work running, run serial tasks and tests here on main thread.
1564 for (auto task : serial) { Task::Run(task); }
csmartdalton008b9d82017-02-22 12:00:42 -07001565 for (auto test : gSerialTests) { run_test(test, grCtxOptions); }
mtklein21eaf3b2016-02-08 12:39:59 -08001566
1567 // Wait for any remaining parallel work to complete (including any spun off of serial tasks).
1568 parallel.wait();
mtkleincd50bca2016-01-05 06:20:20 -08001569 gDefinitelyThreadSafeWork.wait();
1570
Ben Wagner83c6b962018-07-10 19:40:15 -04001571 // At this point we're back in single-threaded land.
1572
mtkleinda884c42016-02-24 18:00:23 -08001573 // We'd better have run everything.
1574 SkASSERT(gPending == 0);
mtkleine027f172016-02-26 15:53:06 -08001575 // Make sure we've flushed all our results to disk.
Mike Kleinc6142d82019-03-25 10:54:59 -05001576 dump_json();
mtkleinda884c42016-02-24 18:00:23 -08001577
mtklein748ca3b2015-01-15 10:56:12 -08001578 if (gFailures.count() > 0) {
mtkleinc41fd922016-03-08 09:01:39 -08001579 info("Failures:\n");
mtklein748ca3b2015-01-15 10:56:12 -08001580 for (int i = 0; i < gFailures.count(); i++) {
mtkleinc41fd922016-03-08 09:01:39 -08001581 info("\t%s\n", gFailures[i].c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001582 }
mtkleinc41fd922016-03-08 09:01:39 -08001583 info("%d failures\n", gFailures.count());
Kevin Lubick805c4e82019-03-20 09:46:09 -04001584 // A non-zero return code does not make it to Swarming
1585 // An abort does.
1586#ifdef SK_BUILD_FOR_IOS
Kevin Lubickc4fec062019-05-31 12:31:09 +00001587 SK_ABORT("There were failures!");
Kevin Lubick805c4e82019-03-20 09:46:09 -04001588#endif
mtklein748ca3b2015-01-15 10:56:12 -08001589 return 1;
mtklein114c3cd2015-01-15 10:15:02 -08001590 }
mtkleinafae30a2016-02-24 12:28:32 -08001591
Herb Derby5a523fe2017-01-26 16:48:28 -05001592 SkGraphics::PurgeAllCaches();
mtkleinc41fd922016-03-08 09:01:39 -08001593 info("Finished!\n");
Brian Osman53136aa2017-07-20 15:43:35 -04001594
mtklein748ca3b2015-01-15 10:56:12 -08001595 return 0;
mtklein@google.comd36522d2013-10-16 13:02:15 +00001596}