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