blob: e2687a23886aebf9faf4cbe171e26c2e90d779f6 [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
John Stilesfbd050b2020-08-03 13:21:46 -040043#include <memory>
scroggo19b91532016-10-24 09:03:26 -070044#include <vector>
45
bungeman60e0fee2015-08-26 05:15:46 -070046#include <stdlib.h>
47
Mike Klein8f11d4d2018-01-24 12:42:55 -050048#ifndef SK_BUILD_FOR_WIN
scroggo27a58342015-10-28 08:56:41 -070049 #include <unistd.h>
50#endif
51
Dongwon Kang0c7861f2018-02-16 10:55:21 -080052#if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && defined(SK_HAS_HEIF_LIBRARY)
Mike Klein055f5352020-01-30 11:11:12 -060053 #include <binder/IPCThreadState.h>
54#endif
55
56#if defined(SK_BUILD_FOR_MAC)
57 #include "include/utils/mac/SkCGUtils.h"
58 #include "src/utils/mac/SkUniqueCFRef.h"
Dongwon Kang0c7861f2018-02-16 10:55:21 -080059#endif
60
Mike Reed7c26ca72017-07-05 15:45:52 -040061extern bool gSkForceRasterPipelineBlitter;
Mike Klein9ae06632020-01-28 12:41:02 -060062extern bool gUseSkVMBlitter;
Mike Klein813e8cc2020-08-05 09:33:38 -050063extern bool gSkVMAllowJIT;
Mike Reed7c26ca72017-07-05 15:45:52 -040064
Florin Malita02616ea2020-06-25 13:33:17 -040065static DEFINE_string(src, "tests gm skp mskp lottie rive svg image colorImage",
66 "Source types to test.");
Mike Klein84836b72019-03-21 11:31:36 -050067static DEFINE_bool(nameByHash, false,
68 "If true, write to FLAGS_writePath[0]/<hash>.png instead of "
69 "to FLAGS_writePath[0]/<config>/<sourceType>/<sourceOptions>/<name>.png");
70static DEFINE_bool2(pathOpsExtended, x, false, "Run extended pathOps tests.");
71static DEFINE_string(matrix, "1 0 0 1",
72 "2x2 scale+skew matrix to apply or upright when using "
73 "'matrix' or 'upright' in config.");
mtklein@google.comd36522d2013-10-16 13:02:15 +000074
Mike Kleina54d3802020-07-24 12:37:32 -050075static DEFINE_string(skip, "",
76 "Space-separated config/src/srcOptions/name quadruples to skip. "
Chris Daltonecf78ac2017-08-15 15:43:08 -060077 "'_' matches anything. '~' negates the match. E.g. \n"
Mike Kleina54d3802020-07-24 12:37:32 -050078 "'--skip gpu skp _ _' will skip all SKPs drawn into the gpu config.\n"
79 "'--skip gpu skp _ _ 8888 gm _ aarects' will also skip the aarects GM on 8888.\n"
80 "'--skip ~8888 svg _ svgparse_' blocks non-8888 SVGs that contain \"svgparse_\" in "
Chris Daltonecf78ac2017-08-15 15:43:08 -060081 "the name.");
mtkleina2ef6422015-01-15 13:44:22 -080082
Mike Klein84836b72019-03-21 11:31:36 -050083static DEFINE_string2(readPath, r, "",
84 "If set check for equality with golden results in this directory.");
Mike Kleinc6142d82019-03-25 10:54:59 -050085DEFINE_string2(writePath, w, "", "If set, write bitmaps here as .pngs.");
86
Brian Osman57796b32019-01-25 18:02:59 +000087
Mike Klein84836b72019-03-21 11:31:36 -050088static DEFINE_string(uninterestingHashesFile, "",
borenet09ed4802015-04-03 14:15:33 -070089 "File containing a list of uninteresting hashes. If a result hashes to something in "
90 "this list, no image is written for that result.");
91
Mike Klein5b3f3432019-03-21 11:42:21 -050092static DEFINE_int(shards, 1, "We're splitting source data into this many shards.");
93static DEFINE_int(shard, 0, "Which shard do I run?");
mtklein6393c062015-04-27 08:45:01 -070094
Mike Klein84836b72019-03-21 11:31:36 -050095static DEFINE_string(mskps, "", "Directory to read mskps from, or a single mskp file.");
96static DEFINE_bool(forceRasterPipeline, false, "sets gSkForceRasterPipelineBlitter");
Mike Klein9ae06632020-01-28 12:41:02 -060097static DEFINE_bool(skvm, false, "sets gUseSkVMBlitter");
Mike Klein813e8cc2020-08-05 09:33:38 -050098static DEFINE_bool(jit, true, "sets gSkVMAllowJIT");
halcanary45420a92016-06-02 12:41:14 -070099
Mike Klein84836b72019-03-21 11:31:36 -0500100static DEFINE_string(bisect, "",
Chris Dalton184c37e2018-09-28 11:27:39 -0600101 "Pair of: SKP file to bisect, followed by an l/r bisect trail string (e.g., 'lrll'). The "
102 "l/r trail specifies which half to keep at each step of a binary search through the SKP's "
103 "paths. An empty string performs no bisect. Only the SkPaths are bisected; all other draws "
104 "are thrown out. This is useful for finding a reduced repo case for path drawing bugs.");
105
Mike Klein84836b72019-03-21 11:31:36 -0500106static DEFINE_bool(ignoreSigInt, false, "ignore SIGINT signals during test execution");
Derek Sollenbergeredfe3df2017-07-19 15:25:24 -0400107
Mike Klein84836b72019-03-21 11:31:36 -0500108static DEFINE_bool(checkF16, false, "Ensure that F16Norm pixels are clamped.");
Brian Osman582f6862019-03-11 11:20:55 -0400109
Mike Klein19fb3972019-03-21 13:08:08 -0500110static DEFINE_string(colorImages, "",
111 "List of images and/or directories to decode with color correction. "
112 "A directory with no images is treated as a fatal error.");
113
Mike Kleind0f321b2019-03-22 13:15:11 -0500114static DEFINE_bool2(veryVerbose, V, false, "tell individual tests to be verbose.");
115
Leon Scroggins III1ff07062020-07-27 14:52:19 -0400116static DEFINE_bool(cpu, true, "Run CPU-bound work?");
117static DEFINE_bool(gpu, true, "Run GPU-bound work?");
Mike Klein629f5fc2019-03-22 14:55:19 -0500118
119static DEFINE_bool(dryRun, false,
120 "just print the tests that would be run, without actually running them.");
121
122static DEFINE_string(images, "",
123 "List of images and/or directories to decode. A directory with no images"
124 " is treated as a fatal error.");
125
126static DEFINE_bool(simpleCodec, false,
127 "Runs of a subset of the codec tests, "
128 "with no scaling or subsetting, always using the canvas color type.");
Mike Klein19fb3972019-03-21 13:08:08 -0500129
Mike Kleinc6142d82019-03-25 10:54:59 -0500130static DEFINE_string2(match, m, nullptr,
131 "[~][^]substring[$] [...] of name to run.\n"
132 "Multiple matches may be separated by spaces.\n"
133 "~ causes a matching name to always be skipped\n"
134 "^ requires the start of the name to match\n"
135 "$ requires the end of the name to match\n"
136 "^ and $ requires an exact match\n"
137 "If a name does not match any list entry,\n"
138 "it is skipped unless some list entry starts with ~");
139
140static DEFINE_bool2(quiet, q, false, "if true, don't print status updates.");
141static DEFINE_bool2(verbose, v, false, "enable verbose output from the test driver.");
142
143static DEFINE_string(skps, "skps", "Directory to read skps from.");
144static DEFINE_string(lotties, "lotties", "Directory to read (Bodymovin) jsons from.");
Florin Malita02616ea2020-06-25 13:33:17 -0400145static DEFINE_string(rives, "rives", "Directory to read Rive/Flare files from.");
Mike Kleinc6142d82019-03-25 10:54:59 -0500146static DEFINE_string(svgs, "", "Directory to read SVGs from, or a single SVG file.");
147
148static DEFINE_int_2(threads, j, -1,
149 "Run threadsafe tests on a threadpool with this many extra threads, "
150 "defaulting to one extra thread per core.");
151
152static DEFINE_string(key, "",
153 "Space-separated key/value pairs to add to JSON identifying this builder.");
154static DEFINE_string(properties, "",
155 "Space-separated key/value pairs to add to JSON identifying this run.");
156
Mike Klein055f5352020-01-30 11:11:12 -0600157static DEFINE_bool(rasterize_pdf, false, "Rasterize PDFs when possible.");
158
Tyler Denniston45f94f82020-02-04 16:09:08 -0500159static DEFINE_bool(runVerifiers, false,
160 "if true, run SkQP-style verification of GM-produced images.");
161
Brian Osman1c1208e2019-06-24 13:36:05 -0400162#if defined(__MSVC_RUNTIME_CHECKS)
163#include <rtcapi.h>
164int RuntimeCheckErrorFunc(int errorType, const char* filename, int linenumber,
165 const char* moduleName, const char* fmt, ...) {
166 va_list args;
167 va_start(args, fmt);
168 vfprintf(stderr, fmt, args);
169 va_end(args);
170
171 SkDebugf("Line #%d\nFile: %s\nModule: %s\n",
172 linenumber, filename ? filename : "Unknown", moduleName ? moduleName : "Unknwon");
173 return 1;
174}
175#endif
176
mtklein748ca3b2015-01-15 10:56:12 -0800177using namespace DM;
bsalomon3724e572016-03-30 18:56:19 -0700178using sk_gpu_test::GrContextFactory;
bsalomon273c0f52016-03-31 10:59:06 -0700179using sk_gpu_test::GLTestContext;
bsalomonf2f1c172016-04-05 12:59:06 -0700180using sk_gpu_test::ContextInfo;
mtklein@google.comd36522d2013-10-16 13:02:15 +0000181
mtklein748ca3b2015-01-15 10:56:12 -0800182/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
183
mtkleinc41fd922016-03-08 09:01:39 -0800184static FILE* gVLog;
185
186template <typename... Args>
187static void vlog(const char* fmt, Args&&... args) {
188 if (gVLog) {
mtkleinc41fd922016-03-08 09:01:39 -0800189 fprintf(gVLog, fmt, args...);
190 fflush(gVLog);
191 }
192}
193
194template <typename... Args>
195static void info(const char* fmt, Args&&... args) {
196 vlog(fmt, args...);
197 if (!FLAGS_quiet) {
198 printf(fmt, args...);
199 }
200}
201static void info(const char* fmt) {
202 if (!FLAGS_quiet) {
203 printf("%s", fmt); // Clang warns printf(fmt) is insecure.
204 }
205}
206
John Stiles33e044f2020-06-19 18:34:51 -0400207static SkTArray<SkString>* gFailures = new SkTArray<SkString>;
mtklein748ca3b2015-01-15 10:56:12 -0800208
mtklein3eed7dd2016-02-24 19:07:07 -0800209static void fail(const SkString& err) {
Herb Derby9c71e7b2019-06-17 14:40:42 -0400210 static SkSpinlock mutex;
211 SkAutoSpinlock lock(mutex);
mtklein748ca3b2015-01-15 10:56:12 -0800212 SkDebugf("\n\nFAILURE: %s\n\n", err.c_str());
John Stiles33e044f2020-06-19 18:34:51 -0400213 gFailures->push_back(err);
halcanary9e398f72015-01-10 11:18:04 -0800214}
215
mtklein0f7748a2016-07-25 15:27:29 -0700216struct Running {
217 SkString id;
218 SkThreadID thread;
219
220 void dump() const {
221 info("\t%s\n", id.c_str());
222 }
223};
mtkleinb37cb412015-03-18 05:27:14 -0700224
Mike Kleinc6142d82019-03-25 10:54:59 -0500225static void dump_json() {
226 if (!FLAGS_writePath.isEmpty()) {
227 JsonWriter::DumpJson(FLAGS_writePath[0], FLAGS_key, FLAGS_properties);
228 }
229}
230
mtklein246ba3a2016-02-23 10:39:36 -0800231// We use a spinlock to make locking this in a signal handler _somewhat_ safe.
John Stiles33e044f2020-06-19 18:34:51 -0400232static SkSpinlock* gMutex = new SkSpinlock;
233static int gPending;
234static SkTArray<Running>* gRunning = new SkTArray<Running>;
mtklein748ca3b2015-01-15 10:56:12 -0800235
mtklein3eed7dd2016-02-24 19:07:07 -0800236static void done(const char* config, const char* src, const char* srcOptions, const char* name) {
237 SkString id = SkStringPrintf("%s %s %s %s", config, src, srcOptions, name);
mtkleinc41fd922016-03-08 09:01:39 -0800238 vlog("done %s\n", id.c_str());
mtkleinafae30a2016-02-24 12:28:32 -0800239 int pending;
mtkleinb37cb412015-03-18 05:27:14 -0700240 {
John Stiles33e044f2020-06-19 18:34:51 -0400241 SkAutoSpinlock lock(*gMutex);
242 for (int i = 0; i < gRunning->count(); i++) {
243 if (gRunning->at(i).id == id) {
244 gRunning->removeShuffle(i);
mtkleinb37cb412015-03-18 05:27:14 -0700245 break;
246 }
247 }
mtkleinafae30a2016-02-24 12:28:32 -0800248 pending = --gPending;
reed50bc0512015-05-19 14:13:31 -0700249 }
Mike Klein03a95ad2017-06-23 12:36:32 -0400250
251 // We write out dm.json file and print out a progress update every once in a while.
252 // Notice this also handles the final dm.json and progress update when pending == 0.
mtkleina17241b2015-01-23 05:48:00 -0800253 if (pending % 500 == 0) {
Mike Kleinc6142d82019-03-25 10:54:59 -0500254 dump_json();
Mike Klein03a95ad2017-06-23 12:36:32 -0400255
256 int curr = sk_tools::getCurrResidentSetSizeMB(),
257 peak = sk_tools::getMaxResidentSetSizeMB();
Mike Klein03a95ad2017-06-23 12:36:32 -0400258
John Stiles33e044f2020-06-19 18:34:51 -0400259 SkAutoSpinlock lock(*gMutex);
Mike Klein21ba7722018-10-02 13:57:44 +0000260 info("\n%dMB RAM, %dMB peak, %d queued, %d active:\n",
John Stiles33e044f2020-06-19 18:34:51 -0400261 curr, peak, gPending - gRunning->count(), gRunning->count());
262 for (auto& task : *gRunning) {
Mike Klein03a95ad2017-06-23 12:36:32 -0400263 task.dump();
264 }
mtkleina17241b2015-01-23 05:48:00 -0800265 }
mtklein@google.comd36522d2013-10-16 13:02:15 +0000266}
267
mtklein3eed7dd2016-02-24 19:07:07 -0800268static void start(const char* config, const char* src, const char* srcOptions, const char* name) {
269 SkString id = SkStringPrintf("%s %s %s %s", config, src, srcOptions, name);
mtkleinc41fd922016-03-08 09:01:39 -0800270 vlog("start %s\n", id.c_str());
John Stiles33e044f2020-06-19 18:34:51 -0400271 SkAutoSpinlock lock(*gMutex);
272 gRunning->push_back({id,SkGetThreadID()});
mtkleinb37cb412015-03-18 05:27:14 -0700273}
274
Mike Klein3cc2d202016-10-24 11:39:43 -0400275static void find_culprit() {
276 // Assumes gMutex is locked.
277 SkThreadID thisThread = SkGetThreadID();
John Stiles33e044f2020-06-19 18:34:51 -0400278 for (auto& task : *gRunning) {
Mike Klein3cc2d202016-10-24 11:39:43 -0400279 if (task.thread == thisThread) {
280 info("Likely culprit:\n");
281 task.dump();
mtklein0f7748a2016-07-25 15:27:29 -0700282 }
283 }
Mike Klein3cc2d202016-10-24 11:39:43 -0400284}
mtklein0f7748a2016-07-25 15:27:29 -0700285
Mike Klein8f11d4d2018-01-24 12:42:55 -0500286#if defined(SK_BUILD_FOR_WIN)
mtklein5b64dab2016-06-09 08:59:48 -0700287 static LONG WINAPI crash_handler(EXCEPTION_POINTERS* e) {
mtkleinf8557292016-02-29 06:35:28 -0800288 static const struct {
289 const char* name;
robertphillips75467862016-03-01 14:10:23 -0800290 DWORD code;
mtkleinf8557292016-02-29 06:35:28 -0800291 } kExceptions[] = {
292 #define _(E) {#E, E}
293 _(EXCEPTION_ACCESS_VIOLATION),
294 _(EXCEPTION_BREAKPOINT),
295 _(EXCEPTION_INT_DIVIDE_BY_ZERO),
296 _(EXCEPTION_STACK_OVERFLOW),
297 // TODO: more?
298 #undef _
299 };
300
John Stiles33e044f2020-06-19 18:34:51 -0400301 SkAutoSpinlock lock(*gMutex);
mtklein5b64dab2016-06-09 08:59:48 -0700302
303 const DWORD code = e->ExceptionRecord->ExceptionCode;
304 info("\nCaught exception %u", code);
305 for (const auto& exception : kExceptions) {
306 if (exception.code == code) {
307 info(" %s", exception.name);
mtkleinf8557292016-02-29 06:35:28 -0800308 }
mtkleinf8557292016-02-29 06:35:28 -0800309 }
mtklein5b64dab2016-06-09 08:59:48 -0700310 info(", was running:\n");
John Stiles33e044f2020-06-19 18:34:51 -0400311 for (auto& task : *gRunning) {
mtklein0f7748a2016-07-25 15:27:29 -0700312 task.dump();
mtklein5b64dab2016-06-09 08:59:48 -0700313 }
mtklein0f7748a2016-07-25 15:27:29 -0700314 find_culprit();
mtklein5b64dab2016-06-09 08:59:48 -0700315 fflush(stdout);
316
mtkleinf8557292016-02-29 06:35:28 -0800317 // Execute default exception handler... hopefully, exit.
318 return EXCEPTION_EXECUTE_HANDLER;
mtklein246ba3a2016-02-23 10:39:36 -0800319 }
320
Mike Klein3cc2d202016-10-24 11:39:43 -0400321 static void setup_crash_handler() {
322 SetUnhandledExceptionFilter(crash_handler);
323 }
324#else
mtklein246ba3a2016-02-23 10:39:36 -0800325 #include <signal.h>
Mike Klein3cc2d202016-10-24 11:39:43 -0400326 #if !defined(SK_BUILD_FOR_ANDROID)
327 #include <execinfo.h>
Brian Salomondcbb9d92017-07-19 10:53:20 -0400328
329#endif
Mike Klein3cc2d202016-10-24 11:39:43 -0400330
331 static constexpr int max_of() { return 0; }
332 template <typename... Rest>
333 static constexpr int max_of(int x, Rest... rest) {
334 return x > max_of(rest...) ? x : max_of(rest...);
335 }
336
Mike Kleinc7278ad2018-02-15 09:26:54 -0500337 static void (*previous_handler[max_of(SIGABRT,SIGBUS,SIGFPE,SIGILL,SIGSEGV,SIGTERM)+1])(int);
mtkleinf8557292016-02-29 06:35:28 -0800338
mtklein5b64dab2016-06-09 08:59:48 -0700339 static void crash_handler(int sig) {
John Stiles33e044f2020-06-19 18:34:51 -0400340 SkAutoSpinlock lock(*gMutex);
mtklein5b64dab2016-06-09 08:59:48 -0700341
Mike Klein701a3582018-06-28 14:08:19 +0000342 info("\nCaught signal %d [%s] (%dMB RAM, peak %dMB), was running:\n",
343 sig, strsignal(sig),
344 sk_tools::getCurrResidentSetSizeMB(), sk_tools::getMaxResidentSetSizeMB());
345
John Stiles33e044f2020-06-19 18:34:51 -0400346 for (auto& task : *gRunning) {
mtklein0f7748a2016-07-25 15:27:29 -0700347 task.dump();
mtklein5b64dab2016-06-09 08:59:48 -0700348 }
mtklein0f7748a2016-07-25 15:27:29 -0700349 find_culprit();
mtklein5b64dab2016-06-09 08:59:48 -0700350
Mike Klein3cc2d202016-10-24 11:39:43 -0400351 #if !defined(SK_BUILD_FOR_ANDROID)
John Stilesede793a2020-10-15 13:27:12 -0400352 void* stack[128];
mtklein5b64dab2016-06-09 08:59:48 -0700353 int count = backtrace(stack, SK_ARRAY_COUNT(stack));
354 char** symbols = backtrace_symbols(stack, count);
355 info("\nStack trace:\n");
356 for (int i = 0; i < count; i++) {
357 info(" %s\n", symbols[i]);
358 }
Mike Klein3cc2d202016-10-24 11:39:43 -0400359 #endif
mtklein5b64dab2016-06-09 08:59:48 -0700360 fflush(stdout);
361
Mike Kleinca8087f2019-03-18 09:01:39 -0500362 if (sig == SIGINT && FLAGS_ignoreSigInt) {
363 info("Ignoring signal %d because of --ignoreSigInt.\n"
364 "This is probably a sign the bot is overloaded with work.\n", sig);
365 } else {
366 signal(sig, previous_handler[sig]);
367 raise(sig);
368 }
mtklein5b64dab2016-06-09 08:59:48 -0700369 }
370
mtklein246ba3a2016-02-23 10:39:36 -0800371 static void setup_crash_handler() {
Mike Klein701a3582018-06-28 14:08:19 +0000372 const int kSignals[] = { SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGINT, SIGSEGV, SIGTERM };
mtklein246ba3a2016-02-23 10:39:36 -0800373 for (int sig : kSignals) {
Mike Klein3cc2d202016-10-24 11:39:43 -0400374 previous_handler[sig] = signal(sig, crash_handler);
mtklein246ba3a2016-02-23 10:39:36 -0800375 }
376 }
377#endif
378
mtklein748ca3b2015-01-15 10:56:12 -0800379/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
mtklein114c3cd2015-01-15 10:15:02 -0800380
Brian Osman57796b32019-01-25 18:02:59 +0000381struct Gold : public SkString {
382 Gold() : SkString("") {}
383 Gold(const SkString& sink, const SkString& src,
384 const SkString& srcOptions, const SkString& name,
385 const SkString& md5)
386 : SkString("") {
387 this->append(sink);
388 this->append(src);
389 this->append(srcOptions);
390 this->append(name);
391 this->append(md5);
392 }
393 struct Hash {
394 uint32_t operator()(const Gold& g) const {
395 return SkGoodHash()((const SkString&)g);
396 }
397 };
398};
John Stiles33e044f2020-06-19 18:34:51 -0400399static SkTHashSet<Gold, Gold::Hash>* gGold = new SkTHashSet<Gold, Gold::Hash>;
Brian Osman57796b32019-01-25 18:02:59 +0000400
401static void add_gold(JsonWriter::BitmapResult r) {
John Stiles33e044f2020-06-19 18:34:51 -0400402 gGold->add(Gold(r.config, r.sourceType, r.sourceOptions, r.name, r.md5));
Brian Osman57796b32019-01-25 18:02:59 +0000403}
404
405static void gather_gold() {
406 if (!FLAGS_readPath.isEmpty()) {
407 SkString path(FLAGS_readPath[0]);
408 path.append("/dm.json");
409 if (!JsonWriter::ReadJson(path.c_str(), add_gold)) {
410 fail(SkStringPrintf("Couldn't read %s for golden results.", path.c_str()));
411 }
412 }
413}
414
415/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
416
Mike Klein8f11d4d2018-01-24 12:42:55 -0500417#if defined(SK_BUILD_FOR_WIN)
John Stiles33e044f2020-06-19 18:34:51 -0400418 static constexpr char kNewline[] = "\r\n";
mtklein935f1b12016-03-16 08:37:19 -0700419#else
John Stiles33e044f2020-06-19 18:34:51 -0400420 static constexpr char kNewline[] = "\n";
mtklein935f1b12016-03-16 08:37:19 -0700421#endif
422
John Stiles33e044f2020-06-19 18:34:51 -0400423static SkTHashSet<SkString>* gUninterestingHashes = new SkTHashSet<SkString>;
borenet09ed4802015-04-03 14:15:33 -0700424
425static void gather_uninteresting_hashes() {
426 if (!FLAGS_uninterestingHashesFile.isEmpty()) {
bungeman38d909e2016-08-02 14:40:46 -0700427 sk_sp<SkData> data(SkData::MakeFromFileName(FLAGS_uninterestingHashesFile[0]));
mtkleincc334b32015-09-22 11:43:53 -0700428 if (!data) {
mtkleinc41fd922016-03-08 09:01:39 -0800429 info("WARNING: unable to read uninteresting hashes from %s\n",
430 FLAGS_uninterestingHashesFile[0]);
mtkleincc334b32015-09-22 11:43:53 -0700431 return;
432 }
Mike Klein45dcc0c2017-04-05 18:04:31 -0400433
434 // Copy to a string to make sure SkStrSplit has a terminating \0 to find.
435 SkString contents((const char*)data->data(), data->size());
436
borenet09ed4802015-04-03 14:15:33 -0700437 SkTArray<SkString> hashes;
Mike Klein45dcc0c2017-04-05 18:04:31 -0400438 SkStrSplit(contents.c_str(), kNewline, &hashes);
borenet09ed4802015-04-03 14:15:33 -0700439 for (const SkString& hash : hashes) {
John Stiles33e044f2020-06-19 18:34:51 -0400440 gUninterestingHashes->add(hash);
borenet09ed4802015-04-03 14:15:33 -0700441 }
mtkleinc41fd922016-03-08 09:01:39 -0800442 info("FYI: loaded %d distinct uninteresting hashes from %d lines\n",
John Stiles33e044f2020-06-19 18:34:51 -0400443 gUninterestingHashes->count(), hashes.count());
borenet09ed4802015-04-03 14:15:33 -0700444 }
445}
446
447/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
448
Ben Wagner145dbcd2016-11-03 14:40:50 -0400449struct TaggedSrc : public std::unique_ptr<Src> {
mtklein3eed7dd2016-02-24 19:07:07 -0800450 SkString tag;
451 SkString options;
mtkleine0effd62015-07-29 06:37:28 -0700452};
453
Ben Wagner145dbcd2016-11-03 14:40:50 -0400454struct TaggedSink : public std::unique_ptr<Sink> {
kkinnunen3e980c32015-12-23 01:33:00 -0800455 SkString tag;
djsollen54416de2015-04-03 07:24:48 -0700456};
mtklein748ca3b2015-01-15 10:56:12 -0800457
John Stiles33e044f2020-06-19 18:34:51 -0400458static constexpr bool kMemcpyOK = true;
mtklein748ca3b2015-01-15 10:56:12 -0800459
John Stiles33e044f2020-06-19 18:34:51 -0400460static SkTArray<TaggedSrc, kMemcpyOK>* gSrcs = new SkTArray<TaggedSrc, kMemcpyOK>;
461static SkTArray<TaggedSink, kMemcpyOK>* gSinks = new SkTArray<TaggedSink, kMemcpyOK>;
mtklein748ca3b2015-01-15 10:56:12 -0800462
mtklein6393c062015-04-27 08:45:01 -0700463static bool in_shard() {
464 static int N = 0;
465 return N++ % FLAGS_shards == FLAGS_shard;
466}
467
John Stilesb7f22152021-08-11 15:42:39 -0400468static void push_src(const char* tag, ImplicitString options, Src* inSrc) {
469 std::unique_ptr<Src> src(inSrc);
Mike Klein88544fb2019-03-20 10:50:33 -0500470 if (in_shard() && FLAGS_src.contains(tag) &&
471 !CommandLineFlags::ShouldSkip(FLAGS_match, src->name().c_str())) {
John Stiles33e044f2020-06-19 18:34:51 -0400472 TaggedSrc& s = gSrcs->push_back();
mtklein18300a32016-03-16 13:53:35 -0700473 s.reset(src.release());
mtklein748ca3b2015-01-15 10:56:12 -0800474 s.tag = tag;
djsollen54416de2015-04-03 07:24:48 -0700475 s.options = options;
mtklein114c3cd2015-01-15 10:15:02 -0800476 }
mtklein748ca3b2015-01-15 10:56:12 -0800477}
mtklein114c3cd2015-01-15 10:15:02 -0800478
msarett9e707a02015-09-01 14:57:57 -0700479static void push_codec_src(Path path, CodecSrc::Mode mode, CodecSrc::DstColorType dstColorType,
scroggoc5560be2016-02-03 09:42:42 -0800480 SkAlphaType dstAlphaType, float scale) {
scroggoe4499842016-02-25 11:03:47 -0800481 if (FLAGS_simpleCodec) {
scroggo19b91532016-10-24 09:03:26 -0700482 const bool simple = CodecSrc::kCodec_Mode == mode || CodecSrc::kAnimated_Mode == mode;
483 if (!simple || dstColorType != CodecSrc::kGetFromCanvas_DstColorType || scale != 1.0f) {
scroggoe4499842016-02-25 11:03:47 -0800484 // Only decode in the simple case.
485 return;
scroggo19b91532016-10-24 09:03:26 -0700486 }
scroggoe4499842016-02-25 11:03:47 -0800487 }
msarett9e707a02015-09-01 14:57:57 -0700488 SkString folder;
489 switch (mode) {
490 case CodecSrc::kCodec_Mode:
491 folder.append("codec");
492 break;
msarettbb25b532016-01-13 09:31:39 -0800493 case CodecSrc::kCodecZeroInit_Mode:
494 folder.append("codec_zero_init");
495 break;
msarett9e707a02015-09-01 14:57:57 -0700496 case CodecSrc::kScanline_Mode:
497 folder.append("scanline");
498 break;
msarett9e707a02015-09-01 14:57:57 -0700499 case CodecSrc::kStripe_Mode:
500 folder.append("stripe");
501 break;
msarett91c22b22016-02-22 12:27:46 -0800502 case CodecSrc::kCroppedScanline_Mode:
503 folder.append("crop");
504 break;
msarett9e707a02015-09-01 14:57:57 -0700505 case CodecSrc::kSubset_Mode:
msarett36c37962015-09-02 13:20:52 -0700506 folder.append("codec_subset");
msarett9e707a02015-09-01 14:57:57 -0700507 break;
scroggo19b91532016-10-24 09:03:26 -0700508 case CodecSrc::kAnimated_Mode:
509 folder.append("codec_animated");
510 break;
msarett9e707a02015-09-01 14:57:57 -0700511 }
512
513 switch (dstColorType) {
514 case CodecSrc::kGrayscale_Always_DstColorType:
515 folder.append("_kGray8");
516 break;
msarett34e0ec42016-04-22 16:27:24 -0700517 case CodecSrc::kNonNative8888_Always_DstColorType:
518 folder.append("_kNonNative");
519 break;
msarett9e707a02015-09-01 14:57:57 -0700520 default:
521 break;
522 }
523
scroggoc5560be2016-02-03 09:42:42 -0800524 switch (dstAlphaType) {
scroggoc5560be2016-02-03 09:42:42 -0800525 case kPremul_SkAlphaType:
526 folder.append("_premul");
527 break;
528 case kUnpremul_SkAlphaType:
529 folder.append("_unpremul");
530 break;
531 default:
532 break;
533 }
534
msarett9e707a02015-09-01 14:57:57 -0700535 if (1.0f != scale) {
536 folder.appendf("_%.3f", scale);
537 }
538
scroggoc5560be2016-02-03 09:42:42 -0800539 CodecSrc* src = new CodecSrc(path, mode, dstColorType, dstAlphaType, scale);
msarett9e707a02015-09-01 14:57:57 -0700540 push_src("image", folder, src);
541}
542
scroggof8dc9df2016-05-16 09:04:13 -0700543static void push_android_codec_src(Path path, CodecSrc::DstColorType dstColorType,
544 SkAlphaType dstAlphaType, int sampleSize) {
msarett3d9d7a72015-10-21 10:27:10 -0700545 SkString folder;
scroggof8dc9df2016-05-16 09:04:13 -0700546 folder.append("scaled_codec");
msarett3d9d7a72015-10-21 10:27:10 -0700547
548 switch (dstColorType) {
549 case CodecSrc::kGrayscale_Always_DstColorType:
550 folder.append("_kGray8");
551 break;
msarett34e0ec42016-04-22 16:27:24 -0700552 case CodecSrc::kNonNative8888_Always_DstColorType:
553 folder.append("_kNonNative");
554 break;
msarett3d9d7a72015-10-21 10:27:10 -0700555 default:
556 break;
557 }
558
scroggoc5560be2016-02-03 09:42:42 -0800559 switch (dstAlphaType) {
scroggoc5560be2016-02-03 09:42:42 -0800560 case kPremul_SkAlphaType:
561 folder.append("_premul");
562 break;
msarett9e9444c2016-02-03 12:39:10 -0800563 case kUnpremul_SkAlphaType:
564 folder.append("_unpremul");
565 break;
scroggoc5560be2016-02-03 09:42:42 -0800566 default:
567 break;
568 }
569
msarett3d9d7a72015-10-21 10:27:10 -0700570 if (1 != sampleSize) {
msarett4b0778e2015-11-13 09:59:11 -0800571 folder.appendf("_%.3f", 1.0f / (float) sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700572 }
573
scroggof8dc9df2016-05-16 09:04:13 -0700574 AndroidCodecSrc* src = new AndroidCodecSrc(path, dstColorType, dstAlphaType, sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700575 push_src("image", folder, src);
576}
577
msarett18976312016-03-09 14:20:58 -0800578static void push_image_gen_src(Path path, ImageGenSrc::Mode mode, SkAlphaType alphaType, bool isGpu)
579{
580 SkString folder;
581 switch (mode) {
582 case ImageGenSrc::kCodec_Mode:
583 folder.append("gen_codec");
584 break;
585 case ImageGenSrc::kPlatform_Mode:
586 folder.append("gen_platform");
587 break;
588 }
589
590 if (isGpu) {
591 folder.append("_gpu");
592 } else {
593 switch (alphaType) {
594 case kOpaque_SkAlphaType:
595 folder.append("_opaque");
596 break;
597 case kPremul_SkAlphaType:
598 folder.append("_premul");
599 break;
600 case kUnpremul_SkAlphaType:
601 folder.append("_unpremul");
602 break;
603 default:
604 break;
605 }
606 }
607
608 ImageGenSrc* src = new ImageGenSrc(path, mode, alphaType, isGpu);
609 push_src("image", folder, src);
610}
611
Leon Scroggins III87caae62020-05-04 10:02:45 -0400612#ifdef SK_ENABLE_ANDROID_UTILS
Leon Scroggins III07418182017-08-15 12:24:02 -0400613static void push_brd_src(Path path, CodecSrc::DstColorType dstColorType, BRDSrc::Mode mode,
614 uint32_t sampleSize) {
615 SkString folder("brd_android_codec");
616 switch (mode) {
617 case BRDSrc::kFullImage_Mode:
618 break;
619 case BRDSrc::kDivisor_Mode:
620 folder.append("_divisor");
621 break;
622 default:
623 SkASSERT(false);
624 return;
625 }
626
627 switch (dstColorType) {
628 case CodecSrc::kGetFromCanvas_DstColorType:
629 break;
630 case CodecSrc::kGrayscale_Always_DstColorType:
631 folder.append("_kGray");
632 break;
633 default:
634 SkASSERT(false);
635 return;
636 }
637
638 if (1 != sampleSize) {
639 folder.appendf("_%.3f", 1.0f / (float) sampleSize);
640 }
641
642 BRDSrc* src = new BRDSrc(path, mode, dstColorType, sampleSize);
643 push_src("image", folder, src);
644}
645
646static void push_brd_srcs(Path path, bool gray) {
647 if (gray) {
648 // Only run grayscale to one sampleSize and Mode. Though interesting
649 // to test grayscale, it should not reveal anything across various
650 // sampleSizes and Modes
651 // Arbitrarily choose Mode and sampleSize.
652 push_brd_src(path, CodecSrc::kGrayscale_Always_DstColorType,
653 BRDSrc::kFullImage_Mode, 2);
654 }
655
656 // Test on a variety of sampleSizes, making sure to include:
657 // - 2, 4, and 8, which are natively supported by jpeg
658 // - multiples of 2 which are not divisible by 4 (analogous for 4)
659 // - larger powers of two, since BRD clients generally use powers of 2
660 // We will only produce output for the larger sizes on large images.
661 const uint32_t sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 24, 32, 64 };
662
663 const BRDSrc::Mode modes[] = { BRDSrc::kFullImage_Mode, BRDSrc::kDivisor_Mode, };
664
665 for (uint32_t sampleSize : sampleSizes) {
666 for (BRDSrc::Mode mode : modes) {
667 push_brd_src(path, CodecSrc::kGetFromCanvas_DstColorType, mode, sampleSize);
668 }
669 }
670}
Leon Scroggins III87caae62020-05-04 10:02:45 -0400671#endif // SK_ENABLE_ANDROID_UTILS
Leon Scroggins III07418182017-08-15 12:24:02 -0400672
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);
John Stilesa008b0f2020-08-16 08:48:02 -0400680 if (nullptr == codec) {
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 }
Leon Scroggins1340dbd2020-11-09 14:18:12 -0500761 for (float scale : { .5f, .33f }) {
762 push_codec_src(path, CodecSrc::kAnimated_Mode, CodecSrc::kGetFromCanvas_DstColorType,
763 kPremul_SkAlphaType, scale);
764 }
scroggo19b91532016-10-24 09:03:26 -0700765 }
766
767 }
768
scroggoe4499842016-02-25 11:03:47 -0800769 if (FLAGS_simpleCodec) {
770 return;
771 }
772
msarett3d9d7a72015-10-21 10:27:10 -0700773 const int sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
msarett36c37962015-09-02 13:20:52 -0700774
msarett3d9d7a72015-10-21 10:27:10 -0700775 for (int sampleSize : sampleSizes) {
msarett91c22b22016-02-22 12:27:46 -0800776 for (CodecSrc::DstColorType colorType : colorTypes) {
scroggoc5560be2016-02-03 09:42:42 -0800777 for (SkAlphaType alphaType : alphaModes) {
msarettf3dc1882016-04-26 13:06:38 -0700778 // We can exercise all of the kNonNative support code in the swizzler with just a
779 // few sample sizes. Skip the rest.
780 if (CodecSrc::kNonNative8888_Always_DstColorType == colorType && sampleSize > 3) {
781 continue;
782 }
783
scroggof8dc9df2016-05-16 09:04:13 -0700784 push_android_codec_src(path, colorType, alphaType, sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700785 }
msarett36c37962015-09-02 13:20:52 -0700786 }
787 }
msarett18976312016-03-09 14:20:58 -0800788
Leon Scroggins III07418182017-08-15 12:24:02 -0400789 const char* ext = strrchr(path.c_str(), '.');
790 if (ext) {
791 ext++;
msarett18976312016-03-09 14:20:58 -0800792
Leon Scroggins III07418182017-08-15 12:24:02 -0400793 static const char* const rawExts[] = {
794 "arw", "cr2", "dng", "nef", "nrw", "orf", "raf", "rw2", "pef", "srw",
795 "ARW", "CR2", "DNG", "NEF", "NRW", "ORF", "RAF", "RW2", "PEF", "SRW",
796 };
797 for (const char* rawExt : rawExts) {
798 if (0 == strcmp(rawExt, ext)) {
799 // RAW is not supported by image generator (skbug.com/5079) or BRD.
800 return;
801 }
802 }
803
Leon Scroggins III87caae62020-05-04 10:02:45 -0400804#ifdef SK_ENABLE_ANDROID_UTILS
Leon Scroggins III07418182017-08-15 12:24:02 -0400805 static const char* const brdExts[] = {
806 "jpg", "jpeg", "png", "webp",
807 "JPG", "JPEG", "PNG", "WEBP",
808 };
809 for (const char* brdExt : brdExts) {
810 if (0 == strcmp(brdExt, ext)) {
Leon Scroggins IIIc8037dc2017-12-05 13:55:24 -0500811 bool gray = codec->getInfo().colorType() == kGray_8_SkColorType;
Leon Scroggins III07418182017-08-15 12:24:02 -0400812 push_brd_srcs(path, gray);
813 break;
814 }
msarett18976312016-03-09 14:20:58 -0800815 }
Leon Scroggins III87caae62020-05-04 10:02:45 -0400816#endif
msarett18976312016-03-09 14:20:58 -0800817 }
818
819 // Push image generator GPU test.
brianosmanc9ced392016-03-24 07:27:43 -0700820 push_image_gen_src(path, ImageGenSrc::kCodec_Mode, codec->getInfo().alphaType(), true);
msarett18976312016-03-09 14:20:58 -0800821
822 // Push image generator CPU tests.
823 for (SkAlphaType alphaType : alphaModes) {
824 push_image_gen_src(path, ImageGenSrc::kCodec_Mode, alphaType, false);
825
826#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
Hal Canarydb683012016-11-23 08:55:18 -0700827 if (SkEncodedImageFormat::kWEBP != codec->getEncodedFormat() &&
828 SkEncodedImageFormat::kWBMP != codec->getEncodedFormat() &&
msarett18976312016-03-09 14:20:58 -0800829 kUnpremul_SkAlphaType != alphaType)
830 {
831 push_image_gen_src(path, ImageGenSrc::kPlatform_Mode, alphaType, false);
832 }
msarettfc0b6d12016-03-17 13:50:17 -0700833#elif defined(SK_BUILD_FOR_WIN)
Hal Canarydb683012016-11-23 08:55:18 -0700834 if (SkEncodedImageFormat::kWEBP != codec->getEncodedFormat() &&
835 SkEncodedImageFormat::kWBMP != codec->getEncodedFormat())
msarettfc0b6d12016-03-17 13:50:17 -0700836 {
837 push_image_gen_src(path, ImageGenSrc::kPlatform_Mode, alphaType, false);
838 }
Leon Scroggins III326b9892020-08-05 16:51:10 -0400839#elif defined(SK_ENABLE_NDK_IMAGES)
Leon Scroggins IIIf21d6b92020-08-05 10:44:17 -0400840 push_image_gen_src(path, ImageGenSrc::kPlatform_Mode, alphaType, false);
msarett18976312016-03-09 14:20:58 -0800841#endif
842 }
msarett438b2ad2015-04-09 12:43:10 -0700843}
844
fmalitaa2b9fdf2016-08-03 19:53:36 -0700845template <typename T>
Mike Klein88544fb2019-03-20 10:50:33 -0500846void gather_file_srcs(const CommandLineFlags::StringArray& flags,
847 const char* ext,
848 const char* src_name = nullptr) {
Florin Malitaf1ba3ae2018-07-19 15:09:11 -0400849 if (!src_name) {
850 // With the exception of Lottie files, the source name is the extension.
851 src_name = ext;
852 }
853
fmalitaa2b9fdf2016-08-03 19:53:36 -0700854 for (int i = 0; i < flags.count(); i++) {
855 const char* path = flags[i];
856 if (sk_isdir(path)) {
857 SkOSFile::Iter it(path, ext);
858 for (SkString file; it.next(&file); ) {
Florin Malitaf1ba3ae2018-07-19 15:09:11 -0400859 push_src(src_name, "", new T(SkOSPath::Join(path, file.c_str())));
fmalitaa2b9fdf2016-08-03 19:53:36 -0700860 }
861 } else {
Florin Malitaf1ba3ae2018-07-19 15:09:11 -0400862 push_src(src_name, "", new T(path));
fmalitaa2b9fdf2016-08-03 19:53:36 -0700863 }
864 }
865}
866
scroggo86737142016-02-03 12:19:11 -0800867static bool gather_srcs() {
Hal Canary972eba32018-07-30 17:07:07 -0400868 for (skiagm::GMFactory f : skiagm::GMRegistry::Range()) {
869 push_src("gm", "", new GMSrc(f));
mtklein748ca3b2015-01-15 10:56:12 -0800870 }
scroggo86737142016-02-03 12:19:11 -0800871
Robert Phillipse47f0a02018-03-27 17:01:16 -0400872 gather_file_srcs<SKPSrc>(FLAGS_skps, "skp");
fmalitaa2b9fdf2016-08-03 19:53:36 -0700873 gather_file_srcs<MSKPSrc>(FLAGS_mskps, "mskp");
Florin Malita87ccf332018-05-04 12:23:24 -0400874#if defined(SK_ENABLE_SKOTTIE)
Florin Malitaf1ba3ae2018-07-19 15:09:11 -0400875 gather_file_srcs<SkottieSrc>(FLAGS_lotties, "json", "lottie");
Florin Malita124d5af2017-12-31 17:02:26 -0500876#endif
Florin Malita02616ea2020-06-25 13:33:17 -0400877#if defined(SK_ENABLE_SKRIVE)
878 gather_file_srcs<SkRiveSrc>(FLAGS_rives, "flr", "rive");
879#endif
Robert Phillips2af13c12021-09-01 16:47:01 +0000880#if defined(SK_ENABLE_SVG)
fmalitaa2b9fdf2016-08-03 19:53:36 -0700881 gather_file_srcs<SVGSrc>(FLAGS_svgs, "svg");
882#endif
Chris Dalton184c37e2018-09-28 11:27:39 -0600883 if (!FLAGS_bisect.isEmpty()) {
884 // An empty l/r trail string will draw all the paths.
885 push_src("bisect", "",
886 new BisectSrc(FLAGS_bisect[0], FLAGS_bisect.count() > 1 ? FLAGS_bisect[1] : ""));
887 }
halcanary45420a92016-06-02 12:41:14 -0700888
scroggo86737142016-02-03 12:19:11 -0800889 SkTArray<SkString> images;
msarett69deca82016-04-29 09:38:40 -0700890 if (!CollectImages(FLAGS_images, &images)) {
scroggo86737142016-02-03 12:19:11 -0800891 return false;
892 }
893
John Stilesbd3ffa42020-07-30 20:24:57 -0400894 for (const SkString& image : images) {
scroggo86737142016-02-03 12:19:11 -0800895 push_codec_srcs(image);
mtklein709d2c32015-01-15 08:30:25 -0800896 }
scroggo86737142016-02-03 12:19:11 -0800897
msarett69deca82016-04-29 09:38:40 -0700898 SkTArray<SkString> colorImages;
899 if (!CollectImages(FLAGS_colorImages, &colorImages)) {
900 return false;
901 }
902
John Stilesbd3ffa42020-07-30 20:24:57 -0400903 for (const SkString& colorImage : colorImages) {
Mike Klein0d5d1422019-03-06 10:56:04 -0600904 push_src("colorImage", "decode_native", new ColorCodecSrc(colorImage, false));
905 push_src("colorImage", "decode_to_dst", new ColorCodecSrc(colorImage, true));
msarett69deca82016-04-29 09:38:40 -0700906 }
907
scroggo86737142016-02-03 12:19:11 -0800908 return true;
mtklein709d2c32015-01-15 08:30:25 -0800909}
910
kkinnunen3e980c32015-12-23 01:33:00 -0800911static void push_sink(const SkCommandLineConfig& config, Sink* s) {
Ben Wagner145dbcd2016-11-03 14:40:50 -0400912 std::unique_ptr<Sink> sink(s);
kkinnunen3e980c32015-12-23 01:33:00 -0800913
mtkleine0effd62015-07-29 06:37:28 -0700914 // Try a simple Src as a canary. If it fails, skip this sink.
mtklein748ca3b2015-01-15 10:56:12 -0800915 struct : public Src {
Robert Phillipsb87b39b2020-07-01 14:45:24 -0400916 Result draw(GrDirectContext*, SkCanvas* c) const override {
mtkleine0effd62015-07-29 06:37:28 -0700917 c->drawRect(SkRect::MakeWH(1,1), SkPaint());
Ben Wagnerea25fcf2020-02-12 11:18:46 -0500918 return Result::Ok();
mtkleine0effd62015-07-29 06:37:28 -0700919 }
mtklein36352bf2015-03-25 18:17:31 -0700920 SkISize size() const override { return SkISize::Make(16, 16); }
mtkleine0effd62015-07-29 06:37:28 -0700921 Name name() const override { return "justOneRect"; }
922 } justOneRect;
mtklein114c3cd2015-01-15 10:15:02 -0800923
mtklein748ca3b2015-01-15 10:56:12 -0800924 SkBitmap bitmap;
925 SkDynamicMemoryWStream stream;
mtkleinb9eb4ac2015-02-02 18:26:03 -0800926 SkString log;
Ben Wagnerea25fcf2020-02-12 11:18:46 -0500927 Result result = sink->draw(justOneRect, &bitmap, &stream, &log);
928 if (result.isFatal()) {
Robert Phillips45f37c32020-02-13 20:26:58 +0000929 info("Could not run %s: %s\n", config.getTag().c_str(), result.c_str());
mtklein05641a52015-04-21 10:49:13 -0700930 exit(1);
mtklein114c3cd2015-01-15 10:15:02 -0800931 }
932
John Stiles33e044f2020-06-19 18:34:51 -0400933 TaggedSink& ts = gSinks->push_back();
mtklein18300a32016-03-16 13:53:35 -0700934 ts.reset(sink.release());
kkinnunen3e980c32015-12-23 01:33:00 -0800935 ts.tag = config.getTag();
mtklein748ca3b2015-01-15 10:56:12 -0800936}
937
csmartdalton008b9d82017-02-22 12:00:42 -0700938static Sink* create_sink(const GrContextOptions& grCtxOptions, const SkCommandLineConfig* config) {
Brian Osmanc7ad40f2018-05-31 14:27:17 -0400939 if (FLAGS_gpu) {
kkinnunen3e980c32015-12-23 01:33:00 -0800940 if (const SkCommandLineConfigGpu* gpuConfig = config->asConfigGpu()) {
csmartdalton008b9d82017-02-22 12:00:42 -0700941 GrContextFactory testFactory(grCtxOptions);
Brian Osman3fdfe282019-09-09 13:46:52 -0400942 if (!testFactory.get(gpuConfig->getContextType(), gpuConfig->getContextOverrides())) {
mtkleinc41fd922016-03-08 09:01:39 -0800943 info("WARNING: can not create GPU context for config '%s'. "
944 "GM tests will be skipped.\n", gpuConfig->getTag().c_str());
kkinnunen3e980c32015-12-23 01:33:00 -0800945 return nullptr;
946 }
Robert Phillipsd6bf3742021-09-22 16:07:30 -0400947 if (gpuConfig->getUseGraphite()) {
948 return new GraphiteSink();
949 } else if (gpuConfig->getTestThreading()) {
Brian Salomon00a5eb82018-07-11 15:32:05 -0400950 SkASSERT(!gpuConfig->getTestPersistentCache());
Brian Osman3fdfe282019-09-09 13:46:52 -0400951 return new GPUThreadTestingSink(gpuConfig, grCtxOptions);
Brian Salomon00a5eb82018-07-11 15:32:05 -0400952 } else if (gpuConfig->getTestPersistentCache()) {
Brian Osman3fdfe282019-09-09 13:46:52 -0400953 return new GPUPersistentCacheTestingSink(gpuConfig, grCtxOptions);
Brian Osmaned58e002019-09-06 14:42:43 -0400954 } else if (gpuConfig->getTestPrecompile()) {
Brian Osman3fdfe282019-09-09 13:46:52 -0400955 return new GPUPrecompileTestingSink(gpuConfig, grCtxOptions);
Robert Phillips291f3402020-02-19 14:14:47 -0500956 } else if (gpuConfig->getUseDDLSink()) {
957 return new GPUDDLSink(gpuConfig, grCtxOptions);
Robert Phillips762cb4e2020-06-15 13:12:32 -0400958 } else if (gpuConfig->getOOPRish()) {
959 return new GPUOOPRSink(gpuConfig, grCtxOptions);
Brian Osmanf9810662017-08-30 10:02:10 -0400960 } else {
Brian Osman3fdfe282019-09-09 13:46:52 -0400961 return new GPUSink(gpuConfig, grCtxOptions);
Brian Osmanf9810662017-08-30 10:02:10 -0400962 }
kkinnunen3e980c32015-12-23 01:33:00 -0800963 }
964 }
Bryce Thomas95a7b762018-03-02 13:54:21 -0800965 if (const SkCommandLineConfigSvg* svgConfig = config->asConfigSvg()) {
966 int pageIndex = svgConfig->getPageIndex();
967 return new SVGSink(pageIndex);
968 }
kkinnunen3e980c32015-12-23 01:33:00 -0800969
Brian Salomon23356442018-11-30 15:33:19 -0500970#define SINK(t, sink, ...) if (config->getBackend().equals(t)) return new sink(__VA_ARGS__)
kkinnunen3e980c32015-12-23 01:33:00 -0800971
mtklein748ca3b2015-01-15 10:56:12 -0800972 if (FLAGS_cpu) {
Mike Kleinf7eb0542020-02-11 12:19:08 -0600973 SINK("g8", RasterSink, kGray_8_SkColorType);
974 SINK("565", RasterSink, kRGB_565_SkColorType);
975 SINK("4444", RasterSink, kARGB_4444_SkColorType);
976 SINK("8888", RasterSink, kN32_SkColorType);
977 SINK("rgba", RasterSink, kRGBA_8888_SkColorType);
978 SINK("bgra", RasterSink, kBGRA_8888_SkColorType);
979 SINK("rgbx", RasterSink, kRGB_888x_SkColorType);
980 SINK("1010102", RasterSink, kRGBA_1010102_SkColorType);
981 SINK("101010x", RasterSink, kRGB_101010x_SkColorType);
982 SINK("bgra1010102", RasterSink, kBGRA_1010102_SkColorType);
983 SINK("bgr101010x", RasterSink, kBGR_101010x_SkColorType);
Brian Osmanfcb50232021-08-12 10:51:48 -0400984 SINK("f16", RasterSink, kRGBA_F16_SkColorType);
985 SINK("f16norm", RasterSink, kRGBA_F16Norm_SkColorType);
986 SINK("f32", RasterSink, kRGBA_F32_SkColorType);
Brian Osman9f1e06a2021-08-10 14:39:18 -0400987 SINK("srgba", RasterSink, kSRGBA_8888_SkColorType);
Brian Osmanfcb50232021-08-12 10:51:48 -0400988
Mike Kleinf7eb0542020-02-11 12:19:08 -0600989 SINK("pdf", PDFSink, false, SK_ScalarDefaultRasterDPI);
990 SINK("skp", SKPSink);
991 SINK("svg", SVGSink);
992 SINK("null", NullSink);
993 SINK("xps", XPSSink);
994 SINK("pdfa", PDFSink, true, SK_ScalarDefaultRasterDPI);
995 SINK("pdf300", PDFSink, false, 300);
996 SINK("jsdebug", DebugSink);
mtklein748ca3b2015-01-15 10:56:12 -0800997 }
998#undef SINK
halcanary96fcdcc2015-08-27 07:41:13 -0700999 return nullptr;
mtklein114c3cd2015-01-15 10:15:02 -08001000}
1001
kkinnunen3e980c32015-12-23 01:33:00 -08001002static Sink* create_via(const SkString& tag, Sink* wrapped) {
Brian Salomon23356442018-11-30 15:33:19 -05001003#define VIA(t, via, ...) if (tag.equals(t)) return new via(__VA_ARGS__)
Mike Reedbae888e2017-02-18 16:50:45 -05001004#ifdef TEST_VIA_SVG
Mike Reedf67c4592017-02-17 17:06:11 -05001005 VIA("svg", ViaSVG, wrapped);
Mike Reedbae888e2017-02-18 16:50:45 -05001006#endif
halcanary96fcdcc2015-08-27 07:41:13 -07001007 VIA("serialize", ViaSerialization, wrapped);
mtklein4a34ecb2016-01-08 10:19:35 -08001008 VIA("pic", ViaPicture, wrapped);
John Stiles65ec1982021-07-20 12:53:54 -04001009 VIA("rtblend", ViaRuntimeBlend, wrapped);
Robert Phillips33f02ed2018-03-27 08:06:57 -04001010
mtkleind603b222015-02-17 11:13:33 -08001011 if (FLAGS_matrix.count() == 4) {
mtklein748ca3b2015-01-15 10:56:12 -08001012 SkMatrix m;
mtkleind603b222015-02-17 11:13:33 -08001013 m.reset();
1014 m.setScaleX((SkScalar)atof(FLAGS_matrix[0]));
1015 m.setSkewX ((SkScalar)atof(FLAGS_matrix[1]));
1016 m.setSkewY ((SkScalar)atof(FLAGS_matrix[2]));
1017 m.setScaleY((SkScalar)atof(FLAGS_matrix[3]));
1018 VIA("matrix", ViaMatrix, m, wrapped);
1019 VIA("upright", ViaUpright, m, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -08001020 }
tomhudson64de1e12015-03-05 08:01:07 -08001021
mtklein748ca3b2015-01-15 10:56:12 -08001022#undef VIA
Brian Osman54ef97c2021-08-11 17:06:42 -04001023
halcanary96fcdcc2015-08-27 07:41:13 -07001024 return nullptr;
mtklein114c3cd2015-01-15 10:15:02 -08001025}
1026
Ben Wagnerf28d4722017-08-11 17:33:22 -04001027static bool gather_sinks(const GrContextOptions& grCtxOptions, bool defaultConfigs) {
kkinnunen3e980c32015-12-23 01:33:00 -08001028 SkCommandLineConfigArray configs;
1029 ParseConfigs(FLAGS_config, &configs);
Jim Van Verth8a9a3712019-05-31 10:49:12 -04001030 AutoreleasePool pool;
kkinnunen3e980c32015-12-23 01:33:00 -08001031 for (int i = 0; i < configs.count(); i++) {
1032 const SkCommandLineConfig& config = *configs[i];
csmartdalton008b9d82017-02-22 12:00:42 -07001033 Sink* sink = create_sink(grCtxOptions, &config);
kkinnunen3e980c32015-12-23 01:33:00 -08001034 if (sink == nullptr) {
mtkleinc41fd922016-03-08 09:01:39 -08001035 info("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(),
1036 config.getTag().c_str());
kkinnunen3e980c32015-12-23 01:33:00 -08001037 continue;
1038 }
mtklein748ca3b2015-01-15 10:56:12 -08001039
Brian Osmanfcb50232021-08-12 10:51:48 -04001040 // The command line config already parsed out the via-style color space. Apply it here.
1041 sink->setColorSpace(config.refColorSpace());
1042
kkinnunen3e980c32015-12-23 01:33:00 -08001043 const SkTArray<SkString>& parts = config.getViaParts();
1044 for (int j = parts.count(); j-- > 0;) {
1045 const SkString& part = parts[j];
1046 Sink* next = create_via(part, sink);
halcanary96fcdcc2015-08-27 07:41:13 -07001047 if (next == nullptr) {
mtkleinc41fd922016-03-08 09:01:39 -08001048 info("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(),
1049 part.c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001050 delete sink;
halcanary96fcdcc2015-08-27 07:41:13 -07001051 sink = nullptr;
mtklein748ca3b2015-01-15 10:56:12 -08001052 break;
1053 }
1054 sink = next;
1055 }
1056 if (sink) {
1057 push_sink(config, sink);
mtklein114c3cd2015-01-15 10:15:02 -08001058 }
1059 }
brianosman05c987c2016-05-09 13:42:16 -07001060
1061 // If no configs were requested (just running tests, perhaps?), then we're okay.
Ben Wagnerf28d4722017-08-11 17:33:22 -04001062 if (configs.count() == 0 ||
1063 // If we're using the default configs, we're okay.
1064 defaultConfigs ||
Ben Wagner32fa5102017-08-10 21:25:55 -04001065 // Otherwise, make sure that all specified configs have become sinks.
John Stiles33e044f2020-06-19 18:34:51 -04001066 configs.count() == gSinks->count()) {
Ben Wagner32fa5102017-08-10 21:25:55 -04001067 return true;
1068 }
Ben Wagner32fa5102017-08-10 21:25:55 -04001069 return false;
mtklein114c3cd2015-01-15 10:15:02 -08001070}
mtklein709d2c32015-01-15 08:30:25 -08001071
mtkleina2ef6422015-01-15 13:44:22 -08001072static bool match(const char* needle, const char* haystack) {
Chris Daltonecf78ac2017-08-15 15:43:08 -06001073 if ('~' == needle[0]) {
1074 return !match(needle + 1, haystack);
1075 }
1076 if (0 == strcmp("_", needle)) {
1077 return true;
1078 }
1079 return nullptr != strstr(haystack, needle);
mtkleina2ef6422015-01-15 13:44:22 -08001080}
1081
Mike Kleina54d3802020-07-24 12:37:32 -05001082static bool should_skip(const char* sink, const char* src,
1083 const char* srcOptions, const char* name) {
1084 for (int i = 0; i < FLAGS_skip.count() - 3; i += 4) {
1085 if (match(FLAGS_skip[i+0], sink) &&
1086 match(FLAGS_skip[i+1], src) &&
1087 match(FLAGS_skip[i+2], srcOptions) &&
1088 match(FLAGS_skip[i+3], name)) {
mtklein3eed7dd2016-02-24 19:07:07 -08001089 return true;
mtkleina2ef6422015-01-15 13:44:22 -08001090 }
1091 }
mtklein3eed7dd2016-02-24 19:07:07 -08001092 return false;
mtkleina2ef6422015-01-15 13:44:22 -08001093}
1094
mtkleincd50bca2016-01-05 06:20:20 -08001095// Even when a Task Sink reports to be non-threadsafe (e.g. GPU), we know things like
1096// .png encoding are definitely thread safe. This lets us offload that work to CPU threads.
John Stiles33e044f2020-06-19 18:34:51 -04001097static SkTaskGroup* gDefinitelyThreadSafeWork = new SkTaskGroup;
mtkleincd50bca2016-01-05 06:20:20 -08001098
mtklein748ca3b2015-01-15 10:56:12 -08001099// The finest-grained unit of work we can run: draw a single Src into a single Sink,
1100// report any errors, and perhaps write out the output: a .png of the bitmap, or a raw stream.
1101struct Task {
mtkleine0effd62015-07-29 06:37:28 -07001102 Task(const TaggedSrc& src, const TaggedSink& sink) : src(src), sink(sink) {}
1103 const TaggedSrc& src;
1104 const TaggedSink& sink;
mtklein748ca3b2015-01-15 10:56:12 -08001105
mtklein21eaf3b2016-02-08 12:39:59 -08001106 static void Run(const Task& task) {
Jim Van Verth8a9a3712019-05-31 10:49:12 -04001107 AutoreleasePool pool;
mtklein21eaf3b2016-02-08 12:39:59 -08001108 SkString name = task.src->name();
mtkleine0effd62015-07-29 06:37:28 -07001109
mtkleinb9eb4ac2015-02-02 18:26:03 -08001110 SkString log;
mtklein3eed7dd2016-02-24 19:07:07 -08001111 if (!FLAGS_dryRun) {
mtklein748ca3b2015-01-15 10:56:12 -08001112 SkBitmap bitmap;
1113 SkDynamicMemoryWStream stream;
mtklein3eed7dd2016-02-24 19:07:07 -08001114 start(task.sink.tag.c_str(), task.src.tag.c_str(),
1115 task.src.options.c_str(), name.c_str());
Ben Wagnerea25fcf2020-02-12 11:18:46 -05001116 Result result = task.sink->draw(*task.src, &bitmap, &stream, &log);
mtkleinb3b13b72016-03-07 13:20:52 -08001117 if (!log.isEmpty()) {
mtkleinc41fd922016-03-08 09:01:39 -08001118 info("%s %s %s %s:\n%s\n", task.sink.tag.c_str()
1119 , task.src.tag.c_str()
1120 , task.src.options.c_str()
1121 , name.c_str()
1122 , log.c_str());
mtkleinb3b13b72016-03-07 13:20:52 -08001123 }
Ben Wagnerea25fcf2020-02-12 11:18:46 -05001124 if (result.isSkip()) {
1125 done(task.sink.tag.c_str(), task.src.tag.c_str(),
1126 task.src.options.c_str(), name.c_str());
1127 return;
1128 }
1129 if (result.isFatal()) {
1130 fail(SkStringPrintf("%s %s %s %s: %s",
1131 task.sink.tag.c_str(),
1132 task.src.tag.c_str(),
1133 task.src.options.c_str(),
1134 name.c_str(),
1135 result.c_str()));
mtklein748ca3b2015-01-15 10:56:12 -08001136 }
mtklein62bd1a62015-01-27 14:46:26 -08001137
Tyler Denniston45f94f82020-02-04 16:09:08 -05001138 // Run verifiers if specified
1139 if (FLAGS_runVerifiers) {
1140 RunGMVerifiers(task, bitmap);
1141 }
1142
mtkleincd50bca2016-01-05 06:20:20 -08001143 // We're likely switching threads here, so we must capture by value, [=] or [foo,bar].
Hal Canary0b833192017-03-14 14:35:02 -04001144 SkStreamAsset* data = stream.detachAsStream().release();
John Stiles33e044f2020-06-19 18:34:51 -04001145 gDefinitelyThreadSafeWork->add([task,name,bitmap,data]{
Ben Wagner145dbcd2016-11-03 14:40:50 -04001146 std::unique_ptr<SkStreamAsset> ownedData(data);
mtkleincd50bca2016-01-05 06:20:20 -08001147
Mike Kleine1271702019-03-07 11:46:59 -06001148 std::unique_ptr<HashAndEncode> hashAndEncode;
1149
mtkleincd50bca2016-01-05 06:20:20 -08001150 SkString md5;
Brian Osman57796b32019-01-25 18:02:59 +00001151 if (!FLAGS_writePath.isEmpty() || !FLAGS_readPath.isEmpty()) {
mtkleincd50bca2016-01-05 06:20:20 -08001152 SkMD5 hash;
1153 if (data->getLength()) {
1154 hash.writeStream(data, data->getLength());
1155 data->rewind();
mtklein38408462015-07-08 07:25:27 -07001156 } else {
John Stilesfbd050b2020-08-03 13:21:46 -04001157 hashAndEncode = std::make_unique<HashAndEncode>(bitmap);
Mike Klein989f5bf2020-10-07 10:11:50 -05001158 hashAndEncode->feedHash(&hash);
mtkleincd50bca2016-01-05 06:20:20 -08001159 }
Hal Canary0f2f5222019-04-03 10:13:45 -04001160 SkMD5::Digest digest = hash.finish();
mtkleincd50bca2016-01-05 06:20:20 -08001161 for (int i = 0; i < 16; i++) {
1162 md5.appendf("%02x", digest.data[i]);
mtklein38408462015-07-08 07:25:27 -07001163 }
mtklein62bd1a62015-01-27 14:46:26 -08001164 }
mtklein62bd1a62015-01-27 14:46:26 -08001165
Brian Osman57796b32019-01-25 18:02:59 +00001166 if (!FLAGS_readPath.isEmpty() &&
John Stiles33e044f2020-06-19 18:34:51 -04001167 !gGold->contains(Gold(task.sink.tag, task.src.tag,
1168 task.src.options, name, md5))) {
Brian Osman57796b32019-01-25 18:02:59 +00001169 fail(SkStringPrintf("%s not found for %s %s %s %s in %s",
1170 md5.c_str(),
1171 task.sink.tag.c_str(),
1172 task.src.tag.c_str(),
1173 task.src.options.c_str(),
1174 name.c_str(),
1175 FLAGS_readPath[0]));
1176 }
1177
Mike Klein055f5352020-01-30 11:11:12 -06001178 // Tests sometimes use a nullptr ext to indicate no image should be uploaded.
1179 const char* ext = task.sink->fileExtension();
1180 if (ext && !FLAGS_writePath.isEmpty()) {
1181 #if defined(SK_BUILD_FOR_MAC)
1182 if (FLAGS_rasterize_pdf && SkString("pdf").equals(ext)) {
1183 SkASSERT(data->getLength() > 0);
1184
1185 sk_sp<SkData> blob = SkData::MakeFromStream(data, data->getLength());
1186
1187 SkUniqueCFRef<CGDataProviderRef> provider{
1188 CGDataProviderCreateWithData(nullptr,
1189 blob->data(),
1190 blob->size(),
1191 nullptr)};
1192
1193 SkUniqueCFRef<CGPDFDocumentRef> pdf{
1194 CGPDFDocumentCreateWithProvider(provider.get())};
1195
1196 CGPDFPageRef page = CGPDFDocumentGetPage(pdf.get(), 1);
1197
1198 CGRect bounds = CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
1199 const int w = (int)CGRectGetWidth (bounds),
1200 h = (int)CGRectGetHeight(bounds);
1201
1202 SkBitmap rasterized;
John Stiles637838d2020-06-12 12:10:54 -04001203 rasterized.allocPixels(SkImageInfo::Make(
1204 w, h, kRGBA_8888_SkColorType, kPremul_SkAlphaType));
Mike Klein055f5352020-01-30 11:11:12 -06001205 rasterized.eraseColor(SK_ColorWHITE);
1206
John Stiles637838d2020-06-12 12:10:54 -04001207 SkUniqueCFRef<CGColorSpaceRef> cs{CGColorSpaceCreateDeviceRGB()};
1208 CGBitmapInfo info = kCGBitmapByteOrder32Big |
1209 (CGBitmapInfo)kCGImageAlphaPremultipliedLast;
Mike Klein055f5352020-01-30 11:11:12 -06001210
John Stiles637838d2020-06-12 12:10:54 -04001211 SkUniqueCFRef<CGContextRef> ctx{CGBitmapContextCreate(
1212 rasterized.getPixels(), w,h,8, rasterized.rowBytes(), cs.get(), info)};
Mike Klein055f5352020-01-30 11:11:12 -06001213 CGContextDrawPDFPage(ctx.get(), page);
1214
Mike Klein989f5bf2020-10-07 10:11:50 -05001215 // Skip calling hashAndEncode->feedHash(SkMD5*)... we want the .pdf's hash.
John Stilesfbd050b2020-08-03 13:21:46 -04001216 hashAndEncode = std::make_unique<HashAndEncode>(rasterized);
Mike Klein055f5352020-01-30 11:11:12 -06001217 WriteToDisk(task, md5, "png", nullptr,0, &rasterized, hashAndEncode.get());
1218 } else
1219 #endif
1220 if (data->getLength()) {
1221 WriteToDisk(task, md5, ext, data, data->getLength(), nullptr, nullptr);
1222 SkASSERT(bitmap.drawsNothing());
1223 } else if (!bitmap.drawsNothing()) {
1224 WriteToDisk(task, md5, ext, nullptr, 0, &bitmap, hashAndEncode.get());
mtkleincd50bca2016-01-05 06:20:20 -08001225 }
1226 }
Brian Osman582f6862019-03-11 11:20:55 -04001227
1228 SkPixmap pm;
1229 if (FLAGS_checkF16 && bitmap.colorType() == kRGBA_F16Norm_SkColorType &&
1230 bitmap.peekPixels(&pm)) {
1231 bool unclamped = false;
1232 for (int y = 0; y < pm.height() && !unclamped; ++y)
1233 for (int x = 0; x < pm.width() && !unclamped; ++x) {
1234 Sk4f rgba = SkHalfToFloat_finite_ftz(*pm.addr64(x, y));
1235 float a = rgba[3];
1236 if (a > 1.0f || (rgba < 0.0f).anyTrue() || (rgba > a).anyTrue()) {
Brian Osmanb73e6072019-03-15 10:02:16 -04001237 SkDebugf("[%s] F16Norm pixel [%d, %d] unclamped: (%g, %g, %g, %g)\n",
1238 name.c_str(), x, y, rgba[0], rgba[1], rgba[2], rgba[3]);
Brian Osman582f6862019-03-11 11:20:55 -04001239 unclamped = true;
1240 }
1241 }
1242 }
mtkleincd50bca2016-01-05 06:20:20 -08001243 });
mtklein748ca3b2015-01-15 10:56:12 -08001244 }
mtklein3eed7dd2016-02-24 19:07:07 -08001245 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 -08001246 }
1247
Mike Klein66f09a72019-02-12 13:03:54 -05001248 static SkString identify_gamut(SkColorSpace* cs) {
1249 if (!cs) {
1250 return SkString("untagged");
1251 }
1252
1253 skcms_Matrix3x3 gamut;
1254 if (cs->toXYZD50(&gamut)) {
1255 auto eq = [](skcms_Matrix3x3 x, skcms_Matrix3x3 y) {
1256 for (int i = 0; i < 3; i++)
1257 for (int j = 0; j < 3; j++) {
1258 if (x.vals[i][j] != y.vals[i][j]) { return false; }
1259 }
1260 return true;
1261 };
1262
Mike Kleinb147ace2020-01-16 11:11:06 -06001263 if (eq(gamut, SkNamedGamut::kSRGB )) { return SkString("sRGB"); }
1264 if (eq(gamut, SkNamedGamut::kAdobeRGB )) { return SkString("Adobe"); }
1265 if (eq(gamut, SkNamedGamut::kDisplayP3)) { return SkString("P3"); }
1266 if (eq(gamut, SkNamedGamut::kRec2020 )) { return SkString("2020"); }
1267 if (eq(gamut, SkNamedGamut::kXYZ )) { return SkString("XYZ"); }
1268 if (eq(gamut, gNarrow_toXYZD50 )) { return SkString("narrow"); }
Mike Klein66f09a72019-02-12 13:03:54 -05001269 return SkString("other");
1270 }
1271 return SkString("non-XYZ");
1272 }
1273
1274 static SkString identify_transfer_fn(SkColorSpace* cs) {
1275 if (!cs) {
1276 return SkString("untagged");
1277 }
1278
Brian Osman11e6aa82019-10-16 13:58:42 -04001279 auto eq = [](skcms_TransferFunction x, skcms_TransferFunction y) {
1280 return x.g == y.g
1281 && x.a == y.a
1282 && x.b == y.b
1283 && x.c == y.c
1284 && x.d == y.d
1285 && x.e == y.e
1286 && x.f == y.f;
1287 };
Mike Klein66f09a72019-02-12 13:03:54 -05001288
Brian Osman11e6aa82019-10-16 13:58:42 -04001289 skcms_TransferFunction tf;
Brian Osman09ee1122019-11-05 11:41:16 -05001290 cs->transferFn(&tf);
Brian Osman11e6aa82019-10-16 13:58:42 -04001291 switch (classify_transfer_fn(tf)) {
1292 case sRGBish_TF:
1293 if (tf.a == 1 && tf.b == 0 && tf.c == 0 && tf.d == 0 && tf.e == 0 && tf.f == 0) {
1294 return SkStringPrintf("gamma %.3g", tf.g);
1295 }
1296 if (eq(tf, SkNamedTransferFn::kSRGB)) { return SkString("sRGB"); }
1297 if (eq(tf, SkNamedTransferFn::kRec2020)) { return SkString("2020"); }
1298 return SkStringPrintf("%.3g %.3g %.3g %.3g %.3g %.3g %.3g",
1299 tf.g, tf.a, tf.b, tf.c, tf.d, tf.e, tf.f);
1300
1301 case PQish_TF:
1302 if (eq(tf, SkNamedTransferFn::kPQ)) { return SkString("PQ"); }
1303 return SkStringPrintf("PQish %.3g %.3g %.3g %.3g %.3g %.3g",
1304 tf.a, tf.b, tf.c, tf.d, tf.e, tf.f);
1305
1306 case HLGish_TF:
1307 if (eq(tf, SkNamedTransferFn::kHLG)) { return SkString("HLG"); }
Mike Klein627c0022021-01-07 10:50:01 -06001308 return SkStringPrintf("HLGish %.3g %.3g %.3g %.3g %.3g (%.3g)",
1309 tf.a, tf.b, tf.c, tf.d, tf.e, tf.f+1);
Brian Osman11e6aa82019-10-16 13:58:42 -04001310
1311 case HLGinvish_TF: break;
1312 case Bad_TF: break;
Mike Klein66f09a72019-02-12 13:03:54 -05001313 }
1314 return SkString("non-numeric");
1315 }
1316
mtklein748ca3b2015-01-15 10:56:12 -08001317 static void WriteToDisk(const Task& task,
mtklein62bd1a62015-01-27 14:46:26 -08001318 SkString md5,
1319 const char* ext,
mtklein748ca3b2015-01-15 10:56:12 -08001320 SkStream* data, size_t len,
Mike Kleine1271702019-03-07 11:46:59 -06001321 const SkBitmap* bitmap,
1322 const HashAndEncode* hashAndEncode) {
mtklein409d4702016-02-29 07:38:01 -08001323
mtklein748ca3b2015-01-15 10:56:12 -08001324 JsonWriter::BitmapResult result;
djsollen54416de2015-04-03 07:24:48 -07001325 result.name = task.src->name();
mtklein3eed7dd2016-02-24 19:07:07 -08001326 result.config = task.sink.tag;
djsollen54416de2015-04-03 07:24:48 -07001327 result.sourceType = task.src.tag;
1328 result.sourceOptions = task.src.options;
1329 result.ext = ext;
1330 result.md5 = md5;
Mike Klein0abbaca2019-03-06 09:57:49 -06001331 if (bitmap) {
Mike Klein98168782019-04-09 13:45:02 -05001332 result.gamut = identify_gamut (bitmap->colorSpace());
1333 result.transferFn = identify_transfer_fn (bitmap->colorSpace());
1334 result.colorType = ToolUtils::colortype_name (bitmap->colorType());
1335 result.alphaType = ToolUtils::alphatype_name (bitmap->alphaType());
1336 result.colorDepth = ToolUtils::colortype_depth(bitmap->colorType());
Mike Klein0abbaca2019-03-06 09:57:49 -06001337 }
mtklein748ca3b2015-01-15 10:56:12 -08001338 JsonWriter::AddBitmapResult(result);
1339
mtkleinb0531a72015-04-07 13:38:48 -07001340 // If an MD5 is uninteresting, we want it noted in the JSON file,
1341 // but don't want to dump it out as a .png (or whatever ext is).
John Stiles33e044f2020-06-19 18:34:51 -04001342 if (gUninterestingHashes->contains(md5)) {
mtkleinb0531a72015-04-07 13:38:48 -07001343 return;
1344 }
1345
mtklein748ca3b2015-01-15 10:56:12 -08001346 const char* dir = FLAGS_writePath[0];
Mike Kleinc6142d82019-03-25 10:54:59 -05001347 SkString resources = GetResourcePath();
mtklein748ca3b2015-01-15 10:56:12 -08001348 if (0 == strcmp(dir, "@")) { // Needed for iOS.
Mike Kleinc6142d82019-03-25 10:54:59 -05001349 dir = resources.c_str();
mtklein748ca3b2015-01-15 10:56:12 -08001350 }
1351 sk_mkdir(dir);
1352
1353 SkString path;
1354 if (FLAGS_nameByHash) {
1355 path = SkOSPath::Join(dir, result.md5.c_str());
1356 path.append(".");
1357 path.append(ext);
1358 if (sk_exists(path.c_str())) {
1359 return; // Content-addressed. If it exists already, we're done.
1360 }
1361 } else {
kkinnunen3e980c32015-12-23 01:33:00 -08001362 path = SkOSPath::Join(dir, task.sink.tag.c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001363 sk_mkdir(path.c_str());
msarett9e707a02015-09-01 14:57:57 -07001364 path = SkOSPath::Join(path.c_str(), task.src.tag.c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001365 sk_mkdir(path.c_str());
John Stilesc1c3c6d2020-08-15 23:22:53 -04001366 if (0 != strcmp(task.src.options.c_str(), "")) {
msarett9e707a02015-09-01 14:57:57 -07001367 path = SkOSPath::Join(path.c_str(), task.src.options.c_str());
djsollen54416de2015-04-03 07:24:48 -07001368 sk_mkdir(path.c_str());
1369 }
mtklein748ca3b2015-01-15 10:56:12 -08001370 path = SkOSPath::Join(path.c_str(), task.src->name().c_str());
1371 path.append(".");
1372 path.append(ext);
1373 }
1374
Mike Klein989f5bf2020-10-07 10:11:50 -05001375 SkFILEWStream file(path.c_str());
1376 if (!file.isValid()) {
1377 fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str()));
1378 return;
1379 }
mtklein748ca3b2015-01-15 10:56:12 -08001380 if (bitmap) {
Mike Kleine1271702019-03-07 11:46:59 -06001381 SkASSERT(hashAndEncode);
Mike Klein989f5bf2020-10-07 10:11:50 -05001382 if (!hashAndEncode->encodePNG(&file,
1383 result.md5.c_str(),
1384 FLAGS_key,
1385 FLAGS_properties)) {
mtklein748ca3b2015-01-15 10:56:12 -08001386 fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str()));
1387 return;
1388 }
1389 } else {
1390 if (!file.writeStream(data, len)) {
1391 fail(SkStringPrintf("Can't write to %s.\n", path.c_str()));
1392 return;
1393 }
1394 }
1395 }
Tyler Denniston45f94f82020-02-04 16:09:08 -05001396
1397 static void RunGMVerifiers(const Task& task, const SkBitmap& actualBitmap) {
1398 const SkString name = task.src->name();
1399 auto verifierList = task.src->getVerifiers();
1400 if (verifierList == nullptr) {
1401 return;
1402 }
1403
1404 skiagm::verifiers::VerifierResult
1405 res = verifierList->verifyAll(task.sink->colorInfo(), actualBitmap);
1406 if (!res.ok()) {
1407 fail(
1408 SkStringPrintf(
1409 "%s %s %s %s: verifier failed: %s", task.sink.tag.c_str(), task.src.tag.c_str(),
1410 task.src.options.c_str(), name.c_str(), res.message().c_str()));
1411 }
1412 }
mtklein748ca3b2015-01-15 10:56:12 -08001413};
1414
mtklein748ca3b2015-01-15 10:56:12 -08001415/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1416
1417// Unit tests don't fit so well into the Src/Sink model, so we give them special treatment.
1418
John Stiles33e044f2020-06-19 18:34:51 -04001419static SkTDArray<skiatest::Test>* gParallelTests = new SkTDArray<skiatest::Test>;
1420static SkTDArray<skiatest::Test>* gSerialTests = new SkTDArray<skiatest::Test>;
mtklein748ca3b2015-01-15 10:56:12 -08001421
1422static void gather_tests() {
mtklein6c5fed22015-01-20 13:47:23 -08001423 if (!FLAGS_src.contains("tests")) {
mtklein748ca3b2015-01-15 10:56:12 -08001424 return;
1425 }
Hal Canary972eba32018-07-30 17:07:07 -04001426 for (const skiatest::Test& test : skiatest::TestRegistry::Range()) {
mtklein6393c062015-04-27 08:45:01 -07001427 if (!in_shard()) {
1428 continue;
1429 }
Mike Klein88544fb2019-03-20 10:50:33 -05001430 if (CommandLineFlags::ShouldSkip(FLAGS_match, test.name)) {
mtklein748ca3b2015-01-15 10:56:12 -08001431 continue;
1432 }
Brian Osmanc7ad40f2018-05-31 14:27:17 -04001433 if (test.needsGpu && FLAGS_gpu) {
John Stiles33e044f2020-06-19 18:34:51 -04001434 gSerialTests->push_back(test);
halcanary87f3ba42015-01-20 09:30:20 -08001435 } else if (!test.needsGpu && FLAGS_cpu) {
John Stiles33e044f2020-06-19 18:34:51 -04001436 gParallelTests->push_back(test);
mtklein82d28432015-01-15 12:46:02 -08001437 }
mtklein748ca3b2015-01-15 10:56:12 -08001438 }
1439}
1440
csmartdalton008b9d82017-02-22 12:00:42 -07001441static void run_test(skiatest::Test test, const GrContextOptions& grCtxOptions) {
halcanary87f3ba42015-01-20 09:30:20 -08001442 struct : public skiatest::Reporter {
mtklein36352bf2015-03-25 18:17:31 -07001443 void reportFailed(const skiatest::Failure& failure) override {
halcanary87f3ba42015-01-20 09:30:20 -08001444 fail(failure.toString());
halcanary87f3ba42015-01-20 09:30:20 -08001445 }
mtklein36352bf2015-03-25 18:17:31 -07001446 bool allowExtendedTest() const override {
halcanary87f3ba42015-01-20 09:30:20 -08001447 return FLAGS_pathOpsExtended;
1448 }
mtklein36352bf2015-03-25 18:17:31 -07001449 bool verbose() const override { return FLAGS_veryVerbose; }
halcanary87f3ba42015-01-20 09:30:20 -08001450 } reporter;
djsollen824996a2015-06-12 12:06:22 -07001451
Mike Kleina54d3802020-07-24 12:37:32 -05001452 if (!FLAGS_dryRun && !should_skip("_", "tests", "_", test.name)) {
Jim Van Verth8a9a3712019-05-31 10:49:12 -04001453 AutoreleasePool pool;
Robert Phillipsec325342017-10-30 18:02:48 +00001454 GrContextOptions options = grCtxOptions;
1455 test.modifyGrContextOptions(&options);
1456
Brian Osmancdf31742019-03-13 10:13:46 -04001457 skiatest::ReporterContext ctx(&reporter, SkString(test.name));
mtklein21eaf3b2016-02-08 12:39:59 -08001458 start("unit", "test", "", test.name);
Brian Salomondcfca432017-11-15 15:48:03 -05001459 test.run(&reporter, options);
mtklein748ca3b2015-01-15 10:56:12 -08001460 }
mtklein3eed7dd2016-02-24 19:07:07 -08001461 done("unit", "test", "", test.name);
mtklein748ca3b2015-01-15 10:56:12 -08001462}
1463
1464/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1465
Mike Kleinbe28ee22017-02-06 12:46:20 -05001466int main(int argc, char** argv) {
Brian Osman1c1208e2019-06-24 13:36:05 -04001467#if defined(__MSVC_RUNTIME_CHECKS)
1468 _RTC_SetErrorFunc(RuntimeCheckErrorFunc);
1469#endif
Dongwon Kang0c7861f2018-02-16 10:55:21 -08001470#if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && defined(SK_HAS_HEIF_LIBRARY)
1471 android::ProcessState::self()->startThreadPool();
1472#endif
Mike Klein88544fb2019-03-20 10:50:33 -05001473 CommandLineFlags::Parse(argc, argv);
Brian Osman53136aa2017-07-20 15:43:35 -04001474
Brian Osmanbc8150f2017-07-24 11:38:01 -04001475 initializeEventTracingForTools();
Brian Osman53136aa2017-07-20 15:43:35 -04001476
Mike Klein6613cc52017-12-19 09:09:33 -05001477#if !defined(SK_BUILD_FOR_GOOGLE3) && defined(SK_BUILD_FOR_IOS)
Mike Kleinadacaef2017-02-06 09:26:14 -05001478 cd_Documents();
1479#endif
bsalomon71de3532016-04-26 14:27:21 -07001480 setbuf(stdout, nullptr);
mtklein246ba3a2016-02-23 10:39:36 -08001481 setup_crash_handler();
mtkleinafae30a2016-02-24 12:28:32 -08001482
Mike Klein19cc0f62019-03-22 15:30:07 -05001483 ToolUtils::SetDefaultFontMgr();
Mike Klein03fa5d42019-03-22 11:39:09 -05001484 SetAnalyticAAFromCommonFlags();
liyuqian38911a72016-10-04 11:23:22 -07001485
Mike Klein9ae06632020-01-28 12:41:02 -06001486 gSkForceRasterPipelineBlitter = FLAGS_forceRasterPipeline;
1487 gUseSkVMBlitter = FLAGS_skvm;
Mike Klein813e8cc2020-08-05 09:33:38 -05001488 gSkVMAllowJIT = FLAGS_jit;
Yuqian Li550148b2017-01-13 10:13:13 -05001489
Mike Kleine9f187b2017-06-26 13:23:12 -04001490 // The bots like having a verbose.log to upload, so always touch the file even if --verbose.
1491 if (!FLAGS_writePath.isEmpty()) {
mtklein51c8cfc2016-03-11 12:59:09 -08001492 sk_mkdir(FLAGS_writePath[0]);
mtkleina1ce2162016-07-22 12:23:46 -07001493 gVLog = fopen(SkOSPath::Join(FLAGS_writePath[0], "verbose.log").c_str(), "w");
mtkleinc41fd922016-03-08 09:01:39 -08001494 }
Mike Kleine9f187b2017-06-26 13:23:12 -04001495 if (FLAGS_verbose) {
1496 gVLog = stderr;
1497 }
mtkleinc41fd922016-03-08 09:01:39 -08001498
csmartdalton008b9d82017-02-22 12:00:42 -07001499 GrContextOptions grCtxOptions;
Chris Dalton040238b2017-12-18 14:22:34 -07001500 SetCtxOptionsFromCommonFlags(&grCtxOptions);
csmartdalton008b9d82017-02-22 12:00:42 -07001501
Mike Kleinc6142d82019-03-25 10:54:59 -05001502 dump_json(); // It's handy for the bots to assume this is ~never missing.
1503
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +00001504 SkAutoGraphics ag;
mtklein406654b2014-09-03 15:34:37 -07001505 SkTaskGroup::Enabler enabled(FLAGS_threads);
commit-bot@chromium.orga65e2fd2014-05-30 17:23:31 +00001506
Mike Reed0933bc92017-12-09 01:27:41 +00001507 if (nullptr == GetResourceAsData("images/color_wheel.png")) {
1508 info("Some resources are missing. Do you need to set --resourcePath?\n");
halcanary7d571242016-02-24 17:59:16 -08001509 }
Brian Osman57796b32019-01-25 18:02:59 +00001510 gather_gold();
borenet09ed4802015-04-03 14:15:33 -07001511 gather_uninteresting_hashes();
mtklein62bd1a62015-01-27 14:46:26 -08001512
scroggo86737142016-02-03 12:19:11 -08001513 if (!gather_srcs()) {
1514 return 1;
1515 }
Ben Wagnerf28d4722017-08-11 17:33:22 -04001516 // TODO(dogben): This is a bit ugly. Find a cleaner way to do this.
1517 bool defaultConfigs = true;
1518 for (int i = 0; i < argc; i++) {
John Stiles33e044f2020-06-19 18:34:51 -04001519 static constexpr char kConfigArg[] = "--config";
Ben Wagnerf28d4722017-08-11 17:33:22 -04001520 if (strcmp(argv[i], kConfigArg) == 0) {
1521 defaultConfigs = false;
1522 break;
1523 }
1524 }
1525 if (!gather_sinks(grCtxOptions, defaultConfigs)) {
brianosman05c987c2016-05-09 13:42:16 -07001526 return 1;
1527 }
mtklein748ca3b2015-01-15 10:56:12 -08001528 gather_tests();
John Stiles33e044f2020-06-19 18:34:51 -04001529 gPending = gSrcs->count() * gSinks->count() + gParallelTests->count() + gSerialTests->count();
Brian Osmand0677bc2017-08-03 12:13:47 -04001530 info("%d srcs * %d sinks + %d tests == %d tasks\n",
John Stiles33e044f2020-06-19 18:34:51 -04001531 gSrcs->count(), gSinks->count(), gParallelTests->count() + gSerialTests->count(),
1532 gPending);
mtklein748ca3b2015-01-15 10:56:12 -08001533
mtklein21eaf3b2016-02-08 12:39:59 -08001534 // Kick off as much parallel work as we can, making note of any serial work we'll need to do.
1535 SkTaskGroup parallel;
1536 SkTArray<Task> serial;
1537
John Stiles33e044f2020-06-19 18:34:51 -04001538 for (TaggedSink& sink : *gSinks) {
1539 for (TaggedSrc& src : *gSrcs) {
1540 if (src->veto(sink->flags()) ||
Mike Kleina54d3802020-07-24 12:37:32 -05001541 should_skip(sink.tag.c_str(), src.tag.c_str(),
1542 src.options.c_str(), src->name().c_str())) {
John Stiles33e044f2020-06-19 18:34:51 -04001543 SkAutoSpinlock lock(*gMutex);
1544 gPending--;
1545 continue;
1546 }
mtklein3eed7dd2016-02-24 19:07:07 -08001547
John Stiles33e044f2020-06-19 18:34:51 -04001548 Task task(src, sink);
1549 if (src->serial() || sink->serial()) {
1550 serial.push_back(task);
1551 } else {
1552 parallel.add([task] { Task::Run(task); });
1553 }
mtklein748ca3b2015-01-15 10:56:12 -08001554 }
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001555 }
John Stiles33e044f2020-06-19 18:34:51 -04001556 for (skiatest::Test& test : *gParallelTests) {
csmartdalton008b9d82017-02-22 12:00:42 -07001557 parallel.add([test, grCtxOptions] { run_test(test, grCtxOptions); });
mtklein55e88b22015-01-21 15:50:13 -08001558 }
mtklein21eaf3b2016-02-08 12:39:59 -08001559
1560 // With the parallel work running, run serial tasks and tests here on main thread.
John Stiles33e044f2020-06-19 18:34:51 -04001561 for (Task& task : serial) { Task::Run(task); }
1562 for (skiatest::Test& test : *gSerialTests) { run_test(test, grCtxOptions); }
mtklein21eaf3b2016-02-08 12:39:59 -08001563
1564 // Wait for any remaining parallel work to complete (including any spun off of serial tasks).
1565 parallel.wait();
John Stiles33e044f2020-06-19 18:34:51 -04001566 gDefinitelyThreadSafeWork->wait();
mtkleincd50bca2016-01-05 06:20:20 -08001567
Ben Wagner83c6b962018-07-10 19:40:15 -04001568 // At this point we're back in single-threaded land.
1569
mtkleinda884c42016-02-24 18:00:23 -08001570 // We'd better have run everything.
1571 SkASSERT(gPending == 0);
mtkleine027f172016-02-26 15:53:06 -08001572 // Make sure we've flushed all our results to disk.
Mike Kleinc6142d82019-03-25 10:54:59 -05001573 dump_json();
mtkleinda884c42016-02-24 18:00:23 -08001574
John Stiles33e044f2020-06-19 18:34:51 -04001575 if (!gFailures->empty()) {
mtkleinc41fd922016-03-08 09:01:39 -08001576 info("Failures:\n");
John Stiles33e044f2020-06-19 18:34:51 -04001577 for (const SkString& fail : *gFailures) {
1578 info("\t%s\n", fail.c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001579 }
John Stiles33e044f2020-06-19 18:34:51 -04001580 info("%d failures\n", gFailures->count());
mtklein748ca3b2015-01-15 10:56:12 -08001581 return 1;
mtklein114c3cd2015-01-15 10:15:02 -08001582 }
mtkleinafae30a2016-02-24 12:28:32 -08001583
Herb Derby5a523fe2017-01-26 16:48:28 -05001584 SkGraphics::PurgeAllCaches();
mtkleinc41fd922016-03-08 09:01:39 -08001585 info("Finished!\n");
Brian Osman53136aa2017-07-20 15:43:35 -04001586
mtklein748ca3b2015-01-15 10:56:12 -08001587 return 0;
mtklein@google.comd36522d2013-10-16 13:02:15 +00001588}