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