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