blob: bdf9f6e139ddea70864dc233d9eccf4a9a740cb8 [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 Kleineb678fc2019-03-20 12:01:47 -05008#include "ChromeTracingTracer.h"
Mike Klein88544fb2019-03-20 10:50:33 -05009#include "CommonFlags.h"
10#include "CommonFlagsConfig.h"
mtklein748ca3b2015-01-15 10:56:12 -080011#include "DMJsonWriter.h"
12#include "DMSrcSink.h"
Mike Kleineb678fc2019-03-20 12:01:47 -050013#include "EventTracingPriv.h"
Mike Klein735c7ba2019-03-25 12:57:58 -050014#include "HashAndEncode.h"
mtklein748ca3b2015-01-15 10:56:12 -080015#include "ProcStats.h"
halcanary7d571242016-02-24 17:59:16 -080016#include "Resources.h"
mtklein748ca3b2015-01-15 10:56:12 -080017#include "SkBBHFactory.h"
mtklein62bd1a62015-01-27 14:46:26 -080018#include "SkChecksum.h"
scroggocc2feb12015-08-14 08:32:46 -070019#include "SkCodec.h"
mtklein27c3fdd2016-02-26 14:43:21 -080020#include "SkColorPriv.h"
msarett888dc162016-05-23 10:21:17 -070021#include "SkColorSpace.h"
Mike Klein919cc452017-03-18 15:36:52 +000022#include "SkColorSpacePriv.h"
brianosman3c579dc2016-04-19 09:18:11 -070023#include "SkData.h"
Brian Salomondcbb9d92017-07-19 10:53:20 -040024#include "SkDebugfTracer.h"
Hal Canaryd7b38452017-12-11 17:46:26 -050025#include "SkDocument.h"
caryclark83ca6282015-06-10 09:31:09 -070026#include "SkFontMgr.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000027#include "SkGraphics.h"
mtklein27c3fdd2016-02-26 14:43:21 -080028#include "SkHalf.h"
halcanary4dbbd042016-06-07 17:21:10 -070029#include "SkLeanWindows.h"
mtklein748ca3b2015-01-15 10:56:12 -080030#include "SkMD5.h"
mtklein1b249332015-07-07 12:21:21 -070031#include "SkMutex.h"
mtklein1d0f1642014-09-08 08:05:18 -070032#include "SkOSFile.h"
Ben Wagnerbf111d72016-11-07 18:05:29 -050033#include "SkOSPath.h"
mtklein246ba3a2016-02-23 10:39:36 -080034#include "SkSpinlock.h"
mtkleina82f5622015-02-20 12:30:19 -080035#include "SkTHash.h"
mtklein406654b2014-09-03 15:34:37 -070036#include "SkTaskGroup.h"
Mike Klein0c5fdcb2017-11-13 12:40:46 -050037#include "SkTypeface_win.h"
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000038#include "Test.h"
Mike Kleinea3f0142019-03-20 11:12:10 -050039#include "ToolUtils.h"
Mike Kleinadacaef2017-02-06 09:26:14 -050040#include "ios_utils.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 constexpr skcms_TransferFunction k2020_TF =
156 {2.22222f, 0.909672f, 0.0903276f, 0.222222f, 0.0812429f, 0, 0};
157
158static sk_sp<SkColorSpace> rec2020() {
159 return SkColorSpace::MakeRGB(k2020_TF, SkNamedGamut::kRec2020);
160}
161
162/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
163
mtkleinc41fd922016-03-08 09:01:39 -0800164static FILE* gVLog;
165
166template <typename... Args>
167static void vlog(const char* fmt, Args&&... args) {
168 if (gVLog) {
mtkleinc41fd922016-03-08 09:01:39 -0800169 fprintf(gVLog, fmt, args...);
170 fflush(gVLog);
171 }
172}
173
174template <typename... Args>
175static void info(const char* fmt, Args&&... args) {
176 vlog(fmt, args...);
177 if (!FLAGS_quiet) {
178 printf(fmt, args...);
179 }
180}
181static void info(const char* fmt) {
182 if (!FLAGS_quiet) {
183 printf("%s", fmt); // Clang warns printf(fmt) is insecure.
184 }
185}
186
reed086eea92016-05-04 17:12:46 -0700187SK_DECLARE_STATIC_MUTEX(gFailuresMutex);
mtklein748ca3b2015-01-15 10:56:12 -0800188static SkTArray<SkString> gFailures;
189
mtklein3eed7dd2016-02-24 19:07:07 -0800190static void fail(const SkString& err) {
mtklein748ca3b2015-01-15 10:56:12 -0800191 SkAutoMutexAcquire lock(gFailuresMutex);
192 SkDebugf("\n\nFAILURE: %s\n\n", err.c_str());
193 gFailures.push_back(err);
halcanary9e398f72015-01-10 11:18:04 -0800194}
195
mtklein0f7748a2016-07-25 15:27:29 -0700196struct Running {
197 SkString id;
198 SkThreadID thread;
199
200 void dump() const {
201 info("\t%s\n", id.c_str());
202 }
203};
mtkleinb37cb412015-03-18 05:27:14 -0700204
Mike Kleinc6142d82019-03-25 10:54:59 -0500205static void dump_json() {
206 if (!FLAGS_writePath.isEmpty()) {
207 JsonWriter::DumpJson(FLAGS_writePath[0], FLAGS_key, FLAGS_properties);
208 }
209}
210
mtklein246ba3a2016-02-23 10:39:36 -0800211// We use a spinlock to make locking this in a signal handler _somewhat_ safe.
Mike Klein03a95ad2017-06-23 12:36:32 -0400212static SkSpinlock gMutex;
213static int gPending;
mtklein0f7748a2016-07-25 15:27:29 -0700214static SkTArray<Running> gRunning;
mtklein748ca3b2015-01-15 10:56:12 -0800215
mtklein3eed7dd2016-02-24 19:07:07 -0800216static void done(const char* config, const char* src, const char* srcOptions, const char* name) {
217 SkString id = SkStringPrintf("%s %s %s %s", config, src, srcOptions, name);
mtkleinc41fd922016-03-08 09:01:39 -0800218 vlog("done %s\n", id.c_str());
mtkleinafae30a2016-02-24 12:28:32 -0800219 int pending;
mtkleinb37cb412015-03-18 05:27:14 -0700220 {
mtkleinf10637f2016-06-10 13:56:35 -0700221 SkAutoMutexAcquire lock(gMutex);
mtkleinb37cb412015-03-18 05:27:14 -0700222 for (int i = 0; i < gRunning.count(); i++) {
mtklein0f7748a2016-07-25 15:27:29 -0700223 if (gRunning[i].id == id) {
mtkleinb37cb412015-03-18 05:27:14 -0700224 gRunning.removeShuffle(i);
225 break;
226 }
227 }
mtkleinafae30a2016-02-24 12:28:32 -0800228 pending = --gPending;
reed50bc0512015-05-19 14:13:31 -0700229 }
Mike Klein03a95ad2017-06-23 12:36:32 -0400230
231 // We write out dm.json file and print out a progress update every once in a while.
232 // Notice this also handles the final dm.json and progress update when pending == 0.
mtkleina17241b2015-01-23 05:48:00 -0800233 if (pending % 500 == 0) {
Mike Kleinc6142d82019-03-25 10:54:59 -0500234 dump_json();
Mike Klein03a95ad2017-06-23 12:36:32 -0400235
236 int curr = sk_tools::getCurrResidentSetSizeMB(),
237 peak = sk_tools::getMaxResidentSetSizeMB();
Mike Klein03a95ad2017-06-23 12:36:32 -0400238
239 SkAutoMutexAcquire lock(gMutex);
Mike Klein21ba7722018-10-02 13:57:44 +0000240 info("\n%dMB RAM, %dMB peak, %d queued, %d active:\n",
241 curr, peak, gPending - gRunning.count(), gRunning.count());
Mike Klein03a95ad2017-06-23 12:36:32 -0400242 for (auto& task : gRunning) {
243 task.dump();
244 }
mtkleina17241b2015-01-23 05:48:00 -0800245 }
mtklein@google.comd36522d2013-10-16 13:02:15 +0000246}
247
mtklein3eed7dd2016-02-24 19:07:07 -0800248static void start(const char* config, const char* src, const char* srcOptions, const char* name) {
249 SkString id = SkStringPrintf("%s %s %s %s", config, src, srcOptions, name);
mtkleinc41fd922016-03-08 09:01:39 -0800250 vlog("start %s\n", id.c_str());
mtkleinf10637f2016-06-10 13:56:35 -0700251 SkAutoMutexAcquire lock(gMutex);
mtklein0f7748a2016-07-25 15:27:29 -0700252 gRunning.push_back({id,SkGetThreadID()});
mtkleinb37cb412015-03-18 05:27:14 -0700253}
254
Mike Klein3cc2d202016-10-24 11:39:43 -0400255static void find_culprit() {
256 // Assumes gMutex is locked.
257 SkThreadID thisThread = SkGetThreadID();
258 for (auto& task : gRunning) {
259 if (task.thread == thisThread) {
260 info("Likely culprit:\n");
261 task.dump();
mtklein0f7748a2016-07-25 15:27:29 -0700262 }
263 }
Mike Klein3cc2d202016-10-24 11:39:43 -0400264}
mtklein0f7748a2016-07-25 15:27:29 -0700265
Mike Klein8f11d4d2018-01-24 12:42:55 -0500266#if defined(SK_BUILD_FOR_WIN)
mtklein5b64dab2016-06-09 08:59:48 -0700267 static LONG WINAPI crash_handler(EXCEPTION_POINTERS* e) {
mtkleinf8557292016-02-29 06:35:28 -0800268 static const struct {
269 const char* name;
robertphillips75467862016-03-01 14:10:23 -0800270 DWORD code;
mtkleinf8557292016-02-29 06:35:28 -0800271 } kExceptions[] = {
272 #define _(E) {#E, E}
273 _(EXCEPTION_ACCESS_VIOLATION),
274 _(EXCEPTION_BREAKPOINT),
275 _(EXCEPTION_INT_DIVIDE_BY_ZERO),
276 _(EXCEPTION_STACK_OVERFLOW),
277 // TODO: more?
278 #undef _
279 };
280
mtkleinf10637f2016-06-10 13:56:35 -0700281 SkAutoMutexAcquire lock(gMutex);
mtklein5b64dab2016-06-09 08:59:48 -0700282
283 const DWORD code = e->ExceptionRecord->ExceptionCode;
284 info("\nCaught exception %u", code);
285 for (const auto& exception : kExceptions) {
286 if (exception.code == code) {
287 info(" %s", exception.name);
mtkleinf8557292016-02-29 06:35:28 -0800288 }
mtkleinf8557292016-02-29 06:35:28 -0800289 }
mtklein5b64dab2016-06-09 08:59:48 -0700290 info(", was running:\n");
291 for (auto& task : gRunning) {
mtklein0f7748a2016-07-25 15:27:29 -0700292 task.dump();
mtklein5b64dab2016-06-09 08:59:48 -0700293 }
mtklein0f7748a2016-07-25 15:27:29 -0700294 find_culprit();
mtklein5b64dab2016-06-09 08:59:48 -0700295 fflush(stdout);
296
mtkleinf8557292016-02-29 06:35:28 -0800297 // Execute default exception handler... hopefully, exit.
298 return EXCEPTION_EXECUTE_HANDLER;
mtklein246ba3a2016-02-23 10:39:36 -0800299 }
300
Mike Klein3cc2d202016-10-24 11:39:43 -0400301 static void setup_crash_handler() {
302 SetUnhandledExceptionFilter(crash_handler);
303 }
304#else
mtklein246ba3a2016-02-23 10:39:36 -0800305 #include <signal.h>
Mike Klein3cc2d202016-10-24 11:39:43 -0400306 #if !defined(SK_BUILD_FOR_ANDROID)
307 #include <execinfo.h>
Brian Salomondcbb9d92017-07-19 10:53:20 -0400308
309#endif
Mike Klein3cc2d202016-10-24 11:39:43 -0400310
311 static constexpr int max_of() { return 0; }
312 template <typename... Rest>
313 static constexpr int max_of(int x, Rest... rest) {
314 return x > max_of(rest...) ? x : max_of(rest...);
315 }
316
Mike Kleinc7278ad2018-02-15 09:26:54 -0500317 static void (*previous_handler[max_of(SIGABRT,SIGBUS,SIGFPE,SIGILL,SIGSEGV,SIGTERM)+1])(int);
mtkleinf8557292016-02-29 06:35:28 -0800318
mtklein5b64dab2016-06-09 08:59:48 -0700319 static void crash_handler(int sig) {
mtkleinf10637f2016-06-10 13:56:35 -0700320 SkAutoMutexAcquire lock(gMutex);
mtklein5b64dab2016-06-09 08:59:48 -0700321
Mike Klein701a3582018-06-28 14:08:19 +0000322 info("\nCaught signal %d [%s] (%dMB RAM, peak %dMB), was running:\n",
323 sig, strsignal(sig),
324 sk_tools::getCurrResidentSetSizeMB(), sk_tools::getMaxResidentSetSizeMB());
325
mtklein5b64dab2016-06-09 08:59:48 -0700326 for (auto& task : gRunning) {
mtklein0f7748a2016-07-25 15:27:29 -0700327 task.dump();
mtklein5b64dab2016-06-09 08:59:48 -0700328 }
mtklein0f7748a2016-07-25 15:27:29 -0700329 find_culprit();
mtklein5b64dab2016-06-09 08:59:48 -0700330
Mike Klein3cc2d202016-10-24 11:39:43 -0400331 #if !defined(SK_BUILD_FOR_ANDROID)
mtklein5b64dab2016-06-09 08:59:48 -0700332 void* stack[64];
333 int count = backtrace(stack, SK_ARRAY_COUNT(stack));
334 char** symbols = backtrace_symbols(stack, count);
335 info("\nStack trace:\n");
336 for (int i = 0; i < count; i++) {
337 info(" %s\n", symbols[i]);
338 }
Mike Klein3cc2d202016-10-24 11:39:43 -0400339 #endif
mtklein5b64dab2016-06-09 08:59:48 -0700340 fflush(stdout);
341
Mike Kleinca8087f2019-03-18 09:01:39 -0500342 if (sig == SIGINT && FLAGS_ignoreSigInt) {
343 info("Ignoring signal %d because of --ignoreSigInt.\n"
344 "This is probably a sign the bot is overloaded with work.\n", sig);
345 } else {
346 signal(sig, previous_handler[sig]);
347 raise(sig);
348 }
mtklein5b64dab2016-06-09 08:59:48 -0700349 }
350
mtklein246ba3a2016-02-23 10:39:36 -0800351 static void setup_crash_handler() {
Mike Klein701a3582018-06-28 14:08:19 +0000352 const int kSignals[] = { SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGINT, SIGSEGV, SIGTERM };
mtklein246ba3a2016-02-23 10:39:36 -0800353 for (int sig : kSignals) {
Mike Klein3cc2d202016-10-24 11:39:43 -0400354 previous_handler[sig] = signal(sig, crash_handler);
mtklein246ba3a2016-02-23 10:39:36 -0800355 }
356 }
357#endif
358
mtklein748ca3b2015-01-15 10:56:12 -0800359/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
mtklein114c3cd2015-01-15 10:15:02 -0800360
Brian Osman57796b32019-01-25 18:02:59 +0000361struct Gold : public SkString {
362 Gold() : SkString("") {}
363 Gold(const SkString& sink, const SkString& src,
364 const SkString& srcOptions, const SkString& name,
365 const SkString& md5)
366 : SkString("") {
367 this->append(sink);
368 this->append(src);
369 this->append(srcOptions);
370 this->append(name);
371 this->append(md5);
372 }
373 struct Hash {
374 uint32_t operator()(const Gold& g) const {
375 return SkGoodHash()((const SkString&)g);
376 }
377 };
378};
379static SkTHashSet<Gold, Gold::Hash> gGold;
380
381static void add_gold(JsonWriter::BitmapResult r) {
382 gGold.add(Gold(r.config, r.sourceType, r.sourceOptions, r.name, r.md5));
383}
384
385static void gather_gold() {
386 if (!FLAGS_readPath.isEmpty()) {
387 SkString path(FLAGS_readPath[0]);
388 path.append("/dm.json");
389 if (!JsonWriter::ReadJson(path.c_str(), add_gold)) {
390 fail(SkStringPrintf("Couldn't read %s for golden results.", path.c_str()));
391 }
392 }
393}
394
395/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
396
Mike Klein8f11d4d2018-01-24 12:42:55 -0500397#if defined(SK_BUILD_FOR_WIN)
mtklein935f1b12016-03-16 08:37:19 -0700398 static const char* kNewline = "\r\n";
399#else
400 static const char* kNewline = "\n";
401#endif
402
borenet09ed4802015-04-03 14:15:33 -0700403static SkTHashSet<SkString> gUninterestingHashes;
404
405static void gather_uninteresting_hashes() {
406 if (!FLAGS_uninterestingHashesFile.isEmpty()) {
bungeman38d909e2016-08-02 14:40:46 -0700407 sk_sp<SkData> data(SkData::MakeFromFileName(FLAGS_uninterestingHashesFile[0]));
mtkleincc334b32015-09-22 11:43:53 -0700408 if (!data) {
mtkleinc41fd922016-03-08 09:01:39 -0800409 info("WARNING: unable to read uninteresting hashes from %s\n",
410 FLAGS_uninterestingHashesFile[0]);
mtkleincc334b32015-09-22 11:43:53 -0700411 return;
412 }
Mike Klein45dcc0c2017-04-05 18:04:31 -0400413
414 // Copy to a string to make sure SkStrSplit has a terminating \0 to find.
415 SkString contents((const char*)data->data(), data->size());
416
borenet09ed4802015-04-03 14:15:33 -0700417 SkTArray<SkString> hashes;
Mike Klein45dcc0c2017-04-05 18:04:31 -0400418 SkStrSplit(contents.c_str(), kNewline, &hashes);
borenet09ed4802015-04-03 14:15:33 -0700419 for (const SkString& hash : hashes) {
420 gUninterestingHashes.add(hash);
421 }
mtkleinc41fd922016-03-08 09:01:39 -0800422 info("FYI: loaded %d distinct uninteresting hashes from %d lines\n",
423 gUninterestingHashes.count(), hashes.count());
borenet09ed4802015-04-03 14:15:33 -0700424 }
425}
426
427/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
428
Ben Wagner145dbcd2016-11-03 14:40:50 -0400429struct TaggedSrc : public std::unique_ptr<Src> {
mtklein3eed7dd2016-02-24 19:07:07 -0800430 SkString tag;
431 SkString options;
mtkleine0effd62015-07-29 06:37:28 -0700432};
433
Ben Wagner145dbcd2016-11-03 14:40:50 -0400434struct TaggedSink : public std::unique_ptr<Sink> {
kkinnunen3e980c32015-12-23 01:33:00 -0800435 SkString tag;
djsollen54416de2015-04-03 07:24:48 -0700436};
mtklein748ca3b2015-01-15 10:56:12 -0800437
438static const bool kMemcpyOK = true;
439
mtkleine0effd62015-07-29 06:37:28 -0700440static SkTArray<TaggedSrc, kMemcpyOK> gSrcs;
441static SkTArray<TaggedSink, kMemcpyOK> gSinks;
mtklein748ca3b2015-01-15 10:56:12 -0800442
mtklein6393c062015-04-27 08:45:01 -0700443static bool in_shard() {
444 static int N = 0;
445 return N++ % FLAGS_shards == FLAGS_shard;
446}
447
mtklein3eed7dd2016-02-24 19:07:07 -0800448static void push_src(const char* tag, ImplicitString options, Src* s) {
Ben Wagner145dbcd2016-11-03 14:40:50 -0400449 std::unique_ptr<Src> src(s);
Mike Klein88544fb2019-03-20 10:50:33 -0500450 if (in_shard() && FLAGS_src.contains(tag) &&
451 !CommandLineFlags::ShouldSkip(FLAGS_match, src->name().c_str())) {
mtkleine0effd62015-07-29 06:37:28 -0700452 TaggedSrc& s = gSrcs.push_back();
mtklein18300a32016-03-16 13:53:35 -0700453 s.reset(src.release());
mtklein748ca3b2015-01-15 10:56:12 -0800454 s.tag = tag;
djsollen54416de2015-04-03 07:24:48 -0700455 s.options = options;
mtklein114c3cd2015-01-15 10:15:02 -0800456 }
mtklein748ca3b2015-01-15 10:56:12 -0800457}
mtklein114c3cd2015-01-15 10:15:02 -0800458
msarett9e707a02015-09-01 14:57:57 -0700459static void push_codec_src(Path path, CodecSrc::Mode mode, CodecSrc::DstColorType dstColorType,
scroggoc5560be2016-02-03 09:42:42 -0800460 SkAlphaType dstAlphaType, float scale) {
scroggoe4499842016-02-25 11:03:47 -0800461 if (FLAGS_simpleCodec) {
scroggo19b91532016-10-24 09:03:26 -0700462 const bool simple = CodecSrc::kCodec_Mode == mode || CodecSrc::kAnimated_Mode == mode;
463 if (!simple || dstColorType != CodecSrc::kGetFromCanvas_DstColorType || scale != 1.0f) {
scroggoe4499842016-02-25 11:03:47 -0800464 // Only decode in the simple case.
465 return;
scroggo19b91532016-10-24 09:03:26 -0700466 }
scroggoe4499842016-02-25 11:03:47 -0800467 }
msarett9e707a02015-09-01 14:57:57 -0700468 SkString folder;
469 switch (mode) {
470 case CodecSrc::kCodec_Mode:
471 folder.append("codec");
472 break;
msarettbb25b532016-01-13 09:31:39 -0800473 case CodecSrc::kCodecZeroInit_Mode:
474 folder.append("codec_zero_init");
475 break;
msarett9e707a02015-09-01 14:57:57 -0700476 case CodecSrc::kScanline_Mode:
477 folder.append("scanline");
478 break;
msarett9e707a02015-09-01 14:57:57 -0700479 case CodecSrc::kStripe_Mode:
480 folder.append("stripe");
481 break;
msarett91c22b22016-02-22 12:27:46 -0800482 case CodecSrc::kCroppedScanline_Mode:
483 folder.append("crop");
484 break;
msarett9e707a02015-09-01 14:57:57 -0700485 case CodecSrc::kSubset_Mode:
msarett36c37962015-09-02 13:20:52 -0700486 folder.append("codec_subset");
msarett9e707a02015-09-01 14:57:57 -0700487 break;
scroggo19b91532016-10-24 09:03:26 -0700488 case CodecSrc::kAnimated_Mode:
489 folder.append("codec_animated");
490 break;
msarett9e707a02015-09-01 14:57:57 -0700491 }
492
493 switch (dstColorType) {
494 case CodecSrc::kGrayscale_Always_DstColorType:
495 folder.append("_kGray8");
496 break;
msarett34e0ec42016-04-22 16:27:24 -0700497 case CodecSrc::kNonNative8888_Always_DstColorType:
498 folder.append("_kNonNative");
499 break;
msarett9e707a02015-09-01 14:57:57 -0700500 default:
501 break;
502 }
503
scroggoc5560be2016-02-03 09:42:42 -0800504 switch (dstAlphaType) {
scroggoc5560be2016-02-03 09:42:42 -0800505 case kPremul_SkAlphaType:
506 folder.append("_premul");
507 break;
508 case kUnpremul_SkAlphaType:
509 folder.append("_unpremul");
510 break;
511 default:
512 break;
513 }
514
msarett9e707a02015-09-01 14:57:57 -0700515 if (1.0f != scale) {
516 folder.appendf("_%.3f", scale);
517 }
518
scroggoc5560be2016-02-03 09:42:42 -0800519 CodecSrc* src = new CodecSrc(path, mode, dstColorType, dstAlphaType, scale);
msarett9e707a02015-09-01 14:57:57 -0700520 push_src("image", folder, src);
521}
522
scroggof8dc9df2016-05-16 09:04:13 -0700523static void push_android_codec_src(Path path, CodecSrc::DstColorType dstColorType,
524 SkAlphaType dstAlphaType, int sampleSize) {
msarett3d9d7a72015-10-21 10:27:10 -0700525 SkString folder;
scroggof8dc9df2016-05-16 09:04:13 -0700526 folder.append("scaled_codec");
msarett3d9d7a72015-10-21 10:27:10 -0700527
528 switch (dstColorType) {
529 case CodecSrc::kGrayscale_Always_DstColorType:
530 folder.append("_kGray8");
531 break;
msarett34e0ec42016-04-22 16:27:24 -0700532 case CodecSrc::kNonNative8888_Always_DstColorType:
533 folder.append("_kNonNative");
534 break;
msarett3d9d7a72015-10-21 10:27:10 -0700535 default:
536 break;
537 }
538
scroggoc5560be2016-02-03 09:42:42 -0800539 switch (dstAlphaType) {
scroggoc5560be2016-02-03 09:42:42 -0800540 case kPremul_SkAlphaType:
541 folder.append("_premul");
542 break;
msarett9e9444c2016-02-03 12:39:10 -0800543 case kUnpremul_SkAlphaType:
544 folder.append("_unpremul");
545 break;
scroggoc5560be2016-02-03 09:42:42 -0800546 default:
547 break;
548 }
549
msarett3d9d7a72015-10-21 10:27:10 -0700550 if (1 != sampleSize) {
msarett4b0778e2015-11-13 09:59:11 -0800551 folder.appendf("_%.3f", 1.0f / (float) sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700552 }
553
scroggof8dc9df2016-05-16 09:04:13 -0700554 AndroidCodecSrc* src = new AndroidCodecSrc(path, dstColorType, dstAlphaType, sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700555 push_src("image", folder, src);
556}
557
msarett18976312016-03-09 14:20:58 -0800558static void push_image_gen_src(Path path, ImageGenSrc::Mode mode, SkAlphaType alphaType, bool isGpu)
559{
560 SkString folder;
561 switch (mode) {
562 case ImageGenSrc::kCodec_Mode:
563 folder.append("gen_codec");
564 break;
565 case ImageGenSrc::kPlatform_Mode:
566 folder.append("gen_platform");
567 break;
568 }
569
570 if (isGpu) {
571 folder.append("_gpu");
572 } else {
573 switch (alphaType) {
574 case kOpaque_SkAlphaType:
575 folder.append("_opaque");
576 break;
577 case kPremul_SkAlphaType:
578 folder.append("_premul");
579 break;
580 case kUnpremul_SkAlphaType:
581 folder.append("_unpremul");
582 break;
583 default:
584 break;
585 }
586 }
587
588 ImageGenSrc* src = new ImageGenSrc(path, mode, alphaType, isGpu);
589 push_src("image", folder, src);
590}
591
Leon Scroggins III07418182017-08-15 12:24:02 -0400592static void push_brd_src(Path path, CodecSrc::DstColorType dstColorType, BRDSrc::Mode mode,
593 uint32_t sampleSize) {
594 SkString folder("brd_android_codec");
595 switch (mode) {
596 case BRDSrc::kFullImage_Mode:
597 break;
598 case BRDSrc::kDivisor_Mode:
599 folder.append("_divisor");
600 break;
601 default:
602 SkASSERT(false);
603 return;
604 }
605
606 switch (dstColorType) {
607 case CodecSrc::kGetFromCanvas_DstColorType:
608 break;
609 case CodecSrc::kGrayscale_Always_DstColorType:
610 folder.append("_kGray");
611 break;
612 default:
613 SkASSERT(false);
614 return;
615 }
616
617 if (1 != sampleSize) {
618 folder.appendf("_%.3f", 1.0f / (float) sampleSize);
619 }
620
621 BRDSrc* src = new BRDSrc(path, mode, dstColorType, sampleSize);
622 push_src("image", folder, src);
623}
624
625static void push_brd_srcs(Path path, bool gray) {
626 if (gray) {
627 // Only run grayscale to one sampleSize and Mode. Though interesting
628 // to test grayscale, it should not reveal anything across various
629 // sampleSizes and Modes
630 // Arbitrarily choose Mode and sampleSize.
631 push_brd_src(path, CodecSrc::kGrayscale_Always_DstColorType,
632 BRDSrc::kFullImage_Mode, 2);
633 }
634
635 // Test on a variety of sampleSizes, making sure to include:
636 // - 2, 4, and 8, which are natively supported by jpeg
637 // - multiples of 2 which are not divisible by 4 (analogous for 4)
638 // - larger powers of two, since BRD clients generally use powers of 2
639 // We will only produce output for the larger sizes on large images.
640 const uint32_t sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 24, 32, 64 };
641
642 const BRDSrc::Mode modes[] = { BRDSrc::kFullImage_Mode, BRDSrc::kDivisor_Mode, };
643
644 for (uint32_t sampleSize : sampleSizes) {
645 for (BRDSrc::Mode mode : modes) {
646 push_brd_src(path, CodecSrc::kGetFromCanvas_DstColorType, mode, sampleSize);
647 }
648 }
649}
650
msarett438b2ad2015-04-09 12:43:10 -0700651static void push_codec_srcs(Path path) {
bungeman38d909e2016-08-02 14:40:46 -0700652 sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str()));
msarett438b2ad2015-04-09 12:43:10 -0700653 if (!encoded) {
mtkleinc41fd922016-03-08 09:01:39 -0800654 info("Couldn't read %s.", path.c_str());
msarett438b2ad2015-04-09 12:43:10 -0700655 return;
656 }
Mike Reedede7bac2017-07-23 15:30:02 -0400657 std::unique_ptr<SkCodec> codec = SkCodec::MakeFromData(encoded);
halcanary96fcdcc2015-08-27 07:41:13 -0700658 if (nullptr == codec.get()) {
mtkleinc41fd922016-03-08 09:01:39 -0800659 info("Couldn't create codec for %s.", path.c_str());
msarett438b2ad2015-04-09 12:43:10 -0700660 return;
661 }
662
scroggo9366aff2016-05-20 08:38:54 -0700663 // native scaling is only supported by WEBP and JPEG
664 bool supportsNativeScaling = false;
msarett438b2ad2015-04-09 12:43:10 -0700665
msarett91c22b22016-02-22 12:27:46 -0800666 SkTArray<CodecSrc::Mode> nativeModes;
667 nativeModes.push_back(CodecSrc::kCodec_Mode);
668 nativeModes.push_back(CodecSrc::kCodecZeroInit_Mode);
msarett91c22b22016-02-22 12:27:46 -0800669 switch (codec->getEncodedFormat()) {
Hal Canarydb683012016-11-23 08:55:18 -0700670 case SkEncodedImageFormat::kJPEG:
msarett91c22b22016-02-22 12:27:46 -0800671 nativeModes.push_back(CodecSrc::kScanline_Mode);
672 nativeModes.push_back(CodecSrc::kStripe_Mode);
673 nativeModes.push_back(CodecSrc::kCroppedScanline_Mode);
scroggo9366aff2016-05-20 08:38:54 -0700674 supportsNativeScaling = true;
msarett91c22b22016-02-22 12:27:46 -0800675 break;
Hal Canarydb683012016-11-23 08:55:18 -0700676 case SkEncodedImageFormat::kWEBP:
msarett91c22b22016-02-22 12:27:46 -0800677 nativeModes.push_back(CodecSrc::kSubset_Mode);
scroggo9366aff2016-05-20 08:38:54 -0700678 supportsNativeScaling = true;
msarett91c22b22016-02-22 12:27:46 -0800679 break;
Hal Canarydb683012016-11-23 08:55:18 -0700680 case SkEncodedImageFormat::kDNG:
msarettb65e6042016-02-23 05:37:25 -0800681 break;
msarett91c22b22016-02-22 12:27:46 -0800682 default:
683 nativeModes.push_back(CodecSrc::kScanline_Mode);
msarett91c22b22016-02-22 12:27:46 -0800684 break;
685 }
msarett9e707a02015-09-01 14:57:57 -0700686
msarett91c22b22016-02-22 12:27:46 -0800687 SkTArray<CodecSrc::DstColorType> colorTypes;
688 colorTypes.push_back(CodecSrc::kGetFromCanvas_DstColorType);
msarett34e0ec42016-04-22 16:27:24 -0700689 colorTypes.push_back(CodecSrc::kNonNative8888_Always_DstColorType);
msarett36c37962015-09-02 13:20:52 -0700690 switch (codec->getInfo().colorType()) {
691 case kGray_8_SkColorType:
msarett91c22b22016-02-22 12:27:46 -0800692 colorTypes.push_back(CodecSrc::kGrayscale_Always_DstColorType);
msarett36c37962015-09-02 13:20:52 -0700693 break;
694 default:
msarett36c37962015-09-02 13:20:52 -0700695 break;
696 }
msarett9e707a02015-09-01 14:57:57 -0700697
scroggoc5560be2016-02-03 09:42:42 -0800698 SkTArray<SkAlphaType> alphaModes;
699 alphaModes.push_back(kPremul_SkAlphaType);
scroggof2c96a22016-05-20 11:08:27 -0700700 if (codec->getInfo().alphaType() != kOpaque_SkAlphaType) {
701 alphaModes.push_back(kUnpremul_SkAlphaType);
scroggoc5560be2016-02-03 09:42:42 -0800702 }
msarettb714fb02016-01-22 14:46:42 -0800703
704 for (CodecSrc::Mode mode : nativeModes) {
scroggo9366aff2016-05-20 08:38:54 -0700705 for (CodecSrc::DstColorType colorType : colorTypes) {
706 for (SkAlphaType alphaType : alphaModes) {
scroggof2c96a22016-05-20 11:08:27 -0700707 // Only test kCroppedScanline_Mode when the alpha type is premul. The test is
scroggo9366aff2016-05-20 08:38:54 -0700708 // slow and won't be interestingly different with different alpha types.
709 if (CodecSrc::kCroppedScanline_Mode == mode &&
scroggof2c96a22016-05-20 11:08:27 -0700710 kPremul_SkAlphaType != alphaType) {
scroggo9366aff2016-05-20 08:38:54 -0700711 continue;
712 }
msarett91c22b22016-02-22 12:27:46 -0800713
scroggo9366aff2016-05-20 08:38:54 -0700714 push_codec_src(path, mode, colorType, alphaType, 1.0f);
msarettf3dc1882016-04-26 13:06:38 -0700715
scroggo9366aff2016-05-20 08:38:54 -0700716 // Skip kNonNative on different native scales. It won't be interestingly
717 // different.
718 if (supportsNativeScaling &&
719 CodecSrc::kNonNative8888_Always_DstColorType == colorType) {
720 // Native Scales
721 // SkJpegCodec natively supports scaling to the following:
722 for (auto scale : { 0.125f, 0.25f, 0.375f, 0.5f, 0.625f, 0.750f, 0.875f }) {
723 push_codec_src(path, mode, colorType, alphaType, scale);
724 }
scroggoc5560be2016-02-03 09:42:42 -0800725 }
msarett9e707a02015-09-01 14:57:57 -0700726 }
727 }
msarett0a242972015-06-11 14:27:27 -0700728 }
msarett36c37962015-09-02 13:20:52 -0700729
scroggo19b91532016-10-24 09:03:26 -0700730 {
731 std::vector<SkCodec::FrameInfo> frameInfos = codec->getFrameInfo();
732 if (frameInfos.size() > 1) {
Leon Scroggins III557fbbe2017-05-23 09:37:21 -0400733 for (auto dstCT : { CodecSrc::kNonNative8888_Always_DstColorType,
734 CodecSrc::kGetFromCanvas_DstColorType }) {
735 for (auto at : { kUnpremul_SkAlphaType, kPremul_SkAlphaType }) {
736 push_codec_src(path, CodecSrc::kAnimated_Mode, dstCT, at, 1.0f);
737 }
738 }
scroggo19b91532016-10-24 09:03:26 -0700739 }
740
741 }
742
scroggoe4499842016-02-25 11:03:47 -0800743 if (FLAGS_simpleCodec) {
744 return;
745 }
746
msarett3d9d7a72015-10-21 10:27:10 -0700747 const int sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
msarett36c37962015-09-02 13:20:52 -0700748
msarett3d9d7a72015-10-21 10:27:10 -0700749 for (int sampleSize : sampleSizes) {
msarett91c22b22016-02-22 12:27:46 -0800750 for (CodecSrc::DstColorType colorType : colorTypes) {
scroggoc5560be2016-02-03 09:42:42 -0800751 for (SkAlphaType alphaType : alphaModes) {
msarettf3dc1882016-04-26 13:06:38 -0700752 // We can exercise all of the kNonNative support code in the swizzler with just a
753 // few sample sizes. Skip the rest.
754 if (CodecSrc::kNonNative8888_Always_DstColorType == colorType && sampleSize > 3) {
755 continue;
756 }
757
scroggof8dc9df2016-05-16 09:04:13 -0700758 push_android_codec_src(path, colorType, alphaType, sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700759 }
msarett36c37962015-09-02 13:20:52 -0700760 }
761 }
msarett18976312016-03-09 14:20:58 -0800762
Leon Scroggins III07418182017-08-15 12:24:02 -0400763 const char* ext = strrchr(path.c_str(), '.');
764 if (ext) {
765 ext++;
msarett18976312016-03-09 14:20:58 -0800766
Leon Scroggins III07418182017-08-15 12:24:02 -0400767 static const char* const rawExts[] = {
768 "arw", "cr2", "dng", "nef", "nrw", "orf", "raf", "rw2", "pef", "srw",
769 "ARW", "CR2", "DNG", "NEF", "NRW", "ORF", "RAF", "RW2", "PEF", "SRW",
770 };
771 for (const char* rawExt : rawExts) {
772 if (0 == strcmp(rawExt, ext)) {
773 // RAW is not supported by image generator (skbug.com/5079) or BRD.
774 return;
775 }
776 }
777
778 static const char* const brdExts[] = {
779 "jpg", "jpeg", "png", "webp",
780 "JPG", "JPEG", "PNG", "WEBP",
781 };
782 for (const char* brdExt : brdExts) {
783 if (0 == strcmp(brdExt, ext)) {
Leon Scroggins IIIc8037dc2017-12-05 13:55:24 -0500784 bool gray = codec->getInfo().colorType() == kGray_8_SkColorType;
Leon Scroggins III07418182017-08-15 12:24:02 -0400785 push_brd_srcs(path, gray);
786 break;
787 }
msarett18976312016-03-09 14:20:58 -0800788 }
789 }
790
791 // Push image generator GPU test.
brianosmanc9ced392016-03-24 07:27:43 -0700792 push_image_gen_src(path, ImageGenSrc::kCodec_Mode, codec->getInfo().alphaType(), true);
msarett18976312016-03-09 14:20:58 -0800793
794 // Push image generator CPU tests.
795 for (SkAlphaType alphaType : alphaModes) {
796 push_image_gen_src(path, ImageGenSrc::kCodec_Mode, alphaType, false);
797
798#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
Hal Canarydb683012016-11-23 08:55:18 -0700799 if (SkEncodedImageFormat::kWEBP != codec->getEncodedFormat() &&
800 SkEncodedImageFormat::kWBMP != codec->getEncodedFormat() &&
msarett18976312016-03-09 14:20:58 -0800801 kUnpremul_SkAlphaType != alphaType)
802 {
803 push_image_gen_src(path, ImageGenSrc::kPlatform_Mode, alphaType, false);
804 }
msarettfc0b6d12016-03-17 13:50:17 -0700805#elif defined(SK_BUILD_FOR_WIN)
Hal Canarydb683012016-11-23 08:55:18 -0700806 if (SkEncodedImageFormat::kWEBP != codec->getEncodedFormat() &&
807 SkEncodedImageFormat::kWBMP != codec->getEncodedFormat())
msarettfc0b6d12016-03-17 13:50:17 -0700808 {
809 push_image_gen_src(path, ImageGenSrc::kPlatform_Mode, alphaType, false);
810 }
msarett18976312016-03-09 14:20:58 -0800811#endif
812 }
msarett438b2ad2015-04-09 12:43:10 -0700813}
814
fmalitaa2b9fdf2016-08-03 19:53:36 -0700815template <typename T>
Mike Klein88544fb2019-03-20 10:50:33 -0500816void gather_file_srcs(const CommandLineFlags::StringArray& flags,
817 const char* ext,
818 const char* src_name = nullptr) {
Florin Malitaf1ba3ae2018-07-19 15:09:11 -0400819 if (!src_name) {
820 // With the exception of Lottie files, the source name is the extension.
821 src_name = ext;
822 }
823
fmalitaa2b9fdf2016-08-03 19:53:36 -0700824 for (int i = 0; i < flags.count(); i++) {
825 const char* path = flags[i];
826 if (sk_isdir(path)) {
827 SkOSFile::Iter it(path, ext);
828 for (SkString file; it.next(&file); ) {
Florin Malitaf1ba3ae2018-07-19 15:09:11 -0400829 push_src(src_name, "", new T(SkOSPath::Join(path, file.c_str())));
fmalitaa2b9fdf2016-08-03 19:53:36 -0700830 }
831 } else {
Florin Malitaf1ba3ae2018-07-19 15:09:11 -0400832 push_src(src_name, "", new T(path));
fmalitaa2b9fdf2016-08-03 19:53:36 -0700833 }
834 }
835}
836
scroggo86737142016-02-03 12:19:11 -0800837static bool gather_srcs() {
Hal Canary972eba32018-07-30 17:07:07 -0400838 for (skiagm::GMFactory f : skiagm::GMRegistry::Range()) {
839 push_src("gm", "", new GMSrc(f));
mtklein748ca3b2015-01-15 10:56:12 -0800840 }
scroggo86737142016-02-03 12:19:11 -0800841
Robert Phillipse47f0a02018-03-27 17:01:16 -0400842 gather_file_srcs<SKPSrc>(FLAGS_skps, "skp");
fmalitaa2b9fdf2016-08-03 19:53:36 -0700843 gather_file_srcs<MSKPSrc>(FLAGS_mskps, "mskp");
Florin Malita87ccf332018-05-04 12:23:24 -0400844#if defined(SK_ENABLE_SKOTTIE)
Florin Malitaf1ba3ae2018-07-19 15:09:11 -0400845 gather_file_srcs<SkottieSrc>(FLAGS_lotties, "json", "lottie");
Florin Malita124d5af2017-12-31 17:02:26 -0500846#endif
fmalitaa2b9fdf2016-08-03 19:53:36 -0700847#if defined(SK_XML)
848 gather_file_srcs<SVGSrc>(FLAGS_svgs, "svg");
849#endif
Chris Dalton184c37e2018-09-28 11:27:39 -0600850 if (!FLAGS_bisect.isEmpty()) {
851 // An empty l/r trail string will draw all the paths.
852 push_src("bisect", "",
853 new BisectSrc(FLAGS_bisect[0], FLAGS_bisect.count() > 1 ? FLAGS_bisect[1] : ""));
854 }
halcanary45420a92016-06-02 12:41:14 -0700855
scroggo86737142016-02-03 12:19:11 -0800856 SkTArray<SkString> images;
msarett69deca82016-04-29 09:38:40 -0700857 if (!CollectImages(FLAGS_images, &images)) {
scroggo86737142016-02-03 12:19:11 -0800858 return false;
859 }
860
861 for (auto image : images) {
862 push_codec_srcs(image);
mtklein709d2c32015-01-15 08:30:25 -0800863 }
scroggo86737142016-02-03 12:19:11 -0800864
msarett69deca82016-04-29 09:38:40 -0700865 SkTArray<SkString> colorImages;
866 if (!CollectImages(FLAGS_colorImages, &colorImages)) {
867 return false;
868 }
869
870 for (auto colorImage : colorImages) {
Mike Klein0d5d1422019-03-06 10:56:04 -0600871 push_src("colorImage", "decode_native", new ColorCodecSrc(colorImage, false));
872 push_src("colorImage", "decode_to_dst", new ColorCodecSrc(colorImage, true));
msarett69deca82016-04-29 09:38:40 -0700873 }
874
scroggo86737142016-02-03 12:19:11 -0800875 return true;
mtklein709d2c32015-01-15 08:30:25 -0800876}
877
kkinnunen3e980c32015-12-23 01:33:00 -0800878static void push_sink(const SkCommandLineConfig& config, Sink* s) {
Ben Wagner145dbcd2016-11-03 14:40:50 -0400879 std::unique_ptr<Sink> sink(s);
kkinnunen3e980c32015-12-23 01:33:00 -0800880
mtkleine0effd62015-07-29 06:37:28 -0700881 // Try a simple Src as a canary. If it fails, skip this sink.
mtklein748ca3b2015-01-15 10:56:12 -0800882 struct : public Src {
mtkleine0effd62015-07-29 06:37:28 -0700883 Error draw(SkCanvas* c) const override {
884 c->drawRect(SkRect::MakeWH(1,1), SkPaint());
885 return "";
886 }
mtklein36352bf2015-03-25 18:17:31 -0700887 SkISize size() const override { return SkISize::Make(16, 16); }
mtkleine0effd62015-07-29 06:37:28 -0700888 Name name() const override { return "justOneRect"; }
889 } justOneRect;
mtklein114c3cd2015-01-15 10:15:02 -0800890
mtklein748ca3b2015-01-15 10:56:12 -0800891 SkBitmap bitmap;
892 SkDynamicMemoryWStream stream;
mtkleinb9eb4ac2015-02-02 18:26:03 -0800893 SkString log;
mtkleine0effd62015-07-29 06:37:28 -0700894 Error err = sink->draw(justOneRect, &bitmap, &stream, &log);
mtklein4089ef72015-03-05 08:40:28 -0800895 if (err.isFatal()) {
mtkleinc41fd922016-03-08 09:01:39 -0800896 info("Could not run %s: %s\n", config.getTag().c_str(), err.c_str());
mtklein05641a52015-04-21 10:49:13 -0700897 exit(1);
mtklein114c3cd2015-01-15 10:15:02 -0800898 }
899
mtkleine0effd62015-07-29 06:37:28 -0700900 TaggedSink& ts = gSinks.push_back();
mtklein18300a32016-03-16 13:53:35 -0700901 ts.reset(sink.release());
kkinnunen3e980c32015-12-23 01:33:00 -0800902 ts.tag = config.getTag();
mtklein748ca3b2015-01-15 10:56:12 -0800903}
904
Mike Kleinc7a09162019-02-19 06:14:39 -0500905static sk_sp<SkColorSpace> rgb_to_gbr() {
906 return SkColorSpace::MakeSRGB()->makeColorSpin();
907}
908
csmartdalton008b9d82017-02-22 12:00:42 -0700909static Sink* create_sink(const GrContextOptions& grCtxOptions, const SkCommandLineConfig* config) {
Brian Osmanc7ad40f2018-05-31 14:27:17 -0400910 if (FLAGS_gpu) {
kkinnunen3e980c32015-12-23 01:33:00 -0800911 if (const SkCommandLineConfigGpu* gpuConfig = config->asConfigGpu()) {
bsalomon85b4b532016-04-05 11:06:27 -0700912 GrContextFactory::ContextType contextType = gpuConfig->getContextType();
csmartdaltone812d492017-02-21 12:36:05 -0700913 GrContextFactory::ContextOverrides contextOverrides = gpuConfig->getContextOverrides();
csmartdalton008b9d82017-02-22 12:00:42 -0700914 GrContextFactory testFactory(grCtxOptions);
csmartdaltone812d492017-02-21 12:36:05 -0700915 if (!testFactory.get(contextType, contextOverrides)) {
mtkleinc41fd922016-03-08 09:01:39 -0800916 info("WARNING: can not create GPU context for config '%s'. "
917 "GM tests will be skipped.\n", gpuConfig->getTag().c_str());
kkinnunen3e980c32015-12-23 01:33:00 -0800918 return nullptr;
919 }
Brian Osmanf9810662017-08-30 10:02:10 -0400920 if (gpuConfig->getTestThreading()) {
Brian Salomon00a5eb82018-07-11 15:32:05 -0400921 SkASSERT(!gpuConfig->getTestPersistentCache());
Brian Salomonf865b052018-03-09 09:01:53 -0500922 return new GPUThreadTestingSink(
923 contextType, contextOverrides, gpuConfig->getSurfType(),
924 gpuConfig->getSamples(), gpuConfig->getUseDIText(),
925 gpuConfig->getColorType(), gpuConfig->getAlphaType(),
926 sk_ref_sp(gpuConfig->getColorSpace()), FLAGS_gpu_threading, grCtxOptions);
Brian Salomon00a5eb82018-07-11 15:32:05 -0400927 } else if (gpuConfig->getTestPersistentCache()) {
928 return new GPUPersistentCacheTestingSink(
929 contextType, contextOverrides, gpuConfig->getSurfType(),
930 gpuConfig->getSamples(), gpuConfig->getUseDIText(),
931 gpuConfig->getColorType(), gpuConfig->getAlphaType(),
Brian Osmanf71b0702019-04-03 13:04:16 -0400932 sk_ref_sp(gpuConfig->getColorSpace()), FLAGS_gpu_threading, grCtxOptions,
933 gpuConfig->getTestPersistentCache());
Brian Osmanf9810662017-08-30 10:02:10 -0400934 } else {
Brian Salomonf865b052018-03-09 09:01:53 -0500935 return new GPUSink(contextType, contextOverrides, gpuConfig->getSurfType(),
936 gpuConfig->getSamples(), gpuConfig->getUseDIText(),
937 gpuConfig->getColorType(), gpuConfig->getAlphaType(),
938 sk_ref_sp(gpuConfig->getColorSpace()), FLAGS_gpu_threading,
939 grCtxOptions);
Brian Osmanf9810662017-08-30 10:02:10 -0400940 }
kkinnunen3e980c32015-12-23 01:33:00 -0800941 }
942 }
Bryce Thomas95a7b762018-03-02 13:54:21 -0800943 if (const SkCommandLineConfigSvg* svgConfig = config->asConfigSvg()) {
944 int pageIndex = svgConfig->getPageIndex();
945 return new SVGSink(pageIndex);
946 }
kkinnunen3e980c32015-12-23 01:33:00 -0800947
Brian Salomon23356442018-11-30 15:33:19 -0500948#define SINK(t, sink, ...) if (config->getBackend().equals(t)) return new sink(__VA_ARGS__)
kkinnunen3e980c32015-12-23 01:33:00 -0800949
mtklein748ca3b2015-01-15 10:56:12 -0800950 if (FLAGS_cpu) {
Mike Klein515bda62018-01-09 11:21:58 -0500951 SINK("g8", RasterSink, kGray_8_SkColorType);
Matt Sarettd2228302017-03-02 08:53:46 -0500952 SINK("565", RasterSink, kRGB_565_SkColorType);
Mike Klein5340b3f2018-01-24 13:42:05 -0500953 SINK("4444", RasterSink, kARGB_4444_SkColorType);
Matt Sarettd2228302017-03-02 08:53:46 -0500954 SINK("8888", RasterSink, kN32_SkColorType);
Mike Kleinac568a92018-01-25 09:09:32 -0500955 SINK("rgba", RasterSink, kRGBA_8888_SkColorType);
956 SINK("bgra", RasterSink, kBGRA_8888_SkColorType);
957 SINK("rgbx", RasterSink, kRGB_888x_SkColorType);
958 SINK("1010102", RasterSink, kRGBA_1010102_SkColorType);
959 SINK("101010x", RasterSink, kRGB_101010x_SkColorType);
Hal Canaryc7d295e2017-07-20 15:36:00 -0400960 SINK("pdf", PDFSink, false, SK_ScalarDefaultRasterDPI);
Matt Sarettd2228302017-03-02 08:53:46 -0500961 SINK("skp", SKPSink);
Matt Sarettd2228302017-03-02 08:53:46 -0500962 SINK("svg", SVGSink);
963 SINK("null", NullSink);
964 SINK("xps", XPSSink);
Hal Canaryc7d295e2017-07-20 15:36:00 -0400965 SINK("pdfa", PDFSink, true, SK_ScalarDefaultRasterDPI);
966 SINK("pdf300", PDFSink, false, 300);
Hal Canary85c7fe82016-10-25 10:33:27 -0400967 SINK("jsdebug", DebugSink);
Mike Klein0e4041f2018-06-19 16:00:40 -0400968
969 // Configs relevant to color management testing (and 8888 for reference).
970
971 // 'narrow' has a gamut narrower than sRGB, and different transfer function.
Brian Osman82ebe042019-01-04 17:03:00 -0500972 auto narrow = SkColorSpace::MakeRGB(SkNamedTransferFn::k2Dot2, gNarrow_toXYZD50),
Mike Klein0e4041f2018-06-19 16:00:40 -0400973 srgb = SkColorSpace::MakeSRGB(),
Mike Klein4de05072018-08-16 09:09:14 -0400974 srgbLinear = SkColorSpace::MakeSRGBLinear(),
Brian Osman82ebe042019-01-04 17:03:00 -0500975 p3 = SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, SkNamedGamut::kDCIP3);
Mike Klein0e4041f2018-06-19 16:00:40 -0400976
Mike Kleinff6a73c2018-08-17 16:19:24 -0400977 SINK( "f16", RasterSink, kRGBA_F16_SkColorType, srgbLinear);
978 SINK( "srgb", RasterSink, kRGBA_8888_SkColorType, srgb );
979 SINK( "esrgb", RasterSink, kRGBA_F16_SkColorType, srgb );
Mike Kleinc7a09162019-02-19 06:14:39 -0500980 SINK( "esgbr", RasterSink, kRGBA_F16_SkColorType, rgb_to_gbr());
Mike Kleinff6a73c2018-08-17 16:19:24 -0400981 SINK( "narrow", RasterSink, kRGBA_8888_SkColorType, narrow );
982 SINK( "enarrow", RasterSink, kRGBA_F16_SkColorType, narrow );
983 SINK( "p3", RasterSink, kRGBA_8888_SkColorType, p3 );
984 SINK( "ep3", RasterSink, kRGBA_F16_SkColorType, p3 );
Mike Kleinae4b1f42018-09-13 11:13:15 -0400985 SINK( "rec2020", RasterSink, kRGBA_8888_SkColorType, rec2020() );
986 SINK("erec2020", RasterSink, kRGBA_F16_SkColorType, rec2020() );
Mike Klein37854712018-06-26 11:43:06 -0400987
Mike Kleinb70990e2019-02-28 10:03:27 -0600988 SINK("f16norm", RasterSink, kRGBA_F16Norm_SkColorType, srgb);
989
Mike Klein37854712018-06-26 11:43:06 -0400990 SINK( "f32", RasterSink, kRGBA_F32_SkColorType, srgbLinear);
mtklein748ca3b2015-01-15 10:56:12 -0800991 }
992#undef SINK
halcanary96fcdcc2015-08-27 07:41:13 -0700993 return nullptr;
mtklein114c3cd2015-01-15 10:15:02 -0800994}
995
kkinnunen3e980c32015-12-23 01:33:00 -0800996static Sink* create_via(const SkString& tag, Sink* wrapped) {
Brian Salomon23356442018-11-30 15:33:19 -0500997#define VIA(t, via, ...) if (tag.equals(t)) return new via(__VA_ARGS__)
mtklein9c5052f2016-08-06 12:51:51 -0700998 VIA("lite", ViaLite, wrapped);
Mike Reedbae888e2017-02-18 16:50:45 -0500999#ifdef TEST_VIA_SVG
Mike Reedf67c4592017-02-17 17:06:11 -05001000 VIA("svg", ViaSVG, wrapped);
Mike Reedbae888e2017-02-18 16:50:45 -05001001#endif
halcanary96fcdcc2015-08-27 07:41:13 -07001002 VIA("serialize", ViaSerialization, wrapped);
mtklein4a34ecb2016-01-08 10:19:35 -08001003 VIA("pic", ViaPicture, wrapped);
halcanary96fcdcc2015-08-27 07:41:13 -07001004 VIA("tiles", ViaTiles, 256, 256, nullptr, wrapped);
mtklein7edca212015-01-21 13:18:51 -08001005 VIA("tiles_rt", ViaTiles, 256, 256, new SkRTreeFactory, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -08001006
Brian Salomon57904202018-12-17 14:45:00 -05001007 VIA("ddl", ViaDDL, 1, 3, wrapped);
1008 VIA("ddl2", ViaDDL, 2, 3, wrapped);
Robert Phillips33f02ed2018-03-27 08:06:57 -04001009
mtkleind603b222015-02-17 11:13:33 -08001010 if (FLAGS_matrix.count() == 4) {
mtklein748ca3b2015-01-15 10:56:12 -08001011 SkMatrix m;
mtkleind603b222015-02-17 11:13:33 -08001012 m.reset();
1013 m.setScaleX((SkScalar)atof(FLAGS_matrix[0]));
1014 m.setSkewX ((SkScalar)atof(FLAGS_matrix[1]));
1015 m.setSkewY ((SkScalar)atof(FLAGS_matrix[2]));
1016 m.setScaleY((SkScalar)atof(FLAGS_matrix[3]));
1017 VIA("matrix", ViaMatrix, m, wrapped);
1018 VIA("upright", ViaUpright, m, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -08001019 }
tomhudson64de1e12015-03-05 08:01:07 -08001020
mtklein748ca3b2015-01-15 10:56:12 -08001021#undef VIA
halcanary96fcdcc2015-08-27 07:41:13 -07001022 return nullptr;
mtklein114c3cd2015-01-15 10:15:02 -08001023}
1024
Ben Wagnerf28d4722017-08-11 17:33:22 -04001025static bool gather_sinks(const GrContextOptions& grCtxOptions, bool defaultConfigs) {
kkinnunen3e980c32015-12-23 01:33:00 -08001026 SkCommandLineConfigArray configs;
1027 ParseConfigs(FLAGS_config, &configs);
1028 for (int i = 0; i < configs.count(); i++) {
1029 const SkCommandLineConfig& config = *configs[i];
csmartdalton008b9d82017-02-22 12:00:42 -07001030 Sink* sink = create_sink(grCtxOptions, &config);
kkinnunen3e980c32015-12-23 01:33:00 -08001031 if (sink == nullptr) {
mtkleinc41fd922016-03-08 09:01:39 -08001032 info("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(),
1033 config.getTag().c_str());
kkinnunen3e980c32015-12-23 01:33:00 -08001034 continue;
1035 }
mtklein748ca3b2015-01-15 10:56:12 -08001036
kkinnunen3e980c32015-12-23 01:33:00 -08001037 const SkTArray<SkString>& parts = config.getViaParts();
1038 for (int j = parts.count(); j-- > 0;) {
1039 const SkString& part = parts[j];
1040 Sink* next = create_via(part, sink);
halcanary96fcdcc2015-08-27 07:41:13 -07001041 if (next == nullptr) {
mtkleinc41fd922016-03-08 09:01:39 -08001042 info("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(),
1043 part.c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001044 delete sink;
halcanary96fcdcc2015-08-27 07:41:13 -07001045 sink = nullptr;
mtklein748ca3b2015-01-15 10:56:12 -08001046 break;
1047 }
1048 sink = next;
1049 }
1050 if (sink) {
1051 push_sink(config, sink);
mtklein114c3cd2015-01-15 10:15:02 -08001052 }
1053 }
brianosman05c987c2016-05-09 13:42:16 -07001054
1055 // If no configs were requested (just running tests, perhaps?), then we're okay.
Ben Wagnerf28d4722017-08-11 17:33:22 -04001056 if (configs.count() == 0 ||
1057 // If we're using the default configs, we're okay.
1058 defaultConfigs ||
Ben Wagner32fa5102017-08-10 21:25:55 -04001059 // Otherwise, make sure that all specified configs have become sinks.
1060 configs.count() == gSinks.count()) {
1061 return true;
1062 }
Ben Wagner32fa5102017-08-10 21:25:55 -04001063 return false;
mtklein114c3cd2015-01-15 10:15:02 -08001064}
mtklein709d2c32015-01-15 08:30:25 -08001065
mtkleina2ef6422015-01-15 13:44:22 -08001066static bool match(const char* needle, const char* haystack) {
Chris Daltonecf78ac2017-08-15 15:43:08 -06001067 if ('~' == needle[0]) {
1068 return !match(needle + 1, haystack);
1069 }
1070 if (0 == strcmp("_", needle)) {
1071 return true;
1072 }
1073 return nullptr != strstr(haystack, needle);
mtkleina2ef6422015-01-15 13:44:22 -08001074}
1075
mtklein3eed7dd2016-02-24 19:07:07 -08001076static bool is_blacklisted(const char* sink, const char* src,
1077 const char* srcOptions, const char* name) {
mtklein0d243ff2015-04-03 07:51:00 -07001078 for (int i = 0; i < FLAGS_blacklist.count() - 3; i += 4) {
mtkleina2ef6422015-01-15 13:44:22 -08001079 if (match(FLAGS_blacklist[i+0], sink) &&
djsollen54416de2015-04-03 07:24:48 -07001080 match(FLAGS_blacklist[i+1], src) &&
1081 match(FLAGS_blacklist[i+2], srcOptions) &&
1082 match(FLAGS_blacklist[i+3], name)) {
mtklein3eed7dd2016-02-24 19:07:07 -08001083 return true;
mtkleina2ef6422015-01-15 13:44:22 -08001084 }
1085 }
mtklein3eed7dd2016-02-24 19:07:07 -08001086 return false;
mtkleina2ef6422015-01-15 13:44:22 -08001087}
1088
mtkleincd50bca2016-01-05 06:20:20 -08001089// Even when a Task Sink reports to be non-threadsafe (e.g. GPU), we know things like
1090// .png encoding are definitely thread safe. This lets us offload that work to CPU threads.
1091static SkTaskGroup gDefinitelyThreadSafeWork;
1092
mtklein748ca3b2015-01-15 10:56:12 -08001093// The finest-grained unit of work we can run: draw a single Src into a single Sink,
1094// report any errors, and perhaps write out the output: a .png of the bitmap, or a raw stream.
1095struct Task {
mtkleine0effd62015-07-29 06:37:28 -07001096 Task(const TaggedSrc& src, const TaggedSink& sink) : src(src), sink(sink) {}
1097 const TaggedSrc& src;
1098 const TaggedSink& sink;
mtklein748ca3b2015-01-15 10:56:12 -08001099
mtklein21eaf3b2016-02-08 12:39:59 -08001100 static void Run(const Task& task) {
1101 SkString name = task.src->name();
mtkleine0effd62015-07-29 06:37:28 -07001102
mtkleinb9eb4ac2015-02-02 18:26:03 -08001103 SkString log;
mtklein3eed7dd2016-02-24 19:07:07 -08001104 if (!FLAGS_dryRun) {
mtklein748ca3b2015-01-15 10:56:12 -08001105 SkBitmap bitmap;
1106 SkDynamicMemoryWStream stream;
mtklein3eed7dd2016-02-24 19:07:07 -08001107 start(task.sink.tag.c_str(), task.src.tag.c_str(),
1108 task.src.options.c_str(), name.c_str());
mtklein21eaf3b2016-02-08 12:39:59 -08001109 Error err = task.sink->draw(*task.src, &bitmap, &stream, &log);
mtkleinb3b13b72016-03-07 13:20:52 -08001110 if (!log.isEmpty()) {
mtkleinc41fd922016-03-08 09:01:39 -08001111 info("%s %s %s %s:\n%s\n", task.sink.tag.c_str()
1112 , task.src.tag.c_str()
1113 , task.src.options.c_str()
1114 , name.c_str()
1115 , log.c_str());
mtkleinb3b13b72016-03-07 13:20:52 -08001116 }
mtklein748ca3b2015-01-15 10:56:12 -08001117 if (!err.isEmpty()) {
mtklein4089ef72015-03-05 08:40:28 -08001118 if (err.isFatal()) {
djsollen54416de2015-04-03 07:24:48 -07001119 fail(SkStringPrintf("%s %s %s %s: %s",
mtklein21eaf3b2016-02-08 12:39:59 -08001120 task.sink.tag.c_str(),
1121 task.src.tag.c_str(),
1122 task.src.options.c_str(),
mtklein4089ef72015-03-05 08:40:28 -08001123 name.c_str(),
1124 err.c_str()));
mtkleinb37cb412015-03-18 05:27:14 -07001125 } else {
mtklein3eed7dd2016-02-24 19:07:07 -08001126 done(task.sink.tag.c_str(), task.src.tag.c_str(),
1127 task.src.options.c_str(), name.c_str());
mtkleinba6ada72016-01-21 09:39:35 -08001128 return;
mtklein4089ef72015-03-05 08:40:28 -08001129 }
mtklein748ca3b2015-01-15 10:56:12 -08001130 }
mtklein62bd1a62015-01-27 14:46:26 -08001131
mtkleincd50bca2016-01-05 06:20:20 -08001132 // We're likely switching threads here, so we must capture by value, [=] or [foo,bar].
Hal Canary0b833192017-03-14 14:35:02 -04001133 SkStreamAsset* data = stream.detachAsStream().release();
mtkleincd50bca2016-01-05 06:20:20 -08001134 gDefinitelyThreadSafeWork.add([task,name,bitmap,data]{
Ben Wagner145dbcd2016-11-03 14:40:50 -04001135 std::unique_ptr<SkStreamAsset> ownedData(data);
mtkleincd50bca2016-01-05 06:20:20 -08001136
Mike Kleine1271702019-03-07 11:46:59 -06001137 std::unique_ptr<HashAndEncode> hashAndEncode;
1138
mtkleincd50bca2016-01-05 06:20:20 -08001139 SkString md5;
Brian Osman57796b32019-01-25 18:02:59 +00001140 if (!FLAGS_writePath.isEmpty() || !FLAGS_readPath.isEmpty()) {
mtkleincd50bca2016-01-05 06:20:20 -08001141 SkMD5 hash;
1142 if (data->getLength()) {
1143 hash.writeStream(data, data->getLength());
1144 data->rewind();
mtklein38408462015-07-08 07:25:27 -07001145 } else {
Mike Kleine1271702019-03-07 11:46:59 -06001146 hashAndEncode.reset(new HashAndEncode(bitmap));
1147 hashAndEncode->write(&hash);
mtkleincd50bca2016-01-05 06:20:20 -08001148 }
Hal Canary0f2f5222019-04-03 10:13:45 -04001149 SkMD5::Digest digest = hash.finish();
mtkleincd50bca2016-01-05 06:20:20 -08001150 for (int i = 0; i < 16; i++) {
1151 md5.appendf("%02x", digest.data[i]);
mtklein38408462015-07-08 07:25:27 -07001152 }
mtklein62bd1a62015-01-27 14:46:26 -08001153 }
mtklein62bd1a62015-01-27 14:46:26 -08001154
Brian Osman57796b32019-01-25 18:02:59 +00001155 if (!FLAGS_readPath.isEmpty() &&
1156 !gGold.contains(Gold(task.sink.tag, task.src.tag,
1157 task.src.options, name, md5))) {
1158 fail(SkStringPrintf("%s not found for %s %s %s %s in %s",
1159 md5.c_str(),
1160 task.sink.tag.c_str(),
1161 task.src.tag.c_str(),
1162 task.src.options.c_str(),
1163 name.c_str(),
1164 FLAGS_readPath[0]));
1165 }
1166
mtkleincd50bca2016-01-05 06:20:20 -08001167 if (!FLAGS_writePath.isEmpty()) {
mtklein21eaf3b2016-02-08 12:39:59 -08001168 const char* ext = task.sink->fileExtension();
Brian Osmanf1942de2017-08-30 14:50:22 -04001169 if (ext && !FLAGS_dont_write.contains(ext)) {
Mike Klein97d6a7a2017-07-24 10:37:19 -04001170 if (data->getLength()) {
Mike Kleine1271702019-03-07 11:46:59 -06001171 WriteToDisk(task, md5, ext, data, data->getLength(), nullptr, nullptr);
Mike Klein97d6a7a2017-07-24 10:37:19 -04001172 SkASSERT(bitmap.drawsNothing());
1173 } else if (!bitmap.drawsNothing()) {
Mike Kleine1271702019-03-07 11:46:59 -06001174 WriteToDisk(task, md5, ext, nullptr, 0, &bitmap, hashAndEncode.get());
Mike Klein97d6a7a2017-07-24 10:37:19 -04001175 }
mtkleincd50bca2016-01-05 06:20:20 -08001176 }
1177 }
Brian Osman582f6862019-03-11 11:20:55 -04001178
1179 SkPixmap pm;
1180 if (FLAGS_checkF16 && bitmap.colorType() == kRGBA_F16Norm_SkColorType &&
1181 bitmap.peekPixels(&pm)) {
1182 bool unclamped = false;
1183 for (int y = 0; y < pm.height() && !unclamped; ++y)
1184 for (int x = 0; x < pm.width() && !unclamped; ++x) {
1185 Sk4f rgba = SkHalfToFloat_finite_ftz(*pm.addr64(x, y));
1186 float a = rgba[3];
1187 if (a > 1.0f || (rgba < 0.0f).anyTrue() || (rgba > a).anyTrue()) {
Brian Osmanb73e6072019-03-15 10:02:16 -04001188 SkDebugf("[%s] F16Norm pixel [%d, %d] unclamped: (%g, %g, %g, %g)\n",
1189 name.c_str(), x, y, rgba[0], rgba[1], rgba[2], rgba[3]);
Brian Osman582f6862019-03-11 11:20:55 -04001190 unclamped = true;
1191 }
1192 }
1193 }
mtkleincd50bca2016-01-05 06:20:20 -08001194 });
mtklein748ca3b2015-01-15 10:56:12 -08001195 }
mtklein3eed7dd2016-02-24 19:07:07 -08001196 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 -08001197 }
1198
Mike Klein66f09a72019-02-12 13:03:54 -05001199 static SkString identify_gamut(SkColorSpace* cs) {
1200 if (!cs) {
1201 return SkString("untagged");
1202 }
1203
1204 skcms_Matrix3x3 gamut;
1205 if (cs->toXYZD50(&gamut)) {
1206 auto eq = [](skcms_Matrix3x3 x, skcms_Matrix3x3 y) {
1207 for (int i = 0; i < 3; i++)
1208 for (int j = 0; j < 3; j++) {
1209 if (x.vals[i][j] != y.vals[i][j]) { return false; }
1210 }
1211 return true;
1212 };
1213
1214 if (eq(gamut, SkNamedGamut::kSRGB )) { return SkString("sRGB"); }
1215 if (eq(gamut, SkNamedGamut::kAdobeRGB)) { return SkString("Adobe"); }
1216 if (eq(gamut, SkNamedGamut::kDCIP3 )) { return SkString("P3"); }
1217 if (eq(gamut, SkNamedGamut::kRec2020 )) { return SkString("2020"); }
1218 if (eq(gamut, SkNamedGamut::kXYZ )) { return SkString("XYZ"); }
1219 if (eq(gamut, gNarrow_toXYZD50 )) { return SkString("narrow"); }
1220 return SkString("other");
1221 }
1222 return SkString("non-XYZ");
1223 }
1224
1225 static SkString identify_transfer_fn(SkColorSpace* cs) {
1226 if (!cs) {
1227 return SkString("untagged");
1228 }
1229
1230 skcms_TransferFunction tf;
1231 if (cs->isNumericalTransferFn(&tf)) {
1232 auto eq = [](skcms_TransferFunction x, skcms_TransferFunction y) {
1233 return x.g == y.g
1234 && x.a == y.a
1235 && x.b == y.b
1236 && x.c == y.c
1237 && x.d == y.d
1238 && x.e == y.e
1239 && x.f == y.f;
1240 };
1241
1242 if (tf.a == 1 && tf.b == 0 && tf.c == 0 && tf.d == 0 && tf.e == 0 && tf.f == 0) {
1243 return SkStringPrintf("gamma %.3g", tf.g);
1244 }
1245 if (eq(tf, SkNamedTransferFn::kSRGB)) { return SkString("sRGB"); }
1246 if (eq(tf, k2020_TF )) { return SkString("2020"); }
1247 return SkStringPrintf("%.3g %.3g %.3g %.3g %.3g %.3g %.3g",
1248 tf.g, tf.a, tf.b, tf.c, tf.d, tf.e, tf.f);
1249 }
1250 return SkString("non-numeric");
1251 }
1252
Mike Klein82020c22019-03-07 14:11:16 -06001253 // Equivalence class to slice color type by in Gold.
1254 // Basically the same as color type ignoring channel order.
1255 static const char* color_depth(SkColorType ct) {
1256 switch (ct) {
1257 case kUnknown_SkColorType: break;
1258
1259 case kAlpha_8_SkColorType: return "A8";
1260 case kRGB_565_SkColorType: return "565";
1261 case kARGB_4444_SkColorType: return "4444";
1262 case kRGBA_8888_SkColorType: return "8888";
1263 case kRGB_888x_SkColorType: return "888";
1264 case kBGRA_8888_SkColorType: return "8888";
1265 case kRGBA_1010102_SkColorType: return "1010102";
1266 case kRGB_101010x_SkColorType: return "101010";
1267 case kGray_8_SkColorType: return "G8";
1268 case kRGBA_F16Norm_SkColorType: return "F16Norm"; // TODO: "F16"?
1269 case kRGBA_F16_SkColorType: return "F16";
1270 case kRGBA_F32_SkColorType: return "F32";
1271 }
1272 return "Unknown";
1273 }
1274
mtklein748ca3b2015-01-15 10:56:12 -08001275 static void WriteToDisk(const Task& task,
mtklein62bd1a62015-01-27 14:46:26 -08001276 SkString md5,
1277 const char* ext,
mtklein748ca3b2015-01-15 10:56:12 -08001278 SkStream* data, size_t len,
Mike Kleine1271702019-03-07 11:46:59 -06001279 const SkBitmap* bitmap,
1280 const HashAndEncode* hashAndEncode) {
mtklein409d4702016-02-29 07:38:01 -08001281
mtklein748ca3b2015-01-15 10:56:12 -08001282 JsonWriter::BitmapResult result;
djsollen54416de2015-04-03 07:24:48 -07001283 result.name = task.src->name();
mtklein3eed7dd2016-02-24 19:07:07 -08001284 result.config = task.sink.tag;
djsollen54416de2015-04-03 07:24:48 -07001285 result.sourceType = task.src.tag;
1286 result.sourceOptions = task.src.options;
1287 result.ext = ext;
1288 result.md5 = md5;
Mike Klein0abbaca2019-03-06 09:57:49 -06001289 if (bitmap) {
1290 result.gamut = identify_gamut (bitmap->colorSpace());
1291 result.transferFn = identify_transfer_fn (bitmap->colorSpace());
Mike Kleinea3f0142019-03-20 11:12:10 -05001292 result.colorType = ToolUtils::colortype_name(bitmap->colorType());
1293 result.alphaType = ToolUtils::alphatype_name(bitmap->alphaType());
Mike Klein82020c22019-03-07 14:11:16 -06001294 result.colorDepth = color_depth (bitmap->colorType());
Mike Klein0abbaca2019-03-06 09:57:49 -06001295 }
mtklein748ca3b2015-01-15 10:56:12 -08001296 JsonWriter::AddBitmapResult(result);
1297
mtkleinb0531a72015-04-07 13:38:48 -07001298 // If an MD5 is uninteresting, we want it noted in the JSON file,
1299 // but don't want to dump it out as a .png (or whatever ext is).
1300 if (gUninterestingHashes.contains(md5)) {
1301 return;
1302 }
1303
mtklein748ca3b2015-01-15 10:56:12 -08001304 const char* dir = FLAGS_writePath[0];
Mike Kleinc6142d82019-03-25 10:54:59 -05001305 SkString resources = GetResourcePath();
mtklein748ca3b2015-01-15 10:56:12 -08001306 if (0 == strcmp(dir, "@")) { // Needed for iOS.
Mike Kleinc6142d82019-03-25 10:54:59 -05001307 dir = resources.c_str();
mtklein748ca3b2015-01-15 10:56:12 -08001308 }
1309 sk_mkdir(dir);
1310
1311 SkString path;
1312 if (FLAGS_nameByHash) {
1313 path = SkOSPath::Join(dir, result.md5.c_str());
1314 path.append(".");
1315 path.append(ext);
1316 if (sk_exists(path.c_str())) {
1317 return; // Content-addressed. If it exists already, we're done.
1318 }
1319 } else {
kkinnunen3e980c32015-12-23 01:33:00 -08001320 path = SkOSPath::Join(dir, task.sink.tag.c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001321 sk_mkdir(path.c_str());
msarett9e707a02015-09-01 14:57:57 -07001322 path = SkOSPath::Join(path.c_str(), task.src.tag.c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001323 sk_mkdir(path.c_str());
msarett9e707a02015-09-01 14:57:57 -07001324 if (strcmp(task.src.options.c_str(), "") != 0) {
1325 path = SkOSPath::Join(path.c_str(), task.src.options.c_str());
djsollen54416de2015-04-03 07:24:48 -07001326 sk_mkdir(path.c_str());
1327 }
mtklein748ca3b2015-01-15 10:56:12 -08001328 path = SkOSPath::Join(path.c_str(), task.src->name().c_str());
1329 path.append(".");
1330 path.append(ext);
1331 }
1332
mtklein748ca3b2015-01-15 10:56:12 -08001333 if (bitmap) {
Mike Kleine1271702019-03-07 11:46:59 -06001334 SkASSERT(hashAndEncode);
Mike Klein735c7ba2019-03-25 12:57:58 -05001335 if (!hashAndEncode->writePngTo(path.c_str(),
1336 result.md5.c_str(),
1337 FLAGS_key,
1338 FLAGS_properties)) {
mtklein748ca3b2015-01-15 10:56:12 -08001339 fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str()));
1340 return;
1341 }
1342 } else {
mtkleina5114d72015-08-24 13:27:01 -07001343 SkFILEWStream file(path.c_str());
1344 if (!file.isValid()) {
1345 fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str()));
1346 return;
1347 }
mtklein748ca3b2015-01-15 10:56:12 -08001348 if (!file.writeStream(data, len)) {
1349 fail(SkStringPrintf("Can't write to %s.\n", path.c_str()));
1350 return;
1351 }
1352 }
1353 }
1354};
1355
mtklein748ca3b2015-01-15 10:56:12 -08001356/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1357
1358// Unit tests don't fit so well into the Src/Sink model, so we give them special treatment.
1359
mtklein21eaf3b2016-02-08 12:39:59 -08001360static SkTDArray<skiatest::Test> gParallelTests, gSerialTests;
mtklein748ca3b2015-01-15 10:56:12 -08001361
1362static void gather_tests() {
mtklein6c5fed22015-01-20 13:47:23 -08001363 if (!FLAGS_src.contains("tests")) {
mtklein748ca3b2015-01-15 10:56:12 -08001364 return;
1365 }
Hal Canary972eba32018-07-30 17:07:07 -04001366 for (const skiatest::Test& test : skiatest::TestRegistry::Range()) {
mtklein6393c062015-04-27 08:45:01 -07001367 if (!in_shard()) {
1368 continue;
1369 }
Mike Klein88544fb2019-03-20 10:50:33 -05001370 if (CommandLineFlags::ShouldSkip(FLAGS_match, test.name)) {
mtklein748ca3b2015-01-15 10:56:12 -08001371 continue;
1372 }
Brian Osmanc7ad40f2018-05-31 14:27:17 -04001373 if (test.needsGpu && FLAGS_gpu) {
Mike Reed5edcd312018-08-08 11:23:41 -04001374 (FLAGS_gpu_threading ? gParallelTests : gSerialTests).push_back(test);
halcanary87f3ba42015-01-20 09:30:20 -08001375 } else if (!test.needsGpu && FLAGS_cpu) {
Mike Reed5edcd312018-08-08 11:23:41 -04001376 gParallelTests.push_back(test);
mtklein82d28432015-01-15 12:46:02 -08001377 }
mtklein748ca3b2015-01-15 10:56:12 -08001378 }
1379}
1380
csmartdalton008b9d82017-02-22 12:00:42 -07001381static void run_test(skiatest::Test test, const GrContextOptions& grCtxOptions) {
halcanary87f3ba42015-01-20 09:30:20 -08001382 struct : public skiatest::Reporter {
mtklein36352bf2015-03-25 18:17:31 -07001383 void reportFailed(const skiatest::Failure& failure) override {
halcanary87f3ba42015-01-20 09:30:20 -08001384 fail(failure.toString());
1385 JsonWriter::AddTestFailure(failure);
1386 }
mtklein36352bf2015-03-25 18:17:31 -07001387 bool allowExtendedTest() const override {
halcanary87f3ba42015-01-20 09:30:20 -08001388 return FLAGS_pathOpsExtended;
1389 }
mtklein36352bf2015-03-25 18:17:31 -07001390 bool verbose() const override { return FLAGS_veryVerbose; }
halcanary87f3ba42015-01-20 09:30:20 -08001391 } reporter;
djsollen824996a2015-06-12 12:06:22 -07001392
mtklein3eed7dd2016-02-24 19:07:07 -08001393 if (!FLAGS_dryRun && !is_blacklisted("_", "tests", "_", test.name)) {
Robert Phillipsec325342017-10-30 18:02:48 +00001394 GrContextOptions options = grCtxOptions;
1395 test.modifyGrContextOptions(&options);
1396
Brian Osmancdf31742019-03-13 10:13:46 -04001397 skiatest::ReporterContext ctx(&reporter, SkString(test.name));
mtklein21eaf3b2016-02-08 12:39:59 -08001398 start("unit", "test", "", test.name);
Brian Salomondcfca432017-11-15 15:48:03 -05001399 test.run(&reporter, options);
mtklein748ca3b2015-01-15 10:56:12 -08001400 }
mtklein3eed7dd2016-02-24 19:07:07 -08001401 done("unit", "test", "", test.name);
mtklein748ca3b2015-01-15 10:56:12 -08001402}
1403
1404/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1405
Mike Kleinbe28ee22017-02-06 12:46:20 -05001406int main(int argc, char** argv) {
Dongwon Kang0c7861f2018-02-16 10:55:21 -08001407#if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && defined(SK_HAS_HEIF_LIBRARY)
1408 android::ProcessState::self()->startThreadPool();
1409#endif
Mike Klein88544fb2019-03-20 10:50:33 -05001410 CommandLineFlags::Parse(argc, argv);
Brian Osman53136aa2017-07-20 15:43:35 -04001411
Brian Osmanbc8150f2017-07-24 11:38:01 -04001412 initializeEventTracingForTools();
Brian Osman53136aa2017-07-20 15:43:35 -04001413
Mike Klein6613cc52017-12-19 09:09:33 -05001414#if !defined(SK_BUILD_FOR_GOOGLE3) && defined(SK_BUILD_FOR_IOS)
Mike Kleinadacaef2017-02-06 09:26:14 -05001415 cd_Documents();
1416#endif
bsalomon71de3532016-04-26 14:27:21 -07001417 setbuf(stdout, nullptr);
mtklein246ba3a2016-02-23 10:39:36 -08001418 setup_crash_handler();
mtkleinafae30a2016-02-24 12:28:32 -08001419
Mike Klein19cc0f62019-03-22 15:30:07 -05001420 ToolUtils::SetDefaultFontMgr();
Mike Klein03fa5d42019-03-22 11:39:09 -05001421 SetAnalyticAAFromCommonFlags();
liyuqian38911a72016-10-04 11:23:22 -07001422
Mike Reed7c26ca72017-07-05 15:45:52 -04001423 if (FLAGS_forceRasterPipeline) {
1424 gSkForceRasterPipelineBlitter = true;
1425 }
Yuqian Li550148b2017-01-13 10:13:13 -05001426
Mike Kleine9f187b2017-06-26 13:23:12 -04001427 // The bots like having a verbose.log to upload, so always touch the file even if --verbose.
1428 if (!FLAGS_writePath.isEmpty()) {
mtklein51c8cfc2016-03-11 12:59:09 -08001429 sk_mkdir(FLAGS_writePath[0]);
mtkleina1ce2162016-07-22 12:23:46 -07001430 gVLog = fopen(SkOSPath::Join(FLAGS_writePath[0], "verbose.log").c_str(), "w");
mtkleinc41fd922016-03-08 09:01:39 -08001431 }
Mike Kleine9f187b2017-06-26 13:23:12 -04001432 if (FLAGS_verbose) {
1433 gVLog = stderr;
1434 }
mtkleinc41fd922016-03-08 09:01:39 -08001435
csmartdalton008b9d82017-02-22 12:00:42 -07001436 GrContextOptions grCtxOptions;
Chris Dalton040238b2017-12-18 14:22:34 -07001437 SetCtxOptionsFromCommonFlags(&grCtxOptions);
csmartdalton008b9d82017-02-22 12:00:42 -07001438
Mike Kleinc6142d82019-03-25 10:54:59 -05001439 dump_json(); // It's handy for the bots to assume this is ~never missing.
1440
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +00001441 SkAutoGraphics ag;
mtklein406654b2014-09-03 15:34:37 -07001442 SkTaskGroup::Enabler enabled(FLAGS_threads);
commit-bot@chromium.orga65e2fd2014-05-30 17:23:31 +00001443
Mike Reed0933bc92017-12-09 01:27:41 +00001444 if (nullptr == GetResourceAsData("images/color_wheel.png")) {
1445 info("Some resources are missing. Do you need to set --resourcePath?\n");
halcanary7d571242016-02-24 17:59:16 -08001446 }
Brian Osman57796b32019-01-25 18:02:59 +00001447 gather_gold();
borenet09ed4802015-04-03 14:15:33 -07001448 gather_uninteresting_hashes();
mtklein62bd1a62015-01-27 14:46:26 -08001449
scroggo86737142016-02-03 12:19:11 -08001450 if (!gather_srcs()) {
1451 return 1;
1452 }
Ben Wagnerf28d4722017-08-11 17:33:22 -04001453 // TODO(dogben): This is a bit ugly. Find a cleaner way to do this.
1454 bool defaultConfigs = true;
1455 for (int i = 0; i < argc; i++) {
1456 static const char* kConfigArg = "--config";
1457 if (strcmp(argv[i], kConfigArg) == 0) {
1458 defaultConfigs = false;
1459 break;
1460 }
1461 }
1462 if (!gather_sinks(grCtxOptions, defaultConfigs)) {
brianosman05c987c2016-05-09 13:42:16 -07001463 return 1;
1464 }
mtklein748ca3b2015-01-15 10:56:12 -08001465 gather_tests();
mtklein21eaf3b2016-02-08 12:39:59 -08001466 gPending = gSrcs.count() * gSinks.count() + gParallelTests.count() + gSerialTests.count();
Brian Osmand0677bc2017-08-03 12:13:47 -04001467 info("%d srcs * %d sinks + %d tests == %d tasks\n",
mtkleinc41fd922016-03-08 09:01:39 -08001468 gSrcs.count(), gSinks.count(), gParallelTests.count() + gSerialTests.count(), gPending);
mtklein748ca3b2015-01-15 10:56:12 -08001469
mtklein21eaf3b2016-02-08 12:39:59 -08001470 // Kick off as much parallel work as we can, making note of any serial work we'll need to do.
1471 SkTaskGroup parallel;
1472 SkTArray<Task> serial;
1473
1474 for (auto& sink : gSinks)
1475 for (auto& src : gSrcs) {
mtklein3eed7dd2016-02-24 19:07:07 -08001476 if (src->veto(sink->flags()) ||
1477 is_blacklisted(sink.tag.c_str(), src.tag.c_str(),
1478 src.options.c_str(), src->name().c_str())) {
mtkleinf10637f2016-06-10 13:56:35 -07001479 SkAutoMutexAcquire lock(gMutex);
mtklein3eed7dd2016-02-24 19:07:07 -08001480 gPending--;
1481 continue;
1482 }
1483
mtklein21eaf3b2016-02-08 12:39:59 -08001484 Task task(src, sink);
1485 if (src->serial() || sink->serial()) {
1486 serial.push_back(task);
1487 } else {
1488 parallel.add([task] { Task::Run(task); });
mtklein748ca3b2015-01-15 10:56:12 -08001489 }
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001490 }
mtklein21eaf3b2016-02-08 12:39:59 -08001491 for (auto test : gParallelTests) {
csmartdalton008b9d82017-02-22 12:00:42 -07001492 parallel.add([test, grCtxOptions] { run_test(test, grCtxOptions); });
mtklein55e88b22015-01-21 15:50:13 -08001493 }
mtklein21eaf3b2016-02-08 12:39:59 -08001494
1495 // With the parallel work running, run serial tasks and tests here on main thread.
1496 for (auto task : serial) { Task::Run(task); }
csmartdalton008b9d82017-02-22 12:00:42 -07001497 for (auto test : gSerialTests) { run_test(test, grCtxOptions); }
mtklein21eaf3b2016-02-08 12:39:59 -08001498
1499 // Wait for any remaining parallel work to complete (including any spun off of serial tasks).
1500 parallel.wait();
mtkleincd50bca2016-01-05 06:20:20 -08001501 gDefinitelyThreadSafeWork.wait();
1502
Ben Wagner83c6b962018-07-10 19:40:15 -04001503 // At this point we're back in single-threaded land.
1504
mtkleinda884c42016-02-24 18:00:23 -08001505 // We'd better have run everything.
1506 SkASSERT(gPending == 0);
mtkleine027f172016-02-26 15:53:06 -08001507 // Make sure we've flushed all our results to disk.
Mike Kleinc6142d82019-03-25 10:54:59 -05001508 dump_json();
mtkleinda884c42016-02-24 18:00:23 -08001509
mtklein748ca3b2015-01-15 10:56:12 -08001510 if (gFailures.count() > 0) {
mtkleinc41fd922016-03-08 09:01:39 -08001511 info("Failures:\n");
mtklein748ca3b2015-01-15 10:56:12 -08001512 for (int i = 0; i < gFailures.count(); i++) {
mtkleinc41fd922016-03-08 09:01:39 -08001513 info("\t%s\n", gFailures[i].c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001514 }
mtkleinc41fd922016-03-08 09:01:39 -08001515 info("%d failures\n", gFailures.count());
Kevin Lubick805c4e82019-03-20 09:46:09 -04001516 // A non-zero return code does not make it to Swarming
1517 // An abort does.
1518#ifdef SK_BUILD_FOR_IOS
1519 SK_ABORT("There were failures!");
1520#endif
mtklein748ca3b2015-01-15 10:56:12 -08001521 return 1;
mtklein114c3cd2015-01-15 10:15:02 -08001522 }
mtkleinafae30a2016-02-24 12:28:32 -08001523
Herb Derby5a523fe2017-01-26 16:48:28 -05001524 SkGraphics::PurgeAllCaches();
mtkleinc41fd922016-03-08 09:01:39 -08001525 info("Finished!\n");
Brian Osman53136aa2017-07-20 15:43:35 -04001526
mtklein748ca3b2015-01-15 10:56:12 -08001527 return 0;
mtklein@google.comd36522d2013-10-16 13:02:15 +00001528}