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