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