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