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