blob: 1e02d25b7b1d0232a0fbef12024384f1f972ed88 [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
csmartdalton008b9d82017-02-22 12:00:42 -070095#if SK_SUPPORT_GPU
96DEFINE_pathrenderer_flag;
97#endif
98
Derek Sollenbergeredfe3df2017-07-19 15:25:24 -040099DEFINE_bool(ignoreSigInt, false, "ignore SIGINT signals during test execution");
100
Mike Klein97d6a7a2017-07-24 10:37:19 -0400101DEFINE_string(dont_write, "", "File extensions to skip writing to --writePath."); // See skia:6821
102
mtklein748ca3b2015-01-15 10:56:12 -0800103using namespace DM;
bsalomon3724e572016-03-30 18:56:19 -0700104using sk_gpu_test::GrContextFactory;
bsalomon273c0f52016-03-31 10:59:06 -0700105using sk_gpu_test::GLTestContext;
bsalomonf2f1c172016-04-05 12:59:06 -0700106using sk_gpu_test::ContextInfo;
mtklein@google.comd36522d2013-10-16 13:02:15 +0000107
mtklein748ca3b2015-01-15 10:56:12 -0800108/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
109
benjaminwagnerec4d4d72016-03-25 12:59:53 -0700110static const double kStartMs = SkTime::GetMSecs();
mtkleinc41fd922016-03-08 09:01:39 -0800111
112static FILE* gVLog;
113
114template <typename... Args>
115static void vlog(const char* fmt, Args&&... args) {
116 if (gVLog) {
117 fprintf(gVLog, "%s\t", HumanizeMs(SkTime::GetMSecs() - kStartMs).c_str());
118 fprintf(gVLog, fmt, args...);
119 fflush(gVLog);
120 }
121}
122
123template <typename... Args>
124static void info(const char* fmt, Args&&... args) {
125 vlog(fmt, args...);
126 if (!FLAGS_quiet) {
127 printf(fmt, args...);
128 }
129}
130static void info(const char* fmt) {
131 if (!FLAGS_quiet) {
132 printf("%s", fmt); // Clang warns printf(fmt) is insecure.
133 }
134}
135
reed086eea92016-05-04 17:12:46 -0700136SK_DECLARE_STATIC_MUTEX(gFailuresMutex);
mtklein748ca3b2015-01-15 10:56:12 -0800137static SkTArray<SkString> gFailures;
138
mtklein3eed7dd2016-02-24 19:07:07 -0800139static void fail(const SkString& err) {
mtklein748ca3b2015-01-15 10:56:12 -0800140 SkAutoMutexAcquire lock(gFailuresMutex);
141 SkDebugf("\n\nFAILURE: %s\n\n", err.c_str());
142 gFailures.push_back(err);
halcanary9e398f72015-01-10 11:18:04 -0800143}
144
mtklein0f7748a2016-07-25 15:27:29 -0700145struct Running {
146 SkString id;
147 SkThreadID thread;
148
149 void dump() const {
150 info("\t%s\n", id.c_str());
151 }
152};
mtkleinb37cb412015-03-18 05:27:14 -0700153
mtklein246ba3a2016-02-23 10:39:36 -0800154// We use a spinlock to make locking this in a signal handler _somewhat_ safe.
Mike Klein03a95ad2017-06-23 12:36:32 -0400155static SkSpinlock gMutex;
156static int gPending;
mtklein0f7748a2016-07-25 15:27:29 -0700157static SkTArray<Running> gRunning;
mtklein748ca3b2015-01-15 10:56:12 -0800158
mtklein3eed7dd2016-02-24 19:07:07 -0800159static void done(const char* config, const char* src, const char* srcOptions, const char* name) {
160 SkString id = SkStringPrintf("%s %s %s %s", config, src, srcOptions, name);
mtkleinc41fd922016-03-08 09:01:39 -0800161 vlog("done %s\n", id.c_str());
mtkleinafae30a2016-02-24 12:28:32 -0800162 int pending;
mtkleinb37cb412015-03-18 05:27:14 -0700163 {
mtkleinf10637f2016-06-10 13:56:35 -0700164 SkAutoMutexAcquire lock(gMutex);
mtkleinb37cb412015-03-18 05:27:14 -0700165 for (int i = 0; i < gRunning.count(); i++) {
mtklein0f7748a2016-07-25 15:27:29 -0700166 if (gRunning[i].id == id) {
mtkleinb37cb412015-03-18 05:27:14 -0700167 gRunning.removeShuffle(i);
168 break;
169 }
170 }
mtkleinafae30a2016-02-24 12:28:32 -0800171 pending = --gPending;
reed50bc0512015-05-19 14:13:31 -0700172 }
Mike Klein03a95ad2017-06-23 12:36:32 -0400173
174 // We write out dm.json file and print out a progress update every once in a while.
175 // Notice this also handles the final dm.json and progress update when pending == 0.
mtkleina17241b2015-01-23 05:48:00 -0800176 if (pending % 500 == 0) {
177 JsonWriter::DumpJson();
Mike Klein03a95ad2017-06-23 12:36:32 -0400178
179 int curr = sk_tools::getCurrResidentSetSizeMB(),
180 peak = sk_tools::getMaxResidentSetSizeMB();
181 SkString elapsed = HumanizeMs(SkTime::GetMSecs() - kStartMs);
182
183 SkAutoMutexAcquire lock(gMutex);
184 info("\n%dMB RAM, %dMB peak, %s elapsed, %d queued, %d active:\n",
185 curr, peak, elapsed.c_str(), gPending - gRunning.count(), gRunning.count());
186 for (auto& task : gRunning) {
187 task.dump();
188 }
mtkleina17241b2015-01-23 05:48:00 -0800189 }
mtklein@google.comd36522d2013-10-16 13:02:15 +0000190}
191
mtklein3eed7dd2016-02-24 19:07:07 -0800192static void start(const char* config, const char* src, const char* srcOptions, const char* name) {
193 SkString id = SkStringPrintf("%s %s %s %s", config, src, srcOptions, name);
mtkleinc41fd922016-03-08 09:01:39 -0800194 vlog("start %s\n", id.c_str());
mtkleinf10637f2016-06-10 13:56:35 -0700195 SkAutoMutexAcquire lock(gMutex);
mtklein0f7748a2016-07-25 15:27:29 -0700196 gRunning.push_back({id,SkGetThreadID()});
mtkleinb37cb412015-03-18 05:27:14 -0700197}
198
Mike Klein3cc2d202016-10-24 11:39:43 -0400199static void find_culprit() {
200 // Assumes gMutex is locked.
201 SkThreadID thisThread = SkGetThreadID();
202 for (auto& task : gRunning) {
203 if (task.thread == thisThread) {
204 info("Likely culprit:\n");
205 task.dump();
mtklein0f7748a2016-07-25 15:27:29 -0700206 }
207 }
Mike Klein3cc2d202016-10-24 11:39:43 -0400208}
mtklein0f7748a2016-07-25 15:27:29 -0700209
mtklein246ba3a2016-02-23 10:39:36 -0800210#if defined(SK_BUILD_FOR_WIN32)
mtklein5b64dab2016-06-09 08:59:48 -0700211 static LONG WINAPI crash_handler(EXCEPTION_POINTERS* e) {
mtkleinf8557292016-02-29 06:35:28 -0800212 static const struct {
213 const char* name;
robertphillips75467862016-03-01 14:10:23 -0800214 DWORD code;
mtkleinf8557292016-02-29 06:35:28 -0800215 } kExceptions[] = {
216 #define _(E) {#E, E}
217 _(EXCEPTION_ACCESS_VIOLATION),
218 _(EXCEPTION_BREAKPOINT),
219 _(EXCEPTION_INT_DIVIDE_BY_ZERO),
220 _(EXCEPTION_STACK_OVERFLOW),
221 // TODO: more?
222 #undef _
223 };
224
mtkleinf10637f2016-06-10 13:56:35 -0700225 SkAutoMutexAcquire lock(gMutex);
mtklein5b64dab2016-06-09 08:59:48 -0700226
227 const DWORD code = e->ExceptionRecord->ExceptionCode;
228 info("\nCaught exception %u", code);
229 for (const auto& exception : kExceptions) {
230 if (exception.code == code) {
231 info(" %s", exception.name);
mtkleinf8557292016-02-29 06:35:28 -0800232 }
mtkleinf8557292016-02-29 06:35:28 -0800233 }
mtklein5b64dab2016-06-09 08:59:48 -0700234 info(", was running:\n");
235 for (auto& task : gRunning) {
mtklein0f7748a2016-07-25 15:27:29 -0700236 task.dump();
mtklein5b64dab2016-06-09 08:59:48 -0700237 }
mtklein0f7748a2016-07-25 15:27:29 -0700238 find_culprit();
mtklein5b64dab2016-06-09 08:59:48 -0700239 fflush(stdout);
240
mtkleinf8557292016-02-29 06:35:28 -0800241 // Execute default exception handler... hopefully, exit.
242 return EXCEPTION_EXECUTE_HANDLER;
mtklein246ba3a2016-02-23 10:39:36 -0800243 }
244
Mike Klein3cc2d202016-10-24 11:39:43 -0400245 static void setup_crash_handler() {
246 SetUnhandledExceptionFilter(crash_handler);
247 }
248#else
mtklein246ba3a2016-02-23 10:39:36 -0800249 #include <signal.h>
Mike Klein3cc2d202016-10-24 11:39:43 -0400250 #if !defined(SK_BUILD_FOR_ANDROID)
251 #include <execinfo.h>
Brian Salomondcbb9d92017-07-19 10:53:20 -0400252
253#endif
Mike Klein3cc2d202016-10-24 11:39:43 -0400254
255 static constexpr int max_of() { return 0; }
256 template <typename... Rest>
257 static constexpr int max_of(int x, Rest... rest) {
258 return x > max_of(rest...) ? x : max_of(rest...);
259 }
260
261 static void (*previous_handler[max_of(SIGABRT,SIGBUS,SIGFPE,SIGILL,SIGSEGV)+1])(int);
mtkleinf8557292016-02-29 06:35:28 -0800262
mtklein5b64dab2016-06-09 08:59:48 -0700263 static void crash_handler(int sig) {
mtkleinf10637f2016-06-10 13:56:35 -0700264 SkAutoMutexAcquire lock(gMutex);
mtklein5b64dab2016-06-09 08:59:48 -0700265
266 info("\nCaught signal %d [%s], was running:\n", sig, strsignal(sig));
267 for (auto& task : gRunning) {
mtklein0f7748a2016-07-25 15:27:29 -0700268 task.dump();
mtklein5b64dab2016-06-09 08:59:48 -0700269 }
mtklein0f7748a2016-07-25 15:27:29 -0700270 find_culprit();
mtklein5b64dab2016-06-09 08:59:48 -0700271
Mike Klein3cc2d202016-10-24 11:39:43 -0400272 #if !defined(SK_BUILD_FOR_ANDROID)
mtklein5b64dab2016-06-09 08:59:48 -0700273 void* stack[64];
274 int count = backtrace(stack, SK_ARRAY_COUNT(stack));
275 char** symbols = backtrace_symbols(stack, count);
276 info("\nStack trace:\n");
277 for (int i = 0; i < count; i++) {
278 info(" %s\n", symbols[i]);
279 }
Mike Klein3cc2d202016-10-24 11:39:43 -0400280 #endif
mtklein5b64dab2016-06-09 08:59:48 -0700281 fflush(stdout);
282
Mike Klein3cc2d202016-10-24 11:39:43 -0400283 signal(sig, previous_handler[sig]);
284 raise(sig);
mtklein5b64dab2016-06-09 08:59:48 -0700285 }
286
mtklein246ba3a2016-02-23 10:39:36 -0800287 static void setup_crash_handler() {
288 const int kSignals[] = { SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGSEGV };
289 for (int sig : kSignals) {
Mike Klein3cc2d202016-10-24 11:39:43 -0400290 previous_handler[sig] = signal(sig, crash_handler);
mtklein246ba3a2016-02-23 10:39:36 -0800291 }
Derek Sollenbergeredfe3df2017-07-19 15:25:24 -0400292
293 if (FLAGS_ignoreSigInt) {
294 signal(SIGINT, SIG_IGN);
295 }
mtklein246ba3a2016-02-23 10:39:36 -0800296 }
297#endif
298
mtklein748ca3b2015-01-15 10:56:12 -0800299/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
mtklein114c3cd2015-01-15 10:15:02 -0800300
mtklein62bd1a62015-01-27 14:46:26 -0800301struct Gold : public SkString {
mtkleina82f5622015-02-20 12:30:19 -0800302 Gold() : SkString("") {}
mtklein3eed7dd2016-02-24 19:07:07 -0800303 Gold(const SkString& sink, const SkString& src,
304 const SkString& srcOptions, const SkString& name,
305 const SkString& md5)
mtklein62bd1a62015-01-27 14:46:26 -0800306 : SkString("") {
307 this->append(sink);
308 this->append(src);
djsollen54416de2015-04-03 07:24:48 -0700309 this->append(srcOptions);
mtklein62bd1a62015-01-27 14:46:26 -0800310 this->append(name);
311 this->append(md5);
mtklein62bd1a62015-01-27 14:46:26 -0800312 }
mtkleinc8d1dd42015-10-15 12:23:01 -0700313 struct Hash {
314 uint32_t operator()(const Gold& g) const {
315 return SkGoodHash()((const SkString&)g);
316 }
317 };
mtklein62bd1a62015-01-27 14:46:26 -0800318};
mtkleina82f5622015-02-20 12:30:19 -0800319static SkTHashSet<Gold, Gold::Hash> gGold;
mtklein62bd1a62015-01-27 14:46:26 -0800320
321static void add_gold(JsonWriter::BitmapResult r) {
djsollen54416de2015-04-03 07:24:48 -0700322 gGold.add(Gold(r.config, r.sourceType, r.sourceOptions, r.name, r.md5));
mtklein62bd1a62015-01-27 14:46:26 -0800323}
324
325static void gather_gold() {
326 if (!FLAGS_readPath.isEmpty()) {
327 SkString path(FLAGS_readPath[0]);
328 path.append("/dm.json");
329 if (!JsonWriter::ReadJson(path.c_str(), add_gold)) {
330 fail(SkStringPrintf("Couldn't read %s for golden results.", path.c_str()));
331 }
332 }
333}
334
335/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
336
mtklein935f1b12016-03-16 08:37:19 -0700337#if defined(SK_BUILD_FOR_WIN32)
338 static const char* kNewline = "\r\n";
339#else
340 static const char* kNewline = "\n";
341#endif
342
borenet09ed4802015-04-03 14:15:33 -0700343static SkTHashSet<SkString> gUninterestingHashes;
344
345static void gather_uninteresting_hashes() {
346 if (!FLAGS_uninterestingHashesFile.isEmpty()) {
bungeman38d909e2016-08-02 14:40:46 -0700347 sk_sp<SkData> data(SkData::MakeFromFileName(FLAGS_uninterestingHashesFile[0]));
mtkleincc334b32015-09-22 11:43:53 -0700348 if (!data) {
mtkleinc41fd922016-03-08 09:01:39 -0800349 info("WARNING: unable to read uninteresting hashes from %s\n",
350 FLAGS_uninterestingHashesFile[0]);
mtkleincc334b32015-09-22 11:43:53 -0700351 return;
352 }
Mike Klein45dcc0c2017-04-05 18:04:31 -0400353
354 // Copy to a string to make sure SkStrSplit has a terminating \0 to find.
355 SkString contents((const char*)data->data(), data->size());
356
borenet09ed4802015-04-03 14:15:33 -0700357 SkTArray<SkString> hashes;
Mike Klein45dcc0c2017-04-05 18:04:31 -0400358 SkStrSplit(contents.c_str(), kNewline, &hashes);
borenet09ed4802015-04-03 14:15:33 -0700359 for (const SkString& hash : hashes) {
360 gUninterestingHashes.add(hash);
361 }
mtkleinc41fd922016-03-08 09:01:39 -0800362 info("FYI: loaded %d distinct uninteresting hashes from %d lines\n",
363 gUninterestingHashes.count(), hashes.count());
borenet09ed4802015-04-03 14:15:33 -0700364 }
365}
366
367/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
368
Ben Wagner145dbcd2016-11-03 14:40:50 -0400369struct TaggedSrc : public std::unique_ptr<Src> {
mtklein3eed7dd2016-02-24 19:07:07 -0800370 SkString tag;
371 SkString options;
mtkleine0effd62015-07-29 06:37:28 -0700372};
373
Ben Wagner145dbcd2016-11-03 14:40:50 -0400374struct TaggedSink : public std::unique_ptr<Sink> {
kkinnunen3e980c32015-12-23 01:33:00 -0800375 SkString tag;
djsollen54416de2015-04-03 07:24:48 -0700376};
mtklein748ca3b2015-01-15 10:56:12 -0800377
378static const bool kMemcpyOK = true;
379
mtkleine0effd62015-07-29 06:37:28 -0700380static SkTArray<TaggedSrc, kMemcpyOK> gSrcs;
381static SkTArray<TaggedSink, kMemcpyOK> gSinks;
mtklein748ca3b2015-01-15 10:56:12 -0800382
mtklein6393c062015-04-27 08:45:01 -0700383static bool in_shard() {
384 static int N = 0;
385 return N++ % FLAGS_shards == FLAGS_shard;
386}
387
mtklein3eed7dd2016-02-24 19:07:07 -0800388static void push_src(const char* tag, ImplicitString options, Src* s) {
Ben Wagner145dbcd2016-11-03 14:40:50 -0400389 std::unique_ptr<Src> src(s);
mtklein6393c062015-04-27 08:45:01 -0700390 if (in_shard() &&
mtklein3eed7dd2016-02-24 19:07:07 -0800391 FLAGS_src.contains(tag) &&
mtklein748ca3b2015-01-15 10:56:12 -0800392 !SkCommandLineFlags::ShouldSkip(FLAGS_match, src->name().c_str())) {
mtkleine0effd62015-07-29 06:37:28 -0700393 TaggedSrc& s = gSrcs.push_back();
mtklein18300a32016-03-16 13:53:35 -0700394 s.reset(src.release());
mtklein748ca3b2015-01-15 10:56:12 -0800395 s.tag = tag;
djsollen54416de2015-04-03 07:24:48 -0700396 s.options = options;
mtklein114c3cd2015-01-15 10:15:02 -0800397 }
mtklein748ca3b2015-01-15 10:56:12 -0800398}
mtklein114c3cd2015-01-15 10:15:02 -0800399
msarett9e707a02015-09-01 14:57:57 -0700400static void push_codec_src(Path path, CodecSrc::Mode mode, CodecSrc::DstColorType dstColorType,
scroggoc5560be2016-02-03 09:42:42 -0800401 SkAlphaType dstAlphaType, float scale) {
scroggoe4499842016-02-25 11:03:47 -0800402 if (FLAGS_simpleCodec) {
scroggo19b91532016-10-24 09:03:26 -0700403 const bool simple = CodecSrc::kCodec_Mode == mode || CodecSrc::kAnimated_Mode == mode;
404 if (!simple || dstColorType != CodecSrc::kGetFromCanvas_DstColorType || scale != 1.0f) {
scroggoe4499842016-02-25 11:03:47 -0800405 // Only decode in the simple case.
406 return;
scroggo19b91532016-10-24 09:03:26 -0700407 }
scroggoe4499842016-02-25 11:03:47 -0800408 }
msarett9e707a02015-09-01 14:57:57 -0700409 SkString folder;
410 switch (mode) {
411 case CodecSrc::kCodec_Mode:
412 folder.append("codec");
413 break;
msarettbb25b532016-01-13 09:31:39 -0800414 case CodecSrc::kCodecZeroInit_Mode:
415 folder.append("codec_zero_init");
416 break;
msarett9e707a02015-09-01 14:57:57 -0700417 case CodecSrc::kScanline_Mode:
418 folder.append("scanline");
419 break;
msarett9e707a02015-09-01 14:57:57 -0700420 case CodecSrc::kStripe_Mode:
421 folder.append("stripe");
422 break;
msarett91c22b22016-02-22 12:27:46 -0800423 case CodecSrc::kCroppedScanline_Mode:
424 folder.append("crop");
425 break;
msarett9e707a02015-09-01 14:57:57 -0700426 case CodecSrc::kSubset_Mode:
msarett36c37962015-09-02 13:20:52 -0700427 folder.append("codec_subset");
msarett9e707a02015-09-01 14:57:57 -0700428 break;
scroggo19b91532016-10-24 09:03:26 -0700429 case CodecSrc::kAnimated_Mode:
430 folder.append("codec_animated");
431 break;
msarett9e707a02015-09-01 14:57:57 -0700432 }
433
434 switch (dstColorType) {
435 case CodecSrc::kGrayscale_Always_DstColorType:
436 folder.append("_kGray8");
437 break;
msarett34e0ec42016-04-22 16:27:24 -0700438 case CodecSrc::kNonNative8888_Always_DstColorType:
439 folder.append("_kNonNative");
440 break;
msarett9e707a02015-09-01 14:57:57 -0700441 default:
442 break;
443 }
444
scroggoc5560be2016-02-03 09:42:42 -0800445 switch (dstAlphaType) {
scroggoc5560be2016-02-03 09:42:42 -0800446 case kPremul_SkAlphaType:
447 folder.append("_premul");
448 break;
449 case kUnpremul_SkAlphaType:
450 folder.append("_unpremul");
451 break;
452 default:
453 break;
454 }
455
msarett9e707a02015-09-01 14:57:57 -0700456 if (1.0f != scale) {
457 folder.appendf("_%.3f", scale);
458 }
459
scroggoc5560be2016-02-03 09:42:42 -0800460 CodecSrc* src = new CodecSrc(path, mode, dstColorType, dstAlphaType, scale);
msarett9e707a02015-09-01 14:57:57 -0700461 push_src("image", folder, src);
462}
463
scroggof8dc9df2016-05-16 09:04:13 -0700464static void push_android_codec_src(Path path, CodecSrc::DstColorType dstColorType,
465 SkAlphaType dstAlphaType, int sampleSize) {
msarett3d9d7a72015-10-21 10:27:10 -0700466 SkString folder;
scroggof8dc9df2016-05-16 09:04:13 -0700467 folder.append("scaled_codec");
msarett3d9d7a72015-10-21 10:27:10 -0700468
469 switch (dstColorType) {
470 case CodecSrc::kGrayscale_Always_DstColorType:
471 folder.append("_kGray8");
472 break;
msarett34e0ec42016-04-22 16:27:24 -0700473 case CodecSrc::kNonNative8888_Always_DstColorType:
474 folder.append("_kNonNative");
475 break;
msarett3d9d7a72015-10-21 10:27:10 -0700476 default:
477 break;
478 }
479
scroggoc5560be2016-02-03 09:42:42 -0800480 switch (dstAlphaType) {
scroggoc5560be2016-02-03 09:42:42 -0800481 case kPremul_SkAlphaType:
482 folder.append("_premul");
483 break;
msarett9e9444c2016-02-03 12:39:10 -0800484 case kUnpremul_SkAlphaType:
485 folder.append("_unpremul");
486 break;
scroggoc5560be2016-02-03 09:42:42 -0800487 default:
488 break;
489 }
490
msarett3d9d7a72015-10-21 10:27:10 -0700491 if (1 != sampleSize) {
msarett4b0778e2015-11-13 09:59:11 -0800492 folder.appendf("_%.3f", 1.0f / (float) sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700493 }
494
scroggof8dc9df2016-05-16 09:04:13 -0700495 AndroidCodecSrc* src = new AndroidCodecSrc(path, dstColorType, dstAlphaType, sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700496 push_src("image", folder, src);
497}
498
msarett18976312016-03-09 14:20:58 -0800499static void push_image_gen_src(Path path, ImageGenSrc::Mode mode, SkAlphaType alphaType, bool isGpu)
500{
501 SkString folder;
502 switch (mode) {
503 case ImageGenSrc::kCodec_Mode:
504 folder.append("gen_codec");
505 break;
506 case ImageGenSrc::kPlatform_Mode:
507 folder.append("gen_platform");
508 break;
509 }
510
511 if (isGpu) {
512 folder.append("_gpu");
513 } else {
514 switch (alphaType) {
515 case kOpaque_SkAlphaType:
516 folder.append("_opaque");
517 break;
518 case kPremul_SkAlphaType:
519 folder.append("_premul");
520 break;
521 case kUnpremul_SkAlphaType:
522 folder.append("_unpremul");
523 break;
524 default:
525 break;
526 }
527 }
528
529 ImageGenSrc* src = new ImageGenSrc(path, mode, alphaType, isGpu);
530 push_src("image", folder, src);
531}
532
Leon Scroggins III07418182017-08-15 12:24:02 -0400533static void push_brd_src(Path path, CodecSrc::DstColorType dstColorType, BRDSrc::Mode mode,
534 uint32_t sampleSize) {
535 SkString folder("brd_android_codec");
536 switch (mode) {
537 case BRDSrc::kFullImage_Mode:
538 break;
539 case BRDSrc::kDivisor_Mode:
540 folder.append("_divisor");
541 break;
542 default:
543 SkASSERT(false);
544 return;
545 }
546
547 switch (dstColorType) {
548 case CodecSrc::kGetFromCanvas_DstColorType:
549 break;
550 case CodecSrc::kGrayscale_Always_DstColorType:
551 folder.append("_kGray");
552 break;
553 default:
554 SkASSERT(false);
555 return;
556 }
557
558 if (1 != sampleSize) {
559 folder.appendf("_%.3f", 1.0f / (float) sampleSize);
560 }
561
562 BRDSrc* src = new BRDSrc(path, mode, dstColorType, sampleSize);
563 push_src("image", folder, src);
564}
565
566static void push_brd_srcs(Path path, bool gray) {
567 if (gray) {
568 // Only run grayscale to one sampleSize and Mode. Though interesting
569 // to test grayscale, it should not reveal anything across various
570 // sampleSizes and Modes
571 // Arbitrarily choose Mode and sampleSize.
572 push_brd_src(path, CodecSrc::kGrayscale_Always_DstColorType,
573 BRDSrc::kFullImage_Mode, 2);
574 }
575
576 // Test on a variety of sampleSizes, making sure to include:
577 // - 2, 4, and 8, which are natively supported by jpeg
578 // - multiples of 2 which are not divisible by 4 (analogous for 4)
579 // - larger powers of two, since BRD clients generally use powers of 2
580 // We will only produce output for the larger sizes on large images.
581 const uint32_t sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 24, 32, 64 };
582
583 const BRDSrc::Mode modes[] = { BRDSrc::kFullImage_Mode, BRDSrc::kDivisor_Mode, };
584
585 for (uint32_t sampleSize : sampleSizes) {
586 for (BRDSrc::Mode mode : modes) {
587 push_brd_src(path, CodecSrc::kGetFromCanvas_DstColorType, mode, sampleSize);
588 }
589 }
590}
591
msarett438b2ad2015-04-09 12:43:10 -0700592static void push_codec_srcs(Path path) {
bungeman38d909e2016-08-02 14:40:46 -0700593 sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str()));
msarett438b2ad2015-04-09 12:43:10 -0700594 if (!encoded) {
mtkleinc41fd922016-03-08 09:01:39 -0800595 info("Couldn't read %s.", path.c_str());
msarett438b2ad2015-04-09 12:43:10 -0700596 return;
597 }
Mike Reedede7bac2017-07-23 15:30:02 -0400598 std::unique_ptr<SkCodec> codec = SkCodec::MakeFromData(encoded);
halcanary96fcdcc2015-08-27 07:41:13 -0700599 if (nullptr == codec.get()) {
mtkleinc41fd922016-03-08 09:01:39 -0800600 info("Couldn't create codec for %s.", path.c_str());
msarett438b2ad2015-04-09 12:43:10 -0700601 return;
602 }
603
scroggo9366aff2016-05-20 08:38:54 -0700604 // native scaling is only supported by WEBP and JPEG
605 bool supportsNativeScaling = false;
msarett438b2ad2015-04-09 12:43:10 -0700606
msarett91c22b22016-02-22 12:27:46 -0800607 SkTArray<CodecSrc::Mode> nativeModes;
608 nativeModes.push_back(CodecSrc::kCodec_Mode);
609 nativeModes.push_back(CodecSrc::kCodecZeroInit_Mode);
msarett91c22b22016-02-22 12:27:46 -0800610 switch (codec->getEncodedFormat()) {
Hal Canarydb683012016-11-23 08:55:18 -0700611 case SkEncodedImageFormat::kJPEG:
msarett91c22b22016-02-22 12:27:46 -0800612 nativeModes.push_back(CodecSrc::kScanline_Mode);
613 nativeModes.push_back(CodecSrc::kStripe_Mode);
614 nativeModes.push_back(CodecSrc::kCroppedScanline_Mode);
scroggo9366aff2016-05-20 08:38:54 -0700615 supportsNativeScaling = true;
msarett91c22b22016-02-22 12:27:46 -0800616 break;
Hal Canarydb683012016-11-23 08:55:18 -0700617 case SkEncodedImageFormat::kWEBP:
msarett91c22b22016-02-22 12:27:46 -0800618 nativeModes.push_back(CodecSrc::kSubset_Mode);
scroggo9366aff2016-05-20 08:38:54 -0700619 supportsNativeScaling = true;
msarett91c22b22016-02-22 12:27:46 -0800620 break;
Hal Canarydb683012016-11-23 08:55:18 -0700621 case SkEncodedImageFormat::kDNG:
msarettb65e6042016-02-23 05:37:25 -0800622 break;
msarett91c22b22016-02-22 12:27:46 -0800623 default:
624 nativeModes.push_back(CodecSrc::kScanline_Mode);
msarett91c22b22016-02-22 12:27:46 -0800625 break;
626 }
msarett9e707a02015-09-01 14:57:57 -0700627
msarett91c22b22016-02-22 12:27:46 -0800628 SkTArray<CodecSrc::DstColorType> colorTypes;
629 colorTypes.push_back(CodecSrc::kGetFromCanvas_DstColorType);
msarett34e0ec42016-04-22 16:27:24 -0700630 colorTypes.push_back(CodecSrc::kNonNative8888_Always_DstColorType);
msarett36c37962015-09-02 13:20:52 -0700631 switch (codec->getInfo().colorType()) {
632 case kGray_8_SkColorType:
msarett91c22b22016-02-22 12:27:46 -0800633 colorTypes.push_back(CodecSrc::kGrayscale_Always_DstColorType);
msarett36c37962015-09-02 13:20:52 -0700634 break;
635 default:
msarett36c37962015-09-02 13:20:52 -0700636 break;
637 }
msarett9e707a02015-09-01 14:57:57 -0700638
scroggoc5560be2016-02-03 09:42:42 -0800639 SkTArray<SkAlphaType> alphaModes;
640 alphaModes.push_back(kPremul_SkAlphaType);
scroggof2c96a22016-05-20 11:08:27 -0700641 if (codec->getInfo().alphaType() != kOpaque_SkAlphaType) {
642 alphaModes.push_back(kUnpremul_SkAlphaType);
scroggoc5560be2016-02-03 09:42:42 -0800643 }
msarettb714fb02016-01-22 14:46:42 -0800644
645 for (CodecSrc::Mode mode : nativeModes) {
scroggo9366aff2016-05-20 08:38:54 -0700646 for (CodecSrc::DstColorType colorType : colorTypes) {
647 for (SkAlphaType alphaType : alphaModes) {
scroggof2c96a22016-05-20 11:08:27 -0700648 // Only test kCroppedScanline_Mode when the alpha type is premul. The test is
scroggo9366aff2016-05-20 08:38:54 -0700649 // slow and won't be interestingly different with different alpha types.
650 if (CodecSrc::kCroppedScanline_Mode == mode &&
scroggof2c96a22016-05-20 11:08:27 -0700651 kPremul_SkAlphaType != alphaType) {
scroggo9366aff2016-05-20 08:38:54 -0700652 continue;
653 }
msarett91c22b22016-02-22 12:27:46 -0800654
scroggo9366aff2016-05-20 08:38:54 -0700655 push_codec_src(path, mode, colorType, alphaType, 1.0f);
msarettf3dc1882016-04-26 13:06:38 -0700656
scroggo9366aff2016-05-20 08:38:54 -0700657 // Skip kNonNative on different native scales. It won't be interestingly
658 // different.
659 if (supportsNativeScaling &&
660 CodecSrc::kNonNative8888_Always_DstColorType == colorType) {
661 // Native Scales
662 // SkJpegCodec natively supports scaling to the following:
663 for (auto scale : { 0.125f, 0.25f, 0.375f, 0.5f, 0.625f, 0.750f, 0.875f }) {
664 push_codec_src(path, mode, colorType, alphaType, scale);
665 }
scroggoc5560be2016-02-03 09:42:42 -0800666 }
msarett9e707a02015-09-01 14:57:57 -0700667 }
668 }
msarett0a242972015-06-11 14:27:27 -0700669 }
msarett36c37962015-09-02 13:20:52 -0700670
scroggo19b91532016-10-24 09:03:26 -0700671 {
672 std::vector<SkCodec::FrameInfo> frameInfos = codec->getFrameInfo();
673 if (frameInfos.size() > 1) {
Leon Scroggins III557fbbe2017-05-23 09:37:21 -0400674 for (auto dstCT : { CodecSrc::kNonNative8888_Always_DstColorType,
675 CodecSrc::kGetFromCanvas_DstColorType }) {
676 for (auto at : { kUnpremul_SkAlphaType, kPremul_SkAlphaType }) {
677 push_codec_src(path, CodecSrc::kAnimated_Mode, dstCT, at, 1.0f);
678 }
679 }
scroggo19b91532016-10-24 09:03:26 -0700680 }
681
682 }
683
scroggoe4499842016-02-25 11:03:47 -0800684 if (FLAGS_simpleCodec) {
685 return;
686 }
687
msarett3d9d7a72015-10-21 10:27:10 -0700688 const int sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
msarett36c37962015-09-02 13:20:52 -0700689
msarett3d9d7a72015-10-21 10:27:10 -0700690 for (int sampleSize : sampleSizes) {
msarett91c22b22016-02-22 12:27:46 -0800691 for (CodecSrc::DstColorType colorType : colorTypes) {
scroggoc5560be2016-02-03 09:42:42 -0800692 for (SkAlphaType alphaType : alphaModes) {
msarettf3dc1882016-04-26 13:06:38 -0700693 // We can exercise all of the kNonNative support code in the swizzler with just a
694 // few sample sizes. Skip the rest.
695 if (CodecSrc::kNonNative8888_Always_DstColorType == colorType && sampleSize > 3) {
696 continue;
697 }
698
scroggof8dc9df2016-05-16 09:04:13 -0700699 push_android_codec_src(path, colorType, alphaType, sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700700 }
msarett36c37962015-09-02 13:20:52 -0700701 }
702 }
msarett18976312016-03-09 14:20:58 -0800703
Leon Scroggins III07418182017-08-15 12:24:02 -0400704 const char* ext = strrchr(path.c_str(), '.');
705 if (ext) {
706 ext++;
msarett18976312016-03-09 14:20:58 -0800707
Leon Scroggins III07418182017-08-15 12:24:02 -0400708 static const char* const rawExts[] = {
709 "arw", "cr2", "dng", "nef", "nrw", "orf", "raf", "rw2", "pef", "srw",
710 "ARW", "CR2", "DNG", "NEF", "NRW", "ORF", "RAF", "RW2", "PEF", "SRW",
711 };
712 for (const char* rawExt : rawExts) {
713 if (0 == strcmp(rawExt, ext)) {
714 // RAW is not supported by image generator (skbug.com/5079) or BRD.
715 return;
716 }
717 }
718
719 static const char* const brdExts[] = {
720 "jpg", "jpeg", "png", "webp",
721 "JPG", "JPEG", "PNG", "WEBP",
722 };
723 for (const char* brdExt : brdExts) {
724 if (0 == strcmp(brdExt, ext)) {
725 bool gray = codec->getEncodedInfo().color() == SkEncodedInfo::kGray_Color;
726 push_brd_srcs(path, gray);
727 break;
728 }
msarett18976312016-03-09 14:20:58 -0800729 }
730 }
731
732 // Push image generator GPU test.
brianosmanc9ced392016-03-24 07:27:43 -0700733 push_image_gen_src(path, ImageGenSrc::kCodec_Mode, codec->getInfo().alphaType(), true);
msarett18976312016-03-09 14:20:58 -0800734
735 // Push image generator CPU tests.
736 for (SkAlphaType alphaType : alphaModes) {
737 push_image_gen_src(path, ImageGenSrc::kCodec_Mode, alphaType, false);
738
739#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
Hal Canarydb683012016-11-23 08:55:18 -0700740 if (SkEncodedImageFormat::kWEBP != codec->getEncodedFormat() &&
741 SkEncodedImageFormat::kWBMP != codec->getEncodedFormat() &&
msarett18976312016-03-09 14:20:58 -0800742 kUnpremul_SkAlphaType != alphaType)
743 {
744 push_image_gen_src(path, ImageGenSrc::kPlatform_Mode, alphaType, false);
745 }
msarettfc0b6d12016-03-17 13:50:17 -0700746#elif defined(SK_BUILD_FOR_WIN)
Hal Canarydb683012016-11-23 08:55:18 -0700747 if (SkEncodedImageFormat::kWEBP != codec->getEncodedFormat() &&
748 SkEncodedImageFormat::kWBMP != codec->getEncodedFormat())
msarettfc0b6d12016-03-17 13:50:17 -0700749 {
750 push_image_gen_src(path, ImageGenSrc::kPlatform_Mode, alphaType, false);
751 }
msarett18976312016-03-09 14:20:58 -0800752#endif
753 }
msarett438b2ad2015-04-09 12:43:10 -0700754}
755
fmalitaa2b9fdf2016-08-03 19:53:36 -0700756template <typename T>
757void gather_file_srcs(const SkCommandLineFlags::StringArray& flags, const char* ext) {
758 for (int i = 0; i < flags.count(); i++) {
759 const char* path = flags[i];
760 if (sk_isdir(path)) {
761 SkOSFile::Iter it(path, ext);
762 for (SkString file; it.next(&file); ) {
763 push_src(ext, "", new T(SkOSPath::Join(path, file.c_str())));
764 }
765 } else {
766 push_src(ext, "", new T(path));
767 }
768 }
769}
770
scroggo86737142016-02-03 12:19:11 -0800771static bool gather_srcs() {
mtklein748ca3b2015-01-15 10:56:12 -0800772 for (const skiagm::GMRegistry* r = skiagm::GMRegistry::Head(); r; r = r->next()) {
djsollen54416de2015-04-03 07:24:48 -0700773 push_src("gm", "", new GMSrc(r->factory()));
mtklein748ca3b2015-01-15 10:56:12 -0800774 }
scroggo86737142016-02-03 12:19:11 -0800775
fmalitaa2b9fdf2016-08-03 19:53:36 -0700776 gather_file_srcs<SKPSrc>(FLAGS_skps, "skp");
777 gather_file_srcs<MSKPSrc>(FLAGS_mskps, "mskp");
778#if defined(SK_XML)
779 gather_file_srcs<SVGSrc>(FLAGS_svgs, "svg");
780#endif
halcanary45420a92016-06-02 12:41:14 -0700781
scroggo86737142016-02-03 12:19:11 -0800782 SkTArray<SkString> images;
msarett69deca82016-04-29 09:38:40 -0700783 if (!CollectImages(FLAGS_images, &images)) {
scroggo86737142016-02-03 12:19:11 -0800784 return false;
785 }
786
787 for (auto image : images) {
788 push_codec_srcs(image);
mtklein709d2c32015-01-15 08:30:25 -0800789 }
scroggo86737142016-02-03 12:19:11 -0800790
msarett69deca82016-04-29 09:38:40 -0700791 SkTArray<SkString> colorImages;
792 if (!CollectImages(FLAGS_colorImages, &colorImages)) {
793 return false;
794 }
795
796 for (auto colorImage : colorImages) {
msarett9ce3a542016-07-15 13:54:38 -0700797 ColorCodecSrc* src = new ColorCodecSrc(colorImage, ColorCodecSrc::kBaseline_Mode,
798 kN32_SkColorType);
msarettb8d1aac2016-08-04 12:22:06 -0700799 push_src("colorImage", "color_codec_baseline", src);
msarett888dc162016-05-23 10:21:17 -0700800
msarett9ce3a542016-07-15 13:54:38 -0700801 src = new ColorCodecSrc(colorImage, ColorCodecSrc::kDst_HPZR30w_Mode, kN32_SkColorType);
msarettb8d1aac2016-08-04 12:22:06 -0700802 push_src("colorImage", "color_codec_HPZR30w", src);
msarett9ce3a542016-07-15 13:54:38 -0700803 // TODO (msarett):
804 // 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 -0700805
msarett9ce3a542016-07-15 13:54:38 -0700806 src = new ColorCodecSrc(colorImage, ColorCodecSrc::kDst_sRGB_Mode, kN32_SkColorType);
msarettb8d1aac2016-08-04 12:22:06 -0700807 push_src("colorImage", "color_codec_sRGB_kN32", src);
msarett9ce3a542016-07-15 13:54:38 -0700808 src = new ColorCodecSrc(colorImage, ColorCodecSrc::kDst_sRGB_Mode, kRGBA_F16_SkColorType);
msarettb8d1aac2016-08-04 12:22:06 -0700809 push_src("colorImage", "color_codec_sRGB_kF16", src);
msarett69deca82016-04-29 09:38:40 -0700810 }
811
scroggo86737142016-02-03 12:19:11 -0800812 return true;
mtklein709d2c32015-01-15 08:30:25 -0800813}
814
kkinnunen3e980c32015-12-23 01:33:00 -0800815static void push_sink(const SkCommandLineConfig& config, Sink* s) {
Ben Wagner145dbcd2016-11-03 14:40:50 -0400816 std::unique_ptr<Sink> sink(s);
kkinnunen3e980c32015-12-23 01:33:00 -0800817
mtkleine0effd62015-07-29 06:37:28 -0700818 // Try a simple Src as a canary. If it fails, skip this sink.
mtklein748ca3b2015-01-15 10:56:12 -0800819 struct : public Src {
mtkleine0effd62015-07-29 06:37:28 -0700820 Error draw(SkCanvas* c) const override {
821 c->drawRect(SkRect::MakeWH(1,1), SkPaint());
822 return "";
823 }
mtklein36352bf2015-03-25 18:17:31 -0700824 SkISize size() const override { return SkISize::Make(16, 16); }
mtkleine0effd62015-07-29 06:37:28 -0700825 Name name() const override { return "justOneRect"; }
826 } justOneRect;
mtklein114c3cd2015-01-15 10:15:02 -0800827
mtklein748ca3b2015-01-15 10:56:12 -0800828 SkBitmap bitmap;
829 SkDynamicMemoryWStream stream;
mtkleinb9eb4ac2015-02-02 18:26:03 -0800830 SkString log;
mtkleine0effd62015-07-29 06:37:28 -0700831 Error err = sink->draw(justOneRect, &bitmap, &stream, &log);
mtklein4089ef72015-03-05 08:40:28 -0800832 if (err.isFatal()) {
mtkleinc41fd922016-03-08 09:01:39 -0800833 info("Could not run %s: %s\n", config.getTag().c_str(), err.c_str());
mtklein05641a52015-04-21 10:49:13 -0700834 exit(1);
mtklein114c3cd2015-01-15 10:15:02 -0800835 }
836
mtkleine0effd62015-07-29 06:37:28 -0700837 TaggedSink& ts = gSinks.push_back();
mtklein18300a32016-03-16 13:53:35 -0700838 ts.reset(sink.release());
kkinnunen3e980c32015-12-23 01:33:00 -0800839 ts.tag = config.getTag();
mtklein748ca3b2015-01-15 10:56:12 -0800840}
841
842static bool gpu_supported() {
843#if SK_SUPPORT_GPU
844 return FLAGS_gpu;
845#else
846 return false;
847#endif
848}
kkinnunen9ebc3f02015-12-21 23:48:13 -0800849
csmartdalton008b9d82017-02-22 12:00:42 -0700850static Sink* create_sink(const GrContextOptions& grCtxOptions, const SkCommandLineConfig* config) {
kkinnunen3e980c32015-12-23 01:33:00 -0800851#if SK_SUPPORT_GPU
852 if (gpu_supported()) {
853 if (const SkCommandLineConfigGpu* gpuConfig = config->asConfigGpu()) {
bsalomon85b4b532016-04-05 11:06:27 -0700854 GrContextFactory::ContextType contextType = gpuConfig->getContextType();
csmartdaltone812d492017-02-21 12:36:05 -0700855 GrContextFactory::ContextOverrides contextOverrides = gpuConfig->getContextOverrides();
csmartdalton008b9d82017-02-22 12:00:42 -0700856 GrContextFactory testFactory(grCtxOptions);
csmartdaltone812d492017-02-21 12:36:05 -0700857 if (!testFactory.get(contextType, contextOverrides)) {
mtkleinc41fd922016-03-08 09:01:39 -0800858 info("WARNING: can not create GPU context for config '%s'. "
859 "GM tests will be skipped.\n", gpuConfig->getTag().c_str());
kkinnunen3e980c32015-12-23 01:33:00 -0800860 return nullptr;
861 }
Brian Osmanf9810662017-08-30 10:02:10 -0400862 if (gpuConfig->getTestThreading()) {
863 return new GPUThreadTestingSink(contextType, contextOverrides,
864 gpuConfig->getSamples(), gpuConfig->getUseDIText(),
865 gpuConfig->getColorType(),
866 gpuConfig->getAlphaType(),
867 sk_ref_sp(gpuConfig->getColorSpace()),
868 FLAGS_gpu_threading, grCtxOptions);
869 } else {
870 return new GPUSink(contextType, contextOverrides, gpuConfig->getSamples(),
871 gpuConfig->getUseDIText(), gpuConfig->getColorType(),
872 gpuConfig->getAlphaType(), sk_ref_sp(gpuConfig->getColorSpace()),
873 FLAGS_gpu_threading, grCtxOptions);
874 }
kkinnunen3e980c32015-12-23 01:33:00 -0800875 }
876 }
877#endif
878
879#define SINK(t, sink, ...) if (config->getBackend().equals(t)) { return new sink(__VA_ARGS__); }
880
mtklein748ca3b2015-01-15 10:56:12 -0800881 if (FLAGS_cpu) {
Matt Sarett77a7a1b2017-02-07 13:56:11 -0500882 auto srgbColorSpace = SkColorSpace::MakeSRGB();
883 auto srgbLinearColorSpace = SkColorSpace::MakeSRGBLinear();
brianosmanb109b8c2016-06-16 13:03:24 -0700884
Matt Sarettd2228302017-03-02 08:53:46 -0500885 SINK("565", RasterSink, kRGB_565_SkColorType);
886 SINK("8888", RasterSink, kN32_SkColorType);
887 SINK("srgb", RasterSink, kN32_SkColorType, srgbColorSpace);
Matt Sarettd2228302017-03-02 08:53:46 -0500888 SINK("f16", RasterSink, kRGBA_F16_SkColorType, srgbLinearColorSpace);
Hal Canaryc7d295e2017-07-20 15:36:00 -0400889 SINK("pdf", PDFSink, false, SK_ScalarDefaultRasterDPI);
Matt Sarettd2228302017-03-02 08:53:46 -0500890 SINK("skp", SKPSink);
891 SINK("pipe", PipeSink);
892 SINK("svg", SVGSink);
893 SINK("null", NullSink);
894 SINK("xps", XPSSink);
Hal Canaryc7d295e2017-07-20 15:36:00 -0400895 SINK("pdfa", PDFSink, true, SK_ScalarDefaultRasterDPI);
896 SINK("pdf300", PDFSink, false, 300);
Hal Canary85c7fe82016-10-25 10:33:27 -0400897 SINK("jsdebug", DebugSink);
mtklein748ca3b2015-01-15 10:56:12 -0800898 }
899#undef SINK
halcanary96fcdcc2015-08-27 07:41:13 -0700900 return nullptr;
mtklein114c3cd2015-01-15 10:15:02 -0800901}
902
Mike Klein841101d2017-03-10 09:55:51 -0500903static sk_sp<SkColorSpace> adobe_rgb() {
904 return SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
905 SkColorSpace::kAdobeRGB_Gamut);
906}
907
Mike Klein919cc452017-03-18 15:36:52 +0000908static sk_sp<SkColorSpace> rgb_to_gbr() {
909 float gbr[9];
910 gbr[0] = gSRGB_toXYZD50[1];
911 gbr[1] = gSRGB_toXYZD50[2];
912 gbr[2] = gSRGB_toXYZD50[0];
913 gbr[3] = gSRGB_toXYZD50[4];
914 gbr[4] = gSRGB_toXYZD50[5];
915 gbr[5] = gSRGB_toXYZD50[3];
916 gbr[6] = gSRGB_toXYZD50[7];
917 gbr[7] = gSRGB_toXYZD50[8];
918 gbr[8] = gSRGB_toXYZD50[6];
919 SkMatrix44 toXYZD50(SkMatrix44::kUninitialized_Constructor);
920 toXYZD50.set3x3RowMajorf(gbr);
921 return SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma, toXYZD50);
922}
923
kkinnunen3e980c32015-12-23 01:33:00 -0800924static Sink* create_via(const SkString& tag, Sink* wrapped) {
925#define VIA(t, via, ...) if (tag.equals(t)) { return new via(__VA_ARGS__); }
Mike Klein919cc452017-03-18 15:36:52 +0000926 VIA("adobe", ViaCSXform, wrapped, adobe_rgb(), false);
927 VIA("gbr", ViaCSXform, wrapped, rgb_to_gbr(), true);
mtklein9c5052f2016-08-06 12:51:51 -0700928 VIA("lite", ViaLite, wrapped);
reed54dc4872016-09-13 08:09:45 -0700929 VIA("pipe", ViaPipe, wrapped);
halcanary96fcdcc2015-08-27 07:41:13 -0700930 VIA("twice", ViaTwice, wrapped);
Mike Reedbae888e2017-02-18 16:50:45 -0500931#ifdef TEST_VIA_SVG
Mike Reedf67c4592017-02-17 17:06:11 -0500932 VIA("svg", ViaSVG, wrapped);
Mike Reedbae888e2017-02-18 16:50:45 -0500933#endif
halcanary96fcdcc2015-08-27 07:41:13 -0700934 VIA("serialize", ViaSerialization, wrapped);
mtklein4a34ecb2016-01-08 10:19:35 -0800935 VIA("pic", ViaPicture, wrapped);
halcanary96fcdcc2015-08-27 07:41:13 -0700936 VIA("2ndpic", ViaSecondPicture, wrapped);
mtkleind31c13d2015-05-05 12:59:56 -0700937 VIA("sp", ViaSingletonPictures, wrapped);
reedbabc3de2016-07-08 08:43:27 -0700938 VIA("defer", ViaDefer, wrapped);
halcanary96fcdcc2015-08-27 07:41:13 -0700939 VIA("tiles", ViaTiles, 256, 256, nullptr, wrapped);
mtklein7edca212015-01-21 13:18:51 -0800940 VIA("tiles_rt", ViaTiles, 256, 256, new SkRTreeFactory, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800941
mtkleind603b222015-02-17 11:13:33 -0800942 if (FLAGS_matrix.count() == 4) {
mtklein748ca3b2015-01-15 10:56:12 -0800943 SkMatrix m;
mtkleind603b222015-02-17 11:13:33 -0800944 m.reset();
945 m.setScaleX((SkScalar)atof(FLAGS_matrix[0]));
946 m.setSkewX ((SkScalar)atof(FLAGS_matrix[1]));
947 m.setSkewY ((SkScalar)atof(FLAGS_matrix[2]));
948 m.setScaleY((SkScalar)atof(FLAGS_matrix[3]));
949 VIA("matrix", ViaMatrix, m, wrapped);
950 VIA("upright", ViaUpright, m, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800951 }
tomhudson64de1e12015-03-05 08:01:07 -0800952
mtklein748ca3b2015-01-15 10:56:12 -0800953#undef VIA
halcanary96fcdcc2015-08-27 07:41:13 -0700954 return nullptr;
mtklein114c3cd2015-01-15 10:15:02 -0800955}
956
Ben Wagnerf28d4722017-08-11 17:33:22 -0400957static bool gather_sinks(const GrContextOptions& grCtxOptions, bool defaultConfigs) {
kkinnunen3e980c32015-12-23 01:33:00 -0800958 SkCommandLineConfigArray configs;
959 ParseConfigs(FLAGS_config, &configs);
960 for (int i = 0; i < configs.count(); i++) {
961 const SkCommandLineConfig& config = *configs[i];
csmartdalton008b9d82017-02-22 12:00:42 -0700962 Sink* sink = create_sink(grCtxOptions, &config);
kkinnunen3e980c32015-12-23 01:33:00 -0800963 if (sink == nullptr) {
mtkleinc41fd922016-03-08 09:01:39 -0800964 info("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(),
965 config.getTag().c_str());
kkinnunen3e980c32015-12-23 01:33:00 -0800966 continue;
967 }
mtklein748ca3b2015-01-15 10:56:12 -0800968
kkinnunen3e980c32015-12-23 01:33:00 -0800969 const SkTArray<SkString>& parts = config.getViaParts();
970 for (int j = parts.count(); j-- > 0;) {
971 const SkString& part = parts[j];
972 Sink* next = create_via(part, sink);
halcanary96fcdcc2015-08-27 07:41:13 -0700973 if (next == nullptr) {
mtkleinc41fd922016-03-08 09:01:39 -0800974 info("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(),
975 part.c_str());
mtklein748ca3b2015-01-15 10:56:12 -0800976 delete sink;
halcanary96fcdcc2015-08-27 07:41:13 -0700977 sink = nullptr;
mtklein748ca3b2015-01-15 10:56:12 -0800978 break;
979 }
980 sink = next;
981 }
982 if (sink) {
983 push_sink(config, sink);
mtklein114c3cd2015-01-15 10:15:02 -0800984 }
985 }
brianosman05c987c2016-05-09 13:42:16 -0700986
987 // If no configs were requested (just running tests, perhaps?), then we're okay.
Ben Wagnerf28d4722017-08-11 17:33:22 -0400988 if (configs.count() == 0 ||
989 // If we're using the default configs, we're okay.
990 defaultConfigs ||
Ben Wagner32fa5102017-08-10 21:25:55 -0400991 // If we've been told to ignore undefined flags, we're okay.
992 FLAGS_undefok ||
993 // Otherwise, make sure that all specified configs have become sinks.
994 configs.count() == gSinks.count()) {
995 return true;
996 }
997 info("Invalid --config. Use --undefok to bypass this warning.\n");
998 return false;
mtklein114c3cd2015-01-15 10:15:02 -0800999}
mtklein709d2c32015-01-15 08:30:25 -08001000
mtkleina5114d72015-08-24 13:27:01 -07001001static bool dump_png(SkBitmap bitmap, const char* path, const char* md5) {
Mike Klein13b6afd2017-06-12 12:45:41 -04001002 SkPixmap pm;
1003 if (!bitmap.peekPixels(&pm)) {
1004 return false; // Ought to never happen... we're already read-back at this point.
mtkleina5114d72015-08-24 13:27:01 -07001005 }
Mike Klein13b6afd2017-06-12 12:45:41 -04001006 SkFILEWStream dst{path};
mtkleina5114d72015-08-24 13:27:01 -07001007
mtkleind69ece62015-09-10 10:37:44 -07001008 SkString description;
1009 description.append("Key: ");
1010 for (int i = 0; i < FLAGS_key.count(); i++) {
1011 description.appendf("%s ", FLAGS_key[i]);
1012 }
1013 description.append("Properties: ");
1014 for (int i = 0; i < FLAGS_properties.count(); i++) {
1015 description.appendf("%s ", FLAGS_properties[i]);
1016 }
1017 description.appendf("MD5: %s", md5);
1018
Mike Klein13b6afd2017-06-12 12:45:41 -04001019 const char* comments[] = {
1020 "Author", "DM dump_png()",
1021 "Description", description.c_str(),
1022 };
1023 size_t lengths[] = {
1024 strlen(comments[0])+1, strlen(comments[1])+1,
1025 strlen(comments[2])+1, strlen(comments[3])+1,
1026 };
mtkleina5114d72015-08-24 13:27:01 -07001027
Mike Klein13b6afd2017-06-12 12:45:41 -04001028 SkPngEncoder::Options options;
1029 options.fComments = SkDataTable::MakeCopyArrays((const void**)comments, lengths, 4);
1030 options.fFilterFlags = SkPngEncoder::FilterFlag::kNone;
1031 options.fZLibLevel = 1;
1032 options.fUnpremulBehavior = pm.colorSpace() ? SkTransferFunctionBehavior::kRespect
1033 : SkTransferFunctionBehavior::kIgnore;
1034 return SkPngEncoder::Encode(&dst, pm, options);
mtkleina5114d72015-08-24 13:27:01 -07001035}
1036
mtkleina2ef6422015-01-15 13:44:22 -08001037static bool match(const char* needle, const char* haystack) {
Chris Daltonecf78ac2017-08-15 15:43:08 -06001038 if ('~' == needle[0]) {
1039 return !match(needle + 1, haystack);
1040 }
1041 if (0 == strcmp("_", needle)) {
1042 return true;
1043 }
1044 return nullptr != strstr(haystack, needle);
mtkleina2ef6422015-01-15 13:44:22 -08001045}
1046
mtklein3eed7dd2016-02-24 19:07:07 -08001047static bool is_blacklisted(const char* sink, const char* src,
1048 const char* srcOptions, const char* name) {
mtklein0d243ff2015-04-03 07:51:00 -07001049 for (int i = 0; i < FLAGS_blacklist.count() - 3; i += 4) {
mtkleina2ef6422015-01-15 13:44:22 -08001050 if (match(FLAGS_blacklist[i+0], sink) &&
djsollen54416de2015-04-03 07:24:48 -07001051 match(FLAGS_blacklist[i+1], src) &&
1052 match(FLAGS_blacklist[i+2], srcOptions) &&
1053 match(FLAGS_blacklist[i+3], name)) {
mtklein3eed7dd2016-02-24 19:07:07 -08001054 return true;
mtkleina2ef6422015-01-15 13:44:22 -08001055 }
1056 }
mtklein3eed7dd2016-02-24 19:07:07 -08001057 return false;
mtkleina2ef6422015-01-15 13:44:22 -08001058}
1059
mtkleincd50bca2016-01-05 06:20:20 -08001060// Even when a Task Sink reports to be non-threadsafe (e.g. GPU), we know things like
1061// .png encoding are definitely thread safe. This lets us offload that work to CPU threads.
1062static SkTaskGroup gDefinitelyThreadSafeWork;
1063
mtklein748ca3b2015-01-15 10:56:12 -08001064// The finest-grained unit of work we can run: draw a single Src into a single Sink,
1065// report any errors, and perhaps write out the output: a .png of the bitmap, or a raw stream.
1066struct Task {
mtkleine0effd62015-07-29 06:37:28 -07001067 Task(const TaggedSrc& src, const TaggedSink& sink) : src(src), sink(sink) {}
1068 const TaggedSrc& src;
1069 const TaggedSink& sink;
mtklein748ca3b2015-01-15 10:56:12 -08001070
mtklein21eaf3b2016-02-08 12:39:59 -08001071 static void Run(const Task& task) {
1072 SkString name = task.src->name();
mtkleine0effd62015-07-29 06:37:28 -07001073
mtkleinb9eb4ac2015-02-02 18:26:03 -08001074 SkString log;
mtklein3eed7dd2016-02-24 19:07:07 -08001075 if (!FLAGS_dryRun) {
mtklein748ca3b2015-01-15 10:56:12 -08001076 SkBitmap bitmap;
1077 SkDynamicMemoryWStream stream;
mtklein3eed7dd2016-02-24 19:07:07 -08001078 start(task.sink.tag.c_str(), task.src.tag.c_str(),
1079 task.src.options.c_str(), name.c_str());
mtklein21eaf3b2016-02-08 12:39:59 -08001080 Error err = task.sink->draw(*task.src, &bitmap, &stream, &log);
mtkleinb3b13b72016-03-07 13:20:52 -08001081 if (!log.isEmpty()) {
mtkleinc41fd922016-03-08 09:01:39 -08001082 info("%s %s %s %s:\n%s\n", task.sink.tag.c_str()
1083 , task.src.tag.c_str()
1084 , task.src.options.c_str()
1085 , name.c_str()
1086 , log.c_str());
mtkleinb3b13b72016-03-07 13:20:52 -08001087 }
mtklein748ca3b2015-01-15 10:56:12 -08001088 if (!err.isEmpty()) {
mtklein4089ef72015-03-05 08:40:28 -08001089 if (err.isFatal()) {
djsollen54416de2015-04-03 07:24:48 -07001090 fail(SkStringPrintf("%s %s %s %s: %s",
mtklein21eaf3b2016-02-08 12:39:59 -08001091 task.sink.tag.c_str(),
1092 task.src.tag.c_str(),
1093 task.src.options.c_str(),
mtklein4089ef72015-03-05 08:40:28 -08001094 name.c_str(),
1095 err.c_str()));
mtkleinb37cb412015-03-18 05:27:14 -07001096 } else {
mtklein3eed7dd2016-02-24 19:07:07 -08001097 done(task.sink.tag.c_str(), task.src.tag.c_str(),
1098 task.src.options.c_str(), name.c_str());
mtkleinba6ada72016-01-21 09:39:35 -08001099 return;
mtklein4089ef72015-03-05 08:40:28 -08001100 }
mtklein748ca3b2015-01-15 10:56:12 -08001101 }
mtklein62bd1a62015-01-27 14:46:26 -08001102
mtkleincd50bca2016-01-05 06:20:20 -08001103 // We're likely switching threads here, so we must capture by value, [=] or [foo,bar].
Hal Canary0b833192017-03-14 14:35:02 -04001104 SkStreamAsset* data = stream.detachAsStream().release();
mtkleincd50bca2016-01-05 06:20:20 -08001105 gDefinitelyThreadSafeWork.add([task,name,bitmap,data]{
Ben Wagner145dbcd2016-11-03 14:40:50 -04001106 std::unique_ptr<SkStreamAsset> ownedData(data);
mtkleincd50bca2016-01-05 06:20:20 -08001107
mtkleincd50bca2016-01-05 06:20:20 -08001108 SkString md5;
1109 if (!FLAGS_writePath.isEmpty() || !FLAGS_readPath.isEmpty()) {
1110 SkMD5 hash;
1111 if (data->getLength()) {
1112 hash.writeStream(data, data->getLength());
1113 data->rewind();
mtklein38408462015-07-08 07:25:27 -07001114 } else {
mtkleincd50bca2016-01-05 06:20:20 -08001115 // If we're BGRA (Linux, Windows), swizzle over to RGBA (Mac, Android).
1116 // This helps eliminate multiple 0-pixel-diff hashes on gold.skia.org.
1117 // (Android's general slow speed breaks the tie arbitrarily in RGBA's favor.)
1118 // We might consider promoting 565 to RGBA too.
1119 if (bitmap.colorType() == kBGRA_8888_SkColorType) {
1120 SkBitmap swizzle;
Matt Sarett68b8e3d2017-04-28 11:15:22 -04001121 SkAssertResult(sk_tool_utils::copy_to(&swizzle, kRGBA_8888_SkColorType,
1122 bitmap));
mtkleincd50bca2016-01-05 06:20:20 -08001123 hash.write(swizzle.getPixels(), swizzle.getSize());
1124 } else {
1125 hash.write(bitmap.getPixels(), bitmap.getSize());
1126 }
1127 }
1128 SkMD5::Digest digest;
1129 hash.finish(digest);
1130 for (int i = 0; i < 16; i++) {
1131 md5.appendf("%02x", digest.data[i]);
mtklein38408462015-07-08 07:25:27 -07001132 }
mtklein62bd1a62015-01-27 14:46:26 -08001133 }
mtklein62bd1a62015-01-27 14:46:26 -08001134
mtkleincd50bca2016-01-05 06:20:20 -08001135 if (!FLAGS_readPath.isEmpty() &&
mtklein3eed7dd2016-02-24 19:07:07 -08001136 !gGold.contains(Gold(task.sink.tag, task.src.tag,
1137 task.src.options, name, md5))) {
mtkleincd50bca2016-01-05 06:20:20 -08001138 fail(SkStringPrintf("%s not found for %s %s %s %s in %s",
1139 md5.c_str(),
mtklein21eaf3b2016-02-08 12:39:59 -08001140 task.sink.tag.c_str(),
1141 task.src.tag.c_str(),
1142 task.src.options.c_str(),
mtkleincd50bca2016-01-05 06:20:20 -08001143 name.c_str(),
1144 FLAGS_readPath[0]));
mtklein748ca3b2015-01-15 10:56:12 -08001145 }
mtkleincd50bca2016-01-05 06:20:20 -08001146
1147 if (!FLAGS_writePath.isEmpty()) {
mtklein21eaf3b2016-02-08 12:39:59 -08001148 const char* ext = task.sink->fileExtension();
Mike Klein97d6a7a2017-07-24 10:37:19 -04001149 if (!FLAGS_dont_write.contains(ext)) {
1150 if (data->getLength()) {
1151 WriteToDisk(task, md5, ext, data, data->getLength(), nullptr);
1152 SkASSERT(bitmap.drawsNothing());
1153 } else if (!bitmap.drawsNothing()) {
1154 WriteToDisk(task, md5, ext, nullptr, 0, &bitmap);
1155 }
mtkleincd50bca2016-01-05 06:20:20 -08001156 }
1157 }
1158 });
mtklein748ca3b2015-01-15 10:56:12 -08001159 }
mtklein3eed7dd2016-02-24 19:07:07 -08001160 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 -08001161 }
1162
1163 static void WriteToDisk(const Task& task,
mtklein62bd1a62015-01-27 14:46:26 -08001164 SkString md5,
1165 const char* ext,
mtklein748ca3b2015-01-15 10:56:12 -08001166 SkStream* data, size_t len,
mtklein62bd1a62015-01-27 14:46:26 -08001167 const SkBitmap* bitmap) {
mtklein409d4702016-02-29 07:38:01 -08001168 bool gammaCorrect = false;
1169 if (bitmap) {
Brian Osman7039f742016-11-01 15:56:16 -04001170 gammaCorrect = SkToBool(bitmap->info().colorSpace());
mtklein409d4702016-02-29 07:38:01 -08001171 }
1172
mtklein748ca3b2015-01-15 10:56:12 -08001173 JsonWriter::BitmapResult result;
djsollen54416de2015-04-03 07:24:48 -07001174 result.name = task.src->name();
mtklein3eed7dd2016-02-24 19:07:07 -08001175 result.config = task.sink.tag;
djsollen54416de2015-04-03 07:24:48 -07001176 result.sourceType = task.src.tag;
1177 result.sourceOptions = task.src.options;
1178 result.ext = ext;
mtklein409d4702016-02-29 07:38:01 -08001179 result.gammaCorrect = gammaCorrect;
djsollen54416de2015-04-03 07:24:48 -07001180 result.md5 = md5;
mtklein748ca3b2015-01-15 10:56:12 -08001181 JsonWriter::AddBitmapResult(result);
1182
mtkleinb0531a72015-04-07 13:38:48 -07001183 // If an MD5 is uninteresting, we want it noted in the JSON file,
1184 // but don't want to dump it out as a .png (or whatever ext is).
1185 if (gUninterestingHashes.contains(md5)) {
1186 return;
1187 }
1188
mtklein748ca3b2015-01-15 10:56:12 -08001189 const char* dir = FLAGS_writePath[0];
1190 if (0 == strcmp(dir, "@")) { // Needed for iOS.
1191 dir = FLAGS_resourcePath[0];
1192 }
1193 sk_mkdir(dir);
1194
1195 SkString path;
1196 if (FLAGS_nameByHash) {
1197 path = SkOSPath::Join(dir, result.md5.c_str());
1198 path.append(".");
1199 path.append(ext);
1200 if (sk_exists(path.c_str())) {
1201 return; // Content-addressed. If it exists already, we're done.
1202 }
1203 } else {
kkinnunen3e980c32015-12-23 01:33:00 -08001204 path = SkOSPath::Join(dir, task.sink.tag.c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001205 sk_mkdir(path.c_str());
msarett9e707a02015-09-01 14:57:57 -07001206 path = SkOSPath::Join(path.c_str(), task.src.tag.c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001207 sk_mkdir(path.c_str());
msarett9e707a02015-09-01 14:57:57 -07001208 if (strcmp(task.src.options.c_str(), "") != 0) {
1209 path = SkOSPath::Join(path.c_str(), task.src.options.c_str());
djsollen54416de2015-04-03 07:24:48 -07001210 sk_mkdir(path.c_str());
1211 }
mtklein748ca3b2015-01-15 10:56:12 -08001212 path = SkOSPath::Join(path.c_str(), task.src->name().c_str());
1213 path.append(".");
1214 path.append(ext);
1215 }
1216
mtklein748ca3b2015-01-15 10:56:12 -08001217 if (bitmap) {
mtkleina5114d72015-08-24 13:27:01 -07001218 if (!dump_png(*bitmap, path.c_str(), result.md5.c_str())) {
mtklein748ca3b2015-01-15 10:56:12 -08001219 fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str()));
1220 return;
1221 }
1222 } else {
mtkleina5114d72015-08-24 13:27:01 -07001223 SkFILEWStream file(path.c_str());
1224 if (!file.isValid()) {
1225 fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str()));
1226 return;
1227 }
mtklein748ca3b2015-01-15 10:56:12 -08001228 if (!file.writeStream(data, len)) {
1229 fail(SkStringPrintf("Can't write to %s.\n", path.c_str()));
1230 return;
1231 }
1232 }
1233 }
1234};
1235
mtklein748ca3b2015-01-15 10:56:12 -08001236/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1237
1238// Unit tests don't fit so well into the Src/Sink model, so we give them special treatment.
1239
mtklein21eaf3b2016-02-08 12:39:59 -08001240static SkTDArray<skiatest::Test> gParallelTests, gSerialTests;
mtklein748ca3b2015-01-15 10:56:12 -08001241
1242static void gather_tests() {
mtklein6c5fed22015-01-20 13:47:23 -08001243 if (!FLAGS_src.contains("tests")) {
mtklein748ca3b2015-01-15 10:56:12 -08001244 return;
1245 }
mtklein6393c062015-04-27 08:45:01 -07001246 for (const skiatest::TestRegistry* r = skiatest::TestRegistry::Head(); r; r = r->next()) {
1247 if (!in_shard()) {
1248 continue;
1249 }
halcanary87f3ba42015-01-20 09:30:20 -08001250 // Despite its name, factory() is returning a reference to
1251 // link-time static const POD data.
1252 const skiatest::Test& test = r->factory();
1253 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, test.name)) {
mtklein748ca3b2015-01-15 10:56:12 -08001254 continue;
1255 }
halcanary87f3ba42015-01-20 09:30:20 -08001256 if (test.needsGpu && gpu_supported()) {
mtklein21eaf3b2016-02-08 12:39:59 -08001257 (FLAGS_gpu_threading ? gParallelTests : gSerialTests).push(test);
halcanary87f3ba42015-01-20 09:30:20 -08001258 } else if (!test.needsGpu && FLAGS_cpu) {
mtklein21eaf3b2016-02-08 12:39:59 -08001259 gParallelTests.push(test);
mtklein82d28432015-01-15 12:46:02 -08001260 }
mtklein748ca3b2015-01-15 10:56:12 -08001261 }
1262}
1263
csmartdalton008b9d82017-02-22 12:00:42 -07001264static void run_test(skiatest::Test test, const GrContextOptions& grCtxOptions) {
halcanary87f3ba42015-01-20 09:30:20 -08001265 struct : public skiatest::Reporter {
mtklein36352bf2015-03-25 18:17:31 -07001266 void reportFailed(const skiatest::Failure& failure) override {
halcanary87f3ba42015-01-20 09:30:20 -08001267 fail(failure.toString());
1268 JsonWriter::AddTestFailure(failure);
1269 }
mtklein36352bf2015-03-25 18:17:31 -07001270 bool allowExtendedTest() const override {
halcanary87f3ba42015-01-20 09:30:20 -08001271 return FLAGS_pathOpsExtended;
1272 }
mtklein36352bf2015-03-25 18:17:31 -07001273 bool verbose() const override { return FLAGS_veryVerbose; }
halcanary87f3ba42015-01-20 09:30:20 -08001274 } reporter;
djsollen824996a2015-06-12 12:06:22 -07001275
mtklein3eed7dd2016-02-24 19:07:07 -08001276 if (!FLAGS_dryRun && !is_blacklisted("_", "tests", "_", test.name)) {
mtklein21eaf3b2016-02-08 12:39:59 -08001277 start("unit", "test", "", test.name);
csmartdalton008b9d82017-02-22 12:00:42 -07001278 GrContextFactory factory(grCtxOptions);
Mike Kleinb323a5e2017-07-24 15:21:31 -04001279 test.run(&reporter, &factory);
mtklein748ca3b2015-01-15 10:56:12 -08001280 }
mtklein3eed7dd2016-02-24 19:07:07 -08001281 done("unit", "test", "", test.name);
mtklein748ca3b2015-01-15 10:56:12 -08001282}
1283
1284/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1285
caryclark83ca6282015-06-10 09:31:09 -07001286#define PORTABLE_FONT_PREFIX "Toy Liberation "
1287
mbocee6a9912016-05-31 11:42:36 -07001288static sk_sp<SkTypeface> create_from_name(const char familyName[], SkFontStyle style) {
caryclark83ca6282015-06-10 09:31:09 -07001289 if (familyName && strlen(familyName) > sizeof(PORTABLE_FONT_PREFIX)
1290 && !strncmp(familyName, PORTABLE_FONT_PREFIX, sizeof(PORTABLE_FONT_PREFIX) - 1)) {
caryclark1818acb2015-07-24 12:09:25 -07001291 return sk_tool_utils::create_portable_typeface(familyName, style);
caryclark83ca6282015-06-10 09:31:09 -07001292 }
halcanary96fcdcc2015-08-27 07:41:13 -07001293 return nullptr;
caryclark83ca6282015-06-10 09:31:09 -07001294}
1295
1296#undef PORTABLE_FONT_PREFIX
1297
mbocee6a9912016-05-31 11:42:36 -07001298extern sk_sp<SkTypeface> (*gCreateTypefaceDelegate)(const char [], SkFontStyle );
caryclark83ca6282015-06-10 09:31:09 -07001299
Mike Kleinbe28ee22017-02-06 12:46:20 -05001300int main(int argc, char** argv) {
1301 SkCommandLineFlags::Parse(argc, argv);
Brian Osman53136aa2017-07-20 15:43:35 -04001302
Brian Osmanbc8150f2017-07-24 11:38:01 -04001303 initializeEventTracingForTools();
Brian Osman53136aa2017-07-20 15:43:35 -04001304
Mike Klein135a1b12017-08-15 13:13:59 -04001305#if !defined(GOOGLE3) && defined(SK_BUILD_FOR_IOS)
Mike Kleinadacaef2017-02-06 09:26:14 -05001306 cd_Documents();
1307#endif
bsalomon71de3532016-04-26 14:27:21 -07001308 setbuf(stdout, nullptr);
mtklein246ba3a2016-02-23 10:39:36 -08001309 setup_crash_handler();
mtkleinafae30a2016-02-24 12:28:32 -08001310
Yuqian Liba62b4a2016-12-14 13:46:53 -05001311 gSkUseAnalyticAA = FLAGS_analyticAA;
Yuqian Lidf60e362017-07-25 11:26:31 -04001312 gSkUseDeltaAA = FLAGS_deltaAA;
liyuqian38911a72016-10-04 11:23:22 -07001313
Yuqian Li550148b2017-01-13 10:13:13 -05001314 if (FLAGS_forceAnalyticAA) {
1315 gSkForceAnalyticAA = true;
1316 }
Mike Reed7c26ca72017-07-05 15:45:52 -04001317 if (FLAGS_forceRasterPipeline) {
1318 gSkForceRasterPipelineBlitter = true;
1319 }
Yuqian Li550148b2017-01-13 10:13:13 -05001320
Mike Kleine9f187b2017-06-26 13:23:12 -04001321 // The bots like having a verbose.log to upload, so always touch the file even if --verbose.
1322 if (!FLAGS_writePath.isEmpty()) {
mtklein51c8cfc2016-03-11 12:59:09 -08001323 sk_mkdir(FLAGS_writePath[0]);
mtkleina1ce2162016-07-22 12:23:46 -07001324 gVLog = fopen(SkOSPath::Join(FLAGS_writePath[0], "verbose.log").c_str(), "w");
mtkleinc41fd922016-03-08 09:01:39 -08001325 }
Mike Kleine9f187b2017-06-26 13:23:12 -04001326 if (FLAGS_verbose) {
1327 gVLog = stderr;
1328 }
mtkleinc41fd922016-03-08 09:01:39 -08001329
csmartdalton008b9d82017-02-22 12:00:42 -07001330 GrContextOptions grCtxOptions;
1331#if SK_SUPPORT_GPU
1332 grCtxOptions.fGpuPathRenderers = CollectGpuPathRenderersFromFlags();
Brian Osmanf9810662017-08-30 10:02:10 -04001333 grCtxOptions.fExecutor = GpuExecutorForTools();
csmartdalton008b9d82017-02-22 12:00:42 -07001334#endif
1335
mtklein5286f022016-01-22 08:18:14 -08001336 JsonWriter::DumpJson(); // It's handy for the bots to assume this is ~never missing.
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +00001337 SkAutoGraphics ag;
mtklein406654b2014-09-03 15:34:37 -07001338 SkTaskGroup::Enabler enabled(FLAGS_threads);
caryclark83ca6282015-06-10 09:31:09 -07001339 gCreateTypefaceDelegate = &create_from_name;
commit-bot@chromium.orga65e2fd2014-05-30 17:23:31 +00001340
halcanary7d571242016-02-24 17:59:16 -08001341 {
1342 SkString testResourcePath = GetResourcePath("color_wheel.png");
1343 SkFILEStream testResource(testResourcePath.c_str());
1344 if (!testResource.isValid()) {
mtkleinc41fd922016-03-08 09:01:39 -08001345 info("Some resources are missing. Do you need to set --resourcePath?\n");
halcanary7d571242016-02-24 17:59:16 -08001346 }
1347 }
mtklein62bd1a62015-01-27 14:46:26 -08001348 gather_gold();
borenet09ed4802015-04-03 14:15:33 -07001349 gather_uninteresting_hashes();
mtklein62bd1a62015-01-27 14:46:26 -08001350
scroggo86737142016-02-03 12:19:11 -08001351 if (!gather_srcs()) {
1352 return 1;
1353 }
Ben Wagnerf28d4722017-08-11 17:33:22 -04001354 // TODO(dogben): This is a bit ugly. Find a cleaner way to do this.
1355 bool defaultConfigs = true;
1356 for (int i = 0; i < argc; i++) {
1357 static const char* kConfigArg = "--config";
1358 if (strcmp(argv[i], kConfigArg) == 0) {
1359 defaultConfigs = false;
1360 break;
1361 }
1362 }
1363 if (!gather_sinks(grCtxOptions, defaultConfigs)) {
brianosman05c987c2016-05-09 13:42:16 -07001364 return 1;
1365 }
mtklein748ca3b2015-01-15 10:56:12 -08001366 gather_tests();
mtklein21eaf3b2016-02-08 12:39:59 -08001367 gPending = gSrcs.count() * gSinks.count() + gParallelTests.count() + gSerialTests.count();
Brian Osmand0677bc2017-08-03 12:13:47 -04001368 info("%d srcs * %d sinks + %d tests == %d tasks\n",
mtkleinc41fd922016-03-08 09:01:39 -08001369 gSrcs.count(), gSinks.count(), gParallelTests.count() + gSerialTests.count(), gPending);
mtklein748ca3b2015-01-15 10:56:12 -08001370
mtklein21eaf3b2016-02-08 12:39:59 -08001371 // Kick off as much parallel work as we can, making note of any serial work we'll need to do.
1372 SkTaskGroup parallel;
1373 SkTArray<Task> serial;
1374
1375 for (auto& sink : gSinks)
1376 for (auto& src : gSrcs) {
mtklein3eed7dd2016-02-24 19:07:07 -08001377 if (src->veto(sink->flags()) ||
1378 is_blacklisted(sink.tag.c_str(), src.tag.c_str(),
1379 src.options.c_str(), src->name().c_str())) {
mtkleinf10637f2016-06-10 13:56:35 -07001380 SkAutoMutexAcquire lock(gMutex);
mtklein3eed7dd2016-02-24 19:07:07 -08001381 gPending--;
1382 continue;
1383 }
1384
mtklein21eaf3b2016-02-08 12:39:59 -08001385 Task task(src, sink);
1386 if (src->serial() || sink->serial()) {
1387 serial.push_back(task);
1388 } else {
1389 parallel.add([task] { Task::Run(task); });
mtklein748ca3b2015-01-15 10:56:12 -08001390 }
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001391 }
mtklein21eaf3b2016-02-08 12:39:59 -08001392 for (auto test : gParallelTests) {
csmartdalton008b9d82017-02-22 12:00:42 -07001393 parallel.add([test, grCtxOptions] { run_test(test, grCtxOptions); });
mtklein55e88b22015-01-21 15:50:13 -08001394 }
mtklein21eaf3b2016-02-08 12:39:59 -08001395
1396 // With the parallel work running, run serial tasks and tests here on main thread.
1397 for (auto task : serial) { Task::Run(task); }
csmartdalton008b9d82017-02-22 12:00:42 -07001398 for (auto test : gSerialTests) { run_test(test, grCtxOptions); }
mtklein21eaf3b2016-02-08 12:39:59 -08001399
1400 // Wait for any remaining parallel work to complete (including any spun off of serial tasks).
1401 parallel.wait();
mtkleincd50bca2016-01-05 06:20:20 -08001402 gDefinitelyThreadSafeWork.wait();
1403
mtkleinda884c42016-02-24 18:00:23 -08001404 // We'd better have run everything.
1405 SkASSERT(gPending == 0);
mtkleine027f172016-02-26 15:53:06 -08001406 // Make sure we've flushed all our results to disk.
1407 JsonWriter::DumpJson();
mtkleinda884c42016-02-24 18:00:23 -08001408
mtklein748ca3b2015-01-15 10:56:12 -08001409 // At this point we're back in single-threaded land.
caryclarkf53ce802015-06-15 06:48:30 -07001410 sk_tool_utils::release_portable_typefaces();
mtklein@google.comd36522d2013-10-16 13:02:15 +00001411
mtklein748ca3b2015-01-15 10:56:12 -08001412 if (gFailures.count() > 0) {
mtkleinc41fd922016-03-08 09:01:39 -08001413 info("Failures:\n");
mtklein748ca3b2015-01-15 10:56:12 -08001414 for (int i = 0; i < gFailures.count(); i++) {
mtkleinc41fd922016-03-08 09:01:39 -08001415 info("\t%s\n", gFailures[i].c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001416 }
mtkleinc41fd922016-03-08 09:01:39 -08001417 info("%d failures\n", gFailures.count());
mtklein748ca3b2015-01-15 10:56:12 -08001418 return 1;
mtklein114c3cd2015-01-15 10:15:02 -08001419 }
mtkleinafae30a2016-02-24 12:28:32 -08001420
1421#ifdef SK_PDF_IMAGE_STATS
halcanary7a14b312015-10-01 07:28:13 -07001422 SkPDFImageDumpStats();
mtkleinafae30a2016-02-24 12:28:32 -08001423#endif // SK_PDF_IMAGE_STATS
1424
Herb Derby5a523fe2017-01-26 16:48:28 -05001425 SkGraphics::PurgeAllCaches();
mtkleinc41fd922016-03-08 09:01:39 -08001426 info("Finished!\n");
Brian Osman53136aa2017-07-20 15:43:35 -04001427
mtklein748ca3b2015-01-15 10:56:12 -08001428 return 0;
mtklein@google.comd36522d2013-10-16 13:02:15 +00001429}
jcgregorio3b27ade2014-11-13 08:06:40 -08001430
kkinnunen179a8f52015-11-20 13:32:24 -08001431// TODO: currently many GPU tests are declared outside SK_SUPPORT_GPU guards.
1432// Thus we export the empty RunWithGPUTestContexts when SK_SUPPORT_GPU=0.
1433namespace skiatest {
bsalomon758586c2016-04-06 14:02:39 -07001434
1435#if SK_SUPPORT_GPU
1436bool IsGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
1437 return kOpenGL_GrBackend == GrContextFactory::ContextTypeBackend(type);
1438}
bsalomondc0fcd42016-04-11 14:21:33 -07001439bool IsVulkanContextType(sk_gpu_test::GrContextFactory::ContextType type) {
1440 return kVulkan_GrBackend == GrContextFactory::ContextTypeBackend(type);
1441}
bsalomon758586c2016-04-06 14:02:39 -07001442bool IsRenderingGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
1443 return IsGLContextType(type) && GrContextFactory::IsRenderingContext(type);
1444}
1445bool IsNullGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
1446 return type == GrContextFactory::kNullGL_ContextType;
1447}
1448#else
1449bool IsGLContextType(int) { return false; }
bsalomondc0fcd42016-04-11 14:21:33 -07001450bool IsVulkanContextType(int) { return false; }
bsalomon758586c2016-04-06 14:02:39 -07001451bool IsRenderingGLContextType(int) { return false; }
1452bool IsNullGLContextType(int) { return false; }
1453#endif
1454
1455void RunWithGPUTestContexts(GrContextTestFn* test, GrContextTypeFilterFn* contextTypeFilter,
bsalomonf2f1c172016-04-05 12:59:06 -07001456 Reporter* reporter, GrContextFactory* factory) {
kkinnunen179a8f52015-11-20 13:32:24 -08001457#if SK_SUPPORT_GPU
kkinnunen3e980c32015-12-23 01:33:00 -08001458
Brian Salomon6405e712017-03-20 08:54:16 -04001459#if defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_WIN) || defined(SK_BUILD_FOR_MAC)
1460 static constexpr auto kNativeGLType = GrContextFactory::kGL_ContextType;
1461#else
1462 static constexpr auto kNativeGLType = GrContextFactory::kGLES_ContextType;
1463#endif
1464
bsalomon758586c2016-04-06 14:02:39 -07001465 for (int typeInt = 0; typeInt < GrContextFactory::kContextTypeCnt; ++typeInt) {
1466 GrContextFactory::ContextType contextType = (GrContextFactory::ContextType) typeInt;
Brian Osmanaa2219c2016-12-05 10:12:17 -05001467 // Use "native" instead of explicitly trying OpenGL and OpenGL ES. Do not use GLES on
bsalomon758586c2016-04-06 14:02:39 -07001468 // desktop since tests do not account for not fixing http://skbug.com/2809
1469 if (contextType == GrContextFactory::kGL_ContextType ||
1470 contextType == GrContextFactory::kGLES_ContextType) {
Brian Salomon6405e712017-03-20 08:54:16 -04001471 if (contextType != kNativeGLType) {
bsalomon758586c2016-04-06 14:02:39 -07001472 continue;
1473 }
1474 }
csmartdaltone812d492017-02-21 12:36:05 -07001475 ContextInfo ctxInfo = factory->getContextInfo(contextType,
1476 GrContextFactory::ContextOverrides::kDisableNVPR);
Brian Osmanaa2219c2016-12-05 10:12:17 -05001477 if (contextTypeFilter && !(*contextTypeFilter)(contextType)) {
1478 continue;
1479 }
Greg Daniela5cb7812017-06-16 09:45:32 -04001480 ReporterContext ctx(reporter, SkString(GrContextFactory::ContextTypeName(contextType)));
bsalomon8b7451a2016-05-11 06:33:06 -07001481 if (ctxInfo.grContext()) {
bsalomonf2f1c172016-04-05 12:59:06 -07001482 (*test)(reporter, ctxInfo);
Robert Phillipseaa90b22017-08-01 10:36:36 -04001483 ctxInfo.grContext()->flush();
kkinnunen5219fd92015-12-10 06:28:13 -08001484 }
bsalomonf2f1c172016-04-05 12:59:06 -07001485 ctxInfo = factory->getContextInfo(contextType,
csmartdaltone812d492017-02-21 12:36:05 -07001486 GrContextFactory::ContextOverrides::kRequireNVPRSupport);
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();
kkinnunen179a8f52015-11-20 13:32:24 -08001490 }
1491 }
1492#endif
1493}
kkinnunen179a8f52015-11-20 13:32:24 -08001494} // namespace skiatest