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