blob: b2bba029ba2ab5f4cdddbacdb2b75a3d5d7f6731 [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
mtklein748ca3b2015-01-15 10:56:12 -08008#include "DMJsonWriter.h"
9#include "DMSrcSink.h"
mtklein748ca3b2015-01-15 10:56:12 -080010#include "ProcStats.h"
halcanary7d571242016-02-24 17:59:16 -080011#include "Resources.h"
mtklein748ca3b2015-01-15 10:56:12 -080012#include "SkBBHFactory.h"
mtklein62bd1a62015-01-27 14:46:26 -080013#include "SkChecksum.h"
Brian Osman53136aa2017-07-20 15:43:35 -040014#include "SkChromeTracingTracer.h"
scroggocc2feb12015-08-14 08:32:46 -070015#include "SkCodec.h"
mtklein27c3fdd2016-02-26 14:43:21 -080016#include "SkColorPriv.h"
msarett888dc162016-05-23 10:21:17 -070017#include "SkColorSpace.h"
Mike Klein919cc452017-03-18 15:36:52 +000018#include "SkColorSpacePriv.h"
caryclark17f0b6d2014-07-22 10:15:34 -070019#include "SkCommonFlags.h"
kkinnunen3e980c32015-12-23 01:33:00 -080020#include "SkCommonFlagsConfig.h"
Chris Dalton040238b2017-12-18 14:22:34 -070021#include "SkCommonFlagsGpu.h"
brianosman3c579dc2016-04-19 09:18:11 -070022#include "SkData.h"
Brian Salomondcbb9d92017-07-19 10:53:20 -040023#include "SkDebugfTracer.h"
Hal Canaryd7b38452017-12-11 17:46:26 -050024#include "SkDocument.h"
Brian Osman53136aa2017-07-20 15:43:35 -040025#include "SkEventTracingPriv.h"
caryclark83ca6282015-06-10 09:31:09 -070026#include "SkFontMgr.h"
Hal Canaryd7b38452017-12-11 17:46:26 -050027#include "SkFontMgrPriv.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000028#include "SkGraphics.h"
mtklein27c3fdd2016-02-26 14:43:21 -080029#include "SkHalf.h"
halcanary4dbbd042016-06-07 17:21:10 -070030#include "SkLeanWindows.h"
mtklein748ca3b2015-01-15 10:56:12 -080031#include "SkMD5.h"
mtklein1b249332015-07-07 12:21:21 -070032#include "SkMutex.h"
mtklein1d0f1642014-09-08 08:05:18 -070033#include "SkOSFile.h"
Ben Wagnerbf111d72016-11-07 18:05:29 -050034#include "SkOSPath.h"
Mike Klein13b6afd2017-06-12 12:45:41 -040035#include "SkPngEncoder.h"
Brian Salomondcbb9d92017-07-19 10:53:20 -040036#include "SkScan.h"
mtklein246ba3a2016-02-23 10:39:36 -080037#include "SkSpinlock.h"
Hal Canaryf4abda52018-08-06 19:29:43 +000038#include "SkTestFontMgr.h"
mtkleina82f5622015-02-20 12:30:19 -080039#include "SkTHash.h"
mtklein406654b2014-09-03 15:34:37 -070040#include "SkTaskGroup.h"
Mike Klein0c5fdcb2017-11-13 12:40:46 -050041#include "SkTypeface_win.h"
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000042#include "Test.h"
Mike Kleinadacaef2017-02-06 09:26:14 -050043#include "ios_utils.h"
caryclark83ca6282015-06-10 09:31:09 -070044#include "sk_tool_utils.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000045
scroggo19b91532016-10-24 09:03:26 -070046#include <vector>
47
mtkleina5114d72015-08-24 13:27:01 -070048#include "png.h"
49
bungeman60e0fee2015-08-26 05:15:46 -070050#include <stdlib.h>
51
Mike Klein8f11d4d2018-01-24 12:42:55 -050052#ifndef SK_BUILD_FOR_WIN
scroggo27a58342015-10-28 08:56:41 -070053 #include <unistd.h>
54#endif
55
Dongwon Kang0c7861f2018-02-16 10:55:21 -080056#if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && defined(SK_HAS_HEIF_LIBRARY)
57#include <binder/IPCThreadState.h>
58#endif
59
Mike Reed7c26ca72017-07-05 15:45:52 -040060extern bool gSkForceRasterPipelineBlitter;
61
djsollen54416de2015-04-03 07:24:48 -070062DEFINE_string(src, "tests gm skp image", "Source types to test.");
mtklein748ca3b2015-01-15 10:56:12 -080063DEFINE_bool(nameByHash, false,
64 "If true, write to FLAGS_writePath[0]/<hash>.png instead of "
djsollen54416de2015-04-03 07:24:48 -070065 "to FLAGS_writePath[0]/<config>/<sourceType>/<sourceOptions>/<name>.png");
mtklein748ca3b2015-01-15 10:56:12 -080066DEFINE_bool2(pathOpsExtended, x, false, "Run extended pathOps tests.");
mtkleind603b222015-02-17 11:13:33 -080067DEFINE_string(matrix, "1 0 0 1",
68 "2x2 scale+skew matrix to apply or upright when using "
69 "'matrix' or 'upright' in config.");
mtklein82d28432015-01-15 12:46:02 -080070DEFINE_bool(gpu_threading, false, "Allow GPU work to run on multiple threads?");
mtklein@google.comd36522d2013-10-16 13:02:15 +000071
mtkleina2ef6422015-01-15 13:44:22 -080072DEFINE_string(blacklist, "",
Chris Daltonecf78ac2017-08-15 15:43:08 -060073 "Space-separated config/src/srcOptions/name quadruples to blacklist. "
74 "'_' matches anything. '~' negates the match. E.g. \n"
djsollen54416de2015-04-03 07:24:48 -070075 "'--blacklist gpu skp _ _' will blacklist all SKPs drawn into the gpu config.\n"
Chris Daltonecf78ac2017-08-15 15:43:08 -060076 "'--blacklist gpu skp _ _ 8888 gm _ aarects' will also blacklist the aarects GM on 8888.\n"
77 "'--blacklist ~8888 svg _ svgparse_' blocks non-8888 SVGs that contain \"svgparse_\" in "
78 "the name.");
mtkleina2ef6422015-01-15 13:44:22 -080079
Brian Osman57796b32019-01-25 18:02:59 +000080DEFINE_string2(readPath, r, "", "If set check for equality with golden results in this directory.");
81
borenet09ed4802015-04-03 14:15:33 -070082DEFINE_string(uninterestingHashesFile, "",
83 "File containing a list of uninteresting hashes. If a result hashes to something in "
84 "this list, no image is written for that result.");
85
mtklein6393c062015-04-27 08:45:01 -070086DEFINE_int32(shards, 1, "We're splitting source data into this many shards.");
87DEFINE_int32(shard, 0, "Which shard do I run?");
88
halcanary45420a92016-06-02 12:41:14 -070089DEFINE_string(mskps, "", "Directory to read mskps from, or a single mskp file.");
Mike Reed7c26ca72017-07-05 15:45:52 -040090DEFINE_bool(forceRasterPipeline, false, "sets gSkForceRasterPipelineBlitter");
halcanary45420a92016-06-02 12:41:14 -070091
Chris Dalton184c37e2018-09-28 11:27:39 -060092DEFINE_string(bisect, "",
93 "Pair of: SKP file to bisect, followed by an l/r bisect trail string (e.g., 'lrll'). The "
94 "l/r trail specifies which half to keep at each step of a binary search through the SKP's "
95 "paths. An empty string performs no bisect. Only the SkPaths are bisected; all other draws "
96 "are thrown out. This is useful for finding a reduced repo case for path drawing bugs.");
97
Derek Sollenbergeredfe3df2017-07-19 15:25:24 -040098DEFINE_bool(ignoreSigInt, false, "ignore SIGINT signals during test execution");
99
Mike Klein97d6a7a2017-07-24 10:37:19 -0400100DEFINE_string(dont_write, "", "File extensions to skip writing to --writePath."); // See skia:6821
101
Mike Klein0c5fdcb2017-11-13 12:40:46 -0500102DEFINE_bool(gdi, false, "On Windows, use GDI instead of DirectWrite for font rendering.");
Mike Klein31868212017-11-06 12:02:47 -0500103
mtklein748ca3b2015-01-15 10:56:12 -0800104using namespace DM;
bsalomon3724e572016-03-30 18:56:19 -0700105using sk_gpu_test::GrContextFactory;
bsalomon273c0f52016-03-31 10:59:06 -0700106using sk_gpu_test::GLTestContext;
bsalomonf2f1c172016-04-05 12:59:06 -0700107using sk_gpu_test::ContextInfo;
mtklein@google.comd36522d2013-10-16 13:02:15 +0000108
mtklein748ca3b2015-01-15 10:56:12 -0800109/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
110
mtkleinc41fd922016-03-08 09:01:39 -0800111static FILE* gVLog;
112
113template <typename... Args>
114static void vlog(const char* fmt, Args&&... args) {
115 if (gVLog) {
mtkleinc41fd922016-03-08 09:01:39 -0800116 fprintf(gVLog, fmt, args...);
117 fflush(gVLog);
118 }
119}
120
121template <typename... Args>
122static void info(const char* fmt, Args&&... args) {
123 vlog(fmt, args...);
124 if (!FLAGS_quiet) {
125 printf(fmt, args...);
126 }
127}
128static void info(const char* fmt) {
129 if (!FLAGS_quiet) {
130 printf("%s", fmt); // Clang warns printf(fmt) is insecure.
131 }
132}
133
reed086eea92016-05-04 17:12:46 -0700134SK_DECLARE_STATIC_MUTEX(gFailuresMutex);
mtklein748ca3b2015-01-15 10:56:12 -0800135static SkTArray<SkString> gFailures;
136
mtklein3eed7dd2016-02-24 19:07:07 -0800137static void fail(const SkString& err) {
mtklein748ca3b2015-01-15 10:56:12 -0800138 SkAutoMutexAcquire lock(gFailuresMutex);
139 SkDebugf("\n\nFAILURE: %s\n\n", err.c_str());
140 gFailures.push_back(err);
halcanary9e398f72015-01-10 11:18:04 -0800141}
142
mtklein0f7748a2016-07-25 15:27:29 -0700143struct Running {
144 SkString id;
145 SkThreadID thread;
146
147 void dump() const {
148 info("\t%s\n", id.c_str());
149 }
150};
mtkleinb37cb412015-03-18 05:27:14 -0700151
mtklein246ba3a2016-02-23 10:39:36 -0800152// We use a spinlock to make locking this in a signal handler _somewhat_ safe.
Mike Klein03a95ad2017-06-23 12:36:32 -0400153static SkSpinlock gMutex;
154static int gPending;
mtklein0f7748a2016-07-25 15:27:29 -0700155static SkTArray<Running> gRunning;
mtklein748ca3b2015-01-15 10:56:12 -0800156
mtklein3eed7dd2016-02-24 19:07:07 -0800157static void done(const char* config, const char* src, const char* srcOptions, const char* name) {
158 SkString id = SkStringPrintf("%s %s %s %s", config, src, srcOptions, name);
mtkleinc41fd922016-03-08 09:01:39 -0800159 vlog("done %s\n", id.c_str());
mtkleinafae30a2016-02-24 12:28:32 -0800160 int pending;
mtkleinb37cb412015-03-18 05:27:14 -0700161 {
mtkleinf10637f2016-06-10 13:56:35 -0700162 SkAutoMutexAcquire lock(gMutex);
mtkleinb37cb412015-03-18 05:27:14 -0700163 for (int i = 0; i < gRunning.count(); i++) {
mtklein0f7748a2016-07-25 15:27:29 -0700164 if (gRunning[i].id == id) {
mtkleinb37cb412015-03-18 05:27:14 -0700165 gRunning.removeShuffle(i);
166 break;
167 }
168 }
mtkleinafae30a2016-02-24 12:28:32 -0800169 pending = --gPending;
reed50bc0512015-05-19 14:13:31 -0700170 }
Mike Klein03a95ad2017-06-23 12:36:32 -0400171
172 // We write out dm.json file and print out a progress update every once in a while.
173 // Notice this also handles the final dm.json and progress update when pending == 0.
mtkleina17241b2015-01-23 05:48:00 -0800174 if (pending % 500 == 0) {
175 JsonWriter::DumpJson();
Mike Klein03a95ad2017-06-23 12:36:32 -0400176
177 int curr = sk_tools::getCurrResidentSetSizeMB(),
178 peak = sk_tools::getMaxResidentSetSizeMB();
Mike Klein03a95ad2017-06-23 12:36:32 -0400179
180 SkAutoMutexAcquire lock(gMutex);
Mike Klein21ba7722018-10-02 13:57:44 +0000181 info("\n%dMB RAM, %dMB peak, %d queued, %d active:\n",
182 curr, peak, gPending - gRunning.count(), gRunning.count());
Mike Klein03a95ad2017-06-23 12:36:32 -0400183 for (auto& task : gRunning) {
184 task.dump();
185 }
mtkleina17241b2015-01-23 05:48:00 -0800186 }
mtklein@google.comd36522d2013-10-16 13:02:15 +0000187}
188
mtklein3eed7dd2016-02-24 19:07:07 -0800189static void start(const char* config, const char* src, const char* srcOptions, const char* name) {
190 SkString id = SkStringPrintf("%s %s %s %s", config, src, srcOptions, name);
mtkleinc41fd922016-03-08 09:01:39 -0800191 vlog("start %s\n", id.c_str());
mtkleinf10637f2016-06-10 13:56:35 -0700192 SkAutoMutexAcquire lock(gMutex);
mtklein0f7748a2016-07-25 15:27:29 -0700193 gRunning.push_back({id,SkGetThreadID()});
mtkleinb37cb412015-03-18 05:27:14 -0700194}
195
Mike Klein3cc2d202016-10-24 11:39:43 -0400196static void find_culprit() {
197 // Assumes gMutex is locked.
198 SkThreadID thisThread = SkGetThreadID();
199 for (auto& task : gRunning) {
200 if (task.thread == thisThread) {
201 info("Likely culprit:\n");
202 task.dump();
mtklein0f7748a2016-07-25 15:27:29 -0700203 }
204 }
Mike Klein3cc2d202016-10-24 11:39:43 -0400205}
mtklein0f7748a2016-07-25 15:27:29 -0700206
Mike Klein8f11d4d2018-01-24 12:42:55 -0500207#if defined(SK_BUILD_FOR_WIN)
mtklein5b64dab2016-06-09 08:59:48 -0700208 static LONG WINAPI crash_handler(EXCEPTION_POINTERS* e) {
mtkleinf8557292016-02-29 06:35:28 -0800209 static const struct {
210 const char* name;
robertphillips75467862016-03-01 14:10:23 -0800211 DWORD code;
mtkleinf8557292016-02-29 06:35:28 -0800212 } kExceptions[] = {
213 #define _(E) {#E, E}
214 _(EXCEPTION_ACCESS_VIOLATION),
215 _(EXCEPTION_BREAKPOINT),
216 _(EXCEPTION_INT_DIVIDE_BY_ZERO),
217 _(EXCEPTION_STACK_OVERFLOW),
218 // TODO: more?
219 #undef _
220 };
221
mtkleinf10637f2016-06-10 13:56:35 -0700222 SkAutoMutexAcquire lock(gMutex);
mtklein5b64dab2016-06-09 08:59:48 -0700223
224 const DWORD code = e->ExceptionRecord->ExceptionCode;
225 info("\nCaught exception %u", code);
226 for (const auto& exception : kExceptions) {
227 if (exception.code == code) {
228 info(" %s", exception.name);
mtkleinf8557292016-02-29 06:35:28 -0800229 }
mtkleinf8557292016-02-29 06:35:28 -0800230 }
mtklein5b64dab2016-06-09 08:59:48 -0700231 info(", was running:\n");
232 for (auto& task : gRunning) {
mtklein0f7748a2016-07-25 15:27:29 -0700233 task.dump();
mtklein5b64dab2016-06-09 08:59:48 -0700234 }
mtklein0f7748a2016-07-25 15:27:29 -0700235 find_culprit();
mtklein5b64dab2016-06-09 08:59:48 -0700236 fflush(stdout);
237
mtkleinf8557292016-02-29 06:35:28 -0800238 // Execute default exception handler... hopefully, exit.
239 return EXCEPTION_EXECUTE_HANDLER;
mtklein246ba3a2016-02-23 10:39:36 -0800240 }
241
Mike Klein3cc2d202016-10-24 11:39:43 -0400242 static void setup_crash_handler() {
243 SetUnhandledExceptionFilter(crash_handler);
244 }
245#else
mtklein246ba3a2016-02-23 10:39:36 -0800246 #include <signal.h>
Mike Klein3cc2d202016-10-24 11:39:43 -0400247 #if !defined(SK_BUILD_FOR_ANDROID)
248 #include <execinfo.h>
Brian Salomondcbb9d92017-07-19 10:53:20 -0400249
250#endif
Mike Klein3cc2d202016-10-24 11:39:43 -0400251
252 static constexpr int max_of() { return 0; }
253 template <typename... Rest>
254 static constexpr int max_of(int x, Rest... rest) {
255 return x > max_of(rest...) ? x : max_of(rest...);
256 }
257
Mike Kleinc7278ad2018-02-15 09:26:54 -0500258 static void (*previous_handler[max_of(SIGABRT,SIGBUS,SIGFPE,SIGILL,SIGSEGV,SIGTERM)+1])(int);
mtkleinf8557292016-02-29 06:35:28 -0800259
mtklein5b64dab2016-06-09 08:59:48 -0700260 static void crash_handler(int sig) {
mtkleinf10637f2016-06-10 13:56:35 -0700261 SkAutoMutexAcquire lock(gMutex);
mtklein5b64dab2016-06-09 08:59:48 -0700262
Mike Klein701a3582018-06-28 14:08:19 +0000263 info("\nCaught signal %d [%s] (%dMB RAM, peak %dMB), was running:\n",
264 sig, strsignal(sig),
265 sk_tools::getCurrResidentSetSizeMB(), sk_tools::getMaxResidentSetSizeMB());
266
mtklein5b64dab2016-06-09 08:59:48 -0700267 for (auto& task : gRunning) {
mtklein0f7748a2016-07-25 15:27:29 -0700268 task.dump();
mtklein5b64dab2016-06-09 08:59:48 -0700269 }
mtklein0f7748a2016-07-25 15:27:29 -0700270 find_culprit();
mtklein5b64dab2016-06-09 08:59:48 -0700271
Mike Klein3cc2d202016-10-24 11:39:43 -0400272 #if !defined(SK_BUILD_FOR_ANDROID)
mtklein5b64dab2016-06-09 08:59:48 -0700273 void* stack[64];
274 int count = backtrace(stack, SK_ARRAY_COUNT(stack));
275 char** symbols = backtrace_symbols(stack, count);
276 info("\nStack trace:\n");
277 for (int i = 0; i < count; i++) {
278 info(" %s\n", symbols[i]);
279 }
Mike Klein3cc2d202016-10-24 11:39:43 -0400280 #endif
mtklein5b64dab2016-06-09 08:59:48 -0700281 fflush(stdout);
282
Mike Klein3cc2d202016-10-24 11:39:43 -0400283 signal(sig, previous_handler[sig]);
284 raise(sig);
mtklein5b64dab2016-06-09 08:59:48 -0700285 }
286
mtklein246ba3a2016-02-23 10:39:36 -0800287 static void setup_crash_handler() {
Mike Klein701a3582018-06-28 14:08:19 +0000288 const int kSignals[] = { SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGINT, SIGSEGV, SIGTERM };
mtklein246ba3a2016-02-23 10:39:36 -0800289 for (int sig : kSignals) {
Mike Klein3cc2d202016-10-24 11:39:43 -0400290 previous_handler[sig] = signal(sig, crash_handler);
mtklein246ba3a2016-02-23 10:39:36 -0800291 }
Derek Sollenbergeredfe3df2017-07-19 15:25:24 -0400292
293 if (FLAGS_ignoreSigInt) {
294 signal(SIGINT, SIG_IGN);
295 }
mtklein246ba3a2016-02-23 10:39:36 -0800296 }
297#endif
298
mtklein748ca3b2015-01-15 10:56:12 -0800299/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
mtklein114c3cd2015-01-15 10:15:02 -0800300
Brian Osman57796b32019-01-25 18:02:59 +0000301struct Gold : public SkString {
302 Gold() : SkString("") {}
303 Gold(const SkString& sink, const SkString& src,
304 const SkString& srcOptions, const SkString& name,
305 const SkString& md5)
306 : SkString("") {
307 this->append(sink);
308 this->append(src);
309 this->append(srcOptions);
310 this->append(name);
311 this->append(md5);
312 }
313 struct Hash {
314 uint32_t operator()(const Gold& g) const {
315 return SkGoodHash()((const SkString&)g);
316 }
317 };
318};
319static SkTHashSet<Gold, Gold::Hash> gGold;
320
321static void add_gold(JsonWriter::BitmapResult r) {
322 gGold.add(Gold(r.config, r.sourceType, r.sourceOptions, r.name, r.md5));
323}
324
325static void gather_gold() {
326 if (!FLAGS_readPath.isEmpty()) {
327 SkString path(FLAGS_readPath[0]);
328 path.append("/dm.json");
329 if (!JsonWriter::ReadJson(path.c_str(), add_gold)) {
330 fail(SkStringPrintf("Couldn't read %s for golden results.", path.c_str()));
331 }
332 }
333}
334
335/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
336
Mike Klein8f11d4d2018-01-24 12:42:55 -0500337#if defined(SK_BUILD_FOR_WIN)
mtklein935f1b12016-03-16 08:37:19 -0700338 static const char* kNewline = "\r\n";
339#else
340 static const char* kNewline = "\n";
341#endif
342
borenet09ed4802015-04-03 14:15:33 -0700343static SkTHashSet<SkString> gUninterestingHashes;
344
345static void gather_uninteresting_hashes() {
346 if (!FLAGS_uninterestingHashesFile.isEmpty()) {
bungeman38d909e2016-08-02 14:40:46 -0700347 sk_sp<SkData> data(SkData::MakeFromFileName(FLAGS_uninterestingHashesFile[0]));
mtkleincc334b32015-09-22 11:43:53 -0700348 if (!data) {
mtkleinc41fd922016-03-08 09:01:39 -0800349 info("WARNING: unable to read uninteresting hashes from %s\n",
350 FLAGS_uninterestingHashesFile[0]);
mtkleincc334b32015-09-22 11:43:53 -0700351 return;
352 }
Mike Klein45dcc0c2017-04-05 18:04:31 -0400353
354 // Copy to a string to make sure SkStrSplit has a terminating \0 to find.
355 SkString contents((const char*)data->data(), data->size());
356
borenet09ed4802015-04-03 14:15:33 -0700357 SkTArray<SkString> hashes;
Mike Klein45dcc0c2017-04-05 18:04:31 -0400358 SkStrSplit(contents.c_str(), kNewline, &hashes);
borenet09ed4802015-04-03 14:15:33 -0700359 for (const SkString& hash : hashes) {
360 gUninterestingHashes.add(hash);
361 }
mtkleinc41fd922016-03-08 09:01:39 -0800362 info("FYI: loaded %d distinct uninteresting hashes from %d lines\n",
363 gUninterestingHashes.count(), hashes.count());
borenet09ed4802015-04-03 14:15:33 -0700364 }
365}
366
367/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
368
Ben Wagner145dbcd2016-11-03 14:40:50 -0400369struct TaggedSrc : public std::unique_ptr<Src> {
mtklein3eed7dd2016-02-24 19:07:07 -0800370 SkString tag;
371 SkString options;
mtkleine0effd62015-07-29 06:37:28 -0700372};
373
Ben Wagner145dbcd2016-11-03 14:40:50 -0400374struct TaggedSink : public std::unique_ptr<Sink> {
kkinnunen3e980c32015-12-23 01:33:00 -0800375 SkString tag;
djsollen54416de2015-04-03 07:24:48 -0700376};
mtklein748ca3b2015-01-15 10:56:12 -0800377
378static const bool kMemcpyOK = true;
379
mtkleine0effd62015-07-29 06:37:28 -0700380static SkTArray<TaggedSrc, kMemcpyOK> gSrcs;
381static SkTArray<TaggedSink, kMemcpyOK> gSinks;
mtklein748ca3b2015-01-15 10:56:12 -0800382
mtklein6393c062015-04-27 08:45:01 -0700383static bool in_shard() {
384 static int N = 0;
385 return N++ % FLAGS_shards == FLAGS_shard;
386}
387
mtklein3eed7dd2016-02-24 19:07:07 -0800388static void push_src(const char* tag, ImplicitString options, Src* s) {
Ben Wagner145dbcd2016-11-03 14:40:50 -0400389 std::unique_ptr<Src> src(s);
mtklein6393c062015-04-27 08:45:01 -0700390 if (in_shard() &&
mtklein3eed7dd2016-02-24 19:07:07 -0800391 FLAGS_src.contains(tag) &&
mtklein748ca3b2015-01-15 10:56:12 -0800392 !SkCommandLineFlags::ShouldSkip(FLAGS_match, src->name().c_str())) {
mtkleine0effd62015-07-29 06:37:28 -0700393 TaggedSrc& s = gSrcs.push_back();
mtklein18300a32016-03-16 13:53:35 -0700394 s.reset(src.release());
mtklein748ca3b2015-01-15 10:56:12 -0800395 s.tag = tag;
djsollen54416de2015-04-03 07:24:48 -0700396 s.options = options;
mtklein114c3cd2015-01-15 10:15:02 -0800397 }
mtklein748ca3b2015-01-15 10:56:12 -0800398}
mtklein114c3cd2015-01-15 10:15:02 -0800399
msarett9e707a02015-09-01 14:57:57 -0700400static void push_codec_src(Path path, CodecSrc::Mode mode, CodecSrc::DstColorType dstColorType,
scroggoc5560be2016-02-03 09:42:42 -0800401 SkAlphaType dstAlphaType, float scale) {
scroggoe4499842016-02-25 11:03:47 -0800402 if (FLAGS_simpleCodec) {
scroggo19b91532016-10-24 09:03:26 -0700403 const bool simple = CodecSrc::kCodec_Mode == mode || CodecSrc::kAnimated_Mode == mode;
404 if (!simple || dstColorType != CodecSrc::kGetFromCanvas_DstColorType || scale != 1.0f) {
scroggoe4499842016-02-25 11:03:47 -0800405 // Only decode in the simple case.
406 return;
scroggo19b91532016-10-24 09:03:26 -0700407 }
scroggoe4499842016-02-25 11:03:47 -0800408 }
msarett9e707a02015-09-01 14:57:57 -0700409 SkString folder;
410 switch (mode) {
411 case CodecSrc::kCodec_Mode:
412 folder.append("codec");
413 break;
msarettbb25b532016-01-13 09:31:39 -0800414 case CodecSrc::kCodecZeroInit_Mode:
415 folder.append("codec_zero_init");
416 break;
msarett9e707a02015-09-01 14:57:57 -0700417 case CodecSrc::kScanline_Mode:
418 folder.append("scanline");
419 break;
msarett9e707a02015-09-01 14:57:57 -0700420 case CodecSrc::kStripe_Mode:
421 folder.append("stripe");
422 break;
msarett91c22b22016-02-22 12:27:46 -0800423 case CodecSrc::kCroppedScanline_Mode:
424 folder.append("crop");
425 break;
msarett9e707a02015-09-01 14:57:57 -0700426 case CodecSrc::kSubset_Mode:
msarett36c37962015-09-02 13:20:52 -0700427 folder.append("codec_subset");
msarett9e707a02015-09-01 14:57:57 -0700428 break;
scroggo19b91532016-10-24 09:03:26 -0700429 case CodecSrc::kAnimated_Mode:
430 folder.append("codec_animated");
431 break;
msarett9e707a02015-09-01 14:57:57 -0700432 }
433
434 switch (dstColorType) {
435 case CodecSrc::kGrayscale_Always_DstColorType:
436 folder.append("_kGray8");
437 break;
msarett34e0ec42016-04-22 16:27:24 -0700438 case CodecSrc::kNonNative8888_Always_DstColorType:
439 folder.append("_kNonNative");
440 break;
msarett9e707a02015-09-01 14:57:57 -0700441 default:
442 break;
443 }
444
scroggoc5560be2016-02-03 09:42:42 -0800445 switch (dstAlphaType) {
scroggoc5560be2016-02-03 09:42:42 -0800446 case kPremul_SkAlphaType:
447 folder.append("_premul");
448 break;
449 case kUnpremul_SkAlphaType:
450 folder.append("_unpremul");
451 break;
452 default:
453 break;
454 }
455
msarett9e707a02015-09-01 14:57:57 -0700456 if (1.0f != scale) {
457 folder.appendf("_%.3f", scale);
458 }
459
scroggoc5560be2016-02-03 09:42:42 -0800460 CodecSrc* src = new CodecSrc(path, mode, dstColorType, dstAlphaType, scale);
msarett9e707a02015-09-01 14:57:57 -0700461 push_src("image", folder, src);
462}
463
scroggof8dc9df2016-05-16 09:04:13 -0700464static void push_android_codec_src(Path path, CodecSrc::DstColorType dstColorType,
465 SkAlphaType dstAlphaType, int sampleSize) {
msarett3d9d7a72015-10-21 10:27:10 -0700466 SkString folder;
scroggof8dc9df2016-05-16 09:04:13 -0700467 folder.append("scaled_codec");
msarett3d9d7a72015-10-21 10:27:10 -0700468
469 switch (dstColorType) {
470 case CodecSrc::kGrayscale_Always_DstColorType:
471 folder.append("_kGray8");
472 break;
msarett34e0ec42016-04-22 16:27:24 -0700473 case CodecSrc::kNonNative8888_Always_DstColorType:
474 folder.append("_kNonNative");
475 break;
msarett3d9d7a72015-10-21 10:27:10 -0700476 default:
477 break;
478 }
479
scroggoc5560be2016-02-03 09:42:42 -0800480 switch (dstAlphaType) {
scroggoc5560be2016-02-03 09:42:42 -0800481 case kPremul_SkAlphaType:
482 folder.append("_premul");
483 break;
msarett9e9444c2016-02-03 12:39:10 -0800484 case kUnpremul_SkAlphaType:
485 folder.append("_unpremul");
486 break;
scroggoc5560be2016-02-03 09:42:42 -0800487 default:
488 break;
489 }
490
msarett3d9d7a72015-10-21 10:27:10 -0700491 if (1 != sampleSize) {
msarett4b0778e2015-11-13 09:59:11 -0800492 folder.appendf("_%.3f", 1.0f / (float) sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700493 }
494
scroggof8dc9df2016-05-16 09:04:13 -0700495 AndroidCodecSrc* src = new AndroidCodecSrc(path, dstColorType, dstAlphaType, sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700496 push_src("image", folder, src);
497}
498
msarett18976312016-03-09 14:20:58 -0800499static void push_image_gen_src(Path path, ImageGenSrc::Mode mode, SkAlphaType alphaType, bool isGpu)
500{
501 SkString folder;
502 switch (mode) {
503 case ImageGenSrc::kCodec_Mode:
504 folder.append("gen_codec");
505 break;
506 case ImageGenSrc::kPlatform_Mode:
507 folder.append("gen_platform");
508 break;
509 }
510
511 if (isGpu) {
512 folder.append("_gpu");
513 } else {
514 switch (alphaType) {
515 case kOpaque_SkAlphaType:
516 folder.append("_opaque");
517 break;
518 case kPremul_SkAlphaType:
519 folder.append("_premul");
520 break;
521 case kUnpremul_SkAlphaType:
522 folder.append("_unpremul");
523 break;
524 default:
525 break;
526 }
527 }
528
529 ImageGenSrc* src = new ImageGenSrc(path, mode, alphaType, isGpu);
530 push_src("image", folder, src);
531}
532
Leon Scroggins III07418182017-08-15 12:24:02 -0400533static void push_brd_src(Path path, CodecSrc::DstColorType dstColorType, BRDSrc::Mode mode,
534 uint32_t sampleSize) {
535 SkString folder("brd_android_codec");
536 switch (mode) {
537 case BRDSrc::kFullImage_Mode:
538 break;
539 case BRDSrc::kDivisor_Mode:
540 folder.append("_divisor");
541 break;
542 default:
543 SkASSERT(false);
544 return;
545 }
546
547 switch (dstColorType) {
548 case CodecSrc::kGetFromCanvas_DstColorType:
549 break;
550 case CodecSrc::kGrayscale_Always_DstColorType:
551 folder.append("_kGray");
552 break;
553 default:
554 SkASSERT(false);
555 return;
556 }
557
558 if (1 != sampleSize) {
559 folder.appendf("_%.3f", 1.0f / (float) sampleSize);
560 }
561
562 BRDSrc* src = new BRDSrc(path, mode, dstColorType, sampleSize);
563 push_src("image", folder, src);
564}
565
566static void push_brd_srcs(Path path, bool gray) {
567 if (gray) {
568 // Only run grayscale to one sampleSize and Mode. Though interesting
569 // to test grayscale, it should not reveal anything across various
570 // sampleSizes and Modes
571 // Arbitrarily choose Mode and sampleSize.
572 push_brd_src(path, CodecSrc::kGrayscale_Always_DstColorType,
573 BRDSrc::kFullImage_Mode, 2);
574 }
575
576 // Test on a variety of sampleSizes, making sure to include:
577 // - 2, 4, and 8, which are natively supported by jpeg
578 // - multiples of 2 which are not divisible by 4 (analogous for 4)
579 // - larger powers of two, since BRD clients generally use powers of 2
580 // We will only produce output for the larger sizes on large images.
581 const uint32_t sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 24, 32, 64 };
582
583 const BRDSrc::Mode modes[] = { BRDSrc::kFullImage_Mode, BRDSrc::kDivisor_Mode, };
584
585 for (uint32_t sampleSize : sampleSizes) {
586 for (BRDSrc::Mode mode : modes) {
587 push_brd_src(path, CodecSrc::kGetFromCanvas_DstColorType, mode, sampleSize);
588 }
589 }
590}
591
msarett438b2ad2015-04-09 12:43:10 -0700592static void push_codec_srcs(Path path) {
bungeman38d909e2016-08-02 14:40:46 -0700593 sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str()));
msarett438b2ad2015-04-09 12:43:10 -0700594 if (!encoded) {
mtkleinc41fd922016-03-08 09:01:39 -0800595 info("Couldn't read %s.", path.c_str());
msarett438b2ad2015-04-09 12:43:10 -0700596 return;
597 }
Mike Reedede7bac2017-07-23 15:30:02 -0400598 std::unique_ptr<SkCodec> codec = SkCodec::MakeFromData(encoded);
halcanary96fcdcc2015-08-27 07:41:13 -0700599 if (nullptr == codec.get()) {
mtkleinc41fd922016-03-08 09:01:39 -0800600 info("Couldn't create codec for %s.", path.c_str());
msarett438b2ad2015-04-09 12:43:10 -0700601 return;
602 }
603
scroggo9366aff2016-05-20 08:38:54 -0700604 // native scaling is only supported by WEBP and JPEG
605 bool supportsNativeScaling = false;
msarett438b2ad2015-04-09 12:43:10 -0700606
msarett91c22b22016-02-22 12:27:46 -0800607 SkTArray<CodecSrc::Mode> nativeModes;
608 nativeModes.push_back(CodecSrc::kCodec_Mode);
609 nativeModes.push_back(CodecSrc::kCodecZeroInit_Mode);
msarett91c22b22016-02-22 12:27:46 -0800610 switch (codec->getEncodedFormat()) {
Hal Canarydb683012016-11-23 08:55:18 -0700611 case SkEncodedImageFormat::kJPEG:
msarett91c22b22016-02-22 12:27:46 -0800612 nativeModes.push_back(CodecSrc::kScanline_Mode);
613 nativeModes.push_back(CodecSrc::kStripe_Mode);
614 nativeModes.push_back(CodecSrc::kCroppedScanline_Mode);
scroggo9366aff2016-05-20 08:38:54 -0700615 supportsNativeScaling = true;
msarett91c22b22016-02-22 12:27:46 -0800616 break;
Hal Canarydb683012016-11-23 08:55:18 -0700617 case SkEncodedImageFormat::kWEBP:
msarett91c22b22016-02-22 12:27:46 -0800618 nativeModes.push_back(CodecSrc::kSubset_Mode);
scroggo9366aff2016-05-20 08:38:54 -0700619 supportsNativeScaling = true;
msarett91c22b22016-02-22 12:27:46 -0800620 break;
Hal Canarydb683012016-11-23 08:55:18 -0700621 case SkEncodedImageFormat::kDNG:
msarettb65e6042016-02-23 05:37:25 -0800622 break;
msarett91c22b22016-02-22 12:27:46 -0800623 default:
624 nativeModes.push_back(CodecSrc::kScanline_Mode);
msarett91c22b22016-02-22 12:27:46 -0800625 break;
626 }
msarett9e707a02015-09-01 14:57:57 -0700627
msarett91c22b22016-02-22 12:27:46 -0800628 SkTArray<CodecSrc::DstColorType> colorTypes;
629 colorTypes.push_back(CodecSrc::kGetFromCanvas_DstColorType);
msarett34e0ec42016-04-22 16:27:24 -0700630 colorTypes.push_back(CodecSrc::kNonNative8888_Always_DstColorType);
msarett36c37962015-09-02 13:20:52 -0700631 switch (codec->getInfo().colorType()) {
632 case kGray_8_SkColorType:
msarett91c22b22016-02-22 12:27:46 -0800633 colorTypes.push_back(CodecSrc::kGrayscale_Always_DstColorType);
msarett36c37962015-09-02 13:20:52 -0700634 break;
635 default:
msarett36c37962015-09-02 13:20:52 -0700636 break;
637 }
msarett9e707a02015-09-01 14:57:57 -0700638
scroggoc5560be2016-02-03 09:42:42 -0800639 SkTArray<SkAlphaType> alphaModes;
640 alphaModes.push_back(kPremul_SkAlphaType);
scroggof2c96a22016-05-20 11:08:27 -0700641 if (codec->getInfo().alphaType() != kOpaque_SkAlphaType) {
642 alphaModes.push_back(kUnpremul_SkAlphaType);
scroggoc5560be2016-02-03 09:42:42 -0800643 }
msarettb714fb02016-01-22 14:46:42 -0800644
645 for (CodecSrc::Mode mode : nativeModes) {
scroggo9366aff2016-05-20 08:38:54 -0700646 for (CodecSrc::DstColorType colorType : colorTypes) {
647 for (SkAlphaType alphaType : alphaModes) {
scroggof2c96a22016-05-20 11:08:27 -0700648 // Only test kCroppedScanline_Mode when the alpha type is premul. The test is
scroggo9366aff2016-05-20 08:38:54 -0700649 // slow and won't be interestingly different with different alpha types.
650 if (CodecSrc::kCroppedScanline_Mode == mode &&
scroggof2c96a22016-05-20 11:08:27 -0700651 kPremul_SkAlphaType != alphaType) {
scroggo9366aff2016-05-20 08:38:54 -0700652 continue;
653 }
msarett91c22b22016-02-22 12:27:46 -0800654
scroggo9366aff2016-05-20 08:38:54 -0700655 push_codec_src(path, mode, colorType, alphaType, 1.0f);
msarettf3dc1882016-04-26 13:06:38 -0700656
scroggo9366aff2016-05-20 08:38:54 -0700657 // Skip kNonNative on different native scales. It won't be interestingly
658 // different.
659 if (supportsNativeScaling &&
660 CodecSrc::kNonNative8888_Always_DstColorType == colorType) {
661 // Native Scales
662 // SkJpegCodec natively supports scaling to the following:
663 for (auto scale : { 0.125f, 0.25f, 0.375f, 0.5f, 0.625f, 0.750f, 0.875f }) {
664 push_codec_src(path, mode, colorType, alphaType, scale);
665 }
scroggoc5560be2016-02-03 09:42:42 -0800666 }
msarett9e707a02015-09-01 14:57:57 -0700667 }
668 }
msarett0a242972015-06-11 14:27:27 -0700669 }
msarett36c37962015-09-02 13:20:52 -0700670
scroggo19b91532016-10-24 09:03:26 -0700671 {
672 std::vector<SkCodec::FrameInfo> frameInfos = codec->getFrameInfo();
673 if (frameInfos.size() > 1) {
Leon Scroggins III557fbbe2017-05-23 09:37:21 -0400674 for (auto dstCT : { CodecSrc::kNonNative8888_Always_DstColorType,
675 CodecSrc::kGetFromCanvas_DstColorType }) {
676 for (auto at : { kUnpremul_SkAlphaType, kPremul_SkAlphaType }) {
677 push_codec_src(path, CodecSrc::kAnimated_Mode, dstCT, at, 1.0f);
678 }
679 }
scroggo19b91532016-10-24 09:03:26 -0700680 }
681
682 }
683
scroggoe4499842016-02-25 11:03:47 -0800684 if (FLAGS_simpleCodec) {
685 return;
686 }
687
msarett3d9d7a72015-10-21 10:27:10 -0700688 const int sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
msarett36c37962015-09-02 13:20:52 -0700689
msarett3d9d7a72015-10-21 10:27:10 -0700690 for (int sampleSize : sampleSizes) {
msarett91c22b22016-02-22 12:27:46 -0800691 for (CodecSrc::DstColorType colorType : colorTypes) {
scroggoc5560be2016-02-03 09:42:42 -0800692 for (SkAlphaType alphaType : alphaModes) {
msarettf3dc1882016-04-26 13:06:38 -0700693 // We can exercise all of the kNonNative support code in the swizzler with just a
694 // few sample sizes. Skip the rest.
695 if (CodecSrc::kNonNative8888_Always_DstColorType == colorType && sampleSize > 3) {
696 continue;
697 }
698
scroggof8dc9df2016-05-16 09:04:13 -0700699 push_android_codec_src(path, colorType, alphaType, sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700700 }
msarett36c37962015-09-02 13:20:52 -0700701 }
702 }
msarett18976312016-03-09 14:20:58 -0800703
Leon Scroggins III07418182017-08-15 12:24:02 -0400704 const char* ext = strrchr(path.c_str(), '.');
705 if (ext) {
706 ext++;
msarett18976312016-03-09 14:20:58 -0800707
Leon Scroggins III07418182017-08-15 12:24:02 -0400708 static const char* const rawExts[] = {
709 "arw", "cr2", "dng", "nef", "nrw", "orf", "raf", "rw2", "pef", "srw",
710 "ARW", "CR2", "DNG", "NEF", "NRW", "ORF", "RAF", "RW2", "PEF", "SRW",
711 };
712 for (const char* rawExt : rawExts) {
713 if (0 == strcmp(rawExt, ext)) {
714 // RAW is not supported by image generator (skbug.com/5079) or BRD.
715 return;
716 }
717 }
718
719 static const char* const brdExts[] = {
720 "jpg", "jpeg", "png", "webp",
721 "JPG", "JPEG", "PNG", "WEBP",
722 };
723 for (const char* brdExt : brdExts) {
724 if (0 == strcmp(brdExt, ext)) {
Leon Scroggins IIIc8037dc2017-12-05 13:55:24 -0500725 bool gray = codec->getInfo().colorType() == kGray_8_SkColorType;
Leon Scroggins III07418182017-08-15 12:24:02 -0400726 push_brd_srcs(path, gray);
727 break;
728 }
msarett18976312016-03-09 14:20:58 -0800729 }
730 }
731
732 // Push image generator GPU test.
brianosmanc9ced392016-03-24 07:27:43 -0700733 push_image_gen_src(path, ImageGenSrc::kCodec_Mode, codec->getInfo().alphaType(), true);
msarett18976312016-03-09 14:20:58 -0800734
735 // Push image generator CPU tests.
736 for (SkAlphaType alphaType : alphaModes) {
737 push_image_gen_src(path, ImageGenSrc::kCodec_Mode, alphaType, false);
738
739#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
Hal Canarydb683012016-11-23 08:55:18 -0700740 if (SkEncodedImageFormat::kWEBP != codec->getEncodedFormat() &&
741 SkEncodedImageFormat::kWBMP != codec->getEncodedFormat() &&
msarett18976312016-03-09 14:20:58 -0800742 kUnpremul_SkAlphaType != alphaType)
743 {
744 push_image_gen_src(path, ImageGenSrc::kPlatform_Mode, alphaType, false);
745 }
msarettfc0b6d12016-03-17 13:50:17 -0700746#elif defined(SK_BUILD_FOR_WIN)
Hal Canarydb683012016-11-23 08:55:18 -0700747 if (SkEncodedImageFormat::kWEBP != codec->getEncodedFormat() &&
748 SkEncodedImageFormat::kWBMP != codec->getEncodedFormat())
msarettfc0b6d12016-03-17 13:50:17 -0700749 {
750 push_image_gen_src(path, ImageGenSrc::kPlatform_Mode, alphaType, false);
751 }
msarett18976312016-03-09 14:20:58 -0800752#endif
753 }
msarett438b2ad2015-04-09 12:43:10 -0700754}
755
fmalitaa2b9fdf2016-08-03 19:53:36 -0700756template <typename T>
Florin Malitaf1ba3ae2018-07-19 15:09:11 -0400757void gather_file_srcs(const SkCommandLineFlags::StringArray& flags, const char* ext,
758 const char* src_name = nullptr) {
759 if (!src_name) {
760 // With the exception of Lottie files, the source name is the extension.
761 src_name = ext;
762 }
763
fmalitaa2b9fdf2016-08-03 19:53:36 -0700764 for (int i = 0; i < flags.count(); i++) {
765 const char* path = flags[i];
766 if (sk_isdir(path)) {
767 SkOSFile::Iter it(path, ext);
768 for (SkString file; it.next(&file); ) {
Florin Malitaf1ba3ae2018-07-19 15:09:11 -0400769 push_src(src_name, "", new T(SkOSPath::Join(path, file.c_str())));
fmalitaa2b9fdf2016-08-03 19:53:36 -0700770 }
771 } else {
Florin Malitaf1ba3ae2018-07-19 15:09:11 -0400772 push_src(src_name, "", new T(path));
fmalitaa2b9fdf2016-08-03 19:53:36 -0700773 }
774 }
775}
776
scroggo86737142016-02-03 12:19:11 -0800777static bool gather_srcs() {
Hal Canary972eba32018-07-30 17:07:07 -0400778 for (skiagm::GMFactory f : skiagm::GMRegistry::Range()) {
779 push_src("gm", "", new GMSrc(f));
mtklein748ca3b2015-01-15 10:56:12 -0800780 }
scroggo86737142016-02-03 12:19:11 -0800781
Robert Phillipse47f0a02018-03-27 17:01:16 -0400782 gather_file_srcs<SKPSrc>(FLAGS_skps, "skp");
fmalitaa2b9fdf2016-08-03 19:53:36 -0700783 gather_file_srcs<MSKPSrc>(FLAGS_mskps, "mskp");
Florin Malita87ccf332018-05-04 12:23:24 -0400784#if defined(SK_ENABLE_SKOTTIE)
Florin Malitaf1ba3ae2018-07-19 15:09:11 -0400785 gather_file_srcs<SkottieSrc>(FLAGS_lotties, "json", "lottie");
Florin Malita124d5af2017-12-31 17:02:26 -0500786#endif
fmalitaa2b9fdf2016-08-03 19:53:36 -0700787#if defined(SK_XML)
788 gather_file_srcs<SVGSrc>(FLAGS_svgs, "svg");
789#endif
Chris Dalton184c37e2018-09-28 11:27:39 -0600790 if (!FLAGS_bisect.isEmpty()) {
791 // An empty l/r trail string will draw all the paths.
792 push_src("bisect", "",
793 new BisectSrc(FLAGS_bisect[0], FLAGS_bisect.count() > 1 ? FLAGS_bisect[1] : ""));
794 }
halcanary45420a92016-06-02 12:41:14 -0700795
scroggo86737142016-02-03 12:19:11 -0800796 SkTArray<SkString> images;
msarett69deca82016-04-29 09:38:40 -0700797 if (!CollectImages(FLAGS_images, &images)) {
scroggo86737142016-02-03 12:19:11 -0800798 return false;
799 }
800
801 for (auto image : images) {
802 push_codec_srcs(image);
mtklein709d2c32015-01-15 08:30:25 -0800803 }
scroggo86737142016-02-03 12:19:11 -0800804
msarett69deca82016-04-29 09:38:40 -0700805 SkTArray<SkString> colorImages;
806 if (!CollectImages(FLAGS_colorImages, &colorImages)) {
807 return false;
808 }
809
810 for (auto colorImage : colorImages) {
msarett9ce3a542016-07-15 13:54:38 -0700811 ColorCodecSrc* src = new ColorCodecSrc(colorImage, ColorCodecSrc::kBaseline_Mode,
812 kN32_SkColorType);
msarettb8d1aac2016-08-04 12:22:06 -0700813 push_src("colorImage", "color_codec_baseline", src);
msarett888dc162016-05-23 10:21:17 -0700814
msarett9ce3a542016-07-15 13:54:38 -0700815 src = new ColorCodecSrc(colorImage, ColorCodecSrc::kDst_HPZR30w_Mode, kN32_SkColorType);
msarettb8d1aac2016-08-04 12:22:06 -0700816 push_src("colorImage", "color_codec_HPZR30w", src);
msarett9ce3a542016-07-15 13:54:38 -0700817 // TODO (msarett):
818 // Should we test this Dst in F16 mode (even though the Dst gamma is 2.2 instead of sRGB)?
msarett9876ac52016-06-01 14:47:18 -0700819
msarett9ce3a542016-07-15 13:54:38 -0700820 src = new ColorCodecSrc(colorImage, ColorCodecSrc::kDst_sRGB_Mode, kN32_SkColorType);
msarettb8d1aac2016-08-04 12:22:06 -0700821 push_src("colorImage", "color_codec_sRGB_kN32", src);
msarett9ce3a542016-07-15 13:54:38 -0700822 src = new ColorCodecSrc(colorImage, ColorCodecSrc::kDst_sRGB_Mode, kRGBA_F16_SkColorType);
msarettb8d1aac2016-08-04 12:22:06 -0700823 push_src("colorImage", "color_codec_sRGB_kF16", src);
msarett69deca82016-04-29 09:38:40 -0700824 }
825
scroggo86737142016-02-03 12:19:11 -0800826 return true;
mtklein709d2c32015-01-15 08:30:25 -0800827}
828
Mike Klein66f09a72019-02-12 13:03:54 -0500829static constexpr skcms_TransferFunction k2020_TF =
830 {2.22222f, 0.909672f, 0.0903276f, 0.222222f, 0.0812429f, 0, 0};
831
Mike Kleinae4b1f42018-09-13 11:13:15 -0400832static sk_sp<SkColorSpace> rec2020() {
Mike Klein66f09a72019-02-12 13:03:54 -0500833 return SkColorSpace::MakeRGB(k2020_TF, SkNamedGamut::kRec2020);
Mike Kleinae4b1f42018-09-13 11:13:15 -0400834}
835
kkinnunen3e980c32015-12-23 01:33:00 -0800836static void push_sink(const SkCommandLineConfig& config, Sink* s) {
Ben Wagner145dbcd2016-11-03 14:40:50 -0400837 std::unique_ptr<Sink> sink(s);
kkinnunen3e980c32015-12-23 01:33:00 -0800838
mtkleine0effd62015-07-29 06:37:28 -0700839 // Try a simple Src as a canary. If it fails, skip this sink.
mtklein748ca3b2015-01-15 10:56:12 -0800840 struct : public Src {
mtkleine0effd62015-07-29 06:37:28 -0700841 Error draw(SkCanvas* c) const override {
842 c->drawRect(SkRect::MakeWH(1,1), SkPaint());
843 return "";
844 }
mtklein36352bf2015-03-25 18:17:31 -0700845 SkISize size() const override { return SkISize::Make(16, 16); }
mtkleine0effd62015-07-29 06:37:28 -0700846 Name name() const override { return "justOneRect"; }
847 } justOneRect;
mtklein114c3cd2015-01-15 10:15:02 -0800848
mtklein748ca3b2015-01-15 10:56:12 -0800849 SkBitmap bitmap;
850 SkDynamicMemoryWStream stream;
mtkleinb9eb4ac2015-02-02 18:26:03 -0800851 SkString log;
mtkleine0effd62015-07-29 06:37:28 -0700852 Error err = sink->draw(justOneRect, &bitmap, &stream, &log);
mtklein4089ef72015-03-05 08:40:28 -0800853 if (err.isFatal()) {
mtkleinc41fd922016-03-08 09:01:39 -0800854 info("Could not run %s: %s\n", config.getTag().c_str(), err.c_str());
mtklein05641a52015-04-21 10:49:13 -0700855 exit(1);
mtklein114c3cd2015-01-15 10:15:02 -0800856 }
857
mtkleine0effd62015-07-29 06:37:28 -0700858 TaggedSink& ts = gSinks.push_back();
mtklein18300a32016-03-16 13:53:35 -0700859 ts.reset(sink.release());
kkinnunen3e980c32015-12-23 01:33:00 -0800860 ts.tag = config.getTag();
mtklein748ca3b2015-01-15 10:56:12 -0800861}
862
csmartdalton008b9d82017-02-22 12:00:42 -0700863static Sink* create_sink(const GrContextOptions& grCtxOptions, const SkCommandLineConfig* config) {
Brian Osmanc7ad40f2018-05-31 14:27:17 -0400864 if (FLAGS_gpu) {
kkinnunen3e980c32015-12-23 01:33:00 -0800865 if (const SkCommandLineConfigGpu* gpuConfig = config->asConfigGpu()) {
bsalomon85b4b532016-04-05 11:06:27 -0700866 GrContextFactory::ContextType contextType = gpuConfig->getContextType();
csmartdaltone812d492017-02-21 12:36:05 -0700867 GrContextFactory::ContextOverrides contextOverrides = gpuConfig->getContextOverrides();
csmartdalton008b9d82017-02-22 12:00:42 -0700868 GrContextFactory testFactory(grCtxOptions);
csmartdaltone812d492017-02-21 12:36:05 -0700869 if (!testFactory.get(contextType, contextOverrides)) {
mtkleinc41fd922016-03-08 09:01:39 -0800870 info("WARNING: can not create GPU context for config '%s'. "
871 "GM tests will be skipped.\n", gpuConfig->getTag().c_str());
kkinnunen3e980c32015-12-23 01:33:00 -0800872 return nullptr;
873 }
Brian Osmanf9810662017-08-30 10:02:10 -0400874 if (gpuConfig->getTestThreading()) {
Brian Salomon00a5eb82018-07-11 15:32:05 -0400875 SkASSERT(!gpuConfig->getTestPersistentCache());
Brian Salomonf865b052018-03-09 09:01:53 -0500876 return new GPUThreadTestingSink(
877 contextType, contextOverrides, gpuConfig->getSurfType(),
878 gpuConfig->getSamples(), gpuConfig->getUseDIText(),
879 gpuConfig->getColorType(), gpuConfig->getAlphaType(),
880 sk_ref_sp(gpuConfig->getColorSpace()), FLAGS_gpu_threading, grCtxOptions);
Brian Salomon00a5eb82018-07-11 15:32:05 -0400881 } else if (gpuConfig->getTestPersistentCache()) {
882 return new GPUPersistentCacheTestingSink(
883 contextType, contextOverrides, gpuConfig->getSurfType(),
884 gpuConfig->getSamples(), gpuConfig->getUseDIText(),
885 gpuConfig->getColorType(), gpuConfig->getAlphaType(),
886 sk_ref_sp(gpuConfig->getColorSpace()), FLAGS_gpu_threading, grCtxOptions);
Brian Osmanf9810662017-08-30 10:02:10 -0400887 } else {
Brian Salomonf865b052018-03-09 09:01:53 -0500888 return new GPUSink(contextType, contextOverrides, gpuConfig->getSurfType(),
889 gpuConfig->getSamples(), gpuConfig->getUseDIText(),
890 gpuConfig->getColorType(), gpuConfig->getAlphaType(),
891 sk_ref_sp(gpuConfig->getColorSpace()), FLAGS_gpu_threading,
892 grCtxOptions);
Brian Osmanf9810662017-08-30 10:02:10 -0400893 }
kkinnunen3e980c32015-12-23 01:33:00 -0800894 }
895 }
Bryce Thomas95a7b762018-03-02 13:54:21 -0800896 if (const SkCommandLineConfigSvg* svgConfig = config->asConfigSvg()) {
897 int pageIndex = svgConfig->getPageIndex();
898 return new SVGSink(pageIndex);
899 }
kkinnunen3e980c32015-12-23 01:33:00 -0800900
Brian Salomon23356442018-11-30 15:33:19 -0500901#define SINK(t, sink, ...) if (config->getBackend().equals(t)) return new sink(__VA_ARGS__)
kkinnunen3e980c32015-12-23 01:33:00 -0800902
mtklein748ca3b2015-01-15 10:56:12 -0800903 if (FLAGS_cpu) {
Mike Klein515bda62018-01-09 11:21:58 -0500904 SINK("g8", RasterSink, kGray_8_SkColorType);
Matt Sarettd2228302017-03-02 08:53:46 -0500905 SINK("565", RasterSink, kRGB_565_SkColorType);
Mike Klein5340b3f2018-01-24 13:42:05 -0500906 SINK("4444", RasterSink, kARGB_4444_SkColorType);
Matt Sarettd2228302017-03-02 08:53:46 -0500907 SINK("8888", RasterSink, kN32_SkColorType);
Mike Kleinac568a92018-01-25 09:09:32 -0500908 SINK("rgba", RasterSink, kRGBA_8888_SkColorType);
909 SINK("bgra", RasterSink, kBGRA_8888_SkColorType);
910 SINK("rgbx", RasterSink, kRGB_888x_SkColorType);
911 SINK("1010102", RasterSink, kRGBA_1010102_SkColorType);
912 SINK("101010x", RasterSink, kRGB_101010x_SkColorType);
Hal Canaryc7d295e2017-07-20 15:36:00 -0400913 SINK("pdf", PDFSink, false, SK_ScalarDefaultRasterDPI);
Matt Sarettd2228302017-03-02 08:53:46 -0500914 SINK("skp", SKPSink);
Matt Sarettd2228302017-03-02 08:53:46 -0500915 SINK("svg", SVGSink);
916 SINK("null", NullSink);
917 SINK("xps", XPSSink);
Hal Canaryc7d295e2017-07-20 15:36:00 -0400918 SINK("pdfa", PDFSink, true, SK_ScalarDefaultRasterDPI);
919 SINK("pdf300", PDFSink, false, 300);
Hal Canary85c7fe82016-10-25 10:33:27 -0400920 SINK("jsdebug", DebugSink);
Mike Klein0e4041f2018-06-19 16:00:40 -0400921
922 // Configs relevant to color management testing (and 8888 for reference).
923
924 // 'narrow' has a gamut narrower than sRGB, and different transfer function.
Brian Osman82ebe042019-01-04 17:03:00 -0500925 auto narrow = SkColorSpace::MakeRGB(SkNamedTransferFn::k2Dot2, gNarrow_toXYZD50),
Mike Klein0e4041f2018-06-19 16:00:40 -0400926 srgb = SkColorSpace::MakeSRGB(),
Mike Klein4de05072018-08-16 09:09:14 -0400927 srgbLinear = SkColorSpace::MakeSRGBLinear(),
Brian Osman82ebe042019-01-04 17:03:00 -0500928 p3 = SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, SkNamedGamut::kDCIP3);
Mike Klein0e4041f2018-06-19 16:00:40 -0400929
Mike Kleinff6a73c2018-08-17 16:19:24 -0400930 SINK( "f16", RasterSink, kRGBA_F16_SkColorType, srgbLinear);
931 SINK( "srgb", RasterSink, kRGBA_8888_SkColorType, srgb );
932 SINK( "esrgb", RasterSink, kRGBA_F16_SkColorType, srgb );
933 SINK( "narrow", RasterSink, kRGBA_8888_SkColorType, narrow );
934 SINK( "enarrow", RasterSink, kRGBA_F16_SkColorType, narrow );
935 SINK( "p3", RasterSink, kRGBA_8888_SkColorType, p3 );
936 SINK( "ep3", RasterSink, kRGBA_F16_SkColorType, p3 );
Mike Kleinae4b1f42018-09-13 11:13:15 -0400937 SINK( "rec2020", RasterSink, kRGBA_8888_SkColorType, rec2020() );
938 SINK("erec2020", RasterSink, kRGBA_F16_SkColorType, rec2020() );
Mike Klein37854712018-06-26 11:43:06 -0400939
940 SINK( "f32", RasterSink, kRGBA_F32_SkColorType, srgbLinear);
mtklein748ca3b2015-01-15 10:56:12 -0800941 }
942#undef SINK
halcanary96fcdcc2015-08-27 07:41:13 -0700943 return nullptr;
mtklein114c3cd2015-01-15 10:15:02 -0800944}
945
Mike Kleinb7ea3da2017-10-31 17:42:08 +0000946static sk_sp<SkColorSpace> rgb_to_gbr() {
Brian Osman36703d92017-12-12 14:09:31 -0500947 return SkColorSpace::MakeSRGB()->makeColorSpin();
Mike Klein919cc452017-03-18 15:36:52 +0000948}
949
kkinnunen3e980c32015-12-23 01:33:00 -0800950static Sink* create_via(const SkString& tag, Sink* wrapped) {
Brian Salomon23356442018-11-30 15:33:19 -0500951#define VIA(t, via, ...) if (tag.equals(t)) return new via(__VA_ARGS__)
Mike Kleinb7ea3da2017-10-31 17:42:08 +0000952 VIA("gbr", ViaCSXform, wrapped, rgb_to_gbr(), true);
Brian Osmana76b7a92018-07-18 14:36:43 -0400953 VIA("p3", ViaCSXform, wrapped,
Brian Osman82ebe042019-01-04 17:03:00 -0500954 SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, SkNamedGamut::kDCIP3), false);
mtklein9c5052f2016-08-06 12:51:51 -0700955 VIA("lite", ViaLite, wrapped);
Mike Reedbae888e2017-02-18 16:50:45 -0500956#ifdef TEST_VIA_SVG
Mike Reedf67c4592017-02-17 17:06:11 -0500957 VIA("svg", ViaSVG, wrapped);
Mike Reedbae888e2017-02-18 16:50:45 -0500958#endif
halcanary96fcdcc2015-08-27 07:41:13 -0700959 VIA("serialize", ViaSerialization, wrapped);
mtklein4a34ecb2016-01-08 10:19:35 -0800960 VIA("pic", ViaPicture, wrapped);
halcanary96fcdcc2015-08-27 07:41:13 -0700961 VIA("tiles", ViaTiles, 256, 256, nullptr, wrapped);
mtklein7edca212015-01-21 13:18:51 -0800962 VIA("tiles_rt", ViaTiles, 256, 256, new SkRTreeFactory, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800963
Brian Salomon57904202018-12-17 14:45:00 -0500964 VIA("ddl", ViaDDL, 1, 3, wrapped);
965 VIA("ddl2", ViaDDL, 2, 3, wrapped);
Robert Phillips33f02ed2018-03-27 08:06:57 -0400966
mtkleind603b222015-02-17 11:13:33 -0800967 if (FLAGS_matrix.count() == 4) {
mtklein748ca3b2015-01-15 10:56:12 -0800968 SkMatrix m;
mtkleind603b222015-02-17 11:13:33 -0800969 m.reset();
970 m.setScaleX((SkScalar)atof(FLAGS_matrix[0]));
971 m.setSkewX ((SkScalar)atof(FLAGS_matrix[1]));
972 m.setSkewY ((SkScalar)atof(FLAGS_matrix[2]));
973 m.setScaleY((SkScalar)atof(FLAGS_matrix[3]));
974 VIA("matrix", ViaMatrix, m, wrapped);
975 VIA("upright", ViaUpright, m, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800976 }
tomhudson64de1e12015-03-05 08:01:07 -0800977
mtklein748ca3b2015-01-15 10:56:12 -0800978#undef VIA
halcanary96fcdcc2015-08-27 07:41:13 -0700979 return nullptr;
mtklein114c3cd2015-01-15 10:15:02 -0800980}
981
Ben Wagnerf28d4722017-08-11 17:33:22 -0400982static bool gather_sinks(const GrContextOptions& grCtxOptions, bool defaultConfigs) {
kkinnunen3e980c32015-12-23 01:33:00 -0800983 SkCommandLineConfigArray configs;
984 ParseConfigs(FLAGS_config, &configs);
985 for (int i = 0; i < configs.count(); i++) {
986 const SkCommandLineConfig& config = *configs[i];
csmartdalton008b9d82017-02-22 12:00:42 -0700987 Sink* sink = create_sink(grCtxOptions, &config);
kkinnunen3e980c32015-12-23 01:33:00 -0800988 if (sink == nullptr) {
mtkleinc41fd922016-03-08 09:01:39 -0800989 info("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(),
990 config.getTag().c_str());
kkinnunen3e980c32015-12-23 01:33:00 -0800991 continue;
992 }
mtklein748ca3b2015-01-15 10:56:12 -0800993
kkinnunen3e980c32015-12-23 01:33:00 -0800994 const SkTArray<SkString>& parts = config.getViaParts();
995 for (int j = parts.count(); j-- > 0;) {
996 const SkString& part = parts[j];
997 Sink* next = create_via(part, sink);
halcanary96fcdcc2015-08-27 07:41:13 -0700998 if (next == nullptr) {
mtkleinc41fd922016-03-08 09:01:39 -0800999 info("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(),
1000 part.c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001001 delete sink;
halcanary96fcdcc2015-08-27 07:41:13 -07001002 sink = nullptr;
mtklein748ca3b2015-01-15 10:56:12 -08001003 break;
1004 }
1005 sink = next;
1006 }
1007 if (sink) {
1008 push_sink(config, sink);
mtklein114c3cd2015-01-15 10:15:02 -08001009 }
1010 }
brianosman05c987c2016-05-09 13:42:16 -07001011
1012 // If no configs were requested (just running tests, perhaps?), then we're okay.
Ben Wagnerf28d4722017-08-11 17:33:22 -04001013 if (configs.count() == 0 ||
1014 // If we're using the default configs, we're okay.
1015 defaultConfigs ||
Ben Wagner32fa5102017-08-10 21:25:55 -04001016 // Otherwise, make sure that all specified configs have become sinks.
1017 configs.count() == gSinks.count()) {
1018 return true;
1019 }
Ben Wagner32fa5102017-08-10 21:25:55 -04001020 return false;
mtklein114c3cd2015-01-15 10:15:02 -08001021}
mtklein709d2c32015-01-15 08:30:25 -08001022
mtkleina5114d72015-08-24 13:27:01 -07001023static bool dump_png(SkBitmap bitmap, const char* path, const char* md5) {
Mike Klein13b6afd2017-06-12 12:45:41 -04001024 SkPixmap pm;
1025 if (!bitmap.peekPixels(&pm)) {
1026 return false; // Ought to never happen... we're already read-back at this point.
mtkleina5114d72015-08-24 13:27:01 -07001027 }
Mike Klein13b6afd2017-06-12 12:45:41 -04001028 SkFILEWStream dst{path};
mtkleina5114d72015-08-24 13:27:01 -07001029
mtkleind69ece62015-09-10 10:37:44 -07001030 SkString description;
1031 description.append("Key: ");
1032 for (int i = 0; i < FLAGS_key.count(); i++) {
1033 description.appendf("%s ", FLAGS_key[i]);
1034 }
1035 description.append("Properties: ");
1036 for (int i = 0; i < FLAGS_properties.count(); i++) {
1037 description.appendf("%s ", FLAGS_properties[i]);
1038 }
1039 description.appendf("MD5: %s", md5);
1040
Mike Klein13b6afd2017-06-12 12:45:41 -04001041 const char* comments[] = {
1042 "Author", "DM dump_png()",
1043 "Description", description.c_str(),
1044 };
1045 size_t lengths[] = {
1046 strlen(comments[0])+1, strlen(comments[1])+1,
1047 strlen(comments[2])+1, strlen(comments[3])+1,
1048 };
mtkleina5114d72015-08-24 13:27:01 -07001049
Mike Kleinae4b1f42018-09-13 11:13:15 -04001050 // PNGs can't hold out-of-gamut values, so if we're likely to be holding them,
1051 // convert to a wide gamut, giving us the best chance to have the PNG look like our colors.
1052 SkBitmap wide;
1053 if (pm.colorType() >= kRGBA_F16_SkColorType) {
1054 wide.allocPixels(pm.info().makeColorSpace(rec2020()));
1055 SkAssertResult(wide.writePixels(pm, 0,0));
1056 SkAssertResult(wide.peekPixels(&pm));
1057 }
1058
Mike Klein13b6afd2017-06-12 12:45:41 -04001059 SkPngEncoder::Options options;
1060 options.fComments = SkDataTable::MakeCopyArrays((const void**)comments, lengths, 4);
1061 options.fFilterFlags = SkPngEncoder::FilterFlag::kNone;
1062 options.fZLibLevel = 1;
Mike Klein13b6afd2017-06-12 12:45:41 -04001063 return SkPngEncoder::Encode(&dst, pm, options);
mtkleina5114d72015-08-24 13:27:01 -07001064}
1065
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
mtkleincd50bca2016-01-05 06:20:20 -08001137 SkString md5;
Brian Osman57796b32019-01-25 18:02:59 +00001138 if (!FLAGS_writePath.isEmpty() || !FLAGS_readPath.isEmpty()) {
mtkleincd50bca2016-01-05 06:20:20 -08001139 SkMD5 hash;
1140 if (data->getLength()) {
1141 hash.writeStream(data, data->getLength());
1142 data->rewind();
mtklein38408462015-07-08 07:25:27 -07001143 } else {
mtkleincd50bca2016-01-05 06:20:20 -08001144 // If we're BGRA (Linux, Windows), swizzle over to RGBA (Mac, Android).
1145 // This helps eliminate multiple 0-pixel-diff hashes on gold.skia.org.
1146 // (Android's general slow speed breaks the tie arbitrarily in RGBA's favor.)
1147 // We might consider promoting 565 to RGBA too.
1148 if (bitmap.colorType() == kBGRA_8888_SkColorType) {
1149 SkBitmap swizzle;
Matt Sarett68b8e3d2017-04-28 11:15:22 -04001150 SkAssertResult(sk_tool_utils::copy_to(&swizzle, kRGBA_8888_SkColorType,
1151 bitmap));
Mike Reedf0ffb892017-10-03 14:47:21 -04001152 hash.write(swizzle.getPixels(), swizzle.computeByteSize());
mtkleincd50bca2016-01-05 06:20:20 -08001153 } else {
Mike Reedf0ffb892017-10-03 14:47:21 -04001154 hash.write(bitmap.getPixels(), bitmap.computeByteSize());
mtkleincd50bca2016-01-05 06:20:20 -08001155 }
1156 }
1157 SkMD5::Digest digest;
1158 hash.finish(digest);
1159 for (int i = 0; i < 16; i++) {
1160 md5.appendf("%02x", digest.data[i]);
mtklein38408462015-07-08 07:25:27 -07001161 }
mtklein62bd1a62015-01-27 14:46:26 -08001162 }
mtklein62bd1a62015-01-27 14:46:26 -08001163
Brian Osman57796b32019-01-25 18:02:59 +00001164 if (!FLAGS_readPath.isEmpty() &&
1165 !gGold.contains(Gold(task.sink.tag, task.src.tag,
1166 task.src.options, name, md5))) {
1167 fail(SkStringPrintf("%s not found for %s %s %s %s in %s",
1168 md5.c_str(),
1169 task.sink.tag.c_str(),
1170 task.src.tag.c_str(),
1171 task.src.options.c_str(),
1172 name.c_str(),
1173 FLAGS_readPath[0]));
1174 }
1175
mtkleincd50bca2016-01-05 06:20:20 -08001176 if (!FLAGS_writePath.isEmpty()) {
mtklein21eaf3b2016-02-08 12:39:59 -08001177 const char* ext = task.sink->fileExtension();
Brian Osmanf1942de2017-08-30 14:50:22 -04001178 if (ext && !FLAGS_dont_write.contains(ext)) {
Mike Klein97d6a7a2017-07-24 10:37:19 -04001179 if (data->getLength()) {
1180 WriteToDisk(task, md5, ext, data, data->getLength(), nullptr);
1181 SkASSERT(bitmap.drawsNothing());
1182 } else if (!bitmap.drawsNothing()) {
1183 WriteToDisk(task, md5, ext, nullptr, 0, &bitmap);
1184 }
mtkleincd50bca2016-01-05 06:20:20 -08001185 }
1186 }
1187 });
mtklein748ca3b2015-01-15 10:56:12 -08001188 }
mtklein3eed7dd2016-02-24 19:07:07 -08001189 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 -08001190 }
1191
Mike Klein66f09a72019-02-12 13:03:54 -05001192 static SkString identify_gamut(SkColorSpace* cs) {
1193 if (!cs) {
1194 return SkString("untagged");
1195 }
1196
1197 skcms_Matrix3x3 gamut;
1198 if (cs->toXYZD50(&gamut)) {
1199 auto eq = [](skcms_Matrix3x3 x, skcms_Matrix3x3 y) {
1200 for (int i = 0; i < 3; i++)
1201 for (int j = 0; j < 3; j++) {
1202 if (x.vals[i][j] != y.vals[i][j]) { return false; }
1203 }
1204 return true;
1205 };
1206
1207 if (eq(gamut, SkNamedGamut::kSRGB )) { return SkString("sRGB"); }
1208 if (eq(gamut, SkNamedGamut::kAdobeRGB)) { return SkString("Adobe"); }
1209 if (eq(gamut, SkNamedGamut::kDCIP3 )) { return SkString("P3"); }
1210 if (eq(gamut, SkNamedGamut::kRec2020 )) { return SkString("2020"); }
1211 if (eq(gamut, SkNamedGamut::kXYZ )) { return SkString("XYZ"); }
1212 if (eq(gamut, gNarrow_toXYZD50 )) { return SkString("narrow"); }
1213 return SkString("other");
1214 }
1215 return SkString("non-XYZ");
1216 }
1217
1218 static SkString identify_transfer_fn(SkColorSpace* cs) {
1219 if (!cs) {
1220 return SkString("untagged");
1221 }
1222
1223 skcms_TransferFunction tf;
1224 if (cs->isNumericalTransferFn(&tf)) {
1225 auto eq = [](skcms_TransferFunction x, skcms_TransferFunction y) {
1226 return x.g == y.g
1227 && x.a == y.a
1228 && x.b == y.b
1229 && x.c == y.c
1230 && x.d == y.d
1231 && x.e == y.e
1232 && x.f == y.f;
1233 };
1234
1235 if (tf.a == 1 && tf.b == 0 && tf.c == 0 && tf.d == 0 && tf.e == 0 && tf.f == 0) {
1236 return SkStringPrintf("gamma %.3g", tf.g);
1237 }
1238 if (eq(tf, SkNamedTransferFn::kSRGB)) { return SkString("sRGB"); }
1239 if (eq(tf, k2020_TF )) { return SkString("2020"); }
1240 return SkStringPrintf("%.3g %.3g %.3g %.3g %.3g %.3g %.3g",
1241 tf.g, tf.a, tf.b, tf.c, tf.d, tf.e, tf.f);
1242 }
1243 return SkString("non-numeric");
1244 }
1245
mtklein748ca3b2015-01-15 10:56:12 -08001246 static void WriteToDisk(const Task& task,
mtklein62bd1a62015-01-27 14:46:26 -08001247 SkString md5,
1248 const char* ext,
mtklein748ca3b2015-01-15 10:56:12 -08001249 SkStream* data, size_t len,
mtklein62bd1a62015-01-27 14:46:26 -08001250 const SkBitmap* bitmap) {
Mike Klein66f09a72019-02-12 13:03:54 -05001251 SkColorSpace* cs = bitmap ? bitmap->info().colorSpace() : nullptr;
mtklein409d4702016-02-29 07:38:01 -08001252
mtklein748ca3b2015-01-15 10:56:12 -08001253 JsonWriter::BitmapResult result;
djsollen54416de2015-04-03 07:24:48 -07001254 result.name = task.src->name();
mtklein3eed7dd2016-02-24 19:07:07 -08001255 result.config = task.sink.tag;
djsollen54416de2015-04-03 07:24:48 -07001256 result.sourceType = task.src.tag;
1257 result.sourceOptions = task.src.options;
1258 result.ext = ext;
Mike Klein66f09a72019-02-12 13:03:54 -05001259 result.gamut = identify_gamut(cs);
1260 result.transferFn = identify_transfer_fn(cs);
djsollen54416de2015-04-03 07:24:48 -07001261 result.md5 = md5;
mtklein748ca3b2015-01-15 10:56:12 -08001262 JsonWriter::AddBitmapResult(result);
1263
mtkleinb0531a72015-04-07 13:38:48 -07001264 // If an MD5 is uninteresting, we want it noted in the JSON file,
1265 // but don't want to dump it out as a .png (or whatever ext is).
1266 if (gUninterestingHashes.contains(md5)) {
1267 return;
1268 }
1269
mtklein748ca3b2015-01-15 10:56:12 -08001270 const char* dir = FLAGS_writePath[0];
1271 if (0 == strcmp(dir, "@")) { // Needed for iOS.
1272 dir = FLAGS_resourcePath[0];
1273 }
1274 sk_mkdir(dir);
1275
1276 SkString path;
1277 if (FLAGS_nameByHash) {
1278 path = SkOSPath::Join(dir, result.md5.c_str());
1279 path.append(".");
1280 path.append(ext);
1281 if (sk_exists(path.c_str())) {
1282 return; // Content-addressed. If it exists already, we're done.
1283 }
1284 } else {
kkinnunen3e980c32015-12-23 01:33:00 -08001285 path = SkOSPath::Join(dir, task.sink.tag.c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001286 sk_mkdir(path.c_str());
msarett9e707a02015-09-01 14:57:57 -07001287 path = SkOSPath::Join(path.c_str(), task.src.tag.c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001288 sk_mkdir(path.c_str());
msarett9e707a02015-09-01 14:57:57 -07001289 if (strcmp(task.src.options.c_str(), "") != 0) {
1290 path = SkOSPath::Join(path.c_str(), task.src.options.c_str());
djsollen54416de2015-04-03 07:24:48 -07001291 sk_mkdir(path.c_str());
1292 }
mtklein748ca3b2015-01-15 10:56:12 -08001293 path = SkOSPath::Join(path.c_str(), task.src->name().c_str());
1294 path.append(".");
1295 path.append(ext);
1296 }
1297
mtklein748ca3b2015-01-15 10:56:12 -08001298 if (bitmap) {
mtkleina5114d72015-08-24 13:27:01 -07001299 if (!dump_png(*bitmap, path.c_str(), result.md5.c_str())) {
mtklein748ca3b2015-01-15 10:56:12 -08001300 fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str()));
1301 return;
1302 }
1303 } else {
mtkleina5114d72015-08-24 13:27:01 -07001304 SkFILEWStream file(path.c_str());
1305 if (!file.isValid()) {
1306 fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str()));
1307 return;
1308 }
mtklein748ca3b2015-01-15 10:56:12 -08001309 if (!file.writeStream(data, len)) {
1310 fail(SkStringPrintf("Can't write to %s.\n", path.c_str()));
1311 return;
1312 }
1313 }
1314 }
1315};
1316
mtklein748ca3b2015-01-15 10:56:12 -08001317/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1318
1319// Unit tests don't fit so well into the Src/Sink model, so we give them special treatment.
1320
mtklein21eaf3b2016-02-08 12:39:59 -08001321static SkTDArray<skiatest::Test> gParallelTests, gSerialTests;
mtklein748ca3b2015-01-15 10:56:12 -08001322
1323static void gather_tests() {
mtklein6c5fed22015-01-20 13:47:23 -08001324 if (!FLAGS_src.contains("tests")) {
mtklein748ca3b2015-01-15 10:56:12 -08001325 return;
1326 }
Hal Canary972eba32018-07-30 17:07:07 -04001327 for (const skiatest::Test& test : skiatest::TestRegistry::Range()) {
mtklein6393c062015-04-27 08:45:01 -07001328 if (!in_shard()) {
1329 continue;
1330 }
halcanary87f3ba42015-01-20 09:30:20 -08001331 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, test.name)) {
mtklein748ca3b2015-01-15 10:56:12 -08001332 continue;
1333 }
Brian Osmanc7ad40f2018-05-31 14:27:17 -04001334 if (test.needsGpu && FLAGS_gpu) {
Mike Reed5edcd312018-08-08 11:23:41 -04001335 (FLAGS_gpu_threading ? gParallelTests : gSerialTests).push_back(test);
halcanary87f3ba42015-01-20 09:30:20 -08001336 } else if (!test.needsGpu && FLAGS_cpu) {
Mike Reed5edcd312018-08-08 11:23:41 -04001337 gParallelTests.push_back(test);
mtklein82d28432015-01-15 12:46:02 -08001338 }
mtklein748ca3b2015-01-15 10:56:12 -08001339 }
1340}
1341
csmartdalton008b9d82017-02-22 12:00:42 -07001342static void run_test(skiatest::Test test, const GrContextOptions& grCtxOptions) {
halcanary87f3ba42015-01-20 09:30:20 -08001343 struct : public skiatest::Reporter {
mtklein36352bf2015-03-25 18:17:31 -07001344 void reportFailed(const skiatest::Failure& failure) override {
halcanary87f3ba42015-01-20 09:30:20 -08001345 fail(failure.toString());
1346 JsonWriter::AddTestFailure(failure);
1347 }
mtklein36352bf2015-03-25 18:17:31 -07001348 bool allowExtendedTest() const override {
halcanary87f3ba42015-01-20 09:30:20 -08001349 return FLAGS_pathOpsExtended;
1350 }
mtklein36352bf2015-03-25 18:17:31 -07001351 bool verbose() const override { return FLAGS_veryVerbose; }
halcanary87f3ba42015-01-20 09:30:20 -08001352 } reporter;
djsollen824996a2015-06-12 12:06:22 -07001353
mtklein3eed7dd2016-02-24 19:07:07 -08001354 if (!FLAGS_dryRun && !is_blacklisted("_", "tests", "_", test.name)) {
Robert Phillipsec325342017-10-30 18:02:48 +00001355 GrContextOptions options = grCtxOptions;
1356 test.modifyGrContextOptions(&options);
1357
mtklein21eaf3b2016-02-08 12:39:59 -08001358 start("unit", "test", "", test.name);
Brian Salomondcfca432017-11-15 15:48:03 -05001359 test.run(&reporter, options);
mtklein748ca3b2015-01-15 10:56:12 -08001360 }
mtklein3eed7dd2016-02-24 19:07:07 -08001361 done("unit", "test", "", test.name);
mtklein748ca3b2015-01-15 10:56:12 -08001362}
1363
1364/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1365
Mike Kleinbe28ee22017-02-06 12:46:20 -05001366int main(int argc, char** argv) {
Dongwon Kang0c7861f2018-02-16 10:55:21 -08001367#if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && defined(SK_HAS_HEIF_LIBRARY)
1368 android::ProcessState::self()->startThreadPool();
1369#endif
Mike Kleinbe28ee22017-02-06 12:46:20 -05001370 SkCommandLineFlags::Parse(argc, argv);
Brian Osman53136aa2017-07-20 15:43:35 -04001371
Mike Klein31868212017-11-06 12:02:47 -05001372 if (!FLAGS_nativeFonts) {
Ben Wagner483c7722018-02-20 17:06:07 -05001373 gSkFontMgr_DefaultFactory = &sk_tool_utils::MakePortableFontMgr;
Mike Klein31868212017-11-06 12:02:47 -05001374 }
1375
Mike Klein0c5fdcb2017-11-13 12:40:46 -05001376#if defined(SK_BUILD_FOR_WIN)
1377 if (FLAGS_gdi) {
Hal Canaryccafca02017-11-14 10:34:48 -05001378 gSkFontMgr_DefaultFactory = &SkFontMgr_New_GDI;
Mike Klein0c5fdcb2017-11-13 12:40:46 -05001379 }
1380#endif
1381
Brian Osmanbc8150f2017-07-24 11:38:01 -04001382 initializeEventTracingForTools();
Brian Osman53136aa2017-07-20 15:43:35 -04001383
Mike Klein6613cc52017-12-19 09:09:33 -05001384#if !defined(SK_BUILD_FOR_GOOGLE3) && defined(SK_BUILD_FOR_IOS)
Mike Kleinadacaef2017-02-06 09:26:14 -05001385 cd_Documents();
1386#endif
bsalomon71de3532016-04-26 14:27:21 -07001387 setbuf(stdout, nullptr);
mtklein246ba3a2016-02-23 10:39:36 -08001388 setup_crash_handler();
mtkleinafae30a2016-02-24 12:28:32 -08001389
Yuqian Liba62b4a2016-12-14 13:46:53 -05001390 gSkUseAnalyticAA = FLAGS_analyticAA;
Yuqian Lidf60e362017-07-25 11:26:31 -04001391 gSkUseDeltaAA = FLAGS_deltaAA;
liyuqian38911a72016-10-04 11:23:22 -07001392
Yuqian Li550148b2017-01-13 10:13:13 -05001393 if (FLAGS_forceAnalyticAA) {
1394 gSkForceAnalyticAA = true;
1395 }
Yuqian Lia81b6262017-09-06 17:10:05 -04001396 if (FLAGS_forceDeltaAA) {
1397 gSkForceDeltaAA = true;
1398 }
Mike Reed7c26ca72017-07-05 15:45:52 -04001399 if (FLAGS_forceRasterPipeline) {
1400 gSkForceRasterPipelineBlitter = true;
1401 }
Yuqian Li550148b2017-01-13 10:13:13 -05001402
Mike Kleine9f187b2017-06-26 13:23:12 -04001403 // The bots like having a verbose.log to upload, so always touch the file even if --verbose.
1404 if (!FLAGS_writePath.isEmpty()) {
mtklein51c8cfc2016-03-11 12:59:09 -08001405 sk_mkdir(FLAGS_writePath[0]);
mtkleina1ce2162016-07-22 12:23:46 -07001406 gVLog = fopen(SkOSPath::Join(FLAGS_writePath[0], "verbose.log").c_str(), "w");
mtkleinc41fd922016-03-08 09:01:39 -08001407 }
Mike Kleine9f187b2017-06-26 13:23:12 -04001408 if (FLAGS_verbose) {
1409 gVLog = stderr;
1410 }
mtkleinc41fd922016-03-08 09:01:39 -08001411
csmartdalton008b9d82017-02-22 12:00:42 -07001412 GrContextOptions grCtxOptions;
Chris Dalton040238b2017-12-18 14:22:34 -07001413 SetCtxOptionsFromCommonFlags(&grCtxOptions);
csmartdalton008b9d82017-02-22 12:00:42 -07001414
mtklein5286f022016-01-22 08:18:14 -08001415 JsonWriter::DumpJson(); // It's handy for the bots to assume this is ~never missing.
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +00001416 SkAutoGraphics ag;
mtklein406654b2014-09-03 15:34:37 -07001417 SkTaskGroup::Enabler enabled(FLAGS_threads);
commit-bot@chromium.orga65e2fd2014-05-30 17:23:31 +00001418
Mike Reed0933bc92017-12-09 01:27:41 +00001419 if (nullptr == GetResourceAsData("images/color_wheel.png")) {
1420 info("Some resources are missing. Do you need to set --resourcePath?\n");
halcanary7d571242016-02-24 17:59:16 -08001421 }
Brian Osman57796b32019-01-25 18:02:59 +00001422 gather_gold();
borenet09ed4802015-04-03 14:15:33 -07001423 gather_uninteresting_hashes();
mtklein62bd1a62015-01-27 14:46:26 -08001424
scroggo86737142016-02-03 12:19:11 -08001425 if (!gather_srcs()) {
1426 return 1;
1427 }
Ben Wagnerf28d4722017-08-11 17:33:22 -04001428 // TODO(dogben): This is a bit ugly. Find a cleaner way to do this.
1429 bool defaultConfigs = true;
1430 for (int i = 0; i < argc; i++) {
1431 static const char* kConfigArg = "--config";
1432 if (strcmp(argv[i], kConfigArg) == 0) {
1433 defaultConfigs = false;
1434 break;
1435 }
1436 }
1437 if (!gather_sinks(grCtxOptions, defaultConfigs)) {
brianosman05c987c2016-05-09 13:42:16 -07001438 return 1;
1439 }
mtklein748ca3b2015-01-15 10:56:12 -08001440 gather_tests();
mtklein21eaf3b2016-02-08 12:39:59 -08001441 gPending = gSrcs.count() * gSinks.count() + gParallelTests.count() + gSerialTests.count();
Brian Osmand0677bc2017-08-03 12:13:47 -04001442 info("%d srcs * %d sinks + %d tests == %d tasks\n",
mtkleinc41fd922016-03-08 09:01:39 -08001443 gSrcs.count(), gSinks.count(), gParallelTests.count() + gSerialTests.count(), gPending);
mtklein748ca3b2015-01-15 10:56:12 -08001444
mtklein21eaf3b2016-02-08 12:39:59 -08001445 // Kick off as much parallel work as we can, making note of any serial work we'll need to do.
1446 SkTaskGroup parallel;
1447 SkTArray<Task> serial;
1448
1449 for (auto& sink : gSinks)
1450 for (auto& src : gSrcs) {
mtklein3eed7dd2016-02-24 19:07:07 -08001451 if (src->veto(sink->flags()) ||
1452 is_blacklisted(sink.tag.c_str(), src.tag.c_str(),
1453 src.options.c_str(), src->name().c_str())) {
mtkleinf10637f2016-06-10 13:56:35 -07001454 SkAutoMutexAcquire lock(gMutex);
mtklein3eed7dd2016-02-24 19:07:07 -08001455 gPending--;
1456 continue;
1457 }
1458
mtklein21eaf3b2016-02-08 12:39:59 -08001459 Task task(src, sink);
1460 if (src->serial() || sink->serial()) {
1461 serial.push_back(task);
1462 } else {
1463 parallel.add([task] { Task::Run(task); });
mtklein748ca3b2015-01-15 10:56:12 -08001464 }
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001465 }
mtklein21eaf3b2016-02-08 12:39:59 -08001466 for (auto test : gParallelTests) {
csmartdalton008b9d82017-02-22 12:00:42 -07001467 parallel.add([test, grCtxOptions] { run_test(test, grCtxOptions); });
mtklein55e88b22015-01-21 15:50:13 -08001468 }
mtklein21eaf3b2016-02-08 12:39:59 -08001469
1470 // With the parallel work running, run serial tasks and tests here on main thread.
1471 for (auto task : serial) { Task::Run(task); }
csmartdalton008b9d82017-02-22 12:00:42 -07001472 for (auto test : gSerialTests) { run_test(test, grCtxOptions); }
mtklein21eaf3b2016-02-08 12:39:59 -08001473
1474 // Wait for any remaining parallel work to complete (including any spun off of serial tasks).
1475 parallel.wait();
mtkleincd50bca2016-01-05 06:20:20 -08001476 gDefinitelyThreadSafeWork.wait();
1477
Ben Wagner83c6b962018-07-10 19:40:15 -04001478 // At this point we're back in single-threaded land.
1479
mtkleinda884c42016-02-24 18:00:23 -08001480 // We'd better have run everything.
1481 SkASSERT(gPending == 0);
mtkleine027f172016-02-26 15:53:06 -08001482 // Make sure we've flushed all our results to disk.
1483 JsonWriter::DumpJson();
mtkleinda884c42016-02-24 18:00:23 -08001484
mtklein748ca3b2015-01-15 10:56:12 -08001485 if (gFailures.count() > 0) {
mtkleinc41fd922016-03-08 09:01:39 -08001486 info("Failures:\n");
mtklein748ca3b2015-01-15 10:56:12 -08001487 for (int i = 0; i < gFailures.count(); i++) {
mtkleinc41fd922016-03-08 09:01:39 -08001488 info("\t%s\n", gFailures[i].c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001489 }
mtkleinc41fd922016-03-08 09:01:39 -08001490 info("%d failures\n", gFailures.count());
mtklein748ca3b2015-01-15 10:56:12 -08001491 return 1;
mtklein114c3cd2015-01-15 10:15:02 -08001492 }
mtkleinafae30a2016-02-24 12:28:32 -08001493
Herb Derby5a523fe2017-01-26 16:48:28 -05001494 SkGraphics::PurgeAllCaches();
mtkleinc41fd922016-03-08 09:01:39 -08001495 info("Finished!\n");
Brian Osman53136aa2017-07-20 15:43:35 -04001496
mtklein748ca3b2015-01-15 10:56:12 -08001497 return 0;
mtklein@google.comd36522d2013-10-16 13:02:15 +00001498}