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" |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 16 | #include "SkCommonFlags.h" |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 17 | #include "SkForceLinking.h" |
| 18 | #include "SkGraphics.h" |
mtklein | e67164d | 2015-02-02 13:24:37 -0800 | [diff] [blame] | 19 | #include "SkInstCnt.h" |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 20 | #include "SkMD5.h" |
mtklein | 1d0f164 | 2014-09-08 08:05:18 -0700 | [diff] [blame] | 21 | #include "SkOSFile.h" |
mtklein | a82f562 | 2015-02-20 12:30:19 -0800 | [diff] [blame] | 22 | #include "SkTHash.h" |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 23 | #include "SkTaskGroup.h" |
mtklein | de6fc2b | 2015-03-12 06:28:54 -0700 | [diff] [blame] | 24 | #include "SkThreadUtils.h" |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 25 | #include "Test.h" |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 26 | #include "Timer.h" |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 27 | |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 28 | DEFINE_string(src, "tests gm skp image", "Source types to test."); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 29 | DEFINE_bool(nameByHash, false, |
| 30 | "If true, write to FLAGS_writePath[0]/<hash>.png instead of " |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 31 | "to FLAGS_writePath[0]/<config>/<sourceType>/<sourceOptions>/<name>.png"); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 32 | DEFINE_bool2(pathOpsExtended, x, false, "Run extended pathOps tests."); |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 33 | DEFINE_string(matrix, "1 0 0 1", |
| 34 | "2x2 scale+skew matrix to apply or upright when using " |
| 35 | "'matrix' or 'upright' in config."); |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 36 | 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] | 37 | |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 38 | DEFINE_string(blacklist, "", |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 39 | "Space-separated config/src/srcOptions/name quadruples to blacklist. '_' matches anything. E.g. \n" |
| 40 | "'--blacklist gpu skp _ _' will blacklist all SKPs drawn into the gpu config.\n" |
| 41 | "'--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] | 42 | |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 43 | DEFINE_string2(readPath, r, "", "If set check for equality with golden results in this directory."); |
| 44 | |
borenet | 09ed480 | 2015-04-03 14:15:33 -0700 | [diff] [blame] | 45 | DEFINE_string(uninterestingHashesFile, "", |
| 46 | "File containing a list of uninteresting hashes. If a result hashes to something in " |
| 47 | "this list, no image is written for that result."); |
| 48 | |
mtklein | 6393c06 | 2015-04-27 08:45:01 -0700 | [diff] [blame] | 49 | DEFINE_int32(shards, 1, "We're splitting source data into this many shards."); |
| 50 | DEFINE_int32(shard, 0, "Which shard do I run?"); |
| 51 | |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 52 | __SK_FORCE_IMAGE_DECODER_LINKING; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 53 | using namespace DM; |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 54 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 55 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 56 | |
| 57 | SK_DECLARE_STATIC_MUTEX(gFailuresMutex); |
| 58 | static SkTArray<SkString> gFailures; |
| 59 | |
| 60 | static void fail(ImplicitString err) { |
| 61 | SkAutoMutexAcquire lock(gFailuresMutex); |
| 62 | SkDebugf("\n\nFAILURE: %s\n\n", err.c_str()); |
| 63 | gFailures.push_back(err); |
halcanary | 9e398f7 | 2015-01-10 11:18:04 -0800 | [diff] [blame] | 64 | } |
| 65 | |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 66 | static int32_t gPending = 0; // Atomic. Total number of running and queued tasks. |
| 67 | |
| 68 | SK_DECLARE_STATIC_MUTEX(gRunningMutex); |
| 69 | static SkTArray<SkString> gRunning; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 70 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 71 | static void done(double ms, |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 72 | ImplicitString config, ImplicitString src, ImplicitString srcOptions, |
| 73 | ImplicitString name, ImplicitString note, ImplicitString log) { |
| 74 | SkString id = SkStringPrintf("%s %s %s %s", config.c_str(), src.c_str(), |
| 75 | srcOptions.c_str(), name.c_str()); |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 76 | { |
| 77 | SkAutoMutexAcquire lock(gRunningMutex); |
| 78 | for (int i = 0; i < gRunning.count(); i++) { |
| 79 | if (gRunning[i] == id) { |
| 80 | gRunning.removeShuffle(i); |
| 81 | break; |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | if (!FLAGS_verbose) { |
| 86 | note = ""; |
| 87 | } |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 88 | if (!log.isEmpty()) { |
| 89 | log.prepend("\n"); |
| 90 | } |
mtklein | 6dee2ad | 2015-02-05 09:53:44 -0800 | [diff] [blame] | 91 | auto pending = sk_atomic_dec(&gPending)-1; |
reed | 50bc051 | 2015-05-19 14:13:31 -0700 | [diff] [blame^] | 92 | if (!FLAGS_quiet) { |
| 93 | SkDebugf("%s(%4d/%-4dMB %5d) %s\t%s%s%s", FLAGS_verbose ? "\n" : kSkOverwriteLine |
| 94 | , sk_tools::getCurrResidentSetSizeMB() |
| 95 | , sk_tools::getMaxResidentSetSizeMB() |
| 96 | , pending |
| 97 | , HumanizeMs(ms).c_str() |
| 98 | , id.c_str() |
| 99 | , note.c_str() |
| 100 | , log.c_str()); |
| 101 | } |
mtklein | a17241b | 2015-01-23 05:48:00 -0800 | [diff] [blame] | 102 | // We write our dm.json file every once in a while in case we crash. |
| 103 | // Notice this also handles the final dm.json when pending == 0. |
| 104 | if (pending % 500 == 0) { |
| 105 | JsonWriter::DumpJson(); |
| 106 | } |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 107 | } |
| 108 | |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 109 | static void start(ImplicitString config, ImplicitString src, |
| 110 | ImplicitString srcOptions, ImplicitString name) { |
| 111 | SkString id = SkStringPrintf("%s %s %s %s", config.c_str(), src.c_str(), |
| 112 | srcOptions.c_str(), name.c_str()); |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 113 | SkAutoMutexAcquire lock(gRunningMutex); |
| 114 | gRunning.push_back(id); |
| 115 | } |
| 116 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 117 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 118 | |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 119 | struct Gold : public SkString { |
mtklein | a82f562 | 2015-02-20 12:30:19 -0800 | [diff] [blame] | 120 | Gold() : SkString("") {} |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 121 | Gold(ImplicitString sink, ImplicitString src, ImplicitString srcOptions, |
| 122 | ImplicitString name, ImplicitString md5) |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 123 | : SkString("") { |
| 124 | this->append(sink); |
| 125 | this->append(src); |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 126 | this->append(srcOptions); |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 127 | this->append(name); |
| 128 | this->append(md5); |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 129 | } |
mtklein | 02f46cf | 2015-03-20 13:48:42 -0700 | [diff] [blame] | 130 | static uint32_t Hash(const Gold& g) { return SkGoodHash((const SkString&)g); } |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 131 | }; |
mtklein | a82f562 | 2015-02-20 12:30:19 -0800 | [diff] [blame] | 132 | static SkTHashSet<Gold, Gold::Hash> gGold; |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 133 | |
| 134 | static void add_gold(JsonWriter::BitmapResult r) { |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 135 | gGold.add(Gold(r.config, r.sourceType, r.sourceOptions, r.name, r.md5)); |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | static void gather_gold() { |
| 139 | if (!FLAGS_readPath.isEmpty()) { |
| 140 | SkString path(FLAGS_readPath[0]); |
| 141 | path.append("/dm.json"); |
| 142 | if (!JsonWriter::ReadJson(path.c_str(), add_gold)) { |
| 143 | fail(SkStringPrintf("Couldn't read %s for golden results.", path.c_str())); |
| 144 | } |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 149 | |
borenet | 09ed480 | 2015-04-03 14:15:33 -0700 | [diff] [blame] | 150 | static SkTHashSet<SkString> gUninterestingHashes; |
| 151 | |
| 152 | static void gather_uninteresting_hashes() { |
| 153 | if (!FLAGS_uninterestingHashesFile.isEmpty()) { |
| 154 | SkAutoTUnref<SkData> data(SkData::NewFromFileName(FLAGS_uninterestingHashesFile[0])); |
| 155 | SkTArray<SkString> hashes; |
| 156 | SkStrSplit((const char*)data->data(), "\n", &hashes); |
| 157 | for (const SkString& hash : hashes) { |
| 158 | gUninterestingHashes.add(hash); |
| 159 | } |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 164 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 165 | template <typename T> |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 166 | struct Tagged : public SkAutoTDelete<T> { |
| 167 | const char* tag; |
| 168 | const char* options; |
| 169 | }; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 170 | |
| 171 | static const bool kMemcpyOK = true; |
| 172 | |
| 173 | static SkTArray<Tagged<Src>, kMemcpyOK> gSrcs; |
| 174 | static SkTArray<Tagged<Sink>, kMemcpyOK> gSinks; |
| 175 | |
mtklein | 6393c06 | 2015-04-27 08:45:01 -0700 | [diff] [blame] | 176 | static bool in_shard() { |
| 177 | static int N = 0; |
| 178 | return N++ % FLAGS_shards == FLAGS_shard; |
| 179 | } |
| 180 | |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 181 | static void push_src(const char* tag, const char* options, Src* s) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 182 | SkAutoTDelete<Src> src(s); |
mtklein | 6393c06 | 2015-04-27 08:45:01 -0700 | [diff] [blame] | 183 | if (in_shard() && |
| 184 | FLAGS_src.contains(tag) && |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 185 | !SkCommandLineFlags::ShouldSkip(FLAGS_match, src->name().c_str())) { |
| 186 | Tagged<Src>& s = gSrcs.push_back(); |
| 187 | s.reset(src.detach()); |
| 188 | s.tag = tag; |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 189 | s.options = options; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 190 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 191 | } |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 192 | |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 193 | static void push_codec_srcs(Path path) { |
| 194 | SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); |
| 195 | if (!encoded) { |
| 196 | SkDebugf("Couldn't read %s.", path.c_str()); |
| 197 | return; |
| 198 | } |
| 199 | SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); |
| 200 | if (NULL == codec.get()) { |
| 201 | SkDebugf("Couldn't create codec for %s.", path.c_str()); |
| 202 | return; |
| 203 | } |
| 204 | |
| 205 | // Build additional test cases for images that decode natively to non-canvas types |
| 206 | switch(codec->getInfo().colorType()) { |
| 207 | case kGray_8_SkColorType: |
djsollen | a669bc3 | 2015-04-14 13:47:51 -0700 | [diff] [blame] | 208 | push_src("image", "codec_kGray8", new CodecSrc(path, CodecSrc::kNormal_Mode, |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 209 | CodecSrc::kGrayscale_Always_DstColorType)); |
djsollen | a669bc3 | 2015-04-14 13:47:51 -0700 | [diff] [blame] | 210 | push_src("image", "scanline_kGray8", new CodecSrc(path, CodecSrc::kScanline_Mode, |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 211 | CodecSrc::kGrayscale_Always_DstColorType)); |
| 212 | // Intentional fall through |
| 213 | // FIXME: Is this a long term solution for testing wbmps decodes to kIndex8? |
| 214 | // Further discussion on this topic is at skbug.com/3683 |
| 215 | case kIndex_8_SkColorType: |
djsollen | a669bc3 | 2015-04-14 13:47:51 -0700 | [diff] [blame] | 216 | push_src("image", "codec_kIndex8", new CodecSrc(path, CodecSrc::kNormal_Mode, |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 217 | CodecSrc::kIndex8_Always_DstColorType)); |
msarett | 9e43cab | 2015-04-29 07:38:43 -0700 | [diff] [blame] | 218 | push_src("image", "scanline_kIndex8", new CodecSrc(path, CodecSrc::kScanline_Mode, |
| 219 | CodecSrc::kIndex8_Always_DstColorType)); |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 220 | break; |
| 221 | default: |
| 222 | // Do nothing |
| 223 | break; |
| 224 | } |
| 225 | |
| 226 | // Decode all images to the canvas color type |
| 227 | push_src("image", "codec", new CodecSrc(path, CodecSrc::kNormal_Mode, |
| 228 | CodecSrc::kGetFromCanvas_DstColorType)); |
| 229 | push_src("image", "scanline", new CodecSrc(path, CodecSrc::kScanline_Mode, |
| 230 | CodecSrc::kGetFromCanvas_DstColorType)); |
| 231 | } |
| 232 | |
scroggo | 9b77ddd | 2015-03-19 06:03:39 -0700 | [diff] [blame] | 233 | static bool codec_supported(const char* ext) { |
| 234 | // FIXME: Once other versions of SkCodec are available, we can add them to this |
| 235 | // list (and eventually we can remove this check once they are all supported). |
msarett | 8c8f22a | 2015-04-01 06:58:48 -0700 | [diff] [blame] | 236 | static const char* const exts[] = { |
msarett | e16b04a | 2015-04-15 07:32:19 -0700 | [diff] [blame] | 237 | "bmp", "gif", "jpg", "jpeg", "png", "ico", "wbmp", |
| 238 | "BMP", "GIF", "JPG", "JPEG", "PNG", "ICO", "WBMP" |
msarett | 8c8f22a | 2015-04-01 06:58:48 -0700 | [diff] [blame] | 239 | }; |
| 240 | |
| 241 | for (uint32_t i = 0; i < SK_ARRAY_COUNT(exts); i++) { |
| 242 | if (0 == strcmp(exts[i], ext)) { |
| 243 | return true; |
| 244 | } |
| 245 | } |
| 246 | return false; |
scroggo | 9b77ddd | 2015-03-19 06:03:39 -0700 | [diff] [blame] | 247 | } |
| 248 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 249 | static void gather_srcs() { |
| 250 | for (const skiagm::GMRegistry* r = skiagm::GMRegistry::Head(); r; r = r->next()) { |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 251 | push_src("gm", "", new GMSrc(r->factory())); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 252 | } |
halcanary | fc37ad1 | 2015-01-30 07:31:19 -0800 | [diff] [blame] | 253 | for (int i = 0; i < FLAGS_skps.count(); i++) { |
| 254 | const char* path = FLAGS_skps[i]; |
| 255 | if (sk_isdir(path)) { |
| 256 | SkOSFile::Iter it(path, "skp"); |
| 257 | for (SkString file; it.next(&file); ) { |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 258 | push_src("skp", "", new SKPSrc(SkOSPath::Join(path, file.c_str()))); |
halcanary | fc37ad1 | 2015-01-30 07:31:19 -0800 | [diff] [blame] | 259 | } |
| 260 | } else { |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 261 | push_src("skp", "", new SKPSrc(path)); |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 262 | } |
| 263 | } |
halcanary | 23b03c3 | 2015-01-30 09:58:58 -0800 | [diff] [blame] | 264 | static const char* const exts[] = { |
| 265 | "bmp", "gif", "jpg", "jpeg", "png", "webp", "ktx", "astc", "wbmp", "ico", |
| 266 | "BMP", "GIF", "JPG", "JPEG", "PNG", "WEBP", "KTX", "ASTC", "WBMP", "ICO", |
| 267 | }; |
| 268 | for (int i = 0; i < FLAGS_images.count(); i++) { |
| 269 | const char* flag = FLAGS_images[i]; |
| 270 | if (sk_isdir(flag)) { |
| 271 | for (size_t j = 0; j < SK_ARRAY_COUNT(exts); j++) { |
| 272 | SkOSFile::Iter it(flag, exts[j]); |
| 273 | for (SkString file; it.next(&file); ) { |
| 274 | SkString path = SkOSPath::Join(flag, file.c_str()); |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 275 | push_src("image", "decode", new ImageSrc(path)); // Decode entire image |
| 276 | push_src("image", "subset", new ImageSrc(path, 2)); // Decode into 2x2 subsets |
scroggo | 9b77ddd | 2015-03-19 06:03:39 -0700 | [diff] [blame] | 277 | if (codec_supported(exts[j])) { |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 278 | push_codec_srcs(path); |
scroggo | 9b77ddd | 2015-03-19 06:03:39 -0700 | [diff] [blame] | 279 | } |
halcanary | 23b03c3 | 2015-01-30 09:58:58 -0800 | [diff] [blame] | 280 | } |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 281 | } |
halcanary | 23b03c3 | 2015-01-30 09:58:58 -0800 | [diff] [blame] | 282 | } else if (sk_exists(flag)) { |
| 283 | // 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] | 284 | push_src("image", "decode", new ImageSrc(flag)); // Decode entire image. |
| 285 | 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] | 286 | push_codec_srcs(flag); |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 287 | } |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 288 | } |
| 289 | } |
| 290 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 291 | static GrGLStandard get_gpu_api() { |
| 292 | if (FLAGS_gpuAPI.contains("gl")) { return kGL_GrGLStandard; } |
| 293 | if (FLAGS_gpuAPI.contains("gles")) { return kGLES_GrGLStandard; } |
| 294 | return kNone_GrGLStandard; |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 295 | } |
| 296 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 297 | static void push_sink(const char* tag, Sink* s) { |
| 298 | SkAutoTDelete<Sink> sink(s); |
| 299 | if (!FLAGS_config.contains(tag)) { |
| 300 | return; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 301 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 302 | // Try a noop Src as a canary. If it fails, skip this sink. |
| 303 | struct : public Src { |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 304 | Error draw(SkCanvas*) const override { return ""; } |
| 305 | SkISize size() const override { return SkISize::Make(16, 16); } |
| 306 | Name name() const override { return "noop"; } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 307 | } noop; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 308 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 309 | SkBitmap bitmap; |
| 310 | SkDynamicMemoryWStream stream; |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 311 | SkString log; |
| 312 | Error err = sink->draw(noop, &bitmap, &stream, &log); |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 313 | if (err.isFatal()) { |
mtklein | 05641a5 | 2015-04-21 10:49:13 -0700 | [diff] [blame] | 314 | SkDebugf("Could not run %s: %s\n", tag, err.c_str()); |
| 315 | exit(1); |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 316 | } |
| 317 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 318 | Tagged<Sink>& ts = gSinks.push_back(); |
| 319 | ts.reset(sink.detach()); |
| 320 | ts.tag = tag; |
| 321 | } |
| 322 | |
| 323 | static bool gpu_supported() { |
| 324 | #if SK_SUPPORT_GPU |
| 325 | return FLAGS_gpu; |
| 326 | #else |
| 327 | return false; |
| 328 | #endif |
| 329 | } |
| 330 | |
| 331 | static Sink* create_sink(const char* tag) { |
| 332 | #define SINK(t, sink, ...) if (0 == strcmp(t, tag)) { return new sink(__VA_ARGS__); } |
| 333 | if (gpu_supported()) { |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 334 | typedef GrContextFactory Gr; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 335 | const GrGLStandard api = get_gpu_api(); |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 336 | SINK("gpunull", GPUSink, Gr::kNull_GLContextType, api, 0, false, FLAGS_gpu_threading); |
| 337 | SINK("gpudebug", GPUSink, Gr::kDebug_GLContextType, api, 0, false, FLAGS_gpu_threading); |
| 338 | SINK("gpu", GPUSink, Gr::kNative_GLContextType, api, 0, false, FLAGS_gpu_threading); |
| 339 | SINK("gpudft", GPUSink, Gr::kNative_GLContextType, api, 0, true, FLAGS_gpu_threading); |
| 340 | SINK("msaa4", GPUSink, Gr::kNative_GLContextType, api, 4, false, FLAGS_gpu_threading); |
| 341 | SINK("msaa16", GPUSink, Gr::kNative_GLContextType, api, 16, false, FLAGS_gpu_threading); |
| 342 | SINK("nvprmsaa4", GPUSink, Gr::kNVPR_GLContextType, api, 4, false, FLAGS_gpu_threading); |
| 343 | SINK("nvprmsaa16", GPUSink, Gr::kNVPR_GLContextType, api, 16, false, FLAGS_gpu_threading); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 344 | #if SK_ANGLE |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 345 | SINK("angle", GPUSink, Gr::kANGLE_GLContextType, api, 0, false, FLAGS_gpu_threading); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 346 | #endif |
| 347 | #if SK_MESA |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 348 | SINK("mesa", GPUSink, Gr::kMESA_GLContextType, api, 0, false, FLAGS_gpu_threading); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 349 | #endif |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 350 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 351 | |
tomhudson | eebc39a | 2015-02-23 12:18:05 -0800 | [diff] [blame] | 352 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 353 | SINK("hwui", HWUISink); |
| 354 | #endif |
| 355 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 356 | if (FLAGS_cpu) { |
| 357 | SINK("565", RasterSink, kRGB_565_SkColorType); |
| 358 | SINK("8888", RasterSink, kN32_SkColorType); |
mtklein | 19f3060 | 2015-01-20 13:34:39 -0800 | [diff] [blame] | 359 | SINK("pdf", PDFSink); |
mtklein | 9c3f17d | 2015-01-28 11:35:18 -0800 | [diff] [blame] | 360 | SINK("skp", SKPSink); |
mtklein | 8a4527e | 2015-01-31 20:00:58 -0800 | [diff] [blame] | 361 | SINK("svg", SVGSink); |
| 362 | SINK("null", NullSink); |
halcanary | 47ef4d5 | 2015-03-03 09:13:09 -0800 | [diff] [blame] | 363 | SINK("xps", XPSSink); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 364 | } |
| 365 | #undef SINK |
| 366 | return NULL; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 367 | } |
| 368 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 369 | static Sink* create_via(const char* tag, Sink* wrapped) { |
| 370 | #define VIA(t, via, ...) if (0 == strcmp(t, tag)) { return new via(__VA_ARGS__); } |
mtklein | 6fbf4b3 | 2015-05-06 11:35:40 -0700 | [diff] [blame] | 371 | VIA("twice", ViaTwice, wrapped); |
mtklein | 7edca21 | 2015-01-21 13:18:51 -0800 | [diff] [blame] | 372 | VIA("pipe", ViaPipe, wrapped); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 373 | VIA("serialize", ViaSerialization, wrapped); |
reed | 06a22f6 | 2015-05-05 08:11:33 -0700 | [diff] [blame] | 374 | VIA("deferred", ViaDeferred, wrapped); |
mtklein | b7e8d69 | 2015-04-07 08:30:32 -0700 | [diff] [blame] | 375 | VIA("2ndpic", ViaSecondPicture, wrapped); |
mtklein | d31c13d | 2015-05-05 12:59:56 -0700 | [diff] [blame] | 376 | VIA("sp", ViaSingletonPictures, wrapped); |
mtklein | 7edca21 | 2015-01-21 13:18:51 -0800 | [diff] [blame] | 377 | VIA("tiles", ViaTiles, 256, 256, NULL, wrapped); |
| 378 | VIA("tiles_rt", ViaTiles, 256, 256, new SkRTreeFactory, wrapped); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 379 | |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 380 | if (FLAGS_matrix.count() == 4) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 381 | SkMatrix m; |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 382 | m.reset(); |
| 383 | m.setScaleX((SkScalar)atof(FLAGS_matrix[0])); |
| 384 | m.setSkewX ((SkScalar)atof(FLAGS_matrix[1])); |
| 385 | m.setSkewY ((SkScalar)atof(FLAGS_matrix[2])); |
| 386 | m.setScaleY((SkScalar)atof(FLAGS_matrix[3])); |
| 387 | VIA("matrix", ViaMatrix, m, wrapped); |
| 388 | VIA("upright", ViaUpright, m, wrapped); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 389 | } |
tomhudson | 64de1e1 | 2015-03-05 08:01:07 -0800 | [diff] [blame] | 390 | |
| 391 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 392 | VIA("androidsdk", ViaAndroidSDK, wrapped); |
| 393 | #endif |
| 394 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 395 | #undef VIA |
| 396 | return NULL; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 397 | } |
| 398 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 399 | static void gather_sinks() { |
| 400 | for (int i = 0; i < FLAGS_config.count(); i++) { |
| 401 | const char* config = FLAGS_config[i]; |
| 402 | SkTArray<SkString> parts; |
| 403 | SkStrSplit(config, "-", &parts); |
| 404 | |
| 405 | Sink* sink = NULL; |
| 406 | for (int i = parts.count(); i-- > 0;) { |
| 407 | const char* part = parts[i].c_str(); |
| 408 | Sink* next = (sink == NULL) ? create_sink(part) : create_via(part, sink); |
| 409 | if (next == NULL) { |
| 410 | SkDebugf("Skipping %s: Don't understand '%s'.\n", config, part); |
| 411 | delete sink; |
| 412 | sink = NULL; |
| 413 | break; |
| 414 | } |
| 415 | sink = next; |
| 416 | } |
| 417 | if (sink) { |
| 418 | push_sink(config, sink); |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 419 | } |
| 420 | } |
| 421 | } |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 422 | |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 423 | static bool match(const char* needle, const char* haystack) { |
| 424 | return 0 == strcmp("_", needle) || NULL != strstr(haystack, needle); |
| 425 | } |
| 426 | |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 427 | static ImplicitString is_blacklisted(const char* sink, const char* src, |
| 428 | const char* srcOptions, const char* name) { |
mtklein | 0d243ff | 2015-04-03 07:51:00 -0700 | [diff] [blame] | 429 | for (int i = 0; i < FLAGS_blacklist.count() - 3; i += 4) { |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 430 | if (match(FLAGS_blacklist[i+0], sink) && |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 431 | match(FLAGS_blacklist[i+1], src) && |
| 432 | match(FLAGS_blacklist[i+2], srcOptions) && |
| 433 | match(FLAGS_blacklist[i+3], name)) { |
| 434 | return SkStringPrintf("%s %s %s %s", |
| 435 | FLAGS_blacklist[i+0], FLAGS_blacklist[i+1], |
| 436 | FLAGS_blacklist[i+2], FLAGS_blacklist[i+3]); |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 437 | } |
| 438 | } |
| 439 | return ""; |
| 440 | } |
| 441 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 442 | // The finest-grained unit of work we can run: draw a single Src into a single Sink, |
| 443 | // report any errors, and perhaps write out the output: a .png of the bitmap, or a raw stream. |
| 444 | struct Task { |
| 445 | Task(const Tagged<Src>& src, const Tagged<Sink>& sink) : src(src), sink(sink) {} |
| 446 | const Tagged<Src>& src; |
| 447 | const Tagged<Sink>& sink; |
| 448 | |
| 449 | static void Run(Task* task) { |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 450 | SkString name = task->src->name(); |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 451 | SkString note; |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 452 | SkString whyBlacklisted = is_blacklisted(task->sink.tag, task->src.tag, |
| 453 | task->src.options, name.c_str()); |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 454 | if (!whyBlacklisted.isEmpty()) { |
| 455 | note.appendf(" (--blacklist %s)", whyBlacklisted.c_str()); |
| 456 | } |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 457 | SkString log; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 458 | WallTimer timer; |
| 459 | timer.start(); |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 460 | if (!FLAGS_dryRun && whyBlacklisted.isEmpty()) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 461 | SkBitmap bitmap; |
| 462 | SkDynamicMemoryWStream stream; |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 463 | start(task->sink.tag, task->src.tag, task->src.options, name.c_str()); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 464 | Error err = task->sink->draw(*task->src, &bitmap, &stream, &log); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 465 | if (!err.isEmpty()) { |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 466 | timer.end(); |
| 467 | if (err.isFatal()) { |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 468 | fail(SkStringPrintf("%s %s %s %s: %s", |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 469 | task->sink.tag, |
| 470 | task->src.tag, |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 471 | task->src.options, |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 472 | name.c_str(), |
| 473 | err.c_str())); |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 474 | } else { |
| 475 | note.appendf(" (skipped: %s)", err.c_str()); |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 476 | } |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 477 | done(timer.fWall, task->sink.tag, task->src.tag, task->src.options, |
| 478 | name, note, log); |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 479 | return; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 480 | } |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 481 | SkAutoTDelete<SkStreamAsset> data(stream.detachAsStream()); |
| 482 | |
| 483 | SkString md5; |
| 484 | if (!FLAGS_writePath.isEmpty() || !FLAGS_readPath.isEmpty()) { |
| 485 | SkMD5 hash; |
| 486 | if (data->getLength()) { |
| 487 | hash.writeStream(data, data->getLength()); |
| 488 | data->rewind(); |
| 489 | } else { |
| 490 | hash.write(bitmap.getPixels(), bitmap.getSize()); |
| 491 | } |
| 492 | SkMD5::Digest digest; |
| 493 | hash.finish(digest); |
| 494 | for (int i = 0; i < 16; i++) { |
| 495 | md5.appendf("%02x", digest.data[i]); |
| 496 | } |
| 497 | } |
| 498 | |
| 499 | if (!FLAGS_readPath.isEmpty() && |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 500 | !gGold.contains(Gold(task->sink.tag, task->src.tag, |
| 501 | task->src.options, name, md5))) { |
| 502 | fail(SkStringPrintf("%s not found for %s %s %s %s in %s", |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 503 | md5.c_str(), |
| 504 | task->sink.tag, |
| 505 | task->src.tag, |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 506 | task->src.options, |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 507 | name.c_str(), |
| 508 | FLAGS_readPath[0])); |
| 509 | } |
| 510 | |
mtklein | b0531a7 | 2015-04-07 13:38:48 -0700 | [diff] [blame] | 511 | if (!FLAGS_writePath.isEmpty()) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 512 | const char* ext = task->sink->fileExtension(); |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 513 | if (data->getLength()) { |
| 514 | WriteToDisk(*task, md5, ext, data, data->getLength(), NULL); |
halcanary | 022afb8 | 2015-01-30 11:00:12 -0800 | [diff] [blame] | 515 | SkASSERT(bitmap.drawsNothing()); |
| 516 | } else if (!bitmap.drawsNothing()) { |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 517 | WriteToDisk(*task, md5, ext, NULL, 0, &bitmap); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 518 | } |
| 519 | } |
| 520 | } |
| 521 | timer.end(); |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 522 | done(timer.fWall, task->sink.tag, task->src.tag, task->src.options, name, note, log); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | static void WriteToDisk(const Task& task, |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 526 | SkString md5, |
| 527 | const char* ext, |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 528 | SkStream* data, size_t len, |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 529 | const SkBitmap* bitmap) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 530 | JsonWriter::BitmapResult result; |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 531 | result.name = task.src->name(); |
| 532 | result.config = task.sink.tag; |
| 533 | result.sourceType = task.src.tag; |
| 534 | result.sourceOptions = task.src.options; |
| 535 | result.ext = ext; |
| 536 | result.md5 = md5; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 537 | JsonWriter::AddBitmapResult(result); |
| 538 | |
mtklein | b0531a7 | 2015-04-07 13:38:48 -0700 | [diff] [blame] | 539 | // If an MD5 is uninteresting, we want it noted in the JSON file, |
| 540 | // but don't want to dump it out as a .png (or whatever ext is). |
| 541 | if (gUninterestingHashes.contains(md5)) { |
| 542 | return; |
| 543 | } |
| 544 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 545 | const char* dir = FLAGS_writePath[0]; |
| 546 | if (0 == strcmp(dir, "@")) { // Needed for iOS. |
| 547 | dir = FLAGS_resourcePath[0]; |
| 548 | } |
| 549 | sk_mkdir(dir); |
| 550 | |
| 551 | SkString path; |
| 552 | if (FLAGS_nameByHash) { |
| 553 | path = SkOSPath::Join(dir, result.md5.c_str()); |
| 554 | path.append("."); |
| 555 | path.append(ext); |
| 556 | if (sk_exists(path.c_str())) { |
| 557 | return; // Content-addressed. If it exists already, we're done. |
| 558 | } |
| 559 | } else { |
| 560 | path = SkOSPath::Join(dir, task.sink.tag); |
| 561 | sk_mkdir(path.c_str()); |
| 562 | path = SkOSPath::Join(path.c_str(), task.src.tag); |
| 563 | sk_mkdir(path.c_str()); |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 564 | if (strcmp(task.src.options, "") != 0) { |
| 565 | path = SkOSPath::Join(path.c_str(), task.src.options); |
| 566 | sk_mkdir(path.c_str()); |
| 567 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 568 | path = SkOSPath::Join(path.c_str(), task.src->name().c_str()); |
| 569 | path.append("."); |
| 570 | path.append(ext); |
| 571 | } |
| 572 | |
| 573 | SkFILEWStream file(path.c_str()); |
| 574 | if (!file.isValid()) { |
| 575 | fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str())); |
| 576 | return; |
| 577 | } |
| 578 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 579 | if (bitmap) { |
| 580 | // We can't encode A8 bitmaps as PNGs. Convert them to 8888 first. |
| 581 | SkBitmap converted; |
| 582 | if (bitmap->info().colorType() == kAlpha_8_SkColorType) { |
| 583 | if (!bitmap->copyTo(&converted, kN32_SkColorType)) { |
| 584 | fail("Can't convert A8 to 8888.\n"); |
| 585 | return; |
| 586 | } |
| 587 | bitmap = &converted; |
| 588 | } |
| 589 | if (!SkImageEncoder::EncodeStream(&file, *bitmap, SkImageEncoder::kPNG_Type, 100)) { |
| 590 | fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str())); |
| 591 | return; |
| 592 | } |
| 593 | } else { |
| 594 | if (!file.writeStream(data, len)) { |
| 595 | fail(SkStringPrintf("Can't write to %s.\n", path.c_str())); |
| 596 | return; |
| 597 | } |
| 598 | } |
| 599 | } |
| 600 | }; |
| 601 | |
| 602 | // Run all tasks in the same enclave serially on the same thread. |
| 603 | // They can't possibly run concurrently with each other. |
| 604 | static void run_enclave(SkTArray<Task>* tasks) { |
| 605 | for (int i = 0; i < tasks->count(); i++) { |
| 606 | Task::Run(tasks->begin() + i); |
| 607 | } |
| 608 | } |
| 609 | |
| 610 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 611 | |
| 612 | // Unit tests don't fit so well into the Src/Sink model, so we give them special treatment. |
| 613 | |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 614 | static SkTDArray<skiatest::Test> gThreadedTests, gGPUTests; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 615 | |
| 616 | static void gather_tests() { |
mtklein | 6c5fed2 | 2015-01-20 13:47:23 -0800 | [diff] [blame] | 617 | if (!FLAGS_src.contains("tests")) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 618 | return; |
| 619 | } |
mtklein | 6393c06 | 2015-04-27 08:45:01 -0700 | [diff] [blame] | 620 | for (const skiatest::TestRegistry* r = skiatest::TestRegistry::Head(); r; r = r->next()) { |
| 621 | if (!in_shard()) { |
| 622 | continue; |
| 623 | } |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 624 | // Despite its name, factory() is returning a reference to |
| 625 | // link-time static const POD data. |
| 626 | const skiatest::Test& test = r->factory(); |
| 627 | if (SkCommandLineFlags::ShouldSkip(FLAGS_match, test.name)) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 628 | continue; |
| 629 | } |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 630 | if (test.needsGpu && gpu_supported()) { |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 631 | (FLAGS_gpu_threading ? gThreadedTests : gGPUTests).push(test); |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 632 | } else if (!test.needsGpu && FLAGS_cpu) { |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 633 | gThreadedTests.push(test); |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 634 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 635 | } |
| 636 | } |
| 637 | |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 638 | static void run_test(skiatest::Test* test) { |
| 639 | struct : public skiatest::Reporter { |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 640 | void reportFailed(const skiatest::Failure& failure) override { |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 641 | fail(failure.toString()); |
| 642 | JsonWriter::AddTestFailure(failure); |
| 643 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 644 | bool allowExtendedTest() const override { |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 645 | return FLAGS_pathOpsExtended; |
| 646 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 647 | bool verbose() const override { return FLAGS_veryVerbose; } |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 648 | } reporter; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 649 | WallTimer timer; |
| 650 | timer.start(); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 651 | if (!FLAGS_dryRun) { |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 652 | start("unit", "test", "", test->name); |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 653 | GrContextFactory factory; |
| 654 | test->proc(&reporter, &factory); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 655 | } |
| 656 | timer.end(); |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 657 | done(timer.fWall, "unit", "test", "", test->name, "", ""); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 661 | |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 662 | // If we're isolating all GPU-bound work to one thread (the default), this function runs all that. |
| 663 | static void run_enclave_and_gpu_tests(SkTArray<Task>* tasks) { |
| 664 | run_enclave(tasks); |
| 665 | for (int i = 0; i < gGPUTests.count(); i++) { |
| 666 | run_test(&gGPUTests[i]); |
| 667 | } |
| 668 | } |
| 669 | |
mtklein | de6fc2b | 2015-03-12 06:28:54 -0700 | [diff] [blame] | 670 | // Some runs (mostly, Valgrind) are so slow that the bot framework thinks we've hung. |
| 671 | // 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] | 672 | static void start_keepalive() { |
| 673 | struct Loop { |
| 674 | static void forever(void*) { |
| 675 | for (;;) { |
| 676 | static const int kSec = 300; |
| 677 | #if defined(SK_BUILD_FOR_WIN) |
| 678 | Sleep(kSec * 1000); |
| 679 | #else |
| 680 | sleep(kSec); |
| 681 | #endif |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 682 | SkString running; |
| 683 | { |
| 684 | SkAutoMutexAcquire lock(gRunningMutex); |
| 685 | for (int i = 0; i < gRunning.count(); i++) { |
| 686 | running.appendf("\n\t%s", gRunning[i].c_str()); |
| 687 | } |
| 688 | } |
| 689 | SkDebugf("\nCurrently running:%s\n", running.c_str()); |
mtklein | 2e1c47e | 2015-03-12 07:16:56 -0700 | [diff] [blame] | 690 | } |
| 691 | } |
| 692 | }; |
| 693 | static SkThread* intentionallyLeaked = new SkThread(Loop::forever); |
| 694 | intentionallyLeaked->start(); |
mtklein | de6fc2b | 2015-03-12 06:28:54 -0700 | [diff] [blame] | 695 | } |
| 696 | |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 697 | int dm_main(); |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 698 | int dm_main() { |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 699 | SetupCrashHandler(); |
commit-bot@chromium.org | 39e8d93 | 2014-05-29 20:14:48 +0000 | [diff] [blame] | 700 | SkAutoGraphics ag; |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 701 | SkTaskGroup::Enabler enabled(FLAGS_threads); |
mtklein | e67164d | 2015-02-02 13:24:37 -0800 | [diff] [blame] | 702 | if (FLAGS_leaks) { |
| 703 | SkInstCountPrintLeaksOnExit(); |
| 704 | } |
commit-bot@chromium.org | a65e2fd | 2014-05-30 17:23:31 +0000 | [diff] [blame] | 705 | |
mtklein | 2e1c47e | 2015-03-12 07:16:56 -0700 | [diff] [blame] | 706 | start_keepalive(); |
mtklein | de6fc2b | 2015-03-12 06:28:54 -0700 | [diff] [blame] | 707 | |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 708 | gather_gold(); |
borenet | 09ed480 | 2015-04-03 14:15:33 -0700 | [diff] [blame] | 709 | gather_uninteresting_hashes(); |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 710 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 711 | gather_srcs(); |
| 712 | gather_sinks(); |
| 713 | gather_tests(); |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 714 | |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 715 | gPending = gSrcs.count() * gSinks.count() + gThreadedTests.count() + gGPUTests.count(); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 716 | SkDebugf("%d srcs * %d sinks + %d tests == %d tasks\n", |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 717 | gSrcs.count(), gSinks.count(), gThreadedTests.count() + gGPUTests.count(), gPending); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 718 | |
| 719 | // We try to exploit as much parallelism as is safe. Most Src/Sink pairs run on any thread, |
| 720 | // 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] | 721 | // CPU tests run on any thread. GPU tests depend on --gpu_threading. |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 722 | SkTArray<Task> enclaves[kNumEnclaves]; |
| 723 | for (int j = 0; j < gSinks.count(); j++) { |
| 724 | SkTArray<Task>& tasks = enclaves[gSinks[j]->enclave()]; |
| 725 | for (int i = 0; i < gSrcs.count(); i++) { |
| 726 | tasks.push_back(Task(gSrcs[i], gSinks[j])); |
| 727 | } |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 728 | } |
| 729 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 730 | SkTaskGroup tg; |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 731 | tg.batch(run_test, gThreadedTests.begin(), gThreadedTests.count()); |
| 732 | for (int i = 0; i < kNumEnclaves; i++) { |
| 733 | switch(i) { |
| 734 | case kAnyThread_Enclave: |
| 735 | tg.batch(Task::Run, enclaves[i].begin(), enclaves[i].count()); |
| 736 | break; |
| 737 | case kGPU_Enclave: |
| 738 | tg.add(run_enclave_and_gpu_tests, &enclaves[i]); |
| 739 | break; |
| 740 | default: |
| 741 | tg.add(run_enclave, &enclaves[i]); |
| 742 | break; |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 743 | } |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 744 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 745 | tg.wait(); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 746 | // At this point we're back in single-threaded land. |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 747 | |
mtklein | 2f64eec | 2015-01-15 14:20:41 -0800 | [diff] [blame] | 748 | SkDebugf("\n"); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 749 | if (gFailures.count() > 0) { |
| 750 | SkDebugf("Failures:\n"); |
| 751 | for (int i = 0; i < gFailures.count(); i++) { |
mtklein | 9dc0910 | 2015-01-15 15:47:33 -0800 | [diff] [blame] | 752 | SkDebugf("\t%s\n", gFailures[i].c_str()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 753 | } |
| 754 | SkDebugf("%d failures\n", gFailures.count()); |
| 755 | return 1; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 756 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 757 | if (gPending > 0) { |
| 758 | SkDebugf("Hrm, we didn't seem to run everything we intended to! Please file a bug.\n"); |
| 759 | return 1; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 760 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 761 | return 0; |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 762 | } |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 763 | |
borenet | 4808757 | 2015-04-02 12:16:36 -0700 | [diff] [blame] | 764 | #if !defined(SK_BUILD_FOR_IOS) |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 765 | int main(int argc, char** argv) { |
| 766 | SkCommandLineFlags::Parse(argc, argv); |
| 767 | return dm_main(); |
| 768 | } |
| 769 | #endif |