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