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" |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 17 | #include "SkCodecTools.h" |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 18 | #include "SkCommonFlags.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 | |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 32 | #ifdef SKIA_PNG_PREFIXED |
| 33 | // this must proceed png.h |
| 34 | #include "pngprefix.h" |
| 35 | #endif |
| 36 | #include "png.h" |
| 37 | |
bungeman | 60e0fee | 2015-08-26 05:15:46 -0700 | [diff] [blame] | 38 | #include <stdlib.h> |
| 39 | |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 40 | DEFINE_string(src, "tests gm skp image", "Source types to test."); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 41 | DEFINE_bool(nameByHash, false, |
| 42 | "If true, write to FLAGS_writePath[0]/<hash>.png instead of " |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 43 | "to FLAGS_writePath[0]/<config>/<sourceType>/<sourceOptions>/<name>.png"); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 44 | DEFINE_bool2(pathOpsExtended, x, false, "Run extended pathOps tests."); |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 45 | DEFINE_string(matrix, "1 0 0 1", |
| 46 | "2x2 scale+skew matrix to apply or upright when using " |
| 47 | "'matrix' or 'upright' in config."); |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 48 | 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] | 49 | |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 50 | DEFINE_string(blacklist, "", |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 51 | "Space-separated config/src/srcOptions/name quadruples to blacklist. '_' matches anything. E.g. \n" |
| 52 | "'--blacklist gpu skp _ _' will blacklist all SKPs drawn into the gpu config.\n" |
| 53 | "'--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] | 54 | |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 55 | DEFINE_string2(readPath, r, "", "If set check for equality with golden results in this directory."); |
| 56 | |
borenet | 09ed480 | 2015-04-03 14:15:33 -0700 | [diff] [blame] | 57 | DEFINE_string(uninterestingHashesFile, "", |
| 58 | "File containing a list of uninteresting hashes. If a result hashes to something in " |
| 59 | "this list, no image is written for that result."); |
| 60 | |
mtklein | 6393c06 | 2015-04-27 08:45:01 -0700 | [diff] [blame] | 61 | DEFINE_int32(shards, 1, "We're splitting source data into this many shards."); |
| 62 | DEFINE_int32(shard, 0, "Which shard do I run?"); |
bsalomon | 821e10e | 2015-06-04 14:15:33 -0700 | [diff] [blame] | 63 | 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] | 64 | |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 65 | __SK_FORCE_IMAGE_DECODER_LINKING; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 66 | using namespace DM; |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 67 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 68 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 69 | |
| 70 | SK_DECLARE_STATIC_MUTEX(gFailuresMutex); |
| 71 | static SkTArray<SkString> gFailures; |
| 72 | |
| 73 | static void fail(ImplicitString err) { |
| 74 | SkAutoMutexAcquire lock(gFailuresMutex); |
| 75 | SkDebugf("\n\nFAILURE: %s\n\n", err.c_str()); |
| 76 | gFailures.push_back(err); |
halcanary | 9e398f7 | 2015-01-10 11:18:04 -0800 | [diff] [blame] | 77 | } |
| 78 | |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 79 | static int32_t gPending = 0; // Atomic. Total number of running and queued tasks. |
| 80 | |
| 81 | SK_DECLARE_STATIC_MUTEX(gRunningMutex); |
| 82 | static SkTArray<SkString> gRunning; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 83 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 84 | static void done(double ms, |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 85 | ImplicitString config, ImplicitString src, ImplicitString srcOptions, |
| 86 | ImplicitString name, ImplicitString note, ImplicitString log) { |
| 87 | SkString id = SkStringPrintf("%s %s %s %s", config.c_str(), src.c_str(), |
| 88 | srcOptions.c_str(), name.c_str()); |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 89 | { |
| 90 | SkAutoMutexAcquire lock(gRunningMutex); |
| 91 | for (int i = 0; i < gRunning.count(); i++) { |
| 92 | if (gRunning[i] == id) { |
| 93 | gRunning.removeShuffle(i); |
| 94 | break; |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | if (!FLAGS_verbose) { |
| 99 | note = ""; |
| 100 | } |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 101 | if (!log.isEmpty()) { |
| 102 | log.prepend("\n"); |
| 103 | } |
mtklein | 6dee2ad | 2015-02-05 09:53:44 -0800 | [diff] [blame] | 104 | auto pending = sk_atomic_dec(&gPending)-1; |
reed | 50bc051 | 2015-05-19 14:13:31 -0700 | [diff] [blame] | 105 | if (!FLAGS_quiet) { |
mtklein | 711a245 | 2015-07-08 08:49:20 -0700 | [diff] [blame] | 106 | SkDebugf("%s(%4d/%-4dMB %6d) %s\t%s%s%s", FLAGS_verbose ? "\n" : kSkOverwriteLine |
reed | 50bc051 | 2015-05-19 14:13:31 -0700 | [diff] [blame] | 107 | , sk_tools::getCurrResidentSetSizeMB() |
| 108 | , sk_tools::getMaxResidentSetSizeMB() |
| 109 | , pending |
| 110 | , HumanizeMs(ms).c_str() |
| 111 | , id.c_str() |
| 112 | , note.c_str() |
| 113 | , log.c_str()); |
| 114 | } |
mtklein | a17241b | 2015-01-23 05:48:00 -0800 | [diff] [blame] | 115 | // We write our dm.json file every once in a while in case we crash. |
| 116 | // Notice this also handles the final dm.json when pending == 0. |
| 117 | if (pending % 500 == 0) { |
| 118 | JsonWriter::DumpJson(); |
| 119 | } |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 120 | } |
| 121 | |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 122 | static void start(ImplicitString config, ImplicitString src, |
| 123 | ImplicitString srcOptions, ImplicitString name) { |
| 124 | SkString id = SkStringPrintf("%s %s %s %s", config.c_str(), src.c_str(), |
| 125 | srcOptions.c_str(), name.c_str()); |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 126 | SkAutoMutexAcquire lock(gRunningMutex); |
| 127 | gRunning.push_back(id); |
| 128 | } |
| 129 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 130 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 131 | |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 132 | struct Gold : public SkString { |
mtklein | a82f562 | 2015-02-20 12:30:19 -0800 | [diff] [blame] | 133 | Gold() : SkString("") {} |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 134 | Gold(ImplicitString sink, ImplicitString src, ImplicitString srcOptions, |
| 135 | ImplicitString name, ImplicitString md5) |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 136 | : SkString("") { |
| 137 | this->append(sink); |
| 138 | this->append(src); |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 139 | this->append(srcOptions); |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 140 | this->append(name); |
| 141 | this->append(md5); |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 142 | } |
mtklein | 02f46cf | 2015-03-20 13:48:42 -0700 | [diff] [blame] | 143 | static uint32_t Hash(const Gold& g) { return SkGoodHash((const SkString&)g); } |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 144 | }; |
mtklein | a82f562 | 2015-02-20 12:30:19 -0800 | [diff] [blame] | 145 | static SkTHashSet<Gold, Gold::Hash> gGold; |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 146 | |
| 147 | static void add_gold(JsonWriter::BitmapResult r) { |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 148 | gGold.add(Gold(r.config, r.sourceType, r.sourceOptions, r.name, r.md5)); |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | static void gather_gold() { |
| 152 | if (!FLAGS_readPath.isEmpty()) { |
| 153 | SkString path(FLAGS_readPath[0]); |
| 154 | path.append("/dm.json"); |
| 155 | if (!JsonWriter::ReadJson(path.c_str(), add_gold)) { |
| 156 | fail(SkStringPrintf("Couldn't read %s for golden results.", path.c_str())); |
| 157 | } |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 162 | |
borenet | 09ed480 | 2015-04-03 14:15:33 -0700 | [diff] [blame] | 163 | static SkTHashSet<SkString> gUninterestingHashes; |
| 164 | |
| 165 | static void gather_uninteresting_hashes() { |
| 166 | if (!FLAGS_uninterestingHashesFile.isEmpty()) { |
| 167 | SkAutoTUnref<SkData> data(SkData::NewFromFileName(FLAGS_uninterestingHashesFile[0])); |
mtklein | cc334b3 | 2015-09-22 11:43:53 -0700 | [diff] [blame] | 168 | if (!data) { |
| 169 | SkDebugf("WARNING: unable to read uninteresting hashes from %s\n", |
| 170 | FLAGS_uninterestingHashesFile[0]); |
| 171 | return; |
| 172 | } |
borenet | 09ed480 | 2015-04-03 14:15:33 -0700 | [diff] [blame] | 173 | SkTArray<SkString> hashes; |
| 174 | SkStrSplit((const char*)data->data(), "\n", &hashes); |
| 175 | for (const SkString& hash : hashes) { |
| 176 | gUninterestingHashes.add(hash); |
| 177 | } |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 182 | |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 183 | struct TaggedSrc : public SkAutoTDelete<Src> { |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 184 | ImplicitString tag; |
| 185 | ImplicitString options; |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 186 | }; |
| 187 | |
| 188 | struct TaggedSink : public SkAutoTDelete<Sink> { |
| 189 | const char* tag; |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 190 | }; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 191 | |
| 192 | static const bool kMemcpyOK = true; |
| 193 | |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 194 | static SkTArray<TaggedSrc, kMemcpyOK> gSrcs; |
| 195 | static SkTArray<TaggedSink, kMemcpyOK> gSinks; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 196 | |
mtklein | 6393c06 | 2015-04-27 08:45:01 -0700 | [diff] [blame] | 197 | static bool in_shard() { |
| 198 | static int N = 0; |
| 199 | return N++ % FLAGS_shards == FLAGS_shard; |
| 200 | } |
| 201 | |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 202 | static void push_src(ImplicitString tag, ImplicitString options, Src* s) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 203 | SkAutoTDelete<Src> src(s); |
mtklein | 6393c06 | 2015-04-27 08:45:01 -0700 | [diff] [blame] | 204 | if (in_shard() && |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 205 | FLAGS_src.contains(tag.c_str()) && |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 206 | !SkCommandLineFlags::ShouldSkip(FLAGS_match, src->name().c_str())) { |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 207 | TaggedSrc& s = gSrcs.push_back(); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 208 | s.reset(src.detach()); |
| 209 | s.tag = tag; |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 210 | s.options = options; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 211 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 212 | } |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 213 | |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 214 | static void push_codec_src(Path path, CodecSrc::Mode mode, CodecSrc::DstColorType dstColorType, |
| 215 | float scale) { |
| 216 | SkString folder; |
| 217 | switch (mode) { |
| 218 | case CodecSrc::kCodec_Mode: |
| 219 | folder.append("codec"); |
| 220 | break; |
| 221 | case CodecSrc::kScaledCodec_Mode: |
| 222 | folder.append("scaled_codec"); |
| 223 | break; |
| 224 | case CodecSrc::kScanline_Mode: |
| 225 | folder.append("scanline"); |
| 226 | break; |
| 227 | case CodecSrc::kScanline_Subset_Mode: |
| 228 | folder.append("scanline_subset"); |
| 229 | break; |
| 230 | case CodecSrc::kStripe_Mode: |
| 231 | folder.append("stripe"); |
| 232 | break; |
| 233 | case CodecSrc::kSubset_Mode: |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 234 | folder.append("codec_subset"); |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 235 | break; |
| 236 | } |
| 237 | |
| 238 | switch (dstColorType) { |
| 239 | case CodecSrc::kGrayscale_Always_DstColorType: |
| 240 | folder.append("_kGray8"); |
| 241 | break; |
| 242 | case CodecSrc::kIndex8_Always_DstColorType: |
| 243 | folder.append("_kIndex8"); |
| 244 | break; |
| 245 | default: |
| 246 | break; |
| 247 | } |
| 248 | |
| 249 | if (1.0f != scale) { |
| 250 | folder.appendf("_%.3f", scale); |
| 251 | } |
| 252 | |
| 253 | CodecSrc* src = new CodecSrc(path, mode, dstColorType, scale); |
| 254 | push_src("image", folder, src); |
| 255 | } |
| 256 | |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 257 | static void push_codec_srcs(Path path) { |
| 258 | SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); |
| 259 | if (!encoded) { |
| 260 | SkDebugf("Couldn't read %s.", path.c_str()); |
| 261 | return; |
| 262 | } |
| 263 | SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 264 | if (nullptr == codec.get()) { |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 265 | SkDebugf("Couldn't create codec for %s.", path.c_str()); |
| 266 | return; |
| 267 | } |
| 268 | |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 269 | // Native Scales |
msarett | 0a24297 | 2015-06-11 14:27:27 -0700 | [diff] [blame] | 270 | // TODO (msarett): Implement scaling tests for SkImageDecoder in order to compare with these |
| 271 | // tests. SkImageDecoder supports downscales by integer factors. |
emmaleer | 8f4ba76 | 2015-08-14 07:44:46 -0700 | [diff] [blame] | 272 | // 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] | 273 | 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] | 274 | |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 275 | const CodecSrc::Mode nativeModes[] = { CodecSrc::kCodec_Mode, CodecSrc::kScanline_Mode, |
| 276 | CodecSrc::kScanline_Subset_Mode, CodecSrc::kStripe_Mode, CodecSrc::kSubset_Mode }; |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 277 | |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 278 | CodecSrc::DstColorType colorTypes[3]; |
| 279 | uint32_t numColorTypes; |
| 280 | switch (codec->getInfo().colorType()) { |
| 281 | case kGray_8_SkColorType: |
| 282 | // FIXME: Is this a long term solution for testing wbmps decodes to kIndex8? |
| 283 | // Further discussion on this topic is at skbug.com/3683 |
| 284 | colorTypes[0] = CodecSrc::kGetFromCanvas_DstColorType; |
| 285 | colorTypes[1] = CodecSrc::kGrayscale_Always_DstColorType; |
| 286 | colorTypes[2] = CodecSrc::kIndex8_Always_DstColorType; |
| 287 | numColorTypes = 3; |
| 288 | break; |
| 289 | case kIndex_8_SkColorType: |
| 290 | colorTypes[0] = CodecSrc::kGetFromCanvas_DstColorType; |
| 291 | colorTypes[1] = CodecSrc::kIndex8_Always_DstColorType; |
| 292 | numColorTypes = 2; |
| 293 | break; |
| 294 | default: |
| 295 | colorTypes[0] = CodecSrc::kGetFromCanvas_DstColorType; |
| 296 | numColorTypes = 1; |
| 297 | break; |
| 298 | } |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 299 | |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 300 | for (float scale : nativeScales) { |
scroggo | 0df0e43 | 2015-08-07 12:53:25 -0700 | [diff] [blame] | 301 | if (scale != 1.0f && (path.endsWith(".webp") || path.endsWith(".WEBP"))) { |
| 302 | // FIXME: skbug.com/4038 Scaling webp seems to leave some pixels uninitialized/ |
| 303 | // compute their colors based on uninitialized values. |
| 304 | continue; |
| 305 | } |
msarett | 0a24297 | 2015-06-11 14:27:27 -0700 | [diff] [blame] | 306 | |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 307 | for (CodecSrc::Mode mode : nativeModes) { |
| 308 | for (uint32_t i = 0; i < numColorTypes; i++) { |
| 309 | push_codec_src(path, mode, colorTypes[i], scale); |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 310 | } |
| 311 | } |
msarett | 0a24297 | 2015-06-11 14:27:27 -0700 | [diff] [blame] | 312 | } |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 313 | |
| 314 | // SkScaledCodec Scales |
| 315 | // The native scales are included to make sure that SkScaledCodec defaults to the native |
| 316 | // scaling strategy when possible. |
| 317 | // 0.1, 0.16, 0.2 etc allow us to test SkScaledCodec with sampleSize 10, 6, 5, etc. |
| 318 | // 0.4, 0.7 etc allow to test what happens when the client requests a scale that |
| 319 | // does not exactly match a sampleSize or native scaling capability. |
msarett | 6c50a8f | 2015-09-18 11:24:44 -0700 | [diff] [blame] | 320 | const float samplingScales[] = { 0.1f, 0.125f, 0.167f, 0.2f, 0.25f, 0.333f, 0.375f, 0.4f, 0.5f, |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 321 | 0.6f, 0.625f, 0.750f, 0.8f, 0.875f, 1.0f }; |
| 322 | |
| 323 | for (float scale : samplingScales) { |
| 324 | if (scale != 1.0f && (path.endsWith(".webp") || path.endsWith(".WEBP"))) { |
| 325 | // FIXME: skbug.com/4038 Scaling webp seems to leave some pixels uninitialized/ |
| 326 | // compute their colors based on uninitialized values. |
| 327 | continue; |
| 328 | } |
| 329 | |
| 330 | for (uint32_t i = 0; i < numColorTypes; i++) { |
| 331 | push_codec_src(path, CodecSrc::kScaledCodec_Mode, colorTypes[i], scale); |
| 332 | } |
| 333 | } |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 334 | } |
| 335 | |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 336 | static bool brd_color_type_supported(SkBitmapRegionDecoderInterface::Strategy strategy, |
| 337 | CodecSrc::DstColorType dstColorType) { |
| 338 | switch (strategy) { |
| 339 | case SkBitmapRegionDecoderInterface::kCanvas_Strategy: |
| 340 | if (CodecSrc::kGetFromCanvas_DstColorType == dstColorType) { |
| 341 | return true; |
| 342 | } |
| 343 | return false; |
| 344 | case SkBitmapRegionDecoderInterface::kOriginal_Strategy: |
| 345 | switch (dstColorType) { |
| 346 | case CodecSrc::kGetFromCanvas_DstColorType: |
| 347 | case CodecSrc::kIndex8_Always_DstColorType: |
| 348 | case CodecSrc::kGrayscale_Always_DstColorType: |
| 349 | return true; |
| 350 | default: |
| 351 | return false; |
| 352 | } |
| 353 | default: |
| 354 | SkASSERT(false); |
| 355 | return false; |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | static void push_brd_src(Path path, SkBitmapRegionDecoderInterface::Strategy strategy, |
| 360 | CodecSrc::DstColorType dstColorType, BRDSrc::Mode mode, uint32_t sampleSize) { |
| 361 | SkString folder; |
| 362 | switch (strategy) { |
| 363 | case SkBitmapRegionDecoderInterface::kCanvas_Strategy: |
| 364 | folder.append("brd_canvas"); |
| 365 | break; |
| 366 | case SkBitmapRegionDecoderInterface::kOriginal_Strategy: |
| 367 | folder.append("brd_sample"); |
| 368 | break; |
| 369 | default: |
| 370 | SkASSERT(false); |
| 371 | return; |
| 372 | } |
| 373 | |
| 374 | switch (mode) { |
| 375 | case BRDSrc::kFullImage_Mode: |
| 376 | break; |
| 377 | case BRDSrc::kDivisor_Mode: |
| 378 | folder.append("_divisor"); |
| 379 | break; |
| 380 | default: |
| 381 | SkASSERT(false); |
| 382 | return; |
| 383 | } |
| 384 | |
| 385 | switch (dstColorType) { |
| 386 | case CodecSrc::kGetFromCanvas_DstColorType: |
| 387 | break; |
| 388 | case CodecSrc::kIndex8_Always_DstColorType: |
| 389 | folder.append("_kIndex"); |
| 390 | break; |
| 391 | case CodecSrc::kGrayscale_Always_DstColorType: |
| 392 | folder.append("_kGray"); |
| 393 | break; |
| 394 | default: |
| 395 | SkASSERT(false); |
| 396 | return; |
| 397 | } |
| 398 | |
| 399 | if (1 != sampleSize) { |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 400 | folder.appendf("_%.3f", get_scale_from_sample_size(sampleSize)); |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | BRDSrc* src = new BRDSrc(path, strategy, mode, dstColorType, sampleSize); |
| 404 | push_src("image", folder, src); |
| 405 | } |
| 406 | |
| 407 | static void push_brd_srcs(Path path) { |
| 408 | |
| 409 | const SkBitmapRegionDecoderInterface::Strategy strategies[] = { |
| 410 | SkBitmapRegionDecoderInterface::kCanvas_Strategy, |
| 411 | SkBitmapRegionDecoderInterface::kOriginal_Strategy |
| 412 | }; |
| 413 | |
msarett | 6efbe05 | 2015-09-11 09:01:16 -0700 | [diff] [blame] | 414 | const uint32_t sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; |
| 415 | |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 416 | // We will only test to one backend (8888), but we will test all of the |
| 417 | // color types that we need to decode to on this backend. |
| 418 | const CodecSrc::DstColorType dstColorTypes[] = { |
| 419 | CodecSrc::kGetFromCanvas_DstColorType, |
| 420 | CodecSrc::kIndex8_Always_DstColorType, |
| 421 | CodecSrc::kGrayscale_Always_DstColorType, |
| 422 | }; |
| 423 | |
| 424 | const BRDSrc::Mode modes[] = { |
| 425 | BRDSrc::kFullImage_Mode, |
| 426 | BRDSrc::kDivisor_Mode |
| 427 | }; |
| 428 | |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 429 | for (SkBitmapRegionDecoderInterface::Strategy strategy : strategies) { |
msarett | 6efbe05 | 2015-09-11 09:01:16 -0700 | [diff] [blame] | 430 | |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 431 | // We disable png testing for kOriginal_Strategy because the implementation leaks |
| 432 | // memory in our forked libpng. |
| 433 | // TODO (msarett): Decide if we want to test pngs in this mode and how we might do this. |
| 434 | if (SkBitmapRegionDecoderInterface::kOriginal_Strategy == strategy && |
| 435 | (path.endsWith(".png") || path.endsWith(".PNG"))) { |
| 436 | continue; |
| 437 | } |
msarett | 6efbe05 | 2015-09-11 09:01:16 -0700 | [diff] [blame] | 438 | for (uint32_t sampleSize : sampleSizes) { |
| 439 | |
| 440 | // kOriginal_Strategy does not work for jpegs that are scaled to non-powers of two. |
| 441 | // We don't need to test this. We know it doesn't work, and it causes images with |
| 442 | // uninitialized memory to show up on Gold. |
| 443 | if (SkBitmapRegionDecoderInterface::kOriginal_Strategy == strategy && |
| 444 | (path.endsWith(".jpg") || path.endsWith(".JPG") || |
| 445 | path.endsWith(".jpeg") || path.endsWith(".JPEG")) && !SkIsPow2(sampleSize)) { |
| 446 | continue; |
| 447 | } |
| 448 | for (CodecSrc::DstColorType dstColorType : dstColorTypes) { |
| 449 | if (brd_color_type_supported(strategy, dstColorType)) { |
| 450 | for (BRDSrc::Mode mode : modes) { |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 451 | push_brd_src(path, strategy, dstColorType, mode, sampleSize); |
| 452 | } |
| 453 | } |
| 454 | } |
| 455 | } |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | static bool brd_supported(const char* ext) { |
msarett | 8c8f22a | 2015-04-01 06:58:48 -0700 | [diff] [blame] | 460 | static const char* const exts[] = { |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 461 | "jpg", "jpeg", "png", "webp", |
| 462 | "JPG", "JPEG", "PNG", "WEBP", |
msarett | 8c8f22a | 2015-04-01 06:58:48 -0700 | [diff] [blame] | 463 | }; |
| 464 | |
| 465 | for (uint32_t i = 0; i < SK_ARRAY_COUNT(exts); i++) { |
| 466 | if (0 == strcmp(exts[i], ext)) { |
| 467 | return true; |
| 468 | } |
| 469 | } |
| 470 | return false; |
scroggo | 9b77ddd | 2015-03-19 06:03:39 -0700 | [diff] [blame] | 471 | } |
| 472 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 473 | static void gather_srcs() { |
| 474 | for (const skiagm::GMRegistry* r = skiagm::GMRegistry::Head(); r; r = r->next()) { |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 475 | push_src("gm", "", new GMSrc(r->factory())); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 476 | } |
halcanary | fc37ad1 | 2015-01-30 07:31:19 -0800 | [diff] [blame] | 477 | for (int i = 0; i < FLAGS_skps.count(); i++) { |
| 478 | const char* path = FLAGS_skps[i]; |
| 479 | if (sk_isdir(path)) { |
| 480 | SkOSFile::Iter it(path, "skp"); |
| 481 | for (SkString file; it.next(&file); ) { |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 482 | push_src("skp", "", new SKPSrc(SkOSPath::Join(path, file.c_str()))); |
halcanary | fc37ad1 | 2015-01-30 07:31:19 -0800 | [diff] [blame] | 483 | } |
| 484 | } else { |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 485 | push_src("skp", "", new SKPSrc(path)); |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 486 | } |
| 487 | } |
halcanary | 23b03c3 | 2015-01-30 09:58:58 -0800 | [diff] [blame] | 488 | static const char* const exts[] = { |
| 489 | "bmp", "gif", "jpg", "jpeg", "png", "webp", "ktx", "astc", "wbmp", "ico", |
| 490 | "BMP", "GIF", "JPG", "JPEG", "PNG", "WEBP", "KTX", "ASTC", "WBMP", "ICO", |
| 491 | }; |
| 492 | for (int i = 0; i < FLAGS_images.count(); i++) { |
| 493 | const char* flag = FLAGS_images[i]; |
| 494 | if (sk_isdir(flag)) { |
| 495 | for (size_t j = 0; j < SK_ARRAY_COUNT(exts); j++) { |
| 496 | SkOSFile::Iter it(flag, exts[j]); |
| 497 | for (SkString file; it.next(&file); ) { |
| 498 | SkString path = SkOSPath::Join(flag, file.c_str()); |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 499 | push_src("image", "decode", new ImageSrc(path)); // Decode entire image |
| 500 | push_src("image", "subset", new ImageSrc(path, 2)); // Decode into 2x2 subsets |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 501 | push_codec_srcs(path); |
| 502 | if (brd_supported(exts[j])) { |
| 503 | push_brd_srcs(path); |
scroggo | 9b77ddd | 2015-03-19 06:03:39 -0700 | [diff] [blame] | 504 | } |
halcanary | 23b03c3 | 2015-01-30 09:58:58 -0800 | [diff] [blame] | 505 | } |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 506 | } |
halcanary | 23b03c3 | 2015-01-30 09:58:58 -0800 | [diff] [blame] | 507 | } else if (sk_exists(flag)) { |
| 508 | // 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] | 509 | push_src("image", "decode", new ImageSrc(flag)); // Decode entire image. |
| 510 | push_src("image", "subset", new ImageSrc(flag, 2)); // Decode into 2 x 2 subsets |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 511 | push_codec_srcs(flag); |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 512 | push_brd_srcs(flag); |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 513 | } |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 514 | } |
| 515 | } |
| 516 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 517 | static GrGLStandard get_gpu_api() { |
| 518 | if (FLAGS_gpuAPI.contains("gl")) { return kGL_GrGLStandard; } |
| 519 | if (FLAGS_gpuAPI.contains("gles")) { return kGLES_GrGLStandard; } |
| 520 | return kNone_GrGLStandard; |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 521 | } |
| 522 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 523 | static void push_sink(const char* tag, Sink* s) { |
| 524 | SkAutoTDelete<Sink> sink(s); |
| 525 | if (!FLAGS_config.contains(tag)) { |
| 526 | return; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 527 | } |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 528 | // Try a simple Src as a canary. If it fails, skip this sink. |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 529 | struct : public Src { |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 530 | Error draw(SkCanvas* c) const override { |
| 531 | c->drawRect(SkRect::MakeWH(1,1), SkPaint()); |
| 532 | return ""; |
| 533 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 534 | SkISize size() const override { return SkISize::Make(16, 16); } |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 535 | Name name() const override { return "justOneRect"; } |
| 536 | } justOneRect; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 537 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 538 | SkBitmap bitmap; |
| 539 | SkDynamicMemoryWStream stream; |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 540 | SkString log; |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 541 | Error err = sink->draw(justOneRect, &bitmap, &stream, &log); |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 542 | if (err.isFatal()) { |
mtklein | 05641a5 | 2015-04-21 10:49:13 -0700 | [diff] [blame] | 543 | SkDebugf("Could not run %s: %s\n", tag, err.c_str()); |
| 544 | exit(1); |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 545 | } |
| 546 | |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 547 | TaggedSink& ts = gSinks.push_back(); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 548 | ts.reset(sink.detach()); |
| 549 | ts.tag = tag; |
| 550 | } |
| 551 | |
| 552 | static bool gpu_supported() { |
| 553 | #if SK_SUPPORT_GPU |
| 554 | return FLAGS_gpu; |
| 555 | #else |
| 556 | return false; |
| 557 | #endif |
| 558 | } |
| 559 | |
| 560 | static Sink* create_sink(const char* tag) { |
| 561 | #define SINK(t, sink, ...) if (0 == strcmp(t, tag)) { return new sink(__VA_ARGS__); } |
| 562 | if (gpu_supported()) { |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 563 | typedef GrContextFactory Gr; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 564 | const GrGLStandard api = get_gpu_api(); |
hendrikw | 885bf09 | 2015-08-27 10:38:39 -0700 | [diff] [blame] | 565 | SINK("gpunull", GPUSink, Gr::kNull_GLContextType, api, 0, false, FLAGS_gpu_threading); |
| 566 | SINK("gpudebug", GPUSink, Gr::kDebug_GLContextType, api, 0, false, FLAGS_gpu_threading); |
| 567 | SINK("gpu", GPUSink, Gr::kNative_GLContextType, api, 0, false, FLAGS_gpu_threading); |
| 568 | SINK("gpudft", GPUSink, Gr::kNative_GLContextType, api, 0, true, FLAGS_gpu_threading); |
| 569 | SINK("msaa4", GPUSink, Gr::kNative_GLContextType, api, 4, false, FLAGS_gpu_threading); |
| 570 | SINK("msaa16", GPUSink, Gr::kNative_GLContextType, api, 16, false, FLAGS_gpu_threading); |
bsalomon | 90e8ab7 | 2015-09-08 10:26:51 -0700 | [diff] [blame] | 571 | SINK("nvprmsaa4", GPUSink, Gr::kNVPR_GLContextType, api, 4, true, FLAGS_gpu_threading); |
| 572 | SINK("nvprmsaa16", GPUSink, Gr::kNVPR_GLContextType, api, 16, true, FLAGS_gpu_threading); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 573 | #if SK_ANGLE |
hendrikw | 885bf09 | 2015-08-27 10:38:39 -0700 | [diff] [blame] | 574 | SINK("angle", GPUSink, Gr::kANGLE_GLContextType, api, 0, false, FLAGS_gpu_threading); |
hendrikw | eddbefb | 2015-09-11 13:07:29 -0700 | [diff] [blame] | 575 | SINK("angle-gl", GPUSink, Gr::kANGLE_GL_GLContextType, api, 0, false, FLAGS_gpu_threading); |
hendrikw | 885bf09 | 2015-08-27 10:38:39 -0700 | [diff] [blame] | 576 | #endif |
| 577 | #if SK_COMMAND_BUFFER |
| 578 | SINK("commandbuffer", GPUSink, Gr::kCommandBuffer_GLContextType, api, 0, false, FLAGS_gpu_threading); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 579 | #endif |
| 580 | #if SK_MESA |
hendrikw | 885bf09 | 2015-08-27 10:38:39 -0700 | [diff] [blame] | 581 | SINK("mesa", GPUSink, Gr::kMESA_GLContextType, api, 0, false, FLAGS_gpu_threading); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 582 | #endif |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 583 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 584 | |
tomhudson | eebc39a | 2015-02-23 12:18:05 -0800 | [diff] [blame] | 585 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 586 | SINK("hwui", HWUISink); |
| 587 | #endif |
| 588 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 589 | if (FLAGS_cpu) { |
| 590 | SINK("565", RasterSink, kRGB_565_SkColorType); |
| 591 | SINK("8888", RasterSink, kN32_SkColorType); |
halcanary | c11c62f | 2015-09-28 11:51:54 -0700 | [diff] [blame^] | 592 | SINK("pdf", PDFSink, "Pdfium"); |
| 593 | SINK("pdf_poppler", PDFSink, "Poppler"); |
mtklein | 9c3f17d | 2015-01-28 11:35:18 -0800 | [diff] [blame] | 594 | SINK("skp", SKPSink); |
mtklein | 8a4527e | 2015-01-31 20:00:58 -0800 | [diff] [blame] | 595 | SINK("svg", SVGSink); |
| 596 | SINK("null", NullSink); |
halcanary | 47ef4d5 | 2015-03-03 09:13:09 -0800 | [diff] [blame] | 597 | SINK("xps", XPSSink); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 598 | } |
| 599 | #undef SINK |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 600 | return nullptr; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 601 | } |
| 602 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 603 | static Sink* create_via(const char* tag, Sink* wrapped) { |
| 604 | #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] | 605 | VIA("twice", ViaTwice, wrapped); |
| 606 | VIA("pipe", ViaPipe, wrapped); |
| 607 | VIA("serialize", ViaSerialization, wrapped); |
| 608 | VIA("2ndpic", ViaSecondPicture, wrapped); |
mtklein | d31c13d | 2015-05-05 12:59:56 -0700 | [diff] [blame] | 609 | VIA("sp", ViaSingletonPictures, wrapped); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 610 | VIA("tiles", ViaTiles, 256, 256, nullptr, wrapped); |
mtklein | 7edca21 | 2015-01-21 13:18:51 -0800 | [diff] [blame] | 611 | VIA("tiles_rt", ViaTiles, 256, 256, new SkRTreeFactory, wrapped); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 612 | |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 613 | if (FLAGS_matrix.count() == 4) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 614 | SkMatrix m; |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 615 | m.reset(); |
| 616 | m.setScaleX((SkScalar)atof(FLAGS_matrix[0])); |
| 617 | m.setSkewX ((SkScalar)atof(FLAGS_matrix[1])); |
| 618 | m.setSkewY ((SkScalar)atof(FLAGS_matrix[2])); |
| 619 | m.setScaleY((SkScalar)atof(FLAGS_matrix[3])); |
| 620 | VIA("matrix", ViaMatrix, m, wrapped); |
| 621 | VIA("upright", ViaUpright, m, wrapped); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 622 | } |
tomhudson | 64de1e1 | 2015-03-05 08:01:07 -0800 | [diff] [blame] | 623 | |
| 624 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 625 | VIA("androidsdk", ViaAndroidSDK, wrapped); |
| 626 | #endif |
| 627 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 628 | #undef VIA |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 629 | return nullptr; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 630 | } |
| 631 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 632 | static void gather_sinks() { |
| 633 | for (int i = 0; i < FLAGS_config.count(); i++) { |
| 634 | const char* config = FLAGS_config[i]; |
| 635 | SkTArray<SkString> parts; |
| 636 | SkStrSplit(config, "-", &parts); |
| 637 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 638 | Sink* sink = nullptr; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 639 | for (int i = parts.count(); i-- > 0;) { |
| 640 | const char* part = parts[i].c_str(); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 641 | Sink* next = (sink == nullptr) ? create_sink(part) : create_via(part, sink); |
| 642 | if (next == nullptr) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 643 | SkDebugf("Skipping %s: Don't understand '%s'.\n", config, part); |
| 644 | delete sink; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 645 | sink = nullptr; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 646 | break; |
| 647 | } |
| 648 | sink = next; |
| 649 | } |
| 650 | if (sink) { |
| 651 | push_sink(config, sink); |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 652 | } |
| 653 | } |
| 654 | } |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 655 | |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 656 | static bool dump_png(SkBitmap bitmap, const char* path, const char* md5) { |
| 657 | const int w = bitmap.width(), |
| 658 | h = bitmap.height(); |
| 659 | |
| 660 | // First get the bitmap into N32 color format. The next step will work only there. |
| 661 | if (bitmap.colorType() != kN32_SkColorType) { |
| 662 | SkBitmap n32; |
| 663 | if (!bitmap.copyTo(&n32, kN32_SkColorType)) { |
| 664 | return false; |
| 665 | } |
| 666 | bitmap = n32; |
| 667 | } |
| 668 | |
| 669 | // Convert our N32 bitmap into unpremul RGBA for libpng. |
| 670 | SkAutoTMalloc<uint32_t> rgba(w*h); |
| 671 | if (!bitmap.readPixels(SkImageInfo::Make(w,h, kRGBA_8888_SkColorType, kUnpremul_SkAlphaType), |
| 672 | rgba, 4*w, 0,0)) { |
| 673 | return false; |
| 674 | } |
| 675 | |
| 676 | // We don't need bitmap anymore. Might as well drop our ref. |
mtklein | fccb77d | 2015-08-24 14:13:29 -0700 | [diff] [blame] | 677 | bitmap.reset(); |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 678 | |
mtklein | c64137c | 2015-08-25 10:56:08 -0700 | [diff] [blame] | 679 | FILE* f = fopen(path, "wb"); |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 680 | if (!f) { return false; } |
| 681 | |
| 682 | png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr); |
| 683 | if (!png) { |
| 684 | fclose(f); |
| 685 | return false; |
| 686 | } |
| 687 | |
| 688 | png_infop info = png_create_info_struct(png); |
| 689 | if (!info) { |
| 690 | png_destroy_write_struct(&png, &info); |
| 691 | fclose(f); |
| 692 | return false; |
| 693 | } |
| 694 | |
mtklein | d69ece6 | 2015-09-10 10:37:44 -0700 | [diff] [blame] | 695 | SkString description; |
| 696 | description.append("Key: "); |
| 697 | for (int i = 0; i < FLAGS_key.count(); i++) { |
| 698 | description.appendf("%s ", FLAGS_key[i]); |
| 699 | } |
| 700 | description.append("Properties: "); |
| 701 | for (int i = 0; i < FLAGS_properties.count(); i++) { |
| 702 | description.appendf("%s ", FLAGS_properties[i]); |
| 703 | } |
| 704 | description.appendf("MD5: %s", md5); |
| 705 | |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 706 | png_text text[2]; |
| 707 | text[0].key = (png_charp)"Author"; |
| 708 | text[0].text = (png_charp)"DM dump_png()"; |
| 709 | text[0].compression = PNG_TEXT_COMPRESSION_NONE; |
| 710 | text[1].key = (png_charp)"Description"; |
mtklein | d69ece6 | 2015-09-10 10:37:44 -0700 | [diff] [blame] | 711 | text[1].text = (png_charp)description.c_str(); |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 712 | text[1].compression = PNG_TEXT_COMPRESSION_NONE; |
| 713 | png_set_text(png, info, text, 2); |
| 714 | |
| 715 | png_init_io(png, f); |
| 716 | png_set_IHDR(png, info, (png_uint_32)w, (png_uint_32)h, 8, |
| 717 | PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, |
| 718 | PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); |
| 719 | png_write_info(png, info); |
| 720 | for (int j = 0; j < h; j++) { |
| 721 | png_bytep row = (png_bytep)(rgba.get() + w*j); |
| 722 | png_write_rows(png, &row, 1); |
| 723 | } |
| 724 | png_write_end(png, info); |
| 725 | |
| 726 | png_destroy_write_struct(&png, &info); |
| 727 | fclose(f); |
| 728 | return true; |
| 729 | } |
| 730 | |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 731 | static bool match(const char* needle, const char* haystack) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 732 | return 0 == strcmp("_", needle) || nullptr != strstr(haystack, needle); |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 733 | } |
| 734 | |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 735 | static ImplicitString is_blacklisted(const char* sink, const char* src, |
| 736 | const char* srcOptions, const char* name) { |
mtklein | 0d243ff | 2015-04-03 07:51:00 -0700 | [diff] [blame] | 737 | for (int i = 0; i < FLAGS_blacklist.count() - 3; i += 4) { |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 738 | if (match(FLAGS_blacklist[i+0], sink) && |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 739 | match(FLAGS_blacklist[i+1], src) && |
| 740 | match(FLAGS_blacklist[i+2], srcOptions) && |
| 741 | match(FLAGS_blacklist[i+3], name)) { |
| 742 | return SkStringPrintf("%s %s %s %s", |
| 743 | FLAGS_blacklist[i+0], FLAGS_blacklist[i+1], |
| 744 | FLAGS_blacklist[i+2], FLAGS_blacklist[i+3]); |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 745 | } |
| 746 | } |
| 747 | return ""; |
| 748 | } |
| 749 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 750 | // The finest-grained unit of work we can run: draw a single Src into a single Sink, |
| 751 | // report any errors, and perhaps write out the output: a .png of the bitmap, or a raw stream. |
| 752 | struct Task { |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 753 | Task(const TaggedSrc& src, const TaggedSink& sink) : src(src), sink(sink) {} |
| 754 | const TaggedSrc& src; |
| 755 | const TaggedSink& sink; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 756 | |
| 757 | static void Run(Task* task) { |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 758 | SkString name = task->src->name(); |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 759 | |
| 760 | // We'll skip drawing this Src/Sink pair if: |
| 761 | // - the Src vetoes the Sink; |
| 762 | // - this Src / Sink combination is on the blacklist; |
| 763 | // - it's a dry run. |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 764 | SkString note(task->src->veto(task->sink->flags()) ? " (veto)" : ""); |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 765 | SkString whyBlacklisted = is_blacklisted(task->sink.tag, task->src.tag.c_str(), |
| 766 | task->src.options.c_str(), name.c_str()); |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 767 | if (!whyBlacklisted.isEmpty()) { |
| 768 | note.appendf(" (--blacklist %s)", whyBlacklisted.c_str()); |
| 769 | } |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 770 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 771 | SkString log; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 772 | WallTimer timer; |
| 773 | timer.start(); |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 774 | if (!FLAGS_dryRun && note.isEmpty()) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 775 | SkBitmap bitmap; |
| 776 | SkDynamicMemoryWStream stream; |
bsalomon | 821e10e | 2015-06-04 14:15:33 -0700 | [diff] [blame] | 777 | if (FLAGS_pre_log) { |
| 778 | SkDebugf("\nRunning %s->%s", name.c_str(), task->sink.tag); |
| 779 | } |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 780 | start(task->sink.tag, task->src.tag, task->src.options, name.c_str()); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 781 | Error err = task->sink->draw(*task->src, &bitmap, &stream, &log); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 782 | if (!err.isEmpty()) { |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 783 | timer.end(); |
| 784 | if (err.isFatal()) { |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 785 | fail(SkStringPrintf("%s %s %s %s: %s", |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 786 | task->sink.tag, |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 787 | task->src.tag.c_str(), |
| 788 | task->src.options.c_str(), |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 789 | name.c_str(), |
| 790 | err.c_str())); |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 791 | } else { |
| 792 | note.appendf(" (skipped: %s)", err.c_str()); |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 793 | } |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 794 | done(timer.fWall, task->sink.tag, task->src.tag, task->src.options, |
| 795 | name, note, log); |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 796 | return; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 797 | } |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 798 | SkAutoTDelete<SkStreamAsset> data(stream.detachAsStream()); |
| 799 | |
| 800 | SkString md5; |
| 801 | if (!FLAGS_writePath.isEmpty() || !FLAGS_readPath.isEmpty()) { |
| 802 | SkMD5 hash; |
| 803 | if (data->getLength()) { |
| 804 | hash.writeStream(data, data->getLength()); |
| 805 | data->rewind(); |
| 806 | } else { |
mtklein | 3840846 | 2015-07-08 07:25:27 -0700 | [diff] [blame] | 807 | // If we're BGRA (Linux, Windows), swizzle over to RGBA (Mac, Android). |
| 808 | // This helps eliminate multiple 0-pixel-diff hashes on gold.skia.org. |
| 809 | // (Android's general slow speed breaks the tie arbitrarily in RGBA's favor.) |
| 810 | // We might consider promoting 565 to RGBA too. |
| 811 | if (bitmap.colorType() == kBGRA_8888_SkColorType) { |
| 812 | SkBitmap swizzle; |
| 813 | SkAssertResult(bitmap.copyTo(&swizzle, kRGBA_8888_SkColorType)); |
| 814 | hash.write(swizzle.getPixels(), swizzle.getSize()); |
| 815 | } else { |
| 816 | hash.write(bitmap.getPixels(), bitmap.getSize()); |
| 817 | } |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 818 | } |
| 819 | SkMD5::Digest digest; |
| 820 | hash.finish(digest); |
| 821 | for (int i = 0; i < 16; i++) { |
| 822 | md5.appendf("%02x", digest.data[i]); |
| 823 | } |
| 824 | } |
| 825 | |
| 826 | if (!FLAGS_readPath.isEmpty() && |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 827 | !gGold.contains(Gold(task->sink.tag, task->src.tag.c_str(), |
| 828 | task->src.options.c_str(), name, md5))) { |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 829 | fail(SkStringPrintf("%s not found for %s %s %s %s in %s", |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 830 | md5.c_str(), |
| 831 | task->sink.tag, |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 832 | task->src.tag.c_str(), |
| 833 | task->src.options.c_str(), |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 834 | name.c_str(), |
| 835 | FLAGS_readPath[0])); |
| 836 | } |
| 837 | |
mtklein | b0531a7 | 2015-04-07 13:38:48 -0700 | [diff] [blame] | 838 | if (!FLAGS_writePath.isEmpty()) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 839 | const char* ext = task->sink->fileExtension(); |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 840 | if (data->getLength()) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 841 | WriteToDisk(*task, md5, ext, data, data->getLength(), nullptr); |
halcanary | 022afb8 | 2015-01-30 11:00:12 -0800 | [diff] [blame] | 842 | SkASSERT(bitmap.drawsNothing()); |
| 843 | } else if (!bitmap.drawsNothing()) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 844 | WriteToDisk(*task, md5, ext, nullptr, 0, &bitmap); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 845 | } |
| 846 | } |
| 847 | } |
| 848 | timer.end(); |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 849 | done(timer.fWall, task->sink.tag, task->src.tag.c_str(), task->src.options.c_str(), name, |
| 850 | note, log); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | static void WriteToDisk(const Task& task, |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 854 | SkString md5, |
| 855 | const char* ext, |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 856 | SkStream* data, size_t len, |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 857 | const SkBitmap* bitmap) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 858 | JsonWriter::BitmapResult result; |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 859 | result.name = task.src->name(); |
| 860 | result.config = task.sink.tag; |
| 861 | result.sourceType = task.src.tag; |
| 862 | result.sourceOptions = task.src.options; |
| 863 | result.ext = ext; |
| 864 | result.md5 = md5; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 865 | JsonWriter::AddBitmapResult(result); |
| 866 | |
mtklein | b0531a7 | 2015-04-07 13:38:48 -0700 | [diff] [blame] | 867 | // If an MD5 is uninteresting, we want it noted in the JSON file, |
| 868 | // but don't want to dump it out as a .png (or whatever ext is). |
| 869 | if (gUninterestingHashes.contains(md5)) { |
| 870 | return; |
| 871 | } |
| 872 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 873 | const char* dir = FLAGS_writePath[0]; |
| 874 | if (0 == strcmp(dir, "@")) { // Needed for iOS. |
| 875 | dir = FLAGS_resourcePath[0]; |
| 876 | } |
| 877 | sk_mkdir(dir); |
| 878 | |
| 879 | SkString path; |
| 880 | if (FLAGS_nameByHash) { |
| 881 | path = SkOSPath::Join(dir, result.md5.c_str()); |
| 882 | path.append("."); |
| 883 | path.append(ext); |
| 884 | if (sk_exists(path.c_str())) { |
| 885 | return; // Content-addressed. If it exists already, we're done. |
| 886 | } |
| 887 | } else { |
| 888 | path = SkOSPath::Join(dir, task.sink.tag); |
| 889 | sk_mkdir(path.c_str()); |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 890 | path = SkOSPath::Join(path.c_str(), task.src.tag.c_str()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 891 | sk_mkdir(path.c_str()); |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 892 | if (strcmp(task.src.options.c_str(), "") != 0) { |
| 893 | path = SkOSPath::Join(path.c_str(), task.src.options.c_str()); |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 894 | sk_mkdir(path.c_str()); |
| 895 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 896 | path = SkOSPath::Join(path.c_str(), task.src->name().c_str()); |
| 897 | path.append("."); |
| 898 | path.append(ext); |
| 899 | } |
| 900 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 901 | if (bitmap) { |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 902 | if (!dump_png(*bitmap, path.c_str(), result.md5.c_str())) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 903 | fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str())); |
| 904 | return; |
| 905 | } |
| 906 | } else { |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 907 | SkFILEWStream file(path.c_str()); |
| 908 | if (!file.isValid()) { |
| 909 | fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str())); |
| 910 | return; |
| 911 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 912 | if (!file.writeStream(data, len)) { |
| 913 | fail(SkStringPrintf("Can't write to %s.\n", path.c_str())); |
| 914 | return; |
| 915 | } |
| 916 | } |
| 917 | } |
| 918 | }; |
| 919 | |
| 920 | // Run all tasks in the same enclave serially on the same thread. |
| 921 | // They can't possibly run concurrently with each other. |
| 922 | static void run_enclave(SkTArray<Task>* tasks) { |
| 923 | for (int i = 0; i < tasks->count(); i++) { |
| 924 | Task::Run(tasks->begin() + i); |
| 925 | } |
| 926 | } |
| 927 | |
| 928 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 929 | |
| 930 | // Unit tests don't fit so well into the Src/Sink model, so we give them special treatment. |
| 931 | |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 932 | static SkTDArray<skiatest::Test> gThreadedTests, gGPUTests; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 933 | |
| 934 | static void gather_tests() { |
mtklein | 6c5fed2 | 2015-01-20 13:47:23 -0800 | [diff] [blame] | 935 | if (!FLAGS_src.contains("tests")) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 936 | return; |
| 937 | } |
mtklein | 6393c06 | 2015-04-27 08:45:01 -0700 | [diff] [blame] | 938 | for (const skiatest::TestRegistry* r = skiatest::TestRegistry::Head(); r; r = r->next()) { |
| 939 | if (!in_shard()) { |
| 940 | continue; |
| 941 | } |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 942 | // Despite its name, factory() is returning a reference to |
| 943 | // link-time static const POD data. |
| 944 | const skiatest::Test& test = r->factory(); |
| 945 | if (SkCommandLineFlags::ShouldSkip(FLAGS_match, test.name)) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 946 | continue; |
| 947 | } |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 948 | if (test.needsGpu && gpu_supported()) { |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 949 | (FLAGS_gpu_threading ? gThreadedTests : gGPUTests).push(test); |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 950 | } else if (!test.needsGpu && FLAGS_cpu) { |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 951 | gThreadedTests.push(test); |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 952 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 953 | } |
| 954 | } |
| 955 | |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 956 | static void run_test(skiatest::Test* test) { |
| 957 | struct : public skiatest::Reporter { |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 958 | void reportFailed(const skiatest::Failure& failure) override { |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 959 | fail(failure.toString()); |
| 960 | JsonWriter::AddTestFailure(failure); |
| 961 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 962 | bool allowExtendedTest() const override { |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 963 | return FLAGS_pathOpsExtended; |
| 964 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 965 | bool verbose() const override { return FLAGS_veryVerbose; } |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 966 | } reporter; |
djsollen | 824996a | 2015-06-12 12:06:22 -0700 | [diff] [blame] | 967 | |
| 968 | SkString note; |
| 969 | SkString whyBlacklisted = is_blacklisted("_", "tests", "_", test->name); |
| 970 | if (!whyBlacklisted.isEmpty()) { |
| 971 | note.appendf(" (--blacklist %s)", whyBlacklisted.c_str()); |
| 972 | } |
| 973 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 974 | WallTimer timer; |
| 975 | timer.start(); |
djsollen | 824996a | 2015-06-12 12:06:22 -0700 | [diff] [blame] | 976 | if (!FLAGS_dryRun && whyBlacklisted.isEmpty()) { |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 977 | start("unit", "test", "", test->name); |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 978 | GrContextFactory factory; |
bsalomon | 821e10e | 2015-06-04 14:15:33 -0700 | [diff] [blame] | 979 | if (FLAGS_pre_log) { |
| 980 | SkDebugf("\nRunning test %s", test->name); |
| 981 | } |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 982 | test->proc(&reporter, &factory); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 983 | } |
| 984 | timer.end(); |
djsollen | 824996a | 2015-06-12 12:06:22 -0700 | [diff] [blame] | 985 | done(timer.fWall, "unit", "test", "", test->name, note, ""); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 989 | |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 990 | // If we're isolating all GPU-bound work to one thread (the default), this function runs all that. |
| 991 | static void run_enclave_and_gpu_tests(SkTArray<Task>* tasks) { |
| 992 | run_enclave(tasks); |
| 993 | for (int i = 0; i < gGPUTests.count(); i++) { |
| 994 | run_test(&gGPUTests[i]); |
| 995 | } |
| 996 | } |
| 997 | |
mtklein | de6fc2b | 2015-03-12 06:28:54 -0700 | [diff] [blame] | 998 | // Some runs (mostly, Valgrind) are so slow that the bot framework thinks we've hung. |
| 999 | // 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] | 1000 | static void start_keepalive() { |
| 1001 | struct Loop { |
| 1002 | static void forever(void*) { |
| 1003 | for (;;) { |
| 1004 | static const int kSec = 300; |
| 1005 | #if defined(SK_BUILD_FOR_WIN) |
| 1006 | Sleep(kSec * 1000); |
| 1007 | #else |
| 1008 | sleep(kSec); |
| 1009 | #endif |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 1010 | SkString running; |
| 1011 | { |
| 1012 | SkAutoMutexAcquire lock(gRunningMutex); |
| 1013 | for (int i = 0; i < gRunning.count(); i++) { |
| 1014 | running.appendf("\n\t%s", gRunning[i].c_str()); |
| 1015 | } |
| 1016 | } |
| 1017 | SkDebugf("\nCurrently running:%s\n", running.c_str()); |
mtklein | 2e1c47e | 2015-03-12 07:16:56 -0700 | [diff] [blame] | 1018 | } |
| 1019 | } |
| 1020 | }; |
| 1021 | static SkThread* intentionallyLeaked = new SkThread(Loop::forever); |
| 1022 | intentionallyLeaked->start(); |
mtklein | de6fc2b | 2015-03-12 06:28:54 -0700 | [diff] [blame] | 1023 | } |
| 1024 | |
caryclark | 83ca628 | 2015-06-10 09:31:09 -0700 | [diff] [blame] | 1025 | #define PORTABLE_FONT_PREFIX "Toy Liberation " |
| 1026 | |
| 1027 | static SkTypeface* create_from_name(const char familyName[], SkTypeface::Style style) { |
| 1028 | if (familyName && strlen(familyName) > sizeof(PORTABLE_FONT_PREFIX) |
| 1029 | && !strncmp(familyName, PORTABLE_FONT_PREFIX, sizeof(PORTABLE_FONT_PREFIX) - 1)) { |
caryclark | 1818acb | 2015-07-24 12:09:25 -0700 | [diff] [blame] | 1030 | return sk_tool_utils::create_portable_typeface(familyName, style); |
caryclark | 83ca628 | 2015-06-10 09:31:09 -0700 | [diff] [blame] | 1031 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1032 | return nullptr; |
caryclark | 83ca628 | 2015-06-10 09:31:09 -0700 | [diff] [blame] | 1033 | } |
| 1034 | |
| 1035 | #undef PORTABLE_FONT_PREFIX |
| 1036 | |
| 1037 | extern SkTypeface* (*gCreateTypefaceDelegate)(const char [], SkTypeface::Style ); |
| 1038 | |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 1039 | int dm_main(); |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 1040 | int dm_main() { |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 1041 | SetupCrashHandler(); |
commit-bot@chromium.org | 39e8d93 | 2014-05-29 20:14:48 +0000 | [diff] [blame] | 1042 | SkAutoGraphics ag; |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 1043 | SkTaskGroup::Enabler enabled(FLAGS_threads); |
caryclark | 83ca628 | 2015-06-10 09:31:09 -0700 | [diff] [blame] | 1044 | gCreateTypefaceDelegate = &create_from_name; |
commit-bot@chromium.org | a65e2fd | 2014-05-30 17:23:31 +0000 | [diff] [blame] | 1045 | |
mtklein | 2e1c47e | 2015-03-12 07:16:56 -0700 | [diff] [blame] | 1046 | start_keepalive(); |
mtklein | de6fc2b | 2015-03-12 06:28:54 -0700 | [diff] [blame] | 1047 | |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 1048 | gather_gold(); |
borenet | 09ed480 | 2015-04-03 14:15:33 -0700 | [diff] [blame] | 1049 | gather_uninteresting_hashes(); |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 1050 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1051 | gather_srcs(); |
| 1052 | gather_sinks(); |
| 1053 | gather_tests(); |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 1054 | |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 1055 | gPending = gSrcs.count() * gSinks.count() + gThreadedTests.count() + gGPUTests.count(); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1056 | SkDebugf("%d srcs * %d sinks + %d tests == %d tasks\n", |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 1057 | gSrcs.count(), gSinks.count(), gThreadedTests.count() + gGPUTests.count(), gPending); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1058 | |
| 1059 | // We try to exploit as much parallelism as is safe. Most Src/Sink pairs run on any thread, |
| 1060 | // 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] | 1061 | // CPU tests run on any thread. GPU tests depend on --gpu_threading. |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1062 | SkTArray<Task> enclaves[kNumEnclaves]; |
| 1063 | for (int j = 0; j < gSinks.count(); j++) { |
| 1064 | SkTArray<Task>& tasks = enclaves[gSinks[j]->enclave()]; |
| 1065 | for (int i = 0; i < gSrcs.count(); i++) { |
| 1066 | tasks.push_back(Task(gSrcs[i], gSinks[j])); |
| 1067 | } |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 1068 | } |
| 1069 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1070 | SkTaskGroup tg; |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 1071 | tg.batch(run_test, gThreadedTests.begin(), gThreadedTests.count()); |
| 1072 | for (int i = 0; i < kNumEnclaves; i++) { |
| 1073 | switch(i) { |
| 1074 | case kAnyThread_Enclave: |
| 1075 | tg.batch(Task::Run, enclaves[i].begin(), enclaves[i].count()); |
| 1076 | break; |
| 1077 | case kGPU_Enclave: |
| 1078 | tg.add(run_enclave_and_gpu_tests, &enclaves[i]); |
| 1079 | break; |
| 1080 | default: |
| 1081 | tg.add(run_enclave, &enclaves[i]); |
| 1082 | break; |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 1083 | } |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 1084 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1085 | tg.wait(); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1086 | // At this point we're back in single-threaded land. |
caryclark | f53ce80 | 2015-06-15 06:48:30 -0700 | [diff] [blame] | 1087 | sk_tool_utils::release_portable_typefaces(); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 1088 | |
mtklein | 2f64eec | 2015-01-15 14:20:41 -0800 | [diff] [blame] | 1089 | SkDebugf("\n"); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1090 | if (gFailures.count() > 0) { |
| 1091 | SkDebugf("Failures:\n"); |
| 1092 | for (int i = 0; i < gFailures.count(); i++) { |
mtklein | 9dc0910 | 2015-01-15 15:47:33 -0800 | [diff] [blame] | 1093 | SkDebugf("\t%s\n", gFailures[i].c_str()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1094 | } |
| 1095 | SkDebugf("%d failures\n", gFailures.count()); |
| 1096 | return 1; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 1097 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1098 | if (gPending > 0) { |
| 1099 | SkDebugf("Hrm, we didn't seem to run everything we intended to! Please file a bug.\n"); |
| 1100 | return 1; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 1101 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1102 | return 0; |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 1103 | } |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 1104 | |
borenet | 4808757 | 2015-04-02 12:16:36 -0700 | [diff] [blame] | 1105 | #if !defined(SK_BUILD_FOR_IOS) |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 1106 | int main(int argc, char** argv) { |
| 1107 | SkCommandLineFlags::Parse(argc, argv); |
| 1108 | return dm_main(); |
| 1109 | } |
| 1110 | #endif |