blob: 0644cc0d7dcf7da022f1de22e287f03c6933680f [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"
csmartdalton008b9d82017-02-22 12:00:42 -070021#include "SkCommonFlagsPathRenderer.h"
brianosman3c579dc2016-04-19 09:18:11 -070022#include "SkData.h"
Hal Canaryc7d295e2017-07-20 15:36:00 -040023#include "SkDocument.h"
Brian Salomondcbb9d92017-07-19 10:53:20 -040024#include "SkDebugfTracer.h"
Brian Osman53136aa2017-07-20 15:43:35 -040025#include "SkEventTracingPriv.h"
caryclark83ca6282015-06-10 09:31:09 -070026#include "SkFontMgr.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000027#include "SkGraphics.h"
mtklein27c3fdd2016-02-26 14:43:21 -080028#include "SkHalf.h"
halcanary4dbbd042016-06-07 17:21:10 -070029#include "SkLeanWindows.h"
mtklein748ca3b2015-01-15 10:56:12 -080030#include "SkMD5.h"
mtklein1b249332015-07-07 12:21:21 -070031#include "SkMutex.h"
mtklein1d0f1642014-09-08 08:05:18 -070032#include "SkOSFile.h"
Ben Wagnerbf111d72016-11-07 18:05:29 -050033#include "SkOSPath.h"
mtklein27c3fdd2016-02-26 14:43:21 -080034#include "SkPM4fPriv.h"
Mike Klein13b6afd2017-06-12 12:45:41 -040035#include "SkPngEncoder.h"
Brian Salomondcbb9d92017-07-19 10:53:20 -040036#include "SkScan.h"
mtklein246ba3a2016-02-23 10:39:36 -080037#include "SkSpinlock.h"
mtkleina82f5622015-02-20 12:30:19 -080038#include "SkTHash.h"
mtklein406654b2014-09-03 15:34:37 -070039#include "SkTaskGroup.h"
mtkleinde6fc2b2015-03-12 06:28:54 -070040#include "SkThreadUtils.h"
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000041#include "Test.h"
mtklein748ca3b2015-01-15 10:56:12 -080042#include "Timer.h"
Mike Kleinadacaef2017-02-06 09:26:14 -050043#include "ios_utils.h"
brianosman3c579dc2016-04-19 09:18:11 -070044#include "picture_utils.h"
caryclark83ca6282015-06-10 09:31:09 -070045#include "sk_tool_utils.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000046
scroggo19b91532016-10-24 09:03:26 -070047#include <vector>
48
halcanary7a14b312015-10-01 07:28:13 -070049#ifdef SK_PDF_IMAGE_STATS
50extern void SkPDFImageDumpStats();
51#endif
52
mtkleina5114d72015-08-24 13:27:01 -070053#include "png.h"
54
bungeman60e0fee2015-08-26 05:15:46 -070055#include <stdlib.h>
56
scroggo27a58342015-10-28 08:56:41 -070057#ifndef SK_BUILD_FOR_WIN32
58 #include <unistd.h>
59#endif
60
Mike Reed7c26ca72017-07-05 15:45:52 -040061extern bool gSkForceRasterPipelineBlitter;
62
Ben Wagner32fa5102017-08-10 21:25:55 -040063DECLARE_bool(undefok);
djsollen54416de2015-04-03 07:24:48 -070064DEFINE_string(src, "tests gm skp image", "Source types to test.");
mtklein748ca3b2015-01-15 10:56:12 -080065DEFINE_bool(nameByHash, false,
66 "If true, write to FLAGS_writePath[0]/<hash>.png instead of "
djsollen54416de2015-04-03 07:24:48 -070067 "to FLAGS_writePath[0]/<config>/<sourceType>/<sourceOptions>/<name>.png");
mtklein748ca3b2015-01-15 10:56:12 -080068DEFINE_bool2(pathOpsExtended, x, false, "Run extended pathOps tests.");
mtkleind603b222015-02-17 11:13:33 -080069DEFINE_string(matrix, "1 0 0 1",
70 "2x2 scale+skew matrix to apply or upright when using "
71 "'matrix' or 'upright' in config.");
mtklein82d28432015-01-15 12:46:02 -080072DEFINE_bool(gpu_threading, false, "Allow GPU work to run on multiple threads?");
mtklein@google.comd36522d2013-10-16 13:02:15 +000073
mtkleina2ef6422015-01-15 13:44:22 -080074DEFINE_string(blacklist, "",
djsollen54416de2015-04-03 07:24:48 -070075 "Space-separated config/src/srcOptions/name quadruples to blacklist. '_' matches anything. E.g. \n"
76 "'--blacklist gpu skp _ _' will blacklist all SKPs drawn into the gpu config.\n"
77 "'--blacklist gpu skp _ _ 8888 gm _ aarects' will also blacklist the aarects GM on 8888.");
mtkleina2ef6422015-01-15 13:44:22 -080078
mtklein62bd1a62015-01-27 14:46:26 -080079DEFINE_string2(readPath, r, "", "If set check for equality with golden results in this directory.");
80
borenet09ed4802015-04-03 14:15:33 -070081DEFINE_string(uninterestingHashesFile, "",
82 "File containing a list of uninteresting hashes. If a result hashes to something in "
83 "this list, no image is written for that result.");
84
mtklein6393c062015-04-27 08:45:01 -070085DEFINE_int32(shards, 1, "We're splitting source data into this many shards.");
86DEFINE_int32(shard, 0, "Which shard do I run?");
87
halcanary45420a92016-06-02 12:41:14 -070088DEFINE_string(mskps, "", "Directory to read mskps from, or a single mskp file.");
Mike Reed7c26ca72017-07-05 15:45:52 -040089DEFINE_bool(forceRasterPipeline, false, "sets gSkForceRasterPipelineBlitter");
halcanary45420a92016-06-02 12:41:14 -070090
csmartdalton008b9d82017-02-22 12:00:42 -070091#if SK_SUPPORT_GPU
92DEFINE_pathrenderer_flag;
93#endif
94
Derek Sollenbergeredfe3df2017-07-19 15:25:24 -040095DEFINE_bool(ignoreSigInt, false, "ignore SIGINT signals during test execution");
96
Mike Klein97d6a7a2017-07-24 10:37:19 -040097DEFINE_string(dont_write, "", "File extensions to skip writing to --writePath."); // See skia:6821
98
mtklein748ca3b2015-01-15 10:56:12 -080099using namespace DM;
bsalomon3724e572016-03-30 18:56:19 -0700100using sk_gpu_test::GrContextFactory;
bsalomon273c0f52016-03-31 10:59:06 -0700101using sk_gpu_test::GLTestContext;
bsalomonf2f1c172016-04-05 12:59:06 -0700102using sk_gpu_test::ContextInfo;
mtklein@google.comd36522d2013-10-16 13:02:15 +0000103
mtklein748ca3b2015-01-15 10:56:12 -0800104/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
105
benjaminwagnerec4d4d72016-03-25 12:59:53 -0700106static const double kStartMs = SkTime::GetMSecs();
mtkleinc41fd922016-03-08 09:01:39 -0800107
108static FILE* gVLog;
109
110template <typename... Args>
111static void vlog(const char* fmt, Args&&... args) {
112 if (gVLog) {
113 fprintf(gVLog, "%s\t", HumanizeMs(SkTime::GetMSecs() - kStartMs).c_str());
114 fprintf(gVLog, fmt, args...);
115 fflush(gVLog);
116 }
117}
118
119template <typename... Args>
120static void info(const char* fmt, Args&&... args) {
121 vlog(fmt, args...);
122 if (!FLAGS_quiet) {
123 printf(fmt, args...);
124 }
125}
126static void info(const char* fmt) {
127 if (!FLAGS_quiet) {
128 printf("%s", fmt); // Clang warns printf(fmt) is insecure.
129 }
130}
131
reed086eea92016-05-04 17:12:46 -0700132SK_DECLARE_STATIC_MUTEX(gFailuresMutex);
mtklein748ca3b2015-01-15 10:56:12 -0800133static SkTArray<SkString> gFailures;
134
mtklein3eed7dd2016-02-24 19:07:07 -0800135static void fail(const SkString& err) {
mtklein748ca3b2015-01-15 10:56:12 -0800136 SkAutoMutexAcquire lock(gFailuresMutex);
137 SkDebugf("\n\nFAILURE: %s\n\n", err.c_str());
138 gFailures.push_back(err);
halcanary9e398f72015-01-10 11:18:04 -0800139}
140
mtklein0f7748a2016-07-25 15:27:29 -0700141struct Running {
142 SkString id;
143 SkThreadID thread;
144
145 void dump() const {
146 info("\t%s\n", id.c_str());
147 }
148};
mtkleinb37cb412015-03-18 05:27:14 -0700149
mtklein246ba3a2016-02-23 10:39:36 -0800150// We use a spinlock to make locking this in a signal handler _somewhat_ safe.
Mike Klein03a95ad2017-06-23 12:36:32 -0400151static SkSpinlock gMutex;
152static int gPending;
mtklein0f7748a2016-07-25 15:27:29 -0700153static SkTArray<Running> gRunning;
mtklein748ca3b2015-01-15 10:56:12 -0800154
mtklein3eed7dd2016-02-24 19:07:07 -0800155static void done(const char* config, const char* src, const char* srcOptions, const char* name) {
156 SkString id = SkStringPrintf("%s %s %s %s", config, src, srcOptions, name);
mtkleinc41fd922016-03-08 09:01:39 -0800157 vlog("done %s\n", id.c_str());
mtkleinafae30a2016-02-24 12:28:32 -0800158 int pending;
mtkleinb37cb412015-03-18 05:27:14 -0700159 {
mtkleinf10637f2016-06-10 13:56:35 -0700160 SkAutoMutexAcquire lock(gMutex);
mtkleinb37cb412015-03-18 05:27:14 -0700161 for (int i = 0; i < gRunning.count(); i++) {
mtklein0f7748a2016-07-25 15:27:29 -0700162 if (gRunning[i].id == id) {
mtkleinb37cb412015-03-18 05:27:14 -0700163 gRunning.removeShuffle(i);
164 break;
165 }
166 }
mtkleinafae30a2016-02-24 12:28:32 -0800167 pending = --gPending;
reed50bc0512015-05-19 14:13:31 -0700168 }
Mike Klein03a95ad2017-06-23 12:36:32 -0400169
170 // We write out dm.json file and print out a progress update every once in a while.
171 // Notice this also handles the final dm.json and progress update when pending == 0.
mtkleina17241b2015-01-23 05:48:00 -0800172 if (pending % 500 == 0) {
173 JsonWriter::DumpJson();
Mike Klein03a95ad2017-06-23 12:36:32 -0400174
175 int curr = sk_tools::getCurrResidentSetSizeMB(),
176 peak = sk_tools::getMaxResidentSetSizeMB();
177 SkString elapsed = HumanizeMs(SkTime::GetMSecs() - kStartMs);
178
179 SkAutoMutexAcquire lock(gMutex);
180 info("\n%dMB RAM, %dMB peak, %s elapsed, %d queued, %d active:\n",
181 curr, peak, elapsed.c_str(), gPending - gRunning.count(), gRunning.count());
182 for (auto& task : gRunning) {
183 task.dump();
184 }
mtkleina17241b2015-01-23 05:48:00 -0800185 }
mtklein@google.comd36522d2013-10-16 13:02:15 +0000186}
187
mtklein3eed7dd2016-02-24 19:07:07 -0800188static void start(const char* config, const char* src, const char* srcOptions, const char* name) {
189 SkString id = SkStringPrintf("%s %s %s %s", config, src, srcOptions, name);
mtkleinc41fd922016-03-08 09:01:39 -0800190 vlog("start %s\n", id.c_str());
mtkleinf10637f2016-06-10 13:56:35 -0700191 SkAutoMutexAcquire lock(gMutex);
mtklein0f7748a2016-07-25 15:27:29 -0700192 gRunning.push_back({id,SkGetThreadID()});
mtkleinb37cb412015-03-18 05:27:14 -0700193}
194
Mike Klein3cc2d202016-10-24 11:39:43 -0400195static void find_culprit() {
196 // Assumes gMutex is locked.
197 SkThreadID thisThread = SkGetThreadID();
198 for (auto& task : gRunning) {
199 if (task.thread == thisThread) {
200 info("Likely culprit:\n");
201 task.dump();
mtklein0f7748a2016-07-25 15:27:29 -0700202 }
203 }
Mike Klein3cc2d202016-10-24 11:39:43 -0400204}
mtklein0f7748a2016-07-25 15:27:29 -0700205
mtklein246ba3a2016-02-23 10:39:36 -0800206#if defined(SK_BUILD_FOR_WIN32)
mtklein5b64dab2016-06-09 08:59:48 -0700207 static LONG WINAPI crash_handler(EXCEPTION_POINTERS* e) {
mtkleinf8557292016-02-29 06:35:28 -0800208 static const struct {
209 const char* name;
robertphillips75467862016-03-01 14:10:23 -0800210 DWORD code;
mtkleinf8557292016-02-29 06:35:28 -0800211 } kExceptions[] = {
212 #define _(E) {#E, E}
213 _(EXCEPTION_ACCESS_VIOLATION),
214 _(EXCEPTION_BREAKPOINT),
215 _(EXCEPTION_INT_DIVIDE_BY_ZERO),
216 _(EXCEPTION_STACK_OVERFLOW),
217 // TODO: more?
218 #undef _
219 };
220
mtkleinf10637f2016-06-10 13:56:35 -0700221 SkAutoMutexAcquire lock(gMutex);
mtklein5b64dab2016-06-09 08:59:48 -0700222
223 const DWORD code = e->ExceptionRecord->ExceptionCode;
224 info("\nCaught exception %u", code);
225 for (const auto& exception : kExceptions) {
226 if (exception.code == code) {
227 info(" %s", exception.name);
mtkleinf8557292016-02-29 06:35:28 -0800228 }
mtkleinf8557292016-02-29 06:35:28 -0800229 }
mtklein5b64dab2016-06-09 08:59:48 -0700230 info(", was running:\n");
231 for (auto& task : gRunning) {
mtklein0f7748a2016-07-25 15:27:29 -0700232 task.dump();
mtklein5b64dab2016-06-09 08:59:48 -0700233 }
mtklein0f7748a2016-07-25 15:27:29 -0700234 find_culprit();
mtklein5b64dab2016-06-09 08:59:48 -0700235 fflush(stdout);
236
mtkleinf8557292016-02-29 06:35:28 -0800237 // Execute default exception handler... hopefully, exit.
238 return EXCEPTION_EXECUTE_HANDLER;
mtklein246ba3a2016-02-23 10:39:36 -0800239 }
240
Mike Klein3cc2d202016-10-24 11:39:43 -0400241 static void setup_crash_handler() {
242 SetUnhandledExceptionFilter(crash_handler);
243 }
244#else
mtklein246ba3a2016-02-23 10:39:36 -0800245 #include <signal.h>
Mike Klein3cc2d202016-10-24 11:39:43 -0400246 #if !defined(SK_BUILD_FOR_ANDROID)
247 #include <execinfo.h>
Brian Salomondcbb9d92017-07-19 10:53:20 -0400248
249#endif
Mike Klein3cc2d202016-10-24 11:39:43 -0400250
251 static constexpr int max_of() { return 0; }
252 template <typename... Rest>
253 static constexpr int max_of(int x, Rest... rest) {
254 return x > max_of(rest...) ? x : max_of(rest...);
255 }
256
257 static void (*previous_handler[max_of(SIGABRT,SIGBUS,SIGFPE,SIGILL,SIGSEGV)+1])(int);
mtkleinf8557292016-02-29 06:35:28 -0800258
mtklein5b64dab2016-06-09 08:59:48 -0700259 static void crash_handler(int sig) {
mtkleinf10637f2016-06-10 13:56:35 -0700260 SkAutoMutexAcquire lock(gMutex);
mtklein5b64dab2016-06-09 08:59:48 -0700261
262 info("\nCaught signal %d [%s], was running:\n", sig, strsignal(sig));
263 for (auto& task : gRunning) {
mtklein0f7748a2016-07-25 15:27:29 -0700264 task.dump();
mtklein5b64dab2016-06-09 08:59:48 -0700265 }
mtklein0f7748a2016-07-25 15:27:29 -0700266 find_culprit();
mtklein5b64dab2016-06-09 08:59:48 -0700267
Mike Klein3cc2d202016-10-24 11:39:43 -0400268 #if !defined(SK_BUILD_FOR_ANDROID)
mtklein5b64dab2016-06-09 08:59:48 -0700269 void* stack[64];
270 int count = backtrace(stack, SK_ARRAY_COUNT(stack));
271 char** symbols = backtrace_symbols(stack, count);
272 info("\nStack trace:\n");
273 for (int i = 0; i < count; i++) {
274 info(" %s\n", symbols[i]);
275 }
Mike Klein3cc2d202016-10-24 11:39:43 -0400276 #endif
mtklein5b64dab2016-06-09 08:59:48 -0700277 fflush(stdout);
278
Mike Klein3cc2d202016-10-24 11:39:43 -0400279 signal(sig, previous_handler[sig]);
280 raise(sig);
mtklein5b64dab2016-06-09 08:59:48 -0700281 }
282
mtklein246ba3a2016-02-23 10:39:36 -0800283 static void setup_crash_handler() {
284 const int kSignals[] = { SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGSEGV };
285 for (int sig : kSignals) {
Mike Klein3cc2d202016-10-24 11:39:43 -0400286 previous_handler[sig] = signal(sig, crash_handler);
mtklein246ba3a2016-02-23 10:39:36 -0800287 }
Derek Sollenbergeredfe3df2017-07-19 15:25:24 -0400288
289 if (FLAGS_ignoreSigInt) {
290 signal(SIGINT, SIG_IGN);
291 }
mtklein246ba3a2016-02-23 10:39:36 -0800292 }
293#endif
294
mtklein748ca3b2015-01-15 10:56:12 -0800295/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
mtklein114c3cd2015-01-15 10:15:02 -0800296
mtklein62bd1a62015-01-27 14:46:26 -0800297struct Gold : public SkString {
mtkleina82f5622015-02-20 12:30:19 -0800298 Gold() : SkString("") {}
mtklein3eed7dd2016-02-24 19:07:07 -0800299 Gold(const SkString& sink, const SkString& src,
300 const SkString& srcOptions, const SkString& name,
301 const SkString& md5)
mtklein62bd1a62015-01-27 14:46:26 -0800302 : SkString("") {
303 this->append(sink);
304 this->append(src);
djsollen54416de2015-04-03 07:24:48 -0700305 this->append(srcOptions);
mtklein62bd1a62015-01-27 14:46:26 -0800306 this->append(name);
307 this->append(md5);
mtklein62bd1a62015-01-27 14:46:26 -0800308 }
mtkleinc8d1dd42015-10-15 12:23:01 -0700309 struct Hash {
310 uint32_t operator()(const Gold& g) const {
311 return SkGoodHash()((const SkString&)g);
312 }
313 };
mtklein62bd1a62015-01-27 14:46:26 -0800314};
mtkleina82f5622015-02-20 12:30:19 -0800315static SkTHashSet<Gold, Gold::Hash> gGold;
mtklein62bd1a62015-01-27 14:46:26 -0800316
317static void add_gold(JsonWriter::BitmapResult r) {
djsollen54416de2015-04-03 07:24:48 -0700318 gGold.add(Gold(r.config, r.sourceType, r.sourceOptions, r.name, r.md5));
mtklein62bd1a62015-01-27 14:46:26 -0800319}
320
321static void gather_gold() {
322 if (!FLAGS_readPath.isEmpty()) {
323 SkString path(FLAGS_readPath[0]);
324 path.append("/dm.json");
325 if (!JsonWriter::ReadJson(path.c_str(), add_gold)) {
326 fail(SkStringPrintf("Couldn't read %s for golden results.", path.c_str()));
327 }
328 }
329}
330
331/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
332
mtklein935f1b12016-03-16 08:37:19 -0700333#if defined(SK_BUILD_FOR_WIN32)
334 static const char* kNewline = "\r\n";
335#else
336 static const char* kNewline = "\n";
337#endif
338
borenet09ed4802015-04-03 14:15:33 -0700339static SkTHashSet<SkString> gUninterestingHashes;
340
341static void gather_uninteresting_hashes() {
342 if (!FLAGS_uninterestingHashesFile.isEmpty()) {
bungeman38d909e2016-08-02 14:40:46 -0700343 sk_sp<SkData> data(SkData::MakeFromFileName(FLAGS_uninterestingHashesFile[0]));
mtkleincc334b32015-09-22 11:43:53 -0700344 if (!data) {
mtkleinc41fd922016-03-08 09:01:39 -0800345 info("WARNING: unable to read uninteresting hashes from %s\n",
346 FLAGS_uninterestingHashesFile[0]);
mtkleincc334b32015-09-22 11:43:53 -0700347 return;
348 }
Mike Klein45dcc0c2017-04-05 18:04:31 -0400349
350 // Copy to a string to make sure SkStrSplit has a terminating \0 to find.
351 SkString contents((const char*)data->data(), data->size());
352
borenet09ed4802015-04-03 14:15:33 -0700353 SkTArray<SkString> hashes;
Mike Klein45dcc0c2017-04-05 18:04:31 -0400354 SkStrSplit(contents.c_str(), kNewline, &hashes);
borenet09ed4802015-04-03 14:15:33 -0700355 for (const SkString& hash : hashes) {
356 gUninterestingHashes.add(hash);
357 }
mtkleinc41fd922016-03-08 09:01:39 -0800358 info("FYI: loaded %d distinct uninteresting hashes from %d lines\n",
359 gUninterestingHashes.count(), hashes.count());
borenet09ed4802015-04-03 14:15:33 -0700360 }
361}
362
363/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
364
Ben Wagner145dbcd2016-11-03 14:40:50 -0400365struct TaggedSrc : public std::unique_ptr<Src> {
mtklein3eed7dd2016-02-24 19:07:07 -0800366 SkString tag;
367 SkString options;
mtkleine0effd62015-07-29 06:37:28 -0700368};
369
Ben Wagner145dbcd2016-11-03 14:40:50 -0400370struct TaggedSink : public std::unique_ptr<Sink> {
kkinnunen3e980c32015-12-23 01:33:00 -0800371 SkString tag;
djsollen54416de2015-04-03 07:24:48 -0700372};
mtklein748ca3b2015-01-15 10:56:12 -0800373
374static const bool kMemcpyOK = true;
375
mtkleine0effd62015-07-29 06:37:28 -0700376static SkTArray<TaggedSrc, kMemcpyOK> gSrcs;
377static SkTArray<TaggedSink, kMemcpyOK> gSinks;
mtklein748ca3b2015-01-15 10:56:12 -0800378
mtklein6393c062015-04-27 08:45:01 -0700379static bool in_shard() {
380 static int N = 0;
381 return N++ % FLAGS_shards == FLAGS_shard;
382}
383
mtklein3eed7dd2016-02-24 19:07:07 -0800384static void push_src(const char* tag, ImplicitString options, Src* s) {
Ben Wagner145dbcd2016-11-03 14:40:50 -0400385 std::unique_ptr<Src> src(s);
mtklein6393c062015-04-27 08:45:01 -0700386 if (in_shard() &&
mtklein3eed7dd2016-02-24 19:07:07 -0800387 FLAGS_src.contains(tag) &&
mtklein748ca3b2015-01-15 10:56:12 -0800388 !SkCommandLineFlags::ShouldSkip(FLAGS_match, src->name().c_str())) {
mtkleine0effd62015-07-29 06:37:28 -0700389 TaggedSrc& s = gSrcs.push_back();
mtklein18300a32016-03-16 13:53:35 -0700390 s.reset(src.release());
mtklein748ca3b2015-01-15 10:56:12 -0800391 s.tag = tag;
djsollen54416de2015-04-03 07:24:48 -0700392 s.options = options;
mtklein114c3cd2015-01-15 10:15:02 -0800393 }
mtklein748ca3b2015-01-15 10:56:12 -0800394}
mtklein114c3cd2015-01-15 10:15:02 -0800395
msarett9e707a02015-09-01 14:57:57 -0700396static void push_codec_src(Path path, CodecSrc::Mode mode, CodecSrc::DstColorType dstColorType,
scroggoc5560be2016-02-03 09:42:42 -0800397 SkAlphaType dstAlphaType, float scale) {
scroggoe4499842016-02-25 11:03:47 -0800398 if (FLAGS_simpleCodec) {
scroggo19b91532016-10-24 09:03:26 -0700399 const bool simple = CodecSrc::kCodec_Mode == mode || CodecSrc::kAnimated_Mode == mode;
400 if (!simple || dstColorType != CodecSrc::kGetFromCanvas_DstColorType || scale != 1.0f) {
scroggoe4499842016-02-25 11:03:47 -0800401 // Only decode in the simple case.
402 return;
scroggo19b91532016-10-24 09:03:26 -0700403 }
scroggoe4499842016-02-25 11:03:47 -0800404 }
msarett9e707a02015-09-01 14:57:57 -0700405 SkString folder;
406 switch (mode) {
407 case CodecSrc::kCodec_Mode:
408 folder.append("codec");
409 break;
msarettbb25b532016-01-13 09:31:39 -0800410 case CodecSrc::kCodecZeroInit_Mode:
411 folder.append("codec_zero_init");
412 break;
msarett9e707a02015-09-01 14:57:57 -0700413 case CodecSrc::kScanline_Mode:
414 folder.append("scanline");
415 break;
msarett9e707a02015-09-01 14:57:57 -0700416 case CodecSrc::kStripe_Mode:
417 folder.append("stripe");
418 break;
msarett91c22b22016-02-22 12:27:46 -0800419 case CodecSrc::kCroppedScanline_Mode:
420 folder.append("crop");
421 break;
msarett9e707a02015-09-01 14:57:57 -0700422 case CodecSrc::kSubset_Mode:
msarett36c37962015-09-02 13:20:52 -0700423 folder.append("codec_subset");
msarett9e707a02015-09-01 14:57:57 -0700424 break;
scroggo19b91532016-10-24 09:03:26 -0700425 case CodecSrc::kAnimated_Mode:
426 folder.append("codec_animated");
427 break;
msarett9e707a02015-09-01 14:57:57 -0700428 }
429
430 switch (dstColorType) {
431 case CodecSrc::kGrayscale_Always_DstColorType:
432 folder.append("_kGray8");
433 break;
msarett34e0ec42016-04-22 16:27:24 -0700434 case CodecSrc::kNonNative8888_Always_DstColorType:
435 folder.append("_kNonNative");
436 break;
msarett9e707a02015-09-01 14:57:57 -0700437 default:
438 break;
439 }
440
scroggoc5560be2016-02-03 09:42:42 -0800441 switch (dstAlphaType) {
scroggoc5560be2016-02-03 09:42:42 -0800442 case kPremul_SkAlphaType:
443 folder.append("_premul");
444 break;
445 case kUnpremul_SkAlphaType:
446 folder.append("_unpremul");
447 break;
448 default:
449 break;
450 }
451
msarett9e707a02015-09-01 14:57:57 -0700452 if (1.0f != scale) {
453 folder.appendf("_%.3f", scale);
454 }
455
scroggoc5560be2016-02-03 09:42:42 -0800456 CodecSrc* src = new CodecSrc(path, mode, dstColorType, dstAlphaType, scale);
msarett9e707a02015-09-01 14:57:57 -0700457 push_src("image", folder, src);
458}
459
scroggof8dc9df2016-05-16 09:04:13 -0700460static void push_android_codec_src(Path path, CodecSrc::DstColorType dstColorType,
461 SkAlphaType dstAlphaType, int sampleSize) {
msarett3d9d7a72015-10-21 10:27:10 -0700462 SkString folder;
scroggof8dc9df2016-05-16 09:04:13 -0700463 folder.append("scaled_codec");
msarett3d9d7a72015-10-21 10:27:10 -0700464
465 switch (dstColorType) {
466 case CodecSrc::kGrayscale_Always_DstColorType:
467 folder.append("_kGray8");
468 break;
msarett34e0ec42016-04-22 16:27:24 -0700469 case CodecSrc::kNonNative8888_Always_DstColorType:
470 folder.append("_kNonNative");
471 break;
msarett3d9d7a72015-10-21 10:27:10 -0700472 default:
473 break;
474 }
475
scroggoc5560be2016-02-03 09:42:42 -0800476 switch (dstAlphaType) {
scroggoc5560be2016-02-03 09:42:42 -0800477 case kPremul_SkAlphaType:
478 folder.append("_premul");
479 break;
msarett9e9444c2016-02-03 12:39:10 -0800480 case kUnpremul_SkAlphaType:
481 folder.append("_unpremul");
482 break;
scroggoc5560be2016-02-03 09:42:42 -0800483 default:
484 break;
485 }
486
msarett3d9d7a72015-10-21 10:27:10 -0700487 if (1 != sampleSize) {
msarett4b0778e2015-11-13 09:59:11 -0800488 folder.appendf("_%.3f", 1.0f / (float) sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700489 }
490
scroggof8dc9df2016-05-16 09:04:13 -0700491 AndroidCodecSrc* src = new AndroidCodecSrc(path, dstColorType, dstAlphaType, sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700492 push_src("image", folder, src);
493}
494
msarett18976312016-03-09 14:20:58 -0800495static void push_image_gen_src(Path path, ImageGenSrc::Mode mode, SkAlphaType alphaType, bool isGpu)
496{
497 SkString folder;
498 switch (mode) {
499 case ImageGenSrc::kCodec_Mode:
500 folder.append("gen_codec");
501 break;
502 case ImageGenSrc::kPlatform_Mode:
503 folder.append("gen_platform");
504 break;
505 }
506
507 if (isGpu) {
508 folder.append("_gpu");
509 } else {
510 switch (alphaType) {
511 case kOpaque_SkAlphaType:
512 folder.append("_opaque");
513 break;
514 case kPremul_SkAlphaType:
515 folder.append("_premul");
516 break;
517 case kUnpremul_SkAlphaType:
518 folder.append("_unpremul");
519 break;
520 default:
521 break;
522 }
523 }
524
525 ImageGenSrc* src = new ImageGenSrc(path, mode, alphaType, isGpu);
526 push_src("image", folder, src);
527}
528
msarett438b2ad2015-04-09 12:43:10 -0700529static void push_codec_srcs(Path path) {
bungeman38d909e2016-08-02 14:40:46 -0700530 sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str()));
msarett438b2ad2015-04-09 12:43:10 -0700531 if (!encoded) {
mtkleinc41fd922016-03-08 09:01:39 -0800532 info("Couldn't read %s.", path.c_str());
msarett438b2ad2015-04-09 12:43:10 -0700533 return;
534 }
Mike Reedede7bac2017-07-23 15:30:02 -0400535 std::unique_ptr<SkCodec> codec = SkCodec::MakeFromData(encoded);
halcanary96fcdcc2015-08-27 07:41:13 -0700536 if (nullptr == codec.get()) {
mtkleinc41fd922016-03-08 09:01:39 -0800537 info("Couldn't create codec for %s.", path.c_str());
msarett438b2ad2015-04-09 12:43:10 -0700538 return;
539 }
540
scroggo9366aff2016-05-20 08:38:54 -0700541 // native scaling is only supported by WEBP and JPEG
542 bool supportsNativeScaling = false;
msarett438b2ad2015-04-09 12:43:10 -0700543
msarett91c22b22016-02-22 12:27:46 -0800544 SkTArray<CodecSrc::Mode> nativeModes;
545 nativeModes.push_back(CodecSrc::kCodec_Mode);
546 nativeModes.push_back(CodecSrc::kCodecZeroInit_Mode);
msarett91c22b22016-02-22 12:27:46 -0800547 switch (codec->getEncodedFormat()) {
Hal Canarydb683012016-11-23 08:55:18 -0700548 case SkEncodedImageFormat::kJPEG:
msarett91c22b22016-02-22 12:27:46 -0800549 nativeModes.push_back(CodecSrc::kScanline_Mode);
550 nativeModes.push_back(CodecSrc::kStripe_Mode);
551 nativeModes.push_back(CodecSrc::kCroppedScanline_Mode);
scroggo9366aff2016-05-20 08:38:54 -0700552 supportsNativeScaling = true;
msarett91c22b22016-02-22 12:27:46 -0800553 break;
Hal Canarydb683012016-11-23 08:55:18 -0700554 case SkEncodedImageFormat::kWEBP:
msarett91c22b22016-02-22 12:27:46 -0800555 nativeModes.push_back(CodecSrc::kSubset_Mode);
scroggo9366aff2016-05-20 08:38:54 -0700556 supportsNativeScaling = true;
msarett91c22b22016-02-22 12:27:46 -0800557 break;
Hal Canarydb683012016-11-23 08:55:18 -0700558 case SkEncodedImageFormat::kDNG:
msarettb65e6042016-02-23 05:37:25 -0800559 break;
msarett91c22b22016-02-22 12:27:46 -0800560 default:
561 nativeModes.push_back(CodecSrc::kScanline_Mode);
msarett91c22b22016-02-22 12:27:46 -0800562 break;
563 }
msarett9e707a02015-09-01 14:57:57 -0700564
msarett91c22b22016-02-22 12:27:46 -0800565 SkTArray<CodecSrc::DstColorType> colorTypes;
566 colorTypes.push_back(CodecSrc::kGetFromCanvas_DstColorType);
msarett34e0ec42016-04-22 16:27:24 -0700567 colorTypes.push_back(CodecSrc::kNonNative8888_Always_DstColorType);
msarett36c37962015-09-02 13:20:52 -0700568 switch (codec->getInfo().colorType()) {
569 case kGray_8_SkColorType:
msarett91c22b22016-02-22 12:27:46 -0800570 colorTypes.push_back(CodecSrc::kGrayscale_Always_DstColorType);
msarett36c37962015-09-02 13:20:52 -0700571 break;
572 default:
msarett36c37962015-09-02 13:20:52 -0700573 break;
574 }
msarett9e707a02015-09-01 14:57:57 -0700575
scroggoc5560be2016-02-03 09:42:42 -0800576 SkTArray<SkAlphaType> alphaModes;
577 alphaModes.push_back(kPremul_SkAlphaType);
scroggof2c96a22016-05-20 11:08:27 -0700578 if (codec->getInfo().alphaType() != kOpaque_SkAlphaType) {
579 alphaModes.push_back(kUnpremul_SkAlphaType);
scroggoc5560be2016-02-03 09:42:42 -0800580 }
msarettb714fb02016-01-22 14:46:42 -0800581
582 for (CodecSrc::Mode mode : nativeModes) {
scroggo9366aff2016-05-20 08:38:54 -0700583 for (CodecSrc::DstColorType colorType : colorTypes) {
584 for (SkAlphaType alphaType : alphaModes) {
scroggof2c96a22016-05-20 11:08:27 -0700585 // Only test kCroppedScanline_Mode when the alpha type is premul. The test is
scroggo9366aff2016-05-20 08:38:54 -0700586 // slow and won't be interestingly different with different alpha types.
587 if (CodecSrc::kCroppedScanline_Mode == mode &&
scroggof2c96a22016-05-20 11:08:27 -0700588 kPremul_SkAlphaType != alphaType) {
scroggo9366aff2016-05-20 08:38:54 -0700589 continue;
590 }
msarett91c22b22016-02-22 12:27:46 -0800591
scroggo9366aff2016-05-20 08:38:54 -0700592 push_codec_src(path, mode, colorType, alphaType, 1.0f);
msarettf3dc1882016-04-26 13:06:38 -0700593
scroggo9366aff2016-05-20 08:38:54 -0700594 // Skip kNonNative on different native scales. It won't be interestingly
595 // different.
596 if (supportsNativeScaling &&
597 CodecSrc::kNonNative8888_Always_DstColorType == colorType) {
598 // Native Scales
599 // SkJpegCodec natively supports scaling to the following:
600 for (auto scale : { 0.125f, 0.25f, 0.375f, 0.5f, 0.625f, 0.750f, 0.875f }) {
601 push_codec_src(path, mode, colorType, alphaType, scale);
602 }
scroggoc5560be2016-02-03 09:42:42 -0800603 }
msarett9e707a02015-09-01 14:57:57 -0700604 }
605 }
msarett0a242972015-06-11 14:27:27 -0700606 }
msarett36c37962015-09-02 13:20:52 -0700607
scroggo19b91532016-10-24 09:03:26 -0700608 {
609 std::vector<SkCodec::FrameInfo> frameInfos = codec->getFrameInfo();
610 if (frameInfos.size() > 1) {
Leon Scroggins III557fbbe2017-05-23 09:37:21 -0400611 for (auto dstCT : { CodecSrc::kNonNative8888_Always_DstColorType,
612 CodecSrc::kGetFromCanvas_DstColorType }) {
613 for (auto at : { kUnpremul_SkAlphaType, kPremul_SkAlphaType }) {
614 push_codec_src(path, CodecSrc::kAnimated_Mode, dstCT, at, 1.0f);
615 }
616 }
scroggo19b91532016-10-24 09:03:26 -0700617 }
618
619 }
620
scroggoe4499842016-02-25 11:03:47 -0800621 if (FLAGS_simpleCodec) {
622 return;
623 }
624
msarett3d9d7a72015-10-21 10:27:10 -0700625 const int sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
msarett36c37962015-09-02 13:20:52 -0700626
msarett3d9d7a72015-10-21 10:27:10 -0700627 for (int sampleSize : sampleSizes) {
msarett91c22b22016-02-22 12:27:46 -0800628 for (CodecSrc::DstColorType colorType : colorTypes) {
scroggoc5560be2016-02-03 09:42:42 -0800629 for (SkAlphaType alphaType : alphaModes) {
msarettf3dc1882016-04-26 13:06:38 -0700630 // We can exercise all of the kNonNative support code in the swizzler with just a
631 // few sample sizes. Skip the rest.
632 if (CodecSrc::kNonNative8888_Always_DstColorType == colorType && sampleSize > 3) {
633 continue;
634 }
635
scroggof8dc9df2016-05-16 09:04:13 -0700636 push_android_codec_src(path, colorType, alphaType, sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700637 }
msarett36c37962015-09-02 13:20:52 -0700638 }
639 }
msarett18976312016-03-09 14:20:58 -0800640
641 static const char* const rawExts[] = {
642 "arw", "cr2", "dng", "nef", "nrw", "orf", "raf", "rw2", "pef", "srw",
643 "ARW", "CR2", "DNG", "NEF", "NRW", "ORF", "RAF", "RW2", "PEF", "SRW",
644 };
645
646 // There is not currently a reason to test RAW images on image generator.
647 // If we want to enable these tests, we will need to fix skbug.com/5079.
648 for (const char* ext : rawExts) {
649 if (path.endsWith(ext)) {
650 return;
651 }
652 }
653
654 // Push image generator GPU test.
brianosmanc9ced392016-03-24 07:27:43 -0700655 push_image_gen_src(path, ImageGenSrc::kCodec_Mode, codec->getInfo().alphaType(), true);
msarett18976312016-03-09 14:20:58 -0800656
657 // Push image generator CPU tests.
658 for (SkAlphaType alphaType : alphaModes) {
659 push_image_gen_src(path, ImageGenSrc::kCodec_Mode, alphaType, false);
660
661#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
Hal Canarydb683012016-11-23 08:55:18 -0700662 if (SkEncodedImageFormat::kWEBP != codec->getEncodedFormat() &&
663 SkEncodedImageFormat::kWBMP != codec->getEncodedFormat() &&
msarett18976312016-03-09 14:20:58 -0800664 kUnpremul_SkAlphaType != alphaType)
665 {
666 push_image_gen_src(path, ImageGenSrc::kPlatform_Mode, alphaType, false);
667 }
msarettfc0b6d12016-03-17 13:50:17 -0700668#elif defined(SK_BUILD_FOR_WIN)
Hal Canarydb683012016-11-23 08:55:18 -0700669 if (SkEncodedImageFormat::kWEBP != codec->getEncodedFormat() &&
670 SkEncodedImageFormat::kWBMP != codec->getEncodedFormat())
msarettfc0b6d12016-03-17 13:50:17 -0700671 {
672 push_image_gen_src(path, ImageGenSrc::kPlatform_Mode, alphaType, false);
673 }
msarett18976312016-03-09 14:20:58 -0800674#endif
675 }
msarett438b2ad2015-04-09 12:43:10 -0700676}
677
msarettd1227a72016-05-18 06:23:57 -0700678static void push_brd_src(Path path, CodecSrc::DstColorType dstColorType, BRDSrc::Mode mode,
679 uint32_t sampleSize) {
680 SkString folder("brd_android_codec");
msaretta5783ae2015-09-08 15:35:32 -0700681 switch (mode) {
682 case BRDSrc::kFullImage_Mode:
683 break;
684 case BRDSrc::kDivisor_Mode:
685 folder.append("_divisor");
686 break;
687 default:
688 SkASSERT(false);
689 return;
690 }
691
692 switch (dstColorType) {
693 case CodecSrc::kGetFromCanvas_DstColorType:
694 break;
msaretta5783ae2015-09-08 15:35:32 -0700695 case CodecSrc::kGrayscale_Always_DstColorType:
696 folder.append("_kGray");
697 break;
698 default:
699 SkASSERT(false);
700 return;
701 }
702
703 if (1 != sampleSize) {
msarett4b0778e2015-11-13 09:59:11 -0800704 folder.appendf("_%.3f", 1.0f / (float) sampleSize);
msaretta5783ae2015-09-08 15:35:32 -0700705 }
706
msarettd1227a72016-05-18 06:23:57 -0700707 BRDSrc* src = new BRDSrc(path, mode, dstColorType, sampleSize);
msaretta5783ae2015-09-08 15:35:32 -0700708 push_src("image", folder, src);
709}
710
711static void push_brd_srcs(Path path) {
Leon Scroggins IIIbace7a92017-07-05 11:39:27 -0400712 // Only run grayscale to one sampleSize and Mode. Though interesting
713 // to test grayscale, it should not reveal anything across various
scroggo24a9bd72016-05-20 06:02:42 -0700714 // sampleSizes and Modes
Leon Scroggins IIIbace7a92017-07-05 11:39:27 -0400715 // Arbitrarily choose Mode and sampleSize.
716 push_brd_src(path, CodecSrc::kGrayscale_Always_DstColorType, BRDSrc::kFullImage_Mode, 2);
scroggo24a9bd72016-05-20 06:02:42 -0700717
718
scroggo501b7342015-11-03 07:55:11 -0800719 // Test on a variety of sampleSizes, making sure to include:
720 // - 2, 4, and 8, which are natively supported by jpeg
721 // - multiples of 2 which are not divisible by 4 (analogous for 4)
722 // - larger powers of two, since BRD clients generally use powers of 2
723 // We will only produce output for the larger sizes on large images.
724 const uint32_t sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 24, 32, 64 };
msarett6efbe052015-09-11 09:01:16 -0700725
msaretta5783ae2015-09-08 15:35:32 -0700726 const BRDSrc::Mode modes[] = {
msarett26ad17b2015-10-22 07:29:19 -0700727 BRDSrc::kFullImage_Mode,
728 BRDSrc::kDivisor_Mode,
msaretta5783ae2015-09-08 15:35:32 -0700729 };
730
msarettd1227a72016-05-18 06:23:57 -0700731 for (uint32_t sampleSize : sampleSizes) {
scroggo24a9bd72016-05-20 06:02:42 -0700732 for (BRDSrc::Mode mode : modes) {
733 push_brd_src(path, CodecSrc::kGetFromCanvas_DstColorType, mode, sampleSize);
msaretta5783ae2015-09-08 15:35:32 -0700734 }
735 }
736}
737
738static bool brd_supported(const char* ext) {
msarett8c8f22a2015-04-01 06:58:48 -0700739 static const char* const exts[] = {
msaretta5783ae2015-09-08 15:35:32 -0700740 "jpg", "jpeg", "png", "webp",
741 "JPG", "JPEG", "PNG", "WEBP",
msarett8c8f22a2015-04-01 06:58:48 -0700742 };
743
744 for (uint32_t i = 0; i < SK_ARRAY_COUNT(exts); i++) {
745 if (0 == strcmp(exts[i], ext)) {
746 return true;
747 }
748 }
749 return false;
scroggo9b77ddd2015-03-19 06:03:39 -0700750}
751
fmalitaa2b9fdf2016-08-03 19:53:36 -0700752template <typename T>
753void gather_file_srcs(const SkCommandLineFlags::StringArray& flags, const char* ext) {
754 for (int i = 0; i < flags.count(); i++) {
755 const char* path = flags[i];
756 if (sk_isdir(path)) {
757 SkOSFile::Iter it(path, ext);
758 for (SkString file; it.next(&file); ) {
759 push_src(ext, "", new T(SkOSPath::Join(path, file.c_str())));
760 }
761 } else {
762 push_src(ext, "", new T(path));
763 }
764 }
765}
766
scroggo86737142016-02-03 12:19:11 -0800767static bool gather_srcs() {
mtklein748ca3b2015-01-15 10:56:12 -0800768 for (const skiagm::GMRegistry* r = skiagm::GMRegistry::Head(); r; r = r->next()) {
djsollen54416de2015-04-03 07:24:48 -0700769 push_src("gm", "", new GMSrc(r->factory()));
mtklein748ca3b2015-01-15 10:56:12 -0800770 }
scroggo86737142016-02-03 12:19:11 -0800771
fmalitaa2b9fdf2016-08-03 19:53:36 -0700772 gather_file_srcs<SKPSrc>(FLAGS_skps, "skp");
773 gather_file_srcs<MSKPSrc>(FLAGS_mskps, "mskp");
774#if defined(SK_XML)
775 gather_file_srcs<SVGSrc>(FLAGS_svgs, "svg");
776#endif
halcanary45420a92016-06-02 12:41:14 -0700777
scroggo86737142016-02-03 12:19:11 -0800778 SkTArray<SkString> images;
msarett69deca82016-04-29 09:38:40 -0700779 if (!CollectImages(FLAGS_images, &images)) {
scroggo86737142016-02-03 12:19:11 -0800780 return false;
781 }
782
783 for (auto image : images) {
784 push_codec_srcs(image);
scroggoe4499842016-02-25 11:03:47 -0800785 if (FLAGS_simpleCodec) {
786 continue;
787 }
788
mtklein21eaf3b2016-02-08 12:39:59 -0800789 const char* ext = strrchr(image.c_str(), '.');
790 if (ext && brd_supported(ext+1)) {
scroggo86737142016-02-03 12:19:11 -0800791 push_brd_srcs(image);
mtklein709d2c32015-01-15 08:30:25 -0800792 }
mtklein709d2c32015-01-15 08:30:25 -0800793 }
scroggo86737142016-02-03 12:19:11 -0800794
msarett69deca82016-04-29 09:38:40 -0700795 SkTArray<SkString> colorImages;
796 if (!CollectImages(FLAGS_colorImages, &colorImages)) {
797 return false;
798 }
799
800 for (auto colorImage : colorImages) {
msarett9ce3a542016-07-15 13:54:38 -0700801 ColorCodecSrc* src = new ColorCodecSrc(colorImage, ColorCodecSrc::kBaseline_Mode,
802 kN32_SkColorType);
msarettb8d1aac2016-08-04 12:22:06 -0700803 push_src("colorImage", "color_codec_baseline", src);
msarett888dc162016-05-23 10:21:17 -0700804
msarett9ce3a542016-07-15 13:54:38 -0700805 src = new ColorCodecSrc(colorImage, ColorCodecSrc::kDst_HPZR30w_Mode, kN32_SkColorType);
msarettb8d1aac2016-08-04 12:22:06 -0700806 push_src("colorImage", "color_codec_HPZR30w", src);
msarett9ce3a542016-07-15 13:54:38 -0700807 // TODO (msarett):
808 // 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 -0700809
msarett9ce3a542016-07-15 13:54:38 -0700810 src = new ColorCodecSrc(colorImage, ColorCodecSrc::kDst_sRGB_Mode, kN32_SkColorType);
msarettb8d1aac2016-08-04 12:22:06 -0700811 push_src("colorImage", "color_codec_sRGB_kN32", src);
msarett9ce3a542016-07-15 13:54:38 -0700812 src = new ColorCodecSrc(colorImage, ColorCodecSrc::kDst_sRGB_Mode, kRGBA_F16_SkColorType);
msarettb8d1aac2016-08-04 12:22:06 -0700813 push_src("colorImage", "color_codec_sRGB_kF16", src);
msarett69deca82016-04-29 09:38:40 -0700814 }
815
scroggo86737142016-02-03 12:19:11 -0800816 return true;
mtklein709d2c32015-01-15 08:30:25 -0800817}
818
kkinnunen3e980c32015-12-23 01:33:00 -0800819static void push_sink(const SkCommandLineConfig& config, Sink* s) {
Ben Wagner145dbcd2016-11-03 14:40:50 -0400820 std::unique_ptr<Sink> sink(s);
kkinnunen3e980c32015-12-23 01:33:00 -0800821
mtkleine0effd62015-07-29 06:37:28 -0700822 // Try a simple Src as a canary. If it fails, skip this sink.
mtklein748ca3b2015-01-15 10:56:12 -0800823 struct : public Src {
mtkleine0effd62015-07-29 06:37:28 -0700824 Error draw(SkCanvas* c) const override {
825 c->drawRect(SkRect::MakeWH(1,1), SkPaint());
826 return "";
827 }
mtklein36352bf2015-03-25 18:17:31 -0700828 SkISize size() const override { return SkISize::Make(16, 16); }
mtkleine0effd62015-07-29 06:37:28 -0700829 Name name() const override { return "justOneRect"; }
830 } justOneRect;
mtklein114c3cd2015-01-15 10:15:02 -0800831
mtklein748ca3b2015-01-15 10:56:12 -0800832 SkBitmap bitmap;
833 SkDynamicMemoryWStream stream;
mtkleinb9eb4ac2015-02-02 18:26:03 -0800834 SkString log;
mtkleine0effd62015-07-29 06:37:28 -0700835 Error err = sink->draw(justOneRect, &bitmap, &stream, &log);
mtklein4089ef72015-03-05 08:40:28 -0800836 if (err.isFatal()) {
mtkleinc41fd922016-03-08 09:01:39 -0800837 info("Could not run %s: %s\n", config.getTag().c_str(), err.c_str());
mtklein05641a52015-04-21 10:49:13 -0700838 exit(1);
mtklein114c3cd2015-01-15 10:15:02 -0800839 }
840
mtkleine0effd62015-07-29 06:37:28 -0700841 TaggedSink& ts = gSinks.push_back();
mtklein18300a32016-03-16 13:53:35 -0700842 ts.reset(sink.release());
kkinnunen3e980c32015-12-23 01:33:00 -0800843 ts.tag = config.getTag();
mtklein748ca3b2015-01-15 10:56:12 -0800844}
845
846static bool gpu_supported() {
847#if SK_SUPPORT_GPU
848 return FLAGS_gpu;
849#else
850 return false;
851#endif
852}
kkinnunen9ebc3f02015-12-21 23:48:13 -0800853
csmartdalton008b9d82017-02-22 12:00:42 -0700854static Sink* create_sink(const GrContextOptions& grCtxOptions, const SkCommandLineConfig* config) {
kkinnunen3e980c32015-12-23 01:33:00 -0800855#if SK_SUPPORT_GPU
856 if (gpu_supported()) {
857 if (const SkCommandLineConfigGpu* gpuConfig = config->asConfigGpu()) {
bsalomon85b4b532016-04-05 11:06:27 -0700858 GrContextFactory::ContextType contextType = gpuConfig->getContextType();
csmartdaltone812d492017-02-21 12:36:05 -0700859 GrContextFactory::ContextOverrides contextOverrides = gpuConfig->getContextOverrides();
csmartdalton008b9d82017-02-22 12:00:42 -0700860 GrContextFactory testFactory(grCtxOptions);
csmartdaltone812d492017-02-21 12:36:05 -0700861 if (!testFactory.get(contextType, contextOverrides)) {
mtkleinc41fd922016-03-08 09:01:39 -0800862 info("WARNING: can not create GPU context for config '%s'. "
863 "GM tests will be skipped.\n", gpuConfig->getTag().c_str());
kkinnunen3e980c32015-12-23 01:33:00 -0800864 return nullptr;
865 }
csmartdaltone812d492017-02-21 12:36:05 -0700866 return new GPUSink(contextType, contextOverrides, gpuConfig->getSamples(),
brianosmand93c1202016-03-10 07:49:08 -0800867 gpuConfig->getUseDIText(), gpuConfig->getColorType(),
Brian Salomonce5ee602017-07-17 11:31:31 -0400868 gpuConfig->getAlphaType(), sk_ref_sp(gpuConfig->getColorSpace()),
869 FLAGS_gpu_threading);
kkinnunen3e980c32015-12-23 01:33:00 -0800870 }
871 }
872#endif
873
874#define SINK(t, sink, ...) if (config->getBackend().equals(t)) { return new sink(__VA_ARGS__); }
875
mtklein748ca3b2015-01-15 10:56:12 -0800876 if (FLAGS_cpu) {
Matt Sarett77a7a1b2017-02-07 13:56:11 -0500877 auto srgbColorSpace = SkColorSpace::MakeSRGB();
878 auto srgbLinearColorSpace = SkColorSpace::MakeSRGBLinear();
brianosmanb109b8c2016-06-16 13:03:24 -0700879
Matt Sarettd2228302017-03-02 08:53:46 -0500880 SINK("565", RasterSink, kRGB_565_SkColorType);
881 SINK("8888", RasterSink, kN32_SkColorType);
882 SINK("srgb", RasterSink, kN32_SkColorType, srgbColorSpace);
Matt Sarettd2228302017-03-02 08:53:46 -0500883 SINK("f16", RasterSink, kRGBA_F16_SkColorType, srgbLinearColorSpace);
Hal Canaryc7d295e2017-07-20 15:36:00 -0400884 SINK("pdf", PDFSink, false, SK_ScalarDefaultRasterDPI);
Matt Sarettd2228302017-03-02 08:53:46 -0500885 SINK("skp", SKPSink);
886 SINK("pipe", PipeSink);
887 SINK("svg", SVGSink);
888 SINK("null", NullSink);
889 SINK("xps", XPSSink);
Hal Canaryc7d295e2017-07-20 15:36:00 -0400890 SINK("pdfa", PDFSink, true, SK_ScalarDefaultRasterDPI);
891 SINK("pdf300", PDFSink, false, 300);
Hal Canary85c7fe82016-10-25 10:33:27 -0400892 SINK("jsdebug", DebugSink);
mtklein748ca3b2015-01-15 10:56:12 -0800893 }
894#undef SINK
halcanary96fcdcc2015-08-27 07:41:13 -0700895 return nullptr;
mtklein114c3cd2015-01-15 10:15:02 -0800896}
897
Mike Klein841101d2017-03-10 09:55:51 -0500898static sk_sp<SkColorSpace> adobe_rgb() {
899 return SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
900 SkColorSpace::kAdobeRGB_Gamut);
901}
902
Mike Klein919cc452017-03-18 15:36:52 +0000903static sk_sp<SkColorSpace> rgb_to_gbr() {
904 float gbr[9];
905 gbr[0] = gSRGB_toXYZD50[1];
906 gbr[1] = gSRGB_toXYZD50[2];
907 gbr[2] = gSRGB_toXYZD50[0];
908 gbr[3] = gSRGB_toXYZD50[4];
909 gbr[4] = gSRGB_toXYZD50[5];
910 gbr[5] = gSRGB_toXYZD50[3];
911 gbr[6] = gSRGB_toXYZD50[7];
912 gbr[7] = gSRGB_toXYZD50[8];
913 gbr[8] = gSRGB_toXYZD50[6];
914 SkMatrix44 toXYZD50(SkMatrix44::kUninitialized_Constructor);
915 toXYZD50.set3x3RowMajorf(gbr);
916 return SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma, toXYZD50);
917}
918
kkinnunen3e980c32015-12-23 01:33:00 -0800919static Sink* create_via(const SkString& tag, Sink* wrapped) {
920#define VIA(t, via, ...) if (tag.equals(t)) { return new via(__VA_ARGS__); }
Mike Klein919cc452017-03-18 15:36:52 +0000921 VIA("adobe", ViaCSXform, wrapped, adobe_rgb(), false);
922 VIA("gbr", ViaCSXform, wrapped, rgb_to_gbr(), true);
mtklein9c5052f2016-08-06 12:51:51 -0700923 VIA("lite", ViaLite, wrapped);
reed54dc4872016-09-13 08:09:45 -0700924 VIA("pipe", ViaPipe, wrapped);
halcanary96fcdcc2015-08-27 07:41:13 -0700925 VIA("twice", ViaTwice, wrapped);
Mike Reedbae888e2017-02-18 16:50:45 -0500926#ifdef TEST_VIA_SVG
Mike Reedf67c4592017-02-17 17:06:11 -0500927 VIA("svg", ViaSVG, wrapped);
Mike Reedbae888e2017-02-18 16:50:45 -0500928#endif
halcanary96fcdcc2015-08-27 07:41:13 -0700929 VIA("serialize", ViaSerialization, wrapped);
mtklein4a34ecb2016-01-08 10:19:35 -0800930 VIA("pic", ViaPicture, wrapped);
halcanary96fcdcc2015-08-27 07:41:13 -0700931 VIA("2ndpic", ViaSecondPicture, wrapped);
mtkleind31c13d2015-05-05 12:59:56 -0700932 VIA("sp", ViaSingletonPictures, wrapped);
reedbabc3de2016-07-08 08:43:27 -0700933 VIA("defer", ViaDefer, wrapped);
halcanary96fcdcc2015-08-27 07:41:13 -0700934 VIA("tiles", ViaTiles, 256, 256, nullptr, wrapped);
mtklein7edca212015-01-21 13:18:51 -0800935 VIA("tiles_rt", ViaTiles, 256, 256, new SkRTreeFactory, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800936
mtkleind603b222015-02-17 11:13:33 -0800937 if (FLAGS_matrix.count() == 4) {
mtklein748ca3b2015-01-15 10:56:12 -0800938 SkMatrix m;
mtkleind603b222015-02-17 11:13:33 -0800939 m.reset();
940 m.setScaleX((SkScalar)atof(FLAGS_matrix[0]));
941 m.setSkewX ((SkScalar)atof(FLAGS_matrix[1]));
942 m.setSkewY ((SkScalar)atof(FLAGS_matrix[2]));
943 m.setScaleY((SkScalar)atof(FLAGS_matrix[3]));
944 VIA("matrix", ViaMatrix, m, wrapped);
945 VIA("upright", ViaUpright, m, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800946 }
tomhudson64de1e12015-03-05 08:01:07 -0800947
mtklein748ca3b2015-01-15 10:56:12 -0800948#undef VIA
halcanary96fcdcc2015-08-27 07:41:13 -0700949 return nullptr;
mtklein114c3cd2015-01-15 10:15:02 -0800950}
951
Ben Wagnerf28d4722017-08-11 17:33:22 -0400952static bool gather_sinks(const GrContextOptions& grCtxOptions, bool defaultConfigs) {
kkinnunen3e980c32015-12-23 01:33:00 -0800953 SkCommandLineConfigArray configs;
954 ParseConfigs(FLAGS_config, &configs);
955 for (int i = 0; i < configs.count(); i++) {
956 const SkCommandLineConfig& config = *configs[i];
csmartdalton008b9d82017-02-22 12:00:42 -0700957 Sink* sink = create_sink(grCtxOptions, &config);
kkinnunen3e980c32015-12-23 01:33:00 -0800958 if (sink == nullptr) {
mtkleinc41fd922016-03-08 09:01:39 -0800959 info("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(),
960 config.getTag().c_str());
kkinnunen3e980c32015-12-23 01:33:00 -0800961 continue;
962 }
mtklein748ca3b2015-01-15 10:56:12 -0800963
kkinnunen3e980c32015-12-23 01:33:00 -0800964 const SkTArray<SkString>& parts = config.getViaParts();
965 for (int j = parts.count(); j-- > 0;) {
966 const SkString& part = parts[j];
967 Sink* next = create_via(part, sink);
halcanary96fcdcc2015-08-27 07:41:13 -0700968 if (next == nullptr) {
mtkleinc41fd922016-03-08 09:01:39 -0800969 info("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(),
970 part.c_str());
mtklein748ca3b2015-01-15 10:56:12 -0800971 delete sink;
halcanary96fcdcc2015-08-27 07:41:13 -0700972 sink = nullptr;
mtklein748ca3b2015-01-15 10:56:12 -0800973 break;
974 }
975 sink = next;
976 }
977 if (sink) {
978 push_sink(config, sink);
mtklein114c3cd2015-01-15 10:15:02 -0800979 }
980 }
brianosman05c987c2016-05-09 13:42:16 -0700981
982 // If no configs were requested (just running tests, perhaps?), then we're okay.
Ben Wagnerf28d4722017-08-11 17:33:22 -0400983 if (configs.count() == 0 ||
984 // If we're using the default configs, we're okay.
985 defaultConfigs ||
Ben Wagner32fa5102017-08-10 21:25:55 -0400986 // If we've been told to ignore undefined flags, we're okay.
987 FLAGS_undefok ||
988 // Otherwise, make sure that all specified configs have become sinks.
989 configs.count() == gSinks.count()) {
990 return true;
991 }
992 info("Invalid --config. Use --undefok to bypass this warning.\n");
993 return false;
mtklein114c3cd2015-01-15 10:15:02 -0800994}
mtklein709d2c32015-01-15 08:30:25 -0800995
mtkleina5114d72015-08-24 13:27:01 -0700996static bool dump_png(SkBitmap bitmap, const char* path, const char* md5) {
Mike Klein13b6afd2017-06-12 12:45:41 -0400997 SkPixmap pm;
998 if (!bitmap.peekPixels(&pm)) {
999 return false; // Ought to never happen... we're already read-back at this point.
mtkleina5114d72015-08-24 13:27:01 -07001000 }
Mike Klein13b6afd2017-06-12 12:45:41 -04001001 SkFILEWStream dst{path};
mtkleina5114d72015-08-24 13:27:01 -07001002
mtkleind69ece62015-09-10 10:37:44 -07001003 SkString description;
1004 description.append("Key: ");
1005 for (int i = 0; i < FLAGS_key.count(); i++) {
1006 description.appendf("%s ", FLAGS_key[i]);
1007 }
1008 description.append("Properties: ");
1009 for (int i = 0; i < FLAGS_properties.count(); i++) {
1010 description.appendf("%s ", FLAGS_properties[i]);
1011 }
1012 description.appendf("MD5: %s", md5);
1013
Mike Klein13b6afd2017-06-12 12:45:41 -04001014 const char* comments[] = {
1015 "Author", "DM dump_png()",
1016 "Description", description.c_str(),
1017 };
1018 size_t lengths[] = {
1019 strlen(comments[0])+1, strlen(comments[1])+1,
1020 strlen(comments[2])+1, strlen(comments[3])+1,
1021 };
mtkleina5114d72015-08-24 13:27:01 -07001022
Mike Klein13b6afd2017-06-12 12:45:41 -04001023 SkPngEncoder::Options options;
1024 options.fComments = SkDataTable::MakeCopyArrays((const void**)comments, lengths, 4);
1025 options.fFilterFlags = SkPngEncoder::FilterFlag::kNone;
1026 options.fZLibLevel = 1;
1027 options.fUnpremulBehavior = pm.colorSpace() ? SkTransferFunctionBehavior::kRespect
1028 : SkTransferFunctionBehavior::kIgnore;
1029 return SkPngEncoder::Encode(&dst, pm, options);
mtkleina5114d72015-08-24 13:27:01 -07001030}
1031
mtkleina2ef6422015-01-15 13:44:22 -08001032static bool match(const char* needle, const char* haystack) {
halcanary96fcdcc2015-08-27 07:41:13 -07001033 return 0 == strcmp("_", needle) || nullptr != strstr(haystack, needle);
mtkleina2ef6422015-01-15 13:44:22 -08001034}
1035
mtklein3eed7dd2016-02-24 19:07:07 -08001036static bool is_blacklisted(const char* sink, const char* src,
1037 const char* srcOptions, const char* name) {
mtklein0d243ff2015-04-03 07:51:00 -07001038 for (int i = 0; i < FLAGS_blacklist.count() - 3; i += 4) {
mtkleina2ef6422015-01-15 13:44:22 -08001039 if (match(FLAGS_blacklist[i+0], sink) &&
djsollen54416de2015-04-03 07:24:48 -07001040 match(FLAGS_blacklist[i+1], src) &&
1041 match(FLAGS_blacklist[i+2], srcOptions) &&
1042 match(FLAGS_blacklist[i+3], name)) {
mtklein3eed7dd2016-02-24 19:07:07 -08001043 return true;
mtkleina2ef6422015-01-15 13:44:22 -08001044 }
1045 }
mtklein3eed7dd2016-02-24 19:07:07 -08001046 return false;
mtkleina2ef6422015-01-15 13:44:22 -08001047}
1048
mtkleincd50bca2016-01-05 06:20:20 -08001049// Even when a Task Sink reports to be non-threadsafe (e.g. GPU), we know things like
1050// .png encoding are definitely thread safe. This lets us offload that work to CPU threads.
1051static SkTaskGroup gDefinitelyThreadSafeWork;
1052
mtklein748ca3b2015-01-15 10:56:12 -08001053// The finest-grained unit of work we can run: draw a single Src into a single Sink,
1054// report any errors, and perhaps write out the output: a .png of the bitmap, or a raw stream.
1055struct Task {
mtkleine0effd62015-07-29 06:37:28 -07001056 Task(const TaggedSrc& src, const TaggedSink& sink) : src(src), sink(sink) {}
1057 const TaggedSrc& src;
1058 const TaggedSink& sink;
mtklein748ca3b2015-01-15 10:56:12 -08001059
mtklein21eaf3b2016-02-08 12:39:59 -08001060 static void Run(const Task& task) {
1061 SkString name = task.src->name();
mtkleine0effd62015-07-29 06:37:28 -07001062
mtkleinb9eb4ac2015-02-02 18:26:03 -08001063 SkString log;
mtklein3eed7dd2016-02-24 19:07:07 -08001064 if (!FLAGS_dryRun) {
mtklein748ca3b2015-01-15 10:56:12 -08001065 SkBitmap bitmap;
1066 SkDynamicMemoryWStream stream;
mtklein3eed7dd2016-02-24 19:07:07 -08001067 start(task.sink.tag.c_str(), task.src.tag.c_str(),
1068 task.src.options.c_str(), name.c_str());
mtklein21eaf3b2016-02-08 12:39:59 -08001069 Error err = task.sink->draw(*task.src, &bitmap, &stream, &log);
mtkleinb3b13b72016-03-07 13:20:52 -08001070 if (!log.isEmpty()) {
mtkleinc41fd922016-03-08 09:01:39 -08001071 info("%s %s %s %s:\n%s\n", task.sink.tag.c_str()
1072 , task.src.tag.c_str()
1073 , task.src.options.c_str()
1074 , name.c_str()
1075 , log.c_str());
mtkleinb3b13b72016-03-07 13:20:52 -08001076 }
mtklein748ca3b2015-01-15 10:56:12 -08001077 if (!err.isEmpty()) {
mtklein4089ef72015-03-05 08:40:28 -08001078 if (err.isFatal()) {
djsollen54416de2015-04-03 07:24:48 -07001079 fail(SkStringPrintf("%s %s %s %s: %s",
mtklein21eaf3b2016-02-08 12:39:59 -08001080 task.sink.tag.c_str(),
1081 task.src.tag.c_str(),
1082 task.src.options.c_str(),
mtklein4089ef72015-03-05 08:40:28 -08001083 name.c_str(),
1084 err.c_str()));
mtkleinb37cb412015-03-18 05:27:14 -07001085 } else {
mtklein3eed7dd2016-02-24 19:07:07 -08001086 done(task.sink.tag.c_str(), task.src.tag.c_str(),
1087 task.src.options.c_str(), name.c_str());
mtkleinba6ada72016-01-21 09:39:35 -08001088 return;
mtklein4089ef72015-03-05 08:40:28 -08001089 }
mtklein748ca3b2015-01-15 10:56:12 -08001090 }
mtklein62bd1a62015-01-27 14:46:26 -08001091
mtkleincd50bca2016-01-05 06:20:20 -08001092 // We're likely switching threads here, so we must capture by value, [=] or [foo,bar].
Hal Canary0b833192017-03-14 14:35:02 -04001093 SkStreamAsset* data = stream.detachAsStream().release();
mtkleincd50bca2016-01-05 06:20:20 -08001094 gDefinitelyThreadSafeWork.add([task,name,bitmap,data]{
Ben Wagner145dbcd2016-11-03 14:40:50 -04001095 std::unique_ptr<SkStreamAsset> ownedData(data);
mtkleincd50bca2016-01-05 06:20:20 -08001096
mtkleincd50bca2016-01-05 06:20:20 -08001097 SkString md5;
1098 if (!FLAGS_writePath.isEmpty() || !FLAGS_readPath.isEmpty()) {
1099 SkMD5 hash;
1100 if (data->getLength()) {
1101 hash.writeStream(data, data->getLength());
1102 data->rewind();
mtklein38408462015-07-08 07:25:27 -07001103 } else {
mtkleincd50bca2016-01-05 06:20:20 -08001104 // If we're BGRA (Linux, Windows), swizzle over to RGBA (Mac, Android).
1105 // This helps eliminate multiple 0-pixel-diff hashes on gold.skia.org.
1106 // (Android's general slow speed breaks the tie arbitrarily in RGBA's favor.)
1107 // We might consider promoting 565 to RGBA too.
1108 if (bitmap.colorType() == kBGRA_8888_SkColorType) {
1109 SkBitmap swizzle;
Matt Sarett68b8e3d2017-04-28 11:15:22 -04001110 SkAssertResult(sk_tool_utils::copy_to(&swizzle, kRGBA_8888_SkColorType,
1111 bitmap));
mtkleincd50bca2016-01-05 06:20:20 -08001112 hash.write(swizzle.getPixels(), swizzle.getSize());
1113 } else {
1114 hash.write(bitmap.getPixels(), bitmap.getSize());
1115 }
1116 }
1117 SkMD5::Digest digest;
1118 hash.finish(digest);
1119 for (int i = 0; i < 16; i++) {
1120 md5.appendf("%02x", digest.data[i]);
mtklein38408462015-07-08 07:25:27 -07001121 }
mtklein62bd1a62015-01-27 14:46:26 -08001122 }
mtklein62bd1a62015-01-27 14:46:26 -08001123
mtkleincd50bca2016-01-05 06:20:20 -08001124 if (!FLAGS_readPath.isEmpty() &&
mtklein3eed7dd2016-02-24 19:07:07 -08001125 !gGold.contains(Gold(task.sink.tag, task.src.tag,
1126 task.src.options, name, md5))) {
mtkleincd50bca2016-01-05 06:20:20 -08001127 fail(SkStringPrintf("%s not found for %s %s %s %s in %s",
1128 md5.c_str(),
mtklein21eaf3b2016-02-08 12:39:59 -08001129 task.sink.tag.c_str(),
1130 task.src.tag.c_str(),
1131 task.src.options.c_str(),
mtkleincd50bca2016-01-05 06:20:20 -08001132 name.c_str(),
1133 FLAGS_readPath[0]));
mtklein748ca3b2015-01-15 10:56:12 -08001134 }
mtkleincd50bca2016-01-05 06:20:20 -08001135
1136 if (!FLAGS_writePath.isEmpty()) {
mtklein21eaf3b2016-02-08 12:39:59 -08001137 const char* ext = task.sink->fileExtension();
Mike Klein97d6a7a2017-07-24 10:37:19 -04001138 if (!FLAGS_dont_write.contains(ext)) {
1139 if (data->getLength()) {
1140 WriteToDisk(task, md5, ext, data, data->getLength(), nullptr);
1141 SkASSERT(bitmap.drawsNothing());
1142 } else if (!bitmap.drawsNothing()) {
1143 WriteToDisk(task, md5, ext, nullptr, 0, &bitmap);
1144 }
mtkleincd50bca2016-01-05 06:20:20 -08001145 }
1146 }
1147 });
mtklein748ca3b2015-01-15 10:56:12 -08001148 }
mtklein3eed7dd2016-02-24 19:07:07 -08001149 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 -08001150 }
1151
1152 static void WriteToDisk(const Task& task,
mtklein62bd1a62015-01-27 14:46:26 -08001153 SkString md5,
1154 const char* ext,
mtklein748ca3b2015-01-15 10:56:12 -08001155 SkStream* data, size_t len,
mtklein62bd1a62015-01-27 14:46:26 -08001156 const SkBitmap* bitmap) {
mtklein409d4702016-02-29 07:38:01 -08001157 bool gammaCorrect = false;
1158 if (bitmap) {
Brian Osman7039f742016-11-01 15:56:16 -04001159 gammaCorrect = SkToBool(bitmap->info().colorSpace());
mtklein409d4702016-02-29 07:38:01 -08001160 }
1161
mtklein748ca3b2015-01-15 10:56:12 -08001162 JsonWriter::BitmapResult result;
djsollen54416de2015-04-03 07:24:48 -07001163 result.name = task.src->name();
mtklein3eed7dd2016-02-24 19:07:07 -08001164 result.config = task.sink.tag;
djsollen54416de2015-04-03 07:24:48 -07001165 result.sourceType = task.src.tag;
1166 result.sourceOptions = task.src.options;
1167 result.ext = ext;
mtklein409d4702016-02-29 07:38:01 -08001168 result.gammaCorrect = gammaCorrect;
djsollen54416de2015-04-03 07:24:48 -07001169 result.md5 = md5;
mtklein748ca3b2015-01-15 10:56:12 -08001170 JsonWriter::AddBitmapResult(result);
1171
mtkleinb0531a72015-04-07 13:38:48 -07001172 // If an MD5 is uninteresting, we want it noted in the JSON file,
1173 // but don't want to dump it out as a .png (or whatever ext is).
1174 if (gUninterestingHashes.contains(md5)) {
1175 return;
1176 }
1177
mtklein748ca3b2015-01-15 10:56:12 -08001178 const char* dir = FLAGS_writePath[0];
1179 if (0 == strcmp(dir, "@")) { // Needed for iOS.
1180 dir = FLAGS_resourcePath[0];
1181 }
1182 sk_mkdir(dir);
1183
1184 SkString path;
1185 if (FLAGS_nameByHash) {
1186 path = SkOSPath::Join(dir, result.md5.c_str());
1187 path.append(".");
1188 path.append(ext);
1189 if (sk_exists(path.c_str())) {
1190 return; // Content-addressed. If it exists already, we're done.
1191 }
1192 } else {
kkinnunen3e980c32015-12-23 01:33:00 -08001193 path = SkOSPath::Join(dir, task.sink.tag.c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001194 sk_mkdir(path.c_str());
msarett9e707a02015-09-01 14:57:57 -07001195 path = SkOSPath::Join(path.c_str(), task.src.tag.c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001196 sk_mkdir(path.c_str());
msarett9e707a02015-09-01 14:57:57 -07001197 if (strcmp(task.src.options.c_str(), "") != 0) {
1198 path = SkOSPath::Join(path.c_str(), task.src.options.c_str());
djsollen54416de2015-04-03 07:24:48 -07001199 sk_mkdir(path.c_str());
1200 }
mtklein748ca3b2015-01-15 10:56:12 -08001201 path = SkOSPath::Join(path.c_str(), task.src->name().c_str());
1202 path.append(".");
1203 path.append(ext);
1204 }
1205
mtklein748ca3b2015-01-15 10:56:12 -08001206 if (bitmap) {
mtkleina5114d72015-08-24 13:27:01 -07001207 if (!dump_png(*bitmap, path.c_str(), result.md5.c_str())) {
mtklein748ca3b2015-01-15 10:56:12 -08001208 fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str()));
1209 return;
1210 }
1211 } else {
mtkleina5114d72015-08-24 13:27:01 -07001212 SkFILEWStream file(path.c_str());
1213 if (!file.isValid()) {
1214 fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str()));
1215 return;
1216 }
mtklein748ca3b2015-01-15 10:56:12 -08001217 if (!file.writeStream(data, len)) {
1218 fail(SkStringPrintf("Can't write to %s.\n", path.c_str()));
1219 return;
1220 }
1221 }
1222 }
1223};
1224
mtklein748ca3b2015-01-15 10:56:12 -08001225/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1226
1227// Unit tests don't fit so well into the Src/Sink model, so we give them special treatment.
1228
mtklein21eaf3b2016-02-08 12:39:59 -08001229static SkTDArray<skiatest::Test> gParallelTests, gSerialTests;
mtklein748ca3b2015-01-15 10:56:12 -08001230
1231static void gather_tests() {
mtklein6c5fed22015-01-20 13:47:23 -08001232 if (!FLAGS_src.contains("tests")) {
mtklein748ca3b2015-01-15 10:56:12 -08001233 return;
1234 }
mtklein6393c062015-04-27 08:45:01 -07001235 for (const skiatest::TestRegistry* r = skiatest::TestRegistry::Head(); r; r = r->next()) {
1236 if (!in_shard()) {
1237 continue;
1238 }
halcanary87f3ba42015-01-20 09:30:20 -08001239 // Despite its name, factory() is returning a reference to
1240 // link-time static const POD data.
1241 const skiatest::Test& test = r->factory();
1242 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, test.name)) {
mtklein748ca3b2015-01-15 10:56:12 -08001243 continue;
1244 }
halcanary87f3ba42015-01-20 09:30:20 -08001245 if (test.needsGpu && gpu_supported()) {
mtklein21eaf3b2016-02-08 12:39:59 -08001246 (FLAGS_gpu_threading ? gParallelTests : gSerialTests).push(test);
halcanary87f3ba42015-01-20 09:30:20 -08001247 } else if (!test.needsGpu && FLAGS_cpu) {
mtklein21eaf3b2016-02-08 12:39:59 -08001248 gParallelTests.push(test);
mtklein82d28432015-01-15 12:46:02 -08001249 }
mtklein748ca3b2015-01-15 10:56:12 -08001250 }
1251}
1252
csmartdalton008b9d82017-02-22 12:00:42 -07001253static void run_test(skiatest::Test test, const GrContextOptions& grCtxOptions) {
halcanary87f3ba42015-01-20 09:30:20 -08001254 struct : public skiatest::Reporter {
mtklein36352bf2015-03-25 18:17:31 -07001255 void reportFailed(const skiatest::Failure& failure) override {
halcanary87f3ba42015-01-20 09:30:20 -08001256 fail(failure.toString());
1257 JsonWriter::AddTestFailure(failure);
1258 }
mtklein36352bf2015-03-25 18:17:31 -07001259 bool allowExtendedTest() const override {
halcanary87f3ba42015-01-20 09:30:20 -08001260 return FLAGS_pathOpsExtended;
1261 }
mtklein36352bf2015-03-25 18:17:31 -07001262 bool verbose() const override { return FLAGS_veryVerbose; }
halcanary87f3ba42015-01-20 09:30:20 -08001263 } reporter;
djsollen824996a2015-06-12 12:06:22 -07001264
mtklein3eed7dd2016-02-24 19:07:07 -08001265 if (!FLAGS_dryRun && !is_blacklisted("_", "tests", "_", test.name)) {
mtklein21eaf3b2016-02-08 12:39:59 -08001266 start("unit", "test", "", test.name);
csmartdalton008b9d82017-02-22 12:00:42 -07001267 GrContextFactory factory(grCtxOptions);
Mike Kleinb323a5e2017-07-24 15:21:31 -04001268 test.run(&reporter, &factory);
mtklein748ca3b2015-01-15 10:56:12 -08001269 }
mtklein3eed7dd2016-02-24 19:07:07 -08001270 done("unit", "test", "", test.name);
mtklein748ca3b2015-01-15 10:56:12 -08001271}
1272
1273/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1274
caryclark83ca6282015-06-10 09:31:09 -07001275#define PORTABLE_FONT_PREFIX "Toy Liberation "
1276
mbocee6a9912016-05-31 11:42:36 -07001277static sk_sp<SkTypeface> create_from_name(const char familyName[], SkFontStyle style) {
caryclark83ca6282015-06-10 09:31:09 -07001278 if (familyName && strlen(familyName) > sizeof(PORTABLE_FONT_PREFIX)
1279 && !strncmp(familyName, PORTABLE_FONT_PREFIX, sizeof(PORTABLE_FONT_PREFIX) - 1)) {
caryclark1818acb2015-07-24 12:09:25 -07001280 return sk_tool_utils::create_portable_typeface(familyName, style);
caryclark83ca6282015-06-10 09:31:09 -07001281 }
halcanary96fcdcc2015-08-27 07:41:13 -07001282 return nullptr;
caryclark83ca6282015-06-10 09:31:09 -07001283}
1284
1285#undef PORTABLE_FONT_PREFIX
1286
mbocee6a9912016-05-31 11:42:36 -07001287extern sk_sp<SkTypeface> (*gCreateTypefaceDelegate)(const char [], SkFontStyle );
caryclark83ca6282015-06-10 09:31:09 -07001288
Mike Kleinbe28ee22017-02-06 12:46:20 -05001289int main(int argc, char** argv) {
1290 SkCommandLineFlags::Parse(argc, argv);
Brian Osman53136aa2017-07-20 15:43:35 -04001291
Brian Osmanbc8150f2017-07-24 11:38:01 -04001292 initializeEventTracingForTools();
Brian Osman53136aa2017-07-20 15:43:35 -04001293
1294#if defined(SK_BUILD_FOR_IOS)
Mike Kleinadacaef2017-02-06 09:26:14 -05001295 cd_Documents();
1296#endif
bsalomon71de3532016-04-26 14:27:21 -07001297 setbuf(stdout, nullptr);
mtklein246ba3a2016-02-23 10:39:36 -08001298 setup_crash_handler();
mtkleinafae30a2016-02-24 12:28:32 -08001299
Yuqian Liba62b4a2016-12-14 13:46:53 -05001300 gSkUseAnalyticAA = FLAGS_analyticAA;
Yuqian Lidf60e362017-07-25 11:26:31 -04001301 gSkUseDeltaAA = FLAGS_deltaAA;
liyuqian38911a72016-10-04 11:23:22 -07001302
Yuqian Li550148b2017-01-13 10:13:13 -05001303 if (FLAGS_forceAnalyticAA) {
1304 gSkForceAnalyticAA = true;
1305 }
Mike Reed7c26ca72017-07-05 15:45:52 -04001306 if (FLAGS_forceRasterPipeline) {
1307 gSkForceRasterPipelineBlitter = true;
1308 }
Yuqian Li550148b2017-01-13 10:13:13 -05001309
Mike Kleine9f187b2017-06-26 13:23:12 -04001310 // The bots like having a verbose.log to upload, so always touch the file even if --verbose.
1311 if (!FLAGS_writePath.isEmpty()) {
mtklein51c8cfc2016-03-11 12:59:09 -08001312 sk_mkdir(FLAGS_writePath[0]);
mtkleina1ce2162016-07-22 12:23:46 -07001313 gVLog = fopen(SkOSPath::Join(FLAGS_writePath[0], "verbose.log").c_str(), "w");
mtkleinc41fd922016-03-08 09:01:39 -08001314 }
Mike Kleine9f187b2017-06-26 13:23:12 -04001315 if (FLAGS_verbose) {
1316 gVLog = stderr;
1317 }
mtkleinc41fd922016-03-08 09:01:39 -08001318
csmartdalton008b9d82017-02-22 12:00:42 -07001319 GrContextOptions grCtxOptions;
1320#if SK_SUPPORT_GPU
1321 grCtxOptions.fGpuPathRenderers = CollectGpuPathRenderersFromFlags();
1322#endif
1323
mtklein5286f022016-01-22 08:18:14 -08001324 JsonWriter::DumpJson(); // It's handy for the bots to assume this is ~never missing.
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +00001325 SkAutoGraphics ag;
mtklein406654b2014-09-03 15:34:37 -07001326 SkTaskGroup::Enabler enabled(FLAGS_threads);
caryclark83ca6282015-06-10 09:31:09 -07001327 gCreateTypefaceDelegate = &create_from_name;
commit-bot@chromium.orga65e2fd2014-05-30 17:23:31 +00001328
halcanary7d571242016-02-24 17:59:16 -08001329 {
1330 SkString testResourcePath = GetResourcePath("color_wheel.png");
1331 SkFILEStream testResource(testResourcePath.c_str());
1332 if (!testResource.isValid()) {
mtkleinc41fd922016-03-08 09:01:39 -08001333 info("Some resources are missing. Do you need to set --resourcePath?\n");
halcanary7d571242016-02-24 17:59:16 -08001334 }
1335 }
mtklein62bd1a62015-01-27 14:46:26 -08001336 gather_gold();
borenet09ed4802015-04-03 14:15:33 -07001337 gather_uninteresting_hashes();
mtklein62bd1a62015-01-27 14:46:26 -08001338
scroggo86737142016-02-03 12:19:11 -08001339 if (!gather_srcs()) {
1340 return 1;
1341 }
Ben Wagnerf28d4722017-08-11 17:33:22 -04001342 // TODO(dogben): This is a bit ugly. Find a cleaner way to do this.
1343 bool defaultConfigs = true;
1344 for (int i = 0; i < argc; i++) {
1345 static const char* kConfigArg = "--config";
1346 if (strcmp(argv[i], kConfigArg) == 0) {
1347 defaultConfigs = false;
1348 break;
1349 }
1350 }
1351 if (!gather_sinks(grCtxOptions, defaultConfigs)) {
brianosman05c987c2016-05-09 13:42:16 -07001352 return 1;
1353 }
mtklein748ca3b2015-01-15 10:56:12 -08001354 gather_tests();
mtklein21eaf3b2016-02-08 12:39:59 -08001355 gPending = gSrcs.count() * gSinks.count() + gParallelTests.count() + gSerialTests.count();
Brian Osmand0677bc2017-08-03 12:13:47 -04001356 info("%d srcs * %d sinks + %d tests == %d tasks\n",
mtkleinc41fd922016-03-08 09:01:39 -08001357 gSrcs.count(), gSinks.count(), gParallelTests.count() + gSerialTests.count(), gPending);
mtklein748ca3b2015-01-15 10:56:12 -08001358
mtklein21eaf3b2016-02-08 12:39:59 -08001359 // Kick off as much parallel work as we can, making note of any serial work we'll need to do.
1360 SkTaskGroup parallel;
1361 SkTArray<Task> serial;
1362
1363 for (auto& sink : gSinks)
1364 for (auto& src : gSrcs) {
mtklein3eed7dd2016-02-24 19:07:07 -08001365 if (src->veto(sink->flags()) ||
1366 is_blacklisted(sink.tag.c_str(), src.tag.c_str(),
1367 src.options.c_str(), src->name().c_str())) {
mtkleinf10637f2016-06-10 13:56:35 -07001368 SkAutoMutexAcquire lock(gMutex);
mtklein3eed7dd2016-02-24 19:07:07 -08001369 gPending--;
1370 continue;
1371 }
1372
mtklein21eaf3b2016-02-08 12:39:59 -08001373 Task task(src, sink);
1374 if (src->serial() || sink->serial()) {
1375 serial.push_back(task);
1376 } else {
1377 parallel.add([task] { Task::Run(task); });
mtklein748ca3b2015-01-15 10:56:12 -08001378 }
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001379 }
mtklein21eaf3b2016-02-08 12:39:59 -08001380 for (auto test : gParallelTests) {
csmartdalton008b9d82017-02-22 12:00:42 -07001381 parallel.add([test, grCtxOptions] { run_test(test, grCtxOptions); });
mtklein55e88b22015-01-21 15:50:13 -08001382 }
mtklein21eaf3b2016-02-08 12:39:59 -08001383
1384 // With the parallel work running, run serial tasks and tests here on main thread.
1385 for (auto task : serial) { Task::Run(task); }
csmartdalton008b9d82017-02-22 12:00:42 -07001386 for (auto test : gSerialTests) { run_test(test, grCtxOptions); }
mtklein21eaf3b2016-02-08 12:39:59 -08001387
1388 // Wait for any remaining parallel work to complete (including any spun off of serial tasks).
1389 parallel.wait();
mtkleincd50bca2016-01-05 06:20:20 -08001390 gDefinitelyThreadSafeWork.wait();
1391
mtkleinda884c42016-02-24 18:00:23 -08001392 // We'd better have run everything.
1393 SkASSERT(gPending == 0);
mtkleine027f172016-02-26 15:53:06 -08001394 // Make sure we've flushed all our results to disk.
1395 JsonWriter::DumpJson();
mtkleinda884c42016-02-24 18:00:23 -08001396
mtklein748ca3b2015-01-15 10:56:12 -08001397 // At this point we're back in single-threaded land.
caryclarkf53ce802015-06-15 06:48:30 -07001398 sk_tool_utils::release_portable_typefaces();
mtklein@google.comd36522d2013-10-16 13:02:15 +00001399
mtklein748ca3b2015-01-15 10:56:12 -08001400 if (gFailures.count() > 0) {
mtkleinc41fd922016-03-08 09:01:39 -08001401 info("Failures:\n");
mtklein748ca3b2015-01-15 10:56:12 -08001402 for (int i = 0; i < gFailures.count(); i++) {
mtkleinc41fd922016-03-08 09:01:39 -08001403 info("\t%s\n", gFailures[i].c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001404 }
mtkleinc41fd922016-03-08 09:01:39 -08001405 info("%d failures\n", gFailures.count());
mtklein748ca3b2015-01-15 10:56:12 -08001406 return 1;
mtklein114c3cd2015-01-15 10:15:02 -08001407 }
mtkleinafae30a2016-02-24 12:28:32 -08001408
1409#ifdef SK_PDF_IMAGE_STATS
halcanary7a14b312015-10-01 07:28:13 -07001410 SkPDFImageDumpStats();
mtkleinafae30a2016-02-24 12:28:32 -08001411#endif // SK_PDF_IMAGE_STATS
1412
Herb Derby5a523fe2017-01-26 16:48:28 -05001413 SkGraphics::PurgeAllCaches();
mtkleinc41fd922016-03-08 09:01:39 -08001414 info("Finished!\n");
Brian Osman53136aa2017-07-20 15:43:35 -04001415
mtklein748ca3b2015-01-15 10:56:12 -08001416 return 0;
mtklein@google.comd36522d2013-10-16 13:02:15 +00001417}
jcgregorio3b27ade2014-11-13 08:06:40 -08001418
kkinnunen179a8f52015-11-20 13:32:24 -08001419// TODO: currently many GPU tests are declared outside SK_SUPPORT_GPU guards.
1420// Thus we export the empty RunWithGPUTestContexts when SK_SUPPORT_GPU=0.
1421namespace skiatest {
bsalomon758586c2016-04-06 14:02:39 -07001422
1423#if SK_SUPPORT_GPU
1424bool IsGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
1425 return kOpenGL_GrBackend == GrContextFactory::ContextTypeBackend(type);
1426}
bsalomondc0fcd42016-04-11 14:21:33 -07001427bool IsVulkanContextType(sk_gpu_test::GrContextFactory::ContextType type) {
1428 return kVulkan_GrBackend == GrContextFactory::ContextTypeBackend(type);
1429}
bsalomon758586c2016-04-06 14:02:39 -07001430bool IsRenderingGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
1431 return IsGLContextType(type) && GrContextFactory::IsRenderingContext(type);
1432}
1433bool IsNullGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
1434 return type == GrContextFactory::kNullGL_ContextType;
1435}
1436#else
1437bool IsGLContextType(int) { return false; }
bsalomondc0fcd42016-04-11 14:21:33 -07001438bool IsVulkanContextType(int) { return false; }
bsalomon758586c2016-04-06 14:02:39 -07001439bool IsRenderingGLContextType(int) { return false; }
1440bool IsNullGLContextType(int) { return false; }
1441#endif
1442
1443void RunWithGPUTestContexts(GrContextTestFn* test, GrContextTypeFilterFn* contextTypeFilter,
bsalomonf2f1c172016-04-05 12:59:06 -07001444 Reporter* reporter, GrContextFactory* factory) {
kkinnunen179a8f52015-11-20 13:32:24 -08001445#if SK_SUPPORT_GPU
kkinnunen3e980c32015-12-23 01:33:00 -08001446
Brian Salomon6405e712017-03-20 08:54:16 -04001447#if defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_WIN) || defined(SK_BUILD_FOR_MAC)
1448 static constexpr auto kNativeGLType = GrContextFactory::kGL_ContextType;
1449#else
1450 static constexpr auto kNativeGLType = GrContextFactory::kGLES_ContextType;
1451#endif
1452
bsalomon758586c2016-04-06 14:02:39 -07001453 for (int typeInt = 0; typeInt < GrContextFactory::kContextTypeCnt; ++typeInt) {
1454 GrContextFactory::ContextType contextType = (GrContextFactory::ContextType) typeInt;
Brian Osmanaa2219c2016-12-05 10:12:17 -05001455 // Use "native" instead of explicitly trying OpenGL and OpenGL ES. Do not use GLES on
bsalomon758586c2016-04-06 14:02:39 -07001456 // desktop since tests do not account for not fixing http://skbug.com/2809
1457 if (contextType == GrContextFactory::kGL_ContextType ||
1458 contextType == GrContextFactory::kGLES_ContextType) {
Brian Salomon6405e712017-03-20 08:54:16 -04001459 if (contextType != kNativeGLType) {
bsalomon758586c2016-04-06 14:02:39 -07001460 continue;
1461 }
1462 }
csmartdaltone812d492017-02-21 12:36:05 -07001463 ContextInfo ctxInfo = factory->getContextInfo(contextType,
1464 GrContextFactory::ContextOverrides::kDisableNVPR);
Brian Osmanaa2219c2016-12-05 10:12:17 -05001465 if (contextTypeFilter && !(*contextTypeFilter)(contextType)) {
1466 continue;
1467 }
Greg Daniela5cb7812017-06-16 09:45:32 -04001468 ReporterContext ctx(reporter, SkString(GrContextFactory::ContextTypeName(contextType)));
bsalomon8b7451a2016-05-11 06:33:06 -07001469 if (ctxInfo.grContext()) {
bsalomonf2f1c172016-04-05 12:59:06 -07001470 (*test)(reporter, ctxInfo);
Robert Phillipseaa90b22017-08-01 10:36:36 -04001471 ctxInfo.grContext()->flush();
kkinnunen5219fd92015-12-10 06:28:13 -08001472 }
bsalomonf2f1c172016-04-05 12:59:06 -07001473 ctxInfo = factory->getContextInfo(contextType,
csmartdaltone812d492017-02-21 12:36:05 -07001474 GrContextFactory::ContextOverrides::kRequireNVPRSupport);
bsalomon8b7451a2016-05-11 06:33:06 -07001475 if (ctxInfo.grContext()) {
bsalomonf2f1c172016-04-05 12:59:06 -07001476 (*test)(reporter, ctxInfo);
Robert Phillipseaa90b22017-08-01 10:36:36 -04001477 ctxInfo.grContext()->flush();
kkinnunen179a8f52015-11-20 13:32:24 -08001478 }
1479 }
1480#endif
1481}
kkinnunen179a8f52015-11-20 13:32:24 -08001482} // namespace skiatest