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 | |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 8 | #include "CrashHandler.h" |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 9 | #include "DMJsonWriter.h" |
| 10 | #include "DMSrcSink.h" |
tomhudson | eebc39a | 2015-02-23 12:18:05 -0800 | [diff] [blame] | 11 | #include "DMSrcSinkAndroid.h" |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 12 | #include "ProcStats.h" |
halcanary | 7d57124 | 2016-02-24 17:59:16 -0800 | [diff] [blame] | 13 | #include "Resources.h" |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 14 | #include "SkBBHFactory.h" |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 15 | #include "SkChecksum.h" |
scroggo | cc2feb1 | 2015-08-14 08:32:46 -0700 | [diff] [blame] | 16 | #include "SkCodec.h" |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 17 | #include "SkCommonFlags.h" |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 18 | #include "SkCommonFlagsConfig.h" |
caryclark | 83ca628 | 2015-06-10 09:31:09 -0700 | [diff] [blame] | 19 | #include "SkFontMgr.h" |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 20 | #include "SkForceLinking.h" |
| 21 | #include "SkGraphics.h" |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 22 | #include "SkMD5.h" |
mtklein | 1b24933 | 2015-07-07 12:21:21 -0700 | [diff] [blame] | 23 | #include "SkMutex.h" |
mtklein | 1d0f164 | 2014-09-08 08:05:18 -0700 | [diff] [blame] | 24 | #include "SkOSFile.h" |
mtklein | 246ba3a | 2016-02-23 10:39:36 -0800 | [diff] [blame] | 25 | #include "SkSpinlock.h" |
mtklein | a82f562 | 2015-02-20 12:30:19 -0800 | [diff] [blame] | 26 | #include "SkTHash.h" |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 27 | #include "SkTaskGroup.h" |
mtklein | de6fc2b | 2015-03-12 06:28:54 -0700 | [diff] [blame] | 28 | #include "SkThreadUtils.h" |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 29 | #include "Test.h" |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 30 | #include "Timer.h" |
caryclark | 83ca628 | 2015-06-10 09:31:09 -0700 | [diff] [blame] | 31 | #include "sk_tool_utils.h" |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 32 | |
halcanary | 7a14b31 | 2015-10-01 07:28:13 -0700 | [diff] [blame] | 33 | #ifdef SK_PDF_IMAGE_STATS |
| 34 | extern void SkPDFImageDumpStats(); |
| 35 | #endif |
| 36 | |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 37 | #include "png.h" |
| 38 | |
bungeman | 60e0fee | 2015-08-26 05:15:46 -0700 | [diff] [blame] | 39 | #include <stdlib.h> |
| 40 | |
scroggo | 27a5834 | 2015-10-28 08:56:41 -0700 | [diff] [blame] | 41 | #ifndef SK_BUILD_FOR_WIN32 |
| 42 | #include <unistd.h> |
| 43 | #endif |
| 44 | |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 45 | DEFINE_string(src, "tests gm skp image", "Source types to test."); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 46 | DEFINE_bool(nameByHash, false, |
| 47 | "If true, write to FLAGS_writePath[0]/<hash>.png instead of " |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 48 | "to FLAGS_writePath[0]/<config>/<sourceType>/<sourceOptions>/<name>.png"); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 49 | DEFINE_bool2(pathOpsExtended, x, false, "Run extended pathOps tests."); |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 50 | DEFINE_string(matrix, "1 0 0 1", |
| 51 | "2x2 scale+skew matrix to apply or upright when using " |
| 52 | "'matrix' or 'upright' in config."); |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 53 | 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] | 54 | |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 55 | DEFINE_string(blacklist, "", |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 56 | "Space-separated config/src/srcOptions/name quadruples to blacklist. '_' matches anything. E.g. \n" |
| 57 | "'--blacklist gpu skp _ _' will blacklist all SKPs drawn into the gpu config.\n" |
| 58 | "'--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] | 59 | |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 60 | DEFINE_string2(readPath, r, "", "If set check for equality with golden results in this directory."); |
| 61 | |
borenet | 09ed480 | 2015-04-03 14:15:33 -0700 | [diff] [blame] | 62 | DEFINE_string(uninterestingHashesFile, "", |
| 63 | "File containing a list of uninteresting hashes. If a result hashes to something in " |
| 64 | "this list, no image is written for that result."); |
| 65 | |
mtklein | 6393c06 | 2015-04-27 08:45:01 -0700 | [diff] [blame] | 66 | DEFINE_int32(shards, 1, "We're splitting source data into this many shards."); |
| 67 | DEFINE_int32(shard, 0, "Which shard do I run?"); |
| 68 | |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 69 | __SK_FORCE_IMAGE_DECODER_LINKING; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 70 | using namespace DM; |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 71 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 72 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 73 | |
| 74 | SK_DECLARE_STATIC_MUTEX(gFailuresMutex); |
| 75 | static SkTArray<SkString> gFailures; |
| 76 | |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame^] | 77 | static void fail(const SkString& err) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 78 | SkAutoMutexAcquire lock(gFailuresMutex); |
| 79 | SkDebugf("\n\nFAILURE: %s\n\n", err.c_str()); |
| 80 | gFailures.push_back(err); |
halcanary | 9e398f7 | 2015-01-10 11:18:04 -0800 | [diff] [blame] | 81 | } |
| 82 | |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 83 | |
mtklein | 246ba3a | 2016-02-23 10:39:36 -0800 | [diff] [blame] | 84 | // We use a spinlock to make locking this in a signal handler _somewhat_ safe. |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 85 | SK_DECLARE_STATIC_SPINLOCK(gMutex); |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame^] | 86 | static int32_t gPending; |
| 87 | static SkTArray<SkString> gRunning; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 88 | |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame^] | 89 | static void done(const char* config, const char* src, const char* srcOptions, const char* name) { |
| 90 | SkString id = SkStringPrintf("%s %s %s %s", config, src, srcOptions, name); |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 91 | int pending; |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 92 | { |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 93 | SkAutoTAcquire<SkPODSpinlock> lock(gMutex); |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 94 | for (int i = 0; i < gRunning.count(); i++) { |
| 95 | if (gRunning[i] == id) { |
| 96 | gRunning.removeShuffle(i); |
| 97 | break; |
| 98 | } |
| 99 | } |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 100 | pending = --gPending; |
reed | 50bc051 | 2015-05-19 14:13:31 -0700 | [diff] [blame] | 101 | } |
mtklein | a17241b | 2015-01-23 05:48:00 -0800 | [diff] [blame] | 102 | // We write our dm.json file every once in a while in case we crash. |
| 103 | // Notice this also handles the final dm.json when pending == 0. |
| 104 | if (pending % 500 == 0) { |
| 105 | JsonWriter::DumpJson(); |
| 106 | } |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 107 | } |
| 108 | |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame^] | 109 | static void start(const char* config, const char* src, const char* srcOptions, const char* name) { |
| 110 | SkString id = SkStringPrintf("%s %s %s %s", config, src, srcOptions, name); |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 111 | SkAutoTAcquire<SkPODSpinlock> lock(gMutex); |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 112 | gRunning.push_back(id); |
| 113 | } |
| 114 | |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 115 | static void print_status() { |
| 116 | static SkMSec start_ms = SkTime::GetMSecs(); |
| 117 | |
| 118 | int curr = sk_tools::getCurrResidentSetSizeMB(), |
| 119 | peak = sk_tools::getMaxResidentSetSizeMB(); |
| 120 | SkString elapsed = HumanizeMs(SkTime::GetMSecs() - start_ms); |
| 121 | |
| 122 | SkAutoTAcquire<SkPODSpinlock> lock(gMutex); |
| 123 | SkDebugf("\n%s elapsed, %d active, %d queued, %dMB RAM, %dMB peak\n", |
| 124 | elapsed.c_str(), gRunning.count(), gPending - gRunning.count(), curr, peak); |
| 125 | for (auto& task : gRunning) { |
| 126 | SkDebugf("\t%s\n", task.c_str()); |
| 127 | } |
| 128 | } |
| 129 | |
mtklein | 246ba3a | 2016-02-23 10:39:36 -0800 | [diff] [blame] | 130 | #if defined(SK_BUILD_FOR_WIN32) |
| 131 | static void setup_crash_handler() { |
| 132 | // TODO: custom crash handler like below to print out what was running |
| 133 | SetupCrashHandler(); |
| 134 | } |
| 135 | |
| 136 | #else |
| 137 | #include <signal.h> |
| 138 | static void setup_crash_handler() { |
| 139 | const int kSignals[] = { SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGSEGV }; |
| 140 | for (int sig : kSignals) { |
| 141 | signal(sig, [](int sig) { |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 142 | SkDebugf("\nCaught signal %d [%s].\n", sig, strsignal(sig)); |
| 143 | print_status(); |
mtklein | 246ba3a | 2016-02-23 10:39:36 -0800 | [diff] [blame] | 144 | }); |
| 145 | } |
| 146 | } |
| 147 | #endif |
| 148 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 149 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 150 | |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 151 | struct Gold : public SkString { |
mtklein | a82f562 | 2015-02-20 12:30:19 -0800 | [diff] [blame] | 152 | Gold() : SkString("") {} |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame^] | 153 | Gold(const SkString& sink, const SkString& src, |
| 154 | const SkString& srcOptions, const SkString& name, |
| 155 | const SkString& md5) |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 156 | : SkString("") { |
| 157 | this->append(sink); |
| 158 | this->append(src); |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 159 | this->append(srcOptions); |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 160 | this->append(name); |
| 161 | this->append(md5); |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 162 | } |
mtklein | c8d1dd4 | 2015-10-15 12:23:01 -0700 | [diff] [blame] | 163 | struct Hash { |
| 164 | uint32_t operator()(const Gold& g) const { |
| 165 | return SkGoodHash()((const SkString&)g); |
| 166 | } |
| 167 | }; |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 168 | }; |
mtklein | a82f562 | 2015-02-20 12:30:19 -0800 | [diff] [blame] | 169 | static SkTHashSet<Gold, Gold::Hash> gGold; |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 170 | |
| 171 | static void add_gold(JsonWriter::BitmapResult r) { |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 172 | gGold.add(Gold(r.config, r.sourceType, r.sourceOptions, r.name, r.md5)); |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | static void gather_gold() { |
| 176 | if (!FLAGS_readPath.isEmpty()) { |
| 177 | SkString path(FLAGS_readPath[0]); |
| 178 | path.append("/dm.json"); |
| 179 | if (!JsonWriter::ReadJson(path.c_str(), add_gold)) { |
| 180 | fail(SkStringPrintf("Couldn't read %s for golden results.", path.c_str())); |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 186 | |
borenet | 09ed480 | 2015-04-03 14:15:33 -0700 | [diff] [blame] | 187 | static SkTHashSet<SkString> gUninterestingHashes; |
| 188 | |
| 189 | static void gather_uninteresting_hashes() { |
| 190 | if (!FLAGS_uninterestingHashesFile.isEmpty()) { |
| 191 | SkAutoTUnref<SkData> data(SkData::NewFromFileName(FLAGS_uninterestingHashesFile[0])); |
mtklein | cc334b3 | 2015-09-22 11:43:53 -0700 | [diff] [blame] | 192 | if (!data) { |
| 193 | SkDebugf("WARNING: unable to read uninteresting hashes from %s\n", |
| 194 | FLAGS_uninterestingHashesFile[0]); |
| 195 | return; |
| 196 | } |
borenet | 09ed480 | 2015-04-03 14:15:33 -0700 | [diff] [blame] | 197 | SkTArray<SkString> hashes; |
| 198 | SkStrSplit((const char*)data->data(), "\n", &hashes); |
| 199 | for (const SkString& hash : hashes) { |
| 200 | gUninterestingHashes.add(hash); |
| 201 | } |
mtklein | 136baaa | 2016-02-03 11:21:45 -0800 | [diff] [blame] | 202 | SkDebugf("FYI: loaded %d distinct uninteresting hashes from %d lines\n", |
| 203 | gUninterestingHashes.count(), hashes.count()); |
borenet | 09ed480 | 2015-04-03 14:15:33 -0700 | [diff] [blame] | 204 | } |
| 205 | } |
| 206 | |
| 207 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 208 | |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 209 | struct TaggedSrc : public SkAutoTDelete<Src> { |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame^] | 210 | SkString tag; |
| 211 | SkString options; |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 212 | }; |
| 213 | |
| 214 | struct TaggedSink : public SkAutoTDelete<Sink> { |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 215 | SkString tag; |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 216 | }; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 217 | |
| 218 | static const bool kMemcpyOK = true; |
| 219 | |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 220 | static SkTArray<TaggedSrc, kMemcpyOK> gSrcs; |
| 221 | static SkTArray<TaggedSink, kMemcpyOK> gSinks; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 222 | |
mtklein | 6393c06 | 2015-04-27 08:45:01 -0700 | [diff] [blame] | 223 | static bool in_shard() { |
| 224 | static int N = 0; |
| 225 | return N++ % FLAGS_shards == FLAGS_shard; |
| 226 | } |
| 227 | |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame^] | 228 | static void push_src(const char* tag, ImplicitString options, Src* s) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 229 | SkAutoTDelete<Src> src(s); |
mtklein | 6393c06 | 2015-04-27 08:45:01 -0700 | [diff] [blame] | 230 | if (in_shard() && |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame^] | 231 | FLAGS_src.contains(tag) && |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 232 | !SkCommandLineFlags::ShouldSkip(FLAGS_match, src->name().c_str())) { |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 233 | TaggedSrc& s = gSrcs.push_back(); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 234 | s.reset(src.detach()); |
| 235 | s.tag = tag; |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 236 | s.options = options; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 237 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 238 | } |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 239 | |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 240 | static void push_codec_src(Path path, CodecSrc::Mode mode, CodecSrc::DstColorType dstColorType, |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 241 | SkAlphaType dstAlphaType, float scale) { |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 242 | SkString folder; |
| 243 | switch (mode) { |
| 244 | case CodecSrc::kCodec_Mode: |
| 245 | folder.append("codec"); |
| 246 | break; |
msarett | bb25b53 | 2016-01-13 09:31:39 -0800 | [diff] [blame] | 247 | case CodecSrc::kCodecZeroInit_Mode: |
| 248 | folder.append("codec_zero_init"); |
| 249 | break; |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 250 | case CodecSrc::kScanline_Mode: |
| 251 | folder.append("scanline"); |
| 252 | break; |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 253 | case CodecSrc::kStripe_Mode: |
| 254 | folder.append("stripe"); |
| 255 | break; |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 256 | case CodecSrc::kCroppedScanline_Mode: |
| 257 | folder.append("crop"); |
| 258 | break; |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 259 | case CodecSrc::kSubset_Mode: |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 260 | folder.append("codec_subset"); |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 261 | break; |
msarett | b714fb0 | 2016-01-22 14:46:42 -0800 | [diff] [blame] | 262 | case CodecSrc::kGen_Mode: |
| 263 | folder.append("gen"); |
| 264 | break; |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | switch (dstColorType) { |
| 268 | case CodecSrc::kGrayscale_Always_DstColorType: |
| 269 | folder.append("_kGray8"); |
| 270 | break; |
| 271 | case CodecSrc::kIndex8_Always_DstColorType: |
| 272 | folder.append("_kIndex8"); |
| 273 | break; |
| 274 | default: |
| 275 | break; |
| 276 | } |
| 277 | |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 278 | switch (dstAlphaType) { |
| 279 | case kOpaque_SkAlphaType: |
| 280 | folder.append("_opaque"); |
| 281 | break; |
| 282 | case kPremul_SkAlphaType: |
| 283 | folder.append("_premul"); |
| 284 | break; |
| 285 | case kUnpremul_SkAlphaType: |
| 286 | folder.append("_unpremul"); |
| 287 | break; |
| 288 | default: |
| 289 | break; |
| 290 | } |
| 291 | |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 292 | if (1.0f != scale) { |
| 293 | folder.appendf("_%.3f", scale); |
| 294 | } |
| 295 | |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 296 | CodecSrc* src = new CodecSrc(path, mode, dstColorType, dstAlphaType, scale); |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 297 | push_src("image", folder, src); |
| 298 | } |
| 299 | |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 300 | static void push_android_codec_src(Path path, AndroidCodecSrc::Mode mode, |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 301 | CodecSrc::DstColorType dstColorType, SkAlphaType dstAlphaType, int sampleSize) { |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 302 | SkString folder; |
| 303 | switch (mode) { |
| 304 | case AndroidCodecSrc::kFullImage_Mode: |
| 305 | folder.append("scaled_codec"); |
| 306 | break; |
| 307 | case AndroidCodecSrc::kDivisor_Mode: |
| 308 | folder.append("scaled_codec_divisor"); |
| 309 | break; |
| 310 | } |
| 311 | |
| 312 | switch (dstColorType) { |
| 313 | case CodecSrc::kGrayscale_Always_DstColorType: |
| 314 | folder.append("_kGray8"); |
| 315 | break; |
| 316 | case CodecSrc::kIndex8_Always_DstColorType: |
| 317 | folder.append("_kIndex8"); |
| 318 | break; |
| 319 | default: |
| 320 | break; |
| 321 | } |
| 322 | |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 323 | switch (dstAlphaType) { |
| 324 | case kOpaque_SkAlphaType: |
| 325 | folder.append("_opaque"); |
| 326 | break; |
| 327 | case kPremul_SkAlphaType: |
| 328 | folder.append("_premul"); |
| 329 | break; |
msarett | 9e9444c | 2016-02-03 12:39:10 -0800 | [diff] [blame] | 330 | case kUnpremul_SkAlphaType: |
| 331 | folder.append("_unpremul"); |
| 332 | break; |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 333 | default: |
| 334 | break; |
| 335 | } |
| 336 | |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 337 | if (1 != sampleSize) { |
msarett | 4b0778e | 2015-11-13 09:59:11 -0800 | [diff] [blame] | 338 | folder.appendf("_%.3f", 1.0f / (float) sampleSize); |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 339 | } |
| 340 | |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 341 | AndroidCodecSrc* src = new AndroidCodecSrc(path, mode, dstColorType, dstAlphaType, sampleSize); |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 342 | push_src("image", folder, src); |
| 343 | } |
| 344 | |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 345 | static void push_codec_srcs(Path path) { |
| 346 | SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); |
| 347 | if (!encoded) { |
| 348 | SkDebugf("Couldn't read %s.", path.c_str()); |
| 349 | return; |
| 350 | } |
| 351 | SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 352 | if (nullptr == codec.get()) { |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 353 | SkDebugf("Couldn't create codec for %s.", path.c_str()); |
| 354 | return; |
| 355 | } |
| 356 | |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 357 | // Native Scales |
msarett | 0a24297 | 2015-06-11 14:27:27 -0700 | [diff] [blame] | 358 | // TODO (msarett): Implement scaling tests for SkImageDecoder in order to compare with these |
| 359 | // tests. SkImageDecoder supports downscales by integer factors. |
emmaleer | 8f4ba76 | 2015-08-14 07:44:46 -0700 | [diff] [blame] | 360 | // SkJpegCodec natively supports scaling to: 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875 |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 361 | const float nativeScales[] = { 0.125f, 0.25f, 0.375f, 0.5f, 0.625f, 0.750f, 0.875f, 1.0f }; |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 362 | |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 363 | SkTArray<CodecSrc::Mode> nativeModes; |
| 364 | nativeModes.push_back(CodecSrc::kCodec_Mode); |
| 365 | nativeModes.push_back(CodecSrc::kCodecZeroInit_Mode); |
| 366 | nativeModes.push_back(CodecSrc::kGen_Mode); |
| 367 | switch (codec->getEncodedFormat()) { |
| 368 | case SkEncodedFormat::kJPEG_SkEncodedFormat: |
| 369 | nativeModes.push_back(CodecSrc::kScanline_Mode); |
| 370 | nativeModes.push_back(CodecSrc::kStripe_Mode); |
| 371 | nativeModes.push_back(CodecSrc::kCroppedScanline_Mode); |
| 372 | break; |
| 373 | case SkEncodedFormat::kWEBP_SkEncodedFormat: |
| 374 | nativeModes.push_back(CodecSrc::kSubset_Mode); |
| 375 | break; |
msarett | b65e604 | 2016-02-23 05:37:25 -0800 | [diff] [blame] | 376 | case SkEncodedFormat::kRAW_SkEncodedFormat: |
| 377 | break; |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 378 | default: |
| 379 | nativeModes.push_back(CodecSrc::kScanline_Mode); |
| 380 | nativeModes.push_back(CodecSrc::kStripe_Mode); |
| 381 | break; |
| 382 | } |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 383 | |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 384 | SkTArray<CodecSrc::DstColorType> colorTypes; |
| 385 | colorTypes.push_back(CodecSrc::kGetFromCanvas_DstColorType); |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 386 | switch (codec->getInfo().colorType()) { |
| 387 | case kGray_8_SkColorType: |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 388 | colorTypes.push_back(CodecSrc::kGrayscale_Always_DstColorType); |
msarett | 55f7bdd | 2016-02-16 13:24:54 -0800 | [diff] [blame] | 389 | if (kWBMP_SkEncodedFormat == codec->getEncodedFormat()) { |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 390 | colorTypes.push_back(CodecSrc::kIndex8_Always_DstColorType); |
msarett | 55f7bdd | 2016-02-16 13:24:54 -0800 | [diff] [blame] | 391 | } |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 392 | break; |
| 393 | case kIndex_8_SkColorType: |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 394 | colorTypes.push_back(CodecSrc::kIndex8_Always_DstColorType); |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 395 | break; |
| 396 | default: |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 397 | break; |
| 398 | } |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 399 | |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 400 | SkTArray<SkAlphaType> alphaModes; |
| 401 | alphaModes.push_back(kPremul_SkAlphaType); |
msarett | 9e9444c | 2016-02-03 12:39:10 -0800 | [diff] [blame] | 402 | alphaModes.push_back(kUnpremul_SkAlphaType); |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 403 | if (codec->getInfo().alphaType() == kOpaque_SkAlphaType) { |
| 404 | alphaModes.push_back(kOpaque_SkAlphaType); |
| 405 | } |
msarett | b714fb0 | 2016-01-22 14:46:42 -0800 | [diff] [blame] | 406 | |
| 407 | for (CodecSrc::Mode mode : nativeModes) { |
| 408 | // SkCodecImageGenerator only runs for the default colorType |
| 409 | // recommended by SkCodec. There is no need to generate multiple |
| 410 | // tests for different colorTypes. |
| 411 | // TODO (msarett): Add scaling support to SkCodecImageGenerator. |
| 412 | if (CodecSrc::kGen_Mode == mode) { |
| 413 | // FIXME: The gpu backend does not draw kGray sources correctly. (skbug.com/4822) |
| 414 | if (kGray_8_SkColorType != codec->getInfo().colorType()) { |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 415 | push_codec_src(path, mode, CodecSrc::kGetFromCanvas_DstColorType, |
| 416 | codec->getInfo().alphaType(), 1.0f); |
msarett | b714fb0 | 2016-01-22 14:46:42 -0800 | [diff] [blame] | 417 | } |
| 418 | continue; |
| 419 | } |
| 420 | |
| 421 | for (float scale : nativeScales) { |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 422 | for (CodecSrc::DstColorType colorType : colorTypes) { |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 423 | for (SkAlphaType alphaType : alphaModes) { |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 424 | // Only test kCroppedScanline_Mode when the alpha type is opaque. The test is |
| 425 | // slow and won't be interestingly different with different alpha types. |
| 426 | if (CodecSrc::kCroppedScanline_Mode == mode && |
| 427 | kOpaque_SkAlphaType != alphaType) { |
| 428 | continue; |
| 429 | } |
| 430 | |
| 431 | push_codec_src(path, mode, colorType, alphaType, scale); |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 432 | } |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 433 | } |
| 434 | } |
msarett | 0a24297 | 2015-06-11 14:27:27 -0700 | [diff] [blame] | 435 | } |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 436 | |
halcanary | 6950de6 | 2015-11-07 05:29:00 -0800 | [diff] [blame] | 437 | // https://bug.skia.org/4428 |
msarett | 33c7623 | 2015-11-16 13:43:40 -0800 | [diff] [blame] | 438 | bool subset = false; |
| 439 | // The following image types are supported by BitmapRegionDecoder, |
| 440 | // so we will test full image decodes and subset decodes. |
msarett | be8216a | 2015-12-04 08:00:50 -0800 | [diff] [blame] | 441 | static const char* const exts[] = { |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 442 | "jpg", "jpeg", "png", "webp", |
| 443 | "JPG", "JPEG", "PNG", "WEBP", |
| 444 | }; |
msarett | be8216a | 2015-12-04 08:00:50 -0800 | [diff] [blame] | 445 | for (const char* ext : exts) { |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 446 | if (path.endsWith(ext)) { |
msarett | 33c7623 | 2015-11-16 13:43:40 -0800 | [diff] [blame] | 447 | subset = true; |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 448 | break; |
| 449 | } |
| 450 | } |
msarett | 33c7623 | 2015-11-16 13:43:40 -0800 | [diff] [blame] | 451 | |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 452 | const int sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 453 | |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 454 | for (int sampleSize : sampleSizes) { |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 455 | for (CodecSrc::DstColorType colorType : colorTypes) { |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 456 | for (SkAlphaType alphaType : alphaModes) { |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 457 | push_android_codec_src(path, AndroidCodecSrc::kFullImage_Mode, colorType, |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 458 | alphaType, sampleSize); |
| 459 | if (subset) { |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 460 | push_android_codec_src(path, AndroidCodecSrc::kDivisor_Mode, colorType, |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 461 | alphaType, sampleSize); |
| 462 | } |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 463 | } |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 464 | } |
| 465 | } |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 466 | } |
| 467 | |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 468 | static bool brd_color_type_supported(SkBitmapRegionDecoder::Strategy strategy, |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 469 | CodecSrc::DstColorType dstColorType) { |
| 470 | switch (strategy) { |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 471 | case SkBitmapRegionDecoder::kCanvas_Strategy: |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 472 | if (CodecSrc::kGetFromCanvas_DstColorType == dstColorType) { |
| 473 | return true; |
| 474 | } |
| 475 | return false; |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 476 | case SkBitmapRegionDecoder::kAndroidCodec_Strategy: |
msarett | 26ad17b | 2015-10-22 07:29:19 -0700 | [diff] [blame] | 477 | switch (dstColorType) { |
| 478 | case CodecSrc::kGetFromCanvas_DstColorType: |
| 479 | case CodecSrc::kIndex8_Always_DstColorType: |
| 480 | case CodecSrc::kGrayscale_Always_DstColorType: |
| 481 | return true; |
| 482 | default: |
| 483 | return false; |
| 484 | } |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 485 | default: |
| 486 | SkASSERT(false); |
| 487 | return false; |
| 488 | } |
| 489 | } |
| 490 | |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 491 | static void push_brd_src(Path path, SkBitmapRegionDecoder::Strategy strategy, |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 492 | CodecSrc::DstColorType dstColorType, BRDSrc::Mode mode, uint32_t sampleSize) { |
| 493 | SkString folder; |
| 494 | switch (strategy) { |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 495 | case SkBitmapRegionDecoder::kCanvas_Strategy: |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 496 | folder.append("brd_canvas"); |
| 497 | break; |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 498 | case SkBitmapRegionDecoder::kAndroidCodec_Strategy: |
msarett | 26ad17b | 2015-10-22 07:29:19 -0700 | [diff] [blame] | 499 | folder.append("brd_android_codec"); |
| 500 | break; |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 501 | default: |
| 502 | SkASSERT(false); |
| 503 | return; |
| 504 | } |
| 505 | |
| 506 | switch (mode) { |
| 507 | case BRDSrc::kFullImage_Mode: |
| 508 | break; |
| 509 | case BRDSrc::kDivisor_Mode: |
| 510 | folder.append("_divisor"); |
| 511 | break; |
| 512 | default: |
| 513 | SkASSERT(false); |
| 514 | return; |
| 515 | } |
| 516 | |
| 517 | switch (dstColorType) { |
| 518 | case CodecSrc::kGetFromCanvas_DstColorType: |
| 519 | break; |
| 520 | case CodecSrc::kIndex8_Always_DstColorType: |
| 521 | folder.append("_kIndex"); |
| 522 | break; |
| 523 | case CodecSrc::kGrayscale_Always_DstColorType: |
| 524 | folder.append("_kGray"); |
| 525 | break; |
| 526 | default: |
| 527 | SkASSERT(false); |
| 528 | return; |
| 529 | } |
| 530 | |
| 531 | if (1 != sampleSize) { |
msarett | 4b0778e | 2015-11-13 09:59:11 -0800 | [diff] [blame] | 532 | folder.appendf("_%.3f", 1.0f / (float) sampleSize); |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | BRDSrc* src = new BRDSrc(path, strategy, mode, dstColorType, sampleSize); |
| 536 | push_src("image", folder, src); |
| 537 | } |
| 538 | |
| 539 | static void push_brd_srcs(Path path) { |
| 540 | |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 541 | const SkBitmapRegionDecoder::Strategy strategies[] = { |
| 542 | SkBitmapRegionDecoder::kCanvas_Strategy, |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 543 | SkBitmapRegionDecoder::kAndroidCodec_Strategy, |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 544 | }; |
| 545 | |
scroggo | 501b734 | 2015-11-03 07:55:11 -0800 | [diff] [blame] | 546 | // Test on a variety of sampleSizes, making sure to include: |
| 547 | // - 2, 4, and 8, which are natively supported by jpeg |
| 548 | // - multiples of 2 which are not divisible by 4 (analogous for 4) |
| 549 | // - larger powers of two, since BRD clients generally use powers of 2 |
| 550 | // We will only produce output for the larger sizes on large images. |
| 551 | 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] | 552 | |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 553 | // We will only test to one backend (8888), but we will test all of the |
| 554 | // color types that we need to decode to on this backend. |
| 555 | const CodecSrc::DstColorType dstColorTypes[] = { |
msarett | 26ad17b | 2015-10-22 07:29:19 -0700 | [diff] [blame] | 556 | CodecSrc::kGetFromCanvas_DstColorType, |
| 557 | CodecSrc::kIndex8_Always_DstColorType, |
| 558 | CodecSrc::kGrayscale_Always_DstColorType, |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 559 | }; |
| 560 | |
| 561 | const BRDSrc::Mode modes[] = { |
msarett | 26ad17b | 2015-10-22 07:29:19 -0700 | [diff] [blame] | 562 | BRDSrc::kFullImage_Mode, |
| 563 | BRDSrc::kDivisor_Mode, |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 564 | }; |
| 565 | |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 566 | for (SkBitmapRegionDecoder::Strategy strategy : strategies) { |
msarett | 6efbe05 | 2015-09-11 09:01:16 -0700 | [diff] [blame] | 567 | for (uint32_t sampleSize : sampleSizes) { |
msarett | 6efbe05 | 2015-09-11 09:01:16 -0700 | [diff] [blame] | 568 | for (CodecSrc::DstColorType dstColorType : dstColorTypes) { |
| 569 | if (brd_color_type_supported(strategy, dstColorType)) { |
| 570 | for (BRDSrc::Mode mode : modes) { |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 571 | push_brd_src(path, strategy, dstColorType, mode, sampleSize); |
| 572 | } |
| 573 | } |
| 574 | } |
| 575 | } |
| 576 | } |
| 577 | } |
| 578 | |
| 579 | static bool brd_supported(const char* ext) { |
msarett | 8c8f22a | 2015-04-01 06:58:48 -0700 | [diff] [blame] | 580 | static const char* const exts[] = { |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 581 | "jpg", "jpeg", "png", "webp", |
| 582 | "JPG", "JPEG", "PNG", "WEBP", |
msarett | 8c8f22a | 2015-04-01 06:58:48 -0700 | [diff] [blame] | 583 | }; |
| 584 | |
| 585 | for (uint32_t i = 0; i < SK_ARRAY_COUNT(exts); i++) { |
| 586 | if (0 == strcmp(exts[i], ext)) { |
| 587 | return true; |
| 588 | } |
| 589 | } |
| 590 | return false; |
scroggo | 9b77ddd | 2015-03-19 06:03:39 -0700 | [diff] [blame] | 591 | } |
| 592 | |
scroggo | 8673714 | 2016-02-03 12:19:11 -0800 | [diff] [blame] | 593 | static bool gather_srcs() { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 594 | for (const skiagm::GMRegistry* r = skiagm::GMRegistry::Head(); r; r = r->next()) { |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 595 | push_src("gm", "", new GMSrc(r->factory())); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 596 | } |
halcanary | fc37ad1 | 2015-01-30 07:31:19 -0800 | [diff] [blame] | 597 | for (int i = 0; i < FLAGS_skps.count(); i++) { |
| 598 | const char* path = FLAGS_skps[i]; |
| 599 | if (sk_isdir(path)) { |
| 600 | SkOSFile::Iter it(path, "skp"); |
| 601 | for (SkString file; it.next(&file); ) { |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 602 | push_src("skp", "", new SKPSrc(SkOSPath::Join(path, file.c_str()))); |
halcanary | fc37ad1 | 2015-01-30 07:31:19 -0800 | [diff] [blame] | 603 | } |
| 604 | } else { |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 605 | push_src("skp", "", new SKPSrc(path)); |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 606 | } |
| 607 | } |
scroggo | 8673714 | 2016-02-03 12:19:11 -0800 | [diff] [blame] | 608 | |
| 609 | SkTArray<SkString> images; |
| 610 | if (!CollectImages(&images)) { |
| 611 | return false; |
| 612 | } |
| 613 | |
| 614 | for (auto image : images) { |
| 615 | push_codec_srcs(image); |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 616 | const char* ext = strrchr(image.c_str(), '.'); |
| 617 | if (ext && brd_supported(ext+1)) { |
scroggo | 8673714 | 2016-02-03 12:19:11 -0800 | [diff] [blame] | 618 | push_brd_srcs(image); |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 619 | } |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 620 | } |
scroggo | 8673714 | 2016-02-03 12:19:11 -0800 | [diff] [blame] | 621 | |
| 622 | return true; |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 623 | } |
| 624 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 625 | static void push_sink(const SkCommandLineConfig& config, Sink* s) { |
rmistry | 0f515bd | 2015-12-22 10:22:26 -0800 | [diff] [blame] | 626 | SkAutoTDelete<Sink> sink(s); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 627 | |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 628 | // Try a simple Src as a canary. If it fails, skip this sink. |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 629 | struct : public Src { |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 630 | Error draw(SkCanvas* c) const override { |
| 631 | c->drawRect(SkRect::MakeWH(1,1), SkPaint()); |
| 632 | return ""; |
| 633 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 634 | SkISize size() const override { return SkISize::Make(16, 16); } |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 635 | Name name() const override { return "justOneRect"; } |
| 636 | } justOneRect; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 637 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 638 | SkBitmap bitmap; |
| 639 | SkDynamicMemoryWStream stream; |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 640 | SkString log; |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 641 | Error err = sink->draw(justOneRect, &bitmap, &stream, &log); |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 642 | if (err.isFatal()) { |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 643 | SkDebugf("Could not run %s: %s\n", config.getTag().c_str(), err.c_str()); |
mtklein | 05641a5 | 2015-04-21 10:49:13 -0700 | [diff] [blame] | 644 | exit(1); |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 645 | } |
| 646 | |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 647 | TaggedSink& ts = gSinks.push_back(); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 648 | ts.reset(sink.detach()); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 649 | ts.tag = config.getTag(); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | static bool gpu_supported() { |
| 653 | #if SK_SUPPORT_GPU |
| 654 | return FLAGS_gpu; |
| 655 | #else |
| 656 | return false; |
| 657 | #endif |
| 658 | } |
kkinnunen | 9ebc3f0 | 2015-12-21 23:48:13 -0800 | [diff] [blame] | 659 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 660 | static Sink* create_sink(const SkCommandLineConfig* config) { |
| 661 | #if SK_SUPPORT_GPU |
| 662 | if (gpu_supported()) { |
| 663 | if (const SkCommandLineConfigGpu* gpuConfig = config->asConfigGpu()) { |
| 664 | GrContextFactory::GLContextType contextType = gpuConfig->getContextType(); |
| 665 | GrContextFactory::GLContextOptions contextOptions = |
| 666 | GrContextFactory::kNone_GLContextOptions; |
| 667 | if (gpuConfig->getUseNVPR()) { |
| 668 | contextOptions = static_cast<GrContextFactory::GLContextOptions>( |
| 669 | contextOptions | GrContextFactory::kEnableNVPR_GLContextOptions); |
| 670 | } |
| 671 | GrContextFactory testFactory; |
| 672 | if (!testFactory.get(contextType, contextOptions)) { |
| 673 | SkDebugf("WARNING: can not create GPU context for config '%s'. " |
| 674 | "GM tests will be skipped.\n", gpuConfig->getTag().c_str()); |
| 675 | return nullptr; |
| 676 | } |
| 677 | return new GPUSink(contextType, contextOptions, gpuConfig->getSamples(), |
| 678 | gpuConfig->getUseDIText(), FLAGS_gpu_threading); |
| 679 | } |
| 680 | } |
| 681 | #endif |
| 682 | |
| 683 | #define SINK(t, sink, ...) if (config->getBackend().equals(t)) { return new sink(__VA_ARGS__); } |
| 684 | |
tomhudson | eebc39a | 2015-02-23 12:18:05 -0800 | [diff] [blame] | 685 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 686 | SINK("hwui", HWUISink); |
| 687 | #endif |
| 688 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 689 | if (FLAGS_cpu) { |
| 690 | SINK("565", RasterSink, kRGB_565_SkColorType); |
| 691 | SINK("8888", RasterSink, kN32_SkColorType); |
halcanary | c11c62f | 2015-09-28 11:51:54 -0700 | [diff] [blame] | 692 | SINK("pdf", PDFSink, "Pdfium"); |
| 693 | SINK("pdf_poppler", PDFSink, "Poppler"); |
mtklein | 9c3f17d | 2015-01-28 11:35:18 -0800 | [diff] [blame] | 694 | SINK("skp", SKPSink); |
mtklein | 8a4527e | 2015-01-31 20:00:58 -0800 | [diff] [blame] | 695 | SINK("svg", SVGSink); |
| 696 | SINK("null", NullSink); |
halcanary | 47ef4d5 | 2015-03-03 09:13:09 -0800 | [diff] [blame] | 697 | SINK("xps", XPSSink); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 698 | } |
| 699 | #undef SINK |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 700 | return nullptr; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 701 | } |
| 702 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 703 | static Sink* create_via(const SkString& tag, Sink* wrapped) { |
| 704 | #define VIA(t, via, ...) if (tag.equals(t)) { return new via(__VA_ARGS__); } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 705 | VIA("twice", ViaTwice, wrapped); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 706 | VIA("serialize", ViaSerialization, wrapped); |
mtklein | 4a34ecb | 2016-01-08 10:19:35 -0800 | [diff] [blame] | 707 | VIA("pic", ViaPicture, wrapped); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 708 | VIA("2ndpic", ViaSecondPicture, wrapped); |
mtklein | d31c13d | 2015-05-05 12:59:56 -0700 | [diff] [blame] | 709 | VIA("sp", ViaSingletonPictures, wrapped); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 710 | VIA("tiles", ViaTiles, 256, 256, nullptr, wrapped); |
mtklein | 7edca21 | 2015-01-21 13:18:51 -0800 | [diff] [blame] | 711 | VIA("tiles_rt", ViaTiles, 256, 256, new SkRTreeFactory, wrapped); |
mtklein | 2e2ea38 | 2015-10-16 10:29:41 -0700 | [diff] [blame] | 712 | VIA("remote", ViaRemote, false, wrapped); |
| 713 | VIA("remote_cache", ViaRemote, true, wrapped); |
halcanary | 7a76f9c | 2016-02-03 11:53:18 -0800 | [diff] [blame] | 714 | VIA("mojo", ViaMojo, wrapped); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 715 | |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 716 | if (FLAGS_matrix.count() == 4) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 717 | SkMatrix m; |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 718 | m.reset(); |
| 719 | m.setScaleX((SkScalar)atof(FLAGS_matrix[0])); |
| 720 | m.setSkewX ((SkScalar)atof(FLAGS_matrix[1])); |
| 721 | m.setSkewY ((SkScalar)atof(FLAGS_matrix[2])); |
| 722 | m.setScaleY((SkScalar)atof(FLAGS_matrix[3])); |
| 723 | VIA("matrix", ViaMatrix, m, wrapped); |
| 724 | VIA("upright", ViaUpright, m, wrapped); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 725 | } |
tomhudson | 64de1e1 | 2015-03-05 08:01:07 -0800 | [diff] [blame] | 726 | |
| 727 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 728 | VIA("androidsdk", ViaAndroidSDK, wrapped); |
| 729 | #endif |
| 730 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 731 | #undef VIA |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 732 | return nullptr; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 733 | } |
| 734 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 735 | static void gather_sinks() { |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 736 | SkCommandLineConfigArray configs; |
| 737 | ParseConfigs(FLAGS_config, &configs); |
| 738 | for (int i = 0; i < configs.count(); i++) { |
| 739 | const SkCommandLineConfig& config = *configs[i]; |
| 740 | Sink* sink = create_sink(&config); |
| 741 | if (sink == nullptr) { |
| 742 | SkDebugf("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(), |
| 743 | config.getTag().c_str()); |
| 744 | continue; |
| 745 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 746 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 747 | const SkTArray<SkString>& parts = config.getViaParts(); |
| 748 | for (int j = parts.count(); j-- > 0;) { |
| 749 | const SkString& part = parts[j]; |
| 750 | Sink* next = create_via(part, sink); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 751 | if (next == nullptr) { |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 752 | SkDebugf("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(), |
| 753 | part.c_str()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 754 | delete sink; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 755 | sink = nullptr; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 756 | break; |
| 757 | } |
| 758 | sink = next; |
| 759 | } |
| 760 | if (sink) { |
| 761 | push_sink(config, sink); |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 762 | } |
| 763 | } |
| 764 | } |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 765 | |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 766 | static bool dump_png(SkBitmap bitmap, const char* path, const char* md5) { |
| 767 | const int w = bitmap.width(), |
| 768 | h = bitmap.height(); |
| 769 | |
| 770 | // First get the bitmap into N32 color format. The next step will work only there. |
| 771 | if (bitmap.colorType() != kN32_SkColorType) { |
| 772 | SkBitmap n32; |
| 773 | if (!bitmap.copyTo(&n32, kN32_SkColorType)) { |
| 774 | return false; |
| 775 | } |
| 776 | bitmap = n32; |
| 777 | } |
| 778 | |
| 779 | // Convert our N32 bitmap into unpremul RGBA for libpng. |
| 780 | SkAutoTMalloc<uint32_t> rgba(w*h); |
| 781 | if (!bitmap.readPixels(SkImageInfo::Make(w,h, kRGBA_8888_SkColorType, kUnpremul_SkAlphaType), |
| 782 | rgba, 4*w, 0,0)) { |
| 783 | return false; |
| 784 | } |
| 785 | |
| 786 | // We don't need bitmap anymore. Might as well drop our ref. |
mtklein | fccb77d | 2015-08-24 14:13:29 -0700 | [diff] [blame] | 787 | bitmap.reset(); |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 788 | |
mtklein | c64137c | 2015-08-25 10:56:08 -0700 | [diff] [blame] | 789 | FILE* f = fopen(path, "wb"); |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 790 | if (!f) { return false; } |
| 791 | |
| 792 | png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr); |
| 793 | if (!png) { |
| 794 | fclose(f); |
| 795 | return false; |
| 796 | } |
| 797 | |
| 798 | png_infop info = png_create_info_struct(png); |
| 799 | if (!info) { |
| 800 | png_destroy_write_struct(&png, &info); |
| 801 | fclose(f); |
| 802 | return false; |
| 803 | } |
| 804 | |
mtklein | d69ece6 | 2015-09-10 10:37:44 -0700 | [diff] [blame] | 805 | SkString description; |
| 806 | description.append("Key: "); |
| 807 | for (int i = 0; i < FLAGS_key.count(); i++) { |
| 808 | description.appendf("%s ", FLAGS_key[i]); |
| 809 | } |
| 810 | description.append("Properties: "); |
| 811 | for (int i = 0; i < FLAGS_properties.count(); i++) { |
| 812 | description.appendf("%s ", FLAGS_properties[i]); |
| 813 | } |
| 814 | description.appendf("MD5: %s", md5); |
| 815 | |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 816 | png_text text[2]; |
| 817 | text[0].key = (png_charp)"Author"; |
| 818 | text[0].text = (png_charp)"DM dump_png()"; |
| 819 | text[0].compression = PNG_TEXT_COMPRESSION_NONE; |
| 820 | text[1].key = (png_charp)"Description"; |
mtklein | d69ece6 | 2015-09-10 10:37:44 -0700 | [diff] [blame] | 821 | text[1].text = (png_charp)description.c_str(); |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 822 | text[1].compression = PNG_TEXT_COMPRESSION_NONE; |
| 823 | png_set_text(png, info, text, 2); |
| 824 | |
| 825 | png_init_io(png, f); |
| 826 | png_set_IHDR(png, info, (png_uint_32)w, (png_uint_32)h, 8, |
| 827 | PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, |
| 828 | PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); |
| 829 | png_write_info(png, info); |
| 830 | for (int j = 0; j < h; j++) { |
| 831 | png_bytep row = (png_bytep)(rgba.get() + w*j); |
| 832 | png_write_rows(png, &row, 1); |
| 833 | } |
| 834 | png_write_end(png, info); |
| 835 | |
| 836 | png_destroy_write_struct(&png, &info); |
| 837 | fclose(f); |
| 838 | return true; |
| 839 | } |
| 840 | |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 841 | static bool match(const char* needle, const char* haystack) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 842 | return 0 == strcmp("_", needle) || nullptr != strstr(haystack, needle); |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 843 | } |
| 844 | |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame^] | 845 | static bool is_blacklisted(const char* sink, const char* src, |
| 846 | const char* srcOptions, const char* name) { |
mtklein | 0d243ff | 2015-04-03 07:51:00 -0700 | [diff] [blame] | 847 | for (int i = 0; i < FLAGS_blacklist.count() - 3; i += 4) { |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 848 | if (match(FLAGS_blacklist[i+0], sink) && |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 849 | match(FLAGS_blacklist[i+1], src) && |
| 850 | match(FLAGS_blacklist[i+2], srcOptions) && |
| 851 | match(FLAGS_blacklist[i+3], name)) { |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame^] | 852 | return true; |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 853 | } |
| 854 | } |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame^] | 855 | return false; |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 856 | } |
| 857 | |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 858 | // Even when a Task Sink reports to be non-threadsafe (e.g. GPU), we know things like |
| 859 | // .png encoding are definitely thread safe. This lets us offload that work to CPU threads. |
| 860 | static SkTaskGroup gDefinitelyThreadSafeWork; |
| 861 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 862 | // The finest-grained unit of work we can run: draw a single Src into a single Sink, |
| 863 | // report any errors, and perhaps write out the output: a .png of the bitmap, or a raw stream. |
| 864 | struct Task { |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 865 | Task(const TaggedSrc& src, const TaggedSink& sink) : src(src), sink(sink) {} |
| 866 | const TaggedSrc& src; |
| 867 | const TaggedSink& sink; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 868 | |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 869 | static void Run(const Task& task) { |
| 870 | SkString name = task.src->name(); |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 871 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 872 | SkString log; |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame^] | 873 | if (!FLAGS_dryRun) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 874 | SkBitmap bitmap; |
| 875 | SkDynamicMemoryWStream stream; |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame^] | 876 | start(task.sink.tag.c_str(), task.src.tag.c_str(), |
| 877 | task.src.options.c_str(), name.c_str()); |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 878 | Error err = task.sink->draw(*task.src, &bitmap, &stream, &log); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 879 | if (!err.isEmpty()) { |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 880 | if (err.isFatal()) { |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 881 | fail(SkStringPrintf("%s %s %s %s: %s", |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 882 | task.sink.tag.c_str(), |
| 883 | task.src.tag.c_str(), |
| 884 | task.src.options.c_str(), |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 885 | name.c_str(), |
| 886 | err.c_str())); |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 887 | } else { |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame^] | 888 | done(task.sink.tag.c_str(), task.src.tag.c_str(), |
| 889 | task.src.options.c_str(), name.c_str()); |
mtklein | ba6ada7 | 2016-01-21 09:39:35 -0800 | [diff] [blame] | 890 | return; |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 891 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 892 | } |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 893 | |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 894 | // We're likely switching threads here, so we must capture by value, [=] or [foo,bar]. |
| 895 | SkStreamAsset* data = stream.detachAsStream(); |
| 896 | gDefinitelyThreadSafeWork.add([task,name,bitmap,data]{ |
| 897 | SkAutoTDelete<SkStreamAsset> ownedData(data); |
| 898 | |
| 899 | // Why doesn't the copy constructor do this when we have pre-locked pixels? |
| 900 | bitmap.lockPixels(); |
| 901 | |
| 902 | SkString md5; |
| 903 | if (!FLAGS_writePath.isEmpty() || !FLAGS_readPath.isEmpty()) { |
| 904 | SkMD5 hash; |
| 905 | if (data->getLength()) { |
| 906 | hash.writeStream(data, data->getLength()); |
| 907 | data->rewind(); |
mtklein | 3840846 | 2015-07-08 07:25:27 -0700 | [diff] [blame] | 908 | } else { |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 909 | // If we're BGRA (Linux, Windows), swizzle over to RGBA (Mac, Android). |
| 910 | // This helps eliminate multiple 0-pixel-diff hashes on gold.skia.org. |
| 911 | // (Android's general slow speed breaks the tie arbitrarily in RGBA's favor.) |
| 912 | // We might consider promoting 565 to RGBA too. |
| 913 | if (bitmap.colorType() == kBGRA_8888_SkColorType) { |
| 914 | SkBitmap swizzle; |
| 915 | SkAssertResult(bitmap.copyTo(&swizzle, kRGBA_8888_SkColorType)); |
| 916 | hash.write(swizzle.getPixels(), swizzle.getSize()); |
| 917 | } else { |
| 918 | hash.write(bitmap.getPixels(), bitmap.getSize()); |
| 919 | } |
| 920 | } |
| 921 | SkMD5::Digest digest; |
| 922 | hash.finish(digest); |
| 923 | for (int i = 0; i < 16; i++) { |
| 924 | md5.appendf("%02x", digest.data[i]); |
mtklein | 3840846 | 2015-07-08 07:25:27 -0700 | [diff] [blame] | 925 | } |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 926 | } |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 927 | |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 928 | if (!FLAGS_readPath.isEmpty() && |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame^] | 929 | !gGold.contains(Gold(task.sink.tag, task.src.tag, |
| 930 | task.src.options, name, md5))) { |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 931 | fail(SkStringPrintf("%s not found for %s %s %s %s in %s", |
| 932 | md5.c_str(), |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 933 | task.sink.tag.c_str(), |
| 934 | task.src.tag.c_str(), |
| 935 | task.src.options.c_str(), |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 936 | name.c_str(), |
| 937 | FLAGS_readPath[0])); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 938 | } |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 939 | |
| 940 | if (!FLAGS_writePath.isEmpty()) { |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 941 | const char* ext = task.sink->fileExtension(); |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 942 | if (data->getLength()) { |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 943 | WriteToDisk(task, md5, ext, data, data->getLength(), nullptr); |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 944 | SkASSERT(bitmap.drawsNothing()); |
| 945 | } else if (!bitmap.drawsNothing()) { |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 946 | WriteToDisk(task, md5, ext, nullptr, 0, &bitmap); |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 947 | } |
| 948 | } |
| 949 | }); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 950 | } |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame^] | 951 | 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] | 952 | } |
| 953 | |
| 954 | static void WriteToDisk(const Task& task, |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 955 | SkString md5, |
| 956 | const char* ext, |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 957 | SkStream* data, size_t len, |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 958 | const SkBitmap* bitmap) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 959 | JsonWriter::BitmapResult result; |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 960 | result.name = task.src->name(); |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame^] | 961 | result.config = task.sink.tag; |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 962 | result.sourceType = task.src.tag; |
| 963 | result.sourceOptions = task.src.options; |
| 964 | result.ext = ext; |
| 965 | result.md5 = md5; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 966 | JsonWriter::AddBitmapResult(result); |
| 967 | |
mtklein | b0531a7 | 2015-04-07 13:38:48 -0700 | [diff] [blame] | 968 | // If an MD5 is uninteresting, we want it noted in the JSON file, |
| 969 | // but don't want to dump it out as a .png (or whatever ext is). |
| 970 | if (gUninterestingHashes.contains(md5)) { |
| 971 | return; |
| 972 | } |
| 973 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 974 | const char* dir = FLAGS_writePath[0]; |
| 975 | if (0 == strcmp(dir, "@")) { // Needed for iOS. |
| 976 | dir = FLAGS_resourcePath[0]; |
| 977 | } |
| 978 | sk_mkdir(dir); |
| 979 | |
| 980 | SkString path; |
| 981 | if (FLAGS_nameByHash) { |
| 982 | path = SkOSPath::Join(dir, result.md5.c_str()); |
| 983 | path.append("."); |
| 984 | path.append(ext); |
| 985 | if (sk_exists(path.c_str())) { |
| 986 | return; // Content-addressed. If it exists already, we're done. |
| 987 | } |
| 988 | } else { |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 989 | path = SkOSPath::Join(dir, task.sink.tag.c_str()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 990 | sk_mkdir(path.c_str()); |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 991 | path = SkOSPath::Join(path.c_str(), task.src.tag.c_str()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 992 | sk_mkdir(path.c_str()); |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 993 | if (strcmp(task.src.options.c_str(), "") != 0) { |
| 994 | path = SkOSPath::Join(path.c_str(), task.src.options.c_str()); |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 995 | sk_mkdir(path.c_str()); |
| 996 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 997 | path = SkOSPath::Join(path.c_str(), task.src->name().c_str()); |
| 998 | path.append("."); |
| 999 | path.append(ext); |
| 1000 | } |
| 1001 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1002 | if (bitmap) { |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 1003 | if (!dump_png(*bitmap, path.c_str(), result.md5.c_str())) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1004 | fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str())); |
| 1005 | return; |
| 1006 | } |
| 1007 | } else { |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 1008 | SkFILEWStream file(path.c_str()); |
| 1009 | if (!file.isValid()) { |
| 1010 | fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str())); |
| 1011 | return; |
| 1012 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1013 | if (!file.writeStream(data, len)) { |
| 1014 | fail(SkStringPrintf("Can't write to %s.\n", path.c_str())); |
| 1015 | return; |
| 1016 | } |
| 1017 | } |
| 1018 | } |
| 1019 | }; |
| 1020 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1021 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 1022 | |
| 1023 | // Unit tests don't fit so well into the Src/Sink model, so we give them special treatment. |
| 1024 | |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1025 | static SkTDArray<skiatest::Test> gParallelTests, gSerialTests; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1026 | |
| 1027 | static void gather_tests() { |
mtklein | 6c5fed2 | 2015-01-20 13:47:23 -0800 | [diff] [blame] | 1028 | if (!FLAGS_src.contains("tests")) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1029 | return; |
| 1030 | } |
mtklein | 6393c06 | 2015-04-27 08:45:01 -0700 | [diff] [blame] | 1031 | for (const skiatest::TestRegistry* r = skiatest::TestRegistry::Head(); r; r = r->next()) { |
| 1032 | if (!in_shard()) { |
| 1033 | continue; |
| 1034 | } |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1035 | // Despite its name, factory() is returning a reference to |
| 1036 | // link-time static const POD data. |
| 1037 | const skiatest::Test& test = r->factory(); |
| 1038 | if (SkCommandLineFlags::ShouldSkip(FLAGS_match, test.name)) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1039 | continue; |
| 1040 | } |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1041 | if (test.needsGpu && gpu_supported()) { |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1042 | (FLAGS_gpu_threading ? gParallelTests : gSerialTests).push(test); |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1043 | } else if (!test.needsGpu && FLAGS_cpu) { |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1044 | gParallelTests.push(test); |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 1045 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1046 | } |
| 1047 | } |
| 1048 | |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1049 | static void run_test(skiatest::Test test) { |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1050 | struct : public skiatest::Reporter { |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 1051 | void reportFailed(const skiatest::Failure& failure) override { |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1052 | fail(failure.toString()); |
| 1053 | JsonWriter::AddTestFailure(failure); |
| 1054 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 1055 | bool allowExtendedTest() const override { |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1056 | return FLAGS_pathOpsExtended; |
| 1057 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 1058 | bool verbose() const override { return FLAGS_veryVerbose; } |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1059 | } reporter; |
djsollen | 824996a | 2015-06-12 12:06:22 -0700 | [diff] [blame] | 1060 | |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame^] | 1061 | if (!FLAGS_dryRun && !is_blacklisted("_", "tests", "_", test.name)) { |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1062 | start("unit", "test", "", test.name); |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 1063 | GrContextFactory factory; |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1064 | test.proc(&reporter, &factory); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1065 | } |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame^] | 1066 | done("unit", "test", "", test.name); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1067 | } |
| 1068 | |
| 1069 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 1070 | |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 1071 | DEFINE_int32(status_sec, 15, "Print status this often (and if we crash)."); |
| 1072 | |
| 1073 | SkThread* start_status_thread() { |
| 1074 | auto thread = new SkThread([] (void*) { |
| 1075 | for (;;) { |
| 1076 | print_status(); |
| 1077 | #if defined(SK_BUILD_FOR_WIN) |
| 1078 | Sleep(FLAGS_status_sec * 1000); |
| 1079 | #else |
| 1080 | sleep(FLAGS_status_sec); |
| 1081 | #endif |
mtklein | 2e1c47e | 2015-03-12 07:16:56 -0700 | [diff] [blame] | 1082 | } |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 1083 | }); |
| 1084 | thread->start(); |
| 1085 | return thread; |
mtklein | de6fc2b | 2015-03-12 06:28:54 -0700 | [diff] [blame] | 1086 | } |
| 1087 | |
caryclark | 83ca628 | 2015-06-10 09:31:09 -0700 | [diff] [blame] | 1088 | #define PORTABLE_FONT_PREFIX "Toy Liberation " |
| 1089 | |
| 1090 | static SkTypeface* create_from_name(const char familyName[], SkTypeface::Style style) { |
| 1091 | if (familyName && strlen(familyName) > sizeof(PORTABLE_FONT_PREFIX) |
| 1092 | && !strncmp(familyName, PORTABLE_FONT_PREFIX, sizeof(PORTABLE_FONT_PREFIX) - 1)) { |
caryclark | 1818acb | 2015-07-24 12:09:25 -0700 | [diff] [blame] | 1093 | return sk_tool_utils::create_portable_typeface(familyName, style); |
caryclark | 83ca628 | 2015-06-10 09:31:09 -0700 | [diff] [blame] | 1094 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1095 | return nullptr; |
caryclark | 83ca628 | 2015-06-10 09:31:09 -0700 | [diff] [blame] | 1096 | } |
| 1097 | |
| 1098 | #undef PORTABLE_FONT_PREFIX |
| 1099 | |
| 1100 | extern SkTypeface* (*gCreateTypefaceDelegate)(const char [], SkTypeface::Style ); |
| 1101 | |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 1102 | int dm_main(); |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 1103 | int dm_main() { |
mtklein | 246ba3a | 2016-02-23 10:39:36 -0800 | [diff] [blame] | 1104 | setup_crash_handler(); |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 1105 | |
mtklein | 5286f02 | 2016-01-22 08:18:14 -0800 | [diff] [blame] | 1106 | 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] | 1107 | SkAutoGraphics ag; |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 1108 | SkTaskGroup::Enabler enabled(FLAGS_threads); |
caryclark | 83ca628 | 2015-06-10 09:31:09 -0700 | [diff] [blame] | 1109 | gCreateTypefaceDelegate = &create_from_name; |
commit-bot@chromium.org | a65e2fd | 2014-05-30 17:23:31 +0000 | [diff] [blame] | 1110 | |
halcanary | 7d57124 | 2016-02-24 17:59:16 -0800 | [diff] [blame] | 1111 | { |
| 1112 | SkString testResourcePath = GetResourcePath("color_wheel.png"); |
| 1113 | SkFILEStream testResource(testResourcePath.c_str()); |
| 1114 | if (!testResource.isValid()) { |
| 1115 | SkDebugf("Some resources are missing. Do you need to set --resourcePath?\n"); |
| 1116 | } |
| 1117 | } |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 1118 | gather_gold(); |
borenet | 09ed480 | 2015-04-03 14:15:33 -0700 | [diff] [blame] | 1119 | gather_uninteresting_hashes(); |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 1120 | |
scroggo | 8673714 | 2016-02-03 12:19:11 -0800 | [diff] [blame] | 1121 | if (!gather_srcs()) { |
| 1122 | return 1; |
| 1123 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1124 | gather_sinks(); |
| 1125 | gather_tests(); |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 1126 | |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1127 | gPending = gSrcs.count() * gSinks.count() + gParallelTests.count() + gSerialTests.count(); |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 1128 | SkDebugf("%d srcs * %d sinks + %d tests == %d tasks", |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1129 | gSrcs.count(), gSinks.count(), gParallelTests.count() + gSerialTests.count(), gPending); |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 1130 | SkAutoTDelete<SkThread> statusThread(start_status_thread()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1131 | |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1132 | // Kick off as much parallel work as we can, making note of any serial work we'll need to do. |
| 1133 | SkTaskGroup parallel; |
| 1134 | SkTArray<Task> serial; |
| 1135 | |
| 1136 | for (auto& sink : gSinks) |
| 1137 | for (auto& src : gSrcs) { |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame^] | 1138 | if (src->veto(sink->flags()) || |
| 1139 | is_blacklisted(sink.tag.c_str(), src.tag.c_str(), |
| 1140 | src.options.c_str(), src->name().c_str())) { |
| 1141 | SkAutoTAcquire<SkPODSpinlock> lock(gMutex); |
| 1142 | gPending--; |
| 1143 | continue; |
| 1144 | } |
| 1145 | |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1146 | Task task(src, sink); |
| 1147 | if (src->serial() || sink->serial()) { |
| 1148 | serial.push_back(task); |
| 1149 | } else { |
| 1150 | parallel.add([task] { Task::Run(task); }); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1151 | } |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 1152 | } |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1153 | for (auto test : gParallelTests) { |
| 1154 | parallel.add([test] { run_test(test); }); |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 1155 | } |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1156 | |
| 1157 | // With the parallel work running, run serial tasks and tests here on main thread. |
| 1158 | for (auto task : serial) { Task::Run(task); } |
| 1159 | for (auto test : gSerialTests) { run_test(test); } |
| 1160 | |
| 1161 | // Wait for any remaining parallel work to complete (including any spun off of serial tasks). |
| 1162 | parallel.wait(); |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1163 | gDefinitelyThreadSafeWork.wait(); |
| 1164 | |
mtklein | da884c4 | 2016-02-24 18:00:23 -0800 | [diff] [blame] | 1165 | // We'd better have run everything. |
| 1166 | SkASSERT(gPending == 0); |
| 1167 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1168 | // At this point we're back in single-threaded land. |
caryclark | f53ce80 | 2015-06-15 06:48:30 -0700 | [diff] [blame] | 1169 | sk_tool_utils::release_portable_typefaces(); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 1170 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1171 | if (gFailures.count() > 0) { |
| 1172 | SkDebugf("Failures:\n"); |
| 1173 | for (int i = 0; i < gFailures.count(); i++) { |
mtklein | 9dc0910 | 2015-01-15 15:47:33 -0800 | [diff] [blame] | 1174 | SkDebugf("\t%s\n", gFailures[i].c_str()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1175 | } |
| 1176 | SkDebugf("%d failures\n", gFailures.count()); |
| 1177 | return 1; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 1178 | } |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 1179 | |
| 1180 | #ifdef SK_PDF_IMAGE_STATS |
halcanary | 7a14b31 | 2015-10-01 07:28:13 -0700 | [diff] [blame] | 1181 | SkPDFImageDumpStats(); |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 1182 | #endif // SK_PDF_IMAGE_STATS |
| 1183 | |
| 1184 | print_status(); |
scroggo | 4d9eaea | 2016-01-29 07:48:33 -0800 | [diff] [blame] | 1185 | SkDebugf("Finished!\n"); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1186 | return 0; |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 1187 | } |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 1188 | |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1189 | // TODO: currently many GPU tests are declared outside SK_SUPPORT_GPU guards. |
| 1190 | // Thus we export the empty RunWithGPUTestContexts when SK_SUPPORT_GPU=0. |
| 1191 | namespace skiatest { |
| 1192 | namespace { |
| 1193 | typedef void(*TestWithGrContext)(skiatest::Reporter*, GrContext*); |
| 1194 | typedef void(*TestWithGrContextAndGLContext)(skiatest::Reporter*, GrContext*, SkGLContext*); |
| 1195 | #if SK_SUPPORT_GPU |
| 1196 | template<typename T> |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 1197 | void call_test(T test, skiatest::Reporter* reporter, const GrContextFactory::ContextInfo& context); |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1198 | template<> |
| 1199 | void call_test(TestWithGrContext test, skiatest::Reporter* reporter, |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 1200 | const GrContextFactory::ContextInfo& context) { |
| 1201 | test(reporter, context.fGrContext); |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1202 | } |
| 1203 | template<> |
| 1204 | void call_test(TestWithGrContextAndGLContext test, skiatest::Reporter* reporter, |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 1205 | const GrContextFactory::ContextInfo& context) { |
| 1206 | test(reporter, context.fGrContext, context.fGLContext); |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1207 | } |
| 1208 | #endif |
| 1209 | } // namespace |
| 1210 | |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1211 | template<typename T> |
| 1212 | void RunWithGPUTestContexts(T test, GPUTestContexts testContexts, Reporter* reporter, |
| 1213 | GrContextFactory* factory) { |
| 1214 | #if SK_SUPPORT_GPU |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 1215 | // Iterate over context types, except use "native" instead of explicitly trying OpenGL and |
| 1216 | // OpenGL ES. Do not use GLES on desktop, since tests do not account for not fixing |
| 1217 | // http://skbug.com/2809 |
| 1218 | GrContextFactory::GLContextType contextTypes[] = { |
| 1219 | GrContextFactory::kNative_GLContextType, |
| 1220 | #if SK_ANGLE |
| 1221 | #ifdef SK_BUILD_FOR_WIN |
| 1222 | GrContextFactory::kANGLE_GLContextType, |
| 1223 | #endif |
| 1224 | GrContextFactory::kANGLE_GL_GLContextType, |
| 1225 | #endif |
| 1226 | #if SK_COMMAND_BUFFER |
| 1227 | GrContextFactory::kCommandBuffer_GLContextType, |
| 1228 | #endif |
| 1229 | #if SK_MESA |
| 1230 | GrContextFactory::kMESA_GLContextType, |
| 1231 | #endif |
| 1232 | GrContextFactory::kNull_GLContextType, |
| 1233 | GrContextFactory::kDebug_GLContextType, |
| 1234 | }; |
| 1235 | static_assert(SK_ARRAY_COUNT(contextTypes) == GrContextFactory::kGLContextTypeCnt - 2, |
| 1236 | "Skipping unexpected GLContextType for GPU tests"); |
| 1237 | |
| 1238 | for (auto& contextType : contextTypes) { |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1239 | int contextSelector = kNone_GPUTestContexts; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 1240 | if (GrContextFactory::IsRenderingGLContext(contextType)) { |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1241 | contextSelector |= kAllRendering_GPUTestContexts; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 1242 | } else if (contextType == GrContextFactory::kNative_GLContextType) { |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1243 | contextSelector |= kNative_GPUTestContexts; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 1244 | } else if (contextType == GrContextFactory::kNull_GLContextType) { |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1245 | contextSelector |= kNull_GPUTestContexts; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 1246 | } else if (contextType == GrContextFactory::kDebug_GLContextType) { |
kkinnunen | 55eeae9 | 2015-12-10 23:19:29 -0800 | [diff] [blame] | 1247 | contextSelector |= kDebug_GPUTestContexts; |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1248 | } |
| 1249 | if ((testContexts & contextSelector) == 0) { |
| 1250 | continue; |
| 1251 | } |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 1252 | GrContextFactory::ContextInfo context = factory->getContextInfo(contextType); |
| 1253 | if (context.fGrContext) { |
kkinnunen | 5219fd9 | 2015-12-10 06:28:13 -0800 | [diff] [blame] | 1254 | call_test(test, reporter, context); |
| 1255 | } |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 1256 | context = factory->getContextInfo(contextType, |
| 1257 | GrContextFactory::kEnableNVPR_GLContextOptions); |
| 1258 | if (context.fGrContext) { |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1259 | call_test(test, reporter, context); |
| 1260 | } |
| 1261 | } |
| 1262 | #endif |
| 1263 | } |
| 1264 | |
| 1265 | template |
| 1266 | void RunWithGPUTestContexts<TestWithGrContext>(TestWithGrContext test, |
| 1267 | GPUTestContexts testContexts, |
| 1268 | Reporter* reporter, |
| 1269 | GrContextFactory* factory); |
| 1270 | template |
| 1271 | void RunWithGPUTestContexts<TestWithGrContextAndGLContext>(TestWithGrContextAndGLContext test, |
| 1272 | GPUTestContexts testContexts, |
| 1273 | Reporter* reporter, |
| 1274 | GrContextFactory* factory); |
| 1275 | } // namespace skiatest |
| 1276 | |
borenet | 4808757 | 2015-04-02 12:16:36 -0700 | [diff] [blame] | 1277 | #if !defined(SK_BUILD_FOR_IOS) |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 1278 | int main(int argc, char** argv) { |
| 1279 | SkCommandLineFlags::Parse(argc, argv); |
| 1280 | return dm_main(); |
| 1281 | } |
| 1282 | #endif |