blob: 459e51a0a0f70866a535e03a92bf919d791b0484 [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"
mtklein27c3fdd2016-02-26 14:43:21 -080035#include "SkPM4fPriv.h"
Mike Klein13b6afd2017-06-12 12:45:41 -040036#include "SkPngEncoder.h"
Brian Salomondcbb9d92017-07-19 10:53:20 -040037#include "SkScan.h"
mtklein246ba3a2016-02-23 10:39:36 -080038#include "SkSpinlock.h"
Hal Canaryf4abda52018-08-06 19:29:43 +000039#include "SkTestFontMgr.h"
mtkleina82f5622015-02-20 12:30:19 -080040#include "SkTHash.h"
mtklein406654b2014-09-03 15:34:37 -070041#include "SkTaskGroup.h"
Mike Klein0c5fdcb2017-11-13 12:40:46 -050042#include "SkTypeface_win.h"
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000043#include "Test.h"
mtklein748ca3b2015-01-15 10:56:12 -080044#include "Timer.h"
Mike Kleinadacaef2017-02-06 09:26:14 -050045#include "ios_utils.h"
caryclark83ca6282015-06-10 09:31:09 -070046#include "sk_tool_utils.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000047
scroggo19b91532016-10-24 09:03:26 -070048#include <vector>
49
halcanary7a14b312015-10-01 07:28:13 -070050#ifdef SK_PDF_IMAGE_STATS
51extern void SkPDFImageDumpStats();
52#endif
53
mtkleina5114d72015-08-24 13:27:01 -070054#include "png.h"
55
bungeman60e0fee2015-08-26 05:15:46 -070056#include <stdlib.h>
57
Mike Klein8f11d4d2018-01-24 12:42:55 -050058#ifndef SK_BUILD_FOR_WIN
scroggo27a58342015-10-28 08:56:41 -070059 #include <unistd.h>
60#endif
61
Dongwon Kang0c7861f2018-02-16 10:55:21 -080062#if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && defined(SK_HAS_HEIF_LIBRARY)
63#include <binder/IPCThreadState.h>
64#endif
65
Mike Reed7c26ca72017-07-05 15:45:52 -040066extern bool gSkForceRasterPipelineBlitter;
67
Ben Wagner32fa5102017-08-10 21:25:55 -040068DECLARE_bool(undefok);
djsollen54416de2015-04-03 07:24:48 -070069DEFINE_string(src, "tests gm skp image", "Source types to test.");
mtklein748ca3b2015-01-15 10:56:12 -080070DEFINE_bool(nameByHash, false,
71 "If true, write to FLAGS_writePath[0]/<hash>.png instead of "
djsollen54416de2015-04-03 07:24:48 -070072 "to FLAGS_writePath[0]/<config>/<sourceType>/<sourceOptions>/<name>.png");
mtklein748ca3b2015-01-15 10:56:12 -080073DEFINE_bool2(pathOpsExtended, x, false, "Run extended pathOps tests.");
mtkleind603b222015-02-17 11:13:33 -080074DEFINE_string(matrix, "1 0 0 1",
75 "2x2 scale+skew matrix to apply or upright when using "
76 "'matrix' or 'upright' in config.");
mtklein82d28432015-01-15 12:46:02 -080077DEFINE_bool(gpu_threading, false, "Allow GPU work to run on multiple threads?");
mtklein@google.comd36522d2013-10-16 13:02:15 +000078
mtkleina2ef6422015-01-15 13:44:22 -080079DEFINE_string(blacklist, "",
Chris Daltonecf78ac2017-08-15 15:43:08 -060080 "Space-separated config/src/srcOptions/name quadruples to blacklist. "
81 "'_' matches anything. '~' negates the match. E.g. \n"
djsollen54416de2015-04-03 07:24:48 -070082 "'--blacklist gpu skp _ _' will blacklist all SKPs drawn into the gpu config.\n"
Chris Daltonecf78ac2017-08-15 15:43:08 -060083 "'--blacklist gpu skp _ _ 8888 gm _ aarects' will also blacklist the aarects GM on 8888.\n"
84 "'--blacklist ~8888 svg _ svgparse_' blocks non-8888 SVGs that contain \"svgparse_\" in "
85 "the name.");
mtkleina2ef6422015-01-15 13:44:22 -080086
mtklein62bd1a62015-01-27 14:46:26 -080087DEFINE_string2(readPath, r, "", "If set check for equality with golden results in this directory.");
88
borenet09ed4802015-04-03 14:15:33 -070089DEFINE_string(uninterestingHashesFile, "",
90 "File containing a list of uninteresting hashes. If a result hashes to something in "
91 "this list, no image is written for that result.");
92
mtklein6393c062015-04-27 08:45:01 -070093DEFINE_int32(shards, 1, "We're splitting source data into this many shards.");
94DEFINE_int32(shard, 0, "Which shard do I run?");
95
halcanary45420a92016-06-02 12:41:14 -070096DEFINE_string(mskps, "", "Directory to read mskps from, or a single mskp file.");
Mike Reed7c26ca72017-07-05 15:45:52 -040097DEFINE_bool(forceRasterPipeline, false, "sets gSkForceRasterPipelineBlitter");
halcanary45420a92016-06-02 12:41:14 -070098
Derek Sollenbergeredfe3df2017-07-19 15:25:24 -040099DEFINE_bool(ignoreSigInt, false, "ignore SIGINT signals during test execution");
100
Mike Klein97d6a7a2017-07-24 10:37:19 -0400101DEFINE_string(dont_write, "", "File extensions to skip writing to --writePath."); // See skia:6821
102
Mike Klein0c5fdcb2017-11-13 12:40:46 -0500103DEFINE_bool(gdi, false, "On Windows, use GDI instead of DirectWrite for font rendering.");
Mike Klein31868212017-11-06 12:02:47 -0500104
mtklein748ca3b2015-01-15 10:56:12 -0800105using namespace DM;
bsalomon3724e572016-03-30 18:56:19 -0700106using sk_gpu_test::GrContextFactory;
bsalomon273c0f52016-03-31 10:59:06 -0700107using sk_gpu_test::GLTestContext;
bsalomonf2f1c172016-04-05 12:59:06 -0700108using sk_gpu_test::ContextInfo;
mtklein@google.comd36522d2013-10-16 13:02:15 +0000109
mtklein748ca3b2015-01-15 10:56:12 -0800110/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
111
benjaminwagnerec4d4d72016-03-25 12:59:53 -0700112static const double kStartMs = SkTime::GetMSecs();
mtkleinc41fd922016-03-08 09:01:39 -0800113
114static FILE* gVLog;
115
116template <typename... Args>
117static void vlog(const char* fmt, Args&&... args) {
118 if (gVLog) {
Jim Van Verth32bbf372017-09-20 12:53:00 -0400119 char s[64];
120 HumanizeMs(s, 64, SkTime::GetMSecs() - kStartMs);
121 fprintf(gVLog, "%s\t", s);
mtkleinc41fd922016-03-08 09:01:39 -0800122 fprintf(gVLog, fmt, args...);
123 fflush(gVLog);
124 }
125}
126
127template <typename... Args>
128static void info(const char* fmt, Args&&... args) {
129 vlog(fmt, args...);
130 if (!FLAGS_quiet) {
131 printf(fmt, args...);
132 }
133}
134static void info(const char* fmt) {
135 if (!FLAGS_quiet) {
136 printf("%s", fmt); // Clang warns printf(fmt) is insecure.
137 }
138}
139
reed086eea92016-05-04 17:12:46 -0700140SK_DECLARE_STATIC_MUTEX(gFailuresMutex);
mtklein748ca3b2015-01-15 10:56:12 -0800141static SkTArray<SkString> gFailures;
142
mtklein3eed7dd2016-02-24 19:07:07 -0800143static void fail(const SkString& err) {
mtklein748ca3b2015-01-15 10:56:12 -0800144 SkAutoMutexAcquire lock(gFailuresMutex);
145 SkDebugf("\n\nFAILURE: %s\n\n", err.c_str());
146 gFailures.push_back(err);
halcanary9e398f72015-01-10 11:18:04 -0800147}
148
mtklein0f7748a2016-07-25 15:27:29 -0700149struct Running {
150 SkString id;
151 SkThreadID thread;
152
153 void dump() const {
154 info("\t%s\n", id.c_str());
155 }
156};
mtkleinb37cb412015-03-18 05:27:14 -0700157
mtklein246ba3a2016-02-23 10:39:36 -0800158// We use a spinlock to make locking this in a signal handler _somewhat_ safe.
Mike Klein03a95ad2017-06-23 12:36:32 -0400159static SkSpinlock gMutex;
160static int gPending;
mtklein0f7748a2016-07-25 15:27:29 -0700161static SkTArray<Running> gRunning;
mtklein748ca3b2015-01-15 10:56:12 -0800162
mtklein3eed7dd2016-02-24 19:07:07 -0800163static void done(const char* config, const char* src, const char* srcOptions, const char* name) {
164 SkString id = SkStringPrintf("%s %s %s %s", config, src, srcOptions, name);
mtkleinc41fd922016-03-08 09:01:39 -0800165 vlog("done %s\n", id.c_str());
mtkleinafae30a2016-02-24 12:28:32 -0800166 int pending;
mtkleinb37cb412015-03-18 05:27:14 -0700167 {
mtkleinf10637f2016-06-10 13:56:35 -0700168 SkAutoMutexAcquire lock(gMutex);
mtkleinb37cb412015-03-18 05:27:14 -0700169 for (int i = 0; i < gRunning.count(); i++) {
mtklein0f7748a2016-07-25 15:27:29 -0700170 if (gRunning[i].id == id) {
mtkleinb37cb412015-03-18 05:27:14 -0700171 gRunning.removeShuffle(i);
172 break;
173 }
174 }
mtkleinafae30a2016-02-24 12:28:32 -0800175 pending = --gPending;
reed50bc0512015-05-19 14:13:31 -0700176 }
Mike Klein03a95ad2017-06-23 12:36:32 -0400177
178 // We write out dm.json file and print out a progress update every once in a while.
179 // Notice this also handles the final dm.json and progress update when pending == 0.
mtkleina17241b2015-01-23 05:48:00 -0800180 if (pending % 500 == 0) {
181 JsonWriter::DumpJson();
Mike Klein03a95ad2017-06-23 12:36:32 -0400182
183 int curr = sk_tools::getCurrResidentSetSizeMB(),
184 peak = sk_tools::getMaxResidentSetSizeMB();
185 SkString elapsed = HumanizeMs(SkTime::GetMSecs() - kStartMs);
186
187 SkAutoMutexAcquire lock(gMutex);
188 info("\n%dMB RAM, %dMB peak, %s elapsed, %d queued, %d active:\n",
189 curr, peak, elapsed.c_str(), gPending - gRunning.count(), gRunning.count());
190 for (auto& task : gRunning) {
191 task.dump();
192 }
mtkleina17241b2015-01-23 05:48:00 -0800193 }
mtklein@google.comd36522d2013-10-16 13:02:15 +0000194}
195
mtklein3eed7dd2016-02-24 19:07:07 -0800196static void start(const char* config, const char* src, const char* srcOptions, const char* name) {
197 SkString id = SkStringPrintf("%s %s %s %s", config, src, srcOptions, name);
mtkleinc41fd922016-03-08 09:01:39 -0800198 vlog("start %s\n", id.c_str());
mtkleinf10637f2016-06-10 13:56:35 -0700199 SkAutoMutexAcquire lock(gMutex);
mtklein0f7748a2016-07-25 15:27:29 -0700200 gRunning.push_back({id,SkGetThreadID()});
mtkleinb37cb412015-03-18 05:27:14 -0700201}
202
Mike Klein3cc2d202016-10-24 11:39:43 -0400203static void find_culprit() {
204 // Assumes gMutex is locked.
205 SkThreadID thisThread = SkGetThreadID();
206 for (auto& task : gRunning) {
207 if (task.thread == thisThread) {
208 info("Likely culprit:\n");
209 task.dump();
mtklein0f7748a2016-07-25 15:27:29 -0700210 }
211 }
Mike Klein3cc2d202016-10-24 11:39:43 -0400212}
mtklein0f7748a2016-07-25 15:27:29 -0700213
Mike Klein8f11d4d2018-01-24 12:42:55 -0500214#if defined(SK_BUILD_FOR_WIN)
mtklein5b64dab2016-06-09 08:59:48 -0700215 static LONG WINAPI crash_handler(EXCEPTION_POINTERS* e) {
mtkleinf8557292016-02-29 06:35:28 -0800216 static const struct {
217 const char* name;
robertphillips75467862016-03-01 14:10:23 -0800218 DWORD code;
mtkleinf8557292016-02-29 06:35:28 -0800219 } kExceptions[] = {
220 #define _(E) {#E, E}
221 _(EXCEPTION_ACCESS_VIOLATION),
222 _(EXCEPTION_BREAKPOINT),
223 _(EXCEPTION_INT_DIVIDE_BY_ZERO),
224 _(EXCEPTION_STACK_OVERFLOW),
225 // TODO: more?
226 #undef _
227 };
228
mtkleinf10637f2016-06-10 13:56:35 -0700229 SkAutoMutexAcquire lock(gMutex);
mtklein5b64dab2016-06-09 08:59:48 -0700230
231 const DWORD code = e->ExceptionRecord->ExceptionCode;
232 info("\nCaught exception %u", code);
233 for (const auto& exception : kExceptions) {
234 if (exception.code == code) {
235 info(" %s", exception.name);
mtkleinf8557292016-02-29 06:35:28 -0800236 }
mtkleinf8557292016-02-29 06:35:28 -0800237 }
mtklein5b64dab2016-06-09 08:59:48 -0700238 info(", was running:\n");
239 for (auto& task : gRunning) {
mtklein0f7748a2016-07-25 15:27:29 -0700240 task.dump();
mtklein5b64dab2016-06-09 08:59:48 -0700241 }
mtklein0f7748a2016-07-25 15:27:29 -0700242 find_culprit();
mtklein5b64dab2016-06-09 08:59:48 -0700243 fflush(stdout);
244
mtkleinf8557292016-02-29 06:35:28 -0800245 // Execute default exception handler... hopefully, exit.
246 return EXCEPTION_EXECUTE_HANDLER;
mtklein246ba3a2016-02-23 10:39:36 -0800247 }
248
Mike Klein3cc2d202016-10-24 11:39:43 -0400249 static void setup_crash_handler() {
250 SetUnhandledExceptionFilter(crash_handler);
251 }
252#else
mtklein246ba3a2016-02-23 10:39:36 -0800253 #include <signal.h>
Mike Klein3cc2d202016-10-24 11:39:43 -0400254 #if !defined(SK_BUILD_FOR_ANDROID)
255 #include <execinfo.h>
Brian Salomondcbb9d92017-07-19 10:53:20 -0400256
257#endif
Mike Klein3cc2d202016-10-24 11:39:43 -0400258
259 static constexpr int max_of() { return 0; }
260 template <typename... Rest>
261 static constexpr int max_of(int x, Rest... rest) {
262 return x > max_of(rest...) ? x : max_of(rest...);
263 }
264
Mike Kleinc7278ad2018-02-15 09:26:54 -0500265 static void (*previous_handler[max_of(SIGABRT,SIGBUS,SIGFPE,SIGILL,SIGSEGV,SIGTERM)+1])(int);
mtkleinf8557292016-02-29 06:35:28 -0800266
mtklein5b64dab2016-06-09 08:59:48 -0700267 static void crash_handler(int sig) {
mtkleinf10637f2016-06-10 13:56:35 -0700268 SkAutoMutexAcquire lock(gMutex);
mtklein5b64dab2016-06-09 08:59:48 -0700269
Mike Klein701a3582018-06-28 14:08:19 +0000270 info("\nCaught signal %d [%s] (%dMB RAM, peak %dMB), was running:\n",
271 sig, strsignal(sig),
272 sk_tools::getCurrResidentSetSizeMB(), sk_tools::getMaxResidentSetSizeMB());
273
mtklein5b64dab2016-06-09 08:59:48 -0700274 for (auto& task : gRunning) {
mtklein0f7748a2016-07-25 15:27:29 -0700275 task.dump();
mtklein5b64dab2016-06-09 08:59:48 -0700276 }
mtklein0f7748a2016-07-25 15:27:29 -0700277 find_culprit();
mtklein5b64dab2016-06-09 08:59:48 -0700278
Mike Klein3cc2d202016-10-24 11:39:43 -0400279 #if !defined(SK_BUILD_FOR_ANDROID)
mtklein5b64dab2016-06-09 08:59:48 -0700280 void* stack[64];
281 int count = backtrace(stack, SK_ARRAY_COUNT(stack));
282 char** symbols = backtrace_symbols(stack, count);
283 info("\nStack trace:\n");
284 for (int i = 0; i < count; i++) {
285 info(" %s\n", symbols[i]);
286 }
Mike Klein3cc2d202016-10-24 11:39:43 -0400287 #endif
mtklein5b64dab2016-06-09 08:59:48 -0700288 fflush(stdout);
289
Mike Klein3cc2d202016-10-24 11:39:43 -0400290 signal(sig, previous_handler[sig]);
291 raise(sig);
mtklein5b64dab2016-06-09 08:59:48 -0700292 }
293
mtklein246ba3a2016-02-23 10:39:36 -0800294 static void setup_crash_handler() {
Mike Klein701a3582018-06-28 14:08:19 +0000295 const int kSignals[] = { SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGINT, SIGSEGV, SIGTERM };
mtklein246ba3a2016-02-23 10:39:36 -0800296 for (int sig : kSignals) {
Mike Klein3cc2d202016-10-24 11:39:43 -0400297 previous_handler[sig] = signal(sig, crash_handler);
mtklein246ba3a2016-02-23 10:39:36 -0800298 }
Derek Sollenbergeredfe3df2017-07-19 15:25:24 -0400299
300 if (FLAGS_ignoreSigInt) {
301 signal(SIGINT, SIG_IGN);
302 }
mtklein246ba3a2016-02-23 10:39:36 -0800303 }
304#endif
305
mtklein748ca3b2015-01-15 10:56:12 -0800306/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
mtklein114c3cd2015-01-15 10:15:02 -0800307
mtklein62bd1a62015-01-27 14:46:26 -0800308struct Gold : public SkString {
mtkleina82f5622015-02-20 12:30:19 -0800309 Gold() : SkString("") {}
mtklein3eed7dd2016-02-24 19:07:07 -0800310 Gold(const SkString& sink, const SkString& src,
311 const SkString& srcOptions, const SkString& name,
312 const SkString& md5)
mtklein62bd1a62015-01-27 14:46:26 -0800313 : SkString("") {
314 this->append(sink);
315 this->append(src);
djsollen54416de2015-04-03 07:24:48 -0700316 this->append(srcOptions);
mtklein62bd1a62015-01-27 14:46:26 -0800317 this->append(name);
318 this->append(md5);
mtklein62bd1a62015-01-27 14:46:26 -0800319 }
mtkleinc8d1dd42015-10-15 12:23:01 -0700320 struct Hash {
321 uint32_t operator()(const Gold& g) const {
322 return SkGoodHash()((const SkString&)g);
323 }
324 };
mtklein62bd1a62015-01-27 14:46:26 -0800325};
mtkleina82f5622015-02-20 12:30:19 -0800326static SkTHashSet<Gold, Gold::Hash> gGold;
mtklein62bd1a62015-01-27 14:46:26 -0800327
328static void add_gold(JsonWriter::BitmapResult r) {
djsollen54416de2015-04-03 07:24:48 -0700329 gGold.add(Gold(r.config, r.sourceType, r.sourceOptions, r.name, r.md5));
mtklein62bd1a62015-01-27 14:46:26 -0800330}
331
332static void gather_gold() {
333 if (!FLAGS_readPath.isEmpty()) {
334 SkString path(FLAGS_readPath[0]);
335 path.append("/dm.json");
336 if (!JsonWriter::ReadJson(path.c_str(), add_gold)) {
337 fail(SkStringPrintf("Couldn't read %s for golden results.", path.c_str()));
338 }
339 }
340}
341
342/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
343
Mike Klein8f11d4d2018-01-24 12:42:55 -0500344#if defined(SK_BUILD_FOR_WIN)
mtklein935f1b12016-03-16 08:37:19 -0700345 static const char* kNewline = "\r\n";
346#else
347 static const char* kNewline = "\n";
348#endif
349
borenet09ed4802015-04-03 14:15:33 -0700350static SkTHashSet<SkString> gUninterestingHashes;
351
352static void gather_uninteresting_hashes() {
353 if (!FLAGS_uninterestingHashesFile.isEmpty()) {
bungeman38d909e2016-08-02 14:40:46 -0700354 sk_sp<SkData> data(SkData::MakeFromFileName(FLAGS_uninterestingHashesFile[0]));
mtkleincc334b32015-09-22 11:43:53 -0700355 if (!data) {
mtkleinc41fd922016-03-08 09:01:39 -0800356 info("WARNING: unable to read uninteresting hashes from %s\n",
357 FLAGS_uninterestingHashesFile[0]);
mtkleincc334b32015-09-22 11:43:53 -0700358 return;
359 }
Mike Klein45dcc0c2017-04-05 18:04:31 -0400360
361 // Copy to a string to make sure SkStrSplit has a terminating \0 to find.
362 SkString contents((const char*)data->data(), data->size());
363
borenet09ed4802015-04-03 14:15:33 -0700364 SkTArray<SkString> hashes;
Mike Klein45dcc0c2017-04-05 18:04:31 -0400365 SkStrSplit(contents.c_str(), kNewline, &hashes);
borenet09ed4802015-04-03 14:15:33 -0700366 for (const SkString& hash : hashes) {
367 gUninterestingHashes.add(hash);
368 }
mtkleinc41fd922016-03-08 09:01:39 -0800369 info("FYI: loaded %d distinct uninteresting hashes from %d lines\n",
370 gUninterestingHashes.count(), hashes.count());
borenet09ed4802015-04-03 14:15:33 -0700371 }
372}
373
374/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
375
Ben Wagner145dbcd2016-11-03 14:40:50 -0400376struct TaggedSrc : public std::unique_ptr<Src> {
mtklein3eed7dd2016-02-24 19:07:07 -0800377 SkString tag;
378 SkString options;
mtkleine0effd62015-07-29 06:37:28 -0700379};
380
Ben Wagner145dbcd2016-11-03 14:40:50 -0400381struct TaggedSink : public std::unique_ptr<Sink> {
kkinnunen3e980c32015-12-23 01:33:00 -0800382 SkString tag;
djsollen54416de2015-04-03 07:24:48 -0700383};
mtklein748ca3b2015-01-15 10:56:12 -0800384
385static const bool kMemcpyOK = true;
386
mtkleine0effd62015-07-29 06:37:28 -0700387static SkTArray<TaggedSrc, kMemcpyOK> gSrcs;
388static SkTArray<TaggedSink, kMemcpyOK> gSinks;
mtklein748ca3b2015-01-15 10:56:12 -0800389
mtklein6393c062015-04-27 08:45:01 -0700390static bool in_shard() {
391 static int N = 0;
392 return N++ % FLAGS_shards == FLAGS_shard;
393}
394
mtklein3eed7dd2016-02-24 19:07:07 -0800395static void push_src(const char* tag, ImplicitString options, Src* s) {
Ben Wagner145dbcd2016-11-03 14:40:50 -0400396 std::unique_ptr<Src> src(s);
mtklein6393c062015-04-27 08:45:01 -0700397 if (in_shard() &&
mtklein3eed7dd2016-02-24 19:07:07 -0800398 FLAGS_src.contains(tag) &&
mtklein748ca3b2015-01-15 10:56:12 -0800399 !SkCommandLineFlags::ShouldSkip(FLAGS_match, src->name().c_str())) {
mtkleine0effd62015-07-29 06:37:28 -0700400 TaggedSrc& s = gSrcs.push_back();
mtklein18300a32016-03-16 13:53:35 -0700401 s.reset(src.release());
mtklein748ca3b2015-01-15 10:56:12 -0800402 s.tag = tag;
djsollen54416de2015-04-03 07:24:48 -0700403 s.options = options;
mtklein114c3cd2015-01-15 10:15:02 -0800404 }
mtklein748ca3b2015-01-15 10:56:12 -0800405}
mtklein114c3cd2015-01-15 10:15:02 -0800406
msarett9e707a02015-09-01 14:57:57 -0700407static void push_codec_src(Path path, CodecSrc::Mode mode, CodecSrc::DstColorType dstColorType,
scroggoc5560be2016-02-03 09:42:42 -0800408 SkAlphaType dstAlphaType, float scale) {
scroggoe4499842016-02-25 11:03:47 -0800409 if (FLAGS_simpleCodec) {
scroggo19b91532016-10-24 09:03:26 -0700410 const bool simple = CodecSrc::kCodec_Mode == mode || CodecSrc::kAnimated_Mode == mode;
411 if (!simple || dstColorType != CodecSrc::kGetFromCanvas_DstColorType || scale != 1.0f) {
scroggoe4499842016-02-25 11:03:47 -0800412 // Only decode in the simple case.
413 return;
scroggo19b91532016-10-24 09:03:26 -0700414 }
scroggoe4499842016-02-25 11:03:47 -0800415 }
msarett9e707a02015-09-01 14:57:57 -0700416 SkString folder;
417 switch (mode) {
418 case CodecSrc::kCodec_Mode:
419 folder.append("codec");
420 break;
msarettbb25b532016-01-13 09:31:39 -0800421 case CodecSrc::kCodecZeroInit_Mode:
422 folder.append("codec_zero_init");
423 break;
msarett9e707a02015-09-01 14:57:57 -0700424 case CodecSrc::kScanline_Mode:
425 folder.append("scanline");
426 break;
msarett9e707a02015-09-01 14:57:57 -0700427 case CodecSrc::kStripe_Mode:
428 folder.append("stripe");
429 break;
msarett91c22b22016-02-22 12:27:46 -0800430 case CodecSrc::kCroppedScanline_Mode:
431 folder.append("crop");
432 break;
msarett9e707a02015-09-01 14:57:57 -0700433 case CodecSrc::kSubset_Mode:
msarett36c37962015-09-02 13:20:52 -0700434 folder.append("codec_subset");
msarett9e707a02015-09-01 14:57:57 -0700435 break;
scroggo19b91532016-10-24 09:03:26 -0700436 case CodecSrc::kAnimated_Mode:
437 folder.append("codec_animated");
438 break;
msarett9e707a02015-09-01 14:57:57 -0700439 }
440
441 switch (dstColorType) {
442 case CodecSrc::kGrayscale_Always_DstColorType:
443 folder.append("_kGray8");
444 break;
msarett34e0ec42016-04-22 16:27:24 -0700445 case CodecSrc::kNonNative8888_Always_DstColorType:
446 folder.append("_kNonNative");
447 break;
msarett9e707a02015-09-01 14:57:57 -0700448 default:
449 break;
450 }
451
scroggoc5560be2016-02-03 09:42:42 -0800452 switch (dstAlphaType) {
scroggoc5560be2016-02-03 09:42:42 -0800453 case kPremul_SkAlphaType:
454 folder.append("_premul");
455 break;
456 case kUnpremul_SkAlphaType:
457 folder.append("_unpremul");
458 break;
459 default:
460 break;
461 }
462
msarett9e707a02015-09-01 14:57:57 -0700463 if (1.0f != scale) {
464 folder.appendf("_%.3f", scale);
465 }
466
scroggoc5560be2016-02-03 09:42:42 -0800467 CodecSrc* src = new CodecSrc(path, mode, dstColorType, dstAlphaType, scale);
msarett9e707a02015-09-01 14:57:57 -0700468 push_src("image", folder, src);
469}
470
scroggof8dc9df2016-05-16 09:04:13 -0700471static void push_android_codec_src(Path path, CodecSrc::DstColorType dstColorType,
472 SkAlphaType dstAlphaType, int sampleSize) {
msarett3d9d7a72015-10-21 10:27:10 -0700473 SkString folder;
scroggof8dc9df2016-05-16 09:04:13 -0700474 folder.append("scaled_codec");
msarett3d9d7a72015-10-21 10:27:10 -0700475
476 switch (dstColorType) {
477 case CodecSrc::kGrayscale_Always_DstColorType:
478 folder.append("_kGray8");
479 break;
msarett34e0ec42016-04-22 16:27:24 -0700480 case CodecSrc::kNonNative8888_Always_DstColorType:
481 folder.append("_kNonNative");
482 break;
msarett3d9d7a72015-10-21 10:27:10 -0700483 default:
484 break;
485 }
486
scroggoc5560be2016-02-03 09:42:42 -0800487 switch (dstAlphaType) {
scroggoc5560be2016-02-03 09:42:42 -0800488 case kPremul_SkAlphaType:
489 folder.append("_premul");
490 break;
msarett9e9444c2016-02-03 12:39:10 -0800491 case kUnpremul_SkAlphaType:
492 folder.append("_unpremul");
493 break;
scroggoc5560be2016-02-03 09:42:42 -0800494 default:
495 break;
496 }
497
msarett3d9d7a72015-10-21 10:27:10 -0700498 if (1 != sampleSize) {
msarett4b0778e2015-11-13 09:59:11 -0800499 folder.appendf("_%.3f", 1.0f / (float) sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700500 }
501
scroggof8dc9df2016-05-16 09:04:13 -0700502 AndroidCodecSrc* src = new AndroidCodecSrc(path, dstColorType, dstAlphaType, sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700503 push_src("image", folder, src);
504}
505
msarett18976312016-03-09 14:20:58 -0800506static void push_image_gen_src(Path path, ImageGenSrc::Mode mode, SkAlphaType alphaType, bool isGpu)
507{
508 SkString folder;
509 switch (mode) {
510 case ImageGenSrc::kCodec_Mode:
511 folder.append("gen_codec");
512 break;
513 case ImageGenSrc::kPlatform_Mode:
514 folder.append("gen_platform");
515 break;
516 }
517
518 if (isGpu) {
519 folder.append("_gpu");
520 } else {
521 switch (alphaType) {
522 case kOpaque_SkAlphaType:
523 folder.append("_opaque");
524 break;
525 case kPremul_SkAlphaType:
526 folder.append("_premul");
527 break;
528 case kUnpremul_SkAlphaType:
529 folder.append("_unpremul");
530 break;
531 default:
532 break;
533 }
534 }
535
536 ImageGenSrc* src = new ImageGenSrc(path, mode, alphaType, isGpu);
537 push_src("image", folder, src);
538}
539
Leon Scroggins III07418182017-08-15 12:24:02 -0400540static void push_brd_src(Path path, CodecSrc::DstColorType dstColorType, BRDSrc::Mode mode,
541 uint32_t sampleSize) {
542 SkString folder("brd_android_codec");
543 switch (mode) {
544 case BRDSrc::kFullImage_Mode:
545 break;
546 case BRDSrc::kDivisor_Mode:
547 folder.append("_divisor");
548 break;
549 default:
550 SkASSERT(false);
551 return;
552 }
553
554 switch (dstColorType) {
555 case CodecSrc::kGetFromCanvas_DstColorType:
556 break;
557 case CodecSrc::kGrayscale_Always_DstColorType:
558 folder.append("_kGray");
559 break;
560 default:
561 SkASSERT(false);
562 return;
563 }
564
565 if (1 != sampleSize) {
566 folder.appendf("_%.3f", 1.0f / (float) sampleSize);
567 }
568
569 BRDSrc* src = new BRDSrc(path, mode, dstColorType, sampleSize);
570 push_src("image", folder, src);
571}
572
573static void push_brd_srcs(Path path, bool gray) {
574 if (gray) {
575 // Only run grayscale to one sampleSize and Mode. Though interesting
576 // to test grayscale, it should not reveal anything across various
577 // sampleSizes and Modes
578 // Arbitrarily choose Mode and sampleSize.
579 push_brd_src(path, CodecSrc::kGrayscale_Always_DstColorType,
580 BRDSrc::kFullImage_Mode, 2);
581 }
582
583 // Test on a variety of sampleSizes, making sure to include:
584 // - 2, 4, and 8, which are natively supported by jpeg
585 // - multiples of 2 which are not divisible by 4 (analogous for 4)
586 // - larger powers of two, since BRD clients generally use powers of 2
587 // We will only produce output for the larger sizes on large images.
588 const uint32_t sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 24, 32, 64 };
589
590 const BRDSrc::Mode modes[] = { BRDSrc::kFullImage_Mode, BRDSrc::kDivisor_Mode, };
591
592 for (uint32_t sampleSize : sampleSizes) {
593 for (BRDSrc::Mode mode : modes) {
594 push_brd_src(path, CodecSrc::kGetFromCanvas_DstColorType, mode, sampleSize);
595 }
596 }
597}
598
msarett438b2ad2015-04-09 12:43:10 -0700599static void push_codec_srcs(Path path) {
bungeman38d909e2016-08-02 14:40:46 -0700600 sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str()));
msarett438b2ad2015-04-09 12:43:10 -0700601 if (!encoded) {
mtkleinc41fd922016-03-08 09:01:39 -0800602 info("Couldn't read %s.", path.c_str());
msarett438b2ad2015-04-09 12:43:10 -0700603 return;
604 }
Mike Reedede7bac2017-07-23 15:30:02 -0400605 std::unique_ptr<SkCodec> codec = SkCodec::MakeFromData(encoded);
halcanary96fcdcc2015-08-27 07:41:13 -0700606 if (nullptr == codec.get()) {
mtkleinc41fd922016-03-08 09:01:39 -0800607 info("Couldn't create codec for %s.", path.c_str());
msarett438b2ad2015-04-09 12:43:10 -0700608 return;
609 }
610
scroggo9366aff2016-05-20 08:38:54 -0700611 // native scaling is only supported by WEBP and JPEG
612 bool supportsNativeScaling = false;
msarett438b2ad2015-04-09 12:43:10 -0700613
msarett91c22b22016-02-22 12:27:46 -0800614 SkTArray<CodecSrc::Mode> nativeModes;
615 nativeModes.push_back(CodecSrc::kCodec_Mode);
616 nativeModes.push_back(CodecSrc::kCodecZeroInit_Mode);
msarett91c22b22016-02-22 12:27:46 -0800617 switch (codec->getEncodedFormat()) {
Hal Canarydb683012016-11-23 08:55:18 -0700618 case SkEncodedImageFormat::kJPEG:
msarett91c22b22016-02-22 12:27:46 -0800619 nativeModes.push_back(CodecSrc::kScanline_Mode);
620 nativeModes.push_back(CodecSrc::kStripe_Mode);
621 nativeModes.push_back(CodecSrc::kCroppedScanline_Mode);
scroggo9366aff2016-05-20 08:38:54 -0700622 supportsNativeScaling = true;
msarett91c22b22016-02-22 12:27:46 -0800623 break;
Hal Canarydb683012016-11-23 08:55:18 -0700624 case SkEncodedImageFormat::kWEBP:
msarett91c22b22016-02-22 12:27:46 -0800625 nativeModes.push_back(CodecSrc::kSubset_Mode);
scroggo9366aff2016-05-20 08:38:54 -0700626 supportsNativeScaling = true;
msarett91c22b22016-02-22 12:27:46 -0800627 break;
Hal Canarydb683012016-11-23 08:55:18 -0700628 case SkEncodedImageFormat::kDNG:
msarettb65e6042016-02-23 05:37:25 -0800629 break;
msarett91c22b22016-02-22 12:27:46 -0800630 default:
631 nativeModes.push_back(CodecSrc::kScanline_Mode);
msarett91c22b22016-02-22 12:27:46 -0800632 break;
633 }
msarett9e707a02015-09-01 14:57:57 -0700634
msarett91c22b22016-02-22 12:27:46 -0800635 SkTArray<CodecSrc::DstColorType> colorTypes;
636 colorTypes.push_back(CodecSrc::kGetFromCanvas_DstColorType);
msarett34e0ec42016-04-22 16:27:24 -0700637 colorTypes.push_back(CodecSrc::kNonNative8888_Always_DstColorType);
msarett36c37962015-09-02 13:20:52 -0700638 switch (codec->getInfo().colorType()) {
639 case kGray_8_SkColorType:
msarett91c22b22016-02-22 12:27:46 -0800640 colorTypes.push_back(CodecSrc::kGrayscale_Always_DstColorType);
msarett36c37962015-09-02 13:20:52 -0700641 break;
642 default:
msarett36c37962015-09-02 13:20:52 -0700643 break;
644 }
msarett9e707a02015-09-01 14:57:57 -0700645
scroggoc5560be2016-02-03 09:42:42 -0800646 SkTArray<SkAlphaType> alphaModes;
647 alphaModes.push_back(kPremul_SkAlphaType);
scroggof2c96a22016-05-20 11:08:27 -0700648 if (codec->getInfo().alphaType() != kOpaque_SkAlphaType) {
649 alphaModes.push_back(kUnpremul_SkAlphaType);
scroggoc5560be2016-02-03 09:42:42 -0800650 }
msarettb714fb02016-01-22 14:46:42 -0800651
652 for (CodecSrc::Mode mode : nativeModes) {
scroggo9366aff2016-05-20 08:38:54 -0700653 for (CodecSrc::DstColorType colorType : colorTypes) {
654 for (SkAlphaType alphaType : alphaModes) {
scroggof2c96a22016-05-20 11:08:27 -0700655 // Only test kCroppedScanline_Mode when the alpha type is premul. The test is
scroggo9366aff2016-05-20 08:38:54 -0700656 // slow and won't be interestingly different with different alpha types.
657 if (CodecSrc::kCroppedScanline_Mode == mode &&
scroggof2c96a22016-05-20 11:08:27 -0700658 kPremul_SkAlphaType != alphaType) {
scroggo9366aff2016-05-20 08:38:54 -0700659 continue;
660 }
msarett91c22b22016-02-22 12:27:46 -0800661
scroggo9366aff2016-05-20 08:38:54 -0700662 push_codec_src(path, mode, colorType, alphaType, 1.0f);
msarettf3dc1882016-04-26 13:06:38 -0700663
scroggo9366aff2016-05-20 08:38:54 -0700664 // Skip kNonNative on different native scales. It won't be interestingly
665 // different.
666 if (supportsNativeScaling &&
667 CodecSrc::kNonNative8888_Always_DstColorType == colorType) {
668 // Native Scales
669 // SkJpegCodec natively supports scaling to the following:
670 for (auto scale : { 0.125f, 0.25f, 0.375f, 0.5f, 0.625f, 0.750f, 0.875f }) {
671 push_codec_src(path, mode, colorType, alphaType, scale);
672 }
scroggoc5560be2016-02-03 09:42:42 -0800673 }
msarett9e707a02015-09-01 14:57:57 -0700674 }
675 }
msarett0a242972015-06-11 14:27:27 -0700676 }
msarett36c37962015-09-02 13:20:52 -0700677
scroggo19b91532016-10-24 09:03:26 -0700678 {
679 std::vector<SkCodec::FrameInfo> frameInfos = codec->getFrameInfo();
680 if (frameInfos.size() > 1) {
Leon Scroggins III557fbbe2017-05-23 09:37:21 -0400681 for (auto dstCT : { CodecSrc::kNonNative8888_Always_DstColorType,
682 CodecSrc::kGetFromCanvas_DstColorType }) {
683 for (auto at : { kUnpremul_SkAlphaType, kPremul_SkAlphaType }) {
684 push_codec_src(path, CodecSrc::kAnimated_Mode, dstCT, at, 1.0f);
685 }
686 }
scroggo19b91532016-10-24 09:03:26 -0700687 }
688
689 }
690
scroggoe4499842016-02-25 11:03:47 -0800691 if (FLAGS_simpleCodec) {
692 return;
693 }
694
msarett3d9d7a72015-10-21 10:27:10 -0700695 const int sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
msarett36c37962015-09-02 13:20:52 -0700696
msarett3d9d7a72015-10-21 10:27:10 -0700697 for (int sampleSize : sampleSizes) {
msarett91c22b22016-02-22 12:27:46 -0800698 for (CodecSrc::DstColorType colorType : colorTypes) {
scroggoc5560be2016-02-03 09:42:42 -0800699 for (SkAlphaType alphaType : alphaModes) {
msarettf3dc1882016-04-26 13:06:38 -0700700 // We can exercise all of the kNonNative support code in the swizzler with just a
701 // few sample sizes. Skip the rest.
702 if (CodecSrc::kNonNative8888_Always_DstColorType == colorType && sampleSize > 3) {
703 continue;
704 }
705
scroggof8dc9df2016-05-16 09:04:13 -0700706 push_android_codec_src(path, colorType, alphaType, sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700707 }
msarett36c37962015-09-02 13:20:52 -0700708 }
709 }
msarett18976312016-03-09 14:20:58 -0800710
Leon Scroggins III07418182017-08-15 12:24:02 -0400711 const char* ext = strrchr(path.c_str(), '.');
712 if (ext) {
713 ext++;
msarett18976312016-03-09 14:20:58 -0800714
Leon Scroggins III07418182017-08-15 12:24:02 -0400715 static const char* const rawExts[] = {
716 "arw", "cr2", "dng", "nef", "nrw", "orf", "raf", "rw2", "pef", "srw",
717 "ARW", "CR2", "DNG", "NEF", "NRW", "ORF", "RAF", "RW2", "PEF", "SRW",
718 };
719 for (const char* rawExt : rawExts) {
720 if (0 == strcmp(rawExt, ext)) {
721 // RAW is not supported by image generator (skbug.com/5079) or BRD.
722 return;
723 }
724 }
725
726 static const char* const brdExts[] = {
727 "jpg", "jpeg", "png", "webp",
728 "JPG", "JPEG", "PNG", "WEBP",
729 };
730 for (const char* brdExt : brdExts) {
731 if (0 == strcmp(brdExt, ext)) {
Leon Scroggins IIIc8037dc2017-12-05 13:55:24 -0500732 bool gray = codec->getInfo().colorType() == kGray_8_SkColorType;
Leon Scroggins III07418182017-08-15 12:24:02 -0400733 push_brd_srcs(path, gray);
734 break;
735 }
msarett18976312016-03-09 14:20:58 -0800736 }
737 }
738
739 // Push image generator GPU test.
brianosmanc9ced392016-03-24 07:27:43 -0700740 push_image_gen_src(path, ImageGenSrc::kCodec_Mode, codec->getInfo().alphaType(), true);
msarett18976312016-03-09 14:20:58 -0800741
742 // Push image generator CPU tests.
743 for (SkAlphaType alphaType : alphaModes) {
744 push_image_gen_src(path, ImageGenSrc::kCodec_Mode, alphaType, false);
745
746#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
Hal Canarydb683012016-11-23 08:55:18 -0700747 if (SkEncodedImageFormat::kWEBP != codec->getEncodedFormat() &&
748 SkEncodedImageFormat::kWBMP != codec->getEncodedFormat() &&
msarett18976312016-03-09 14:20:58 -0800749 kUnpremul_SkAlphaType != alphaType)
750 {
751 push_image_gen_src(path, ImageGenSrc::kPlatform_Mode, alphaType, false);
752 }
msarettfc0b6d12016-03-17 13:50:17 -0700753#elif defined(SK_BUILD_FOR_WIN)
Hal Canarydb683012016-11-23 08:55:18 -0700754 if (SkEncodedImageFormat::kWEBP != codec->getEncodedFormat() &&
755 SkEncodedImageFormat::kWBMP != codec->getEncodedFormat())
msarettfc0b6d12016-03-17 13:50:17 -0700756 {
757 push_image_gen_src(path, ImageGenSrc::kPlatform_Mode, alphaType, false);
758 }
msarett18976312016-03-09 14:20:58 -0800759#endif
760 }
msarett438b2ad2015-04-09 12:43:10 -0700761}
762
fmalitaa2b9fdf2016-08-03 19:53:36 -0700763template <typename T>
Florin Malitaf1ba3ae2018-07-19 15:09:11 -0400764void gather_file_srcs(const SkCommandLineFlags::StringArray& flags, const char* ext,
765 const char* src_name = nullptr) {
766 if (!src_name) {
767 // With the exception of Lottie files, the source name is the extension.
768 src_name = ext;
769 }
770
fmalitaa2b9fdf2016-08-03 19:53:36 -0700771 for (int i = 0; i < flags.count(); i++) {
772 const char* path = flags[i];
773 if (sk_isdir(path)) {
774 SkOSFile::Iter it(path, ext);
775 for (SkString file; it.next(&file); ) {
Florin Malitaf1ba3ae2018-07-19 15:09:11 -0400776 push_src(src_name, "", new T(SkOSPath::Join(path, file.c_str())));
fmalitaa2b9fdf2016-08-03 19:53:36 -0700777 }
778 } else {
Florin Malitaf1ba3ae2018-07-19 15:09:11 -0400779 push_src(src_name, "", new T(path));
fmalitaa2b9fdf2016-08-03 19:53:36 -0700780 }
781 }
782}
783
scroggo86737142016-02-03 12:19:11 -0800784static bool gather_srcs() {
Hal Canary972eba32018-07-30 17:07:07 -0400785 for (skiagm::GMFactory f : skiagm::GMRegistry::Range()) {
786 push_src("gm", "", new GMSrc(f));
mtklein748ca3b2015-01-15 10:56:12 -0800787 }
scroggo86737142016-02-03 12:19:11 -0800788
Robert Phillipse47f0a02018-03-27 17:01:16 -0400789 gather_file_srcs<SKPSrc>(FLAGS_skps, "skp");
fmalitaa2b9fdf2016-08-03 19:53:36 -0700790 gather_file_srcs<MSKPSrc>(FLAGS_mskps, "mskp");
Florin Malita87ccf332018-05-04 12:23:24 -0400791#if defined(SK_ENABLE_SKOTTIE)
Florin Malitaf1ba3ae2018-07-19 15:09:11 -0400792 gather_file_srcs<SkottieSrc>(FLAGS_lotties, "json", "lottie");
Florin Malita124d5af2017-12-31 17:02:26 -0500793#endif
fmalitaa2b9fdf2016-08-03 19:53:36 -0700794#if defined(SK_XML)
795 gather_file_srcs<SVGSrc>(FLAGS_svgs, "svg");
796#endif
halcanary45420a92016-06-02 12:41:14 -0700797
scroggo86737142016-02-03 12:19:11 -0800798 SkTArray<SkString> images;
msarett69deca82016-04-29 09:38:40 -0700799 if (!CollectImages(FLAGS_images, &images)) {
scroggo86737142016-02-03 12:19:11 -0800800 return false;
801 }
802
803 for (auto image : images) {
804 push_codec_srcs(image);
mtklein709d2c32015-01-15 08:30:25 -0800805 }
scroggo86737142016-02-03 12:19:11 -0800806
msarett69deca82016-04-29 09:38:40 -0700807 SkTArray<SkString> colorImages;
808 if (!CollectImages(FLAGS_colorImages, &colorImages)) {
809 return false;
810 }
811
812 for (auto colorImage : colorImages) {
msarett9ce3a542016-07-15 13:54:38 -0700813 ColorCodecSrc* src = new ColorCodecSrc(colorImage, ColorCodecSrc::kBaseline_Mode,
814 kN32_SkColorType);
msarettb8d1aac2016-08-04 12:22:06 -0700815 push_src("colorImage", "color_codec_baseline", src);
msarett888dc162016-05-23 10:21:17 -0700816
msarett9ce3a542016-07-15 13:54:38 -0700817 src = new ColorCodecSrc(colorImage, ColorCodecSrc::kDst_HPZR30w_Mode, kN32_SkColorType);
msarettb8d1aac2016-08-04 12:22:06 -0700818 push_src("colorImage", "color_codec_HPZR30w", src);
msarett9ce3a542016-07-15 13:54:38 -0700819 // TODO (msarett):
820 // 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 -0700821
msarett9ce3a542016-07-15 13:54:38 -0700822 src = new ColorCodecSrc(colorImage, ColorCodecSrc::kDst_sRGB_Mode, kN32_SkColorType);
msarettb8d1aac2016-08-04 12:22:06 -0700823 push_src("colorImage", "color_codec_sRGB_kN32", src);
msarett9ce3a542016-07-15 13:54:38 -0700824 src = new ColorCodecSrc(colorImage, ColorCodecSrc::kDst_sRGB_Mode, kRGBA_F16_SkColorType);
msarettb8d1aac2016-08-04 12:22:06 -0700825 push_src("colorImage", "color_codec_sRGB_kF16", src);
msarett69deca82016-04-29 09:38:40 -0700826 }
827
scroggo86737142016-02-03 12:19:11 -0800828 return true;
mtklein709d2c32015-01-15 08:30:25 -0800829}
830
kkinnunen3e980c32015-12-23 01:33:00 -0800831static void push_sink(const SkCommandLineConfig& config, Sink* s) {
Ben Wagner145dbcd2016-11-03 14:40:50 -0400832 std::unique_ptr<Sink> sink(s);
kkinnunen3e980c32015-12-23 01:33:00 -0800833
mtkleine0effd62015-07-29 06:37:28 -0700834 // Try a simple Src as a canary. If it fails, skip this sink.
mtklein748ca3b2015-01-15 10:56:12 -0800835 struct : public Src {
mtkleine0effd62015-07-29 06:37:28 -0700836 Error draw(SkCanvas* c) const override {
837 c->drawRect(SkRect::MakeWH(1,1), SkPaint());
838 return "";
839 }
mtklein36352bf2015-03-25 18:17:31 -0700840 SkISize size() const override { return SkISize::Make(16, 16); }
mtkleine0effd62015-07-29 06:37:28 -0700841 Name name() const override { return "justOneRect"; }
842 } justOneRect;
mtklein114c3cd2015-01-15 10:15:02 -0800843
mtklein748ca3b2015-01-15 10:56:12 -0800844 SkBitmap bitmap;
845 SkDynamicMemoryWStream stream;
mtkleinb9eb4ac2015-02-02 18:26:03 -0800846 SkString log;
mtkleine0effd62015-07-29 06:37:28 -0700847 Error err = sink->draw(justOneRect, &bitmap, &stream, &log);
mtklein4089ef72015-03-05 08:40:28 -0800848 if (err.isFatal()) {
mtkleinc41fd922016-03-08 09:01:39 -0800849 info("Could not run %s: %s\n", config.getTag().c_str(), err.c_str());
mtklein05641a52015-04-21 10:49:13 -0700850 exit(1);
mtklein114c3cd2015-01-15 10:15:02 -0800851 }
852
mtkleine0effd62015-07-29 06:37:28 -0700853 TaggedSink& ts = gSinks.push_back();
mtklein18300a32016-03-16 13:53:35 -0700854 ts.reset(sink.release());
kkinnunen3e980c32015-12-23 01:33:00 -0800855 ts.tag = config.getTag();
mtklein748ca3b2015-01-15 10:56:12 -0800856}
857
csmartdalton008b9d82017-02-22 12:00:42 -0700858static Sink* create_sink(const GrContextOptions& grCtxOptions, const SkCommandLineConfig* config) {
Brian Osmanc7ad40f2018-05-31 14:27:17 -0400859 if (FLAGS_gpu) {
kkinnunen3e980c32015-12-23 01:33:00 -0800860 if (const SkCommandLineConfigGpu* gpuConfig = config->asConfigGpu()) {
bsalomon85b4b532016-04-05 11:06:27 -0700861 GrContextFactory::ContextType contextType = gpuConfig->getContextType();
csmartdaltone812d492017-02-21 12:36:05 -0700862 GrContextFactory::ContextOverrides contextOverrides = gpuConfig->getContextOverrides();
csmartdalton008b9d82017-02-22 12:00:42 -0700863 GrContextFactory testFactory(grCtxOptions);
csmartdaltone812d492017-02-21 12:36:05 -0700864 if (!testFactory.get(contextType, contextOverrides)) {
mtkleinc41fd922016-03-08 09:01:39 -0800865 info("WARNING: can not create GPU context for config '%s'. "
866 "GM tests will be skipped.\n", gpuConfig->getTag().c_str());
kkinnunen3e980c32015-12-23 01:33:00 -0800867 return nullptr;
868 }
Brian Osmanf9810662017-08-30 10:02:10 -0400869 if (gpuConfig->getTestThreading()) {
Brian Salomon00a5eb82018-07-11 15:32:05 -0400870 SkASSERT(!gpuConfig->getTestPersistentCache());
Brian Salomonf865b052018-03-09 09:01:53 -0500871 return new GPUThreadTestingSink(
872 contextType, contextOverrides, gpuConfig->getSurfType(),
873 gpuConfig->getSamples(), gpuConfig->getUseDIText(),
874 gpuConfig->getColorType(), gpuConfig->getAlphaType(),
875 sk_ref_sp(gpuConfig->getColorSpace()), FLAGS_gpu_threading, grCtxOptions);
Brian Salomon00a5eb82018-07-11 15:32:05 -0400876 } else if (gpuConfig->getTestPersistentCache()) {
877 return new GPUPersistentCacheTestingSink(
878 contextType, contextOverrides, gpuConfig->getSurfType(),
879 gpuConfig->getSamples(), gpuConfig->getUseDIText(),
880 gpuConfig->getColorType(), gpuConfig->getAlphaType(),
881 sk_ref_sp(gpuConfig->getColorSpace()), FLAGS_gpu_threading, grCtxOptions);
Brian Osmanf9810662017-08-30 10:02:10 -0400882 } else {
Brian Salomonf865b052018-03-09 09:01:53 -0500883 return new GPUSink(contextType, contextOverrides, gpuConfig->getSurfType(),
884 gpuConfig->getSamples(), gpuConfig->getUseDIText(),
885 gpuConfig->getColorType(), gpuConfig->getAlphaType(),
886 sk_ref_sp(gpuConfig->getColorSpace()), FLAGS_gpu_threading,
887 grCtxOptions);
Brian Osmanf9810662017-08-30 10:02:10 -0400888 }
kkinnunen3e980c32015-12-23 01:33:00 -0800889 }
890 }
Bryce Thomas95a7b762018-03-02 13:54:21 -0800891 if (const SkCommandLineConfigSvg* svgConfig = config->asConfigSvg()) {
892 int pageIndex = svgConfig->getPageIndex();
893 return new SVGSink(pageIndex);
894 }
kkinnunen3e980c32015-12-23 01:33:00 -0800895
896#define SINK(t, sink, ...) if (config->getBackend().equals(t)) { return new sink(__VA_ARGS__); }
897
mtklein748ca3b2015-01-15 10:56:12 -0800898 if (FLAGS_cpu) {
Mike Klein515bda62018-01-09 11:21:58 -0500899 SINK("g8", RasterSink, kGray_8_SkColorType);
Matt Sarettd2228302017-03-02 08:53:46 -0500900 SINK("565", RasterSink, kRGB_565_SkColorType);
Mike Klein5340b3f2018-01-24 13:42:05 -0500901 SINK("4444", RasterSink, kARGB_4444_SkColorType);
Matt Sarettd2228302017-03-02 08:53:46 -0500902 SINK("8888", RasterSink, kN32_SkColorType);
Mike Kleinac568a92018-01-25 09:09:32 -0500903 SINK("rgba", RasterSink, kRGBA_8888_SkColorType);
904 SINK("bgra", RasterSink, kBGRA_8888_SkColorType);
905 SINK("rgbx", RasterSink, kRGB_888x_SkColorType);
906 SINK("1010102", RasterSink, kRGBA_1010102_SkColorType);
907 SINK("101010x", RasterSink, kRGB_101010x_SkColorType);
Hal Canaryc7d295e2017-07-20 15:36:00 -0400908 SINK("pdf", PDFSink, false, SK_ScalarDefaultRasterDPI);
Matt Sarettd2228302017-03-02 08:53:46 -0500909 SINK("skp", SKPSink);
910 SINK("pipe", PipeSink);
911 SINK("svg", SVGSink);
912 SINK("null", NullSink);
913 SINK("xps", XPSSink);
Hal Canaryc7d295e2017-07-20 15:36:00 -0400914 SINK("pdfa", PDFSink, true, SK_ScalarDefaultRasterDPI);
915 SINK("pdf300", PDFSink, false, 300);
Hal Canary85c7fe82016-10-25 10:33:27 -0400916 SINK("jsdebug", DebugSink);
Mike Klein0e4041f2018-06-19 16:00:40 -0400917
918 // Configs relevant to color management testing (and 8888 for reference).
919
920 // 'narrow' has a gamut narrower than sRGB, and different transfer function.
921 SkMatrix44 narrow_gamut(SkMatrix44::kUninitialized_Constructor);
922 narrow_gamut.set3x3RowMajorf(gNarrow_toXYZD50);
923
Mike Kleinff6a73c2018-08-17 16:19:24 -0400924 // See https://en.wikipedia.org/wiki/Rec._2020
925 float alpha = 1.09929682680944f,
926 beta = 0.018053968510807f,
927 gamma = 0.45f;
928 SkColorSpaceTransferFn rec2020_TF = SkColorSpaceTransferFn{
929 gamma,
930 powf(alpha, 1/gamma),
931 0.0f,
932 4.5f,
933 beta,
934 1 - alpha,
935 0.0f,
936 }.invert();
937
Mike Klein0e4041f2018-06-19 16:00:40 -0400938 auto narrow = SkColorSpace::MakeRGB(k2Dot2Curve_SkGammaNamed, narrow_gamut),
939 srgb = SkColorSpace::MakeSRGB(),
Mike Klein4de05072018-08-16 09:09:14 -0400940 srgbLinear = SkColorSpace::MakeSRGBLinear(),
941 p3 = SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
Mike Kleinff6a73c2018-08-17 16:19:24 -0400942 SkColorSpace::kDCIP3_D65_Gamut),
943 rec2020 = SkColorSpace::MakeRGB(rec2020_TF, SkColorSpace::kRec2020_Gamut);
Mike Klein0e4041f2018-06-19 16:00:40 -0400944
Mike Kleinff6a73c2018-08-17 16:19:24 -0400945 SINK( "f16", RasterSink, kRGBA_F16_SkColorType, srgbLinear);
946 SINK( "srgb", RasterSink, kRGBA_8888_SkColorType, srgb );
947 SINK( "esrgb", RasterSink, kRGBA_F16_SkColorType, srgb );
948 SINK( "narrow", RasterSink, kRGBA_8888_SkColorType, narrow );
949 SINK( "enarrow", RasterSink, kRGBA_F16_SkColorType, narrow );
950 SINK( "p3", RasterSink, kRGBA_8888_SkColorType, p3 );
951 SINK( "ep3", RasterSink, kRGBA_F16_SkColorType, p3 );
952 SINK( "rec2020", RasterSink, kRGBA_8888_SkColorType, rec2020 );
953 SINK("erec2020", RasterSink, kRGBA_F16_SkColorType, rec2020 );
Mike Klein37854712018-06-26 11:43:06 -0400954
955 SINK( "f32", RasterSink, kRGBA_F32_SkColorType, srgbLinear);
mtklein748ca3b2015-01-15 10:56:12 -0800956 }
957#undef SINK
halcanary96fcdcc2015-08-27 07:41:13 -0700958 return nullptr;
mtklein114c3cd2015-01-15 10:15:02 -0800959}
960
Mike Kleinb7ea3da2017-10-31 17:42:08 +0000961static sk_sp<SkColorSpace> rgb_to_gbr() {
Brian Osman36703d92017-12-12 14:09:31 -0500962 return SkColorSpace::MakeSRGB()->makeColorSpin();
Mike Klein919cc452017-03-18 15:36:52 +0000963}
964
kkinnunen3e980c32015-12-23 01:33:00 -0800965static Sink* create_via(const SkString& tag, Sink* wrapped) {
966#define VIA(t, via, ...) if (tag.equals(t)) { return new via(__VA_ARGS__); }
Mike Kleinb7ea3da2017-10-31 17:42:08 +0000967 VIA("gbr", ViaCSXform, wrapped, rgb_to_gbr(), true);
Brian Osmana76b7a92018-07-18 14:36:43 -0400968 VIA("p3", ViaCSXform, wrapped,
969 SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
970 SkColorSpace::kDCIP3_D65_Gamut), false);
mtklein9c5052f2016-08-06 12:51:51 -0700971 VIA("lite", ViaLite, wrapped);
reed54dc4872016-09-13 08:09:45 -0700972 VIA("pipe", ViaPipe, wrapped);
Mike Reedbae888e2017-02-18 16:50:45 -0500973#ifdef TEST_VIA_SVG
Mike Reedf67c4592017-02-17 17:06:11 -0500974 VIA("svg", ViaSVG, wrapped);
Mike Reedbae888e2017-02-18 16:50:45 -0500975#endif
halcanary96fcdcc2015-08-27 07:41:13 -0700976 VIA("serialize", ViaSerialization, wrapped);
mtklein4a34ecb2016-01-08 10:19:35 -0800977 VIA("pic", ViaPicture, wrapped);
halcanary96fcdcc2015-08-27 07:41:13 -0700978 VIA("tiles", ViaTiles, 256, 256, nullptr, wrapped);
mtklein7edca212015-01-21 13:18:51 -0800979 VIA("tiles_rt", ViaTiles, 256, 256, new SkRTreeFactory, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800980
Robert Phillips33f02ed2018-03-27 08:06:57 -0400981 VIA("ddl", ViaDDL, 3, wrapped);
982
mtkleind603b222015-02-17 11:13:33 -0800983 if (FLAGS_matrix.count() == 4) {
mtklein748ca3b2015-01-15 10:56:12 -0800984 SkMatrix m;
mtkleind603b222015-02-17 11:13:33 -0800985 m.reset();
986 m.setScaleX((SkScalar)atof(FLAGS_matrix[0]));
987 m.setSkewX ((SkScalar)atof(FLAGS_matrix[1]));
988 m.setSkewY ((SkScalar)atof(FLAGS_matrix[2]));
989 m.setScaleY((SkScalar)atof(FLAGS_matrix[3]));
990 VIA("matrix", ViaMatrix, m, wrapped);
991 VIA("upright", ViaUpright, m, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800992 }
tomhudson64de1e12015-03-05 08:01:07 -0800993
mtklein748ca3b2015-01-15 10:56:12 -0800994#undef VIA
halcanary96fcdcc2015-08-27 07:41:13 -0700995 return nullptr;
mtklein114c3cd2015-01-15 10:15:02 -0800996}
997
Ben Wagnerf28d4722017-08-11 17:33:22 -0400998static bool gather_sinks(const GrContextOptions& grCtxOptions, bool defaultConfigs) {
kkinnunen3e980c32015-12-23 01:33:00 -0800999 SkCommandLineConfigArray configs;
1000 ParseConfigs(FLAGS_config, &configs);
1001 for (int i = 0; i < configs.count(); i++) {
1002 const SkCommandLineConfig& config = *configs[i];
csmartdalton008b9d82017-02-22 12:00:42 -07001003 Sink* sink = create_sink(grCtxOptions, &config);
kkinnunen3e980c32015-12-23 01:33:00 -08001004 if (sink == nullptr) {
mtkleinc41fd922016-03-08 09:01:39 -08001005 info("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(),
1006 config.getTag().c_str());
kkinnunen3e980c32015-12-23 01:33:00 -08001007 continue;
1008 }
mtklein748ca3b2015-01-15 10:56:12 -08001009
kkinnunen3e980c32015-12-23 01:33:00 -08001010 const SkTArray<SkString>& parts = config.getViaParts();
1011 for (int j = parts.count(); j-- > 0;) {
1012 const SkString& part = parts[j];
1013 Sink* next = create_via(part, sink);
halcanary96fcdcc2015-08-27 07:41:13 -07001014 if (next == nullptr) {
mtkleinc41fd922016-03-08 09:01:39 -08001015 info("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(),
1016 part.c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001017 delete sink;
halcanary96fcdcc2015-08-27 07:41:13 -07001018 sink = nullptr;
mtklein748ca3b2015-01-15 10:56:12 -08001019 break;
1020 }
1021 sink = next;
1022 }
1023 if (sink) {
1024 push_sink(config, sink);
mtklein114c3cd2015-01-15 10:15:02 -08001025 }
1026 }
brianosman05c987c2016-05-09 13:42:16 -07001027
1028 // If no configs were requested (just running tests, perhaps?), then we're okay.
Ben Wagnerf28d4722017-08-11 17:33:22 -04001029 if (configs.count() == 0 ||
1030 // If we're using the default configs, we're okay.
1031 defaultConfigs ||
Ben Wagner32fa5102017-08-10 21:25:55 -04001032 // If we've been told to ignore undefined flags, we're okay.
1033 FLAGS_undefok ||
1034 // Otherwise, make sure that all specified configs have become sinks.
1035 configs.count() == gSinks.count()) {
1036 return true;
1037 }
1038 info("Invalid --config. Use --undefok to bypass this warning.\n");
1039 return false;
mtklein114c3cd2015-01-15 10:15:02 -08001040}
mtklein709d2c32015-01-15 08:30:25 -08001041
mtkleina5114d72015-08-24 13:27:01 -07001042static bool dump_png(SkBitmap bitmap, const char* path, const char* md5) {
Mike Klein13b6afd2017-06-12 12:45:41 -04001043 SkPixmap pm;
1044 if (!bitmap.peekPixels(&pm)) {
1045 return false; // Ought to never happen... we're already read-back at this point.
mtkleina5114d72015-08-24 13:27:01 -07001046 }
Mike Klein13b6afd2017-06-12 12:45:41 -04001047 SkFILEWStream dst{path};
mtkleina5114d72015-08-24 13:27:01 -07001048
mtkleind69ece62015-09-10 10:37:44 -07001049 SkString description;
1050 description.append("Key: ");
1051 for (int i = 0; i < FLAGS_key.count(); i++) {
1052 description.appendf("%s ", FLAGS_key[i]);
1053 }
1054 description.append("Properties: ");
1055 for (int i = 0; i < FLAGS_properties.count(); i++) {
1056 description.appendf("%s ", FLAGS_properties[i]);
1057 }
1058 description.appendf("MD5: %s", md5);
1059
Mike Klein13b6afd2017-06-12 12:45:41 -04001060 const char* comments[] = {
1061 "Author", "DM dump_png()",
1062 "Description", description.c_str(),
1063 };
1064 size_t lengths[] = {
1065 strlen(comments[0])+1, strlen(comments[1])+1,
1066 strlen(comments[2])+1, strlen(comments[3])+1,
1067 };
mtkleina5114d72015-08-24 13:27:01 -07001068
Mike Klein13b6afd2017-06-12 12:45:41 -04001069 SkPngEncoder::Options options;
1070 options.fComments = SkDataTable::MakeCopyArrays((const void**)comments, lengths, 4);
1071 options.fFilterFlags = SkPngEncoder::FilterFlag::kNone;
1072 options.fZLibLevel = 1;
Mike Klein13b6afd2017-06-12 12:45:41 -04001073 return SkPngEncoder::Encode(&dst, pm, options);
mtkleina5114d72015-08-24 13:27:01 -07001074}
1075
mtkleina2ef6422015-01-15 13:44:22 -08001076static bool match(const char* needle, const char* haystack) {
Chris Daltonecf78ac2017-08-15 15:43:08 -06001077 if ('~' == needle[0]) {
1078 return !match(needle + 1, haystack);
1079 }
1080 if (0 == strcmp("_", needle)) {
1081 return true;
1082 }
1083 return nullptr != strstr(haystack, needle);
mtkleina2ef6422015-01-15 13:44:22 -08001084}
1085
mtklein3eed7dd2016-02-24 19:07:07 -08001086static bool is_blacklisted(const char* sink, const char* src,
1087 const char* srcOptions, const char* name) {
mtklein0d243ff2015-04-03 07:51:00 -07001088 for (int i = 0; i < FLAGS_blacklist.count() - 3; i += 4) {
mtkleina2ef6422015-01-15 13:44:22 -08001089 if (match(FLAGS_blacklist[i+0], sink) &&
djsollen54416de2015-04-03 07:24:48 -07001090 match(FLAGS_blacklist[i+1], src) &&
1091 match(FLAGS_blacklist[i+2], srcOptions) &&
1092 match(FLAGS_blacklist[i+3], name)) {
mtklein3eed7dd2016-02-24 19:07:07 -08001093 return true;
mtkleina2ef6422015-01-15 13:44:22 -08001094 }
1095 }
mtklein3eed7dd2016-02-24 19:07:07 -08001096 return false;
mtkleina2ef6422015-01-15 13:44:22 -08001097}
1098
mtkleincd50bca2016-01-05 06:20:20 -08001099// Even when a Task Sink reports to be non-threadsafe (e.g. GPU), we know things like
1100// .png encoding are definitely thread safe. This lets us offload that work to CPU threads.
1101static SkTaskGroup gDefinitelyThreadSafeWork;
1102
mtklein748ca3b2015-01-15 10:56:12 -08001103// The finest-grained unit of work we can run: draw a single Src into a single Sink,
1104// report any errors, and perhaps write out the output: a .png of the bitmap, or a raw stream.
1105struct Task {
mtkleine0effd62015-07-29 06:37:28 -07001106 Task(const TaggedSrc& src, const TaggedSink& sink) : src(src), sink(sink) {}
1107 const TaggedSrc& src;
1108 const TaggedSink& sink;
mtklein748ca3b2015-01-15 10:56:12 -08001109
mtklein21eaf3b2016-02-08 12:39:59 -08001110 static void Run(const Task& task) {
1111 SkString name = task.src->name();
mtkleine0effd62015-07-29 06:37:28 -07001112
mtkleinb9eb4ac2015-02-02 18:26:03 -08001113 SkString log;
mtklein3eed7dd2016-02-24 19:07:07 -08001114 if (!FLAGS_dryRun) {
mtklein748ca3b2015-01-15 10:56:12 -08001115 SkBitmap bitmap;
1116 SkDynamicMemoryWStream stream;
mtklein3eed7dd2016-02-24 19:07:07 -08001117 start(task.sink.tag.c_str(), task.src.tag.c_str(),
1118 task.src.options.c_str(), name.c_str());
mtklein21eaf3b2016-02-08 12:39:59 -08001119 Error err = task.sink->draw(*task.src, &bitmap, &stream, &log);
mtkleinb3b13b72016-03-07 13:20:52 -08001120 if (!log.isEmpty()) {
mtkleinc41fd922016-03-08 09:01:39 -08001121 info("%s %s %s %s:\n%s\n", task.sink.tag.c_str()
1122 , task.src.tag.c_str()
1123 , task.src.options.c_str()
1124 , name.c_str()
1125 , log.c_str());
mtkleinb3b13b72016-03-07 13:20:52 -08001126 }
mtklein748ca3b2015-01-15 10:56:12 -08001127 if (!err.isEmpty()) {
mtklein4089ef72015-03-05 08:40:28 -08001128 if (err.isFatal()) {
djsollen54416de2015-04-03 07:24:48 -07001129 fail(SkStringPrintf("%s %s %s %s: %s",
mtklein21eaf3b2016-02-08 12:39:59 -08001130 task.sink.tag.c_str(),
1131 task.src.tag.c_str(),
1132 task.src.options.c_str(),
mtklein4089ef72015-03-05 08:40:28 -08001133 name.c_str(),
1134 err.c_str()));
mtkleinb37cb412015-03-18 05:27:14 -07001135 } else {
mtklein3eed7dd2016-02-24 19:07:07 -08001136 done(task.sink.tag.c_str(), task.src.tag.c_str(),
1137 task.src.options.c_str(), name.c_str());
mtkleinba6ada72016-01-21 09:39:35 -08001138 return;
mtklein4089ef72015-03-05 08:40:28 -08001139 }
mtklein748ca3b2015-01-15 10:56:12 -08001140 }
mtklein62bd1a62015-01-27 14:46:26 -08001141
mtkleincd50bca2016-01-05 06:20:20 -08001142 // We're likely switching threads here, so we must capture by value, [=] or [foo,bar].
Hal Canary0b833192017-03-14 14:35:02 -04001143 SkStreamAsset* data = stream.detachAsStream().release();
mtkleincd50bca2016-01-05 06:20:20 -08001144 gDefinitelyThreadSafeWork.add([task,name,bitmap,data]{
Ben Wagner145dbcd2016-11-03 14:40:50 -04001145 std::unique_ptr<SkStreamAsset> ownedData(data);
mtkleincd50bca2016-01-05 06:20:20 -08001146
mtkleincd50bca2016-01-05 06:20:20 -08001147 SkString md5;
1148 if (!FLAGS_writePath.isEmpty() || !FLAGS_readPath.isEmpty()) {
1149 SkMD5 hash;
1150 if (data->getLength()) {
1151 hash.writeStream(data, data->getLength());
1152 data->rewind();
mtklein38408462015-07-08 07:25:27 -07001153 } else {
mtkleincd50bca2016-01-05 06:20:20 -08001154 // If we're BGRA (Linux, Windows), swizzle over to RGBA (Mac, Android).
1155 // This helps eliminate multiple 0-pixel-diff hashes on gold.skia.org.
1156 // (Android's general slow speed breaks the tie arbitrarily in RGBA's favor.)
1157 // We might consider promoting 565 to RGBA too.
1158 if (bitmap.colorType() == kBGRA_8888_SkColorType) {
1159 SkBitmap swizzle;
Matt Sarett68b8e3d2017-04-28 11:15:22 -04001160 SkAssertResult(sk_tool_utils::copy_to(&swizzle, kRGBA_8888_SkColorType,
1161 bitmap));
Mike Reedf0ffb892017-10-03 14:47:21 -04001162 hash.write(swizzle.getPixels(), swizzle.computeByteSize());
mtkleincd50bca2016-01-05 06:20:20 -08001163 } else {
Mike Reedf0ffb892017-10-03 14:47:21 -04001164 hash.write(bitmap.getPixels(), bitmap.computeByteSize());
mtkleincd50bca2016-01-05 06:20:20 -08001165 }
1166 }
1167 SkMD5::Digest digest;
1168 hash.finish(digest);
1169 for (int i = 0; i < 16; i++) {
1170 md5.appendf("%02x", digest.data[i]);
mtklein38408462015-07-08 07:25:27 -07001171 }
mtklein62bd1a62015-01-27 14:46:26 -08001172 }
mtklein62bd1a62015-01-27 14:46:26 -08001173
mtkleincd50bca2016-01-05 06:20:20 -08001174 if (!FLAGS_readPath.isEmpty() &&
mtklein3eed7dd2016-02-24 19:07:07 -08001175 !gGold.contains(Gold(task.sink.tag, task.src.tag,
1176 task.src.options, name, md5))) {
mtkleincd50bca2016-01-05 06:20:20 -08001177 fail(SkStringPrintf("%s not found for %s %s %s %s in %s",
1178 md5.c_str(),
mtklein21eaf3b2016-02-08 12:39:59 -08001179 task.sink.tag.c_str(),
1180 task.src.tag.c_str(),
1181 task.src.options.c_str(),
mtkleincd50bca2016-01-05 06:20:20 -08001182 name.c_str(),
1183 FLAGS_readPath[0]));
mtklein748ca3b2015-01-15 10:56:12 -08001184 }
mtkleincd50bca2016-01-05 06:20:20 -08001185
1186 if (!FLAGS_writePath.isEmpty()) {
mtklein21eaf3b2016-02-08 12:39:59 -08001187 const char* ext = task.sink->fileExtension();
Brian Osmanf1942de2017-08-30 14:50:22 -04001188 if (ext && !FLAGS_dont_write.contains(ext)) {
Mike Klein97d6a7a2017-07-24 10:37:19 -04001189 if (data->getLength()) {
1190 WriteToDisk(task, md5, ext, data, data->getLength(), nullptr);
1191 SkASSERT(bitmap.drawsNothing());
1192 } else if (!bitmap.drawsNothing()) {
1193 WriteToDisk(task, md5, ext, nullptr, 0, &bitmap);
1194 }
mtkleincd50bca2016-01-05 06:20:20 -08001195 }
1196 }
1197 });
mtklein748ca3b2015-01-15 10:56:12 -08001198 }
mtklein3eed7dd2016-02-24 19:07:07 -08001199 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 -08001200 }
1201
1202 static void WriteToDisk(const Task& task,
mtklein62bd1a62015-01-27 14:46:26 -08001203 SkString md5,
1204 const char* ext,
mtklein748ca3b2015-01-15 10:56:12 -08001205 SkStream* data, size_t len,
mtklein62bd1a62015-01-27 14:46:26 -08001206 const SkBitmap* bitmap) {
Brian Osmana76b7a92018-07-18 14:36:43 -04001207 bool gammaCorrect = bitmap &&
1208 bitmap->info().colorSpace() &&
1209 bitmap->info().colorSpace()->gammaIsLinear();
mtklein409d4702016-02-29 07:38:01 -08001210
mtklein748ca3b2015-01-15 10:56:12 -08001211 JsonWriter::BitmapResult result;
djsollen54416de2015-04-03 07:24:48 -07001212 result.name = task.src->name();
mtklein3eed7dd2016-02-24 19:07:07 -08001213 result.config = task.sink.tag;
djsollen54416de2015-04-03 07:24:48 -07001214 result.sourceType = task.src.tag;
1215 result.sourceOptions = task.src.options;
1216 result.ext = ext;
mtklein409d4702016-02-29 07:38:01 -08001217 result.gammaCorrect = gammaCorrect;
djsollen54416de2015-04-03 07:24:48 -07001218 result.md5 = md5;
mtklein748ca3b2015-01-15 10:56:12 -08001219 JsonWriter::AddBitmapResult(result);
1220
mtkleinb0531a72015-04-07 13:38:48 -07001221 // If an MD5 is uninteresting, we want it noted in the JSON file,
1222 // but don't want to dump it out as a .png (or whatever ext is).
1223 if (gUninterestingHashes.contains(md5)) {
1224 return;
1225 }
1226
mtklein748ca3b2015-01-15 10:56:12 -08001227 const char* dir = FLAGS_writePath[0];
1228 if (0 == strcmp(dir, "@")) { // Needed for iOS.
1229 dir = FLAGS_resourcePath[0];
1230 }
1231 sk_mkdir(dir);
1232
1233 SkString path;
1234 if (FLAGS_nameByHash) {
1235 path = SkOSPath::Join(dir, result.md5.c_str());
1236 path.append(".");
1237 path.append(ext);
1238 if (sk_exists(path.c_str())) {
1239 return; // Content-addressed. If it exists already, we're done.
1240 }
1241 } else {
kkinnunen3e980c32015-12-23 01:33:00 -08001242 path = SkOSPath::Join(dir, task.sink.tag.c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001243 sk_mkdir(path.c_str());
msarett9e707a02015-09-01 14:57:57 -07001244 path = SkOSPath::Join(path.c_str(), task.src.tag.c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001245 sk_mkdir(path.c_str());
msarett9e707a02015-09-01 14:57:57 -07001246 if (strcmp(task.src.options.c_str(), "") != 0) {
1247 path = SkOSPath::Join(path.c_str(), task.src.options.c_str());
djsollen54416de2015-04-03 07:24:48 -07001248 sk_mkdir(path.c_str());
1249 }
mtklein748ca3b2015-01-15 10:56:12 -08001250 path = SkOSPath::Join(path.c_str(), task.src->name().c_str());
1251 path.append(".");
1252 path.append(ext);
1253 }
1254
mtklein748ca3b2015-01-15 10:56:12 -08001255 if (bitmap) {
mtkleina5114d72015-08-24 13:27:01 -07001256 if (!dump_png(*bitmap, path.c_str(), result.md5.c_str())) {
mtklein748ca3b2015-01-15 10:56:12 -08001257 fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str()));
1258 return;
1259 }
1260 } else {
mtkleina5114d72015-08-24 13:27:01 -07001261 SkFILEWStream file(path.c_str());
1262 if (!file.isValid()) {
1263 fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str()));
1264 return;
1265 }
mtklein748ca3b2015-01-15 10:56:12 -08001266 if (!file.writeStream(data, len)) {
1267 fail(SkStringPrintf("Can't write to %s.\n", path.c_str()));
1268 return;
1269 }
1270 }
1271 }
1272};
1273
mtklein748ca3b2015-01-15 10:56:12 -08001274/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1275
1276// Unit tests don't fit so well into the Src/Sink model, so we give them special treatment.
1277
mtklein21eaf3b2016-02-08 12:39:59 -08001278static SkTDArray<skiatest::Test> gParallelTests, gSerialTests;
mtklein748ca3b2015-01-15 10:56:12 -08001279
1280static void gather_tests() {
mtklein6c5fed22015-01-20 13:47:23 -08001281 if (!FLAGS_src.contains("tests")) {
mtklein748ca3b2015-01-15 10:56:12 -08001282 return;
1283 }
Hal Canary972eba32018-07-30 17:07:07 -04001284 for (const skiatest::Test& test : skiatest::TestRegistry::Range()) {
mtklein6393c062015-04-27 08:45:01 -07001285 if (!in_shard()) {
1286 continue;
1287 }
halcanary87f3ba42015-01-20 09:30:20 -08001288 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, test.name)) {
mtklein748ca3b2015-01-15 10:56:12 -08001289 continue;
1290 }
Brian Osmanc7ad40f2018-05-31 14:27:17 -04001291 if (test.needsGpu && FLAGS_gpu) {
Mike Reed5edcd312018-08-08 11:23:41 -04001292 (FLAGS_gpu_threading ? gParallelTests : gSerialTests).push_back(test);
halcanary87f3ba42015-01-20 09:30:20 -08001293 } else if (!test.needsGpu && FLAGS_cpu) {
Mike Reed5edcd312018-08-08 11:23:41 -04001294 gParallelTests.push_back(test);
mtklein82d28432015-01-15 12:46:02 -08001295 }
mtklein748ca3b2015-01-15 10:56:12 -08001296 }
1297}
1298
csmartdalton008b9d82017-02-22 12:00:42 -07001299static void run_test(skiatest::Test test, const GrContextOptions& grCtxOptions) {
halcanary87f3ba42015-01-20 09:30:20 -08001300 struct : public skiatest::Reporter {
mtklein36352bf2015-03-25 18:17:31 -07001301 void reportFailed(const skiatest::Failure& failure) override {
halcanary87f3ba42015-01-20 09:30:20 -08001302 fail(failure.toString());
1303 JsonWriter::AddTestFailure(failure);
1304 }
mtklein36352bf2015-03-25 18:17:31 -07001305 bool allowExtendedTest() const override {
halcanary87f3ba42015-01-20 09:30:20 -08001306 return FLAGS_pathOpsExtended;
1307 }
mtklein36352bf2015-03-25 18:17:31 -07001308 bool verbose() const override { return FLAGS_veryVerbose; }
halcanary87f3ba42015-01-20 09:30:20 -08001309 } reporter;
djsollen824996a2015-06-12 12:06:22 -07001310
mtklein3eed7dd2016-02-24 19:07:07 -08001311 if (!FLAGS_dryRun && !is_blacklisted("_", "tests", "_", test.name)) {
Robert Phillipsec325342017-10-30 18:02:48 +00001312 GrContextOptions options = grCtxOptions;
1313 test.modifyGrContextOptions(&options);
1314
mtklein21eaf3b2016-02-08 12:39:59 -08001315 start("unit", "test", "", test.name);
Brian Salomondcfca432017-11-15 15:48:03 -05001316 test.run(&reporter, options);
mtklein748ca3b2015-01-15 10:56:12 -08001317 }
mtklein3eed7dd2016-02-24 19:07:07 -08001318 done("unit", "test", "", test.name);
mtklein748ca3b2015-01-15 10:56:12 -08001319}
1320
1321/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1322
Mike Kleinbe28ee22017-02-06 12:46:20 -05001323int main(int argc, char** argv) {
Dongwon Kang0c7861f2018-02-16 10:55:21 -08001324#if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && defined(SK_HAS_HEIF_LIBRARY)
1325 android::ProcessState::self()->startThreadPool();
1326#endif
Mike Kleinbe28ee22017-02-06 12:46:20 -05001327 SkCommandLineFlags::Parse(argc, argv);
Brian Osman53136aa2017-07-20 15:43:35 -04001328
Mike Klein31868212017-11-06 12:02:47 -05001329 if (!FLAGS_nativeFonts) {
Ben Wagner483c7722018-02-20 17:06:07 -05001330 gSkFontMgr_DefaultFactory = &sk_tool_utils::MakePortableFontMgr;
Mike Klein31868212017-11-06 12:02:47 -05001331 }
1332
Mike Klein0c5fdcb2017-11-13 12:40:46 -05001333#if defined(SK_BUILD_FOR_WIN)
1334 if (FLAGS_gdi) {
Hal Canaryccafca02017-11-14 10:34:48 -05001335 gSkFontMgr_DefaultFactory = &SkFontMgr_New_GDI;
Mike Klein0c5fdcb2017-11-13 12:40:46 -05001336 }
1337#endif
1338
Brian Osmanbc8150f2017-07-24 11:38:01 -04001339 initializeEventTracingForTools();
Brian Osman53136aa2017-07-20 15:43:35 -04001340
Mike Klein6613cc52017-12-19 09:09:33 -05001341#if !defined(SK_BUILD_FOR_GOOGLE3) && defined(SK_BUILD_FOR_IOS)
Mike Kleinadacaef2017-02-06 09:26:14 -05001342 cd_Documents();
1343#endif
bsalomon71de3532016-04-26 14:27:21 -07001344 setbuf(stdout, nullptr);
mtklein246ba3a2016-02-23 10:39:36 -08001345 setup_crash_handler();
mtkleinafae30a2016-02-24 12:28:32 -08001346
Yuqian Liba62b4a2016-12-14 13:46:53 -05001347 gSkUseAnalyticAA = FLAGS_analyticAA;
Yuqian Lidf60e362017-07-25 11:26:31 -04001348 gSkUseDeltaAA = FLAGS_deltaAA;
liyuqian38911a72016-10-04 11:23:22 -07001349
Yuqian Li550148b2017-01-13 10:13:13 -05001350 if (FLAGS_forceAnalyticAA) {
1351 gSkForceAnalyticAA = true;
1352 }
Yuqian Lia81b6262017-09-06 17:10:05 -04001353 if (FLAGS_forceDeltaAA) {
1354 gSkForceDeltaAA = true;
1355 }
Mike Reed7c26ca72017-07-05 15:45:52 -04001356 if (FLAGS_forceRasterPipeline) {
1357 gSkForceRasterPipelineBlitter = true;
1358 }
Yuqian Li550148b2017-01-13 10:13:13 -05001359
Mike Kleine9f187b2017-06-26 13:23:12 -04001360 // The bots like having a verbose.log to upload, so always touch the file even if --verbose.
1361 if (!FLAGS_writePath.isEmpty()) {
mtklein51c8cfc2016-03-11 12:59:09 -08001362 sk_mkdir(FLAGS_writePath[0]);
mtkleina1ce2162016-07-22 12:23:46 -07001363 gVLog = fopen(SkOSPath::Join(FLAGS_writePath[0], "verbose.log").c_str(), "w");
mtkleinc41fd922016-03-08 09:01:39 -08001364 }
Mike Kleine9f187b2017-06-26 13:23:12 -04001365 if (FLAGS_verbose) {
1366 gVLog = stderr;
1367 }
mtkleinc41fd922016-03-08 09:01:39 -08001368
csmartdalton008b9d82017-02-22 12:00:42 -07001369 GrContextOptions grCtxOptions;
Chris Dalton040238b2017-12-18 14:22:34 -07001370 SetCtxOptionsFromCommonFlags(&grCtxOptions);
csmartdalton008b9d82017-02-22 12:00:42 -07001371
mtklein5286f022016-01-22 08:18:14 -08001372 JsonWriter::DumpJson(); // It's handy for the bots to assume this is ~never missing.
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +00001373 SkAutoGraphics ag;
mtklein406654b2014-09-03 15:34:37 -07001374 SkTaskGroup::Enabler enabled(FLAGS_threads);
commit-bot@chromium.orga65e2fd2014-05-30 17:23:31 +00001375
Mike Reed0933bc92017-12-09 01:27:41 +00001376 if (nullptr == GetResourceAsData("images/color_wheel.png")) {
1377 info("Some resources are missing. Do you need to set --resourcePath?\n");
halcanary7d571242016-02-24 17:59:16 -08001378 }
mtklein62bd1a62015-01-27 14:46:26 -08001379 gather_gold();
borenet09ed4802015-04-03 14:15:33 -07001380 gather_uninteresting_hashes();
mtklein62bd1a62015-01-27 14:46:26 -08001381
scroggo86737142016-02-03 12:19:11 -08001382 if (!gather_srcs()) {
1383 return 1;
1384 }
Ben Wagnerf28d4722017-08-11 17:33:22 -04001385 // TODO(dogben): This is a bit ugly. Find a cleaner way to do this.
1386 bool defaultConfigs = true;
1387 for (int i = 0; i < argc; i++) {
1388 static const char* kConfigArg = "--config";
1389 if (strcmp(argv[i], kConfigArg) == 0) {
1390 defaultConfigs = false;
1391 break;
1392 }
1393 }
1394 if (!gather_sinks(grCtxOptions, defaultConfigs)) {
brianosman05c987c2016-05-09 13:42:16 -07001395 return 1;
1396 }
mtklein748ca3b2015-01-15 10:56:12 -08001397 gather_tests();
mtklein21eaf3b2016-02-08 12:39:59 -08001398 gPending = gSrcs.count() * gSinks.count() + gParallelTests.count() + gSerialTests.count();
Brian Osmand0677bc2017-08-03 12:13:47 -04001399 info("%d srcs * %d sinks + %d tests == %d tasks\n",
mtkleinc41fd922016-03-08 09:01:39 -08001400 gSrcs.count(), gSinks.count(), gParallelTests.count() + gSerialTests.count(), gPending);
mtklein748ca3b2015-01-15 10:56:12 -08001401
mtklein21eaf3b2016-02-08 12:39:59 -08001402 // Kick off as much parallel work as we can, making note of any serial work we'll need to do.
1403 SkTaskGroup parallel;
1404 SkTArray<Task> serial;
1405
1406 for (auto& sink : gSinks)
1407 for (auto& src : gSrcs) {
mtklein3eed7dd2016-02-24 19:07:07 -08001408 if (src->veto(sink->flags()) ||
1409 is_blacklisted(sink.tag.c_str(), src.tag.c_str(),
1410 src.options.c_str(), src->name().c_str())) {
mtkleinf10637f2016-06-10 13:56:35 -07001411 SkAutoMutexAcquire lock(gMutex);
mtklein3eed7dd2016-02-24 19:07:07 -08001412 gPending--;
1413 continue;
1414 }
1415
mtklein21eaf3b2016-02-08 12:39:59 -08001416 Task task(src, sink);
1417 if (src->serial() || sink->serial()) {
1418 serial.push_back(task);
1419 } else {
1420 parallel.add([task] { Task::Run(task); });
mtklein748ca3b2015-01-15 10:56:12 -08001421 }
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001422 }
mtklein21eaf3b2016-02-08 12:39:59 -08001423 for (auto test : gParallelTests) {
csmartdalton008b9d82017-02-22 12:00:42 -07001424 parallel.add([test, grCtxOptions] { run_test(test, grCtxOptions); });
mtklein55e88b22015-01-21 15:50:13 -08001425 }
mtklein21eaf3b2016-02-08 12:39:59 -08001426
1427 // With the parallel work running, run serial tasks and tests here on main thread.
1428 for (auto task : serial) { Task::Run(task); }
csmartdalton008b9d82017-02-22 12:00:42 -07001429 for (auto test : gSerialTests) { run_test(test, grCtxOptions); }
mtklein21eaf3b2016-02-08 12:39:59 -08001430
1431 // Wait for any remaining parallel work to complete (including any spun off of serial tasks).
1432 parallel.wait();
mtkleincd50bca2016-01-05 06:20:20 -08001433 gDefinitelyThreadSafeWork.wait();
1434
Ben Wagner83c6b962018-07-10 19:40:15 -04001435 // At this point we're back in single-threaded land.
1436
mtkleinda884c42016-02-24 18:00:23 -08001437 // We'd better have run everything.
1438 SkASSERT(gPending == 0);
mtkleine027f172016-02-26 15:53:06 -08001439 // Make sure we've flushed all our results to disk.
1440 JsonWriter::DumpJson();
mtkleinda884c42016-02-24 18:00:23 -08001441
mtklein748ca3b2015-01-15 10:56:12 -08001442 if (gFailures.count() > 0) {
mtkleinc41fd922016-03-08 09:01:39 -08001443 info("Failures:\n");
mtklein748ca3b2015-01-15 10:56:12 -08001444 for (int i = 0; i < gFailures.count(); i++) {
mtkleinc41fd922016-03-08 09:01:39 -08001445 info("\t%s\n", gFailures[i].c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001446 }
mtkleinc41fd922016-03-08 09:01:39 -08001447 info("%d failures\n", gFailures.count());
mtklein748ca3b2015-01-15 10:56:12 -08001448 return 1;
mtklein114c3cd2015-01-15 10:15:02 -08001449 }
mtkleinafae30a2016-02-24 12:28:32 -08001450
1451#ifdef SK_PDF_IMAGE_STATS
halcanary7a14b312015-10-01 07:28:13 -07001452 SkPDFImageDumpStats();
mtkleinafae30a2016-02-24 12:28:32 -08001453#endif // SK_PDF_IMAGE_STATS
1454
Herb Derby5a523fe2017-01-26 16:48:28 -05001455 SkGraphics::PurgeAllCaches();
mtkleinc41fd922016-03-08 09:01:39 -08001456 info("Finished!\n");
Brian Osman53136aa2017-07-20 15:43:35 -04001457
mtklein748ca3b2015-01-15 10:56:12 -08001458 return 0;
mtklein@google.comd36522d2013-10-16 13:02:15 +00001459}