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