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