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; |
msarett | 9e9444c | 2016-02-03 12:39:10 -0800 | [diff] [blame] | 316 | case kUnpremul_SkAlphaType: |
| 317 | folder.append("_unpremul"); |
| 318 | break; |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 319 | default: |
| 320 | break; |
| 321 | } |
| 322 | |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 323 | if (1 != sampleSize) { |
msarett | 4b0778e | 2015-11-13 09:59:11 -0800 | [diff] [blame] | 324 | folder.appendf("_%.3f", 1.0f / (float) sampleSize); |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 325 | } |
| 326 | |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 327 | AndroidCodecSrc* src = new AndroidCodecSrc(path, mode, dstColorType, dstAlphaType, sampleSize); |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 328 | push_src("image", folder, src); |
| 329 | } |
| 330 | |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 331 | static void push_codec_srcs(Path path) { |
| 332 | SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); |
| 333 | if (!encoded) { |
| 334 | SkDebugf("Couldn't read %s.", path.c_str()); |
| 335 | return; |
| 336 | } |
| 337 | SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 338 | if (nullptr == codec.get()) { |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 339 | SkDebugf("Couldn't create codec for %s.", path.c_str()); |
| 340 | return; |
| 341 | } |
| 342 | |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 343 | // Native Scales |
msarett | 0a24297 | 2015-06-11 14:27:27 -0700 | [diff] [blame] | 344 | // TODO (msarett): Implement scaling tests for SkImageDecoder in order to compare with these |
| 345 | // tests. SkImageDecoder supports downscales by integer factors. |
emmaleer | 8f4ba76 | 2015-08-14 07:44:46 -0700 | [diff] [blame] | 346 | // 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] | 347 | 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] | 348 | |
msarett | bb25b53 | 2016-01-13 09:31:39 -0800 | [diff] [blame] | 349 | const CodecSrc::Mode nativeModes[] = { CodecSrc::kCodec_Mode, CodecSrc::kCodecZeroInit_Mode, |
msarett | b714fb0 | 2016-01-22 14:46:42 -0800 | [diff] [blame] | 350 | CodecSrc::kScanline_Mode, CodecSrc::kStripe_Mode, CodecSrc::kSubset_Mode, |
| 351 | CodecSrc::kGen_Mode }; |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 352 | |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 353 | CodecSrc::DstColorType colorTypes[3]; |
| 354 | uint32_t numColorTypes; |
| 355 | switch (codec->getInfo().colorType()) { |
| 356 | case kGray_8_SkColorType: |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 357 | colorTypes[0] = CodecSrc::kGetFromCanvas_DstColorType; |
| 358 | colorTypes[1] = CodecSrc::kGrayscale_Always_DstColorType; |
msarett | 55f7bdd | 2016-02-16 13:24:54 -0800 | [diff] [blame] | 359 | if (kWBMP_SkEncodedFormat == codec->getEncodedFormat()) { |
| 360 | colorTypes[2] = CodecSrc::kIndex8_Always_DstColorType; |
| 361 | numColorTypes = 3; |
| 362 | } else { |
| 363 | numColorTypes = 2; |
| 364 | } |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 365 | break; |
| 366 | case kIndex_8_SkColorType: |
| 367 | colorTypes[0] = CodecSrc::kGetFromCanvas_DstColorType; |
| 368 | colorTypes[1] = CodecSrc::kIndex8_Always_DstColorType; |
| 369 | numColorTypes = 2; |
| 370 | break; |
| 371 | default: |
| 372 | colorTypes[0] = CodecSrc::kGetFromCanvas_DstColorType; |
| 373 | numColorTypes = 1; |
| 374 | break; |
| 375 | } |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 376 | |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 377 | SkTArray<SkAlphaType> alphaModes; |
| 378 | alphaModes.push_back(kPremul_SkAlphaType); |
msarett | 9e9444c | 2016-02-03 12:39:10 -0800 | [diff] [blame] | 379 | alphaModes.push_back(kUnpremul_SkAlphaType); |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 380 | if (codec->getInfo().alphaType() == kOpaque_SkAlphaType) { |
| 381 | alphaModes.push_back(kOpaque_SkAlphaType); |
| 382 | } |
msarett | b714fb0 | 2016-01-22 14:46:42 -0800 | [diff] [blame] | 383 | |
| 384 | for (CodecSrc::Mode mode : nativeModes) { |
| 385 | // SkCodecImageGenerator only runs for the default colorType |
| 386 | // recommended by SkCodec. There is no need to generate multiple |
| 387 | // tests for different colorTypes. |
| 388 | // TODO (msarett): Add scaling support to SkCodecImageGenerator. |
| 389 | if (CodecSrc::kGen_Mode == mode) { |
| 390 | // FIXME: The gpu backend does not draw kGray sources correctly. (skbug.com/4822) |
| 391 | if (kGray_8_SkColorType != codec->getInfo().colorType()) { |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 392 | push_codec_src(path, mode, CodecSrc::kGetFromCanvas_DstColorType, |
| 393 | codec->getInfo().alphaType(), 1.0f); |
msarett | b714fb0 | 2016-01-22 14:46:42 -0800 | [diff] [blame] | 394 | } |
| 395 | continue; |
| 396 | } |
| 397 | |
| 398 | for (float scale : nativeScales) { |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 399 | for (uint32_t i = 0; i < numColorTypes; i++) { |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 400 | for (SkAlphaType alphaType : alphaModes) { |
| 401 | push_codec_src(path, mode, colorTypes[i], alphaType, scale); |
| 402 | } |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 403 | } |
| 404 | } |
msarett | 0a24297 | 2015-06-11 14:27:27 -0700 | [diff] [blame] | 405 | } |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 406 | |
halcanary | 6950de6 | 2015-11-07 05:29:00 -0800 | [diff] [blame] | 407 | // https://bug.skia.org/4428 |
msarett | 33c7623 | 2015-11-16 13:43:40 -0800 | [diff] [blame] | 408 | bool subset = false; |
| 409 | // The following image types are supported by BitmapRegionDecoder, |
| 410 | // so we will test full image decodes and subset decodes. |
msarett | be8216a | 2015-12-04 08:00:50 -0800 | [diff] [blame] | 411 | static const char* const exts[] = { |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 412 | "jpg", "jpeg", "png", "webp", |
| 413 | "JPG", "JPEG", "PNG", "WEBP", |
| 414 | }; |
msarett | be8216a | 2015-12-04 08:00:50 -0800 | [diff] [blame] | 415 | for (const char* ext : exts) { |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 416 | if (path.endsWith(ext)) { |
msarett | 33c7623 | 2015-11-16 13:43:40 -0800 | [diff] [blame] | 417 | subset = true; |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 418 | break; |
| 419 | } |
| 420 | } |
msarett | 33c7623 | 2015-11-16 13:43:40 -0800 | [diff] [blame] | 421 | |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 422 | const int sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 423 | |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 424 | for (int sampleSize : sampleSizes) { |
msarett | 33c7623 | 2015-11-16 13:43:40 -0800 | [diff] [blame] | 425 | for (uint32_t i = 0; i < numColorTypes; i++) { |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 426 | for (SkAlphaType alphaType : alphaModes) { |
| 427 | push_android_codec_src(path, AndroidCodecSrc::kFullImage_Mode, colorTypes[i], |
| 428 | alphaType, sampleSize); |
| 429 | if (subset) { |
| 430 | push_android_codec_src(path, AndroidCodecSrc::kDivisor_Mode, colorTypes[i], |
| 431 | alphaType, sampleSize); |
| 432 | } |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 433 | } |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 434 | } |
| 435 | } |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 436 | } |
| 437 | |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 438 | static bool brd_color_type_supported(SkBitmapRegionDecoder::Strategy strategy, |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 439 | CodecSrc::DstColorType dstColorType) { |
| 440 | switch (strategy) { |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 441 | case SkBitmapRegionDecoder::kCanvas_Strategy: |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 442 | if (CodecSrc::kGetFromCanvas_DstColorType == dstColorType) { |
| 443 | return true; |
| 444 | } |
| 445 | return false; |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 446 | case SkBitmapRegionDecoder::kAndroidCodec_Strategy: |
msarett | 26ad17b | 2015-10-22 07:29:19 -0700 | [diff] [blame] | 447 | switch (dstColorType) { |
| 448 | case CodecSrc::kGetFromCanvas_DstColorType: |
| 449 | case CodecSrc::kIndex8_Always_DstColorType: |
| 450 | case CodecSrc::kGrayscale_Always_DstColorType: |
| 451 | return true; |
| 452 | default: |
| 453 | return false; |
| 454 | } |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 455 | default: |
| 456 | SkASSERT(false); |
| 457 | return false; |
| 458 | } |
| 459 | } |
| 460 | |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 461 | static void push_brd_src(Path path, SkBitmapRegionDecoder::Strategy strategy, |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 462 | CodecSrc::DstColorType dstColorType, BRDSrc::Mode mode, uint32_t sampleSize) { |
| 463 | SkString folder; |
| 464 | switch (strategy) { |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 465 | case SkBitmapRegionDecoder::kCanvas_Strategy: |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 466 | folder.append("brd_canvas"); |
| 467 | break; |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 468 | case SkBitmapRegionDecoder::kAndroidCodec_Strategy: |
msarett | 26ad17b | 2015-10-22 07:29:19 -0700 | [diff] [blame] | 469 | folder.append("brd_android_codec"); |
| 470 | break; |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 471 | default: |
| 472 | SkASSERT(false); |
| 473 | return; |
| 474 | } |
| 475 | |
| 476 | switch (mode) { |
| 477 | case BRDSrc::kFullImage_Mode: |
| 478 | break; |
| 479 | case BRDSrc::kDivisor_Mode: |
| 480 | folder.append("_divisor"); |
| 481 | break; |
| 482 | default: |
| 483 | SkASSERT(false); |
| 484 | return; |
| 485 | } |
| 486 | |
| 487 | switch (dstColorType) { |
| 488 | case CodecSrc::kGetFromCanvas_DstColorType: |
| 489 | break; |
| 490 | case CodecSrc::kIndex8_Always_DstColorType: |
| 491 | folder.append("_kIndex"); |
| 492 | break; |
| 493 | case CodecSrc::kGrayscale_Always_DstColorType: |
| 494 | folder.append("_kGray"); |
| 495 | break; |
| 496 | default: |
| 497 | SkASSERT(false); |
| 498 | return; |
| 499 | } |
| 500 | |
| 501 | if (1 != sampleSize) { |
msarett | 4b0778e | 2015-11-13 09:59:11 -0800 | [diff] [blame] | 502 | folder.appendf("_%.3f", 1.0f / (float) sampleSize); |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | BRDSrc* src = new BRDSrc(path, strategy, mode, dstColorType, sampleSize); |
| 506 | push_src("image", folder, src); |
| 507 | } |
| 508 | |
| 509 | static void push_brd_srcs(Path path) { |
| 510 | |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 511 | const SkBitmapRegionDecoder::Strategy strategies[] = { |
| 512 | SkBitmapRegionDecoder::kCanvas_Strategy, |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 513 | SkBitmapRegionDecoder::kAndroidCodec_Strategy, |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 514 | }; |
| 515 | |
scroggo | 501b734 | 2015-11-03 07:55:11 -0800 | [diff] [blame] | 516 | // Test on a variety of sampleSizes, making sure to include: |
| 517 | // - 2, 4, and 8, which are natively supported by jpeg |
| 518 | // - multiples of 2 which are not divisible by 4 (analogous for 4) |
| 519 | // - larger powers of two, since BRD clients generally use powers of 2 |
| 520 | // We will only produce output for the larger sizes on large images. |
| 521 | 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] | 522 | |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 523 | // We will only test to one backend (8888), but we will test all of the |
| 524 | // color types that we need to decode to on this backend. |
| 525 | const CodecSrc::DstColorType dstColorTypes[] = { |
msarett | 26ad17b | 2015-10-22 07:29:19 -0700 | [diff] [blame] | 526 | CodecSrc::kGetFromCanvas_DstColorType, |
| 527 | CodecSrc::kIndex8_Always_DstColorType, |
| 528 | CodecSrc::kGrayscale_Always_DstColorType, |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 529 | }; |
| 530 | |
| 531 | const BRDSrc::Mode modes[] = { |
msarett | 26ad17b | 2015-10-22 07:29:19 -0700 | [diff] [blame] | 532 | BRDSrc::kFullImage_Mode, |
| 533 | BRDSrc::kDivisor_Mode, |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 534 | }; |
| 535 | |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 536 | for (SkBitmapRegionDecoder::Strategy strategy : strategies) { |
msarett | 6efbe05 | 2015-09-11 09:01:16 -0700 | [diff] [blame] | 537 | for (uint32_t sampleSize : sampleSizes) { |
msarett | 6efbe05 | 2015-09-11 09:01:16 -0700 | [diff] [blame] | 538 | for (CodecSrc::DstColorType dstColorType : dstColorTypes) { |
| 539 | if (brd_color_type_supported(strategy, dstColorType)) { |
| 540 | for (BRDSrc::Mode mode : modes) { |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 541 | push_brd_src(path, strategy, dstColorType, mode, sampleSize); |
| 542 | } |
| 543 | } |
| 544 | } |
| 545 | } |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | static bool brd_supported(const char* ext) { |
msarett | 8c8f22a | 2015-04-01 06:58:48 -0700 | [diff] [blame] | 550 | static const char* const exts[] = { |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 551 | "jpg", "jpeg", "png", "webp", |
| 552 | "JPG", "JPEG", "PNG", "WEBP", |
msarett | 8c8f22a | 2015-04-01 06:58:48 -0700 | [diff] [blame] | 553 | }; |
| 554 | |
| 555 | for (uint32_t i = 0; i < SK_ARRAY_COUNT(exts); i++) { |
| 556 | if (0 == strcmp(exts[i], ext)) { |
| 557 | return true; |
| 558 | } |
| 559 | } |
| 560 | return false; |
scroggo | 9b77ddd | 2015-03-19 06:03:39 -0700 | [diff] [blame] | 561 | } |
| 562 | |
scroggo | 8673714 | 2016-02-03 12:19:11 -0800 | [diff] [blame] | 563 | static bool gather_srcs() { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 564 | for (const skiagm::GMRegistry* r = skiagm::GMRegistry::Head(); r; r = r->next()) { |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 565 | push_src("gm", "", new GMSrc(r->factory())); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 566 | } |
halcanary | fc37ad1 | 2015-01-30 07:31:19 -0800 | [diff] [blame] | 567 | for (int i = 0; i < FLAGS_skps.count(); i++) { |
| 568 | const char* path = FLAGS_skps[i]; |
| 569 | if (sk_isdir(path)) { |
| 570 | SkOSFile::Iter it(path, "skp"); |
| 571 | for (SkString file; it.next(&file); ) { |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 572 | push_src("skp", "", new SKPSrc(SkOSPath::Join(path, file.c_str()))); |
halcanary | fc37ad1 | 2015-01-30 07:31:19 -0800 | [diff] [blame] | 573 | } |
| 574 | } else { |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 575 | push_src("skp", "", new SKPSrc(path)); |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 576 | } |
| 577 | } |
scroggo | 8673714 | 2016-02-03 12:19:11 -0800 | [diff] [blame] | 578 | |
| 579 | SkTArray<SkString> images; |
| 580 | if (!CollectImages(&images)) { |
| 581 | return false; |
| 582 | } |
| 583 | |
| 584 | for (auto image : images) { |
| 585 | push_codec_srcs(image); |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 586 | const char* ext = strrchr(image.c_str(), '.'); |
| 587 | if (ext && brd_supported(ext+1)) { |
scroggo | 8673714 | 2016-02-03 12:19:11 -0800 | [diff] [blame] | 588 | push_brd_srcs(image); |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 589 | } |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 590 | } |
scroggo | 8673714 | 2016-02-03 12:19:11 -0800 | [diff] [blame] | 591 | |
| 592 | return true; |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 593 | } |
| 594 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 595 | static void push_sink(const SkCommandLineConfig& config, Sink* s) { |
rmistry | 0f515bd | 2015-12-22 10:22:26 -0800 | [diff] [blame] | 596 | SkAutoTDelete<Sink> sink(s); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 597 | |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 598 | // Try a simple Src as a canary. If it fails, skip this sink. |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 599 | struct : public Src { |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 600 | Error draw(SkCanvas* c) const override { |
| 601 | c->drawRect(SkRect::MakeWH(1,1), SkPaint()); |
| 602 | return ""; |
| 603 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 604 | SkISize size() const override { return SkISize::Make(16, 16); } |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 605 | Name name() const override { return "justOneRect"; } |
| 606 | } justOneRect; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 607 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 608 | SkBitmap bitmap; |
| 609 | SkDynamicMemoryWStream stream; |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 610 | SkString log; |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 611 | Error err = sink->draw(justOneRect, &bitmap, &stream, &log); |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 612 | if (err.isFatal()) { |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 613 | 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] | 614 | exit(1); |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 615 | } |
| 616 | |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 617 | TaggedSink& ts = gSinks.push_back(); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 618 | ts.reset(sink.detach()); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 619 | ts.tag = config.getTag(); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | static bool gpu_supported() { |
| 623 | #if SK_SUPPORT_GPU |
| 624 | return FLAGS_gpu; |
| 625 | #else |
| 626 | return false; |
| 627 | #endif |
| 628 | } |
kkinnunen | 9ebc3f0 | 2015-12-21 23:48:13 -0800 | [diff] [blame] | 629 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 630 | static Sink* create_sink(const SkCommandLineConfig* config) { |
| 631 | #if SK_SUPPORT_GPU |
| 632 | if (gpu_supported()) { |
| 633 | if (const SkCommandLineConfigGpu* gpuConfig = config->asConfigGpu()) { |
| 634 | GrContextFactory::GLContextType contextType = gpuConfig->getContextType(); |
| 635 | GrContextFactory::GLContextOptions contextOptions = |
| 636 | GrContextFactory::kNone_GLContextOptions; |
| 637 | if (gpuConfig->getUseNVPR()) { |
| 638 | contextOptions = static_cast<GrContextFactory::GLContextOptions>( |
| 639 | contextOptions | GrContextFactory::kEnableNVPR_GLContextOptions); |
| 640 | } |
| 641 | GrContextFactory testFactory; |
| 642 | if (!testFactory.get(contextType, contextOptions)) { |
| 643 | SkDebugf("WARNING: can not create GPU context for config '%s'. " |
| 644 | "GM tests will be skipped.\n", gpuConfig->getTag().c_str()); |
| 645 | return nullptr; |
| 646 | } |
| 647 | return new GPUSink(contextType, contextOptions, gpuConfig->getSamples(), |
| 648 | gpuConfig->getUseDIText(), FLAGS_gpu_threading); |
| 649 | } |
| 650 | } |
| 651 | #endif |
| 652 | |
| 653 | #define SINK(t, sink, ...) if (config->getBackend().equals(t)) { return new sink(__VA_ARGS__); } |
| 654 | |
tomhudson | eebc39a | 2015-02-23 12:18:05 -0800 | [diff] [blame] | 655 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 656 | SINK("hwui", HWUISink); |
| 657 | #endif |
| 658 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 659 | if (FLAGS_cpu) { |
| 660 | SINK("565", RasterSink, kRGB_565_SkColorType); |
| 661 | SINK("8888", RasterSink, kN32_SkColorType); |
halcanary | c11c62f | 2015-09-28 11:51:54 -0700 | [diff] [blame] | 662 | SINK("pdf", PDFSink, "Pdfium"); |
| 663 | SINK("pdf_poppler", PDFSink, "Poppler"); |
mtklein | 9c3f17d | 2015-01-28 11:35:18 -0800 | [diff] [blame] | 664 | SINK("skp", SKPSink); |
mtklein | 8a4527e | 2015-01-31 20:00:58 -0800 | [diff] [blame] | 665 | SINK("svg", SVGSink); |
| 666 | SINK("null", NullSink); |
halcanary | 47ef4d5 | 2015-03-03 09:13:09 -0800 | [diff] [blame] | 667 | SINK("xps", XPSSink); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 668 | } |
| 669 | #undef SINK |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 670 | return nullptr; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 671 | } |
| 672 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 673 | static Sink* create_via(const SkString& tag, Sink* wrapped) { |
| 674 | #define VIA(t, via, ...) if (tag.equals(t)) { return new via(__VA_ARGS__); } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 675 | VIA("twice", ViaTwice, wrapped); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 676 | VIA("serialize", ViaSerialization, wrapped); |
mtklein | 4a34ecb | 2016-01-08 10:19:35 -0800 | [diff] [blame] | 677 | VIA("pic", ViaPicture, wrapped); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 678 | VIA("2ndpic", ViaSecondPicture, wrapped); |
mtklein | d31c13d | 2015-05-05 12:59:56 -0700 | [diff] [blame] | 679 | VIA("sp", ViaSingletonPictures, wrapped); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 680 | VIA("tiles", ViaTiles, 256, 256, nullptr, wrapped); |
mtklein | 7edca21 | 2015-01-21 13:18:51 -0800 | [diff] [blame] | 681 | VIA("tiles_rt", ViaTiles, 256, 256, new SkRTreeFactory, wrapped); |
mtklein | 2e2ea38 | 2015-10-16 10:29:41 -0700 | [diff] [blame] | 682 | VIA("remote", ViaRemote, false, wrapped); |
| 683 | VIA("remote_cache", ViaRemote, true, wrapped); |
halcanary | 7a76f9c | 2016-02-03 11:53:18 -0800 | [diff] [blame] | 684 | VIA("mojo", ViaMojo, wrapped); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 685 | |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 686 | if (FLAGS_matrix.count() == 4) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 687 | SkMatrix m; |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 688 | m.reset(); |
| 689 | m.setScaleX((SkScalar)atof(FLAGS_matrix[0])); |
| 690 | m.setSkewX ((SkScalar)atof(FLAGS_matrix[1])); |
| 691 | m.setSkewY ((SkScalar)atof(FLAGS_matrix[2])); |
| 692 | m.setScaleY((SkScalar)atof(FLAGS_matrix[3])); |
| 693 | VIA("matrix", ViaMatrix, m, wrapped); |
| 694 | VIA("upright", ViaUpright, m, wrapped); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 695 | } |
tomhudson | 64de1e1 | 2015-03-05 08:01:07 -0800 | [diff] [blame] | 696 | |
| 697 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 698 | VIA("androidsdk", ViaAndroidSDK, wrapped); |
| 699 | #endif |
| 700 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 701 | #undef VIA |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 702 | return nullptr; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 703 | } |
| 704 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 705 | static void gather_sinks() { |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 706 | SkCommandLineConfigArray configs; |
| 707 | ParseConfigs(FLAGS_config, &configs); |
| 708 | for (int i = 0; i < configs.count(); i++) { |
| 709 | const SkCommandLineConfig& config = *configs[i]; |
| 710 | Sink* sink = create_sink(&config); |
| 711 | if (sink == nullptr) { |
| 712 | SkDebugf("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(), |
| 713 | config.getTag().c_str()); |
| 714 | continue; |
| 715 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 716 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 717 | const SkTArray<SkString>& parts = config.getViaParts(); |
| 718 | for (int j = parts.count(); j-- > 0;) { |
| 719 | const SkString& part = parts[j]; |
| 720 | Sink* next = create_via(part, sink); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 721 | if (next == nullptr) { |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 722 | SkDebugf("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(), |
| 723 | part.c_str()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 724 | delete sink; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 725 | sink = nullptr; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 726 | break; |
| 727 | } |
| 728 | sink = next; |
| 729 | } |
| 730 | if (sink) { |
| 731 | push_sink(config, sink); |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 732 | } |
| 733 | } |
| 734 | } |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 735 | |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 736 | static bool dump_png(SkBitmap bitmap, const char* path, const char* md5) { |
| 737 | const int w = bitmap.width(), |
| 738 | h = bitmap.height(); |
| 739 | |
| 740 | // First get the bitmap into N32 color format. The next step will work only there. |
| 741 | if (bitmap.colorType() != kN32_SkColorType) { |
| 742 | SkBitmap n32; |
| 743 | if (!bitmap.copyTo(&n32, kN32_SkColorType)) { |
| 744 | return false; |
| 745 | } |
| 746 | bitmap = n32; |
| 747 | } |
| 748 | |
| 749 | // Convert our N32 bitmap into unpremul RGBA for libpng. |
| 750 | SkAutoTMalloc<uint32_t> rgba(w*h); |
| 751 | if (!bitmap.readPixels(SkImageInfo::Make(w,h, kRGBA_8888_SkColorType, kUnpremul_SkAlphaType), |
| 752 | rgba, 4*w, 0,0)) { |
| 753 | return false; |
| 754 | } |
| 755 | |
| 756 | // We don't need bitmap anymore. Might as well drop our ref. |
mtklein | fccb77d | 2015-08-24 14:13:29 -0700 | [diff] [blame] | 757 | bitmap.reset(); |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 758 | |
mtklein | c64137c | 2015-08-25 10:56:08 -0700 | [diff] [blame] | 759 | FILE* f = fopen(path, "wb"); |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 760 | if (!f) { return false; } |
| 761 | |
| 762 | png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr); |
| 763 | if (!png) { |
| 764 | fclose(f); |
| 765 | return false; |
| 766 | } |
| 767 | |
| 768 | png_infop info = png_create_info_struct(png); |
| 769 | if (!info) { |
| 770 | png_destroy_write_struct(&png, &info); |
| 771 | fclose(f); |
| 772 | return false; |
| 773 | } |
| 774 | |
mtklein | d69ece6 | 2015-09-10 10:37:44 -0700 | [diff] [blame] | 775 | SkString description; |
| 776 | description.append("Key: "); |
| 777 | for (int i = 0; i < FLAGS_key.count(); i++) { |
| 778 | description.appendf("%s ", FLAGS_key[i]); |
| 779 | } |
| 780 | description.append("Properties: "); |
| 781 | for (int i = 0; i < FLAGS_properties.count(); i++) { |
| 782 | description.appendf("%s ", FLAGS_properties[i]); |
| 783 | } |
| 784 | description.appendf("MD5: %s", md5); |
| 785 | |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 786 | png_text text[2]; |
| 787 | text[0].key = (png_charp)"Author"; |
| 788 | text[0].text = (png_charp)"DM dump_png()"; |
| 789 | text[0].compression = PNG_TEXT_COMPRESSION_NONE; |
| 790 | text[1].key = (png_charp)"Description"; |
mtklein | d69ece6 | 2015-09-10 10:37:44 -0700 | [diff] [blame] | 791 | text[1].text = (png_charp)description.c_str(); |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 792 | text[1].compression = PNG_TEXT_COMPRESSION_NONE; |
| 793 | png_set_text(png, info, text, 2); |
| 794 | |
| 795 | png_init_io(png, f); |
| 796 | png_set_IHDR(png, info, (png_uint_32)w, (png_uint_32)h, 8, |
| 797 | PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, |
| 798 | PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); |
| 799 | png_write_info(png, info); |
| 800 | for (int j = 0; j < h; j++) { |
| 801 | png_bytep row = (png_bytep)(rgba.get() + w*j); |
| 802 | png_write_rows(png, &row, 1); |
| 803 | } |
| 804 | png_write_end(png, info); |
| 805 | |
| 806 | png_destroy_write_struct(&png, &info); |
| 807 | fclose(f); |
| 808 | return true; |
| 809 | } |
| 810 | |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 811 | static bool match(const char* needle, const char* haystack) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 812 | return 0 == strcmp("_", needle) || nullptr != strstr(haystack, needle); |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 813 | } |
| 814 | |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 815 | static ImplicitString is_blacklisted(const char* sink, const char* src, |
| 816 | const char* srcOptions, const char* name) { |
mtklein | 0d243ff | 2015-04-03 07:51:00 -0700 | [diff] [blame] | 817 | for (int i = 0; i < FLAGS_blacklist.count() - 3; i += 4) { |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 818 | if (match(FLAGS_blacklist[i+0], sink) && |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 819 | match(FLAGS_blacklist[i+1], src) && |
| 820 | match(FLAGS_blacklist[i+2], srcOptions) && |
| 821 | match(FLAGS_blacklist[i+3], name)) { |
| 822 | return SkStringPrintf("%s %s %s %s", |
| 823 | FLAGS_blacklist[i+0], FLAGS_blacklist[i+1], |
| 824 | FLAGS_blacklist[i+2], FLAGS_blacklist[i+3]); |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 825 | } |
| 826 | } |
| 827 | return ""; |
| 828 | } |
| 829 | |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 830 | // Even when a Task Sink reports to be non-threadsafe (e.g. GPU), we know things like |
| 831 | // .png encoding are definitely thread safe. This lets us offload that work to CPU threads. |
| 832 | static SkTaskGroup gDefinitelyThreadSafeWork; |
| 833 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 834 | // The finest-grained unit of work we can run: draw a single Src into a single Sink, |
| 835 | // report any errors, and perhaps write out the output: a .png of the bitmap, or a raw stream. |
| 836 | struct Task { |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 837 | Task(const TaggedSrc& src, const TaggedSink& sink) : src(src), sink(sink) {} |
| 838 | const TaggedSrc& src; |
| 839 | const TaggedSink& sink; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 840 | |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 841 | static void Run(const Task& task) { |
| 842 | SkString name = task.src->name(); |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 843 | |
| 844 | // We'll skip drawing this Src/Sink pair if: |
| 845 | // - the Src vetoes the Sink; |
| 846 | // - this Src / Sink combination is on the blacklist; |
| 847 | // - it's a dry run. |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 848 | SkString note(task.src->veto(task.sink->flags()) ? " (veto)" : ""); |
| 849 | SkString whyBlacklisted = is_blacklisted(task.sink.tag.c_str(), task.src.tag.c_str(), |
| 850 | task.src.options.c_str(), name.c_str()); |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 851 | if (!whyBlacklisted.isEmpty()) { |
| 852 | note.appendf(" (--blacklist %s)", whyBlacklisted.c_str()); |
| 853 | } |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 854 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 855 | SkString log; |
mtklein | f27f08b | 2015-11-03 06:54:24 -0800 | [diff] [blame] | 856 | auto timerStart = now_ms(); |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 857 | if (!FLAGS_dryRun && note.isEmpty()) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 858 | SkBitmap bitmap; |
| 859 | SkDynamicMemoryWStream stream; |
bsalomon | 821e10e | 2015-06-04 14:15:33 -0700 | [diff] [blame] | 860 | if (FLAGS_pre_log) { |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 861 | SkDebugf("\nRunning %s->%s", name.c_str(), task.sink.tag.c_str()); |
bsalomon | 821e10e | 2015-06-04 14:15:33 -0700 | [diff] [blame] | 862 | } |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 863 | start(task.sink.tag.c_str(), task.src.tag, task.src.options, name.c_str()); |
| 864 | Error err = task.sink->draw(*task.src, &bitmap, &stream, &log); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 865 | if (!err.isEmpty()) { |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 866 | if (err.isFatal()) { |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 867 | fail(SkStringPrintf("%s %s %s %s: %s", |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 868 | task.sink.tag.c_str(), |
| 869 | task.src.tag.c_str(), |
| 870 | task.src.options.c_str(), |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 871 | name.c_str(), |
| 872 | err.c_str())); |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 873 | } else { |
| 874 | note.appendf(" (skipped: %s)", err.c_str()); |
mtklein | ba6ada7 | 2016-01-21 09:39:35 -0800 | [diff] [blame] | 875 | auto elapsed = now_ms() - timerStart; |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 876 | done(elapsed, task.sink.tag.c_str(), task.src.tag, task.src.options, |
mtklein | ba6ada7 | 2016-01-21 09:39:35 -0800 | [diff] [blame] | 877 | name, note, log); |
| 878 | return; |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 879 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 880 | } |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 881 | |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 882 | // We're likely switching threads here, so we must capture by value, [=] or [foo,bar]. |
| 883 | SkStreamAsset* data = stream.detachAsStream(); |
| 884 | gDefinitelyThreadSafeWork.add([task,name,bitmap,data]{ |
| 885 | SkAutoTDelete<SkStreamAsset> ownedData(data); |
| 886 | |
| 887 | // Why doesn't the copy constructor do this when we have pre-locked pixels? |
| 888 | bitmap.lockPixels(); |
| 889 | |
| 890 | SkString md5; |
| 891 | if (!FLAGS_writePath.isEmpty() || !FLAGS_readPath.isEmpty()) { |
| 892 | SkMD5 hash; |
| 893 | if (data->getLength()) { |
| 894 | hash.writeStream(data, data->getLength()); |
| 895 | data->rewind(); |
mtklein | 3840846 | 2015-07-08 07:25:27 -0700 | [diff] [blame] | 896 | } else { |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 897 | // If we're BGRA (Linux, Windows), swizzle over to RGBA (Mac, Android). |
| 898 | // This helps eliminate multiple 0-pixel-diff hashes on gold.skia.org. |
| 899 | // (Android's general slow speed breaks the tie arbitrarily in RGBA's favor.) |
| 900 | // We might consider promoting 565 to RGBA too. |
| 901 | if (bitmap.colorType() == kBGRA_8888_SkColorType) { |
| 902 | SkBitmap swizzle; |
| 903 | SkAssertResult(bitmap.copyTo(&swizzle, kRGBA_8888_SkColorType)); |
| 904 | hash.write(swizzle.getPixels(), swizzle.getSize()); |
| 905 | } else { |
| 906 | hash.write(bitmap.getPixels(), bitmap.getSize()); |
| 907 | } |
| 908 | } |
| 909 | SkMD5::Digest digest; |
| 910 | hash.finish(digest); |
| 911 | for (int i = 0; i < 16; i++) { |
| 912 | md5.appendf("%02x", digest.data[i]); |
mtklein | 3840846 | 2015-07-08 07:25:27 -0700 | [diff] [blame] | 913 | } |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 914 | } |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 915 | |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 916 | if (!FLAGS_readPath.isEmpty() && |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 917 | !gGold.contains(Gold(task.sink.tag.c_str(), task.src.tag.c_str(), |
| 918 | task.src.options.c_str(), name, md5))) { |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 919 | fail(SkStringPrintf("%s not found for %s %s %s %s in %s", |
| 920 | md5.c_str(), |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 921 | task.sink.tag.c_str(), |
| 922 | task.src.tag.c_str(), |
| 923 | task.src.options.c_str(), |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 924 | name.c_str(), |
| 925 | FLAGS_readPath[0])); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 926 | } |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 927 | |
| 928 | if (!FLAGS_writePath.isEmpty()) { |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 929 | const char* ext = task.sink->fileExtension(); |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 930 | if (data->getLength()) { |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 931 | WriteToDisk(task, md5, ext, data, data->getLength(), nullptr); |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 932 | SkASSERT(bitmap.drawsNothing()); |
| 933 | } else if (!bitmap.drawsNothing()) { |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 934 | WriteToDisk(task, md5, ext, nullptr, 0, &bitmap); |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 935 | } |
| 936 | } |
| 937 | }); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 938 | } |
mtklein | ba6ada7 | 2016-01-21 09:39:35 -0800 | [diff] [blame] | 939 | auto elapsed = now_ms() - timerStart; |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 940 | 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] | 941 | name, note, log); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 942 | } |
| 943 | |
| 944 | static void WriteToDisk(const Task& task, |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 945 | SkString md5, |
| 946 | const char* ext, |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 947 | SkStream* data, size_t len, |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 948 | const SkBitmap* bitmap) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 949 | JsonWriter::BitmapResult result; |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 950 | result.name = task.src->name(); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 951 | result.config = task.sink.tag.c_str(); |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 952 | result.sourceType = task.src.tag; |
| 953 | result.sourceOptions = task.src.options; |
| 954 | result.ext = ext; |
| 955 | result.md5 = md5; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 956 | JsonWriter::AddBitmapResult(result); |
| 957 | |
mtklein | b0531a7 | 2015-04-07 13:38:48 -0700 | [diff] [blame] | 958 | // If an MD5 is uninteresting, we want it noted in the JSON file, |
| 959 | // but don't want to dump it out as a .png (or whatever ext is). |
| 960 | if (gUninterestingHashes.contains(md5)) { |
| 961 | return; |
| 962 | } |
| 963 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 964 | const char* dir = FLAGS_writePath[0]; |
| 965 | if (0 == strcmp(dir, "@")) { // Needed for iOS. |
| 966 | dir = FLAGS_resourcePath[0]; |
| 967 | } |
| 968 | sk_mkdir(dir); |
| 969 | |
| 970 | SkString path; |
| 971 | if (FLAGS_nameByHash) { |
| 972 | path = SkOSPath::Join(dir, result.md5.c_str()); |
| 973 | path.append("."); |
| 974 | path.append(ext); |
| 975 | if (sk_exists(path.c_str())) { |
| 976 | return; // Content-addressed. If it exists already, we're done. |
| 977 | } |
| 978 | } else { |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 979 | path = SkOSPath::Join(dir, task.sink.tag.c_str()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 980 | sk_mkdir(path.c_str()); |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 981 | path = SkOSPath::Join(path.c_str(), task.src.tag.c_str()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 982 | sk_mkdir(path.c_str()); |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 983 | if (strcmp(task.src.options.c_str(), "") != 0) { |
| 984 | path = SkOSPath::Join(path.c_str(), task.src.options.c_str()); |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 985 | sk_mkdir(path.c_str()); |
| 986 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 987 | path = SkOSPath::Join(path.c_str(), task.src->name().c_str()); |
| 988 | path.append("."); |
| 989 | path.append(ext); |
| 990 | } |
| 991 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 992 | if (bitmap) { |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 993 | if (!dump_png(*bitmap, path.c_str(), result.md5.c_str())) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 994 | fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str())); |
| 995 | return; |
| 996 | } |
| 997 | } else { |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 998 | SkFILEWStream file(path.c_str()); |
| 999 | if (!file.isValid()) { |
| 1000 | fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str())); |
| 1001 | return; |
| 1002 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1003 | if (!file.writeStream(data, len)) { |
| 1004 | fail(SkStringPrintf("Can't write to %s.\n", path.c_str())); |
| 1005 | return; |
| 1006 | } |
| 1007 | } |
| 1008 | } |
| 1009 | }; |
| 1010 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1011 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 1012 | |
| 1013 | // Unit tests don't fit so well into the Src/Sink model, so we give them special treatment. |
| 1014 | |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1015 | static SkTDArray<skiatest::Test> gParallelTests, gSerialTests; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1016 | |
| 1017 | static void gather_tests() { |
mtklein | 6c5fed2 | 2015-01-20 13:47:23 -0800 | [diff] [blame] | 1018 | if (!FLAGS_src.contains("tests")) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1019 | return; |
| 1020 | } |
mtklein | 6393c06 | 2015-04-27 08:45:01 -0700 | [diff] [blame] | 1021 | for (const skiatest::TestRegistry* r = skiatest::TestRegistry::Head(); r; r = r->next()) { |
| 1022 | if (!in_shard()) { |
| 1023 | continue; |
| 1024 | } |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1025 | // Despite its name, factory() is returning a reference to |
| 1026 | // link-time static const POD data. |
| 1027 | const skiatest::Test& test = r->factory(); |
| 1028 | if (SkCommandLineFlags::ShouldSkip(FLAGS_match, test.name)) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1029 | continue; |
| 1030 | } |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1031 | if (test.needsGpu && gpu_supported()) { |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1032 | (FLAGS_gpu_threading ? gParallelTests : gSerialTests).push(test); |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1033 | } else if (!test.needsGpu && FLAGS_cpu) { |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1034 | gParallelTests.push(test); |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 1035 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1036 | } |
| 1037 | } |
| 1038 | |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1039 | static void run_test(skiatest::Test test) { |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1040 | struct : public skiatest::Reporter { |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 1041 | void reportFailed(const skiatest::Failure& failure) override { |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1042 | fail(failure.toString()); |
| 1043 | JsonWriter::AddTestFailure(failure); |
| 1044 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 1045 | bool allowExtendedTest() const override { |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1046 | return FLAGS_pathOpsExtended; |
| 1047 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 1048 | bool verbose() const override { return FLAGS_veryVerbose; } |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1049 | } reporter; |
djsollen | 824996a | 2015-06-12 12:06:22 -0700 | [diff] [blame] | 1050 | |
| 1051 | SkString note; |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1052 | SkString whyBlacklisted = is_blacklisted("_", "tests", "_", test.name); |
djsollen | 824996a | 2015-06-12 12:06:22 -0700 | [diff] [blame] | 1053 | if (!whyBlacklisted.isEmpty()) { |
| 1054 | note.appendf(" (--blacklist %s)", whyBlacklisted.c_str()); |
| 1055 | } |
| 1056 | |
mtklein | f27f08b | 2015-11-03 06:54:24 -0800 | [diff] [blame] | 1057 | auto timerStart = now_ms(); |
djsollen | 824996a | 2015-06-12 12:06:22 -0700 | [diff] [blame] | 1058 | if (!FLAGS_dryRun && whyBlacklisted.isEmpty()) { |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1059 | start("unit", "test", "", test.name); |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 1060 | GrContextFactory factory; |
bsalomon | 821e10e | 2015-06-04 14:15:33 -0700 | [diff] [blame] | 1061 | if (FLAGS_pre_log) { |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1062 | SkDebugf("\nRunning test %s", test.name); |
bsalomon | 821e10e | 2015-06-04 14:15:33 -0700 | [diff] [blame] | 1063 | } |
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 | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1066 | done(now_ms()-timerStart, "unit", "test", "", test.name, note, ""); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1067 | } |
| 1068 | |
| 1069 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 1070 | |
mtklein | de6fc2b | 2015-03-12 06:28:54 -0700 | [diff] [blame] | 1071 | // Some runs (mostly, Valgrind) are so slow that the bot framework thinks we've hung. |
| 1072 | // 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] | 1073 | static void start_keepalive() { |
| 1074 | struct Loop { |
| 1075 | static void forever(void*) { |
| 1076 | for (;;) { |
| 1077 | static const int kSec = 300; |
| 1078 | #if defined(SK_BUILD_FOR_WIN) |
| 1079 | Sleep(kSec * 1000); |
| 1080 | #else |
| 1081 | sleep(kSec); |
| 1082 | #endif |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 1083 | SkString running; |
| 1084 | { |
mtklein | bc4e003 | 2015-12-09 08:37:35 -0800 | [diff] [blame] | 1085 | SkAutoMutexAcquire lock(gRunningAndTallyMutex); |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 1086 | for (int i = 0; i < gRunning.count(); i++) { |
| 1087 | running.appendf("\n\t%s", gRunning[i].c_str()); |
| 1088 | } |
| 1089 | } |
| 1090 | SkDebugf("\nCurrently running:%s\n", running.c_str()); |
mtklein | 2e1c47e | 2015-03-12 07:16:56 -0700 | [diff] [blame] | 1091 | } |
| 1092 | } |
| 1093 | }; |
| 1094 | static SkThread* intentionallyLeaked = new SkThread(Loop::forever); |
| 1095 | intentionallyLeaked->start(); |
mtklein | de6fc2b | 2015-03-12 06:28:54 -0700 | [diff] [blame] | 1096 | } |
| 1097 | |
caryclark | 83ca628 | 2015-06-10 09:31:09 -0700 | [diff] [blame] | 1098 | #define PORTABLE_FONT_PREFIX "Toy Liberation " |
| 1099 | |
| 1100 | static SkTypeface* create_from_name(const char familyName[], SkTypeface::Style style) { |
| 1101 | if (familyName && strlen(familyName) > sizeof(PORTABLE_FONT_PREFIX) |
| 1102 | && !strncmp(familyName, PORTABLE_FONT_PREFIX, sizeof(PORTABLE_FONT_PREFIX) - 1)) { |
caryclark | 1818acb | 2015-07-24 12:09:25 -0700 | [diff] [blame] | 1103 | return sk_tool_utils::create_portable_typeface(familyName, style); |
caryclark | 83ca628 | 2015-06-10 09:31:09 -0700 | [diff] [blame] | 1104 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1105 | return nullptr; |
caryclark | 83ca628 | 2015-06-10 09:31:09 -0700 | [diff] [blame] | 1106 | } |
| 1107 | |
| 1108 | #undef PORTABLE_FONT_PREFIX |
| 1109 | |
| 1110 | extern SkTypeface* (*gCreateTypefaceDelegate)(const char [], SkTypeface::Style ); |
| 1111 | |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 1112 | int dm_main(); |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 1113 | int dm_main() { |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 1114 | SetupCrashHandler(); |
mtklein | 5286f02 | 2016-01-22 08:18:14 -0800 | [diff] [blame] | 1115 | 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] | 1116 | SkAutoGraphics ag; |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 1117 | SkTaskGroup::Enabler enabled(FLAGS_threads); |
caryclark | 83ca628 | 2015-06-10 09:31:09 -0700 | [diff] [blame] | 1118 | gCreateTypefaceDelegate = &create_from_name; |
commit-bot@chromium.org | a65e2fd | 2014-05-30 17:23:31 +0000 | [diff] [blame] | 1119 | |
mtklein | 2e1c47e | 2015-03-12 07:16:56 -0700 | [diff] [blame] | 1120 | start_keepalive(); |
mtklein | de6fc2b | 2015-03-12 06:28:54 -0700 | [diff] [blame] | 1121 | |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 1122 | gather_gold(); |
borenet | 09ed480 | 2015-04-03 14:15:33 -0700 | [diff] [blame] | 1123 | gather_uninteresting_hashes(); |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 1124 | |
scroggo | 8673714 | 2016-02-03 12:19:11 -0800 | [diff] [blame] | 1125 | if (!gather_srcs()) { |
| 1126 | return 1; |
| 1127 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1128 | gather_sinks(); |
| 1129 | gather_tests(); |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 1130 | |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1131 | gPending = gSrcs.count() * gSinks.count() + gParallelTests.count() + gSerialTests.count(); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1132 | SkDebugf("%d srcs * %d sinks + %d tests == %d tasks\n", |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1133 | gSrcs.count(), gSinks.count(), gParallelTests.count() + gSerialTests.count(), gPending); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1134 | |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1135 | // Kick off as much parallel work as we can, making note of any serial work we'll need to do. |
| 1136 | SkTaskGroup parallel; |
| 1137 | SkTArray<Task> serial; |
| 1138 | |
| 1139 | for (auto& sink : gSinks) |
| 1140 | for (auto& src : gSrcs) { |
| 1141 | Task task(src, sink); |
| 1142 | if (src->serial() || sink->serial()) { |
| 1143 | serial.push_back(task); |
| 1144 | } else { |
| 1145 | parallel.add([task] { Task::Run(task); }); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1146 | } |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 1147 | } |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1148 | for (auto test : gParallelTests) { |
| 1149 | parallel.add([test] { run_test(test); }); |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 1150 | } |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1151 | |
| 1152 | // With the parallel work running, run serial tasks and tests here on main thread. |
| 1153 | for (auto task : serial) { Task::Run(task); } |
| 1154 | for (auto test : gSerialTests) { run_test(test); } |
| 1155 | |
| 1156 | // Wait for any remaining parallel work to complete (including any spun off of serial tasks). |
| 1157 | parallel.wait(); |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1158 | gDefinitelyThreadSafeWork.wait(); |
| 1159 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1160 | // At this point we're back in single-threaded land. |
caryclark | f53ce80 | 2015-06-15 06:48:30 -0700 | [diff] [blame] | 1161 | sk_tool_utils::release_portable_typefaces(); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 1162 | |
mtklein | bc4e003 | 2015-12-09 08:37:35 -0800 | [diff] [blame] | 1163 | if (FLAGS_verbose && gNoteTally.count() > 0) { |
| 1164 | SkDebugf("\nNote tally:\n"); |
| 1165 | gNoteTally.foreach([](const SkString& note, int* tally) { |
| 1166 | SkDebugf("%dx\t%s\n", *tally, note.c_str()); |
| 1167 | }); |
| 1168 | } |
| 1169 | |
mtklein | 2f64eec | 2015-01-15 14:20:41 -0800 | [diff] [blame] | 1170 | SkDebugf("\n"); |
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 | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1179 | if (gPending > 0) { |
| 1180 | SkDebugf("Hrm, we didn't seem to run everything we intended to! Please file a bug.\n"); |
| 1181 | return 1; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 1182 | } |
halcanary | 7a14b31 | 2015-10-01 07:28:13 -0700 | [diff] [blame] | 1183 | #ifdef SK_PDF_IMAGE_STATS |
| 1184 | SkPDFImageDumpStats(); |
| 1185 | #endif // SK_PDF_IMAGE_STATS |
scroggo | 4d9eaea | 2016-01-29 07:48:33 -0800 | [diff] [blame] | 1186 | SkDebugf("Finished!\n"); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1187 | return 0; |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 1188 | } |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 1189 | |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1190 | // TODO: currently many GPU tests are declared outside SK_SUPPORT_GPU guards. |
| 1191 | // Thus we export the empty RunWithGPUTestContexts when SK_SUPPORT_GPU=0. |
| 1192 | namespace skiatest { |
| 1193 | namespace { |
| 1194 | typedef void(*TestWithGrContext)(skiatest::Reporter*, GrContext*); |
| 1195 | typedef void(*TestWithGrContextAndGLContext)(skiatest::Reporter*, GrContext*, SkGLContext*); |
| 1196 | #if SK_SUPPORT_GPU |
| 1197 | template<typename T> |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 1198 | void call_test(T test, skiatest::Reporter* reporter, const GrContextFactory::ContextInfo& context); |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1199 | template<> |
| 1200 | void call_test(TestWithGrContext test, skiatest::Reporter* reporter, |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 1201 | const GrContextFactory::ContextInfo& context) { |
| 1202 | test(reporter, context.fGrContext); |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1203 | } |
| 1204 | template<> |
| 1205 | void call_test(TestWithGrContextAndGLContext test, skiatest::Reporter* reporter, |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 1206 | const GrContextFactory::ContextInfo& context) { |
| 1207 | test(reporter, context.fGrContext, context.fGLContext); |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1208 | } |
| 1209 | #endif |
| 1210 | } // namespace |
| 1211 | |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1212 | template<typename T> |
| 1213 | void RunWithGPUTestContexts(T test, GPUTestContexts testContexts, Reporter* reporter, |
| 1214 | GrContextFactory* factory) { |
| 1215 | #if SK_SUPPORT_GPU |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 1216 | // Iterate over context types, except use "native" instead of explicitly trying OpenGL and |
| 1217 | // OpenGL ES. Do not use GLES on desktop, since tests do not account for not fixing |
| 1218 | // http://skbug.com/2809 |
| 1219 | GrContextFactory::GLContextType contextTypes[] = { |
| 1220 | GrContextFactory::kNative_GLContextType, |
| 1221 | #if SK_ANGLE |
| 1222 | #ifdef SK_BUILD_FOR_WIN |
| 1223 | GrContextFactory::kANGLE_GLContextType, |
| 1224 | #endif |
| 1225 | GrContextFactory::kANGLE_GL_GLContextType, |
| 1226 | #endif |
| 1227 | #if SK_COMMAND_BUFFER |
| 1228 | GrContextFactory::kCommandBuffer_GLContextType, |
| 1229 | #endif |
| 1230 | #if SK_MESA |
| 1231 | GrContextFactory::kMESA_GLContextType, |
| 1232 | #endif |
| 1233 | GrContextFactory::kNull_GLContextType, |
| 1234 | GrContextFactory::kDebug_GLContextType, |
| 1235 | }; |
| 1236 | static_assert(SK_ARRAY_COUNT(contextTypes) == GrContextFactory::kGLContextTypeCnt - 2, |
| 1237 | "Skipping unexpected GLContextType for GPU tests"); |
| 1238 | |
| 1239 | for (auto& contextType : contextTypes) { |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1240 | int contextSelector = kNone_GPUTestContexts; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 1241 | if (GrContextFactory::IsRenderingGLContext(contextType)) { |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1242 | contextSelector |= kAllRendering_GPUTestContexts; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 1243 | } else if (contextType == GrContextFactory::kNative_GLContextType) { |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1244 | contextSelector |= kNative_GPUTestContexts; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 1245 | } else if (contextType == GrContextFactory::kNull_GLContextType) { |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1246 | contextSelector |= kNull_GPUTestContexts; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 1247 | } else if (contextType == GrContextFactory::kDebug_GLContextType) { |
kkinnunen | 55eeae9 | 2015-12-10 23:19:29 -0800 | [diff] [blame] | 1248 | contextSelector |= kDebug_GPUTestContexts; |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1249 | } |
| 1250 | if ((testContexts & contextSelector) == 0) { |
| 1251 | continue; |
| 1252 | } |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 1253 | GrContextFactory::ContextInfo context = factory->getContextInfo(contextType); |
| 1254 | if (context.fGrContext) { |
kkinnunen | 5219fd9 | 2015-12-10 06:28:13 -0800 | [diff] [blame] | 1255 | call_test(test, reporter, context); |
| 1256 | } |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 1257 | context = factory->getContextInfo(contextType, |
| 1258 | GrContextFactory::kEnableNVPR_GLContextOptions); |
| 1259 | if (context.fGrContext) { |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1260 | call_test(test, reporter, context); |
| 1261 | } |
| 1262 | } |
| 1263 | #endif |
| 1264 | } |
| 1265 | |
| 1266 | template |
| 1267 | void RunWithGPUTestContexts<TestWithGrContext>(TestWithGrContext test, |
| 1268 | GPUTestContexts testContexts, |
| 1269 | Reporter* reporter, |
| 1270 | GrContextFactory* factory); |
| 1271 | template |
| 1272 | void RunWithGPUTestContexts<TestWithGrContextAndGLContext>(TestWithGrContextAndGLContext test, |
| 1273 | GPUTestContexts testContexts, |
| 1274 | Reporter* reporter, |
| 1275 | GrContextFactory* factory); |
| 1276 | } // namespace skiatest |
| 1277 | |
borenet | 4808757 | 2015-04-02 12:16:36 -0700 | [diff] [blame] | 1278 | #if !defined(SK_BUILD_FOR_IOS) |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 1279 | int main(int argc, char** argv) { |
| 1280 | SkCommandLineFlags::Parse(argc, argv); |
| 1281 | return dm_main(); |
| 1282 | } |
| 1283 | #endif |