scroggo | 478652e | 2015-03-25 07:11:02 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 8 | #include "CrashHandler.h" |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 9 | #include "DMJsonWriter.h" |
| 10 | #include "DMSrcSink.h" |
tomhudson | eebc39a | 2015-02-23 12:18:05 -0800 | [diff] [blame] | 11 | #include "DMSrcSinkAndroid.h" |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 12 | #include "ProcStats.h" |
halcanary | 7d57124 | 2016-02-24 17:59:16 -0800 | [diff] [blame] | 13 | #include "Resources.h" |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 14 | #include "SkBBHFactory.h" |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 15 | #include "SkChecksum.h" |
scroggo | cc2feb1 | 2015-08-14 08:32:46 -0700 | [diff] [blame] | 16 | #include "SkCodec.h" |
mtklein | 27c3fdd | 2016-02-26 14:43:21 -0800 | [diff] [blame] | 17 | #include "SkColorPriv.h" |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 18 | #include "SkCommonFlags.h" |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 19 | #include "SkCommonFlagsConfig.h" |
brianosman | 3c579dc | 2016-04-19 09:18:11 -0700 | [diff] [blame] | 20 | #include "SkData.h" |
caryclark | 83ca628 | 2015-06-10 09:31:09 -0700 | [diff] [blame] | 21 | #include "SkFontMgr.h" |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 22 | #include "SkGraphics.h" |
mtklein | 27c3fdd | 2016-02-26 14:43:21 -0800 | [diff] [blame] | 23 | #include "SkHalf.h" |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 24 | #include "SkMD5.h" |
mtklein | 1b24933 | 2015-07-07 12:21:21 -0700 | [diff] [blame] | 25 | #include "SkMutex.h" |
mtklein | 1d0f164 | 2014-09-08 08:05:18 -0700 | [diff] [blame] | 26 | #include "SkOSFile.h" |
mtklein | 27c3fdd | 2016-02-26 14:43:21 -0800 | [diff] [blame] | 27 | #include "SkPM4fPriv.h" |
mtklein | 246ba3a | 2016-02-23 10:39:36 -0800 | [diff] [blame] | 28 | #include "SkSpinlock.h" |
mtklein | a82f562 | 2015-02-20 12:30:19 -0800 | [diff] [blame] | 29 | #include "SkTHash.h" |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 30 | #include "SkTaskGroup.h" |
mtklein | de6fc2b | 2015-03-12 06:28:54 -0700 | [diff] [blame] | 31 | #include "SkThreadUtils.h" |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 32 | #include "Test.h" |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 33 | #include "Timer.h" |
brianosman | 3c579dc | 2016-04-19 09:18:11 -0700 | [diff] [blame] | 34 | #include "picture_utils.h" |
caryclark | 83ca628 | 2015-06-10 09:31:09 -0700 | [diff] [blame] | 35 | #include "sk_tool_utils.h" |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 36 | |
halcanary | 7a14b31 | 2015-10-01 07:28:13 -0700 | [diff] [blame] | 37 | #ifdef SK_PDF_IMAGE_STATS |
| 38 | extern void SkPDFImageDumpStats(); |
| 39 | #endif |
| 40 | |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 41 | #include "png.h" |
| 42 | |
bungeman | 60e0fee | 2015-08-26 05:15:46 -0700 | [diff] [blame] | 43 | #include <stdlib.h> |
| 44 | |
scroggo | 27a5834 | 2015-10-28 08:56:41 -0700 | [diff] [blame] | 45 | #ifndef SK_BUILD_FOR_WIN32 |
| 46 | #include <unistd.h> |
| 47 | #endif |
| 48 | |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 49 | DEFINE_string(src, "tests gm skp image", "Source types to test."); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 50 | DEFINE_bool(nameByHash, false, |
| 51 | "If true, write to FLAGS_writePath[0]/<hash>.png instead of " |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 52 | "to FLAGS_writePath[0]/<config>/<sourceType>/<sourceOptions>/<name>.png"); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 53 | DEFINE_bool2(pathOpsExtended, x, false, "Run extended pathOps tests."); |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 54 | DEFINE_string(matrix, "1 0 0 1", |
| 55 | "2x2 scale+skew matrix to apply or upright when using " |
| 56 | "'matrix' or 'upright' in config."); |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 57 | DEFINE_bool(gpu_threading, false, "Allow GPU work to run on multiple threads?"); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 58 | |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 59 | DEFINE_string(blacklist, "", |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 60 | "Space-separated config/src/srcOptions/name quadruples to blacklist. '_' matches anything. E.g. \n" |
| 61 | "'--blacklist gpu skp _ _' will blacklist all SKPs drawn into the gpu config.\n" |
| 62 | "'--blacklist gpu skp _ _ 8888 gm _ aarects' will also blacklist the aarects GM on 8888."); |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 63 | |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 64 | DEFINE_string2(readPath, r, "", "If set check for equality with golden results in this directory."); |
| 65 | |
borenet | 09ed480 | 2015-04-03 14:15:33 -0700 | [diff] [blame] | 66 | DEFINE_string(uninterestingHashesFile, "", |
| 67 | "File containing a list of uninteresting hashes. If a result hashes to something in " |
| 68 | "this list, no image is written for that result."); |
| 69 | |
mtklein | 6393c06 | 2015-04-27 08:45:01 -0700 | [diff] [blame] | 70 | DEFINE_int32(shards, 1, "We're splitting source data into this many shards."); |
| 71 | DEFINE_int32(shard, 0, "Which shard do I run?"); |
scroggo | e449984 | 2016-02-25 11:03:47 -0800 | [diff] [blame] | 72 | DEFINE_bool(simpleCodec, false, "Only decode images to native scale"); |
mtklein | 6393c06 | 2015-04-27 08:45:01 -0700 | [diff] [blame] | 73 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 74 | using namespace DM; |
bsalomon | 3724e57 | 2016-03-30 18:56:19 -0700 | [diff] [blame] | 75 | using sk_gpu_test::GrContextFactory; |
bsalomon | 273c0f5 | 2016-03-31 10:59:06 -0700 | [diff] [blame] | 76 | using sk_gpu_test::GLTestContext; |
bsalomon | f2f1c17 | 2016-04-05 12:59:06 -0700 | [diff] [blame] | 77 | using sk_gpu_test::ContextInfo; |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 78 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 79 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 80 | |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 81 | static const double kStartMs = SkTime::GetMSecs(); |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 82 | |
| 83 | static FILE* gVLog; |
| 84 | |
| 85 | template <typename... Args> |
| 86 | static void vlog(const char* fmt, Args&&... args) { |
| 87 | if (gVLog) { |
| 88 | fprintf(gVLog, "%s\t", HumanizeMs(SkTime::GetMSecs() - kStartMs).c_str()); |
| 89 | fprintf(gVLog, fmt, args...); |
| 90 | fflush(gVLog); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | template <typename... Args> |
| 95 | static void info(const char* fmt, Args&&... args) { |
| 96 | vlog(fmt, args...); |
| 97 | if (!FLAGS_quiet) { |
| 98 | printf(fmt, args...); |
| 99 | } |
| 100 | } |
| 101 | static void info(const char* fmt) { |
| 102 | if (!FLAGS_quiet) { |
| 103 | printf("%s", fmt); // Clang warns printf(fmt) is insecure. |
| 104 | } |
| 105 | } |
| 106 | |
reed | 086eea9 | 2016-05-04 17:12:46 -0700 | [diff] [blame] | 107 | SK_DECLARE_STATIC_MUTEX(gFailuresMutex); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 108 | static SkTArray<SkString> gFailures; |
| 109 | |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 110 | static void fail(const SkString& err) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 111 | SkAutoMutexAcquire lock(gFailuresMutex); |
| 112 | SkDebugf("\n\nFAILURE: %s\n\n", err.c_str()); |
| 113 | gFailures.push_back(err); |
halcanary | 9e398f7 | 2015-01-10 11:18:04 -0800 | [diff] [blame] | 114 | } |
| 115 | |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 116 | |
mtklein | 246ba3a | 2016-02-23 10:39:36 -0800 | [diff] [blame] | 117 | // We use a spinlock to make locking this in a signal handler _somewhat_ safe. |
mtklein | 15923c9 | 2016-02-29 10:14:38 -0800 | [diff] [blame] | 118 | static SkSpinlock gMutex; |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 119 | static int32_t gPending; |
| 120 | static SkTArray<SkString> gRunning; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 121 | |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 122 | static void done(const char* config, const char* src, const char* srcOptions, const char* name) { |
| 123 | SkString id = SkStringPrintf("%s %s %s %s", config, src, srcOptions, name); |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 124 | vlog("done %s\n", id.c_str()); |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 125 | int pending; |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 126 | { |
mtklein | 15923c9 | 2016-02-29 10:14:38 -0800 | [diff] [blame] | 127 | SkAutoTAcquire<SkSpinlock> lock(gMutex); |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 128 | for (int i = 0; i < gRunning.count(); i++) { |
| 129 | if (gRunning[i] == id) { |
| 130 | gRunning.removeShuffle(i); |
| 131 | break; |
| 132 | } |
| 133 | } |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 134 | pending = --gPending; |
reed | 50bc051 | 2015-05-19 14:13:31 -0700 | [diff] [blame] | 135 | } |
mtklein | a17241b | 2015-01-23 05:48:00 -0800 | [diff] [blame] | 136 | // We write our dm.json file every once in a while in case we crash. |
| 137 | // Notice this also handles the final dm.json when pending == 0. |
| 138 | if (pending % 500 == 0) { |
| 139 | JsonWriter::DumpJson(); |
| 140 | } |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 141 | } |
| 142 | |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 143 | static void start(const char* config, const char* src, const char* srcOptions, const char* name) { |
| 144 | SkString id = SkStringPrintf("%s %s %s %s", config, src, srcOptions, name); |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 145 | vlog("start %s\n", id.c_str()); |
mtklein | 15923c9 | 2016-02-29 10:14:38 -0800 | [diff] [blame] | 146 | SkAutoTAcquire<SkSpinlock> lock(gMutex); |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 147 | gRunning.push_back(id); |
| 148 | } |
| 149 | |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 150 | static void print_status() { |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 151 | int curr = sk_tools::getCurrResidentSetSizeMB(), |
| 152 | peak = sk_tools::getMaxResidentSetSizeMB(); |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 153 | SkString elapsed = HumanizeMs(SkTime::GetMSecs() - kStartMs); |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 154 | |
mtklein | 15923c9 | 2016-02-29 10:14:38 -0800 | [diff] [blame] | 155 | SkAutoTAcquire<SkSpinlock> lock(gMutex); |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 156 | info("\n%s elapsed, %d active, %d queued, %dMB RAM, %dMB peak\n", |
| 157 | elapsed.c_str(), gRunning.count(), gPending - gRunning.count(), curr, peak); |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 158 | for (auto& task : gRunning) { |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 159 | info("\t%s\n", task.c_str()); |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 160 | } |
| 161 | } |
| 162 | |
mtklein | f855729 | 2016-02-29 06:35:28 -0800 | [diff] [blame] | 163 | // Yo dawg, I heard you like signals so I caught a signal in your |
| 164 | // signal handler so you can handle signals while you handle signals. |
| 165 | // Let's not get into that situation. Only print if we're the first ones to get a crash signal. |
| 166 | static std::atomic<bool> in_signal_handler{false}; |
| 167 | |
mtklein | 246ba3a | 2016-02-23 10:39:36 -0800 | [diff] [blame] | 168 | #if defined(SK_BUILD_FOR_WIN32) |
mtklein | f855729 | 2016-02-29 06:35:28 -0800 | [diff] [blame] | 169 | static LONG WINAPI handler(EXCEPTION_POINTERS* e) { |
| 170 | static const struct { |
| 171 | const char* name; |
robertphillips | 7546786 | 2016-03-01 14:10:23 -0800 | [diff] [blame] | 172 | DWORD code; |
mtklein | f855729 | 2016-02-29 06:35:28 -0800 | [diff] [blame] | 173 | } kExceptions[] = { |
| 174 | #define _(E) {#E, E} |
| 175 | _(EXCEPTION_ACCESS_VIOLATION), |
| 176 | _(EXCEPTION_BREAKPOINT), |
| 177 | _(EXCEPTION_INT_DIVIDE_BY_ZERO), |
| 178 | _(EXCEPTION_STACK_OVERFLOW), |
| 179 | // TODO: more? |
| 180 | #undef _ |
| 181 | }; |
| 182 | |
| 183 | if (!in_signal_handler.exchange(true)) { |
| 184 | const DWORD code = e->ExceptionRecord->ExceptionCode; |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 185 | info("\nCaught exception %u", code); |
mtklein | f855729 | 2016-02-29 06:35:28 -0800 | [diff] [blame] | 186 | for (const auto& exception : kExceptions) { |
| 187 | if (exception.code == code) { |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 188 | info(" %s", exception.name); |
mtklein | f855729 | 2016-02-29 06:35:28 -0800 | [diff] [blame] | 189 | } |
| 190 | } |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 191 | info("\n"); |
mtklein | f855729 | 2016-02-29 06:35:28 -0800 | [diff] [blame] | 192 | print_status(); |
mtklein | 13bf339 | 2016-03-17 10:16:12 -0700 | [diff] [blame] | 193 | fflush(stdout); |
mtklein | f855729 | 2016-02-29 06:35:28 -0800 | [diff] [blame] | 194 | } |
| 195 | // Execute default exception handler... hopefully, exit. |
| 196 | return EXCEPTION_EXECUTE_HANDLER; |
mtklein | 246ba3a | 2016-02-23 10:39:36 -0800 | [diff] [blame] | 197 | } |
mtklein | f855729 | 2016-02-29 06:35:28 -0800 | [diff] [blame] | 198 | static void setup_crash_handler() { SetUnhandledExceptionFilter(handler); } |
mtklein | 246ba3a | 2016-02-23 10:39:36 -0800 | [diff] [blame] | 199 | |
mtklein | 819ab10 | 2016-02-29 17:02:52 -0800 | [diff] [blame] | 200 | #elif !defined(SK_BUILD_FOR_ANDROID) |
| 201 | #include <execinfo.h> |
mtklein | 246ba3a | 2016-02-23 10:39:36 -0800 | [diff] [blame] | 202 | #include <signal.h> |
mtklein | 819ab10 | 2016-02-29 17:02:52 -0800 | [diff] [blame] | 203 | #include <stdlib.h> |
mtklein | f855729 | 2016-02-29 06:35:28 -0800 | [diff] [blame] | 204 | |
mtklein | 246ba3a | 2016-02-23 10:39:36 -0800 | [diff] [blame] | 205 | static void setup_crash_handler() { |
| 206 | const int kSignals[] = { SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGSEGV }; |
| 207 | for (int sig : kSignals) { |
| 208 | signal(sig, [](int sig) { |
mtklein | f855729 | 2016-02-29 06:35:28 -0800 | [diff] [blame] | 209 | if (!in_signal_handler.exchange(true)) { |
mtklein | 819ab10 | 2016-02-29 17:02:52 -0800 | [diff] [blame] | 210 | SkAutoTAcquire<SkSpinlock> lock(gMutex); |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 211 | info("\nCaught signal %d [%s], was running:\n", sig, strsignal(sig)); |
mtklein | 819ab10 | 2016-02-29 17:02:52 -0800 | [diff] [blame] | 212 | for (auto& task : gRunning) { |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 213 | info("\t%s\n", task.c_str()); |
mtklein | 819ab10 | 2016-02-29 17:02:52 -0800 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | void* stack[64]; |
| 217 | int count = backtrace(stack, SK_ARRAY_COUNT(stack)); |
| 218 | char** symbols = backtrace_symbols(stack, count); |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 219 | info("\nStack trace:\n"); |
mtklein | 819ab10 | 2016-02-29 17:02:52 -0800 | [diff] [blame] | 220 | for (int i = 0; i < count; i++) { |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 221 | info(" %s\n", symbols[i]); |
mtklein | 819ab10 | 2016-02-29 17:02:52 -0800 | [diff] [blame] | 222 | } |
mtklein | 13bf339 | 2016-03-17 10:16:12 -0700 | [diff] [blame] | 223 | fflush(stdout); |
mtklein | f855729 | 2016-02-29 06:35:28 -0800 | [diff] [blame] | 224 | } |
mtklein | 819ab10 | 2016-02-29 17:02:52 -0800 | [diff] [blame] | 225 | _Exit(sig); |
mtklein | 246ba3a | 2016-02-23 10:39:36 -0800 | [diff] [blame] | 226 | }); |
| 227 | } |
| 228 | } |
mtklein | 819ab10 | 2016-02-29 17:02:52 -0800 | [diff] [blame] | 229 | |
| 230 | #else // Android |
| 231 | static void setup_crash_handler() {} |
mtklein | 246ba3a | 2016-02-23 10:39:36 -0800 | [diff] [blame] | 232 | #endif |
| 233 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 234 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 235 | |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 236 | struct Gold : public SkString { |
mtklein | a82f562 | 2015-02-20 12:30:19 -0800 | [diff] [blame] | 237 | Gold() : SkString("") {} |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 238 | Gold(const SkString& sink, const SkString& src, |
| 239 | const SkString& srcOptions, const SkString& name, |
| 240 | const SkString& md5) |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 241 | : SkString("") { |
| 242 | this->append(sink); |
| 243 | this->append(src); |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 244 | this->append(srcOptions); |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 245 | this->append(name); |
| 246 | this->append(md5); |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 247 | } |
mtklein | c8d1dd4 | 2015-10-15 12:23:01 -0700 | [diff] [blame] | 248 | struct Hash { |
| 249 | uint32_t operator()(const Gold& g) const { |
| 250 | return SkGoodHash()((const SkString&)g); |
| 251 | } |
| 252 | }; |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 253 | }; |
mtklein | a82f562 | 2015-02-20 12:30:19 -0800 | [diff] [blame] | 254 | static SkTHashSet<Gold, Gold::Hash> gGold; |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 255 | |
| 256 | static void add_gold(JsonWriter::BitmapResult r) { |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 257 | gGold.add(Gold(r.config, r.sourceType, r.sourceOptions, r.name, r.md5)); |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | static void gather_gold() { |
| 261 | if (!FLAGS_readPath.isEmpty()) { |
| 262 | SkString path(FLAGS_readPath[0]); |
| 263 | path.append("/dm.json"); |
| 264 | if (!JsonWriter::ReadJson(path.c_str(), add_gold)) { |
| 265 | fail(SkStringPrintf("Couldn't read %s for golden results.", path.c_str())); |
| 266 | } |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 271 | |
mtklein | 935f1b1 | 2016-03-16 08:37:19 -0700 | [diff] [blame] | 272 | #if defined(SK_BUILD_FOR_WIN32) |
| 273 | static const char* kNewline = "\r\n"; |
| 274 | #else |
| 275 | static const char* kNewline = "\n"; |
| 276 | #endif |
| 277 | |
borenet | 09ed480 | 2015-04-03 14:15:33 -0700 | [diff] [blame] | 278 | static SkTHashSet<SkString> gUninterestingHashes; |
| 279 | |
| 280 | static void gather_uninteresting_hashes() { |
| 281 | if (!FLAGS_uninterestingHashesFile.isEmpty()) { |
| 282 | SkAutoTUnref<SkData> data(SkData::NewFromFileName(FLAGS_uninterestingHashesFile[0])); |
mtklein | cc334b3 | 2015-09-22 11:43:53 -0700 | [diff] [blame] | 283 | if (!data) { |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 284 | info("WARNING: unable to read uninteresting hashes from %s\n", |
| 285 | FLAGS_uninterestingHashesFile[0]); |
mtklein | cc334b3 | 2015-09-22 11:43:53 -0700 | [diff] [blame] | 286 | return; |
| 287 | } |
borenet | 09ed480 | 2015-04-03 14:15:33 -0700 | [diff] [blame] | 288 | SkTArray<SkString> hashes; |
mtklein | 935f1b1 | 2016-03-16 08:37:19 -0700 | [diff] [blame] | 289 | SkStrSplit((const char*)data->data(), kNewline, &hashes); |
borenet | 09ed480 | 2015-04-03 14:15:33 -0700 | [diff] [blame] | 290 | for (const SkString& hash : hashes) { |
| 291 | gUninterestingHashes.add(hash); |
| 292 | } |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 293 | info("FYI: loaded %d distinct uninteresting hashes from %d lines\n", |
| 294 | gUninterestingHashes.count(), hashes.count()); |
borenet | 09ed480 | 2015-04-03 14:15:33 -0700 | [diff] [blame] | 295 | } |
| 296 | } |
| 297 | |
| 298 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 299 | |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 300 | struct TaggedSrc : public SkAutoTDelete<Src> { |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 301 | SkString tag; |
| 302 | SkString options; |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 303 | }; |
| 304 | |
| 305 | struct TaggedSink : public SkAutoTDelete<Sink> { |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 306 | SkString tag; |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 307 | }; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 308 | |
| 309 | static const bool kMemcpyOK = true; |
| 310 | |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 311 | static SkTArray<TaggedSrc, kMemcpyOK> gSrcs; |
| 312 | static SkTArray<TaggedSink, kMemcpyOK> gSinks; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 313 | |
mtklein | 6393c06 | 2015-04-27 08:45:01 -0700 | [diff] [blame] | 314 | static bool in_shard() { |
| 315 | static int N = 0; |
| 316 | return N++ % FLAGS_shards == FLAGS_shard; |
| 317 | } |
| 318 | |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 319 | static void push_src(const char* tag, ImplicitString options, Src* s) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 320 | SkAutoTDelete<Src> src(s); |
mtklein | 6393c06 | 2015-04-27 08:45:01 -0700 | [diff] [blame] | 321 | if (in_shard() && |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 322 | FLAGS_src.contains(tag) && |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 323 | !SkCommandLineFlags::ShouldSkip(FLAGS_match, src->name().c_str())) { |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 324 | TaggedSrc& s = gSrcs.push_back(); |
mtklein | 18300a3 | 2016-03-16 13:53:35 -0700 | [diff] [blame] | 325 | s.reset(src.release()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 326 | s.tag = tag; |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 327 | s.options = options; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 328 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 329 | } |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 330 | |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 331 | static void push_codec_src(Path path, CodecSrc::Mode mode, CodecSrc::DstColorType dstColorType, |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 332 | SkAlphaType dstAlphaType, float scale) { |
scroggo | e449984 | 2016-02-25 11:03:47 -0800 | [diff] [blame] | 333 | if (FLAGS_simpleCodec) { |
| 334 | if (mode != CodecSrc::kCodec_Mode || dstColorType != CodecSrc::kGetFromCanvas_DstColorType |
| 335 | || scale != 1.0f) |
| 336 | // Only decode in the simple case. |
| 337 | return; |
| 338 | } |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 339 | SkString folder; |
| 340 | switch (mode) { |
| 341 | case CodecSrc::kCodec_Mode: |
| 342 | folder.append("codec"); |
| 343 | break; |
msarett | bb25b53 | 2016-01-13 09:31:39 -0800 | [diff] [blame] | 344 | case CodecSrc::kCodecZeroInit_Mode: |
| 345 | folder.append("codec_zero_init"); |
| 346 | break; |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 347 | case CodecSrc::kScanline_Mode: |
| 348 | folder.append("scanline"); |
| 349 | break; |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 350 | case CodecSrc::kStripe_Mode: |
| 351 | folder.append("stripe"); |
| 352 | break; |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 353 | case CodecSrc::kCroppedScanline_Mode: |
| 354 | folder.append("crop"); |
| 355 | break; |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 356 | case CodecSrc::kSubset_Mode: |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 357 | folder.append("codec_subset"); |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 358 | break; |
| 359 | } |
| 360 | |
| 361 | switch (dstColorType) { |
| 362 | case CodecSrc::kGrayscale_Always_DstColorType: |
| 363 | folder.append("_kGray8"); |
| 364 | break; |
| 365 | case CodecSrc::kIndex8_Always_DstColorType: |
| 366 | folder.append("_kIndex8"); |
| 367 | break; |
msarett | 34e0ec4 | 2016-04-22 16:27:24 -0700 | [diff] [blame] | 368 | case CodecSrc::kNonNative8888_Always_DstColorType: |
| 369 | folder.append("_kNonNative"); |
| 370 | break; |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 371 | default: |
| 372 | break; |
| 373 | } |
| 374 | |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 375 | switch (dstAlphaType) { |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 376 | case kPremul_SkAlphaType: |
| 377 | folder.append("_premul"); |
| 378 | break; |
| 379 | case kUnpremul_SkAlphaType: |
| 380 | folder.append("_unpremul"); |
| 381 | break; |
| 382 | default: |
| 383 | break; |
| 384 | } |
| 385 | |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 386 | if (1.0f != scale) { |
| 387 | folder.appendf("_%.3f", scale); |
| 388 | } |
| 389 | |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 390 | CodecSrc* src = new CodecSrc(path, mode, dstColorType, dstAlphaType, scale); |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 391 | push_src("image", folder, src); |
| 392 | } |
| 393 | |
scroggo | f8dc9df | 2016-05-16 09:04:13 -0700 | [diff] [blame] | 394 | static void push_android_codec_src(Path path, CodecSrc::DstColorType dstColorType, |
| 395 | SkAlphaType dstAlphaType, int sampleSize) { |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 396 | SkString folder; |
scroggo | f8dc9df | 2016-05-16 09:04:13 -0700 | [diff] [blame] | 397 | folder.append("scaled_codec"); |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 398 | |
| 399 | switch (dstColorType) { |
| 400 | case CodecSrc::kGrayscale_Always_DstColorType: |
| 401 | folder.append("_kGray8"); |
| 402 | break; |
| 403 | case CodecSrc::kIndex8_Always_DstColorType: |
| 404 | folder.append("_kIndex8"); |
| 405 | break; |
msarett | 34e0ec4 | 2016-04-22 16:27:24 -0700 | [diff] [blame] | 406 | case CodecSrc::kNonNative8888_Always_DstColorType: |
| 407 | folder.append("_kNonNative"); |
| 408 | break; |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 409 | default: |
| 410 | break; |
| 411 | } |
| 412 | |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 413 | switch (dstAlphaType) { |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 414 | case kPremul_SkAlphaType: |
| 415 | folder.append("_premul"); |
| 416 | break; |
msarett | 9e9444c | 2016-02-03 12:39:10 -0800 | [diff] [blame] | 417 | case kUnpremul_SkAlphaType: |
| 418 | folder.append("_unpremul"); |
| 419 | break; |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 420 | default: |
| 421 | break; |
| 422 | } |
| 423 | |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 424 | if (1 != sampleSize) { |
msarett | 4b0778e | 2015-11-13 09:59:11 -0800 | [diff] [blame] | 425 | folder.appendf("_%.3f", 1.0f / (float) sampleSize); |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 426 | } |
| 427 | |
scroggo | f8dc9df | 2016-05-16 09:04:13 -0700 | [diff] [blame] | 428 | AndroidCodecSrc* src = new AndroidCodecSrc(path, dstColorType, dstAlphaType, sampleSize); |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 429 | push_src("image", folder, src); |
| 430 | } |
| 431 | |
msarett | 1897631 | 2016-03-09 14:20:58 -0800 | [diff] [blame] | 432 | static void push_image_gen_src(Path path, ImageGenSrc::Mode mode, SkAlphaType alphaType, bool isGpu) |
| 433 | { |
| 434 | SkString folder; |
| 435 | switch (mode) { |
| 436 | case ImageGenSrc::kCodec_Mode: |
| 437 | folder.append("gen_codec"); |
| 438 | break; |
| 439 | case ImageGenSrc::kPlatform_Mode: |
| 440 | folder.append("gen_platform"); |
| 441 | break; |
| 442 | } |
| 443 | |
| 444 | if (isGpu) { |
| 445 | folder.append("_gpu"); |
| 446 | } else { |
| 447 | switch (alphaType) { |
| 448 | case kOpaque_SkAlphaType: |
| 449 | folder.append("_opaque"); |
| 450 | break; |
| 451 | case kPremul_SkAlphaType: |
| 452 | folder.append("_premul"); |
| 453 | break; |
| 454 | case kUnpremul_SkAlphaType: |
| 455 | folder.append("_unpremul"); |
| 456 | break; |
| 457 | default: |
| 458 | break; |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | ImageGenSrc* src = new ImageGenSrc(path, mode, alphaType, isGpu); |
| 463 | push_src("image", folder, src); |
| 464 | } |
| 465 | |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 466 | static void push_codec_srcs(Path path) { |
| 467 | SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); |
| 468 | if (!encoded) { |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 469 | info("Couldn't read %s.", path.c_str()); |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 470 | return; |
| 471 | } |
| 472 | SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 473 | if (nullptr == codec.get()) { |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 474 | info("Couldn't create codec for %s.", path.c_str()); |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 475 | return; |
| 476 | } |
| 477 | |
scroggo | 9366aff | 2016-05-20 08:38:54 -0700 | [diff] [blame] | 478 | // native scaling is only supported by WEBP and JPEG |
| 479 | bool supportsNativeScaling = false; |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 480 | |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 481 | SkTArray<CodecSrc::Mode> nativeModes; |
| 482 | nativeModes.push_back(CodecSrc::kCodec_Mode); |
| 483 | nativeModes.push_back(CodecSrc::kCodecZeroInit_Mode); |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 484 | switch (codec->getEncodedFormat()) { |
| 485 | case SkEncodedFormat::kJPEG_SkEncodedFormat: |
| 486 | nativeModes.push_back(CodecSrc::kScanline_Mode); |
| 487 | nativeModes.push_back(CodecSrc::kStripe_Mode); |
| 488 | nativeModes.push_back(CodecSrc::kCroppedScanline_Mode); |
scroggo | 9366aff | 2016-05-20 08:38:54 -0700 | [diff] [blame] | 489 | supportsNativeScaling = true; |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 490 | break; |
| 491 | case SkEncodedFormat::kWEBP_SkEncodedFormat: |
| 492 | nativeModes.push_back(CodecSrc::kSubset_Mode); |
scroggo | 9366aff | 2016-05-20 08:38:54 -0700 | [diff] [blame] | 493 | supportsNativeScaling = true; |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 494 | break; |
yujieqin | 7a307df | 2016-03-11 07:32:33 -0800 | [diff] [blame] | 495 | case SkEncodedFormat::kDNG_SkEncodedFormat: |
msarett | b65e604 | 2016-02-23 05:37:25 -0800 | [diff] [blame] | 496 | break; |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 497 | default: |
| 498 | nativeModes.push_back(CodecSrc::kScanline_Mode); |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 499 | break; |
| 500 | } |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 501 | |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 502 | SkTArray<CodecSrc::DstColorType> colorTypes; |
| 503 | colorTypes.push_back(CodecSrc::kGetFromCanvas_DstColorType); |
msarett | 34e0ec4 | 2016-04-22 16:27:24 -0700 | [diff] [blame] | 504 | colorTypes.push_back(CodecSrc::kNonNative8888_Always_DstColorType); |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 505 | switch (codec->getInfo().colorType()) { |
| 506 | case kGray_8_SkColorType: |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 507 | colorTypes.push_back(CodecSrc::kGrayscale_Always_DstColorType); |
msarett | 55f7bdd | 2016-02-16 13:24:54 -0800 | [diff] [blame] | 508 | if (kWBMP_SkEncodedFormat == codec->getEncodedFormat()) { |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 509 | colorTypes.push_back(CodecSrc::kIndex8_Always_DstColorType); |
msarett | 55f7bdd | 2016-02-16 13:24:54 -0800 | [diff] [blame] | 510 | } |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 511 | break; |
| 512 | case kIndex_8_SkColorType: |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 513 | colorTypes.push_back(CodecSrc::kIndex8_Always_DstColorType); |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 514 | break; |
| 515 | default: |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 516 | break; |
| 517 | } |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 518 | |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 519 | SkTArray<SkAlphaType> alphaModes; |
| 520 | alphaModes.push_back(kPremul_SkAlphaType); |
scroggo | f2c96a2 | 2016-05-20 11:08:27 -0700 | [diff] [blame^] | 521 | if (codec->getInfo().alphaType() != kOpaque_SkAlphaType) { |
| 522 | alphaModes.push_back(kUnpremul_SkAlphaType); |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 523 | } |
msarett | b714fb0 | 2016-01-22 14:46:42 -0800 | [diff] [blame] | 524 | |
| 525 | for (CodecSrc::Mode mode : nativeModes) { |
scroggo | 9366aff | 2016-05-20 08:38:54 -0700 | [diff] [blame] | 526 | for (CodecSrc::DstColorType colorType : colorTypes) { |
| 527 | for (SkAlphaType alphaType : alphaModes) { |
scroggo | f2c96a2 | 2016-05-20 11:08:27 -0700 | [diff] [blame^] | 528 | // Only test kCroppedScanline_Mode when the alpha type is premul. The test is |
scroggo | 9366aff | 2016-05-20 08:38:54 -0700 | [diff] [blame] | 529 | // slow and won't be interestingly different with different alpha types. |
| 530 | if (CodecSrc::kCroppedScanline_Mode == mode && |
scroggo | f2c96a2 | 2016-05-20 11:08:27 -0700 | [diff] [blame^] | 531 | kPremul_SkAlphaType != alphaType) { |
scroggo | 9366aff | 2016-05-20 08:38:54 -0700 | [diff] [blame] | 532 | continue; |
| 533 | } |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 534 | |
scroggo | 9366aff | 2016-05-20 08:38:54 -0700 | [diff] [blame] | 535 | push_codec_src(path, mode, colorType, alphaType, 1.0f); |
msarett | f3dc188 | 2016-04-26 13:06:38 -0700 | [diff] [blame] | 536 | |
scroggo | 9366aff | 2016-05-20 08:38:54 -0700 | [diff] [blame] | 537 | // Skip kNonNative on different native scales. It won't be interestingly |
| 538 | // different. |
| 539 | if (supportsNativeScaling && |
| 540 | CodecSrc::kNonNative8888_Always_DstColorType == colorType) { |
| 541 | // Native Scales |
| 542 | // SkJpegCodec natively supports scaling to the following: |
| 543 | for (auto scale : { 0.125f, 0.25f, 0.375f, 0.5f, 0.625f, 0.750f, 0.875f }) { |
| 544 | push_codec_src(path, mode, colorType, alphaType, scale); |
| 545 | } |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 546 | } |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 547 | } |
| 548 | } |
msarett | 0a24297 | 2015-06-11 14:27:27 -0700 | [diff] [blame] | 549 | } |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 550 | |
scroggo | e449984 | 2016-02-25 11:03:47 -0800 | [diff] [blame] | 551 | if (FLAGS_simpleCodec) { |
| 552 | return; |
| 553 | } |
| 554 | |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 555 | const int sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 556 | |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 557 | for (int sampleSize : sampleSizes) { |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 558 | for (CodecSrc::DstColorType colorType : colorTypes) { |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 559 | for (SkAlphaType alphaType : alphaModes) { |
msarett | f3dc188 | 2016-04-26 13:06:38 -0700 | [diff] [blame] | 560 | // We can exercise all of the kNonNative support code in the swizzler with just a |
| 561 | // few sample sizes. Skip the rest. |
| 562 | if (CodecSrc::kNonNative8888_Always_DstColorType == colorType && sampleSize > 3) { |
| 563 | continue; |
| 564 | } |
| 565 | |
scroggo | f8dc9df | 2016-05-16 09:04:13 -0700 | [diff] [blame] | 566 | push_android_codec_src(path, colorType, alphaType, sampleSize); |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 567 | } |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 568 | } |
| 569 | } |
msarett | 1897631 | 2016-03-09 14:20:58 -0800 | [diff] [blame] | 570 | |
| 571 | static const char* const rawExts[] = { |
| 572 | "arw", "cr2", "dng", "nef", "nrw", "orf", "raf", "rw2", "pef", "srw", |
| 573 | "ARW", "CR2", "DNG", "NEF", "NRW", "ORF", "RAF", "RW2", "PEF", "SRW", |
| 574 | }; |
| 575 | |
| 576 | // There is not currently a reason to test RAW images on image generator. |
| 577 | // If we want to enable these tests, we will need to fix skbug.com/5079. |
| 578 | for (const char* ext : rawExts) { |
| 579 | if (path.endsWith(ext)) { |
| 580 | return; |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | // Push image generator GPU test. |
brianosman | c9ced39 | 2016-03-24 07:27:43 -0700 | [diff] [blame] | 585 | push_image_gen_src(path, ImageGenSrc::kCodec_Mode, codec->getInfo().alphaType(), true); |
msarett | 1897631 | 2016-03-09 14:20:58 -0800 | [diff] [blame] | 586 | |
| 587 | // Push image generator CPU tests. |
| 588 | for (SkAlphaType alphaType : alphaModes) { |
| 589 | push_image_gen_src(path, ImageGenSrc::kCodec_Mode, alphaType, false); |
| 590 | |
| 591 | #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) |
| 592 | if (kWEBP_SkEncodedFormat != codec->getEncodedFormat() && |
| 593 | kWBMP_SkEncodedFormat != codec->getEncodedFormat() && |
| 594 | kUnpremul_SkAlphaType != alphaType) |
| 595 | { |
| 596 | push_image_gen_src(path, ImageGenSrc::kPlatform_Mode, alphaType, false); |
| 597 | } |
msarett | fc0b6d1 | 2016-03-17 13:50:17 -0700 | [diff] [blame] | 598 | #elif defined(SK_BUILD_FOR_WIN) |
| 599 | if (kWEBP_SkEncodedFormat != codec->getEncodedFormat() && |
| 600 | kWBMP_SkEncodedFormat != codec->getEncodedFormat()) |
| 601 | { |
| 602 | push_image_gen_src(path, ImageGenSrc::kPlatform_Mode, alphaType, false); |
| 603 | } |
msarett | 1897631 | 2016-03-09 14:20:58 -0800 | [diff] [blame] | 604 | #endif |
| 605 | } |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 606 | } |
| 607 | |
msarett | d1227a7 | 2016-05-18 06:23:57 -0700 | [diff] [blame] | 608 | static void push_brd_src(Path path, CodecSrc::DstColorType dstColorType, BRDSrc::Mode mode, |
| 609 | uint32_t sampleSize) { |
| 610 | SkString folder("brd_android_codec"); |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 611 | switch (mode) { |
| 612 | case BRDSrc::kFullImage_Mode: |
| 613 | break; |
| 614 | case BRDSrc::kDivisor_Mode: |
| 615 | folder.append("_divisor"); |
| 616 | break; |
| 617 | default: |
| 618 | SkASSERT(false); |
| 619 | return; |
| 620 | } |
| 621 | |
| 622 | switch (dstColorType) { |
| 623 | case CodecSrc::kGetFromCanvas_DstColorType: |
| 624 | break; |
| 625 | case CodecSrc::kIndex8_Always_DstColorType: |
| 626 | folder.append("_kIndex"); |
| 627 | break; |
| 628 | case CodecSrc::kGrayscale_Always_DstColorType: |
| 629 | folder.append("_kGray"); |
| 630 | break; |
| 631 | default: |
| 632 | SkASSERT(false); |
| 633 | return; |
| 634 | } |
| 635 | |
| 636 | if (1 != sampleSize) { |
msarett | 4b0778e | 2015-11-13 09:59:11 -0800 | [diff] [blame] | 637 | folder.appendf("_%.3f", 1.0f / (float) sampleSize); |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 638 | } |
| 639 | |
msarett | d1227a7 | 2016-05-18 06:23:57 -0700 | [diff] [blame] | 640 | BRDSrc* src = new BRDSrc(path, mode, dstColorType, sampleSize); |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 641 | push_src("image", folder, src); |
| 642 | } |
| 643 | |
| 644 | static void push_brd_srcs(Path path) { |
scroggo | 24a9bd7 | 2016-05-20 06:02:42 -0700 | [diff] [blame] | 645 | // Only run Index8 and grayscale to one sampleSize and Mode. Though interesting |
| 646 | // to test these color types, they should not reveal anything across various |
| 647 | // sampleSizes and Modes |
| 648 | for (auto type : { CodecSrc::kIndex8_Always_DstColorType, |
| 649 | CodecSrc::kGrayscale_Always_DstColorType }) { |
| 650 | // Arbitrarily choose Mode and sampleSize. |
| 651 | push_brd_src(path, type, BRDSrc::kFullImage_Mode, 2); |
| 652 | } |
| 653 | |
| 654 | |
scroggo | 501b734 | 2015-11-03 07:55:11 -0800 | [diff] [blame] | 655 | // Test on a variety of sampleSizes, making sure to include: |
| 656 | // - 2, 4, and 8, which are natively supported by jpeg |
| 657 | // - multiples of 2 which are not divisible by 4 (analogous for 4) |
| 658 | // - larger powers of two, since BRD clients generally use powers of 2 |
| 659 | // We will only produce output for the larger sizes on large images. |
| 660 | const uint32_t sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 24, 32, 64 }; |
msarett | 6efbe05 | 2015-09-11 09:01:16 -0700 | [diff] [blame] | 661 | |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 662 | const BRDSrc::Mode modes[] = { |
msarett | 26ad17b | 2015-10-22 07:29:19 -0700 | [diff] [blame] | 663 | BRDSrc::kFullImage_Mode, |
| 664 | BRDSrc::kDivisor_Mode, |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 665 | }; |
| 666 | |
msarett | d1227a7 | 2016-05-18 06:23:57 -0700 | [diff] [blame] | 667 | for (uint32_t sampleSize : sampleSizes) { |
scroggo | 24a9bd7 | 2016-05-20 06:02:42 -0700 | [diff] [blame] | 668 | for (BRDSrc::Mode mode : modes) { |
| 669 | push_brd_src(path, CodecSrc::kGetFromCanvas_DstColorType, mode, sampleSize); |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 670 | } |
| 671 | } |
| 672 | } |
| 673 | |
| 674 | static bool brd_supported(const char* ext) { |
msarett | 8c8f22a | 2015-04-01 06:58:48 -0700 | [diff] [blame] | 675 | static const char* const exts[] = { |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 676 | "jpg", "jpeg", "png", "webp", |
| 677 | "JPG", "JPEG", "PNG", "WEBP", |
msarett | 8c8f22a | 2015-04-01 06:58:48 -0700 | [diff] [blame] | 678 | }; |
| 679 | |
| 680 | for (uint32_t i = 0; i < SK_ARRAY_COUNT(exts); i++) { |
| 681 | if (0 == strcmp(exts[i], ext)) { |
| 682 | return true; |
| 683 | } |
| 684 | } |
| 685 | return false; |
scroggo | 9b77ddd | 2015-03-19 06:03:39 -0700 | [diff] [blame] | 686 | } |
| 687 | |
scroggo | 8673714 | 2016-02-03 12:19:11 -0800 | [diff] [blame] | 688 | static bool gather_srcs() { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 689 | for (const skiagm::GMRegistry* r = skiagm::GMRegistry::Head(); r; r = r->next()) { |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 690 | push_src("gm", "", new GMSrc(r->factory())); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 691 | } |
halcanary | fc37ad1 | 2015-01-30 07:31:19 -0800 | [diff] [blame] | 692 | for (int i = 0; i < FLAGS_skps.count(); i++) { |
| 693 | const char* path = FLAGS_skps[i]; |
| 694 | if (sk_isdir(path)) { |
| 695 | SkOSFile::Iter it(path, "skp"); |
| 696 | for (SkString file; it.next(&file); ) { |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 697 | push_src("skp", "", new SKPSrc(SkOSPath::Join(path, file.c_str()))); |
halcanary | fc37ad1 | 2015-01-30 07:31:19 -0800 | [diff] [blame] | 698 | } |
| 699 | } else { |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 700 | push_src("skp", "", new SKPSrc(path)); |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 701 | } |
| 702 | } |
scroggo | 8673714 | 2016-02-03 12:19:11 -0800 | [diff] [blame] | 703 | |
| 704 | SkTArray<SkString> images; |
msarett | 69deca8 | 2016-04-29 09:38:40 -0700 | [diff] [blame] | 705 | if (!CollectImages(FLAGS_images, &images)) { |
scroggo | 8673714 | 2016-02-03 12:19:11 -0800 | [diff] [blame] | 706 | return false; |
| 707 | } |
| 708 | |
| 709 | for (auto image : images) { |
| 710 | push_codec_srcs(image); |
scroggo | e449984 | 2016-02-25 11:03:47 -0800 | [diff] [blame] | 711 | if (FLAGS_simpleCodec) { |
| 712 | continue; |
| 713 | } |
| 714 | |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 715 | const char* ext = strrchr(image.c_str(), '.'); |
| 716 | if (ext && brd_supported(ext+1)) { |
scroggo | 8673714 | 2016-02-03 12:19:11 -0800 | [diff] [blame] | 717 | push_brd_srcs(image); |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 718 | } |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 719 | } |
scroggo | 8673714 | 2016-02-03 12:19:11 -0800 | [diff] [blame] | 720 | |
msarett | 69deca8 | 2016-04-29 09:38:40 -0700 | [diff] [blame] | 721 | SkTArray<SkString> colorImages; |
| 722 | if (!CollectImages(FLAGS_colorImages, &colorImages)) { |
| 723 | return false; |
| 724 | } |
| 725 | |
| 726 | for (auto colorImage : colorImages) { |
| 727 | ColorCodecSrc* src = new ColorCodecSrc(colorImage, ColorCodecSrc::kBaseline_Mode); |
| 728 | push_src("image", "color_codec_baseline", src); |
| 729 | } |
| 730 | |
scroggo | 8673714 | 2016-02-03 12:19:11 -0800 | [diff] [blame] | 731 | return true; |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 732 | } |
| 733 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 734 | static void push_sink(const SkCommandLineConfig& config, Sink* s) { |
rmistry | 0f515bd | 2015-12-22 10:22:26 -0800 | [diff] [blame] | 735 | SkAutoTDelete<Sink> sink(s); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 736 | |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 737 | // Try a simple Src as a canary. If it fails, skip this sink. |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 738 | struct : public Src { |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 739 | Error draw(SkCanvas* c) const override { |
| 740 | c->drawRect(SkRect::MakeWH(1,1), SkPaint()); |
| 741 | return ""; |
| 742 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 743 | SkISize size() const override { return SkISize::Make(16, 16); } |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 744 | Name name() const override { return "justOneRect"; } |
| 745 | } justOneRect; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 746 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 747 | SkBitmap bitmap; |
| 748 | SkDynamicMemoryWStream stream; |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 749 | SkString log; |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 750 | Error err = sink->draw(justOneRect, &bitmap, &stream, &log); |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 751 | if (err.isFatal()) { |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 752 | info("Could not run %s: %s\n", config.getTag().c_str(), err.c_str()); |
mtklein | 05641a5 | 2015-04-21 10:49:13 -0700 | [diff] [blame] | 753 | exit(1); |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 754 | } |
| 755 | |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 756 | TaggedSink& ts = gSinks.push_back(); |
mtklein | 18300a3 | 2016-03-16 13:53:35 -0700 | [diff] [blame] | 757 | ts.reset(sink.release()); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 758 | ts.tag = config.getTag(); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | static bool gpu_supported() { |
| 762 | #if SK_SUPPORT_GPU |
| 763 | return FLAGS_gpu; |
| 764 | #else |
| 765 | return false; |
| 766 | #endif |
| 767 | } |
kkinnunen | 9ebc3f0 | 2015-12-21 23:48:13 -0800 | [diff] [blame] | 768 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 769 | static Sink* create_sink(const SkCommandLineConfig* config) { |
| 770 | #if SK_SUPPORT_GPU |
| 771 | if (gpu_supported()) { |
| 772 | if (const SkCommandLineConfigGpu* gpuConfig = config->asConfigGpu()) { |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 773 | GrContextFactory::ContextType contextType = gpuConfig->getContextType(); |
| 774 | GrContextFactory::ContextOptions contextOptions = |
| 775 | GrContextFactory::kNone_ContextOptions; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 776 | if (gpuConfig->getUseNVPR()) { |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 777 | contextOptions = static_cast<GrContextFactory::ContextOptions>( |
| 778 | contextOptions | GrContextFactory::kEnableNVPR_ContextOptions); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 779 | } |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame] | 780 | if (SkColorAndProfileAreGammaCorrect(gpuConfig->getColorType(), |
| 781 | gpuConfig->getProfileType())) { |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 782 | contextOptions = static_cast<GrContextFactory::ContextOptions>( |
| 783 | contextOptions | GrContextFactory::kRequireSRGBSupport_ContextOptions); |
brianosman | 61d3b08 | 2016-03-30 11:19:36 -0700 | [diff] [blame] | 784 | } |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 785 | GrContextFactory testFactory; |
| 786 | if (!testFactory.get(contextType, contextOptions)) { |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 787 | info("WARNING: can not create GPU context for config '%s'. " |
| 788 | "GM tests will be skipped.\n", gpuConfig->getTag().c_str()); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 789 | return nullptr; |
| 790 | } |
| 791 | return new GPUSink(contextType, contextOptions, gpuConfig->getSamples(), |
brianosman | d93c120 | 2016-03-10 07:49:08 -0800 | [diff] [blame] | 792 | gpuConfig->getUseDIText(), gpuConfig->getColorType(), |
| 793 | gpuConfig->getProfileType(), FLAGS_gpu_threading); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 794 | } |
| 795 | } |
| 796 | #endif |
| 797 | |
| 798 | #define SINK(t, sink, ...) if (config->getBackend().equals(t)) { return new sink(__VA_ARGS__); } |
| 799 | |
tomhudson | eebc39a | 2015-02-23 12:18:05 -0800 | [diff] [blame] | 800 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 801 | SINK("hwui", HWUISink); |
| 802 | #endif |
| 803 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 804 | if (FLAGS_cpu) { |
| 805 | SINK("565", RasterSink, kRGB_565_SkColorType); |
| 806 | SINK("8888", RasterSink, kN32_SkColorType); |
mtklein | 27c3fdd | 2016-02-26 14:43:21 -0800 | [diff] [blame] | 807 | SINK("srgb", RasterSink, kN32_SkColorType, kSRGB_SkColorProfileType); |
| 808 | SINK("f16", RasterSink, kRGBA_F16_SkColorType); |
halcanary | 94b87bd | 2016-04-04 06:12:15 -0700 | [diff] [blame] | 809 | SINK("pdf", PDFSink); |
mtklein | 9c3f17d | 2015-01-28 11:35:18 -0800 | [diff] [blame] | 810 | SINK("skp", SKPSink); |
mtklein | 8a4527e | 2015-01-31 20:00:58 -0800 | [diff] [blame] | 811 | SINK("svg", SVGSink); |
| 812 | SINK("null", NullSink); |
halcanary | 47ef4d5 | 2015-03-03 09:13:09 -0800 | [diff] [blame] | 813 | SINK("xps", XPSSink); |
halcanary | 4b65666 | 2016-04-27 07:45:18 -0700 | [diff] [blame] | 814 | SINK("pdfa", PDFSink, true); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 815 | } |
| 816 | #undef SINK |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 817 | return nullptr; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 818 | } |
| 819 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 820 | static Sink* create_via(const SkString& tag, Sink* wrapped) { |
| 821 | #define VIA(t, via, ...) if (tag.equals(t)) { return new via(__VA_ARGS__); } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 822 | VIA("twice", ViaTwice, wrapped); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 823 | VIA("serialize", ViaSerialization, wrapped); |
mtklein | 4a34ecb | 2016-01-08 10:19:35 -0800 | [diff] [blame] | 824 | VIA("pic", ViaPicture, wrapped); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 825 | VIA("2ndpic", ViaSecondPicture, wrapped); |
mtklein | d31c13d | 2015-05-05 12:59:56 -0700 | [diff] [blame] | 826 | VIA("sp", ViaSingletonPictures, wrapped); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 827 | VIA("tiles", ViaTiles, 256, 256, nullptr, wrapped); |
mtklein | 7edca21 | 2015-01-21 13:18:51 -0800 | [diff] [blame] | 828 | VIA("tiles_rt", ViaTiles, 256, 256, new SkRTreeFactory, wrapped); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 829 | |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 830 | if (FLAGS_matrix.count() == 4) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 831 | SkMatrix m; |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 832 | m.reset(); |
| 833 | m.setScaleX((SkScalar)atof(FLAGS_matrix[0])); |
| 834 | m.setSkewX ((SkScalar)atof(FLAGS_matrix[1])); |
| 835 | m.setSkewY ((SkScalar)atof(FLAGS_matrix[2])); |
| 836 | m.setScaleY((SkScalar)atof(FLAGS_matrix[3])); |
| 837 | VIA("matrix", ViaMatrix, m, wrapped); |
| 838 | VIA("upright", ViaUpright, m, wrapped); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 839 | } |
tomhudson | 64de1e1 | 2015-03-05 08:01:07 -0800 | [diff] [blame] | 840 | |
| 841 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 842 | VIA("androidsdk", ViaAndroidSDK, wrapped); |
| 843 | #endif |
| 844 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 845 | #undef VIA |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 846 | return nullptr; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 847 | } |
| 848 | |
brianosman | 05c987c | 2016-05-09 13:42:16 -0700 | [diff] [blame] | 849 | static bool gather_sinks() { |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 850 | SkCommandLineConfigArray configs; |
| 851 | ParseConfigs(FLAGS_config, &configs); |
| 852 | for (int i = 0; i < configs.count(); i++) { |
| 853 | const SkCommandLineConfig& config = *configs[i]; |
| 854 | Sink* sink = create_sink(&config); |
| 855 | if (sink == nullptr) { |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 856 | info("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(), |
| 857 | config.getTag().c_str()); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 858 | continue; |
| 859 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 860 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 861 | const SkTArray<SkString>& parts = config.getViaParts(); |
| 862 | for (int j = parts.count(); j-- > 0;) { |
| 863 | const SkString& part = parts[j]; |
| 864 | Sink* next = create_via(part, sink); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 865 | if (next == nullptr) { |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 866 | info("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(), |
| 867 | part.c_str()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 868 | delete sink; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 869 | sink = nullptr; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 870 | break; |
| 871 | } |
| 872 | sink = next; |
| 873 | } |
| 874 | if (sink) { |
| 875 | push_sink(config, sink); |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 876 | } |
| 877 | } |
brianosman | 05c987c | 2016-05-09 13:42:16 -0700 | [diff] [blame] | 878 | |
| 879 | // If no configs were requested (just running tests, perhaps?), then we're okay. |
| 880 | // Otherwise, make sure that at least one sink was constructed correctly. This catches |
| 881 | // the case of bots without a GPU being assigned GPU configs. |
| 882 | return (configs.count() == 0) || (gSinks.count() > 0); |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 883 | } |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 884 | |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 885 | static bool dump_png(SkBitmap bitmap, const char* path, const char* md5) { |
| 886 | const int w = bitmap.width(), |
| 887 | h = bitmap.height(); |
| 888 | |
brianosman | 3c579dc | 2016-04-19 09:18:11 -0700 | [diff] [blame] | 889 | sk_sp<SkData> encodedBitmap = sk_tools::encode_bitmap_for_png(bitmap); |
| 890 | if (encodedBitmap.get() == nullptr) { |
| 891 | return false; |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 892 | } |
brianosman | 3c579dc | 2016-04-19 09:18:11 -0700 | [diff] [blame] | 893 | uint32_t* rgba = static_cast<uint32_t*>(encodedBitmap.get()->writable_data()); |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 894 | |
| 895 | // We don't need bitmap anymore. Might as well drop our ref. |
mtklein | fccb77d | 2015-08-24 14:13:29 -0700 | [diff] [blame] | 896 | bitmap.reset(); |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 897 | |
mtklein | c64137c | 2015-08-25 10:56:08 -0700 | [diff] [blame] | 898 | FILE* f = fopen(path, "wb"); |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 899 | if (!f) { return false; } |
| 900 | |
| 901 | png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr); |
| 902 | if (!png) { |
| 903 | fclose(f); |
| 904 | return false; |
| 905 | } |
| 906 | |
| 907 | png_infop info = png_create_info_struct(png); |
| 908 | if (!info) { |
| 909 | png_destroy_write_struct(&png, &info); |
| 910 | fclose(f); |
| 911 | return false; |
| 912 | } |
| 913 | |
mtklein | d69ece6 | 2015-09-10 10:37:44 -0700 | [diff] [blame] | 914 | SkString description; |
| 915 | description.append("Key: "); |
| 916 | for (int i = 0; i < FLAGS_key.count(); i++) { |
| 917 | description.appendf("%s ", FLAGS_key[i]); |
| 918 | } |
| 919 | description.append("Properties: "); |
| 920 | for (int i = 0; i < FLAGS_properties.count(); i++) { |
| 921 | description.appendf("%s ", FLAGS_properties[i]); |
| 922 | } |
| 923 | description.appendf("MD5: %s", md5); |
| 924 | |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 925 | png_text text[2]; |
| 926 | text[0].key = (png_charp)"Author"; |
| 927 | text[0].text = (png_charp)"DM dump_png()"; |
| 928 | text[0].compression = PNG_TEXT_COMPRESSION_NONE; |
| 929 | text[1].key = (png_charp)"Description"; |
mtklein | d69ece6 | 2015-09-10 10:37:44 -0700 | [diff] [blame] | 930 | text[1].text = (png_charp)description.c_str(); |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 931 | text[1].compression = PNG_TEXT_COMPRESSION_NONE; |
| 932 | png_set_text(png, info, text, 2); |
| 933 | |
| 934 | png_init_io(png, f); |
| 935 | png_set_IHDR(png, info, (png_uint_32)w, (png_uint_32)h, 8, |
| 936 | PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, |
| 937 | PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); |
| 938 | png_write_info(png, info); |
| 939 | for (int j = 0; j < h; j++) { |
brianosman | 3c579dc | 2016-04-19 09:18:11 -0700 | [diff] [blame] | 940 | png_bytep row = (png_bytep)(rgba + w*j); |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 941 | png_write_rows(png, &row, 1); |
| 942 | } |
| 943 | png_write_end(png, info); |
| 944 | |
| 945 | png_destroy_write_struct(&png, &info); |
| 946 | fclose(f); |
| 947 | return true; |
| 948 | } |
| 949 | |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 950 | static bool match(const char* needle, const char* haystack) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 951 | return 0 == strcmp("_", needle) || nullptr != strstr(haystack, needle); |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 952 | } |
| 953 | |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 954 | static bool is_blacklisted(const char* sink, const char* src, |
| 955 | const char* srcOptions, const char* name) { |
mtklein | 0d243ff | 2015-04-03 07:51:00 -0700 | [diff] [blame] | 956 | for (int i = 0; i < FLAGS_blacklist.count() - 3; i += 4) { |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 957 | if (match(FLAGS_blacklist[i+0], sink) && |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 958 | match(FLAGS_blacklist[i+1], src) && |
| 959 | match(FLAGS_blacklist[i+2], srcOptions) && |
| 960 | match(FLAGS_blacklist[i+3], name)) { |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 961 | return true; |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 962 | } |
| 963 | } |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 964 | return false; |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 965 | } |
| 966 | |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 967 | // Even when a Task Sink reports to be non-threadsafe (e.g. GPU), we know things like |
| 968 | // .png encoding are definitely thread safe. This lets us offload that work to CPU threads. |
| 969 | static SkTaskGroup gDefinitelyThreadSafeWork; |
| 970 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 971 | // The finest-grained unit of work we can run: draw a single Src into a single Sink, |
| 972 | // report any errors, and perhaps write out the output: a .png of the bitmap, or a raw stream. |
| 973 | struct Task { |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 974 | Task(const TaggedSrc& src, const TaggedSink& sink) : src(src), sink(sink) {} |
| 975 | const TaggedSrc& src; |
| 976 | const TaggedSink& sink; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 977 | |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 978 | static void Run(const Task& task) { |
| 979 | SkString name = task.src->name(); |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 980 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 981 | SkString log; |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 982 | if (!FLAGS_dryRun) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 983 | SkBitmap bitmap; |
| 984 | SkDynamicMemoryWStream stream; |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 985 | start(task.sink.tag.c_str(), task.src.tag.c_str(), |
| 986 | task.src.options.c_str(), name.c_str()); |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 987 | Error err = task.sink->draw(*task.src, &bitmap, &stream, &log); |
mtklein | b3b13b7 | 2016-03-07 13:20:52 -0800 | [diff] [blame] | 988 | if (!log.isEmpty()) { |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 989 | info("%s %s %s %s:\n%s\n", task.sink.tag.c_str() |
| 990 | , task.src.tag.c_str() |
| 991 | , task.src.options.c_str() |
| 992 | , name.c_str() |
| 993 | , log.c_str()); |
mtklein | b3b13b7 | 2016-03-07 13:20:52 -0800 | [diff] [blame] | 994 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 995 | if (!err.isEmpty()) { |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 996 | if (err.isFatal()) { |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 997 | fail(SkStringPrintf("%s %s %s %s: %s", |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 998 | task.sink.tag.c_str(), |
| 999 | task.src.tag.c_str(), |
| 1000 | task.src.options.c_str(), |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 1001 | name.c_str(), |
| 1002 | err.c_str())); |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 1003 | } else { |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1004 | done(task.sink.tag.c_str(), task.src.tag.c_str(), |
| 1005 | task.src.options.c_str(), name.c_str()); |
mtklein | ba6ada7 | 2016-01-21 09:39:35 -0800 | [diff] [blame] | 1006 | return; |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 1007 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1008 | } |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 1009 | |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1010 | // We're likely switching threads here, so we must capture by value, [=] or [foo,bar]. |
| 1011 | SkStreamAsset* data = stream.detachAsStream(); |
| 1012 | gDefinitelyThreadSafeWork.add([task,name,bitmap,data]{ |
| 1013 | SkAutoTDelete<SkStreamAsset> ownedData(data); |
| 1014 | |
| 1015 | // Why doesn't the copy constructor do this when we have pre-locked pixels? |
| 1016 | bitmap.lockPixels(); |
| 1017 | |
| 1018 | SkString md5; |
| 1019 | if (!FLAGS_writePath.isEmpty() || !FLAGS_readPath.isEmpty()) { |
| 1020 | SkMD5 hash; |
| 1021 | if (data->getLength()) { |
| 1022 | hash.writeStream(data, data->getLength()); |
| 1023 | data->rewind(); |
mtklein | 3840846 | 2015-07-08 07:25:27 -0700 | [diff] [blame] | 1024 | } else { |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1025 | // If we're BGRA (Linux, Windows), swizzle over to RGBA (Mac, Android). |
| 1026 | // This helps eliminate multiple 0-pixel-diff hashes on gold.skia.org. |
| 1027 | // (Android's general slow speed breaks the tie arbitrarily in RGBA's favor.) |
| 1028 | // We might consider promoting 565 to RGBA too. |
| 1029 | if (bitmap.colorType() == kBGRA_8888_SkColorType) { |
| 1030 | SkBitmap swizzle; |
| 1031 | SkAssertResult(bitmap.copyTo(&swizzle, kRGBA_8888_SkColorType)); |
| 1032 | hash.write(swizzle.getPixels(), swizzle.getSize()); |
| 1033 | } else { |
| 1034 | hash.write(bitmap.getPixels(), bitmap.getSize()); |
| 1035 | } |
| 1036 | } |
| 1037 | SkMD5::Digest digest; |
| 1038 | hash.finish(digest); |
| 1039 | for (int i = 0; i < 16; i++) { |
| 1040 | md5.appendf("%02x", digest.data[i]); |
mtklein | 3840846 | 2015-07-08 07:25:27 -0700 | [diff] [blame] | 1041 | } |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 1042 | } |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 1043 | |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1044 | if (!FLAGS_readPath.isEmpty() && |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1045 | !gGold.contains(Gold(task.sink.tag, task.src.tag, |
| 1046 | task.src.options, name, md5))) { |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1047 | fail(SkStringPrintf("%s not found for %s %s %s %s in %s", |
| 1048 | md5.c_str(), |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1049 | task.sink.tag.c_str(), |
| 1050 | task.src.tag.c_str(), |
| 1051 | task.src.options.c_str(), |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1052 | name.c_str(), |
| 1053 | FLAGS_readPath[0])); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1054 | } |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1055 | |
| 1056 | if (!FLAGS_writePath.isEmpty()) { |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1057 | const char* ext = task.sink->fileExtension(); |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1058 | if (data->getLength()) { |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1059 | WriteToDisk(task, md5, ext, data, data->getLength(), nullptr); |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1060 | SkASSERT(bitmap.drawsNothing()); |
| 1061 | } else if (!bitmap.drawsNothing()) { |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1062 | WriteToDisk(task, md5, ext, nullptr, 0, &bitmap); |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1063 | } |
| 1064 | } |
| 1065 | }); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1066 | } |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1067 | done(task.sink.tag.c_str(), task.src.tag.c_str(), task.src.options.c_str(), name.c_str()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1068 | } |
| 1069 | |
| 1070 | static void WriteToDisk(const Task& task, |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 1071 | SkString md5, |
| 1072 | const char* ext, |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1073 | SkStream* data, size_t len, |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 1074 | const SkBitmap* bitmap) { |
mtklein | 409d470 | 2016-02-29 07:38:01 -0800 | [diff] [blame] | 1075 | bool gammaCorrect = false; |
| 1076 | if (bitmap) { |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame] | 1077 | gammaCorrect = SkImageInfoIsGammaCorrect(bitmap->info()); |
mtklein | 409d470 | 2016-02-29 07:38:01 -0800 | [diff] [blame] | 1078 | } |
| 1079 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1080 | JsonWriter::BitmapResult result; |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 1081 | result.name = task.src->name(); |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1082 | result.config = task.sink.tag; |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 1083 | result.sourceType = task.src.tag; |
| 1084 | result.sourceOptions = task.src.options; |
| 1085 | result.ext = ext; |
mtklein | 409d470 | 2016-02-29 07:38:01 -0800 | [diff] [blame] | 1086 | result.gammaCorrect = gammaCorrect; |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 1087 | result.md5 = md5; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1088 | JsonWriter::AddBitmapResult(result); |
| 1089 | |
mtklein | b0531a7 | 2015-04-07 13:38:48 -0700 | [diff] [blame] | 1090 | // If an MD5 is uninteresting, we want it noted in the JSON file, |
| 1091 | // but don't want to dump it out as a .png (or whatever ext is). |
| 1092 | if (gUninterestingHashes.contains(md5)) { |
| 1093 | return; |
| 1094 | } |
| 1095 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1096 | const char* dir = FLAGS_writePath[0]; |
| 1097 | if (0 == strcmp(dir, "@")) { // Needed for iOS. |
| 1098 | dir = FLAGS_resourcePath[0]; |
| 1099 | } |
| 1100 | sk_mkdir(dir); |
| 1101 | |
| 1102 | SkString path; |
| 1103 | if (FLAGS_nameByHash) { |
| 1104 | path = SkOSPath::Join(dir, result.md5.c_str()); |
| 1105 | path.append("."); |
| 1106 | path.append(ext); |
| 1107 | if (sk_exists(path.c_str())) { |
| 1108 | return; // Content-addressed. If it exists already, we're done. |
| 1109 | } |
| 1110 | } else { |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 1111 | path = SkOSPath::Join(dir, task.sink.tag.c_str()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1112 | sk_mkdir(path.c_str()); |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 1113 | path = SkOSPath::Join(path.c_str(), task.src.tag.c_str()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1114 | sk_mkdir(path.c_str()); |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 1115 | if (strcmp(task.src.options.c_str(), "") != 0) { |
| 1116 | path = SkOSPath::Join(path.c_str(), task.src.options.c_str()); |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 1117 | sk_mkdir(path.c_str()); |
| 1118 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1119 | path = SkOSPath::Join(path.c_str(), task.src->name().c_str()); |
| 1120 | path.append("."); |
| 1121 | path.append(ext); |
| 1122 | } |
| 1123 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1124 | if (bitmap) { |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 1125 | if (!dump_png(*bitmap, path.c_str(), result.md5.c_str())) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1126 | fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str())); |
| 1127 | return; |
| 1128 | } |
| 1129 | } else { |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 1130 | SkFILEWStream file(path.c_str()); |
| 1131 | if (!file.isValid()) { |
| 1132 | fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str())); |
| 1133 | return; |
| 1134 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1135 | if (!file.writeStream(data, len)) { |
| 1136 | fail(SkStringPrintf("Can't write to %s.\n", path.c_str())); |
| 1137 | return; |
| 1138 | } |
| 1139 | } |
| 1140 | } |
| 1141 | }; |
| 1142 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1143 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 1144 | |
| 1145 | // Unit tests don't fit so well into the Src/Sink model, so we give them special treatment. |
| 1146 | |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1147 | static SkTDArray<skiatest::Test> gParallelTests, gSerialTests; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1148 | |
| 1149 | static void gather_tests() { |
mtklein | 6c5fed2 | 2015-01-20 13:47:23 -0800 | [diff] [blame] | 1150 | if (!FLAGS_src.contains("tests")) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1151 | return; |
| 1152 | } |
mtklein | 6393c06 | 2015-04-27 08:45:01 -0700 | [diff] [blame] | 1153 | for (const skiatest::TestRegistry* r = skiatest::TestRegistry::Head(); r; r = r->next()) { |
| 1154 | if (!in_shard()) { |
| 1155 | continue; |
| 1156 | } |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1157 | // Despite its name, factory() is returning a reference to |
| 1158 | // link-time static const POD data. |
| 1159 | const skiatest::Test& test = r->factory(); |
| 1160 | if (SkCommandLineFlags::ShouldSkip(FLAGS_match, test.name)) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1161 | continue; |
| 1162 | } |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1163 | if (test.needsGpu && gpu_supported()) { |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1164 | (FLAGS_gpu_threading ? gParallelTests : gSerialTests).push(test); |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1165 | } else if (!test.needsGpu && FLAGS_cpu) { |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1166 | gParallelTests.push(test); |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 1167 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1168 | } |
| 1169 | } |
| 1170 | |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1171 | static void run_test(skiatest::Test test) { |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1172 | struct : public skiatest::Reporter { |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 1173 | void reportFailed(const skiatest::Failure& failure) override { |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1174 | fail(failure.toString()); |
| 1175 | JsonWriter::AddTestFailure(failure); |
| 1176 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 1177 | bool allowExtendedTest() const override { |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1178 | return FLAGS_pathOpsExtended; |
| 1179 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 1180 | bool verbose() const override { return FLAGS_veryVerbose; } |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1181 | } reporter; |
djsollen | 824996a | 2015-06-12 12:06:22 -0700 | [diff] [blame] | 1182 | |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1183 | if (!FLAGS_dryRun && !is_blacklisted("_", "tests", "_", test.name)) { |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1184 | start("unit", "test", "", test.name); |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 1185 | GrContextFactory factory; |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1186 | test.proc(&reporter, &factory); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1187 | } |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1188 | done("unit", "test", "", test.name); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1189 | } |
| 1190 | |
| 1191 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 1192 | |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 1193 | DEFINE_int32(status_sec, 15, "Print status this often (and if we crash)."); |
| 1194 | |
| 1195 | SkThread* start_status_thread() { |
| 1196 | auto thread = new SkThread([] (void*) { |
| 1197 | for (;;) { |
| 1198 | print_status(); |
| 1199 | #if defined(SK_BUILD_FOR_WIN) |
| 1200 | Sleep(FLAGS_status_sec * 1000); |
| 1201 | #else |
| 1202 | sleep(FLAGS_status_sec); |
| 1203 | #endif |
mtklein | 2e1c47e | 2015-03-12 07:16:56 -0700 | [diff] [blame] | 1204 | } |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 1205 | }); |
| 1206 | thread->start(); |
| 1207 | return thread; |
mtklein | de6fc2b | 2015-03-12 06:28:54 -0700 | [diff] [blame] | 1208 | } |
| 1209 | |
caryclark | 83ca628 | 2015-06-10 09:31:09 -0700 | [diff] [blame] | 1210 | #define PORTABLE_FONT_PREFIX "Toy Liberation " |
| 1211 | |
bungeman | 13b9c95 | 2016-05-12 10:09:30 -0700 | [diff] [blame] | 1212 | static sk_sp<SkTypeface> create_from_name(const char familyName[], SkTypeface::Style style) { |
caryclark | 83ca628 | 2015-06-10 09:31:09 -0700 | [diff] [blame] | 1213 | if (familyName && strlen(familyName) > sizeof(PORTABLE_FONT_PREFIX) |
| 1214 | && !strncmp(familyName, PORTABLE_FONT_PREFIX, sizeof(PORTABLE_FONT_PREFIX) - 1)) { |
caryclark | 1818acb | 2015-07-24 12:09:25 -0700 | [diff] [blame] | 1215 | return sk_tool_utils::create_portable_typeface(familyName, style); |
caryclark | 83ca628 | 2015-06-10 09:31:09 -0700 | [diff] [blame] | 1216 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1217 | return nullptr; |
caryclark | 83ca628 | 2015-06-10 09:31:09 -0700 | [diff] [blame] | 1218 | } |
| 1219 | |
| 1220 | #undef PORTABLE_FONT_PREFIX |
| 1221 | |
bungeman | 13b9c95 | 2016-05-12 10:09:30 -0700 | [diff] [blame] | 1222 | extern sk_sp<SkTypeface> (*gCreateTypefaceDelegate)(const char [], SkTypeface::Style ); |
caryclark | 83ca628 | 2015-06-10 09:31:09 -0700 | [diff] [blame] | 1223 | |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 1224 | int dm_main(); |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 1225 | int dm_main() { |
bsalomon | 71de353 | 2016-04-26 14:27:21 -0700 | [diff] [blame] | 1226 | setbuf(stdout, nullptr); |
mtklein | 246ba3a | 2016-02-23 10:39:36 -0800 | [diff] [blame] | 1227 | setup_crash_handler(); |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 1228 | |
mtklein | a483da3 | 2016-03-17 12:53:36 -0700 | [diff] [blame] | 1229 | if (FLAGS_verbose) { |
| 1230 | gVLog = stderr; |
| 1231 | } else if (!FLAGS_writePath.isEmpty()) { |
mtklein | 51c8cfc | 2016-03-11 12:59:09 -0800 | [diff] [blame] | 1232 | sk_mkdir(FLAGS_writePath[0]); |
| 1233 | gVLog = freopen(SkOSPath::Join(FLAGS_writePath[0], "verbose.log").c_str(), "w", stderr); |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 1234 | } |
| 1235 | |
mtklein | 5286f02 | 2016-01-22 08:18:14 -0800 | [diff] [blame] | 1236 | JsonWriter::DumpJson(); // It's handy for the bots to assume this is ~never missing. |
commit-bot@chromium.org | 39e8d93 | 2014-05-29 20:14:48 +0000 | [diff] [blame] | 1237 | SkAutoGraphics ag; |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 1238 | SkTaskGroup::Enabler enabled(FLAGS_threads); |
caryclark | 83ca628 | 2015-06-10 09:31:09 -0700 | [diff] [blame] | 1239 | gCreateTypefaceDelegate = &create_from_name; |
commit-bot@chromium.org | a65e2fd | 2014-05-30 17:23:31 +0000 | [diff] [blame] | 1240 | |
halcanary | 7d57124 | 2016-02-24 17:59:16 -0800 | [diff] [blame] | 1241 | { |
| 1242 | SkString testResourcePath = GetResourcePath("color_wheel.png"); |
| 1243 | SkFILEStream testResource(testResourcePath.c_str()); |
| 1244 | if (!testResource.isValid()) { |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 1245 | info("Some resources are missing. Do you need to set --resourcePath?\n"); |
halcanary | 7d57124 | 2016-02-24 17:59:16 -0800 | [diff] [blame] | 1246 | } |
| 1247 | } |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 1248 | gather_gold(); |
borenet | 09ed480 | 2015-04-03 14:15:33 -0700 | [diff] [blame] | 1249 | gather_uninteresting_hashes(); |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 1250 | |
scroggo | 8673714 | 2016-02-03 12:19:11 -0800 | [diff] [blame] | 1251 | if (!gather_srcs()) { |
| 1252 | return 1; |
| 1253 | } |
brianosman | 05c987c | 2016-05-09 13:42:16 -0700 | [diff] [blame] | 1254 | if (!gather_sinks()) { |
| 1255 | return 1; |
| 1256 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1257 | gather_tests(); |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1258 | gPending = gSrcs.count() * gSinks.count() + gParallelTests.count() + gSerialTests.count(); |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 1259 | info("%d srcs * %d sinks + %d tests == %d tasks", |
| 1260 | gSrcs.count(), gSinks.count(), gParallelTests.count() + gSerialTests.count(), gPending); |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 1261 | SkAutoTDelete<SkThread> statusThread(start_status_thread()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1262 | |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1263 | // Kick off as much parallel work as we can, making note of any serial work we'll need to do. |
| 1264 | SkTaskGroup parallel; |
| 1265 | SkTArray<Task> serial; |
| 1266 | |
| 1267 | for (auto& sink : gSinks) |
| 1268 | for (auto& src : gSrcs) { |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1269 | if (src->veto(sink->flags()) || |
| 1270 | is_blacklisted(sink.tag.c_str(), src.tag.c_str(), |
| 1271 | src.options.c_str(), src->name().c_str())) { |
mtklein | 15923c9 | 2016-02-29 10:14:38 -0800 | [diff] [blame] | 1272 | SkAutoTAcquire<SkSpinlock> lock(gMutex); |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1273 | gPending--; |
| 1274 | continue; |
| 1275 | } |
| 1276 | |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1277 | Task task(src, sink); |
| 1278 | if (src->serial() || sink->serial()) { |
| 1279 | serial.push_back(task); |
| 1280 | } else { |
| 1281 | parallel.add([task] { Task::Run(task); }); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1282 | } |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 1283 | } |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1284 | for (auto test : gParallelTests) { |
| 1285 | parallel.add([test] { run_test(test); }); |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 1286 | } |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1287 | |
| 1288 | // With the parallel work running, run serial tasks and tests here on main thread. |
| 1289 | for (auto task : serial) { Task::Run(task); } |
| 1290 | for (auto test : gSerialTests) { run_test(test); } |
| 1291 | |
| 1292 | // Wait for any remaining parallel work to complete (including any spun off of serial tasks). |
| 1293 | parallel.wait(); |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1294 | gDefinitelyThreadSafeWork.wait(); |
| 1295 | |
mtklein | da884c4 | 2016-02-24 18:00:23 -0800 | [diff] [blame] | 1296 | // We'd better have run everything. |
| 1297 | SkASSERT(gPending == 0); |
mtklein | e027f17 | 2016-02-26 15:53:06 -0800 | [diff] [blame] | 1298 | // Make sure we've flushed all our results to disk. |
| 1299 | JsonWriter::DumpJson(); |
mtklein | da884c4 | 2016-02-24 18:00:23 -0800 | [diff] [blame] | 1300 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1301 | // At this point we're back in single-threaded land. |
caryclark | f53ce80 | 2015-06-15 06:48:30 -0700 | [diff] [blame] | 1302 | sk_tool_utils::release_portable_typefaces(); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 1303 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1304 | if (gFailures.count() > 0) { |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 1305 | info("Failures:\n"); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1306 | for (int i = 0; i < gFailures.count(); i++) { |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 1307 | info("\t%s\n", gFailures[i].c_str()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1308 | } |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 1309 | info("%d failures\n", gFailures.count()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1310 | return 1; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 1311 | } |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 1312 | |
| 1313 | #ifdef SK_PDF_IMAGE_STATS |
halcanary | 7a14b31 | 2015-10-01 07:28:13 -0700 | [diff] [blame] | 1314 | SkPDFImageDumpStats(); |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 1315 | #endif // SK_PDF_IMAGE_STATS |
| 1316 | |
| 1317 | print_status(); |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 1318 | info("Finished!\n"); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1319 | return 0; |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 1320 | } |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 1321 | |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1322 | // TODO: currently many GPU tests are declared outside SK_SUPPORT_GPU guards. |
| 1323 | // Thus we export the empty RunWithGPUTestContexts when SK_SUPPORT_GPU=0. |
| 1324 | namespace skiatest { |
bsalomon | 758586c | 2016-04-06 14:02:39 -0700 | [diff] [blame] | 1325 | |
| 1326 | #if SK_SUPPORT_GPU |
| 1327 | bool IsGLContextType(sk_gpu_test::GrContextFactory::ContextType type) { |
| 1328 | return kOpenGL_GrBackend == GrContextFactory::ContextTypeBackend(type); |
| 1329 | } |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 1330 | bool IsVulkanContextType(sk_gpu_test::GrContextFactory::ContextType type) { |
| 1331 | return kVulkan_GrBackend == GrContextFactory::ContextTypeBackend(type); |
| 1332 | } |
bsalomon | 758586c | 2016-04-06 14:02:39 -0700 | [diff] [blame] | 1333 | bool IsRenderingGLContextType(sk_gpu_test::GrContextFactory::ContextType type) { |
| 1334 | return IsGLContextType(type) && GrContextFactory::IsRenderingContext(type); |
| 1335 | } |
| 1336 | bool IsNullGLContextType(sk_gpu_test::GrContextFactory::ContextType type) { |
| 1337 | return type == GrContextFactory::kNullGL_ContextType; |
| 1338 | } |
| 1339 | #else |
| 1340 | bool IsGLContextType(int) { return false; } |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 1341 | bool IsVulkanContextType(int) { return false; } |
bsalomon | 758586c | 2016-04-06 14:02:39 -0700 | [diff] [blame] | 1342 | bool IsRenderingGLContextType(int) { return false; } |
| 1343 | bool IsNullGLContextType(int) { return false; } |
| 1344 | #endif |
| 1345 | |
| 1346 | void RunWithGPUTestContexts(GrContextTestFn* test, GrContextTypeFilterFn* contextTypeFilter, |
bsalomon | f2f1c17 | 2016-04-05 12:59:06 -0700 | [diff] [blame] | 1347 | Reporter* reporter, GrContextFactory* factory) { |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1348 | #if SK_SUPPORT_GPU |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 1349 | |
bsalomon | 758586c | 2016-04-06 14:02:39 -0700 | [diff] [blame] | 1350 | for (int typeInt = 0; typeInt < GrContextFactory::kContextTypeCnt; ++typeInt) { |
| 1351 | GrContextFactory::ContextType contextType = (GrContextFactory::ContextType) typeInt; |
| 1352 | ContextInfo ctxInfo = factory->getContextInfo(contextType); |
bsalomon | fda8807 | 2016-04-11 14:40:50 -0700 | [diff] [blame] | 1353 | if (contextTypeFilter && !(*contextTypeFilter)(contextType)) { |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1354 | continue; |
| 1355 | } |
bsalomon | 758586c | 2016-04-06 14:02:39 -0700 | [diff] [blame] | 1356 | // Use "native" instead of explicitly trying OpenGL and OpenGL ES. Do not use GLES on, |
| 1357 | // desktop since tests do not account for not fixing http://skbug.com/2809 |
| 1358 | if (contextType == GrContextFactory::kGL_ContextType || |
| 1359 | contextType == GrContextFactory::kGLES_ContextType) { |
| 1360 | if (contextType != GrContextFactory::kNativeGL_ContextType) { |
| 1361 | continue; |
| 1362 | } |
| 1363 | } |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 1364 | if (ctxInfo.grContext()) { |
bsalomon | f2f1c17 | 2016-04-05 12:59:06 -0700 | [diff] [blame] | 1365 | (*test)(reporter, ctxInfo); |
kkinnunen | 5219fd9 | 2015-12-10 06:28:13 -0800 | [diff] [blame] | 1366 | } |
bsalomon | f2f1c17 | 2016-04-05 12:59:06 -0700 | [diff] [blame] | 1367 | ctxInfo = factory->getContextInfo(contextType, |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 1368 | GrContextFactory::kEnableNVPR_ContextOptions); |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 1369 | if (ctxInfo.grContext()) { |
bsalomon | f2f1c17 | 2016-04-05 12:59:06 -0700 | [diff] [blame] | 1370 | (*test)(reporter, ctxInfo); |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1371 | } |
| 1372 | } |
| 1373 | #endif |
| 1374 | } |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1375 | } // namespace skiatest |
| 1376 | |
borenet | 4808757 | 2015-04-02 12:16:36 -0700 | [diff] [blame] | 1377 | #if !defined(SK_BUILD_FOR_IOS) |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 1378 | int main(int argc, char** argv) { |
| 1379 | SkCommandLineFlags::Parse(argc, argv); |
| 1380 | return dm_main(); |
| 1381 | } |
| 1382 | #endif |