blob: d92b5ae3ceecd45abd6ce9b362dabcf4162e88b9 [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"
Mike Klein13b6afd2017-06-12 12:45:41 -040031#include "SkPngEncoder.h"
mtklein246ba3a2016-02-23 10:39:36 -080032#include "SkSpinlock.h"
mtkleina82f5622015-02-20 12:30:19 -080033#include "SkTHash.h"
mtklein406654b2014-09-03 15:34:37 -070034#include "SkTaskGroup.h"
mtkleinde6fc2b2015-03-12 06:28:54 -070035#include "SkThreadUtils.h"
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000036#include "Test.h"
mtklein748ca3b2015-01-15 10:56:12 -080037#include "Timer.h"
Mike Kleinadacaef2017-02-06 09:26:14 -050038#include "ios_utils.h"
brianosman3c579dc2016-04-19 09:18:11 -070039#include "picture_utils.h"
caryclark83ca6282015-06-10 09:31:09 -070040#include "sk_tool_utils.h"
liyuqian38911a72016-10-04 11:23:22 -070041#include "SkScan.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000042
scroggo19b91532016-10-24 09:03:26 -070043#include <vector>
44
halcanary7a14b312015-10-01 07:28:13 -070045#ifdef SK_PDF_IMAGE_STATS
46extern void SkPDFImageDumpStats();
47#endif
48
mtkleina5114d72015-08-24 13:27:01 -070049#include "png.h"
50
bungeman60e0fee2015-08-26 05:15:46 -070051#include <stdlib.h>
52
scroggo27a58342015-10-28 08:56:41 -070053#ifndef SK_BUILD_FOR_WIN32
54 #include <unistd.h>
55#endif
56
djsollen54416de2015-04-03 07:24:48 -070057DEFINE_string(src, "tests gm skp image", "Source types to test.");
mtklein748ca3b2015-01-15 10:56:12 -080058DEFINE_bool(nameByHash, false,
59 "If true, write to FLAGS_writePath[0]/<hash>.png instead of "
djsollen54416de2015-04-03 07:24:48 -070060 "to FLAGS_writePath[0]/<config>/<sourceType>/<sourceOptions>/<name>.png");
mtklein748ca3b2015-01-15 10:56:12 -080061DEFINE_bool2(pathOpsExtended, x, false, "Run extended pathOps tests.");
mtkleind603b222015-02-17 11:13:33 -080062DEFINE_string(matrix, "1 0 0 1",
63 "2x2 scale+skew matrix to apply or upright when using "
64 "'matrix' or 'upright' in config.");
mtklein82d28432015-01-15 12:46:02 -080065DEFINE_bool(gpu_threading, false, "Allow GPU work to run on multiple threads?");
mtklein@google.comd36522d2013-10-16 13:02:15 +000066
mtkleina2ef6422015-01-15 13:44:22 -080067DEFINE_string(blacklist, "",
djsollen54416de2015-04-03 07:24:48 -070068 "Space-separated config/src/srcOptions/name quadruples to blacklist. '_' matches anything. E.g. \n"
69 "'--blacklist gpu skp _ _' will blacklist all SKPs drawn into the gpu config.\n"
70 "'--blacklist gpu skp _ _ 8888 gm _ aarects' will also blacklist the aarects GM on 8888.");
mtkleina2ef6422015-01-15 13:44:22 -080071
mtklein62bd1a62015-01-27 14:46:26 -080072DEFINE_string2(readPath, r, "", "If set check for equality with golden results in this directory.");
73
borenet09ed4802015-04-03 14:15:33 -070074DEFINE_string(uninterestingHashesFile, "",
75 "File containing a list of uninteresting hashes. If a result hashes to something in "
76 "this list, no image is written for that result.");
77
mtklein6393c062015-04-27 08:45:01 -070078DEFINE_int32(shards, 1, "We're splitting source data into this many shards.");
79DEFINE_int32(shard, 0, "Which shard do I run?");
80
halcanary45420a92016-06-02 12:41:14 -070081DEFINE_string(mskps, "", "Directory to read mskps from, or a single mskp file.");
82
csmartdalton008b9d82017-02-22 12:00:42 -070083#if SK_SUPPORT_GPU
84DEFINE_pathrenderer_flag;
85#endif
86
mtklein748ca3b2015-01-15 10:56:12 -080087using namespace DM;
bsalomon3724e572016-03-30 18:56:19 -070088using sk_gpu_test::GrContextFactory;
bsalomon273c0f52016-03-31 10:59:06 -070089using sk_gpu_test::GLTestContext;
bsalomonf2f1c172016-04-05 12:59:06 -070090using sk_gpu_test::ContextInfo;
mtklein@google.comd36522d2013-10-16 13:02:15 +000091
mtklein748ca3b2015-01-15 10:56:12 -080092/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
93
benjaminwagnerec4d4d72016-03-25 12:59:53 -070094static const double kStartMs = SkTime::GetMSecs();
mtkleinc41fd922016-03-08 09:01:39 -080095
96static FILE* gVLog;
97
98template <typename... Args>
99static void vlog(const char* fmt, Args&&... args) {
100 if (gVLog) {
101 fprintf(gVLog, "%s\t", HumanizeMs(SkTime::GetMSecs() - kStartMs).c_str());
102 fprintf(gVLog, fmt, args...);
103 fflush(gVLog);
104 }
105}
106
107template <typename... Args>
108static void info(const char* fmt, Args&&... args) {
109 vlog(fmt, args...);
110 if (!FLAGS_quiet) {
111 printf(fmt, args...);
112 }
113}
114static void info(const char* fmt) {
115 if (!FLAGS_quiet) {
116 printf("%s", fmt); // Clang warns printf(fmt) is insecure.
117 }
118}
119
reed086eea92016-05-04 17:12:46 -0700120SK_DECLARE_STATIC_MUTEX(gFailuresMutex);
mtklein748ca3b2015-01-15 10:56:12 -0800121static SkTArray<SkString> gFailures;
122
mtklein3eed7dd2016-02-24 19:07:07 -0800123static void fail(const SkString& err) {
mtklein748ca3b2015-01-15 10:56:12 -0800124 SkAutoMutexAcquire lock(gFailuresMutex);
125 SkDebugf("\n\nFAILURE: %s\n\n", err.c_str());
126 gFailures.push_back(err);
halcanary9e398f72015-01-10 11:18:04 -0800127}
128
mtklein0f7748a2016-07-25 15:27:29 -0700129struct Running {
130 SkString id;
131 SkThreadID thread;
132
133 void dump() const {
134 info("\t%s\n", id.c_str());
135 }
136};
mtkleinb37cb412015-03-18 05:27:14 -0700137
mtklein246ba3a2016-02-23 10:39:36 -0800138// We use a spinlock to make locking this in a signal handler _somewhat_ safe.
mtklein15923c92016-02-29 10:14:38 -0800139static SkSpinlock gMutex;
mtklein0f7748a2016-07-25 15:27:29 -0700140static int32_t gPending;
141static SkTArray<Running> gRunning;
mtklein748ca3b2015-01-15 10:56:12 -0800142
mtklein3eed7dd2016-02-24 19:07:07 -0800143static void done(const char* config, const char* src, const char* srcOptions, const char* name) {
144 SkString id = SkStringPrintf("%s %s %s %s", config, src, srcOptions, name);
mtkleinc41fd922016-03-08 09:01:39 -0800145 vlog("done %s\n", id.c_str());
mtkleinafae30a2016-02-24 12:28:32 -0800146 int pending;
mtkleinb37cb412015-03-18 05:27:14 -0700147 {
mtkleinf10637f2016-06-10 13:56:35 -0700148 SkAutoMutexAcquire lock(gMutex);
mtkleinb37cb412015-03-18 05:27:14 -0700149 for (int i = 0; i < gRunning.count(); i++) {
mtklein0f7748a2016-07-25 15:27:29 -0700150 if (gRunning[i].id == id) {
mtkleinb37cb412015-03-18 05:27:14 -0700151 gRunning.removeShuffle(i);
152 break;
153 }
154 }
mtkleinafae30a2016-02-24 12:28:32 -0800155 pending = --gPending;
reed50bc0512015-05-19 14:13:31 -0700156 }
mtkleina17241b2015-01-23 05:48:00 -0800157 // We write our dm.json file every once in a while in case we crash.
158 // Notice this also handles the final dm.json when pending == 0.
159 if (pending % 500 == 0) {
160 JsonWriter::DumpJson();
161 }
mtklein@google.comd36522d2013-10-16 13:02:15 +0000162}
163
mtklein3eed7dd2016-02-24 19:07:07 -0800164static void start(const char* config, const char* src, const char* srcOptions, const char* name) {
165 SkString id = SkStringPrintf("%s %s %s %s", config, src, srcOptions, name);
mtkleinc41fd922016-03-08 09:01:39 -0800166 vlog("start %s\n", id.c_str());
mtkleinf10637f2016-06-10 13:56:35 -0700167 SkAutoMutexAcquire lock(gMutex);
mtklein0f7748a2016-07-25 15:27:29 -0700168 gRunning.push_back({id,SkGetThreadID()});
mtkleinb37cb412015-03-18 05:27:14 -0700169}
170
mtkleinafae30a2016-02-24 12:28:32 -0800171static void print_status() {
mtkleinafae30a2016-02-24 12:28:32 -0800172 int curr = sk_tools::getCurrResidentSetSizeMB(),
173 peak = sk_tools::getMaxResidentSetSizeMB();
mtkleinc41fd922016-03-08 09:01:39 -0800174 SkString elapsed = HumanizeMs(SkTime::GetMSecs() - kStartMs);
mtkleinafae30a2016-02-24 12:28:32 -0800175
mtkleinf10637f2016-06-10 13:56:35 -0700176 SkAutoMutexAcquire lock(gMutex);
mtkleinc41fd922016-03-08 09:01:39 -0800177 info("\n%s elapsed, %d active, %d queued, %dMB RAM, %dMB peak\n",
178 elapsed.c_str(), gRunning.count(), gPending - gRunning.count(), curr, peak);
mtkleinafae30a2016-02-24 12:28:32 -0800179 for (auto& task : gRunning) {
mtklein0f7748a2016-07-25 15:27:29 -0700180 task.dump();
mtkleinafae30a2016-02-24 12:28:32 -0800181 }
182}
183
Mike Klein3cc2d202016-10-24 11:39:43 -0400184static void find_culprit() {
185 // Assumes gMutex is locked.
186 SkThreadID thisThread = SkGetThreadID();
187 for (auto& task : gRunning) {
188 if (task.thread == thisThread) {
189 info("Likely culprit:\n");
190 task.dump();
mtklein0f7748a2016-07-25 15:27:29 -0700191 }
192 }
Mike Klein3cc2d202016-10-24 11:39:43 -0400193}
mtklein0f7748a2016-07-25 15:27:29 -0700194
mtklein246ba3a2016-02-23 10:39:36 -0800195#if defined(SK_BUILD_FOR_WIN32)
mtklein5b64dab2016-06-09 08:59:48 -0700196 static LONG WINAPI crash_handler(EXCEPTION_POINTERS* e) {
mtkleinf8557292016-02-29 06:35:28 -0800197 static const struct {
198 const char* name;
robertphillips75467862016-03-01 14:10:23 -0800199 DWORD code;
mtkleinf8557292016-02-29 06:35:28 -0800200 } kExceptions[] = {
201 #define _(E) {#E, E}
202 _(EXCEPTION_ACCESS_VIOLATION),
203 _(EXCEPTION_BREAKPOINT),
204 _(EXCEPTION_INT_DIVIDE_BY_ZERO),
205 _(EXCEPTION_STACK_OVERFLOW),
206 // TODO: more?
207 #undef _
208 };
209
mtkleinf10637f2016-06-10 13:56:35 -0700210 SkAutoMutexAcquire lock(gMutex);
mtklein5b64dab2016-06-09 08:59:48 -0700211
212 const DWORD code = e->ExceptionRecord->ExceptionCode;
213 info("\nCaught exception %u", code);
214 for (const auto& exception : kExceptions) {
215 if (exception.code == code) {
216 info(" %s", exception.name);
mtkleinf8557292016-02-29 06:35:28 -0800217 }
mtkleinf8557292016-02-29 06:35:28 -0800218 }
mtklein5b64dab2016-06-09 08:59:48 -0700219 info(", was running:\n");
220 for (auto& task : gRunning) {
mtklein0f7748a2016-07-25 15:27:29 -0700221 task.dump();
mtklein5b64dab2016-06-09 08:59:48 -0700222 }
mtklein0f7748a2016-07-25 15:27:29 -0700223 find_culprit();
mtklein5b64dab2016-06-09 08:59:48 -0700224 fflush(stdout);
225
mtkleinf8557292016-02-29 06:35:28 -0800226 // Execute default exception handler... hopefully, exit.
227 return EXCEPTION_EXECUTE_HANDLER;
mtklein246ba3a2016-02-23 10:39:36 -0800228 }
229
Mike Klein3cc2d202016-10-24 11:39:43 -0400230 static void setup_crash_handler() {
231 SetUnhandledExceptionFilter(crash_handler);
232 }
233#else
mtklein246ba3a2016-02-23 10:39:36 -0800234 #include <signal.h>
Mike Klein3cc2d202016-10-24 11:39:43 -0400235 #if !defined(SK_BUILD_FOR_ANDROID)
236 #include <execinfo.h>
237 #endif
238
239 static constexpr int max_of() { return 0; }
240 template <typename... Rest>
241 static constexpr int max_of(int x, Rest... rest) {
242 return x > max_of(rest...) ? x : max_of(rest...);
243 }
244
245 static void (*previous_handler[max_of(SIGABRT,SIGBUS,SIGFPE,SIGILL,SIGSEGV)+1])(int);
mtkleinf8557292016-02-29 06:35:28 -0800246
mtklein5b64dab2016-06-09 08:59:48 -0700247 static void crash_handler(int sig) {
mtkleinf10637f2016-06-10 13:56:35 -0700248 SkAutoMutexAcquire lock(gMutex);
mtklein5b64dab2016-06-09 08:59:48 -0700249
250 info("\nCaught signal %d [%s], was running:\n", sig, strsignal(sig));
251 for (auto& task : gRunning) {
mtklein0f7748a2016-07-25 15:27:29 -0700252 task.dump();
mtklein5b64dab2016-06-09 08:59:48 -0700253 }
mtklein0f7748a2016-07-25 15:27:29 -0700254 find_culprit();
mtklein5b64dab2016-06-09 08:59:48 -0700255
Mike Klein3cc2d202016-10-24 11:39:43 -0400256 #if !defined(SK_BUILD_FOR_ANDROID)
mtklein5b64dab2016-06-09 08:59:48 -0700257 void* stack[64];
258 int count = backtrace(stack, SK_ARRAY_COUNT(stack));
259 char** symbols = backtrace_symbols(stack, count);
260 info("\nStack trace:\n");
261 for (int i = 0; i < count; i++) {
262 info(" %s\n", symbols[i]);
263 }
Mike Klein3cc2d202016-10-24 11:39:43 -0400264 #endif
mtklein5b64dab2016-06-09 08:59:48 -0700265 fflush(stdout);
266
Mike Klein3cc2d202016-10-24 11:39:43 -0400267 signal(sig, previous_handler[sig]);
268 raise(sig);
mtklein5b64dab2016-06-09 08:59:48 -0700269 }
270
mtklein246ba3a2016-02-23 10:39:36 -0800271 static void setup_crash_handler() {
272 const int kSignals[] = { SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGSEGV };
273 for (int sig : kSignals) {
Mike Klein3cc2d202016-10-24 11:39:43 -0400274 previous_handler[sig] = signal(sig, crash_handler);
mtklein246ba3a2016-02-23 10:39:36 -0800275 }
276 }
277#endif
278
mtklein748ca3b2015-01-15 10:56:12 -0800279/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
mtklein114c3cd2015-01-15 10:15:02 -0800280
mtklein62bd1a62015-01-27 14:46:26 -0800281struct Gold : public SkString {
mtkleina82f5622015-02-20 12:30:19 -0800282 Gold() : SkString("") {}
mtklein3eed7dd2016-02-24 19:07:07 -0800283 Gold(const SkString& sink, const SkString& src,
284 const SkString& srcOptions, const SkString& name,
285 const SkString& md5)
mtklein62bd1a62015-01-27 14:46:26 -0800286 : SkString("") {
287 this->append(sink);
288 this->append(src);
djsollen54416de2015-04-03 07:24:48 -0700289 this->append(srcOptions);
mtklein62bd1a62015-01-27 14:46:26 -0800290 this->append(name);
291 this->append(md5);
mtklein62bd1a62015-01-27 14:46:26 -0800292 }
mtkleinc8d1dd42015-10-15 12:23:01 -0700293 struct Hash {
294 uint32_t operator()(const Gold& g) const {
295 return SkGoodHash()((const SkString&)g);
296 }
297 };
mtklein62bd1a62015-01-27 14:46:26 -0800298};
mtkleina82f5622015-02-20 12:30:19 -0800299static SkTHashSet<Gold, Gold::Hash> gGold;
mtklein62bd1a62015-01-27 14:46:26 -0800300
301static void add_gold(JsonWriter::BitmapResult r) {
djsollen54416de2015-04-03 07:24:48 -0700302 gGold.add(Gold(r.config, r.sourceType, r.sourceOptions, r.name, r.md5));
mtklein62bd1a62015-01-27 14:46:26 -0800303}
304
305static void gather_gold() {
306 if (!FLAGS_readPath.isEmpty()) {
307 SkString path(FLAGS_readPath[0]);
308 path.append("/dm.json");
309 if (!JsonWriter::ReadJson(path.c_str(), add_gold)) {
310 fail(SkStringPrintf("Couldn't read %s for golden results.", path.c_str()));
311 }
312 }
313}
314
315/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
316
mtklein935f1b12016-03-16 08:37:19 -0700317#if defined(SK_BUILD_FOR_WIN32)
318 static const char* kNewline = "\r\n";
319#else
320 static const char* kNewline = "\n";
321#endif
322
borenet09ed4802015-04-03 14:15:33 -0700323static SkTHashSet<SkString> gUninterestingHashes;
324
325static void gather_uninteresting_hashes() {
326 if (!FLAGS_uninterestingHashesFile.isEmpty()) {
bungeman38d909e2016-08-02 14:40:46 -0700327 sk_sp<SkData> data(SkData::MakeFromFileName(FLAGS_uninterestingHashesFile[0]));
mtkleincc334b32015-09-22 11:43:53 -0700328 if (!data) {
mtkleinc41fd922016-03-08 09:01:39 -0800329 info("WARNING: unable to read uninteresting hashes from %s\n",
330 FLAGS_uninterestingHashesFile[0]);
mtkleincc334b32015-09-22 11:43:53 -0700331 return;
332 }
Mike Klein45dcc0c2017-04-05 18:04:31 -0400333
334 // Copy to a string to make sure SkStrSplit has a terminating \0 to find.
335 SkString contents((const char*)data->data(), data->size());
336
borenet09ed4802015-04-03 14:15:33 -0700337 SkTArray<SkString> hashes;
Mike Klein45dcc0c2017-04-05 18:04:31 -0400338 SkStrSplit(contents.c_str(), kNewline, &hashes);
borenet09ed4802015-04-03 14:15:33 -0700339 for (const SkString& hash : hashes) {
340 gUninterestingHashes.add(hash);
341 }
mtkleinc41fd922016-03-08 09:01:39 -0800342 info("FYI: loaded %d distinct uninteresting hashes from %d lines\n",
343 gUninterestingHashes.count(), hashes.count());
borenet09ed4802015-04-03 14:15:33 -0700344 }
345}
346
347/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
348
Ben Wagner145dbcd2016-11-03 14:40:50 -0400349struct TaggedSrc : public std::unique_ptr<Src> {
mtklein3eed7dd2016-02-24 19:07:07 -0800350 SkString tag;
351 SkString options;
mtkleine0effd62015-07-29 06:37:28 -0700352};
353
Ben Wagner145dbcd2016-11-03 14:40:50 -0400354struct TaggedSink : public std::unique_ptr<Sink> {
kkinnunen3e980c32015-12-23 01:33:00 -0800355 SkString tag;
djsollen54416de2015-04-03 07:24:48 -0700356};
mtklein748ca3b2015-01-15 10:56:12 -0800357
358static const bool kMemcpyOK = true;
359
mtkleine0effd62015-07-29 06:37:28 -0700360static SkTArray<TaggedSrc, kMemcpyOK> gSrcs;
361static SkTArray<TaggedSink, kMemcpyOK> gSinks;
mtklein748ca3b2015-01-15 10:56:12 -0800362
mtklein6393c062015-04-27 08:45:01 -0700363static bool in_shard() {
364 static int N = 0;
365 return N++ % FLAGS_shards == FLAGS_shard;
366}
367
mtklein3eed7dd2016-02-24 19:07:07 -0800368static void push_src(const char* tag, ImplicitString options, Src* s) {
Ben Wagner145dbcd2016-11-03 14:40:50 -0400369 std::unique_ptr<Src> src(s);
mtklein6393c062015-04-27 08:45:01 -0700370 if (in_shard() &&
mtklein3eed7dd2016-02-24 19:07:07 -0800371 FLAGS_src.contains(tag) &&
mtklein748ca3b2015-01-15 10:56:12 -0800372 !SkCommandLineFlags::ShouldSkip(FLAGS_match, src->name().c_str())) {
mtkleine0effd62015-07-29 06:37:28 -0700373 TaggedSrc& s = gSrcs.push_back();
mtklein18300a32016-03-16 13:53:35 -0700374 s.reset(src.release());
mtklein748ca3b2015-01-15 10:56:12 -0800375 s.tag = tag;
djsollen54416de2015-04-03 07:24:48 -0700376 s.options = options;
mtklein114c3cd2015-01-15 10:15:02 -0800377 }
mtklein748ca3b2015-01-15 10:56:12 -0800378}
mtklein114c3cd2015-01-15 10:15:02 -0800379
msarett9e707a02015-09-01 14:57:57 -0700380static void push_codec_src(Path path, CodecSrc::Mode mode, CodecSrc::DstColorType dstColorType,
scroggoc5560be2016-02-03 09:42:42 -0800381 SkAlphaType dstAlphaType, float scale) {
scroggoe4499842016-02-25 11:03:47 -0800382 if (FLAGS_simpleCodec) {
scroggo19b91532016-10-24 09:03:26 -0700383 const bool simple = CodecSrc::kCodec_Mode == mode || CodecSrc::kAnimated_Mode == mode;
384 if (!simple || dstColorType != CodecSrc::kGetFromCanvas_DstColorType || scale != 1.0f) {
scroggoe4499842016-02-25 11:03:47 -0800385 // Only decode in the simple case.
386 return;
scroggo19b91532016-10-24 09:03:26 -0700387 }
scroggoe4499842016-02-25 11:03:47 -0800388 }
msarett9e707a02015-09-01 14:57:57 -0700389 SkString folder;
390 switch (mode) {
391 case CodecSrc::kCodec_Mode:
392 folder.append("codec");
393 break;
msarettbb25b532016-01-13 09:31:39 -0800394 case CodecSrc::kCodecZeroInit_Mode:
395 folder.append("codec_zero_init");
396 break;
msarett9e707a02015-09-01 14:57:57 -0700397 case CodecSrc::kScanline_Mode:
398 folder.append("scanline");
399 break;
msarett9e707a02015-09-01 14:57:57 -0700400 case CodecSrc::kStripe_Mode:
401 folder.append("stripe");
402 break;
msarett91c22b22016-02-22 12:27:46 -0800403 case CodecSrc::kCroppedScanline_Mode:
404 folder.append("crop");
405 break;
msarett9e707a02015-09-01 14:57:57 -0700406 case CodecSrc::kSubset_Mode:
msarett36c37962015-09-02 13:20:52 -0700407 folder.append("codec_subset");
msarett9e707a02015-09-01 14:57:57 -0700408 break;
scroggo19b91532016-10-24 09:03:26 -0700409 case CodecSrc::kAnimated_Mode:
410 folder.append("codec_animated");
411 break;
msarett9e707a02015-09-01 14:57:57 -0700412 }
413
414 switch (dstColorType) {
415 case CodecSrc::kGrayscale_Always_DstColorType:
416 folder.append("_kGray8");
417 break;
418 case CodecSrc::kIndex8_Always_DstColorType:
419 folder.append("_kIndex8");
420 break;
msarett34e0ec42016-04-22 16:27:24 -0700421 case CodecSrc::kNonNative8888_Always_DstColorType:
422 folder.append("_kNonNative");
423 break;
msarett9e707a02015-09-01 14:57:57 -0700424 default:
425 break;
426 }
427
scroggoc5560be2016-02-03 09:42:42 -0800428 switch (dstAlphaType) {
scroggoc5560be2016-02-03 09:42:42 -0800429 case kPremul_SkAlphaType:
430 folder.append("_premul");
431 break;
432 case kUnpremul_SkAlphaType:
433 folder.append("_unpremul");
434 break;
435 default:
436 break;
437 }
438
msarett9e707a02015-09-01 14:57:57 -0700439 if (1.0f != scale) {
440 folder.appendf("_%.3f", scale);
441 }
442
scroggoc5560be2016-02-03 09:42:42 -0800443 CodecSrc* src = new CodecSrc(path, mode, dstColorType, dstAlphaType, scale);
msarett9e707a02015-09-01 14:57:57 -0700444 push_src("image", folder, src);
445}
446
scroggof8dc9df2016-05-16 09:04:13 -0700447static void push_android_codec_src(Path path, CodecSrc::DstColorType dstColorType,
448 SkAlphaType dstAlphaType, int sampleSize) {
msarett3d9d7a72015-10-21 10:27:10 -0700449 SkString folder;
scroggof8dc9df2016-05-16 09:04:13 -0700450 folder.append("scaled_codec");
msarett3d9d7a72015-10-21 10:27:10 -0700451
452 switch (dstColorType) {
453 case CodecSrc::kGrayscale_Always_DstColorType:
454 folder.append("_kGray8");
455 break;
456 case CodecSrc::kIndex8_Always_DstColorType:
457 folder.append("_kIndex8");
458 break;
msarett34e0ec42016-04-22 16:27:24 -0700459 case CodecSrc::kNonNative8888_Always_DstColorType:
460 folder.append("_kNonNative");
461 break;
msarett3d9d7a72015-10-21 10:27:10 -0700462 default:
463 break;
464 }
465
scroggoc5560be2016-02-03 09:42:42 -0800466 switch (dstAlphaType) {
scroggoc5560be2016-02-03 09:42:42 -0800467 case kPremul_SkAlphaType:
468 folder.append("_premul");
469 break;
msarett9e9444c2016-02-03 12:39:10 -0800470 case kUnpremul_SkAlphaType:
471 folder.append("_unpremul");
472 break;
scroggoc5560be2016-02-03 09:42:42 -0800473 default:
474 break;
475 }
476
msarett3d9d7a72015-10-21 10:27:10 -0700477 if (1 != sampleSize) {
msarett4b0778e2015-11-13 09:59:11 -0800478 folder.appendf("_%.3f", 1.0f / (float) sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700479 }
480
scroggof8dc9df2016-05-16 09:04:13 -0700481 AndroidCodecSrc* src = new AndroidCodecSrc(path, dstColorType, dstAlphaType, sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700482 push_src("image", folder, src);
483}
484
msarett18976312016-03-09 14:20:58 -0800485static void push_image_gen_src(Path path, ImageGenSrc::Mode mode, SkAlphaType alphaType, bool isGpu)
486{
487 SkString folder;
488 switch (mode) {
489 case ImageGenSrc::kCodec_Mode:
490 folder.append("gen_codec");
491 break;
492 case ImageGenSrc::kPlatform_Mode:
493 folder.append("gen_platform");
494 break;
495 }
496
497 if (isGpu) {
498 folder.append("_gpu");
499 } else {
500 switch (alphaType) {
501 case kOpaque_SkAlphaType:
502 folder.append("_opaque");
503 break;
504 case kPremul_SkAlphaType:
505 folder.append("_premul");
506 break;
507 case kUnpremul_SkAlphaType:
508 folder.append("_unpremul");
509 break;
510 default:
511 break;
512 }
513 }
514
515 ImageGenSrc* src = new ImageGenSrc(path, mode, alphaType, isGpu);
516 push_src("image", folder, src);
517}
518
msarett438b2ad2015-04-09 12:43:10 -0700519static void push_codec_srcs(Path path) {
bungeman38d909e2016-08-02 14:40:46 -0700520 sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str()));
msarett438b2ad2015-04-09 12:43:10 -0700521 if (!encoded) {
mtkleinc41fd922016-03-08 09:01:39 -0800522 info("Couldn't read %s.", path.c_str());
msarett438b2ad2015-04-09 12:43:10 -0700523 return;
524 }
Ben Wagner145dbcd2016-11-03 14:40:50 -0400525 std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(encoded));
halcanary96fcdcc2015-08-27 07:41:13 -0700526 if (nullptr == codec.get()) {
mtkleinc41fd922016-03-08 09:01:39 -0800527 info("Couldn't create codec for %s.", path.c_str());
msarett438b2ad2015-04-09 12:43:10 -0700528 return;
529 }
530
scroggo9366aff2016-05-20 08:38:54 -0700531 // native scaling is only supported by WEBP and JPEG
532 bool supportsNativeScaling = false;
msarett438b2ad2015-04-09 12:43:10 -0700533
msarett91c22b22016-02-22 12:27:46 -0800534 SkTArray<CodecSrc::Mode> nativeModes;
535 nativeModes.push_back(CodecSrc::kCodec_Mode);
536 nativeModes.push_back(CodecSrc::kCodecZeroInit_Mode);
msarett91c22b22016-02-22 12:27:46 -0800537 switch (codec->getEncodedFormat()) {
Hal Canarydb683012016-11-23 08:55:18 -0700538 case SkEncodedImageFormat::kJPEG:
msarett91c22b22016-02-22 12:27:46 -0800539 nativeModes.push_back(CodecSrc::kScanline_Mode);
540 nativeModes.push_back(CodecSrc::kStripe_Mode);
541 nativeModes.push_back(CodecSrc::kCroppedScanline_Mode);
scroggo9366aff2016-05-20 08:38:54 -0700542 supportsNativeScaling = true;
msarett91c22b22016-02-22 12:27:46 -0800543 break;
Hal Canarydb683012016-11-23 08:55:18 -0700544 case SkEncodedImageFormat::kWEBP:
msarett91c22b22016-02-22 12:27:46 -0800545 nativeModes.push_back(CodecSrc::kSubset_Mode);
scroggo9366aff2016-05-20 08:38:54 -0700546 supportsNativeScaling = true;
msarett91c22b22016-02-22 12:27:46 -0800547 break;
Hal Canarydb683012016-11-23 08:55:18 -0700548 case SkEncodedImageFormat::kDNG:
msarettb65e6042016-02-23 05:37:25 -0800549 break;
msarett91c22b22016-02-22 12:27:46 -0800550 default:
551 nativeModes.push_back(CodecSrc::kScanline_Mode);
msarett91c22b22016-02-22 12:27:46 -0800552 break;
553 }
msarett9e707a02015-09-01 14:57:57 -0700554
msarett91c22b22016-02-22 12:27:46 -0800555 SkTArray<CodecSrc::DstColorType> colorTypes;
556 colorTypes.push_back(CodecSrc::kGetFromCanvas_DstColorType);
msarett34e0ec42016-04-22 16:27:24 -0700557 colorTypes.push_back(CodecSrc::kNonNative8888_Always_DstColorType);
msarett36c37962015-09-02 13:20:52 -0700558 switch (codec->getInfo().colorType()) {
559 case kGray_8_SkColorType:
msarett91c22b22016-02-22 12:27:46 -0800560 colorTypes.push_back(CodecSrc::kGrayscale_Always_DstColorType);
Hal Canarydb683012016-11-23 08:55:18 -0700561 if (SkEncodedImageFormat::kWBMP == codec->getEncodedFormat()) {
msarett91c22b22016-02-22 12:27:46 -0800562 colorTypes.push_back(CodecSrc::kIndex8_Always_DstColorType);
msarett55f7bdd2016-02-16 13:24:54 -0800563 }
msarett36c37962015-09-02 13:20:52 -0700564 break;
565 case kIndex_8_SkColorType:
msarett91c22b22016-02-22 12:27:46 -0800566 colorTypes.push_back(CodecSrc::kIndex8_Always_DstColorType);
msarett36c37962015-09-02 13:20:52 -0700567 break;
568 default:
msarett36c37962015-09-02 13:20:52 -0700569 break;
570 }
msarett9e707a02015-09-01 14:57:57 -0700571
scroggoc5560be2016-02-03 09:42:42 -0800572 SkTArray<SkAlphaType> alphaModes;
573 alphaModes.push_back(kPremul_SkAlphaType);
scroggof2c96a22016-05-20 11:08:27 -0700574 if (codec->getInfo().alphaType() != kOpaque_SkAlphaType) {
575 alphaModes.push_back(kUnpremul_SkAlphaType);
scroggoc5560be2016-02-03 09:42:42 -0800576 }
msarettb714fb02016-01-22 14:46:42 -0800577
578 for (CodecSrc::Mode mode : nativeModes) {
scroggo9366aff2016-05-20 08:38:54 -0700579 for (CodecSrc::DstColorType colorType : colorTypes) {
580 for (SkAlphaType alphaType : alphaModes) {
scroggof2c96a22016-05-20 11:08:27 -0700581 // Only test kCroppedScanline_Mode when the alpha type is premul. The test is
scroggo9366aff2016-05-20 08:38:54 -0700582 // slow and won't be interestingly different with different alpha types.
583 if (CodecSrc::kCroppedScanline_Mode == mode &&
scroggof2c96a22016-05-20 11:08:27 -0700584 kPremul_SkAlphaType != alphaType) {
scroggo9366aff2016-05-20 08:38:54 -0700585 continue;
586 }
msarett91c22b22016-02-22 12:27:46 -0800587
scroggo9366aff2016-05-20 08:38:54 -0700588 push_codec_src(path, mode, colorType, alphaType, 1.0f);
msarettf3dc1882016-04-26 13:06:38 -0700589
scroggo9366aff2016-05-20 08:38:54 -0700590 // Skip kNonNative on different native scales. It won't be interestingly
591 // different.
592 if (supportsNativeScaling &&
593 CodecSrc::kNonNative8888_Always_DstColorType == colorType) {
594 // Native Scales
595 // SkJpegCodec natively supports scaling to the following:
596 for (auto scale : { 0.125f, 0.25f, 0.375f, 0.5f, 0.625f, 0.750f, 0.875f }) {
597 push_codec_src(path, mode, colorType, alphaType, scale);
598 }
scroggoc5560be2016-02-03 09:42:42 -0800599 }
msarett9e707a02015-09-01 14:57:57 -0700600 }
601 }
msarett0a242972015-06-11 14:27:27 -0700602 }
msarett36c37962015-09-02 13:20:52 -0700603
scroggo19b91532016-10-24 09:03:26 -0700604 {
605 std::vector<SkCodec::FrameInfo> frameInfos = codec->getFrameInfo();
606 if (frameInfos.size() > 1) {
Leon Scroggins III557fbbe2017-05-23 09:37:21 -0400607 for (auto dstCT : { CodecSrc::kNonNative8888_Always_DstColorType,
608 CodecSrc::kGetFromCanvas_DstColorType }) {
609 for (auto at : { kUnpremul_SkAlphaType, kPremul_SkAlphaType }) {
610 push_codec_src(path, CodecSrc::kAnimated_Mode, dstCT, at, 1.0f);
611 }
612 }
scroggo19b91532016-10-24 09:03:26 -0700613 }
614
615 }
616
scroggoe4499842016-02-25 11:03:47 -0800617 if (FLAGS_simpleCodec) {
618 return;
619 }
620
msarett3d9d7a72015-10-21 10:27:10 -0700621 const int sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
msarett36c37962015-09-02 13:20:52 -0700622
msarett3d9d7a72015-10-21 10:27:10 -0700623 for (int sampleSize : sampleSizes) {
msarett91c22b22016-02-22 12:27:46 -0800624 for (CodecSrc::DstColorType colorType : colorTypes) {
scroggoc5560be2016-02-03 09:42:42 -0800625 for (SkAlphaType alphaType : alphaModes) {
msarettf3dc1882016-04-26 13:06:38 -0700626 // We can exercise all of the kNonNative support code in the swizzler with just a
627 // few sample sizes. Skip the rest.
628 if (CodecSrc::kNonNative8888_Always_DstColorType == colorType && sampleSize > 3) {
629 continue;
630 }
631
scroggof8dc9df2016-05-16 09:04:13 -0700632 push_android_codec_src(path, colorType, alphaType, sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700633 }
msarett36c37962015-09-02 13:20:52 -0700634 }
635 }
msarett18976312016-03-09 14:20:58 -0800636
637 static const char* const rawExts[] = {
638 "arw", "cr2", "dng", "nef", "nrw", "orf", "raf", "rw2", "pef", "srw",
639 "ARW", "CR2", "DNG", "NEF", "NRW", "ORF", "RAF", "RW2", "PEF", "SRW",
640 };
641
642 // There is not currently a reason to test RAW images on image generator.
643 // If we want to enable these tests, we will need to fix skbug.com/5079.
644 for (const char* ext : rawExts) {
645 if (path.endsWith(ext)) {
646 return;
647 }
648 }
649
650 // Push image generator GPU test.
brianosmanc9ced392016-03-24 07:27:43 -0700651 push_image_gen_src(path, ImageGenSrc::kCodec_Mode, codec->getInfo().alphaType(), true);
msarett18976312016-03-09 14:20:58 -0800652
653 // Push image generator CPU tests.
654 for (SkAlphaType alphaType : alphaModes) {
655 push_image_gen_src(path, ImageGenSrc::kCodec_Mode, alphaType, false);
656
657#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
Hal Canarydb683012016-11-23 08:55:18 -0700658 if (SkEncodedImageFormat::kWEBP != codec->getEncodedFormat() &&
659 SkEncodedImageFormat::kWBMP != codec->getEncodedFormat() &&
msarett18976312016-03-09 14:20:58 -0800660 kUnpremul_SkAlphaType != alphaType)
661 {
662 push_image_gen_src(path, ImageGenSrc::kPlatform_Mode, alphaType, false);
663 }
msarettfc0b6d12016-03-17 13:50:17 -0700664#elif defined(SK_BUILD_FOR_WIN)
Hal Canarydb683012016-11-23 08:55:18 -0700665 if (SkEncodedImageFormat::kWEBP != codec->getEncodedFormat() &&
666 SkEncodedImageFormat::kWBMP != codec->getEncodedFormat())
msarettfc0b6d12016-03-17 13:50:17 -0700667 {
668 push_image_gen_src(path, ImageGenSrc::kPlatform_Mode, alphaType, false);
669 }
msarett18976312016-03-09 14:20:58 -0800670#endif
671 }
msarett438b2ad2015-04-09 12:43:10 -0700672}
673
msarettd1227a72016-05-18 06:23:57 -0700674static void push_brd_src(Path path, CodecSrc::DstColorType dstColorType, BRDSrc::Mode mode,
675 uint32_t sampleSize) {
676 SkString folder("brd_android_codec");
msaretta5783ae2015-09-08 15:35:32 -0700677 switch (mode) {
678 case BRDSrc::kFullImage_Mode:
679 break;
680 case BRDSrc::kDivisor_Mode:
681 folder.append("_divisor");
682 break;
683 default:
684 SkASSERT(false);
685 return;
686 }
687
688 switch (dstColorType) {
689 case CodecSrc::kGetFromCanvas_DstColorType:
690 break;
691 case CodecSrc::kIndex8_Always_DstColorType:
692 folder.append("_kIndex");
693 break;
694 case CodecSrc::kGrayscale_Always_DstColorType:
695 folder.append("_kGray");
696 break;
697 default:
698 SkASSERT(false);
699 return;
700 }
701
702 if (1 != sampleSize) {
msarett4b0778e2015-11-13 09:59:11 -0800703 folder.appendf("_%.3f", 1.0f / (float) sampleSize);
msaretta5783ae2015-09-08 15:35:32 -0700704 }
705
msarettd1227a72016-05-18 06:23:57 -0700706 BRDSrc* src = new BRDSrc(path, mode, dstColorType, sampleSize);
msaretta5783ae2015-09-08 15:35:32 -0700707 push_src("image", folder, src);
708}
709
710static void push_brd_srcs(Path path) {
scroggo24a9bd72016-05-20 06:02:42 -0700711 // Only run Index8 and grayscale to one sampleSize and Mode. Though interesting
712 // to test these color types, they should not reveal anything across various
713 // sampleSizes and Modes
714 for (auto type : { CodecSrc::kIndex8_Always_DstColorType,
715 CodecSrc::kGrayscale_Always_DstColorType }) {
716 // Arbitrarily choose Mode and sampleSize.
717 push_brd_src(path, type, BRDSrc::kFullImage_Mode, 2);
718 }
719
720
scroggo501b7342015-11-03 07:55:11 -0800721 // Test on a variety of sampleSizes, making sure to include:
722 // - 2, 4, and 8, which are natively supported by jpeg
723 // - multiples of 2 which are not divisible by 4 (analogous for 4)
724 // - larger powers of two, since BRD clients generally use powers of 2
725 // We will only produce output for the larger sizes on large images.
726 const uint32_t sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 24, 32, 64 };
msarett6efbe052015-09-11 09:01:16 -0700727
msaretta5783ae2015-09-08 15:35:32 -0700728 const BRDSrc::Mode modes[] = {
msarett26ad17b2015-10-22 07:29:19 -0700729 BRDSrc::kFullImage_Mode,
730 BRDSrc::kDivisor_Mode,
msaretta5783ae2015-09-08 15:35:32 -0700731 };
732
msarettd1227a72016-05-18 06:23:57 -0700733 for (uint32_t sampleSize : sampleSizes) {
scroggo24a9bd72016-05-20 06:02:42 -0700734 for (BRDSrc::Mode mode : modes) {
735 push_brd_src(path, CodecSrc::kGetFromCanvas_DstColorType, mode, sampleSize);
msaretta5783ae2015-09-08 15:35:32 -0700736 }
737 }
738}
739
740static bool brd_supported(const char* ext) {
msarett8c8f22a2015-04-01 06:58:48 -0700741 static const char* const exts[] = {
msaretta5783ae2015-09-08 15:35:32 -0700742 "jpg", "jpeg", "png", "webp",
743 "JPG", "JPEG", "PNG", "WEBP",
msarett8c8f22a2015-04-01 06:58:48 -0700744 };
745
746 for (uint32_t i = 0; i < SK_ARRAY_COUNT(exts); i++) {
747 if (0 == strcmp(exts[i], ext)) {
748 return true;
749 }
750 }
751 return false;
scroggo9b77ddd2015-03-19 06:03:39 -0700752}
753
fmalitaa2b9fdf2016-08-03 19:53:36 -0700754template <typename T>
755void gather_file_srcs(const SkCommandLineFlags::StringArray& flags, const char* ext) {
756 for (int i = 0; i < flags.count(); i++) {
757 const char* path = flags[i];
758 if (sk_isdir(path)) {
759 SkOSFile::Iter it(path, ext);
760 for (SkString file; it.next(&file); ) {
761 push_src(ext, "", new T(SkOSPath::Join(path, file.c_str())));
762 }
763 } else {
764 push_src(ext, "", new T(path));
765 }
766 }
767}
768
scroggo86737142016-02-03 12:19:11 -0800769static bool gather_srcs() {
mtklein748ca3b2015-01-15 10:56:12 -0800770 for (const skiagm::GMRegistry* r = skiagm::GMRegistry::Head(); r; r = r->next()) {
djsollen54416de2015-04-03 07:24:48 -0700771 push_src("gm", "", new GMSrc(r->factory()));
mtklein748ca3b2015-01-15 10:56:12 -0800772 }
scroggo86737142016-02-03 12:19:11 -0800773
fmalitaa2b9fdf2016-08-03 19:53:36 -0700774 gather_file_srcs<SKPSrc>(FLAGS_skps, "skp");
775 gather_file_srcs<MSKPSrc>(FLAGS_mskps, "mskp");
776#if defined(SK_XML)
777 gather_file_srcs<SVGSrc>(FLAGS_svgs, "svg");
778#endif
halcanary45420a92016-06-02 12:41:14 -0700779
scroggo86737142016-02-03 12:19:11 -0800780 SkTArray<SkString> images;
msarett69deca82016-04-29 09:38:40 -0700781 if (!CollectImages(FLAGS_images, &images)) {
scroggo86737142016-02-03 12:19:11 -0800782 return false;
783 }
784
785 for (auto image : images) {
786 push_codec_srcs(image);
scroggoe4499842016-02-25 11:03:47 -0800787 if (FLAGS_simpleCodec) {
788 continue;
789 }
790
mtklein21eaf3b2016-02-08 12:39:59 -0800791 const char* ext = strrchr(image.c_str(), '.');
792 if (ext && brd_supported(ext+1)) {
scroggo86737142016-02-03 12:19:11 -0800793 push_brd_srcs(image);
mtklein709d2c32015-01-15 08:30:25 -0800794 }
mtklein709d2c32015-01-15 08:30:25 -0800795 }
scroggo86737142016-02-03 12:19:11 -0800796
msarett69deca82016-04-29 09:38:40 -0700797 SkTArray<SkString> colorImages;
798 if (!CollectImages(FLAGS_colorImages, &colorImages)) {
799 return false;
800 }
801
802 for (auto colorImage : colorImages) {
msarett9ce3a542016-07-15 13:54:38 -0700803 ColorCodecSrc* src = new ColorCodecSrc(colorImage, ColorCodecSrc::kBaseline_Mode,
804 kN32_SkColorType);
msarettb8d1aac2016-08-04 12:22:06 -0700805 push_src("colorImage", "color_codec_baseline", src);
msarett888dc162016-05-23 10:21:17 -0700806
msarett9ce3a542016-07-15 13:54:38 -0700807 src = new ColorCodecSrc(colorImage, ColorCodecSrc::kDst_HPZR30w_Mode, kN32_SkColorType);
msarettb8d1aac2016-08-04 12:22:06 -0700808 push_src("colorImage", "color_codec_HPZR30w", src);
msarett9ce3a542016-07-15 13:54:38 -0700809 // TODO (msarett):
810 // Should we test this Dst in F16 mode (even though the Dst gamma is 2.2 instead of sRGB)?
msarett9876ac52016-06-01 14:47:18 -0700811
msarett9ce3a542016-07-15 13:54:38 -0700812 src = new ColorCodecSrc(colorImage, ColorCodecSrc::kDst_sRGB_Mode, kN32_SkColorType);
msarettb8d1aac2016-08-04 12:22:06 -0700813 push_src("colorImage", "color_codec_sRGB_kN32", src);
msarett9ce3a542016-07-15 13:54:38 -0700814 src = new ColorCodecSrc(colorImage, ColorCodecSrc::kDst_sRGB_Mode, kRGBA_F16_SkColorType);
msarettb8d1aac2016-08-04 12:22:06 -0700815 push_src("colorImage", "color_codec_sRGB_kF16", src);
msarett69deca82016-04-29 09:38:40 -0700816 }
817
scroggo86737142016-02-03 12:19:11 -0800818 return true;
mtklein709d2c32015-01-15 08:30:25 -0800819}
820
kkinnunen3e980c32015-12-23 01:33:00 -0800821static void push_sink(const SkCommandLineConfig& config, Sink* s) {
Ben Wagner145dbcd2016-11-03 14:40:50 -0400822 std::unique_ptr<Sink> sink(s);
kkinnunen3e980c32015-12-23 01:33:00 -0800823
mtkleine0effd62015-07-29 06:37:28 -0700824 // Try a simple Src as a canary. If it fails, skip this sink.
mtklein748ca3b2015-01-15 10:56:12 -0800825 struct : public Src {
mtkleine0effd62015-07-29 06:37:28 -0700826 Error draw(SkCanvas* c) const override {
827 c->drawRect(SkRect::MakeWH(1,1), SkPaint());
828 return "";
829 }
mtklein36352bf2015-03-25 18:17:31 -0700830 SkISize size() const override { return SkISize::Make(16, 16); }
mtkleine0effd62015-07-29 06:37:28 -0700831 Name name() const override { return "justOneRect"; }
832 } justOneRect;
mtklein114c3cd2015-01-15 10:15:02 -0800833
mtklein748ca3b2015-01-15 10:56:12 -0800834 SkBitmap bitmap;
835 SkDynamicMemoryWStream stream;
mtkleinb9eb4ac2015-02-02 18:26:03 -0800836 SkString log;
mtkleine0effd62015-07-29 06:37:28 -0700837 Error err = sink->draw(justOneRect, &bitmap, &stream, &log);
mtklein4089ef72015-03-05 08:40:28 -0800838 if (err.isFatal()) {
mtkleinc41fd922016-03-08 09:01:39 -0800839 info("Could not run %s: %s\n", config.getTag().c_str(), err.c_str());
mtklein05641a52015-04-21 10:49:13 -0700840 exit(1);
mtklein114c3cd2015-01-15 10:15:02 -0800841 }
842
mtkleine0effd62015-07-29 06:37:28 -0700843 TaggedSink& ts = gSinks.push_back();
mtklein18300a32016-03-16 13:53:35 -0700844 ts.reset(sink.release());
kkinnunen3e980c32015-12-23 01:33:00 -0800845 ts.tag = config.getTag();
mtklein748ca3b2015-01-15 10:56:12 -0800846}
847
848static bool gpu_supported() {
849#if SK_SUPPORT_GPU
850 return FLAGS_gpu;
851#else
852 return false;
853#endif
854}
kkinnunen9ebc3f02015-12-21 23:48:13 -0800855
csmartdalton008b9d82017-02-22 12:00:42 -0700856static Sink* create_sink(const GrContextOptions& grCtxOptions, const SkCommandLineConfig* config) {
kkinnunen3e980c32015-12-23 01:33:00 -0800857#if SK_SUPPORT_GPU
858 if (gpu_supported()) {
859 if (const SkCommandLineConfigGpu* gpuConfig = config->asConfigGpu()) {
bsalomon85b4b532016-04-05 11:06:27 -0700860 GrContextFactory::ContextType contextType = gpuConfig->getContextType();
csmartdaltone812d492017-02-21 12:36:05 -0700861 GrContextFactory::ContextOverrides contextOverrides = gpuConfig->getContextOverrides();
csmartdalton008b9d82017-02-22 12:00:42 -0700862 GrContextFactory testFactory(grCtxOptions);
csmartdaltone812d492017-02-21 12:36:05 -0700863 if (!testFactory.get(contextType, contextOverrides)) {
mtkleinc41fd922016-03-08 09:01:39 -0800864 info("WARNING: can not create GPU context for config '%s'. "
865 "GM tests will be skipped.\n", gpuConfig->getTag().c_str());
kkinnunen3e980c32015-12-23 01:33:00 -0800866 return nullptr;
867 }
csmartdaltone812d492017-02-21 12:36:05 -0700868 return new GPUSink(contextType, contextOverrides, gpuConfig->getSamples(),
brianosmand93c1202016-03-10 07:49:08 -0800869 gpuConfig->getUseDIText(), gpuConfig->getColorType(),
brianosmanb109b8c2016-06-16 13:03:24 -0700870 sk_ref_sp(gpuConfig->getColorSpace()), FLAGS_gpu_threading);
kkinnunen3e980c32015-12-23 01:33:00 -0800871 }
872 }
873#endif
874
875#define SINK(t, sink, ...) if (config->getBackend().equals(t)) { return new sink(__VA_ARGS__); }
876
mtklein748ca3b2015-01-15 10:56:12 -0800877 if (FLAGS_cpu) {
Matt Sarett77a7a1b2017-02-07 13:56:11 -0500878 auto srgbColorSpace = SkColorSpace::MakeSRGB();
879 auto srgbLinearColorSpace = SkColorSpace::MakeSRGBLinear();
brianosmanb109b8c2016-06-16 13:03:24 -0700880
Matt Sarettd2228302017-03-02 08:53:46 -0500881 SINK("565", RasterSink, kRGB_565_SkColorType);
882 SINK("8888", RasterSink, kN32_SkColorType);
883 SINK("srgb", RasterSink, kN32_SkColorType, srgbColorSpace);
Matt Sarettd2228302017-03-02 08:53:46 -0500884 SINK("f16", RasterSink, kRGBA_F16_SkColorType, srgbLinearColorSpace);
885 SINK("pdf", PDFSink);
886 SINK("skp", SKPSink);
887 SINK("pipe", PipeSink);
888 SINK("svg", SVGSink);
889 SINK("null", NullSink);
890 SINK("xps", XPSSink);
891 SINK("pdfa", PDFSink, true);
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
csmartdalton008b9d82017-02-22 12:00:42 -0700952static bool gather_sinks(const GrContextOptions& grCtxOptions) {
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.
983 // Otherwise, make sure that at least one sink was constructed correctly. This catches
984 // the case of bots without a GPU being assigned GPU configs.
985 return (configs.count() == 0) || (gSinks.count() > 0);
mtklein114c3cd2015-01-15 10:15:02 -0800986}
mtklein709d2c32015-01-15 08:30:25 -0800987
mtkleina5114d72015-08-24 13:27:01 -0700988static bool dump_png(SkBitmap bitmap, const char* path, const char* md5) {
Mike Klein13b6afd2017-06-12 12:45:41 -0400989 SkPixmap pm;
990 if (!bitmap.peekPixels(&pm)) {
991 return false; // Ought to never happen... we're already read-back at this point.
mtkleina5114d72015-08-24 13:27:01 -0700992 }
Mike Klein13b6afd2017-06-12 12:45:41 -0400993 SkFILEWStream dst{path};
mtkleina5114d72015-08-24 13:27:01 -0700994
mtkleind69ece62015-09-10 10:37:44 -0700995 SkString description;
996 description.append("Key: ");
997 for (int i = 0; i < FLAGS_key.count(); i++) {
998 description.appendf("%s ", FLAGS_key[i]);
999 }
1000 description.append("Properties: ");
1001 for (int i = 0; i < FLAGS_properties.count(); i++) {
1002 description.appendf("%s ", FLAGS_properties[i]);
1003 }
1004 description.appendf("MD5: %s", md5);
1005
Mike Klein13b6afd2017-06-12 12:45:41 -04001006 const char* comments[] = {
1007 "Author", "DM dump_png()",
1008 "Description", description.c_str(),
1009 };
1010 size_t lengths[] = {
1011 strlen(comments[0])+1, strlen(comments[1])+1,
1012 strlen(comments[2])+1, strlen(comments[3])+1,
1013 };
mtkleina5114d72015-08-24 13:27:01 -07001014
Mike Klein13b6afd2017-06-12 12:45:41 -04001015 SkPngEncoder::Options options;
1016 options.fComments = SkDataTable::MakeCopyArrays((const void**)comments, lengths, 4);
1017 options.fFilterFlags = SkPngEncoder::FilterFlag::kNone;
1018 options.fZLibLevel = 1;
1019 options.fUnpremulBehavior = pm.colorSpace() ? SkTransferFunctionBehavior::kRespect
1020 : SkTransferFunctionBehavior::kIgnore;
1021 return SkPngEncoder::Encode(&dst, pm, options);
mtkleina5114d72015-08-24 13:27:01 -07001022}
1023
mtkleina2ef6422015-01-15 13:44:22 -08001024static bool match(const char* needle, const char* haystack) {
halcanary96fcdcc2015-08-27 07:41:13 -07001025 return 0 == strcmp("_", needle) || nullptr != strstr(haystack, needle);
mtkleina2ef6422015-01-15 13:44:22 -08001026}
1027
mtklein3eed7dd2016-02-24 19:07:07 -08001028static bool is_blacklisted(const char* sink, const char* src,
1029 const char* srcOptions, const char* name) {
mtklein0d243ff2015-04-03 07:51:00 -07001030 for (int i = 0; i < FLAGS_blacklist.count() - 3; i += 4) {
mtkleina2ef6422015-01-15 13:44:22 -08001031 if (match(FLAGS_blacklist[i+0], sink) &&
djsollen54416de2015-04-03 07:24:48 -07001032 match(FLAGS_blacklist[i+1], src) &&
1033 match(FLAGS_blacklist[i+2], srcOptions) &&
1034 match(FLAGS_blacklist[i+3], name)) {
mtklein3eed7dd2016-02-24 19:07:07 -08001035 return true;
mtkleina2ef6422015-01-15 13:44:22 -08001036 }
1037 }
mtklein3eed7dd2016-02-24 19:07:07 -08001038 return false;
mtkleina2ef6422015-01-15 13:44:22 -08001039}
1040
mtkleincd50bca2016-01-05 06:20:20 -08001041// Even when a Task Sink reports to be non-threadsafe (e.g. GPU), we know things like
1042// .png encoding are definitely thread safe. This lets us offload that work to CPU threads.
1043static SkTaskGroup gDefinitelyThreadSafeWork;
1044
mtklein748ca3b2015-01-15 10:56:12 -08001045// The finest-grained unit of work we can run: draw a single Src into a single Sink,
1046// report any errors, and perhaps write out the output: a .png of the bitmap, or a raw stream.
1047struct Task {
mtkleine0effd62015-07-29 06:37:28 -07001048 Task(const TaggedSrc& src, const TaggedSink& sink) : src(src), sink(sink) {}
1049 const TaggedSrc& src;
1050 const TaggedSink& sink;
mtklein748ca3b2015-01-15 10:56:12 -08001051
mtklein21eaf3b2016-02-08 12:39:59 -08001052 static void Run(const Task& task) {
1053 SkString name = task.src->name();
mtkleine0effd62015-07-29 06:37:28 -07001054
mtkleinb9eb4ac2015-02-02 18:26:03 -08001055 SkString log;
mtklein3eed7dd2016-02-24 19:07:07 -08001056 if (!FLAGS_dryRun) {
mtklein748ca3b2015-01-15 10:56:12 -08001057 SkBitmap bitmap;
1058 SkDynamicMemoryWStream stream;
mtklein3eed7dd2016-02-24 19:07:07 -08001059 start(task.sink.tag.c_str(), task.src.tag.c_str(),
1060 task.src.options.c_str(), name.c_str());
mtklein21eaf3b2016-02-08 12:39:59 -08001061 Error err = task.sink->draw(*task.src, &bitmap, &stream, &log);
mtkleinb3b13b72016-03-07 13:20:52 -08001062 if (!log.isEmpty()) {
mtkleinc41fd922016-03-08 09:01:39 -08001063 info("%s %s %s %s:\n%s\n", task.sink.tag.c_str()
1064 , task.src.tag.c_str()
1065 , task.src.options.c_str()
1066 , name.c_str()
1067 , log.c_str());
mtkleinb3b13b72016-03-07 13:20:52 -08001068 }
mtklein748ca3b2015-01-15 10:56:12 -08001069 if (!err.isEmpty()) {
mtklein4089ef72015-03-05 08:40:28 -08001070 if (err.isFatal()) {
djsollen54416de2015-04-03 07:24:48 -07001071 fail(SkStringPrintf("%s %s %s %s: %s",
mtklein21eaf3b2016-02-08 12:39:59 -08001072 task.sink.tag.c_str(),
1073 task.src.tag.c_str(),
1074 task.src.options.c_str(),
mtklein4089ef72015-03-05 08:40:28 -08001075 name.c_str(),
1076 err.c_str()));
mtkleinb37cb412015-03-18 05:27:14 -07001077 } else {
mtklein3eed7dd2016-02-24 19:07:07 -08001078 done(task.sink.tag.c_str(), task.src.tag.c_str(),
1079 task.src.options.c_str(), name.c_str());
mtkleinba6ada72016-01-21 09:39:35 -08001080 return;
mtklein4089ef72015-03-05 08:40:28 -08001081 }
mtklein748ca3b2015-01-15 10:56:12 -08001082 }
mtklein62bd1a62015-01-27 14:46:26 -08001083
mtkleincd50bca2016-01-05 06:20:20 -08001084 // We're likely switching threads here, so we must capture by value, [=] or [foo,bar].
Hal Canary0b833192017-03-14 14:35:02 -04001085 SkStreamAsset* data = stream.detachAsStream().release();
mtkleincd50bca2016-01-05 06:20:20 -08001086 gDefinitelyThreadSafeWork.add([task,name,bitmap,data]{
Ben Wagner145dbcd2016-11-03 14:40:50 -04001087 std::unique_ptr<SkStreamAsset> ownedData(data);
mtkleincd50bca2016-01-05 06:20:20 -08001088
mtkleincd50bca2016-01-05 06:20:20 -08001089 SkString md5;
1090 if (!FLAGS_writePath.isEmpty() || !FLAGS_readPath.isEmpty()) {
1091 SkMD5 hash;
1092 if (data->getLength()) {
1093 hash.writeStream(data, data->getLength());
1094 data->rewind();
mtklein38408462015-07-08 07:25:27 -07001095 } else {
mtkleincd50bca2016-01-05 06:20:20 -08001096 // If we're BGRA (Linux, Windows), swizzle over to RGBA (Mac, Android).
1097 // This helps eliminate multiple 0-pixel-diff hashes on gold.skia.org.
1098 // (Android's general slow speed breaks the tie arbitrarily in RGBA's favor.)
1099 // We might consider promoting 565 to RGBA too.
1100 if (bitmap.colorType() == kBGRA_8888_SkColorType) {
1101 SkBitmap swizzle;
Matt Sarett68b8e3d2017-04-28 11:15:22 -04001102 SkAssertResult(sk_tool_utils::copy_to(&swizzle, kRGBA_8888_SkColorType,
1103 bitmap));
mtkleincd50bca2016-01-05 06:20:20 -08001104 hash.write(swizzle.getPixels(), swizzle.getSize());
1105 } else {
1106 hash.write(bitmap.getPixels(), bitmap.getSize());
1107 }
1108 }
1109 SkMD5::Digest digest;
1110 hash.finish(digest);
1111 for (int i = 0; i < 16; i++) {
1112 md5.appendf("%02x", digest.data[i]);
mtklein38408462015-07-08 07:25:27 -07001113 }
mtklein62bd1a62015-01-27 14:46:26 -08001114 }
mtklein62bd1a62015-01-27 14:46:26 -08001115
mtkleincd50bca2016-01-05 06:20:20 -08001116 if (!FLAGS_readPath.isEmpty() &&
mtklein3eed7dd2016-02-24 19:07:07 -08001117 !gGold.contains(Gold(task.sink.tag, task.src.tag,
1118 task.src.options, name, md5))) {
mtkleincd50bca2016-01-05 06:20:20 -08001119 fail(SkStringPrintf("%s not found for %s %s %s %s in %s",
1120 md5.c_str(),
mtklein21eaf3b2016-02-08 12:39:59 -08001121 task.sink.tag.c_str(),
1122 task.src.tag.c_str(),
1123 task.src.options.c_str(),
mtkleincd50bca2016-01-05 06:20:20 -08001124 name.c_str(),
1125 FLAGS_readPath[0]));
mtklein748ca3b2015-01-15 10:56:12 -08001126 }
mtkleincd50bca2016-01-05 06:20:20 -08001127
1128 if (!FLAGS_writePath.isEmpty()) {
mtklein21eaf3b2016-02-08 12:39:59 -08001129 const char* ext = task.sink->fileExtension();
mtkleincd50bca2016-01-05 06:20:20 -08001130 if (data->getLength()) {
mtklein21eaf3b2016-02-08 12:39:59 -08001131 WriteToDisk(task, md5, ext, data, data->getLength(), nullptr);
mtkleincd50bca2016-01-05 06:20:20 -08001132 SkASSERT(bitmap.drawsNothing());
1133 } else if (!bitmap.drawsNothing()) {
mtklein21eaf3b2016-02-08 12:39:59 -08001134 WriteToDisk(task, md5, ext, nullptr, 0, &bitmap);
mtkleincd50bca2016-01-05 06:20:20 -08001135 }
1136 }
1137 });
mtklein748ca3b2015-01-15 10:56:12 -08001138 }
mtklein3eed7dd2016-02-24 19:07:07 -08001139 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 -08001140 }
1141
1142 static void WriteToDisk(const Task& task,
mtklein62bd1a62015-01-27 14:46:26 -08001143 SkString md5,
1144 const char* ext,
mtklein748ca3b2015-01-15 10:56:12 -08001145 SkStream* data, size_t len,
mtklein62bd1a62015-01-27 14:46:26 -08001146 const SkBitmap* bitmap) {
mtklein409d4702016-02-29 07:38:01 -08001147 bool gammaCorrect = false;
1148 if (bitmap) {
Brian Osman7039f742016-11-01 15:56:16 -04001149 gammaCorrect = SkToBool(bitmap->info().colorSpace());
mtklein409d4702016-02-29 07:38:01 -08001150 }
1151
mtklein748ca3b2015-01-15 10:56:12 -08001152 JsonWriter::BitmapResult result;
djsollen54416de2015-04-03 07:24:48 -07001153 result.name = task.src->name();
mtklein3eed7dd2016-02-24 19:07:07 -08001154 result.config = task.sink.tag;
djsollen54416de2015-04-03 07:24:48 -07001155 result.sourceType = task.src.tag;
1156 result.sourceOptions = task.src.options;
1157 result.ext = ext;
mtklein409d4702016-02-29 07:38:01 -08001158 result.gammaCorrect = gammaCorrect;
djsollen54416de2015-04-03 07:24:48 -07001159 result.md5 = md5;
mtklein748ca3b2015-01-15 10:56:12 -08001160 JsonWriter::AddBitmapResult(result);
1161
mtkleinb0531a72015-04-07 13:38:48 -07001162 // If an MD5 is uninteresting, we want it noted in the JSON file,
1163 // but don't want to dump it out as a .png (or whatever ext is).
1164 if (gUninterestingHashes.contains(md5)) {
1165 return;
1166 }
1167
mtklein748ca3b2015-01-15 10:56:12 -08001168 const char* dir = FLAGS_writePath[0];
1169 if (0 == strcmp(dir, "@")) { // Needed for iOS.
1170 dir = FLAGS_resourcePath[0];
1171 }
1172 sk_mkdir(dir);
1173
1174 SkString path;
1175 if (FLAGS_nameByHash) {
1176 path = SkOSPath::Join(dir, result.md5.c_str());
1177 path.append(".");
1178 path.append(ext);
1179 if (sk_exists(path.c_str())) {
1180 return; // Content-addressed. If it exists already, we're done.
1181 }
1182 } else {
kkinnunen3e980c32015-12-23 01:33:00 -08001183 path = SkOSPath::Join(dir, task.sink.tag.c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001184 sk_mkdir(path.c_str());
msarett9e707a02015-09-01 14:57:57 -07001185 path = SkOSPath::Join(path.c_str(), task.src.tag.c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001186 sk_mkdir(path.c_str());
msarett9e707a02015-09-01 14:57:57 -07001187 if (strcmp(task.src.options.c_str(), "") != 0) {
1188 path = SkOSPath::Join(path.c_str(), task.src.options.c_str());
djsollen54416de2015-04-03 07:24:48 -07001189 sk_mkdir(path.c_str());
1190 }
mtklein748ca3b2015-01-15 10:56:12 -08001191 path = SkOSPath::Join(path.c_str(), task.src->name().c_str());
1192 path.append(".");
1193 path.append(ext);
1194 }
1195
mtklein748ca3b2015-01-15 10:56:12 -08001196 if (bitmap) {
mtkleina5114d72015-08-24 13:27:01 -07001197 if (!dump_png(*bitmap, path.c_str(), result.md5.c_str())) {
mtklein748ca3b2015-01-15 10:56:12 -08001198 fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str()));
1199 return;
1200 }
1201 } else {
mtkleina5114d72015-08-24 13:27:01 -07001202 SkFILEWStream file(path.c_str());
1203 if (!file.isValid()) {
1204 fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str()));
1205 return;
1206 }
mtklein748ca3b2015-01-15 10:56:12 -08001207 if (!file.writeStream(data, len)) {
1208 fail(SkStringPrintf("Can't write to %s.\n", path.c_str()));
1209 return;
1210 }
1211 }
1212 }
1213};
1214
mtklein748ca3b2015-01-15 10:56:12 -08001215/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1216
1217// Unit tests don't fit so well into the Src/Sink model, so we give them special treatment.
1218
mtklein21eaf3b2016-02-08 12:39:59 -08001219static SkTDArray<skiatest::Test> gParallelTests, gSerialTests;
mtklein748ca3b2015-01-15 10:56:12 -08001220
1221static void gather_tests() {
mtklein6c5fed22015-01-20 13:47:23 -08001222 if (!FLAGS_src.contains("tests")) {
mtklein748ca3b2015-01-15 10:56:12 -08001223 return;
1224 }
mtklein6393c062015-04-27 08:45:01 -07001225 for (const skiatest::TestRegistry* r = skiatest::TestRegistry::Head(); r; r = r->next()) {
1226 if (!in_shard()) {
1227 continue;
1228 }
halcanary87f3ba42015-01-20 09:30:20 -08001229 // Despite its name, factory() is returning a reference to
1230 // link-time static const POD data.
1231 const skiatest::Test& test = r->factory();
1232 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, test.name)) {
mtklein748ca3b2015-01-15 10:56:12 -08001233 continue;
1234 }
halcanary87f3ba42015-01-20 09:30:20 -08001235 if (test.needsGpu && gpu_supported()) {
mtklein21eaf3b2016-02-08 12:39:59 -08001236 (FLAGS_gpu_threading ? gParallelTests : gSerialTests).push(test);
halcanary87f3ba42015-01-20 09:30:20 -08001237 } else if (!test.needsGpu && FLAGS_cpu) {
mtklein21eaf3b2016-02-08 12:39:59 -08001238 gParallelTests.push(test);
mtklein82d28432015-01-15 12:46:02 -08001239 }
mtklein748ca3b2015-01-15 10:56:12 -08001240 }
1241}
1242
csmartdalton008b9d82017-02-22 12:00:42 -07001243static void run_test(skiatest::Test test, const GrContextOptions& grCtxOptions) {
halcanary87f3ba42015-01-20 09:30:20 -08001244 struct : public skiatest::Reporter {
mtklein36352bf2015-03-25 18:17:31 -07001245 void reportFailed(const skiatest::Failure& failure) override {
halcanary87f3ba42015-01-20 09:30:20 -08001246 fail(failure.toString());
1247 JsonWriter::AddTestFailure(failure);
1248 }
mtklein36352bf2015-03-25 18:17:31 -07001249 bool allowExtendedTest() const override {
halcanary87f3ba42015-01-20 09:30:20 -08001250 return FLAGS_pathOpsExtended;
1251 }
mtklein36352bf2015-03-25 18:17:31 -07001252 bool verbose() const override { return FLAGS_veryVerbose; }
halcanary87f3ba42015-01-20 09:30:20 -08001253 } reporter;
djsollen824996a2015-06-12 12:06:22 -07001254
mtklein3eed7dd2016-02-24 19:07:07 -08001255 if (!FLAGS_dryRun && !is_blacklisted("_", "tests", "_", test.name)) {
mtklein21eaf3b2016-02-08 12:39:59 -08001256 start("unit", "test", "", test.name);
csmartdalton008b9d82017-02-22 12:00:42 -07001257 GrContextFactory factory(grCtxOptions);
mtklein21eaf3b2016-02-08 12:39:59 -08001258 test.proc(&reporter, &factory);
mtklein748ca3b2015-01-15 10:56:12 -08001259 }
mtklein3eed7dd2016-02-24 19:07:07 -08001260 done("unit", "test", "", test.name);
mtklein748ca3b2015-01-15 10:56:12 -08001261}
1262
1263/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1264
mtkleinafae30a2016-02-24 12:28:32 -08001265DEFINE_int32(status_sec, 15, "Print status this often (and if we crash).");
1266
Mike Klein2048c3e2017-05-26 15:19:56 -04001267static std::atomic<bool> gStopStatusThread{false};
1268
mtkleinafae30a2016-02-24 12:28:32 -08001269SkThread* start_status_thread() {
1270 auto thread = new SkThread([] (void*) {
Mike Klein2048c3e2017-05-26 15:19:56 -04001271 while (!gStopStatusThread.load()) {
mtkleinafae30a2016-02-24 12:28:32 -08001272 print_status();
1273 #if defined(SK_BUILD_FOR_WIN)
1274 Sleep(FLAGS_status_sec * 1000);
1275 #else
1276 sleep(FLAGS_status_sec);
1277 #endif
mtklein2e1c47e2015-03-12 07:16:56 -07001278 }
mtkleinafae30a2016-02-24 12:28:32 -08001279 });
1280 thread->start();
1281 return thread;
mtkleinde6fc2b2015-03-12 06:28:54 -07001282}
1283
caryclark83ca6282015-06-10 09:31:09 -07001284#define PORTABLE_FONT_PREFIX "Toy Liberation "
1285
mbocee6a9912016-05-31 11:42:36 -07001286static sk_sp<SkTypeface> create_from_name(const char familyName[], SkFontStyle style) {
caryclark83ca6282015-06-10 09:31:09 -07001287 if (familyName && strlen(familyName) > sizeof(PORTABLE_FONT_PREFIX)
1288 && !strncmp(familyName, PORTABLE_FONT_PREFIX, sizeof(PORTABLE_FONT_PREFIX) - 1)) {
caryclark1818acb2015-07-24 12:09:25 -07001289 return sk_tool_utils::create_portable_typeface(familyName, style);
caryclark83ca6282015-06-10 09:31:09 -07001290 }
halcanary96fcdcc2015-08-27 07:41:13 -07001291 return nullptr;
caryclark83ca6282015-06-10 09:31:09 -07001292}
1293
1294#undef PORTABLE_FONT_PREFIX
1295
mbocee6a9912016-05-31 11:42:36 -07001296extern sk_sp<SkTypeface> (*gCreateTypefaceDelegate)(const char [], SkFontStyle );
caryclark83ca6282015-06-10 09:31:09 -07001297
Mike Kleinbe28ee22017-02-06 12:46:20 -05001298int main(int argc, char** argv) {
1299 SkCommandLineFlags::Parse(argc, argv);
Mike Kleinadacaef2017-02-06 09:26:14 -05001300#if defined(SK_BUILD_FOR_IOS)
1301 cd_Documents();
1302#endif
bsalomon71de3532016-04-26 14:27:21 -07001303 setbuf(stdout, nullptr);
mtklein246ba3a2016-02-23 10:39:36 -08001304 setup_crash_handler();
mtkleinafae30a2016-02-24 12:28:32 -08001305
Yuqian Liba62b4a2016-12-14 13:46:53 -05001306 gSkUseAnalyticAA = FLAGS_analyticAA;
liyuqian38911a72016-10-04 11:23:22 -07001307
Yuqian Li550148b2017-01-13 10:13:13 -05001308 if (FLAGS_forceAnalyticAA) {
1309 gSkForceAnalyticAA = true;
1310 }
1311
mtkleina483da32016-03-17 12:53:36 -07001312 if (FLAGS_verbose) {
1313 gVLog = stderr;
1314 } else if (!FLAGS_writePath.isEmpty()) {
mtklein51c8cfc2016-03-11 12:59:09 -08001315 sk_mkdir(FLAGS_writePath[0]);
mtkleina1ce2162016-07-22 12:23:46 -07001316 gVLog = fopen(SkOSPath::Join(FLAGS_writePath[0], "verbose.log").c_str(), "w");
mtkleinc41fd922016-03-08 09:01:39 -08001317 }
1318
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 }
csmartdalton008b9d82017-02-22 12:00:42 -07001342 if (!gather_sinks(grCtxOptions)) {
brianosman05c987c2016-05-09 13:42:16 -07001343 return 1;
1344 }
mtklein748ca3b2015-01-15 10:56:12 -08001345 gather_tests();
mtklein21eaf3b2016-02-08 12:39:59 -08001346 gPending = gSrcs.count() * gSinks.count() + gParallelTests.count() + gSerialTests.count();
mtkleinc41fd922016-03-08 09:01:39 -08001347 info("%d srcs * %d sinks + %d tests == %d tasks",
1348 gSrcs.count(), gSinks.count(), gParallelTests.count() + gSerialTests.count(), gPending);
Ben Wagner145dbcd2016-11-03 14:40:50 -04001349 std::unique_ptr<SkThread> statusThread(start_status_thread());
mtklein748ca3b2015-01-15 10:56:12 -08001350
mtklein21eaf3b2016-02-08 12:39:59 -08001351 // Kick off as much parallel work as we can, making note of any serial work we'll need to do.
1352 SkTaskGroup parallel;
1353 SkTArray<Task> serial;
1354
1355 for (auto& sink : gSinks)
1356 for (auto& src : gSrcs) {
mtklein3eed7dd2016-02-24 19:07:07 -08001357 if (src->veto(sink->flags()) ||
1358 is_blacklisted(sink.tag.c_str(), src.tag.c_str(),
1359 src.options.c_str(), src->name().c_str())) {
mtkleinf10637f2016-06-10 13:56:35 -07001360 SkAutoMutexAcquire lock(gMutex);
mtklein3eed7dd2016-02-24 19:07:07 -08001361 gPending--;
1362 continue;
1363 }
1364
mtklein21eaf3b2016-02-08 12:39:59 -08001365 Task task(src, sink);
1366 if (src->serial() || sink->serial()) {
1367 serial.push_back(task);
1368 } else {
1369 parallel.add([task] { Task::Run(task); });
mtklein748ca3b2015-01-15 10:56:12 -08001370 }
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001371 }
mtklein21eaf3b2016-02-08 12:39:59 -08001372 for (auto test : gParallelTests) {
csmartdalton008b9d82017-02-22 12:00:42 -07001373 parallel.add([test, grCtxOptions] { run_test(test, grCtxOptions); });
mtklein55e88b22015-01-21 15:50:13 -08001374 }
mtklein21eaf3b2016-02-08 12:39:59 -08001375
1376 // With the parallel work running, run serial tasks and tests here on main thread.
1377 for (auto task : serial) { Task::Run(task); }
csmartdalton008b9d82017-02-22 12:00:42 -07001378 for (auto test : gSerialTests) { run_test(test, grCtxOptions); }
mtklein21eaf3b2016-02-08 12:39:59 -08001379
1380 // Wait for any remaining parallel work to complete (including any spun off of serial tasks).
1381 parallel.wait();
mtkleincd50bca2016-01-05 06:20:20 -08001382 gDefinitelyThreadSafeWork.wait();
1383
mtkleinda884c42016-02-24 18:00:23 -08001384 // We'd better have run everything.
1385 SkASSERT(gPending == 0);
mtkleine027f172016-02-26 15:53:06 -08001386 // Make sure we've flushed all our results to disk.
1387 JsonWriter::DumpJson();
mtkleinda884c42016-02-24 18:00:23 -08001388
mtklein748ca3b2015-01-15 10:56:12 -08001389 // At this point we're back in single-threaded land.
caryclarkf53ce802015-06-15 06:48:30 -07001390 sk_tool_utils::release_portable_typefaces();
mtklein@google.comd36522d2013-10-16 13:02:15 +00001391
mtklein748ca3b2015-01-15 10:56:12 -08001392 if (gFailures.count() > 0) {
mtkleinc41fd922016-03-08 09:01:39 -08001393 info("Failures:\n");
mtklein748ca3b2015-01-15 10:56:12 -08001394 for (int i = 0; i < gFailures.count(); i++) {
mtkleinc41fd922016-03-08 09:01:39 -08001395 info("\t%s\n", gFailures[i].c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001396 }
mtkleinc41fd922016-03-08 09:01:39 -08001397 info("%d failures\n", gFailures.count());
mtklein748ca3b2015-01-15 10:56:12 -08001398 return 1;
mtklein114c3cd2015-01-15 10:15:02 -08001399 }
mtkleinafae30a2016-02-24 12:28:32 -08001400
1401#ifdef SK_PDF_IMAGE_STATS
halcanary7a14b312015-10-01 07:28:13 -07001402 SkPDFImageDumpStats();
mtkleinafae30a2016-02-24 12:28:32 -08001403#endif // SK_PDF_IMAGE_STATS
1404
Mike Klein2048c3e2017-05-26 15:19:56 -04001405 // An experiment to work around problems with libmobiledevice driving DM.
1406 // Make sure the status thread has stopped completely before we exit.
1407#if defined(SK_BUILD_FOR_IOS)
1408 gStopStatusThread.store(true);
1409 statusThread->join();
1410#endif
1411
mtkleinafae30a2016-02-24 12:28:32 -08001412 print_status();
Herb Derby5a523fe2017-01-26 16:48:28 -05001413 SkGraphics::PurgeAllCaches();
mtkleinc41fd922016-03-08 09:01:39 -08001414 info("Finished!\n");
mtklein748ca3b2015-01-15 10:56:12 -08001415 return 0;
mtklein@google.comd36522d2013-10-16 13:02:15 +00001416}
jcgregorio3b27ade2014-11-13 08:06:40 -08001417
kkinnunen179a8f52015-11-20 13:32:24 -08001418// TODO: currently many GPU tests are declared outside SK_SUPPORT_GPU guards.
1419// Thus we export the empty RunWithGPUTestContexts when SK_SUPPORT_GPU=0.
1420namespace skiatest {
bsalomon758586c2016-04-06 14:02:39 -07001421
1422#if SK_SUPPORT_GPU
1423bool IsGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
1424 return kOpenGL_GrBackend == GrContextFactory::ContextTypeBackend(type);
1425}
bsalomondc0fcd42016-04-11 14:21:33 -07001426bool IsVulkanContextType(sk_gpu_test::GrContextFactory::ContextType type) {
1427 return kVulkan_GrBackend == GrContextFactory::ContextTypeBackend(type);
1428}
bsalomon758586c2016-04-06 14:02:39 -07001429bool IsRenderingGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
1430 return IsGLContextType(type) && GrContextFactory::IsRenderingContext(type);
1431}
1432bool IsNullGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
1433 return type == GrContextFactory::kNullGL_ContextType;
1434}
Brian Osman287f6512016-12-05 11:35:07 -05001435const char* ContextTypeName(GrContextFactory::ContextType contextType) {
1436 switch (contextType) {
1437 case GrContextFactory::kGL_ContextType:
1438 return "OpenGL";
1439 case GrContextFactory::kGLES_ContextType:
1440 return "OpenGLES";
1441 case GrContextFactory::kANGLE_D3D9_ES2_ContextType:
1442 return "ANGLE D3D9 ES2";
1443 case GrContextFactory::kANGLE_D3D11_ES2_ContextType:
1444 return "ANGLE D3D11 ES2";
1445 case GrContextFactory::kANGLE_D3D11_ES3_ContextType:
1446 return "ANGLE D3D11 ES3";
1447 case GrContextFactory::kANGLE_GL_ES2_ContextType:
1448 return "ANGLE GL ES2";
1449 case GrContextFactory::kANGLE_GL_ES3_ContextType:
1450 return "ANGLE GL ES3";
1451 case GrContextFactory::kCommandBuffer_ContextType:
1452 return "Command Buffer";
1453 case GrContextFactory::kMESA_ContextType:
1454 return "Mesa";
1455 case GrContextFactory::kNullGL_ContextType:
1456 return "Null GL";
1457 case GrContextFactory::kDebugGL_ContextType:
1458 return "Debug GL";
1459 case GrContextFactory::kVulkan_ContextType:
1460 return "Vulkan";
1461 }
1462 SkDEBUGFAIL("Unreachable");
1463 return "Unknown";
1464}
bsalomon758586c2016-04-06 14:02:39 -07001465#else
1466bool IsGLContextType(int) { return false; }
bsalomondc0fcd42016-04-11 14:21:33 -07001467bool IsVulkanContextType(int) { return false; }
bsalomon758586c2016-04-06 14:02:39 -07001468bool IsRenderingGLContextType(int) { return false; }
1469bool IsNullGLContextType(int) { return false; }
1470#endif
1471
1472void RunWithGPUTestContexts(GrContextTestFn* test, GrContextTypeFilterFn* contextTypeFilter,
bsalomonf2f1c172016-04-05 12:59:06 -07001473 Reporter* reporter, GrContextFactory* factory) {
kkinnunen179a8f52015-11-20 13:32:24 -08001474#if SK_SUPPORT_GPU
kkinnunen3e980c32015-12-23 01:33:00 -08001475
Brian Salomon6405e712017-03-20 08:54:16 -04001476#if defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_WIN) || defined(SK_BUILD_FOR_MAC)
1477 static constexpr auto kNativeGLType = GrContextFactory::kGL_ContextType;
1478#else
1479 static constexpr auto kNativeGLType = GrContextFactory::kGLES_ContextType;
1480#endif
1481
bsalomon758586c2016-04-06 14:02:39 -07001482 for (int typeInt = 0; typeInt < GrContextFactory::kContextTypeCnt; ++typeInt) {
1483 GrContextFactory::ContextType contextType = (GrContextFactory::ContextType) typeInt;
Brian Osmanaa2219c2016-12-05 10:12:17 -05001484 // Use "native" instead of explicitly trying OpenGL and OpenGL ES. Do not use GLES on
bsalomon758586c2016-04-06 14:02:39 -07001485 // desktop since tests do not account for not fixing http://skbug.com/2809
1486 if (contextType == GrContextFactory::kGL_ContextType ||
1487 contextType == GrContextFactory::kGLES_ContextType) {
Brian Salomon6405e712017-03-20 08:54:16 -04001488 if (contextType != kNativeGLType) {
bsalomon758586c2016-04-06 14:02:39 -07001489 continue;
1490 }
1491 }
csmartdaltone812d492017-02-21 12:36:05 -07001492 ContextInfo ctxInfo = factory->getContextInfo(contextType,
1493 GrContextFactory::ContextOverrides::kDisableNVPR);
Brian Osmanaa2219c2016-12-05 10:12:17 -05001494 if (contextTypeFilter && !(*contextTypeFilter)(contextType)) {
1495 continue;
1496 }
Brian Osman287f6512016-12-05 11:35:07 -05001497 ReporterContext ctx(reporter, SkString(ContextTypeName(contextType)));
bsalomon8b7451a2016-05-11 06:33:06 -07001498 if (ctxInfo.grContext()) {
bsalomonf2f1c172016-04-05 12:59:06 -07001499 (*test)(reporter, ctxInfo);
kkinnunen5219fd92015-12-10 06:28:13 -08001500 }
bsalomonf2f1c172016-04-05 12:59:06 -07001501 ctxInfo = factory->getContextInfo(contextType,
csmartdaltone812d492017-02-21 12:36:05 -07001502 GrContextFactory::ContextOverrides::kRequireNVPRSupport);
bsalomon8b7451a2016-05-11 06:33:06 -07001503 if (ctxInfo.grContext()) {
bsalomonf2f1c172016-04-05 12:59:06 -07001504 (*test)(reporter, ctxInfo);
kkinnunen179a8f52015-11-20 13:32:24 -08001505 }
1506 }
1507#endif
1508}
kkinnunen179a8f52015-11-20 13:32:24 -08001509} // namespace skiatest