blob: 0b36e4bb879570fcb19c2eb5cba69b68288ce70c [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"
scroggocc2feb12015-08-14 08:32:46 -070014#include "SkCodec.h"
mtklein27c3fdd2016-02-26 14:43:21 -080015#include "SkColorPriv.h"
msarett888dc162016-05-23 10:21:17 -070016#include "SkColorSpace.h"
Mike Klein919cc452017-03-18 15:36:52 +000017#include "SkColorSpacePriv.h"
caryclark17f0b6d2014-07-22 10:15:34 -070018#include "SkCommonFlags.h"
kkinnunen3e980c32015-12-23 01:33:00 -080019#include "SkCommonFlagsConfig.h"
csmartdalton008b9d82017-02-22 12:00:42 -070020#include "SkCommonFlagsPathRenderer.h"
brianosman3c579dc2016-04-19 09:18:11 -070021#include "SkData.h"
caryclark83ca6282015-06-10 09:31:09 -070022#include "SkFontMgr.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000023#include "SkGraphics.h"
mtklein27c3fdd2016-02-26 14:43:21 -080024#include "SkHalf.h"
halcanary4dbbd042016-06-07 17:21:10 -070025#include "SkLeanWindows.h"
mtklein748ca3b2015-01-15 10:56:12 -080026#include "SkMD5.h"
mtklein1b249332015-07-07 12:21:21 -070027#include "SkMutex.h"
mtklein1d0f1642014-09-08 08:05:18 -070028#include "SkOSFile.h"
Ben Wagnerbf111d72016-11-07 18:05:29 -050029#include "SkOSPath.h"
mtklein27c3fdd2016-02-26 14:43:21 -080030#include "SkPM4fPriv.h"
mtklein246ba3a2016-02-23 10:39:36 -080031#include "SkSpinlock.h"
mtkleina82f5622015-02-20 12:30:19 -080032#include "SkTHash.h"
mtklein406654b2014-09-03 15:34:37 -070033#include "SkTaskGroup.h"
mtkleinde6fc2b2015-03-12 06:28:54 -070034#include "SkThreadUtils.h"
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000035#include "Test.h"
mtklein748ca3b2015-01-15 10:56:12 -080036#include "Timer.h"
Mike Kleinadacaef2017-02-06 09:26:14 -050037#include "ios_utils.h"
brianosman3c579dc2016-04-19 09:18:11 -070038#include "picture_utils.h"
caryclark83ca6282015-06-10 09:31:09 -070039#include "sk_tool_utils.h"
liyuqian38911a72016-10-04 11:23:22 -070040#include "SkScan.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000041
scroggo19b91532016-10-24 09:03:26 -070042#include <vector>
43
halcanary7a14b312015-10-01 07:28:13 -070044#ifdef SK_PDF_IMAGE_STATS
45extern void SkPDFImageDumpStats();
46#endif
47
mtkleina5114d72015-08-24 13:27:01 -070048#include "png.h"
49
bungeman60e0fee2015-08-26 05:15:46 -070050#include <stdlib.h>
51
scroggo27a58342015-10-28 08:56:41 -070052#ifndef SK_BUILD_FOR_WIN32
53 #include <unistd.h>
54#endif
55
djsollen54416de2015-04-03 07:24:48 -070056DEFINE_string(src, "tests gm skp image", "Source types to test.");
mtklein748ca3b2015-01-15 10:56:12 -080057DEFINE_bool(nameByHash, false,
58 "If true, write to FLAGS_writePath[0]/<hash>.png instead of "
djsollen54416de2015-04-03 07:24:48 -070059 "to FLAGS_writePath[0]/<config>/<sourceType>/<sourceOptions>/<name>.png");
mtklein748ca3b2015-01-15 10:56:12 -080060DEFINE_bool2(pathOpsExtended, x, false, "Run extended pathOps tests.");
mtkleind603b222015-02-17 11:13:33 -080061DEFINE_string(matrix, "1 0 0 1",
62 "2x2 scale+skew matrix to apply or upright when using "
63 "'matrix' or 'upright' in config.");
mtklein82d28432015-01-15 12:46:02 -080064DEFINE_bool(gpu_threading, false, "Allow GPU work to run on multiple threads?");
mtklein@google.comd36522d2013-10-16 13:02:15 +000065
mtkleina2ef6422015-01-15 13:44:22 -080066DEFINE_string(blacklist, "",
djsollen54416de2015-04-03 07:24:48 -070067 "Space-separated config/src/srcOptions/name quadruples to blacklist. '_' matches anything. E.g. \n"
68 "'--blacklist gpu skp _ _' will blacklist all SKPs drawn into the gpu config.\n"
69 "'--blacklist gpu skp _ _ 8888 gm _ aarects' will also blacklist the aarects GM on 8888.");
mtkleina2ef6422015-01-15 13:44:22 -080070
mtklein62bd1a62015-01-27 14:46:26 -080071DEFINE_string2(readPath, r, "", "If set check for equality with golden results in this directory.");
72
borenet09ed4802015-04-03 14:15:33 -070073DEFINE_string(uninterestingHashesFile, "",
74 "File containing a list of uninteresting hashes. If a result hashes to something in "
75 "this list, no image is written for that result.");
76
mtklein6393c062015-04-27 08:45:01 -070077DEFINE_int32(shards, 1, "We're splitting source data into this many shards.");
78DEFINE_int32(shard, 0, "Which shard do I run?");
79
halcanary45420a92016-06-02 12:41:14 -070080DEFINE_string(mskps, "", "Directory to read mskps from, or a single mskp file.");
81
csmartdalton008b9d82017-02-22 12:00:42 -070082#if SK_SUPPORT_GPU
83DEFINE_pathrenderer_flag;
84#endif
85
mtklein748ca3b2015-01-15 10:56:12 -080086using namespace DM;
bsalomon3724e572016-03-30 18:56:19 -070087using sk_gpu_test::GrContextFactory;
bsalomon273c0f52016-03-31 10:59:06 -070088using sk_gpu_test::GLTestContext;
bsalomonf2f1c172016-04-05 12:59:06 -070089using sk_gpu_test::ContextInfo;
mtklein@google.comd36522d2013-10-16 13:02:15 +000090
mtklein748ca3b2015-01-15 10:56:12 -080091/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
92
benjaminwagnerec4d4d72016-03-25 12:59:53 -070093static const double kStartMs = SkTime::GetMSecs();
mtkleinc41fd922016-03-08 09:01:39 -080094
95static FILE* gVLog;
96
97template <typename... Args>
98static void vlog(const char* fmt, Args&&... args) {
99 if (gVLog) {
100 fprintf(gVLog, "%s\t", HumanizeMs(SkTime::GetMSecs() - kStartMs).c_str());
101 fprintf(gVLog, fmt, args...);
102 fflush(gVLog);
103 }
104}
105
106template <typename... Args>
107static void info(const char* fmt, Args&&... args) {
108 vlog(fmt, args...);
109 if (!FLAGS_quiet) {
110 printf(fmt, args...);
111 }
112}
113static void info(const char* fmt) {
114 if (!FLAGS_quiet) {
115 printf("%s", fmt); // Clang warns printf(fmt) is insecure.
116 }
117}
118
reed086eea92016-05-04 17:12:46 -0700119SK_DECLARE_STATIC_MUTEX(gFailuresMutex);
mtklein748ca3b2015-01-15 10:56:12 -0800120static SkTArray<SkString> gFailures;
121
mtklein3eed7dd2016-02-24 19:07:07 -0800122static void fail(const SkString& err) {
mtklein748ca3b2015-01-15 10:56:12 -0800123 SkAutoMutexAcquire lock(gFailuresMutex);
124 SkDebugf("\n\nFAILURE: %s\n\n", err.c_str());
125 gFailures.push_back(err);
halcanary9e398f72015-01-10 11:18:04 -0800126}
127
mtklein0f7748a2016-07-25 15:27:29 -0700128struct Running {
129 SkString id;
130 SkThreadID thread;
131
132 void dump() const {
133 info("\t%s\n", id.c_str());
134 }
135};
mtkleinb37cb412015-03-18 05:27:14 -0700136
mtklein246ba3a2016-02-23 10:39:36 -0800137// We use a spinlock to make locking this in a signal handler _somewhat_ safe.
mtklein15923c92016-02-29 10:14:38 -0800138static SkSpinlock gMutex;
mtklein0f7748a2016-07-25 15:27:29 -0700139static int32_t gPending;
140static SkTArray<Running> gRunning;
mtklein748ca3b2015-01-15 10:56:12 -0800141
mtklein3eed7dd2016-02-24 19:07:07 -0800142static void done(const char* config, const char* src, const char* srcOptions, const char* name) {
143 SkString id = SkStringPrintf("%s %s %s %s", config, src, srcOptions, name);
mtkleinc41fd922016-03-08 09:01:39 -0800144 vlog("done %s\n", id.c_str());
mtkleinafae30a2016-02-24 12:28:32 -0800145 int pending;
mtkleinb37cb412015-03-18 05:27:14 -0700146 {
mtkleinf10637f2016-06-10 13:56:35 -0700147 SkAutoMutexAcquire lock(gMutex);
mtkleinb37cb412015-03-18 05:27:14 -0700148 for (int i = 0; i < gRunning.count(); i++) {
mtklein0f7748a2016-07-25 15:27:29 -0700149 if (gRunning[i].id == id) {
mtkleinb37cb412015-03-18 05:27:14 -0700150 gRunning.removeShuffle(i);
151 break;
152 }
153 }
mtkleinafae30a2016-02-24 12:28:32 -0800154 pending = --gPending;
reed50bc0512015-05-19 14:13:31 -0700155 }
mtkleina17241b2015-01-23 05:48:00 -0800156 // We write our dm.json file every once in a while in case we crash.
157 // Notice this also handles the final dm.json when pending == 0.
158 if (pending % 500 == 0) {
159 JsonWriter::DumpJson();
160 }
mtklein@google.comd36522d2013-10-16 13:02:15 +0000161}
162
mtklein3eed7dd2016-02-24 19:07:07 -0800163static void start(const char* config, const char* src, const char* srcOptions, const char* name) {
164 SkString id = SkStringPrintf("%s %s %s %s", config, src, srcOptions, name);
mtkleinc41fd922016-03-08 09:01:39 -0800165 vlog("start %s\n", id.c_str());
mtkleinf10637f2016-06-10 13:56:35 -0700166 SkAutoMutexAcquire lock(gMutex);
mtklein0f7748a2016-07-25 15:27:29 -0700167 gRunning.push_back({id,SkGetThreadID()});
mtkleinb37cb412015-03-18 05:27:14 -0700168}
169
mtkleinafae30a2016-02-24 12:28:32 -0800170static void print_status() {
mtkleinafae30a2016-02-24 12:28:32 -0800171 int curr = sk_tools::getCurrResidentSetSizeMB(),
172 peak = sk_tools::getMaxResidentSetSizeMB();
mtkleinc41fd922016-03-08 09:01:39 -0800173 SkString elapsed = HumanizeMs(SkTime::GetMSecs() - kStartMs);
mtkleinafae30a2016-02-24 12:28:32 -0800174
mtkleinf10637f2016-06-10 13:56:35 -0700175 SkAutoMutexAcquire lock(gMutex);
mtkleinc41fd922016-03-08 09:01:39 -0800176 info("\n%s elapsed, %d active, %d queued, %dMB RAM, %dMB peak\n",
177 elapsed.c_str(), gRunning.count(), gPending - gRunning.count(), curr, peak);
mtkleinafae30a2016-02-24 12:28:32 -0800178 for (auto& task : gRunning) {
mtklein0f7748a2016-07-25 15:27:29 -0700179 task.dump();
mtkleinafae30a2016-02-24 12:28:32 -0800180 }
181}
182
Mike Klein3cc2d202016-10-24 11:39:43 -0400183static void find_culprit() {
184 // Assumes gMutex is locked.
185 SkThreadID thisThread = SkGetThreadID();
186 for (auto& task : gRunning) {
187 if (task.thread == thisThread) {
188 info("Likely culprit:\n");
189 task.dump();
mtklein0f7748a2016-07-25 15:27:29 -0700190 }
191 }
Mike Klein3cc2d202016-10-24 11:39:43 -0400192}
mtklein0f7748a2016-07-25 15:27:29 -0700193
mtklein246ba3a2016-02-23 10:39:36 -0800194#if defined(SK_BUILD_FOR_WIN32)
mtklein5b64dab2016-06-09 08:59:48 -0700195 static LONG WINAPI crash_handler(EXCEPTION_POINTERS* e) {
mtkleinf8557292016-02-29 06:35:28 -0800196 static const struct {
197 const char* name;
robertphillips75467862016-03-01 14:10:23 -0800198 DWORD code;
mtkleinf8557292016-02-29 06:35:28 -0800199 } kExceptions[] = {
200 #define _(E) {#E, E}
201 _(EXCEPTION_ACCESS_VIOLATION),
202 _(EXCEPTION_BREAKPOINT),
203 _(EXCEPTION_INT_DIVIDE_BY_ZERO),
204 _(EXCEPTION_STACK_OVERFLOW),
205 // TODO: more?
206 #undef _
207 };
208
mtkleinf10637f2016-06-10 13:56:35 -0700209 SkAutoMutexAcquire lock(gMutex);
mtklein5b64dab2016-06-09 08:59:48 -0700210
211 const DWORD code = e->ExceptionRecord->ExceptionCode;
212 info("\nCaught exception %u", code);
213 for (const auto& exception : kExceptions) {
214 if (exception.code == code) {
215 info(" %s", exception.name);
mtkleinf8557292016-02-29 06:35:28 -0800216 }
mtkleinf8557292016-02-29 06:35:28 -0800217 }
mtklein5b64dab2016-06-09 08:59:48 -0700218 info(", was running:\n");
219 for (auto& task : gRunning) {
mtklein0f7748a2016-07-25 15:27:29 -0700220 task.dump();
mtklein5b64dab2016-06-09 08:59:48 -0700221 }
mtklein0f7748a2016-07-25 15:27:29 -0700222 find_culprit();
mtklein5b64dab2016-06-09 08:59:48 -0700223 fflush(stdout);
224
mtkleinf8557292016-02-29 06:35:28 -0800225 // Execute default exception handler... hopefully, exit.
226 return EXCEPTION_EXECUTE_HANDLER;
mtklein246ba3a2016-02-23 10:39:36 -0800227 }
228
Mike Klein3cc2d202016-10-24 11:39:43 -0400229 static void setup_crash_handler() {
230 SetUnhandledExceptionFilter(crash_handler);
231 }
232#else
mtklein246ba3a2016-02-23 10:39:36 -0800233 #include <signal.h>
Mike Klein3cc2d202016-10-24 11:39:43 -0400234 #if !defined(SK_BUILD_FOR_ANDROID)
235 #include <execinfo.h>
236 #endif
237
238 static constexpr int max_of() { return 0; }
239 template <typename... Rest>
240 static constexpr int max_of(int x, Rest... rest) {
241 return x > max_of(rest...) ? x : max_of(rest...);
242 }
243
244 static void (*previous_handler[max_of(SIGABRT,SIGBUS,SIGFPE,SIGILL,SIGSEGV)+1])(int);
mtkleinf8557292016-02-29 06:35:28 -0800245
mtklein5b64dab2016-06-09 08:59:48 -0700246 static void crash_handler(int sig) {
mtkleinf10637f2016-06-10 13:56:35 -0700247 SkAutoMutexAcquire lock(gMutex);
mtklein5b64dab2016-06-09 08:59:48 -0700248
249 info("\nCaught signal %d [%s], was running:\n", sig, strsignal(sig));
250 for (auto& task : gRunning) {
mtklein0f7748a2016-07-25 15:27:29 -0700251 task.dump();
mtklein5b64dab2016-06-09 08:59:48 -0700252 }
mtklein0f7748a2016-07-25 15:27:29 -0700253 find_culprit();
mtklein5b64dab2016-06-09 08:59:48 -0700254
Mike Klein3cc2d202016-10-24 11:39:43 -0400255 #if !defined(SK_BUILD_FOR_ANDROID)
mtklein5b64dab2016-06-09 08:59:48 -0700256 void* stack[64];
257 int count = backtrace(stack, SK_ARRAY_COUNT(stack));
258 char** symbols = backtrace_symbols(stack, count);
259 info("\nStack trace:\n");
260 for (int i = 0; i < count; i++) {
261 info(" %s\n", symbols[i]);
262 }
Mike Klein3cc2d202016-10-24 11:39:43 -0400263 #endif
mtklein5b64dab2016-06-09 08:59:48 -0700264 fflush(stdout);
265
Mike Klein3cc2d202016-10-24 11:39:43 -0400266 signal(sig, previous_handler[sig]);
267 raise(sig);
mtklein5b64dab2016-06-09 08:59:48 -0700268 }
269
mtklein246ba3a2016-02-23 10:39:36 -0800270 static void setup_crash_handler() {
271 const int kSignals[] = { SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGSEGV };
272 for (int sig : kSignals) {
Mike Klein3cc2d202016-10-24 11:39:43 -0400273 previous_handler[sig] = signal(sig, crash_handler);
mtklein246ba3a2016-02-23 10:39:36 -0800274 }
275 }
276#endif
277
mtklein748ca3b2015-01-15 10:56:12 -0800278/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
mtklein114c3cd2015-01-15 10:15:02 -0800279
mtklein62bd1a62015-01-27 14:46:26 -0800280struct Gold : public SkString {
mtkleina82f5622015-02-20 12:30:19 -0800281 Gold() : SkString("") {}
mtklein3eed7dd2016-02-24 19:07:07 -0800282 Gold(const SkString& sink, const SkString& src,
283 const SkString& srcOptions, const SkString& name,
284 const SkString& md5)
mtklein62bd1a62015-01-27 14:46:26 -0800285 : SkString("") {
286 this->append(sink);
287 this->append(src);
djsollen54416de2015-04-03 07:24:48 -0700288 this->append(srcOptions);
mtklein62bd1a62015-01-27 14:46:26 -0800289 this->append(name);
290 this->append(md5);
mtklein62bd1a62015-01-27 14:46:26 -0800291 }
mtkleinc8d1dd42015-10-15 12:23:01 -0700292 struct Hash {
293 uint32_t operator()(const Gold& g) const {
294 return SkGoodHash()((const SkString&)g);
295 }
296 };
mtklein62bd1a62015-01-27 14:46:26 -0800297};
mtkleina82f5622015-02-20 12:30:19 -0800298static SkTHashSet<Gold, Gold::Hash> gGold;
mtklein62bd1a62015-01-27 14:46:26 -0800299
300static void add_gold(JsonWriter::BitmapResult r) {
djsollen54416de2015-04-03 07:24:48 -0700301 gGold.add(Gold(r.config, r.sourceType, r.sourceOptions, r.name, r.md5));
mtklein62bd1a62015-01-27 14:46:26 -0800302}
303
304static void gather_gold() {
305 if (!FLAGS_readPath.isEmpty()) {
306 SkString path(FLAGS_readPath[0]);
307 path.append("/dm.json");
308 if (!JsonWriter::ReadJson(path.c_str(), add_gold)) {
309 fail(SkStringPrintf("Couldn't read %s for golden results.", path.c_str()));
310 }
311 }
312}
313
314/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
315
mtklein935f1b12016-03-16 08:37:19 -0700316#if defined(SK_BUILD_FOR_WIN32)
317 static const char* kNewline = "\r\n";
318#else
319 static const char* kNewline = "\n";
320#endif
321
borenet09ed4802015-04-03 14:15:33 -0700322static SkTHashSet<SkString> gUninterestingHashes;
323
324static void gather_uninteresting_hashes() {
325 if (!FLAGS_uninterestingHashesFile.isEmpty()) {
bungeman38d909e2016-08-02 14:40:46 -0700326 sk_sp<SkData> data(SkData::MakeFromFileName(FLAGS_uninterestingHashesFile[0]));
mtkleincc334b32015-09-22 11:43:53 -0700327 if (!data) {
mtkleinc41fd922016-03-08 09:01:39 -0800328 info("WARNING: unable to read uninteresting hashes from %s\n",
329 FLAGS_uninterestingHashesFile[0]);
mtkleincc334b32015-09-22 11:43:53 -0700330 return;
331 }
borenet09ed4802015-04-03 14:15:33 -0700332 SkTArray<SkString> hashes;
mtklein935f1b12016-03-16 08:37:19 -0700333 SkStrSplit((const char*)data->data(), kNewline, &hashes);
borenet09ed4802015-04-03 14:15:33 -0700334 for (const SkString& hash : hashes) {
335 gUninterestingHashes.add(hash);
336 }
mtkleinc41fd922016-03-08 09:01:39 -0800337 info("FYI: loaded %d distinct uninteresting hashes from %d lines\n",
338 gUninterestingHashes.count(), hashes.count());
borenet09ed4802015-04-03 14:15:33 -0700339 }
340}
341
342/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
343
Ben Wagner145dbcd2016-11-03 14:40:50 -0400344struct TaggedSrc : public std::unique_ptr<Src> {
mtklein3eed7dd2016-02-24 19:07:07 -0800345 SkString tag;
346 SkString options;
mtkleine0effd62015-07-29 06:37:28 -0700347};
348
Ben Wagner145dbcd2016-11-03 14:40:50 -0400349struct TaggedSink : public std::unique_ptr<Sink> {
kkinnunen3e980c32015-12-23 01:33:00 -0800350 SkString tag;
djsollen54416de2015-04-03 07:24:48 -0700351};
mtklein748ca3b2015-01-15 10:56:12 -0800352
353static const bool kMemcpyOK = true;
354
mtkleine0effd62015-07-29 06:37:28 -0700355static SkTArray<TaggedSrc, kMemcpyOK> gSrcs;
356static SkTArray<TaggedSink, kMemcpyOK> gSinks;
mtklein748ca3b2015-01-15 10:56:12 -0800357
mtklein6393c062015-04-27 08:45:01 -0700358static bool in_shard() {
359 static int N = 0;
360 return N++ % FLAGS_shards == FLAGS_shard;
361}
362
mtklein3eed7dd2016-02-24 19:07:07 -0800363static void push_src(const char* tag, ImplicitString options, Src* s) {
Ben Wagner145dbcd2016-11-03 14:40:50 -0400364 std::unique_ptr<Src> src(s);
mtklein6393c062015-04-27 08:45:01 -0700365 if (in_shard() &&
mtklein3eed7dd2016-02-24 19:07:07 -0800366 FLAGS_src.contains(tag) &&
mtklein748ca3b2015-01-15 10:56:12 -0800367 !SkCommandLineFlags::ShouldSkip(FLAGS_match, src->name().c_str())) {
mtkleine0effd62015-07-29 06:37:28 -0700368 TaggedSrc& s = gSrcs.push_back();
mtklein18300a32016-03-16 13:53:35 -0700369 s.reset(src.release());
mtklein748ca3b2015-01-15 10:56:12 -0800370 s.tag = tag;
djsollen54416de2015-04-03 07:24:48 -0700371 s.options = options;
mtklein114c3cd2015-01-15 10:15:02 -0800372 }
mtklein748ca3b2015-01-15 10:56:12 -0800373}
mtklein114c3cd2015-01-15 10:15:02 -0800374
msarett9e707a02015-09-01 14:57:57 -0700375static void push_codec_src(Path path, CodecSrc::Mode mode, CodecSrc::DstColorType dstColorType,
scroggoc5560be2016-02-03 09:42:42 -0800376 SkAlphaType dstAlphaType, float scale) {
scroggoe4499842016-02-25 11:03:47 -0800377 if (FLAGS_simpleCodec) {
scroggo19b91532016-10-24 09:03:26 -0700378 const bool simple = CodecSrc::kCodec_Mode == mode || CodecSrc::kAnimated_Mode == mode;
379 if (!simple || dstColorType != CodecSrc::kGetFromCanvas_DstColorType || scale != 1.0f) {
scroggoe4499842016-02-25 11:03:47 -0800380 // Only decode in the simple case.
381 return;
scroggo19b91532016-10-24 09:03:26 -0700382 }
scroggoe4499842016-02-25 11:03:47 -0800383 }
msarett9e707a02015-09-01 14:57:57 -0700384 SkString folder;
385 switch (mode) {
386 case CodecSrc::kCodec_Mode:
387 folder.append("codec");
388 break;
msarettbb25b532016-01-13 09:31:39 -0800389 case CodecSrc::kCodecZeroInit_Mode:
390 folder.append("codec_zero_init");
391 break;
msarett9e707a02015-09-01 14:57:57 -0700392 case CodecSrc::kScanline_Mode:
393 folder.append("scanline");
394 break;
msarett9e707a02015-09-01 14:57:57 -0700395 case CodecSrc::kStripe_Mode:
396 folder.append("stripe");
397 break;
msarett91c22b22016-02-22 12:27:46 -0800398 case CodecSrc::kCroppedScanline_Mode:
399 folder.append("crop");
400 break;
msarett9e707a02015-09-01 14:57:57 -0700401 case CodecSrc::kSubset_Mode:
msarett36c37962015-09-02 13:20:52 -0700402 folder.append("codec_subset");
msarett9e707a02015-09-01 14:57:57 -0700403 break;
scroggo19b91532016-10-24 09:03:26 -0700404 case CodecSrc::kAnimated_Mode:
405 folder.append("codec_animated");
406 break;
msarett9e707a02015-09-01 14:57:57 -0700407 }
408
409 switch (dstColorType) {
410 case CodecSrc::kGrayscale_Always_DstColorType:
411 folder.append("_kGray8");
412 break;
413 case CodecSrc::kIndex8_Always_DstColorType:
414 folder.append("_kIndex8");
415 break;
msarett34e0ec42016-04-22 16:27:24 -0700416 case CodecSrc::kNonNative8888_Always_DstColorType:
417 folder.append("_kNonNative");
418 break;
msarett9e707a02015-09-01 14:57:57 -0700419 default:
420 break;
421 }
422
scroggoc5560be2016-02-03 09:42:42 -0800423 switch (dstAlphaType) {
scroggoc5560be2016-02-03 09:42:42 -0800424 case kPremul_SkAlphaType:
425 folder.append("_premul");
426 break;
427 case kUnpremul_SkAlphaType:
428 folder.append("_unpremul");
429 break;
430 default:
431 break;
432 }
433
msarett9e707a02015-09-01 14:57:57 -0700434 if (1.0f != scale) {
435 folder.appendf("_%.3f", scale);
436 }
437
scroggoc5560be2016-02-03 09:42:42 -0800438 CodecSrc* src = new CodecSrc(path, mode, dstColorType, dstAlphaType, scale);
msarett9e707a02015-09-01 14:57:57 -0700439 push_src("image", folder, src);
440}
441
scroggof8dc9df2016-05-16 09:04:13 -0700442static void push_android_codec_src(Path path, CodecSrc::DstColorType dstColorType,
443 SkAlphaType dstAlphaType, int sampleSize) {
msarett3d9d7a72015-10-21 10:27:10 -0700444 SkString folder;
scroggof8dc9df2016-05-16 09:04:13 -0700445 folder.append("scaled_codec");
msarett3d9d7a72015-10-21 10:27:10 -0700446
447 switch (dstColorType) {
448 case CodecSrc::kGrayscale_Always_DstColorType:
449 folder.append("_kGray8");
450 break;
451 case CodecSrc::kIndex8_Always_DstColorType:
452 folder.append("_kIndex8");
453 break;
msarett34e0ec42016-04-22 16:27:24 -0700454 case CodecSrc::kNonNative8888_Always_DstColorType:
455 folder.append("_kNonNative");
456 break;
msarett3d9d7a72015-10-21 10:27:10 -0700457 default:
458 break;
459 }
460
scroggoc5560be2016-02-03 09:42:42 -0800461 switch (dstAlphaType) {
scroggoc5560be2016-02-03 09:42:42 -0800462 case kPremul_SkAlphaType:
463 folder.append("_premul");
464 break;
msarett9e9444c2016-02-03 12:39:10 -0800465 case kUnpremul_SkAlphaType:
466 folder.append("_unpremul");
467 break;
scroggoc5560be2016-02-03 09:42:42 -0800468 default:
469 break;
470 }
471
msarett3d9d7a72015-10-21 10:27:10 -0700472 if (1 != sampleSize) {
msarett4b0778e2015-11-13 09:59:11 -0800473 folder.appendf("_%.3f", 1.0f / (float) sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700474 }
475
scroggof8dc9df2016-05-16 09:04:13 -0700476 AndroidCodecSrc* src = new AndroidCodecSrc(path, dstColorType, dstAlphaType, sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700477 push_src("image", folder, src);
478}
479
msarett18976312016-03-09 14:20:58 -0800480static void push_image_gen_src(Path path, ImageGenSrc::Mode mode, SkAlphaType alphaType, bool isGpu)
481{
482 SkString folder;
483 switch (mode) {
484 case ImageGenSrc::kCodec_Mode:
485 folder.append("gen_codec");
486 break;
487 case ImageGenSrc::kPlatform_Mode:
488 folder.append("gen_platform");
489 break;
490 }
491
492 if (isGpu) {
493 folder.append("_gpu");
494 } else {
495 switch (alphaType) {
496 case kOpaque_SkAlphaType:
497 folder.append("_opaque");
498 break;
499 case kPremul_SkAlphaType:
500 folder.append("_premul");
501 break;
502 case kUnpremul_SkAlphaType:
503 folder.append("_unpremul");
504 break;
505 default:
506 break;
507 }
508 }
509
510 ImageGenSrc* src = new ImageGenSrc(path, mode, alphaType, isGpu);
511 push_src("image", folder, src);
512}
513
msarett438b2ad2015-04-09 12:43:10 -0700514static void push_codec_srcs(Path path) {
bungeman38d909e2016-08-02 14:40:46 -0700515 sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str()));
msarett438b2ad2015-04-09 12:43:10 -0700516 if (!encoded) {
mtkleinc41fd922016-03-08 09:01:39 -0800517 info("Couldn't read %s.", path.c_str());
msarett438b2ad2015-04-09 12:43:10 -0700518 return;
519 }
Ben Wagner145dbcd2016-11-03 14:40:50 -0400520 std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(encoded));
halcanary96fcdcc2015-08-27 07:41:13 -0700521 if (nullptr == codec.get()) {
mtkleinc41fd922016-03-08 09:01:39 -0800522 info("Couldn't create codec for %s.", path.c_str());
msarett438b2ad2015-04-09 12:43:10 -0700523 return;
524 }
525
scroggo9366aff2016-05-20 08:38:54 -0700526 // native scaling is only supported by WEBP and JPEG
527 bool supportsNativeScaling = false;
msarett438b2ad2015-04-09 12:43:10 -0700528
msarett91c22b22016-02-22 12:27:46 -0800529 SkTArray<CodecSrc::Mode> nativeModes;
530 nativeModes.push_back(CodecSrc::kCodec_Mode);
531 nativeModes.push_back(CodecSrc::kCodecZeroInit_Mode);
msarett91c22b22016-02-22 12:27:46 -0800532 switch (codec->getEncodedFormat()) {
Hal Canarydb683012016-11-23 08:55:18 -0700533 case SkEncodedImageFormat::kJPEG:
msarett91c22b22016-02-22 12:27:46 -0800534 nativeModes.push_back(CodecSrc::kScanline_Mode);
535 nativeModes.push_back(CodecSrc::kStripe_Mode);
536 nativeModes.push_back(CodecSrc::kCroppedScanline_Mode);
scroggo9366aff2016-05-20 08:38:54 -0700537 supportsNativeScaling = true;
msarett91c22b22016-02-22 12:27:46 -0800538 break;
Hal Canarydb683012016-11-23 08:55:18 -0700539 case SkEncodedImageFormat::kWEBP:
msarett91c22b22016-02-22 12:27:46 -0800540 nativeModes.push_back(CodecSrc::kSubset_Mode);
scroggo9366aff2016-05-20 08:38:54 -0700541 supportsNativeScaling = true;
msarett91c22b22016-02-22 12:27:46 -0800542 break;
Hal Canarydb683012016-11-23 08:55:18 -0700543 case SkEncodedImageFormat::kDNG:
msarettb65e6042016-02-23 05:37:25 -0800544 break;
msarett91c22b22016-02-22 12:27:46 -0800545 default:
546 nativeModes.push_back(CodecSrc::kScanline_Mode);
msarett91c22b22016-02-22 12:27:46 -0800547 break;
548 }
msarett9e707a02015-09-01 14:57:57 -0700549
msarett91c22b22016-02-22 12:27:46 -0800550 SkTArray<CodecSrc::DstColorType> colorTypes;
551 colorTypes.push_back(CodecSrc::kGetFromCanvas_DstColorType);
msarett34e0ec42016-04-22 16:27:24 -0700552 colorTypes.push_back(CodecSrc::kNonNative8888_Always_DstColorType);
msarett36c37962015-09-02 13:20:52 -0700553 switch (codec->getInfo().colorType()) {
554 case kGray_8_SkColorType:
msarett91c22b22016-02-22 12:27:46 -0800555 colorTypes.push_back(CodecSrc::kGrayscale_Always_DstColorType);
Hal Canarydb683012016-11-23 08:55:18 -0700556 if (SkEncodedImageFormat::kWBMP == codec->getEncodedFormat()) {
msarett91c22b22016-02-22 12:27:46 -0800557 colorTypes.push_back(CodecSrc::kIndex8_Always_DstColorType);
msarett55f7bdd2016-02-16 13:24:54 -0800558 }
msarett36c37962015-09-02 13:20:52 -0700559 break;
560 case kIndex_8_SkColorType:
msarett91c22b22016-02-22 12:27:46 -0800561 colorTypes.push_back(CodecSrc::kIndex8_Always_DstColorType);
msarett36c37962015-09-02 13:20:52 -0700562 break;
563 default:
msarett36c37962015-09-02 13:20:52 -0700564 break;
565 }
msarett9e707a02015-09-01 14:57:57 -0700566
scroggoc5560be2016-02-03 09:42:42 -0800567 SkTArray<SkAlphaType> alphaModes;
568 alphaModes.push_back(kPremul_SkAlphaType);
scroggof2c96a22016-05-20 11:08:27 -0700569 if (codec->getInfo().alphaType() != kOpaque_SkAlphaType) {
570 alphaModes.push_back(kUnpremul_SkAlphaType);
scroggoc5560be2016-02-03 09:42:42 -0800571 }
msarettb714fb02016-01-22 14:46:42 -0800572
573 for (CodecSrc::Mode mode : nativeModes) {
scroggo9366aff2016-05-20 08:38:54 -0700574 for (CodecSrc::DstColorType colorType : colorTypes) {
575 for (SkAlphaType alphaType : alphaModes) {
scroggof2c96a22016-05-20 11:08:27 -0700576 // Only test kCroppedScanline_Mode when the alpha type is premul. The test is
scroggo9366aff2016-05-20 08:38:54 -0700577 // slow and won't be interestingly different with different alpha types.
578 if (CodecSrc::kCroppedScanline_Mode == mode &&
scroggof2c96a22016-05-20 11:08:27 -0700579 kPremul_SkAlphaType != alphaType) {
scroggo9366aff2016-05-20 08:38:54 -0700580 continue;
581 }
msarett91c22b22016-02-22 12:27:46 -0800582
scroggo9366aff2016-05-20 08:38:54 -0700583 push_codec_src(path, mode, colorType, alphaType, 1.0f);
msarettf3dc1882016-04-26 13:06:38 -0700584
scroggo9366aff2016-05-20 08:38:54 -0700585 // Skip kNonNative on different native scales. It won't be interestingly
586 // different.
587 if (supportsNativeScaling &&
588 CodecSrc::kNonNative8888_Always_DstColorType == colorType) {
589 // Native Scales
590 // SkJpegCodec natively supports scaling to the following:
591 for (auto scale : { 0.125f, 0.25f, 0.375f, 0.5f, 0.625f, 0.750f, 0.875f }) {
592 push_codec_src(path, mode, colorType, alphaType, scale);
593 }
scroggoc5560be2016-02-03 09:42:42 -0800594 }
msarett9e707a02015-09-01 14:57:57 -0700595 }
596 }
msarett0a242972015-06-11 14:27:27 -0700597 }
msarett36c37962015-09-02 13:20:52 -0700598
scroggo19b91532016-10-24 09:03:26 -0700599 {
600 std::vector<SkCodec::FrameInfo> frameInfos = codec->getFrameInfo();
601 if (frameInfos.size() > 1) {
602 push_codec_src(path, CodecSrc::kAnimated_Mode, CodecSrc::kGetFromCanvas_DstColorType,
603 kPremul_SkAlphaType, 1.0f);
604 }
605
606 }
607
scroggoe4499842016-02-25 11:03:47 -0800608 if (FLAGS_simpleCodec) {
609 return;
610 }
611
msarett3d9d7a72015-10-21 10:27:10 -0700612 const int sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
msarett36c37962015-09-02 13:20:52 -0700613
msarett3d9d7a72015-10-21 10:27:10 -0700614 for (int sampleSize : sampleSizes) {
msarett91c22b22016-02-22 12:27:46 -0800615 for (CodecSrc::DstColorType colorType : colorTypes) {
scroggoc5560be2016-02-03 09:42:42 -0800616 for (SkAlphaType alphaType : alphaModes) {
msarettf3dc1882016-04-26 13:06:38 -0700617 // We can exercise all of the kNonNative support code in the swizzler with just a
618 // few sample sizes. Skip the rest.
619 if (CodecSrc::kNonNative8888_Always_DstColorType == colorType && sampleSize > 3) {
620 continue;
621 }
622
scroggof8dc9df2016-05-16 09:04:13 -0700623 push_android_codec_src(path, colorType, alphaType, sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700624 }
msarett36c37962015-09-02 13:20:52 -0700625 }
626 }
msarett18976312016-03-09 14:20:58 -0800627
628 static const char* const rawExts[] = {
629 "arw", "cr2", "dng", "nef", "nrw", "orf", "raf", "rw2", "pef", "srw",
630 "ARW", "CR2", "DNG", "NEF", "NRW", "ORF", "RAF", "RW2", "PEF", "SRW",
631 };
632
633 // There is not currently a reason to test RAW images on image generator.
634 // If we want to enable these tests, we will need to fix skbug.com/5079.
635 for (const char* ext : rawExts) {
636 if (path.endsWith(ext)) {
637 return;
638 }
639 }
640
641 // Push image generator GPU test.
brianosmanc9ced392016-03-24 07:27:43 -0700642 push_image_gen_src(path, ImageGenSrc::kCodec_Mode, codec->getInfo().alphaType(), true);
msarett18976312016-03-09 14:20:58 -0800643
644 // Push image generator CPU tests.
645 for (SkAlphaType alphaType : alphaModes) {
646 push_image_gen_src(path, ImageGenSrc::kCodec_Mode, alphaType, false);
647
648#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
Hal Canarydb683012016-11-23 08:55:18 -0700649 if (SkEncodedImageFormat::kWEBP != codec->getEncodedFormat() &&
650 SkEncodedImageFormat::kWBMP != codec->getEncodedFormat() &&
msarett18976312016-03-09 14:20:58 -0800651 kUnpremul_SkAlphaType != alphaType)
652 {
653 push_image_gen_src(path, ImageGenSrc::kPlatform_Mode, alphaType, false);
654 }
msarettfc0b6d12016-03-17 13:50:17 -0700655#elif defined(SK_BUILD_FOR_WIN)
Hal Canarydb683012016-11-23 08:55:18 -0700656 if (SkEncodedImageFormat::kWEBP != codec->getEncodedFormat() &&
657 SkEncodedImageFormat::kWBMP != codec->getEncodedFormat())
msarettfc0b6d12016-03-17 13:50:17 -0700658 {
659 push_image_gen_src(path, ImageGenSrc::kPlatform_Mode, alphaType, false);
660 }
msarett18976312016-03-09 14:20:58 -0800661#endif
662 }
msarett438b2ad2015-04-09 12:43:10 -0700663}
664
msarettd1227a72016-05-18 06:23:57 -0700665static void push_brd_src(Path path, CodecSrc::DstColorType dstColorType, BRDSrc::Mode mode,
666 uint32_t sampleSize) {
667 SkString folder("brd_android_codec");
msaretta5783ae2015-09-08 15:35:32 -0700668 switch (mode) {
669 case BRDSrc::kFullImage_Mode:
670 break;
671 case BRDSrc::kDivisor_Mode:
672 folder.append("_divisor");
673 break;
674 default:
675 SkASSERT(false);
676 return;
677 }
678
679 switch (dstColorType) {
680 case CodecSrc::kGetFromCanvas_DstColorType:
681 break;
682 case CodecSrc::kIndex8_Always_DstColorType:
683 folder.append("_kIndex");
684 break;
685 case CodecSrc::kGrayscale_Always_DstColorType:
686 folder.append("_kGray");
687 break;
688 default:
689 SkASSERT(false);
690 return;
691 }
692
693 if (1 != sampleSize) {
msarett4b0778e2015-11-13 09:59:11 -0800694 folder.appendf("_%.3f", 1.0f / (float) sampleSize);
msaretta5783ae2015-09-08 15:35:32 -0700695 }
696
msarettd1227a72016-05-18 06:23:57 -0700697 BRDSrc* src = new BRDSrc(path, mode, dstColorType, sampleSize);
msaretta5783ae2015-09-08 15:35:32 -0700698 push_src("image", folder, src);
699}
700
701static void push_brd_srcs(Path path) {
scroggo24a9bd72016-05-20 06:02:42 -0700702 // Only run Index8 and grayscale to one sampleSize and Mode. Though interesting
703 // to test these color types, they should not reveal anything across various
704 // sampleSizes and Modes
705 for (auto type : { CodecSrc::kIndex8_Always_DstColorType,
706 CodecSrc::kGrayscale_Always_DstColorType }) {
707 // Arbitrarily choose Mode and sampleSize.
708 push_brd_src(path, type, BRDSrc::kFullImage_Mode, 2);
709 }
710
711
scroggo501b7342015-11-03 07:55:11 -0800712 // Test on a variety of sampleSizes, making sure to include:
713 // - 2, 4, and 8, which are natively supported by jpeg
714 // - multiples of 2 which are not divisible by 4 (analogous for 4)
715 // - larger powers of two, since BRD clients generally use powers of 2
716 // We will only produce output for the larger sizes on large images.
717 const uint32_t sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 24, 32, 64 };
msarett6efbe052015-09-11 09:01:16 -0700718
msaretta5783ae2015-09-08 15:35:32 -0700719 const BRDSrc::Mode modes[] = {
msarett26ad17b2015-10-22 07:29:19 -0700720 BRDSrc::kFullImage_Mode,
721 BRDSrc::kDivisor_Mode,
msaretta5783ae2015-09-08 15:35:32 -0700722 };
723
msarettd1227a72016-05-18 06:23:57 -0700724 for (uint32_t sampleSize : sampleSizes) {
scroggo24a9bd72016-05-20 06:02:42 -0700725 for (BRDSrc::Mode mode : modes) {
726 push_brd_src(path, CodecSrc::kGetFromCanvas_DstColorType, mode, sampleSize);
msaretta5783ae2015-09-08 15:35:32 -0700727 }
728 }
729}
730
731static bool brd_supported(const char* ext) {
msarett8c8f22a2015-04-01 06:58:48 -0700732 static const char* const exts[] = {
msaretta5783ae2015-09-08 15:35:32 -0700733 "jpg", "jpeg", "png", "webp",
734 "JPG", "JPEG", "PNG", "WEBP",
msarett8c8f22a2015-04-01 06:58:48 -0700735 };
736
737 for (uint32_t i = 0; i < SK_ARRAY_COUNT(exts); i++) {
738 if (0 == strcmp(exts[i], ext)) {
739 return true;
740 }
741 }
742 return false;
scroggo9b77ddd2015-03-19 06:03:39 -0700743}
744
fmalitaa2b9fdf2016-08-03 19:53:36 -0700745template <typename T>
746void gather_file_srcs(const SkCommandLineFlags::StringArray& flags, const char* ext) {
747 for (int i = 0; i < flags.count(); i++) {
748 const char* path = flags[i];
749 if (sk_isdir(path)) {
750 SkOSFile::Iter it(path, ext);
751 for (SkString file; it.next(&file); ) {
752 push_src(ext, "", new T(SkOSPath::Join(path, file.c_str())));
753 }
754 } else {
755 push_src(ext, "", new T(path));
756 }
757 }
758}
759
scroggo86737142016-02-03 12:19:11 -0800760static bool gather_srcs() {
mtklein748ca3b2015-01-15 10:56:12 -0800761 for (const skiagm::GMRegistry* r = skiagm::GMRegistry::Head(); r; r = r->next()) {
djsollen54416de2015-04-03 07:24:48 -0700762 push_src("gm", "", new GMSrc(r->factory()));
mtklein748ca3b2015-01-15 10:56:12 -0800763 }
scroggo86737142016-02-03 12:19:11 -0800764
fmalitaa2b9fdf2016-08-03 19:53:36 -0700765 gather_file_srcs<SKPSrc>(FLAGS_skps, "skp");
766 gather_file_srcs<MSKPSrc>(FLAGS_mskps, "mskp");
767#if defined(SK_XML)
768 gather_file_srcs<SVGSrc>(FLAGS_svgs, "svg");
769#endif
halcanary45420a92016-06-02 12:41:14 -0700770
scroggo86737142016-02-03 12:19:11 -0800771 SkTArray<SkString> images;
msarett69deca82016-04-29 09:38:40 -0700772 if (!CollectImages(FLAGS_images, &images)) {
scroggo86737142016-02-03 12:19:11 -0800773 return false;
774 }
775
776 for (auto image : images) {
777 push_codec_srcs(image);
scroggoe4499842016-02-25 11:03:47 -0800778 if (FLAGS_simpleCodec) {
779 continue;
780 }
781
mtklein21eaf3b2016-02-08 12:39:59 -0800782 const char* ext = strrchr(image.c_str(), '.');
783 if (ext && brd_supported(ext+1)) {
scroggo86737142016-02-03 12:19:11 -0800784 push_brd_srcs(image);
mtklein709d2c32015-01-15 08:30:25 -0800785 }
mtklein709d2c32015-01-15 08:30:25 -0800786 }
scroggo86737142016-02-03 12:19:11 -0800787
msarett69deca82016-04-29 09:38:40 -0700788 SkTArray<SkString> colorImages;
789 if (!CollectImages(FLAGS_colorImages, &colorImages)) {
790 return false;
791 }
792
793 for (auto colorImage : colorImages) {
msarett9ce3a542016-07-15 13:54:38 -0700794 ColorCodecSrc* src = new ColorCodecSrc(colorImage, ColorCodecSrc::kBaseline_Mode,
795 kN32_SkColorType);
msarettb8d1aac2016-08-04 12:22:06 -0700796 push_src("colorImage", "color_codec_baseline", src);
msarett888dc162016-05-23 10:21:17 -0700797
msarett9ce3a542016-07-15 13:54:38 -0700798 src = new ColorCodecSrc(colorImage, ColorCodecSrc::kDst_HPZR30w_Mode, kN32_SkColorType);
msarettb8d1aac2016-08-04 12:22:06 -0700799 push_src("colorImage", "color_codec_HPZR30w", src);
msarett9ce3a542016-07-15 13:54:38 -0700800 // TODO (msarett):
801 // 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 -0700802
msarett9ce3a542016-07-15 13:54:38 -0700803 src = new ColorCodecSrc(colorImage, ColorCodecSrc::kDst_sRGB_Mode, kN32_SkColorType);
msarettb8d1aac2016-08-04 12:22:06 -0700804 push_src("colorImage", "color_codec_sRGB_kN32", src);
msarett9ce3a542016-07-15 13:54:38 -0700805 src = new ColorCodecSrc(colorImage, ColorCodecSrc::kDst_sRGB_Mode, kRGBA_F16_SkColorType);
msarettb8d1aac2016-08-04 12:22:06 -0700806 push_src("colorImage", "color_codec_sRGB_kF16", src);
msarett69deca82016-04-29 09:38:40 -0700807 }
808
scroggo86737142016-02-03 12:19:11 -0800809 return true;
mtklein709d2c32015-01-15 08:30:25 -0800810}
811
kkinnunen3e980c32015-12-23 01:33:00 -0800812static void push_sink(const SkCommandLineConfig& config, Sink* s) {
Ben Wagner145dbcd2016-11-03 14:40:50 -0400813 std::unique_ptr<Sink> sink(s);
kkinnunen3e980c32015-12-23 01:33:00 -0800814
mtkleine0effd62015-07-29 06:37:28 -0700815 // Try a simple Src as a canary. If it fails, skip this sink.
mtklein748ca3b2015-01-15 10:56:12 -0800816 struct : public Src {
mtkleine0effd62015-07-29 06:37:28 -0700817 Error draw(SkCanvas* c) const override {
818 c->drawRect(SkRect::MakeWH(1,1), SkPaint());
819 return "";
820 }
mtklein36352bf2015-03-25 18:17:31 -0700821 SkISize size() const override { return SkISize::Make(16, 16); }
mtkleine0effd62015-07-29 06:37:28 -0700822 Name name() const override { return "justOneRect"; }
823 } justOneRect;
mtklein114c3cd2015-01-15 10:15:02 -0800824
mtklein748ca3b2015-01-15 10:56:12 -0800825 SkBitmap bitmap;
826 SkDynamicMemoryWStream stream;
mtkleinb9eb4ac2015-02-02 18:26:03 -0800827 SkString log;
mtkleine0effd62015-07-29 06:37:28 -0700828 Error err = sink->draw(justOneRect, &bitmap, &stream, &log);
mtklein4089ef72015-03-05 08:40:28 -0800829 if (err.isFatal()) {
mtkleinc41fd922016-03-08 09:01:39 -0800830 info("Could not run %s: %s\n", config.getTag().c_str(), err.c_str());
mtklein05641a52015-04-21 10:49:13 -0700831 exit(1);
mtklein114c3cd2015-01-15 10:15:02 -0800832 }
833
mtkleine0effd62015-07-29 06:37:28 -0700834 TaggedSink& ts = gSinks.push_back();
mtklein18300a32016-03-16 13:53:35 -0700835 ts.reset(sink.release());
kkinnunen3e980c32015-12-23 01:33:00 -0800836 ts.tag = config.getTag();
mtklein748ca3b2015-01-15 10:56:12 -0800837}
838
839static bool gpu_supported() {
840#if SK_SUPPORT_GPU
841 return FLAGS_gpu;
842#else
843 return false;
844#endif
845}
kkinnunen9ebc3f02015-12-21 23:48:13 -0800846
csmartdalton008b9d82017-02-22 12:00:42 -0700847static Sink* create_sink(const GrContextOptions& grCtxOptions, const SkCommandLineConfig* config) {
kkinnunen3e980c32015-12-23 01:33:00 -0800848#if SK_SUPPORT_GPU
849 if (gpu_supported()) {
850 if (const SkCommandLineConfigGpu* gpuConfig = config->asConfigGpu()) {
bsalomon85b4b532016-04-05 11:06:27 -0700851 GrContextFactory::ContextType contextType = gpuConfig->getContextType();
csmartdaltone812d492017-02-21 12:36:05 -0700852 GrContextFactory::ContextOverrides contextOverrides = gpuConfig->getContextOverrides();
csmartdalton008b9d82017-02-22 12:00:42 -0700853 GrContextFactory testFactory(grCtxOptions);
csmartdaltone812d492017-02-21 12:36:05 -0700854 if (!testFactory.get(contextType, contextOverrides)) {
mtkleinc41fd922016-03-08 09:01:39 -0800855 info("WARNING: can not create GPU context for config '%s'. "
856 "GM tests will be skipped.\n", gpuConfig->getTag().c_str());
kkinnunen3e980c32015-12-23 01:33:00 -0800857 return nullptr;
858 }
csmartdaltone812d492017-02-21 12:36:05 -0700859 return new GPUSink(contextType, contextOverrides, gpuConfig->getSamples(),
brianosmand93c1202016-03-10 07:49:08 -0800860 gpuConfig->getUseDIText(), gpuConfig->getColorType(),
brianosmanb109b8c2016-06-16 13:03:24 -0700861 sk_ref_sp(gpuConfig->getColorSpace()), FLAGS_gpu_threading);
kkinnunen3e980c32015-12-23 01:33:00 -0800862 }
863 }
864#endif
865
866#define SINK(t, sink, ...) if (config->getBackend().equals(t)) { return new sink(__VA_ARGS__); }
867
mtklein748ca3b2015-01-15 10:56:12 -0800868 if (FLAGS_cpu) {
Matt Sarett77a7a1b2017-02-07 13:56:11 -0500869 auto srgbColorSpace = SkColorSpace::MakeSRGB();
870 auto srgbLinearColorSpace = SkColorSpace::MakeSRGBLinear();
brianosmanb109b8c2016-06-16 13:03:24 -0700871
Matt Sarettd2228302017-03-02 08:53:46 -0500872 SINK("565", RasterSink, kRGB_565_SkColorType);
873 SINK("8888", RasterSink, kN32_SkColorType);
874 SINK("srgb", RasterSink, kN32_SkColorType, srgbColorSpace);
Matt Sarettd2228302017-03-02 08:53:46 -0500875 SINK("f16", RasterSink, kRGBA_F16_SkColorType, srgbLinearColorSpace);
876 SINK("pdf", PDFSink);
877 SINK("skp", SKPSink);
878 SINK("pipe", PipeSink);
879 SINK("svg", SVGSink);
880 SINK("null", NullSink);
881 SINK("xps", XPSSink);
882 SINK("pdfa", PDFSink, true);
Hal Canary85c7fe82016-10-25 10:33:27 -0400883 SINK("jsdebug", DebugSink);
mtklein748ca3b2015-01-15 10:56:12 -0800884 }
885#undef SINK
halcanary96fcdcc2015-08-27 07:41:13 -0700886 return nullptr;
mtklein114c3cd2015-01-15 10:15:02 -0800887}
888
Mike Klein841101d2017-03-10 09:55:51 -0500889static sk_sp<SkColorSpace> adobe_rgb() {
890 return SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
891 SkColorSpace::kAdobeRGB_Gamut);
892}
893
Mike Klein919cc452017-03-18 15:36:52 +0000894static sk_sp<SkColorSpace> rgb_to_gbr() {
895 float gbr[9];
896 gbr[0] = gSRGB_toXYZD50[1];
897 gbr[1] = gSRGB_toXYZD50[2];
898 gbr[2] = gSRGB_toXYZD50[0];
899 gbr[3] = gSRGB_toXYZD50[4];
900 gbr[4] = gSRGB_toXYZD50[5];
901 gbr[5] = gSRGB_toXYZD50[3];
902 gbr[6] = gSRGB_toXYZD50[7];
903 gbr[7] = gSRGB_toXYZD50[8];
904 gbr[8] = gSRGB_toXYZD50[6];
905 SkMatrix44 toXYZD50(SkMatrix44::kUninitialized_Constructor);
906 toXYZD50.set3x3RowMajorf(gbr);
907 return SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma, toXYZD50);
908}
909
kkinnunen3e980c32015-12-23 01:33:00 -0800910static Sink* create_via(const SkString& tag, Sink* wrapped) {
911#define VIA(t, via, ...) if (tag.equals(t)) { return new via(__VA_ARGS__); }
Mike Klein919cc452017-03-18 15:36:52 +0000912 VIA("adobe", ViaCSXform, wrapped, adobe_rgb(), false);
913 VIA("gbr", ViaCSXform, wrapped, rgb_to_gbr(), true);
mtklein9c5052f2016-08-06 12:51:51 -0700914 VIA("lite", ViaLite, wrapped);
reed54dc4872016-09-13 08:09:45 -0700915 VIA("pipe", ViaPipe, wrapped);
halcanary96fcdcc2015-08-27 07:41:13 -0700916 VIA("twice", ViaTwice, wrapped);
Mike Reedbae888e2017-02-18 16:50:45 -0500917#ifdef TEST_VIA_SVG
Mike Reedf67c4592017-02-17 17:06:11 -0500918 VIA("svg", ViaSVG, wrapped);
Mike Reedbae888e2017-02-18 16:50:45 -0500919#endif
halcanary96fcdcc2015-08-27 07:41:13 -0700920 VIA("serialize", ViaSerialization, wrapped);
mtklein4a34ecb2016-01-08 10:19:35 -0800921 VIA("pic", ViaPicture, wrapped);
halcanary96fcdcc2015-08-27 07:41:13 -0700922 VIA("2ndpic", ViaSecondPicture, wrapped);
mtkleind31c13d2015-05-05 12:59:56 -0700923 VIA("sp", ViaSingletonPictures, wrapped);
reedbabc3de2016-07-08 08:43:27 -0700924 VIA("defer", ViaDefer, wrapped);
halcanary96fcdcc2015-08-27 07:41:13 -0700925 VIA("tiles", ViaTiles, 256, 256, nullptr, wrapped);
mtklein7edca212015-01-21 13:18:51 -0800926 VIA("tiles_rt", ViaTiles, 256, 256, new SkRTreeFactory, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800927
mtkleind603b222015-02-17 11:13:33 -0800928 if (FLAGS_matrix.count() == 4) {
mtklein748ca3b2015-01-15 10:56:12 -0800929 SkMatrix m;
mtkleind603b222015-02-17 11:13:33 -0800930 m.reset();
931 m.setScaleX((SkScalar)atof(FLAGS_matrix[0]));
932 m.setSkewX ((SkScalar)atof(FLAGS_matrix[1]));
933 m.setSkewY ((SkScalar)atof(FLAGS_matrix[2]));
934 m.setScaleY((SkScalar)atof(FLAGS_matrix[3]));
935 VIA("matrix", ViaMatrix, m, wrapped);
936 VIA("upright", ViaUpright, m, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800937 }
tomhudson64de1e12015-03-05 08:01:07 -0800938
mtklein748ca3b2015-01-15 10:56:12 -0800939#undef VIA
halcanary96fcdcc2015-08-27 07:41:13 -0700940 return nullptr;
mtklein114c3cd2015-01-15 10:15:02 -0800941}
942
csmartdalton008b9d82017-02-22 12:00:42 -0700943static bool gather_sinks(const GrContextOptions& grCtxOptions) {
kkinnunen3e980c32015-12-23 01:33:00 -0800944 SkCommandLineConfigArray configs;
945 ParseConfigs(FLAGS_config, &configs);
946 for (int i = 0; i < configs.count(); i++) {
947 const SkCommandLineConfig& config = *configs[i];
csmartdalton008b9d82017-02-22 12:00:42 -0700948 Sink* sink = create_sink(grCtxOptions, &config);
kkinnunen3e980c32015-12-23 01:33:00 -0800949 if (sink == nullptr) {
mtkleinc41fd922016-03-08 09:01:39 -0800950 info("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(),
951 config.getTag().c_str());
kkinnunen3e980c32015-12-23 01:33:00 -0800952 continue;
953 }
mtklein748ca3b2015-01-15 10:56:12 -0800954
kkinnunen3e980c32015-12-23 01:33:00 -0800955 const SkTArray<SkString>& parts = config.getViaParts();
956 for (int j = parts.count(); j-- > 0;) {
957 const SkString& part = parts[j];
958 Sink* next = create_via(part, sink);
halcanary96fcdcc2015-08-27 07:41:13 -0700959 if (next == nullptr) {
mtkleinc41fd922016-03-08 09:01:39 -0800960 info("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(),
961 part.c_str());
mtklein748ca3b2015-01-15 10:56:12 -0800962 delete sink;
halcanary96fcdcc2015-08-27 07:41:13 -0700963 sink = nullptr;
mtklein748ca3b2015-01-15 10:56:12 -0800964 break;
965 }
966 sink = next;
967 }
968 if (sink) {
969 push_sink(config, sink);
mtklein114c3cd2015-01-15 10:15:02 -0800970 }
971 }
brianosman05c987c2016-05-09 13:42:16 -0700972
973 // If no configs were requested (just running tests, perhaps?), then we're okay.
974 // Otherwise, make sure that at least one sink was constructed correctly. This catches
975 // the case of bots without a GPU being assigned GPU configs.
976 return (configs.count() == 0) || (gSinks.count() > 0);
mtklein114c3cd2015-01-15 10:15:02 -0800977}
mtklein709d2c32015-01-15 08:30:25 -0800978
mtkleina5114d72015-08-24 13:27:01 -0700979static bool dump_png(SkBitmap bitmap, const char* path, const char* md5) {
980 const int w = bitmap.width(),
981 h = bitmap.height();
982
brianosman3c579dc2016-04-19 09:18:11 -0700983 sk_sp<SkData> encodedBitmap = sk_tools::encode_bitmap_for_png(bitmap);
984 if (encodedBitmap.get() == nullptr) {
985 return false;
mtkleina5114d72015-08-24 13:27:01 -0700986 }
brianosman3c579dc2016-04-19 09:18:11 -0700987 uint32_t* rgba = static_cast<uint32_t*>(encodedBitmap.get()->writable_data());
mtkleina5114d72015-08-24 13:27:01 -0700988
989 // We don't need bitmap anymore. Might as well drop our ref.
mtkleinfccb77d2015-08-24 14:13:29 -0700990 bitmap.reset();
mtkleina5114d72015-08-24 13:27:01 -0700991
mtkleinc64137c2015-08-25 10:56:08 -0700992 FILE* f = fopen(path, "wb");
mtkleina5114d72015-08-24 13:27:01 -0700993 if (!f) { return false; }
994
995 png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
996 if (!png) {
997 fclose(f);
998 return false;
999 }
1000
1001 png_infop info = png_create_info_struct(png);
1002 if (!info) {
1003 png_destroy_write_struct(&png, &info);
1004 fclose(f);
1005 return false;
1006 }
1007
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
mtkleina5114d72015-08-24 13:27:01 -07001019 png_text text[2];
1020 text[0].key = (png_charp)"Author";
1021 text[0].text = (png_charp)"DM dump_png()";
1022 text[0].compression = PNG_TEXT_COMPRESSION_NONE;
1023 text[1].key = (png_charp)"Description";
mtkleind69ece62015-09-10 10:37:44 -07001024 text[1].text = (png_charp)description.c_str();
mtkleina5114d72015-08-24 13:27:01 -07001025 text[1].compression = PNG_TEXT_COMPRESSION_NONE;
1026 png_set_text(png, info, text, 2);
1027
1028 png_init_io(png, f);
1029 png_set_IHDR(png, info, (png_uint_32)w, (png_uint_32)h, 8,
1030 PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE,
1031 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
1032 png_write_info(png, info);
1033 for (int j = 0; j < h; j++) {
brianosman3c579dc2016-04-19 09:18:11 -07001034 png_bytep row = (png_bytep)(rgba + w*j);
mtkleina5114d72015-08-24 13:27:01 -07001035 png_write_rows(png, &row, 1);
1036 }
1037 png_write_end(png, info);
1038
1039 png_destroy_write_struct(&png, &info);
1040 fclose(f);
1041 return true;
1042}
1043
mtkleina2ef6422015-01-15 13:44:22 -08001044static bool match(const char* needle, const char* haystack) {
halcanary96fcdcc2015-08-27 07:41:13 -07001045 return 0 == strcmp("_", needle) || nullptr != strstr(haystack, needle);
mtkleina2ef6422015-01-15 13:44:22 -08001046}
1047
mtklein3eed7dd2016-02-24 19:07:07 -08001048static bool is_blacklisted(const char* sink, const char* src,
1049 const char* srcOptions, const char* name) {
mtklein0d243ff2015-04-03 07:51:00 -07001050 for (int i = 0; i < FLAGS_blacklist.count() - 3; i += 4) {
mtkleina2ef6422015-01-15 13:44:22 -08001051 if (match(FLAGS_blacklist[i+0], sink) &&
djsollen54416de2015-04-03 07:24:48 -07001052 match(FLAGS_blacklist[i+1], src) &&
1053 match(FLAGS_blacklist[i+2], srcOptions) &&
1054 match(FLAGS_blacklist[i+3], name)) {
mtklein3eed7dd2016-02-24 19:07:07 -08001055 return true;
mtkleina2ef6422015-01-15 13:44:22 -08001056 }
1057 }
mtklein3eed7dd2016-02-24 19:07:07 -08001058 return false;
mtkleina2ef6422015-01-15 13:44:22 -08001059}
1060
mtkleincd50bca2016-01-05 06:20:20 -08001061// Even when a Task Sink reports to be non-threadsafe (e.g. GPU), we know things like
1062// .png encoding are definitely thread safe. This lets us offload that work to CPU threads.
1063static SkTaskGroup gDefinitelyThreadSafeWork;
1064
mtklein748ca3b2015-01-15 10:56:12 -08001065// The finest-grained unit of work we can run: draw a single Src into a single Sink,
1066// report any errors, and perhaps write out the output: a .png of the bitmap, or a raw stream.
1067struct Task {
mtkleine0effd62015-07-29 06:37:28 -07001068 Task(const TaggedSrc& src, const TaggedSink& sink) : src(src), sink(sink) {}
1069 const TaggedSrc& src;
1070 const TaggedSink& sink;
mtklein748ca3b2015-01-15 10:56:12 -08001071
mtklein21eaf3b2016-02-08 12:39:59 -08001072 static void Run(const Task& task) {
1073 SkString name = task.src->name();
mtkleine0effd62015-07-29 06:37:28 -07001074
mtkleinb9eb4ac2015-02-02 18:26:03 -08001075 SkString log;
mtklein3eed7dd2016-02-24 19:07:07 -08001076 if (!FLAGS_dryRun) {
mtklein748ca3b2015-01-15 10:56:12 -08001077 SkBitmap bitmap;
1078 SkDynamicMemoryWStream stream;
mtklein3eed7dd2016-02-24 19:07:07 -08001079 start(task.sink.tag.c_str(), task.src.tag.c_str(),
1080 task.src.options.c_str(), name.c_str());
mtklein21eaf3b2016-02-08 12:39:59 -08001081 Error err = task.sink->draw(*task.src, &bitmap, &stream, &log);
mtkleinb3b13b72016-03-07 13:20:52 -08001082 if (!log.isEmpty()) {
mtkleinc41fd922016-03-08 09:01:39 -08001083 info("%s %s %s %s:\n%s\n", task.sink.tag.c_str()
1084 , task.src.tag.c_str()
1085 , task.src.options.c_str()
1086 , name.c_str()
1087 , log.c_str());
mtkleinb3b13b72016-03-07 13:20:52 -08001088 }
mtklein748ca3b2015-01-15 10:56:12 -08001089 if (!err.isEmpty()) {
mtklein4089ef72015-03-05 08:40:28 -08001090 if (err.isFatal()) {
djsollen54416de2015-04-03 07:24:48 -07001091 fail(SkStringPrintf("%s %s %s %s: %s",
mtklein21eaf3b2016-02-08 12:39:59 -08001092 task.sink.tag.c_str(),
1093 task.src.tag.c_str(),
1094 task.src.options.c_str(),
mtklein4089ef72015-03-05 08:40:28 -08001095 name.c_str(),
1096 err.c_str()));
mtkleinb37cb412015-03-18 05:27:14 -07001097 } else {
mtklein3eed7dd2016-02-24 19:07:07 -08001098 done(task.sink.tag.c_str(), task.src.tag.c_str(),
1099 task.src.options.c_str(), name.c_str());
mtkleinba6ada72016-01-21 09:39:35 -08001100 return;
mtklein4089ef72015-03-05 08:40:28 -08001101 }
mtklein748ca3b2015-01-15 10:56:12 -08001102 }
mtklein62bd1a62015-01-27 14:46:26 -08001103
mtkleincd50bca2016-01-05 06:20:20 -08001104 // We're likely switching threads here, so we must capture by value, [=] or [foo,bar].
Hal Canary0b833192017-03-14 14:35:02 -04001105 SkStreamAsset* data = stream.detachAsStream().release();
mtkleincd50bca2016-01-05 06:20:20 -08001106 gDefinitelyThreadSafeWork.add([task,name,bitmap,data]{
Ben Wagner145dbcd2016-11-03 14:40:50 -04001107 std::unique_ptr<SkStreamAsset> ownedData(data);
mtkleincd50bca2016-01-05 06:20:20 -08001108
1109 // Why doesn't the copy constructor do this when we have pre-locked pixels?
1110 bitmap.lockPixels();
1111
1112 SkString md5;
1113 if (!FLAGS_writePath.isEmpty() || !FLAGS_readPath.isEmpty()) {
1114 SkMD5 hash;
1115 if (data->getLength()) {
1116 hash.writeStream(data, data->getLength());
1117 data->rewind();
mtklein38408462015-07-08 07:25:27 -07001118 } else {
mtkleincd50bca2016-01-05 06:20:20 -08001119 // If we're BGRA (Linux, Windows), swizzle over to RGBA (Mac, Android).
1120 // This helps eliminate multiple 0-pixel-diff hashes on gold.skia.org.
1121 // (Android's general slow speed breaks the tie arbitrarily in RGBA's favor.)
1122 // We might consider promoting 565 to RGBA too.
1123 if (bitmap.colorType() == kBGRA_8888_SkColorType) {
1124 SkBitmap swizzle;
1125 SkAssertResult(bitmap.copyTo(&swizzle, kRGBA_8888_SkColorType));
1126 hash.write(swizzle.getPixels(), swizzle.getSize());
1127 } else {
1128 hash.write(bitmap.getPixels(), bitmap.getSize());
1129 }
1130 }
1131 SkMD5::Digest digest;
1132 hash.finish(digest);
1133 for (int i = 0; i < 16; i++) {
1134 md5.appendf("%02x", digest.data[i]);
mtklein38408462015-07-08 07:25:27 -07001135 }
mtklein62bd1a62015-01-27 14:46:26 -08001136 }
mtklein62bd1a62015-01-27 14:46:26 -08001137
mtkleincd50bca2016-01-05 06:20:20 -08001138 if (!FLAGS_readPath.isEmpty() &&
mtklein3eed7dd2016-02-24 19:07:07 -08001139 !gGold.contains(Gold(task.sink.tag, task.src.tag,
1140 task.src.options, name, md5))) {
mtkleincd50bca2016-01-05 06:20:20 -08001141 fail(SkStringPrintf("%s not found for %s %s %s %s in %s",
1142 md5.c_str(),
mtklein21eaf3b2016-02-08 12:39:59 -08001143 task.sink.tag.c_str(),
1144 task.src.tag.c_str(),
1145 task.src.options.c_str(),
mtkleincd50bca2016-01-05 06:20:20 -08001146 name.c_str(),
1147 FLAGS_readPath[0]));
mtklein748ca3b2015-01-15 10:56:12 -08001148 }
mtkleincd50bca2016-01-05 06:20:20 -08001149
1150 if (!FLAGS_writePath.isEmpty()) {
mtklein21eaf3b2016-02-08 12:39:59 -08001151 const char* ext = task.sink->fileExtension();
mtkleincd50bca2016-01-05 06:20:20 -08001152 if (data->getLength()) {
mtklein21eaf3b2016-02-08 12:39:59 -08001153 WriteToDisk(task, md5, ext, data, data->getLength(), nullptr);
mtkleincd50bca2016-01-05 06:20:20 -08001154 SkASSERT(bitmap.drawsNothing());
1155 } else if (!bitmap.drawsNothing()) {
mtklein21eaf3b2016-02-08 12:39:59 -08001156 WriteToDisk(task, md5, ext, nullptr, 0, &bitmap);
mtkleincd50bca2016-01-05 06:20:20 -08001157 }
1158 }
1159 });
mtklein748ca3b2015-01-15 10:56:12 -08001160 }
mtklein3eed7dd2016-02-24 19:07:07 -08001161 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 -08001162 }
1163
1164 static void WriteToDisk(const Task& task,
mtklein62bd1a62015-01-27 14:46:26 -08001165 SkString md5,
1166 const char* ext,
mtklein748ca3b2015-01-15 10:56:12 -08001167 SkStream* data, size_t len,
mtklein62bd1a62015-01-27 14:46:26 -08001168 const SkBitmap* bitmap) {
mtklein409d4702016-02-29 07:38:01 -08001169 bool gammaCorrect = false;
1170 if (bitmap) {
Brian Osman7039f742016-11-01 15:56:16 -04001171 gammaCorrect = SkToBool(bitmap->info().colorSpace());
mtklein409d4702016-02-29 07:38:01 -08001172 }
1173
mtklein748ca3b2015-01-15 10:56:12 -08001174 JsonWriter::BitmapResult result;
djsollen54416de2015-04-03 07:24:48 -07001175 result.name = task.src->name();
mtklein3eed7dd2016-02-24 19:07:07 -08001176 result.config = task.sink.tag;
djsollen54416de2015-04-03 07:24:48 -07001177 result.sourceType = task.src.tag;
1178 result.sourceOptions = task.src.options;
1179 result.ext = ext;
mtklein409d4702016-02-29 07:38:01 -08001180 result.gammaCorrect = gammaCorrect;
djsollen54416de2015-04-03 07:24:48 -07001181 result.md5 = md5;
mtklein748ca3b2015-01-15 10:56:12 -08001182 JsonWriter::AddBitmapResult(result);
1183
mtkleinb0531a72015-04-07 13:38:48 -07001184 // If an MD5 is uninteresting, we want it noted in the JSON file,
1185 // but don't want to dump it out as a .png (or whatever ext is).
1186 if (gUninterestingHashes.contains(md5)) {
1187 return;
1188 }
1189
mtklein748ca3b2015-01-15 10:56:12 -08001190 const char* dir = FLAGS_writePath[0];
1191 if (0 == strcmp(dir, "@")) { // Needed for iOS.
1192 dir = FLAGS_resourcePath[0];
1193 }
1194 sk_mkdir(dir);
1195
1196 SkString path;
1197 if (FLAGS_nameByHash) {
1198 path = SkOSPath::Join(dir, result.md5.c_str());
1199 path.append(".");
1200 path.append(ext);
1201 if (sk_exists(path.c_str())) {
1202 return; // Content-addressed. If it exists already, we're done.
1203 }
1204 } else {
kkinnunen3e980c32015-12-23 01:33:00 -08001205 path = SkOSPath::Join(dir, task.sink.tag.c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001206 sk_mkdir(path.c_str());
msarett9e707a02015-09-01 14:57:57 -07001207 path = SkOSPath::Join(path.c_str(), task.src.tag.c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001208 sk_mkdir(path.c_str());
msarett9e707a02015-09-01 14:57:57 -07001209 if (strcmp(task.src.options.c_str(), "") != 0) {
1210 path = SkOSPath::Join(path.c_str(), task.src.options.c_str());
djsollen54416de2015-04-03 07:24:48 -07001211 sk_mkdir(path.c_str());
1212 }
mtklein748ca3b2015-01-15 10:56:12 -08001213 path = SkOSPath::Join(path.c_str(), task.src->name().c_str());
1214 path.append(".");
1215 path.append(ext);
1216 }
1217
mtklein748ca3b2015-01-15 10:56:12 -08001218 if (bitmap) {
mtkleina5114d72015-08-24 13:27:01 -07001219 if (!dump_png(*bitmap, path.c_str(), result.md5.c_str())) {
mtklein748ca3b2015-01-15 10:56:12 -08001220 fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str()));
1221 return;
1222 }
1223 } else {
mtkleina5114d72015-08-24 13:27:01 -07001224 SkFILEWStream file(path.c_str());
1225 if (!file.isValid()) {
1226 fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str()));
1227 return;
1228 }
mtklein748ca3b2015-01-15 10:56:12 -08001229 if (!file.writeStream(data, len)) {
1230 fail(SkStringPrintf("Can't write to %s.\n", path.c_str()));
1231 return;
1232 }
1233 }
1234 }
1235};
1236
mtklein748ca3b2015-01-15 10:56:12 -08001237/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1238
1239// Unit tests don't fit so well into the Src/Sink model, so we give them special treatment.
1240
mtklein21eaf3b2016-02-08 12:39:59 -08001241static SkTDArray<skiatest::Test> gParallelTests, gSerialTests;
mtklein748ca3b2015-01-15 10:56:12 -08001242
1243static void gather_tests() {
mtklein6c5fed22015-01-20 13:47:23 -08001244 if (!FLAGS_src.contains("tests")) {
mtklein748ca3b2015-01-15 10:56:12 -08001245 return;
1246 }
mtklein6393c062015-04-27 08:45:01 -07001247 for (const skiatest::TestRegistry* r = skiatest::TestRegistry::Head(); r; r = r->next()) {
1248 if (!in_shard()) {
1249 continue;
1250 }
halcanary87f3ba42015-01-20 09:30:20 -08001251 // Despite its name, factory() is returning a reference to
1252 // link-time static const POD data.
1253 const skiatest::Test& test = r->factory();
1254 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, test.name)) {
mtklein748ca3b2015-01-15 10:56:12 -08001255 continue;
1256 }
halcanary87f3ba42015-01-20 09:30:20 -08001257 if (test.needsGpu && gpu_supported()) {
mtklein21eaf3b2016-02-08 12:39:59 -08001258 (FLAGS_gpu_threading ? gParallelTests : gSerialTests).push(test);
halcanary87f3ba42015-01-20 09:30:20 -08001259 } else if (!test.needsGpu && FLAGS_cpu) {
mtklein21eaf3b2016-02-08 12:39:59 -08001260 gParallelTests.push(test);
mtklein82d28432015-01-15 12:46:02 -08001261 }
mtklein748ca3b2015-01-15 10:56:12 -08001262 }
1263}
1264
csmartdalton008b9d82017-02-22 12:00:42 -07001265static void run_test(skiatest::Test test, const GrContextOptions& grCtxOptions) {
halcanary87f3ba42015-01-20 09:30:20 -08001266 struct : public skiatest::Reporter {
mtklein36352bf2015-03-25 18:17:31 -07001267 void reportFailed(const skiatest::Failure& failure) override {
halcanary87f3ba42015-01-20 09:30:20 -08001268 fail(failure.toString());
1269 JsonWriter::AddTestFailure(failure);
1270 }
mtklein36352bf2015-03-25 18:17:31 -07001271 bool allowExtendedTest() const override {
halcanary87f3ba42015-01-20 09:30:20 -08001272 return FLAGS_pathOpsExtended;
1273 }
mtklein36352bf2015-03-25 18:17:31 -07001274 bool verbose() const override { return FLAGS_veryVerbose; }
halcanary87f3ba42015-01-20 09:30:20 -08001275 } reporter;
djsollen824996a2015-06-12 12:06:22 -07001276
mtklein3eed7dd2016-02-24 19:07:07 -08001277 if (!FLAGS_dryRun && !is_blacklisted("_", "tests", "_", test.name)) {
mtklein21eaf3b2016-02-08 12:39:59 -08001278 start("unit", "test", "", test.name);
csmartdalton008b9d82017-02-22 12:00:42 -07001279 GrContextFactory factory(grCtxOptions);
mtklein21eaf3b2016-02-08 12:39:59 -08001280 test.proc(&reporter, &factory);
mtklein748ca3b2015-01-15 10:56:12 -08001281 }
mtklein3eed7dd2016-02-24 19:07:07 -08001282 done("unit", "test", "", test.name);
mtklein748ca3b2015-01-15 10:56:12 -08001283}
1284
1285/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1286
mtkleinafae30a2016-02-24 12:28:32 -08001287DEFINE_int32(status_sec, 15, "Print status this often (and if we crash).");
1288
1289SkThread* start_status_thread() {
1290 auto thread = new SkThread([] (void*) {
1291 for (;;) {
1292 print_status();
1293 #if defined(SK_BUILD_FOR_WIN)
1294 Sleep(FLAGS_status_sec * 1000);
1295 #else
1296 sleep(FLAGS_status_sec);
1297 #endif
mtklein2e1c47e2015-03-12 07:16:56 -07001298 }
mtkleinafae30a2016-02-24 12:28:32 -08001299 });
1300 thread->start();
1301 return thread;
mtkleinde6fc2b2015-03-12 06:28:54 -07001302}
1303
caryclark83ca6282015-06-10 09:31:09 -07001304#define PORTABLE_FONT_PREFIX "Toy Liberation "
1305
mbocee6a9912016-05-31 11:42:36 -07001306static sk_sp<SkTypeface> create_from_name(const char familyName[], SkFontStyle style) {
caryclark83ca6282015-06-10 09:31:09 -07001307 if (familyName && strlen(familyName) > sizeof(PORTABLE_FONT_PREFIX)
1308 && !strncmp(familyName, PORTABLE_FONT_PREFIX, sizeof(PORTABLE_FONT_PREFIX) - 1)) {
caryclark1818acb2015-07-24 12:09:25 -07001309 return sk_tool_utils::create_portable_typeface(familyName, style);
caryclark83ca6282015-06-10 09:31:09 -07001310 }
halcanary96fcdcc2015-08-27 07:41:13 -07001311 return nullptr;
caryclark83ca6282015-06-10 09:31:09 -07001312}
1313
1314#undef PORTABLE_FONT_PREFIX
1315
mbocee6a9912016-05-31 11:42:36 -07001316extern sk_sp<SkTypeface> (*gCreateTypefaceDelegate)(const char [], SkFontStyle );
caryclark83ca6282015-06-10 09:31:09 -07001317
Mike Kleinbe28ee22017-02-06 12:46:20 -05001318int main(int argc, char** argv) {
1319 SkCommandLineFlags::Parse(argc, argv);
Mike Kleinadacaef2017-02-06 09:26:14 -05001320#if defined(SK_BUILD_FOR_IOS)
1321 cd_Documents();
1322#endif
bsalomon71de3532016-04-26 14:27:21 -07001323 setbuf(stdout, nullptr);
mtklein246ba3a2016-02-23 10:39:36 -08001324 setup_crash_handler();
mtkleinafae30a2016-02-24 12:28:32 -08001325
Yuqian Liba62b4a2016-12-14 13:46:53 -05001326 gSkUseAnalyticAA = FLAGS_analyticAA;
liyuqian38911a72016-10-04 11:23:22 -07001327
Yuqian Li550148b2017-01-13 10:13:13 -05001328 if (FLAGS_forceAnalyticAA) {
1329 gSkForceAnalyticAA = true;
1330 }
1331
mtkleina483da32016-03-17 12:53:36 -07001332 if (FLAGS_verbose) {
1333 gVLog = stderr;
1334 } else if (!FLAGS_writePath.isEmpty()) {
mtklein51c8cfc2016-03-11 12:59:09 -08001335 sk_mkdir(FLAGS_writePath[0]);
mtkleina1ce2162016-07-22 12:23:46 -07001336 gVLog = fopen(SkOSPath::Join(FLAGS_writePath[0], "verbose.log").c_str(), "w");
mtkleinc41fd922016-03-08 09:01:39 -08001337 }
1338
csmartdalton008b9d82017-02-22 12:00:42 -07001339 GrContextOptions grCtxOptions;
1340#if SK_SUPPORT_GPU
1341 grCtxOptions.fGpuPathRenderers = CollectGpuPathRenderersFromFlags();
1342#endif
1343
mtklein5286f022016-01-22 08:18:14 -08001344 JsonWriter::DumpJson(); // It's handy for the bots to assume this is ~never missing.
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +00001345 SkAutoGraphics ag;
mtklein406654b2014-09-03 15:34:37 -07001346 SkTaskGroup::Enabler enabled(FLAGS_threads);
caryclark83ca6282015-06-10 09:31:09 -07001347 gCreateTypefaceDelegate = &create_from_name;
commit-bot@chromium.orga65e2fd2014-05-30 17:23:31 +00001348
halcanary7d571242016-02-24 17:59:16 -08001349 {
1350 SkString testResourcePath = GetResourcePath("color_wheel.png");
1351 SkFILEStream testResource(testResourcePath.c_str());
1352 if (!testResource.isValid()) {
mtkleinc41fd922016-03-08 09:01:39 -08001353 info("Some resources are missing. Do you need to set --resourcePath?\n");
halcanary7d571242016-02-24 17:59:16 -08001354 }
1355 }
mtklein62bd1a62015-01-27 14:46:26 -08001356 gather_gold();
borenet09ed4802015-04-03 14:15:33 -07001357 gather_uninteresting_hashes();
mtklein62bd1a62015-01-27 14:46:26 -08001358
scroggo86737142016-02-03 12:19:11 -08001359 if (!gather_srcs()) {
1360 return 1;
1361 }
csmartdalton008b9d82017-02-22 12:00:42 -07001362 if (!gather_sinks(grCtxOptions)) {
brianosman05c987c2016-05-09 13:42:16 -07001363 return 1;
1364 }
mtklein748ca3b2015-01-15 10:56:12 -08001365 gather_tests();
mtklein21eaf3b2016-02-08 12:39:59 -08001366 gPending = gSrcs.count() * gSinks.count() + gParallelTests.count() + gSerialTests.count();
mtkleinc41fd922016-03-08 09:01:39 -08001367 info("%d srcs * %d sinks + %d tests == %d tasks",
1368 gSrcs.count(), gSinks.count(), gParallelTests.count() + gSerialTests.count(), gPending);
Ben Wagner145dbcd2016-11-03 14:40:50 -04001369 std::unique_ptr<SkThread> statusThread(start_status_thread());
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
1425 print_status();
Herb Derby5a523fe2017-01-26 16:48:28 -05001426 SkGraphics::PurgeAllCaches();
mtkleinc41fd922016-03-08 09:01:39 -08001427 info("Finished!\n");
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}
Brian Osman287f6512016-12-05 11:35:07 -05001448const char* ContextTypeName(GrContextFactory::ContextType contextType) {
1449 switch (contextType) {
1450 case GrContextFactory::kGL_ContextType:
1451 return "OpenGL";
1452 case GrContextFactory::kGLES_ContextType:
1453 return "OpenGLES";
1454 case GrContextFactory::kANGLE_D3D9_ES2_ContextType:
1455 return "ANGLE D3D9 ES2";
1456 case GrContextFactory::kANGLE_D3D11_ES2_ContextType:
1457 return "ANGLE D3D11 ES2";
1458 case GrContextFactory::kANGLE_D3D11_ES3_ContextType:
1459 return "ANGLE D3D11 ES3";
1460 case GrContextFactory::kANGLE_GL_ES2_ContextType:
1461 return "ANGLE GL ES2";
1462 case GrContextFactory::kANGLE_GL_ES3_ContextType:
1463 return "ANGLE GL ES3";
1464 case GrContextFactory::kCommandBuffer_ContextType:
1465 return "Command Buffer";
1466 case GrContextFactory::kMESA_ContextType:
1467 return "Mesa";
1468 case GrContextFactory::kNullGL_ContextType:
1469 return "Null GL";
1470 case GrContextFactory::kDebugGL_ContextType:
1471 return "Debug GL";
1472 case GrContextFactory::kVulkan_ContextType:
1473 return "Vulkan";
1474 }
1475 SkDEBUGFAIL("Unreachable");
1476 return "Unknown";
1477}
bsalomon758586c2016-04-06 14:02:39 -07001478#else
1479bool IsGLContextType(int) { return false; }
bsalomondc0fcd42016-04-11 14:21:33 -07001480bool IsVulkanContextType(int) { return false; }
bsalomon758586c2016-04-06 14:02:39 -07001481bool IsRenderingGLContextType(int) { return false; }
1482bool IsNullGLContextType(int) { return false; }
1483#endif
1484
1485void RunWithGPUTestContexts(GrContextTestFn* test, GrContextTypeFilterFn* contextTypeFilter,
bsalomonf2f1c172016-04-05 12:59:06 -07001486 Reporter* reporter, GrContextFactory* factory) {
kkinnunen179a8f52015-11-20 13:32:24 -08001487#if SK_SUPPORT_GPU
kkinnunen3e980c32015-12-23 01:33:00 -08001488
Brian Salomon6405e712017-03-20 08:54:16 -04001489#if defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_WIN) || defined(SK_BUILD_FOR_MAC)
1490 static constexpr auto kNativeGLType = GrContextFactory::kGL_ContextType;
1491#else
1492 static constexpr auto kNativeGLType = GrContextFactory::kGLES_ContextType;
1493#endif
1494
bsalomon758586c2016-04-06 14:02:39 -07001495 for (int typeInt = 0; typeInt < GrContextFactory::kContextTypeCnt; ++typeInt) {
1496 GrContextFactory::ContextType contextType = (GrContextFactory::ContextType) typeInt;
Brian Osmanaa2219c2016-12-05 10:12:17 -05001497 // Use "native" instead of explicitly trying OpenGL and OpenGL ES. Do not use GLES on
bsalomon758586c2016-04-06 14:02:39 -07001498 // desktop since tests do not account for not fixing http://skbug.com/2809
1499 if (contextType == GrContextFactory::kGL_ContextType ||
1500 contextType == GrContextFactory::kGLES_ContextType) {
Brian Salomon6405e712017-03-20 08:54:16 -04001501 if (contextType != kNativeGLType) {
bsalomon758586c2016-04-06 14:02:39 -07001502 continue;
1503 }
1504 }
csmartdaltone812d492017-02-21 12:36:05 -07001505 ContextInfo ctxInfo = factory->getContextInfo(contextType,
1506 GrContextFactory::ContextOverrides::kDisableNVPR);
Brian Osmanaa2219c2016-12-05 10:12:17 -05001507 if (contextTypeFilter && !(*contextTypeFilter)(contextType)) {
1508 continue;
1509 }
Brian Osman287f6512016-12-05 11:35:07 -05001510 ReporterContext ctx(reporter, SkString(ContextTypeName(contextType)));
bsalomon8b7451a2016-05-11 06:33:06 -07001511 if (ctxInfo.grContext()) {
bsalomonf2f1c172016-04-05 12:59:06 -07001512 (*test)(reporter, ctxInfo);
kkinnunen5219fd92015-12-10 06:28:13 -08001513 }
bsalomonf2f1c172016-04-05 12:59:06 -07001514 ctxInfo = factory->getContextInfo(contextType,
csmartdaltone812d492017-02-21 12:36:05 -07001515 GrContextFactory::ContextOverrides::kRequireNVPRSupport);
bsalomon8b7451a2016-05-11 06:33:06 -07001516 if (ctxInfo.grContext()) {
bsalomonf2f1c172016-04-05 12:59:06 -07001517 (*test)(reporter, ctxInfo);
kkinnunen179a8f52015-11-20 13:32:24 -08001518 }
1519 }
1520#endif
1521}
kkinnunen179a8f52015-11-20 13:32:24 -08001522} // namespace skiatest