blob: ab7b46ea0ec1e43fc8ec075803497ea205915197 [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
halcanary7a14b312015-10-01 07:28:13 -070048#ifdef SK_PDF_IMAGE_STATS
49extern void SkPDFImageDumpStats();
50#endif
51
mtkleina5114d72015-08-24 13:27:01 -070052#include "png.h"
53
bungeman60e0fee2015-08-26 05:15:46 -070054#include <stdlib.h>
55
Mike Klein8f11d4d2018-01-24 12:42:55 -050056#ifndef SK_BUILD_FOR_WIN
scroggo27a58342015-10-28 08:56:41 -070057 #include <unistd.h>
58#endif
59
Dongwon Kang0c7861f2018-02-16 10:55:21 -080060#if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && defined(SK_HAS_HEIF_LIBRARY)
61#include <binder/IPCThreadState.h>
62#endif
63
Mike Reed7c26ca72017-07-05 15:45:52 -040064extern bool gSkForceRasterPipelineBlitter;
65
Ben Wagner32fa5102017-08-10 21:25:55 -040066DECLARE_bool(undefok);
djsollen54416de2015-04-03 07:24:48 -070067DEFINE_string(src, "tests gm skp image", "Source types to test.");
mtklein748ca3b2015-01-15 10:56:12 -080068DEFINE_bool(nameByHash, false,
69 "If true, write to FLAGS_writePath[0]/<hash>.png instead of "
djsollen54416de2015-04-03 07:24:48 -070070 "to FLAGS_writePath[0]/<config>/<sourceType>/<sourceOptions>/<name>.png");
mtklein748ca3b2015-01-15 10:56:12 -080071DEFINE_bool2(pathOpsExtended, x, false, "Run extended pathOps tests.");
mtkleind603b222015-02-17 11:13:33 -080072DEFINE_string(matrix, "1 0 0 1",
73 "2x2 scale+skew matrix to apply or upright when using "
74 "'matrix' or 'upright' in config.");
mtklein82d28432015-01-15 12:46:02 -080075DEFINE_bool(gpu_threading, false, "Allow GPU work to run on multiple threads?");
mtklein@google.comd36522d2013-10-16 13:02:15 +000076
mtkleina2ef6422015-01-15 13:44:22 -080077DEFINE_string(blacklist, "",
Chris Daltonecf78ac2017-08-15 15:43:08 -060078 "Space-separated config/src/srcOptions/name quadruples to blacklist. "
79 "'_' matches anything. '~' negates the match. E.g. \n"
djsollen54416de2015-04-03 07:24:48 -070080 "'--blacklist gpu skp _ _' will blacklist all SKPs drawn into the gpu config.\n"
Chris Daltonecf78ac2017-08-15 15:43:08 -060081 "'--blacklist gpu skp _ _ 8888 gm _ aarects' will also blacklist the aarects GM on 8888.\n"
82 "'--blacklist ~8888 svg _ svgparse_' blocks non-8888 SVGs that contain \"svgparse_\" in "
83 "the name.");
mtkleina2ef6422015-01-15 13:44:22 -080084
mtklein62bd1a62015-01-27 14:46:26 -080085DEFINE_string2(readPath, r, "", "If set check for equality with golden results in this directory.");
86
borenet09ed4802015-04-03 14:15:33 -070087DEFINE_string(uninterestingHashesFile, "",
88 "File containing a list of uninteresting hashes. If a result hashes to something in "
89 "this list, no image is written for that result.");
90
mtklein6393c062015-04-27 08:45:01 -070091DEFINE_int32(shards, 1, "We're splitting source data into this many shards.");
92DEFINE_int32(shard, 0, "Which shard do I run?");
93
halcanary45420a92016-06-02 12:41:14 -070094DEFINE_string(mskps, "", "Directory to read mskps from, or a single mskp file.");
Mike Reed7c26ca72017-07-05 15:45:52 -040095DEFINE_bool(forceRasterPipeline, false, "sets gSkForceRasterPipelineBlitter");
halcanary45420a92016-06-02 12:41:14 -070096
Chris Dalton184c37e2018-09-28 11:27:39 -060097DEFINE_string(bisect, "",
98 "Pair of: SKP file to bisect, followed by an l/r bisect trail string (e.g., 'lrll'). The "
99 "l/r trail specifies which half to keep at each step of a binary search through the SKP's "
100 "paths. An empty string performs no bisect. Only the SkPaths are bisected; all other draws "
101 "are thrown out. This is useful for finding a reduced repo case for path drawing bugs.");
102
Derek Sollenbergeredfe3df2017-07-19 15:25:24 -0400103DEFINE_bool(ignoreSigInt, false, "ignore SIGINT signals during test execution");
104
Mike Klein97d6a7a2017-07-24 10:37:19 -0400105DEFINE_string(dont_write, "", "File extensions to skip writing to --writePath."); // See skia:6821
106
Mike Klein0c5fdcb2017-11-13 12:40:46 -0500107DEFINE_bool(gdi, false, "On Windows, use GDI instead of DirectWrite for font rendering.");
Mike Klein31868212017-11-06 12:02:47 -0500108
mtklein748ca3b2015-01-15 10:56:12 -0800109using namespace DM;
bsalomon3724e572016-03-30 18:56:19 -0700110using sk_gpu_test::GrContextFactory;
bsalomon273c0f52016-03-31 10:59:06 -0700111using sk_gpu_test::GLTestContext;
bsalomonf2f1c172016-04-05 12:59:06 -0700112using sk_gpu_test::ContextInfo;
mtklein@google.comd36522d2013-10-16 13:02:15 +0000113
mtklein748ca3b2015-01-15 10:56:12 -0800114/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
115
mtkleinc41fd922016-03-08 09:01:39 -0800116static FILE* gVLog;
117
118template <typename... Args>
119static void vlog(const char* fmt, Args&&... args) {
120 if (gVLog) {
mtkleinc41fd922016-03-08 09:01:39 -0800121 fprintf(gVLog, fmt, args...);
122 fflush(gVLog);
123 }
124}
125
126template <typename... Args>
127static void info(const char* fmt, Args&&... args) {
128 vlog(fmt, args...);
129 if (!FLAGS_quiet) {
130 printf(fmt, args...);
131 }
132}
133static void info(const char* fmt) {
134 if (!FLAGS_quiet) {
135 printf("%s", fmt); // Clang warns printf(fmt) is insecure.
136 }
137}
138
reed086eea92016-05-04 17:12:46 -0700139SK_DECLARE_STATIC_MUTEX(gFailuresMutex);
mtklein748ca3b2015-01-15 10:56:12 -0800140static SkTArray<SkString> gFailures;
141
mtklein3eed7dd2016-02-24 19:07:07 -0800142static void fail(const SkString& err) {
mtklein748ca3b2015-01-15 10:56:12 -0800143 SkAutoMutexAcquire lock(gFailuresMutex);
144 SkDebugf("\n\nFAILURE: %s\n\n", err.c_str());
145 gFailures.push_back(err);
halcanary9e398f72015-01-10 11:18:04 -0800146}
147
mtklein0f7748a2016-07-25 15:27:29 -0700148struct Running {
149 SkString id;
150 SkThreadID thread;
151
152 void dump() const {
153 info("\t%s\n", id.c_str());
154 }
155};
mtkleinb37cb412015-03-18 05:27:14 -0700156
mtklein246ba3a2016-02-23 10:39:36 -0800157// We use a spinlock to make locking this in a signal handler _somewhat_ safe.
Mike Klein03a95ad2017-06-23 12:36:32 -0400158static SkSpinlock gMutex;
159static int gPending;
mtklein0f7748a2016-07-25 15:27:29 -0700160static SkTArray<Running> gRunning;
mtklein748ca3b2015-01-15 10:56:12 -0800161
mtklein3eed7dd2016-02-24 19:07:07 -0800162static void done(const char* config, const char* src, const char* srcOptions, const char* name) {
163 SkString id = SkStringPrintf("%s %s %s %s", config, src, srcOptions, name);
mtkleinc41fd922016-03-08 09:01:39 -0800164 vlog("done %s\n", id.c_str());
mtkleinafae30a2016-02-24 12:28:32 -0800165 int pending;
mtkleinb37cb412015-03-18 05:27:14 -0700166 {
mtkleinf10637f2016-06-10 13:56:35 -0700167 SkAutoMutexAcquire lock(gMutex);
mtkleinb37cb412015-03-18 05:27:14 -0700168 for (int i = 0; i < gRunning.count(); i++) {
mtklein0f7748a2016-07-25 15:27:29 -0700169 if (gRunning[i].id == id) {
mtkleinb37cb412015-03-18 05:27:14 -0700170 gRunning.removeShuffle(i);
171 break;
172 }
173 }
mtkleinafae30a2016-02-24 12:28:32 -0800174 pending = --gPending;
reed50bc0512015-05-19 14:13:31 -0700175 }
Mike Klein03a95ad2017-06-23 12:36:32 -0400176
177 // We write out dm.json file and print out a progress update every once in a while.
178 // Notice this also handles the final dm.json and progress update when pending == 0.
mtkleina17241b2015-01-23 05:48:00 -0800179 if (pending % 500 == 0) {
180 JsonWriter::DumpJson();
Mike Klein03a95ad2017-06-23 12:36:32 -0400181
182 int curr = sk_tools::getCurrResidentSetSizeMB(),
183 peak = sk_tools::getMaxResidentSetSizeMB();
Mike Klein03a95ad2017-06-23 12:36:32 -0400184
185 SkAutoMutexAcquire lock(gMutex);
Mike Klein21ba7722018-10-02 13:57:44 +0000186 info("\n%dMB RAM, %dMB peak, %d queued, %d active:\n",
187 curr, peak, gPending - gRunning.count(), gRunning.count());
Mike Klein03a95ad2017-06-23 12:36:32 -0400188 for (auto& task : gRunning) {
189 task.dump();
190 }
mtkleina17241b2015-01-23 05:48:00 -0800191 }
mtklein@google.comd36522d2013-10-16 13:02:15 +0000192}
193
mtklein3eed7dd2016-02-24 19:07:07 -0800194static void start(const char* config, const char* src, const char* srcOptions, const char* name) {
195 SkString id = SkStringPrintf("%s %s %s %s", config, src, srcOptions, name);
mtkleinc41fd922016-03-08 09:01:39 -0800196 vlog("start %s\n", id.c_str());
mtkleinf10637f2016-06-10 13:56:35 -0700197 SkAutoMutexAcquire lock(gMutex);
mtklein0f7748a2016-07-25 15:27:29 -0700198 gRunning.push_back({id,SkGetThreadID()});
mtkleinb37cb412015-03-18 05:27:14 -0700199}
200
Mike Klein3cc2d202016-10-24 11:39:43 -0400201static void find_culprit() {
202 // Assumes gMutex is locked.
203 SkThreadID thisThread = SkGetThreadID();
204 for (auto& task : gRunning) {
205 if (task.thread == thisThread) {
206 info("Likely culprit:\n");
207 task.dump();
mtklein0f7748a2016-07-25 15:27:29 -0700208 }
209 }
Mike Klein3cc2d202016-10-24 11:39:43 -0400210}
mtklein0f7748a2016-07-25 15:27:29 -0700211
Mike Klein8f11d4d2018-01-24 12:42:55 -0500212#if defined(SK_BUILD_FOR_WIN)
mtklein5b64dab2016-06-09 08:59:48 -0700213 static LONG WINAPI crash_handler(EXCEPTION_POINTERS* e) {
mtkleinf8557292016-02-29 06:35:28 -0800214 static const struct {
215 const char* name;
robertphillips75467862016-03-01 14:10:23 -0800216 DWORD code;
mtkleinf8557292016-02-29 06:35:28 -0800217 } kExceptions[] = {
218 #define _(E) {#E, E}
219 _(EXCEPTION_ACCESS_VIOLATION),
220 _(EXCEPTION_BREAKPOINT),
221 _(EXCEPTION_INT_DIVIDE_BY_ZERO),
222 _(EXCEPTION_STACK_OVERFLOW),
223 // TODO: more?
224 #undef _
225 };
226
mtkleinf10637f2016-06-10 13:56:35 -0700227 SkAutoMutexAcquire lock(gMutex);
mtklein5b64dab2016-06-09 08:59:48 -0700228
229 const DWORD code = e->ExceptionRecord->ExceptionCode;
230 info("\nCaught exception %u", code);
231 for (const auto& exception : kExceptions) {
232 if (exception.code == code) {
233 info(" %s", exception.name);
mtkleinf8557292016-02-29 06:35:28 -0800234 }
mtkleinf8557292016-02-29 06:35:28 -0800235 }
mtklein5b64dab2016-06-09 08:59:48 -0700236 info(", was running:\n");
237 for (auto& task : gRunning) {
mtklein0f7748a2016-07-25 15:27:29 -0700238 task.dump();
mtklein5b64dab2016-06-09 08:59:48 -0700239 }
mtklein0f7748a2016-07-25 15:27:29 -0700240 find_culprit();
mtklein5b64dab2016-06-09 08:59:48 -0700241 fflush(stdout);
242
mtkleinf8557292016-02-29 06:35:28 -0800243 // Execute default exception handler... hopefully, exit.
244 return EXCEPTION_EXECUTE_HANDLER;
mtklein246ba3a2016-02-23 10:39:36 -0800245 }
246
Mike Klein3cc2d202016-10-24 11:39:43 -0400247 static void setup_crash_handler() {
248 SetUnhandledExceptionFilter(crash_handler);
249 }
250#else
mtklein246ba3a2016-02-23 10:39:36 -0800251 #include <signal.h>
Mike Klein3cc2d202016-10-24 11:39:43 -0400252 #if !defined(SK_BUILD_FOR_ANDROID)
253 #include <execinfo.h>
Brian Salomondcbb9d92017-07-19 10:53:20 -0400254
255#endif
Mike Klein3cc2d202016-10-24 11:39:43 -0400256
257 static constexpr int max_of() { return 0; }
258 template <typename... Rest>
259 static constexpr int max_of(int x, Rest... rest) {
260 return x > max_of(rest...) ? x : max_of(rest...);
261 }
262
Mike Kleinc7278ad2018-02-15 09:26:54 -0500263 static void (*previous_handler[max_of(SIGABRT,SIGBUS,SIGFPE,SIGILL,SIGSEGV,SIGTERM)+1])(int);
mtkleinf8557292016-02-29 06:35:28 -0800264
mtklein5b64dab2016-06-09 08:59:48 -0700265 static void crash_handler(int sig) {
mtkleinf10637f2016-06-10 13:56:35 -0700266 SkAutoMutexAcquire lock(gMutex);
mtklein5b64dab2016-06-09 08:59:48 -0700267
Mike Klein701a3582018-06-28 14:08:19 +0000268 info("\nCaught signal %d [%s] (%dMB RAM, peak %dMB), was running:\n",
269 sig, strsignal(sig),
270 sk_tools::getCurrResidentSetSizeMB(), sk_tools::getMaxResidentSetSizeMB());
271
mtklein5b64dab2016-06-09 08:59:48 -0700272 for (auto& task : gRunning) {
mtklein0f7748a2016-07-25 15:27:29 -0700273 task.dump();
mtklein5b64dab2016-06-09 08:59:48 -0700274 }
mtklein0f7748a2016-07-25 15:27:29 -0700275 find_culprit();
mtklein5b64dab2016-06-09 08:59:48 -0700276
Mike Klein3cc2d202016-10-24 11:39:43 -0400277 #if !defined(SK_BUILD_FOR_ANDROID)
mtklein5b64dab2016-06-09 08:59:48 -0700278 void* stack[64];
279 int count = backtrace(stack, SK_ARRAY_COUNT(stack));
280 char** symbols = backtrace_symbols(stack, count);
281 info("\nStack trace:\n");
282 for (int i = 0; i < count; i++) {
283 info(" %s\n", symbols[i]);
284 }
Mike Klein3cc2d202016-10-24 11:39:43 -0400285 #endif
mtklein5b64dab2016-06-09 08:59:48 -0700286 fflush(stdout);
287
Mike Klein3cc2d202016-10-24 11:39:43 -0400288 signal(sig, previous_handler[sig]);
289 raise(sig);
mtklein5b64dab2016-06-09 08:59:48 -0700290 }
291
mtklein246ba3a2016-02-23 10:39:36 -0800292 static void setup_crash_handler() {
Mike Klein701a3582018-06-28 14:08:19 +0000293 const int kSignals[] = { SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGINT, SIGSEGV, SIGTERM };
mtklein246ba3a2016-02-23 10:39:36 -0800294 for (int sig : kSignals) {
Mike Klein3cc2d202016-10-24 11:39:43 -0400295 previous_handler[sig] = signal(sig, crash_handler);
mtklein246ba3a2016-02-23 10:39:36 -0800296 }
Derek Sollenbergeredfe3df2017-07-19 15:25:24 -0400297
298 if (FLAGS_ignoreSigInt) {
299 signal(SIGINT, SIG_IGN);
300 }
mtklein246ba3a2016-02-23 10:39:36 -0800301 }
302#endif
303
mtklein748ca3b2015-01-15 10:56:12 -0800304/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
mtklein114c3cd2015-01-15 10:15:02 -0800305
mtklein62bd1a62015-01-27 14:46:26 -0800306struct Gold : public SkString {
mtkleina82f5622015-02-20 12:30:19 -0800307 Gold() : SkString("") {}
mtklein3eed7dd2016-02-24 19:07:07 -0800308 Gold(const SkString& sink, const SkString& src,
309 const SkString& srcOptions, const SkString& name,
310 const SkString& md5)
mtklein62bd1a62015-01-27 14:46:26 -0800311 : SkString("") {
312 this->append(sink);
313 this->append(src);
djsollen54416de2015-04-03 07:24:48 -0700314 this->append(srcOptions);
mtklein62bd1a62015-01-27 14:46:26 -0800315 this->append(name);
316 this->append(md5);
mtklein62bd1a62015-01-27 14:46:26 -0800317 }
mtkleinc8d1dd42015-10-15 12:23:01 -0700318 struct Hash {
319 uint32_t operator()(const Gold& g) const {
320 return SkGoodHash()((const SkString&)g);
321 }
322 };
mtklein62bd1a62015-01-27 14:46:26 -0800323};
mtkleina82f5622015-02-20 12:30:19 -0800324static SkTHashSet<Gold, Gold::Hash> gGold;
mtklein62bd1a62015-01-27 14:46:26 -0800325
326static void add_gold(JsonWriter::BitmapResult r) {
djsollen54416de2015-04-03 07:24:48 -0700327 gGold.add(Gold(r.config, r.sourceType, r.sourceOptions, r.name, r.md5));
mtklein62bd1a62015-01-27 14:46:26 -0800328}
329
330static void gather_gold() {
331 if (!FLAGS_readPath.isEmpty()) {
332 SkString path(FLAGS_readPath[0]);
333 path.append("/dm.json");
334 if (!JsonWriter::ReadJson(path.c_str(), add_gold)) {
335 fail(SkStringPrintf("Couldn't read %s for golden results.", path.c_str()));
336 }
337 }
338}
339
340/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
341
Mike Klein8f11d4d2018-01-24 12:42:55 -0500342#if defined(SK_BUILD_FOR_WIN)
mtklein935f1b12016-03-16 08:37:19 -0700343 static const char* kNewline = "\r\n";
344#else
345 static const char* kNewline = "\n";
346#endif
347
borenet09ed4802015-04-03 14:15:33 -0700348static SkTHashSet<SkString> gUninterestingHashes;
349
350static void gather_uninteresting_hashes() {
351 if (!FLAGS_uninterestingHashesFile.isEmpty()) {
bungeman38d909e2016-08-02 14:40:46 -0700352 sk_sp<SkData> data(SkData::MakeFromFileName(FLAGS_uninterestingHashesFile[0]));
mtkleincc334b32015-09-22 11:43:53 -0700353 if (!data) {
mtkleinc41fd922016-03-08 09:01:39 -0800354 info("WARNING: unable to read uninteresting hashes from %s\n",
355 FLAGS_uninterestingHashesFile[0]);
mtkleincc334b32015-09-22 11:43:53 -0700356 return;
357 }
Mike Klein45dcc0c2017-04-05 18:04:31 -0400358
359 // Copy to a string to make sure SkStrSplit has a terminating \0 to find.
360 SkString contents((const char*)data->data(), data->size());
361
borenet09ed4802015-04-03 14:15:33 -0700362 SkTArray<SkString> hashes;
Mike Klein45dcc0c2017-04-05 18:04:31 -0400363 SkStrSplit(contents.c_str(), kNewline, &hashes);
borenet09ed4802015-04-03 14:15:33 -0700364 for (const SkString& hash : hashes) {
365 gUninterestingHashes.add(hash);
366 }
mtkleinc41fd922016-03-08 09:01:39 -0800367 info("FYI: loaded %d distinct uninteresting hashes from %d lines\n",
368 gUninterestingHashes.count(), hashes.count());
borenet09ed4802015-04-03 14:15:33 -0700369 }
370}
371
372/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
373
Ben Wagner145dbcd2016-11-03 14:40:50 -0400374struct TaggedSrc : public std::unique_ptr<Src> {
mtklein3eed7dd2016-02-24 19:07:07 -0800375 SkString tag;
376 SkString options;
mtkleine0effd62015-07-29 06:37:28 -0700377};
378
Ben Wagner145dbcd2016-11-03 14:40:50 -0400379struct TaggedSink : public std::unique_ptr<Sink> {
kkinnunen3e980c32015-12-23 01:33:00 -0800380 SkString tag;
djsollen54416de2015-04-03 07:24:48 -0700381};
mtklein748ca3b2015-01-15 10:56:12 -0800382
383static const bool kMemcpyOK = true;
384
mtkleine0effd62015-07-29 06:37:28 -0700385static SkTArray<TaggedSrc, kMemcpyOK> gSrcs;
386static SkTArray<TaggedSink, kMemcpyOK> gSinks;
mtklein748ca3b2015-01-15 10:56:12 -0800387
mtklein6393c062015-04-27 08:45:01 -0700388static bool in_shard() {
389 static int N = 0;
390 return N++ % FLAGS_shards == FLAGS_shard;
391}
392
mtklein3eed7dd2016-02-24 19:07:07 -0800393static void push_src(const char* tag, ImplicitString options, Src* s) {
Ben Wagner145dbcd2016-11-03 14:40:50 -0400394 std::unique_ptr<Src> src(s);
mtklein6393c062015-04-27 08:45:01 -0700395 if (in_shard() &&
mtklein3eed7dd2016-02-24 19:07:07 -0800396 FLAGS_src.contains(tag) &&
mtklein748ca3b2015-01-15 10:56:12 -0800397 !SkCommandLineFlags::ShouldSkip(FLAGS_match, src->name().c_str())) {
mtkleine0effd62015-07-29 06:37:28 -0700398 TaggedSrc& s = gSrcs.push_back();
mtklein18300a32016-03-16 13:53:35 -0700399 s.reset(src.release());
mtklein748ca3b2015-01-15 10:56:12 -0800400 s.tag = tag;
djsollen54416de2015-04-03 07:24:48 -0700401 s.options = options;
mtklein114c3cd2015-01-15 10:15:02 -0800402 }
mtklein748ca3b2015-01-15 10:56:12 -0800403}
mtklein114c3cd2015-01-15 10:15:02 -0800404
msarett9e707a02015-09-01 14:57:57 -0700405static void push_codec_src(Path path, CodecSrc::Mode mode, CodecSrc::DstColorType dstColorType,
scroggoc5560be2016-02-03 09:42:42 -0800406 SkAlphaType dstAlphaType, float scale) {
scroggoe4499842016-02-25 11:03:47 -0800407 if (FLAGS_simpleCodec) {
scroggo19b91532016-10-24 09:03:26 -0700408 const bool simple = CodecSrc::kCodec_Mode == mode || CodecSrc::kAnimated_Mode == mode;
409 if (!simple || dstColorType != CodecSrc::kGetFromCanvas_DstColorType || scale != 1.0f) {
scroggoe4499842016-02-25 11:03:47 -0800410 // Only decode in the simple case.
411 return;
scroggo19b91532016-10-24 09:03:26 -0700412 }
scroggoe4499842016-02-25 11:03:47 -0800413 }
msarett9e707a02015-09-01 14:57:57 -0700414 SkString folder;
415 switch (mode) {
416 case CodecSrc::kCodec_Mode:
417 folder.append("codec");
418 break;
msarettbb25b532016-01-13 09:31:39 -0800419 case CodecSrc::kCodecZeroInit_Mode:
420 folder.append("codec_zero_init");
421 break;
msarett9e707a02015-09-01 14:57:57 -0700422 case CodecSrc::kScanline_Mode:
423 folder.append("scanline");
424 break;
msarett9e707a02015-09-01 14:57:57 -0700425 case CodecSrc::kStripe_Mode:
426 folder.append("stripe");
427 break;
msarett91c22b22016-02-22 12:27:46 -0800428 case CodecSrc::kCroppedScanline_Mode:
429 folder.append("crop");
430 break;
msarett9e707a02015-09-01 14:57:57 -0700431 case CodecSrc::kSubset_Mode:
msarett36c37962015-09-02 13:20:52 -0700432 folder.append("codec_subset");
msarett9e707a02015-09-01 14:57:57 -0700433 break;
scroggo19b91532016-10-24 09:03:26 -0700434 case CodecSrc::kAnimated_Mode:
435 folder.append("codec_animated");
436 break;
msarett9e707a02015-09-01 14:57:57 -0700437 }
438
439 switch (dstColorType) {
440 case CodecSrc::kGrayscale_Always_DstColorType:
441 folder.append("_kGray8");
442 break;
msarett34e0ec42016-04-22 16:27:24 -0700443 case CodecSrc::kNonNative8888_Always_DstColorType:
444 folder.append("_kNonNative");
445 break;
msarett9e707a02015-09-01 14:57:57 -0700446 default:
447 break;
448 }
449
scroggoc5560be2016-02-03 09:42:42 -0800450 switch (dstAlphaType) {
scroggoc5560be2016-02-03 09:42:42 -0800451 case kPremul_SkAlphaType:
452 folder.append("_premul");
453 break;
454 case kUnpremul_SkAlphaType:
455 folder.append("_unpremul");
456 break;
457 default:
458 break;
459 }
460
msarett9e707a02015-09-01 14:57:57 -0700461 if (1.0f != scale) {
462 folder.appendf("_%.3f", scale);
463 }
464
scroggoc5560be2016-02-03 09:42:42 -0800465 CodecSrc* src = new CodecSrc(path, mode, dstColorType, dstAlphaType, scale);
msarett9e707a02015-09-01 14:57:57 -0700466 push_src("image", folder, src);
467}
468
scroggof8dc9df2016-05-16 09:04:13 -0700469static void push_android_codec_src(Path path, CodecSrc::DstColorType dstColorType,
470 SkAlphaType dstAlphaType, int sampleSize) {
msarett3d9d7a72015-10-21 10:27:10 -0700471 SkString folder;
scroggof8dc9df2016-05-16 09:04:13 -0700472 folder.append("scaled_codec");
msarett3d9d7a72015-10-21 10:27:10 -0700473
474 switch (dstColorType) {
475 case CodecSrc::kGrayscale_Always_DstColorType:
476 folder.append("_kGray8");
477 break;
msarett34e0ec42016-04-22 16:27:24 -0700478 case CodecSrc::kNonNative8888_Always_DstColorType:
479 folder.append("_kNonNative");
480 break;
msarett3d9d7a72015-10-21 10:27:10 -0700481 default:
482 break;
483 }
484
scroggoc5560be2016-02-03 09:42:42 -0800485 switch (dstAlphaType) {
scroggoc5560be2016-02-03 09:42:42 -0800486 case kPremul_SkAlphaType:
487 folder.append("_premul");
488 break;
msarett9e9444c2016-02-03 12:39:10 -0800489 case kUnpremul_SkAlphaType:
490 folder.append("_unpremul");
491 break;
scroggoc5560be2016-02-03 09:42:42 -0800492 default:
493 break;
494 }
495
msarett3d9d7a72015-10-21 10:27:10 -0700496 if (1 != sampleSize) {
msarett4b0778e2015-11-13 09:59:11 -0800497 folder.appendf("_%.3f", 1.0f / (float) sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700498 }
499
scroggof8dc9df2016-05-16 09:04:13 -0700500 AndroidCodecSrc* src = new AndroidCodecSrc(path, dstColorType, dstAlphaType, sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700501 push_src("image", folder, src);
502}
503
msarett18976312016-03-09 14:20:58 -0800504static void push_image_gen_src(Path path, ImageGenSrc::Mode mode, SkAlphaType alphaType, bool isGpu)
505{
506 SkString folder;
507 switch (mode) {
508 case ImageGenSrc::kCodec_Mode:
509 folder.append("gen_codec");
510 break;
511 case ImageGenSrc::kPlatform_Mode:
512 folder.append("gen_platform");
513 break;
514 }
515
516 if (isGpu) {
517 folder.append("_gpu");
518 } else {
519 switch (alphaType) {
520 case kOpaque_SkAlphaType:
521 folder.append("_opaque");
522 break;
523 case kPremul_SkAlphaType:
524 folder.append("_premul");
525 break;
526 case kUnpremul_SkAlphaType:
527 folder.append("_unpremul");
528 break;
529 default:
530 break;
531 }
532 }
533
534 ImageGenSrc* src = new ImageGenSrc(path, mode, alphaType, isGpu);
535 push_src("image", folder, src);
536}
537
Leon Scroggins III07418182017-08-15 12:24:02 -0400538static void push_brd_src(Path path, CodecSrc::DstColorType dstColorType, BRDSrc::Mode mode,
539 uint32_t sampleSize) {
540 SkString folder("brd_android_codec");
541 switch (mode) {
542 case BRDSrc::kFullImage_Mode:
543 break;
544 case BRDSrc::kDivisor_Mode:
545 folder.append("_divisor");
546 break;
547 default:
548 SkASSERT(false);
549 return;
550 }
551
552 switch (dstColorType) {
553 case CodecSrc::kGetFromCanvas_DstColorType:
554 break;
555 case CodecSrc::kGrayscale_Always_DstColorType:
556 folder.append("_kGray");
557 break;
558 default:
559 SkASSERT(false);
560 return;
561 }
562
563 if (1 != sampleSize) {
564 folder.appendf("_%.3f", 1.0f / (float) sampleSize);
565 }
566
567 BRDSrc* src = new BRDSrc(path, mode, dstColorType, sampleSize);
568 push_src("image", folder, src);
569}
570
571static void push_brd_srcs(Path path, bool gray) {
572 if (gray) {
573 // Only run grayscale to one sampleSize and Mode. Though interesting
574 // to test grayscale, it should not reveal anything across various
575 // sampleSizes and Modes
576 // Arbitrarily choose Mode and sampleSize.
577 push_brd_src(path, CodecSrc::kGrayscale_Always_DstColorType,
578 BRDSrc::kFullImage_Mode, 2);
579 }
580
581 // Test on a variety of sampleSizes, making sure to include:
582 // - 2, 4, and 8, which are natively supported by jpeg
583 // - multiples of 2 which are not divisible by 4 (analogous for 4)
584 // - larger powers of two, since BRD clients generally use powers of 2
585 // We will only produce output for the larger sizes on large images.
586 const uint32_t sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 24, 32, 64 };
587
588 const BRDSrc::Mode modes[] = { BRDSrc::kFullImage_Mode, BRDSrc::kDivisor_Mode, };
589
590 for (uint32_t sampleSize : sampleSizes) {
591 for (BRDSrc::Mode mode : modes) {
592 push_brd_src(path, CodecSrc::kGetFromCanvas_DstColorType, mode, sampleSize);
593 }
594 }
595}
596
msarett438b2ad2015-04-09 12:43:10 -0700597static void push_codec_srcs(Path path) {
bungeman38d909e2016-08-02 14:40:46 -0700598 sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str()));
msarett438b2ad2015-04-09 12:43:10 -0700599 if (!encoded) {
mtkleinc41fd922016-03-08 09:01:39 -0800600 info("Couldn't read %s.", path.c_str());
msarett438b2ad2015-04-09 12:43:10 -0700601 return;
602 }
Mike Reedede7bac2017-07-23 15:30:02 -0400603 std::unique_ptr<SkCodec> codec = SkCodec::MakeFromData(encoded);
halcanary96fcdcc2015-08-27 07:41:13 -0700604 if (nullptr == codec.get()) {
mtkleinc41fd922016-03-08 09:01:39 -0800605 info("Couldn't create codec for %s.", path.c_str());
msarett438b2ad2015-04-09 12:43:10 -0700606 return;
607 }
608
scroggo9366aff2016-05-20 08:38:54 -0700609 // native scaling is only supported by WEBP and JPEG
610 bool supportsNativeScaling = false;
msarett438b2ad2015-04-09 12:43:10 -0700611
msarett91c22b22016-02-22 12:27:46 -0800612 SkTArray<CodecSrc::Mode> nativeModes;
613 nativeModes.push_back(CodecSrc::kCodec_Mode);
614 nativeModes.push_back(CodecSrc::kCodecZeroInit_Mode);
msarett91c22b22016-02-22 12:27:46 -0800615 switch (codec->getEncodedFormat()) {
Hal Canarydb683012016-11-23 08:55:18 -0700616 case SkEncodedImageFormat::kJPEG:
msarett91c22b22016-02-22 12:27:46 -0800617 nativeModes.push_back(CodecSrc::kScanline_Mode);
618 nativeModes.push_back(CodecSrc::kStripe_Mode);
619 nativeModes.push_back(CodecSrc::kCroppedScanline_Mode);
scroggo9366aff2016-05-20 08:38:54 -0700620 supportsNativeScaling = true;
msarett91c22b22016-02-22 12:27:46 -0800621 break;
Hal Canarydb683012016-11-23 08:55:18 -0700622 case SkEncodedImageFormat::kWEBP:
msarett91c22b22016-02-22 12:27:46 -0800623 nativeModes.push_back(CodecSrc::kSubset_Mode);
scroggo9366aff2016-05-20 08:38:54 -0700624 supportsNativeScaling = true;
msarett91c22b22016-02-22 12:27:46 -0800625 break;
Hal Canarydb683012016-11-23 08:55:18 -0700626 case SkEncodedImageFormat::kDNG:
msarettb65e6042016-02-23 05:37:25 -0800627 break;
msarett91c22b22016-02-22 12:27:46 -0800628 default:
629 nativeModes.push_back(CodecSrc::kScanline_Mode);
msarett91c22b22016-02-22 12:27:46 -0800630 break;
631 }
msarett9e707a02015-09-01 14:57:57 -0700632
msarett91c22b22016-02-22 12:27:46 -0800633 SkTArray<CodecSrc::DstColorType> colorTypes;
634 colorTypes.push_back(CodecSrc::kGetFromCanvas_DstColorType);
msarett34e0ec42016-04-22 16:27:24 -0700635 colorTypes.push_back(CodecSrc::kNonNative8888_Always_DstColorType);
msarett36c37962015-09-02 13:20:52 -0700636 switch (codec->getInfo().colorType()) {
637 case kGray_8_SkColorType:
msarett91c22b22016-02-22 12:27:46 -0800638 colorTypes.push_back(CodecSrc::kGrayscale_Always_DstColorType);
msarett36c37962015-09-02 13:20:52 -0700639 break;
640 default:
msarett36c37962015-09-02 13:20:52 -0700641 break;
642 }
msarett9e707a02015-09-01 14:57:57 -0700643
scroggoc5560be2016-02-03 09:42:42 -0800644 SkTArray<SkAlphaType> alphaModes;
645 alphaModes.push_back(kPremul_SkAlphaType);
scroggof2c96a22016-05-20 11:08:27 -0700646 if (codec->getInfo().alphaType() != kOpaque_SkAlphaType) {
647 alphaModes.push_back(kUnpremul_SkAlphaType);
scroggoc5560be2016-02-03 09:42:42 -0800648 }
msarettb714fb02016-01-22 14:46:42 -0800649
650 for (CodecSrc::Mode mode : nativeModes) {
scroggo9366aff2016-05-20 08:38:54 -0700651 for (CodecSrc::DstColorType colorType : colorTypes) {
652 for (SkAlphaType alphaType : alphaModes) {
scroggof2c96a22016-05-20 11:08:27 -0700653 // Only test kCroppedScanline_Mode when the alpha type is premul. The test is
scroggo9366aff2016-05-20 08:38:54 -0700654 // slow and won't be interestingly different with different alpha types.
655 if (CodecSrc::kCroppedScanline_Mode == mode &&
scroggof2c96a22016-05-20 11:08:27 -0700656 kPremul_SkAlphaType != alphaType) {
scroggo9366aff2016-05-20 08:38:54 -0700657 continue;
658 }
msarett91c22b22016-02-22 12:27:46 -0800659
scroggo9366aff2016-05-20 08:38:54 -0700660 push_codec_src(path, mode, colorType, alphaType, 1.0f);
msarettf3dc1882016-04-26 13:06:38 -0700661
scroggo9366aff2016-05-20 08:38:54 -0700662 // Skip kNonNative on different native scales. It won't be interestingly
663 // different.
664 if (supportsNativeScaling &&
665 CodecSrc::kNonNative8888_Always_DstColorType == colorType) {
666 // Native Scales
667 // SkJpegCodec natively supports scaling to the following:
668 for (auto scale : { 0.125f, 0.25f, 0.375f, 0.5f, 0.625f, 0.750f, 0.875f }) {
669 push_codec_src(path, mode, colorType, alphaType, scale);
670 }
scroggoc5560be2016-02-03 09:42:42 -0800671 }
msarett9e707a02015-09-01 14:57:57 -0700672 }
673 }
msarett0a242972015-06-11 14:27:27 -0700674 }
msarett36c37962015-09-02 13:20:52 -0700675
scroggo19b91532016-10-24 09:03:26 -0700676 {
677 std::vector<SkCodec::FrameInfo> frameInfos = codec->getFrameInfo();
678 if (frameInfos.size() > 1) {
Leon Scroggins III557fbbe2017-05-23 09:37:21 -0400679 for (auto dstCT : { CodecSrc::kNonNative8888_Always_DstColorType,
680 CodecSrc::kGetFromCanvas_DstColorType }) {
681 for (auto at : { kUnpremul_SkAlphaType, kPremul_SkAlphaType }) {
682 push_codec_src(path, CodecSrc::kAnimated_Mode, dstCT, at, 1.0f);
683 }
684 }
scroggo19b91532016-10-24 09:03:26 -0700685 }
686
687 }
688
scroggoe4499842016-02-25 11:03:47 -0800689 if (FLAGS_simpleCodec) {
690 return;
691 }
692
msarett3d9d7a72015-10-21 10:27:10 -0700693 const int sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
msarett36c37962015-09-02 13:20:52 -0700694
msarett3d9d7a72015-10-21 10:27:10 -0700695 for (int sampleSize : sampleSizes) {
msarett91c22b22016-02-22 12:27:46 -0800696 for (CodecSrc::DstColorType colorType : colorTypes) {
scroggoc5560be2016-02-03 09:42:42 -0800697 for (SkAlphaType alphaType : alphaModes) {
msarettf3dc1882016-04-26 13:06:38 -0700698 // We can exercise all of the kNonNative support code in the swizzler with just a
699 // few sample sizes. Skip the rest.
700 if (CodecSrc::kNonNative8888_Always_DstColorType == colorType && sampleSize > 3) {
701 continue;
702 }
703
scroggof8dc9df2016-05-16 09:04:13 -0700704 push_android_codec_src(path, colorType, alphaType, sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700705 }
msarett36c37962015-09-02 13:20:52 -0700706 }
707 }
msarett18976312016-03-09 14:20:58 -0800708
Leon Scroggins III07418182017-08-15 12:24:02 -0400709 const char* ext = strrchr(path.c_str(), '.');
710 if (ext) {
711 ext++;
msarett18976312016-03-09 14:20:58 -0800712
Leon Scroggins III07418182017-08-15 12:24:02 -0400713 static const char* const rawExts[] = {
714 "arw", "cr2", "dng", "nef", "nrw", "orf", "raf", "rw2", "pef", "srw",
715 "ARW", "CR2", "DNG", "NEF", "NRW", "ORF", "RAF", "RW2", "PEF", "SRW",
716 };
717 for (const char* rawExt : rawExts) {
718 if (0 == strcmp(rawExt, ext)) {
719 // RAW is not supported by image generator (skbug.com/5079) or BRD.
720 return;
721 }
722 }
723
724 static const char* const brdExts[] = {
725 "jpg", "jpeg", "png", "webp",
726 "JPG", "JPEG", "PNG", "WEBP",
727 };
728 for (const char* brdExt : brdExts) {
729 if (0 == strcmp(brdExt, ext)) {
Leon Scroggins IIIc8037dc2017-12-05 13:55:24 -0500730 bool gray = codec->getInfo().colorType() == kGray_8_SkColorType;
Leon Scroggins III07418182017-08-15 12:24:02 -0400731 push_brd_srcs(path, gray);
732 break;
733 }
msarett18976312016-03-09 14:20:58 -0800734 }
735 }
736
737 // Push image generator GPU test.
brianosmanc9ced392016-03-24 07:27:43 -0700738 push_image_gen_src(path, ImageGenSrc::kCodec_Mode, codec->getInfo().alphaType(), true);
msarett18976312016-03-09 14:20:58 -0800739
740 // Push image generator CPU tests.
741 for (SkAlphaType alphaType : alphaModes) {
742 push_image_gen_src(path, ImageGenSrc::kCodec_Mode, alphaType, false);
743
744#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
Hal Canarydb683012016-11-23 08:55:18 -0700745 if (SkEncodedImageFormat::kWEBP != codec->getEncodedFormat() &&
746 SkEncodedImageFormat::kWBMP != codec->getEncodedFormat() &&
msarett18976312016-03-09 14:20:58 -0800747 kUnpremul_SkAlphaType != alphaType)
748 {
749 push_image_gen_src(path, ImageGenSrc::kPlatform_Mode, alphaType, false);
750 }
msarettfc0b6d12016-03-17 13:50:17 -0700751#elif defined(SK_BUILD_FOR_WIN)
Hal Canarydb683012016-11-23 08:55:18 -0700752 if (SkEncodedImageFormat::kWEBP != codec->getEncodedFormat() &&
753 SkEncodedImageFormat::kWBMP != codec->getEncodedFormat())
msarettfc0b6d12016-03-17 13:50:17 -0700754 {
755 push_image_gen_src(path, ImageGenSrc::kPlatform_Mode, alphaType, false);
756 }
msarett18976312016-03-09 14:20:58 -0800757#endif
758 }
msarett438b2ad2015-04-09 12:43:10 -0700759}
760
fmalitaa2b9fdf2016-08-03 19:53:36 -0700761template <typename T>
Florin Malitaf1ba3ae2018-07-19 15:09:11 -0400762void gather_file_srcs(const SkCommandLineFlags::StringArray& flags, const char* ext,
763 const char* src_name = nullptr) {
764 if (!src_name) {
765 // With the exception of Lottie files, the source name is the extension.
766 src_name = ext;
767 }
768
fmalitaa2b9fdf2016-08-03 19:53:36 -0700769 for (int i = 0; i < flags.count(); i++) {
770 const char* path = flags[i];
771 if (sk_isdir(path)) {
772 SkOSFile::Iter it(path, ext);
773 for (SkString file; it.next(&file); ) {
Florin Malitaf1ba3ae2018-07-19 15:09:11 -0400774 push_src(src_name, "", new T(SkOSPath::Join(path, file.c_str())));
fmalitaa2b9fdf2016-08-03 19:53:36 -0700775 }
776 } else {
Florin Malitaf1ba3ae2018-07-19 15:09:11 -0400777 push_src(src_name, "", new T(path));
fmalitaa2b9fdf2016-08-03 19:53:36 -0700778 }
779 }
780}
781
scroggo86737142016-02-03 12:19:11 -0800782static bool gather_srcs() {
Hal Canary972eba32018-07-30 17:07:07 -0400783 for (skiagm::GMFactory f : skiagm::GMRegistry::Range()) {
784 push_src("gm", "", new GMSrc(f));
mtklein748ca3b2015-01-15 10:56:12 -0800785 }
scroggo86737142016-02-03 12:19:11 -0800786
Robert Phillipse47f0a02018-03-27 17:01:16 -0400787 gather_file_srcs<SKPSrc>(FLAGS_skps, "skp");
fmalitaa2b9fdf2016-08-03 19:53:36 -0700788 gather_file_srcs<MSKPSrc>(FLAGS_mskps, "mskp");
Florin Malita87ccf332018-05-04 12:23:24 -0400789#if defined(SK_ENABLE_SKOTTIE)
Florin Malitaf1ba3ae2018-07-19 15:09:11 -0400790 gather_file_srcs<SkottieSrc>(FLAGS_lotties, "json", "lottie");
Florin Malita124d5af2017-12-31 17:02:26 -0500791#endif
fmalitaa2b9fdf2016-08-03 19:53:36 -0700792#if defined(SK_XML)
793 gather_file_srcs<SVGSrc>(FLAGS_svgs, "svg");
794#endif
Chris Dalton184c37e2018-09-28 11:27:39 -0600795 if (!FLAGS_bisect.isEmpty()) {
796 // An empty l/r trail string will draw all the paths.
797 push_src("bisect", "",
798 new BisectSrc(FLAGS_bisect[0], FLAGS_bisect.count() > 1 ? FLAGS_bisect[1] : ""));
799 }
halcanary45420a92016-06-02 12:41:14 -0700800
scroggo86737142016-02-03 12:19:11 -0800801 SkTArray<SkString> images;
msarett69deca82016-04-29 09:38:40 -0700802 if (!CollectImages(FLAGS_images, &images)) {
scroggo86737142016-02-03 12:19:11 -0800803 return false;
804 }
805
806 for (auto image : images) {
807 push_codec_srcs(image);
mtklein709d2c32015-01-15 08:30:25 -0800808 }
scroggo86737142016-02-03 12:19:11 -0800809
msarett69deca82016-04-29 09:38:40 -0700810 SkTArray<SkString> colorImages;
811 if (!CollectImages(FLAGS_colorImages, &colorImages)) {
812 return false;
813 }
814
815 for (auto colorImage : colorImages) {
msarett9ce3a542016-07-15 13:54:38 -0700816 ColorCodecSrc* src = new ColorCodecSrc(colorImage, ColorCodecSrc::kBaseline_Mode,
817 kN32_SkColorType);
msarettb8d1aac2016-08-04 12:22:06 -0700818 push_src("colorImage", "color_codec_baseline", src);
msarett888dc162016-05-23 10:21:17 -0700819
msarett9ce3a542016-07-15 13:54:38 -0700820 src = new ColorCodecSrc(colorImage, ColorCodecSrc::kDst_HPZR30w_Mode, kN32_SkColorType);
msarettb8d1aac2016-08-04 12:22:06 -0700821 push_src("colorImage", "color_codec_HPZR30w", src);
msarett9ce3a542016-07-15 13:54:38 -0700822 // TODO (msarett):
823 // 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 -0700824
msarett9ce3a542016-07-15 13:54:38 -0700825 src = new ColorCodecSrc(colorImage, ColorCodecSrc::kDst_sRGB_Mode, kN32_SkColorType);
msarettb8d1aac2016-08-04 12:22:06 -0700826 push_src("colorImage", "color_codec_sRGB_kN32", src);
msarett9ce3a542016-07-15 13:54:38 -0700827 src = new ColorCodecSrc(colorImage, ColorCodecSrc::kDst_sRGB_Mode, kRGBA_F16_SkColorType);
msarettb8d1aac2016-08-04 12:22:06 -0700828 push_src("colorImage", "color_codec_sRGB_kF16", src);
msarett69deca82016-04-29 09:38:40 -0700829 }
830
scroggo86737142016-02-03 12:19:11 -0800831 return true;
mtklein709d2c32015-01-15 08:30:25 -0800832}
833
Mike Kleinae4b1f42018-09-13 11:13:15 -0400834static sk_sp<SkColorSpace> rec2020() {
835 // See https://en.wikipedia.org/wiki/Rec._2020
836 float alpha = 1.09929682680944f,
837 beta = 0.018053968510807f,
838 gamma = 0.45f;
839 SkColorSpaceTransferFn rec2020_TF = SkColorSpaceTransferFn{
840 gamma,
841 powf(alpha, 1/gamma),
842 0.0f,
843 4.5f,
844 beta,
845 1 - alpha,
846 0.0f,
847 }.invert();
848 return SkColorSpace::MakeRGB(rec2020_TF, SkColorSpace::kRec2020_Gamut);
849}
850
kkinnunen3e980c32015-12-23 01:33:00 -0800851static void push_sink(const SkCommandLineConfig& config, Sink* s) {
Ben Wagner145dbcd2016-11-03 14:40:50 -0400852 std::unique_ptr<Sink> sink(s);
kkinnunen3e980c32015-12-23 01:33:00 -0800853
mtkleine0effd62015-07-29 06:37:28 -0700854 // Try a simple Src as a canary. If it fails, skip this sink.
mtklein748ca3b2015-01-15 10:56:12 -0800855 struct : public Src {
mtkleine0effd62015-07-29 06:37:28 -0700856 Error draw(SkCanvas* c) const override {
857 c->drawRect(SkRect::MakeWH(1,1), SkPaint());
858 return "";
859 }
mtklein36352bf2015-03-25 18:17:31 -0700860 SkISize size() const override { return SkISize::Make(16, 16); }
mtkleine0effd62015-07-29 06:37:28 -0700861 Name name() const override { return "justOneRect"; }
862 } justOneRect;
mtklein114c3cd2015-01-15 10:15:02 -0800863
mtklein748ca3b2015-01-15 10:56:12 -0800864 SkBitmap bitmap;
865 SkDynamicMemoryWStream stream;
mtkleinb9eb4ac2015-02-02 18:26:03 -0800866 SkString log;
mtkleine0effd62015-07-29 06:37:28 -0700867 Error err = sink->draw(justOneRect, &bitmap, &stream, &log);
mtklein4089ef72015-03-05 08:40:28 -0800868 if (err.isFatal()) {
mtkleinc41fd922016-03-08 09:01:39 -0800869 info("Could not run %s: %s\n", config.getTag().c_str(), err.c_str());
mtklein05641a52015-04-21 10:49:13 -0700870 exit(1);
mtklein114c3cd2015-01-15 10:15:02 -0800871 }
872
mtkleine0effd62015-07-29 06:37:28 -0700873 TaggedSink& ts = gSinks.push_back();
mtklein18300a32016-03-16 13:53:35 -0700874 ts.reset(sink.release());
kkinnunen3e980c32015-12-23 01:33:00 -0800875 ts.tag = config.getTag();
mtklein748ca3b2015-01-15 10:56:12 -0800876}
877
csmartdalton008b9d82017-02-22 12:00:42 -0700878static Sink* create_sink(const GrContextOptions& grCtxOptions, const SkCommandLineConfig* config) {
Brian Osmanc7ad40f2018-05-31 14:27:17 -0400879 if (FLAGS_gpu) {
kkinnunen3e980c32015-12-23 01:33:00 -0800880 if (const SkCommandLineConfigGpu* gpuConfig = config->asConfigGpu()) {
bsalomon85b4b532016-04-05 11:06:27 -0700881 GrContextFactory::ContextType contextType = gpuConfig->getContextType();
csmartdaltone812d492017-02-21 12:36:05 -0700882 GrContextFactory::ContextOverrides contextOverrides = gpuConfig->getContextOverrides();
csmartdalton008b9d82017-02-22 12:00:42 -0700883 GrContextFactory testFactory(grCtxOptions);
csmartdaltone812d492017-02-21 12:36:05 -0700884 if (!testFactory.get(contextType, contextOverrides)) {
mtkleinc41fd922016-03-08 09:01:39 -0800885 info("WARNING: can not create GPU context for config '%s'. "
886 "GM tests will be skipped.\n", gpuConfig->getTag().c_str());
kkinnunen3e980c32015-12-23 01:33:00 -0800887 return nullptr;
888 }
Brian Osmanf9810662017-08-30 10:02:10 -0400889 if (gpuConfig->getTestThreading()) {
Brian Salomon00a5eb82018-07-11 15:32:05 -0400890 SkASSERT(!gpuConfig->getTestPersistentCache());
Brian Salomonf865b052018-03-09 09:01:53 -0500891 return new GPUThreadTestingSink(
892 contextType, contextOverrides, gpuConfig->getSurfType(),
893 gpuConfig->getSamples(), gpuConfig->getUseDIText(),
894 gpuConfig->getColorType(), gpuConfig->getAlphaType(),
895 sk_ref_sp(gpuConfig->getColorSpace()), FLAGS_gpu_threading, grCtxOptions);
Brian Salomon00a5eb82018-07-11 15:32:05 -0400896 } else if (gpuConfig->getTestPersistentCache()) {
897 return new GPUPersistentCacheTestingSink(
898 contextType, contextOverrides, gpuConfig->getSurfType(),
899 gpuConfig->getSamples(), gpuConfig->getUseDIText(),
900 gpuConfig->getColorType(), gpuConfig->getAlphaType(),
901 sk_ref_sp(gpuConfig->getColorSpace()), FLAGS_gpu_threading, grCtxOptions);
Brian Osmanf9810662017-08-30 10:02:10 -0400902 } else {
Brian Salomonf865b052018-03-09 09:01:53 -0500903 return new GPUSink(contextType, contextOverrides, gpuConfig->getSurfType(),
904 gpuConfig->getSamples(), gpuConfig->getUseDIText(),
905 gpuConfig->getColorType(), gpuConfig->getAlphaType(),
906 sk_ref_sp(gpuConfig->getColorSpace()), FLAGS_gpu_threading,
907 grCtxOptions);
Brian Osmanf9810662017-08-30 10:02:10 -0400908 }
kkinnunen3e980c32015-12-23 01:33:00 -0800909 }
910 }
Bryce Thomas95a7b762018-03-02 13:54:21 -0800911 if (const SkCommandLineConfigSvg* svgConfig = config->asConfigSvg()) {
912 int pageIndex = svgConfig->getPageIndex();
913 return new SVGSink(pageIndex);
914 }
kkinnunen3e980c32015-12-23 01:33:00 -0800915
916#define SINK(t, sink, ...) if (config->getBackend().equals(t)) { return new sink(__VA_ARGS__); }
917
mtklein748ca3b2015-01-15 10:56:12 -0800918 if (FLAGS_cpu) {
Mike Klein515bda62018-01-09 11:21:58 -0500919 SINK("g8", RasterSink, kGray_8_SkColorType);
Matt Sarettd2228302017-03-02 08:53:46 -0500920 SINK("565", RasterSink, kRGB_565_SkColorType);
Mike Klein5340b3f2018-01-24 13:42:05 -0500921 SINK("4444", RasterSink, kARGB_4444_SkColorType);
Matt Sarettd2228302017-03-02 08:53:46 -0500922 SINK("8888", RasterSink, kN32_SkColorType);
Mike Kleinac568a92018-01-25 09:09:32 -0500923 SINK("rgba", RasterSink, kRGBA_8888_SkColorType);
924 SINK("bgra", RasterSink, kBGRA_8888_SkColorType);
925 SINK("rgbx", RasterSink, kRGB_888x_SkColorType);
926 SINK("1010102", RasterSink, kRGBA_1010102_SkColorType);
927 SINK("101010x", RasterSink, kRGB_101010x_SkColorType);
Hal Canaryc7d295e2017-07-20 15:36:00 -0400928 SINK("pdf", PDFSink, false, SK_ScalarDefaultRasterDPI);
Matt Sarettd2228302017-03-02 08:53:46 -0500929 SINK("skp", SKPSink);
930 SINK("pipe", PipeSink);
931 SINK("svg", SVGSink);
932 SINK("null", NullSink);
933 SINK("xps", XPSSink);
Hal Canaryc7d295e2017-07-20 15:36:00 -0400934 SINK("pdfa", PDFSink, true, SK_ScalarDefaultRasterDPI);
935 SINK("pdf300", PDFSink, false, 300);
Hal Canary85c7fe82016-10-25 10:33:27 -0400936 SINK("jsdebug", DebugSink);
Mike Klein0e4041f2018-06-19 16:00:40 -0400937
938 // Configs relevant to color management testing (and 8888 for reference).
939
940 // 'narrow' has a gamut narrower than sRGB, and different transfer function.
941 SkMatrix44 narrow_gamut(SkMatrix44::kUninitialized_Constructor);
942 narrow_gamut.set3x3RowMajorf(gNarrow_toXYZD50);
943
944 auto narrow = SkColorSpace::MakeRGB(k2Dot2Curve_SkGammaNamed, narrow_gamut),
945 srgb = SkColorSpace::MakeSRGB(),
Mike Klein4de05072018-08-16 09:09:14 -0400946 srgbLinear = SkColorSpace::MakeSRGBLinear(),
947 p3 = SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
Mike Kleinae4b1f42018-09-13 11:13:15 -0400948 SkColorSpace::kDCIP3_D65_Gamut);
Mike Klein0e4041f2018-06-19 16:00:40 -0400949
Mike Kleinff6a73c2018-08-17 16:19:24 -0400950 SINK( "f16", RasterSink, kRGBA_F16_SkColorType, srgbLinear);
951 SINK( "srgb", RasterSink, kRGBA_8888_SkColorType, srgb );
952 SINK( "esrgb", RasterSink, kRGBA_F16_SkColorType, srgb );
953 SINK( "narrow", RasterSink, kRGBA_8888_SkColorType, narrow );
954 SINK( "enarrow", RasterSink, kRGBA_F16_SkColorType, narrow );
955 SINK( "p3", RasterSink, kRGBA_8888_SkColorType, p3 );
956 SINK( "ep3", RasterSink, kRGBA_F16_SkColorType, p3 );
Mike Kleinae4b1f42018-09-13 11:13:15 -0400957 SINK( "rec2020", RasterSink, kRGBA_8888_SkColorType, rec2020() );
958 SINK("erec2020", RasterSink, kRGBA_F16_SkColorType, rec2020() );
Mike Klein37854712018-06-26 11:43:06 -0400959
960 SINK( "f32", RasterSink, kRGBA_F32_SkColorType, srgbLinear);
mtklein748ca3b2015-01-15 10:56:12 -0800961 }
962#undef SINK
halcanary96fcdcc2015-08-27 07:41:13 -0700963 return nullptr;
mtklein114c3cd2015-01-15 10:15:02 -0800964}
965
Mike Kleinb7ea3da2017-10-31 17:42:08 +0000966static sk_sp<SkColorSpace> rgb_to_gbr() {
Brian Osman36703d92017-12-12 14:09:31 -0500967 return SkColorSpace::MakeSRGB()->makeColorSpin();
Mike Klein919cc452017-03-18 15:36:52 +0000968}
969
kkinnunen3e980c32015-12-23 01:33:00 -0800970static Sink* create_via(const SkString& tag, Sink* wrapped) {
971#define VIA(t, via, ...) if (tag.equals(t)) { return new via(__VA_ARGS__); }
Mike Kleinb7ea3da2017-10-31 17:42:08 +0000972 VIA("gbr", ViaCSXform, wrapped, rgb_to_gbr(), true);
Brian Osmana76b7a92018-07-18 14:36:43 -0400973 VIA("p3", ViaCSXform, wrapped,
974 SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
975 SkColorSpace::kDCIP3_D65_Gamut), false);
mtklein9c5052f2016-08-06 12:51:51 -0700976 VIA("lite", ViaLite, wrapped);
reed54dc4872016-09-13 08:09:45 -0700977 VIA("pipe", ViaPipe, wrapped);
Mike Reedbae888e2017-02-18 16:50:45 -0500978#ifdef TEST_VIA_SVG
Mike Reedf67c4592017-02-17 17:06:11 -0500979 VIA("svg", ViaSVG, wrapped);
Mike Reedbae888e2017-02-18 16:50:45 -0500980#endif
halcanary96fcdcc2015-08-27 07:41:13 -0700981 VIA("serialize", ViaSerialization, wrapped);
mtklein4a34ecb2016-01-08 10:19:35 -0800982 VIA("pic", ViaPicture, wrapped);
halcanary96fcdcc2015-08-27 07:41:13 -0700983 VIA("tiles", ViaTiles, 256, 256, nullptr, wrapped);
mtklein7edca212015-01-21 13:18:51 -0800984 VIA("tiles_rt", ViaTiles, 256, 256, new SkRTreeFactory, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800985
Robert Phillips33f02ed2018-03-27 08:06:57 -0400986 VIA("ddl", ViaDDL, 3, wrapped);
987
mtkleind603b222015-02-17 11:13:33 -0800988 if (FLAGS_matrix.count() == 4) {
mtklein748ca3b2015-01-15 10:56:12 -0800989 SkMatrix m;
mtkleind603b222015-02-17 11:13:33 -0800990 m.reset();
991 m.setScaleX((SkScalar)atof(FLAGS_matrix[0]));
992 m.setSkewX ((SkScalar)atof(FLAGS_matrix[1]));
993 m.setSkewY ((SkScalar)atof(FLAGS_matrix[2]));
994 m.setScaleY((SkScalar)atof(FLAGS_matrix[3]));
995 VIA("matrix", ViaMatrix, m, wrapped);
996 VIA("upright", ViaUpright, m, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800997 }
tomhudson64de1e12015-03-05 08:01:07 -0800998
mtklein748ca3b2015-01-15 10:56:12 -0800999#undef VIA
halcanary96fcdcc2015-08-27 07:41:13 -07001000 return nullptr;
mtklein114c3cd2015-01-15 10:15:02 -08001001}
1002
Ben Wagnerf28d4722017-08-11 17:33:22 -04001003static bool gather_sinks(const GrContextOptions& grCtxOptions, bool defaultConfigs) {
kkinnunen3e980c32015-12-23 01:33:00 -08001004 SkCommandLineConfigArray configs;
1005 ParseConfigs(FLAGS_config, &configs);
1006 for (int i = 0; i < configs.count(); i++) {
1007 const SkCommandLineConfig& config = *configs[i];
csmartdalton008b9d82017-02-22 12:00:42 -07001008 Sink* sink = create_sink(grCtxOptions, &config);
kkinnunen3e980c32015-12-23 01:33:00 -08001009 if (sink == nullptr) {
mtkleinc41fd922016-03-08 09:01:39 -08001010 info("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(),
1011 config.getTag().c_str());
kkinnunen3e980c32015-12-23 01:33:00 -08001012 continue;
1013 }
mtklein748ca3b2015-01-15 10:56:12 -08001014
kkinnunen3e980c32015-12-23 01:33:00 -08001015 const SkTArray<SkString>& parts = config.getViaParts();
1016 for (int j = parts.count(); j-- > 0;) {
1017 const SkString& part = parts[j];
1018 Sink* next = create_via(part, sink);
halcanary96fcdcc2015-08-27 07:41:13 -07001019 if (next == nullptr) {
mtkleinc41fd922016-03-08 09:01:39 -08001020 info("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(),
1021 part.c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001022 delete sink;
halcanary96fcdcc2015-08-27 07:41:13 -07001023 sink = nullptr;
mtklein748ca3b2015-01-15 10:56:12 -08001024 break;
1025 }
1026 sink = next;
1027 }
1028 if (sink) {
1029 push_sink(config, sink);
mtklein114c3cd2015-01-15 10:15:02 -08001030 }
1031 }
brianosman05c987c2016-05-09 13:42:16 -07001032
1033 // If no configs were requested (just running tests, perhaps?), then we're okay.
Ben Wagnerf28d4722017-08-11 17:33:22 -04001034 if (configs.count() == 0 ||
1035 // If we're using the default configs, we're okay.
1036 defaultConfigs ||
Ben Wagner32fa5102017-08-10 21:25:55 -04001037 // If we've been told to ignore undefined flags, we're okay.
1038 FLAGS_undefok ||
1039 // Otherwise, make sure that all specified configs have become sinks.
1040 configs.count() == gSinks.count()) {
1041 return true;
1042 }
1043 info("Invalid --config. Use --undefok to bypass this warning.\n");
1044 return false;
mtklein114c3cd2015-01-15 10:15:02 -08001045}
mtklein709d2c32015-01-15 08:30:25 -08001046
mtkleina5114d72015-08-24 13:27:01 -07001047static bool dump_png(SkBitmap bitmap, const char* path, const char* md5) {
Mike Klein13b6afd2017-06-12 12:45:41 -04001048 SkPixmap pm;
1049 if (!bitmap.peekPixels(&pm)) {
1050 return false; // Ought to never happen... we're already read-back at this point.
mtkleina5114d72015-08-24 13:27:01 -07001051 }
Mike Klein13b6afd2017-06-12 12:45:41 -04001052 SkFILEWStream dst{path};
mtkleina5114d72015-08-24 13:27:01 -07001053
mtkleind69ece62015-09-10 10:37:44 -07001054 SkString description;
1055 description.append("Key: ");
1056 for (int i = 0; i < FLAGS_key.count(); i++) {
1057 description.appendf("%s ", FLAGS_key[i]);
1058 }
1059 description.append("Properties: ");
1060 for (int i = 0; i < FLAGS_properties.count(); i++) {
1061 description.appendf("%s ", FLAGS_properties[i]);
1062 }
1063 description.appendf("MD5: %s", md5);
1064
Mike Klein13b6afd2017-06-12 12:45:41 -04001065 const char* comments[] = {
1066 "Author", "DM dump_png()",
1067 "Description", description.c_str(),
1068 };
1069 size_t lengths[] = {
1070 strlen(comments[0])+1, strlen(comments[1])+1,
1071 strlen(comments[2])+1, strlen(comments[3])+1,
1072 };
mtkleina5114d72015-08-24 13:27:01 -07001073
Mike Kleinae4b1f42018-09-13 11:13:15 -04001074 // PNGs can't hold out-of-gamut values, so if we're likely to be holding them,
1075 // convert to a wide gamut, giving us the best chance to have the PNG look like our colors.
1076 SkBitmap wide;
1077 if (pm.colorType() >= kRGBA_F16_SkColorType) {
1078 wide.allocPixels(pm.info().makeColorSpace(rec2020()));
1079 SkAssertResult(wide.writePixels(pm, 0,0));
1080 SkAssertResult(wide.peekPixels(&pm));
1081 }
1082
Mike Klein13b6afd2017-06-12 12:45:41 -04001083 SkPngEncoder::Options options;
1084 options.fComments = SkDataTable::MakeCopyArrays((const void**)comments, lengths, 4);
1085 options.fFilterFlags = SkPngEncoder::FilterFlag::kNone;
1086 options.fZLibLevel = 1;
Mike Klein13b6afd2017-06-12 12:45:41 -04001087 return SkPngEncoder::Encode(&dst, pm, options);
mtkleina5114d72015-08-24 13:27:01 -07001088}
1089
mtkleina2ef6422015-01-15 13:44:22 -08001090static bool match(const char* needle, const char* haystack) {
Chris Daltonecf78ac2017-08-15 15:43:08 -06001091 if ('~' == needle[0]) {
1092 return !match(needle + 1, haystack);
1093 }
1094 if (0 == strcmp("_", needle)) {
1095 return true;
1096 }
1097 return nullptr != strstr(haystack, needle);
mtkleina2ef6422015-01-15 13:44:22 -08001098}
1099
mtklein3eed7dd2016-02-24 19:07:07 -08001100static bool is_blacklisted(const char* sink, const char* src,
1101 const char* srcOptions, const char* name) {
mtklein0d243ff2015-04-03 07:51:00 -07001102 for (int i = 0; i < FLAGS_blacklist.count() - 3; i += 4) {
mtkleina2ef6422015-01-15 13:44:22 -08001103 if (match(FLAGS_blacklist[i+0], sink) &&
djsollen54416de2015-04-03 07:24:48 -07001104 match(FLAGS_blacklist[i+1], src) &&
1105 match(FLAGS_blacklist[i+2], srcOptions) &&
1106 match(FLAGS_blacklist[i+3], name)) {
mtklein3eed7dd2016-02-24 19:07:07 -08001107 return true;
mtkleina2ef6422015-01-15 13:44:22 -08001108 }
1109 }
mtklein3eed7dd2016-02-24 19:07:07 -08001110 return false;
mtkleina2ef6422015-01-15 13:44:22 -08001111}
1112
mtkleincd50bca2016-01-05 06:20:20 -08001113// Even when a Task Sink reports to be non-threadsafe (e.g. GPU), we know things like
1114// .png encoding are definitely thread safe. This lets us offload that work to CPU threads.
1115static SkTaskGroup gDefinitelyThreadSafeWork;
1116
mtklein748ca3b2015-01-15 10:56:12 -08001117// The finest-grained unit of work we can run: draw a single Src into a single Sink,
1118// report any errors, and perhaps write out the output: a .png of the bitmap, or a raw stream.
1119struct Task {
mtkleine0effd62015-07-29 06:37:28 -07001120 Task(const TaggedSrc& src, const TaggedSink& sink) : src(src), sink(sink) {}
1121 const TaggedSrc& src;
1122 const TaggedSink& sink;
mtklein748ca3b2015-01-15 10:56:12 -08001123
mtklein21eaf3b2016-02-08 12:39:59 -08001124 static void Run(const Task& task) {
1125 SkString name = task.src->name();
mtkleine0effd62015-07-29 06:37:28 -07001126
mtkleinb9eb4ac2015-02-02 18:26:03 -08001127 SkString log;
mtklein3eed7dd2016-02-24 19:07:07 -08001128 if (!FLAGS_dryRun) {
mtklein748ca3b2015-01-15 10:56:12 -08001129 SkBitmap bitmap;
1130 SkDynamicMemoryWStream stream;
mtklein3eed7dd2016-02-24 19:07:07 -08001131 start(task.sink.tag.c_str(), task.src.tag.c_str(),
1132 task.src.options.c_str(), name.c_str());
mtklein21eaf3b2016-02-08 12:39:59 -08001133 Error err = task.sink->draw(*task.src, &bitmap, &stream, &log);
mtkleinb3b13b72016-03-07 13:20:52 -08001134 if (!log.isEmpty()) {
mtkleinc41fd922016-03-08 09:01:39 -08001135 info("%s %s %s %s:\n%s\n", task.sink.tag.c_str()
1136 , task.src.tag.c_str()
1137 , task.src.options.c_str()
1138 , name.c_str()
1139 , log.c_str());
mtkleinb3b13b72016-03-07 13:20:52 -08001140 }
mtklein748ca3b2015-01-15 10:56:12 -08001141 if (!err.isEmpty()) {
mtklein4089ef72015-03-05 08:40:28 -08001142 if (err.isFatal()) {
djsollen54416de2015-04-03 07:24:48 -07001143 fail(SkStringPrintf("%s %s %s %s: %s",
mtklein21eaf3b2016-02-08 12:39:59 -08001144 task.sink.tag.c_str(),
1145 task.src.tag.c_str(),
1146 task.src.options.c_str(),
mtklein4089ef72015-03-05 08:40:28 -08001147 name.c_str(),
1148 err.c_str()));
mtkleinb37cb412015-03-18 05:27:14 -07001149 } else {
mtklein3eed7dd2016-02-24 19:07:07 -08001150 done(task.sink.tag.c_str(), task.src.tag.c_str(),
1151 task.src.options.c_str(), name.c_str());
mtkleinba6ada72016-01-21 09:39:35 -08001152 return;
mtklein4089ef72015-03-05 08:40:28 -08001153 }
mtklein748ca3b2015-01-15 10:56:12 -08001154 }
mtklein62bd1a62015-01-27 14:46:26 -08001155
mtkleincd50bca2016-01-05 06:20:20 -08001156 // We're likely switching threads here, so we must capture by value, [=] or [foo,bar].
Hal Canary0b833192017-03-14 14:35:02 -04001157 SkStreamAsset* data = stream.detachAsStream().release();
mtkleincd50bca2016-01-05 06:20:20 -08001158 gDefinitelyThreadSafeWork.add([task,name,bitmap,data]{
Ben Wagner145dbcd2016-11-03 14:40:50 -04001159 std::unique_ptr<SkStreamAsset> ownedData(data);
mtkleincd50bca2016-01-05 06:20:20 -08001160
mtkleincd50bca2016-01-05 06:20:20 -08001161 SkString md5;
1162 if (!FLAGS_writePath.isEmpty() || !FLAGS_readPath.isEmpty()) {
1163 SkMD5 hash;
1164 if (data->getLength()) {
1165 hash.writeStream(data, data->getLength());
1166 data->rewind();
mtklein38408462015-07-08 07:25:27 -07001167 } else {
mtkleincd50bca2016-01-05 06:20:20 -08001168 // If we're BGRA (Linux, Windows), swizzle over to RGBA (Mac, Android).
1169 // This helps eliminate multiple 0-pixel-diff hashes on gold.skia.org.
1170 // (Android's general slow speed breaks the tie arbitrarily in RGBA's favor.)
1171 // We might consider promoting 565 to RGBA too.
1172 if (bitmap.colorType() == kBGRA_8888_SkColorType) {
1173 SkBitmap swizzle;
Matt Sarett68b8e3d2017-04-28 11:15:22 -04001174 SkAssertResult(sk_tool_utils::copy_to(&swizzle, kRGBA_8888_SkColorType,
1175 bitmap));
Mike Reedf0ffb892017-10-03 14:47:21 -04001176 hash.write(swizzle.getPixels(), swizzle.computeByteSize());
mtkleincd50bca2016-01-05 06:20:20 -08001177 } else {
Mike Reedf0ffb892017-10-03 14:47:21 -04001178 hash.write(bitmap.getPixels(), bitmap.computeByteSize());
mtkleincd50bca2016-01-05 06:20:20 -08001179 }
1180 }
1181 SkMD5::Digest digest;
1182 hash.finish(digest);
1183 for (int i = 0; i < 16; i++) {
1184 md5.appendf("%02x", digest.data[i]);
mtklein38408462015-07-08 07:25:27 -07001185 }
mtklein62bd1a62015-01-27 14:46:26 -08001186 }
mtklein62bd1a62015-01-27 14:46:26 -08001187
mtkleincd50bca2016-01-05 06:20:20 -08001188 if (!FLAGS_readPath.isEmpty() &&
mtklein3eed7dd2016-02-24 19:07:07 -08001189 !gGold.contains(Gold(task.sink.tag, task.src.tag,
1190 task.src.options, name, md5))) {
mtkleincd50bca2016-01-05 06:20:20 -08001191 fail(SkStringPrintf("%s not found for %s %s %s %s in %s",
1192 md5.c_str(),
mtklein21eaf3b2016-02-08 12:39:59 -08001193 task.sink.tag.c_str(),
1194 task.src.tag.c_str(),
1195 task.src.options.c_str(),
mtkleincd50bca2016-01-05 06:20:20 -08001196 name.c_str(),
1197 FLAGS_readPath[0]));
mtklein748ca3b2015-01-15 10:56:12 -08001198 }
mtkleincd50bca2016-01-05 06:20:20 -08001199
1200 if (!FLAGS_writePath.isEmpty()) {
mtklein21eaf3b2016-02-08 12:39:59 -08001201 const char* ext = task.sink->fileExtension();
Brian Osmanf1942de2017-08-30 14:50:22 -04001202 if (ext && !FLAGS_dont_write.contains(ext)) {
Mike Klein97d6a7a2017-07-24 10:37:19 -04001203 if (data->getLength()) {
1204 WriteToDisk(task, md5, ext, data, data->getLength(), nullptr);
1205 SkASSERT(bitmap.drawsNothing());
1206 } else if (!bitmap.drawsNothing()) {
1207 WriteToDisk(task, md5, ext, nullptr, 0, &bitmap);
1208 }
mtkleincd50bca2016-01-05 06:20:20 -08001209 }
1210 }
1211 });
mtklein748ca3b2015-01-15 10:56:12 -08001212 }
mtklein3eed7dd2016-02-24 19:07:07 -08001213 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 -08001214 }
1215
1216 static void WriteToDisk(const Task& task,
mtklein62bd1a62015-01-27 14:46:26 -08001217 SkString md5,
1218 const char* ext,
mtklein748ca3b2015-01-15 10:56:12 -08001219 SkStream* data, size_t len,
mtklein62bd1a62015-01-27 14:46:26 -08001220 const SkBitmap* bitmap) {
Brian Osmana76b7a92018-07-18 14:36:43 -04001221 bool gammaCorrect = bitmap &&
1222 bitmap->info().colorSpace() &&
1223 bitmap->info().colorSpace()->gammaIsLinear();
mtklein409d4702016-02-29 07:38:01 -08001224
mtklein748ca3b2015-01-15 10:56:12 -08001225 JsonWriter::BitmapResult result;
djsollen54416de2015-04-03 07:24:48 -07001226 result.name = task.src->name();
mtklein3eed7dd2016-02-24 19:07:07 -08001227 result.config = task.sink.tag;
djsollen54416de2015-04-03 07:24:48 -07001228 result.sourceType = task.src.tag;
1229 result.sourceOptions = task.src.options;
1230 result.ext = ext;
mtklein409d4702016-02-29 07:38:01 -08001231 result.gammaCorrect = gammaCorrect;
djsollen54416de2015-04-03 07:24:48 -07001232 result.md5 = md5;
mtklein748ca3b2015-01-15 10:56:12 -08001233 JsonWriter::AddBitmapResult(result);
1234
mtkleinb0531a72015-04-07 13:38:48 -07001235 // If an MD5 is uninteresting, we want it noted in the JSON file,
1236 // but don't want to dump it out as a .png (or whatever ext is).
1237 if (gUninterestingHashes.contains(md5)) {
1238 return;
1239 }
1240
mtklein748ca3b2015-01-15 10:56:12 -08001241 const char* dir = FLAGS_writePath[0];
1242 if (0 == strcmp(dir, "@")) { // Needed for iOS.
1243 dir = FLAGS_resourcePath[0];
1244 }
1245 sk_mkdir(dir);
1246
1247 SkString path;
1248 if (FLAGS_nameByHash) {
1249 path = SkOSPath::Join(dir, result.md5.c_str());
1250 path.append(".");
1251 path.append(ext);
1252 if (sk_exists(path.c_str())) {
1253 return; // Content-addressed. If it exists already, we're done.
1254 }
1255 } else {
kkinnunen3e980c32015-12-23 01:33:00 -08001256 path = SkOSPath::Join(dir, task.sink.tag.c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001257 sk_mkdir(path.c_str());
msarett9e707a02015-09-01 14:57:57 -07001258 path = SkOSPath::Join(path.c_str(), task.src.tag.c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001259 sk_mkdir(path.c_str());
msarett9e707a02015-09-01 14:57:57 -07001260 if (strcmp(task.src.options.c_str(), "") != 0) {
1261 path = SkOSPath::Join(path.c_str(), task.src.options.c_str());
djsollen54416de2015-04-03 07:24:48 -07001262 sk_mkdir(path.c_str());
1263 }
mtklein748ca3b2015-01-15 10:56:12 -08001264 path = SkOSPath::Join(path.c_str(), task.src->name().c_str());
1265 path.append(".");
1266 path.append(ext);
1267 }
1268
mtklein748ca3b2015-01-15 10:56:12 -08001269 if (bitmap) {
mtkleina5114d72015-08-24 13:27:01 -07001270 if (!dump_png(*bitmap, path.c_str(), result.md5.c_str())) {
mtklein748ca3b2015-01-15 10:56:12 -08001271 fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str()));
1272 return;
1273 }
1274 } else {
mtkleina5114d72015-08-24 13:27:01 -07001275 SkFILEWStream file(path.c_str());
1276 if (!file.isValid()) {
1277 fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str()));
1278 return;
1279 }
mtklein748ca3b2015-01-15 10:56:12 -08001280 if (!file.writeStream(data, len)) {
1281 fail(SkStringPrintf("Can't write to %s.\n", path.c_str()));
1282 return;
1283 }
1284 }
1285 }
1286};
1287
mtklein748ca3b2015-01-15 10:56:12 -08001288/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1289
1290// Unit tests don't fit so well into the Src/Sink model, so we give them special treatment.
1291
mtklein21eaf3b2016-02-08 12:39:59 -08001292static SkTDArray<skiatest::Test> gParallelTests, gSerialTests;
mtklein748ca3b2015-01-15 10:56:12 -08001293
1294static void gather_tests() {
mtklein6c5fed22015-01-20 13:47:23 -08001295 if (!FLAGS_src.contains("tests")) {
mtklein748ca3b2015-01-15 10:56:12 -08001296 return;
1297 }
Hal Canary972eba32018-07-30 17:07:07 -04001298 for (const skiatest::Test& test : skiatest::TestRegistry::Range()) {
mtklein6393c062015-04-27 08:45:01 -07001299 if (!in_shard()) {
1300 continue;
1301 }
halcanary87f3ba42015-01-20 09:30:20 -08001302 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, test.name)) {
mtklein748ca3b2015-01-15 10:56:12 -08001303 continue;
1304 }
Brian Osmanc7ad40f2018-05-31 14:27:17 -04001305 if (test.needsGpu && FLAGS_gpu) {
Mike Reed5edcd312018-08-08 11:23:41 -04001306 (FLAGS_gpu_threading ? gParallelTests : gSerialTests).push_back(test);
halcanary87f3ba42015-01-20 09:30:20 -08001307 } else if (!test.needsGpu && FLAGS_cpu) {
Mike Reed5edcd312018-08-08 11:23:41 -04001308 gParallelTests.push_back(test);
mtklein82d28432015-01-15 12:46:02 -08001309 }
mtklein748ca3b2015-01-15 10:56:12 -08001310 }
1311}
1312
csmartdalton008b9d82017-02-22 12:00:42 -07001313static void run_test(skiatest::Test test, const GrContextOptions& grCtxOptions) {
halcanary87f3ba42015-01-20 09:30:20 -08001314 struct : public skiatest::Reporter {
mtklein36352bf2015-03-25 18:17:31 -07001315 void reportFailed(const skiatest::Failure& failure) override {
halcanary87f3ba42015-01-20 09:30:20 -08001316 fail(failure.toString());
1317 JsonWriter::AddTestFailure(failure);
1318 }
mtklein36352bf2015-03-25 18:17:31 -07001319 bool allowExtendedTest() const override {
halcanary87f3ba42015-01-20 09:30:20 -08001320 return FLAGS_pathOpsExtended;
1321 }
mtklein36352bf2015-03-25 18:17:31 -07001322 bool verbose() const override { return FLAGS_veryVerbose; }
halcanary87f3ba42015-01-20 09:30:20 -08001323 } reporter;
djsollen824996a2015-06-12 12:06:22 -07001324
mtklein3eed7dd2016-02-24 19:07:07 -08001325 if (!FLAGS_dryRun && !is_blacklisted("_", "tests", "_", test.name)) {
Robert Phillipsec325342017-10-30 18:02:48 +00001326 GrContextOptions options = grCtxOptions;
1327 test.modifyGrContextOptions(&options);
1328
mtklein21eaf3b2016-02-08 12:39:59 -08001329 start("unit", "test", "", test.name);
Brian Salomondcfca432017-11-15 15:48:03 -05001330 test.run(&reporter, options);
mtklein748ca3b2015-01-15 10:56:12 -08001331 }
mtklein3eed7dd2016-02-24 19:07:07 -08001332 done("unit", "test", "", test.name);
mtklein748ca3b2015-01-15 10:56:12 -08001333}
1334
1335/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1336
Mike Kleinbe28ee22017-02-06 12:46:20 -05001337int main(int argc, char** argv) {
Dongwon Kang0c7861f2018-02-16 10:55:21 -08001338#if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && defined(SK_HAS_HEIF_LIBRARY)
1339 android::ProcessState::self()->startThreadPool();
1340#endif
Mike Kleinbe28ee22017-02-06 12:46:20 -05001341 SkCommandLineFlags::Parse(argc, argv);
Brian Osman53136aa2017-07-20 15:43:35 -04001342
Mike Klein31868212017-11-06 12:02:47 -05001343 if (!FLAGS_nativeFonts) {
Ben Wagner483c7722018-02-20 17:06:07 -05001344 gSkFontMgr_DefaultFactory = &sk_tool_utils::MakePortableFontMgr;
Mike Klein31868212017-11-06 12:02:47 -05001345 }
1346
Mike Klein0c5fdcb2017-11-13 12:40:46 -05001347#if defined(SK_BUILD_FOR_WIN)
1348 if (FLAGS_gdi) {
Hal Canaryccafca02017-11-14 10:34:48 -05001349 gSkFontMgr_DefaultFactory = &SkFontMgr_New_GDI;
Mike Klein0c5fdcb2017-11-13 12:40:46 -05001350 }
1351#endif
1352
Brian Osmanbc8150f2017-07-24 11:38:01 -04001353 initializeEventTracingForTools();
Brian Osman53136aa2017-07-20 15:43:35 -04001354
Mike Klein6613cc52017-12-19 09:09:33 -05001355#if !defined(SK_BUILD_FOR_GOOGLE3) && defined(SK_BUILD_FOR_IOS)
Mike Kleinadacaef2017-02-06 09:26:14 -05001356 cd_Documents();
1357#endif
bsalomon71de3532016-04-26 14:27:21 -07001358 setbuf(stdout, nullptr);
mtklein246ba3a2016-02-23 10:39:36 -08001359 setup_crash_handler();
mtkleinafae30a2016-02-24 12:28:32 -08001360
Yuqian Liba62b4a2016-12-14 13:46:53 -05001361 gSkUseAnalyticAA = FLAGS_analyticAA;
Yuqian Lidf60e362017-07-25 11:26:31 -04001362 gSkUseDeltaAA = FLAGS_deltaAA;
liyuqian38911a72016-10-04 11:23:22 -07001363
Yuqian Li550148b2017-01-13 10:13:13 -05001364 if (FLAGS_forceAnalyticAA) {
1365 gSkForceAnalyticAA = true;
1366 }
Yuqian Lia81b6262017-09-06 17:10:05 -04001367 if (FLAGS_forceDeltaAA) {
1368 gSkForceDeltaAA = true;
1369 }
Mike Reed7c26ca72017-07-05 15:45:52 -04001370 if (FLAGS_forceRasterPipeline) {
1371 gSkForceRasterPipelineBlitter = true;
1372 }
Yuqian Li550148b2017-01-13 10:13:13 -05001373
Mike Kleine9f187b2017-06-26 13:23:12 -04001374 // The bots like having a verbose.log to upload, so always touch the file even if --verbose.
1375 if (!FLAGS_writePath.isEmpty()) {
mtklein51c8cfc2016-03-11 12:59:09 -08001376 sk_mkdir(FLAGS_writePath[0]);
mtkleina1ce2162016-07-22 12:23:46 -07001377 gVLog = fopen(SkOSPath::Join(FLAGS_writePath[0], "verbose.log").c_str(), "w");
mtkleinc41fd922016-03-08 09:01:39 -08001378 }
Mike Kleine9f187b2017-06-26 13:23:12 -04001379 if (FLAGS_verbose) {
1380 gVLog = stderr;
1381 }
mtkleinc41fd922016-03-08 09:01:39 -08001382
csmartdalton008b9d82017-02-22 12:00:42 -07001383 GrContextOptions grCtxOptions;
Chris Dalton040238b2017-12-18 14:22:34 -07001384 SetCtxOptionsFromCommonFlags(&grCtxOptions);
csmartdalton008b9d82017-02-22 12:00:42 -07001385
mtklein5286f022016-01-22 08:18:14 -08001386 JsonWriter::DumpJson(); // It's handy for the bots to assume this is ~never missing.
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +00001387 SkAutoGraphics ag;
mtklein406654b2014-09-03 15:34:37 -07001388 SkTaskGroup::Enabler enabled(FLAGS_threads);
commit-bot@chromium.orga65e2fd2014-05-30 17:23:31 +00001389
Mike Reed0933bc92017-12-09 01:27:41 +00001390 if (nullptr == GetResourceAsData("images/color_wheel.png")) {
1391 info("Some resources are missing. Do you need to set --resourcePath?\n");
halcanary7d571242016-02-24 17:59:16 -08001392 }
mtklein62bd1a62015-01-27 14:46:26 -08001393 gather_gold();
borenet09ed4802015-04-03 14:15:33 -07001394 gather_uninteresting_hashes();
mtklein62bd1a62015-01-27 14:46:26 -08001395
scroggo86737142016-02-03 12:19:11 -08001396 if (!gather_srcs()) {
1397 return 1;
1398 }
Ben Wagnerf28d4722017-08-11 17:33:22 -04001399 // TODO(dogben): This is a bit ugly. Find a cleaner way to do this.
1400 bool defaultConfigs = true;
1401 for (int i = 0; i < argc; i++) {
1402 static const char* kConfigArg = "--config";
1403 if (strcmp(argv[i], kConfigArg) == 0) {
1404 defaultConfigs = false;
1405 break;
1406 }
1407 }
1408 if (!gather_sinks(grCtxOptions, defaultConfigs)) {
brianosman05c987c2016-05-09 13:42:16 -07001409 return 1;
1410 }
mtklein748ca3b2015-01-15 10:56:12 -08001411 gather_tests();
mtklein21eaf3b2016-02-08 12:39:59 -08001412 gPending = gSrcs.count() * gSinks.count() + gParallelTests.count() + gSerialTests.count();
Brian Osmand0677bc2017-08-03 12:13:47 -04001413 info("%d srcs * %d sinks + %d tests == %d tasks\n",
mtkleinc41fd922016-03-08 09:01:39 -08001414 gSrcs.count(), gSinks.count(), gParallelTests.count() + gSerialTests.count(), gPending);
mtklein748ca3b2015-01-15 10:56:12 -08001415
mtklein21eaf3b2016-02-08 12:39:59 -08001416 // Kick off as much parallel work as we can, making note of any serial work we'll need to do.
1417 SkTaskGroup parallel;
1418 SkTArray<Task> serial;
1419
1420 for (auto& sink : gSinks)
1421 for (auto& src : gSrcs) {
mtklein3eed7dd2016-02-24 19:07:07 -08001422 if (src->veto(sink->flags()) ||
1423 is_blacklisted(sink.tag.c_str(), src.tag.c_str(),
1424 src.options.c_str(), src->name().c_str())) {
mtkleinf10637f2016-06-10 13:56:35 -07001425 SkAutoMutexAcquire lock(gMutex);
mtklein3eed7dd2016-02-24 19:07:07 -08001426 gPending--;
1427 continue;
1428 }
1429
mtklein21eaf3b2016-02-08 12:39:59 -08001430 Task task(src, sink);
1431 if (src->serial() || sink->serial()) {
1432 serial.push_back(task);
1433 } else {
1434 parallel.add([task] { Task::Run(task); });
mtklein748ca3b2015-01-15 10:56:12 -08001435 }
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001436 }
mtklein21eaf3b2016-02-08 12:39:59 -08001437 for (auto test : gParallelTests) {
csmartdalton008b9d82017-02-22 12:00:42 -07001438 parallel.add([test, grCtxOptions] { run_test(test, grCtxOptions); });
mtklein55e88b22015-01-21 15:50:13 -08001439 }
mtklein21eaf3b2016-02-08 12:39:59 -08001440
1441 // With the parallel work running, run serial tasks and tests here on main thread.
1442 for (auto task : serial) { Task::Run(task); }
csmartdalton008b9d82017-02-22 12:00:42 -07001443 for (auto test : gSerialTests) { run_test(test, grCtxOptions); }
mtklein21eaf3b2016-02-08 12:39:59 -08001444
1445 // Wait for any remaining parallel work to complete (including any spun off of serial tasks).
1446 parallel.wait();
mtkleincd50bca2016-01-05 06:20:20 -08001447 gDefinitelyThreadSafeWork.wait();
1448
Ben Wagner83c6b962018-07-10 19:40:15 -04001449 // At this point we're back in single-threaded land.
1450
mtkleinda884c42016-02-24 18:00:23 -08001451 // We'd better have run everything.
1452 SkASSERT(gPending == 0);
mtkleine027f172016-02-26 15:53:06 -08001453 // Make sure we've flushed all our results to disk.
1454 JsonWriter::DumpJson();
mtkleinda884c42016-02-24 18:00:23 -08001455
mtklein748ca3b2015-01-15 10:56:12 -08001456 if (gFailures.count() > 0) {
mtkleinc41fd922016-03-08 09:01:39 -08001457 info("Failures:\n");
mtklein748ca3b2015-01-15 10:56:12 -08001458 for (int i = 0; i < gFailures.count(); i++) {
mtkleinc41fd922016-03-08 09:01:39 -08001459 info("\t%s\n", gFailures[i].c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001460 }
mtkleinc41fd922016-03-08 09:01:39 -08001461 info("%d failures\n", gFailures.count());
mtklein748ca3b2015-01-15 10:56:12 -08001462 return 1;
mtklein114c3cd2015-01-15 10:15:02 -08001463 }
mtkleinafae30a2016-02-24 12:28:32 -08001464
1465#ifdef SK_PDF_IMAGE_STATS
halcanary7a14b312015-10-01 07:28:13 -07001466 SkPDFImageDumpStats();
mtkleinafae30a2016-02-24 12:28:32 -08001467#endif // SK_PDF_IMAGE_STATS
1468
Herb Derby5a523fe2017-01-26 16:48:28 -05001469 SkGraphics::PurgeAllCaches();
mtkleinc41fd922016-03-08 09:01:39 -08001470 info("Finished!\n");
Brian Osman53136aa2017-07-20 15:43:35 -04001471
mtklein748ca3b2015-01-15 10:56:12 -08001472 return 0;
mtklein@google.comd36522d2013-10-16 13:02:15 +00001473}