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