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