blob: 1d3d815647e378b572e85ac9f0efa20ba39ea738 [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"
Ben Wagner483c7722018-02-20 17:06:07 -050039#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"
brianosman3c579dc2016-04-19 09:18:11 -070046#include "picture_utils.h"
caryclark83ca6282015-06-10 09:31:09 -070047#include "sk_tool_utils.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000048
scroggo19b91532016-10-24 09:03:26 -070049#include <vector>
50
halcanary7a14b312015-10-01 07:28:13 -070051#ifdef SK_PDF_IMAGE_STATS
52extern void SkPDFImageDumpStats();
53#endif
54
mtkleina5114d72015-08-24 13:27:01 -070055#include "png.h"
56
bungeman60e0fee2015-08-26 05:15:46 -070057#include <stdlib.h>
58
Mike Klein8f11d4d2018-01-24 12:42:55 -050059#ifndef SK_BUILD_FOR_WIN
scroggo27a58342015-10-28 08:56:41 -070060 #include <unistd.h>
61#endif
62
Dongwon Kang0c7861f2018-02-16 10:55:21 -080063#if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && defined(SK_HAS_HEIF_LIBRARY)
64#include <binder/IPCThreadState.h>
65#endif
66
Mike Reed7c26ca72017-07-05 15:45:52 -040067extern bool gSkForceRasterPipelineBlitter;
68
Ben Wagner32fa5102017-08-10 21:25:55 -040069DECLARE_bool(undefok);
djsollen54416de2015-04-03 07:24:48 -070070DEFINE_string(src, "tests gm skp image", "Source types to test.");
mtklein748ca3b2015-01-15 10:56:12 -080071DEFINE_bool(nameByHash, false,
72 "If true, write to FLAGS_writePath[0]/<hash>.png instead of "
djsollen54416de2015-04-03 07:24:48 -070073 "to FLAGS_writePath[0]/<config>/<sourceType>/<sourceOptions>/<name>.png");
mtklein748ca3b2015-01-15 10:56:12 -080074DEFINE_bool2(pathOpsExtended, x, false, "Run extended pathOps tests.");
mtkleind603b222015-02-17 11:13:33 -080075DEFINE_string(matrix, "1 0 0 1",
76 "2x2 scale+skew matrix to apply or upright when using "
77 "'matrix' or 'upright' in config.");
mtklein82d28432015-01-15 12:46:02 -080078DEFINE_bool(gpu_threading, false, "Allow GPU work to run on multiple threads?");
mtklein@google.comd36522d2013-10-16 13:02:15 +000079
mtkleina2ef6422015-01-15 13:44:22 -080080DEFINE_string(blacklist, "",
Chris Daltonecf78ac2017-08-15 15:43:08 -060081 "Space-separated config/src/srcOptions/name quadruples to blacklist. "
82 "'_' matches anything. '~' negates the match. E.g. \n"
djsollen54416de2015-04-03 07:24:48 -070083 "'--blacklist gpu skp _ _' will blacklist all SKPs drawn into the gpu config.\n"
Chris Daltonecf78ac2017-08-15 15:43:08 -060084 "'--blacklist gpu skp _ _ 8888 gm _ aarects' will also blacklist the aarects GM on 8888.\n"
85 "'--blacklist ~8888 svg _ svgparse_' blocks non-8888 SVGs that contain \"svgparse_\" in "
86 "the name.");
mtkleina2ef6422015-01-15 13:44:22 -080087
mtklein62bd1a62015-01-27 14:46:26 -080088DEFINE_string2(readPath, r, "", "If set check for equality with golden results in this directory.");
89
borenet09ed4802015-04-03 14:15:33 -070090DEFINE_string(uninterestingHashesFile, "",
91 "File containing a list of uninteresting hashes. If a result hashes to something in "
92 "this list, no image is written for that result.");
93
mtklein6393c062015-04-27 08:45:01 -070094DEFINE_int32(shards, 1, "We're splitting source data into this many shards.");
95DEFINE_int32(shard, 0, "Which shard do I run?");
96
halcanary45420a92016-06-02 12:41:14 -070097DEFINE_string(mskps, "", "Directory to read mskps from, or a single mskp file.");
Mike Reed7c26ca72017-07-05 15:45:52 -040098DEFINE_bool(forceRasterPipeline, false, "sets gSkForceRasterPipelineBlitter");
halcanary45420a92016-06-02 12:41:14 -070099
Robert Phillipsad8a43f2017-08-30 12:06:35 -0400100DEFINE_bool(ddl, false, "If true, use DeferredDisplayLists for GPU SKP rendering.");
101
Derek Sollenbergeredfe3df2017-07-19 15:25:24 -0400102DEFINE_bool(ignoreSigInt, false, "ignore SIGINT signals during test execution");
103
Mike Klein97d6a7a2017-07-24 10:37:19 -0400104DEFINE_string(dont_write, "", "File extensions to skip writing to --writePath."); // See skia:6821
105
Mike Klein0c5fdcb2017-11-13 12:40:46 -0500106DEFINE_bool(gdi, false, "On Windows, use GDI instead of DirectWrite for font rendering.");
Mike Klein31868212017-11-06 12:02:47 -0500107
mtklein748ca3b2015-01-15 10:56:12 -0800108using namespace DM;
bsalomon3724e572016-03-30 18:56:19 -0700109using sk_gpu_test::GrContextFactory;
bsalomon273c0f52016-03-31 10:59:06 -0700110using sk_gpu_test::GLTestContext;
bsalomonf2f1c172016-04-05 12:59:06 -0700111using sk_gpu_test::ContextInfo;
mtklein@google.comd36522d2013-10-16 13:02:15 +0000112
mtklein748ca3b2015-01-15 10:56:12 -0800113/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
114
benjaminwagnerec4d4d72016-03-25 12:59:53 -0700115static const double kStartMs = SkTime::GetMSecs();
mtkleinc41fd922016-03-08 09:01:39 -0800116
117static FILE* gVLog;
118
119template <typename... Args>
120static void vlog(const char* fmt, Args&&... args) {
121 if (gVLog) {
Jim Van Verth32bbf372017-09-20 12:53:00 -0400122 char s[64];
123 HumanizeMs(s, 64, SkTime::GetMSecs() - kStartMs);
124 fprintf(gVLog, "%s\t", s);
mtkleinc41fd922016-03-08 09:01:39 -0800125 fprintf(gVLog, fmt, args...);
126 fflush(gVLog);
127 }
128}
129
130template <typename... Args>
131static void info(const char* fmt, Args&&... args) {
132 vlog(fmt, args...);
133 if (!FLAGS_quiet) {
134 printf(fmt, args...);
135 }
136}
137static void info(const char* fmt) {
138 if (!FLAGS_quiet) {
139 printf("%s", fmt); // Clang warns printf(fmt) is insecure.
140 }
141}
142
reed086eea92016-05-04 17:12:46 -0700143SK_DECLARE_STATIC_MUTEX(gFailuresMutex);
mtklein748ca3b2015-01-15 10:56:12 -0800144static SkTArray<SkString> gFailures;
145
mtklein3eed7dd2016-02-24 19:07:07 -0800146static void fail(const SkString& err) {
mtklein748ca3b2015-01-15 10:56:12 -0800147 SkAutoMutexAcquire lock(gFailuresMutex);
148 SkDebugf("\n\nFAILURE: %s\n\n", err.c_str());
149 gFailures.push_back(err);
halcanary9e398f72015-01-10 11:18:04 -0800150}
151
mtklein0f7748a2016-07-25 15:27:29 -0700152struct Running {
153 SkString id;
154 SkThreadID thread;
155
156 void dump() const {
157 info("\t%s\n", id.c_str());
158 }
159};
mtkleinb37cb412015-03-18 05:27:14 -0700160
mtklein246ba3a2016-02-23 10:39:36 -0800161// We use a spinlock to make locking this in a signal handler _somewhat_ safe.
Mike Klein03a95ad2017-06-23 12:36:32 -0400162static SkSpinlock gMutex;
163static int gPending;
mtklein0f7748a2016-07-25 15:27:29 -0700164static SkTArray<Running> gRunning;
mtklein748ca3b2015-01-15 10:56:12 -0800165
mtklein3eed7dd2016-02-24 19:07:07 -0800166static void done(const char* config, const char* src, const char* srcOptions, const char* name) {
167 SkString id = SkStringPrintf("%s %s %s %s", config, src, srcOptions, name);
mtkleinc41fd922016-03-08 09:01:39 -0800168 vlog("done %s\n", id.c_str());
mtkleinafae30a2016-02-24 12:28:32 -0800169 int pending;
mtkleinb37cb412015-03-18 05:27:14 -0700170 {
mtkleinf10637f2016-06-10 13:56:35 -0700171 SkAutoMutexAcquire lock(gMutex);
mtkleinb37cb412015-03-18 05:27:14 -0700172 for (int i = 0; i < gRunning.count(); i++) {
mtklein0f7748a2016-07-25 15:27:29 -0700173 if (gRunning[i].id == id) {
mtkleinb37cb412015-03-18 05:27:14 -0700174 gRunning.removeShuffle(i);
175 break;
176 }
177 }
mtkleinafae30a2016-02-24 12:28:32 -0800178 pending = --gPending;
reed50bc0512015-05-19 14:13:31 -0700179 }
Mike Klein03a95ad2017-06-23 12:36:32 -0400180
181 // We write out dm.json file and print out a progress update every once in a while.
182 // Notice this also handles the final dm.json and progress update when pending == 0.
mtkleina17241b2015-01-23 05:48:00 -0800183 if (pending % 500 == 0) {
184 JsonWriter::DumpJson();
Mike Klein03a95ad2017-06-23 12:36:32 -0400185
186 int curr = sk_tools::getCurrResidentSetSizeMB(),
187 peak = sk_tools::getMaxResidentSetSizeMB();
188 SkString elapsed = HumanizeMs(SkTime::GetMSecs() - kStartMs);
189
190 SkAutoMutexAcquire lock(gMutex);
191 info("\n%dMB RAM, %dMB peak, %s elapsed, %d queued, %d active:\n",
192 curr, peak, elapsed.c_str(), gPending - gRunning.count(), gRunning.count());
193 for (auto& task : gRunning) {
194 task.dump();
195 }
mtkleina17241b2015-01-23 05:48:00 -0800196 }
mtklein@google.comd36522d2013-10-16 13:02:15 +0000197}
198
mtklein3eed7dd2016-02-24 19:07:07 -0800199static void start(const char* config, const char* src, const char* srcOptions, const char* name) {
200 SkString id = SkStringPrintf("%s %s %s %s", config, src, srcOptions, name);
mtkleinc41fd922016-03-08 09:01:39 -0800201 vlog("start %s\n", id.c_str());
mtkleinf10637f2016-06-10 13:56:35 -0700202 SkAutoMutexAcquire lock(gMutex);
mtklein0f7748a2016-07-25 15:27:29 -0700203 gRunning.push_back({id,SkGetThreadID()});
mtkleinb37cb412015-03-18 05:27:14 -0700204}
205
Mike Klein3cc2d202016-10-24 11:39:43 -0400206static void find_culprit() {
207 // Assumes gMutex is locked.
208 SkThreadID thisThread = SkGetThreadID();
209 for (auto& task : gRunning) {
210 if (task.thread == thisThread) {
211 info("Likely culprit:\n");
212 task.dump();
mtklein0f7748a2016-07-25 15:27:29 -0700213 }
214 }
Mike Klein3cc2d202016-10-24 11:39:43 -0400215}
mtklein0f7748a2016-07-25 15:27:29 -0700216
Mike Klein8f11d4d2018-01-24 12:42:55 -0500217#if defined(SK_BUILD_FOR_WIN)
mtklein5b64dab2016-06-09 08:59:48 -0700218 static LONG WINAPI crash_handler(EXCEPTION_POINTERS* e) {
mtkleinf8557292016-02-29 06:35:28 -0800219 static const struct {
220 const char* name;
robertphillips75467862016-03-01 14:10:23 -0800221 DWORD code;
mtkleinf8557292016-02-29 06:35:28 -0800222 } kExceptions[] = {
223 #define _(E) {#E, E}
224 _(EXCEPTION_ACCESS_VIOLATION),
225 _(EXCEPTION_BREAKPOINT),
226 _(EXCEPTION_INT_DIVIDE_BY_ZERO),
227 _(EXCEPTION_STACK_OVERFLOW),
228 // TODO: more?
229 #undef _
230 };
231
mtkleinf10637f2016-06-10 13:56:35 -0700232 SkAutoMutexAcquire lock(gMutex);
mtklein5b64dab2016-06-09 08:59:48 -0700233
234 const DWORD code = e->ExceptionRecord->ExceptionCode;
235 info("\nCaught exception %u", code);
236 for (const auto& exception : kExceptions) {
237 if (exception.code == code) {
238 info(" %s", exception.name);
mtkleinf8557292016-02-29 06:35:28 -0800239 }
mtkleinf8557292016-02-29 06:35:28 -0800240 }
mtklein5b64dab2016-06-09 08:59:48 -0700241 info(", was running:\n");
242 for (auto& task : gRunning) {
mtklein0f7748a2016-07-25 15:27:29 -0700243 task.dump();
mtklein5b64dab2016-06-09 08:59:48 -0700244 }
mtklein0f7748a2016-07-25 15:27:29 -0700245 find_culprit();
mtklein5b64dab2016-06-09 08:59:48 -0700246 fflush(stdout);
247
mtkleinf8557292016-02-29 06:35:28 -0800248 // Execute default exception handler... hopefully, exit.
249 return EXCEPTION_EXECUTE_HANDLER;
mtklein246ba3a2016-02-23 10:39:36 -0800250 }
251
Mike Klein3cc2d202016-10-24 11:39:43 -0400252 static void setup_crash_handler() {
253 SetUnhandledExceptionFilter(crash_handler);
254 }
255#else
mtklein246ba3a2016-02-23 10:39:36 -0800256 #include <signal.h>
Mike Klein3cc2d202016-10-24 11:39:43 -0400257 #if !defined(SK_BUILD_FOR_ANDROID)
258 #include <execinfo.h>
Brian Salomondcbb9d92017-07-19 10:53:20 -0400259
260#endif
Mike Klein3cc2d202016-10-24 11:39:43 -0400261
262 static constexpr int max_of() { return 0; }
263 template <typename... Rest>
264 static constexpr int max_of(int x, Rest... rest) {
265 return x > max_of(rest...) ? x : max_of(rest...);
266 }
267
Mike Kleinc7278ad2018-02-15 09:26:54 -0500268 static void (*previous_handler[max_of(SIGABRT,SIGBUS,SIGFPE,SIGILL,SIGSEGV,SIGTERM)+1])(int);
mtkleinf8557292016-02-29 06:35:28 -0800269
mtklein5b64dab2016-06-09 08:59:48 -0700270 static void crash_handler(int sig) {
mtkleinf10637f2016-06-10 13:56:35 -0700271 SkAutoMutexAcquire lock(gMutex);
mtklein5b64dab2016-06-09 08:59:48 -0700272
273 info("\nCaught signal %d [%s], was running:\n", sig, strsignal(sig));
274 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
Mike Kleinc7278ad2018-02-15 09:26:54 -0500294 static void term_handler(int sig) {
295 info("\nWe have been politely asked to die by %s (%d)."
296 "\nCurrently using %dMB RAM, peak %dMB.\n",
297 strsignal(sig), sig,
298 sk_tools::getCurrResidentSetSizeMB(), sk_tools::getMaxResidentSetSizeMB());
299 signal(sig, previous_handler[sig]);
300 raise(sig);
301 }
302
mtklein246ba3a2016-02-23 10:39:36 -0800303 static void setup_crash_handler() {
304 const int kSignals[] = { SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGSEGV };
305 for (int sig : kSignals) {
Mike Klein3cc2d202016-10-24 11:39:43 -0400306 previous_handler[sig] = signal(sig, crash_handler);
mtklein246ba3a2016-02-23 10:39:36 -0800307 }
Mike Kleinc7278ad2018-02-15 09:26:54 -0500308 previous_handler[SIGTERM] = signal(SIGTERM, term_handler);
Derek Sollenbergeredfe3df2017-07-19 15:25:24 -0400309
310 if (FLAGS_ignoreSigInt) {
311 signal(SIGINT, SIG_IGN);
312 }
mtklein246ba3a2016-02-23 10:39:36 -0800313 }
314#endif
315
mtklein748ca3b2015-01-15 10:56:12 -0800316/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
mtklein114c3cd2015-01-15 10:15:02 -0800317
mtklein62bd1a62015-01-27 14:46:26 -0800318struct Gold : public SkString {
mtkleina82f5622015-02-20 12:30:19 -0800319 Gold() : SkString("") {}
mtklein3eed7dd2016-02-24 19:07:07 -0800320 Gold(const SkString& sink, const SkString& src,
321 const SkString& srcOptions, const SkString& name,
322 const SkString& md5)
mtklein62bd1a62015-01-27 14:46:26 -0800323 : SkString("") {
324 this->append(sink);
325 this->append(src);
djsollen54416de2015-04-03 07:24:48 -0700326 this->append(srcOptions);
mtklein62bd1a62015-01-27 14:46:26 -0800327 this->append(name);
328 this->append(md5);
mtklein62bd1a62015-01-27 14:46:26 -0800329 }
mtkleinc8d1dd42015-10-15 12:23:01 -0700330 struct Hash {
331 uint32_t operator()(const Gold& g) const {
332 return SkGoodHash()((const SkString&)g);
333 }
334 };
mtklein62bd1a62015-01-27 14:46:26 -0800335};
mtkleina82f5622015-02-20 12:30:19 -0800336static SkTHashSet<Gold, Gold::Hash> gGold;
mtklein62bd1a62015-01-27 14:46:26 -0800337
338static void add_gold(JsonWriter::BitmapResult r) {
djsollen54416de2015-04-03 07:24:48 -0700339 gGold.add(Gold(r.config, r.sourceType, r.sourceOptions, r.name, r.md5));
mtklein62bd1a62015-01-27 14:46:26 -0800340}
341
342static void gather_gold() {
343 if (!FLAGS_readPath.isEmpty()) {
344 SkString path(FLAGS_readPath[0]);
345 path.append("/dm.json");
346 if (!JsonWriter::ReadJson(path.c_str(), add_gold)) {
347 fail(SkStringPrintf("Couldn't read %s for golden results.", path.c_str()));
348 }
349 }
350}
351
352/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
353
Mike Klein8f11d4d2018-01-24 12:42:55 -0500354#if defined(SK_BUILD_FOR_WIN)
mtklein935f1b12016-03-16 08:37:19 -0700355 static const char* kNewline = "\r\n";
356#else
357 static const char* kNewline = "\n";
358#endif
359
borenet09ed4802015-04-03 14:15:33 -0700360static SkTHashSet<SkString> gUninterestingHashes;
361
362static void gather_uninteresting_hashes() {
363 if (!FLAGS_uninterestingHashesFile.isEmpty()) {
bungeman38d909e2016-08-02 14:40:46 -0700364 sk_sp<SkData> data(SkData::MakeFromFileName(FLAGS_uninterestingHashesFile[0]));
mtkleincc334b32015-09-22 11:43:53 -0700365 if (!data) {
mtkleinc41fd922016-03-08 09:01:39 -0800366 info("WARNING: unable to read uninteresting hashes from %s\n",
367 FLAGS_uninterestingHashesFile[0]);
mtkleincc334b32015-09-22 11:43:53 -0700368 return;
369 }
Mike Klein45dcc0c2017-04-05 18:04:31 -0400370
371 // Copy to a string to make sure SkStrSplit has a terminating \0 to find.
372 SkString contents((const char*)data->data(), data->size());
373
borenet09ed4802015-04-03 14:15:33 -0700374 SkTArray<SkString> hashes;
Mike Klein45dcc0c2017-04-05 18:04:31 -0400375 SkStrSplit(contents.c_str(), kNewline, &hashes);
borenet09ed4802015-04-03 14:15:33 -0700376 for (const SkString& hash : hashes) {
377 gUninterestingHashes.add(hash);
378 }
mtkleinc41fd922016-03-08 09:01:39 -0800379 info("FYI: loaded %d distinct uninteresting hashes from %d lines\n",
380 gUninterestingHashes.count(), hashes.count());
borenet09ed4802015-04-03 14:15:33 -0700381 }
382}
383
384/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
385
Ben Wagner145dbcd2016-11-03 14:40:50 -0400386struct TaggedSrc : public std::unique_ptr<Src> {
mtklein3eed7dd2016-02-24 19:07:07 -0800387 SkString tag;
388 SkString options;
mtkleine0effd62015-07-29 06:37:28 -0700389};
390
Ben Wagner145dbcd2016-11-03 14:40:50 -0400391struct TaggedSink : public std::unique_ptr<Sink> {
kkinnunen3e980c32015-12-23 01:33:00 -0800392 SkString tag;
djsollen54416de2015-04-03 07:24:48 -0700393};
mtklein748ca3b2015-01-15 10:56:12 -0800394
395static const bool kMemcpyOK = true;
396
mtkleine0effd62015-07-29 06:37:28 -0700397static SkTArray<TaggedSrc, kMemcpyOK> gSrcs;
398static SkTArray<TaggedSink, kMemcpyOK> gSinks;
mtklein748ca3b2015-01-15 10:56:12 -0800399
mtklein6393c062015-04-27 08:45:01 -0700400static bool in_shard() {
401 static int N = 0;
402 return N++ % FLAGS_shards == FLAGS_shard;
403}
404
mtklein3eed7dd2016-02-24 19:07:07 -0800405static void push_src(const char* tag, ImplicitString options, Src* s) {
Ben Wagner145dbcd2016-11-03 14:40:50 -0400406 std::unique_ptr<Src> src(s);
mtklein6393c062015-04-27 08:45:01 -0700407 if (in_shard() &&
mtklein3eed7dd2016-02-24 19:07:07 -0800408 FLAGS_src.contains(tag) &&
mtklein748ca3b2015-01-15 10:56:12 -0800409 !SkCommandLineFlags::ShouldSkip(FLAGS_match, src->name().c_str())) {
mtkleine0effd62015-07-29 06:37:28 -0700410 TaggedSrc& s = gSrcs.push_back();
mtklein18300a32016-03-16 13:53:35 -0700411 s.reset(src.release());
mtklein748ca3b2015-01-15 10:56:12 -0800412 s.tag = tag;
djsollen54416de2015-04-03 07:24:48 -0700413 s.options = options;
mtklein114c3cd2015-01-15 10:15:02 -0800414 }
mtklein748ca3b2015-01-15 10:56:12 -0800415}
mtklein114c3cd2015-01-15 10:15:02 -0800416
msarett9e707a02015-09-01 14:57:57 -0700417static void push_codec_src(Path path, CodecSrc::Mode mode, CodecSrc::DstColorType dstColorType,
scroggoc5560be2016-02-03 09:42:42 -0800418 SkAlphaType dstAlphaType, float scale) {
scroggoe4499842016-02-25 11:03:47 -0800419 if (FLAGS_simpleCodec) {
scroggo19b91532016-10-24 09:03:26 -0700420 const bool simple = CodecSrc::kCodec_Mode == mode || CodecSrc::kAnimated_Mode == mode;
421 if (!simple || dstColorType != CodecSrc::kGetFromCanvas_DstColorType || scale != 1.0f) {
scroggoe4499842016-02-25 11:03:47 -0800422 // Only decode in the simple case.
423 return;
scroggo19b91532016-10-24 09:03:26 -0700424 }
scroggoe4499842016-02-25 11:03:47 -0800425 }
msarett9e707a02015-09-01 14:57:57 -0700426 SkString folder;
427 switch (mode) {
428 case CodecSrc::kCodec_Mode:
429 folder.append("codec");
430 break;
msarettbb25b532016-01-13 09:31:39 -0800431 case CodecSrc::kCodecZeroInit_Mode:
432 folder.append("codec_zero_init");
433 break;
msarett9e707a02015-09-01 14:57:57 -0700434 case CodecSrc::kScanline_Mode:
435 folder.append("scanline");
436 break;
msarett9e707a02015-09-01 14:57:57 -0700437 case CodecSrc::kStripe_Mode:
438 folder.append("stripe");
439 break;
msarett91c22b22016-02-22 12:27:46 -0800440 case CodecSrc::kCroppedScanline_Mode:
441 folder.append("crop");
442 break;
msarett9e707a02015-09-01 14:57:57 -0700443 case CodecSrc::kSubset_Mode:
msarett36c37962015-09-02 13:20:52 -0700444 folder.append("codec_subset");
msarett9e707a02015-09-01 14:57:57 -0700445 break;
scroggo19b91532016-10-24 09:03:26 -0700446 case CodecSrc::kAnimated_Mode:
447 folder.append("codec_animated");
448 break;
msarett9e707a02015-09-01 14:57:57 -0700449 }
450
451 switch (dstColorType) {
452 case CodecSrc::kGrayscale_Always_DstColorType:
453 folder.append("_kGray8");
454 break;
msarett34e0ec42016-04-22 16:27:24 -0700455 case CodecSrc::kNonNative8888_Always_DstColorType:
456 folder.append("_kNonNative");
457 break;
msarett9e707a02015-09-01 14:57:57 -0700458 default:
459 break;
460 }
461
scroggoc5560be2016-02-03 09:42:42 -0800462 switch (dstAlphaType) {
scroggoc5560be2016-02-03 09:42:42 -0800463 case kPremul_SkAlphaType:
464 folder.append("_premul");
465 break;
466 case kUnpremul_SkAlphaType:
467 folder.append("_unpremul");
468 break;
469 default:
470 break;
471 }
472
msarett9e707a02015-09-01 14:57:57 -0700473 if (1.0f != scale) {
474 folder.appendf("_%.3f", scale);
475 }
476
scroggoc5560be2016-02-03 09:42:42 -0800477 CodecSrc* src = new CodecSrc(path, mode, dstColorType, dstAlphaType, scale);
msarett9e707a02015-09-01 14:57:57 -0700478 push_src("image", folder, src);
479}
480
scroggof8dc9df2016-05-16 09:04:13 -0700481static void push_android_codec_src(Path path, CodecSrc::DstColorType dstColorType,
482 SkAlphaType dstAlphaType, int sampleSize) {
msarett3d9d7a72015-10-21 10:27:10 -0700483 SkString folder;
scroggof8dc9df2016-05-16 09:04:13 -0700484 folder.append("scaled_codec");
msarett3d9d7a72015-10-21 10:27:10 -0700485
486 switch (dstColorType) {
487 case CodecSrc::kGrayscale_Always_DstColorType:
488 folder.append("_kGray8");
489 break;
msarett34e0ec42016-04-22 16:27:24 -0700490 case CodecSrc::kNonNative8888_Always_DstColorType:
491 folder.append("_kNonNative");
492 break;
msarett3d9d7a72015-10-21 10:27:10 -0700493 default:
494 break;
495 }
496
scroggoc5560be2016-02-03 09:42:42 -0800497 switch (dstAlphaType) {
scroggoc5560be2016-02-03 09:42:42 -0800498 case kPremul_SkAlphaType:
499 folder.append("_premul");
500 break;
msarett9e9444c2016-02-03 12:39:10 -0800501 case kUnpremul_SkAlphaType:
502 folder.append("_unpremul");
503 break;
scroggoc5560be2016-02-03 09:42:42 -0800504 default:
505 break;
506 }
507
msarett3d9d7a72015-10-21 10:27:10 -0700508 if (1 != sampleSize) {
msarett4b0778e2015-11-13 09:59:11 -0800509 folder.appendf("_%.3f", 1.0f / (float) sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700510 }
511
scroggof8dc9df2016-05-16 09:04:13 -0700512 AndroidCodecSrc* src = new AndroidCodecSrc(path, dstColorType, dstAlphaType, sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700513 push_src("image", folder, src);
514}
515
msarett18976312016-03-09 14:20:58 -0800516static void push_image_gen_src(Path path, ImageGenSrc::Mode mode, SkAlphaType alphaType, bool isGpu)
517{
518 SkString folder;
519 switch (mode) {
520 case ImageGenSrc::kCodec_Mode:
521 folder.append("gen_codec");
522 break;
523 case ImageGenSrc::kPlatform_Mode:
524 folder.append("gen_platform");
525 break;
526 }
527
528 if (isGpu) {
529 folder.append("_gpu");
530 } else {
531 switch (alphaType) {
532 case kOpaque_SkAlphaType:
533 folder.append("_opaque");
534 break;
535 case kPremul_SkAlphaType:
536 folder.append("_premul");
537 break;
538 case kUnpremul_SkAlphaType:
539 folder.append("_unpremul");
540 break;
541 default:
542 break;
543 }
544 }
545
546 ImageGenSrc* src = new ImageGenSrc(path, mode, alphaType, isGpu);
547 push_src("image", folder, src);
548}
549
Leon Scroggins III07418182017-08-15 12:24:02 -0400550static void push_brd_src(Path path, CodecSrc::DstColorType dstColorType, BRDSrc::Mode mode,
551 uint32_t sampleSize) {
552 SkString folder("brd_android_codec");
553 switch (mode) {
554 case BRDSrc::kFullImage_Mode:
555 break;
556 case BRDSrc::kDivisor_Mode:
557 folder.append("_divisor");
558 break;
559 default:
560 SkASSERT(false);
561 return;
562 }
563
564 switch (dstColorType) {
565 case CodecSrc::kGetFromCanvas_DstColorType:
566 break;
567 case CodecSrc::kGrayscale_Always_DstColorType:
568 folder.append("_kGray");
569 break;
570 default:
571 SkASSERT(false);
572 return;
573 }
574
575 if (1 != sampleSize) {
576 folder.appendf("_%.3f", 1.0f / (float) sampleSize);
577 }
578
579 BRDSrc* src = new BRDSrc(path, mode, dstColorType, sampleSize);
580 push_src("image", folder, src);
581}
582
583static void push_brd_srcs(Path path, bool gray) {
584 if (gray) {
585 // Only run grayscale to one sampleSize and Mode. Though interesting
586 // to test grayscale, it should not reveal anything across various
587 // sampleSizes and Modes
588 // Arbitrarily choose Mode and sampleSize.
589 push_brd_src(path, CodecSrc::kGrayscale_Always_DstColorType,
590 BRDSrc::kFullImage_Mode, 2);
591 }
592
593 // Test on a variety of sampleSizes, making sure to include:
594 // - 2, 4, and 8, which are natively supported by jpeg
595 // - multiples of 2 which are not divisible by 4 (analogous for 4)
596 // - larger powers of two, since BRD clients generally use powers of 2
597 // We will only produce output for the larger sizes on large images.
598 const uint32_t sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 24, 32, 64 };
599
600 const BRDSrc::Mode modes[] = { BRDSrc::kFullImage_Mode, BRDSrc::kDivisor_Mode, };
601
602 for (uint32_t sampleSize : sampleSizes) {
603 for (BRDSrc::Mode mode : modes) {
604 push_brd_src(path, CodecSrc::kGetFromCanvas_DstColorType, mode, sampleSize);
605 }
606 }
607}
608
msarett438b2ad2015-04-09 12:43:10 -0700609static void push_codec_srcs(Path path) {
bungeman38d909e2016-08-02 14:40:46 -0700610 sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str()));
msarett438b2ad2015-04-09 12:43:10 -0700611 if (!encoded) {
mtkleinc41fd922016-03-08 09:01:39 -0800612 info("Couldn't read %s.", path.c_str());
msarett438b2ad2015-04-09 12:43:10 -0700613 return;
614 }
Mike Reedede7bac2017-07-23 15:30:02 -0400615 std::unique_ptr<SkCodec> codec = SkCodec::MakeFromData(encoded);
halcanary96fcdcc2015-08-27 07:41:13 -0700616 if (nullptr == codec.get()) {
mtkleinc41fd922016-03-08 09:01:39 -0800617 info("Couldn't create codec for %s.", path.c_str());
msarett438b2ad2015-04-09 12:43:10 -0700618 return;
619 }
620
scroggo9366aff2016-05-20 08:38:54 -0700621 // native scaling is only supported by WEBP and JPEG
622 bool supportsNativeScaling = false;
msarett438b2ad2015-04-09 12:43:10 -0700623
msarett91c22b22016-02-22 12:27:46 -0800624 SkTArray<CodecSrc::Mode> nativeModes;
625 nativeModes.push_back(CodecSrc::kCodec_Mode);
626 nativeModes.push_back(CodecSrc::kCodecZeroInit_Mode);
msarett91c22b22016-02-22 12:27:46 -0800627 switch (codec->getEncodedFormat()) {
Hal Canarydb683012016-11-23 08:55:18 -0700628 case SkEncodedImageFormat::kJPEG:
msarett91c22b22016-02-22 12:27:46 -0800629 nativeModes.push_back(CodecSrc::kScanline_Mode);
630 nativeModes.push_back(CodecSrc::kStripe_Mode);
631 nativeModes.push_back(CodecSrc::kCroppedScanline_Mode);
scroggo9366aff2016-05-20 08:38:54 -0700632 supportsNativeScaling = true;
msarett91c22b22016-02-22 12:27:46 -0800633 break;
Hal Canarydb683012016-11-23 08:55:18 -0700634 case SkEncodedImageFormat::kWEBP:
msarett91c22b22016-02-22 12:27:46 -0800635 nativeModes.push_back(CodecSrc::kSubset_Mode);
scroggo9366aff2016-05-20 08:38:54 -0700636 supportsNativeScaling = true;
msarett91c22b22016-02-22 12:27:46 -0800637 break;
Hal Canarydb683012016-11-23 08:55:18 -0700638 case SkEncodedImageFormat::kDNG:
msarettb65e6042016-02-23 05:37:25 -0800639 break;
msarett91c22b22016-02-22 12:27:46 -0800640 default:
641 nativeModes.push_back(CodecSrc::kScanline_Mode);
msarett91c22b22016-02-22 12:27:46 -0800642 break;
643 }
msarett9e707a02015-09-01 14:57:57 -0700644
msarett91c22b22016-02-22 12:27:46 -0800645 SkTArray<CodecSrc::DstColorType> colorTypes;
646 colorTypes.push_back(CodecSrc::kGetFromCanvas_DstColorType);
msarett34e0ec42016-04-22 16:27:24 -0700647 colorTypes.push_back(CodecSrc::kNonNative8888_Always_DstColorType);
msarett36c37962015-09-02 13:20:52 -0700648 switch (codec->getInfo().colorType()) {
649 case kGray_8_SkColorType:
msarett91c22b22016-02-22 12:27:46 -0800650 colorTypes.push_back(CodecSrc::kGrayscale_Always_DstColorType);
msarett36c37962015-09-02 13:20:52 -0700651 break;
652 default:
msarett36c37962015-09-02 13:20:52 -0700653 break;
654 }
msarett9e707a02015-09-01 14:57:57 -0700655
scroggoc5560be2016-02-03 09:42:42 -0800656 SkTArray<SkAlphaType> alphaModes;
657 alphaModes.push_back(kPremul_SkAlphaType);
scroggof2c96a22016-05-20 11:08:27 -0700658 if (codec->getInfo().alphaType() != kOpaque_SkAlphaType) {
659 alphaModes.push_back(kUnpremul_SkAlphaType);
scroggoc5560be2016-02-03 09:42:42 -0800660 }
msarettb714fb02016-01-22 14:46:42 -0800661
662 for (CodecSrc::Mode mode : nativeModes) {
scroggo9366aff2016-05-20 08:38:54 -0700663 for (CodecSrc::DstColorType colorType : colorTypes) {
664 for (SkAlphaType alphaType : alphaModes) {
scroggof2c96a22016-05-20 11:08:27 -0700665 // Only test kCroppedScanline_Mode when the alpha type is premul. The test is
scroggo9366aff2016-05-20 08:38:54 -0700666 // slow and won't be interestingly different with different alpha types.
667 if (CodecSrc::kCroppedScanline_Mode == mode &&
scroggof2c96a22016-05-20 11:08:27 -0700668 kPremul_SkAlphaType != alphaType) {
scroggo9366aff2016-05-20 08:38:54 -0700669 continue;
670 }
msarett91c22b22016-02-22 12:27:46 -0800671
scroggo9366aff2016-05-20 08:38:54 -0700672 push_codec_src(path, mode, colorType, alphaType, 1.0f);
msarettf3dc1882016-04-26 13:06:38 -0700673
scroggo9366aff2016-05-20 08:38:54 -0700674 // Skip kNonNative on different native scales. It won't be interestingly
675 // different.
676 if (supportsNativeScaling &&
677 CodecSrc::kNonNative8888_Always_DstColorType == colorType) {
678 // Native Scales
679 // SkJpegCodec natively supports scaling to the following:
680 for (auto scale : { 0.125f, 0.25f, 0.375f, 0.5f, 0.625f, 0.750f, 0.875f }) {
681 push_codec_src(path, mode, colorType, alphaType, scale);
682 }
scroggoc5560be2016-02-03 09:42:42 -0800683 }
msarett9e707a02015-09-01 14:57:57 -0700684 }
685 }
msarett0a242972015-06-11 14:27:27 -0700686 }
msarett36c37962015-09-02 13:20:52 -0700687
scroggo19b91532016-10-24 09:03:26 -0700688 {
689 std::vector<SkCodec::FrameInfo> frameInfos = codec->getFrameInfo();
690 if (frameInfos.size() > 1) {
Leon Scroggins III557fbbe2017-05-23 09:37:21 -0400691 for (auto dstCT : { CodecSrc::kNonNative8888_Always_DstColorType,
692 CodecSrc::kGetFromCanvas_DstColorType }) {
693 for (auto at : { kUnpremul_SkAlphaType, kPremul_SkAlphaType }) {
694 push_codec_src(path, CodecSrc::kAnimated_Mode, dstCT, at, 1.0f);
695 }
696 }
scroggo19b91532016-10-24 09:03:26 -0700697 }
698
699 }
700
scroggoe4499842016-02-25 11:03:47 -0800701 if (FLAGS_simpleCodec) {
702 return;
703 }
704
msarett3d9d7a72015-10-21 10:27:10 -0700705 const int sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
msarett36c37962015-09-02 13:20:52 -0700706
msarett3d9d7a72015-10-21 10:27:10 -0700707 for (int sampleSize : sampleSizes) {
msarett91c22b22016-02-22 12:27:46 -0800708 for (CodecSrc::DstColorType colorType : colorTypes) {
scroggoc5560be2016-02-03 09:42:42 -0800709 for (SkAlphaType alphaType : alphaModes) {
msarettf3dc1882016-04-26 13:06:38 -0700710 // We can exercise all of the kNonNative support code in the swizzler with just a
711 // few sample sizes. Skip the rest.
712 if (CodecSrc::kNonNative8888_Always_DstColorType == colorType && sampleSize > 3) {
713 continue;
714 }
715
scroggof8dc9df2016-05-16 09:04:13 -0700716 push_android_codec_src(path, colorType, alphaType, sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700717 }
msarett36c37962015-09-02 13:20:52 -0700718 }
719 }
msarett18976312016-03-09 14:20:58 -0800720
Leon Scroggins III07418182017-08-15 12:24:02 -0400721 const char* ext = strrchr(path.c_str(), '.');
722 if (ext) {
723 ext++;
msarett18976312016-03-09 14:20:58 -0800724
Leon Scroggins III07418182017-08-15 12:24:02 -0400725 static const char* const rawExts[] = {
726 "arw", "cr2", "dng", "nef", "nrw", "orf", "raf", "rw2", "pef", "srw",
727 "ARW", "CR2", "DNG", "NEF", "NRW", "ORF", "RAF", "RW2", "PEF", "SRW",
728 };
729 for (const char* rawExt : rawExts) {
730 if (0 == strcmp(rawExt, ext)) {
731 // RAW is not supported by image generator (skbug.com/5079) or BRD.
732 return;
733 }
734 }
735
736 static const char* const brdExts[] = {
737 "jpg", "jpeg", "png", "webp",
738 "JPG", "JPEG", "PNG", "WEBP",
739 };
740 for (const char* brdExt : brdExts) {
741 if (0 == strcmp(brdExt, ext)) {
Leon Scroggins IIIc8037dc2017-12-05 13:55:24 -0500742 bool gray = codec->getInfo().colorType() == kGray_8_SkColorType;
Leon Scroggins III07418182017-08-15 12:24:02 -0400743 push_brd_srcs(path, gray);
744 break;
745 }
msarett18976312016-03-09 14:20:58 -0800746 }
747 }
748
749 // Push image generator GPU test.
brianosmanc9ced392016-03-24 07:27:43 -0700750 push_image_gen_src(path, ImageGenSrc::kCodec_Mode, codec->getInfo().alphaType(), true);
msarett18976312016-03-09 14:20:58 -0800751
752 // Push image generator CPU tests.
753 for (SkAlphaType alphaType : alphaModes) {
754 push_image_gen_src(path, ImageGenSrc::kCodec_Mode, alphaType, false);
755
756#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
Hal Canarydb683012016-11-23 08:55:18 -0700757 if (SkEncodedImageFormat::kWEBP != codec->getEncodedFormat() &&
758 SkEncodedImageFormat::kWBMP != codec->getEncodedFormat() &&
msarett18976312016-03-09 14:20:58 -0800759 kUnpremul_SkAlphaType != alphaType)
760 {
761 push_image_gen_src(path, ImageGenSrc::kPlatform_Mode, alphaType, false);
762 }
msarettfc0b6d12016-03-17 13:50:17 -0700763#elif defined(SK_BUILD_FOR_WIN)
Hal Canarydb683012016-11-23 08:55:18 -0700764 if (SkEncodedImageFormat::kWEBP != codec->getEncodedFormat() &&
765 SkEncodedImageFormat::kWBMP != codec->getEncodedFormat())
msarettfc0b6d12016-03-17 13:50:17 -0700766 {
767 push_image_gen_src(path, ImageGenSrc::kPlatform_Mode, alphaType, false);
768 }
msarett18976312016-03-09 14:20:58 -0800769#endif
770 }
msarett438b2ad2015-04-09 12:43:10 -0700771}
772
fmalitaa2b9fdf2016-08-03 19:53:36 -0700773template <typename T>
774void gather_file_srcs(const SkCommandLineFlags::StringArray& flags, const char* ext) {
775 for (int i = 0; i < flags.count(); i++) {
776 const char* path = flags[i];
777 if (sk_isdir(path)) {
778 SkOSFile::Iter it(path, ext);
779 for (SkString file; it.next(&file); ) {
780 push_src(ext, "", new T(SkOSPath::Join(path, file.c_str())));
781 }
782 } else {
783 push_src(ext, "", new T(path));
784 }
785 }
786}
787
scroggo86737142016-02-03 12:19:11 -0800788static bool gather_srcs() {
mtklein748ca3b2015-01-15 10:56:12 -0800789 for (const skiagm::GMRegistry* r = skiagm::GMRegistry::Head(); r; r = r->next()) {
djsollen54416de2015-04-03 07:24:48 -0700790 push_src("gm", "", new GMSrc(r->factory()));
mtklein748ca3b2015-01-15 10:56:12 -0800791 }
scroggo86737142016-02-03 12:19:11 -0800792
Robert Phillipsad8a43f2017-08-30 12:06:35 -0400793 if (FLAGS_ddl) {
794 gather_file_srcs<DDLSKPSrc>(FLAGS_skps, "skp");
795 } else {
796 gather_file_srcs<SKPSrc>(FLAGS_skps, "skp");
797 }
fmalitaa2b9fdf2016-08-03 19:53:36 -0700798 gather_file_srcs<MSKPSrc>(FLAGS_mskps, "mskp");
Florin Malita124d5af2017-12-31 17:02:26 -0500799#if !defined(SK_BUILD_FOR_GOOGLE3)
Florin Malita54f65c42018-01-16 17:04:30 -0500800 gather_file_srcs<SkottieSrc>(FLAGS_jsons, "json");
Florin Malita124d5af2017-12-31 17:02:26 -0500801#endif
fmalitaa2b9fdf2016-08-03 19:53:36 -0700802#if defined(SK_XML)
803 gather_file_srcs<SVGSrc>(FLAGS_svgs, "svg");
804#endif
halcanary45420a92016-06-02 12:41:14 -0700805
scroggo86737142016-02-03 12:19:11 -0800806 SkTArray<SkString> images;
msarett69deca82016-04-29 09:38:40 -0700807 if (!CollectImages(FLAGS_images, &images)) {
scroggo86737142016-02-03 12:19:11 -0800808 return false;
809 }
810
811 for (auto image : images) {
812 push_codec_srcs(image);
mtklein709d2c32015-01-15 08:30:25 -0800813 }
scroggo86737142016-02-03 12:19:11 -0800814
msarett69deca82016-04-29 09:38:40 -0700815 SkTArray<SkString> colorImages;
816 if (!CollectImages(FLAGS_colorImages, &colorImages)) {
817 return false;
818 }
819
820 for (auto colorImage : colorImages) {
msarett9ce3a542016-07-15 13:54:38 -0700821 ColorCodecSrc* src = new ColorCodecSrc(colorImage, ColorCodecSrc::kBaseline_Mode,
822 kN32_SkColorType);
msarettb8d1aac2016-08-04 12:22:06 -0700823 push_src("colorImage", "color_codec_baseline", src);
msarett888dc162016-05-23 10:21:17 -0700824
msarett9ce3a542016-07-15 13:54:38 -0700825 src = new ColorCodecSrc(colorImage, ColorCodecSrc::kDst_HPZR30w_Mode, kN32_SkColorType);
msarettb8d1aac2016-08-04 12:22:06 -0700826 push_src("colorImage", "color_codec_HPZR30w", src);
msarett9ce3a542016-07-15 13:54:38 -0700827 // TODO (msarett):
828 // 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 -0700829
msarett9ce3a542016-07-15 13:54:38 -0700830 src = new ColorCodecSrc(colorImage, ColorCodecSrc::kDst_sRGB_Mode, kN32_SkColorType);
msarettb8d1aac2016-08-04 12:22:06 -0700831 push_src("colorImage", "color_codec_sRGB_kN32", src);
msarett9ce3a542016-07-15 13:54:38 -0700832 src = new ColorCodecSrc(colorImage, ColorCodecSrc::kDst_sRGB_Mode, kRGBA_F16_SkColorType);
msarettb8d1aac2016-08-04 12:22:06 -0700833 push_src("colorImage", "color_codec_sRGB_kF16", src);
msarett69deca82016-04-29 09:38:40 -0700834 }
835
scroggo86737142016-02-03 12:19:11 -0800836 return true;
mtklein709d2c32015-01-15 08:30:25 -0800837}
838
kkinnunen3e980c32015-12-23 01:33:00 -0800839static void push_sink(const SkCommandLineConfig& config, Sink* s) {
Ben Wagner145dbcd2016-11-03 14:40:50 -0400840 std::unique_ptr<Sink> sink(s);
kkinnunen3e980c32015-12-23 01:33:00 -0800841
mtkleine0effd62015-07-29 06:37:28 -0700842 // Try a simple Src as a canary. If it fails, skip this sink.
mtklein748ca3b2015-01-15 10:56:12 -0800843 struct : public Src {
mtkleine0effd62015-07-29 06:37:28 -0700844 Error draw(SkCanvas* c) const override {
845 c->drawRect(SkRect::MakeWH(1,1), SkPaint());
846 return "";
847 }
mtklein36352bf2015-03-25 18:17:31 -0700848 SkISize size() const override { return SkISize::Make(16, 16); }
mtkleine0effd62015-07-29 06:37:28 -0700849 Name name() const override { return "justOneRect"; }
850 } justOneRect;
mtklein114c3cd2015-01-15 10:15:02 -0800851
mtklein748ca3b2015-01-15 10:56:12 -0800852 SkBitmap bitmap;
853 SkDynamicMemoryWStream stream;
mtkleinb9eb4ac2015-02-02 18:26:03 -0800854 SkString log;
mtkleine0effd62015-07-29 06:37:28 -0700855 Error err = sink->draw(justOneRect, &bitmap, &stream, &log);
mtklein4089ef72015-03-05 08:40:28 -0800856 if (err.isFatal()) {
mtkleinc41fd922016-03-08 09:01:39 -0800857 info("Could not run %s: %s\n", config.getTag().c_str(), err.c_str());
mtklein05641a52015-04-21 10:49:13 -0700858 exit(1);
mtklein114c3cd2015-01-15 10:15:02 -0800859 }
860
mtkleine0effd62015-07-29 06:37:28 -0700861 TaggedSink& ts = gSinks.push_back();
mtklein18300a32016-03-16 13:53:35 -0700862 ts.reset(sink.release());
kkinnunen3e980c32015-12-23 01:33:00 -0800863 ts.tag = config.getTag();
mtklein748ca3b2015-01-15 10:56:12 -0800864}
865
866static bool gpu_supported() {
867#if SK_SUPPORT_GPU
868 return FLAGS_gpu;
869#else
870 return false;
871#endif
872}
kkinnunen9ebc3f02015-12-21 23:48:13 -0800873
csmartdalton008b9d82017-02-22 12:00:42 -0700874static Sink* create_sink(const GrContextOptions& grCtxOptions, const SkCommandLineConfig* config) {
kkinnunen3e980c32015-12-23 01:33:00 -0800875#if SK_SUPPORT_GPU
876 if (gpu_supported()) {
877 if (const SkCommandLineConfigGpu* gpuConfig = config->asConfigGpu()) {
bsalomon85b4b532016-04-05 11:06:27 -0700878 GrContextFactory::ContextType contextType = gpuConfig->getContextType();
csmartdaltone812d492017-02-21 12:36:05 -0700879 GrContextFactory::ContextOverrides contextOverrides = gpuConfig->getContextOverrides();
csmartdalton008b9d82017-02-22 12:00:42 -0700880 GrContextFactory testFactory(grCtxOptions);
csmartdaltone812d492017-02-21 12:36:05 -0700881 if (!testFactory.get(contextType, contextOverrides)) {
mtkleinc41fd922016-03-08 09:01:39 -0800882 info("WARNING: can not create GPU context for config '%s'. "
883 "GM tests will be skipped.\n", gpuConfig->getTag().c_str());
kkinnunen3e980c32015-12-23 01:33:00 -0800884 return nullptr;
885 }
Brian Osmanf9810662017-08-30 10:02:10 -0400886 if (gpuConfig->getTestThreading()) {
887 return new GPUThreadTestingSink(contextType, contextOverrides,
888 gpuConfig->getSamples(), gpuConfig->getUseDIText(),
889 gpuConfig->getColorType(),
890 gpuConfig->getAlphaType(),
891 sk_ref_sp(gpuConfig->getColorSpace()),
892 FLAGS_gpu_threading, grCtxOptions);
893 } else {
894 return new GPUSink(contextType, contextOverrides, gpuConfig->getSamples(),
895 gpuConfig->getUseDIText(), gpuConfig->getColorType(),
896 gpuConfig->getAlphaType(), sk_ref_sp(gpuConfig->getColorSpace()),
897 FLAGS_gpu_threading, grCtxOptions);
898 }
kkinnunen3e980c32015-12-23 01:33:00 -0800899 }
900 }
901#endif
902
903#define SINK(t, sink, ...) if (config->getBackend().equals(t)) { return new sink(__VA_ARGS__); }
904
mtklein748ca3b2015-01-15 10:56:12 -0800905 if (FLAGS_cpu) {
Matt Sarett77a7a1b2017-02-07 13:56:11 -0500906 auto srgbColorSpace = SkColorSpace::MakeSRGB();
907 auto srgbLinearColorSpace = SkColorSpace::MakeSRGBLinear();
brianosmanb109b8c2016-06-16 13:03:24 -0700908
Mike Klein515bda62018-01-09 11:21:58 -0500909 SINK("g8", RasterSink, kGray_8_SkColorType);
Matt Sarettd2228302017-03-02 08:53:46 -0500910 SINK("565", RasterSink, kRGB_565_SkColorType);
Mike Klein5340b3f2018-01-24 13:42:05 -0500911 SINK("4444", RasterSink, kARGB_4444_SkColorType);
Matt Sarettd2228302017-03-02 08:53:46 -0500912 SINK("8888", RasterSink, kN32_SkColorType);
913 SINK("srgb", RasterSink, kN32_SkColorType, srgbColorSpace);
Mike Kleinac568a92018-01-25 09:09:32 -0500914 SINK("rgba", RasterSink, kRGBA_8888_SkColorType);
915 SINK("bgra", RasterSink, kBGRA_8888_SkColorType);
916 SINK("rgbx", RasterSink, kRGB_888x_SkColorType);
917 SINK("1010102", RasterSink, kRGBA_1010102_SkColorType);
918 SINK("101010x", RasterSink, kRGB_101010x_SkColorType);
Matt Sarettd2228302017-03-02 08:53:46 -0500919 SINK("f16", RasterSink, kRGBA_F16_SkColorType, srgbLinearColorSpace);
Yuqian Lib8b62532018-02-23 14:13:36 +0800920 SINK("t8888", ThreadedSink, kN32_SkColorType);
Hal Canaryc7d295e2017-07-20 15:36:00 -0400921 SINK("pdf", PDFSink, false, SK_ScalarDefaultRasterDPI);
Matt Sarettd2228302017-03-02 08:53:46 -0500922 SINK("skp", SKPSink);
923 SINK("pipe", PipeSink);
924 SINK("svg", SVGSink);
925 SINK("null", NullSink);
926 SINK("xps", XPSSink);
Hal Canaryc7d295e2017-07-20 15:36:00 -0400927 SINK("pdfa", PDFSink, true, SK_ScalarDefaultRasterDPI);
928 SINK("pdf300", PDFSink, false, 300);
Hal Canary85c7fe82016-10-25 10:33:27 -0400929 SINK("jsdebug", DebugSink);
mtklein748ca3b2015-01-15 10:56:12 -0800930 }
931#undef SINK
halcanary96fcdcc2015-08-27 07:41:13 -0700932 return nullptr;
mtklein114c3cd2015-01-15 10:15:02 -0800933}
934
Mike Klein841101d2017-03-10 09:55:51 -0500935static sk_sp<SkColorSpace> adobe_rgb() {
936 return SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
937 SkColorSpace::kAdobeRGB_Gamut);
938}
939
Mike Kleinb7ea3da2017-10-31 17:42:08 +0000940static sk_sp<SkColorSpace> rgb_to_gbr() {
Brian Osman36703d92017-12-12 14:09:31 -0500941 return SkColorSpace::MakeSRGB()->makeColorSpin();
Mike Klein919cc452017-03-18 15:36:52 +0000942}
943
kkinnunen3e980c32015-12-23 01:33:00 -0800944static Sink* create_via(const SkString& tag, Sink* wrapped) {
945#define VIA(t, via, ...) if (tag.equals(t)) { return new via(__VA_ARGS__); }
Mike Klein919cc452017-03-18 15:36:52 +0000946 VIA("adobe", ViaCSXform, wrapped, adobe_rgb(), false);
Mike Kleinb7ea3da2017-10-31 17:42:08 +0000947 VIA("gbr", ViaCSXform, wrapped, rgb_to_gbr(), true);
mtklein9c5052f2016-08-06 12:51:51 -0700948 VIA("lite", ViaLite, wrapped);
reed54dc4872016-09-13 08:09:45 -0700949 VIA("pipe", ViaPipe, wrapped);
Mike Reedbae888e2017-02-18 16:50:45 -0500950#ifdef TEST_VIA_SVG
Mike Reedf67c4592017-02-17 17:06:11 -0500951 VIA("svg", ViaSVG, wrapped);
Mike Reedbae888e2017-02-18 16:50:45 -0500952#endif
halcanary96fcdcc2015-08-27 07:41:13 -0700953 VIA("serialize", ViaSerialization, wrapped);
mtklein4a34ecb2016-01-08 10:19:35 -0800954 VIA("pic", ViaPicture, wrapped);
halcanary96fcdcc2015-08-27 07:41:13 -0700955 VIA("tiles", ViaTiles, 256, 256, nullptr, wrapped);
mtklein7edca212015-01-21 13:18:51 -0800956 VIA("tiles_rt", ViaTiles, 256, 256, new SkRTreeFactory, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800957
mtkleind603b222015-02-17 11:13:33 -0800958 if (FLAGS_matrix.count() == 4) {
mtklein748ca3b2015-01-15 10:56:12 -0800959 SkMatrix m;
mtkleind603b222015-02-17 11:13:33 -0800960 m.reset();
961 m.setScaleX((SkScalar)atof(FLAGS_matrix[0]));
962 m.setSkewX ((SkScalar)atof(FLAGS_matrix[1]));
963 m.setSkewY ((SkScalar)atof(FLAGS_matrix[2]));
964 m.setScaleY((SkScalar)atof(FLAGS_matrix[3]));
965 VIA("matrix", ViaMatrix, m, wrapped);
966 VIA("upright", ViaUpright, m, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800967 }
tomhudson64de1e12015-03-05 08:01:07 -0800968
mtklein748ca3b2015-01-15 10:56:12 -0800969#undef VIA
halcanary96fcdcc2015-08-27 07:41:13 -0700970 return nullptr;
mtklein114c3cd2015-01-15 10:15:02 -0800971}
972
Ben Wagnerf28d4722017-08-11 17:33:22 -0400973static bool gather_sinks(const GrContextOptions& grCtxOptions, bool defaultConfigs) {
kkinnunen3e980c32015-12-23 01:33:00 -0800974 SkCommandLineConfigArray configs;
975 ParseConfigs(FLAGS_config, &configs);
976 for (int i = 0; i < configs.count(); i++) {
977 const SkCommandLineConfig& config = *configs[i];
csmartdalton008b9d82017-02-22 12:00:42 -0700978 Sink* sink = create_sink(grCtxOptions, &config);
kkinnunen3e980c32015-12-23 01:33:00 -0800979 if (sink == nullptr) {
mtkleinc41fd922016-03-08 09:01:39 -0800980 info("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(),
981 config.getTag().c_str());
kkinnunen3e980c32015-12-23 01:33:00 -0800982 continue;
983 }
mtklein748ca3b2015-01-15 10:56:12 -0800984
kkinnunen3e980c32015-12-23 01:33:00 -0800985 const SkTArray<SkString>& parts = config.getViaParts();
986 for (int j = parts.count(); j-- > 0;) {
987 const SkString& part = parts[j];
988 Sink* next = create_via(part, sink);
halcanary96fcdcc2015-08-27 07:41:13 -0700989 if (next == nullptr) {
mtkleinc41fd922016-03-08 09:01:39 -0800990 info("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(),
991 part.c_str());
mtklein748ca3b2015-01-15 10:56:12 -0800992 delete sink;
halcanary96fcdcc2015-08-27 07:41:13 -0700993 sink = nullptr;
mtklein748ca3b2015-01-15 10:56:12 -0800994 break;
995 }
996 sink = next;
997 }
998 if (sink) {
999 push_sink(config, sink);
mtklein114c3cd2015-01-15 10:15:02 -08001000 }
1001 }
brianosman05c987c2016-05-09 13:42:16 -07001002
1003 // If no configs were requested (just running tests, perhaps?), then we're okay.
Ben Wagnerf28d4722017-08-11 17:33:22 -04001004 if (configs.count() == 0 ||
1005 // If we're using the default configs, we're okay.
1006 defaultConfigs ||
Ben Wagner32fa5102017-08-10 21:25:55 -04001007 // If we've been told to ignore undefined flags, we're okay.
1008 FLAGS_undefok ||
1009 // Otherwise, make sure that all specified configs have become sinks.
1010 configs.count() == gSinks.count()) {
1011 return true;
1012 }
1013 info("Invalid --config. Use --undefok to bypass this warning.\n");
1014 return false;
mtklein114c3cd2015-01-15 10:15:02 -08001015}
mtklein709d2c32015-01-15 08:30:25 -08001016
mtkleina5114d72015-08-24 13:27:01 -07001017static bool dump_png(SkBitmap bitmap, const char* path, const char* md5) {
Mike Klein13b6afd2017-06-12 12:45:41 -04001018 SkPixmap pm;
1019 if (!bitmap.peekPixels(&pm)) {
1020 return false; // Ought to never happen... we're already read-back at this point.
mtkleina5114d72015-08-24 13:27:01 -07001021 }
Mike Klein13b6afd2017-06-12 12:45:41 -04001022 SkFILEWStream dst{path};
mtkleina5114d72015-08-24 13:27:01 -07001023
mtkleind69ece62015-09-10 10:37:44 -07001024 SkString description;
1025 description.append("Key: ");
1026 for (int i = 0; i < FLAGS_key.count(); i++) {
1027 description.appendf("%s ", FLAGS_key[i]);
1028 }
1029 description.append("Properties: ");
1030 for (int i = 0; i < FLAGS_properties.count(); i++) {
1031 description.appendf("%s ", FLAGS_properties[i]);
1032 }
1033 description.appendf("MD5: %s", md5);
1034
Mike Klein13b6afd2017-06-12 12:45:41 -04001035 const char* comments[] = {
1036 "Author", "DM dump_png()",
1037 "Description", description.c_str(),
1038 };
1039 size_t lengths[] = {
1040 strlen(comments[0])+1, strlen(comments[1])+1,
1041 strlen(comments[2])+1, strlen(comments[3])+1,
1042 };
mtkleina5114d72015-08-24 13:27:01 -07001043
Mike Klein13b6afd2017-06-12 12:45:41 -04001044 SkPngEncoder::Options options;
1045 options.fComments = SkDataTable::MakeCopyArrays((const void**)comments, lengths, 4);
1046 options.fFilterFlags = SkPngEncoder::FilterFlag::kNone;
1047 options.fZLibLevel = 1;
1048 options.fUnpremulBehavior = pm.colorSpace() ? SkTransferFunctionBehavior::kRespect
1049 : SkTransferFunctionBehavior::kIgnore;
1050 return SkPngEncoder::Encode(&dst, pm, options);
mtkleina5114d72015-08-24 13:27:01 -07001051}
1052
mtkleina2ef6422015-01-15 13:44:22 -08001053static bool match(const char* needle, const char* haystack) {
Chris Daltonecf78ac2017-08-15 15:43:08 -06001054 if ('~' == needle[0]) {
1055 return !match(needle + 1, haystack);
1056 }
1057 if (0 == strcmp("_", needle)) {
1058 return true;
1059 }
1060 return nullptr != strstr(haystack, needle);
mtkleina2ef6422015-01-15 13:44:22 -08001061}
1062
mtklein3eed7dd2016-02-24 19:07:07 -08001063static bool is_blacklisted(const char* sink, const char* src,
1064 const char* srcOptions, const char* name) {
mtklein0d243ff2015-04-03 07:51:00 -07001065 for (int i = 0; i < FLAGS_blacklist.count() - 3; i += 4) {
mtkleina2ef6422015-01-15 13:44:22 -08001066 if (match(FLAGS_blacklist[i+0], sink) &&
djsollen54416de2015-04-03 07:24:48 -07001067 match(FLAGS_blacklist[i+1], src) &&
1068 match(FLAGS_blacklist[i+2], srcOptions) &&
1069 match(FLAGS_blacklist[i+3], name)) {
mtklein3eed7dd2016-02-24 19:07:07 -08001070 return true;
mtkleina2ef6422015-01-15 13:44:22 -08001071 }
1072 }
mtklein3eed7dd2016-02-24 19:07:07 -08001073 return false;
mtkleina2ef6422015-01-15 13:44:22 -08001074}
1075
mtkleincd50bca2016-01-05 06:20:20 -08001076// Even when a Task Sink reports to be non-threadsafe (e.g. GPU), we know things like
1077// .png encoding are definitely thread safe. This lets us offload that work to CPU threads.
1078static SkTaskGroup gDefinitelyThreadSafeWork;
1079
mtklein748ca3b2015-01-15 10:56:12 -08001080// The finest-grained unit of work we can run: draw a single Src into a single Sink,
1081// report any errors, and perhaps write out the output: a .png of the bitmap, or a raw stream.
1082struct Task {
mtkleine0effd62015-07-29 06:37:28 -07001083 Task(const TaggedSrc& src, const TaggedSink& sink) : src(src), sink(sink) {}
1084 const TaggedSrc& src;
1085 const TaggedSink& sink;
mtklein748ca3b2015-01-15 10:56:12 -08001086
mtklein21eaf3b2016-02-08 12:39:59 -08001087 static void Run(const Task& task) {
1088 SkString name = task.src->name();
mtkleine0effd62015-07-29 06:37:28 -07001089
mtkleinb9eb4ac2015-02-02 18:26:03 -08001090 SkString log;
mtklein3eed7dd2016-02-24 19:07:07 -08001091 if (!FLAGS_dryRun) {
mtklein748ca3b2015-01-15 10:56:12 -08001092 SkBitmap bitmap;
1093 SkDynamicMemoryWStream stream;
mtklein3eed7dd2016-02-24 19:07:07 -08001094 start(task.sink.tag.c_str(), task.src.tag.c_str(),
1095 task.src.options.c_str(), name.c_str());
mtklein21eaf3b2016-02-08 12:39:59 -08001096 Error err = task.sink->draw(*task.src, &bitmap, &stream, &log);
mtkleinb3b13b72016-03-07 13:20:52 -08001097 if (!log.isEmpty()) {
mtkleinc41fd922016-03-08 09:01:39 -08001098 info("%s %s %s %s:\n%s\n", task.sink.tag.c_str()
1099 , task.src.tag.c_str()
1100 , task.src.options.c_str()
1101 , name.c_str()
1102 , log.c_str());
mtkleinb3b13b72016-03-07 13:20:52 -08001103 }
mtklein748ca3b2015-01-15 10:56:12 -08001104 if (!err.isEmpty()) {
mtklein4089ef72015-03-05 08:40:28 -08001105 if (err.isFatal()) {
djsollen54416de2015-04-03 07:24:48 -07001106 fail(SkStringPrintf("%s %s %s %s: %s",
mtklein21eaf3b2016-02-08 12:39:59 -08001107 task.sink.tag.c_str(),
1108 task.src.tag.c_str(),
1109 task.src.options.c_str(),
mtklein4089ef72015-03-05 08:40:28 -08001110 name.c_str(),
1111 err.c_str()));
mtkleinb37cb412015-03-18 05:27:14 -07001112 } else {
mtklein3eed7dd2016-02-24 19:07:07 -08001113 done(task.sink.tag.c_str(), task.src.tag.c_str(),
1114 task.src.options.c_str(), name.c_str());
mtkleinba6ada72016-01-21 09:39:35 -08001115 return;
mtklein4089ef72015-03-05 08:40:28 -08001116 }
mtklein748ca3b2015-01-15 10:56:12 -08001117 }
mtklein62bd1a62015-01-27 14:46:26 -08001118
mtkleincd50bca2016-01-05 06:20:20 -08001119 // We're likely switching threads here, so we must capture by value, [=] or [foo,bar].
Hal Canary0b833192017-03-14 14:35:02 -04001120 SkStreamAsset* data = stream.detachAsStream().release();
mtkleincd50bca2016-01-05 06:20:20 -08001121 gDefinitelyThreadSafeWork.add([task,name,bitmap,data]{
Ben Wagner145dbcd2016-11-03 14:40:50 -04001122 std::unique_ptr<SkStreamAsset> ownedData(data);
mtkleincd50bca2016-01-05 06:20:20 -08001123
mtkleincd50bca2016-01-05 06:20:20 -08001124 SkString md5;
1125 if (!FLAGS_writePath.isEmpty() || !FLAGS_readPath.isEmpty()) {
1126 SkMD5 hash;
1127 if (data->getLength()) {
1128 hash.writeStream(data, data->getLength());
1129 data->rewind();
mtklein38408462015-07-08 07:25:27 -07001130 } else {
mtkleincd50bca2016-01-05 06:20:20 -08001131 // If we're BGRA (Linux, Windows), swizzle over to RGBA (Mac, Android).
1132 // This helps eliminate multiple 0-pixel-diff hashes on gold.skia.org.
1133 // (Android's general slow speed breaks the tie arbitrarily in RGBA's favor.)
1134 // We might consider promoting 565 to RGBA too.
1135 if (bitmap.colorType() == kBGRA_8888_SkColorType) {
1136 SkBitmap swizzle;
Matt Sarett68b8e3d2017-04-28 11:15:22 -04001137 SkAssertResult(sk_tool_utils::copy_to(&swizzle, kRGBA_8888_SkColorType,
1138 bitmap));
Mike Reedf0ffb892017-10-03 14:47:21 -04001139 hash.write(swizzle.getPixels(), swizzle.computeByteSize());
mtkleincd50bca2016-01-05 06:20:20 -08001140 } else {
Mike Reedf0ffb892017-10-03 14:47:21 -04001141 hash.write(bitmap.getPixels(), bitmap.computeByteSize());
mtkleincd50bca2016-01-05 06:20:20 -08001142 }
1143 }
1144 SkMD5::Digest digest;
1145 hash.finish(digest);
1146 for (int i = 0; i < 16; i++) {
1147 md5.appendf("%02x", digest.data[i]);
mtklein38408462015-07-08 07:25:27 -07001148 }
mtklein62bd1a62015-01-27 14:46:26 -08001149 }
mtklein62bd1a62015-01-27 14:46:26 -08001150
mtkleincd50bca2016-01-05 06:20:20 -08001151 if (!FLAGS_readPath.isEmpty() &&
mtklein3eed7dd2016-02-24 19:07:07 -08001152 !gGold.contains(Gold(task.sink.tag, task.src.tag,
1153 task.src.options, name, md5))) {
mtkleincd50bca2016-01-05 06:20:20 -08001154 fail(SkStringPrintf("%s not found for %s %s %s %s in %s",
1155 md5.c_str(),
mtklein21eaf3b2016-02-08 12:39:59 -08001156 task.sink.tag.c_str(),
1157 task.src.tag.c_str(),
1158 task.src.options.c_str(),
mtkleincd50bca2016-01-05 06:20:20 -08001159 name.c_str(),
1160 FLAGS_readPath[0]));
mtklein748ca3b2015-01-15 10:56:12 -08001161 }
mtkleincd50bca2016-01-05 06:20:20 -08001162
1163 if (!FLAGS_writePath.isEmpty()) {
mtklein21eaf3b2016-02-08 12:39:59 -08001164 const char* ext = task.sink->fileExtension();
Brian Osmanf1942de2017-08-30 14:50:22 -04001165 if (ext && !FLAGS_dont_write.contains(ext)) {
Mike Klein97d6a7a2017-07-24 10:37:19 -04001166 if (data->getLength()) {
1167 WriteToDisk(task, md5, ext, data, data->getLength(), nullptr);
1168 SkASSERT(bitmap.drawsNothing());
1169 } else if (!bitmap.drawsNothing()) {
1170 WriteToDisk(task, md5, ext, nullptr, 0, &bitmap);
1171 }
mtkleincd50bca2016-01-05 06:20:20 -08001172 }
1173 }
1174 });
mtklein748ca3b2015-01-15 10:56:12 -08001175 }
mtklein3eed7dd2016-02-24 19:07:07 -08001176 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 -08001177 }
1178
1179 static void WriteToDisk(const Task& task,
mtklein62bd1a62015-01-27 14:46:26 -08001180 SkString md5,
1181 const char* ext,
mtklein748ca3b2015-01-15 10:56:12 -08001182 SkStream* data, size_t len,
mtklein62bd1a62015-01-27 14:46:26 -08001183 const SkBitmap* bitmap) {
mtklein409d4702016-02-29 07:38:01 -08001184 bool gammaCorrect = false;
1185 if (bitmap) {
Brian Osman7039f742016-11-01 15:56:16 -04001186 gammaCorrect = SkToBool(bitmap->info().colorSpace());
mtklein409d4702016-02-29 07:38:01 -08001187 }
1188
mtklein748ca3b2015-01-15 10:56:12 -08001189 JsonWriter::BitmapResult result;
djsollen54416de2015-04-03 07:24:48 -07001190 result.name = task.src->name();
mtklein3eed7dd2016-02-24 19:07:07 -08001191 result.config = task.sink.tag;
djsollen54416de2015-04-03 07:24:48 -07001192 result.sourceType = task.src.tag;
1193 result.sourceOptions = task.src.options;
1194 result.ext = ext;
mtklein409d4702016-02-29 07:38:01 -08001195 result.gammaCorrect = gammaCorrect;
djsollen54416de2015-04-03 07:24:48 -07001196 result.md5 = md5;
mtklein748ca3b2015-01-15 10:56:12 -08001197 JsonWriter::AddBitmapResult(result);
1198
mtkleinb0531a72015-04-07 13:38:48 -07001199 // If an MD5 is uninteresting, we want it noted in the JSON file,
1200 // but don't want to dump it out as a .png (or whatever ext is).
1201 if (gUninterestingHashes.contains(md5)) {
1202 return;
1203 }
1204
mtklein748ca3b2015-01-15 10:56:12 -08001205 const char* dir = FLAGS_writePath[0];
1206 if (0 == strcmp(dir, "@")) { // Needed for iOS.
1207 dir = FLAGS_resourcePath[0];
1208 }
1209 sk_mkdir(dir);
1210
1211 SkString path;
1212 if (FLAGS_nameByHash) {
1213 path = SkOSPath::Join(dir, result.md5.c_str());
1214 path.append(".");
1215 path.append(ext);
1216 if (sk_exists(path.c_str())) {
1217 return; // Content-addressed. If it exists already, we're done.
1218 }
1219 } else {
kkinnunen3e980c32015-12-23 01:33:00 -08001220 path = SkOSPath::Join(dir, task.sink.tag.c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001221 sk_mkdir(path.c_str());
msarett9e707a02015-09-01 14:57:57 -07001222 path = SkOSPath::Join(path.c_str(), task.src.tag.c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001223 sk_mkdir(path.c_str());
msarett9e707a02015-09-01 14:57:57 -07001224 if (strcmp(task.src.options.c_str(), "") != 0) {
1225 path = SkOSPath::Join(path.c_str(), task.src.options.c_str());
djsollen54416de2015-04-03 07:24:48 -07001226 sk_mkdir(path.c_str());
1227 }
mtklein748ca3b2015-01-15 10:56:12 -08001228 path = SkOSPath::Join(path.c_str(), task.src->name().c_str());
1229 path.append(".");
1230 path.append(ext);
1231 }
1232
mtklein748ca3b2015-01-15 10:56:12 -08001233 if (bitmap) {
mtkleina5114d72015-08-24 13:27:01 -07001234 if (!dump_png(*bitmap, path.c_str(), result.md5.c_str())) {
mtklein748ca3b2015-01-15 10:56:12 -08001235 fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str()));
1236 return;
1237 }
1238 } else {
mtkleina5114d72015-08-24 13:27:01 -07001239 SkFILEWStream file(path.c_str());
1240 if (!file.isValid()) {
1241 fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str()));
1242 return;
1243 }
mtklein748ca3b2015-01-15 10:56:12 -08001244 if (!file.writeStream(data, len)) {
1245 fail(SkStringPrintf("Can't write to %s.\n", path.c_str()));
1246 return;
1247 }
1248 }
1249 }
1250};
1251
mtklein748ca3b2015-01-15 10:56:12 -08001252/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1253
1254// Unit tests don't fit so well into the Src/Sink model, so we give them special treatment.
1255
mtklein21eaf3b2016-02-08 12:39:59 -08001256static SkTDArray<skiatest::Test> gParallelTests, gSerialTests;
mtklein748ca3b2015-01-15 10:56:12 -08001257
1258static void gather_tests() {
mtklein6c5fed22015-01-20 13:47:23 -08001259 if (!FLAGS_src.contains("tests")) {
mtklein748ca3b2015-01-15 10:56:12 -08001260 return;
1261 }
mtklein6393c062015-04-27 08:45:01 -07001262 for (const skiatest::TestRegistry* r = skiatest::TestRegistry::Head(); r; r = r->next()) {
1263 if (!in_shard()) {
1264 continue;
1265 }
halcanary87f3ba42015-01-20 09:30:20 -08001266 // Despite its name, factory() is returning a reference to
1267 // link-time static const POD data.
1268 const skiatest::Test& test = r->factory();
1269 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, test.name)) {
mtklein748ca3b2015-01-15 10:56:12 -08001270 continue;
1271 }
halcanary87f3ba42015-01-20 09:30:20 -08001272 if (test.needsGpu && gpu_supported()) {
mtklein21eaf3b2016-02-08 12:39:59 -08001273 (FLAGS_gpu_threading ? gParallelTests : gSerialTests).push(test);
halcanary87f3ba42015-01-20 09:30:20 -08001274 } else if (!test.needsGpu && FLAGS_cpu) {
mtklein21eaf3b2016-02-08 12:39:59 -08001275 gParallelTests.push(test);
mtklein82d28432015-01-15 12:46:02 -08001276 }
mtklein748ca3b2015-01-15 10:56:12 -08001277 }
1278}
1279
csmartdalton008b9d82017-02-22 12:00:42 -07001280static void run_test(skiatest::Test test, const GrContextOptions& grCtxOptions) {
halcanary87f3ba42015-01-20 09:30:20 -08001281 struct : public skiatest::Reporter {
mtklein36352bf2015-03-25 18:17:31 -07001282 void reportFailed(const skiatest::Failure& failure) override {
halcanary87f3ba42015-01-20 09:30:20 -08001283 fail(failure.toString());
1284 JsonWriter::AddTestFailure(failure);
1285 }
mtklein36352bf2015-03-25 18:17:31 -07001286 bool allowExtendedTest() const override {
halcanary87f3ba42015-01-20 09:30:20 -08001287 return FLAGS_pathOpsExtended;
1288 }
mtklein36352bf2015-03-25 18:17:31 -07001289 bool verbose() const override { return FLAGS_veryVerbose; }
halcanary87f3ba42015-01-20 09:30:20 -08001290 } reporter;
djsollen824996a2015-06-12 12:06:22 -07001291
mtklein3eed7dd2016-02-24 19:07:07 -08001292 if (!FLAGS_dryRun && !is_blacklisted("_", "tests", "_", test.name)) {
Robert Phillipsec325342017-10-30 18:02:48 +00001293 GrContextOptions options = grCtxOptions;
1294 test.modifyGrContextOptions(&options);
1295
mtklein21eaf3b2016-02-08 12:39:59 -08001296 start("unit", "test", "", test.name);
Brian Salomondcfca432017-11-15 15:48:03 -05001297 test.run(&reporter, options);
mtklein748ca3b2015-01-15 10:56:12 -08001298 }
mtklein3eed7dd2016-02-24 19:07:07 -08001299 done("unit", "test", "", test.name);
mtklein748ca3b2015-01-15 10:56:12 -08001300}
1301
1302/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1303
caryclark83ca6282015-06-10 09:31:09 -07001304#define PORTABLE_FONT_PREFIX "Toy Liberation "
1305
mbocee6a9912016-05-31 11:42:36 -07001306static sk_sp<SkTypeface> create_from_name(const char familyName[], SkFontStyle style) {
caryclark83ca6282015-06-10 09:31:09 -07001307 if (familyName && strlen(familyName) > sizeof(PORTABLE_FONT_PREFIX)
1308 && !strncmp(familyName, PORTABLE_FONT_PREFIX, sizeof(PORTABLE_FONT_PREFIX) - 1)) {
caryclark1818acb2015-07-24 12:09:25 -07001309 return sk_tool_utils::create_portable_typeface(familyName, style);
caryclark83ca6282015-06-10 09:31:09 -07001310 }
halcanary96fcdcc2015-08-27 07:41:13 -07001311 return nullptr;
caryclark83ca6282015-06-10 09:31:09 -07001312}
1313
1314#undef PORTABLE_FONT_PREFIX
1315
mbocee6a9912016-05-31 11:42:36 -07001316extern sk_sp<SkTypeface> (*gCreateTypefaceDelegate)(const char [], SkFontStyle );
caryclark83ca6282015-06-10 09:31:09 -07001317
Mike Kleinbe28ee22017-02-06 12:46:20 -05001318int main(int argc, char** argv) {
Dongwon Kang0c7861f2018-02-16 10:55:21 -08001319#if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && defined(SK_HAS_HEIF_LIBRARY)
1320 android::ProcessState::self()->startThreadPool();
1321#endif
Mike Kleinbe28ee22017-02-06 12:46:20 -05001322 SkCommandLineFlags::Parse(argc, argv);
Brian Osman53136aa2017-07-20 15:43:35 -04001323
Mike Klein31868212017-11-06 12:02:47 -05001324 if (!FLAGS_nativeFonts) {
Ben Wagner483c7722018-02-20 17:06:07 -05001325 gSkFontMgr_DefaultFactory = &sk_tool_utils::MakePortableFontMgr;
Mike Klein31868212017-11-06 12:02:47 -05001326 }
1327
Mike Klein0c5fdcb2017-11-13 12:40:46 -05001328#if defined(SK_BUILD_FOR_WIN)
1329 if (FLAGS_gdi) {
Hal Canaryccafca02017-11-14 10:34:48 -05001330 gSkFontMgr_DefaultFactory = &SkFontMgr_New_GDI;
Mike Klein0c5fdcb2017-11-13 12:40:46 -05001331 }
1332#endif
1333
Brian Osmanbc8150f2017-07-24 11:38:01 -04001334 initializeEventTracingForTools();
Brian Osman53136aa2017-07-20 15:43:35 -04001335
Mike Klein6613cc52017-12-19 09:09:33 -05001336#if !defined(SK_BUILD_FOR_GOOGLE3) && defined(SK_BUILD_FOR_IOS)
Mike Kleinadacaef2017-02-06 09:26:14 -05001337 cd_Documents();
1338#endif
bsalomon71de3532016-04-26 14:27:21 -07001339 setbuf(stdout, nullptr);
mtklein246ba3a2016-02-23 10:39:36 -08001340 setup_crash_handler();
mtkleinafae30a2016-02-24 12:28:32 -08001341
Yuqian Liba62b4a2016-12-14 13:46:53 -05001342 gSkUseAnalyticAA = FLAGS_analyticAA;
Yuqian Lidf60e362017-07-25 11:26:31 -04001343 gSkUseDeltaAA = FLAGS_deltaAA;
liyuqian38911a72016-10-04 11:23:22 -07001344
Yuqian Li550148b2017-01-13 10:13:13 -05001345 if (FLAGS_forceAnalyticAA) {
1346 gSkForceAnalyticAA = true;
1347 }
Yuqian Lia81b6262017-09-06 17:10:05 -04001348 if (FLAGS_forceDeltaAA) {
1349 gSkForceDeltaAA = true;
1350 }
Mike Reed7c26ca72017-07-05 15:45:52 -04001351 if (FLAGS_forceRasterPipeline) {
1352 gSkForceRasterPipelineBlitter = true;
1353 }
Yuqian Li550148b2017-01-13 10:13:13 -05001354
Mike Kleine9f187b2017-06-26 13:23:12 -04001355 // The bots like having a verbose.log to upload, so always touch the file even if --verbose.
1356 if (!FLAGS_writePath.isEmpty()) {
mtklein51c8cfc2016-03-11 12:59:09 -08001357 sk_mkdir(FLAGS_writePath[0]);
mtkleina1ce2162016-07-22 12:23:46 -07001358 gVLog = fopen(SkOSPath::Join(FLAGS_writePath[0], "verbose.log").c_str(), "w");
mtkleinc41fd922016-03-08 09:01:39 -08001359 }
Mike Kleine9f187b2017-06-26 13:23:12 -04001360 if (FLAGS_verbose) {
1361 gVLog = stderr;
1362 }
mtkleinc41fd922016-03-08 09:01:39 -08001363
csmartdalton008b9d82017-02-22 12:00:42 -07001364 GrContextOptions grCtxOptions;
1365#if SK_SUPPORT_GPU
Chris Dalton040238b2017-12-18 14:22:34 -07001366 SetCtxOptionsFromCommonFlags(&grCtxOptions);
csmartdalton008b9d82017-02-22 12:00:42 -07001367#endif
1368
mtklein5286f022016-01-22 08:18:14 -08001369 JsonWriter::DumpJson(); // It's handy for the bots to assume this is ~never missing.
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +00001370 SkAutoGraphics ag;
mtklein406654b2014-09-03 15:34:37 -07001371 SkTaskGroup::Enabler enabled(FLAGS_threads);
caryclark83ca6282015-06-10 09:31:09 -07001372 gCreateTypefaceDelegate = &create_from_name;
commit-bot@chromium.orga65e2fd2014-05-30 17:23:31 +00001373
Mike Reed0933bc92017-12-09 01:27:41 +00001374 if (nullptr == GetResourceAsData("images/color_wheel.png")) {
1375 info("Some resources are missing. Do you need to set --resourcePath?\n");
halcanary7d571242016-02-24 17:59:16 -08001376 }
mtklein62bd1a62015-01-27 14:46:26 -08001377 gather_gold();
borenet09ed4802015-04-03 14:15:33 -07001378 gather_uninteresting_hashes();
mtklein62bd1a62015-01-27 14:46:26 -08001379
scroggo86737142016-02-03 12:19:11 -08001380 if (!gather_srcs()) {
1381 return 1;
1382 }
Ben Wagnerf28d4722017-08-11 17:33:22 -04001383 // TODO(dogben): This is a bit ugly. Find a cleaner way to do this.
1384 bool defaultConfigs = true;
1385 for (int i = 0; i < argc; i++) {
1386 static const char* kConfigArg = "--config";
1387 if (strcmp(argv[i], kConfigArg) == 0) {
1388 defaultConfigs = false;
1389 break;
1390 }
1391 }
1392 if (!gather_sinks(grCtxOptions, defaultConfigs)) {
brianosman05c987c2016-05-09 13:42:16 -07001393 return 1;
1394 }
mtklein748ca3b2015-01-15 10:56:12 -08001395 gather_tests();
mtklein21eaf3b2016-02-08 12:39:59 -08001396 gPending = gSrcs.count() * gSinks.count() + gParallelTests.count() + gSerialTests.count();
Brian Osmand0677bc2017-08-03 12:13:47 -04001397 info("%d srcs * %d sinks + %d tests == %d tasks\n",
mtkleinc41fd922016-03-08 09:01:39 -08001398 gSrcs.count(), gSinks.count(), gParallelTests.count() + gSerialTests.count(), gPending);
mtklein748ca3b2015-01-15 10:56:12 -08001399
mtklein21eaf3b2016-02-08 12:39:59 -08001400 // Kick off as much parallel work as we can, making note of any serial work we'll need to do.
1401 SkTaskGroup parallel;
1402 SkTArray<Task> serial;
1403
1404 for (auto& sink : gSinks)
1405 for (auto& src : gSrcs) {
mtklein3eed7dd2016-02-24 19:07:07 -08001406 if (src->veto(sink->flags()) ||
1407 is_blacklisted(sink.tag.c_str(), src.tag.c_str(),
1408 src.options.c_str(), src->name().c_str())) {
mtkleinf10637f2016-06-10 13:56:35 -07001409 SkAutoMutexAcquire lock(gMutex);
mtklein3eed7dd2016-02-24 19:07:07 -08001410 gPending--;
1411 continue;
1412 }
1413
mtklein21eaf3b2016-02-08 12:39:59 -08001414 Task task(src, sink);
1415 if (src->serial() || sink->serial()) {
1416 serial.push_back(task);
1417 } else {
1418 parallel.add([task] { Task::Run(task); });
mtklein748ca3b2015-01-15 10:56:12 -08001419 }
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001420 }
mtklein21eaf3b2016-02-08 12:39:59 -08001421 for (auto test : gParallelTests) {
csmartdalton008b9d82017-02-22 12:00:42 -07001422 parallel.add([test, grCtxOptions] { run_test(test, grCtxOptions); });
mtklein55e88b22015-01-21 15:50:13 -08001423 }
mtklein21eaf3b2016-02-08 12:39:59 -08001424
1425 // With the parallel work running, run serial tasks and tests here on main thread.
1426 for (auto task : serial) { Task::Run(task); }
csmartdalton008b9d82017-02-22 12:00:42 -07001427 for (auto test : gSerialTests) { run_test(test, grCtxOptions); }
mtklein21eaf3b2016-02-08 12:39:59 -08001428
1429 // Wait for any remaining parallel work to complete (including any spun off of serial tasks).
1430 parallel.wait();
mtkleincd50bca2016-01-05 06:20:20 -08001431 gDefinitelyThreadSafeWork.wait();
1432
mtkleinda884c42016-02-24 18:00:23 -08001433 // We'd better have run everything.
1434 SkASSERT(gPending == 0);
mtkleine027f172016-02-26 15:53:06 -08001435 // Make sure we've flushed all our results to disk.
1436 JsonWriter::DumpJson();
mtkleinda884c42016-02-24 18:00:23 -08001437
mtklein748ca3b2015-01-15 10:56:12 -08001438 // At this point we're back in single-threaded land.
caryclarkf53ce802015-06-15 06:48:30 -07001439 sk_tool_utils::release_portable_typefaces();
mtklein@google.comd36522d2013-10-16 13:02:15 +00001440
mtklein748ca3b2015-01-15 10:56:12 -08001441 if (gFailures.count() > 0) {
mtkleinc41fd922016-03-08 09:01:39 -08001442 info("Failures:\n");
mtklein748ca3b2015-01-15 10:56:12 -08001443 for (int i = 0; i < gFailures.count(); i++) {
mtkleinc41fd922016-03-08 09:01:39 -08001444 info("\t%s\n", gFailures[i].c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001445 }
mtkleinc41fd922016-03-08 09:01:39 -08001446 info("%d failures\n", gFailures.count());
mtklein748ca3b2015-01-15 10:56:12 -08001447 return 1;
mtklein114c3cd2015-01-15 10:15:02 -08001448 }
mtkleinafae30a2016-02-24 12:28:32 -08001449
1450#ifdef SK_PDF_IMAGE_STATS
halcanary7a14b312015-10-01 07:28:13 -07001451 SkPDFImageDumpStats();
mtkleinafae30a2016-02-24 12:28:32 -08001452#endif // SK_PDF_IMAGE_STATS
1453
Herb Derby5a523fe2017-01-26 16:48:28 -05001454 SkGraphics::PurgeAllCaches();
mtkleinc41fd922016-03-08 09:01:39 -08001455 info("Finished!\n");
Brian Osman53136aa2017-07-20 15:43:35 -04001456
mtklein748ca3b2015-01-15 10:56:12 -08001457 return 0;
mtklein@google.comd36522d2013-10-16 13:02:15 +00001458}