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