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