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