blob: 044fea59073ee0a92865d7561b8c1675d60359cf [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"
Brian Osmanf9810662017-08-30 10:02:10 -040021#include "SkCommonFlagsGpuThreads.h"
csmartdalton008b9d82017-02-22 12:00:42 -070022#include "SkCommonFlagsPathRenderer.h"
brianosman3c579dc2016-04-19 09:18:11 -070023#include "SkData.h"
Hal Canaryc7d295e2017-07-20 15:36:00 -040024#include "SkDocument.h"
Brian Salomondcbb9d92017-07-19 10:53:20 -040025#include "SkDebugfTracer.h"
Brian Osman53136aa2017-07-20 15:43:35 -040026#include "SkEventTracingPriv.h"
caryclark83ca6282015-06-10 09:31:09 -070027#include "SkFontMgr.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"
mtkleina82f5622015-02-20 12:30:19 -080039#include "SkTHash.h"
mtklein406654b2014-09-03 15:34:37 -070040#include "SkTaskGroup.h"
mtkleinde6fc2b2015-03-12 06:28:54 -070041#include "SkThreadUtils.h"
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000042#include "Test.h"
mtklein748ca3b2015-01-15 10:56:12 -080043#include "Timer.h"
Mike Kleinadacaef2017-02-06 09:26:14 -050044#include "ios_utils.h"
brianosman3c579dc2016-04-19 09:18:11 -070045#include "picture_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
scroggo27a58342015-10-28 08:56:41 -070058#ifndef SK_BUILD_FOR_WIN32
59 #include <unistd.h>
60#endif
61
Mike Reed7c26ca72017-07-05 15:45:52 -040062extern bool gSkForceRasterPipelineBlitter;
63
Ben Wagner32fa5102017-08-10 21:25:55 -040064DECLARE_bool(undefok);
djsollen54416de2015-04-03 07:24:48 -070065DEFINE_string(src, "tests gm skp image", "Source types to test.");
mtklein748ca3b2015-01-15 10:56:12 -080066DEFINE_bool(nameByHash, false,
67 "If true, write to FLAGS_writePath[0]/<hash>.png instead of "
djsollen54416de2015-04-03 07:24:48 -070068 "to FLAGS_writePath[0]/<config>/<sourceType>/<sourceOptions>/<name>.png");
mtklein748ca3b2015-01-15 10:56:12 -080069DEFINE_bool2(pathOpsExtended, x, false, "Run extended pathOps tests.");
mtkleind603b222015-02-17 11:13:33 -080070DEFINE_string(matrix, "1 0 0 1",
71 "2x2 scale+skew matrix to apply or upright when using "
72 "'matrix' or 'upright' in config.");
mtklein82d28432015-01-15 12:46:02 -080073DEFINE_bool(gpu_threading, false, "Allow GPU work to run on multiple threads?");
mtklein@google.comd36522d2013-10-16 13:02:15 +000074
mtkleina2ef6422015-01-15 13:44:22 -080075DEFINE_string(blacklist, "",
Chris Daltonecf78ac2017-08-15 15:43:08 -060076 "Space-separated config/src/srcOptions/name quadruples to blacklist. "
77 "'_' matches anything. '~' negates the match. E.g. \n"
djsollen54416de2015-04-03 07:24:48 -070078 "'--blacklist gpu skp _ _' will blacklist all SKPs drawn into the gpu config.\n"
Chris Daltonecf78ac2017-08-15 15:43:08 -060079 "'--blacklist gpu skp _ _ 8888 gm _ aarects' will also blacklist the aarects GM on 8888.\n"
80 "'--blacklist ~8888 svg _ svgparse_' blocks non-8888 SVGs that contain \"svgparse_\" in "
81 "the name.");
mtkleina2ef6422015-01-15 13:44:22 -080082
mtklein62bd1a62015-01-27 14:46:26 -080083DEFINE_string2(readPath, r, "", "If set check for equality with golden results in this directory.");
84
borenet09ed4802015-04-03 14:15:33 -070085DEFINE_string(uninterestingHashesFile, "",
86 "File containing a list of uninteresting hashes. If a result hashes to something in "
87 "this list, no image is written for that result.");
88
mtklein6393c062015-04-27 08:45:01 -070089DEFINE_int32(shards, 1, "We're splitting source data into this many shards.");
90DEFINE_int32(shard, 0, "Which shard do I run?");
91
halcanary45420a92016-06-02 12:41:14 -070092DEFINE_string(mskps, "", "Directory to read mskps from, or a single mskp file.");
Mike Reed7c26ca72017-07-05 15:45:52 -040093DEFINE_bool(forceRasterPipeline, false, "sets gSkForceRasterPipelineBlitter");
halcanary45420a92016-06-02 12:41:14 -070094
Robert Phillipsad8a43f2017-08-30 12:06:35 -040095DEFINE_bool(ddl, false, "If true, use DeferredDisplayLists for GPU SKP rendering.");
96
csmartdalton008b9d82017-02-22 12:00:42 -070097#if SK_SUPPORT_GPU
98DEFINE_pathrenderer_flag;
99#endif
100
Derek Sollenbergeredfe3df2017-07-19 15:25:24 -0400101DEFINE_bool(ignoreSigInt, false, "ignore SIGINT signals during test execution");
102
Mike Klein97d6a7a2017-07-24 10:37:19 -0400103DEFINE_string(dont_write, "", "File extensions to skip writing to --writePath."); // See skia:6821
104
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) {
119 fprintf(gVLog, "%s\t", HumanizeMs(SkTime::GetMSecs() - kStartMs).c_str());
120 fprintf(gVLog, fmt, args...);
121 fflush(gVLog);
122 }
123}
124
125template <typename... Args>
126static void info(const char* fmt, Args&&... args) {
127 vlog(fmt, args...);
128 if (!FLAGS_quiet) {
129 printf(fmt, args...);
130 }
131}
132static void info(const char* fmt) {
133 if (!FLAGS_quiet) {
134 printf("%s", fmt); // Clang warns printf(fmt) is insecure.
135 }
136}
137
reed086eea92016-05-04 17:12:46 -0700138SK_DECLARE_STATIC_MUTEX(gFailuresMutex);
mtklein748ca3b2015-01-15 10:56:12 -0800139static SkTArray<SkString> gFailures;
140
mtklein3eed7dd2016-02-24 19:07:07 -0800141static void fail(const SkString& err) {
mtklein748ca3b2015-01-15 10:56:12 -0800142 SkAutoMutexAcquire lock(gFailuresMutex);
143 SkDebugf("\n\nFAILURE: %s\n\n", err.c_str());
144 gFailures.push_back(err);
halcanary9e398f72015-01-10 11:18:04 -0800145}
146
mtklein0f7748a2016-07-25 15:27:29 -0700147struct Running {
148 SkString id;
149 SkThreadID thread;
150
151 void dump() const {
152 info("\t%s\n", id.c_str());
153 }
154};
mtkleinb37cb412015-03-18 05:27:14 -0700155
mtklein246ba3a2016-02-23 10:39:36 -0800156// We use a spinlock to make locking this in a signal handler _somewhat_ safe.
Mike Klein03a95ad2017-06-23 12:36:32 -0400157static SkSpinlock gMutex;
158static int gPending;
mtklein0f7748a2016-07-25 15:27:29 -0700159static SkTArray<Running> gRunning;
mtklein748ca3b2015-01-15 10:56:12 -0800160
mtklein3eed7dd2016-02-24 19:07:07 -0800161static void done(const char* config, const char* src, const char* srcOptions, const char* name) {
162 SkString id = SkStringPrintf("%s %s %s %s", config, src, srcOptions, name);
mtkleinc41fd922016-03-08 09:01:39 -0800163 vlog("done %s\n", id.c_str());
mtkleinafae30a2016-02-24 12:28:32 -0800164 int pending;
mtkleinb37cb412015-03-18 05:27:14 -0700165 {
mtkleinf10637f2016-06-10 13:56:35 -0700166 SkAutoMutexAcquire lock(gMutex);
mtkleinb37cb412015-03-18 05:27:14 -0700167 for (int i = 0; i < gRunning.count(); i++) {
mtklein0f7748a2016-07-25 15:27:29 -0700168 if (gRunning[i].id == id) {
mtkleinb37cb412015-03-18 05:27:14 -0700169 gRunning.removeShuffle(i);
170 break;
171 }
172 }
mtkleinafae30a2016-02-24 12:28:32 -0800173 pending = --gPending;
reed50bc0512015-05-19 14:13:31 -0700174 }
Mike Klein03a95ad2017-06-23 12:36:32 -0400175
176 // We write out dm.json file and print out a progress update every once in a while.
177 // Notice this also handles the final dm.json and progress update when pending == 0.
mtkleina17241b2015-01-23 05:48:00 -0800178 if (pending % 500 == 0) {
179 JsonWriter::DumpJson();
Mike Klein03a95ad2017-06-23 12:36:32 -0400180
181 int curr = sk_tools::getCurrResidentSetSizeMB(),
182 peak = sk_tools::getMaxResidentSetSizeMB();
183 SkString elapsed = HumanizeMs(SkTime::GetMSecs() - kStartMs);
184
185 SkAutoMutexAcquire lock(gMutex);
186 info("\n%dMB RAM, %dMB peak, %s elapsed, %d queued, %d active:\n",
187 curr, peak, elapsed.c_str(), gPending - gRunning.count(), gRunning.count());
188 for (auto& task : gRunning) {
189 task.dump();
190 }
mtkleina17241b2015-01-23 05:48:00 -0800191 }
mtklein@google.comd36522d2013-10-16 13:02:15 +0000192}
193
mtklein3eed7dd2016-02-24 19:07:07 -0800194static void start(const char* config, const char* src, const char* srcOptions, const char* name) {
195 SkString id = SkStringPrintf("%s %s %s %s", config, src, srcOptions, name);
mtkleinc41fd922016-03-08 09:01:39 -0800196 vlog("start %s\n", id.c_str());
mtkleinf10637f2016-06-10 13:56:35 -0700197 SkAutoMutexAcquire lock(gMutex);
mtklein0f7748a2016-07-25 15:27:29 -0700198 gRunning.push_back({id,SkGetThreadID()});
mtkleinb37cb412015-03-18 05:27:14 -0700199}
200
Mike Klein3cc2d202016-10-24 11:39:43 -0400201static void find_culprit() {
202 // Assumes gMutex is locked.
203 SkThreadID thisThread = SkGetThreadID();
204 for (auto& task : gRunning) {
205 if (task.thread == thisThread) {
206 info("Likely culprit:\n");
207 task.dump();
mtklein0f7748a2016-07-25 15:27:29 -0700208 }
209 }
Mike Klein3cc2d202016-10-24 11:39:43 -0400210}
mtklein0f7748a2016-07-25 15:27:29 -0700211
mtklein246ba3a2016-02-23 10:39:36 -0800212#if defined(SK_BUILD_FOR_WIN32)
mtklein5b64dab2016-06-09 08:59:48 -0700213 static LONG WINAPI crash_handler(EXCEPTION_POINTERS* e) {
mtkleinf8557292016-02-29 06:35:28 -0800214 static const struct {
215 const char* name;
robertphillips75467862016-03-01 14:10:23 -0800216 DWORD code;
mtkleinf8557292016-02-29 06:35:28 -0800217 } kExceptions[] = {
218 #define _(E) {#E, E}
219 _(EXCEPTION_ACCESS_VIOLATION),
220 _(EXCEPTION_BREAKPOINT),
221 _(EXCEPTION_INT_DIVIDE_BY_ZERO),
222 _(EXCEPTION_STACK_OVERFLOW),
223 // TODO: more?
224 #undef _
225 };
226
mtkleinf10637f2016-06-10 13:56:35 -0700227 SkAutoMutexAcquire lock(gMutex);
mtklein5b64dab2016-06-09 08:59:48 -0700228
229 const DWORD code = e->ExceptionRecord->ExceptionCode;
230 info("\nCaught exception %u", code);
231 for (const auto& exception : kExceptions) {
232 if (exception.code == code) {
233 info(" %s", exception.name);
mtkleinf8557292016-02-29 06:35:28 -0800234 }
mtkleinf8557292016-02-29 06:35:28 -0800235 }
mtklein5b64dab2016-06-09 08:59:48 -0700236 info(", was running:\n");
237 for (auto& task : gRunning) {
mtklein0f7748a2016-07-25 15:27:29 -0700238 task.dump();
mtklein5b64dab2016-06-09 08:59:48 -0700239 }
mtklein0f7748a2016-07-25 15:27:29 -0700240 find_culprit();
mtklein5b64dab2016-06-09 08:59:48 -0700241 fflush(stdout);
242
mtkleinf8557292016-02-29 06:35:28 -0800243 // Execute default exception handler... hopefully, exit.
244 return EXCEPTION_EXECUTE_HANDLER;
mtklein246ba3a2016-02-23 10:39:36 -0800245 }
246
Mike Klein3cc2d202016-10-24 11:39:43 -0400247 static void setup_crash_handler() {
248 SetUnhandledExceptionFilter(crash_handler);
249 }
250#else
mtklein246ba3a2016-02-23 10:39:36 -0800251 #include <signal.h>
Mike Klein3cc2d202016-10-24 11:39:43 -0400252 #if !defined(SK_BUILD_FOR_ANDROID)
253 #include <execinfo.h>
Brian Salomondcbb9d92017-07-19 10:53:20 -0400254
255#endif
Mike Klein3cc2d202016-10-24 11:39:43 -0400256
257 static constexpr int max_of() { return 0; }
258 template <typename... Rest>
259 static constexpr int max_of(int x, Rest... rest) {
260 return x > max_of(rest...) ? x : max_of(rest...);
261 }
262
263 static void (*previous_handler[max_of(SIGABRT,SIGBUS,SIGFPE,SIGILL,SIGSEGV)+1])(int);
mtkleinf8557292016-02-29 06:35:28 -0800264
mtklein5b64dab2016-06-09 08:59:48 -0700265 static void crash_handler(int sig) {
mtkleinf10637f2016-06-10 13:56:35 -0700266 SkAutoMutexAcquire lock(gMutex);
mtklein5b64dab2016-06-09 08:59:48 -0700267
268 info("\nCaught signal %d [%s], was running:\n", sig, strsignal(sig));
269 for (auto& task : gRunning) {
mtklein0f7748a2016-07-25 15:27:29 -0700270 task.dump();
mtklein5b64dab2016-06-09 08:59:48 -0700271 }
mtklein0f7748a2016-07-25 15:27:29 -0700272 find_culprit();
mtklein5b64dab2016-06-09 08:59:48 -0700273
Mike Klein3cc2d202016-10-24 11:39:43 -0400274 #if !defined(SK_BUILD_FOR_ANDROID)
mtklein5b64dab2016-06-09 08:59:48 -0700275 void* stack[64];
276 int count = backtrace(stack, SK_ARRAY_COUNT(stack));
277 char** symbols = backtrace_symbols(stack, count);
278 info("\nStack trace:\n");
279 for (int i = 0; i < count; i++) {
280 info(" %s\n", symbols[i]);
281 }
Mike Klein3cc2d202016-10-24 11:39:43 -0400282 #endif
mtklein5b64dab2016-06-09 08:59:48 -0700283 fflush(stdout);
284
Mike Klein3cc2d202016-10-24 11:39:43 -0400285 signal(sig, previous_handler[sig]);
286 raise(sig);
mtklein5b64dab2016-06-09 08:59:48 -0700287 }
288
mtklein246ba3a2016-02-23 10:39:36 -0800289 static void setup_crash_handler() {
290 const int kSignals[] = { SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGSEGV };
291 for (int sig : kSignals) {
Mike Klein3cc2d202016-10-24 11:39:43 -0400292 previous_handler[sig] = signal(sig, crash_handler);
mtklein246ba3a2016-02-23 10:39:36 -0800293 }
Derek Sollenbergeredfe3df2017-07-19 15:25:24 -0400294
295 if (FLAGS_ignoreSigInt) {
296 signal(SIGINT, SIG_IGN);
297 }
mtklein246ba3a2016-02-23 10:39:36 -0800298 }
299#endif
300
mtklein748ca3b2015-01-15 10:56:12 -0800301/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
mtklein114c3cd2015-01-15 10:15:02 -0800302
mtklein62bd1a62015-01-27 14:46:26 -0800303struct Gold : public SkString {
mtkleina82f5622015-02-20 12:30:19 -0800304 Gold() : SkString("") {}
mtklein3eed7dd2016-02-24 19:07:07 -0800305 Gold(const SkString& sink, const SkString& src,
306 const SkString& srcOptions, const SkString& name,
307 const SkString& md5)
mtklein62bd1a62015-01-27 14:46:26 -0800308 : SkString("") {
309 this->append(sink);
310 this->append(src);
djsollen54416de2015-04-03 07:24:48 -0700311 this->append(srcOptions);
mtklein62bd1a62015-01-27 14:46:26 -0800312 this->append(name);
313 this->append(md5);
mtklein62bd1a62015-01-27 14:46:26 -0800314 }
mtkleinc8d1dd42015-10-15 12:23:01 -0700315 struct Hash {
316 uint32_t operator()(const Gold& g) const {
317 return SkGoodHash()((const SkString&)g);
318 }
319 };
mtklein62bd1a62015-01-27 14:46:26 -0800320};
mtkleina82f5622015-02-20 12:30:19 -0800321static SkTHashSet<Gold, Gold::Hash> gGold;
mtklein62bd1a62015-01-27 14:46:26 -0800322
323static void add_gold(JsonWriter::BitmapResult r) {
djsollen54416de2015-04-03 07:24:48 -0700324 gGold.add(Gold(r.config, r.sourceType, r.sourceOptions, r.name, r.md5));
mtklein62bd1a62015-01-27 14:46:26 -0800325}
326
327static void gather_gold() {
328 if (!FLAGS_readPath.isEmpty()) {
329 SkString path(FLAGS_readPath[0]);
330 path.append("/dm.json");
331 if (!JsonWriter::ReadJson(path.c_str(), add_gold)) {
332 fail(SkStringPrintf("Couldn't read %s for golden results.", path.c_str()));
333 }
334 }
335}
336
337/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
338
mtklein935f1b12016-03-16 08:37:19 -0700339#if defined(SK_BUILD_FOR_WIN32)
340 static const char* kNewline = "\r\n";
341#else
342 static const char* kNewline = "\n";
343#endif
344
borenet09ed4802015-04-03 14:15:33 -0700345static SkTHashSet<SkString> gUninterestingHashes;
346
347static void gather_uninteresting_hashes() {
348 if (!FLAGS_uninterestingHashesFile.isEmpty()) {
bungeman38d909e2016-08-02 14:40:46 -0700349 sk_sp<SkData> data(SkData::MakeFromFileName(FLAGS_uninterestingHashesFile[0]));
mtkleincc334b32015-09-22 11:43:53 -0700350 if (!data) {
mtkleinc41fd922016-03-08 09:01:39 -0800351 info("WARNING: unable to read uninteresting hashes from %s\n",
352 FLAGS_uninterestingHashesFile[0]);
mtkleincc334b32015-09-22 11:43:53 -0700353 return;
354 }
Mike Klein45dcc0c2017-04-05 18:04:31 -0400355
356 // Copy to a string to make sure SkStrSplit has a terminating \0 to find.
357 SkString contents((const char*)data->data(), data->size());
358
borenet09ed4802015-04-03 14:15:33 -0700359 SkTArray<SkString> hashes;
Mike Klein45dcc0c2017-04-05 18:04:31 -0400360 SkStrSplit(contents.c_str(), kNewline, &hashes);
borenet09ed4802015-04-03 14:15:33 -0700361 for (const SkString& hash : hashes) {
362 gUninterestingHashes.add(hash);
363 }
mtkleinc41fd922016-03-08 09:01:39 -0800364 info("FYI: loaded %d distinct uninteresting hashes from %d lines\n",
365 gUninterestingHashes.count(), hashes.count());
borenet09ed4802015-04-03 14:15:33 -0700366 }
367}
368
369/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
370
Ben Wagner145dbcd2016-11-03 14:40:50 -0400371struct TaggedSrc : public std::unique_ptr<Src> {
mtklein3eed7dd2016-02-24 19:07:07 -0800372 SkString tag;
373 SkString options;
mtkleine0effd62015-07-29 06:37:28 -0700374};
375
Ben Wagner145dbcd2016-11-03 14:40:50 -0400376struct TaggedSink : public std::unique_ptr<Sink> {
kkinnunen3e980c32015-12-23 01:33:00 -0800377 SkString tag;
djsollen54416de2015-04-03 07:24:48 -0700378};
mtklein748ca3b2015-01-15 10:56:12 -0800379
380static const bool kMemcpyOK = true;
381
mtkleine0effd62015-07-29 06:37:28 -0700382static SkTArray<TaggedSrc, kMemcpyOK> gSrcs;
383static SkTArray<TaggedSink, kMemcpyOK> gSinks;
mtklein748ca3b2015-01-15 10:56:12 -0800384
mtklein6393c062015-04-27 08:45:01 -0700385static bool in_shard() {
386 static int N = 0;
387 return N++ % FLAGS_shards == FLAGS_shard;
388}
389
mtklein3eed7dd2016-02-24 19:07:07 -0800390static void push_src(const char* tag, ImplicitString options, Src* s) {
Ben Wagner145dbcd2016-11-03 14:40:50 -0400391 std::unique_ptr<Src> src(s);
mtklein6393c062015-04-27 08:45:01 -0700392 if (in_shard() &&
mtklein3eed7dd2016-02-24 19:07:07 -0800393 FLAGS_src.contains(tag) &&
mtklein748ca3b2015-01-15 10:56:12 -0800394 !SkCommandLineFlags::ShouldSkip(FLAGS_match, src->name().c_str())) {
mtkleine0effd62015-07-29 06:37:28 -0700395 TaggedSrc& s = gSrcs.push_back();
mtklein18300a32016-03-16 13:53:35 -0700396 s.reset(src.release());
mtklein748ca3b2015-01-15 10:56:12 -0800397 s.tag = tag;
djsollen54416de2015-04-03 07:24:48 -0700398 s.options = options;
mtklein114c3cd2015-01-15 10:15:02 -0800399 }
mtklein748ca3b2015-01-15 10:56:12 -0800400}
mtklein114c3cd2015-01-15 10:15:02 -0800401
msarett9e707a02015-09-01 14:57:57 -0700402static void push_codec_src(Path path, CodecSrc::Mode mode, CodecSrc::DstColorType dstColorType,
scroggoc5560be2016-02-03 09:42:42 -0800403 SkAlphaType dstAlphaType, float scale) {
scroggoe4499842016-02-25 11:03:47 -0800404 if (FLAGS_simpleCodec) {
scroggo19b91532016-10-24 09:03:26 -0700405 const bool simple = CodecSrc::kCodec_Mode == mode || CodecSrc::kAnimated_Mode == mode;
406 if (!simple || dstColorType != CodecSrc::kGetFromCanvas_DstColorType || scale != 1.0f) {
scroggoe4499842016-02-25 11:03:47 -0800407 // Only decode in the simple case.
408 return;
scroggo19b91532016-10-24 09:03:26 -0700409 }
scroggoe4499842016-02-25 11:03:47 -0800410 }
msarett9e707a02015-09-01 14:57:57 -0700411 SkString folder;
412 switch (mode) {
413 case CodecSrc::kCodec_Mode:
414 folder.append("codec");
415 break;
msarettbb25b532016-01-13 09:31:39 -0800416 case CodecSrc::kCodecZeroInit_Mode:
417 folder.append("codec_zero_init");
418 break;
msarett9e707a02015-09-01 14:57:57 -0700419 case CodecSrc::kScanline_Mode:
420 folder.append("scanline");
421 break;
msarett9e707a02015-09-01 14:57:57 -0700422 case CodecSrc::kStripe_Mode:
423 folder.append("stripe");
424 break;
msarett91c22b22016-02-22 12:27:46 -0800425 case CodecSrc::kCroppedScanline_Mode:
426 folder.append("crop");
427 break;
msarett9e707a02015-09-01 14:57:57 -0700428 case CodecSrc::kSubset_Mode:
msarett36c37962015-09-02 13:20:52 -0700429 folder.append("codec_subset");
msarett9e707a02015-09-01 14:57:57 -0700430 break;
scroggo19b91532016-10-24 09:03:26 -0700431 case CodecSrc::kAnimated_Mode:
432 folder.append("codec_animated");
433 break;
msarett9e707a02015-09-01 14:57:57 -0700434 }
435
436 switch (dstColorType) {
437 case CodecSrc::kGrayscale_Always_DstColorType:
438 folder.append("_kGray8");
439 break;
msarett34e0ec42016-04-22 16:27:24 -0700440 case CodecSrc::kNonNative8888_Always_DstColorType:
441 folder.append("_kNonNative");
442 break;
msarett9e707a02015-09-01 14:57:57 -0700443 default:
444 break;
445 }
446
scroggoc5560be2016-02-03 09:42:42 -0800447 switch (dstAlphaType) {
scroggoc5560be2016-02-03 09:42:42 -0800448 case kPremul_SkAlphaType:
449 folder.append("_premul");
450 break;
451 case kUnpremul_SkAlphaType:
452 folder.append("_unpremul");
453 break;
454 default:
455 break;
456 }
457
msarett9e707a02015-09-01 14:57:57 -0700458 if (1.0f != scale) {
459 folder.appendf("_%.3f", scale);
460 }
461
scroggoc5560be2016-02-03 09:42:42 -0800462 CodecSrc* src = new CodecSrc(path, mode, dstColorType, dstAlphaType, scale);
msarett9e707a02015-09-01 14:57:57 -0700463 push_src("image", folder, src);
464}
465
scroggof8dc9df2016-05-16 09:04:13 -0700466static void push_android_codec_src(Path path, CodecSrc::DstColorType dstColorType,
467 SkAlphaType dstAlphaType, int sampleSize) {
msarett3d9d7a72015-10-21 10:27:10 -0700468 SkString folder;
scroggof8dc9df2016-05-16 09:04:13 -0700469 folder.append("scaled_codec");
msarett3d9d7a72015-10-21 10:27:10 -0700470
471 switch (dstColorType) {
472 case CodecSrc::kGrayscale_Always_DstColorType:
473 folder.append("_kGray8");
474 break;
msarett34e0ec42016-04-22 16:27:24 -0700475 case CodecSrc::kNonNative8888_Always_DstColorType:
476 folder.append("_kNonNative");
477 break;
msarett3d9d7a72015-10-21 10:27:10 -0700478 default:
479 break;
480 }
481
scroggoc5560be2016-02-03 09:42:42 -0800482 switch (dstAlphaType) {
scroggoc5560be2016-02-03 09:42:42 -0800483 case kPremul_SkAlphaType:
484 folder.append("_premul");
485 break;
msarett9e9444c2016-02-03 12:39:10 -0800486 case kUnpremul_SkAlphaType:
487 folder.append("_unpremul");
488 break;
scroggoc5560be2016-02-03 09:42:42 -0800489 default:
490 break;
491 }
492
msarett3d9d7a72015-10-21 10:27:10 -0700493 if (1 != sampleSize) {
msarett4b0778e2015-11-13 09:59:11 -0800494 folder.appendf("_%.3f", 1.0f / (float) sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700495 }
496
scroggof8dc9df2016-05-16 09:04:13 -0700497 AndroidCodecSrc* src = new AndroidCodecSrc(path, dstColorType, dstAlphaType, sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700498 push_src("image", folder, src);
499}
500
msarett18976312016-03-09 14:20:58 -0800501static void push_image_gen_src(Path path, ImageGenSrc::Mode mode, SkAlphaType alphaType, bool isGpu)
502{
503 SkString folder;
504 switch (mode) {
505 case ImageGenSrc::kCodec_Mode:
506 folder.append("gen_codec");
507 break;
508 case ImageGenSrc::kPlatform_Mode:
509 folder.append("gen_platform");
510 break;
511 }
512
513 if (isGpu) {
514 folder.append("_gpu");
515 } else {
516 switch (alphaType) {
517 case kOpaque_SkAlphaType:
518 folder.append("_opaque");
519 break;
520 case kPremul_SkAlphaType:
521 folder.append("_premul");
522 break;
523 case kUnpremul_SkAlphaType:
524 folder.append("_unpremul");
525 break;
526 default:
527 break;
528 }
529 }
530
531 ImageGenSrc* src = new ImageGenSrc(path, mode, alphaType, isGpu);
532 push_src("image", folder, src);
533}
534
Leon Scroggins III07418182017-08-15 12:24:02 -0400535static void push_brd_src(Path path, CodecSrc::DstColorType dstColorType, BRDSrc::Mode mode,
536 uint32_t sampleSize) {
537 SkString folder("brd_android_codec");
538 switch (mode) {
539 case BRDSrc::kFullImage_Mode:
540 break;
541 case BRDSrc::kDivisor_Mode:
542 folder.append("_divisor");
543 break;
544 default:
545 SkASSERT(false);
546 return;
547 }
548
549 switch (dstColorType) {
550 case CodecSrc::kGetFromCanvas_DstColorType:
551 break;
552 case CodecSrc::kGrayscale_Always_DstColorType:
553 folder.append("_kGray");
554 break;
555 default:
556 SkASSERT(false);
557 return;
558 }
559
560 if (1 != sampleSize) {
561 folder.appendf("_%.3f", 1.0f / (float) sampleSize);
562 }
563
564 BRDSrc* src = new BRDSrc(path, mode, dstColorType, sampleSize);
565 push_src("image", folder, src);
566}
567
568static void push_brd_srcs(Path path, bool gray) {
569 if (gray) {
570 // Only run grayscale to one sampleSize and Mode. Though interesting
571 // to test grayscale, it should not reveal anything across various
572 // sampleSizes and Modes
573 // Arbitrarily choose Mode and sampleSize.
574 push_brd_src(path, CodecSrc::kGrayscale_Always_DstColorType,
575 BRDSrc::kFullImage_Mode, 2);
576 }
577
578 // Test on a variety of sampleSizes, making sure to include:
579 // - 2, 4, and 8, which are natively supported by jpeg
580 // - multiples of 2 which are not divisible by 4 (analogous for 4)
581 // - larger powers of two, since BRD clients generally use powers of 2
582 // We will only produce output for the larger sizes on large images.
583 const uint32_t sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 24, 32, 64 };
584
585 const BRDSrc::Mode modes[] = { BRDSrc::kFullImage_Mode, BRDSrc::kDivisor_Mode, };
586
587 for (uint32_t sampleSize : sampleSizes) {
588 for (BRDSrc::Mode mode : modes) {
589 push_brd_src(path, CodecSrc::kGetFromCanvas_DstColorType, mode, sampleSize);
590 }
591 }
592}
593
msarett438b2ad2015-04-09 12:43:10 -0700594static void push_codec_srcs(Path path) {
bungeman38d909e2016-08-02 14:40:46 -0700595 sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str()));
msarett438b2ad2015-04-09 12:43:10 -0700596 if (!encoded) {
mtkleinc41fd922016-03-08 09:01:39 -0800597 info("Couldn't read %s.", path.c_str());
msarett438b2ad2015-04-09 12:43:10 -0700598 return;
599 }
Mike Reedede7bac2017-07-23 15:30:02 -0400600 std::unique_ptr<SkCodec> codec = SkCodec::MakeFromData(encoded);
halcanary96fcdcc2015-08-27 07:41:13 -0700601 if (nullptr == codec.get()) {
mtkleinc41fd922016-03-08 09:01:39 -0800602 info("Couldn't create codec for %s.", path.c_str());
msarett438b2ad2015-04-09 12:43:10 -0700603 return;
604 }
605
scroggo9366aff2016-05-20 08:38:54 -0700606 // native scaling is only supported by WEBP and JPEG
607 bool supportsNativeScaling = false;
msarett438b2ad2015-04-09 12:43:10 -0700608
msarett91c22b22016-02-22 12:27:46 -0800609 SkTArray<CodecSrc::Mode> nativeModes;
610 nativeModes.push_back(CodecSrc::kCodec_Mode);
611 nativeModes.push_back(CodecSrc::kCodecZeroInit_Mode);
msarett91c22b22016-02-22 12:27:46 -0800612 switch (codec->getEncodedFormat()) {
Hal Canarydb683012016-11-23 08:55:18 -0700613 case SkEncodedImageFormat::kJPEG:
msarett91c22b22016-02-22 12:27:46 -0800614 nativeModes.push_back(CodecSrc::kScanline_Mode);
615 nativeModes.push_back(CodecSrc::kStripe_Mode);
616 nativeModes.push_back(CodecSrc::kCroppedScanline_Mode);
scroggo9366aff2016-05-20 08:38:54 -0700617 supportsNativeScaling = true;
msarett91c22b22016-02-22 12:27:46 -0800618 break;
Hal Canarydb683012016-11-23 08:55:18 -0700619 case SkEncodedImageFormat::kWEBP:
msarett91c22b22016-02-22 12:27:46 -0800620 nativeModes.push_back(CodecSrc::kSubset_Mode);
scroggo9366aff2016-05-20 08:38:54 -0700621 supportsNativeScaling = true;
msarett91c22b22016-02-22 12:27:46 -0800622 break;
Hal Canarydb683012016-11-23 08:55:18 -0700623 case SkEncodedImageFormat::kDNG:
msarettb65e6042016-02-23 05:37:25 -0800624 break;
msarett91c22b22016-02-22 12:27:46 -0800625 default:
626 nativeModes.push_back(CodecSrc::kScanline_Mode);
msarett91c22b22016-02-22 12:27:46 -0800627 break;
628 }
msarett9e707a02015-09-01 14:57:57 -0700629
msarett91c22b22016-02-22 12:27:46 -0800630 SkTArray<CodecSrc::DstColorType> colorTypes;
631 colorTypes.push_back(CodecSrc::kGetFromCanvas_DstColorType);
msarett34e0ec42016-04-22 16:27:24 -0700632 colorTypes.push_back(CodecSrc::kNonNative8888_Always_DstColorType);
msarett36c37962015-09-02 13:20:52 -0700633 switch (codec->getInfo().colorType()) {
634 case kGray_8_SkColorType:
msarett91c22b22016-02-22 12:27:46 -0800635 colorTypes.push_back(CodecSrc::kGrayscale_Always_DstColorType);
msarett36c37962015-09-02 13:20:52 -0700636 break;
637 default:
msarett36c37962015-09-02 13:20:52 -0700638 break;
639 }
msarett9e707a02015-09-01 14:57:57 -0700640
scroggoc5560be2016-02-03 09:42:42 -0800641 SkTArray<SkAlphaType> alphaModes;
642 alphaModes.push_back(kPremul_SkAlphaType);
scroggof2c96a22016-05-20 11:08:27 -0700643 if (codec->getInfo().alphaType() != kOpaque_SkAlphaType) {
644 alphaModes.push_back(kUnpremul_SkAlphaType);
scroggoc5560be2016-02-03 09:42:42 -0800645 }
msarettb714fb02016-01-22 14:46:42 -0800646
647 for (CodecSrc::Mode mode : nativeModes) {
scroggo9366aff2016-05-20 08:38:54 -0700648 for (CodecSrc::DstColorType colorType : colorTypes) {
649 for (SkAlphaType alphaType : alphaModes) {
scroggof2c96a22016-05-20 11:08:27 -0700650 // Only test kCroppedScanline_Mode when the alpha type is premul. The test is
scroggo9366aff2016-05-20 08:38:54 -0700651 // slow and won't be interestingly different with different alpha types.
652 if (CodecSrc::kCroppedScanline_Mode == mode &&
scroggof2c96a22016-05-20 11:08:27 -0700653 kPremul_SkAlphaType != alphaType) {
scroggo9366aff2016-05-20 08:38:54 -0700654 continue;
655 }
msarett91c22b22016-02-22 12:27:46 -0800656
scroggo9366aff2016-05-20 08:38:54 -0700657 push_codec_src(path, mode, colorType, alphaType, 1.0f);
msarettf3dc1882016-04-26 13:06:38 -0700658
scroggo9366aff2016-05-20 08:38:54 -0700659 // Skip kNonNative on different native scales. It won't be interestingly
660 // different.
661 if (supportsNativeScaling &&
662 CodecSrc::kNonNative8888_Always_DstColorType == colorType) {
663 // Native Scales
664 // SkJpegCodec natively supports scaling to the following:
665 for (auto scale : { 0.125f, 0.25f, 0.375f, 0.5f, 0.625f, 0.750f, 0.875f }) {
666 push_codec_src(path, mode, colorType, alphaType, scale);
667 }
scroggoc5560be2016-02-03 09:42:42 -0800668 }
msarett9e707a02015-09-01 14:57:57 -0700669 }
670 }
msarett0a242972015-06-11 14:27:27 -0700671 }
msarett36c37962015-09-02 13:20:52 -0700672
scroggo19b91532016-10-24 09:03:26 -0700673 {
674 std::vector<SkCodec::FrameInfo> frameInfos = codec->getFrameInfo();
675 if (frameInfos.size() > 1) {
Leon Scroggins III557fbbe2017-05-23 09:37:21 -0400676 for (auto dstCT : { CodecSrc::kNonNative8888_Always_DstColorType,
677 CodecSrc::kGetFromCanvas_DstColorType }) {
678 for (auto at : { kUnpremul_SkAlphaType, kPremul_SkAlphaType }) {
679 push_codec_src(path, CodecSrc::kAnimated_Mode, dstCT, at, 1.0f);
680 }
681 }
scroggo19b91532016-10-24 09:03:26 -0700682 }
683
684 }
685
scroggoe4499842016-02-25 11:03:47 -0800686 if (FLAGS_simpleCodec) {
687 return;
688 }
689
msarett3d9d7a72015-10-21 10:27:10 -0700690 const int sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
msarett36c37962015-09-02 13:20:52 -0700691
msarett3d9d7a72015-10-21 10:27:10 -0700692 for (int sampleSize : sampleSizes) {
msarett91c22b22016-02-22 12:27:46 -0800693 for (CodecSrc::DstColorType colorType : colorTypes) {
scroggoc5560be2016-02-03 09:42:42 -0800694 for (SkAlphaType alphaType : alphaModes) {
msarettf3dc1882016-04-26 13:06:38 -0700695 // We can exercise all of the kNonNative support code in the swizzler with just a
696 // few sample sizes. Skip the rest.
697 if (CodecSrc::kNonNative8888_Always_DstColorType == colorType && sampleSize > 3) {
698 continue;
699 }
700
scroggof8dc9df2016-05-16 09:04:13 -0700701 push_android_codec_src(path, colorType, alphaType, sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700702 }
msarett36c37962015-09-02 13:20:52 -0700703 }
704 }
msarett18976312016-03-09 14:20:58 -0800705
Leon Scroggins III07418182017-08-15 12:24:02 -0400706 const char* ext = strrchr(path.c_str(), '.');
707 if (ext) {
708 ext++;
msarett18976312016-03-09 14:20:58 -0800709
Leon Scroggins III07418182017-08-15 12:24:02 -0400710 static const char* const rawExts[] = {
711 "arw", "cr2", "dng", "nef", "nrw", "orf", "raf", "rw2", "pef", "srw",
712 "ARW", "CR2", "DNG", "NEF", "NRW", "ORF", "RAF", "RW2", "PEF", "SRW",
713 };
714 for (const char* rawExt : rawExts) {
715 if (0 == strcmp(rawExt, ext)) {
716 // RAW is not supported by image generator (skbug.com/5079) or BRD.
717 return;
718 }
719 }
720
721 static const char* const brdExts[] = {
722 "jpg", "jpeg", "png", "webp",
723 "JPG", "JPEG", "PNG", "WEBP",
724 };
725 for (const char* brdExt : brdExts) {
726 if (0 == strcmp(brdExt, ext)) {
727 bool gray = codec->getEncodedInfo().color() == SkEncodedInfo::kGray_Color;
728 push_brd_srcs(path, gray);
729 break;
730 }
msarett18976312016-03-09 14:20:58 -0800731 }
732 }
733
734 // Push image generator GPU test.
brianosmanc9ced392016-03-24 07:27:43 -0700735 push_image_gen_src(path, ImageGenSrc::kCodec_Mode, codec->getInfo().alphaType(), true);
msarett18976312016-03-09 14:20:58 -0800736
737 // Push image generator CPU tests.
738 for (SkAlphaType alphaType : alphaModes) {
739 push_image_gen_src(path, ImageGenSrc::kCodec_Mode, alphaType, false);
740
741#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
Hal Canarydb683012016-11-23 08:55:18 -0700742 if (SkEncodedImageFormat::kWEBP != codec->getEncodedFormat() &&
743 SkEncodedImageFormat::kWBMP != codec->getEncodedFormat() &&
msarett18976312016-03-09 14:20:58 -0800744 kUnpremul_SkAlphaType != alphaType)
745 {
746 push_image_gen_src(path, ImageGenSrc::kPlatform_Mode, alphaType, false);
747 }
msarettfc0b6d12016-03-17 13:50:17 -0700748#elif defined(SK_BUILD_FOR_WIN)
Hal Canarydb683012016-11-23 08:55:18 -0700749 if (SkEncodedImageFormat::kWEBP != codec->getEncodedFormat() &&
750 SkEncodedImageFormat::kWBMP != codec->getEncodedFormat())
msarettfc0b6d12016-03-17 13:50:17 -0700751 {
752 push_image_gen_src(path, ImageGenSrc::kPlatform_Mode, alphaType, false);
753 }
msarett18976312016-03-09 14:20:58 -0800754#endif
755 }
msarett438b2ad2015-04-09 12:43:10 -0700756}
757
fmalitaa2b9fdf2016-08-03 19:53:36 -0700758template <typename T>
759void gather_file_srcs(const SkCommandLineFlags::StringArray& flags, const char* ext) {
760 for (int i = 0; i < flags.count(); i++) {
761 const char* path = flags[i];
762 if (sk_isdir(path)) {
763 SkOSFile::Iter it(path, ext);
764 for (SkString file; it.next(&file); ) {
765 push_src(ext, "", new T(SkOSPath::Join(path, file.c_str())));
766 }
767 } else {
768 push_src(ext, "", new T(path));
769 }
770 }
771}
772
scroggo86737142016-02-03 12:19:11 -0800773static bool gather_srcs() {
mtklein748ca3b2015-01-15 10:56:12 -0800774 for (const skiagm::GMRegistry* r = skiagm::GMRegistry::Head(); r; r = r->next()) {
djsollen54416de2015-04-03 07:24:48 -0700775 push_src("gm", "", new GMSrc(r->factory()));
mtklein748ca3b2015-01-15 10:56:12 -0800776 }
scroggo86737142016-02-03 12:19:11 -0800777
Robert Phillipsad8a43f2017-08-30 12:06:35 -0400778 if (FLAGS_ddl) {
779 gather_file_srcs<DDLSKPSrc>(FLAGS_skps, "skp");
780 } else {
781 gather_file_srcs<SKPSrc>(FLAGS_skps, "skp");
782 }
fmalitaa2b9fdf2016-08-03 19:53:36 -0700783 gather_file_srcs<MSKPSrc>(FLAGS_mskps, "mskp");
784#if defined(SK_XML)
785 gather_file_srcs<SVGSrc>(FLAGS_svgs, "svg");
786#endif
halcanary45420a92016-06-02 12:41:14 -0700787
scroggo86737142016-02-03 12:19:11 -0800788 SkTArray<SkString> images;
msarett69deca82016-04-29 09:38:40 -0700789 if (!CollectImages(FLAGS_images, &images)) {
scroggo86737142016-02-03 12:19:11 -0800790 return false;
791 }
792
793 for (auto image : images) {
794 push_codec_srcs(image);
mtklein709d2c32015-01-15 08:30:25 -0800795 }
scroggo86737142016-02-03 12:19:11 -0800796
msarett69deca82016-04-29 09:38:40 -0700797 SkTArray<SkString> colorImages;
798 if (!CollectImages(FLAGS_colorImages, &colorImages)) {
799 return false;
800 }
801
802 for (auto colorImage : colorImages) {
msarett9ce3a542016-07-15 13:54:38 -0700803 ColorCodecSrc* src = new ColorCodecSrc(colorImage, ColorCodecSrc::kBaseline_Mode,
804 kN32_SkColorType);
msarettb8d1aac2016-08-04 12:22:06 -0700805 push_src("colorImage", "color_codec_baseline", src);
msarett888dc162016-05-23 10:21:17 -0700806
msarett9ce3a542016-07-15 13:54:38 -0700807 src = new ColorCodecSrc(colorImage, ColorCodecSrc::kDst_HPZR30w_Mode, kN32_SkColorType);
msarettb8d1aac2016-08-04 12:22:06 -0700808 push_src("colorImage", "color_codec_HPZR30w", src);
msarett9ce3a542016-07-15 13:54:38 -0700809 // TODO (msarett):
810 // 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 -0700811
msarett9ce3a542016-07-15 13:54:38 -0700812 src = new ColorCodecSrc(colorImage, ColorCodecSrc::kDst_sRGB_Mode, kN32_SkColorType);
msarettb8d1aac2016-08-04 12:22:06 -0700813 push_src("colorImage", "color_codec_sRGB_kN32", src);
msarett9ce3a542016-07-15 13:54:38 -0700814 src = new ColorCodecSrc(colorImage, ColorCodecSrc::kDst_sRGB_Mode, kRGBA_F16_SkColorType);
msarettb8d1aac2016-08-04 12:22:06 -0700815 push_src("colorImage", "color_codec_sRGB_kF16", src);
msarett69deca82016-04-29 09:38:40 -0700816 }
817
scroggo86737142016-02-03 12:19:11 -0800818 return true;
mtklein709d2c32015-01-15 08:30:25 -0800819}
820
kkinnunen3e980c32015-12-23 01:33:00 -0800821static void push_sink(const SkCommandLineConfig& config, Sink* s) {
Ben Wagner145dbcd2016-11-03 14:40:50 -0400822 std::unique_ptr<Sink> sink(s);
kkinnunen3e980c32015-12-23 01:33:00 -0800823
mtkleine0effd62015-07-29 06:37:28 -0700824 // Try a simple Src as a canary. If it fails, skip this sink.
mtklein748ca3b2015-01-15 10:56:12 -0800825 struct : public Src {
mtkleine0effd62015-07-29 06:37:28 -0700826 Error draw(SkCanvas* c) const override {
827 c->drawRect(SkRect::MakeWH(1,1), SkPaint());
828 return "";
829 }
mtklein36352bf2015-03-25 18:17:31 -0700830 SkISize size() const override { return SkISize::Make(16, 16); }
mtkleine0effd62015-07-29 06:37:28 -0700831 Name name() const override { return "justOneRect"; }
832 } justOneRect;
mtklein114c3cd2015-01-15 10:15:02 -0800833
mtklein748ca3b2015-01-15 10:56:12 -0800834 SkBitmap bitmap;
835 SkDynamicMemoryWStream stream;
mtkleinb9eb4ac2015-02-02 18:26:03 -0800836 SkString log;
mtkleine0effd62015-07-29 06:37:28 -0700837 Error err = sink->draw(justOneRect, &bitmap, &stream, &log);
mtklein4089ef72015-03-05 08:40:28 -0800838 if (err.isFatal()) {
mtkleinc41fd922016-03-08 09:01:39 -0800839 info("Could not run %s: %s\n", config.getTag().c_str(), err.c_str());
mtklein05641a52015-04-21 10:49:13 -0700840 exit(1);
mtklein114c3cd2015-01-15 10:15:02 -0800841 }
842
mtkleine0effd62015-07-29 06:37:28 -0700843 TaggedSink& ts = gSinks.push_back();
mtklein18300a32016-03-16 13:53:35 -0700844 ts.reset(sink.release());
kkinnunen3e980c32015-12-23 01:33:00 -0800845 ts.tag = config.getTag();
mtklein748ca3b2015-01-15 10:56:12 -0800846}
847
848static bool gpu_supported() {
849#if SK_SUPPORT_GPU
850 return FLAGS_gpu;
851#else
852 return false;
853#endif
854}
kkinnunen9ebc3f02015-12-21 23:48:13 -0800855
csmartdalton008b9d82017-02-22 12:00:42 -0700856static Sink* create_sink(const GrContextOptions& grCtxOptions, const SkCommandLineConfig* config) {
kkinnunen3e980c32015-12-23 01:33:00 -0800857#if SK_SUPPORT_GPU
858 if (gpu_supported()) {
859 if (const SkCommandLineConfigGpu* gpuConfig = config->asConfigGpu()) {
bsalomon85b4b532016-04-05 11:06:27 -0700860 GrContextFactory::ContextType contextType = gpuConfig->getContextType();
csmartdaltone812d492017-02-21 12:36:05 -0700861 GrContextFactory::ContextOverrides contextOverrides = gpuConfig->getContextOverrides();
csmartdalton008b9d82017-02-22 12:00:42 -0700862 GrContextFactory testFactory(grCtxOptions);
csmartdaltone812d492017-02-21 12:36:05 -0700863 if (!testFactory.get(contextType, contextOverrides)) {
mtkleinc41fd922016-03-08 09:01:39 -0800864 info("WARNING: can not create GPU context for config '%s'. "
865 "GM tests will be skipped.\n", gpuConfig->getTag().c_str());
kkinnunen3e980c32015-12-23 01:33:00 -0800866 return nullptr;
867 }
Brian Osmanf9810662017-08-30 10:02:10 -0400868 if (gpuConfig->getTestThreading()) {
869 return new GPUThreadTestingSink(contextType, contextOverrides,
870 gpuConfig->getSamples(), gpuConfig->getUseDIText(),
871 gpuConfig->getColorType(),
872 gpuConfig->getAlphaType(),
873 sk_ref_sp(gpuConfig->getColorSpace()),
874 FLAGS_gpu_threading, grCtxOptions);
875 } else {
876 return new GPUSink(contextType, contextOverrides, gpuConfig->getSamples(),
877 gpuConfig->getUseDIText(), gpuConfig->getColorType(),
878 gpuConfig->getAlphaType(), sk_ref_sp(gpuConfig->getColorSpace()),
879 FLAGS_gpu_threading, grCtxOptions);
880 }
kkinnunen3e980c32015-12-23 01:33:00 -0800881 }
882 }
883#endif
884
885#define SINK(t, sink, ...) if (config->getBackend().equals(t)) { return new sink(__VA_ARGS__); }
886
mtklein748ca3b2015-01-15 10:56:12 -0800887 if (FLAGS_cpu) {
Matt Sarett77a7a1b2017-02-07 13:56:11 -0500888 auto srgbColorSpace = SkColorSpace::MakeSRGB();
889 auto srgbLinearColorSpace = SkColorSpace::MakeSRGBLinear();
brianosmanb109b8c2016-06-16 13:03:24 -0700890
Matt Sarettd2228302017-03-02 08:53:46 -0500891 SINK("565", RasterSink, kRGB_565_SkColorType);
892 SINK("8888", RasterSink, kN32_SkColorType);
893 SINK("srgb", RasterSink, kN32_SkColorType, srgbColorSpace);
Matt Sarettd2228302017-03-02 08:53:46 -0500894 SINK("f16", RasterSink, kRGBA_F16_SkColorType, srgbLinearColorSpace);
Hal Canaryc7d295e2017-07-20 15:36:00 -0400895 SINK("pdf", PDFSink, false, SK_ScalarDefaultRasterDPI);
Matt Sarettd2228302017-03-02 08:53:46 -0500896 SINK("skp", SKPSink);
897 SINK("pipe", PipeSink);
898 SINK("svg", SVGSink);
899 SINK("null", NullSink);
900 SINK("xps", XPSSink);
Hal Canaryc7d295e2017-07-20 15:36:00 -0400901 SINK("pdfa", PDFSink, true, SK_ScalarDefaultRasterDPI);
902 SINK("pdf300", PDFSink, false, 300);
Hal Canary85c7fe82016-10-25 10:33:27 -0400903 SINK("jsdebug", DebugSink);
mtklein748ca3b2015-01-15 10:56:12 -0800904 }
905#undef SINK
halcanary96fcdcc2015-08-27 07:41:13 -0700906 return nullptr;
mtklein114c3cd2015-01-15 10:15:02 -0800907}
908
Mike Klein841101d2017-03-10 09:55:51 -0500909static sk_sp<SkColorSpace> adobe_rgb() {
910 return SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
911 SkColorSpace::kAdobeRGB_Gamut);
912}
913
Mike Klein919cc452017-03-18 15:36:52 +0000914static sk_sp<SkColorSpace> rgb_to_gbr() {
915 float gbr[9];
916 gbr[0] = gSRGB_toXYZD50[1];
917 gbr[1] = gSRGB_toXYZD50[2];
918 gbr[2] = gSRGB_toXYZD50[0];
919 gbr[3] = gSRGB_toXYZD50[4];
920 gbr[4] = gSRGB_toXYZD50[5];
921 gbr[5] = gSRGB_toXYZD50[3];
922 gbr[6] = gSRGB_toXYZD50[7];
923 gbr[7] = gSRGB_toXYZD50[8];
924 gbr[8] = gSRGB_toXYZD50[6];
925 SkMatrix44 toXYZD50(SkMatrix44::kUninitialized_Constructor);
926 toXYZD50.set3x3RowMajorf(gbr);
927 return SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma, toXYZD50);
928}
929
kkinnunen3e980c32015-12-23 01:33:00 -0800930static Sink* create_via(const SkString& tag, Sink* wrapped) {
931#define VIA(t, via, ...) if (tag.equals(t)) { return new via(__VA_ARGS__); }
Mike Klein919cc452017-03-18 15:36:52 +0000932 VIA("adobe", ViaCSXform, wrapped, adobe_rgb(), false);
933 VIA("gbr", ViaCSXform, wrapped, rgb_to_gbr(), true);
mtklein9c5052f2016-08-06 12:51:51 -0700934 VIA("lite", ViaLite, wrapped);
reed54dc4872016-09-13 08:09:45 -0700935 VIA("pipe", ViaPipe, wrapped);
halcanary96fcdcc2015-08-27 07:41:13 -0700936 VIA("twice", ViaTwice, wrapped);
Mike Reedbae888e2017-02-18 16:50:45 -0500937#ifdef TEST_VIA_SVG
Mike Reedf67c4592017-02-17 17:06:11 -0500938 VIA("svg", ViaSVG, wrapped);
Mike Reedbae888e2017-02-18 16:50:45 -0500939#endif
halcanary96fcdcc2015-08-27 07:41:13 -0700940 VIA("serialize", ViaSerialization, wrapped);
mtklein4a34ecb2016-01-08 10:19:35 -0800941 VIA("pic", ViaPicture, wrapped);
halcanary96fcdcc2015-08-27 07:41:13 -0700942 VIA("2ndpic", ViaSecondPicture, wrapped);
mtkleind31c13d2015-05-05 12:59:56 -0700943 VIA("sp", ViaSingletonPictures, wrapped);
reedbabc3de2016-07-08 08:43:27 -0700944 VIA("defer", ViaDefer, wrapped);
halcanary96fcdcc2015-08-27 07:41:13 -0700945 VIA("tiles", ViaTiles, 256, 256, nullptr, wrapped);
mtklein7edca212015-01-21 13:18:51 -0800946 VIA("tiles_rt", ViaTiles, 256, 256, new SkRTreeFactory, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800947
mtkleind603b222015-02-17 11:13:33 -0800948 if (FLAGS_matrix.count() == 4) {
mtklein748ca3b2015-01-15 10:56:12 -0800949 SkMatrix m;
mtkleind603b222015-02-17 11:13:33 -0800950 m.reset();
951 m.setScaleX((SkScalar)atof(FLAGS_matrix[0]));
952 m.setSkewX ((SkScalar)atof(FLAGS_matrix[1]));
953 m.setSkewY ((SkScalar)atof(FLAGS_matrix[2]));
954 m.setScaleY((SkScalar)atof(FLAGS_matrix[3]));
955 VIA("matrix", ViaMatrix, m, wrapped);
956 VIA("upright", ViaUpright, m, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800957 }
tomhudson64de1e12015-03-05 08:01:07 -0800958
mtklein748ca3b2015-01-15 10:56:12 -0800959#undef VIA
halcanary96fcdcc2015-08-27 07:41:13 -0700960 return nullptr;
mtklein114c3cd2015-01-15 10:15:02 -0800961}
962
Ben Wagnerf28d4722017-08-11 17:33:22 -0400963static bool gather_sinks(const GrContextOptions& grCtxOptions, bool defaultConfigs) {
kkinnunen3e980c32015-12-23 01:33:00 -0800964 SkCommandLineConfigArray configs;
965 ParseConfigs(FLAGS_config, &configs);
966 for (int i = 0; i < configs.count(); i++) {
967 const SkCommandLineConfig& config = *configs[i];
csmartdalton008b9d82017-02-22 12:00:42 -0700968 Sink* sink = create_sink(grCtxOptions, &config);
kkinnunen3e980c32015-12-23 01:33:00 -0800969 if (sink == nullptr) {
mtkleinc41fd922016-03-08 09:01:39 -0800970 info("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(),
971 config.getTag().c_str());
kkinnunen3e980c32015-12-23 01:33:00 -0800972 continue;
973 }
mtklein748ca3b2015-01-15 10:56:12 -0800974
kkinnunen3e980c32015-12-23 01:33:00 -0800975 const SkTArray<SkString>& parts = config.getViaParts();
976 for (int j = parts.count(); j-- > 0;) {
977 const SkString& part = parts[j];
978 Sink* next = create_via(part, sink);
halcanary96fcdcc2015-08-27 07:41:13 -0700979 if (next == nullptr) {
mtkleinc41fd922016-03-08 09:01:39 -0800980 info("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(),
981 part.c_str());
mtklein748ca3b2015-01-15 10:56:12 -0800982 delete sink;
halcanary96fcdcc2015-08-27 07:41:13 -0700983 sink = nullptr;
mtklein748ca3b2015-01-15 10:56:12 -0800984 break;
985 }
986 sink = next;
987 }
988 if (sink) {
989 push_sink(config, sink);
mtklein114c3cd2015-01-15 10:15:02 -0800990 }
991 }
brianosman05c987c2016-05-09 13:42:16 -0700992
993 // If no configs were requested (just running tests, perhaps?), then we're okay.
Ben Wagnerf28d4722017-08-11 17:33:22 -0400994 if (configs.count() == 0 ||
995 // If we're using the default configs, we're okay.
996 defaultConfigs ||
Ben Wagner32fa5102017-08-10 21:25:55 -0400997 // If we've been told to ignore undefined flags, we're okay.
998 FLAGS_undefok ||
999 // Otherwise, make sure that all specified configs have become sinks.
1000 configs.count() == gSinks.count()) {
1001 return true;
1002 }
1003 info("Invalid --config. Use --undefok to bypass this warning.\n");
1004 return false;
mtklein114c3cd2015-01-15 10:15:02 -08001005}
mtklein709d2c32015-01-15 08:30:25 -08001006
mtkleina5114d72015-08-24 13:27:01 -07001007static bool dump_png(SkBitmap bitmap, const char* path, const char* md5) {
Mike Klein13b6afd2017-06-12 12:45:41 -04001008 SkPixmap pm;
1009 if (!bitmap.peekPixels(&pm)) {
1010 return false; // Ought to never happen... we're already read-back at this point.
mtkleina5114d72015-08-24 13:27:01 -07001011 }
Mike Klein13b6afd2017-06-12 12:45:41 -04001012 SkFILEWStream dst{path};
mtkleina5114d72015-08-24 13:27:01 -07001013
mtkleind69ece62015-09-10 10:37:44 -07001014 SkString description;
1015 description.append("Key: ");
1016 for (int i = 0; i < FLAGS_key.count(); i++) {
1017 description.appendf("%s ", FLAGS_key[i]);
1018 }
1019 description.append("Properties: ");
1020 for (int i = 0; i < FLAGS_properties.count(); i++) {
1021 description.appendf("%s ", FLAGS_properties[i]);
1022 }
1023 description.appendf("MD5: %s", md5);
1024
Mike Klein13b6afd2017-06-12 12:45:41 -04001025 const char* comments[] = {
1026 "Author", "DM dump_png()",
1027 "Description", description.c_str(),
1028 };
1029 size_t lengths[] = {
1030 strlen(comments[0])+1, strlen(comments[1])+1,
1031 strlen(comments[2])+1, strlen(comments[3])+1,
1032 };
mtkleina5114d72015-08-24 13:27:01 -07001033
Mike Klein13b6afd2017-06-12 12:45:41 -04001034 SkPngEncoder::Options options;
1035 options.fComments = SkDataTable::MakeCopyArrays((const void**)comments, lengths, 4);
1036 options.fFilterFlags = SkPngEncoder::FilterFlag::kNone;
1037 options.fZLibLevel = 1;
1038 options.fUnpremulBehavior = pm.colorSpace() ? SkTransferFunctionBehavior::kRespect
1039 : SkTransferFunctionBehavior::kIgnore;
1040 return SkPngEncoder::Encode(&dst, pm, options);
mtkleina5114d72015-08-24 13:27:01 -07001041}
1042
mtkleina2ef6422015-01-15 13:44:22 -08001043static bool match(const char* needle, const char* haystack) {
Chris Daltonecf78ac2017-08-15 15:43:08 -06001044 if ('~' == needle[0]) {
1045 return !match(needle + 1, haystack);
1046 }
1047 if (0 == strcmp("_", needle)) {
1048 return true;
1049 }
1050 return nullptr != strstr(haystack, needle);
mtkleina2ef6422015-01-15 13:44:22 -08001051}
1052
mtklein3eed7dd2016-02-24 19:07:07 -08001053static bool is_blacklisted(const char* sink, const char* src,
1054 const char* srcOptions, const char* name) {
mtklein0d243ff2015-04-03 07:51:00 -07001055 for (int i = 0; i < FLAGS_blacklist.count() - 3; i += 4) {
mtkleina2ef6422015-01-15 13:44:22 -08001056 if (match(FLAGS_blacklist[i+0], sink) &&
djsollen54416de2015-04-03 07:24:48 -07001057 match(FLAGS_blacklist[i+1], src) &&
1058 match(FLAGS_blacklist[i+2], srcOptions) &&
1059 match(FLAGS_blacklist[i+3], name)) {
mtklein3eed7dd2016-02-24 19:07:07 -08001060 return true;
mtkleina2ef6422015-01-15 13:44:22 -08001061 }
1062 }
mtklein3eed7dd2016-02-24 19:07:07 -08001063 return false;
mtkleina2ef6422015-01-15 13:44:22 -08001064}
1065
mtkleincd50bca2016-01-05 06:20:20 -08001066// Even when a Task Sink reports to be non-threadsafe (e.g. GPU), we know things like
1067// .png encoding are definitely thread safe. This lets us offload that work to CPU threads.
1068static SkTaskGroup gDefinitelyThreadSafeWork;
1069
mtklein748ca3b2015-01-15 10:56:12 -08001070// The finest-grained unit of work we can run: draw a single Src into a single Sink,
1071// report any errors, and perhaps write out the output: a .png of the bitmap, or a raw stream.
1072struct Task {
mtkleine0effd62015-07-29 06:37:28 -07001073 Task(const TaggedSrc& src, const TaggedSink& sink) : src(src), sink(sink) {}
1074 const TaggedSrc& src;
1075 const TaggedSink& sink;
mtklein748ca3b2015-01-15 10:56:12 -08001076
mtklein21eaf3b2016-02-08 12:39:59 -08001077 static void Run(const Task& task) {
1078 SkString name = task.src->name();
mtkleine0effd62015-07-29 06:37:28 -07001079
mtkleinb9eb4ac2015-02-02 18:26:03 -08001080 SkString log;
mtklein3eed7dd2016-02-24 19:07:07 -08001081 if (!FLAGS_dryRun) {
mtklein748ca3b2015-01-15 10:56:12 -08001082 SkBitmap bitmap;
1083 SkDynamicMemoryWStream stream;
mtklein3eed7dd2016-02-24 19:07:07 -08001084 start(task.sink.tag.c_str(), task.src.tag.c_str(),
1085 task.src.options.c_str(), name.c_str());
mtklein21eaf3b2016-02-08 12:39:59 -08001086 Error err = task.sink->draw(*task.src, &bitmap, &stream, &log);
mtkleinb3b13b72016-03-07 13:20:52 -08001087 if (!log.isEmpty()) {
mtkleinc41fd922016-03-08 09:01:39 -08001088 info("%s %s %s %s:\n%s\n", task.sink.tag.c_str()
1089 , task.src.tag.c_str()
1090 , task.src.options.c_str()
1091 , name.c_str()
1092 , log.c_str());
mtkleinb3b13b72016-03-07 13:20:52 -08001093 }
mtklein748ca3b2015-01-15 10:56:12 -08001094 if (!err.isEmpty()) {
mtklein4089ef72015-03-05 08:40:28 -08001095 if (err.isFatal()) {
djsollen54416de2015-04-03 07:24:48 -07001096 fail(SkStringPrintf("%s %s %s %s: %s",
mtklein21eaf3b2016-02-08 12:39:59 -08001097 task.sink.tag.c_str(),
1098 task.src.tag.c_str(),
1099 task.src.options.c_str(),
mtklein4089ef72015-03-05 08:40:28 -08001100 name.c_str(),
1101 err.c_str()));
mtkleinb37cb412015-03-18 05:27:14 -07001102 } else {
mtklein3eed7dd2016-02-24 19:07:07 -08001103 done(task.sink.tag.c_str(), task.src.tag.c_str(),
1104 task.src.options.c_str(), name.c_str());
mtkleinba6ada72016-01-21 09:39:35 -08001105 return;
mtklein4089ef72015-03-05 08:40:28 -08001106 }
mtklein748ca3b2015-01-15 10:56:12 -08001107 }
mtklein62bd1a62015-01-27 14:46:26 -08001108
mtkleincd50bca2016-01-05 06:20:20 -08001109 // We're likely switching threads here, so we must capture by value, [=] or [foo,bar].
Hal Canary0b833192017-03-14 14:35:02 -04001110 SkStreamAsset* data = stream.detachAsStream().release();
mtkleincd50bca2016-01-05 06:20:20 -08001111 gDefinitelyThreadSafeWork.add([task,name,bitmap,data]{
Ben Wagner145dbcd2016-11-03 14:40:50 -04001112 std::unique_ptr<SkStreamAsset> ownedData(data);
mtkleincd50bca2016-01-05 06:20:20 -08001113
mtkleincd50bca2016-01-05 06:20:20 -08001114 SkString md5;
1115 if (!FLAGS_writePath.isEmpty() || !FLAGS_readPath.isEmpty()) {
1116 SkMD5 hash;
1117 if (data->getLength()) {
1118 hash.writeStream(data, data->getLength());
1119 data->rewind();
mtklein38408462015-07-08 07:25:27 -07001120 } else {
mtkleincd50bca2016-01-05 06:20:20 -08001121 // If we're BGRA (Linux, Windows), swizzle over to RGBA (Mac, Android).
1122 // This helps eliminate multiple 0-pixel-diff hashes on gold.skia.org.
1123 // (Android's general slow speed breaks the tie arbitrarily in RGBA's favor.)
1124 // We might consider promoting 565 to RGBA too.
1125 if (bitmap.colorType() == kBGRA_8888_SkColorType) {
1126 SkBitmap swizzle;
Matt Sarett68b8e3d2017-04-28 11:15:22 -04001127 SkAssertResult(sk_tool_utils::copy_to(&swizzle, kRGBA_8888_SkColorType,
1128 bitmap));
mtkleincd50bca2016-01-05 06:20:20 -08001129 hash.write(swizzle.getPixels(), swizzle.getSize());
1130 } else {
1131 hash.write(bitmap.getPixels(), bitmap.getSize());
1132 }
1133 }
1134 SkMD5::Digest digest;
1135 hash.finish(digest);
1136 for (int i = 0; i < 16; i++) {
1137 md5.appendf("%02x", digest.data[i]);
mtklein38408462015-07-08 07:25:27 -07001138 }
mtklein62bd1a62015-01-27 14:46:26 -08001139 }
mtklein62bd1a62015-01-27 14:46:26 -08001140
mtkleincd50bca2016-01-05 06:20:20 -08001141 if (!FLAGS_readPath.isEmpty() &&
mtklein3eed7dd2016-02-24 19:07:07 -08001142 !gGold.contains(Gold(task.sink.tag, task.src.tag,
1143 task.src.options, name, md5))) {
mtkleincd50bca2016-01-05 06:20:20 -08001144 fail(SkStringPrintf("%s not found for %s %s %s %s in %s",
1145 md5.c_str(),
mtklein21eaf3b2016-02-08 12:39:59 -08001146 task.sink.tag.c_str(),
1147 task.src.tag.c_str(),
1148 task.src.options.c_str(),
mtkleincd50bca2016-01-05 06:20:20 -08001149 name.c_str(),
1150 FLAGS_readPath[0]));
mtklein748ca3b2015-01-15 10:56:12 -08001151 }
mtkleincd50bca2016-01-05 06:20:20 -08001152
1153 if (!FLAGS_writePath.isEmpty()) {
mtklein21eaf3b2016-02-08 12:39:59 -08001154 const char* ext = task.sink->fileExtension();
Brian Osmanf1942de2017-08-30 14:50:22 -04001155 if (ext && !FLAGS_dont_write.contains(ext)) {
Mike Klein97d6a7a2017-07-24 10:37:19 -04001156 if (data->getLength()) {
1157 WriteToDisk(task, md5, ext, data, data->getLength(), nullptr);
1158 SkASSERT(bitmap.drawsNothing());
1159 } else if (!bitmap.drawsNothing()) {
1160 WriteToDisk(task, md5, ext, nullptr, 0, &bitmap);
1161 }
mtkleincd50bca2016-01-05 06:20:20 -08001162 }
1163 }
1164 });
mtklein748ca3b2015-01-15 10:56:12 -08001165 }
mtklein3eed7dd2016-02-24 19:07:07 -08001166 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 -08001167 }
1168
1169 static void WriteToDisk(const Task& task,
mtklein62bd1a62015-01-27 14:46:26 -08001170 SkString md5,
1171 const char* ext,
mtklein748ca3b2015-01-15 10:56:12 -08001172 SkStream* data, size_t len,
mtklein62bd1a62015-01-27 14:46:26 -08001173 const SkBitmap* bitmap) {
mtklein409d4702016-02-29 07:38:01 -08001174 bool gammaCorrect = false;
1175 if (bitmap) {
Brian Osman7039f742016-11-01 15:56:16 -04001176 gammaCorrect = SkToBool(bitmap->info().colorSpace());
mtklein409d4702016-02-29 07:38:01 -08001177 }
1178
mtklein748ca3b2015-01-15 10:56:12 -08001179 JsonWriter::BitmapResult result;
djsollen54416de2015-04-03 07:24:48 -07001180 result.name = task.src->name();
mtklein3eed7dd2016-02-24 19:07:07 -08001181 result.config = task.sink.tag;
djsollen54416de2015-04-03 07:24:48 -07001182 result.sourceType = task.src.tag;
1183 result.sourceOptions = task.src.options;
1184 result.ext = ext;
mtklein409d4702016-02-29 07:38:01 -08001185 result.gammaCorrect = gammaCorrect;
djsollen54416de2015-04-03 07:24:48 -07001186 result.md5 = md5;
mtklein748ca3b2015-01-15 10:56:12 -08001187 JsonWriter::AddBitmapResult(result);
1188
mtkleinb0531a72015-04-07 13:38:48 -07001189 // If an MD5 is uninteresting, we want it noted in the JSON file,
1190 // but don't want to dump it out as a .png (or whatever ext is).
1191 if (gUninterestingHashes.contains(md5)) {
1192 return;
1193 }
1194
mtklein748ca3b2015-01-15 10:56:12 -08001195 const char* dir = FLAGS_writePath[0];
1196 if (0 == strcmp(dir, "@")) { // Needed for iOS.
1197 dir = FLAGS_resourcePath[0];
1198 }
1199 sk_mkdir(dir);
1200
1201 SkString path;
1202 if (FLAGS_nameByHash) {
1203 path = SkOSPath::Join(dir, result.md5.c_str());
1204 path.append(".");
1205 path.append(ext);
1206 if (sk_exists(path.c_str())) {
1207 return; // Content-addressed. If it exists already, we're done.
1208 }
1209 } else {
kkinnunen3e980c32015-12-23 01:33:00 -08001210 path = SkOSPath::Join(dir, task.sink.tag.c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001211 sk_mkdir(path.c_str());
msarett9e707a02015-09-01 14:57:57 -07001212 path = SkOSPath::Join(path.c_str(), task.src.tag.c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001213 sk_mkdir(path.c_str());
msarett9e707a02015-09-01 14:57:57 -07001214 if (strcmp(task.src.options.c_str(), "") != 0) {
1215 path = SkOSPath::Join(path.c_str(), task.src.options.c_str());
djsollen54416de2015-04-03 07:24:48 -07001216 sk_mkdir(path.c_str());
1217 }
mtklein748ca3b2015-01-15 10:56:12 -08001218 path = SkOSPath::Join(path.c_str(), task.src->name().c_str());
1219 path.append(".");
1220 path.append(ext);
1221 }
1222
mtklein748ca3b2015-01-15 10:56:12 -08001223 if (bitmap) {
mtkleina5114d72015-08-24 13:27:01 -07001224 if (!dump_png(*bitmap, path.c_str(), result.md5.c_str())) {
mtklein748ca3b2015-01-15 10:56:12 -08001225 fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str()));
1226 return;
1227 }
1228 } else {
mtkleina5114d72015-08-24 13:27:01 -07001229 SkFILEWStream file(path.c_str());
1230 if (!file.isValid()) {
1231 fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str()));
1232 return;
1233 }
mtklein748ca3b2015-01-15 10:56:12 -08001234 if (!file.writeStream(data, len)) {
1235 fail(SkStringPrintf("Can't write to %s.\n", path.c_str()));
1236 return;
1237 }
1238 }
1239 }
1240};
1241
mtklein748ca3b2015-01-15 10:56:12 -08001242/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1243
1244// Unit tests don't fit so well into the Src/Sink model, so we give them special treatment.
1245
mtklein21eaf3b2016-02-08 12:39:59 -08001246static SkTDArray<skiatest::Test> gParallelTests, gSerialTests;
mtklein748ca3b2015-01-15 10:56:12 -08001247
1248static void gather_tests() {
mtklein6c5fed22015-01-20 13:47:23 -08001249 if (!FLAGS_src.contains("tests")) {
mtklein748ca3b2015-01-15 10:56:12 -08001250 return;
1251 }
mtklein6393c062015-04-27 08:45:01 -07001252 for (const skiatest::TestRegistry* r = skiatest::TestRegistry::Head(); r; r = r->next()) {
1253 if (!in_shard()) {
1254 continue;
1255 }
halcanary87f3ba42015-01-20 09:30:20 -08001256 // Despite its name, factory() is returning a reference to
1257 // link-time static const POD data.
1258 const skiatest::Test& test = r->factory();
1259 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, test.name)) {
mtklein748ca3b2015-01-15 10:56:12 -08001260 continue;
1261 }
halcanary87f3ba42015-01-20 09:30:20 -08001262 if (test.needsGpu && gpu_supported()) {
mtklein21eaf3b2016-02-08 12:39:59 -08001263 (FLAGS_gpu_threading ? gParallelTests : gSerialTests).push(test);
halcanary87f3ba42015-01-20 09:30:20 -08001264 } else if (!test.needsGpu && FLAGS_cpu) {
mtklein21eaf3b2016-02-08 12:39:59 -08001265 gParallelTests.push(test);
mtklein82d28432015-01-15 12:46:02 -08001266 }
mtklein748ca3b2015-01-15 10:56:12 -08001267 }
1268}
1269
csmartdalton008b9d82017-02-22 12:00:42 -07001270static void run_test(skiatest::Test test, const GrContextOptions& grCtxOptions) {
halcanary87f3ba42015-01-20 09:30:20 -08001271 struct : public skiatest::Reporter {
mtklein36352bf2015-03-25 18:17:31 -07001272 void reportFailed(const skiatest::Failure& failure) override {
halcanary87f3ba42015-01-20 09:30:20 -08001273 fail(failure.toString());
1274 JsonWriter::AddTestFailure(failure);
1275 }
mtklein36352bf2015-03-25 18:17:31 -07001276 bool allowExtendedTest() const override {
halcanary87f3ba42015-01-20 09:30:20 -08001277 return FLAGS_pathOpsExtended;
1278 }
mtklein36352bf2015-03-25 18:17:31 -07001279 bool verbose() const override { return FLAGS_veryVerbose; }
halcanary87f3ba42015-01-20 09:30:20 -08001280 } reporter;
djsollen824996a2015-06-12 12:06:22 -07001281
mtklein3eed7dd2016-02-24 19:07:07 -08001282 if (!FLAGS_dryRun && !is_blacklisted("_", "tests", "_", test.name)) {
mtklein21eaf3b2016-02-08 12:39:59 -08001283 start("unit", "test", "", test.name);
csmartdalton008b9d82017-02-22 12:00:42 -07001284 GrContextFactory factory(grCtxOptions);
Mike Kleinb323a5e2017-07-24 15:21:31 -04001285 test.run(&reporter, &factory);
mtklein748ca3b2015-01-15 10:56:12 -08001286 }
mtklein3eed7dd2016-02-24 19:07:07 -08001287 done("unit", "test", "", test.name);
mtklein748ca3b2015-01-15 10:56:12 -08001288}
1289
1290/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1291
caryclark83ca6282015-06-10 09:31:09 -07001292#define PORTABLE_FONT_PREFIX "Toy Liberation "
1293
mbocee6a9912016-05-31 11:42:36 -07001294static sk_sp<SkTypeface> create_from_name(const char familyName[], SkFontStyle style) {
caryclark83ca6282015-06-10 09:31:09 -07001295 if (familyName && strlen(familyName) > sizeof(PORTABLE_FONT_PREFIX)
1296 && !strncmp(familyName, PORTABLE_FONT_PREFIX, sizeof(PORTABLE_FONT_PREFIX) - 1)) {
caryclark1818acb2015-07-24 12:09:25 -07001297 return sk_tool_utils::create_portable_typeface(familyName, style);
caryclark83ca6282015-06-10 09:31:09 -07001298 }
halcanary96fcdcc2015-08-27 07:41:13 -07001299 return nullptr;
caryclark83ca6282015-06-10 09:31:09 -07001300}
1301
1302#undef PORTABLE_FONT_PREFIX
1303
mbocee6a9912016-05-31 11:42:36 -07001304extern sk_sp<SkTypeface> (*gCreateTypefaceDelegate)(const char [], SkFontStyle );
caryclark83ca6282015-06-10 09:31:09 -07001305
Mike Kleinbe28ee22017-02-06 12:46:20 -05001306int main(int argc, char** argv) {
1307 SkCommandLineFlags::Parse(argc, argv);
Brian Osman53136aa2017-07-20 15:43:35 -04001308
Brian Osmanbc8150f2017-07-24 11:38:01 -04001309 initializeEventTracingForTools();
Brian Osman53136aa2017-07-20 15:43:35 -04001310
Mike Klein135a1b12017-08-15 13:13:59 -04001311#if !defined(GOOGLE3) && defined(SK_BUILD_FOR_IOS)
Mike Kleinadacaef2017-02-06 09:26:14 -05001312 cd_Documents();
1313#endif
bsalomon71de3532016-04-26 14:27:21 -07001314 setbuf(stdout, nullptr);
mtklein246ba3a2016-02-23 10:39:36 -08001315 setup_crash_handler();
mtkleinafae30a2016-02-24 12:28:32 -08001316
Yuqian Liba62b4a2016-12-14 13:46:53 -05001317 gSkUseAnalyticAA = FLAGS_analyticAA;
Yuqian Lidf60e362017-07-25 11:26:31 -04001318 gSkUseDeltaAA = FLAGS_deltaAA;
liyuqian38911a72016-10-04 11:23:22 -07001319
Yuqian Li550148b2017-01-13 10:13:13 -05001320 if (FLAGS_forceAnalyticAA) {
1321 gSkForceAnalyticAA = true;
1322 }
Mike Reed7c26ca72017-07-05 15:45:52 -04001323 if (FLAGS_forceRasterPipeline) {
1324 gSkForceRasterPipelineBlitter = true;
1325 }
Yuqian Li550148b2017-01-13 10:13:13 -05001326
Mike Kleine9f187b2017-06-26 13:23:12 -04001327 // The bots like having a verbose.log to upload, so always touch the file even if --verbose.
1328 if (!FLAGS_writePath.isEmpty()) {
mtklein51c8cfc2016-03-11 12:59:09 -08001329 sk_mkdir(FLAGS_writePath[0]);
mtkleina1ce2162016-07-22 12:23:46 -07001330 gVLog = fopen(SkOSPath::Join(FLAGS_writePath[0], "verbose.log").c_str(), "w");
mtkleinc41fd922016-03-08 09:01:39 -08001331 }
Mike Kleine9f187b2017-06-26 13:23:12 -04001332 if (FLAGS_verbose) {
1333 gVLog = stderr;
1334 }
mtkleinc41fd922016-03-08 09:01:39 -08001335
csmartdalton008b9d82017-02-22 12:00:42 -07001336 GrContextOptions grCtxOptions;
1337#if SK_SUPPORT_GPU
1338 grCtxOptions.fGpuPathRenderers = CollectGpuPathRenderersFromFlags();
Brian Osmanf9810662017-08-30 10:02:10 -04001339 grCtxOptions.fExecutor = GpuExecutorForTools();
csmartdalton008b9d82017-02-22 12:00:42 -07001340#endif
1341
mtklein5286f022016-01-22 08:18:14 -08001342 JsonWriter::DumpJson(); // It's handy for the bots to assume this is ~never missing.
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +00001343 SkAutoGraphics ag;
mtklein406654b2014-09-03 15:34:37 -07001344 SkTaskGroup::Enabler enabled(FLAGS_threads);
caryclark83ca6282015-06-10 09:31:09 -07001345 gCreateTypefaceDelegate = &create_from_name;
commit-bot@chromium.orga65e2fd2014-05-30 17:23:31 +00001346
halcanary7d571242016-02-24 17:59:16 -08001347 {
1348 SkString testResourcePath = GetResourcePath("color_wheel.png");
1349 SkFILEStream testResource(testResourcePath.c_str());
1350 if (!testResource.isValid()) {
mtkleinc41fd922016-03-08 09:01:39 -08001351 info("Some resources are missing. Do you need to set --resourcePath?\n");
halcanary7d571242016-02-24 17:59:16 -08001352 }
1353 }
mtklein62bd1a62015-01-27 14:46:26 -08001354 gather_gold();
borenet09ed4802015-04-03 14:15:33 -07001355 gather_uninteresting_hashes();
mtklein62bd1a62015-01-27 14:46:26 -08001356
scroggo86737142016-02-03 12:19:11 -08001357 if (!gather_srcs()) {
1358 return 1;
1359 }
Ben Wagnerf28d4722017-08-11 17:33:22 -04001360 // TODO(dogben): This is a bit ugly. Find a cleaner way to do this.
1361 bool defaultConfigs = true;
1362 for (int i = 0; i < argc; i++) {
1363 static const char* kConfigArg = "--config";
1364 if (strcmp(argv[i], kConfigArg) == 0) {
1365 defaultConfigs = false;
1366 break;
1367 }
1368 }
1369 if (!gather_sinks(grCtxOptions, defaultConfigs)) {
brianosman05c987c2016-05-09 13:42:16 -07001370 return 1;
1371 }
mtklein748ca3b2015-01-15 10:56:12 -08001372 gather_tests();
mtklein21eaf3b2016-02-08 12:39:59 -08001373 gPending = gSrcs.count() * gSinks.count() + gParallelTests.count() + gSerialTests.count();
Brian Osmand0677bc2017-08-03 12:13:47 -04001374 info("%d srcs * %d sinks + %d tests == %d tasks\n",
mtkleinc41fd922016-03-08 09:01:39 -08001375 gSrcs.count(), gSinks.count(), gParallelTests.count() + gSerialTests.count(), gPending);
mtklein748ca3b2015-01-15 10:56:12 -08001376
mtklein21eaf3b2016-02-08 12:39:59 -08001377 // Kick off as much parallel work as we can, making note of any serial work we'll need to do.
1378 SkTaskGroup parallel;
1379 SkTArray<Task> serial;
1380
1381 for (auto& sink : gSinks)
1382 for (auto& src : gSrcs) {
mtklein3eed7dd2016-02-24 19:07:07 -08001383 if (src->veto(sink->flags()) ||
1384 is_blacklisted(sink.tag.c_str(), src.tag.c_str(),
1385 src.options.c_str(), src->name().c_str())) {
mtkleinf10637f2016-06-10 13:56:35 -07001386 SkAutoMutexAcquire lock(gMutex);
mtklein3eed7dd2016-02-24 19:07:07 -08001387 gPending--;
1388 continue;
1389 }
1390
mtklein21eaf3b2016-02-08 12:39:59 -08001391 Task task(src, sink);
1392 if (src->serial() || sink->serial()) {
1393 serial.push_back(task);
1394 } else {
1395 parallel.add([task] { Task::Run(task); });
mtklein748ca3b2015-01-15 10:56:12 -08001396 }
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001397 }
mtklein21eaf3b2016-02-08 12:39:59 -08001398 for (auto test : gParallelTests) {
csmartdalton008b9d82017-02-22 12:00:42 -07001399 parallel.add([test, grCtxOptions] { run_test(test, grCtxOptions); });
mtklein55e88b22015-01-21 15:50:13 -08001400 }
mtklein21eaf3b2016-02-08 12:39:59 -08001401
1402 // With the parallel work running, run serial tasks and tests here on main thread.
1403 for (auto task : serial) { Task::Run(task); }
csmartdalton008b9d82017-02-22 12:00:42 -07001404 for (auto test : gSerialTests) { run_test(test, grCtxOptions); }
mtklein21eaf3b2016-02-08 12:39:59 -08001405
1406 // Wait for any remaining parallel work to complete (including any spun off of serial tasks).
1407 parallel.wait();
mtkleincd50bca2016-01-05 06:20:20 -08001408 gDefinitelyThreadSafeWork.wait();
1409
mtkleinda884c42016-02-24 18:00:23 -08001410 // We'd better have run everything.
1411 SkASSERT(gPending == 0);
mtkleine027f172016-02-26 15:53:06 -08001412 // Make sure we've flushed all our results to disk.
1413 JsonWriter::DumpJson();
mtkleinda884c42016-02-24 18:00:23 -08001414
mtklein748ca3b2015-01-15 10:56:12 -08001415 // At this point we're back in single-threaded land.
caryclarkf53ce802015-06-15 06:48:30 -07001416 sk_tool_utils::release_portable_typefaces();
mtklein@google.comd36522d2013-10-16 13:02:15 +00001417
mtklein748ca3b2015-01-15 10:56:12 -08001418 if (gFailures.count() > 0) {
mtkleinc41fd922016-03-08 09:01:39 -08001419 info("Failures:\n");
mtklein748ca3b2015-01-15 10:56:12 -08001420 for (int i = 0; i < gFailures.count(); i++) {
mtkleinc41fd922016-03-08 09:01:39 -08001421 info("\t%s\n", gFailures[i].c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001422 }
mtkleinc41fd922016-03-08 09:01:39 -08001423 info("%d failures\n", gFailures.count());
mtklein748ca3b2015-01-15 10:56:12 -08001424 return 1;
mtklein114c3cd2015-01-15 10:15:02 -08001425 }
mtkleinafae30a2016-02-24 12:28:32 -08001426
1427#ifdef SK_PDF_IMAGE_STATS
halcanary7a14b312015-10-01 07:28:13 -07001428 SkPDFImageDumpStats();
mtkleinafae30a2016-02-24 12:28:32 -08001429#endif // SK_PDF_IMAGE_STATS
1430
Herb Derby5a523fe2017-01-26 16:48:28 -05001431 SkGraphics::PurgeAllCaches();
mtkleinc41fd922016-03-08 09:01:39 -08001432 info("Finished!\n");
Brian Osman53136aa2017-07-20 15:43:35 -04001433
mtklein748ca3b2015-01-15 10:56:12 -08001434 return 0;
mtklein@google.comd36522d2013-10-16 13:02:15 +00001435}
jcgregorio3b27ade2014-11-13 08:06:40 -08001436
kkinnunen179a8f52015-11-20 13:32:24 -08001437// TODO: currently many GPU tests are declared outside SK_SUPPORT_GPU guards.
1438// Thus we export the empty RunWithGPUTestContexts when SK_SUPPORT_GPU=0.
1439namespace skiatest {
bsalomon758586c2016-04-06 14:02:39 -07001440
1441#if SK_SUPPORT_GPU
1442bool IsGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
1443 return kOpenGL_GrBackend == GrContextFactory::ContextTypeBackend(type);
1444}
bsalomondc0fcd42016-04-11 14:21:33 -07001445bool IsVulkanContextType(sk_gpu_test::GrContextFactory::ContextType type) {
1446 return kVulkan_GrBackend == GrContextFactory::ContextTypeBackend(type);
1447}
bsalomon758586c2016-04-06 14:02:39 -07001448bool IsRenderingGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
1449 return IsGLContextType(type) && GrContextFactory::IsRenderingContext(type);
1450}
1451bool IsNullGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
1452 return type == GrContextFactory::kNullGL_ContextType;
1453}
1454#else
1455bool IsGLContextType(int) { return false; }
bsalomondc0fcd42016-04-11 14:21:33 -07001456bool IsVulkanContextType(int) { return false; }
bsalomon758586c2016-04-06 14:02:39 -07001457bool IsRenderingGLContextType(int) { return false; }
1458bool IsNullGLContextType(int) { return false; }
1459#endif
1460
1461void RunWithGPUTestContexts(GrContextTestFn* test, GrContextTypeFilterFn* contextTypeFilter,
bsalomonf2f1c172016-04-05 12:59:06 -07001462 Reporter* reporter, GrContextFactory* factory) {
kkinnunen179a8f52015-11-20 13:32:24 -08001463#if SK_SUPPORT_GPU
kkinnunen3e980c32015-12-23 01:33:00 -08001464
Brian Salomon6405e712017-03-20 08:54:16 -04001465#if defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_WIN) || defined(SK_BUILD_FOR_MAC)
1466 static constexpr auto kNativeGLType = GrContextFactory::kGL_ContextType;
1467#else
1468 static constexpr auto kNativeGLType = GrContextFactory::kGLES_ContextType;
1469#endif
1470
bsalomon758586c2016-04-06 14:02:39 -07001471 for (int typeInt = 0; typeInt < GrContextFactory::kContextTypeCnt; ++typeInt) {
1472 GrContextFactory::ContextType contextType = (GrContextFactory::ContextType) typeInt;
Brian Osmanaa2219c2016-12-05 10:12:17 -05001473 // Use "native" instead of explicitly trying OpenGL and OpenGL ES. Do not use GLES on
bsalomon758586c2016-04-06 14:02:39 -07001474 // desktop since tests do not account for not fixing http://skbug.com/2809
1475 if (contextType == GrContextFactory::kGL_ContextType ||
1476 contextType == GrContextFactory::kGLES_ContextType) {
Brian Salomon6405e712017-03-20 08:54:16 -04001477 if (contextType != kNativeGLType) {
bsalomon758586c2016-04-06 14:02:39 -07001478 continue;
1479 }
1480 }
csmartdaltone812d492017-02-21 12:36:05 -07001481 ContextInfo ctxInfo = factory->getContextInfo(contextType,
1482 GrContextFactory::ContextOverrides::kDisableNVPR);
Brian Osmanaa2219c2016-12-05 10:12:17 -05001483 if (contextTypeFilter && !(*contextTypeFilter)(contextType)) {
1484 continue;
1485 }
Greg Daniela5cb7812017-06-16 09:45:32 -04001486 ReporterContext ctx(reporter, SkString(GrContextFactory::ContextTypeName(contextType)));
bsalomon8b7451a2016-05-11 06:33:06 -07001487 if (ctxInfo.grContext()) {
bsalomonf2f1c172016-04-05 12:59:06 -07001488 (*test)(reporter, ctxInfo);
Robert Phillipseaa90b22017-08-01 10:36:36 -04001489 ctxInfo.grContext()->flush();
kkinnunen5219fd92015-12-10 06:28:13 -08001490 }
bsalomonf2f1c172016-04-05 12:59:06 -07001491 ctxInfo = factory->getContextInfo(contextType,
csmartdaltone812d492017-02-21 12:36:05 -07001492 GrContextFactory::ContextOverrides::kRequireNVPRSupport);
bsalomon8b7451a2016-05-11 06:33:06 -07001493 if (ctxInfo.grContext()) {
bsalomonf2f1c172016-04-05 12:59:06 -07001494 (*test)(reporter, ctxInfo);
Robert Phillipseaa90b22017-08-01 10:36:36 -04001495 ctxInfo.grContext()->flush();
kkinnunen179a8f52015-11-20 13:32:24 -08001496 }
1497 }
1498#endif
1499}
kkinnunen179a8f52015-11-20 13:32:24 -08001500} // namespace skiatest