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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "dm/DMJsonWriter.h" |
| 9 | #include "dm/DMSrcSink.h" |
| 10 | #include "include/codec/SkCodec.h" |
| 11 | #include "include/core/SkBBHFactory.h" |
| 12 | #include "include/core/SkColorPriv.h" |
| 13 | #include "include/core/SkColorSpace.h" |
| 14 | #include "include/core/SkData.h" |
| 15 | #include "include/core/SkDocument.h" |
| 16 | #include "include/core/SkFontMgr.h" |
| 17 | #include "include/core/SkGraphics.h" |
| 18 | #include "include/ports/SkTypeface_win.h" |
| 19 | #include "include/private/SkChecksum.h" |
| 20 | #include "include/private/SkHalf.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 21 | #include "include/private/SkSpinlock.h" |
| 22 | #include "include/private/SkTHash.h" |
| 23 | #include "src/core/SkColorSpacePriv.h" |
Ben Wagner | ab6eefe | 2019-05-20 11:02:49 -0400 | [diff] [blame] | 24 | #include "src/core/SkLeanWindows.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 25 | #include "src/core/SkMD5.h" |
| 26 | #include "src/core/SkOSFile.h" |
| 27 | #include "src/core/SkTaskGroup.h" |
| 28 | #include "src/utils/SkOSPath.h" |
| 29 | #include "tests/Test.h" |
Jim Van Verth | 8a9a371 | 2019-05-31 10:49:12 -0400 | [diff] [blame] | 30 | #include "tools/AutoreleasePool.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 31 | #include "tools/HashAndEncode.h" |
| 32 | #include "tools/ProcStats.h" |
| 33 | #include "tools/Resources.h" |
| 34 | #include "tools/ToolUtils.h" |
| 35 | #include "tools/flags/CommonFlags.h" |
| 36 | #include "tools/flags/CommonFlagsConfig.h" |
| 37 | #include "tools/ios_utils.h" |
| 38 | #include "tools/trace/ChromeTracingTracer.h" |
| 39 | #include "tools/trace/EventTracingPriv.h" |
| 40 | #include "tools/trace/SkDebugfTracer.h" |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 41 | |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 42 | #include <vector> |
| 43 | |
bungeman | 60e0fee | 2015-08-26 05:15:46 -0700 | [diff] [blame] | 44 | #include <stdlib.h> |
| 45 | |
Mike Klein | 8f11d4d | 2018-01-24 12:42:55 -0500 | [diff] [blame] | 46 | #ifndef SK_BUILD_FOR_WIN |
scroggo | 27a5834 | 2015-10-28 08:56:41 -0700 | [diff] [blame] | 47 | #include <unistd.h> |
| 48 | #endif |
| 49 | |
Dongwon Kang | 0c7861f | 2018-02-16 10:55:21 -0800 | [diff] [blame] | 50 | #if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && defined(SK_HAS_HEIF_LIBRARY) |
| 51 | #include <binder/IPCThreadState.h> |
| 52 | #endif |
| 53 | |
Mike Reed | 7c26ca7 | 2017-07-05 15:45:52 -0400 | [diff] [blame] | 54 | extern bool gSkForceRasterPipelineBlitter; |
| 55 | |
Mike Klein | 84836b7 | 2019-03-21 11:31:36 -0500 | [diff] [blame] | 56 | static DEFINE_string(src, "tests gm skp image", "Source types to test."); |
| 57 | static DEFINE_bool(nameByHash, false, |
| 58 | "If true, write to FLAGS_writePath[0]/<hash>.png instead of " |
| 59 | "to FLAGS_writePath[0]/<config>/<sourceType>/<sourceOptions>/<name>.png"); |
| 60 | static DEFINE_bool2(pathOpsExtended, x, false, "Run extended pathOps tests."); |
| 61 | static DEFINE_string(matrix, "1 0 0 1", |
| 62 | "2x2 scale+skew matrix to apply or upright when using " |
| 63 | "'matrix' or 'upright' in config."); |
| 64 | static 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] | 65 | |
Mike Klein | 84836b7 | 2019-03-21 11:31:36 -0500 | [diff] [blame] | 66 | static DEFINE_string(blacklist, "", |
Chris Dalton | ecf78ac | 2017-08-15 15:43:08 -0600 | [diff] [blame] | 67 | "Space-separated config/src/srcOptions/name quadruples to blacklist. " |
| 68 | "'_' matches anything. '~' negates the match. E.g. \n" |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 69 | "'--blacklist gpu skp _ _' will blacklist all SKPs drawn into the gpu config.\n" |
Chris Dalton | ecf78ac | 2017-08-15 15:43:08 -0600 | [diff] [blame] | 70 | "'--blacklist gpu skp _ _ 8888 gm _ aarects' will also blacklist the aarects GM on 8888.\n" |
| 71 | "'--blacklist ~8888 svg _ svgparse_' blocks non-8888 SVGs that contain \"svgparse_\" in " |
| 72 | "the name."); |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 73 | |
Mike Klein | 84836b7 | 2019-03-21 11:31:36 -0500 | [diff] [blame] | 74 | static DEFINE_string2(readPath, r, "", |
| 75 | "If set check for equality with golden results in this directory."); |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 76 | DEFINE_string2(writePath, w, "", "If set, write bitmaps here as .pngs."); |
| 77 | |
Brian Osman | 57796b3 | 2019-01-25 18:02:59 +0000 | [diff] [blame] | 78 | |
Mike Klein | 84836b7 | 2019-03-21 11:31:36 -0500 | [diff] [blame] | 79 | static DEFINE_string(uninterestingHashesFile, "", |
borenet | 09ed480 | 2015-04-03 14:15:33 -0700 | [diff] [blame] | 80 | "File containing a list of uninteresting hashes. If a result hashes to something in " |
| 81 | "this list, no image is written for that result."); |
| 82 | |
Mike Klein | 5b3f343 | 2019-03-21 11:42:21 -0500 | [diff] [blame] | 83 | static DEFINE_int(shards, 1, "We're splitting source data into this many shards."); |
| 84 | static DEFINE_int(shard, 0, "Which shard do I run?"); |
mtklein | 6393c06 | 2015-04-27 08:45:01 -0700 | [diff] [blame] | 85 | |
Mike Klein | 84836b7 | 2019-03-21 11:31:36 -0500 | [diff] [blame] | 86 | static DEFINE_string(mskps, "", "Directory to read mskps from, or a single mskp file."); |
| 87 | static DEFINE_bool(forceRasterPipeline, false, "sets gSkForceRasterPipelineBlitter"); |
halcanary | 45420a9 | 2016-06-02 12:41:14 -0700 | [diff] [blame] | 88 | |
Mike Klein | 84836b7 | 2019-03-21 11:31:36 -0500 | [diff] [blame] | 89 | static DEFINE_string(bisect, "", |
Chris Dalton | 184c37e | 2018-09-28 11:27:39 -0600 | [diff] [blame] | 90 | "Pair of: SKP file to bisect, followed by an l/r bisect trail string (e.g., 'lrll'). The " |
| 91 | "l/r trail specifies which half to keep at each step of a binary search through the SKP's " |
| 92 | "paths. An empty string performs no bisect. Only the SkPaths are bisected; all other draws " |
| 93 | "are thrown out. This is useful for finding a reduced repo case for path drawing bugs."); |
| 94 | |
Mike Klein | 84836b7 | 2019-03-21 11:31:36 -0500 | [diff] [blame] | 95 | static DEFINE_bool(ignoreSigInt, false, "ignore SIGINT signals during test execution"); |
Derek Sollenberger | edfe3df | 2017-07-19 15:25:24 -0400 | [diff] [blame] | 96 | |
Mike Klein | 84836b7 | 2019-03-21 11:31:36 -0500 | [diff] [blame] | 97 | static DEFINE_string(dont_write, "", "File extensions to skip writing to --writePath."); // See skia:6821 |
Mike Klein | 97d6a7a | 2017-07-24 10:37:19 -0400 | [diff] [blame] | 98 | |
Mike Klein | 84836b7 | 2019-03-21 11:31:36 -0500 | [diff] [blame] | 99 | static DEFINE_bool(checkF16, false, "Ensure that F16Norm pixels are clamped."); |
Brian Osman | 582f686 | 2019-03-11 11:20:55 -0400 | [diff] [blame] | 100 | |
Mike Klein | 19fb397 | 2019-03-21 13:08:08 -0500 | [diff] [blame] | 101 | static DEFINE_string(colorImages, "", |
| 102 | "List of images and/or directories to decode with color correction. " |
| 103 | "A directory with no images is treated as a fatal error."); |
| 104 | |
Mike Klein | d0f321b | 2019-03-22 13:15:11 -0500 | [diff] [blame] | 105 | static DEFINE_bool2(veryVerbose, V, false, "tell individual tests to be verbose."); |
| 106 | |
Mike Klein | 629f5fc | 2019-03-22 14:55:19 -0500 | [diff] [blame] | 107 | static DEFINE_bool(cpu, true, "master switch for running CPU-bound work."); |
| 108 | static DEFINE_bool(gpu, true, "master switch for running GPU-bound work."); |
| 109 | |
| 110 | static DEFINE_bool(dryRun, false, |
| 111 | "just print the tests that would be run, without actually running them."); |
| 112 | |
| 113 | static DEFINE_string(images, "", |
| 114 | "List of images and/or directories to decode. A directory with no images" |
| 115 | " is treated as a fatal error."); |
| 116 | |
| 117 | static DEFINE_bool(simpleCodec, false, |
| 118 | "Runs of a subset of the codec tests, " |
| 119 | "with no scaling or subsetting, always using the canvas color type."); |
Mike Klein | 19fb397 | 2019-03-21 13:08:08 -0500 | [diff] [blame] | 120 | |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 121 | static DEFINE_string2(match, m, nullptr, |
| 122 | "[~][^]substring[$] [...] of name to run.\n" |
| 123 | "Multiple matches may be separated by spaces.\n" |
| 124 | "~ causes a matching name to always be skipped\n" |
| 125 | "^ requires the start of the name to match\n" |
| 126 | "$ requires the end of the name to match\n" |
| 127 | "^ and $ requires an exact match\n" |
| 128 | "If a name does not match any list entry,\n" |
| 129 | "it is skipped unless some list entry starts with ~"); |
| 130 | |
| 131 | static DEFINE_bool2(quiet, q, false, "if true, don't print status updates."); |
| 132 | static DEFINE_bool2(verbose, v, false, "enable verbose output from the test driver."); |
| 133 | |
| 134 | static DEFINE_string(skps, "skps", "Directory to read skps from."); |
| 135 | static DEFINE_string(lotties, "lotties", "Directory to read (Bodymovin) jsons from."); |
| 136 | static DEFINE_string(svgs, "", "Directory to read SVGs from, or a single SVG file."); |
| 137 | |
| 138 | static DEFINE_int_2(threads, j, -1, |
| 139 | "Run threadsafe tests on a threadpool with this many extra threads, " |
| 140 | "defaulting to one extra thread per core."); |
| 141 | |
| 142 | static DEFINE_string(key, "", |
| 143 | "Space-separated key/value pairs to add to JSON identifying this builder."); |
| 144 | static DEFINE_string(properties, "", |
| 145 | "Space-separated key/value pairs to add to JSON identifying this run."); |
| 146 | |
| 147 | |
Brian Osman | 1c1208e | 2019-06-24 13:36:05 -0400 | [diff] [blame] | 148 | #if defined(__MSVC_RUNTIME_CHECKS) |
| 149 | #include <rtcapi.h> |
| 150 | int RuntimeCheckErrorFunc(int errorType, const char* filename, int linenumber, |
| 151 | const char* moduleName, const char* fmt, ...) { |
| 152 | va_list args; |
| 153 | va_start(args, fmt); |
| 154 | vfprintf(stderr, fmt, args); |
| 155 | va_end(args); |
| 156 | |
| 157 | SkDebugf("Line #%d\nFile: %s\nModule: %s\n", |
| 158 | linenumber, filename ? filename : "Unknown", moduleName ? moduleName : "Unknwon"); |
| 159 | return 1; |
| 160 | } |
| 161 | #endif |
| 162 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 163 | using namespace DM; |
bsalomon | 3724e57 | 2016-03-30 18:56:19 -0700 | [diff] [blame] | 164 | using sk_gpu_test::GrContextFactory; |
bsalomon | 273c0f5 | 2016-03-31 10:59:06 -0700 | [diff] [blame] | 165 | using sk_gpu_test::GLTestContext; |
bsalomon | f2f1c17 | 2016-04-05 12:59:06 -0700 | [diff] [blame] | 166 | using sk_gpu_test::ContextInfo; |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 167 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 168 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 169 | |
Mike Klein | e127170 | 2019-03-07 11:46:59 -0600 | [diff] [blame] | 170 | static sk_sp<SkColorSpace> rec2020() { |
Hal Canary | be67a17 | 2019-05-24 10:13:36 -0400 | [diff] [blame] | 171 | return SkColorSpace::MakeRGB(SkNamedTransferFn::kRec2020, SkNamedGamut::kRec2020); |
Mike Klein | e127170 | 2019-03-07 11:46:59 -0600 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 175 | |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 176 | static FILE* gVLog; |
| 177 | |
| 178 | template <typename... Args> |
| 179 | static void vlog(const char* fmt, Args&&... args) { |
| 180 | if (gVLog) { |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 181 | fprintf(gVLog, fmt, args...); |
| 182 | fflush(gVLog); |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | template <typename... Args> |
| 187 | static void info(const char* fmt, Args&&... args) { |
| 188 | vlog(fmt, args...); |
| 189 | if (!FLAGS_quiet) { |
| 190 | printf(fmt, args...); |
| 191 | } |
| 192 | } |
| 193 | static void info(const char* fmt) { |
| 194 | if (!FLAGS_quiet) { |
| 195 | printf("%s", fmt); // Clang warns printf(fmt) is insecure. |
| 196 | } |
| 197 | } |
| 198 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 199 | static SkTArray<SkString> gFailures; |
| 200 | |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 201 | static void fail(const SkString& err) { |
Herb Derby | 9c71e7b | 2019-06-17 14:40:42 -0400 | [diff] [blame] | 202 | static SkSpinlock mutex; |
| 203 | SkAutoSpinlock lock(mutex); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 204 | SkDebugf("\n\nFAILURE: %s\n\n", err.c_str()); |
| 205 | gFailures.push_back(err); |
halcanary | 9e398f7 | 2015-01-10 11:18:04 -0800 | [diff] [blame] | 206 | } |
| 207 | |
mtklein | 0f7748a | 2016-07-25 15:27:29 -0700 | [diff] [blame] | 208 | struct Running { |
| 209 | SkString id; |
| 210 | SkThreadID thread; |
| 211 | |
| 212 | void dump() const { |
| 213 | info("\t%s\n", id.c_str()); |
| 214 | } |
| 215 | }; |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 216 | |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 217 | static void dump_json() { |
| 218 | if (!FLAGS_writePath.isEmpty()) { |
| 219 | JsonWriter::DumpJson(FLAGS_writePath[0], FLAGS_key, FLAGS_properties); |
| 220 | } |
| 221 | } |
| 222 | |
mtklein | 246ba3a | 2016-02-23 10:39:36 -0800 | [diff] [blame] | 223 | // We use a spinlock to make locking this in a signal handler _somewhat_ safe. |
Mike Klein | 03a95ad | 2017-06-23 12:36:32 -0400 | [diff] [blame] | 224 | static SkSpinlock gMutex; |
| 225 | static int gPending; |
mtklein | 0f7748a | 2016-07-25 15:27:29 -0700 | [diff] [blame] | 226 | static SkTArray<Running> gRunning; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 227 | |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 228 | static void done(const char* config, const char* src, const char* srcOptions, const char* name) { |
| 229 | SkString id = SkStringPrintf("%s %s %s %s", config, src, srcOptions, name); |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 230 | vlog("done %s\n", id.c_str()); |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 231 | int pending; |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 232 | { |
Herb Derby | a1b7be6 | 2019-05-09 16:59:18 -0400 | [diff] [blame] | 233 | SkAutoSpinlock lock(gMutex); |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 234 | for (int i = 0; i < gRunning.count(); i++) { |
mtklein | 0f7748a | 2016-07-25 15:27:29 -0700 | [diff] [blame] | 235 | if (gRunning[i].id == id) { |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 236 | gRunning.removeShuffle(i); |
| 237 | break; |
| 238 | } |
| 239 | } |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 240 | pending = --gPending; |
reed | 50bc051 | 2015-05-19 14:13:31 -0700 | [diff] [blame] | 241 | } |
Mike Klein | 03a95ad | 2017-06-23 12:36:32 -0400 | [diff] [blame] | 242 | |
| 243 | // We write out dm.json file and print out a progress update every once in a while. |
| 244 | // Notice this also handles the final dm.json and progress update when pending == 0. |
mtklein | a17241b | 2015-01-23 05:48:00 -0800 | [diff] [blame] | 245 | if (pending % 500 == 0) { |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 246 | dump_json(); |
Mike Klein | 03a95ad | 2017-06-23 12:36:32 -0400 | [diff] [blame] | 247 | |
| 248 | int curr = sk_tools::getCurrResidentSetSizeMB(), |
| 249 | peak = sk_tools::getMaxResidentSetSizeMB(); |
Mike Klein | 03a95ad | 2017-06-23 12:36:32 -0400 | [diff] [blame] | 250 | |
Herb Derby | a1b7be6 | 2019-05-09 16:59:18 -0400 | [diff] [blame] | 251 | SkAutoSpinlock lock(gMutex); |
Mike Klein | 21ba772 | 2018-10-02 13:57:44 +0000 | [diff] [blame] | 252 | info("\n%dMB RAM, %dMB peak, %d queued, %d active:\n", |
| 253 | curr, peak, gPending - gRunning.count(), gRunning.count()); |
Mike Klein | 03a95ad | 2017-06-23 12:36:32 -0400 | [diff] [blame] | 254 | for (auto& task : gRunning) { |
| 255 | task.dump(); |
| 256 | } |
mtklein | a17241b | 2015-01-23 05:48:00 -0800 | [diff] [blame] | 257 | } |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 258 | } |
| 259 | |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 260 | static void start(const char* config, const char* src, const char* srcOptions, const char* name) { |
| 261 | SkString id = SkStringPrintf("%s %s %s %s", config, src, srcOptions, name); |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 262 | vlog("start %s\n", id.c_str()); |
Herb Derby | a1b7be6 | 2019-05-09 16:59:18 -0400 | [diff] [blame] | 263 | SkAutoSpinlock lock(gMutex); |
mtklein | 0f7748a | 2016-07-25 15:27:29 -0700 | [diff] [blame] | 264 | gRunning.push_back({id,SkGetThreadID()}); |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 265 | } |
| 266 | |
Mike Klein | 3cc2d20 | 2016-10-24 11:39:43 -0400 | [diff] [blame] | 267 | static void find_culprit() { |
| 268 | // Assumes gMutex is locked. |
| 269 | SkThreadID thisThread = SkGetThreadID(); |
| 270 | for (auto& task : gRunning) { |
| 271 | if (task.thread == thisThread) { |
| 272 | info("Likely culprit:\n"); |
| 273 | task.dump(); |
mtklein | 0f7748a | 2016-07-25 15:27:29 -0700 | [diff] [blame] | 274 | } |
| 275 | } |
Mike Klein | 3cc2d20 | 2016-10-24 11:39:43 -0400 | [diff] [blame] | 276 | } |
mtklein | 0f7748a | 2016-07-25 15:27:29 -0700 | [diff] [blame] | 277 | |
Mike Klein | 8f11d4d | 2018-01-24 12:42:55 -0500 | [diff] [blame] | 278 | #if defined(SK_BUILD_FOR_WIN) |
mtklein | 5b64dab | 2016-06-09 08:59:48 -0700 | [diff] [blame] | 279 | static LONG WINAPI crash_handler(EXCEPTION_POINTERS* e) { |
mtklein | f855729 | 2016-02-29 06:35:28 -0800 | [diff] [blame] | 280 | static const struct { |
| 281 | const char* name; |
robertphillips | 7546786 | 2016-03-01 14:10:23 -0800 | [diff] [blame] | 282 | DWORD code; |
mtklein | f855729 | 2016-02-29 06:35:28 -0800 | [diff] [blame] | 283 | } kExceptions[] = { |
| 284 | #define _(E) {#E, E} |
| 285 | _(EXCEPTION_ACCESS_VIOLATION), |
| 286 | _(EXCEPTION_BREAKPOINT), |
| 287 | _(EXCEPTION_INT_DIVIDE_BY_ZERO), |
| 288 | _(EXCEPTION_STACK_OVERFLOW), |
| 289 | // TODO: more? |
| 290 | #undef _ |
| 291 | }; |
| 292 | |
Herb Derby | a1b7be6 | 2019-05-09 16:59:18 -0400 | [diff] [blame] | 293 | SkAutoSpinlock lock(gMutex); |
mtklein | 5b64dab | 2016-06-09 08:59:48 -0700 | [diff] [blame] | 294 | |
| 295 | const DWORD code = e->ExceptionRecord->ExceptionCode; |
| 296 | info("\nCaught exception %u", code); |
| 297 | for (const auto& exception : kExceptions) { |
| 298 | if (exception.code == code) { |
| 299 | info(" %s", exception.name); |
mtklein | f855729 | 2016-02-29 06:35:28 -0800 | [diff] [blame] | 300 | } |
mtklein | f855729 | 2016-02-29 06:35:28 -0800 | [diff] [blame] | 301 | } |
mtklein | 5b64dab | 2016-06-09 08:59:48 -0700 | [diff] [blame] | 302 | info(", was running:\n"); |
| 303 | for (auto& task : gRunning) { |
mtklein | 0f7748a | 2016-07-25 15:27:29 -0700 | [diff] [blame] | 304 | task.dump(); |
mtklein | 5b64dab | 2016-06-09 08:59:48 -0700 | [diff] [blame] | 305 | } |
mtklein | 0f7748a | 2016-07-25 15:27:29 -0700 | [diff] [blame] | 306 | find_culprit(); |
mtklein | 5b64dab | 2016-06-09 08:59:48 -0700 | [diff] [blame] | 307 | fflush(stdout); |
| 308 | |
mtklein | f855729 | 2016-02-29 06:35:28 -0800 | [diff] [blame] | 309 | // Execute default exception handler... hopefully, exit. |
| 310 | return EXCEPTION_EXECUTE_HANDLER; |
mtklein | 246ba3a | 2016-02-23 10:39:36 -0800 | [diff] [blame] | 311 | } |
| 312 | |
Mike Klein | 3cc2d20 | 2016-10-24 11:39:43 -0400 | [diff] [blame] | 313 | static void setup_crash_handler() { |
| 314 | SetUnhandledExceptionFilter(crash_handler); |
| 315 | } |
| 316 | #else |
mtklein | 246ba3a | 2016-02-23 10:39:36 -0800 | [diff] [blame] | 317 | #include <signal.h> |
Mike Klein | 3cc2d20 | 2016-10-24 11:39:43 -0400 | [diff] [blame] | 318 | #if !defined(SK_BUILD_FOR_ANDROID) |
| 319 | #include <execinfo.h> |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 320 | |
| 321 | #endif |
Mike Klein | 3cc2d20 | 2016-10-24 11:39:43 -0400 | [diff] [blame] | 322 | |
| 323 | static constexpr int max_of() { return 0; } |
| 324 | template <typename... Rest> |
| 325 | static constexpr int max_of(int x, Rest... rest) { |
| 326 | return x > max_of(rest...) ? x : max_of(rest...); |
| 327 | } |
| 328 | |
Mike Klein | c7278ad | 2018-02-15 09:26:54 -0500 | [diff] [blame] | 329 | static void (*previous_handler[max_of(SIGABRT,SIGBUS,SIGFPE,SIGILL,SIGSEGV,SIGTERM)+1])(int); |
mtklein | f855729 | 2016-02-29 06:35:28 -0800 | [diff] [blame] | 330 | |
mtklein | 5b64dab | 2016-06-09 08:59:48 -0700 | [diff] [blame] | 331 | static void crash_handler(int sig) { |
Herb Derby | a1b7be6 | 2019-05-09 16:59:18 -0400 | [diff] [blame] | 332 | SkAutoSpinlock lock(gMutex); |
mtklein | 5b64dab | 2016-06-09 08:59:48 -0700 | [diff] [blame] | 333 | |
Mike Klein | 701a358 | 2018-06-28 14:08:19 +0000 | [diff] [blame] | 334 | info("\nCaught signal %d [%s] (%dMB RAM, peak %dMB), was running:\n", |
| 335 | sig, strsignal(sig), |
| 336 | sk_tools::getCurrResidentSetSizeMB(), sk_tools::getMaxResidentSetSizeMB()); |
| 337 | |
mtklein | 5b64dab | 2016-06-09 08:59:48 -0700 | [diff] [blame] | 338 | for (auto& task : gRunning) { |
mtklein | 0f7748a | 2016-07-25 15:27:29 -0700 | [diff] [blame] | 339 | task.dump(); |
mtklein | 5b64dab | 2016-06-09 08:59:48 -0700 | [diff] [blame] | 340 | } |
mtklein | 0f7748a | 2016-07-25 15:27:29 -0700 | [diff] [blame] | 341 | find_culprit(); |
mtklein | 5b64dab | 2016-06-09 08:59:48 -0700 | [diff] [blame] | 342 | |
Mike Klein | 3cc2d20 | 2016-10-24 11:39:43 -0400 | [diff] [blame] | 343 | #if !defined(SK_BUILD_FOR_ANDROID) |
mtklein | 5b64dab | 2016-06-09 08:59:48 -0700 | [diff] [blame] | 344 | void* stack[64]; |
| 345 | int count = backtrace(stack, SK_ARRAY_COUNT(stack)); |
| 346 | char** symbols = backtrace_symbols(stack, count); |
| 347 | info("\nStack trace:\n"); |
| 348 | for (int i = 0; i < count; i++) { |
| 349 | info(" %s\n", symbols[i]); |
| 350 | } |
Mike Klein | 3cc2d20 | 2016-10-24 11:39:43 -0400 | [diff] [blame] | 351 | #endif |
mtklein | 5b64dab | 2016-06-09 08:59:48 -0700 | [diff] [blame] | 352 | fflush(stdout); |
| 353 | |
Mike Klein | ca8087f | 2019-03-18 09:01:39 -0500 | [diff] [blame] | 354 | if (sig == SIGINT && FLAGS_ignoreSigInt) { |
| 355 | info("Ignoring signal %d because of --ignoreSigInt.\n" |
| 356 | "This is probably a sign the bot is overloaded with work.\n", sig); |
| 357 | } else { |
| 358 | signal(sig, previous_handler[sig]); |
| 359 | raise(sig); |
| 360 | } |
mtklein | 5b64dab | 2016-06-09 08:59:48 -0700 | [diff] [blame] | 361 | } |
| 362 | |
mtklein | 246ba3a | 2016-02-23 10:39:36 -0800 | [diff] [blame] | 363 | static void setup_crash_handler() { |
Mike Klein | 701a358 | 2018-06-28 14:08:19 +0000 | [diff] [blame] | 364 | const int kSignals[] = { SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGINT, SIGSEGV, SIGTERM }; |
mtklein | 246ba3a | 2016-02-23 10:39:36 -0800 | [diff] [blame] | 365 | for (int sig : kSignals) { |
Mike Klein | 3cc2d20 | 2016-10-24 11:39:43 -0400 | [diff] [blame] | 366 | previous_handler[sig] = signal(sig, crash_handler); |
mtklein | 246ba3a | 2016-02-23 10:39:36 -0800 | [diff] [blame] | 367 | } |
| 368 | } |
| 369 | #endif |
| 370 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 371 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 372 | |
Brian Osman | 57796b3 | 2019-01-25 18:02:59 +0000 | [diff] [blame] | 373 | struct Gold : public SkString { |
| 374 | Gold() : SkString("") {} |
| 375 | Gold(const SkString& sink, const SkString& src, |
| 376 | const SkString& srcOptions, const SkString& name, |
| 377 | const SkString& md5) |
| 378 | : SkString("") { |
| 379 | this->append(sink); |
| 380 | this->append(src); |
| 381 | this->append(srcOptions); |
| 382 | this->append(name); |
| 383 | this->append(md5); |
| 384 | } |
| 385 | struct Hash { |
| 386 | uint32_t operator()(const Gold& g) const { |
| 387 | return SkGoodHash()((const SkString&)g); |
| 388 | } |
| 389 | }; |
| 390 | }; |
| 391 | static SkTHashSet<Gold, Gold::Hash> gGold; |
| 392 | |
| 393 | static void add_gold(JsonWriter::BitmapResult r) { |
| 394 | gGold.add(Gold(r.config, r.sourceType, r.sourceOptions, r.name, r.md5)); |
| 395 | } |
| 396 | |
| 397 | static void gather_gold() { |
| 398 | if (!FLAGS_readPath.isEmpty()) { |
| 399 | SkString path(FLAGS_readPath[0]); |
| 400 | path.append("/dm.json"); |
| 401 | if (!JsonWriter::ReadJson(path.c_str(), add_gold)) { |
| 402 | fail(SkStringPrintf("Couldn't read %s for golden results.", path.c_str())); |
| 403 | } |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 408 | |
Mike Klein | 8f11d4d | 2018-01-24 12:42:55 -0500 | [diff] [blame] | 409 | #if defined(SK_BUILD_FOR_WIN) |
mtklein | 935f1b1 | 2016-03-16 08:37:19 -0700 | [diff] [blame] | 410 | static const char* kNewline = "\r\n"; |
| 411 | #else |
| 412 | static const char* kNewline = "\n"; |
| 413 | #endif |
| 414 | |
borenet | 09ed480 | 2015-04-03 14:15:33 -0700 | [diff] [blame] | 415 | static SkTHashSet<SkString> gUninterestingHashes; |
| 416 | |
| 417 | static void gather_uninteresting_hashes() { |
| 418 | if (!FLAGS_uninterestingHashesFile.isEmpty()) { |
bungeman | 38d909e | 2016-08-02 14:40:46 -0700 | [diff] [blame] | 419 | sk_sp<SkData> data(SkData::MakeFromFileName(FLAGS_uninterestingHashesFile[0])); |
mtklein | cc334b3 | 2015-09-22 11:43:53 -0700 | [diff] [blame] | 420 | if (!data) { |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 421 | info("WARNING: unable to read uninteresting hashes from %s\n", |
| 422 | FLAGS_uninterestingHashesFile[0]); |
mtklein | cc334b3 | 2015-09-22 11:43:53 -0700 | [diff] [blame] | 423 | return; |
| 424 | } |
Mike Klein | 45dcc0c | 2017-04-05 18:04:31 -0400 | [diff] [blame] | 425 | |
| 426 | // Copy to a string to make sure SkStrSplit has a terminating \0 to find. |
| 427 | SkString contents((const char*)data->data(), data->size()); |
| 428 | |
borenet | 09ed480 | 2015-04-03 14:15:33 -0700 | [diff] [blame] | 429 | SkTArray<SkString> hashes; |
Mike Klein | 45dcc0c | 2017-04-05 18:04:31 -0400 | [diff] [blame] | 430 | SkStrSplit(contents.c_str(), kNewline, &hashes); |
borenet | 09ed480 | 2015-04-03 14:15:33 -0700 | [diff] [blame] | 431 | for (const SkString& hash : hashes) { |
| 432 | gUninterestingHashes.add(hash); |
| 433 | } |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 434 | info("FYI: loaded %d distinct uninteresting hashes from %d lines\n", |
| 435 | gUninterestingHashes.count(), hashes.count()); |
borenet | 09ed480 | 2015-04-03 14:15:33 -0700 | [diff] [blame] | 436 | } |
| 437 | } |
| 438 | |
| 439 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 440 | |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 441 | struct TaggedSrc : public std::unique_ptr<Src> { |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 442 | SkString tag; |
| 443 | SkString options; |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 444 | }; |
| 445 | |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 446 | struct TaggedSink : public std::unique_ptr<Sink> { |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 447 | SkString tag; |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 448 | }; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 449 | |
| 450 | static const bool kMemcpyOK = true; |
| 451 | |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 452 | static SkTArray<TaggedSrc, kMemcpyOK> gSrcs; |
| 453 | static SkTArray<TaggedSink, kMemcpyOK> gSinks; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 454 | |
mtklein | 6393c06 | 2015-04-27 08:45:01 -0700 | [diff] [blame] | 455 | static bool in_shard() { |
| 456 | static int N = 0; |
| 457 | return N++ % FLAGS_shards == FLAGS_shard; |
| 458 | } |
| 459 | |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 460 | static void push_src(const char* tag, ImplicitString options, Src* s) { |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 461 | std::unique_ptr<Src> src(s); |
Mike Klein | 88544fb | 2019-03-20 10:50:33 -0500 | [diff] [blame] | 462 | if (in_shard() && FLAGS_src.contains(tag) && |
| 463 | !CommandLineFlags::ShouldSkip(FLAGS_match, src->name().c_str())) { |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 464 | TaggedSrc& s = gSrcs.push_back(); |
mtklein | 18300a3 | 2016-03-16 13:53:35 -0700 | [diff] [blame] | 465 | s.reset(src.release()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 466 | s.tag = tag; |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 467 | s.options = options; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 468 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 469 | } |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 470 | |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 471 | static void push_codec_src(Path path, CodecSrc::Mode mode, CodecSrc::DstColorType dstColorType, |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 472 | SkAlphaType dstAlphaType, float scale) { |
scroggo | e449984 | 2016-02-25 11:03:47 -0800 | [diff] [blame] | 473 | if (FLAGS_simpleCodec) { |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 474 | const bool simple = CodecSrc::kCodec_Mode == mode || CodecSrc::kAnimated_Mode == mode; |
| 475 | if (!simple || dstColorType != CodecSrc::kGetFromCanvas_DstColorType || scale != 1.0f) { |
scroggo | e449984 | 2016-02-25 11:03:47 -0800 | [diff] [blame] | 476 | // Only decode in the simple case. |
| 477 | return; |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 478 | } |
scroggo | e449984 | 2016-02-25 11:03:47 -0800 | [diff] [blame] | 479 | } |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 480 | SkString folder; |
| 481 | switch (mode) { |
| 482 | case CodecSrc::kCodec_Mode: |
| 483 | folder.append("codec"); |
| 484 | break; |
msarett | bb25b53 | 2016-01-13 09:31:39 -0800 | [diff] [blame] | 485 | case CodecSrc::kCodecZeroInit_Mode: |
| 486 | folder.append("codec_zero_init"); |
| 487 | break; |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 488 | case CodecSrc::kScanline_Mode: |
| 489 | folder.append("scanline"); |
| 490 | break; |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 491 | case CodecSrc::kStripe_Mode: |
| 492 | folder.append("stripe"); |
| 493 | break; |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 494 | case CodecSrc::kCroppedScanline_Mode: |
| 495 | folder.append("crop"); |
| 496 | break; |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 497 | case CodecSrc::kSubset_Mode: |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 498 | folder.append("codec_subset"); |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 499 | break; |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 500 | case CodecSrc::kAnimated_Mode: |
| 501 | folder.append("codec_animated"); |
| 502 | break; |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | switch (dstColorType) { |
| 506 | case CodecSrc::kGrayscale_Always_DstColorType: |
| 507 | folder.append("_kGray8"); |
| 508 | break; |
msarett | 34e0ec4 | 2016-04-22 16:27:24 -0700 | [diff] [blame] | 509 | case CodecSrc::kNonNative8888_Always_DstColorType: |
| 510 | folder.append("_kNonNative"); |
| 511 | break; |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 512 | default: |
| 513 | break; |
| 514 | } |
| 515 | |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 516 | switch (dstAlphaType) { |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 517 | case kPremul_SkAlphaType: |
| 518 | folder.append("_premul"); |
| 519 | break; |
| 520 | case kUnpremul_SkAlphaType: |
| 521 | folder.append("_unpremul"); |
| 522 | break; |
| 523 | default: |
| 524 | break; |
| 525 | } |
| 526 | |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 527 | if (1.0f != scale) { |
| 528 | folder.appendf("_%.3f", scale); |
| 529 | } |
| 530 | |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 531 | CodecSrc* src = new CodecSrc(path, mode, dstColorType, dstAlphaType, scale); |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 532 | push_src("image", folder, src); |
| 533 | } |
| 534 | |
scroggo | f8dc9df | 2016-05-16 09:04:13 -0700 | [diff] [blame] | 535 | static void push_android_codec_src(Path path, CodecSrc::DstColorType dstColorType, |
| 536 | SkAlphaType dstAlphaType, int sampleSize) { |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 537 | SkString folder; |
scroggo | f8dc9df | 2016-05-16 09:04:13 -0700 | [diff] [blame] | 538 | folder.append("scaled_codec"); |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 539 | |
| 540 | switch (dstColorType) { |
| 541 | case CodecSrc::kGrayscale_Always_DstColorType: |
| 542 | folder.append("_kGray8"); |
| 543 | break; |
msarett | 34e0ec4 | 2016-04-22 16:27:24 -0700 | [diff] [blame] | 544 | case CodecSrc::kNonNative8888_Always_DstColorType: |
| 545 | folder.append("_kNonNative"); |
| 546 | break; |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 547 | default: |
| 548 | break; |
| 549 | } |
| 550 | |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 551 | switch (dstAlphaType) { |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 552 | case kPremul_SkAlphaType: |
| 553 | folder.append("_premul"); |
| 554 | break; |
msarett | 9e9444c | 2016-02-03 12:39:10 -0800 | [diff] [blame] | 555 | case kUnpremul_SkAlphaType: |
| 556 | folder.append("_unpremul"); |
| 557 | break; |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 558 | default: |
| 559 | break; |
| 560 | } |
| 561 | |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 562 | if (1 != sampleSize) { |
msarett | 4b0778e | 2015-11-13 09:59:11 -0800 | [diff] [blame] | 563 | folder.appendf("_%.3f", 1.0f / (float) sampleSize); |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 564 | } |
| 565 | |
scroggo | f8dc9df | 2016-05-16 09:04:13 -0700 | [diff] [blame] | 566 | AndroidCodecSrc* src = new AndroidCodecSrc(path, dstColorType, dstAlphaType, sampleSize); |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 567 | push_src("image", folder, src); |
| 568 | } |
| 569 | |
msarett | 1897631 | 2016-03-09 14:20:58 -0800 | [diff] [blame] | 570 | static void push_image_gen_src(Path path, ImageGenSrc::Mode mode, SkAlphaType alphaType, bool isGpu) |
| 571 | { |
| 572 | SkString folder; |
| 573 | switch (mode) { |
| 574 | case ImageGenSrc::kCodec_Mode: |
| 575 | folder.append("gen_codec"); |
| 576 | break; |
| 577 | case ImageGenSrc::kPlatform_Mode: |
| 578 | folder.append("gen_platform"); |
| 579 | break; |
| 580 | } |
| 581 | |
| 582 | if (isGpu) { |
| 583 | folder.append("_gpu"); |
| 584 | } else { |
| 585 | switch (alphaType) { |
| 586 | case kOpaque_SkAlphaType: |
| 587 | folder.append("_opaque"); |
| 588 | break; |
| 589 | case kPremul_SkAlphaType: |
| 590 | folder.append("_premul"); |
| 591 | break; |
| 592 | case kUnpremul_SkAlphaType: |
| 593 | folder.append("_unpremul"); |
| 594 | break; |
| 595 | default: |
| 596 | break; |
| 597 | } |
| 598 | } |
| 599 | |
| 600 | ImageGenSrc* src = new ImageGenSrc(path, mode, alphaType, isGpu); |
| 601 | push_src("image", folder, src); |
| 602 | } |
| 603 | |
Leon Scroggins III | 0741818 | 2017-08-15 12:24:02 -0400 | [diff] [blame] | 604 | static void push_brd_src(Path path, CodecSrc::DstColorType dstColorType, BRDSrc::Mode mode, |
| 605 | uint32_t sampleSize) { |
| 606 | SkString folder("brd_android_codec"); |
| 607 | switch (mode) { |
| 608 | case BRDSrc::kFullImage_Mode: |
| 609 | break; |
| 610 | case BRDSrc::kDivisor_Mode: |
| 611 | folder.append("_divisor"); |
| 612 | break; |
| 613 | default: |
| 614 | SkASSERT(false); |
| 615 | return; |
| 616 | } |
| 617 | |
| 618 | switch (dstColorType) { |
| 619 | case CodecSrc::kGetFromCanvas_DstColorType: |
| 620 | break; |
| 621 | case CodecSrc::kGrayscale_Always_DstColorType: |
| 622 | folder.append("_kGray"); |
| 623 | break; |
| 624 | default: |
| 625 | SkASSERT(false); |
| 626 | return; |
| 627 | } |
| 628 | |
| 629 | if (1 != sampleSize) { |
| 630 | folder.appendf("_%.3f", 1.0f / (float) sampleSize); |
| 631 | } |
| 632 | |
| 633 | BRDSrc* src = new BRDSrc(path, mode, dstColorType, sampleSize); |
| 634 | push_src("image", folder, src); |
| 635 | } |
| 636 | |
| 637 | static void push_brd_srcs(Path path, bool gray) { |
| 638 | if (gray) { |
| 639 | // Only run grayscale to one sampleSize and Mode. Though interesting |
| 640 | // to test grayscale, it should not reveal anything across various |
| 641 | // sampleSizes and Modes |
| 642 | // Arbitrarily choose Mode and sampleSize. |
| 643 | push_brd_src(path, CodecSrc::kGrayscale_Always_DstColorType, |
| 644 | BRDSrc::kFullImage_Mode, 2); |
| 645 | } |
| 646 | |
| 647 | // Test on a variety of sampleSizes, making sure to include: |
| 648 | // - 2, 4, and 8, which are natively supported by jpeg |
| 649 | // - multiples of 2 which are not divisible by 4 (analogous for 4) |
| 650 | // - larger powers of two, since BRD clients generally use powers of 2 |
| 651 | // We will only produce output for the larger sizes on large images. |
| 652 | const uint32_t sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 24, 32, 64 }; |
| 653 | |
| 654 | const BRDSrc::Mode modes[] = { BRDSrc::kFullImage_Mode, BRDSrc::kDivisor_Mode, }; |
| 655 | |
| 656 | for (uint32_t sampleSize : sampleSizes) { |
| 657 | for (BRDSrc::Mode mode : modes) { |
| 658 | push_brd_src(path, CodecSrc::kGetFromCanvas_DstColorType, mode, sampleSize); |
| 659 | } |
| 660 | } |
| 661 | } |
| 662 | |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 663 | static void push_codec_srcs(Path path) { |
bungeman | 38d909e | 2016-08-02 14:40:46 -0700 | [diff] [blame] | 664 | sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str())); |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 665 | if (!encoded) { |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 666 | info("Couldn't read %s.", path.c_str()); |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 667 | return; |
| 668 | } |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame] | 669 | std::unique_ptr<SkCodec> codec = SkCodec::MakeFromData(encoded); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 670 | if (nullptr == codec.get()) { |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 671 | info("Couldn't create codec for %s.", path.c_str()); |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 672 | return; |
| 673 | } |
| 674 | |
scroggo | 9366aff | 2016-05-20 08:38:54 -0700 | [diff] [blame] | 675 | // native scaling is only supported by WEBP and JPEG |
| 676 | bool supportsNativeScaling = false; |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 677 | |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 678 | SkTArray<CodecSrc::Mode> nativeModes; |
| 679 | nativeModes.push_back(CodecSrc::kCodec_Mode); |
| 680 | nativeModes.push_back(CodecSrc::kCodecZeroInit_Mode); |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 681 | switch (codec->getEncodedFormat()) { |
Hal Canary | db68301 | 2016-11-23 08:55:18 -0700 | [diff] [blame] | 682 | case SkEncodedImageFormat::kJPEG: |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 683 | nativeModes.push_back(CodecSrc::kScanline_Mode); |
| 684 | nativeModes.push_back(CodecSrc::kStripe_Mode); |
| 685 | nativeModes.push_back(CodecSrc::kCroppedScanline_Mode); |
scroggo | 9366aff | 2016-05-20 08:38:54 -0700 | [diff] [blame] | 686 | supportsNativeScaling = true; |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 687 | break; |
Hal Canary | db68301 | 2016-11-23 08:55:18 -0700 | [diff] [blame] | 688 | case SkEncodedImageFormat::kWEBP: |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 689 | nativeModes.push_back(CodecSrc::kSubset_Mode); |
scroggo | 9366aff | 2016-05-20 08:38:54 -0700 | [diff] [blame] | 690 | supportsNativeScaling = true; |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 691 | break; |
Hal Canary | db68301 | 2016-11-23 08:55:18 -0700 | [diff] [blame] | 692 | case SkEncodedImageFormat::kDNG: |
msarett | b65e604 | 2016-02-23 05:37:25 -0800 | [diff] [blame] | 693 | break; |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 694 | default: |
| 695 | nativeModes.push_back(CodecSrc::kScanline_Mode); |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 696 | break; |
| 697 | } |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 698 | |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 699 | SkTArray<CodecSrc::DstColorType> colorTypes; |
| 700 | colorTypes.push_back(CodecSrc::kGetFromCanvas_DstColorType); |
msarett | 34e0ec4 | 2016-04-22 16:27:24 -0700 | [diff] [blame] | 701 | colorTypes.push_back(CodecSrc::kNonNative8888_Always_DstColorType); |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 702 | switch (codec->getInfo().colorType()) { |
| 703 | case kGray_8_SkColorType: |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 704 | colorTypes.push_back(CodecSrc::kGrayscale_Always_DstColorType); |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 705 | break; |
| 706 | default: |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 707 | break; |
| 708 | } |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 709 | |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 710 | SkTArray<SkAlphaType> alphaModes; |
| 711 | alphaModes.push_back(kPremul_SkAlphaType); |
scroggo | f2c96a2 | 2016-05-20 11:08:27 -0700 | [diff] [blame] | 712 | if (codec->getInfo().alphaType() != kOpaque_SkAlphaType) { |
| 713 | alphaModes.push_back(kUnpremul_SkAlphaType); |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 714 | } |
msarett | b714fb0 | 2016-01-22 14:46:42 -0800 | [diff] [blame] | 715 | |
| 716 | for (CodecSrc::Mode mode : nativeModes) { |
scroggo | 9366aff | 2016-05-20 08:38:54 -0700 | [diff] [blame] | 717 | for (CodecSrc::DstColorType colorType : colorTypes) { |
| 718 | for (SkAlphaType alphaType : alphaModes) { |
scroggo | f2c96a2 | 2016-05-20 11:08:27 -0700 | [diff] [blame] | 719 | // Only test kCroppedScanline_Mode when the alpha type is premul. The test is |
scroggo | 9366aff | 2016-05-20 08:38:54 -0700 | [diff] [blame] | 720 | // slow and won't be interestingly different with different alpha types. |
| 721 | if (CodecSrc::kCroppedScanline_Mode == mode && |
scroggo | f2c96a2 | 2016-05-20 11:08:27 -0700 | [diff] [blame] | 722 | kPremul_SkAlphaType != alphaType) { |
scroggo | 9366aff | 2016-05-20 08:38:54 -0700 | [diff] [blame] | 723 | continue; |
| 724 | } |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 725 | |
scroggo | 9366aff | 2016-05-20 08:38:54 -0700 | [diff] [blame] | 726 | push_codec_src(path, mode, colorType, alphaType, 1.0f); |
msarett | f3dc188 | 2016-04-26 13:06:38 -0700 | [diff] [blame] | 727 | |
scroggo | 9366aff | 2016-05-20 08:38:54 -0700 | [diff] [blame] | 728 | // Skip kNonNative on different native scales. It won't be interestingly |
| 729 | // different. |
| 730 | if (supportsNativeScaling && |
| 731 | CodecSrc::kNonNative8888_Always_DstColorType == colorType) { |
| 732 | // Native Scales |
| 733 | // SkJpegCodec natively supports scaling to the following: |
| 734 | for (auto scale : { 0.125f, 0.25f, 0.375f, 0.5f, 0.625f, 0.750f, 0.875f }) { |
| 735 | push_codec_src(path, mode, colorType, alphaType, scale); |
| 736 | } |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 737 | } |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 738 | } |
| 739 | } |
msarett | 0a24297 | 2015-06-11 14:27:27 -0700 | [diff] [blame] | 740 | } |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 741 | |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 742 | { |
| 743 | std::vector<SkCodec::FrameInfo> frameInfos = codec->getFrameInfo(); |
| 744 | if (frameInfos.size() > 1) { |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 745 | for (auto dstCT : { CodecSrc::kNonNative8888_Always_DstColorType, |
| 746 | CodecSrc::kGetFromCanvas_DstColorType }) { |
| 747 | for (auto at : { kUnpremul_SkAlphaType, kPremul_SkAlphaType }) { |
| 748 | push_codec_src(path, CodecSrc::kAnimated_Mode, dstCT, at, 1.0f); |
| 749 | } |
| 750 | } |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | } |
| 754 | |
scroggo | e449984 | 2016-02-25 11:03:47 -0800 | [diff] [blame] | 755 | if (FLAGS_simpleCodec) { |
| 756 | return; |
| 757 | } |
| 758 | |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 759 | const int sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 760 | |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 761 | for (int sampleSize : sampleSizes) { |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 762 | for (CodecSrc::DstColorType colorType : colorTypes) { |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 763 | for (SkAlphaType alphaType : alphaModes) { |
msarett | f3dc188 | 2016-04-26 13:06:38 -0700 | [diff] [blame] | 764 | // We can exercise all of the kNonNative support code in the swizzler with just a |
| 765 | // few sample sizes. Skip the rest. |
| 766 | if (CodecSrc::kNonNative8888_Always_DstColorType == colorType && sampleSize > 3) { |
| 767 | continue; |
| 768 | } |
| 769 | |
scroggo | f8dc9df | 2016-05-16 09:04:13 -0700 | [diff] [blame] | 770 | push_android_codec_src(path, colorType, alphaType, sampleSize); |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 771 | } |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 772 | } |
| 773 | } |
msarett | 1897631 | 2016-03-09 14:20:58 -0800 | [diff] [blame] | 774 | |
Leon Scroggins III | 0741818 | 2017-08-15 12:24:02 -0400 | [diff] [blame] | 775 | const char* ext = strrchr(path.c_str(), '.'); |
| 776 | if (ext) { |
| 777 | ext++; |
msarett | 1897631 | 2016-03-09 14:20:58 -0800 | [diff] [blame] | 778 | |
Leon Scroggins III | 0741818 | 2017-08-15 12:24:02 -0400 | [diff] [blame] | 779 | static const char* const rawExts[] = { |
| 780 | "arw", "cr2", "dng", "nef", "nrw", "orf", "raf", "rw2", "pef", "srw", |
| 781 | "ARW", "CR2", "DNG", "NEF", "NRW", "ORF", "RAF", "RW2", "PEF", "SRW", |
| 782 | }; |
| 783 | for (const char* rawExt : rawExts) { |
| 784 | if (0 == strcmp(rawExt, ext)) { |
| 785 | // RAW is not supported by image generator (skbug.com/5079) or BRD. |
| 786 | return; |
| 787 | } |
| 788 | } |
| 789 | |
| 790 | static const char* const brdExts[] = { |
| 791 | "jpg", "jpeg", "png", "webp", |
| 792 | "JPG", "JPEG", "PNG", "WEBP", |
| 793 | }; |
| 794 | for (const char* brdExt : brdExts) { |
| 795 | if (0 == strcmp(brdExt, ext)) { |
Leon Scroggins III | c8037dc | 2017-12-05 13:55:24 -0500 | [diff] [blame] | 796 | bool gray = codec->getInfo().colorType() == kGray_8_SkColorType; |
Leon Scroggins III | 0741818 | 2017-08-15 12:24:02 -0400 | [diff] [blame] | 797 | push_brd_srcs(path, gray); |
| 798 | break; |
| 799 | } |
msarett | 1897631 | 2016-03-09 14:20:58 -0800 | [diff] [blame] | 800 | } |
| 801 | } |
| 802 | |
| 803 | // Push image generator GPU test. |
brianosman | c9ced39 | 2016-03-24 07:27:43 -0700 | [diff] [blame] | 804 | push_image_gen_src(path, ImageGenSrc::kCodec_Mode, codec->getInfo().alphaType(), true); |
msarett | 1897631 | 2016-03-09 14:20:58 -0800 | [diff] [blame] | 805 | |
| 806 | // Push image generator CPU tests. |
| 807 | for (SkAlphaType alphaType : alphaModes) { |
| 808 | push_image_gen_src(path, ImageGenSrc::kCodec_Mode, alphaType, false); |
| 809 | |
| 810 | #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) |
Hal Canary | db68301 | 2016-11-23 08:55:18 -0700 | [diff] [blame] | 811 | if (SkEncodedImageFormat::kWEBP != codec->getEncodedFormat() && |
| 812 | SkEncodedImageFormat::kWBMP != codec->getEncodedFormat() && |
msarett | 1897631 | 2016-03-09 14:20:58 -0800 | [diff] [blame] | 813 | kUnpremul_SkAlphaType != alphaType) |
| 814 | { |
| 815 | push_image_gen_src(path, ImageGenSrc::kPlatform_Mode, alphaType, false); |
| 816 | } |
msarett | fc0b6d1 | 2016-03-17 13:50:17 -0700 | [diff] [blame] | 817 | #elif defined(SK_BUILD_FOR_WIN) |
Hal Canary | db68301 | 2016-11-23 08:55:18 -0700 | [diff] [blame] | 818 | if (SkEncodedImageFormat::kWEBP != codec->getEncodedFormat() && |
| 819 | SkEncodedImageFormat::kWBMP != codec->getEncodedFormat()) |
msarett | fc0b6d1 | 2016-03-17 13:50:17 -0700 | [diff] [blame] | 820 | { |
| 821 | push_image_gen_src(path, ImageGenSrc::kPlatform_Mode, alphaType, false); |
| 822 | } |
msarett | 1897631 | 2016-03-09 14:20:58 -0800 | [diff] [blame] | 823 | #endif |
| 824 | } |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 825 | } |
| 826 | |
fmalita | a2b9fdf | 2016-08-03 19:53:36 -0700 | [diff] [blame] | 827 | template <typename T> |
Mike Klein | 88544fb | 2019-03-20 10:50:33 -0500 | [diff] [blame] | 828 | void gather_file_srcs(const CommandLineFlags::StringArray& flags, |
| 829 | const char* ext, |
| 830 | const char* src_name = nullptr) { |
Florin Malita | f1ba3ae | 2018-07-19 15:09:11 -0400 | [diff] [blame] | 831 | if (!src_name) { |
| 832 | // With the exception of Lottie files, the source name is the extension. |
| 833 | src_name = ext; |
| 834 | } |
| 835 | |
fmalita | a2b9fdf | 2016-08-03 19:53:36 -0700 | [diff] [blame] | 836 | for (int i = 0; i < flags.count(); i++) { |
| 837 | const char* path = flags[i]; |
| 838 | if (sk_isdir(path)) { |
| 839 | SkOSFile::Iter it(path, ext); |
| 840 | for (SkString file; it.next(&file); ) { |
Florin Malita | f1ba3ae | 2018-07-19 15:09:11 -0400 | [diff] [blame] | 841 | push_src(src_name, "", new T(SkOSPath::Join(path, file.c_str()))); |
fmalita | a2b9fdf | 2016-08-03 19:53:36 -0700 | [diff] [blame] | 842 | } |
| 843 | } else { |
Florin Malita | f1ba3ae | 2018-07-19 15:09:11 -0400 | [diff] [blame] | 844 | push_src(src_name, "", new T(path)); |
fmalita | a2b9fdf | 2016-08-03 19:53:36 -0700 | [diff] [blame] | 845 | } |
| 846 | } |
| 847 | } |
| 848 | |
scroggo | 8673714 | 2016-02-03 12:19:11 -0800 | [diff] [blame] | 849 | static bool gather_srcs() { |
Hal Canary | 972eba3 | 2018-07-30 17:07:07 -0400 | [diff] [blame] | 850 | for (skiagm::GMFactory f : skiagm::GMRegistry::Range()) { |
| 851 | push_src("gm", "", new GMSrc(f)); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 852 | } |
scroggo | 8673714 | 2016-02-03 12:19:11 -0800 | [diff] [blame] | 853 | |
Robert Phillips | e47f0a0 | 2018-03-27 17:01:16 -0400 | [diff] [blame] | 854 | gather_file_srcs<SKPSrc>(FLAGS_skps, "skp"); |
fmalita | a2b9fdf | 2016-08-03 19:53:36 -0700 | [diff] [blame] | 855 | gather_file_srcs<MSKPSrc>(FLAGS_mskps, "mskp"); |
Florin Malita | 87ccf33 | 2018-05-04 12:23:24 -0400 | [diff] [blame] | 856 | #if defined(SK_ENABLE_SKOTTIE) |
Florin Malita | f1ba3ae | 2018-07-19 15:09:11 -0400 | [diff] [blame] | 857 | gather_file_srcs<SkottieSrc>(FLAGS_lotties, "json", "lottie"); |
Florin Malita | 124d5af | 2017-12-31 17:02:26 -0500 | [diff] [blame] | 858 | #endif |
fmalita | a2b9fdf | 2016-08-03 19:53:36 -0700 | [diff] [blame] | 859 | #if defined(SK_XML) |
| 860 | gather_file_srcs<SVGSrc>(FLAGS_svgs, "svg"); |
| 861 | #endif |
Chris Dalton | 184c37e | 2018-09-28 11:27:39 -0600 | [diff] [blame] | 862 | if (!FLAGS_bisect.isEmpty()) { |
| 863 | // An empty l/r trail string will draw all the paths. |
| 864 | push_src("bisect", "", |
| 865 | new BisectSrc(FLAGS_bisect[0], FLAGS_bisect.count() > 1 ? FLAGS_bisect[1] : "")); |
| 866 | } |
halcanary | 45420a9 | 2016-06-02 12:41:14 -0700 | [diff] [blame] | 867 | |
scroggo | 8673714 | 2016-02-03 12:19:11 -0800 | [diff] [blame] | 868 | SkTArray<SkString> images; |
msarett | 69deca8 | 2016-04-29 09:38:40 -0700 | [diff] [blame] | 869 | if (!CollectImages(FLAGS_images, &images)) { |
scroggo | 8673714 | 2016-02-03 12:19:11 -0800 | [diff] [blame] | 870 | return false; |
| 871 | } |
| 872 | |
| 873 | for (auto image : images) { |
| 874 | push_codec_srcs(image); |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 875 | } |
scroggo | 8673714 | 2016-02-03 12:19:11 -0800 | [diff] [blame] | 876 | |
msarett | 69deca8 | 2016-04-29 09:38:40 -0700 | [diff] [blame] | 877 | SkTArray<SkString> colorImages; |
| 878 | if (!CollectImages(FLAGS_colorImages, &colorImages)) { |
| 879 | return false; |
| 880 | } |
| 881 | |
| 882 | for (auto colorImage : colorImages) { |
Mike Klein | 0d5d142 | 2019-03-06 10:56:04 -0600 | [diff] [blame] | 883 | push_src("colorImage", "decode_native", new ColorCodecSrc(colorImage, false)); |
| 884 | push_src("colorImage", "decode_to_dst", new ColorCodecSrc(colorImage, true)); |
msarett | 69deca8 | 2016-04-29 09:38:40 -0700 | [diff] [blame] | 885 | } |
| 886 | |
scroggo | 8673714 | 2016-02-03 12:19:11 -0800 | [diff] [blame] | 887 | return true; |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 888 | } |
| 889 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 890 | static void push_sink(const SkCommandLineConfig& config, Sink* s) { |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 891 | std::unique_ptr<Sink> sink(s); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 892 | |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 893 | // Try a simple Src as a canary. If it fails, skip this sink. |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 894 | struct : public Src { |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 895 | Error draw(SkCanvas* c) const override { |
| 896 | c->drawRect(SkRect::MakeWH(1,1), SkPaint()); |
| 897 | return ""; |
| 898 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 899 | SkISize size() const override { return SkISize::Make(16, 16); } |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 900 | Name name() const override { return "justOneRect"; } |
| 901 | } justOneRect; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 902 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 903 | SkBitmap bitmap; |
| 904 | SkDynamicMemoryWStream stream; |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 905 | SkString log; |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 906 | Error err = sink->draw(justOneRect, &bitmap, &stream, &log); |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 907 | if (err.isFatal()) { |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 908 | 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] | 909 | exit(1); |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 910 | } |
| 911 | |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 912 | TaggedSink& ts = gSinks.push_back(); |
mtklein | 18300a3 | 2016-03-16 13:53:35 -0700 | [diff] [blame] | 913 | ts.reset(sink.release()); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 914 | ts.tag = config.getTag(); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 915 | } |
| 916 | |
Mike Klein | c7a0916 | 2019-02-19 06:14:39 -0500 | [diff] [blame] | 917 | static sk_sp<SkColorSpace> rgb_to_gbr() { |
| 918 | return SkColorSpace::MakeSRGB()->makeColorSpin(); |
| 919 | } |
| 920 | |
csmartdalton | 008b9d8 | 2017-02-22 12:00:42 -0700 | [diff] [blame] | 921 | static Sink* create_sink(const GrContextOptions& grCtxOptions, const SkCommandLineConfig* config) { |
Brian Osman | c7ad40f | 2018-05-31 14:27:17 -0400 | [diff] [blame] | 922 | if (FLAGS_gpu) { |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 923 | if (const SkCommandLineConfigGpu* gpuConfig = config->asConfigGpu()) { |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 924 | GrContextFactory::ContextType contextType = gpuConfig->getContextType(); |
csmartdalton | e812d49 | 2017-02-21 12:36:05 -0700 | [diff] [blame] | 925 | GrContextFactory::ContextOverrides contextOverrides = gpuConfig->getContextOverrides(); |
csmartdalton | 008b9d8 | 2017-02-22 12:00:42 -0700 | [diff] [blame] | 926 | GrContextFactory testFactory(grCtxOptions); |
csmartdalton | e812d49 | 2017-02-21 12:36:05 -0700 | [diff] [blame] | 927 | if (!testFactory.get(contextType, contextOverrides)) { |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 928 | info("WARNING: can not create GPU context for config '%s'. " |
| 929 | "GM tests will be skipped.\n", gpuConfig->getTag().c_str()); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 930 | return nullptr; |
| 931 | } |
Brian Osman | f981066 | 2017-08-30 10:02:10 -0400 | [diff] [blame] | 932 | if (gpuConfig->getTestThreading()) { |
Brian Salomon | 00a5eb8 | 2018-07-11 15:32:05 -0400 | [diff] [blame] | 933 | SkASSERT(!gpuConfig->getTestPersistentCache()); |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 934 | return new GPUThreadTestingSink( |
| 935 | contextType, contextOverrides, gpuConfig->getSurfType(), |
| 936 | gpuConfig->getSamples(), gpuConfig->getUseDIText(), |
| 937 | gpuConfig->getColorType(), gpuConfig->getAlphaType(), |
| 938 | sk_ref_sp(gpuConfig->getColorSpace()), FLAGS_gpu_threading, grCtxOptions); |
Brian Salomon | 00a5eb8 | 2018-07-11 15:32:05 -0400 | [diff] [blame] | 939 | } else if (gpuConfig->getTestPersistentCache()) { |
| 940 | return new GPUPersistentCacheTestingSink( |
| 941 | contextType, contextOverrides, gpuConfig->getSurfType(), |
| 942 | gpuConfig->getSamples(), gpuConfig->getUseDIText(), |
| 943 | gpuConfig->getColorType(), gpuConfig->getAlphaType(), |
Brian Osman | f71b070 | 2019-04-03 13:04:16 -0400 | [diff] [blame] | 944 | sk_ref_sp(gpuConfig->getColorSpace()), FLAGS_gpu_threading, grCtxOptions, |
| 945 | gpuConfig->getTestPersistentCache()); |
Brian Osman | f981066 | 2017-08-30 10:02:10 -0400 | [diff] [blame] | 946 | } else { |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 947 | return new GPUSink(contextType, contextOverrides, gpuConfig->getSurfType(), |
| 948 | gpuConfig->getSamples(), gpuConfig->getUseDIText(), |
| 949 | gpuConfig->getColorType(), gpuConfig->getAlphaType(), |
| 950 | sk_ref_sp(gpuConfig->getColorSpace()), FLAGS_gpu_threading, |
| 951 | grCtxOptions); |
Brian Osman | f981066 | 2017-08-30 10:02:10 -0400 | [diff] [blame] | 952 | } |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 953 | } |
| 954 | } |
Bryce Thomas | 95a7b76 | 2018-03-02 13:54:21 -0800 | [diff] [blame] | 955 | if (const SkCommandLineConfigSvg* svgConfig = config->asConfigSvg()) { |
| 956 | int pageIndex = svgConfig->getPageIndex(); |
| 957 | return new SVGSink(pageIndex); |
| 958 | } |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 959 | |
Brian Salomon | 2335644 | 2018-11-30 15:33:19 -0500 | [diff] [blame] | 960 | #define SINK(t, sink, ...) if (config->getBackend().equals(t)) return new sink(__VA_ARGS__) |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 961 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 962 | if (FLAGS_cpu) { |
Mike Klein | 515bda6 | 2018-01-09 11:21:58 -0500 | [diff] [blame] | 963 | SINK("g8", RasterSink, kGray_8_SkColorType); |
Matt Sarett | d222830 | 2017-03-02 08:53:46 -0500 | [diff] [blame] | 964 | SINK("565", RasterSink, kRGB_565_SkColorType); |
Mike Klein | 5340b3f | 2018-01-24 13:42:05 -0500 | [diff] [blame] | 965 | SINK("4444", RasterSink, kARGB_4444_SkColorType); |
Matt Sarett | d222830 | 2017-03-02 08:53:46 -0500 | [diff] [blame] | 966 | SINK("8888", RasterSink, kN32_SkColorType); |
Mike Klein | ac568a9 | 2018-01-25 09:09:32 -0500 | [diff] [blame] | 967 | SINK("rgba", RasterSink, kRGBA_8888_SkColorType); |
| 968 | SINK("bgra", RasterSink, kBGRA_8888_SkColorType); |
| 969 | SINK("rgbx", RasterSink, kRGB_888x_SkColorType); |
| 970 | SINK("1010102", RasterSink, kRGBA_1010102_SkColorType); |
| 971 | SINK("101010x", RasterSink, kRGB_101010x_SkColorType); |
Hal Canary | c7d295e | 2017-07-20 15:36:00 -0400 | [diff] [blame] | 972 | SINK("pdf", PDFSink, false, SK_ScalarDefaultRasterDPI); |
Matt Sarett | d222830 | 2017-03-02 08:53:46 -0500 | [diff] [blame] | 973 | SINK("skp", SKPSink); |
Matt Sarett | d222830 | 2017-03-02 08:53:46 -0500 | [diff] [blame] | 974 | SINK("svg", SVGSink); |
| 975 | SINK("null", NullSink); |
| 976 | SINK("xps", XPSSink); |
Hal Canary | c7d295e | 2017-07-20 15:36:00 -0400 | [diff] [blame] | 977 | SINK("pdfa", PDFSink, true, SK_ScalarDefaultRasterDPI); |
| 978 | SINK("pdf300", PDFSink, false, 300); |
Hal Canary | 85c7fe8 | 2016-10-25 10:33:27 -0400 | [diff] [blame] | 979 | SINK("jsdebug", DebugSink); |
Mike Klein | 0e4041f | 2018-06-19 16:00:40 -0400 | [diff] [blame] | 980 | |
| 981 | // Configs relevant to color management testing (and 8888 for reference). |
| 982 | |
| 983 | // 'narrow' has a gamut narrower than sRGB, and different transfer function. |
Brian Osman | 82ebe04 | 2019-01-04 17:03:00 -0500 | [diff] [blame] | 984 | auto narrow = SkColorSpace::MakeRGB(SkNamedTransferFn::k2Dot2, gNarrow_toXYZD50), |
Mike Klein | 0e4041f | 2018-06-19 16:00:40 -0400 | [diff] [blame] | 985 | srgb = SkColorSpace::MakeSRGB(), |
Mike Klein | 4de0507 | 2018-08-16 09:09:14 -0400 | [diff] [blame] | 986 | srgbLinear = SkColorSpace::MakeSRGBLinear(), |
Brian Osman | 82ebe04 | 2019-01-04 17:03:00 -0500 | [diff] [blame] | 987 | p3 = SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, SkNamedGamut::kDCIP3); |
Mike Klein | 0e4041f | 2018-06-19 16:00:40 -0400 | [diff] [blame] | 988 | |
Mike Klein | ff6a73c | 2018-08-17 16:19:24 -0400 | [diff] [blame] | 989 | SINK( "f16", RasterSink, kRGBA_F16_SkColorType, srgbLinear); |
| 990 | SINK( "srgb", RasterSink, kRGBA_8888_SkColorType, srgb ); |
| 991 | SINK( "esrgb", RasterSink, kRGBA_F16_SkColorType, srgb ); |
Mike Klein | c7a0916 | 2019-02-19 06:14:39 -0500 | [diff] [blame] | 992 | SINK( "esgbr", RasterSink, kRGBA_F16_SkColorType, rgb_to_gbr()); |
Mike Klein | ff6a73c | 2018-08-17 16:19:24 -0400 | [diff] [blame] | 993 | SINK( "narrow", RasterSink, kRGBA_8888_SkColorType, narrow ); |
| 994 | SINK( "enarrow", RasterSink, kRGBA_F16_SkColorType, narrow ); |
| 995 | SINK( "p3", RasterSink, kRGBA_8888_SkColorType, p3 ); |
| 996 | SINK( "ep3", RasterSink, kRGBA_F16_SkColorType, p3 ); |
Mike Klein | ae4b1f4 | 2018-09-13 11:13:15 -0400 | [diff] [blame] | 997 | SINK( "rec2020", RasterSink, kRGBA_8888_SkColorType, rec2020() ); |
| 998 | SINK("erec2020", RasterSink, kRGBA_F16_SkColorType, rec2020() ); |
Mike Klein | 3785471 | 2018-06-26 11:43:06 -0400 | [diff] [blame] | 999 | |
Mike Klein | b70990e | 2019-02-28 10:03:27 -0600 | [diff] [blame] | 1000 | SINK("f16norm", RasterSink, kRGBA_F16Norm_SkColorType, srgb); |
| 1001 | |
Mike Klein | 3785471 | 2018-06-26 11:43:06 -0400 | [diff] [blame] | 1002 | SINK( "f32", RasterSink, kRGBA_F32_SkColorType, srgbLinear); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1003 | } |
| 1004 | #undef SINK |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1005 | return nullptr; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 1006 | } |
| 1007 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 1008 | static Sink* create_via(const SkString& tag, Sink* wrapped) { |
Brian Salomon | 2335644 | 2018-11-30 15:33:19 -0500 | [diff] [blame] | 1009 | #define VIA(t, via, ...) if (tag.equals(t)) return new via(__VA_ARGS__) |
Mike Reed | bae888e | 2017-02-18 16:50:45 -0500 | [diff] [blame] | 1010 | #ifdef TEST_VIA_SVG |
Mike Reed | f67c459 | 2017-02-17 17:06:11 -0500 | [diff] [blame] | 1011 | VIA("svg", ViaSVG, wrapped); |
Mike Reed | bae888e | 2017-02-18 16:50:45 -0500 | [diff] [blame] | 1012 | #endif |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1013 | VIA("serialize", ViaSerialization, wrapped); |
mtklein | 4a34ecb | 2016-01-08 10:19:35 -0800 | [diff] [blame] | 1014 | VIA("pic", ViaPicture, wrapped); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1015 | VIA("tiles", ViaTiles, 256, 256, nullptr, wrapped); |
mtklein | 7edca21 | 2015-01-21 13:18:51 -0800 | [diff] [blame] | 1016 | VIA("tiles_rt", ViaTiles, 256, 256, new SkRTreeFactory, wrapped); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1017 | |
Brian Salomon | 5790420 | 2018-12-17 14:45:00 -0500 | [diff] [blame] | 1018 | VIA("ddl", ViaDDL, 1, 3, wrapped); |
| 1019 | VIA("ddl2", ViaDDL, 2, 3, wrapped); |
Robert Phillips | 33f02ed | 2018-03-27 08:06:57 -0400 | [diff] [blame] | 1020 | |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 1021 | if (FLAGS_matrix.count() == 4) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1022 | SkMatrix m; |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 1023 | m.reset(); |
| 1024 | m.setScaleX((SkScalar)atof(FLAGS_matrix[0])); |
| 1025 | m.setSkewX ((SkScalar)atof(FLAGS_matrix[1])); |
| 1026 | m.setSkewY ((SkScalar)atof(FLAGS_matrix[2])); |
| 1027 | m.setScaleY((SkScalar)atof(FLAGS_matrix[3])); |
| 1028 | VIA("matrix", ViaMatrix, m, wrapped); |
| 1029 | VIA("upright", ViaUpright, m, wrapped); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1030 | } |
tomhudson | 64de1e1 | 2015-03-05 08:01:07 -0800 | [diff] [blame] | 1031 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1032 | #undef VIA |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1033 | return nullptr; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 1034 | } |
| 1035 | |
Ben Wagner | f28d472 | 2017-08-11 17:33:22 -0400 | [diff] [blame] | 1036 | static bool gather_sinks(const GrContextOptions& grCtxOptions, bool defaultConfigs) { |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 1037 | SkCommandLineConfigArray configs; |
| 1038 | ParseConfigs(FLAGS_config, &configs); |
Jim Van Verth | 8a9a371 | 2019-05-31 10:49:12 -0400 | [diff] [blame] | 1039 | AutoreleasePool pool; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 1040 | for (int i = 0; i < configs.count(); i++) { |
| 1041 | const SkCommandLineConfig& config = *configs[i]; |
csmartdalton | 008b9d8 | 2017-02-22 12:00:42 -0700 | [diff] [blame] | 1042 | Sink* sink = create_sink(grCtxOptions, &config); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 1043 | if (sink == nullptr) { |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 1044 | info("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(), |
| 1045 | config.getTag().c_str()); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 1046 | continue; |
| 1047 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1048 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 1049 | const SkTArray<SkString>& parts = config.getViaParts(); |
| 1050 | for (int j = parts.count(); j-- > 0;) { |
| 1051 | const SkString& part = parts[j]; |
| 1052 | Sink* next = create_via(part, sink); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1053 | if (next == nullptr) { |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 1054 | info("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(), |
| 1055 | part.c_str()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1056 | delete sink; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1057 | sink = nullptr; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1058 | break; |
| 1059 | } |
| 1060 | sink = next; |
| 1061 | } |
| 1062 | if (sink) { |
| 1063 | push_sink(config, sink); |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 1064 | } |
| 1065 | } |
brianosman | 05c987c | 2016-05-09 13:42:16 -0700 | [diff] [blame] | 1066 | |
| 1067 | // If no configs were requested (just running tests, perhaps?), then we're okay. |
Ben Wagner | f28d472 | 2017-08-11 17:33:22 -0400 | [diff] [blame] | 1068 | if (configs.count() == 0 || |
| 1069 | // If we're using the default configs, we're okay. |
| 1070 | defaultConfigs || |
Ben Wagner | 32fa510 | 2017-08-10 21:25:55 -0400 | [diff] [blame] | 1071 | // Otherwise, make sure that all specified configs have become sinks. |
| 1072 | configs.count() == gSinks.count()) { |
| 1073 | return true; |
| 1074 | } |
Ben Wagner | 32fa510 | 2017-08-10 21:25:55 -0400 | [diff] [blame] | 1075 | return false; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 1076 | } |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 1077 | |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 1078 | static bool match(const char* needle, const char* haystack) { |
Chris Dalton | ecf78ac | 2017-08-15 15:43:08 -0600 | [diff] [blame] | 1079 | if ('~' == needle[0]) { |
| 1080 | return !match(needle + 1, haystack); |
| 1081 | } |
| 1082 | if (0 == strcmp("_", needle)) { |
| 1083 | return true; |
| 1084 | } |
| 1085 | return nullptr != strstr(haystack, needle); |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 1086 | } |
| 1087 | |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1088 | static bool is_blacklisted(const char* sink, const char* src, |
| 1089 | const char* srcOptions, const char* name) { |
mtklein | 0d243ff | 2015-04-03 07:51:00 -0700 | [diff] [blame] | 1090 | for (int i = 0; i < FLAGS_blacklist.count() - 3; i += 4) { |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 1091 | if (match(FLAGS_blacklist[i+0], sink) && |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 1092 | match(FLAGS_blacklist[i+1], src) && |
| 1093 | match(FLAGS_blacklist[i+2], srcOptions) && |
| 1094 | match(FLAGS_blacklist[i+3], name)) { |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1095 | return true; |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 1096 | } |
| 1097 | } |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1098 | return false; |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 1099 | } |
| 1100 | |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1101 | // Even when a Task Sink reports to be non-threadsafe (e.g. GPU), we know things like |
| 1102 | // .png encoding are definitely thread safe. This lets us offload that work to CPU threads. |
| 1103 | static SkTaskGroup gDefinitelyThreadSafeWork; |
| 1104 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1105 | // The finest-grained unit of work we can run: draw a single Src into a single Sink, |
| 1106 | // report any errors, and perhaps write out the output: a .png of the bitmap, or a raw stream. |
| 1107 | struct Task { |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 1108 | Task(const TaggedSrc& src, const TaggedSink& sink) : src(src), sink(sink) {} |
| 1109 | const TaggedSrc& src; |
| 1110 | const TaggedSink& sink; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1111 | |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1112 | static void Run(const Task& task) { |
Jim Van Verth | 8a9a371 | 2019-05-31 10:49:12 -0400 | [diff] [blame] | 1113 | AutoreleasePool pool; |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1114 | SkString name = task.src->name(); |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 1115 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 1116 | SkString log; |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1117 | if (!FLAGS_dryRun) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1118 | SkBitmap bitmap; |
| 1119 | SkDynamicMemoryWStream stream; |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1120 | start(task.sink.tag.c_str(), task.src.tag.c_str(), |
| 1121 | task.src.options.c_str(), name.c_str()); |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1122 | Error err = task.sink->draw(*task.src, &bitmap, &stream, &log); |
mtklein | b3b13b7 | 2016-03-07 13:20:52 -0800 | [diff] [blame] | 1123 | if (!log.isEmpty()) { |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 1124 | info("%s %s %s %s:\n%s\n", task.sink.tag.c_str() |
| 1125 | , task.src.tag.c_str() |
| 1126 | , task.src.options.c_str() |
| 1127 | , name.c_str() |
| 1128 | , log.c_str()); |
mtklein | b3b13b7 | 2016-03-07 13:20:52 -0800 | [diff] [blame] | 1129 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1130 | if (!err.isEmpty()) { |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 1131 | if (err.isFatal()) { |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 1132 | fail(SkStringPrintf("%s %s %s %s: %s", |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1133 | task.sink.tag.c_str(), |
| 1134 | task.src.tag.c_str(), |
| 1135 | task.src.options.c_str(), |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 1136 | name.c_str(), |
| 1137 | err.c_str())); |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 1138 | } else { |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1139 | done(task.sink.tag.c_str(), task.src.tag.c_str(), |
| 1140 | task.src.options.c_str(), name.c_str()); |
mtklein | ba6ada7 | 2016-01-21 09:39:35 -0800 | [diff] [blame] | 1141 | return; |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 1142 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1143 | } |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 1144 | |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1145 | // We're likely switching threads here, so we must capture by value, [=] or [foo,bar]. |
Hal Canary | 0b83319 | 2017-03-14 14:35:02 -0400 | [diff] [blame] | 1146 | SkStreamAsset* data = stream.detachAsStream().release(); |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1147 | gDefinitelyThreadSafeWork.add([task,name,bitmap,data]{ |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 1148 | std::unique_ptr<SkStreamAsset> ownedData(data); |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1149 | |
Mike Klein | e127170 | 2019-03-07 11:46:59 -0600 | [diff] [blame] | 1150 | std::unique_ptr<HashAndEncode> hashAndEncode; |
| 1151 | |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1152 | SkString md5; |
Brian Osman | 57796b3 | 2019-01-25 18:02:59 +0000 | [diff] [blame] | 1153 | if (!FLAGS_writePath.isEmpty() || !FLAGS_readPath.isEmpty()) { |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1154 | SkMD5 hash; |
| 1155 | if (data->getLength()) { |
| 1156 | hash.writeStream(data, data->getLength()); |
| 1157 | data->rewind(); |
mtklein | 3840846 | 2015-07-08 07:25:27 -0700 | [diff] [blame] | 1158 | } else { |
Mike Klein | e127170 | 2019-03-07 11:46:59 -0600 | [diff] [blame] | 1159 | hashAndEncode.reset(new HashAndEncode(bitmap)); |
| 1160 | hashAndEncode->write(&hash); |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1161 | } |
Hal Canary | 0f2f522 | 2019-04-03 10:13:45 -0400 | [diff] [blame] | 1162 | SkMD5::Digest digest = hash.finish(); |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1163 | for (int i = 0; i < 16; i++) { |
| 1164 | md5.appendf("%02x", digest.data[i]); |
mtklein | 3840846 | 2015-07-08 07:25:27 -0700 | [diff] [blame] | 1165 | } |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 1166 | } |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 1167 | |
Brian Osman | 57796b3 | 2019-01-25 18:02:59 +0000 | [diff] [blame] | 1168 | if (!FLAGS_readPath.isEmpty() && |
| 1169 | !gGold.contains(Gold(task.sink.tag, task.src.tag, |
| 1170 | task.src.options, name, md5))) { |
| 1171 | fail(SkStringPrintf("%s not found for %s %s %s %s in %s", |
| 1172 | md5.c_str(), |
| 1173 | task.sink.tag.c_str(), |
| 1174 | task.src.tag.c_str(), |
| 1175 | task.src.options.c_str(), |
| 1176 | name.c_str(), |
| 1177 | FLAGS_readPath[0])); |
| 1178 | } |
| 1179 | |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1180 | if (!FLAGS_writePath.isEmpty()) { |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1181 | const char* ext = task.sink->fileExtension(); |
Brian Osman | f1942de | 2017-08-30 14:50:22 -0400 | [diff] [blame] | 1182 | if (ext && !FLAGS_dont_write.contains(ext)) { |
Mike Klein | 97d6a7a | 2017-07-24 10:37:19 -0400 | [diff] [blame] | 1183 | if (data->getLength()) { |
Mike Klein | e127170 | 2019-03-07 11:46:59 -0600 | [diff] [blame] | 1184 | WriteToDisk(task, md5, ext, data, data->getLength(), nullptr, nullptr); |
Mike Klein | 97d6a7a | 2017-07-24 10:37:19 -0400 | [diff] [blame] | 1185 | SkASSERT(bitmap.drawsNothing()); |
| 1186 | } else if (!bitmap.drawsNothing()) { |
Mike Klein | e127170 | 2019-03-07 11:46:59 -0600 | [diff] [blame] | 1187 | WriteToDisk(task, md5, ext, nullptr, 0, &bitmap, hashAndEncode.get()); |
Mike Klein | 97d6a7a | 2017-07-24 10:37:19 -0400 | [diff] [blame] | 1188 | } |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1189 | } |
| 1190 | } |
Brian Osman | 582f686 | 2019-03-11 11:20:55 -0400 | [diff] [blame] | 1191 | |
| 1192 | SkPixmap pm; |
| 1193 | if (FLAGS_checkF16 && bitmap.colorType() == kRGBA_F16Norm_SkColorType && |
| 1194 | bitmap.peekPixels(&pm)) { |
| 1195 | bool unclamped = false; |
| 1196 | for (int y = 0; y < pm.height() && !unclamped; ++y) |
| 1197 | for (int x = 0; x < pm.width() && !unclamped; ++x) { |
| 1198 | Sk4f rgba = SkHalfToFloat_finite_ftz(*pm.addr64(x, y)); |
| 1199 | float a = rgba[3]; |
| 1200 | if (a > 1.0f || (rgba < 0.0f).anyTrue() || (rgba > a).anyTrue()) { |
Brian Osman | b73e607 | 2019-03-15 10:02:16 -0400 | [diff] [blame] | 1201 | SkDebugf("[%s] F16Norm pixel [%d, %d] unclamped: (%g, %g, %g, %g)\n", |
| 1202 | name.c_str(), x, y, rgba[0], rgba[1], rgba[2], rgba[3]); |
Brian Osman | 582f686 | 2019-03-11 11:20:55 -0400 | [diff] [blame] | 1203 | unclamped = true; |
| 1204 | } |
| 1205 | } |
| 1206 | } |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1207 | }); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1208 | } |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1209 | 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] | 1210 | } |
| 1211 | |
Mike Klein | 66f09a7 | 2019-02-12 13:03:54 -0500 | [diff] [blame] | 1212 | static SkString identify_gamut(SkColorSpace* cs) { |
| 1213 | if (!cs) { |
| 1214 | return SkString("untagged"); |
| 1215 | } |
| 1216 | |
| 1217 | skcms_Matrix3x3 gamut; |
| 1218 | if (cs->toXYZD50(&gamut)) { |
| 1219 | auto eq = [](skcms_Matrix3x3 x, skcms_Matrix3x3 y) { |
| 1220 | for (int i = 0; i < 3; i++) |
| 1221 | for (int j = 0; j < 3; j++) { |
| 1222 | if (x.vals[i][j] != y.vals[i][j]) { return false; } |
| 1223 | } |
| 1224 | return true; |
| 1225 | }; |
| 1226 | |
| 1227 | if (eq(gamut, SkNamedGamut::kSRGB )) { return SkString("sRGB"); } |
| 1228 | if (eq(gamut, SkNamedGamut::kAdobeRGB)) { return SkString("Adobe"); } |
| 1229 | if (eq(gamut, SkNamedGamut::kDCIP3 )) { return SkString("P3"); } |
| 1230 | if (eq(gamut, SkNamedGamut::kRec2020 )) { return SkString("2020"); } |
| 1231 | if (eq(gamut, SkNamedGamut::kXYZ )) { return SkString("XYZ"); } |
| 1232 | if (eq(gamut, gNarrow_toXYZD50 )) { return SkString("narrow"); } |
| 1233 | return SkString("other"); |
| 1234 | } |
| 1235 | return SkString("non-XYZ"); |
| 1236 | } |
| 1237 | |
| 1238 | static SkString identify_transfer_fn(SkColorSpace* cs) { |
| 1239 | if (!cs) { |
| 1240 | return SkString("untagged"); |
| 1241 | } |
| 1242 | |
| 1243 | skcms_TransferFunction tf; |
| 1244 | if (cs->isNumericalTransferFn(&tf)) { |
| 1245 | auto eq = [](skcms_TransferFunction x, skcms_TransferFunction y) { |
| 1246 | return x.g == y.g |
| 1247 | && x.a == y.a |
| 1248 | && x.b == y.b |
| 1249 | && x.c == y.c |
| 1250 | && x.d == y.d |
| 1251 | && x.e == y.e |
| 1252 | && x.f == y.f; |
| 1253 | }; |
| 1254 | |
| 1255 | if (tf.a == 1 && tf.b == 0 && tf.c == 0 && tf.d == 0 && tf.e == 0 && tf.f == 0) { |
| 1256 | return SkStringPrintf("gamma %.3g", tf.g); |
| 1257 | } |
Hal Canary | be67a17 | 2019-05-24 10:13:36 -0400 | [diff] [blame] | 1258 | if (eq(tf, SkNamedTransferFn::kSRGB )) { return SkString("sRGB"); } |
| 1259 | if (eq(tf, SkNamedTransferFn::kRec2020)) { return SkString("2020"); } |
Mike Klein | 66f09a7 | 2019-02-12 13:03:54 -0500 | [diff] [blame] | 1260 | return SkStringPrintf("%.3g %.3g %.3g %.3g %.3g %.3g %.3g", |
| 1261 | tf.g, tf.a, tf.b, tf.c, tf.d, tf.e, tf.f); |
| 1262 | } |
| 1263 | return SkString("non-numeric"); |
| 1264 | } |
| 1265 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1266 | static void WriteToDisk(const Task& task, |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 1267 | SkString md5, |
| 1268 | const char* ext, |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1269 | SkStream* data, size_t len, |
Mike Klein | e127170 | 2019-03-07 11:46:59 -0600 | [diff] [blame] | 1270 | const SkBitmap* bitmap, |
| 1271 | const HashAndEncode* hashAndEncode) { |
mtklein | 409d470 | 2016-02-29 07:38:01 -0800 | [diff] [blame] | 1272 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1273 | JsonWriter::BitmapResult result; |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 1274 | result.name = task.src->name(); |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1275 | result.config = task.sink.tag; |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 1276 | result.sourceType = task.src.tag; |
| 1277 | result.sourceOptions = task.src.options; |
| 1278 | result.ext = ext; |
| 1279 | result.md5 = md5; |
Mike Klein | 0abbaca | 2019-03-06 09:57:49 -0600 | [diff] [blame] | 1280 | if (bitmap) { |
Mike Klein | 9816878 | 2019-04-09 13:45:02 -0500 | [diff] [blame] | 1281 | result.gamut = identify_gamut (bitmap->colorSpace()); |
| 1282 | result.transferFn = identify_transfer_fn (bitmap->colorSpace()); |
| 1283 | result.colorType = ToolUtils::colortype_name (bitmap->colorType()); |
| 1284 | result.alphaType = ToolUtils::alphatype_name (bitmap->alphaType()); |
| 1285 | result.colorDepth = ToolUtils::colortype_depth(bitmap->colorType()); |
Mike Klein | 0abbaca | 2019-03-06 09:57:49 -0600 | [diff] [blame] | 1286 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1287 | JsonWriter::AddBitmapResult(result); |
| 1288 | |
mtklein | b0531a7 | 2015-04-07 13:38:48 -0700 | [diff] [blame] | 1289 | // If an MD5 is uninteresting, we want it noted in the JSON file, |
| 1290 | // but don't want to dump it out as a .png (or whatever ext is). |
| 1291 | if (gUninterestingHashes.contains(md5)) { |
| 1292 | return; |
| 1293 | } |
| 1294 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1295 | const char* dir = FLAGS_writePath[0]; |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 1296 | SkString resources = GetResourcePath(); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1297 | if (0 == strcmp(dir, "@")) { // Needed for iOS. |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 1298 | dir = resources.c_str(); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1299 | } |
| 1300 | sk_mkdir(dir); |
| 1301 | |
| 1302 | SkString path; |
| 1303 | if (FLAGS_nameByHash) { |
| 1304 | path = SkOSPath::Join(dir, result.md5.c_str()); |
| 1305 | path.append("."); |
| 1306 | path.append(ext); |
| 1307 | if (sk_exists(path.c_str())) { |
| 1308 | return; // Content-addressed. If it exists already, we're done. |
| 1309 | } |
| 1310 | } else { |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 1311 | path = SkOSPath::Join(dir, task.sink.tag.c_str()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1312 | sk_mkdir(path.c_str()); |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 1313 | path = SkOSPath::Join(path.c_str(), task.src.tag.c_str()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1314 | sk_mkdir(path.c_str()); |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 1315 | if (strcmp(task.src.options.c_str(), "") != 0) { |
| 1316 | path = SkOSPath::Join(path.c_str(), task.src.options.c_str()); |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 1317 | sk_mkdir(path.c_str()); |
| 1318 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1319 | path = SkOSPath::Join(path.c_str(), task.src->name().c_str()); |
| 1320 | path.append("."); |
| 1321 | path.append(ext); |
| 1322 | } |
| 1323 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1324 | if (bitmap) { |
Mike Klein | e127170 | 2019-03-07 11:46:59 -0600 | [diff] [blame] | 1325 | SkASSERT(hashAndEncode); |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 1326 | if (!hashAndEncode->writePngTo(path.c_str(), |
| 1327 | result.md5.c_str(), |
| 1328 | FLAGS_key, |
| 1329 | FLAGS_properties)) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1330 | fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str())); |
| 1331 | return; |
| 1332 | } |
| 1333 | } else { |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 1334 | SkFILEWStream file(path.c_str()); |
| 1335 | if (!file.isValid()) { |
| 1336 | fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str())); |
| 1337 | return; |
| 1338 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1339 | if (!file.writeStream(data, len)) { |
| 1340 | fail(SkStringPrintf("Can't write to %s.\n", path.c_str())); |
| 1341 | return; |
| 1342 | } |
| 1343 | } |
| 1344 | } |
| 1345 | }; |
| 1346 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1347 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 1348 | |
| 1349 | // Unit tests don't fit so well into the Src/Sink model, so we give them special treatment. |
| 1350 | |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1351 | static SkTDArray<skiatest::Test> gParallelTests, gSerialTests; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1352 | |
| 1353 | static void gather_tests() { |
mtklein | 6c5fed2 | 2015-01-20 13:47:23 -0800 | [diff] [blame] | 1354 | if (!FLAGS_src.contains("tests")) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1355 | return; |
| 1356 | } |
Hal Canary | 972eba3 | 2018-07-30 17:07:07 -0400 | [diff] [blame] | 1357 | for (const skiatest::Test& test : skiatest::TestRegistry::Range()) { |
mtklein | 6393c06 | 2015-04-27 08:45:01 -0700 | [diff] [blame] | 1358 | if (!in_shard()) { |
| 1359 | continue; |
| 1360 | } |
Mike Klein | 88544fb | 2019-03-20 10:50:33 -0500 | [diff] [blame] | 1361 | if (CommandLineFlags::ShouldSkip(FLAGS_match, test.name)) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1362 | continue; |
| 1363 | } |
Brian Osman | c7ad40f | 2018-05-31 14:27:17 -0400 | [diff] [blame] | 1364 | if (test.needsGpu && FLAGS_gpu) { |
Mike Reed | 5edcd31 | 2018-08-08 11:23:41 -0400 | [diff] [blame] | 1365 | (FLAGS_gpu_threading ? gParallelTests : gSerialTests).push_back(test); |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1366 | } else if (!test.needsGpu && FLAGS_cpu) { |
Mike Reed | 5edcd31 | 2018-08-08 11:23:41 -0400 | [diff] [blame] | 1367 | gParallelTests.push_back(test); |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 1368 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1369 | } |
| 1370 | } |
| 1371 | |
csmartdalton | 008b9d8 | 2017-02-22 12:00:42 -0700 | [diff] [blame] | 1372 | static void run_test(skiatest::Test test, const GrContextOptions& grCtxOptions) { |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1373 | struct : public skiatest::Reporter { |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 1374 | void reportFailed(const skiatest::Failure& failure) override { |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1375 | fail(failure.toString()); |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1376 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 1377 | bool allowExtendedTest() const override { |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1378 | return FLAGS_pathOpsExtended; |
| 1379 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 1380 | bool verbose() const override { return FLAGS_veryVerbose; } |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1381 | } reporter; |
djsollen | 824996a | 2015-06-12 12:06:22 -0700 | [diff] [blame] | 1382 | |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1383 | if (!FLAGS_dryRun && !is_blacklisted("_", "tests", "_", test.name)) { |
Jim Van Verth | 8a9a371 | 2019-05-31 10:49:12 -0400 | [diff] [blame] | 1384 | AutoreleasePool pool; |
Robert Phillips | ec32534 | 2017-10-30 18:02:48 +0000 | [diff] [blame] | 1385 | GrContextOptions options = grCtxOptions; |
| 1386 | test.modifyGrContextOptions(&options); |
| 1387 | |
Brian Osman | cdf3174 | 2019-03-13 10:13:46 -0400 | [diff] [blame] | 1388 | skiatest::ReporterContext ctx(&reporter, SkString(test.name)); |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1389 | start("unit", "test", "", test.name); |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 1390 | test.run(&reporter, options); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1391 | } |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1392 | done("unit", "test", "", test.name); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1393 | } |
| 1394 | |
| 1395 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 1396 | |
Mike Klein | be28ee2 | 2017-02-06 12:46:20 -0500 | [diff] [blame] | 1397 | int main(int argc, char** argv) { |
Brian Osman | 1c1208e | 2019-06-24 13:36:05 -0400 | [diff] [blame] | 1398 | #if defined(__MSVC_RUNTIME_CHECKS) |
| 1399 | _RTC_SetErrorFunc(RuntimeCheckErrorFunc); |
| 1400 | #endif |
Dongwon Kang | 0c7861f | 2018-02-16 10:55:21 -0800 | [diff] [blame] | 1401 | #if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && defined(SK_HAS_HEIF_LIBRARY) |
| 1402 | android::ProcessState::self()->startThreadPool(); |
| 1403 | #endif |
Mike Klein | 88544fb | 2019-03-20 10:50:33 -0500 | [diff] [blame] | 1404 | CommandLineFlags::Parse(argc, argv); |
Brian Osman | 53136aa | 2017-07-20 15:43:35 -0400 | [diff] [blame] | 1405 | |
Brian Osman | bc8150f | 2017-07-24 11:38:01 -0400 | [diff] [blame] | 1406 | initializeEventTracingForTools(); |
Brian Osman | 53136aa | 2017-07-20 15:43:35 -0400 | [diff] [blame] | 1407 | |
Mike Klein | 6613cc5 | 2017-12-19 09:09:33 -0500 | [diff] [blame] | 1408 | #if !defined(SK_BUILD_FOR_GOOGLE3) && defined(SK_BUILD_FOR_IOS) |
Mike Klein | adacaef | 2017-02-06 09:26:14 -0500 | [diff] [blame] | 1409 | cd_Documents(); |
| 1410 | #endif |
bsalomon | 71de353 | 2016-04-26 14:27:21 -0700 | [diff] [blame] | 1411 | setbuf(stdout, nullptr); |
mtklein | 246ba3a | 2016-02-23 10:39:36 -0800 | [diff] [blame] | 1412 | setup_crash_handler(); |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 1413 | |
Mike Klein | 19cc0f6 | 2019-03-22 15:30:07 -0500 | [diff] [blame] | 1414 | ToolUtils::SetDefaultFontMgr(); |
Mike Klein | 03fa5d4 | 2019-03-22 11:39:09 -0500 | [diff] [blame] | 1415 | SetAnalyticAAFromCommonFlags(); |
liyuqian | 38911a7 | 2016-10-04 11:23:22 -0700 | [diff] [blame] | 1416 | |
Mike Reed | 7c26ca7 | 2017-07-05 15:45:52 -0400 | [diff] [blame] | 1417 | if (FLAGS_forceRasterPipeline) { |
| 1418 | gSkForceRasterPipelineBlitter = true; |
| 1419 | } |
Yuqian Li | 550148b | 2017-01-13 10:13:13 -0500 | [diff] [blame] | 1420 | |
Mike Klein | e9f187b | 2017-06-26 13:23:12 -0400 | [diff] [blame] | 1421 | // The bots like having a verbose.log to upload, so always touch the file even if --verbose. |
| 1422 | if (!FLAGS_writePath.isEmpty()) { |
mtklein | 51c8cfc | 2016-03-11 12:59:09 -0800 | [diff] [blame] | 1423 | sk_mkdir(FLAGS_writePath[0]); |
mtklein | a1ce216 | 2016-07-22 12:23:46 -0700 | [diff] [blame] | 1424 | gVLog = fopen(SkOSPath::Join(FLAGS_writePath[0], "verbose.log").c_str(), "w"); |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 1425 | } |
Mike Klein | e9f187b | 2017-06-26 13:23:12 -0400 | [diff] [blame] | 1426 | if (FLAGS_verbose) { |
| 1427 | gVLog = stderr; |
| 1428 | } |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 1429 | |
csmartdalton | 008b9d8 | 2017-02-22 12:00:42 -0700 | [diff] [blame] | 1430 | GrContextOptions grCtxOptions; |
Chris Dalton | 040238b | 2017-12-18 14:22:34 -0700 | [diff] [blame] | 1431 | SetCtxOptionsFromCommonFlags(&grCtxOptions); |
csmartdalton | 008b9d8 | 2017-02-22 12:00:42 -0700 | [diff] [blame] | 1432 | |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 1433 | dump_json(); // It's handy for the bots to assume this is ~never missing. |
| 1434 | |
commit-bot@chromium.org | 39e8d93 | 2014-05-29 20:14:48 +0000 | [diff] [blame] | 1435 | SkAutoGraphics ag; |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 1436 | SkTaskGroup::Enabler enabled(FLAGS_threads); |
commit-bot@chromium.org | a65e2fd | 2014-05-30 17:23:31 +0000 | [diff] [blame] | 1437 | |
Mike Reed | 0933bc9 | 2017-12-09 01:27:41 +0000 | [diff] [blame] | 1438 | if (nullptr == GetResourceAsData("images/color_wheel.png")) { |
| 1439 | info("Some resources are missing. Do you need to set --resourcePath?\n"); |
halcanary | 7d57124 | 2016-02-24 17:59:16 -0800 | [diff] [blame] | 1440 | } |
Brian Osman | 57796b3 | 2019-01-25 18:02:59 +0000 | [diff] [blame] | 1441 | gather_gold(); |
borenet | 09ed480 | 2015-04-03 14:15:33 -0700 | [diff] [blame] | 1442 | gather_uninteresting_hashes(); |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 1443 | |
scroggo | 8673714 | 2016-02-03 12:19:11 -0800 | [diff] [blame] | 1444 | if (!gather_srcs()) { |
| 1445 | return 1; |
| 1446 | } |
Ben Wagner | f28d472 | 2017-08-11 17:33:22 -0400 | [diff] [blame] | 1447 | // TODO(dogben): This is a bit ugly. Find a cleaner way to do this. |
| 1448 | bool defaultConfigs = true; |
| 1449 | for (int i = 0; i < argc; i++) { |
| 1450 | static const char* kConfigArg = "--config"; |
| 1451 | if (strcmp(argv[i], kConfigArg) == 0) { |
| 1452 | defaultConfigs = false; |
| 1453 | break; |
| 1454 | } |
| 1455 | } |
| 1456 | if (!gather_sinks(grCtxOptions, defaultConfigs)) { |
brianosman | 05c987c | 2016-05-09 13:42:16 -0700 | [diff] [blame] | 1457 | return 1; |
| 1458 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1459 | gather_tests(); |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1460 | gPending = gSrcs.count() * gSinks.count() + gParallelTests.count() + gSerialTests.count(); |
Brian Osman | d0677bc | 2017-08-03 12:13:47 -0400 | [diff] [blame] | 1461 | info("%d srcs * %d sinks + %d tests == %d tasks\n", |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 1462 | gSrcs.count(), gSinks.count(), gParallelTests.count() + gSerialTests.count(), gPending); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1463 | |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1464 | // Kick off as much parallel work as we can, making note of any serial work we'll need to do. |
| 1465 | SkTaskGroup parallel; |
| 1466 | SkTArray<Task> serial; |
| 1467 | |
| 1468 | for (auto& sink : gSinks) |
| 1469 | for (auto& src : gSrcs) { |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1470 | if (src->veto(sink->flags()) || |
| 1471 | is_blacklisted(sink.tag.c_str(), src.tag.c_str(), |
| 1472 | src.options.c_str(), src->name().c_str())) { |
Herb Derby | a1b7be6 | 2019-05-09 16:59:18 -0400 | [diff] [blame] | 1473 | SkAutoSpinlock lock(gMutex); |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1474 | gPending--; |
| 1475 | continue; |
| 1476 | } |
| 1477 | |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1478 | Task task(src, sink); |
| 1479 | if (src->serial() || sink->serial()) { |
| 1480 | serial.push_back(task); |
| 1481 | } else { |
| 1482 | parallel.add([task] { Task::Run(task); }); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1483 | } |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 1484 | } |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1485 | for (auto test : gParallelTests) { |
csmartdalton | 008b9d8 | 2017-02-22 12:00:42 -0700 | [diff] [blame] | 1486 | parallel.add([test, grCtxOptions] { run_test(test, grCtxOptions); }); |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 1487 | } |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1488 | |
| 1489 | // With the parallel work running, run serial tasks and tests here on main thread. |
| 1490 | for (auto task : serial) { Task::Run(task); } |
csmartdalton | 008b9d8 | 2017-02-22 12:00:42 -0700 | [diff] [blame] | 1491 | for (auto test : gSerialTests) { run_test(test, grCtxOptions); } |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1492 | |
| 1493 | // Wait for any remaining parallel work to complete (including any spun off of serial tasks). |
| 1494 | parallel.wait(); |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1495 | gDefinitelyThreadSafeWork.wait(); |
| 1496 | |
Ben Wagner | 83c6b96 | 2018-07-10 19:40:15 -0400 | [diff] [blame] | 1497 | // At this point we're back in single-threaded land. |
| 1498 | |
mtklein | da884c4 | 2016-02-24 18:00:23 -0800 | [diff] [blame] | 1499 | // We'd better have run everything. |
| 1500 | SkASSERT(gPending == 0); |
mtklein | e027f17 | 2016-02-26 15:53:06 -0800 | [diff] [blame] | 1501 | // Make sure we've flushed all our results to disk. |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 1502 | dump_json(); |
mtklein | da884c4 | 2016-02-24 18:00:23 -0800 | [diff] [blame] | 1503 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1504 | if (gFailures.count() > 0) { |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 1505 | info("Failures:\n"); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1506 | for (int i = 0; i < gFailures.count(); i++) { |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 1507 | info("\t%s\n", gFailures[i].c_str()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1508 | } |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 1509 | info("%d failures\n", gFailures.count()); |
Kevin Lubick | 805c4e8 | 2019-03-20 09:46:09 -0400 | [diff] [blame] | 1510 | // A non-zero return code does not make it to Swarming |
| 1511 | // An abort does. |
| 1512 | #ifdef SK_BUILD_FOR_IOS |
Kevin Lubick | c4fec06 | 2019-05-31 12:31:09 +0000 | [diff] [blame] | 1513 | SK_ABORT("There were failures!"); |
Kevin Lubick | 805c4e8 | 2019-03-20 09:46:09 -0400 | [diff] [blame] | 1514 | #endif |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1515 | return 1; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 1516 | } |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 1517 | |
Herb Derby | 5a523fe | 2017-01-26 16:48:28 -0500 | [diff] [blame] | 1518 | SkGraphics::PurgeAllCaches(); |
mtklein | c41fd92 | 2016-03-08 09:01:39 -0800 | [diff] [blame] | 1519 | info("Finished!\n"); |
Brian Osman | 53136aa | 2017-07-20 15:43:35 -0400 | [diff] [blame] | 1520 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1521 | return 0; |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 1522 | } |