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