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