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" |
tomhudson | eebc39a | 2015-02-23 12:18:05 -0800 | [diff] [blame] | 10 | #include "DMSrcSinkAndroid.h" |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 11 | #include "ProcStats.h" |
halcanary | 7d57124 | 2016-02-24 17:59:16 -0800 | [diff] [blame] | 12 | #include "Resources.h" |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 13 | #include "SkBBHFactory.h" |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 14 | #include "SkChecksum.h" |
scroggo | cc2feb1 | 2015-08-14 08:32:46 -0700 | [diff] [blame] | 15 | #include "SkCodec.h" |
mtklein | 27c3fdd | 2016-02-26 14:43:21 -0800 | [diff] [blame] | 16 | #include "SkColorPriv.h" |
msarett | 888dc16 | 2016-05-23 10:21:17 -0700 | [diff] [blame] | 17 | #include "SkColorSpace.h" |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 18 | #include "SkCommonFlags.h" |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 19 | #include "SkCommonFlagsConfig.h" |
brianosman | 3c579dc | 2016-04-19 09:18:11 -0700 | [diff] [blame] | 20 | #include "SkData.h" |
caryclark | 83ca628 | 2015-06-10 09:31:09 -0700 | [diff] [blame] | 21 | #include "SkFontMgr.h" |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 22 | #include "SkGraphics.h" |
mtklein | 27c3fdd | 2016-02-26 14:43:21 -0800 | [diff] [blame] | 23 | #include "SkHalf.h" |
halcanary | 4dbbd04 | 2016-06-07 17:21:10 -0700 | [diff] [blame] | 24 | #include "SkLeanWindows.h" |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 25 | #include "SkMD5.h" |
mtklein | 1b24933 | 2015-07-07 12:21:21 -0700 | [diff] [blame] | 26 | #include "SkMutex.h" |
mtklein | 1d0f164 | 2014-09-08 08:05:18 -0700 | [diff] [blame] | 27 | #include "SkOSFile.h" |
Ben Wagner | bf111d7 | 2016-11-07 18:05:29 -0500 | [diff] [blame] | 28 | #include "SkOSPath.h" |
mtklein | 27c3fdd | 2016-02-26 14:43:21 -0800 | [diff] [blame] | 29 | #include "SkPM4fPriv.h" |
mtklein | 246ba3a | 2016-02-23 10:39:36 -0800 | [diff] [blame] | 30 | #include "SkSpinlock.h" |
mtklein | a82f562 | 2015-02-20 12:30:19 -0800 | [diff] [blame] | 31 | #include "SkTHash.h" |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 32 | #include "SkTaskGroup.h" |
mtklein | de6fc2b | 2015-03-12 06:28:54 -0700 | [diff] [blame] | 33 | #include "SkThreadUtils.h" |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 34 | #include "Test.h" |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 35 | #include "Timer.h" |
brianosman | 3c579dc | 2016-04-19 09:18:11 -0700 | [diff] [blame] | 36 | #include "picture_utils.h" |
caryclark | 83ca628 | 2015-06-10 09:31:09 -0700 | [diff] [blame] | 37 | #include "sk_tool_utils.h" |
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 | |
tomhudson | eebc39a | 2015-02-23 12:18:05 -0800 | [diff] [blame] | 862 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 863 | SINK("hwui", HWUISink); |
| 864 | #endif |
| 865 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 866 | if (FLAGS_cpu) { |
Brian Osman | 526972e | 2016-10-24 09:24:02 -0400 | [diff] [blame] | 867 | auto srgbColorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named); |
| 868 | auto srgbLinearColorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGBLinear_Named); |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 869 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 870 | SINK("565", RasterSink, kRGB_565_SkColorType); |
| 871 | SINK("8888", RasterSink, kN32_SkColorType); |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 872 | SINK("srgb", RasterSink, kN32_SkColorType, srgbColorSpace); |
raftias | 7c602de | 2016-10-13 10:45:44 -0700 | [diff] [blame] | 873 | SINK("f16", RasterSink, kRGBA_F16_SkColorType, srgbLinearColorSpace); |
halcanary | 94b87bd | 2016-04-04 06:12:15 -0700 | [diff] [blame] | 874 | SINK("pdf", PDFSink); |
mtklein | 9c3f17d | 2015-01-28 11:35:18 -0800 | [diff] [blame] | 875 | SINK("skp", SKPSink); |
reed | 54dc487 | 2016-09-13 08:09:45 -0700 | [diff] [blame] | 876 | SINK("pipe", PipeSink); |
mtklein | 8a4527e | 2015-01-31 20:00:58 -0800 | [diff] [blame] | 877 | SINK("svg", SVGSink); |
| 878 | SINK("null", NullSink); |
halcanary | 47ef4d5 | 2015-03-03 09:13:09 -0800 | [diff] [blame] | 879 | SINK("xps", XPSSink); |
halcanary | 4b65666 | 2016-04-27 07:45:18 -0700 | [diff] [blame] | 880 | SINK("pdfa", PDFSink, true); |
Hal Canary | 85c7fe8 | 2016-10-25 10:33:27 -0400 | [diff] [blame] | 881 | SINK("jsdebug", DebugSink); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 882 | } |
| 883 | #undef SINK |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 884 | return nullptr; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 885 | } |
| 886 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 887 | static Sink* create_via(const SkString& tag, Sink* wrapped) { |
| 888 | #define VIA(t, via, ...) if (tag.equals(t)) { return new via(__VA_ARGS__); } |
mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 889 | VIA("lite", ViaLite, wrapped); |
reed | 54dc487 | 2016-09-13 08:09:45 -0700 | [diff] [blame] | 890 | VIA("pipe", ViaPipe, wrapped); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 891 | VIA("twice", ViaTwice, wrapped); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 892 | VIA("serialize", ViaSerialization, wrapped); |
mtklein | 4a34ecb | 2016-01-08 10:19:35 -0800 | [diff] [blame] | 893 | VIA("pic", ViaPicture, wrapped); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 894 | VIA("2ndpic", ViaSecondPicture, wrapped); |
mtklein | d31c13d | 2015-05-05 12:59:56 -0700 | [diff] [blame] | 895 | VIA("sp", ViaSingletonPictures, wrapped); |
reed | babc3de | 2016-07-08 08:43:27 -0700 | [diff] [blame] | 896 | VIA("defer", ViaDefer, wrapped); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 897 | VIA("tiles", ViaTiles, 256, 256, nullptr, wrapped); |
mtklein | 7edca21 | 2015-01-21 13:18:51 -0800 | [diff] [blame] | 898 | VIA("tiles_rt", ViaTiles, 256, 256, new SkRTreeFactory, wrapped); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 899 | |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 900 | if (FLAGS_matrix.count() == 4) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 901 | SkMatrix m; |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 902 | m.reset(); |
| 903 | m.setScaleX((SkScalar)atof(FLAGS_matrix[0])); |
| 904 | m.setSkewX ((SkScalar)atof(FLAGS_matrix[1])); |
| 905 | m.setSkewY ((SkScalar)atof(FLAGS_matrix[2])); |
| 906 | m.setScaleY((SkScalar)atof(FLAGS_matrix[3])); |
| 907 | VIA("matrix", ViaMatrix, m, wrapped); |
| 908 | VIA("upright", ViaUpright, m, wrapped); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 909 | } |
tomhudson | 64de1e1 | 2015-03-05 08:01:07 -0800 | [diff] [blame] | 910 | |
| 911 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 912 | VIA("androidsdk", ViaAndroidSDK, wrapped); |
| 913 | #endif |
| 914 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 915 | #undef VIA |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 916 | return nullptr; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 917 | } |
| 918 | |
brianosman | 05c987c | 2016-05-09 13:42:16 -0700 | [diff] [blame] | 919 | static bool gather_sinks() { |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 920 | SkCommandLineConfigArray configs; |
| 921 | ParseConfigs(FLAGS_config, &configs); |
| 922 | for (int i = 0; i < configs.count(); i++) { |
| 923 | const SkCommandLineConfig& config = *configs[i]; |
| 924 | Sink* sink = create_sink(&config); |
| 925 | if (sink == nullptr) { |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 926 | info("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(), |
| 927 | config.getTag().c_str()); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 928 | continue; |
| 929 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 930 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 931 | const SkTArray<SkString>& parts = config.getViaParts(); |
| 932 | for (int j = parts.count(); j-- > 0;) { |
| 933 | const SkString& part = parts[j]; |
| 934 | Sink* next = create_via(part, sink); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 935 | if (next == nullptr) { |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 936 | info("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(), |
| 937 | part.c_str()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 938 | delete sink; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 939 | sink = nullptr; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 940 | break; |
| 941 | } |
| 942 | sink = next; |
| 943 | } |
| 944 | if (sink) { |
| 945 | push_sink(config, sink); |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 946 | } |
| 947 | } |
brianosman | 05c987c | 2016-05-09 13:42:16 -0700 | [diff] [blame] | 948 | |
| 949 | // If no configs were requested (just running tests, perhaps?), then we're okay. |
| 950 | // Otherwise, make sure that at least one sink was constructed correctly. This catches |
| 951 | // the case of bots without a GPU being assigned GPU configs. |
| 952 | return (configs.count() == 0) || (gSinks.count() > 0); |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 953 | } |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 954 | |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 955 | static bool dump_png(SkBitmap bitmap, const char* path, const char* md5) { |
| 956 | const int w = bitmap.width(), |
| 957 | h = bitmap.height(); |
| 958 | |
brianosman | 3c579dc | 2016-04-19 09:18:11 -0700 | [diff] [blame] | 959 | sk_sp<SkData> encodedBitmap = sk_tools::encode_bitmap_for_png(bitmap); |
| 960 | if (encodedBitmap.get() == nullptr) { |
| 961 | return false; |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 962 | } |
brianosman | 3c579dc | 2016-04-19 09:18:11 -0700 | [diff] [blame] | 963 | uint32_t* rgba = static_cast<uint32_t*>(encodedBitmap.get()->writable_data()); |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 964 | |
| 965 | // We don't need bitmap anymore. Might as well drop our ref. |
mtklein | fccb77d | 2015-08-24 14:13:29 -0700 | [diff] [blame] | 966 | bitmap.reset(); |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 967 | |
mtklein | c64137c | 2015-08-25 10:56:08 -0700 | [diff] [blame] | 968 | FILE* f = fopen(path, "wb"); |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 969 | if (!f) { return false; } |
| 970 | |
| 971 | png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr); |
| 972 | if (!png) { |
| 973 | fclose(f); |
| 974 | return false; |
| 975 | } |
| 976 | |
| 977 | png_infop info = png_create_info_struct(png); |
| 978 | if (!info) { |
| 979 | png_destroy_write_struct(&png, &info); |
| 980 | fclose(f); |
| 981 | return false; |
| 982 | } |
| 983 | |
mtklein | d69ece6 | 2015-09-10 10:37:44 -0700 | [diff] [blame] | 984 | SkString description; |
| 985 | description.append("Key: "); |
| 986 | for (int i = 0; i < FLAGS_key.count(); i++) { |
| 987 | description.appendf("%s ", FLAGS_key[i]); |
| 988 | } |
| 989 | description.append("Properties: "); |
| 990 | for (int i = 0; i < FLAGS_properties.count(); i++) { |
| 991 | description.appendf("%s ", FLAGS_properties[i]); |
| 992 | } |
| 993 | description.appendf("MD5: %s", md5); |
| 994 | |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 995 | png_text text[2]; |
| 996 | text[0].key = (png_charp)"Author"; |
| 997 | text[0].text = (png_charp)"DM dump_png()"; |
| 998 | text[0].compression = PNG_TEXT_COMPRESSION_NONE; |
| 999 | text[1].key = (png_charp)"Description"; |
mtklein | d69ece6 | 2015-09-10 10:37:44 -0700 | [diff] [blame] | 1000 | text[1].text = (png_charp)description.c_str(); |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 1001 | text[1].compression = PNG_TEXT_COMPRESSION_NONE; |
| 1002 | png_set_text(png, info, text, 2); |
| 1003 | |
| 1004 | png_init_io(png, f); |
| 1005 | png_set_IHDR(png, info, (png_uint_32)w, (png_uint_32)h, 8, |
| 1006 | PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, |
| 1007 | PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); |
| 1008 | png_write_info(png, info); |
| 1009 | for (int j = 0; j < h; j++) { |
brianosman | 3c579dc | 2016-04-19 09:18:11 -0700 | [diff] [blame] | 1010 | png_bytep row = (png_bytep)(rgba + w*j); |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 1011 | png_write_rows(png, &row, 1); |
| 1012 | } |
| 1013 | png_write_end(png, info); |
| 1014 | |
| 1015 | png_destroy_write_struct(&png, &info); |
| 1016 | fclose(f); |
| 1017 | return true; |
| 1018 | } |
| 1019 | |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 1020 | static bool match(const char* needle, const char* haystack) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1021 | return 0 == strcmp("_", needle) || nullptr != strstr(haystack, needle); |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 1022 | } |
| 1023 | |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1024 | static bool is_blacklisted(const char* sink, const char* src, |
| 1025 | const char* srcOptions, const char* name) { |
mtklein | 0d243ff | 2015-04-03 07:51:00 -0700 | [diff] [blame] | 1026 | for (int i = 0; i < FLAGS_blacklist.count() - 3; i += 4) { |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 1027 | if (match(FLAGS_blacklist[i+0], sink) && |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 1028 | match(FLAGS_blacklist[i+1], src) && |
| 1029 | match(FLAGS_blacklist[i+2], srcOptions) && |
| 1030 | match(FLAGS_blacklist[i+3], name)) { |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1031 | return true; |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 1032 | } |
| 1033 | } |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1034 | return false; |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 1035 | } |
| 1036 | |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1037 | // Even when a Task Sink reports to be non-threadsafe (e.g. GPU), we know things like |
| 1038 | // .png encoding are definitely thread safe. This lets us offload that work to CPU threads. |
| 1039 | static SkTaskGroup gDefinitelyThreadSafeWork; |
| 1040 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1041 | // The finest-grained unit of work we can run: draw a single Src into a single Sink, |
| 1042 | // report any errors, and perhaps write out the output: a .png of the bitmap, or a raw stream. |
| 1043 | struct Task { |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 1044 | Task(const TaggedSrc& src, const TaggedSink& sink) : src(src), sink(sink) {} |
| 1045 | const TaggedSrc& src; |
| 1046 | const TaggedSink& sink; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1047 | |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1048 | static void Run(const Task& task) { |
| 1049 | SkString name = task.src->name(); |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 1050 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 1051 | SkString log; |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1052 | if (!FLAGS_dryRun) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1053 | SkBitmap bitmap; |
| 1054 | SkDynamicMemoryWStream stream; |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1055 | start(task.sink.tag.c_str(), task.src.tag.c_str(), |
| 1056 | task.src.options.c_str(), name.c_str()); |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1057 | Error err = task.sink->draw(*task.src, &bitmap, &stream, &log); |
mtklein | b3b13b7 | 2016-03-07 13:20:52 -0800 | [diff] [blame] | 1058 | if (!log.isEmpty()) { |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 1059 | info("%s %s %s %s:\n%s\n", task.sink.tag.c_str() |
| 1060 | , task.src.tag.c_str() |
| 1061 | , task.src.options.c_str() |
| 1062 | , name.c_str() |
| 1063 | , log.c_str()); |
mtklein | b3b13b7 | 2016-03-07 13:20:52 -0800 | [diff] [blame] | 1064 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1065 | if (!err.isEmpty()) { |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 1066 | if (err.isFatal()) { |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 1067 | fail(SkStringPrintf("%s %s %s %s: %s", |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1068 | task.sink.tag.c_str(), |
| 1069 | task.src.tag.c_str(), |
| 1070 | task.src.options.c_str(), |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 1071 | name.c_str(), |
| 1072 | err.c_str())); |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 1073 | } else { |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1074 | done(task.sink.tag.c_str(), task.src.tag.c_str(), |
| 1075 | task.src.options.c_str(), name.c_str()); |
mtklein | ba6ada7 | 2016-01-21 09:39:35 -0800 | [diff] [blame] | 1076 | return; |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 1077 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1078 | } |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 1079 | |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1080 | // We're likely switching threads here, so we must capture by value, [=] or [foo,bar]. |
| 1081 | SkStreamAsset* data = stream.detachAsStream(); |
| 1082 | gDefinitelyThreadSafeWork.add([task,name,bitmap,data]{ |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 1083 | std::unique_ptr<SkStreamAsset> ownedData(data); |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1084 | |
| 1085 | // Why doesn't the copy constructor do this when we have pre-locked pixels? |
| 1086 | bitmap.lockPixels(); |
| 1087 | |
| 1088 | SkString md5; |
| 1089 | if (!FLAGS_writePath.isEmpty() || !FLAGS_readPath.isEmpty()) { |
| 1090 | SkMD5 hash; |
| 1091 | if (data->getLength()) { |
| 1092 | hash.writeStream(data, data->getLength()); |
| 1093 | data->rewind(); |
mtklein | 3840846 | 2015-07-08 07:25:27 -0700 | [diff] [blame] | 1094 | } else { |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1095 | // If we're BGRA (Linux, Windows), swizzle over to RGBA (Mac, Android). |
| 1096 | // This helps eliminate multiple 0-pixel-diff hashes on gold.skia.org. |
| 1097 | // (Android's general slow speed breaks the tie arbitrarily in RGBA's favor.) |
| 1098 | // We might consider promoting 565 to RGBA too. |
| 1099 | if (bitmap.colorType() == kBGRA_8888_SkColorType) { |
| 1100 | SkBitmap swizzle; |
| 1101 | SkAssertResult(bitmap.copyTo(&swizzle, kRGBA_8888_SkColorType)); |
| 1102 | hash.write(swizzle.getPixels(), swizzle.getSize()); |
| 1103 | } else { |
| 1104 | hash.write(bitmap.getPixels(), bitmap.getSize()); |
| 1105 | } |
| 1106 | } |
| 1107 | SkMD5::Digest digest; |
| 1108 | hash.finish(digest); |
| 1109 | for (int i = 0; i < 16; i++) { |
| 1110 | md5.appendf("%02x", digest.data[i]); |
mtklein | 3840846 | 2015-07-08 07:25:27 -0700 | [diff] [blame] | 1111 | } |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 1112 | } |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 1113 | |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1114 | if (!FLAGS_readPath.isEmpty() && |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1115 | !gGold.contains(Gold(task.sink.tag, task.src.tag, |
| 1116 | task.src.options, name, md5))) { |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1117 | fail(SkStringPrintf("%s not found for %s %s %s %s in %s", |
| 1118 | md5.c_str(), |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1119 | task.sink.tag.c_str(), |
| 1120 | task.src.tag.c_str(), |
| 1121 | task.src.options.c_str(), |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1122 | name.c_str(), |
| 1123 | FLAGS_readPath[0])); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1124 | } |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1125 | |
| 1126 | if (!FLAGS_writePath.isEmpty()) { |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1127 | const char* ext = task.sink->fileExtension(); |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1128 | if (data->getLength()) { |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1129 | WriteToDisk(task, md5, ext, data, data->getLength(), nullptr); |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1130 | SkASSERT(bitmap.drawsNothing()); |
| 1131 | } else if (!bitmap.drawsNothing()) { |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1132 | WriteToDisk(task, md5, ext, nullptr, 0, &bitmap); |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1133 | } |
| 1134 | } |
| 1135 | }); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1136 | } |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1137 | 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] | 1138 | } |
| 1139 | |
| 1140 | static void WriteToDisk(const Task& task, |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 1141 | SkString md5, |
| 1142 | const char* ext, |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1143 | SkStream* data, size_t len, |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 1144 | const SkBitmap* bitmap) { |
mtklein | 409d470 | 2016-02-29 07:38:01 -0800 | [diff] [blame] | 1145 | bool gammaCorrect = false; |
| 1146 | if (bitmap) { |
Brian Osman | 7039f74 | 2016-11-01 15:56:16 -0400 | [diff] [blame] | 1147 | gammaCorrect = SkToBool(bitmap->info().colorSpace()); |
mtklein | 409d470 | 2016-02-29 07:38:01 -0800 | [diff] [blame] | 1148 | } |
| 1149 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1150 | JsonWriter::BitmapResult result; |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 1151 | result.name = task.src->name(); |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1152 | result.config = task.sink.tag; |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 1153 | result.sourceType = task.src.tag; |
| 1154 | result.sourceOptions = task.src.options; |
| 1155 | result.ext = ext; |
mtklein | 409d470 | 2016-02-29 07:38:01 -0800 | [diff] [blame] | 1156 | result.gammaCorrect = gammaCorrect; |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 1157 | result.md5 = md5; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1158 | JsonWriter::AddBitmapResult(result); |
| 1159 | |
mtklein | b0531a7 | 2015-04-07 13:38:48 -0700 | [diff] [blame] | 1160 | // If an MD5 is uninteresting, we want it noted in the JSON file, |
| 1161 | // but don't want to dump it out as a .png (or whatever ext is). |
| 1162 | if (gUninterestingHashes.contains(md5)) { |
| 1163 | return; |
| 1164 | } |
| 1165 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1166 | const char* dir = FLAGS_writePath[0]; |
| 1167 | if (0 == strcmp(dir, "@")) { // Needed for iOS. |
| 1168 | dir = FLAGS_resourcePath[0]; |
| 1169 | } |
| 1170 | sk_mkdir(dir); |
| 1171 | |
| 1172 | SkString path; |
| 1173 | if (FLAGS_nameByHash) { |
| 1174 | path = SkOSPath::Join(dir, result.md5.c_str()); |
| 1175 | path.append("."); |
| 1176 | path.append(ext); |
| 1177 | if (sk_exists(path.c_str())) { |
| 1178 | return; // Content-addressed. If it exists already, we're done. |
| 1179 | } |
| 1180 | } else { |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 1181 | path = SkOSPath::Join(dir, task.sink.tag.c_str()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1182 | sk_mkdir(path.c_str()); |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 1183 | path = SkOSPath::Join(path.c_str(), task.src.tag.c_str()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1184 | sk_mkdir(path.c_str()); |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 1185 | if (strcmp(task.src.options.c_str(), "") != 0) { |
| 1186 | path = SkOSPath::Join(path.c_str(), task.src.options.c_str()); |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 1187 | sk_mkdir(path.c_str()); |
| 1188 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1189 | path = SkOSPath::Join(path.c_str(), task.src->name().c_str()); |
| 1190 | path.append("."); |
| 1191 | path.append(ext); |
| 1192 | } |
| 1193 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1194 | if (bitmap) { |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 1195 | if (!dump_png(*bitmap, path.c_str(), result.md5.c_str())) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1196 | fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str())); |
| 1197 | return; |
| 1198 | } |
| 1199 | } else { |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 1200 | SkFILEWStream file(path.c_str()); |
| 1201 | if (!file.isValid()) { |
| 1202 | fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str())); |
| 1203 | return; |
| 1204 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1205 | if (!file.writeStream(data, len)) { |
| 1206 | fail(SkStringPrintf("Can't write to %s.\n", path.c_str())); |
| 1207 | return; |
| 1208 | } |
| 1209 | } |
| 1210 | } |
| 1211 | }; |
| 1212 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1213 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 1214 | |
| 1215 | // Unit tests don't fit so well into the Src/Sink model, so we give them special treatment. |
| 1216 | |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1217 | static SkTDArray<skiatest::Test> gParallelTests, gSerialTests; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1218 | |
| 1219 | static void gather_tests() { |
mtklein | 6c5fed2 | 2015-01-20 13:47:23 -0800 | [diff] [blame] | 1220 | if (!FLAGS_src.contains("tests")) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1221 | return; |
| 1222 | } |
mtklein | 6393c06 | 2015-04-27 08:45:01 -0700 | [diff] [blame] | 1223 | for (const skiatest::TestRegistry* r = skiatest::TestRegistry::Head(); r; r = r->next()) { |
| 1224 | if (!in_shard()) { |
| 1225 | continue; |
| 1226 | } |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1227 | // Despite its name, factory() is returning a reference to |
| 1228 | // link-time static const POD data. |
| 1229 | const skiatest::Test& test = r->factory(); |
| 1230 | if (SkCommandLineFlags::ShouldSkip(FLAGS_match, test.name)) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1231 | continue; |
| 1232 | } |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1233 | if (test.needsGpu && gpu_supported()) { |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1234 | (FLAGS_gpu_threading ? gParallelTests : gSerialTests).push(test); |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1235 | } else if (!test.needsGpu && FLAGS_cpu) { |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1236 | gParallelTests.push(test); |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 1237 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1238 | } |
| 1239 | } |
| 1240 | |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1241 | static void run_test(skiatest::Test test) { |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1242 | struct : public skiatest::Reporter { |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 1243 | void reportFailed(const skiatest::Failure& failure) override { |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1244 | fail(failure.toString()); |
| 1245 | JsonWriter::AddTestFailure(failure); |
| 1246 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 1247 | bool allowExtendedTest() const override { |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1248 | return FLAGS_pathOpsExtended; |
| 1249 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 1250 | bool verbose() const override { return FLAGS_veryVerbose; } |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1251 | } reporter; |
djsollen | 824996a | 2015-06-12 12:06:22 -0700 | [diff] [blame] | 1252 | |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1253 | if (!FLAGS_dryRun && !is_blacklisted("_", "tests", "_", test.name)) { |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1254 | start("unit", "test", "", test.name); |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 1255 | GrContextFactory factory; |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1256 | test.proc(&reporter, &factory); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1257 | } |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1258 | done("unit", "test", "", test.name); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1259 | } |
| 1260 | |
| 1261 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 1262 | |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 1263 | DEFINE_int32(status_sec, 15, "Print status this often (and if we crash)."); |
| 1264 | |
| 1265 | SkThread* start_status_thread() { |
| 1266 | auto thread = new SkThread([] (void*) { |
| 1267 | for (;;) { |
| 1268 | print_status(); |
| 1269 | #if defined(SK_BUILD_FOR_WIN) |
| 1270 | Sleep(FLAGS_status_sec * 1000); |
| 1271 | #else |
| 1272 | sleep(FLAGS_status_sec); |
| 1273 | #endif |
mtklein | 2e1c47e | 2015-03-12 07:16:56 -0700 | [diff] [blame] | 1274 | } |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 1275 | }); |
| 1276 | thread->start(); |
| 1277 | return thread; |
mtklein | de6fc2b | 2015-03-12 06:28:54 -0700 | [diff] [blame] | 1278 | } |
| 1279 | |
caryclark | 83ca628 | 2015-06-10 09:31:09 -0700 | [diff] [blame] | 1280 | #define PORTABLE_FONT_PREFIX "Toy Liberation " |
| 1281 | |
mboc | ee6a991 | 2016-05-31 11:42:36 -0700 | [diff] [blame] | 1282 | static sk_sp<SkTypeface> create_from_name(const char familyName[], SkFontStyle style) { |
caryclark | 83ca628 | 2015-06-10 09:31:09 -0700 | [diff] [blame] | 1283 | if (familyName && strlen(familyName) > sizeof(PORTABLE_FONT_PREFIX) |
| 1284 | && !strncmp(familyName, PORTABLE_FONT_PREFIX, sizeof(PORTABLE_FONT_PREFIX) - 1)) { |
caryclark | 1818acb | 2015-07-24 12:09:25 -0700 | [diff] [blame] | 1285 | return sk_tool_utils::create_portable_typeface(familyName, style); |
caryclark | 83ca628 | 2015-06-10 09:31:09 -0700 | [diff] [blame] | 1286 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1287 | return nullptr; |
caryclark | 83ca628 | 2015-06-10 09:31:09 -0700 | [diff] [blame] | 1288 | } |
| 1289 | |
| 1290 | #undef PORTABLE_FONT_PREFIX |
| 1291 | |
mboc | ee6a991 | 2016-05-31 11:42:36 -0700 | [diff] [blame] | 1292 | extern sk_sp<SkTypeface> (*gCreateTypefaceDelegate)(const char [], SkFontStyle ); |
caryclark | 83ca628 | 2015-06-10 09:31:09 -0700 | [diff] [blame] | 1293 | |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 1294 | int dm_main(); |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 1295 | int dm_main() { |
bsalomon | 71de353 | 2016-04-26 14:27:21 -0700 | [diff] [blame] | 1296 | setbuf(stdout, nullptr); |
mtklein | 246ba3a | 2016-02-23 10:39:36 -0800 | [diff] [blame] | 1297 | setup_crash_handler(); |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 1298 | |
Yuqian Li | ba62b4a | 2016-12-14 13:46:53 -0500 | [diff] [blame] | 1299 | gSkUseAnalyticAA = FLAGS_analyticAA; |
liyuqian | 38911a7 | 2016-10-04 11:23:22 -0700 | [diff] [blame] | 1300 | |
mtklein | a483da3 | 2016-03-17 12:53:36 -0700 | [diff] [blame] | 1301 | if (FLAGS_verbose) { |
| 1302 | gVLog = stderr; |
| 1303 | } else if (!FLAGS_writePath.isEmpty()) { |
mtklein | 51c8cfc | 2016-03-11 12:59:09 -0800 | [diff] [blame] | 1304 | sk_mkdir(FLAGS_writePath[0]); |
mtklein | a1ce216 | 2016-07-22 12:23:46 -0700 | [diff] [blame] | 1305 | gVLog = fopen(SkOSPath::Join(FLAGS_writePath[0], "verbose.log").c_str(), "w"); |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 1306 | } |
| 1307 | |
mtklein | 5286f02 | 2016-01-22 08:18:14 -0800 | [diff] [blame] | 1308 | 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] | 1309 | SkAutoGraphics ag; |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 1310 | SkTaskGroup::Enabler enabled(FLAGS_threads); |
caryclark | 83ca628 | 2015-06-10 09:31:09 -0700 | [diff] [blame] | 1311 | gCreateTypefaceDelegate = &create_from_name; |
commit-bot@chromium.org | a65e2fd | 2014-05-30 17:23:31 +0000 | [diff] [blame] | 1312 | |
halcanary | 7d57124 | 2016-02-24 17:59:16 -0800 | [diff] [blame] | 1313 | { |
| 1314 | SkString testResourcePath = GetResourcePath("color_wheel.png"); |
| 1315 | SkFILEStream testResource(testResourcePath.c_str()); |
| 1316 | if (!testResource.isValid()) { |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 1317 | info("Some resources are missing. Do you need to set --resourcePath?\n"); |
halcanary | 7d57124 | 2016-02-24 17:59:16 -0800 | [diff] [blame] | 1318 | } |
| 1319 | } |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 1320 | gather_gold(); |
borenet | 09ed480 | 2015-04-03 14:15:33 -0700 | [diff] [blame] | 1321 | gather_uninteresting_hashes(); |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 1322 | |
scroggo | 8673714 | 2016-02-03 12:19:11 -0800 | [diff] [blame] | 1323 | if (!gather_srcs()) { |
| 1324 | return 1; |
| 1325 | } |
brianosman | 05c987c | 2016-05-09 13:42:16 -0700 | [diff] [blame] | 1326 | if (!gather_sinks()) { |
| 1327 | return 1; |
| 1328 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1329 | gather_tests(); |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1330 | gPending = gSrcs.count() * gSinks.count() + gParallelTests.count() + gSerialTests.count(); |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 1331 | info("%d srcs * %d sinks + %d tests == %d tasks", |
| 1332 | gSrcs.count(), gSinks.count(), gParallelTests.count() + gSerialTests.count(), gPending); |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 1333 | std::unique_ptr<SkThread> statusThread(start_status_thread()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1334 | |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1335 | // Kick off as much parallel work as we can, making note of any serial work we'll need to do. |
| 1336 | SkTaskGroup parallel; |
| 1337 | SkTArray<Task> serial; |
| 1338 | |
| 1339 | for (auto& sink : gSinks) |
| 1340 | for (auto& src : gSrcs) { |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1341 | if (src->veto(sink->flags()) || |
| 1342 | is_blacklisted(sink.tag.c_str(), src.tag.c_str(), |
| 1343 | src.options.c_str(), src->name().c_str())) { |
mtklein | f10637f | 2016-06-10 13:56:35 -0700 | [diff] [blame] | 1344 | SkAutoMutexAcquire lock(gMutex); |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1345 | gPending--; |
| 1346 | continue; |
| 1347 | } |
| 1348 | |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1349 | Task task(src, sink); |
| 1350 | if (src->serial() || sink->serial()) { |
| 1351 | serial.push_back(task); |
| 1352 | } else { |
| 1353 | parallel.add([task] { Task::Run(task); }); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1354 | } |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 1355 | } |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1356 | for (auto test : gParallelTests) { |
| 1357 | parallel.add([test] { run_test(test); }); |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 1358 | } |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1359 | |
| 1360 | // With the parallel work running, run serial tasks and tests here on main thread. |
| 1361 | for (auto task : serial) { Task::Run(task); } |
| 1362 | for (auto test : gSerialTests) { run_test(test); } |
| 1363 | |
| 1364 | // Wait for any remaining parallel work to complete (including any spun off of serial tasks). |
| 1365 | parallel.wait(); |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1366 | gDefinitelyThreadSafeWork.wait(); |
| 1367 | |
mtklein | da884c4 | 2016-02-24 18:00:23 -0800 | [diff] [blame] | 1368 | // We'd better have run everything. |
| 1369 | SkASSERT(gPending == 0); |
mtklein | e027f17 | 2016-02-26 15:53:06 -0800 | [diff] [blame] | 1370 | // Make sure we've flushed all our results to disk. |
| 1371 | JsonWriter::DumpJson(); |
mtklein | da884c4 | 2016-02-24 18:00:23 -0800 | [diff] [blame] | 1372 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1373 | // At this point we're back in single-threaded land. |
caryclark | f53ce80 | 2015-06-15 06:48:30 -0700 | [diff] [blame] | 1374 | sk_tool_utils::release_portable_typefaces(); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 1375 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1376 | if (gFailures.count() > 0) { |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 1377 | info("Failures:\n"); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1378 | for (int i = 0; i < gFailures.count(); i++) { |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 1379 | info("\t%s\n", gFailures[i].c_str()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1380 | } |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 1381 | info("%d failures\n", gFailures.count()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1382 | return 1; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 1383 | } |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 1384 | |
| 1385 | #ifdef SK_PDF_IMAGE_STATS |
halcanary | 7a14b31 | 2015-10-01 07:28:13 -0700 | [diff] [blame] | 1386 | SkPDFImageDumpStats(); |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 1387 | #endif // SK_PDF_IMAGE_STATS |
| 1388 | |
| 1389 | print_status(); |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 1390 | info("Finished!\n"); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1391 | return 0; |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 1392 | } |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 1393 | |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1394 | // TODO: currently many GPU tests are declared outside SK_SUPPORT_GPU guards. |
| 1395 | // Thus we export the empty RunWithGPUTestContexts when SK_SUPPORT_GPU=0. |
| 1396 | namespace skiatest { |
bsalomon | 758586c | 2016-04-06 14:02:39 -0700 | [diff] [blame] | 1397 | |
| 1398 | #if SK_SUPPORT_GPU |
| 1399 | bool IsGLContextType(sk_gpu_test::GrContextFactory::ContextType type) { |
| 1400 | return kOpenGL_GrBackend == GrContextFactory::ContextTypeBackend(type); |
| 1401 | } |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 1402 | bool IsVulkanContextType(sk_gpu_test::GrContextFactory::ContextType type) { |
| 1403 | return kVulkan_GrBackend == GrContextFactory::ContextTypeBackend(type); |
| 1404 | } |
bsalomon | 758586c | 2016-04-06 14:02:39 -0700 | [diff] [blame] | 1405 | bool IsRenderingGLContextType(sk_gpu_test::GrContextFactory::ContextType type) { |
| 1406 | return IsGLContextType(type) && GrContextFactory::IsRenderingContext(type); |
| 1407 | } |
| 1408 | bool IsNullGLContextType(sk_gpu_test::GrContextFactory::ContextType type) { |
| 1409 | return type == GrContextFactory::kNullGL_ContextType; |
| 1410 | } |
Brian Osman | 287f651 | 2016-12-05 11:35:07 -0500 | [diff] [blame] | 1411 | const char* ContextTypeName(GrContextFactory::ContextType contextType) { |
| 1412 | switch (contextType) { |
| 1413 | case GrContextFactory::kGL_ContextType: |
| 1414 | return "OpenGL"; |
| 1415 | case GrContextFactory::kGLES_ContextType: |
| 1416 | return "OpenGLES"; |
| 1417 | case GrContextFactory::kANGLE_D3D9_ES2_ContextType: |
| 1418 | return "ANGLE D3D9 ES2"; |
| 1419 | case GrContextFactory::kANGLE_D3D11_ES2_ContextType: |
| 1420 | return "ANGLE D3D11 ES2"; |
| 1421 | case GrContextFactory::kANGLE_D3D11_ES3_ContextType: |
| 1422 | return "ANGLE D3D11 ES3"; |
| 1423 | case GrContextFactory::kANGLE_GL_ES2_ContextType: |
| 1424 | return "ANGLE GL ES2"; |
| 1425 | case GrContextFactory::kANGLE_GL_ES3_ContextType: |
| 1426 | return "ANGLE GL ES3"; |
| 1427 | case GrContextFactory::kCommandBuffer_ContextType: |
| 1428 | return "Command Buffer"; |
| 1429 | case GrContextFactory::kMESA_ContextType: |
| 1430 | return "Mesa"; |
| 1431 | case GrContextFactory::kNullGL_ContextType: |
| 1432 | return "Null GL"; |
| 1433 | case GrContextFactory::kDebugGL_ContextType: |
| 1434 | return "Debug GL"; |
| 1435 | case GrContextFactory::kVulkan_ContextType: |
| 1436 | return "Vulkan"; |
| 1437 | } |
| 1438 | SkDEBUGFAIL("Unreachable"); |
| 1439 | return "Unknown"; |
| 1440 | } |
bsalomon | 758586c | 2016-04-06 14:02:39 -0700 | [diff] [blame] | 1441 | #else |
| 1442 | bool IsGLContextType(int) { return false; } |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 1443 | bool IsVulkanContextType(int) { return false; } |
bsalomon | 758586c | 2016-04-06 14:02:39 -0700 | [diff] [blame] | 1444 | bool IsRenderingGLContextType(int) { return false; } |
| 1445 | bool IsNullGLContextType(int) { return false; } |
| 1446 | #endif |
| 1447 | |
| 1448 | void RunWithGPUTestContexts(GrContextTestFn* test, GrContextTypeFilterFn* contextTypeFilter, |
bsalomon | f2f1c17 | 2016-04-05 12:59:06 -0700 | [diff] [blame] | 1449 | Reporter* reporter, GrContextFactory* factory) { |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1450 | #if SK_SUPPORT_GPU |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 1451 | |
bsalomon | 758586c | 2016-04-06 14:02:39 -0700 | [diff] [blame] | 1452 | for (int typeInt = 0; typeInt < GrContextFactory::kContextTypeCnt; ++typeInt) { |
| 1453 | GrContextFactory::ContextType contextType = (GrContextFactory::ContextType) typeInt; |
Brian Osman | aa2219c | 2016-12-05 10:12:17 -0500 | [diff] [blame] | 1454 | // 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] | 1455 | // desktop since tests do not account for not fixing http://skbug.com/2809 |
| 1456 | if (contextType == GrContextFactory::kGL_ContextType || |
| 1457 | contextType == GrContextFactory::kGLES_ContextType) { |
| 1458 | if (contextType != GrContextFactory::kNativeGL_ContextType) { |
| 1459 | continue; |
| 1460 | } |
| 1461 | } |
Brian Osman | aa2219c | 2016-12-05 10:12:17 -0500 | [diff] [blame] | 1462 | ContextInfo ctxInfo = factory->getContextInfo(contextType); |
| 1463 | if (contextTypeFilter && !(*contextTypeFilter)(contextType)) { |
| 1464 | continue; |
| 1465 | } |
Brian Osman | 287f651 | 2016-12-05 11:35:07 -0500 | [diff] [blame] | 1466 | ReporterContext ctx(reporter, SkString(ContextTypeName(contextType))); |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 1467 | if (ctxInfo.grContext()) { |
bsalomon | f2f1c17 | 2016-04-05 12:59:06 -0700 | [diff] [blame] | 1468 | (*test)(reporter, ctxInfo); |
kkinnunen | 5219fd9 | 2015-12-10 06:28:13 -0800 | [diff] [blame] | 1469 | } |
bsalomon | f2f1c17 | 2016-04-05 12:59:06 -0700 | [diff] [blame] | 1470 | ctxInfo = factory->getContextInfo(contextType, |
csmartdalton | 6270e55 | 2016-09-13 10:41:49 -0700 | [diff] [blame] | 1471 | GrContextFactory::ContextOptions::kEnableNVPR); |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 1472 | if (ctxInfo.grContext()) { |
bsalomon | f2f1c17 | 2016-04-05 12:59:06 -0700 | [diff] [blame] | 1473 | (*test)(reporter, ctxInfo); |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1474 | } |
| 1475 | } |
| 1476 | #endif |
| 1477 | } |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1478 | } // namespace skiatest |
| 1479 | |
borenet | 4808757 | 2015-04-02 12:16:36 -0700 | [diff] [blame] | 1480 | #if !defined(SK_BUILD_FOR_IOS) |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 1481 | int main(int argc, char** argv) { |
| 1482 | SkCommandLineFlags::Parse(argc, argv); |
| 1483 | return dm_main(); |
| 1484 | } |
| 1485 | #endif |