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; |
msarett | b65e604 | 2016-02-23 05:37:25 -0800 | [diff] [blame] | 488 | case SkEncodedFormat::kRAW_SkEncodedFormat: |
| 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 | 744898a | 2016-03-01 13:44:28 -0800 | [diff] [blame] | 818 | gpuConfig->getUseDIText(), FLAGS_gpu_threading); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 819 | } |
| 820 | } |
| 821 | #endif |
| 822 | |
| 823 | #define SINK(t, sink, ...) if (config->getBackend().equals(t)) { return new sink(__VA_ARGS__); } |
| 824 | |
tomhudson | eebc39a | 2015-02-23 12:18:05 -0800 | [diff] [blame] | 825 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 826 | SINK("hwui", HWUISink); |
| 827 | #endif |
| 828 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 829 | if (FLAGS_cpu) { |
| 830 | SINK("565", RasterSink, kRGB_565_SkColorType); |
| 831 | SINK("8888", RasterSink, kN32_SkColorType); |
mtklein | 27c3fdd | 2016-02-26 14:43:21 -0800 | [diff] [blame] | 832 | SINK("srgb", RasterSink, kN32_SkColorType, kSRGB_SkColorProfileType); |
| 833 | SINK("f16", RasterSink, kRGBA_F16_SkColorType); |
halcanary | c11c62f | 2015-09-28 11:51:54 -0700 | [diff] [blame] | 834 | SINK("pdf", PDFSink, "Pdfium"); |
| 835 | SINK("pdf_poppler", PDFSink, "Poppler"); |
mtklein | 9c3f17d | 2015-01-28 11:35:18 -0800 | [diff] [blame] | 836 | SINK("skp", SKPSink); |
mtklein | 8a4527e | 2015-01-31 20:00:58 -0800 | [diff] [blame] | 837 | SINK("svg", SVGSink); |
| 838 | SINK("null", NullSink); |
halcanary | 47ef4d5 | 2015-03-03 09:13:09 -0800 | [diff] [blame] | 839 | SINK("xps", XPSSink); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 840 | } |
| 841 | #undef SINK |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 842 | return nullptr; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 843 | } |
| 844 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 845 | static Sink* create_via(const SkString& tag, Sink* wrapped) { |
| 846 | #define VIA(t, via, ...) if (tag.equals(t)) { return new via(__VA_ARGS__); } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 847 | VIA("twice", ViaTwice, wrapped); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 848 | VIA("serialize", ViaSerialization, wrapped); |
mtklein | 4a34ecb | 2016-01-08 10:19:35 -0800 | [diff] [blame] | 849 | VIA("pic", ViaPicture, wrapped); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 850 | VIA("2ndpic", ViaSecondPicture, wrapped); |
mtklein | d31c13d | 2015-05-05 12:59:56 -0700 | [diff] [blame] | 851 | VIA("sp", ViaSingletonPictures, wrapped); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 852 | VIA("tiles", ViaTiles, 256, 256, nullptr, wrapped); |
mtklein | 7edca21 | 2015-01-21 13:18:51 -0800 | [diff] [blame] | 853 | VIA("tiles_rt", ViaTiles, 256, 256, new SkRTreeFactory, wrapped); |
halcanary | 7a76f9c | 2016-02-03 11:53:18 -0800 | [diff] [blame] | 854 | VIA("mojo", ViaMojo, wrapped); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 855 | |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 856 | if (FLAGS_matrix.count() == 4) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 857 | SkMatrix m; |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 858 | m.reset(); |
| 859 | m.setScaleX((SkScalar)atof(FLAGS_matrix[0])); |
| 860 | m.setSkewX ((SkScalar)atof(FLAGS_matrix[1])); |
| 861 | m.setSkewY ((SkScalar)atof(FLAGS_matrix[2])); |
| 862 | m.setScaleY((SkScalar)atof(FLAGS_matrix[3])); |
| 863 | VIA("matrix", ViaMatrix, m, wrapped); |
| 864 | VIA("upright", ViaUpright, m, wrapped); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 865 | } |
tomhudson | 64de1e1 | 2015-03-05 08:01:07 -0800 | [diff] [blame] | 866 | |
| 867 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 868 | VIA("androidsdk", ViaAndroidSDK, wrapped); |
| 869 | #endif |
| 870 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 871 | #undef VIA |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 872 | return nullptr; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 873 | } |
| 874 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 875 | static void gather_sinks() { |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 876 | SkCommandLineConfigArray configs; |
| 877 | ParseConfigs(FLAGS_config, &configs); |
| 878 | for (int i = 0; i < configs.count(); i++) { |
| 879 | const SkCommandLineConfig& config = *configs[i]; |
| 880 | Sink* sink = create_sink(&config); |
| 881 | if (sink == nullptr) { |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 882 | info("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(), |
| 883 | config.getTag().c_str()); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 884 | continue; |
| 885 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 886 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 887 | const SkTArray<SkString>& parts = config.getViaParts(); |
| 888 | for (int j = parts.count(); j-- > 0;) { |
| 889 | const SkString& part = parts[j]; |
| 890 | Sink* next = create_via(part, sink); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 891 | if (next == nullptr) { |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 892 | info("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(), |
| 893 | part.c_str()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 894 | delete sink; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 895 | sink = nullptr; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 896 | break; |
| 897 | } |
| 898 | sink = next; |
| 899 | } |
| 900 | if (sink) { |
| 901 | push_sink(config, sink); |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 902 | } |
| 903 | } |
| 904 | } |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 905 | |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 906 | static bool dump_png(SkBitmap bitmap, const char* path, const char* md5) { |
| 907 | const int w = bitmap.width(), |
| 908 | h = bitmap.height(); |
mtklein | 27c3fdd | 2016-02-26 14:43:21 -0800 | [diff] [blame] | 909 | // PNG wants unpremultiplied 8-bit RGBA pixels (16-bit could work fine too). |
| 910 | // We leave the gamma of these bytes unspecified, to continue the status quo, |
| 911 | // which we think generally is to interpret them as sRGB. |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 912 | |
mtklein | 27c3fdd | 2016-02-26 14:43:21 -0800 | [diff] [blame] | 913 | SkAutoTMalloc<uint32_t> rgba(w*h); |
| 914 | |
| 915 | if (bitmap. colorType() == kN32_SkColorType && |
| 916 | bitmap.profileType() == kSRGB_SkColorProfileType) { |
| 917 | // These are premul sRGB 8-bit pixels in SkPMColor order. |
| 918 | // We want unpremul sRGB 8-bit pixels in RGBA order. We'll get there via floats. |
| 919 | bitmap.lockPixels(); |
| 920 | auto px = (const uint32_t*)bitmap.getPixels(); |
| 921 | if (!px) { |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 922 | return false; |
| 923 | } |
mtklein | 27c3fdd | 2016-02-26 14:43:21 -0800 | [diff] [blame] | 924 | for (int i = 0; i < w*h; i++) { |
| 925 | Sk4f fs = Sk4f_fromS32(px[i]); // Convert up to linear floats. |
| 926 | #if defined(SK_PMCOLOR_IS_BGRA) |
| 927 | fs = SkNx_shuffle<2,1,0,3>(fs); // Shuffle to RGBA, if not there already. |
| 928 | #endif |
| 929 | float invA = 1.0f / fs[3]; |
| 930 | fs = fs * Sk4f(invA, invA, invA, 1); // Unpremultiply. |
| 931 | rgba[i] = Sk4f_toS32(fs); // Pack down to sRGB bytes. |
| 932 | } |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 933 | |
mtklein | 27c3fdd | 2016-02-26 14:43:21 -0800 | [diff] [blame] | 934 | } else if (bitmap.colorType() == kRGBA_F16_SkColorType) { |
| 935 | // These are premul linear half-float pixels in RGBA order. |
| 936 | // We want unpremul sRGB 8-bit pixels in RGBA order. We'll get there via floats. |
| 937 | bitmap.lockPixels(); |
| 938 | auto px = (const uint64_t*)bitmap.getPixels(); |
| 939 | if (!px) { |
| 940 | return false; |
| 941 | } |
| 942 | for (int i = 0; i < w*h; i++) { |
| 943 | Sk4f fs = SkHalfToFloat_01(px[i]); // Convert up to linear floats. |
| 944 | float invA = 1.0f / fs[3]; |
| 945 | fs = fs * Sk4f(invA, invA, invA, 1); // Unpremultiply. |
| 946 | rgba[i] = Sk4f_toS32(fs); // Pack down to sRGB bytes. |
| 947 | } |
| 948 | |
| 949 | |
| 950 | } else { |
| 951 | // We "should" gamma correct in here but we don't. |
| 952 | // We want Gold to show exactly what our clients are seeing, broken gamma. |
| 953 | |
| 954 | // Convert smaller formats up to premul linear 8-bit (in SkPMColor order). |
| 955 | if (bitmap.colorType() != kN32_SkColorType) { |
| 956 | SkBitmap n32; |
| 957 | if (!bitmap.copyTo(&n32, kN32_SkColorType)) { |
| 958 | return false; |
| 959 | } |
| 960 | bitmap = n32; |
| 961 | } |
| 962 | |
| 963 | // Convert premul linear 8-bit to unpremul linear 8-bit RGBA. |
| 964 | if (!bitmap.readPixels(SkImageInfo::Make(w,h, kRGBA_8888_SkColorType, |
| 965 | kUnpremul_SkAlphaType), |
| 966 | rgba, 4*w, 0,0)) { |
| 967 | return false; |
| 968 | } |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 969 | } |
| 970 | |
| 971 | // We don't need bitmap anymore. Might as well drop our ref. |
mtklein | fccb77d | 2015-08-24 14:13:29 -0700 | [diff] [blame] | 972 | bitmap.reset(); |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 973 | |
mtklein | c64137c | 2015-08-25 10:56:08 -0700 | [diff] [blame] | 974 | FILE* f = fopen(path, "wb"); |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 975 | if (!f) { return false; } |
| 976 | |
| 977 | png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr); |
| 978 | if (!png) { |
| 979 | fclose(f); |
| 980 | return false; |
| 981 | } |
| 982 | |
| 983 | png_infop info = png_create_info_struct(png); |
| 984 | if (!info) { |
| 985 | png_destroy_write_struct(&png, &info); |
| 986 | fclose(f); |
| 987 | return false; |
| 988 | } |
| 989 | |
mtklein | d69ece6 | 2015-09-10 10:37:44 -0700 | [diff] [blame] | 990 | SkString description; |
| 991 | description.append("Key: "); |
| 992 | for (int i = 0; i < FLAGS_key.count(); i++) { |
| 993 | description.appendf("%s ", FLAGS_key[i]); |
| 994 | } |
| 995 | description.append("Properties: "); |
| 996 | for (int i = 0; i < FLAGS_properties.count(); i++) { |
| 997 | description.appendf("%s ", FLAGS_properties[i]); |
| 998 | } |
| 999 | description.appendf("MD5: %s", md5); |
| 1000 | |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 1001 | png_text text[2]; |
| 1002 | text[0].key = (png_charp)"Author"; |
| 1003 | text[0].text = (png_charp)"DM dump_png()"; |
| 1004 | text[0].compression = PNG_TEXT_COMPRESSION_NONE; |
| 1005 | text[1].key = (png_charp)"Description"; |
mtklein | d69ece6 | 2015-09-10 10:37:44 -0700 | [diff] [blame] | 1006 | text[1].text = (png_charp)description.c_str(); |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 1007 | text[1].compression = PNG_TEXT_COMPRESSION_NONE; |
| 1008 | png_set_text(png, info, text, 2); |
| 1009 | |
| 1010 | png_init_io(png, f); |
| 1011 | png_set_IHDR(png, info, (png_uint_32)w, (png_uint_32)h, 8, |
| 1012 | PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, |
| 1013 | PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); |
| 1014 | png_write_info(png, info); |
| 1015 | for (int j = 0; j < h; j++) { |
| 1016 | png_bytep row = (png_bytep)(rgba.get() + w*j); |
| 1017 | png_write_rows(png, &row, 1); |
| 1018 | } |
| 1019 | png_write_end(png, info); |
| 1020 | |
| 1021 | png_destroy_write_struct(&png, &info); |
| 1022 | fclose(f); |
| 1023 | return true; |
| 1024 | } |
| 1025 | |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 1026 | static bool match(const char* needle, const char* haystack) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1027 | return 0 == strcmp("_", needle) || nullptr != strstr(haystack, needle); |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 1028 | } |
| 1029 | |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1030 | static bool is_blacklisted(const char* sink, const char* src, |
| 1031 | const char* srcOptions, const char* name) { |
mtklein | 0d243ff | 2015-04-03 07:51:00 -0700 | [diff] [blame] | 1032 | for (int i = 0; i < FLAGS_blacklist.count() - 3; i += 4) { |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 1033 | if (match(FLAGS_blacklist[i+0], sink) && |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 1034 | match(FLAGS_blacklist[i+1], src) && |
| 1035 | match(FLAGS_blacklist[i+2], srcOptions) && |
| 1036 | match(FLAGS_blacklist[i+3], name)) { |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1037 | return true; |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 1038 | } |
| 1039 | } |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1040 | return false; |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 1041 | } |
| 1042 | |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1043 | // Even when a Task Sink reports to be non-threadsafe (e.g. GPU), we know things like |
| 1044 | // .png encoding are definitely thread safe. This lets us offload that work to CPU threads. |
| 1045 | static SkTaskGroup gDefinitelyThreadSafeWork; |
| 1046 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1047 | // The finest-grained unit of work we can run: draw a single Src into a single Sink, |
| 1048 | // report any errors, and perhaps write out the output: a .png of the bitmap, or a raw stream. |
| 1049 | struct Task { |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 1050 | Task(const TaggedSrc& src, const TaggedSink& sink) : src(src), sink(sink) {} |
| 1051 | const TaggedSrc& src; |
| 1052 | const TaggedSink& sink; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1053 | |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1054 | static void Run(const Task& task) { |
| 1055 | SkString name = task.src->name(); |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 1056 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 1057 | SkString log; |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1058 | if (!FLAGS_dryRun) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1059 | SkBitmap bitmap; |
| 1060 | SkDynamicMemoryWStream stream; |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1061 | start(task.sink.tag.c_str(), task.src.tag.c_str(), |
| 1062 | task.src.options.c_str(), name.c_str()); |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1063 | Error err = task.sink->draw(*task.src, &bitmap, &stream, &log); |
mtklein | b3b13b7 | 2016-03-07 13:20:52 -0800 | [diff] [blame] | 1064 | if (!log.isEmpty()) { |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 1065 | info("%s %s %s %s:\n%s\n", task.sink.tag.c_str() |
| 1066 | , task.src.tag.c_str() |
| 1067 | , task.src.options.c_str() |
| 1068 | , name.c_str() |
| 1069 | , log.c_str()); |
mtklein | b3b13b7 | 2016-03-07 13:20:52 -0800 | [diff] [blame] | 1070 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1071 | if (!err.isEmpty()) { |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 1072 | if (err.isFatal()) { |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 1073 | fail(SkStringPrintf("%s %s %s %s: %s", |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1074 | task.sink.tag.c_str(), |
| 1075 | task.src.tag.c_str(), |
| 1076 | task.src.options.c_str(), |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 1077 | name.c_str(), |
| 1078 | err.c_str())); |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 1079 | } else { |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1080 | done(task.sink.tag.c_str(), task.src.tag.c_str(), |
| 1081 | task.src.options.c_str(), name.c_str()); |
mtklein | ba6ada7 | 2016-01-21 09:39:35 -0800 | [diff] [blame] | 1082 | return; |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 1083 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1084 | } |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 1085 | |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1086 | // We're likely switching threads here, so we must capture by value, [=] or [foo,bar]. |
| 1087 | SkStreamAsset* data = stream.detachAsStream(); |
| 1088 | gDefinitelyThreadSafeWork.add([task,name,bitmap,data]{ |
| 1089 | SkAutoTDelete<SkStreamAsset> ownedData(data); |
| 1090 | |
| 1091 | // Why doesn't the copy constructor do this when we have pre-locked pixels? |
| 1092 | bitmap.lockPixels(); |
| 1093 | |
| 1094 | SkString md5; |
| 1095 | if (!FLAGS_writePath.isEmpty() || !FLAGS_readPath.isEmpty()) { |
| 1096 | SkMD5 hash; |
| 1097 | if (data->getLength()) { |
| 1098 | hash.writeStream(data, data->getLength()); |
| 1099 | data->rewind(); |
mtklein | 3840846 | 2015-07-08 07:25:27 -0700 | [diff] [blame] | 1100 | } else { |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1101 | // If we're BGRA (Linux, Windows), swizzle over to RGBA (Mac, Android). |
| 1102 | // This helps eliminate multiple 0-pixel-diff hashes on gold.skia.org. |
| 1103 | // (Android's general slow speed breaks the tie arbitrarily in RGBA's favor.) |
| 1104 | // We might consider promoting 565 to RGBA too. |
| 1105 | if (bitmap.colorType() == kBGRA_8888_SkColorType) { |
| 1106 | SkBitmap swizzle; |
| 1107 | SkAssertResult(bitmap.copyTo(&swizzle, kRGBA_8888_SkColorType)); |
| 1108 | hash.write(swizzle.getPixels(), swizzle.getSize()); |
| 1109 | } else { |
| 1110 | hash.write(bitmap.getPixels(), bitmap.getSize()); |
| 1111 | } |
| 1112 | } |
| 1113 | SkMD5::Digest digest; |
| 1114 | hash.finish(digest); |
| 1115 | for (int i = 0; i < 16; i++) { |
| 1116 | md5.appendf("%02x", digest.data[i]); |
mtklein | 3840846 | 2015-07-08 07:25:27 -0700 | [diff] [blame] | 1117 | } |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 1118 | } |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 1119 | |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1120 | if (!FLAGS_readPath.isEmpty() && |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1121 | !gGold.contains(Gold(task.sink.tag, task.src.tag, |
| 1122 | task.src.options, name, md5))) { |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1123 | fail(SkStringPrintf("%s not found for %s %s %s %s in %s", |
| 1124 | md5.c_str(), |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1125 | task.sink.tag.c_str(), |
| 1126 | task.src.tag.c_str(), |
| 1127 | task.src.options.c_str(), |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1128 | name.c_str(), |
| 1129 | FLAGS_readPath[0])); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1130 | } |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1131 | |
| 1132 | if (!FLAGS_writePath.isEmpty()) { |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1133 | const char* ext = task.sink->fileExtension(); |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1134 | if (data->getLength()) { |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1135 | WriteToDisk(task, md5, ext, data, data->getLength(), nullptr); |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1136 | SkASSERT(bitmap.drawsNothing()); |
| 1137 | } else if (!bitmap.drawsNothing()) { |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1138 | WriteToDisk(task, md5, ext, nullptr, 0, &bitmap); |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1139 | } |
| 1140 | } |
| 1141 | }); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1142 | } |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1143 | 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] | 1144 | } |
| 1145 | |
| 1146 | static void WriteToDisk(const Task& task, |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 1147 | SkString md5, |
| 1148 | const char* ext, |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1149 | SkStream* data, size_t len, |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 1150 | const SkBitmap* bitmap) { |
mtklein | 409d470 | 2016-02-29 07:38:01 -0800 | [diff] [blame] | 1151 | bool gammaCorrect = false; |
| 1152 | if (bitmap) { |
| 1153 | gammaCorrect = bitmap->profileType() == kSRGB_SkColorProfileType |
| 1154 | || bitmap-> colorType() == kRGBA_F16_SkColorType; |
| 1155 | } |
| 1156 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1157 | JsonWriter::BitmapResult result; |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 1158 | result.name = task.src->name(); |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1159 | result.config = task.sink.tag; |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 1160 | result.sourceType = task.src.tag; |
| 1161 | result.sourceOptions = task.src.options; |
| 1162 | result.ext = ext; |
mtklein | 409d470 | 2016-02-29 07:38:01 -0800 | [diff] [blame] | 1163 | result.gammaCorrect = gammaCorrect; |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 1164 | result.md5 = md5; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1165 | JsonWriter::AddBitmapResult(result); |
| 1166 | |
mtklein | b0531a7 | 2015-04-07 13:38:48 -0700 | [diff] [blame] | 1167 | // If an MD5 is uninteresting, we want it noted in the JSON file, |
| 1168 | // but don't want to dump it out as a .png (or whatever ext is). |
| 1169 | if (gUninterestingHashes.contains(md5)) { |
| 1170 | return; |
| 1171 | } |
| 1172 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1173 | const char* dir = FLAGS_writePath[0]; |
| 1174 | if (0 == strcmp(dir, "@")) { // Needed for iOS. |
| 1175 | dir = FLAGS_resourcePath[0]; |
| 1176 | } |
| 1177 | sk_mkdir(dir); |
| 1178 | |
| 1179 | SkString path; |
| 1180 | if (FLAGS_nameByHash) { |
| 1181 | path = SkOSPath::Join(dir, result.md5.c_str()); |
| 1182 | path.append("."); |
| 1183 | path.append(ext); |
| 1184 | if (sk_exists(path.c_str())) { |
| 1185 | return; // Content-addressed. If it exists already, we're done. |
| 1186 | } |
| 1187 | } else { |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 1188 | path = SkOSPath::Join(dir, task.sink.tag.c_str()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1189 | sk_mkdir(path.c_str()); |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 1190 | path = SkOSPath::Join(path.c_str(), task.src.tag.c_str()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1191 | sk_mkdir(path.c_str()); |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 1192 | if (strcmp(task.src.options.c_str(), "") != 0) { |
| 1193 | path = SkOSPath::Join(path.c_str(), task.src.options.c_str()); |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 1194 | sk_mkdir(path.c_str()); |
| 1195 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1196 | path = SkOSPath::Join(path.c_str(), task.src->name().c_str()); |
| 1197 | path.append("."); |
| 1198 | path.append(ext); |
| 1199 | } |
| 1200 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1201 | if (bitmap) { |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 1202 | if (!dump_png(*bitmap, path.c_str(), result.md5.c_str())) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1203 | fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str())); |
| 1204 | return; |
| 1205 | } |
| 1206 | } else { |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 1207 | SkFILEWStream file(path.c_str()); |
| 1208 | if (!file.isValid()) { |
| 1209 | fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str())); |
| 1210 | return; |
| 1211 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1212 | if (!file.writeStream(data, len)) { |
| 1213 | fail(SkStringPrintf("Can't write to %s.\n", path.c_str())); |
| 1214 | return; |
| 1215 | } |
| 1216 | } |
| 1217 | } |
| 1218 | }; |
| 1219 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1220 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 1221 | |
| 1222 | // Unit tests don't fit so well into the Src/Sink model, so we give them special treatment. |
| 1223 | |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1224 | static SkTDArray<skiatest::Test> gParallelTests, gSerialTests; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1225 | |
| 1226 | static void gather_tests() { |
mtklein | 6c5fed2 | 2015-01-20 13:47:23 -0800 | [diff] [blame] | 1227 | if (!FLAGS_src.contains("tests")) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1228 | return; |
| 1229 | } |
mtklein | 6393c06 | 2015-04-27 08:45:01 -0700 | [diff] [blame] | 1230 | for (const skiatest::TestRegistry* r = skiatest::TestRegistry::Head(); r; r = r->next()) { |
| 1231 | if (!in_shard()) { |
| 1232 | continue; |
| 1233 | } |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1234 | // Despite its name, factory() is returning a reference to |
| 1235 | // link-time static const POD data. |
| 1236 | const skiatest::Test& test = r->factory(); |
| 1237 | if (SkCommandLineFlags::ShouldSkip(FLAGS_match, test.name)) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1238 | continue; |
| 1239 | } |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1240 | if (test.needsGpu && gpu_supported()) { |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1241 | (FLAGS_gpu_threading ? gParallelTests : gSerialTests).push(test); |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1242 | } else if (!test.needsGpu && FLAGS_cpu) { |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1243 | gParallelTests.push(test); |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 1244 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1245 | } |
| 1246 | } |
| 1247 | |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1248 | static void run_test(skiatest::Test test) { |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1249 | struct : public skiatest::Reporter { |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 1250 | void reportFailed(const skiatest::Failure& failure) override { |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1251 | fail(failure.toString()); |
| 1252 | JsonWriter::AddTestFailure(failure); |
| 1253 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 1254 | bool allowExtendedTest() const override { |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1255 | return FLAGS_pathOpsExtended; |
| 1256 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 1257 | bool verbose() const override { return FLAGS_veryVerbose; } |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1258 | } reporter; |
djsollen | 824996a | 2015-06-12 12:06:22 -0700 | [diff] [blame] | 1259 | |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1260 | if (!FLAGS_dryRun && !is_blacklisted("_", "tests", "_", test.name)) { |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1261 | start("unit", "test", "", test.name); |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 1262 | GrContextFactory factory; |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1263 | test.proc(&reporter, &factory); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1264 | } |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1265 | done("unit", "test", "", test.name); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1266 | } |
| 1267 | |
| 1268 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 1269 | |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 1270 | DEFINE_int32(status_sec, 15, "Print status this often (and if we crash)."); |
| 1271 | |
| 1272 | SkThread* start_status_thread() { |
| 1273 | auto thread = new SkThread([] (void*) { |
| 1274 | for (;;) { |
| 1275 | print_status(); |
| 1276 | #if defined(SK_BUILD_FOR_WIN) |
| 1277 | Sleep(FLAGS_status_sec * 1000); |
| 1278 | #else |
| 1279 | sleep(FLAGS_status_sec); |
| 1280 | #endif |
mtklein | 2e1c47e | 2015-03-12 07:16:56 -0700 | [diff] [blame] | 1281 | } |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 1282 | }); |
| 1283 | thread->start(); |
| 1284 | return thread; |
mtklein | de6fc2b | 2015-03-12 06:28:54 -0700 | [diff] [blame] | 1285 | } |
| 1286 | |
caryclark | 83ca628 | 2015-06-10 09:31:09 -0700 | [diff] [blame] | 1287 | #define PORTABLE_FONT_PREFIX "Toy Liberation " |
| 1288 | |
| 1289 | static SkTypeface* create_from_name(const char familyName[], SkTypeface::Style style) { |
| 1290 | if (familyName && strlen(familyName) > sizeof(PORTABLE_FONT_PREFIX) |
| 1291 | && !strncmp(familyName, PORTABLE_FONT_PREFIX, sizeof(PORTABLE_FONT_PREFIX) - 1)) { |
caryclark | 1818acb | 2015-07-24 12:09:25 -0700 | [diff] [blame] | 1292 | return sk_tool_utils::create_portable_typeface(familyName, style); |
caryclark | 83ca628 | 2015-06-10 09:31:09 -0700 | [diff] [blame] | 1293 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1294 | return nullptr; |
caryclark | 83ca628 | 2015-06-10 09:31:09 -0700 | [diff] [blame] | 1295 | } |
| 1296 | |
| 1297 | #undef PORTABLE_FONT_PREFIX |
| 1298 | |
| 1299 | extern SkTypeface* (*gCreateTypefaceDelegate)(const char [], SkTypeface::Style ); |
| 1300 | |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 1301 | int dm_main(); |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 1302 | int dm_main() { |
mtklein | 246ba3a | 2016-02-23 10:39:36 -0800 | [diff] [blame] | 1303 | setup_crash_handler(); |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 1304 | |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 1305 | if (FLAGS_verbose && !FLAGS_writePath.isEmpty()) { |
| 1306 | sk_mkdir(FLAGS_writePath[0]); |
| 1307 | gVLog = freopen(SkOSPath::Join(FLAGS_writePath[0], "verbose.log").c_str(), "w", stderr); |
| 1308 | } |
| 1309 | |
mtklein | 5286f02 | 2016-01-22 08:18:14 -0800 | [diff] [blame] | 1310 | 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] | 1311 | SkAutoGraphics ag; |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 1312 | SkTaskGroup::Enabler enabled(FLAGS_threads); |
caryclark | 83ca628 | 2015-06-10 09:31:09 -0700 | [diff] [blame] | 1313 | gCreateTypefaceDelegate = &create_from_name; |
commit-bot@chromium.org | a65e2fd | 2014-05-30 17:23:31 +0000 | [diff] [blame] | 1314 | |
halcanary | 7d57124 | 2016-02-24 17:59:16 -0800 | [diff] [blame] | 1315 | { |
| 1316 | SkString testResourcePath = GetResourcePath("color_wheel.png"); |
| 1317 | SkFILEStream testResource(testResourcePath.c_str()); |
| 1318 | if (!testResource.isValid()) { |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 1319 | info("Some resources are missing. Do you need to set --resourcePath?\n"); |
halcanary | 7d57124 | 2016-02-24 17:59:16 -0800 | [diff] [blame] | 1320 | } |
| 1321 | } |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 1322 | gather_gold(); |
borenet | 09ed480 | 2015-04-03 14:15:33 -0700 | [diff] [blame] | 1323 | gather_uninteresting_hashes(); |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 1324 | |
scroggo | 8673714 | 2016-02-03 12:19:11 -0800 | [diff] [blame] | 1325 | if (!gather_srcs()) { |
| 1326 | return 1; |
| 1327 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1328 | gather_sinks(); |
| 1329 | gather_tests(); |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 1330 | |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1331 | gPending = gSrcs.count() * gSinks.count() + gParallelTests.count() + gSerialTests.count(); |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 1332 | info("%d srcs * %d sinks + %d tests == %d tasks", |
| 1333 | gSrcs.count(), gSinks.count(), gParallelTests.count() + gSerialTests.count(), gPending); |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 1334 | SkAutoTDelete<SkThread> statusThread(start_status_thread()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1335 | |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1336 | // Kick off as much parallel work as we can, making note of any serial work we'll need to do. |
| 1337 | SkTaskGroup parallel; |
| 1338 | SkTArray<Task> serial; |
| 1339 | |
| 1340 | for (auto& sink : gSinks) |
| 1341 | for (auto& src : gSrcs) { |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1342 | if (src->veto(sink->flags()) || |
| 1343 | is_blacklisted(sink.tag.c_str(), src.tag.c_str(), |
| 1344 | src.options.c_str(), src->name().c_str())) { |
mtklein | 15923c9 | 2016-02-29 10:14:38 -0800 | [diff] [blame] | 1345 | SkAutoTAcquire<SkSpinlock> lock(gMutex); |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1346 | gPending--; |
| 1347 | continue; |
| 1348 | } |
| 1349 | |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1350 | Task task(src, sink); |
| 1351 | if (src->serial() || sink->serial()) { |
| 1352 | serial.push_back(task); |
| 1353 | } else { |
| 1354 | parallel.add([task] { Task::Run(task); }); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1355 | } |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 1356 | } |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1357 | for (auto test : gParallelTests) { |
| 1358 | parallel.add([test] { run_test(test); }); |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 1359 | } |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1360 | |
| 1361 | // With the parallel work running, run serial tasks and tests here on main thread. |
| 1362 | for (auto task : serial) { Task::Run(task); } |
| 1363 | for (auto test : gSerialTests) { run_test(test); } |
| 1364 | |
| 1365 | // Wait for any remaining parallel work to complete (including any spun off of serial tasks). |
| 1366 | parallel.wait(); |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1367 | gDefinitelyThreadSafeWork.wait(); |
| 1368 | |
mtklein | da884c4 | 2016-02-24 18:00:23 -0800 | [diff] [blame] | 1369 | // We'd better have run everything. |
| 1370 | SkASSERT(gPending == 0); |
mtklein | e027f17 | 2016-02-26 15:53:06 -0800 | [diff] [blame] | 1371 | // Make sure we've flushed all our results to disk. |
| 1372 | JsonWriter::DumpJson(); |
mtklein | da884c4 | 2016-02-24 18:00:23 -0800 | [diff] [blame] | 1373 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1374 | // At this point we're back in single-threaded land. |
caryclark | f53ce80 | 2015-06-15 06:48:30 -0700 | [diff] [blame] | 1375 | sk_tool_utils::release_portable_typefaces(); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 1376 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1377 | if (gFailures.count() > 0) { |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 1378 | info("Failures:\n"); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1379 | for (int i = 0; i < gFailures.count(); i++) { |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 1380 | info("\t%s\n", gFailures[i].c_str()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1381 | } |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 1382 | info("%d failures\n", gFailures.count()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1383 | return 1; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 1384 | } |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 1385 | |
| 1386 | #ifdef SK_PDF_IMAGE_STATS |
halcanary | 7a14b31 | 2015-10-01 07:28:13 -0700 | [diff] [blame] | 1387 | SkPDFImageDumpStats(); |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 1388 | #endif // SK_PDF_IMAGE_STATS |
| 1389 | |
| 1390 | print_status(); |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 1391 | info("Finished!\n"); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1392 | return 0; |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 1393 | } |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 1394 | |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1395 | // TODO: currently many GPU tests are declared outside SK_SUPPORT_GPU guards. |
| 1396 | // Thus we export the empty RunWithGPUTestContexts when SK_SUPPORT_GPU=0. |
| 1397 | namespace skiatest { |
| 1398 | namespace { |
| 1399 | typedef void(*TestWithGrContext)(skiatest::Reporter*, GrContext*); |
| 1400 | typedef void(*TestWithGrContextAndGLContext)(skiatest::Reporter*, GrContext*, SkGLContext*); |
| 1401 | #if SK_SUPPORT_GPU |
| 1402 | template<typename T> |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 1403 | void call_test(T test, skiatest::Reporter* reporter, const GrContextFactory::ContextInfo& context); |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1404 | template<> |
| 1405 | void call_test(TestWithGrContext test, skiatest::Reporter* reporter, |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 1406 | const GrContextFactory::ContextInfo& context) { |
| 1407 | test(reporter, context.fGrContext); |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1408 | } |
| 1409 | template<> |
| 1410 | void call_test(TestWithGrContextAndGLContext 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, context.fGLContext); |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1413 | } |
| 1414 | #endif |
| 1415 | } // namespace |
| 1416 | |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1417 | template<typename T> |
| 1418 | void RunWithGPUTestContexts(T test, GPUTestContexts testContexts, Reporter* reporter, |
| 1419 | GrContextFactory* factory) { |
| 1420 | #if SK_SUPPORT_GPU |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 1421 | // Iterate over context types, except use "native" instead of explicitly trying OpenGL and |
| 1422 | // OpenGL ES. Do not use GLES on desktop, since tests do not account for not fixing |
| 1423 | // http://skbug.com/2809 |
| 1424 | GrContextFactory::GLContextType contextTypes[] = { |
| 1425 | GrContextFactory::kNative_GLContextType, |
| 1426 | #if SK_ANGLE |
| 1427 | #ifdef SK_BUILD_FOR_WIN |
| 1428 | GrContextFactory::kANGLE_GLContextType, |
| 1429 | #endif |
| 1430 | GrContextFactory::kANGLE_GL_GLContextType, |
| 1431 | #endif |
| 1432 | #if SK_COMMAND_BUFFER |
kkinnunen | f655e93 | 2016-03-03 07:39:48 -0800 | [diff] [blame] | 1433 | GrContextFactory::kCommandBuffer_GLContextType, |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 1434 | #endif |
| 1435 | #if SK_MESA |
| 1436 | GrContextFactory::kMESA_GLContextType, |
| 1437 | #endif |
| 1438 | GrContextFactory::kNull_GLContextType, |
| 1439 | GrContextFactory::kDebug_GLContextType, |
| 1440 | }; |
| 1441 | static_assert(SK_ARRAY_COUNT(contextTypes) == GrContextFactory::kGLContextTypeCnt - 2, |
| 1442 | "Skipping unexpected GLContextType for GPU tests"); |
| 1443 | |
| 1444 | for (auto& contextType : contextTypes) { |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1445 | int contextSelector = kNone_GPUTestContexts; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 1446 | if (GrContextFactory::IsRenderingGLContext(contextType)) { |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1447 | contextSelector |= kAllRendering_GPUTestContexts; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 1448 | } else if (contextType == GrContextFactory::kNative_GLContextType) { |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1449 | contextSelector |= kNative_GPUTestContexts; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 1450 | } else if (contextType == GrContextFactory::kNull_GLContextType) { |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1451 | contextSelector |= kNull_GPUTestContexts; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 1452 | } else if (contextType == GrContextFactory::kDebug_GLContextType) { |
kkinnunen | 55eeae9 | 2015-12-10 23:19:29 -0800 | [diff] [blame] | 1453 | contextSelector |= kDebug_GPUTestContexts; |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1454 | } |
| 1455 | if ((testContexts & contextSelector) == 0) { |
| 1456 | continue; |
| 1457 | } |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 1458 | GrContextFactory::ContextInfo context = factory->getContextInfo(contextType); |
| 1459 | if (context.fGrContext) { |
kkinnunen | 5219fd9 | 2015-12-10 06:28:13 -0800 | [diff] [blame] | 1460 | call_test(test, reporter, context); |
| 1461 | } |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 1462 | context = factory->getContextInfo(contextType, |
| 1463 | GrContextFactory::kEnableNVPR_GLContextOptions); |
| 1464 | if (context.fGrContext) { |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1465 | call_test(test, reporter, context); |
| 1466 | } |
| 1467 | } |
| 1468 | #endif |
| 1469 | } |
| 1470 | |
| 1471 | template |
| 1472 | void RunWithGPUTestContexts<TestWithGrContext>(TestWithGrContext test, |
| 1473 | GPUTestContexts testContexts, |
| 1474 | Reporter* reporter, |
| 1475 | GrContextFactory* factory); |
| 1476 | template |
| 1477 | void RunWithGPUTestContexts<TestWithGrContextAndGLContext>(TestWithGrContextAndGLContext test, |
| 1478 | GPUTestContexts testContexts, |
| 1479 | Reporter* reporter, |
| 1480 | GrContextFactory* factory); |
| 1481 | } // namespace skiatest |
| 1482 | |
borenet | 4808757 | 2015-04-02 12:16:36 -0700 | [diff] [blame] | 1483 | #if !defined(SK_BUILD_FOR_IOS) |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 1484 | int main(int argc, char** argv) { |
| 1485 | SkCommandLineFlags::Parse(argc, argv); |
| 1486 | return dm_main(); |
| 1487 | } |
| 1488 | #endif |