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