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